Funding.deposit() doesn’t work if there is no discount set
The Funding contract's deposit function calls getAmountOut, which returns zero when no discount is set, causing a later depositFor call to revert because it requires a non-zero amount. As a result, no deposits are possible unless a discount is configured.
Submitted by Ruhum, also found by TrungOre, MaratCerby, 0xBug, minhquanym, shenwilly, 0xDjango, remora, danb, IllIllI, pedroais, m9800, and hyh
https://github.com/code-423n4/2022-04-badger-citadel/blob/main/src/Funding.sol#L177
https://github.com/code-423n4/2022-04-badger-citadel/blob/main/src/Funding.sol#L202
https://github.com/code-423n4/2022-04-badger-citadel/blob/main/src/Funding.sol#L184
https://github.com/code-423n4/2022-04-badger-citadel/blob/main/src/StakedCitadel.sol#L769
Impact
The Funding contract’s deposit() function uses the getAmountOut() function to determine how many citadel tokens the user should receive for their deposit. But, if no discount is set, the function always returns 0. Now the deposit() function tries to deposit 0 tokens for the user through the StakedCitadel contract. But, that function requires the number of tokens to be != 0. The transaction reverts.
This means, that no deposits are possible. Unless there is a discount.
Proof of Concept
Funding.deposit() calls getAmountOut(): https://github.com/code-423n4/2022-04-badger-citadel/blob/main/src/Funding.sol#L177
Here’s the getAmountOut() function:
function getAmountOut(uint256 _assetAmountIn)
public
view
returns (uint256 citadelAmount_)
{
uint256 citadelAmountWithoutDiscount = _assetAmountIn * citadelPriceInAsset;
if (funding.discount > 0) {
citadelAmount_ =
(citadelAmountWithoutDiscount * MAX_BPS) /
(MAX_BPS - funding.discount);
}
// unless the above if block is executed, `citadelAmount_` is 0 when this line is executed.
// 0 = 0 / x
citadelAmount_ = citadelAmount_ / assetDecimalsNormalizationValue;
}
Call to StakedCitadel.depositFor(): https://github.com/code-423n4/2022-04-badger-citadel/blob/main/src/Funding.sol#L184
require statement that makes the whole transaction revert: https://github.com/code-423n4/2022-04-badger-citadel/blob/main/src/StakedCitadel.sol#L769
Recommended Mitigation Steps
Change the getAmountOut() function to:
function getAmountOut(uint256 _assetAmountIn)
public
view
returns (uint256 citadelAmount_)
{
uint256 citadelAmount_ = _assetAmountIn * citadelPriceInAsset;
if (funding.discount > 0) {
citadelAmount_ =
(citadelAmount_ * MAX_BPS) /
(MAX_BPS - funding.discount);
}
citadelAmount_ = citadelAmount_ / assetDecimalsNormalizationValue;
}
shuklaayush (BadgerDAO) confirmed
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 getAmountOut function only assigns a value to citadelAmount_ inside the discount condition, leaving it zero otherwise.
Impact
No deposits are possible unless a discount is set.
What the attacker needed
No discount set in funding
The fix
The getAmountOut function should be changed to always compute the base amount before applying any discount.
How it was found
- Call Funding.deposit() when no discount is set.
- Funding.deposit() calls getAmountOut(), which returns 0.
- Funding.deposit() calls StakedCitadel.depositFor() with 0 tokens.
- StakedCitadel.depositFor() requires the token amount to be non-zero, so the transaction reverts.
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 that handles deposits calculates how many tokens to give back, but a mistake makes that calculation return zero when a discount setting is missing. The next step refuses to process a zero amount, so the whole deposit fails. This means users cannot deposit at all until the discount is set.
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.