Platform: Code4rena
Start Date: 20/05/2022
Pot Size: $1,000,000 USDC
Total HM: 4
Participants: 59
Period: 14 days
Judge: leastwood
Id: 128
League: ETH
Rank: 37/59
Findings: 1
Award: $570.27
🌟 Selected for report: 0
🚀 Solo Findings: 0
🌟 Selected for report: Dravee
Also found by: 0x1f8b, 0x29A, 0xalpharush, Chom, Czar102, Hawkeye, IllIllI, MaratCerby, MiloTruck, NoamYakov, OriDabush, RoiEvenHaim, Spearbit, Tadashi, TerrierLover, TomJ, asutorufos, cccz, cmichel, csanuragjain, defsec, delfin454000, djxploit, ellahi, foobar, gzeon, hake, hickuphh3, ignacio, ilan, joestakey, kaden, mayo, ming, oyc_109, peritoflores, rfa, sach1r0, sashik_eth, shung, sirhashalot, twojoy, zer0dot, zkhorse
570.2704 USDC - $570.27
I identified a loop invariant code motion optimization in _prepareBasicFulfillmentFromCalldata
which saves roughly 150 gas on average and reduces the max cost 450 whenever the method fulfillBasicOrder
is called. Note, this is based on the hardhat test cases provided in the repo and calculated using yarn profile
.
Before: | Min: 93563 | Max: 1624267 | Avg: 665051 After: | Min: 93577 | Max: 1623834 | Avg: 664908 Change: | +14 | -433 | -143
I found that removing the induction variable, i
, as shown below was not cheaper, on average. However, it may be useful if, on mainnet, many tips are sent and outweigh the cost of the the hoisted expression.
totalAdditionalRecipients := calldataload(BasicOrder_totalOriginalAdditionalRecipients_cdPtr) let additionalRecipientCdPtr := 0x244 let max := add(mul(totalAdditionalRecipients, 0x40), additionalRecipientCdPtr) for {} lt(additionalRecipientCdPtr, max) {} {/ * loop body */ }
The patch required to apply this optimization is available here: https://gist.github.com/0xalpharush/15f4c3eeec9367a853e494daee36150b
#0 - HardlyDifficult
2022-06-26T15:43:52Z
This optimization offers a small but non-trivial savings and may be worth considering.