๐Ÿ‘ŠVulnerability of Unbounded Timelock Loops in Vesting Contracts

Vesting contracts are designed to distribute tokens over time with strict conditions, such as a timelock, ensuring that beneficiaries receive their tokens only after a specific period. However, poorly designed vesting contracts can become vulnerable to attacks that exploit unbounded loops and high gas costs, effectively preventing beneficiaries from claiming their tokens. In this tutorial, weโ€™ll explore how a malicious actor can manipulate a vesting contract by creating a large, unbounded timelock loop, making it impossible for legitimate beneficiaries to claim their tokens.

We will also discuss how to properly mitigate this vulnerability to ensure secure token distribution through vesting contracts.


Vulnerability: Unbounded Timelock Loop in Vesting Contracts

The primary vulnerability occurs when the vesting contractโ€™s timelock arrayโ€”which tracks when beneficiaries are allowed to claim tokensโ€”can grow indefinitely due to unrestricted access or overly frequent updates. This becomes problematic when the contract relies on looping through the timelock array to calculate claimable tokens, leading to high gas usage and eventually causing the transaction to fail when the gas limit is exceeded.

How the Vulnerability Happens

  1. Unrestricted vest() Function: In a vulnerable contract, anyone (not just the beneficiary) can trigger the vesting process by calling the vest() function. This function pushes a new timelock entry into the timelocks[_beneficiary] array every time it is called.

  2. Exploiting the timelocks[_beneficiary] Array: A malicious actor can repeatedly call the vest() function with small vesting amounts, creating a large number of timelock entries for a beneficiary.

  3. Gas Limit Issue in claim(): When the beneficiary later attempts to claim their tokens, the contract must loop through the timelocks[_beneficiary] array to calculate the total amount that has vested. If the array has grown too large, the transaction will exceed the gas limit, causing the claim to fail and rendering the beneficiaryโ€™s tokens unclaimable.

Impact

  • Denial of Service (DoS) Attack: A malicious actor can effectively prevent all beneficiaries from claiming their vested tokens by flooding the timelock array with small vestments, leading to gas limit exhaustion.

  • Unclaimable Tokens: Once the array becomes too large, beneficiaries will no longer be able to claim their vested tokens, as the claim() function will always run out of gas and revert.

Last updated