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.
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 = 0passes check for theindex <= N_COINS + 1part of predicate on L357 inController.sol - ->
index = uint256_MAXafter L362 - ->
gainUsd = ibuoy.lpToUsd(ARBITRARY_HIGH_VALUE_OF_GAIN);on L371 inController.sol - ->
ipnl.distributeStrategyGainLoss(gainUsd, lossUsd, reward);on L376 inController.sol - ->
(gvtAssets, pwrdAssets, performanceBonus) = handleInvestGain(lastGA, lastPA, gain, reward);on L254 inPnL.sol - ->
performanceBonus = profit.mul(performanceFee).div(PERCENTAGE_DECIMAL_FACTOR);on L186 ofPnL.sol - ->
gvt.mint(reward, gvt.factor(gvtAssets), performanceBonus);on L256 inPnL.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.
Confirmed and Fix has been implemented in release version.
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
- Call Controller.distributeStrategyGainLoss with an arbitrary high gain value and zero loss.
- The index defaults to 0, which passes the <= N_COINS + 1 check due to the OR operator.
- The index is decremented by 1, underflowing to uint256_MAX.
- The function proceeds to the else branch meant for Curve LP vault.
- The gain is converted to USD and passed to PnL.distributeStrategyGainLoss.
- 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.