Skip to content

Adds Shrincs testing - #20

Draft
stringhandler wants to merge 4 commits into
mainfrom
pq-shrincs
Draft

stringhandler wants to merge 4 commits into
mainfrom
pq-shrincs

Conversation

@stringhandler

Copy link
Copy Markdown
Owner

No description provided.

…pend takes

The Bitcoin finalize path appended the padding item after the control block, which is
where the node reads the control block from. It also sized the padding from the satisfied
program before pruning, whose cost bound is its heaviest branch. The node rejects both:
a last item that isn't a control block, and padding the program doesn't need
(SIMPLICITY_ERR_OVERWEIGHT; minCost is the budget with one byte less padding).

Padding now goes first, and is the shortest item that fits the pruned program's cost.
Programs cheap enough to need no padding, such as examples/bitcoin_covenant, were not
affected.
Vendor shrincs-simplicity-verifier at 9d3791a (CC0) under contrib/, and add two
examples that flatten it with mcpp:

- pq_shrincs_smoke: upstream's verifier, unmodified. It takes the key and the message as
  witness data, so the coin it locks is anyone-can-spend; it is a smoke test, and has
  been spent on the Simplicity signet (be93b56ddb24f54b4cc8d9378a4baa7db5f880f273af56e2e69f339b305db2f2).
- pq_shrincs: a wrapper that pins the key in param::PK and takes the message from
  jet::sig_all_hash(). Its manifest comes with the signer.

tests/shrincs_verifier.rs runs upstream's witnesses through the Bitcoin finalize path
and checks each witness stack against the signet node's acceptance rule.
Add contrib/shrincs-signer, a thin driver around shrincs-cpp that makes a SHRINCS-L key
from a seed file and stateful signatures over a 32-byte message, and examples/pq_shrincs,
which locks coins to a pinned SHRINCS public key and spends them with a signature over
jet::sig_all_hash().

The signature has to be made outside the wallet, so a spend takes two runs. The new
`run --print-sighash` (Bitcoin only) builds the transaction, prints the sig_all_hash each
covenant input's program will check, and stops without broadcasting. The second run, with
the same inputs, params and fee rate, builds the same transaction and carries the
signature.

tests/shrincs_verifier.rs runs the same spend offline with a test key
(fixtures/shrincs/test_seed.hex, never to hold real coins).
The fee estimate assumed about 1 KB of witness for every covenant input. A SHRINCS spend
carries about 19 KB, so its transaction fell below the relay fee unless the manifest
asked for a fee_rate of about 15. Each covenant input's witness is now estimated from its
program: the stack for every branch, with the widest value of each witness type, and the
padding its costliest branch needs. It uses the program alone and never the witness
values, so both runs of a --print-sighash spend arrive at the same fee. A program that
branches on a witness is estimated for its heaviest branch, so the estimate errs high.

The pq_shrincs examples now spend at fee_rate 1. Bitcoin runs print the txid when the
transaction is built, so the two runs of a two-run spend can be compared. The node's
witness-stack rules move from tests/shrincs_verifier.rs into covenant::bitcoin_node_check.

shrincs-signer gains sign-raw, for test keys only: it signs at a given leaf index with no
state file and prints the raw signature split into its fields, for the pq-contest runner.
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