To prevent repeated code revision reverting, the following gas optimizations are done cumulatively, meaning each one adds to the last's codebase. These are also from running forge test --gas-report with a custom Foundry profile that limits fuzz runs to 100 and disables the IR pipeline.
if (amount != 1) {
revert InvalidERC721TransferAmount();
}
// Perform transfer via the token contract directly.
_performERC721Transfer(token, from, to, identifier);
With the following:
if (amount == 1) {
// Perform transfer via the token contract directly.
_performERC721Transfer(token, from, to, identifier);
} else {
revert InvalidERC721TransferAmount();
}
This again saves extremely small amounts of gas on fulfillBasicOrder(), but hey, it's something.
Gas Optimizations
To prevent repeated code revision reverting, the following gas optimizations are done
cumulatively
, meaning each one adds to the last's codebase. These are also from runningforge test --gas-report
with a custom Foundry profile that limits fuzz runs to 100 and disables the IR pipeline.1 - Use shr instead of dividing by 4
Replace the line here with:
Saves on average 3 gas per
fulfillBasicOrder()
call according to tests. Saves 1 gas on median.Before: fulfillBasicOrder ┆ 753 ┆ 578873 ┆ 214735 ┆ 3437148
After: fulfillBasicOrder ┆ 751 ┆ 578870 ┆ 214734 ┆ 3437146
2 - Short-Circuit a reverting inequality check
Replace the block starting here, copied below:
With the following:
This again saves extremely small amounts of gas on
fulfillBasicOrder()
, but hey, it's something.Before: fulfillBasicOrder ┆ 751 ┆ 578870 ┆ 214734 ┆ 3437146
After: fulfillBasicOrder ┆ 751 ┆ 578870 ┆ 214733 ┆ 3437145