40,000 USDC
View results
Submission Details
Severity: gas

Move computeEscrowAddress inline

Summary

In Escrow.sol, it is cheaper to inline computeEscrowAddress than to reference it in a function. The function is pure, therefore it can be calculated off-chain for testing or UI purposes. This will decrease costs across the board.

Impact

About 100 gas can be saved in each deployment.

Tools Used

  • Foundry

Recommendations

Remove the computeEscrowAddress function. It is not defined within IEscrow.sol.

function newEscrow(
uint256 price,
IERC20 tokenContract,
address seller,
address arbiter,
uint256 arbiterFee,
bytes32 salt
) external returns (IEscrow) {
address computedAddress = address(uint160(uint256(keccak256(
abi.encodePacked(
bytes1(0xff),
address(this),
salt,
keccak256(
abi.encodePacked(
type(Escrow).creationCode,
abi.encode(price, tokenContract, msg.sender, seller, arbiter, arbiterFee)
)
)
)
))));
tokenContract.safeTransferFrom(msg.sender, computedAddress, price);
// ...
}

This will make two tests unusable, but the address can be calculated off-chain.

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.