Skip to content
Smart contracts Audit finding Intermediate

Unchecked approve( ) return causes permanent fund loss in UDA.sol

The contract ignores the return value of ERC20.approve() when initialising a deposit address. With tokens that return false instead of reverting, the approval silently fails, the contract is marked initialised, and the deposited funds become permanently locked because the HTLC cannot transfer them.

barah Follow with 0xDemon, 0xFBI and 7 others

Originally disclosed on Code4rena

Submitted by barah, also found by 0xDemon, 0xFBI, 0xGutzzz, fullstop, holtzzx, makarov, NexusAudits, rox_k, and topenga

swap/UDA.sol #L38

Finding description

The UniqueDepositAddress.initialize() function at line 38 ignores the return value of ERC20.approve():

function initialize() public initializer {
    // ... parameter extraction ...

    HTLC(_addressHTLC).token().approve(_addressHTLC, amount);  // ❌ Return value ignored

    HTLC(_addressHTLC).initiateOnBehalf(
        refundAddress, redeemer, timelock, amount, secretHash, destinationData
    );
}

Root Cause

Non-standard ERC20 tokens (USDT, BNB, etc.) return false instead of reverting when approve() fails. The current implementation does not verify this return value, allowing execution to continue even when approval fails.

Impact

When a user deposits tokens into the UDA and approve() silently fails:

  1. The contract marks itself as initialized.
  2. The allowance remains at 0.
  3. initiateOnBehalf() executes but HTLC cannot transfer tokens.
  4. User funds become permanently locked with no recovery mechanism.

Recommended mitigation steps

The contract already imports SafeERC20 but doesn’t use it for the critical approve() call. Apply one of these fixes:

function initialize() public initializer {
    // ... parameter extraction ...

    //  Use SafeERC20 that's already imported
    IERC20(HTLC(_addressHTLC).token()).safeApprove(_addressHTLC, amount);

    HTLC(_addressHTLC).initiateOnBehalf(
        refundAddress, redeemer, timelock, amount, secretHash, destinationData
    );
}

This fix is recommended as it provides comprehensive protection against all ERC20 edge cases and maintains consistency with the contract’s existing use of SafeERC20 in the recover() functions (lines 59, 106).

Proof of Concept

This PoC demonstrates how the unchecked approve() return value leads to permanent fund loss with non-standard ERC20 tokens like USDT.

View detailed Proof of Concept

Running the PoC:

  1. Navigate to project root: cd evm/
  2. Install dependencies (if needed): forge install foundry-rs/forge-std --no-commit
  3. Run the complete exploit: forge test --match-contract ApproveVulnerabilityPOC -vvv
  4. Run with detailed traces: forge test --match-test testPOC_ApproveFailsSilently -vvvv

Expected Output

EXPLOIT: Complete Fund Loss

  1. User deposited: 10000 USDT

    • UDA Balance: 10000000000
    • Allowance: 0
  2. USDT approve() will return false (real USDT behavior)

  3. Calling initialize()...

    • initialize() completed: SUCCESS
    • Contract initialized: true
    • Allowance after init: 0
  4. VULNERABILITY CONFIRMED:

    • initialize() succeeded
    • But allowance = 0 (approve failed silently)
    • Contract marked as initialized
  5. Attempting to withdraw funds…

    • Withdrawal FAILED: Insufficient allowance

RESULT: 10,000 USDT PERMANENTLY LOCKED

  • Final UDA Balance: 10000 USDT
  • User Loss: $10,000 USD

Trace Analysis (with -vvvv):

[37060] VulnerableUDA::initialize()
  ├─ [549] MockUSDT::balanceOf(VulnerableUDA)
  │   └─ ← 10000000000
  ├─ [573] MockUSDT::approve(MockHTLC, 10000000000)
  │   └─ ← false  ⚠️ RETURNS FALSE - NOT DETECTED!
  └─ ← [Stop]  ❌ Continues execution despite failure

[31720] MockHTLC::withdrawFromUDA(VulnerableUDA, 10000000000)
  ├─ [2805] MockUSDT::transferFrom(VulnerableUDA, user, 10000000000)
  │   └─ ← revert: Insufficient allowance  ❌ FUNDS LOCKED
  └─ ← revert: Insufficient allowance

Key Evidence:

  • approve() returns false but no revert occurs.
  • Allowance remains 0: Despite “successful” initialization.
  • Withdrawal fails: HTLC cannot access funds.
  • No recovery: Contract marked as initialized, blocking re-initialization.

This PoC conclusively demonstrates that 10,000 USDT ($10,000 USD) becomes permanently locked due to the unchecked return value at line 38 of UDA.sol.


The original report as published on Code4rena, by barah. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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 calls ERC20.approve() without checking its boolean return value, so a silent failure is treated as success.

Impact

Deposited funds become permanently locked with no recovery mechanism, because the contract is marked initialised and cannot be re-initialised.

What the attacker needed

Token returns false on failed approve; user deposits into the UDA

The fix

The approve call should use SafeERC20's safeApprove, which is already imported, so a failed approval reverts.

How it was found

  1. A user deposits tokens into the UDA contract.
  2. The token's approve() call returns false instead of reverting.
  3. initialize() completes and marks the contract as initialised.
  4. The allowance stays at zero, so the HTLC cannot transfer the tokens.
  5. A withdrawal attempt fails with an insufficient allowance error.

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.

Some tokens, like USDT, do not crash when an approval fails; they just quietly return 'false'. This contract never checks that answer, so it carries on as if the approval worked. The deposit is then stuck because the other contract was never given permission to move the tokens.

What is Smart contracts?

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.

Similar reports

View all

Same bug class and techniques, clearest first.

Smart contract vulnerabilities

The lesson behind this report.

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.