Skip to content

feat(contracts): pq-receipt-check, verify a receipt's ML-DSA-65 signature on chain - #585

Merged
M0nsxx merged 1 commit into
mainfrom
feat/pq-receipt-check-contract
Dec 4, 2026
Merged

M0nsxx merged 1 commit into
mainfrom
feat/pq-receipt-check-contract

Conversation

@Eras256

@Eras256 Eras256 commented Dec 4, 2026

Copy link
Copy Markdown
Member

Adds contracts/pq-receipt-check, a Soroban contract that checks the pq block of a Nirium receipt on chain, using the ML-DSA host function that Protocol 30 added (CAP-87).

What it does

  • verify_receipt(public_key, content_sha256, signature) -> BytesN<32> builds nirium-audit-v1:<content_sha256 hex> itself, so a caller can't make it check any other message. It runs ml_dsa_65_verify (pure ML-DSA, empty context) and traps if the signature is bad.
  • It returns sha-256 of the public key, the same value an account registers under manage_data nirium-pq-v1. The "only the first registration counts" lookup needs account history, so it stays with the caller (CLI, /verify, Action), which already does it since fix(pq): only the account's first post-quantum key counts #582/feat(action): verify-audit-cid checks the post-quantum signature (pq) #584.
  • No storage, no admin, no upgrade path.
  • It checks the receipt's signature only. The payment and the receipt's agent signature are still ed25519.

Tested on testnet (4 Dec), contract CBQKCPCCGJ2OTGLUZ5XTKIRFJ3UHITDKMOUGOUKKKUT4O3X5CDFXAGC2:

  • QmPW2nfY… verifies and returns 626668…bf9e, the first key GAZKTB4N…XN54 registered. Tx dac60c9b57cd282a26d66f576c594b96c75b7628756728c9e7094095c45dab65.
  • QmWwdPH9… verifies and returns 29ab77…2a6e, the first key GDK7ODGX…GWRI registered. Tx b3c026d74a9d4c3d8ebebc8aa008aa4dfa89c3688d796b63cdb7befe4d9b0e93.
  • One flipped signature bit, and the first key against the second receipt: both rejected with Error(Crypto, InvalidInput).
  • One check cost 14,150 stroops; the declared instruction budget was 3,426,538.

Not deployed on mainnet.

CI: new pq-receipt-check.yml. It runs the 5 cargo test cases against the real receipt in test_fixtures/, then builds the wasm with stellar-cli 30.0.1 pinned by sha-256. soroban-sdk 30 refuses to build wasm with older CLIs.

🤖 Generated with Claude Code

…ture on chain

Soroban contract that checks the pq block of a Nirium receipt with the
Protocol 30 host function (CAP-87). It builds the statement
nirium-audit-v1:<content_sha256 hex> itself, calls ml_dsa_65_verify
(pure, empty context) and returns sha-256 of the public key, the value an
account registers under manage_data nirium-pq-v1. No storage, no admin.

Tested on testnet: contract CBQKCPCC...AGC2, both real pq receipts verify
and return each account's first registered key id; a flipped signature bit
and a key/receipt mismatch are rejected. Not deployed on mainnet.

CI: cargo test against the real receipt, wasm build with stellar-cli
30.0.1 pinned by sha-256 (soroban-sdk 30 requires it).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@M0nsxx M0nsxx left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI-assisted review (Claude)

Reviewed the contract and its tests. verify_receipt builds the nirium-audit-v1: statement inside the contract, so callers can't pass a different message, then calls ml_dsa_65_verify with an empty context and returns sha256 of the public key, which is the nirium-pq-v1 registration value. No storage, no admin, no upgrade path. The 5 tests use the real testnet receipt QmPW2nfY and cover the valid case, a flipped signature bit, a changed hash and a changed key. The testnet run in the description lines up: both real receipts return the key id each account registered first. CI is green, and the new job runs the tests and builds the wasm with stellar-cli 30.0.1 pinned by sha-256. Approving.

@M0nsxx
M0nsxx merged commit 4d39997 into main Dec 4, 2026
5 checks passed
@M0nsxx
M0nsxx deleted the feat/pq-receipt-check-contract branch December 4, 2026 19:52
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.

2 participants