Skip to content
Audit finding Intermediate

Checkpoints wont update block number in point b

The checkpoint calculation in VotingEscrow uses a multiplier too small to produce a non-zero block slope, so the stored block number in each checkpoint never advances. Any off-chain computation that relies on the checkpoint block number would use a stale value.

copperscrewer Follow

Originally disclosed on Immunefi

  • Disclosed after under an hour

31566 - [SC - Medium] Checkpoints wont update block number in point b...

Submitted on May 21st 2024 at 12:27:19 UTC by @copperscrewer for Boost | Alchemix

Report ID: #31566

Report type: Smart Contract

Report severity: Medium

Target: https://github.com/alchemix-finance/alchemix-v2-dao/blob/main/src/VotingEscrow.sol

Impacts:

  • Contract fails to deliver promised returns, but doesn't lose value

Description

Brief/Intro

Voting Escrow Checkpoints won't update block number in point because of a Rounding issue, currently the block time in Ethereum is around ~ 12 seconds, There is an attempt to calculate block slope by the difference of the block number multiplied by a MULTIPLIER and then divided by the difference in block.timestamp.

There is an issue because of the precision of the division.

Vulnerability Details

In _checkpoint of VotingEscrow there is a line

blockSlope = (MULTIPLIER * (block.number - lastPoint.blk)) / (block.timestamp - lastPoint.ts);

Here blockSlope will always be zero as for each block.number the difference in block.timestamp is around ~ 12 seconds. The MULTIPLIER : 2 is too low to cover that and as a result it becomes zero as the numerator is lesser than the denominator

lastPoint.blk = initialLastPoint.blk + (blockSlope * (_time - initialLastPoint.ts)) / MULTIPLIER; as a result will be stagnant and never be updated.

Impact Details

The Point objects used in _checkpoint never have their block value updated. This will affect any off-calculation/computation that relies on the block number for points to make a transaction

Remediation

Increase MULTIPLIER to a much higher value ~ 10000

Proof of Concept

Run forge test --match-test testRounding --fork-url https://eth-mainnet.alchemyapi.io/v2/[API_KETY] -vvv

after pasting this function in VotingEscrow.t.sol

Solidity
function testRounding() external
    {        

        VotingEscrowTest.Point memory lastPoint;
        (int256 a, int256 b, uint256 c, uint256 d) = veALCX.pointHistory(veALCX.epoch());
        lastPoint = Point(a,b,c,d);

        hevm.warp(block.timestamp + 12);
        hevm.roll(block.number + 1);
        
        console.log("block.timestamp : ", block.timestamp, "\tBlock.number : ", block.number);
        uint256 blockSlope = (MULTIPLIER * (block.number - lastPoint.blk)) / (block.timestamp - lastPoint.ts);
        console.log("blockSlope is ", blockSlope);

        veALCX.checkpoint();
        hevm.warp(block.timestamp + 12);
        hevm.roll(block.number + 1);

        ( a,  b,  c,  d) = veALCX.pointHistory(veALCX.epoch());
        lastPoint = Point(a,b,c,d);

        console.log("block.timestamp : ", block.timestamp, "\tBlock.number : ", block.number);
        blockSlope = (MULTIPLIER * (block.number - lastPoint.blk)) / (block.timestamp - lastPoint.ts);
        console.log("blockSlope is ", blockSlope);

        veALCX.checkpoint();

        hevm.warp(block.timestamp + 12*10);
        hevm.roll(block.number + 1*10);

        ( a,  b,  c,  d) = veALCX.pointHistory(veALCX.epoch());
        lastPoint = Point(a,b,c,d);
        
        console.log("block.timestamp : ", block.timestamp, "\tBlock.number : ", block.number);
        blockSlope = (MULTIPLIER * (block.number - lastPoint.blk)) / (block.timestamp - lastPoint.ts);
        console.log("blockSlope is ", blockSlope);

        veALCX.checkpoint();

    }

The original report as published on Immunefi, by copperscrewer. Images and videos are our own copies; raw HTML is shown as text. View it on Immunefi.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the integer division in the block slope calculation truncates to zero because the multiplier is too small relative to the roughly 12-second block time.

Impact

The checkpoint block number never updates, which could affect any off-chain calculation or computation that relies on it, though the contract itself does not lose value.

What the attacker needed

None

The fix

The multiplier should be increased to a much higher value, around 10000, so the division does not truncate to zero.

How it was found

  1. Read the current checkpoint point history for the current epoch.
  2. Advance the block timestamp by 12 seconds and the block number by 1.
  3. Compute the block slope using the multiplier and the differences in block number and timestamp.
  4. Call checkpoint and observe that the block slope is zero.
  5. Repeat with a larger time and block gap and confirm the slope remains zero.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

A smart contract keeps a record of voting power at different times, called a checkpoint. Each record includes the block number, but a maths mistake makes the block number stay the same forever. Anything that reads that block number later gets an old value instead of the current one.

More by copperscrewer

View all

3 more disclosed reports, best first.

More from Alchemix

View all

The newest disclosed reports for this program.

Similar reports

Same bug class and techniques, clearest first.