The maximum size of an ICHI vault spell position can be arbitrarily surpassed
Summary
The maximum size of an ICHI vault spell position can be arbitrarily surpassed by subsequent deposits to a position due to a flaw in the curPosSize calculation.
Vulnerability Detail
Ichi vault spell positions are subject to a maximum size limit to prevent large positions, ensuring a wide margin for liquidators and bad debt prevention for the protocol.
The maximum position size is enforced in the IchiVaultSpell.depositInternal function and compared to the current position size curPosSize.
However, the curPosSize does not reflect the actual position size, but the amount of Ichi vault LP tokens that are currently held in the IchiVaultSpell contract (see L153).
Assets can be repeatedly deposited into an Ichi vault spell position using the IchiVaultSpell.openPosition function (via the BlueBerryBank.execute function).
On the very first deposit, the curPosSize correctly reflects the position size. However, on subsequent deposits, the previously received Ichi vault LP tokens are kept in the BlueBerryBank contract. Thus, checking the balance of vault tokens in the IchiVaultSpell contract only accounts for the current deposit.
Test case
To demonstrate this issue, please use the following test case:
berndartmueller
high
The maximum size of an
ICHI
vault spell position can be arbitrarily surpassedSummary
The maximum size of an
ICHI
vault spell position can be arbitrarily surpassed by subsequent deposits to a position due to a flaw in thecurPosSize
calculation.Vulnerability Detail
Ichi vault spell positions are subject to a maximum size limit to prevent large positions, ensuring a wide margin for liquidators and bad debt prevention for the protocol.
The maximum position size is enforced in the
IchiVaultSpell.depositInternal
function and compared to the current position sizecurPosSize
.However, the
curPosSize
does not reflect the actual position size, but the amount of Ichi vault LP tokens that are currently held in theIchiVaultSpell
contract (see L153).Assets can be repeatedly deposited into an Ichi vault spell position using the
IchiVaultSpell.openPosition
function (via theBlueBerryBank.execute
function).On the very first deposit, the
curPosSize
correctly reflects the position size. However, on subsequent deposits, the previously received Ichi vault LP tokens are kept in theBlueBerryBank
contract. Thus, checking the balance ofvault
tokens in theIchiVaultSpell
contract only accounts for the current deposit.Test case
To demonstrate this issue, please use the following test case:
Run the test with the following command:
The test case fails and therefore shows that the maximum position size can be exceeded without reverting.
Impact
The maximum position size limit can be exceeded, leading to potential issues with liquidations and bad debt accumulation.
Code Snippet
spell/IchiVaultSpell.sol#L152-L156
Tool used
Manual Review
Recommendation
Consider determining the current position size using the
bank.getPositionValue()
function instead of using the current Ichi vault LP token balance.