Minting an NFT with a position on the same bucket as a previously minted NFT changes its deposit time
When multiple users memorialise positions in the same bucket via the PositionManager, the contract centralises their LP positions under one lender address, causing the depositTime to be overwritten with the maximum of the two. This can make an earlier user incur an early withdrawal fee because their depositTime is reset by a later user's action.
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2023-01-ajna-judging/issues/19
Found by
MalfurionWhitehat
Summary
Minting an NFT with a position on the same bucket as a previously minted NFT changes its deposit time.
Vulnerability Detail
This issue happens because, after a position is memorialized on the PositionManager, this contract will centralize LP positions from different users, but these will be mapped to the same address from the point of view of Ajna pools (different users will be mapped as the same lender from the point of view of a Pool).
If more than one user has memorialized a position to the same bucket index, LenderActions.transferLPs will update the depositTime to the maximum of the previous and new lender's values.
As a result, when a second user memorializes their position as an NFT, the first user's depositTime will be overwritten by the second user's (greater) depositTime.
Impact
The depositTime is used when applying early withdrawal fee and on bankruptcy LP calculation. One of the impacts of this issue is that a user might incur in withdrawal fees because of another user. See the following scenario:
- User1 memorializes position on bucket B
- One day passes, so User1 should not be affected by early withdrawal penalty
- User2 memorializes position on bucket B, and
depositTimefor both users (as they are usingPositionManager) is updated to this new value - User1 withdraws, will incur in early withdrawal penalty
Code Snippet
newLender.depositTime = Maths.max(lenderDepositTime, newLender.depositTime);
Tool used
Manual Review
Recommendation
Reconsider the PositionsManager architecture and the way the LP properties are stored on the Ajna protocol. Since positions are not tokenized by default, but instead are stored on state variables on each pool, it is arguably more complex to reason about transferring positions between two users. Conversely, the ERC-721 standard already provides straightforward methods for minting/burning/sending tokens for accounts. This issue could be fixed by removing the optionality of NFT minting through another independent contract (the PositionManager.sol), as it is centralizing other user's LPs, and instead to refactoring the Ajna pools so that every position is an ERC-721 NFT minted directly by the Pool.sol.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Impact
A user could incur an early withdrawal fee because another user memorialised a position in the same bucket, and the depositTime is also used in bankruptcy LP calculation.
What the attacker needed
Two users memorialise positions in same bucket; use of PositionManager contract
The fix
The report recommends refactoring the Ajna pools so that every position is an ERC-721 NFT minted directly by the Pool.sol, removing the optional PositionManager contract that centralises other users' LPs.
How it was found
- User1 memorialises a position on bucket B.
- One day passes, so User1 should not be affected by early withdrawal penalty.
- User2 memorialises a position on bucket B, and depositTime for both users is updated to this new value.
- User1 withdraws and incurs an early withdrawal penalty.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A deposit time records when you put money into a pool; it is used to decide if you pay a fee for taking it out too soon. Here, a shared contract that holds many users' positions updates that time for everyone in the same bucket, so someone else's later deposit can make your money look newly deposited and trigger a fee.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.