Skip to content
Audit finding Intermediate

Due to loss of precision, targetVotes may not reach

The pledge function checks that the receiver's adjusted balance plus the pledged amount does not exceed targetVotes, but the actual votes received are less than the amount due to integer division precision loss. This means the receiver's balance may not reach targetVotes even though the check passes.

cccz Follow

Originally disclosed on Code4rena

Submitted by cccz

In the \_pledge function, require delegationBoost.adjustedbalanceof(pledgeParams.receiver) + amount <= pledgeParams.targetVotes.

In reality, when the user pledges the amount of votes, the actual votes received by the receiver are the bias in the following calculation. And the bias will be less than amount due to the loss of precision.

        uint256 slope = amount / boostDuration;
        uint256 bias = slope * boostDuration;

This means that the balance of receiver may not reach targetVotes

    point = self._checkpoint_read(_user, False)
    amount += (point.bias - point.slope * (block.timestamp - point.ts))
    return amount

Proof of Concept

https://github.com/code-423n4/2022-10-paladin/blob/d6d0c0e57ad80f15e9691086c9c7270d4ccfe0e6/contracts/WardenPledge.sol#L245-L246

https://github.com/curvefi/curve-veBoost/blob/master/contracts/BoostV2.vy#L192-L209

https://github.com/curvefi/curve-veBoost/blob/master/contracts/BoostV2.vy#L175

Recommended Mitigation Steps

Use bias instead of amount in the check below:

        uint256 slope = amount / boostDuration;
        uint256 bias = slope * boostDuration;
        if(delegationBoost.adjusted_balance_of(pledgeParams.receiver) + bias > pledgeParams.targetVotes) revert Errors.TargetVotesOverflow();
        delegationBoost.boost(
            pledgeParams.receiver,
            amount,
            endTimestamp,
            user
        );

Kogaroshi (Paladin) acknowledged and commented:

The current check is made that way to prevent any unnecessary call to the BoostV2 contract (and save gas by not creating the Boost) in the case of a targetVotes overflow.


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

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 check uses the pledged amount instead of the actual bias (votes received after integer division rounding) when comparing against targetVotes.

Impact

The receiver's balance may not reach the targetVotes, potentially causing the pledge to fail its intended goal.

What the attacker needed

None

The fix

The check should use the bias (actual votes received) instead of the amount when comparing against targetVotes.

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.

When you pledge votes, the system calculates how many votes you actually get by dividing the amount by a duration and then multiplying back. Because computers round down whole numbers, this can give you slightly fewer votes than you pledged. The code checks your pledge against a target using the full amount, not the slightly smaller actual votes, so the target might not be met.

More by cccz

View all

104 more disclosed reports, best first.

More from Paladin - Warden Pledges contest

View all

The newest disclosed reports for this program.

Similar reports

Same bug class and techniques, clearest first.