Skip to content

docs(primitives): correct hash_payload docstring to match impl (B3)#38

Open
AquiGorka wants to merge 2 commits into
mainfrom
fix/b3-hash-payload-docstring
Open

docs(primitives): correct hash_payload docstring to match impl (B3)#38
AquiGorka wants to merge 2 commits into
mainfrom
fix/b3-hash-payload-docstring

Conversation

@AquiGorka

Copy link
Copy Markdown
Contributor

Fixes audit finding B3 (informational, documentation-only). The hash_payload docstring in modules/primitives/src/lib.rs contradicted the implementation in three places; this corrects the prose to match the code. Comment-only — no code/behavior/WASM change, no version bump.

Corrections

  • Amount width: "little-endian 8-byte sequences" → 16-byte LE (amounts are i128, impl uses to_le_bytes()).
  • Contract/address encoding: "(32 bytes)" → ~56-byte strkey string (addr.to_string().to_bytes()).
  • Ordering: "same ordering as the original bundle" → bucketed by condition type (create / deposit / withdraw / integration); only order within each bucket follows the original bundle.

Rewritten as a field-by-field layout (contract bytes → per-type buckets → 4-byte LE live_until_ledger → sha256).

Verification

  • Diff touches only the doc comment in modules/primitives/src/lib.rs — no code, no Cargo.toml. WASM identical.
  • cargo check -p moonlight-primitives --target wasm32v1-none clean; file passes rustfmt.

@AquiGorka AquiGorka requested review from fazzatti and pselle July 3, 2026 17:11
AquiGorka added 2 commits July 8, 2026 10:38
Amount width 8->16 bytes (i128 LE), contract/address 32 bytes->~56-byte
strkey string, and ordering 'original bundle order'->bucketed by condition
type. Comment-only; no code/behavior/WASM change.
Replace the per-type bucket concatenation in hash_payload with the
canonical XDR of the ordered Vec<Condition>. The prior encoding had no
length prefixes, variant tags, or separators, so distinct condition
lists could collide -- most sharply, ExtDeposit(X, a) and ExtWithdraw(X, a)
over the same address and amount hashed to identical bytes, letting an
untrusted submitter reinterpret a signed deposit as a withdraw.

XDR is self-delimiting (length-prefixed vectors, variant-tagged enums)
and order-preserving, matching equal_condition_sequence. Add tests for
the deposit/withdraw collision and for order-sensitivity, and update the
B3 docstring to describe the new encoding.
@AquiGorka AquiGorka force-pushed the fix/b3-hash-payload-docstring branch from efb41c8 to 97922db Compare July 8, 2026 13:42
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