Open code423n4 opened 2 years ago
Cache arrays length on loops Use pre increment and pre decrement instead of post increment and post decrement
These should offer some savings.
Assembly casting of address/bytes32 to uint256
Although these recommendations are not great for code readability, they do offer savings and follow the general pattern in this project of using Yul to optimize as much as possible.
Gas optimizations
Cache arrays length on loops
Caching the array length in memory can yield significant gas savings when the array length is high.
On file
contracts/lib/OrderCombiner.sol
you can cache the offers length and the consideration length;On file
contracts/lib/OrderFulfiller.sol
you can cache the offers length and the consideration length;Use pre increment and pre decrement instead of post increment and post decrement
++i
costs less gas compared toi++
ori += 1
for unsigned integers. This is because the pre-increment operation is cheaper. SourceAssembly casting of address/bytes32 to uint256
In ConduitController.sol
L321-L334(13 gas):
if (msg.sender != _conduits[conduit].potentialOwner) {
if (toUint256(msg.sender) != toUint256(_conduits[conduit].potentialOwner)) {
if (msg.sender != _conduits[conduit].owner) {
if (toUint256(msg.sender) != toUint256(_conduits[conduit].owner)) {
In OrderValidator.sol, L280(18-36 gas):
In SignatureVerification.sol, L97(18 gas):
In ZoneInteraction.sol
In Verifiers.sol, L76(18 gas):