Gauge set can be front run if bribe and gauge constructors aren’t run atomically
The Bribe contract's setGauge function can be called by anyone and only once, and it is normally invoked by the Gauge constructor. If the two constructors are not run atomically, an attacker can call setGauge in between, binding the Bribe to a wrong gauge and making it unusable.
Submitted by hyh, also found by 0x1f8b
If Bribe and Gauge constructors are run not in the same transaction, the griefing attack is possible. A malicious user can run setGauge after Bribe, but before Gauge constructor, making Bribe contract unusable. The fix here is Bribe redeployment.
Setting severity to be medium as that is temporary system breaking impact.
Proof of Concept
setGauge can be run by anyone, but only once with a meaningful gauge:
function setGauge(address _gauge) external {
require(gauge == address(0), "gauge already set");
gauge = _gauge;
}
Now it is called in Gauge constructor:
constructor(address _stake, address _bribe, address __ve, address _voter, bool _isForPair) {
stake = _stake;
bribe = _bribe;
_ve = __ve;
voter = _voter;
factory = msg.sender;
IBribe(bribe).setGauge(address(this));
This way it will not be called before Gauge constructor, but if it is not atomic with Bribe constructor, an attacker can call in-between.
Recommended Mitigation Steps
Consider either running Bribe and then Gauge constructors atomically, or introducing an owner role in Bribe constructor and onlyOwner access control in setGauge, setting it manually.
pooltypes (Velodrome) confirmed and commented:
Thanks, we’ve addressed this and removed the
setGaugepattern in our mainnet deployment.
Alex the Entreprenerd (judge) commented:
The warden has identified a grief that can be done by front-running a non-authorized call to
setGauge.Impact would require re-deploying the bribes contract and in lack of an atomic deploy + set. I believe the finding to be valid and Medium Severity to be appropriate.
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 setGauge function lacks access control and the deployment of Bribe and Gauge is not atomic, leaving a window for anyone to set the gauge first.
Impact
The Bribe contract becomes unusable and must be redeployed, causing a temporary disruption to the system.
What the attacker needed
Bribe and Gauge deployed non-atomically; attacker can send a transaction in between
The fix
The project removed the setGauge pattern in its mainnet deployment, and the report also suggested running the constructors atomically or adding owner-only access control.
How it was found
- Deploy the Bribe contract without immediately running the Gauge constructor.
- Before the Gauge constructor runs, call setGauge on the Bribe contract with an arbitrary address.
- The Bribe contract now has its gauge set to the attacker's address and cannot be changed.
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.
A smart contract has a setup step that links it to another contract, and that step can be done by anyone but only once. If the two contracts are deployed in separate transactions, someone else can jump in and do the linking first with the wrong address. The real owner is then stuck with a broken link and has to deploy again.
What is Race condition?
Parallel requests reach a state the code assumed could not happen: a coupon used twice, a limit overrun, a check skipped.