`Voter.replaceFactory()` and `Voter.addFactory()` functions are broken
The Voter contract's addFactory and replaceFactory functions have incorrect validation checks, allowing duplicate factories or gauge factories to be added to arrays. This breaks an invariant and can cause a denial of service when calling createGauge.
dany.armstrong90 Follow with eeyore and jah
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2024-06-velocimeter-judging/issues/301
Found by
dany.armstrong90, eeyore, jah
Summary
The Voter.replaceFactory() and Voter.addFactory() functions are broken due to invalid validation.
Vulnerability Detail
- In the
addFactory()function, the linerequire(!isFactory[_pairFactory], 'factory true');is missing. - In the
replaceFactory()function, theisFactoryandisGaugeFactorychecks are incorrect:
require(isFactory[_pairFactory], 'factory false'); // <=== should be !isFactory
require(isGaugeFactory[_gaugeFactory], 'g.fact false'); // <=== should be !isGaugeFactory
These issues lead to the invariant being broken, allowing multiple instances of a factory or gauge to be pushed to the factories and gaugeFactories arrays.
Impact
Broken code. DoS when calling Voter.createGauge().
Code Snippet
Tool used
Manual Review
Recommendation
- Add the
require(!isFactory[_pairFactory], 'factory true');validation to theaddFactory()function. - Fix the checks in the
replaceFactory()function:
- require(isFactory[_pairFactory], 'factory false');
+ require(!isFactory[_pairFactory], 'factory true');
- require(isGaugeFactory[_gaugeFactory], 'g.fact false');
+ require(!isGaugeFactory[_gaugeFactory], 'g.fact true');
Discussion
sherlock-admin2
The protocol team fixed this issue in the following PRs/commits: https://github.com/Velocimeter/v4-contracts/pull/19
spacegliderrrr
Fix looks good.
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 validation logic in addFactory and replaceFactory is inverted or missing, so duplicate entries are allowed.
Impact
This could cause a denial of service when calling Voter.createGauge().
What the attacker needed
None
The fix
The issue was fixed by adding the missing check in addFactory and correcting the inverted checks in replaceFactory.
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.
Smart contracts often keep lists of approved factories. The code that adds or replaces a factory should check that it is not already in the list, but here the checks are wrong or missing. As a result, the same factory can be added twice, which later causes a function to fail.
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.