Vyper Vested Claims

First Flight #34
Beginner FriendlyDeFi
100 EXP
View results
Submission Details
Severity: low
Invalid

_calculate_vested_amount () function doesn't check vesting end time is greater than start time.

Summary

The function _calculate_vested_amount () doesn't check vesting end time is greater than start time.

Vulnerability Details

See comments below (offending line)

vesting_duration: uint256 = end_time - start_time // <<== Offending line
// full function
def _calculate_vested_amount(total_amount: uint256) -> uint256:
"""
@notice This function is used to calculate the vested amount
@param total_amount: uint256, the total amount of tokens
@return vested: uint256, the vested amount
"""
current_time: uint256 = block.timestamp
start_time: uint256 = self.vesting_start_time
end_time: uint256 = self.vesting_end_time
vested: uint256 = 0
if current_time >= end_time:
return total_amount
vesting_duration: uint256 = end_time - start_time // <<= here
elapsed: uint256 = current_time - start_time
instant_release: uint256 = (total_amount * 31) // 100
linear_vesting: uint256 = (total_amount * 69) // 100
vested = instant_release + (linear_vesting * elapsed) // vesting_duration
return vested
// end

Impact

If the contract is deployed with a vesting_end_time that is equal to or less than vesting_start_time, this subtraction would underflow or yield zero. In the case where (vesting_duration equals zero), the subsequent division in the linear vesting calculation would revert (or behave unpredictably).

Since the vested amount that is returned is wrong, all calculations that rely on it will be wrong in the above scenario (eg transfer func).

Tools Used

Manual review.

Recommendations.

Put a check in the constructor to ensure that vesting_end_time > vesting_start_time.

Updates

Appeal created

bube Lead Judge 4 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity
Assigned finding tags:

[Invalid] Underflow in `_calculate_vested_amount`

The `_calculate_vested_amount` function is called in ` claim` and `claimable_amount` functions. There is a check that ensures the `block.timestamp` is greater or equal to the `vesting_start_time` in the both functions. Also, the admin sets the start and end time of the vesting. This means it will be always correct. Therefore, there is no risk from underflow or division by zero in `_calculate_vested_amount` function.

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.