Platform: Code4rena
Start Date: 20/01/2022
Pot Size: $50,000 USDC
Total HM: 3
Participants: 35
Period: 7 days
Judge: GalloDaSballo
Total Solo HM: 2
Id: 77
League: ETH
Rank: 23/35
Findings: 2
Award: $21.27
🌟 Selected for report: 0
🚀 Solo Findings: 0
🌟 Selected for report: sorrynotsorry
Also found by: 0v3rf10w, Dravee, Meta0xNull, WatchPug, byterocket, defsec, robee, sirhashalot, ye0lde
defsec
Shortening revert strings to fit in 32 bytes will decrease deploy time gas and will decrease runtime gas when the revert condition has been met.
Revert strings that are longer than 32 bytes require at least one additional mstore, along with additional overhead for computing memory offset, etc.
Revert strings > 32 bytes are here:
Manual Review
Shorten the revert strings to fit in 32 bytes. That will affect gas optimization.
#0 - 0xean
2022-01-31T14:08:56Z
dupe of #159
10.4848 USDC - $10.48
defsec
Gas overspending due to excessive external function calls
https://github.com/code-423n4/2022-01-elasticswap/blob/main/elasticswap/src/contracts/Exchange.sol#L176
require(this.totalSupply() > 0, "Exchange: INSUFFICIENT_LIQUIDITY"); require( _baseTokenQtyMin > 0 && _quoteTokenQtyMin > 0, "Exchange: MINS_MUST_BE_GREATER_THAN_ZERO" ); uint256 baseTokenReserveQty = IERC20(baseToken).balanceOf(address(this)); uint256 quoteTokenReserveQty = IERC20(quoteToken).balanceOf(address(this)); uint256 totalSupplyOfLiquidityTokens = this.totalSupply();
Code Review
Store external interaction into the variable at the beginning of the function.
uint256 totalSupplyOfLiquidityTokens = this.totalSupply(); require(totalSupplyOfLiquidityTokens != 0, "Exchange: INSUFFICIENT_LIQUIDITY"); require( _baseTokenQtyMin > 0 && _quoteTokenQtyMin > 0, "Exchange: MINS_MUST_BE_GREATER_THAN_ZERO" ); uint256 baseTokenReserveQty = IERC20(baseToken).balanceOf(address(this)); uint256 quoteTokenReserveQty = IERC20(quoteToken).balanceOf(address(this));
#0 - 0xean
2022-01-31T15:11:13Z
dupe of #178
defsec
!= 0
is a cheaper operation compared to > 0
, when dealing with uint.
https://github.com/code-423n4/2022-01-elasticswap/blob/main/elasticswap/src/contracts/Exchange.sol#L178 https://github.com/code-423n4/2022-01-elasticswap/blob/main/elasticswap/src/contracts/Exchange.sol#L113 https://github.com/code-423n4/2022-01-elasticswap/blob/main/elasticswap/src/contracts/Exchange.sol#L176 https://github.com/code-423n4/2022-01-elasticswap/blob/main/elasticswap/src/contracts/Exchange.sol#L178
Code Review
Use "!=0" instead of ">0" for the gas optimization.
#0 - 0xean
2022-01-31T14:03:34Z
dupe of #161
defsec
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.
https://github.com/code-423n4/2022-01-elasticswap/blob/main/elasticswap/src/libraries/MathLib.sol#L705
None
Consider applying unchecked arithmetic where overflow/underflow is not possible.
#0 - 0xean
2022-01-31T13:54:58Z
dupe of #177