Skip to content
DoS Audit finding Intermediate

`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

  1. In the addFactory() function, the line require(!isFactory[_pairFactory], 'factory true'); is missing.
  2. In the replaceFactory() function, the isFactory and isGaugeFactory checks are incorrect:
Solidity
        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

https://github.com/sherlock-audit/2024-06-velocimeter/blob/main/v4-contracts/contracts/Voter.sol#L155-L185

Tool used

Manual Review

Recommendation

  1. Add the require(!isFactory[_pairFactory], 'factory true'); validation to the addFactory() function.
  2. Fix the checks in the replaceFactory() function:
Diff
-        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.

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

More by dany.armstrong90

View all

4 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.

Denial of service

The lesson behind this report.

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.