when ReserveBase undercollateralized , Manager.orders will not be able to execute
The Manager contract assumes that redeeming reserve tokens always yields the same amount of USDC, but when the reserve is undercollateralised, redemption returns less. This causes order execution to fail with an insufficient balance error.
Source: https://github.com/sherlock-audit/2024-08-perennial-v2-update-3-judging/issues/35
Found by
bin2chen, panprog
Summary
Manager.sol does not take into account that reserve.redeemPrice may be less than 1:1
The current code, reserve.redeem(amount) followed by a direct transfer of the same USDC, will fail because it results in an insufficient balance and the order will not be triggered successfully
Root Cause
If balance order.interfaceFee.unwrap=true, need to convert DSU to USDC
Use reserve.redeem(amount);
But this method, in the case of undercollateralized, is possible to convert less than amount, but the current code implementation logic directly uses amount.
/// @inheritdoc IReserve
function redeemPrice() public view returns (UFixed18) {
// if overcollateralized, cap at 1:1 redemption / if undercollateralized, redeem pro-rata
return assets().unsafeDiv(dsu.totalSupply()).min(UFixed18Lib.ONE);
}
function _unwrapAndWithdaw(address receiver, UFixed18 amount) private {
reserve.redeem(amount);
USDC.push(receiver, UFixed6Lib.from(amount));
}
Internal pre-conditions
No response
External pre-conditions
- XXXReserve.sol undercollateralized
Attack Path
- alice place
TriggerOrder[1] = {price < 123 , interfaceFee.unwrap=true} - XXXReserve.sol undercollateralized , redeemPrice < 1:1
- when price < 123 , Meet the order conditions
- keeper call
executeOrder(TriggerOrder[1]), but execute fail because revert Insufficient balance
Impact
No response
PoC
No response
Mitigation
function _unwrapAndWithdaw(address receiver, UFixed18 amount) private {
- reserve.redeem(amount);
- USDC.push(receiver, UFixed6Lib.from(amount));
+ USDC.push(receiver, UFixed6Lib.from(reserve.redeem(amount)));
}
Discussion
sherlock-admin2
The protocol team fixed this issue in the following PRs/commits: https://github.com/equilibria-xyz/perennial-v2/pull/458
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 code assumes a 1:1 redemption rate between reserve tokens and USDC, ignoring that the redeem price can be less than 1:1 when the reserve is undercollateralised.
Impact
Orders that require unwrapping the interface fee will fail to execute when the reserve is undercollateralised, potentially blocking order fulfilment.
What the attacker needed
Reserve is undercollateralised; order has interfaceFee.unwrap=true; order price condition is met
The fix
The fix was to use the actual amount returned by reserve.redeem when transferring USDC, rather than the requested amount.
How it was found
- Alice places a trigger order with interfaceFee.unwrap set to true.
- The reserve becomes undercollateralised, so the redeem price drops below 1:1.
- The price condition for the order is met.
- A keeper calls executeOrder, but the transaction reverts due to insufficient balance.
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 lets users place orders that automatically trigger when a price condition is met. To pay a fee, it converts an internal token to USDC, assuming one token always equals one USDC. But if the reserve is undercollateralised, the conversion gives less USDC, so the transfer fails and the order cannot execute.
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.