Compared to nested if
statements, using logical AND (&&
) results in a relatively larger deployment size, and higher gas overhead on each call.
Inside the onlyBuyerOrSeller
modifier, a logical AND (&&
) has been used to ensure both conditions (that caller is either buyer or seller) are met for the modified function to be accessed. However, using a logical AND is more expensive than using a nested if
statement. This is due to how the compiler optimizes for nested if
statements.
Gas
Forge, Foundry Tooklit (gas snapshots and gas reports)
The modifier can be refactored to use a nested if statement:
With this change, the following gas savings were seen:
On average, ~1800
gas was saved in each Escrow test in EscrowTest.t.sol
, whereas a cumulative 41650
gas saving was seen across all tests.
Deployment size was reduced from 3666
to 3657
(a saving of 9 bytes).
Deployment cost reduced from 591900
to 590100
(a saving of 1800
gas).
initiateDispute
(the function using the modifier in question)'s size reduced from 316
bytes to 292
bytes (24
bytes). Whereas calling the function saved 19
gas on each call.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.