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: 18/35
Findings: 1
Award: $74.71
🌟 Selected for report: 1
🚀 Solo Findings: 0
🌟 Selected for report: wuwe1
Also found by: Ruhum, WatchPug, csanuragjain, gzeon
13.9797 USDC - $13.98
Ruhum
The parameters here are already validated by the caller of the function: https://github.com/code-423n4/2022-01-elasticswap/blob/main/elasticswap/src/libraries/MathLib.sol#L663
So the same check is done twice.
#0 - GalloDaSballo
2022-02-04T23:05:57Z
Duplicate of #173
10.4848 USDC - $10.48
Ruhum
totalSupply()
is called twice within a function. That can be cached to reduce gas costs
Cache the value and use that in the require statement
#0 - 0xean
2022-01-31T13:50:45Z
dupe of #178
Ruhum
!= 0
uses less gas than > 0
.
Just search for > 0
and you'll find quite a large number of instances where > 0
is used.
#0 - 0xean
2022-01-31T14:03:28Z
dupe of #161
47.9414 USDC - $47.94
Ruhum
The internalBalances
state variable is used extensively throughout the Exchange
contract. Reading and writing to storage is expensive. Instead of working the state variable directly, the functions should work with a cached memory variable. The final value should then be saved to storage.
There are too many places where this is happening. Most prominently in the MathLib
library, where the state variable is passed around as a function parameter. Working with a cached version will be way cheaper.
Replace the storage variable with a cached memory variable. The library has to be refactored to return the modified values so they can be written back to storage.
#0 - GalloDaSballo
2022-02-04T23:03:43Z
Agree with the finding, if a storage var is read at least twice, there will be at least 94 in gas savings units for each optimization (97 for any subsequent cached read)