Fix: deposit everything to AffiliateToken #261
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
First bug:
See:
1.https://github.com/yearn/brownie-wrapper-mix/blob/master/contracts/AffiliateToken.sol#L101
Here share is calculated before the deposit.
If we consider the situation in which MAX UINT256 passed as input
https://github.com/yearn/brownie-wrapper-mix/blob/master/contracts/AffiliateToken.sol#L98
When we pass the MAX_UINT value, the vulnerability appears in this code.
See:
1.https://github.com/yearn/brownie-wrapper-mix/blob/master/contracts/AffiliateToken.sol#L101
Here share is calculated before the deposit.
If we consider the situation in which MAX UINT256 passed as input
https://github.com/yearn/brownie-wrapper-mix/blob/master/contracts/AffiliateToken.sol#L98
When we pass the MAX_UINT value, the vulnerability appears in this code.
Since share will be calculated from the MAX_UINT amount
https://github.com/yearn/brownie-wrapper-mix/blob/master/contracts/AffiliateToken.sol#L91, not the actual amount that was sent to the deposit.
Which ultimately leads to the fact that https://github.com/yearn/brownie-wrapper-mix/blob/master/contracts/AffiliateToken.sol#L104
the wrong number of tokens will be issued.
Another bug:
See:
Here, pass MAX_UINT to trigger DEPOSIT_EVERTING, in the _deposit function
https://github.com/yearn/brownie-wrapper-mix/blob/master/contracts/AffiliateToken.sol#L98
Next, try to call safeTransferFrom
https://github.com/yearn/yearn-vaults/blob/master/contracts/BaseWrapper.sol#L113
But at the same time we are trying to write off MAX_UINT, of course, which are not on the user's balance.
As a result, it gets that the transaction will fail.