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

Ineffective Reentrancy Guard in `InheritanceManager`

Summary

The nonReentrant modifier uses incorrect transient storage slots, disabling reentrancy protection.

Finding Description

The modifier checks tload(1) but stores in slot 0, creating an unlocked state. this is the format from the transint-storage blog post referenced in the documentation

contract Generosity {
mapping(address => bool) sentGifts;
modifier nonreentrant {
assembly {
if tload(0) { revert(0, 0) }
tstore(0, 1)
}
_;
// Unlocks the guard, making the pattern composable.
// After the function exits, it can be called again, even in the same transaction.
assembly {
tstore(0, 0)
}
}
...
}

but the contract makes use of this

/**
* @dev gas efficient cross-function reentrancy lock using transient storage
* @notice refer here: https://soliditylang.org/blog/2024/01/26/transient-storage/
*/
modifier nonReentrant() {
assembly {
@> if tload(1) { revert(0, 0) }
tstore(0, 1)
}
_;
assembly {
tstore(0, 0)
}
}

Malicious contracts can re-enter sendETH/sendERC20 before completion. This breaks the core security invariant of "secure distribution".

Impact Explanation

The impact of this vulnerability is high because it allows attackers to exploit reentrancy to drain funds from the contract. Functions like sendETH and sendERC20 are critical for transferring assets, and if they can be reentered, the contract's funds are at risk.

Likelihood Explanation

The likelihood of this vulnerability being exploited is high because it affects multiple critical functions. Any malicious contract that interacts with these functions could potentially exploit the reentrancy guard's ineffectiveness.

Recommendation

To fix this issue, the nonReentrant modifier should use consistent transient storage slots for both checking and setting the flag. Here is the corrected modifier:

// Fix modifier storage slots
modifier nonReentrant() {
assembly {
if tload(0) { revert(0, 0) }
tstore(0, 1)
}
_;
assembly {
tstore(0, 0)
}
}
Updates

Lead Judging Commences

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

Wrong value in nonReentrant modifier

0xtimefliez Lead Judge 9 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.

Give us feedback!