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

test: fix bound related bug in fork tests #278

Merged
merged 1 commit into from
Feb 2, 2024
Merged

Conversation

smol-ninja
Copy link
Member

Resolves #277.

Bug fixed by this PR

The following lines bound vars.amounts[i] to [1, BIGNUM] but not params.leafData[i].amount.

// Bound each leaf amount so that `aggregateAmount` does not overflow.
vars.amounts[i] = uint128(_bound(params.leafData[i].amount, 1, MAX_UINT256 / vars.recipientsCount - 1));
vars.aggregateAmount += params.leafData[i].amount;

That means if params.leafData[i].amount is 0, vars.aggregateAmount would be 0 but vars.amounts[i] would be non-zero.

This would lead to the token dealing with 0 amount but .claim() would be called with non-zero value of vars.amounts causing ERC20: transfer amount exceeds balance since there would be 0 balance in merkleStreamerLL contract.

deal({ token: address(asset), to: address(vars.merkleStreamerLL), give: vars.aggregateAmount });

vars.actualStreamId = vars.merkleStreamerLL.claim({
index: vars.indexes[params.posBeforeSort],
recipient: vars.recipients[params.posBeforeSort],
amount: vars.amounts[params.posBeforeSort],
merkleProof: getProof(leaves.toBytes32(), vars.leafPos)
});

@smol-ninja smol-ninja requested a review from PaulRBerg February 2, 2024 15:27
@smol-ninja smol-ninja changed the title test: fix bug in bound usage during fork tests test: fix bound related bug in fork tests Feb 2, 2024
@PaulRBerg
Copy link
Member

Fantastic sleuthing, @smol-ninja.

Copy link
Member

@PaulRBerg PaulRBerg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@smol-ninja smol-ninja merged commit 8f4c3de into main Feb 2, 2024
7 checks passed
@smol-ninja smol-ninja deleted the fix/fork-tests-bug branch February 2, 2024 17:02
@PaulRBerg
Copy link
Member

@smol-ninja it looks like we haven't rebased from main? I cannot see this fix on staging:

// Bound each leaf amount so that `aggregateAmount` does not overflow.
vars.amounts[i] = uint128(_bound(params.leafData[i].amount, 1, MAX_UINT256 / vars.recipientsCount - 1));
vars.aggregateAmount += vars.amounts[i];

@PaulRBerg
Copy link
Member

Nevermind, I think you've fixed it on staging by adding vars.amounts[i] instead of params.leafData[i].amount. This means that bounding the leaf data is no longer necessary.

@smol-ninja
Copy link
Member Author

Yes @PaulRBerg.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"ERC20: transfer amount exceeds balance" in fork tests
2 participants