Skip to content
Business logic Audit finding Intermediate

VoterProxy incorrectly assumes a 1-1 mapping between the gauge and the LP tokens.

The VoterProxy contract assumes a one-to-one mapping between gauge tokens and underlying LP tokens when computing the amount to withdraw in withdrawAll. If a gauge rebases its token ratio, the contract would withdraw an incorrect amount and could lose funds.

Picodes Follow

Originally disclosed on Code4rena

Submitted by Picodes

https://github.com/code-423n4/2022-05-vetoken/blob/2d7cd1f6780a9bcc8387dea8fecfbd758462c152/contracts/VoterProxy.sol#L270

https://github.com/code-423n4/2022-05-vetoken/blob/2d7cd1f6780a9bcc8387dea8fecfbd758462c152/contracts/VoterProxy.sol#L140

Impact

When calling withdrawAll, to compute the amount to withdraw, the contract checks the balance of gauge tokens and assume that 1 gauge token = 1 LP token by doing uint256 amount = balanceOfPool(_gauge).add(IERC20(_token).balanceOf(address(this)));. Overall this assumption may not hold and this would lead to a loss of funds when calling withdrawAll.

Proof of Concept

Indeed this is false in some cases, check for example https://etherscan.io/address/0x3785Ce82be62a342052b9E5431e9D3a839cfB581 where the total supply is not the same as the balance of LP tokens held by the contract. You can also check the contract code where you can see there is a staking_factor between the balance and the underlying LP token balance.

Recommended Mitigation Steps

Use the total supply of pool.token which is a better proxy to know how much to withdraw when withdrawing all.

jetbrain10 (veToken Finance) commented:

Are you referring we need to calc the staking _factor by ourself?

Alex the Entreprenerd (judge) commented:

@jetbrain10 the warden says that some Deposits will not return the same amount of Lp Tokens.

See this example from the contract linked by the Warden: https://etherscan.io/tx/0xd3eab573697d4fb92ebe4d91d35b03795d384ac45f7a723b321c98f6da2420cb

I think this means the contracts may break when integrating with Angle Protocol.

As far as I’m aware CRV, Balancer will return a 1-1 between the Deposit Token and the Gauge Token.

Alex the Entreprenerd (judge) commented:

The warden has shown evidence of the GaugeLP-Token being “rebased” from the “usual” 1-1 to a ratio (assuming due to cost / increasing in value in underlying).

Because:

  • The Sponsor system is meant to integrate with multiple protocols
  • The warden has shown a specific example (ANGLE) of the math bring broken

Considering that this is contingent on the sponsor launching an integration with the Angle Protocol, using Gauges that “rebase”, I believe the finding to be Valid and of Medium Severity.

Most likely remediation will require poking the gauge for exchange rates and also checking available tokens after withdrawing.

jetbrain10 (veToken Finance) acknowledged


The original report as published on Code4rena, by Picodes. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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 contract hard-codes a one-to-one exchange rate between gauge tokens and LP tokens instead of querying the gauge's actual exchange rate.

Impact

When integrating with a gauge that rebases, calling withdrawAll could lead to a loss of funds because the computed withdrawal amount is wrong.

What the attacker needed

Integration with a rebasing gauge

The fix

The contract should query the gauge for the actual exchange rate and check the available tokens after withdrawing, rather than assuming a one-to-one ratio.

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 gauge is a contract that holds deposited tokens and gives back a receipt token. The buggy code treats one receipt token as always equal to one deposited token, but some gauges change that ratio over time. Withdrawing based on the wrong ratio can leave funds behind or withdraw too much.

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.

More by Picodes

View all

17 more disclosed reports, best first.

More from veToken Finance contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.