40,000 USDC
View results
Submission Details
Severity: gas

one `sload` gas can be reduced in `resolveDispute` of Escrow

Summary

One additional (SLOAD operation = 100 gas) + (staticcall = minimum 100 gas) = Minimum 200 gas can be saved in resolveDispute

Vulnerability Details

In resolveDispute function token balance is fetched twice on line 110 and 125.

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

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

On line 125, it's fetched to get the remaining token balance of the contract and then transfer it to the seller. The same can be achieved via uint tokenToTransfer = tokenBalance - (buyerAward + i_arbiterFee) without invoking staticcall or sload

Impact

Minimum of 200 gas can be saved

Tools Used

Manual Review

Recommendations

Use uint tokenToTransfer = tokenBalance - (buyerAward + i_arbiterFee) to get the remaining balance

Support

FAQs

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