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

Bake ReentrancyGuard into Escrow

Summary

ReentrancyGuard.sol is a very simple abstract contract. Its functionality can be baked into Escrow.sol, and its gas can be optimized as well.

Impact

Over 800 gas can be saved between deployments.

Tools Used

  • Foundry

Recommendations

Remove Escrow's inheritance of ReentrancyGuard and add the following:

contract Escrow is IEscrow {
// ...rest of the smart contract
/////////////////////
// Bake Reentrancy
/////////////////////
uint256 private _status;
modifier nonReentrant() {
_nonReentrantBefore();
_;
_nonReentrantAfter();
}
error Escrow__ReentrantCall();
function _nonReentrantBefore() private {
if(_status == 1) revert Escrow__ReentrantCall();
_status = 0;
}
function _nonReentrantAfter() private {
_status = 0;
}
}

The Escrow__ReentrantCall error can be moved into IEscrow.sol for continuity.

Support

FAQs

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