The distributePayoutsOf function transfers funds to beneficiaries before updating state, allowing a beneficiary to re-enter and potentially cause incorrect calculations or repeated payouts. The judge noted a lack of a clear exploit path but confirmed that re-entry is possible if the attacker is a splits beneficiary.
Both give back the control to the msg.sender (_to variable) creating a reentrancy attack vector.
Also could end with a lot of bad calculation because is using uncheckeds statements and function _distributePayoutsOf its no respecting the checks, effects, interactions pattern.
Proof of Concept
Craft a contract to call function distributePayoutsOf, on receive ether reentrant to function distributePayoutsOf or use a ERC777 callback.
Recommended Mitigation Steps
Add a reentrancyGuard as you do on JBSingleTokenPaymentTerminalStore.sol; You have already imported the ReentrancyGuard on JBPayoutRedemptionPaymentTerminal.sol#L5 but you are not using it.
My recommendation is to add nonReentrant modifier on function distributePayoutsOf.
Lack of clear path to exploit it, but it does seem like _distributeToPayoutSplitsOf can be used to reenter distributePayoutsOf; it requires the attacker to be one of the project’s splits beneficiaries, though.
The original report as published on Code4rena, by 0x29A. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
Generating the AI write-up for this report.
This usually takes about a minute. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
How it worked
Root cause
The contract performs external transfers before updating state and lacks a reentrancy guard, violating the checks-effects-interactions pattern.
What the attacker needed
Attacker is a splits beneficiary
The fix
Add a nonReentrant modifier to distributePayoutsOf.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
Generating the AI write-up for this report.
This usually takes about a minute. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
When a contract sends Ether or tokens to an external address, that address can run code that calls back into the contract before the first call finishes. This is called reentrancy. Here, the payout function sends funds before updating its records, so a malicious beneficiary could call the function again and potentially receive more than intended.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.