`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.
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
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% andnumberOfGauges= 0- it is expected that 100e18 be minted and transferred to the
teamEmissionsaddress and 2000e18 be transferred to theVoteras rewards - bringing the total distributed (both team and voter) to 2100e18 for that epoch.
However as shown below, the teamEmissions calculation breaks this accounting
// uint _teamEmissions = = (teamRate * weekly) / (PRECISION - teamRate);
_teamEmissions = (50 * 2000e18) / (1000 - 50)
_teamEmissions = 105e18
Notice Now that
- the evaluation of
_teamEmissionsis 105e18 bringing the total to 2105e18 emmited for that epoch - also the actual value now recieved by is
_teamEmissionsis 5.25% of theweeklyemmisions 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
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
Tool used
Manual Review
Recommendation
Modify the Minter::update_period() function as shown below
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.
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.