Skip to content

Daily withdrawal limit (#4457) uses gross accounting: deposit→withdraw cycling starves all users' withdrawals #4471

Closed

Description

@PastaPastaPasta

Summary

The daily withdrawal limit introduced in #4457 (PV14) uses gross outflow
accounting: every withdrawal spends the daily budget, and deposits (asset locks)
never refill it. This means an attacker can cycle their own coins
deposit → withdraw to exhaust the entire day's withdrawal capacity for every
user, indefinitely, for the cost of only transaction fees — even though the pool
of credits never actually shrinks.

#4457 correctly defends the limit from being raised by an inflated total (the
24h-lagged base). It does not defend the budget from being consumed by
self-cancelling flow. Those are two different attacks; this issue is the second.

Reproduction

Self-contained test that passes against the merged code on v4.2-dev
(#4457 = fa9fd05abb). A passing run is the proof: if deposits flowed back into
the budget, the final available() == 0 assertion would fail.

Gist (repro instructions + test + patch):
https://gist.github.com/PastaPastaPasta/561a88e1b54163b98bf719769cd182da

git checkout v4.2-dev
git apply withdrawal-net-proof.patch    # appends the test to the #4457 test module
cargo test -p drive --features full --lib deposit_then_withdraw_cycling
# => ...deposit_then_withdraw_cycling_consumes_the_whole_budget_and_deposits_restore_nothing ... ok

Every mutating step in the test is the real production call:

  • deposit (asset lock) → add_to_system_credits
    (SystemOperationType::AddToSystemCredits, address_funding_from_asset_lock_transition.rs);
  • pool the withdrawal → add_enqueue_untied_withdrawal_transaction_operations
    (WithdrawalOperationType::ReserveWithdrawalAmount), exactly what
    pool_withdrawals_into_transactions_queue does after checking available();
  • execute the withdrawal → remove_from_system_credits.

Trace: Platform holds 20,000 Dash → a day later daily_maximum = 15% = 3,000,
available() = 3,000. Attacker deposits 3,000 and withdraws it. Result:

  • TOTAL_SYSTEM_CREDITS ends at exactly 20,000 — nothing left Platform net;
  • available() == 0 — the whole day's budget is gone for every other user;
  • after recording history, tomorrow's daily_maximum is still 3,000 — the cycle
    is invisible to the day-old base, so the same recycled coins zero it out again,
    every day.

Why the "deposits get added back in" intuition doesn't hold

Deposits do raise TOTAL_SYSTEM_CREDITS, which raises daily_maximum — but only
a day later, and only if the deposit is still there when the 24h-lagged
reference is sampled. A same-day deposit→withdraw cycle cancels itself out of the
history, so it never reaches the base. "Added back in" is true for the base,
tomorrow, if held; it is never true for available(), today — which is the
quantity that blocks users. The only three touchers of the budget are
ReserveWithdrawalAmount (add, on pooling), the 25h expiry cleanup (remove), and
calculate_current_withdrawal_limit (read); no asset-lock path touches it.

Impact

Proposed fix

Make the budget net of L1-verifiable inflows only:

available = daily_maximum + asset_lock_inflows_in_last_24h − withdrawals_in_last_24h

This is algebraically the rule "the total may never drop below (100−percent)% of
the total held a day ago" — it limits the drop in the pool level, not the
flow through the pool. Properties:

  • honest churn (deposit X, withdraw X) nets to zero and consumes no budget →
    unlimited legitimate flow;
  • the griefing cycle self-cancels and blocks nobody;
  • the inflation guardrail is preserved: asset locks are chain-locked coins
    Core validated, so a Platform minting bug cannot forge inflow to raise the
    budget; the worst case still drains at most percent/day. The 24h-lagged base
    from feat(drive)!: make the daily withdrawal limit 15% of the total credits held a day ago #4457 stays exactly as-is.

Implementation is small and mirrors machinery #4457 already added: one more 24h
rolling sum of asset-lock inflows, subtracted alongside the existing
WITHDRAWAL_TRANSACTIONS_SUM_AMOUNT_TREE_KEY sum.

Core side: the v24 credit-pool rule (src/evo/creditpool.cpp,
ConstructCreditPool) counts only unlocks in its window and will become the new
bottleneck under heavy honest flow. It needs the same net treatment — allow
unlocks as long as the credit-pool balance stays above (100−percent)% of its
value one window ago. DEPLOYMENT_V24 is not activated on any network yet, so
this can land before activation without an additional fork.

Related

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions