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

noReenter gas optimization #200

Closed
code423n4 opened this issue Jan 6, 2022 · 2 comments
Closed

noReenter gas optimization #200

code423n4 opened this issue Jan 6, 2022 · 2 comments
Labels
bug Something isn't working duplicate This issue or pull request already exists G (Gas Optimization) sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity")

Comments

@code423n4
Copy link
Contributor

Handle

0xsanson

Vulnerability details

The current implementation uses _locked = 0 for the unlocked state and _locked = 1 for the locked one. It's better to have two non-zero values from an optimization point of view; it can surprisingly save thousands of gas in some test cases.

Consider rewriting the modifier to:

modifier noReenter() {
    require(_locked == 1, "LOCKED");
    _locked = uint256(2);
    _;
    _locked = uint256(1);
}

(also add a _locked = 1 in the constructor).

Tools Used

hardhat gas reporter

@code423n4 code423n4 added bug Something isn't working G (Gas Optimization) labels Jan 6, 2022
code423n4 added a commit that referenced this issue Jan 6, 2022
@deluca-mike deluca-mike added the sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity") label Jan 7, 2022
@deluca-mike
Copy link
Collaborator

Agreed. While not always cheaper, it is cheaper in this case for batch unlocks or relocks. Will implement this.

@deluca-mike deluca-mike added the duplicate This issue or pull request already exists label Jan 9, 2022
@deluca-mike
Copy link
Collaborator

Duplicate #1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working duplicate This issue or pull request already exists G (Gas Optimization) sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity")
Projects
None yet
Development

No branches or pull requests

3 participants