Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOS if user chooses to specify minReturnedTokens in the pay function of the terminal #101

Closed
code423n4 opened this issue May 21, 2023 · 2 comments
Labels
2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value bug Something isn't working duplicate-232 satisfactory satisfies C4 submission criteria; eligible for awards

Comments

@code423n4
Copy link
Contributor

Lines of code

https://github.com/code-423n4/2023-05-juicebox/blob/main/juice-buyback/contracts/JBXBuybackDelegate.sol#L166
https://github.com/jbx-protocol/juice-contracts-v3/blob/main/contracts/JBSingleTokenPaymentTerminalStore3_1.sol#L415
https://github.com/jbx-protocol/juice-contracts-v3/blob/main/contracts/abstract/JBPayoutRedemptionPaymentTerminal3_1.sol#L1493

Vulnerability details

Impact

If user specifies minReturnedTokens in the pay function of the terminal and BuybackDelegate will take the swap path, transaction will be reverted due to the failed condition if (beneficiaryTokenCount < _minReturnedTokens) revert INADEQUATE_TOKEN_COUNT(); in the terminal.

Proof of Concept

In the BuybackDelegate contract if swapping is a preferred method of the acquiring JBX tokens we return with a weight = 0

https://github.com/code-423n4/2023-05-juicebox/blob/main/juice-buyback/contracts/JBXBuybackDelegate.sol#L166

In the payment terminal store we also return early with a tokenCount = 0

https://github.com/jbx-protocol/juice-contracts-v3/blob/main/contracts/JBSingleTokenPaymentTerminalStore3_1.sol#L414C1-L415

And finally in the payment terminal we compare beneficiaryTokenCount < _minReturnedTokens where beneficiaryTokenCount is a variable which is set if tokenCount > 0, in our case tokenCount = 0 therefore beneficiaryTokenCount will also be 0. This will result in failed transaction everytime minReturnedTokens > 0.

Tools Used

Manual review

Recommended Mitigation Steps

Perhaps we can add another condition to the check

if (beneficiaryTokenCount < _minReturnedTokens) && _delegateAllocations.length == 0 revert INADEQUATE_TOKEN_COUNT();

This will revert only if mint path was chosen and we don't use the BuybackDelegate. However there is a possibility that this solution will conflict with data sources other than BuybackDelegate.

Assessed type

DoS

@code423n4 code423n4 added 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value bug Something isn't working labels May 21, 2023
code423n4 added a commit that referenced this issue May 21, 2023
@c4-pre-sort
Copy link

dmvt marked the issue as duplicate of #36

@c4-judge c4-judge added duplicate-232 satisfactory satisfies C4 submission criteria; eligible for awards and removed duplicate-36 labels Jun 2, 2023
@c4-judge
Copy link

c4-judge commented Jun 2, 2023

dmvt marked the issue as satisfactory

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value bug Something isn't working duplicate-232 satisfactory satisfies C4 submission criteria; eligible for awards
Projects
None yet
Development

No branches or pull requests

3 participants