40,000 USDC
View results
Submission Details
Severity: gas

[G‑07] The bytecode can be removed from the function params

All optimizations were benchmarked using the protocol's tests using the following config: solc version 0.8.18, optimizer on, 200 runs, viaIR = true. In most cases forge test --gas-report was used

Each optimization was submitted individually.

Gas Optimizations

Issue Instances Total Gas Saved
[G‑01] Consider using clones * -70% cheaper deployment gas
[G‑02] ReentrancyGuard can be safely removed 1 42725
[G‑03] computeEscrowAddress() can be internal instead of public 1 55863 + 193
[G‑04] Redundant zero address checks 2 237
[G‑05] Input validation should be done in the beginning 2 110649(in the revert case)
[G‑06] Emit after the transfer has been made in case it fails 2 1381(in the revert case)
[G‑07] The bytecode can be removed from the function params 1 27
[G‑08] Nested ifs are cheaper than && 1 19

[G‑07] The bytecode can be removed from the function params

Instead of having computeEscrowAddress() accept the bytecode as an argument it would more efficient if it was already embedded in the keccak256 function. This will allow us to save a small amount of gas.

Gas Savings for newEscrow() obtained via protocol's tests(median was used because the avg isnt accurate here): 27 gas

MED
Before 627057
After 627030

There is 1 instance of this issue:

https://github.com/Cyfrin/2023-07-escrow/blob/65a60eb0773803fa0be4ba72defaec7d8567bccc/src/EscrowFactory.sol#L57

File: EscrowFactory.sol
56: function computeEscrowAddress(
57: bytes memory byteCode,
58: address deployer,
59: uint256 salt,
60: uint256 price,
61: IERC20 tokenContract,
62: address buyer,
63: address seller,
64: address arbiter,
65: uint256 arbiterFee
66: ) public pure returns (address) {
67: address predictedAddress = address(
68: uint160(
69: uint256(
70: keccak256(
71: abi.encodePacked(
72: bytes1(0xff),
73: deployer,
74: salt,
75: keccak256(
76: abi.encodePacked(
77: byteCode, abi.encode(price, tokenContract, buyer, seller, arbiter, arbiterFee)
78: )
79: )

Instead of passing in the byteCode into the function, it can be removed and you can put type(Escrow).creationCode in the abi.encodePacked() where its supposed to be

Support

FAQs

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