Skip to content

fix(xdr): raise the encode and decode depth limit to 1550 - #1902

Open
Ryang-21 wants to merge 2 commits into
mainfrom
fix/xdr-decode-depth-1901
Open

Ryang-21 wants to merge 2 commits into
mainfrom
fix/xdr-decode-depth-1901

Conversation

@Ryang-21

Copy link
Copy Markdown
Contributor

Fixes #1901.

What

Every XDR encode and decode in the SDK now allows 1550 levels of nesting, up from the js-xdr default of 1500. The limit is one constant, MAX_XDR_DEPTH, in src/xdr/values/xdr-value.ts. It applies to toXdr(), fromXdr(), validateXdr() and their deprecated uppercase forms, and to decodeStream(), decodeArray() and encodeArray() when the caller passes no maxDepth.

A new unit test builds the deepest transaction stellar-core accepts, wraps it in a LedgerCloseMetaV2 and a LedgerCloseMetaBatch, and round-trips all three. It also checks that nesting far past that still throws XdrError.

Why

stellar-core 30 accepts an InvokeHostFunction transaction whose auth entry nests 493 invocations. js-xdr counts each struct, union and array as a level, so one invocation costs 3. Inside a LedgerCloseMetaBatch that transaction needs depth 1501, and LedgerCloseMetaBatch.fromXDR() threw max recursion depth 1500 exceeded. A reader of galexie data lake files failed on that file.

The issue reports 1501. I ran more shapes against a local stellar-core 30.0.0 (protocol 30) and found a deeper one that core still accepts: 493 invocations with one i128 argument on the deepest. It needs 1503 in a batch and 1501 in a bare LedgerCloseMeta, so LedgerCloseMeta.fromXDR() failed too.

Shape core accepts TransactionEnvelope LedgerCloseMeta LedgerCloseMetaBatch
493 auth invocations 1489 1499 1501
493 auth invocations, i128 arg on the deepest 1491 1501 1503
491 auth invocations under a fee bump 1486 1496 1498
246 nested ScVal vectors in the call args 995 1005 1007
197 nested ScVal maps in the call args 1193 1203 1205

1550 leaves room above 1503 for shapes I did not test. It cannot go much higher: on Node 22 a decode, class build, encode and toJson() of a nested auth chain overflows the call stack near depth 1870.

The limit is set in the SDK and not in js-xdr, so the SDK does not depend on a js-xdr release.

@github-project-automation github-project-automation Bot moved this to Backlog (Not Ready) in DevX Nov 14, 2026

Copilot AI left a comment

Copy link
Copy Markdown

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 remain for the XDR nesting-limit update.

No open issues 🎉

What changed in this PR

Raises the SDK’s default XDR nesting limit from 1500 to 1550 so it can process deeply nested transactions accepted by stellar-core, including those wrapped in ledger metadata batches.

Changes:

  • Centralizes the depth limit and applies it across XDR encoding, decoding, validation, and stream/array helpers.
  • Adds regression tests for deep transaction and ledger round-trips, while checking that excessive nesting remains rejected.
  • Documents the fix in the changelog.
File Description
test/​unit/​xdr/​max_depth.test.ts Tests deep XDR round-trips and rejection beyond the limit.
src/​xdr/​values/​xdr-value.ts Applies the shared 1550-level default while preserving explicit array depth options.
CHANGELOG.md Records the nesting-limit increase and affected ledger decoding behavior.

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

None yet

Projects

Status: Backlog (Not Ready)

Development

Successfully merging this pull request may close these issues.

LedgerCloseMetaBatch.fromXDR throws "max recursion depth 1500 exceeded" on a ledger that stellar-core 30 produced

2 participants