Platform: Code4rena
Start Date: 22/09/2022
Pot Size: $30,000 USDC
Total HM: 12
Participants: 133
Period: 3 days
Judge: 0xean
Total Solo HM: 2
Id: 165
League: ETH
Rank: 115/133
Findings: 1
Award: $12.81
🌟 Selected for report: 0
🚀 Solo Findings: 0
🌟 Selected for report: pfapostol
Also found by: 0x040, 0x1f8b, 0x4non, 0x5rings, 0xA5DF, 0xNazgul, 0xSmartContract, 0xmatt, 0xsam, Amithuddar, Aymen0909, B2, Ben, Bnke0x0, Chom, CodingNameKiki, Deivitto, Diana, Fitraldys, Funen, IllIllI, JAGADESH, JC, Metatron, Ocean_Sky, PaludoX0, Pheonix, RaymondFam, ReyAdmirado, RockingMiles, Rohan16, Rolezn, Satyam_Sharma, Sm4rty, SnowMan, SooYa, Tagir2003, TomJ, Tomio, Triangle, V_B, Waze, __141345__, ajtra, albincsergo, asutorufos, aysha, beardofginger, bobirichman, brgltd, bulej93, bytera, c3phas, ch0bu, cryptostellar5, cryptphi, d3e4, delfin454000, dharma09, drdr, durianSausage, emrekocak, erictee, fatherOfBlocks, gogo, got_targ, imare, jag, karanctf, ladboy233, leosathya, lukris02, medikko, mics, millersplanet, natzuu, neko_nyaa, oyc_109, peanuts, prasantgupta52, rbserver, ret2basic, rokinot, ronnyx2017, rotcivegaf, sach1r0, samruna, seyni, slowmoses, tnevler, wagmi, zishansami
12.8108 USDC - $12.81
https://github.com/code-423n4/2022-09-frax/blob/main/src/frxETHMinter.sol#L41-L50
withholdRatio cannot exceed 1e6 = 1,000,000. A uint24 can be used as this has a maximum value of 16,777,215.
currentWithheldETH can be changed to uint216, this is more than enough to store an amount of ETH, e.g Uniswap V2 uses a uint112 to store its reserve amounts.
With two booleans which use a byte each, the total storage is 24 + 216 + 8 + 8 = 256.
Change to:
mapping(bytes => bool) public activeValidators; // Tracks validators (via their pubkeys) that already have 32 ETH in them uint24 public withholdRatio; // What we keep and don't deposit whenever someone submit()'s ETH uint216 public currentWithheldETH; // Needed for internal tracking IDepositContract public immutable depositContract; // ETH 2.0 deposit contract frxETH public immutable frxETHToken; IsfrxETH public immutable sfrxETHToken; bool public submitPaused; bool public depositEtherPaused;
saves 97 gas per access after variable is cached. Incurs a gas cost of 3 to write variable to memory.
https://github.com/code-423n4/2022-09-frax/blob/main/src/frxETHMinter.sol#L95-L96
https://github.com/code-423n4/2022-09-frax/blob/main/src/frxETHMinter.sol#L167-L168
Changes: 29586 average gas used in submit function, down from 33464.