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: 26/35
Findings: 2
Award: $13.86
🌟 Selected for report: 0
🚀 Solo Findings: 0
10.4848 USDC - $10.48
sirhashalot
The Exchange.sol removeLiquidity()
function calls this.totalSupply() twice. To save gas, call it once and set the value to a variable, because using a variable is cheaper than a second function call.
There are two calls to this.totalSupply() in removeLiquidity()
Move line 187, shown below, to a line before the require statement. Modify the require statement to reference the variable. The end result will look like:
uint256 totalSupplyOfLiquidityTokens = this.totalSupply(); require(totalSupplyOfLiquidityTokens > 0, "Exchange: INSUFFICIENT_LIQUIDITY");
#0 - 0xean
2022-01-31T13:52:24Z
dupe of #178
🌟 Selected for report: sorrynotsorry
Also found by: 0v3rf10w, Dravee, Meta0xNull, WatchPug, byterocket, defsec, robee, sirhashalot, ye0lde
3.377 USDC - $3.38
sirhashalot
Strings are broken into 32 byte chunks for operations. Revert error strings over 32 bytes therefore consume extra gas as documented publicly
There are multiple examples of this gas optimization opportunity, including but not limited to:
Reducing revert error strings to under 32 bytes decreases deployment time gas and runtime gas when the revert condition is met. Alternatively, the code could be modified to use custom errors, introduced in Solidity 0.8.4: https://blog.soliditylang.org/2021/04/21/custom-errors/
#0 - 0xean
2022-01-31T14:08:40Z
dupe of #159