#37893 [SC-Insight] inflation attack in xalgo

#37893 [SC-Insight] Inflation Attack in xAlgo

Submitted on Dec 18th 2024 at 11:43:02 UTC by @Blockian for Audit Comp | Folks: Liquid Staking

  • Report ID: #37893

  • Report Type: Smart Contract

  • Report severity: Insight

  • Target: https://github.com/Folks-Finance/algo-liquid-staking-contracts/blob/8bd890fde7981335e9b042a99db432e327681e1a/contracts/xalgo/consensus_v2.py

  • Impacts:

    • Direct theft of any user funds, whether at-rest or in-motion, other than unclaimed yield

Description

Folks Finance Liquid Staking Bug Report

Inflation Attack in xAlgo

Description

The liquid staking contract in Folks Finance is vulnerable to an inflation attack, allowing malicious actors to inflate xAlgo value by donating Algo to a proposer. This flaw enables attackers to exploit the system and steal deposits from other users.

Root Cause Analysis

The vulnerability stems from how xAlgo minting is calculated in the immediate_mint and claim_delayed functions.

immediate_mint function:

claim_delayed function:

In both cases, when algo_balance equals zero, xAlgo can be minted at a 1:1 ratio with Algo. For example, if a user supplies 1 Algo, they can mint 1 xAlgo.

An attacker exploits this by donating Algo to a proposer after minting 1 xAlgo for themselves, which increases the rewards pool. Since this rewards Algo is factored into the algo_balance calculation:

The inflated algo_balance results in disproportionate xAlgo minting. Consequently, attackers can steal funds from other users by using the burn mechanism.

Example

  1. User 0 deposits 1 Algo and receives 1 xAlgo.

  2. User 0 donates 50 Algo, artificially inflating the value of xAlgo.

  3. User 1 deposits 100 Algo and receives only 1 xAlgo due to the inflated value, which is a rounded down amount.

  4. User 0 withdraws their entire balance, taking 75 Algo (stealing 25 Algo from User 1).

Why is in interesting to Folks Finance on Algorand?

In Ethereum, such attacks are more prominent due to frontrunning risks. However, in Algorand this is less of an issue, making the inflation possible but the attack a bit tougher to perform.

The more interesting vector lies in the delayed_mint mechanism:

  • When using delayed_mint, xAlgo minting is postponed, allowing attackers to monitor exact deposits and exploit the minting process without the need of frontrunning.

  • Since claim_delayed_mint can be called by anyone, attackers can time their actions with precision and even automate the exploit.

Exploit Process (Using delayed_mint):

  1. Victim performs a delayed mint with 100 Algo.

After 320 rounds, xAlgo is available to mint, allowing the attacker to intervene: 2. Attacker mints 1 Algo, receiving 1 xAlgo. 3. Attacker donates 50 Algo, inflating xAlgo value. 4. Attacker calls claim_delayed_mint for the victim, forcing them to mint only 1 xAlgo. 5. Attacker burns their 1 xAlgo, stealing funds from the victim.

Steps 2-5 can be performed atomically in a single transaction, ensuring minimal risk for the attacker.

Severity and Impact

This vulnerability is critical, as it allows attackers to steal user funds with minimal risk, undermining the protocol's integrity and user trust.

Proposed Solutions

  1. Minimum xAlgo Mint Threshold: Implement a minimum threshold for xAlgo minting to prevent small deposits from manipulating the system.

  2. Minimum Algo Deposit Requirement: Introduce a minimum deposit amount to reduce the attack surface.

  3. Initial Contract Deposit: Mint dead xAlgo to the contract and have it act as the first depositor to ensure proper proportionality and mitigate inflation risks.

By implementing these fixes, the protocol can effectively mitigate this vulnerability and safeguard user funds.

Proof of Concept

POC

Run this test file, the IMMUNEFI POC test is the main test to watch

Last updated

Was this helpful?