Platform: Code4rena
Start Date: 28/01/2022
Pot Size: $30,000 USDC
Total HM: 4
Participants: 22
Period: 3 days
Judge: GalloDaSballo
Total Solo HM: 2
Id: 80
League: ETH
Rank: 21/22
Findings: 1
Award: $17.32
🌟 Selected for report: 0
🚀 Solo Findings: 0
17.3157 USDC - $17.32
bitbopper
TL;DR: Guzzling more gas than needed in https://github.com/code-423n4/2022-01-yield/blob/e946f40239b33812e54fafc700eb2298df1a2579/contracts/ConvexStakingWrapper.sol#L81:L90
Longer version: The refund rules changed for clearing a storage slot. It is cheaper to keep the slot occupied. Since you used constants for ENTERED / NOT ENTERED no readability is lost. You might also want to adjust the eip-2200 comment.
cat src/OldLockTest.sol // SPDX-License-Identifier: GPL-3.0-or-later pragma solidity ^0.8.6; contract OldLockTest { bool private _status; bool private constant _NOT_ENTERED = false; bool private constant _ENTERED = true; modifier nonReentrant() { // On the first call to nonReentrant, _notEntered will be true require(_status != _ENTERED, "ReentrancyGuard: reentrant call"); // Any calls to nonReentrant after this point will fail _status = _ENTERED; _; // By storing the original value once again, a refund is triggered (see // https://eips.ethereum.org/EIPS/eip-2200) _status = _NOT_ENTERED; } function doSomething() public nonReentrant returns (uint256) { return 1; } }
cat src/NewLockTest.sol // SPDX-License-Identifier: GPL-3.0-or-later pragma solidity ^0.8.6; contract NewLockTest { uint private _status = 1; uint private constant _NOT_ENTERED = 1; uint private constant _ENTERED = 2; modifier nonReentrant() { // On the first call to nonReentrant, _notEntered will be true require(_status != _ENTERED, "ReentrancyGuard: reentrant call"); // Any calls to nonReentrant after this point will fail _status = _ENTERED; _; // By storing the original value once again, a refund is triggered (see // https://eips.ethereum.org/EIPS/eip-2200) _status = _NOT_ENTERED; } function doSomething() public nonReentrant returns (uint256) { return 1; } }
< contract OldLockTest { < bool private _status; < bool private constant _NOT_ENTERED = false; < bool private constant _ENTERED = true; --- > contract NewLockTest { > uint private _status = 1; > uint private constant _NOT_ENTERED = 1; > uint private constant _ENTERED = 2;
dapp test Running 2 tests for src/LockTest.t.sol:LockTestTest [PASS] test_old() (gas: 23883) [PASS] test_new() (gas: 1626)
Dapptools
Use provided sample code
#0 - iamsahu
2022-02-01T04:39:26Z
#102
#1 - GalloDaSballo
2022-02-13T15:39:38Z
Great submission, I believe this is the standard we should try to achieve for gas savings findings