Open code423n4 opened 2 years ago
Duplicate of #35
Lack of clear path to exploit it, but it dose seems like _distributeToPayoutSplitsOf
can be used to reenter distributePayoutsOf
; it requires the attacker to be one of the project's splits beneficiaries, though.
_transferFrom(
address(this),
_split.beneficiary != address(0) ? _split.beneficiary : payable(msg.sender),
_netPayoutAmount
);
Lines of code
https://github.com/jbx-protocol/juice-contracts-v2-code4rena/blob/828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/abstract/JBPayoutRedemptionPaymentTerminal.sol#L415-L448 https://github.com/jbx-protocol/juice-contracts-v2-code4rena/blob/828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/abstract/JBPayoutRedemptionPaymentTerminal.sol#L788-L900 https://github.com/jbx-protocol/juice-contracts-v2-code4rena/blob/828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/abstract/JBPayoutRedemptionPaymentTerminal.sol#L981-L1174 https://github.com/jbx-protocol/juice-contracts-v2-code4rena/blob/828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBETHPaymentTerminal.sol#L63-L79 https://github.com/jbx-protocol/juice-contracts-v2-code4rena/blob/828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBERC20PaymentTerminal.sol#L73-L89
Vulnerability details
Impact
In the contract
JBPayoutRedemptionPaymentTerminal
, the functiondistributePayoutsOf
calls the internal function_distributePayoutsOf
and this internal function perfoms a loop where is using the function_distributeToPayoutSplitsOf
In these functions there are a_transferFrom
what:JBETHPaymentTerminal
using aAddress.sendValue(_to, _amount)
JBERC20PaymentTerminal
using aIERC20(token).transfer(_to, _amount)
with aERC777
as tokenBoth give back the control to the
msg.sender
(_to
variable) creating a reentrancy attack vectorAlso could end with a lot of bad calculation because is using uncheckeds statements and function
_distributePayoutsOf
its no respecting thechecks, effects, interactions
patternProof of Concept
Craft a contract to call function
distributePayoutsOf
, on receive ether reentrant to functiondistributePayoutsOf
or use aERC777
callback.Tools Used
Manual Review
Recommended Mitigation Steps
Add a reentrancyGuard as you do on
JBSingleTokenPaymentTerminalStore.sol
; You have already import the ReentrancyGuard on JBPayoutRedemptionPaymentTerminal.sol#L5 but you are not using it.My recommendation is to add
nonReentrant
modifier on functiondistributePayoutsOf