Skip to content

feat(rs-dapi): refuse shielded broadcasts from addresses that keep sending invalid proofs - #5001

Merged
QuantumExplorer merged 1 commit into
v4.2-devfrom
claude/proof-slot-congestion-831fc9
Sep 25, 2026
Merged

QuantumExplorer merged 1 commit into
v4.2-devfrom
claude/proof-slot-congestion-831fc9

Conversation

@QuantumExplorer

@QuantumExplorer QuantumExplorer commented Sep 25, 2026 •

Copy link
Copy Markdown
Member

Issue being fixed or feature implemented

A shielded transition proves who is spending only through its Halo 2 proof. When that proof does not verify, Drive's CheckTx refuses the transition without charging anyone (there is no proven note to take a fee from), but the verification has already taken one of the node's CheckTx proof slots (1 to 4 per node). Nothing limits how many such transitions one client sends, so a single sender can keep a node's slots busy, and honest shielded transitions on that node are refused with "check tx verification capacity is temporarily unavailable" until it stops.

Drive cannot tell who sent a transition; DAPI can. This PR meters proof failures per client address in DAPI, before Drive does any work.

What was done?

  • New ShieldedProofFailureBudget in packages/rs-dapi/src/services/platform_service/shielded_proof_failure_budget.rs, held by PlatformServiceImpl.
  • broadcastStateTransition now:
    1. decodes the transition and counts its Orchard actions (all eight shielded transition types; every other type passes through unmetered),
    2. reserves that count for the client address before calling Tenderdash,
    3. keeps the charge only when Drive answers InvalidShieldedProofError (40902). Any other answer, including Drive's busy refusal, gives it back. A request whose client disconnects mid-broadcast is charged, since Drive may already have verified it.
  • An address over its allowance is refused with RESOURCE_EXHAUSTED and a ratelimit-reset header. That is the header Envoy's rate limiter already sends, so rs-dapi-client stops using this node for that long and retries on another one.

Limits, per address and per node (constants in the module):

Failed actions allowed outstanding 4 (two usual 2-action bundles)
Drain one failed action every 30 s
After a failure one broadcast at a time, only while the failures plus that bundle fit the allowance, so an address that keeps failing gets 2 actions a minute
Actions in flight with no failures one largest bundle (max_shielded_transition_actions, 16)
Tracked addresses 16,384; when full, the idle address with the least debt makes room

Client address: the last x-forwarded-for entry, which the gateway appends (use_remote_address: true); earlier entries come from the client and are ignored. The header is trusted only from a loopback or private peer, which is where the gateway sits; any other peer is taken to be the client. IPv6 addresses are grouped by /48, so one allocation cannot rotate through its own /64s.

Before / after

An address sending 2-action ShieldedTransfer bundles whose proofs do not verify:

Before
  #1, #2, #3, ...  every one reaches Drive and takes a proof slot
                   -> InvalidShieldedProofError (40902)

After
  #1  -> Drive verifies  -> 40902
  #2  -> Drive verifies  -> 40902
  #3  -> refused by DAPI -> RESOURCE_EXHAUSTED, ratelimit-reset: 60   (Drive does no work)
  60 s later: one more bundle is admitted, then the address is refused for another minute

A 16-action bundle whose proof does not verify:

Before: Drive verifies -> 40902; the next one is admitted straight away
After:  Drive verifies -> 40902; the address is refused until all 16 actions drain (8 min)

A wallet whose proofs verify:

Before: admitted
After:  admitted and never charged; up to 16 actions in flight at once from one address
        (a 17th concurrent action gets RESOURCE_EXHAUSTED, ratelimit-reset: 1)

Notes for reviewers

  • Node-local admission policy in DAPI only: no Drive, protocol or consensus change.
  • An operator who puts a load balancer in front of the gateway makes every client look like the balancer's address; Envoy would then need xff_num_trusted_hops. Users behind one shared address (CGNAT) share one allowance; a refusal only covers shielded broadcasts on this node, and the SDK moves to another node.
  • The limits are constants, not dashmate settings yet, and there are no metrics for charges and refusals yet.
  • This slows a sender with few addresses; it does not stop one with many.

How Has This Been Tested?

  • cargo test -p rs-dapi --lib: 327 passed, 18 of them new. They cover: verified proofs are never refused; refusal after two failed bundles with the right retry time; exactly one bundle a minute for an address that keeps failing (10 simulated minutes); one broadcast at a time after a failure; the in-flight cap; a failed largest bundle waiting for a full drain; a dropped reservation being charged; an oversized bundle charged as 16 actions; eviction when the table is full; address extraction (gateway-appended entry, header ignored from a public peer, IPv6 /48, IPv4-mapped IPv6); action counting; the refusal status and its whole-second ratelimit-reset; the 40902 code pinned against dpp.
  • cargo fmt -p rs-dapi --check and cargo clippy -p rs-dapi --all-targets: clean.
  • Not yet run end to end against a local network.

Breaking Changes

None. This is node-local DAPI policy; nothing nodes have to agree on changes.

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have added "!" to the title and described breaking changes in the corresponding section if my code contains any
  • I have made corresponding changes to the documentation if needed
  • If I added or changed GroveDB structure, I described it in the area's structure.rs, regenerated grovedb-structure.json, and checked the structure viewer link posted on this pull request

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

🤖 Generated with Claude Code

PR Hygiene · 356bdda

  • Bots — coderabbitai not yet · thepastaclaw not yet — /skip-bots proceeds without the ones not yet reported
  • Self-review — post /self-reviewed once the bots are done
  • Within your 5 open PRs
  • Build green
  • Approvals
    • rust-dapi (packages/rs-dapi/src/services/platform_service/broadcast_state_transition.rs, packages/rs-dapi/src/services/platform_service/mod.rs, packages/rs-dapi/src/services/platform_service/shielded_proof_failure_budget.rs) — lklimek or shumkov

When every box is checked the PR Hygiene check passes and this can merge.

…nding invalid proofs

Drive refuses a shielded transition whose Orchard proof does not verify
without charging anyone, yet each one still takes one of the node's few
CheckTx proof slots. DAPI now meters those failures per client address:
a broadcast with Orchard actions reserves its action count before it
reaches Tenderdash, keeps the charge only when Drive answers
InvalidShieldedProofError (40902), and an address over its allowance is
refused with RESOURCE_EXHAUSTED plus ratelimit-reset, so the SDK tries
another node.

An address may have 4 failed actions outstanding (two usual bundles);
they drain one every 30 s. After a failure it gets one broadcast at a
time, so a failing address is held to 2 actions a minute per node. An
address with no failures may have one largest bundle's worth (16
actions) in flight. The client address is the last x-forwarded-for
entry the gateway appends, trusted only from a private peer; IPv6 is
grouped by /48.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@coderabbitai

coderabbitai Bot commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

Next included review available in 5 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Repository: dashpay/platform/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 3ac0727b-faf3-4e21-8eaf-2a44c2256117

📥 Commits

Reviewing files that changed from the base of the PR and between d76a0f8 and 356bdda.

📒 Files selected for processing (3)
  • packages/rs-dapi/src/services/platform_service/broadcast_state_transition.rs
  • packages/rs-dapi/src/services/platform_service/mod.rs
  • packages/rs-dapi/src/services/platform_service/shielded_proof_failure_budget.rs

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added this to the v4.2.0 milestone Sep 25, 2026
@github-actions github-actions Bot added the waiting-bots Waiting for the review bots to report on this head label Sep 25, 2026
@thepastaclaw

thepastaclaw commented Sep 25, 2026 •

Copy link
Copy Markdown
Collaborator

🕓 Queued for automated review — 5th in line, estimated start in ~0.9 h (commit 356bdda)
Estimated review time once started: ~40 min (two-phase automated review; median of recent runs).

  • Request priority review — click to move this review to the front of the queue.

@QuantumExplorer QuantumExplorer left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed

@QuantumExplorer
QuantumExplorer merged commit 5ac99ad into v4.2-dev Sep 25, 2026
20 of 21 checks passed
@QuantumExplorer
QuantumExplorer deleted the claude/proof-slot-congestion-831fc9 branch September 25, 2026 21:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

waiting-bots Waiting for the review bots to report on this head

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants