unlock icon indicating copy to clipboard operation
unlock copied to clipboard

[fix]Use Local Memory Type Variable Instead of Global Storage Type Variable in Event to Save Gas

Open Ether1oop opened this issue 2 years ago • 3 comments

Description

Hi, we are a research group on programming languages and software engineering. We recently have conducted a systematic study about Solidity event usage, evolution, and impact, and we are attempting to build a tool to improve the practice of Solidity event use based on our findings. We have tried our prototype tool on some of the most popular GitHub Solidity repositories, and for your repository, we find a potential optimization of gas consumption arisen from event use.

The point is that when we use emit operation to store the value of a certain variable, local memory type variable would be preferable to storage type (state) variable if they hold the same value. The reason is that an extra SLOAD operation would be needed to access the variable if it is storage type, and the SLOAD operation costs 800 gas.

For your repository, we find that several event uses can be improved.

Issues

#9458

Checklist:

  • [x] 1 PR, 1 purpose: my Pull Request applies to a single purpose
  • [ ] I have commented my code, particularly in hard-to-understand areas
  • [ ] I have updated the docs to reflect my changes if applicable
  • [ ] I have added tests (and stories for frontend components) that prove my fix is effective or that my feature works
  • [ ] I have performed a self-review of my own code
  • [ ] If my code involves visual changes, I am adding applicable screenshots to this thread

Ether1oop avatar Sep 07 '22 00:09 Ether1oop

@clemsos What do you think?

julien51 avatar Sep 07 '22 14:09 julien51

@Ether1oop Thanks a lot! would you be able to post about the savings here? How much exactly are they?

julien51 avatar Sep 07 '22 14:09 julien51

@Ether1oop I'm Angela Steffens and I handle developer relations and community here at Unlock Protocol. I'd love to nominate you for our retroactive funding for your contribution here. I just need your wallet address so we know where to send your UDT reward if you receive the votes. It's also not against the rules to nominate yourself if you'd like to do that. https://unlock.community/t/retroactive-funding-september-2022/347

wonderwomancode avatar Sep 07 '22 20:09 wonderwomancode