40,000 USDC
View results
Submission Details
Severity: gas
Valid

balanceOf(address(this)) can be replaced with a constant

The contract reads the balance multiple times:

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

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

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

We can set a constant in the ctor to reduce storage reads.

And this storage access

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

can be replaced by tokenBalance - buyerAward - i_arbiterFee

Support

FAQs

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