-
Notifications
You must be signed in to change notification settings - Fork 0
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
ERC777 token reentrancy allows to steal fees #519
Comments
Picodes marked the issue as primary issue |
dyedm1 (sponsor) confirmed |
Picodes marked the issue as satisfactory |
Picodes marked issue #196 as primary and marked this issue as a duplicate of 196 |
Picodes marked the issue as selected for report |
Hi @Picodes I think this issue deserves to be a medium because:
Kind regards. |
Picodes marked issue #448 as primary and marked this issue as a duplicate of 448 |
@osmanozdemir1 following the Supreme Court verdict, loss of fees should be treated "similar to any other loss of capital". Here to me "assets can be stolen/lost/compromised directly" as the protocol is explicitly made to support ERC777 tokens so this can't be considered an "external requirement". So in my opinion following C4's rules High severity is justified here. |
Lines of code
https://github.com/code-423n4/2023-11-panoptic/blob/main/contracts/SemiFungiblePositionManager.sol#L1031-L1066
Vulnerability details
Impact
An attacker can steal fees in case of ERC-777 tokens
Proof of Concept
When minting a position,
s_accountFeesBase
is updated only after the token transfer to Uniswap.https://github.com/code-423n4/2023-11-panoptic/blob/main/contracts/SemiFungiblePositionManager.sol#L1031-L1066
In case of an ERC-777 token a user can reenter
SemiFungiblePositionManager
and transfer the position/token to another one of his controlled address.This will cause the transferred address to have the updated liquidity but the old
feesBase
and the remaining calculation in the original address to have a reducedfeeBase
. This can be used to earn higher fees than what should actually be distributed to the userhttps://github.com/code-423n4/2023-11-panoptic/blob/main/contracts/SemiFungiblePositionManager.sol#L626-L630
https://github.com/code-423n4/2023-11-panoptic/blob/main/contracts/SemiFungiblePositionManager.sol#L1209
Example Scenario
feesBase is shown as single token variable for ease
SemiFungiblePositionManager
and transfers the entire token amount to another address.SemiFungiblePositionManager
by using the above stepsAnother attack possible is to transfer a position where the liquidity is low ( instead of adding in the above steps the attacker withdraws majority of the liquidity keeping a negligible amount left) and the feeBase is high. This will cause the fees calculation in the transferred address to revert hence disabling any mint on that position
POC Code
Set fork_block_number = 18706858
Run :
forge test --mt testHash_FeesBaseReentry
Tools Used
Manual review
Recommended Mitigation Steps
Add non-reentrant modifier on the transfer functions of
SemiFungiblePositionManager
or change the flow to update thes_accountFeesBase
before Uniswap interaction and use the initial feeBase itself for the fees computation. By burning 0 amount before making the mint/burn liquidity call, the newfeeGrowthInside
can be obtained to update thes_accountFeesBase
Assessed type
Reentrancy
The text was updated successfully, but these errors were encountered: