Skip to content

chore: gas optimizations on terabethia contract - #27

Open
b0xtch wants to merge 1 commit into
masterfrom
chore/tera-gas-optimization
Open

chore: gas optimizations on terabethia contract#27
b0xtch wants to merge 1 commit into
masterfrom
chore/tera-gas-optimization

Conversation

@b0xtch

@b0xtch b0xtch commented Jun 20, 2022

Copy link
Copy Markdown
Contributor

Once simpleStorage().messages[msgHash] is assigned to 1. Consider setting simpleStorage().messages[msgHash] to zero to show the message has been consumed on the L2.

-Gas optimizations within sendMessage function w/ ~500 gas savings in total:
--cache simpleStorage().nonce to avoid performing multiple SLOADS

--use unchecked math when incrementing simpleStorage().nonce, overflow unrealistic. if this contract were called 100 trillion times a day for 100 years we would still not be close to overflow. overflow can and should be monitored outside of the contract.

--don't increment simpleStorage().messages[msgHash]. instead, assign to 1 to save gas. There's never a situation where this value is anything other than 1 or 0 because the nonce is used when encoding the message hash. The message hash will never be repeated.

  • testing
  • deploy

@b0xtch
b0xtch marked this pull request as ready for review August 5, 2022 10:24
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.

1 participant