Skip to content

Conversation

@nicholaspai
Copy link
Member

@nicholaspai nicholaspai commented Oct 27, 2022

I discovered this by while working on this PR for the exact test case I've included. The problem arises when all of the claims for different window indices are for the same token and recipient. If this if statement here is not triggered, then batchedAmount accumulates the amount for each claim. It only gets decremented from a window's remainingAmount once the if statement is entered, which is either:

  • On the last claim
  • When the reward token changes between claims
  • When the account changes between claims

If the reward token and account do not change, then its possible that batchedAmount > window.remainingAmount.

We should be decrementing remainingAmount for each claim that executes, this seems intuitive.

The reason why I think we've never run into this is because we've never tried claiming in production across multiple windows. I don't think we've even used multiple windows in the past

* @param windowIndex merkle root to check.
* @return address Reward token address
*/
function getRewardTokenForWindow(uint256 windowIndex) public view returns (address) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Contributor

@mrice32 mrice32 left a comment

Choose a reason for hiding this comment

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

LGTM! This is a very nice find! Great simple test, too.

@nicholaspai nicholaspai merged commit 2aaf986 into master Oct 28, 2022
@nicholaspai nicholaspai deleted the npai/fixmerkle branch October 28, 2022 20:04
nicholaspai added a commit to UMAprotocol/protocol that referenced this pull request Oct 29, 2022
…unt for merkle windows correctly

PR takes files changed [here](across-protocol/contracts#193) and copies them unmodified to this repo
nicholaspai added a commit to UMAprotocol/protocol that referenced this pull request Nov 1, 2022
…unt for merkle windows correctly (#4209)

* fix: Fix bug in MerkleDistributor that doesn't decrement remainingAmount for merkle windows correctly

PR takes files changed [here](across-protocol/contracts#193) and copies them unmodified to this repo

* update claim and claimMulti to be virtual

* Bump package version in prep for release

* Fix

* Update packages/core/contracts/merkle-distributor/implementation/MerkleDistributorInterface.sol

Co-authored-by: Chris Maree <christopher.maree@gmail.com>

* Update MerkleDistributor.sol

* Update MerkleDistributor.js

* lint

* Update MerkleDistributor.js

* Update MerkleDistributor.js

Co-authored-by: Chris Maree <christopher.maree@gmail.com>
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.

3 participants