Platform: Code4rena
Start Date: 04/02/2022
Pot Size: $30,000 USDC
Total HM: 3
Participants: 37
Period: 3 days
Judge: leastwood
Id: 84
League: ETH
Rank: 32/37
Findings: 1
Award: $40.51
🌟 Selected for report: 0
🚀 Solo Findings: 0
40.5129 USDC - $40.51
Jujic
Shortening revert strings to fit in 32 bytes will decrease deployment time gas and will decrease runtime gas when the revert condition has been met. ##Proof of Concept
require( _saleStart >= block.timestamp, "TokenSale: start date may not be in the past" );
Shorten the revert strings to fit in 32 bytes.
For the arithmetic operations that will never over/underflow, using the unchecked directive (Solidity v0.8 has default overflow/underflow checks) can save some gas from the unnecessary internal over/underflow checks.
function getTokenInLimitLeft() external view returns (uint256 limitLeft_) { if (totalTokenIn < tokenInLimit) { limitLeft_ = tokenInLimit - totalTokenIn; } }
Remix
Consider using 'unchecked' where it is safe to do so. Example:
unchecked { limitLeft_ = tokenInLimit - totalTokenIn; }
Some of the variable can be cached to slightly reduce gas usage.
saleStart
and guestlist
can be cached.
https://github.com/code-423n4/2022-02-badger-citadel/blob/08d43b5662f6d6c3707b720eadc773b913f79f2c/contracts/TokenSaleUpgradeable.sol#L144-L186
Remix
Consider caching those variable for read and make sure write back to storage.
ERC20Upgradeable is a superset of ERC20 and in this case, only ERC20 functions are required to be called on, so IERC20 can be used. ##Proof of Concept https://github.com/code-423n4/2022-02-badger-citadel/blob/08d43b5662f6d6c3707b720eadc773b913f79f2c/contracts/TokenSaleUpgradeable.sol#L19-L21
ERC20Upgradeable public tokenOut; ERC20Upgradeable public tokenIn;
Remix
#0 - GalloDaSballo
2022-02-14T13:58:28Z
Agree with all findings except 4. Use Minimal Interface for gas optimizations, code that is not used doesn't join the final bytecode, the compiler removes it for you