Skip to content

fix(ICRC_Rosetta): DEFI-3056: bound amount length and ledger method args size - #12095

Merged
mbjorkqvist merged 2 commits into
masterfrom
mathias/DEFI-3056-rosetta-bound-amount-length
Nov 13, 2026
Merged

mbjorkqvist merged 2 commits into
masterfrom
mathias/DEFI-3056-rosetta-bound-amount-length

Conversation

@mbjorkqvist

Copy link
Copy Markdown
Contributor

Why

The ICRC Rosetta Construction API builds the ledger method arguments from caller-provided operations and copies them into every envelope of the unsigned transaction. The amounts in those operations (amount, fee, allowance, expected_allowance) are parsed without any length limit. This is a follow-up to #11886, which limits the memo.

What

  • Amount values longer than 78 characters (enough for any u256), not counting a leading -, are rejected before parsing. The check is in rosetta_core. ICRC-1 and ICP amounts are well within this limit.
  • /construction/payloads rejects ledger method arguments larger than 4 KiB before building the envelopes. This bounds all fields, including any added in the future. The largest supported arguments, with a 1 KiB memo, fit well within it.

🤖 Generated with Claude Code

…rgs size

- Reject `Amount` values longer than 78 characters (enough for any u256) before parsing them
  into a `Nat` in `rosetta_core`.
- Reject ledger method arguments larger than 4 KiB in `/construction/payloads` before they are
  copied into the envelopes.

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

There are no active review issues for the change adding Construction API input-size limits.

No open issues 🎉

What changed in this PR

Adds size limits to reduce memory amplification in the ICRC Rosetta Construction API, extending the memo protection introduced in #11886.

Changes:

  • Rejects amount strings longer than 78 characters, excluding a leading -, before conversion to Nat.
  • Rejects encoded ledger method arguments larger than 4 KiB before copying them into transaction envelopes.
  • Adds boundary and oversized-input tests and documents the limits in the changelog.
File Description
rs/​rosetta-api/​icrc1/​src/​construction_api/​utils.rs Validates argument size before envelope creation and tests accepted and oversized arguments.
rs/​rosetta-api/​icrc1/​src/​common/​constants.rs Defines the 4 KiB encoded-argument limit.
rs/​rosetta-api/​icrc1/​CHANGELOG.md Records the new amount and argument-size limits.
rs/​rosetta-api/​common/​rosetta_core/​src/​objects.rs Bounds shared Amount-to-Nat conversion and adds length-validation tests.

Review effort: Balanced

@zeropath-ai

zeropath-ai Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

✅ No security or compliance issues detected. Reviewed everything up to 089a960.

Security Overview
Detected Code Changes
Change Type Relevant files
Enhancement ► rs/rosetta-api/common/rosetta_core/src/objects.rs
      Add MAX_AMOUNT_VALUE_LENGTH constant and enforce max length in TryFrom for Nat; update conversion logic with length check and error context
► rs/rosetta-api/icrc1/src/construction_api/utils.rs
      Validate canister method args size before usage; import MAX_CANISTER_METHOD_ARGS_BYTES
Bug Fix ► rs/rosetta-api/icrc1/src/common/constants.rs
      Add MAX_CANISTER_METHOD_ARGS_BYTES constant (4 KiB) to cap candid-encoded ledger method arguments
Enhancement ► rs/rosetta-api/icrc1/src/construction_api/utils.rs
      Emit validation for canister method args size in multiple call paths; use MAX_CANISTER_METHOD_ARGS_BYTES in validations
Enhancement ► rs/rosetta-api/icrc1/src/construction_api/utils.rs
      Ensure size validation is invoked in handle_construction_payloads and related paths; minor formatting consistency in ingress calculation and related areas
Enhancement ► rs/rosetta-api/icrc1/src/construction_api/utils.rs
      Add tests and test utilities for max length handling and oversized canister method args; include new tests for parsing, hashing, and construction payloads behavior with length limits

- Also bound the size of client-supplied ledger method args in
  /construction/parse, /construction/hash and /construction/submit.
- Avoid an underflow when deriving ingress_start in /construction/parse.
- Test the size check through handle_construction_payloads.

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 were identified for the Construction API input-limit and underflow-hardening changes.

No open issues 🎉

Review effort: Balanced

@mbjorkqvist
mbjorkqvist added this pull request to the merge queue Nov 13, 2026
Merged via the queue into master with commit 14d3bdb Nov 13, 2026
42 checks passed
@mbjorkqvist
mbjorkqvist deleted the mathias/DEFI-3056-rosetta-bound-amount-length branch November 13, 2026 16:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants