Skip to content
Business logic Audit finding Intermediate

`update_period(..)` leads to wrong calculation in weekly emissions breaking accounting for the protocol

The team emissions calculation in update_period() divides by (PRECISION - teamRate) instead of PRECISION, causing team emissions to be overestimated. An attacker could not directly exploit this, but it leads to more FLOW being minted to the team than intended, breaking accounting for the protocol and integrators.

Audinarey Follow with Ch_301, Ruhum and 4 others

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2024-06-velocimeter-judging/issues/168

Found by

Audinarey, Ch_301, Ruhum, Sentryx, bbl4de, eeyore, mike-watson

Summary

The update_period(..) function does the calculation and distribution of voter weekly and _teamEmissions of FLOW. However, the _teamEmissions calculations is over estimated making the calculation wrong and more

Vulnerability Detail

The _teamEmissions is calculated on top of normal weekly emissions in the update_period() function on L119

Solidity
File: Minter.sol
112:     function update_period() external returns (uint) { // @audit 
113:         uint _period = active_period;
114:         if (block.timestamp >= _period + WEEK && initializer == address(0)) { // only trigger if new week
115:             _period = (block.timestamp / WEEK) * WEEK;
116:             active_period = _period;
117:             uint256 weekly = weekly_emission(); // could be just 2k if voter has notified reward
118:             
119:  ->         uint _teamEmissions = (teamRate * weekly) /
120:  ->             (PRECISION - teamRate);
121:             uint _required =  weekly + _teamEmissions;
122:             uint _balanceOf = _flow.balanceOf(address(this));
123:             if (_balanceOf < _required) {
124:  ->             _flow.mint(address(this), _required - _balanceOf);

Ideally , the evaluation should work as follows

  • weeklyPerGauge = 2000e18, teamRate = 5% and numberOfGauges = 0
  • it is expected that 100e18 be minted and transferred to the teamEmissions address and 2000e18 be transferred to the Voter as rewards
  • bringing the total distributed (both team and voter) to 2100e18 for that epoch.

However as shown below, the teamEmissions calculation breaks this accounting

Solidity
// uint _teamEmissions = = (teamRate * weekly) / (PRECISION - teamRate);
_teamEmissions = (50 * 2000e18) / (1000 - 50)
_teamEmissions = 105e18

Notice Now that

  • the evaluation of _teamEmissions is 105e18 bringing the total to 2105e18 emmited for that epoch
  • also the actual value now recieved by is _teamEmissions is 5.25% of the weekly emmisions instead of 5%

This descrepancy becomes larger as the numberOfGauges increases.

This can also lead to inflated values of Minter.circulating_supply() because the total supply of flow is increased contrary to the expected rate owing to each mint action (L124) that may occur due to excess _teamEmissions of FLOW calculated when update_period is called. This could break accounting also for protocol who integrate with VELOCIMETER and use the circulating_supply() function for core accounting

Solidity
File: Minter.sol
93:     function circulating_supply() public view returns (uint)
94:         return _flow.totalSupply() - _ve.totalSupply();
95:     }

Impact

More FLOW is minted to team due to wrong calculation breaking accounting for the protocol and possible third party protocols who integrate with the protocol

Code Snippet

https://github.com/sherlock-audit/2024-06-velocimeter/blob/main/v4-contracts/contracts/Minter.sol#L112-L120

Tool used

Manual Review

Recommendation

Modify the Minter::update_period() function as shown below

Diff
File: Minter.sol
112:     function update_period() external returns (uint) { // @audit
113:         uint _period = active_period;
114:         if (block.timestamp >= _period + WEEK && initializer == address(0)) { // only trigger if new week
115:             _period = (block.timestamp / WEEK) * WEEK;
116:             active_period = _period;
117:             uint256 weekly = weekly_emission(); // could be just 2k if voter has notified reward
118:
-119:             uint _teamEmissions = (teamRate * weekly) /
-120:               (PRECISION - teamRate);
+119:             uint _teamEmissions = (teamRate * weekly) /
+120:               (PRECISION);
121:             uint _required =  weekly + _teamEmissions;
122:             uint _balanceOf = _flow.balanceOf(address(this));
123:             if (_balanceOf < _required) {
124:                 _flow.mint(address(this), _required - _balanceOf);

Discussion

sherlock-admin2

The protocol team fixed this issue in the following PRs/commits: https://github.com/Velocimeter/v4-contracts/pull/16

spacegliderrrr

Fix looks good. Team rate is now calculated correctly.

sherlock-admin2

The Lead Senior Watson signed off on the fix.

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

Likely the team emissions formula divides by (PRECISION - teamRate) instead of PRECISION, overestimating the team's share.

Impact

More FLOW is minted to the team than intended, which could break accounting for the protocol and third-party integrators that use circulating_supply().

What the attacker needed

None

The fix

The team emissions calculation should divide by PRECISION instead of (PRECISION - teamRate); the protocol team fixed this in a pull request.

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 the code that calculates how many tokens go to the team each week uses the wrong formula. Instead of taking a simple percentage of the weekly rewards, it divides by a smaller number, so the team gets slightly more tokens than they should. Over time, this adds extra tokens to the supply, which can mess up other systems that rely on the total supply.

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 by Audinarey

View all

10 more disclosed reports, best first.

More from Velocimeter

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.