The collateral that liquidators receive is valued below their initial expectations as a result of the price fall
The liquidation process lacks slippage protection, so if the price of the underlying asset drops between the time a liquidator submits a transaction and its execution, the liquidator receives less collateral than expected. An attacker could exploit this by manipulating the price or timing transactions to cause liquidators to receive reduced collateral.
Originally disclosed on Code4rena
Submitted by pashap9990
Finding Description and Impact
Due to insufficient safeguards against price drops, liquidators receive less collateral than expected from the vault and pool, resulting in financial losses.
-
An agent is established, after which the necessary collateral is deposited into the agent’s vault and collateral pool. The agent is then made publicly accessible.
-
A minter reserves the required collateral and initiates the corresponding payment transaction.
-
The function
MintingFacet::executeMintingis invoked, resulting in the minter receiving fassets. -
The agent executes a decrease transaction on the underlying network without prior notification.
-
An illegal payment is detected, and the challenger submits proof of the illegal payment. As a result, the agent’s status changes to
FULL_LIQUIDATION.Suppose:
- F-asset = FXRP
- 1 XRP = 1 USD
- Vault’s collateral is USDC
- 1 NAT = 1 USD
- Liquidation factor = 1.05
Based on the above assumptions, the liquidator is expected to receive 10,000 USDC and 500 NAT for one lot.
-
The liquidator submits the transaction to the network. However, if the price of XRP decreases to 0.90 USD at the time of execution, the liquidator receives 9,000 USDC and 450 NAT, which is less than anticipated.
Proof of Concept
Apply the git patch provided below and incorporate the following proof of concept into the file AttackScenario.ts.
+++ b/lib/test-utils/actors/TestChainInfo.ts
@@ -59,7 +59,7 @@ export const testChainInfo: Record<'eth' | 'btc' | 'xrp', TestChainInfo> = {
assetSymbol: "XRP",
decimals: 6,
amgDecimals: 6,
- startPrice: 0.53,
+ startPrice: 1,
blockTime: 10,
finalizationBlocks: 10,
underlyingBlocksForPayment: 10,
diff --git a/lib/test-utils/test-settings.ts b/lib/test-utils/test-settings.ts
index 865c696..779a7c9 100644
--- a/lib/test-utils/test-settings.ts
+++ b/lib/test-utils/test-settings.ts
@@ -344,8 +344,8 @@ export async function createMockFtsoV2PriceStore(governanceSettingsAddress: stri
await priceStore.setCurrentPrice(symbol, toBNExp(price, decimals), 0);
await priceStore.setCurrentPriceFromTrustedProviders(symbol, toBNExp(price, decimals), 0);
}
- await setInitPrice("NAT", 0.42);
- await setInitPrice("USDC", 1.01);
+ await setInitPrice("NAT", 1);
+ await setInitPrice("USDC", 1);
await setInitPrice("USDT", 0.99);
for (const ci of Object.values(assetChainInfos)) {
await setInitPrice(ci.symbol, ci.startPrice);
diff --git a/test/integration/assetManager/AttackScenarios.ts b/test/integration/assetManager/AttackScenarios.ts
index 94532e1..0f4353e 100644
--- a/test/integration/assetManager/AttackScenarios.ts
+++ b/test/integration/assetManager/AttackScenarios.ts
@@ -43,7 +43,7 @@ contract(`AssetManager.sol; ${getTestFile(__filename)}; Asset manager integratio
async function initialize() {
commonContext = await CommonContext.createTest(governance);
- context = await AssetContext.createTest(commonContext, testChainInfo.eth);
+ context = await AssetContext.createTest(commonContext, testChainInfo.xrp);
return { commonContext, context };
}
it.only("liquidator-receive-collateral-less-than-expected", async() => {
const agent = await Agent.createTest(context, agentOwner1, underlyingAgent1);
const minter = await Minter.createTest(context, minterAddress1, underlyingMinter1, context.underlyingAmount(1e8));
const liquidator = await Liquidator.create(context, liquidatorAddress1);
// make agent available one lot worth of pool collateral
const requiredCollateral = await agent.requiredCollateralForLots(100);
await agent.depositCollateralsAndMakeAvailable(requiredCollateral.vault, requiredCollateral.pool);
// minter mints
const lots = 100;
const crt = await minter.reserveCollateral(agent.vaultAddress, lots);
const txHash1 = await minter.performMintingPayment(crt);
const minted = await minter.executeMinting(crt, txHash1);
await agent.performPayment("IllegalPayment1", 100);
// challenge agent for illegal payment
const proof = await context.attestationProvider.proveBalanceDecreasingTransaction(txHash1, agent.underlyingAddress);
await context.assetManager.illegalPaymentChallenge(proof, agent.agentVault.address, { from: accounts[1234] });
// liquidator "buys" f-assets
await context.fAsset.transfer(liquidator.address, minted.mintedAmountUBA, { from: minter.address });
// liquidate agent (partially)
console.log("--------------------> XRP price drop Scenario <-----------------------");
let liquidateMaxUBA1 = minted.mintedAmountUBA.divn(lots);
let startBalanceLiquidator1NAT = await context.wNat.balanceOf(liquidator.address);
let startBalanceLiquidator1VaultCollateral = await agent.vaultCollateralToken().balanceOf(liquidator.address);
let snapshotId = await network.provider.send("evm_snapshot", []);
await context.priceStore.setCurrentPrice("FXRP", 90000, 0);
let [liquidatedUBA1, liquidationTimestamp1, liquidationStarted1, liquidationCancelled1] = await liquidator.liquidate(agent, liquidateMaxUBA1);
let endBalanceLiquidator1NAT = await context.wNat.balanceOf(liquidator.address);
let endBalanceLiquidator1VaultCollateral = await agent.vaultCollateralToken().balanceOf(liquidator.address);
console.log("vault collateral recieved amount:%d USDC", (endBalanceLiquidator1VaultCollateral - startBalanceLiquidator1VaultCollateral) /1e18);
console.log("pool collateral recieved amount:%d NAT", (endBalanceLiquidator1NAT - startBalanceLiquidator1NAT) / 1e18);
console.log("liquidatedUBA1:%d FXRP", liquidatedUBA1.toString() / 1e6);
await network.provider.send("evm_revert", [snapshotId]);
console.log("--------------------> Normal Scenario <-----------------------");
liquidateMaxUBA1 = minted.mintedAmountUBA.divn(lots);
startBalanceLiquidator1NAT = await context.wNat.balanceOf(liquidator.address);
startBalanceLiquidator1VaultCollateral = await agent.vaultCollateralToken().balanceOf(liquidator.address);
[liquidatedUBA1, liquidationTimestamp1, liquidationStarted1, liquidationCancelled1] = await liquidator.liquidate(agent, liquidateMaxUBA1);
endBalanceLiquidator1NAT = await context.wNat.balanceOf(liquidator.address);
endBalanceLiquidator1VaultCollateral = await agent.vaultCollateralToken().balanceOf(liquidator.address);
console.log("vault collateral recieved amount:%d USDC", (endBalanceLiquidator1VaultCollateral - startBalanceLiquidator1VaultCollateral) /1e18);
console.log("pool collateral recieved amount:%d NAT", (endBalanceLiquidator1NAT - startBalanceLiquidator1NAT) / 1e18);
console.log("liquidatedUBA1:%d FXRP", liquidatedUBA1.toString() / 1e6);
});
Contract: AssetManager.sol; test/integration/assetManager/AttackScenarios.ts; Asset manager integration tests
--------------------> XRP price drop Scenario <-----------------------
vault collateral recieved amount:9000 USDC
pool collateral recieved amount:450 NAT
liquidatedUBA1:10000 FXRP
--------------------> Normal Scenario <-----------------------
vault collateral recieved amount:10000 USDC
pool collateral recieved amount:500 NAT
liquidatedUBA1:10000 FXRP
✔ liquidator-receive-collateral-less-than-expected (109ms)
1 passing (2s)
Recommended Mitigation Steps
Implementing a safeguard mechanism, such as slippage control, would provide a more robust solution.
Flare commented:
Flare has decided not to fix this issue, as prices from FTSO oracle are updated only every 90 seconds.
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
What the attacker needed
Agent in liquidation status; liquidator holds f-assets; price drop before execution
The fix
The protocol should implement slippage control to allow liquidators to specify a minimum acceptable collateral amount.
How it was found
- An agent is established with collateral deposited and made publicly accessible.
- A minter reserves collateral and performs a minting payment, receiving fassets.
- The agent performs an illegal payment on the underlying network.
- A challenger submits proof of the illegal payment, setting the agent's status to FULL_LIQUIDATION.
- The liquidator submits a liquidation transaction.
- If the price of the underlying asset drops before execution, the liquidator receives less collateral than expected.
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.
When a loan is liquidated, the liquidator pays off the debt and receives collateral. If the collateral's value drops suddenly before the transaction is processed, the liquidator gets less than they bargained for. This report shows that the system doesn't protect liquidators from such price changes.
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.