Incorrect collateral calculation for delayed swap strategies
The RiskEngine contract's delayed swap collateral calculation used the maximum of the loan requirement and credit value instead of netting the credit against the loan. This inflated collateral requirements, making solvent accounts appear insolvent and potentially triggering unfair liquidations.
eternal1328 Follow with astra39100, Coachmike and 4 others
Originally disclosed on Code4rena
Submitted by eternal1328, also found by astra39100, Coachmike, Funen, lamassu, prk0, and YZX0
RiskEngine.sol L2018-L2038
Finding description
The _computeDelayedSwap function in the RiskEngine contract incorrectly calculates collateral requirements for Delayed Swap strategies. Instead of netting the credit leg value against the loan requirement (which would provide capital efficiency for hedged positions), it uses max (loanRequirement, creditValue). This treats the credit position as a liability floor rather than a deduction, causing artificially inflated collateral requirements. When the credit value exceeds the loan requirement, the collateral requirement becomes the full credit value instead of being reduced to a minimal floor.
Root Cause
The root cause is flawed financial logic in the _computeDelayedSwap function. For a hedged delayed swap position (pairing a loan leg with a credit leg), the correct economic treatment should be to subtract the credit value from the loan requirement, with a minimum floor. Instead, the implementation incorrectly treats the credit as an alternative requirement, taking the maximum of the two values. This violates the fundamental principle of netting in risk calculation for offsetting positions.
Original code block has been omitted. View complete submission.
The vulnerable code computes both the loan requirement and the converted credit value, then returns the maximum of the two values. This is incorrect financial logic for a delayed swap where the credit leg should offset the loan requirement. The correct approach would be to subtract the converted credit from the loan requirement (with a minimum floor), providing capital efficiency for the hedged position. The current implementation penalizes users by requiring collateral equal to the full credit value when it exceeds the loan requirement.
Impact
Users with Delayed Swap strategies face artificially inflated collateral requirements, making solvent accounts appear insolvent. This can trigger unfair liquidations where liquidators seize user collateral, causing direct financial loss. The impact is HIGH severity because it leads to direct asset loss through incorrect solvency determinations. The vulnerability affects all users employing Delayed Swap strategies, potentially causing widespread liquidation events and loss of user funds.
Proof of Concept
Runnable PoC (Foundry test):
- PoC file (custom, entire file included):
2025-12-panoptic/test/foundry/poc/H017_DelayedSwap_MaxNotNetting.t.sol - Test:
test_POC_H017_delayedSwap_requirementUsesMax_notNetting
How to run:
cd 2025-12-panoptic
anvil --silent --port 8545 &
forge test --fork-url http://127.0.0.1:8545 \
--match-path test/foundry/poc/H017_DelayedSwap_MaxNotNetting.t.sol \
--match-test test_POC_H017
PoC source (full file):
View detailed Proof of Concept
PoC shared dependency:
File: 2025-12-panoptic/test/foundry/poc/utils/PoCUtils.sol
View detailed Proof of Concept
Netting the credit against the loan legs.
Status: Mitigation confirmed. Full details in reports from Valves, edoscoba, and Nyx.
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 `_computeDelayedSwap` function used `max(loanRequirement, creditValue)` instead of subtracting the credit value from the loan requirement with a minimum floor.
Impact
Users with delayed swap strategies could face inflated collateral requirements, making solvent accounts appear insolvent and potentially causing unfair liquidations and direct financial loss.
What the attacker needed
A delayed swap strategy position
The fix
The issue was fixed by netting the credit against the loan legs.
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.
In a delayed swap, a user has two sides: a loan they owe and a credit they are owed. The correct way to work out how much collateral they need is to subtract the credit from the loan, so the two sides cancel out. The code instead took the larger of the two numbers, which made users look like they needed much more collateral than they really did, so their accounts could be wrongly liquidated.
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.