TokenggAVAX: maxDeposit and maxMint return wrong value when contract is paused
The TokenggAVAX contract's maxDeposit and maxMint functions return the maximum uint256 value even when the contract is paused, while deposit and mint operations revert due to the pause. This inconsistency could cause components relying on these functions to malfunction.
HollaDieWaldfee Follow with aviggiano
Originally disclosed on Code4rena
Submitted by HollaDieWaldfee, also found by aviggiano
The TokenggAVAX contract (https://github.com/code-423n4/2022-12-gogopool/blob/aec9928d8bdce8a5a4efe45f54c39d4fc7313731/contracts/contract/tokens/TokenggAVAX.sol#L24) can be paused.
The whenTokenNotPaused modifier is applied to the following functions (https://github.com/code-423n4/2022-12-gogopool/blob/aec9928d8bdce8a5a4efe45f54c39d4fc7313731/contracts/contract/tokens/TokenggAVAX.sol#L225-L239):
previewDeposit, previewMint, previewWithdraw and previewRedeem
Thereby any calls to functions that deposit or withdraw funds revert.
There are two functions (maxWithdraw and maxRedeem) that calculate the max amount that can be withdrawn or redeemed respectively.
Both functions return 0 if the TokenggAVAX contract is paused.
The issue is that TokenggAVAX does not override the maxDeposit and maxMint functions (https://github.com/code-423n4/2022-12-gogopool/blob/aec9928d8bdce8a5a4efe45f54c39d4fc7313731/contracts/contract/tokens/upgradeable/ERC4626Upgradeable.sol#L156-L162) in the ERC4626Upgradable contract like it does for maxWithdraw and maxRedeem.
Thereby these two functions return a value that cannot actually be deposited or minted.
This can cause any components that rely on any of these functions to return a correct value to malfunction.
So maxDeposit and maxMint should return the value 0 when TokenggAVAX is paused.
Proof of Concept
- The
TokenggAVAXcontract is paused by callingOcyticus.pauseEverything(https://github.com/code-423n4/2022-12-gogopool/blob/aec9928d8bdce8a5a4efe45f54c39d4fc7313731/contracts/contract/Ocyticus.sol#L37-L43) TokenggAVAX.maxDepositreturnstype(uint256).max(https://github.com/code-423n4/2022-12-gogopool/blob/aec9928d8bdce8a5a4efe45f54c39d4fc7313731/contracts/contract/tokens/upgradeable/ERC4626Upgradeable.sol#L157)- However
depositcannot be called with this value because it is paused (previewDepositreverts because of thewhenTokenNotPausedmodifier) (https://github.com/code-423n4/2022-12-gogopool/blob/aec9928d8bdce8a5a4efe45f54c39d4fc7313731/contracts/contract/tokens/upgradeable/ERC4626Upgradeable.sol#L44)
Tools Used
VSCode
Recommended Mitigation Steps
The maxDeposit and maxMint functions should be overridden by TokenggAVAX just like maxWithdraw and maxRedeem are overridden and return 0 when the contract is paused (https://github.com/code-423n4/2022-12-gogopool/blob/aec9928d8bdce8a5a4efe45f54c39d4fc7313731/contracts/contract/tokens/TokenggAVAX.sol#L206-L223).
So add these two functions to the TokenggAVAX contract:
function maxDeposit(address) public view override returns (uint256) {
if (getBool(keccak256(abi.encodePacked("contract.paused", "TokenggAVAX")))) {
return 0;
}
return return type(uint256).max;
}
function maxMint(address) public view override returns (uint256) {
if (getBool(keccak256(abi.encodePacked("contract.paused", "TokenggAVAX")))) {
return 0;
}
return return type(uint256).max;
}
Alex the Entreprenerd (judge) commented:
Looks off, the modifiers will revert on pause, not return 0.
0xju1ie (GoGoPool) disagreed with severity and commented:
I’d say Low:
(e.g. assets are not at risk: state handling, function incorrect as to spec, issues with comments). Excludes Gas optimizations, which are submitted and judged separately.
emersoncloud (GoGoPool) commented:
Good catch, I think we should override those for consistency at least but there’s no way to exploit to lose assets. Agreed that QA makes sense.
Alex the Entreprenerd (judge) decreased severity to Low and commented:
By definition, the finding is Informational in Nature.
Because of the relevancy, I’m awarding it QA - Low
Alex the Entreprenerd (judge) increased severity to Medium and commented:
I had a change of heart on this issue, because this pertains to a standard that is being implemented.
For that reason am going to award Medium Severity, because the function breaks the standard, and historically we have awarded similar findings (e..g broken ERC20, broken ERC721 standard), with Medium.
The Warden has shown an inconsistency between the ERC-4626 Spec and the implementation done by the sponsor, while technically this is an informational finding, the fact that a standard was broken warrants a higher severity, leading me to believe that Medium is a more appropriate Severity.
Am making this decision because the Sponsor is following the standard, and the implementation of these functions is not consistent with it.
emersoncloud (GoGoPool) mitigated:
Return correct value from maxMint and maxDeposit when the contract is paused: multisig-labs/gogopool#33
Status: Mitigation confirmed by RaymondFam and hansfriese.
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 does not override maxDeposit and maxMint to return zero when paused, unlike maxWithdraw and maxRedeem.
Impact
Components that rely on maxDeposit and maxMint returning correct values could malfunction, though no assets are at risk.
What the attacker needed
Contract is paused
The fix
The maxDeposit and maxMint functions should be overridden to return 0 when the contract is paused, and this was later mitigated.
How it was found
- The TokenggAVAX contract is paused by calling Ocyticus.pauseEverything.
- TokenggAVAX.maxDeposit returns type(uint256).max.
- However deposit cannot be called with this value because it is paused (previewDeposit reverts because of the whenTokenNotPaused modifier).
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.
This is a smart contract that follows a standard for tokenised vaults. The standard says functions that report the maximum amount you can deposit should return zero when deposits are disabled. Here, deposits are disabled by a pause, but the functions still say you can deposit a huge amount, which could confuse other programs that check these functions.
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.