40,000 USDC
View results
Submission Details
Severity: gas

G-02 By using assembly for the creat2 deployment in `newEscrow()` 548 gas can be saved

Summary

If assembly is used for the creat2 deployment, 548 gas can be saved each time a new escrow is created

Vulnerability Details

Impact

Tools Used

Recommendations

Replace the code in newEscrow() with the following:

function newEscrow(uint256 price, IERC20 tokenContract, address seller, address arbiter, uint256 arbiterFee, bytes32 salt ) external returns (IEscrow)
{
bytes memory bytecode = abi.encodePacked(type(Escrow).creationCode, abi.encode(price, tokenContract, msg.sender, seller, arbiter, arbiterFee));
address computedAddress = computeEscrowAddress(bytecode, address(this), uint256(salt));
tokenContract.safeTransferFrom(msg.sender, computedAddress, price);
address addr;
assembly{
addr := create2(0, add(bytecode, 0x20), mload(bytecode), salt)
}
if (addr != computedAddress) {
revert EscrowFactory__AddressesDiffer();
}
emit EscrowCreated(addr, msg.sender, seller, arbiter);
return IEscrow(addr);
}

Support

FAQs

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