Skip to content

fix(serializer,core): align single-byte wire widths, register/extension bounds, and selection checks - #243

Open
a-shannon wants to merge 1 commit into
fleet-sdk:masterfrom
a-shannon:fix/codec-parity-and-selection-hardening
Open

a-shannon wants to merge 1 commit into
fleet-sdk:masterfrom
a-shannon:fix/codec-parity-and-selection-hardening

Conversation

@a-shannon

Copy link
Copy Markdown

Summary

This PR aligns several @fleet-sdk/serializer binary codec widths and bounds with SigmaState and hardens @fleet-sdk/core coin selection and minting validation:

  1. Box token & register counts (packages/serializer/src/serializers/boxSerializer.ts)

    • Encode and decode box token counts and additional register counts as single unsigned bytes (UByte), matching ErgoBoxCandidate serialization in SigmaState (note: a valid standalone box is bounded to 4,096 bytes, so this is codec parity rather than a live-box unlock).
    • Reject boxes with > 255 tokens on write and > 6 registers on read.
    • Share a single extractPackedRegisters validator between writeRegisters and estimateBoxSize so register gaps and unexpected register keys outside R4–R9 are rejected consistently.
  2. Type serializer parity (packages/serializer/src/serializers/typeSerializer.ts)

    • Encode and decode generic tuple arity (0x60) using a single unsigned byte (UByte) and reject declared arity < 2.
    • Decode explicit nested-collection type code 0x18 (nestedColl with embdCode === 0) for non-primitive element types (e.g., Coll[Coll[(Int, Int)]]).
  3. Transaction & context extension serializer (packages/serializer/src/serializers/transactionSerializer.ts)

    • Hash the exact wire extension slice when computing txId on deserialization so non-ascending wire key orders produce the same txId and output boxIds as SigmaState / ergo-lib. (Note: JavaScript Record<string, string> enumerates integer-index keys in ascending order, so re-serializing a deserialized non-ascending transaction emits ascending keys.)
    • Normalize all deserialized inputs to signed shape whenever at least one input has a non-empty spending proof.
    • Enforce single-byte ContextExtension entry counts (0..127) and variable IDs (0..127) matching ContextExtensionSerializer, and reject unexpected trailing bytes after a transaction.
  4. Selection & minting (packages/core/src/builder/selector/strategies/accumulativeSelectionStrategy.ts, packages/core/src/builder/outputBuilder.ts)

    • Accumulate duplicate token ID entries within a single input box during selection.
    • Reject non-positive minted token amounts in OutputBuilder.build before emitting EIP-4 metadata registers, while keeping zero-amount ordinary token filtering intact.

Validation

  • pnpm -r build — pass
  • pnpm cov:check — 66/66 test files, 1,142/1,142 tests pass with 100% line/function/statement coverage across all modified files
  • biome check on all 10 modified source/test files — pass
  • Added .changeset/fix-serializer-and-selection-hardening.md covering @fleet-sdk/serializer and @fleet-sdk/core (patch)

@changeset-bot

changeset-bot Bot commented Dec 6, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: f73270d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@fleet-sdk/serializer Patch
@fleet-sdk/core Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

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.

1 participant