40,000 USDC
View results
Submission Details
Severity: gas

Gas Optimization - Escrow

Summary

Gas Optimizations

Issue Instances
[G‑01] Cache msg.sender 6
[G‑02] Use simple events without argument 1
[G‑03] Wrap most repeated code inside a private or internal function 4

Total: 11 instances over issues.

The table above and its gas numbers are created by considering the automatic findings which are not included.

Gas Optimizations

[G‑01] Cache msg.sender

Caching multiple uses of msg.sender inside memory costs less than the same.

There is 6 instances of this issue:

function newEscrow(
uint256 price,
IERC20 tokenContract,
address seller,
address arbiter,
uint256 arbiterFee,
bytes32 salt
) external returns (IEscrow) {
address computedAddress = computeEscrowAddress(
type(Escrow).creationCode,
address(this),
uint256(salt),
price,
tokenContract,
msg.sender,
seller,
arbiter,
arbiterFee
);
tokenContract.safeTransferFrom(msg.sender, computedAddress, price);
Escrow escrow = new Escrow{salt: salt}(
price,
tokenContract,
msg.sender,
seller,
arbiter,
arbiterFee
);
if (address(escrow) != computedAddress) {
revert EscrowFactory__AddressesDiffer();
}
emit EscrowCreated(address(escrow), msg.sender, seller, arbiter);
return escrow;
}

https://github.com/Cyfrin/2023-07-escrow/blob/main/src/EscrowFactory.sol#L34

https://github.com/Cyfrin/2023-07-escrow/blob/main/src/EscrowFactory.sol#L39C40-L39C51

https://github.com/Cyfrin/2023-07-escrow/blob/main/src/EscrowFactory.sol#L43

https://github.com/Cyfrin/2023-07-escrow/blob/main/src/EscrowFactory.sol#L51C45-L51C55

modifier onlyBuyerOrSeller() {
if (msg.sender != i_buyer && msg.sender != i_seller) {
revert Escrow__OnlyBuyerOrSeller();
}
_;
}

https://github.com/Cyfrin/2023-07-escrow/blob/main/src/Escrow.sol#L67C13-L67C23

https://github.com/Cyfrin/2023-07-escrow/blob/main/src/Escrow.sol#L67C38-L67C48

[G‑02] Use simple events without argument

With Web3 or ether.js libraries it is possible to get some information about the message sender's address or when it is called and emitted.

There is 1 instance of this issue:

emit Disputed(msg.sender);

https://github.com/Cyfrin/2023-07-escrow/blob/main/src/IEscrow.sol#L21

https://github.com/Cyfrin/2023-07-escrow/blob/main/src/Escrow.sol#L105

[G‑03] Wrap most repeated code inside a private or internal function

Wrapping most used codes will result in a bytecode reduction.

There are 4 instances of this issue:

https://github.com/Cyfrin/2023-07-escrow/blob/main/src/Escrow.sol#L44C13-L44C51

https://github.com/Cyfrin/2023-07-escrow/blob/main/src/Escrow.sol#L98C48-L98C88

https://github.com/Cyfrin/2023-07-escrow/blob/main/src/Escrow.sol#L110C32-L110C71

https://github.com/Cyfrin/2023-07-escrow/blob/main/src/Escrow.sol#L125C24-L125C64

Support

FAQs

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