fix(auth): mirror soroban-core #38 injective hash_payload encoding (A1)#41
Closed
AquiGorka wants to merge 1 commit into
Closed
fix(auth): mirror soroban-core #38 injective hash_payload encoding (A1)#41AquiGorka wants to merge 1 commit into
AquiGorka wants to merge 1 commit into
Conversation
Replace the legacy per-type bucketed concatenation in buildAuthPayloadHash with the byte-identical encoding used by soroban-core's hash_payload (modules/primitives/src/lib.rs, PR #38, A1): contractId (strkey bytes) ++ ToXdr(Vec<Condition>) ++ live_until_ledger (4-byte LE) hashed with SHA-256 by the P256 signer. Conditions are serialized via their canonical ScVal-vector XDR in input order (never sorted/bucketed), so ExtDeposit(X,a) and ExtWithdraw(X,a) over the same address/amount now produce distinct digests. Off-chain signatures must match this exactly or on-chain verification fails once #38 merges. Add a known-answer cross-check test asserting the SDK digest equals the contract's hash_payload output for fixed vectors (deposit, withdraw, and a mixed deposit+create list), including deposit != withdraw. Patch bump 0.6.1 -> 0.6.2.
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
Update the off-chain P256 signing pre-image in
buildAuthPayloadHashto be byte-identical to soroban-core'shash_payload(modules/primitives/src/lib.rs) as changed by soroban-core #38 (finding A1, headefb41c8).New encoding, matching the contract exactly:
SHA-256 is applied by the signer (
crypto.subtle.sign, ECDSA/SHA-256), so this function returns the un-hashed pre-image.ScVal.scvVec(conditions.map(c => c.toScVal())).toXDR()), in input order — never sorted or bucketed. This mirrors the contract'sconditions.to_xdr(e).ExtDeposit(X, a)andExtWithdraw(X, a)over the same address/amount now hash differently, and reordering changes the digest.Why
The on-chain verifier hashes this exact pre-image and checks the P256 signature against it. If the off-chain signer diverges by a single byte, every on-chain signature verification fails. This must land and deploy in lockstep with soroban-core #38.
Cross-check test
src/utils/auth/build-auth-payload.unit.test.tsasserts the SDK digest equals the contract'shash_payloadoutput for fixed vectors (generated by running the contract's ownhash_payload):[ExtDeposit(G…, 1000)], live 100 →4482986e…e75b73[ExtWithdraw(G…, 1000)], live 100 →bb0354a9…3bc57e(and asserts deposit ≠ withdraw)[ExtDeposit(G…, 42), Create([7;65], 99)], live 555 →506acd6b…32faeeFixed strkeys are shared with the contract KAT (
StrKey.encodeContract(0x11×32)/encodeEd25519PublicKey(0x22×32)).Verification
deno lint— passdeno task test:unit— 14 passed, 0 failed (includes the new cross-check)deno publish --dry-run --allow-slow-types— type-check cleandev, unrelated to this change:deno checkreportsstellar-plusimport-map errors in test helpers /sorobanSmartContractId.ts/mod.ts, anddeno fmt --checkdrifts onbundle-auth-entry.ts/deposit-auth-entry.ts/deno.jsonnewline. CI (test.yml) runsdeno lint+deno task testonly (fmt is commented out).deno.jsonpatch bump0.6.1 → 0.6.2.Mirrors soroban-core #38 @
efb41c83d8b725e0423dbf5485abf40a54f2811d. If #38's encoding shifts before merge, this PR re-syncs (regenerate the KAT vectors).Do not merge — lands in lockstep with soroban-core #38.