40,000 USDC
View results
Submission Details
Severity: gas

Use `i_price` instead of querying balance in the function `resolveDispute()`

The contract variable i_price can be used to determine how much should be sent to each party instead of querying the balance of the contract. This change will save approximately 30000 gas units on deployment of the Escrow contracts and 1000 gas units per invocation of the resolveDispute() function.

File: Escrow.sol
function resolveDispute(uint256 buyerAward) external onlyArbiter nonReentrant inState(State.Disputed) {
uint256 totalFee = buyerAward + i_arbiterFee;
if (totalFee > i_price) {
revert Escrow__TotalFeeExceedsBalance(i_price, totalFee);
}
s_state = State.Resolved;
emit Resolved(i_buyer, i_seller);
if (buyerAward > 0) {
i_tokenContract.safeTransfer(i_buyer, buyerAward);
}
if (i_arbiterFee > 0) {
i_tokenContract.safeTransfer(i_arbiter, i_arbiterFee);
}
uint256 remainingBalance = i_price - totalFee;
if (remainingBalance > 0) {
i_tokenContract.safeTransfer(i_seller, remainingBalance);
}
}

Tools:

Foundry

Support

FAQs

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