Skip to content

fix: reduce SLOADs and remove dead code in TokenMessenger - #115

Open
Alicepoltora wants to merge 1 commit into
circlefin:masterfrom
Alicepoltora:fix/gas-optimizations-token-messenger
Open

Alicepoltora wants to merge 1 commit into
circlefin:masterfrom
Alicepoltora:fix/gas-optimizations-token-messenger

Conversation

@Alicepoltora

Copy link
Copy Markdown

Summary

Fixes #112

1. _getLocalMinter() — cache SLOAD

Read localMinter into a local variable before the require check. Avoids reading storage twice (once for the check, once for the return).

2. removeRemoteTokenMessenger() — cache SLOAD

Read remoteTokenMessengers[domain] into a local variable first, then use it for both the require check and the emit. Avoids a redundant SLOAD.

3. _isLocalMessageTransmitter() — remove dead immutable check

Removed address(localMessageTransmitter) != address(0). The localMessageTransmitter immutable is set in the constructor with a require(non-zero) guard — it can never be zero. The check always evaluates to true and wastes gas on every call.

1. _getLocalMinter(): cache localMinter in a local variable to avoid
   reading storage twice (require check + return).

2. removeRemoteTokenMessenger(): read remoteTokenMessengers[domain]
   once into a local variable instead of twice (require check + emit).

3. _isLocalMessageTransmitter(): remove dead immutable check
   address(localMessageTransmitter) != address(0). The immutable is
   set in the constructor with a require(non-zero) guard, so this
   condition is always true.

Fixes circlefin#112
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Gas optimization opportunities in TokenMessenger.sol ~$49K/month at current volume

1 participant