Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: gas optimizations on terabethia contract #27

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

b0xtch
Copy link
Contributor

@b0xtch b0xtch commented Jun 20, 2022

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