code-423n4 / 2022-01-yield-findings

1 stars 0 forks source link

more efficient nonReentrant() modifier. #46

Closed code423n4 closed 2 years ago

code423n4 commented 2 years ago

Handle

Funen

Vulnerability details

Impact

Expensive gas

Proof of Concept

https://github.com/code-423n4/2022-01-yield/blob/main/contracts/ConvexStakingWrapper.sol#L52-L55

Declaring 3 bool variable is quite expensive for gas usage. Here the better implementation:

bool private _status = true;

    modifier nonReentrant() {
        // On the first call to nonReentrant, _notEntered will be true
        require(_status, "ReentrancyGuard: reentrant call");
        // Any calls to nonReentrant after this point will fail
        _status = false;
        _;
        // By storing the original value once again, a refund is triggered (see
        // https://eips.ethereum.org/EIPS/eip-2200)
        _status = true;
    }
    // save a lot of gas
iamsahu commented 2 years ago

133

alcueca commented 2 years ago

Actually, #96 has a better solution