-
Notifications
You must be signed in to change notification settings - Fork 7
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
The duration of liquidity provisioning should be taken into account when distributing rewards #71
Comments
141345 marked the issue as primary issue |
Valid finding, not sure if this will be a problem in practice as the lending markets will enforce / incentivize long lending periods (with various mechanisms that is up to them, e.g. dynamic interest rates, fees, bonuses, etc...) because these will be lending markets for real world assets (mortgages, bonds, etc...) which usually have a fixed duration and where people cannot just withdraw arbitrarily. |
OpenCoreCH marked the issue as sponsor confirmed |
alcueca changed the severity to 2 (Med Risk) |
alcueca changed the severity to 3 (High Risk) |
alcueca changed the severity to 2 (Med Risk) |
alcueca changed the severity to 3 (High Risk) |
alcueca marked the issue as selected for report |
alcueca marked issue #416 as primary and marked this issue as a duplicate of 416 |
alcueca marked the issue as satisfactory |
Lines of code
https://github.com/code-423n4/2023-08-verwa/blob/a693b4db05b9e202816346a6f9cada94f28a2698/src/LendingLedger.sol#L70-L73
https://github.com/code-423n4/2023-08-verwa/blob/a693b4db05b9e202816346a6f9cada94f28a2698/src/LendingLedger.sol#L91-L94
https://github.com/code-423n4/2023-08-verwa/blob/a693b4db05b9e202816346a6f9cada94f28a2698/src/LendingLedger.sol#L133-L142
Vulnerability details
Impact
The duration of liquidity provisioning is very important, and should be taken into account when distributing rewards. Otherwise, rewards can be susceptible to theft by malicious individuals.
LendingLedger only records total balance of each market, and balances of each user in this market. Those values are updated on every deposit / withdrawal by a user. An individual's earnings depend on the proportion of liquidity tokens they provide compared to the total market liquidity tokens.
If an individual provides liquidity at the beginning of an epoch but later withdraws it, their eventual provided liquidity becomes 0, resulting in no earnings. Conversely, if someone offers liquidity shortly before the end of an epoch and promptly withdraws it at the start of the next epoch, they will receive earnings.
Therefore, the measurement for calculating the eventual earnings should be based on the amount of tokens deposited by an individual multiplied by the duration of their deposit.
Proof of Concept
In the following example, let's assume that user1 deposited 100 tokens at the beginning of an epoch and withdrew all 100 tokens before the epoch ended. User2 deposited 100 tokens before the epoch ended and immediately withdrew 100 tokens at the start of the next epoch. The governance protocol distributed 100 CANTO tokens as staking rewards.
The code execution result shows that user2 received the full 100 CANTO reward tokens, while user1 did not receive any rewards. This outcome aligns with the explanation provided earlier. User2 received rewards because they maintained their liquidity provision until the epoch ended, even though they withdrew their tokens at the beginning of the next epoch. User1, on the other hand, withdrew their tokens before the epoch ended, resulting in a provided liquidity of 0 and no rewards being earned. This illustrates the significance of the liquidity provision duration in determining the distribution of rewards.
Tools Used
Hardhat
Recommended Mitigation Steps
LendingLedger needs to calculate users' balances and the total balance in the market based on the tokens deposited and withdrawn by users, along with the corresponding time. The formulas for calculating user balance and total balance are as follows:
After calculating user balances and total balances, the tokens are distributed as rewards based on the proportion of each user's balance to the total balance. This allocation ensures that users are rewarded according to their contribution to the overall liquidity.
The complete patch is as follows (due to time constraints, this patch might not be perfect).
Running the PoC program again, the result is as follows.
Assessed type
Context
The text was updated successfully, but these errors were encountered: