Skip to content

fix(ICP_Rosetta): DEFI-3058: bound Candid decoding of envelope args in the construction API - #12108

Draft
mbjorkqvist wants to merge 2 commits into
masterfrom
mathias/DEFI-3058-icp-rosetta-bounded-candid-decoding
Draft

mbjorkqvist wants to merge 2 commits into
masterfrom
mathias/DEFI-3058-icp-rosetta-bounded-candid-decoding

Conversation

@mbjorkqvist

Copy link
Copy Markdown
Contributor

Why

ICP Rosetta decodes the Candid arguments of client-supplied call envelopes in construction/parse and construction/submit without a skipping quota, so the decoding work depends on the lengths declared in the Candid type table rather than on the size of the arguments. The construction handlers also run synchronously on the actix workers, so slow requests can hold up the other endpoints. This is the ICP Rosetta counterpart of #12106.

What

  • Decode the envelope arguments with a skipping quota of 10,000, the same quota the ic-cdk endpoint macros apply to the canister methods being called.
  • Run the construction endpoints that parse or build transactions (parse, hash, combine, payloads) on the blocking thread pool.
  • Add tests for arguments that exceed the quota through a trailing argument, an extra record field and a mismatched opt field.

🤖 Generated with Claude Code

…n the construction API

Decode the canister method arguments of client-supplied envelopes in
construction/parse and construction/submit with a Candid skipping quota, the
same one the ic-cdk endpoint macros apply to the canister methods being
called, so that the decoding work is bounded regardless of the lengths
declared in the type table. Also run the construction endpoints that parse or
build transactions on the blocking thread pool, so a slow request cannot
occupy the actix workers serving the other endpoints.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

A critical denial-of-service path remains because the skipping quota does not bound known-field decoding, allowing small inputs to trigger excessive CPU and memory use before rejection.

1 open issue
What changed in this PR

This PR hardens ICP Rosetta’s construction API against excessive Candid decoding work, following the approach used for ICRC Rosetta in #12106.

Changes:

  • Apply a shared 10,000-unit skipping quota when decoding client-supplied Candid envelope arguments.
  • Move parse, hash, combine, and payloads processing to the blocking thread pool.
  • Add regression tests for oversized skipped values and acceptance of small unexpected values.
File Description
rs/​rosetta-api/​icp/​src/​rosetta_server.rs Offloads four construction handlers to the blocking pool.
rs/​rosetta-api/​icp/​src/​request.rs Applies quota-controlled decoding during submit request conversion.
rs/​rosetta-api/​icp/​src/​request_handler/​construction_parse.rs Updates argument decoding and adds quota regression tests.
rs/​rosetta-api/​icp/​src/​convert.rs Introduces the shared decoder and skipping quota.
rs/​rosetta-api/​icp/​CHANGELOG.md Documents the construction API hardening.

Review effort: Balanced

Comment thread rs/rosetta-api/icp/src/convert.rs Resolved
…elope args

The skipping quota only bounds values that are skipped. A long vector of
records whose fields are all optional, e.g. in `SetFollowing`, takes no bytes
on the wire and is decoded rather than skipped. Also set a decoding quota of
100,000, as the NNS canisters do for `http_request`, and check that the
largest legitimate argument stays well within it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues block approval of the construction API hardening.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

This branch has not been deployed

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants