Skip to content

fix(transaction): validate DataEntry fields for XDR encoding limits - #870

Merged
Just-Bamford merged 3 commits into
Sorokit:mainfrom
Gezziy:silent-truncation
Oct 20, 2026
Merged

Just-Bamford merged 3 commits into
Sorokit:mainfrom
Gezziy:silent-truncation

Conversation

@Gezziy

@Gezziy Gezziy commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

closes #762

Summary of Changes

  • XDR Limit Validation: Enforces the Stellar XDR 64-byte boundary for account data entries (string64 for keys, opaque dataValue<64> for values).
  • Accurate UTF-8 & Binary Sizing: Implemented getDataByteLength using TextEncoder for UTF-8 strings (avoiding UTF-16 code unit mismatch where emojis and multi-byte characters exceed 64 bytes despite small string length) and native .byteLength for Uint8Array / Buffer.
  • Informative Error Messages: Formatted validation errors to report both the limit and the actual byte count:
    • "Data entry value exceeds maximum limit of 64 bytes (actual: X bytes)."
    • "Data entry key exceeds maximum limit of 64 bytes (actual: X bytes)."
  • Fail-Fast Early Checking: Key and value checks run upfront before initiating Horizon loadAccount RPC calls.
  • SDK Compatibility: Automatically adapts Uint8Array payloads to Buffer when building Stellar SDK operations.
  • API Ergonomics & Aliases: Added setData and deleteData aliases in src/transaction/, ComposeBuilder, and createSorokitClient.ts.
  • Test Suite: Added 28 comprehensive test cases in src/tests/dataEntry.test.ts covering ASCII limits, multi-byte UTF-8 emojis, binary buffers, compose workflows, and client methods.

Reason for Changes

Resolves issue #762. Previously, setting account data via setData did not validate value byte length against XDR limits. Oversized values resulted in silent on-chain truncation or opaque Horizon ingestion rejections (op_malformed). Early client-side validation prevents data corruption and unnecessary network overhead.

…orokit#762)

- Validate key and value lengths against Stellar XDR 64-byte limits
- Support string, Uint8Array, and Buffer DataEntryValue inputs
- Compute exact UTF-8 byte length to prevent multi-byte silent overflow
- Return clear validation error messages with limit and actual byte size
- Add setData and deleteData aliases across transaction, compose, and client
- Add comprehensive unit and integration test coverage
@drips-wave

drips-wave Bot commented Oct 20, 2026

Copy link
Copy Markdown

@Gezziy Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@Just-Bamford
Just-Bamford merged commit 0f4eb3e into Sorokit:main Oct 20, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DataEntry fields are not validated for XDR encoding limits — oversized values cause silent truncation

2 participants