Open code423n4 opened 2 years ago
Gas: Unnecessary ERC20 transfer data length check
This impacts the reference implementation which is not a target for optimizations, as the warden notes the optimized Yul version already seems to do the right thing here.
The other 2 recommendations may be worthwhile optimizations to include.
Gas: Unnecessary ERC20 transfer data length check
The
data.length != 0 && data.length >= 32
check has a redundancy. Asdata.length >= 32
is required anddata.length >= 32
impliesdata.length != 0
, one can simplify this expression todata.length >= 32
. The YUL version of the code checks "(abi.decode(data, uint256) == 1 && data.length > 31) || data.length == 0
" which is correctly optimized.Gas: Unnecessary conduit runtime code hash computation
The
ConduitController
computes the_CONDUIT_RUNTIME_CODE_HASH
variable by deploying aConduit
contract and reading its.codehash
. However, this variable is only used to check if a contract has been deployed by checkingconduit.codehash == _CONDUIT_RUNTIME_CODE_HASH
. Theconduit
variable is always acreate2
address and by the waycreate2
addresses work, the check can also be implemented ascondit.code.length != 0
. (Because the creation code is already part of thecreate2
address and the creation code always leads to the same runtime code forConduit
s.) This saves deploying aConduit
contract in the constructor and the new check should also be more gas-efficient.Gas: Improve
MerkleProof.verify
The
MerkleProof.verify
function can be improved using thexor
trick instead of aswitch
to order the hashes. Plus some other improvements. Credit