MintDebt returns a wrong value
The mintDebt function returns the shares amount instead of the assets amount, contradicting its declared return type and documentation. This wrong return value breaks the ERC-4626 invariant that mint functions should return assets.
- Disclosed after under an hour
#34959 [SC-Low] `mintDebt` returns a wrong value
Submitted on Sep 1st 2024 at 21:26:18 UTC by @Bx4 for Audit Comp | Acre
- Report ID: #34959
- Report Type: Smart Contract
- Report severity: Low
- Target: https://sepolia.etherscan.io/address/0x7e184179b1F95A9ca398E6a16127f06b81Cb37a3
- Impacts:
- Contract fails to deliver promised returns, but doesn't lose value
- wrong return value
Description
Brief/Intro
In `mintDebt` it returns `shares` but it is rather supposed to return assets
Vulnerability Details
In `mintDebt` it returns `shares` as seen below `return shares;` meanwhile it is stated in the function natspec to return assets as seen below `/// @return assets The debt amount in asset taken for the shares minted.` Also, it is seen in the function declaration that it returns assets as shown below ` function mintDebt( uint256 shares, address receiver) public whenNotPaused returns (uint256 assets){} ` However the return statement declared last will overwrite it.
Impact Details
it will return a wrong value and it will break the ERC 4626 invariant because it is stated that mint functions return assets as seen in this link.
References
Proof of Concept
Proof of Concept
from the comment(@return) and the return value of the `mintDebt` function below
```solidity /// @return assets The debt amount in asset taken for the shares minted. function mintDebt( uint256 shares, address receiver ) public whenNotPaused returns (uint256 assets) {
...
@-> return shares; } ```
we can deduce that the return value is supposed to be assets and yes in the function declaration it returns `uint256 assets`, However the last return statement will overwrite it and return shares
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
The function's final return statement returns the variable 'shares' instead of the declared return variable 'assets', overwriting the intended value.
Impact
The function returns a wrong value, which could break the ERC-4626 invariant and cause issues for integrators expecting the correct asset amount.
What the attacker needed
None
The fix
The function should return the correct assets value instead of shares.
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 is supposed to give back a number representing the amount of assets (like tokens) involved. Instead, it gives back a different number (shares), which can confuse other programs that rely on the correct value.
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.