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

Using function parameters in emits saves gas #65

Open
code423n4 opened this issue Sep 15, 2021 · 0 comments
Open

Using function parameters in emits saves gas #65

code423n4 opened this issue Sep 15, 2021 · 0 comments

Comments

@code423n4
Copy link
Contributor

Handle

0xRajeev

Vulnerability details

Impact

Public/external setter functions that emit events to indicate the newly set values can use the function parameters (from memory/calldata) or their cached versions as emit arguments instead of the state variables that were just written to because SLOADs cost 2100/100 gas depending on cold/warm reads from Berlin upgrade onwards.

Proof of Concept

https://github.com/sushiswap/miso/blob/2cdb1486a55ded55c81898b7be8811cb68cfda9e/contracts/Liquidity/PostAuctionLauncher.sol#L160

Tools Used

Manual Analysis

Recommended Mitigation Steps

Use function parameters or cached local variables in emits to save gas.

@code423n4 code423n4 added bug Something isn't working G (Gas Optimization) labels Sep 15, 2021
code423n4 added a commit that referenced this issue Sep 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants