40,000 USDC
View results
Submission Details
Severity: gas

nonReentrant modifier can be replaced by CEI pattern

Description

In resolveDispute the state can be changed to Resolved before doing any other thing. This allows for the nonReentrant modifier to be removed as no function can be reentered when the state is set to Resolved. Given that the likelihood of resolveDispute to revert on call multiple times is low, this change also makes sense at a gas level, given that it removes the nonReentrant modifier cost (small as it is).

function resolveDispute(uint256 buyerAward) external onlyArbiter inState(State.Disputed) {
++ s_state = State.Resolved;
uint256 tokenBalance = i_tokenContract.balanceOf(address(this));
uint256 totalFee = buyerAward + i_arbiterFee; // Reverts on overflow
if (totalFee > tokenBalance) {
revert Escrow__TotalFeeExceedsBalance(tokenBalance, totalFee);
}
-- s_state = State.Resolved;
emit Resolved(i_buyer, i_seller);
// ...rest of the code
}

Support

FAQs

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