๐Vulnerability in Bond Depositor's Vesting Period Reset
Bond contracts are commonly used in decentralized finance (DeFi) to allow users to deposit tokens in exchange for future rewards over a predefined vesting period. However, a critical vulnerability can arise when the vesting period is reset unintentionally every time a user makes a new deposit. This issue can result in users being forced to wait longer than originally intended to claim their vested rewards.
In this tutorial, we will explore how this vulnerability works, how it allows users' vesting periods to be reset unnecessarily, and how to mitigate the issue by ensuring vesting periods are handled correctly.
Vulnerability: Resetting of Bond Depositor's Vesting Period
The vulnerability arises when the vesting period for bond depositors is reset each time they make a new deposit. If a user has already partially vested and deposits more tokens, the vesting period resets, causing the user to wait for the full vesting duration again, even though they should have been able to claim a portion of their tokens before the reset.
How the Vulnerability Occurs
In a vulnerable bond contract, when a user makes a deposit, the deposit()
function overwrites the userโs bond information, including the vesting term, without checking if the user has already vested any tokens. This means that any unclaimed tokens will be subject to the new vesting schedule, effectively resetting the user's vesting period each time a new deposit is made.
Conclusion
Resetting the vesting period on each deposit can result in significant frustration for users, as it forces them to wait longer than necessary to claim their tokens. By ensuring that vesting periods are handled correctly, either by preventing resets, forcing claims before new deposits, or tracking separate vesting schedules for each deposit, you can maintain the integrity of the bond contract and provide a better user experience.
Following these best practices will ensure that the bond contract operates fairly and securely, avoiding unintended vesting resets and ensuring that users can claim their vested tokens according to the intended schedule.
Last updated