Repository navigation
Conversation
There was a problem hiding this comment.
🟢 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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, insrc/xdr/values/xdr-value.ts. It applies totoXdr(),fromXdr(),validateXdr()and their deprecated uppercase forms, and todecodeStream(),decodeArray()andencodeArray()when the caller passes nomaxDepth.A new unit test builds the deepest transaction stellar-core accepts, wraps it in a
LedgerCloseMetaV2and aLedgerCloseMetaBatch, and round-trips all three. It also checks that nesting far past that still throwsXdrError.Why
stellar-core 30 accepts an
InvokeHostFunctiontransaction whose auth entry nests 493 invocations. js-xdr counts each struct, union and array as a level, so one invocation costs 3. Inside aLedgerCloseMetaBatchthat transaction needs depth 1501, andLedgerCloseMetaBatch.fromXDR()threwmax 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
i128argument on the deepest. It needs 1503 in a batch and 1501 in a bareLedgerCloseMeta, soLedgerCloseMeta.fromXDR()failed too.TransactionEnvelopeLedgerCloseMetaLedgerCloseMetaBatchi128arg on the deepestScValvectors in the call argsScValmaps in the call args1550 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.