Beginner FriendlySolidity
100 EXP
View results
Submission Details
Severity: high
Valid

Critical Vulnerability in Reentrancy Guard

Summary

The nonReentrant modifier, designed to prevent reentrancy attacks, contains a critical flaw due to inconsistent use of transient storage slots. The modifier checks tload(1) but sets tstore(0, 1), resulting in an ineffective lock.

Vulnerable Code :

modifier nonReentrant() {
assembly {
if tload(1) { revert(0, 0) } // Checks slot 1
tstore(0, 1) // Locks slot 0 (mismatch)
}
_;
assembly {
tstore(0, 0) // Resets slot 0
}
}

Exploitation Scenario :
An attacker can bypass the reentrancy check by reentering the contract during a call to a vulnerable function (e.g., sendETH, sendERC20, or contractInteractions). Since the lock is set in slot 0 but checked in slot 1, the modifier fails to detect reentrant calls, allowing:

  • Fund Drain : Repeated withdrawals of ETH or ERC20 tokens.

  • Malicious Contract Calls : Exploiting contractInteractions to manipulate external protocols.


Impact

  • Critical Fund Loss : Reentrancy attacks can drain all contract-held assets.

  • Broken Security Guarantees : Functions marked as nonReentrant are not protected, undermining trust in the contract.

Recommendation

Fix Transient Storage Mismatch :
Use consistent transient storage slots for both the check and lock:

modifier nonReentrant() {
assembly {
if tload(0) { revert(0, 0) } // Check slot 0
tstore(0, 1) // Lock slot 0
}
_;
assembly {
tstore(0, 0) // Unlock slot 0
}
}

OR Adopt OpenZeppelin’s ReentrancyGuard :
Replace the custom implementation with a battle-tested library:

import "@openzeppelin/contracts/security/ReentrancyGuard.sol";

This ensures compatibility with Solidity’s transient storage and mitigates edge cases.

Affected Functions

The following functions are vulnerable to reentrancy due to the flawed modifier:

  • sendETH

  • sendERC20

  • contractInteractions


Conclusion :
The broken reentrancy guard poses an existential risk to the contract. Immediate patching is required to prevent catastrophic fund loss. Always prioritize well-audited security libraries over custom implementations for critical safeguards.

Updates

Lead Judging Commences

0xtimefliez Lead Judge 6 months ago
Submission Judgement Published
Validated
Assigned finding tags:

Wrong value in nonReentrant modifier

0xtimefliez Lead Judge 6 months ago
Submission Judgement Published
Validated
Assigned finding tags:

Wrong value in nonReentrant modifier

Support

FAQs

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