Skip to content
Business logic Audit finding Intermediate

"Votes" balance can be increased indefinitely in multiple contracts

The public initializeDistributionRecord function in several vesting contracts could be called repeatedly with a valid merkle proof, minting voting tokens each time. An attacker could inflate their voting power indefinitely by calling it multiple times and delegating the votes to themselves.

0xDanielH Follow with 0xDjango, 0xbranded and 21 others

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2023-06-tokensoft-judging/issues/41

Found by

0xDanielH, 0xDjango, 0xbranded, 0xlx, AkshaySrivastav, BenRai, Czar102, Musaka, VAD37, Yuki, caventa, dany.armstrong90, jah, jkoppel, kutugu, magellanXtrachev, ni8mare, p-tsanev, p12473, pengun, r0bert, stopthecap, twicek, y1cunhui

Summary

The "voting power" can be easily manipulated in the following contracts:

  • ContinuousVestingMerkle
  • PriceTierVestingMerkle
  • PriceTierVestingSale_2_0
  • TrancheVestingMerkle
  • CrosschainMerkleDistributor
  • CrosschainContinuousVestingMerkle
  • CrosschainTrancheVestingMerkle
  • All the contracts inheriting from the contracts listed above

This is caused by the public initializeDistributionRecord() function that can be recalled multiple times without any kind of access control:

Solidity
  function initializeDistributionRecord(
    uint32 _domain, // the domain of the beneficiary
    address _beneficiary, // the address that will receive tokens
    uint256 _amount, // the total claimable by this beneficiary
    bytes32[] calldata merkleProof
  ) external validMerkleProof(_getLeaf(_beneficiary, _amount, _domain), merkleProof) {
    _initializeDistributionRecord(_beneficiary, _amount);
  }

Vulnerability Detail

The AdvancedDistributor abstract contract which inherits from the ERC20Votes, ERC20Permit and ERC20 contracts, distributes tokens to beneficiaries with voting-while-vesting and administrative controls. Basically, before the tokens are vested/claimed by a certain group of users, these users can use these ERC20 tokens to vote. These tokens are minted through the _initializeDistributionRecord() function:

Solidity
  function _initializeDistributionRecord(
    address beneficiary,
    uint256 totalAmount
  ) internal virtual override {
    super._initializeDistributionRecord(beneficiary, totalAmount);

    // add voting power through ERC20Votes extension
    _mint(beneficiary, tokensToVotes(totalAmount));
  }

As mentioned in the Tokensoft Discord channel these ERC20 tokens minted are used to track an address's unvested token balance, so that other projects can utilize 'voting while vesting'.

A user can simply call as many times as he wishes the initializeDistributionRecord() function with a valid merkle proof. With each call, the totalAmount of tokens will be minted. Then, the user simply can call delegate() and delegate those votes to himself, "recording" the inflated voting power.

Impact

The issue totally breaks the 'voting while vesting' design. Any DAO/project using these contracts to determine their voting power could be easily manipulated/exploited.

Code Snippet

Tool used

Manual Review

Recommendation

Only allow users to call once the initializeDistributionRecord() function. Consider using a mapping to store if the function was called previously or not. Keep also in mind that fully vested and claimed users should not be able to call this function and if they do, the total amount of tokens that should be minted should be 0 or proportional/related to the amount of tokens that they have already claimed.

Discussion

cr-walker

Great find! We need to preserve the ability to re-initialize distribution records (e.g. if a merkle root changes), so I believe something like this is the best fix:

  function _initializeDistributionRecord(
    address beneficiary,
    uint256 totalAmount
  ) internal virtual override {
    super._initializeDistributionRecord(beneficiary, totalAmount);

    uint256 currentVotes = balanceOf(beneficiary);
    uint256 newVotes = tokensToVotes(totalAmount);

    if (currentVotes > newVotes) {
      // reduce voting power through ERC20Votes extension
      _burn(beneficiary, currentVotes - newVotes);
    } else if (currentVotes < newVotes) {
      // increase voting power through ERC20Votes extension
      _mint(beneficiary, newVotes - currentVotes);
    }
  }

cr-walker

Fixed: https://github.com/SoftDAO/contracts/pull/9

maarcweiss

Fixed by keeping the ability to re-initialize the distribution records, but not increasing the voting power of the user

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

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

The initializeDistributionRecord function lacked access control or a check to prevent repeated calls, so each call minted additional voting tokens.

Impact

Any DAO or project using these contracts to determine voting power could have its voting manipulated, breaking the 'voting while vesting' design.

What the attacker needed

A valid merkle proof for a beneficiary

The fix

The contracts were fixed by allowing re-initialisation but ensuring that repeated calls do not increase a user's voting power.

How it was found

  1. Obtain a valid merkle proof for a beneficiary and amount.
  2. Call initializeDistributionRecord with that proof multiple times.
  3. Each call mints voting tokens for the beneficiary.
  4. Call delegate to assign the inflated votes to yourself.

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.

These contracts let people who are due tokens vote with them before the tokens are fully unlocked. A function that sets up a person's allocation could be called over and over, and each call created new voting tokens. So someone could give themselves unlimited voting power without owning more tokens.

What is Business logic?

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

More from Tokensoft

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.