Zealynx AcademyZealynx Academy
ZLX-Check

Spot the Bug: the cliff that never held

Question 1 of 3Score 0/3

A vesting contract computes vested as (block.timestamp - start) * total / duration and returns it. The math is correct. What is still wrong?

Review and apply

Worked answers

Try the quiz above first, then open an answer to compare your reasoning. These notes are also available to read without completing an attempt.

  1. 1. A vesting contract computes vested as (block.timestamp - start) * total / duration and returns it. The math is correct. What is still wrong?

    • A.Nothing, elapsed over duration is the right formula
    • B.It never gates on the cliff, so it pays a linear share from the very first second
    • C.The function should be payable
    • D.Integer division makes it revert
    Answer and explanation

    B. It never gates on the cliff, so it pays a linear share from the very first second

    The formula is fine, but it starts accruing at start, not at the cliff. Before the cliff the correct answer is exactly zero. With no cliff check the contract releases tokens from day one, before anyone was supposed to claim.

  2. 2. Why does a missing cliff gate leak tokens even when the vesting arithmetic is correct?

    • A.Because integer division rounds up
    • B.Because linear accrual begins at start, so any timestamp after start already returns a nonzero vested amount
    • C.Because block.timestamp can be set to the future by miners
    • D.Because total is stored as a signed integer
    Answer and explanation

    B. Because linear accrual begins at start, so any timestamp after start already returns a nonzero vested amount

    A cliff means nothing vests until a later moment. Linear-from-start accrual returns value the instant time passes start, so the whole interval between start and cliff pays out when it must pay zero. The cliff is a separate gate, not something the linear term encodes.

  3. 3. What is the correct fix?

    • A.Return zero when block.timestamp is less than the cliff, then run the linear formula
    • B.Subtract the cliff duration from total
    • C.Use block.number instead of block.timestamp
    • D.Only let the owner call the function
    Answer and explanation

    A. Return zero when block.timestamp is less than the cliff, then run the linear formula

    Gate the entire calculation on the cliff timestamp: if block.timestamp is before the cliff, return zero, otherwise compute the vested amount. Then test the exact boundary, one second before the cliff, at the cliff, and one second after, so the comparison operator matches the documented intent.

Read alongside: See it in real audits