Skip to content
Smart contracts Audit finding Intermediate

Not updating totalWeight when operator is removed in VeTokenMinter

The VeTokenMinter contract fails to reduce totalWeight when an operator is removed, so remaining operators receive a smaller share of rewards and some rewards are never minted. An attacker cannot directly exploit this, but the misconfiguration causes unfair reward distribution.

sseefried Follow

Originally disclosed on Code4rena

Submitted by sseefried, also found by shenwilly

https://github.com/code-423n4/2022-05-vetoken/blob/2d7cd1f6780a9bcc8387dea8fecfbd758462c152/contracts/VeTokenMinter.sol#L36-L38

https://github.com/code-423n4/2022-05-vetoken/blob/2d7cd1f6780a9bcc8387dea8fecfbd758462c152/contracts/VeTokenMinter.sol#L41-L4

https://github.com/code-423n4/2022-05-vetoken/blob/2d7cd1f6780a9bcc8387dea8fecfbd758462c152/contracts/Booster.sol#L598-L614

Impact

The totalWeight state variable of the VeTokenMinter contract is used to work out the amount of veAsset earned when the Booster.rewardClaimed function is called.

However, while totalWeight is modified inside the VeTokenMinter contract when function updateveAssetWeight is called, the totalWeight is not similarly reduced when function removeOperator is called.

The impact is that remaining operators do not receive a fair share of the total rewards and a portion of the rewards are not given out at all.

Proof of Concept

  • Operator 1 is added with weight 9
  • Operator 2 is added with weight 1

The totalWeight is now 10.

This means that Operator 1 receives 90% of the amount while Operator 2 receives 10%.

If we then call removeOperator on Operator 1 then 90% of the reward is no longer minted and distributed. This is unfair to the remaining operators.

The can be seen on lines 607 - 608 of the Booster contract. Function rewardClaimed will never be called for (removed) Operator 1. But for Operator 2 they will still receive 10% of the rewards even though Operator 1 is no longer registered in the system.

Recommended Mitigation Steps

The totalWeight should be reduced so that the remaining operators receive a fair share of the total rewards.

Using just method calls from VeTokenMinter one could rectify this situation by

  • adding the removed operator with addOperator
  • setting the weight to 0 using updateveAssetWeight. This will have the effect of reducing the totalWeight by the right amount.
  • removing the operator again using removeOperator

However, the removeOperator function should just be rewritten to be as follows:

function removeOperator(address _operator) public onlyOwner {
    totalWeight -= veAssetWeights[_operator];
    veAssetWeights[_operator] = 0;
    operators.remove(_operator);
}

You might also want to modify addOperator so that a weight can be provided as an extra argument. This saves having to call addOperator and then updateveAssetWeight which could save on gas.

solvetony (veToken Finance) disagreed with severity and commented:

Confirmed. But this should be a middle risk.

Alex the Entreprenerd (judge) decreased severity to Medium and commented:

The warden has shown how, due to a privileged call, removing an operator, the weight used to distribute rewards will not be updated fairly. This will cause an improper distribution of rewards.

Because the finding is limited to Loss of Yield, due to Admin Configuration, I believe Medium Severity to be more appropriate.


The original report as published on Code4rena, by sseefried. 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

Impact

Remaining operators do not receive a fair share of the total rewards and a portion of the rewards are not given out at all; the judge rated this as Medium severity due to loss of yield from admin configuration.

What the attacker needed

Owner privilege to call removeOperator; at least two operators with different weights

The fix

The removeOperator function should be rewritten to subtract the operator's weight from totalWeight before removing the operator.

How it was found

  1. Operator 1 is added with weight 9
  2. Operator 2 is added with weight 1
  3. The totalWeight becomes 10, so Operator 1 gets 90% and Operator 2 gets 10%
  4. removeOperator is called on Operator 1, but totalWeight stays 10
  5. Operator 2 still receives only 10% of rewards, and 90% is never minted

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.

This is a smart contract bug where a number used to split rewards is not updated when a participant is removed. As a result, the remaining participants get less than they should, and some rewards are never given out at all.

What is Smart contracts?

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.

More by sseefried

View all

6 more disclosed reports, best first.

More from veToken Finance contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Smart contract vulnerabilities

The lesson behind this report.

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.