Skip to content
Access control Audit finding Intermediate

Incorrect use of operator leads to arbitrary minting of GVT tokens

The access control check in the distributeStrategyGainLoss function used a logical OR instead of AND, allowing any address to bypass the vault-adaptor restriction. An attacker could then call the function with arbitrary gain values, leading to arbitrary minting of GVT tokens.

0xRajeev Follow

Originally disclosed on Code4rena

Submitted by 0xRajeev, also found by pauliax and gpersoon

The distributeStrategyGainLoss() function distributes any gains or losses generated from a harvest and is expected to be called only by valid protocol vault adaptors. It is an externally visible function and the access control is indirectly enforced on msg.sender by checking that vaultIndexes[msg.sender] is a valid index range 1-4. However, the operator used in the require() is || instead of &&, which allows an arbitrary msg.sender, i.e. attacker, to bypass the check.

Scenario: An arbitrary non-vault address calling this function will get an index of 0 because of default mapping value in vaultIndexes[msg.sender], which will fail the > 0 check, but pass the <= N_COINS + 1 check (N_COINS = 3) because 0 <= 4 which will allow control to go past this check.

Furthermore, on L362, index=0 will underflow the -1 decrement (due to lack of SafeMath.sub and use of < 0.8.0 solc) and the index will be set to (uint256_MAX - 1). This will allow execution to proceed to the “else” part of conditional meant for curve LP vault. Therefore, this will allow any random address to call this function with arbitrary values of gain/loss and distribute arbitrary gain/loss appearing to come from Curve vault.

The attack control flow:

  • -> Controller.distributeStrategyGainLoss(ARBITRARY_HIGH_VALUE_OF_GAIN, 0)
  • -> index = 0 passes check for the index <= N_COINS + 1 part of predicate on L357 in Controller.sol
  • -> index = uint256_MAX after L362
  • -> gainUsd = ibuoy.lpToUsd(ARBITRARY_HIGH_VALUE_OF_GAIN); on L371 in Controller.sol
  • -> ipnl.distributeStrategyGainLoss(gainUsd, lossUsd, reward); on L376 in Controller.sol
  • -> (gvtAssets, pwrdAssets, performanceBonus) = handleInvestGain(lastGA, lastPA, gain, reward); on L254 in PnL.sol
  • -> performanceBonus = profit.mul(performanceFee).div(PERCENTAGE_DECIMAL_FACTOR); on L186 of PnL.sol
  • -> gvt.mint(reward, gvt.factor(gvtAssets), performanceBonus); on L256 in PnL.sol

Recommend changing || to && in require() on L357 of Controller.sol to prevent arbitrary addresses from going past this check. Or, consider exercising explicit access control for the authorized vault adaptors.

kristian-gro (Gro) confirmed

Confirmed and Fix has been implemented in release version.

The original report as published on Code4rena, by 0xRajeev. 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

Impact

An attacker could mint arbitrary amounts of GVT tokens, potentially devaluing the token and stealing value from the protocol.

What the attacker needed

None

The fix

The fix was to change the logical OR to AND in the require() condition, or to implement explicit access control for authorized vault adaptors.

How it was found

  1. Call Controller.distributeStrategyGainLoss with an arbitrary high gain value and zero loss.
  2. The index defaults to 0, which passes the <= N_COINS + 1 check due to the OR operator.
  3. The index is decremented by 1, underflowing to uint256_MAX.
  4. The function proceeds to the else branch meant for Curve LP vault.
  5. The gain is converted to USD and passed to PnL.distributeStrategyGainLoss.
  6. PnL calculates a performance bonus and mints GVT tokens to the attacker.

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 function meant only for trusted vault adaptors had a mistake in its access check: it used 'or' instead of 'and', so any address could pass. This let anyone call the function with fake profit numbers, causing the system to mint new GVT tokens out of thin air.

What is Access control?

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.

More by 0xRajeev

View all

61 more disclosed reports, best first.

More from Gro Protocol

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Broken access control

The lesson behind this report.

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.