fix(auth): injective signed-payload XDR encoding (A1) — lockstep with soroban-core#38#44
Open
AquiGorka wants to merge 1 commit into
Open
fix(auth): injective signed-payload XDR encoding (A1) — lockstep with soroban-core#38#44AquiGorka wants to merge 1 commit into
AquiGorka wants to merge 1 commit into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Replace the legacy per-field bucket concatenation in buildAuthPayloadHash with the canonical, order-sensitive XDR encoding of the condition list, byte-matching soroban-core#38's hash_payload: contractId ++ ToXdr(Vec<Condition>) ++ live_until_ledger (4-byte LE), SHA-256 The XDR encoding tags each enum variant and length-prefixes the vector, so distinct condition lists always produce distinct preimages: an ExtDeposit(X,a) and an ExtWithdraw(X,a) over the same address/amount now hash differently, and reordering changes the digest. Condition order is preserved as-is (no sorting). Adds a cross-check unit test asserting SHA-256(SDK preimage) equals the actual contract hash_payload digest for fixed inputs (deposit, withdraw, and an ordered multi-condition payload), using known-answer vectors emitted by soroban-core#38. Bumps deno.json 0.11.1 -> 0.11.2. Lands lockstep with soroban-core#38.
76618bd to
ebb4dc4
Compare
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.
What
Replaces the legacy per-field bucket concatenation in
buildAuthPayloadHash(
src/utils/auth/build-auth-payload.ts) with the canonical, order-sensitive XDRencoding of the condition list, byte-identical to soroban-core#38's
hash_payload:ToXdr(Vec<Condition>)is reproduced asxdr.ScVal.scvVec(conditions.map(c => c.toScVal())).toXDR()— the same variant-tagged, length-prefixed
ScValencoding the contract consumes.The SDK returns the preimage; the P256 signer (
crypto.subtle.sign,hash: SHA-256)applies the SHA-256, mirroring the contract's step.
Why (A1)
The old bucketed layout concatenated deposits and withdraws into fixed buckets, so
ExtDeposit(X, a)andExtWithdraw(X, a)over the same address/amount produced abyte-identical preimage — a signed deposit could be reinterpreted as a withdraw. The
XDR encoding tags each enum variant and preserves list order, closing that collision
and binding the exact ordering the signer reviewed. Conditions are never sorted.
Cross-check test
src/utils/auth/build-auth-payload.unit.test.tsassertsSHA-256(SDK preimage)equalsthe actual
hash_payloaddigest emitted by the soroban-core#38 contract for fixedinputs (known-answer vectors), covering:
SDK digest == contract digest)SDK digest == contract digest)Verification
deno fmt --check,deno lint,deno check: greentest/contracts/*.wasm, which still carry the pre-feat(contracts): refresh artifacts for soroban-core 0.4.0 (v0.11.0) #38hash_payload. Confirmed bybaseline — with the old builder the withdraw flow passes against those WASMs; with this
change it fails (the deposit/Ed25519 path is unaffected). They go green once the contract
WASMs are rebuilt from soroban-core#38. Contract side is out of scope (feat(contracts): refresh artifacts for soroban-core 0.4.0 (v0.11.0) #38).
Coordination
Mirrors soroban-core#38 (
fix/b3-hash-payload-docstring@ 97922db). Do not merge —lands lockstep with #38 once its encoding is finalized/published. Re-sync if #38 shifts.
Bumps
deno.json0.11.1 → 0.11.2.