The circulating_supply() of the Minter contract may revert, resulting in the inability of the Minter to periodically emit Flow tokens
The circulating_supply() function in the Minter contract could revert if the total supply of Flow tokens is less than the total supply of veTokens, causing the weekly token emission to fail. This could lead to a systemic denial of service, preventing the protocol from emitting tokens.
Honour Follow with bughuntoor and neon2835
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2024-06-velocimeter-judging/issues/663
Found by
Honour, bughuntoor, neon2835
Summary
The circulating_supply() of the Minter contract may revert, causing the Minter to fail to periodically emit Flow tokens, leading to systemic DOS risks.
Vulnerability Detail
The code for the Minter contract to emit Flow tokens weekly is in the update_period() function:
function update_period() external returns (uint) {
uint _period = active_period;
if (block.timestamp >= _period + WEEK && initializer == address(0)) { // only trigger if new week
_period = (block.timestamp / WEEK) * WEEK;
active_period = _period;
uint256 weekly = weekly_emission();
uint _teamEmissions = (teamRate * weekly) /
(PRECISION - teamRate);
uint _required = weekly + _teamEmissions;
uint _balanceOf = _flow.balanceOf(address(this));
if (_balanceOf < _required) {
_flow.mint(address(this), _required - _balanceOf);
}
require(_flow.transfer(teamEmissions, _teamEmissions));
_checkpointRewardsDistributors();
_flow.approve(address(_voter), weekly);
_voter.notifyRewardAmount(weekly);
emit Mint(msg.sender, weekly, circulating_supply());
}
return _period;
}
Please pay attention to this statement of the update_period function:
emit Mint(msg.sender, weekly, circulating_supply());
If the value of _flow.totalSupply() is less than the value of _ve.totalSupply() in the circulating_supply() function, a revert will occur, preventing the normal emission of flow tokens during the update_period.
This situation is possible. When the flow-weth pool has good liquidity and the price of flow token is relatively high, the minting amount of lpToken may exceed the total supply of flow token. When there are enough lpToken staked to veEscrow contract , _ve.totalSupply() will be greater than _flow.totalSupply(), which is a potential systemic DOS risk that may occur.
Impact
The circulating_supply() of the Minter contract may revert, resulting in the inability of the Minter to periodically emit Flow tokens, posing a systemic DOS risk.
Code Snippet
Tool used
Manual Review
Recommendation
function circulating_supply() public view returns (uint) {
- return _flow.totalSupply() - _ve.totalSupply();
- return _flow.totalSupply() > _ve.totalSupply() ? _flow.totalSupply() - _ve.totalSupply() : 0 ;
}
Discussion
nevillehuang
request poc
In theory, the lpToken is obtained by locking flow and wethr(or oflow and weth) so the lptoken already needs previously minted flow tokens, and top of that _ve.totalSupply is the actual voting power at current time(which means all lpToken value locked is decaying with time). So I see that the ve.totalSupply will have top be always smaller than flow token’s totalSupply.
sherlock-admin4
PoC requested from @oxneon
Requests remaining: 19
sherlock-admin2
The protocol team fixed this issue in the following PRs/commits: https://github.com/Velocimeter/v4-contracts/pull/15
spacegliderrrr
Fix looks good. circulating_supply now simply returns the total supply of Flow
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 circulating_supply() function performs a subtraction without checking if the result would be negative, which can cause a revert when the veToken total supply exceeds the Flow token total supply.
What the attacker needed
Flow-WETH pool has good liquidity; Flow token price is high; Enough lpTokens staked in veEscrow
The fix
The issue was fixed by changing circulating_supply() to return the total supply of Flow tokens directly.
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.
In this smart contract, a function that calculates the circulating supply of tokens can fail if the total supply of one token is smaller than another. This failure stops the weekly token distribution, which could freeze the protocol's operations.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.