Cyfrin / 2023-07-escrow

16 stars 12 forks source link

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

Open codehawks-bot opened 1 year ago

codehawks-bot commented 1 year ago

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

Severity

Gas Optimization / Informational

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