Repository navigation
·
24 commits
to master
since this release
Immutable
release. Only release title and notes can be modified.
A project for a circuit and the Solana program that verifies it: xark init makes one, xark add program writes the program and a LiteSVM test, and xark build and xark test at its root do the rest. The verifier crate takes its public inputs by name. No circuit changed: keys made with 0.3 still verify (its digests are the same).
Most of the work in 0.4 is @deanmlittle's; its squashed commits credit only the squasher.
Moving from 0.3
The steps, with before and after code: docs/migrating-to-0.4.md.
- A circuit crate from 0.3 still works on its own.
xark exportnow writes its verifier crate to<crate>/clients/rust/(it was<crate>/<name>-verifier/; the crate's name is unchanged) andxark clientits client to<crate>/clients/ts/: move them, or update the program's path dependency. To make it a project, runxark init <name>in a new directory and move the crate'ssrc/and dependencies intocircuits/<name>/. verifytakesimpl Into<Fields>: aPublicInputs, or the[[u8; 32]; N]you passed before, now by value (verify(&proof, inputs), or*inputsfor a reference).verify_instruction_datais gone: split the public inputs off after the proof's 256 bytes intoFields, and callverify.- Re-run
xark exportandxark client, and use@blueshift-gg/xark0.4.
Changes
xark exportandxark clientwrite toclients/beside the circuit's sources by default: the verifier crate toclients/rust/(still named<name>-verifier) and the TypeScript client toclients/ts/<circuit>.ts. They were<name>-verifier/andtarget/xark/<name>/<circuit>.ts, wherecargo cleandeleted the client.--outstill picks the place. See docs/projects.md for where this is going.- The verifier crate
xark exportwrites has aPublicInputsstruct: the circuit's public inputs by name, in Rust types a program has at hand (integers,[u8; 32],Days<FROM, TO>from a Unix time, an enum perChoice, aBitfieldper set), packed into field elements byto_fields(), aconst fn, as#[input]packs them. Breaking:verifyandverify_stricttakeimpl Into<Fields>(Fieldsis[[u8; 32]; N]): aPublicInputs, the elements themselves, or a program's own struct with aFromimpl. A circuit with a public input of a type that has no Rust form yet (a limbed number, an Ed25519 point) gets noPublicInputs. The crate's self-test checks that the sample proof's public inputs, written by name, pack to the sample's elements. - Breaking: the crate
xark exportwrites no longer hasverify_instruction_data,verify_instruction_data_strictorVK_BYTES: they were a second way to verify (re-parsing the key at run time from a second copy of it). A program that takes the public inputs in its instruction data splits them off after the proof's 256 bytes intoFieldsforverify, as the programxark add programwrites does. The bundled self-test checks the sample withverify, and that a changed public input fails. xark_verifier::fields: the packing rules asconst fns, for the generated crate and for packing your own struct.Packer::new().uint::<17>(day).finish()takes each field's width as a const generic, so a value too wide for its bits, or a run past 253 bits, fails the build when the inputs are constants (and panics at run time).Uint<BITS>holds an integer of a width Rust has no type for.- Breaking:
xark init <name>makes a project: axark.toml, one Cargo workspace and the starter circuit incircuits/<name>/.xark add circuit <name>andxark add program <name>grow it: Pinocchio programs inprograms/, and each circuit's generated clients inclients/<circuit>/{rust,ts}. A program comes with a LiteSVM test intests/that proves with the circuit's TypeScript client and verifies onchain. At the root,xark buildbuilds every circuit, its keys and clients, then the programs (failing on the SBF 4 KiB stack-frame warning);xark testruns every test;xark check(rust-analyzer's) checks the whole workspace; and a command that takes a circuit defaults to the project's one. The workspace'sdefault-membersare the programs, socargo build-sbfat the root just works. - A project commits its keys, in
keys/<circuit>/(xark setup's default there; the host prover and@blueshift-gg/xark/testingread them from there), since the verifier crate embedding the verifying key is committed too. With them goes thecircuit.xbcthey were made from: a key proves only with the build it was made from, soxark prove, the host prover and the testing module prove with that one, and a clone that compiles the circuit differently (another Rust, another xark) still proves with the committed keys.xark buildcompares its constraints with the current build's to tell a changed circuit (new keys) from a new build of the same one.xark buildandxark proveno longer make a key when a committed verifier embeds one: a fresh clone without the keys stops with how to restore them, instead of quietly changing the verifier.xark setupsuggests Git LFS for a proving key over 50 MB. xark build --check(at a project's root) fails if the committed clients aren't what the source generates, or a key is missing or for an older circuit, and writes nothing.xark initwrites.github/workflows/ci.yml, which runs it andxark test.xark exportkeeps the sample proof a verifier crate already bundles while it still verifies, so a newer local proof (or none) doesn't change the crate.- At a project's root,
xark build,xark testandxark addwarn when this xark is another release than the project'sxark.tomlrecords. - A failing constraint's file is shown from where you ran the command:
circuits/claim/src/lib.rs:6:16at a project's root. - A project's circuits build with cargo's own profile settings (no LTO, one codegen unit, no debug assertions, debug info stripped), whatever the workspace sets for its programs: its fat LTO changed which functions were inlined, and so the keyed rows and the source a constraint is attributed to (
inputs_doneinxark profile). Builds outside a project are unchanged (every digest is the same). - A key made from another build of the same circuit is no longer said to fit: the note says a key fits the build it was made from.
- In a project,
xark testbuilds a circuit's tests without the programs' fat LTO (the workspace's release profile): after an edit, the starter circuit's tests relink in 1 s instead of 8. xark buildat a project's root works before a circuit's verifier crate exists, as when a program that depends on it is moved in: a placeholder stands in until the export replaces it, andmembersis synced first.xark testruns the programs' tests, the verifier crates' self-tests and those of a library beside the circuits in release, and findsnode_modulesabove the root too (an npm workspace's).xark init <dir> --circuit <name>names the first circuit apart from the project.xark add programnames the verifier crate asxark exportdoes (shielded_transact→shielded-transact-verifier).xark testbuilds each circuit once,xark buildleaves unchanged generated files alone (so cargo doesn't rebuild the programs),xark profileat a project's root profiles its circuit, and afterxark provein a project the next step isxark build.- In a project, a crate in
circuits/is a circuit if it has a#[circuit]: a library the circuits share can sit beside them. - A circuit can't be named
…-programor…-verifier, or anything that isn't one crate name, so the cratesxark addmakes beside it can't clash in the workspace. @blueshift-gg/xark: a proof'stoFields()(its public inputs as an exported verifier'sFields) andtoInstructionData()(the proof, then those), and@blueshift-gg/xark/testing: a circuit's build output by name, LiteSVM with a project's programs, a funded payer andsend, for the tests every example carried a copy of. It needslitesvmand@solana/kitbeside it.xark provesays how long the witness solve and the prove took, in one line under its summary.PROVE_TIME=1(a--features debugbuild) still adds the constraint count and the row-cache marker.- Breaking:
xark setup --streamableis gone: it was a second spelling of--r1cs-form reduced, which works as before. - Breaking: a proving key whose
XKPKheader has a version this xark doesn't know is refused byGroth16Keys::read_proving_key(and so byxark ceremony), asxark proveand xark-wasm already refused it:xark-backendreads the header withxark_groth16::pk::KeyFormatinstead of a copy of it that guessed at the layout. Every key xark has written (headerless, v1 and v2) still loads. - Breaking:
xark_backend::verifyis gone: it only reordered the arguments ofxark_groth16::verify(vk, public_inputs, proof), which returns the same result. - Breaking:
xark_backend::solanano longer has the big-endian decodersdecode_g1,decode_g2anddecode_fr, norencode_fr: nothing used them. ItsG1_BYTES,G2_BYTESandFR_BYTESare nowxark_groth16::solana's; the little-endian encoders there (encode_*_le,assemble_*_bytes_le) are the on-chain format, andxark_groth16::solana::decode_proof_lereads a proof back. - The hidden
xark::_FieldMarkertype alias is gone; nothing used it. xark_poseidon2::commit::<N>andnullifier::<N>: the spongehashwith its capacity lane seeded with2^64 · domain + N(domain 1 and 2), so a commitment is never a nullifier, ahashor ahash2(a Merkle node) short of a Poseidon2 collision. Use them where a circuit hashed a note or an identity withhashand its nullifier withhash2or a hand-placed tag element. Natively innative(andcommit_slice,nullifier_slice), and in@blueshift-gg/xarkasposeidon2Commit/poseidon2Nullifierand a session'scommit/nullifier.xark_poseidon2::challenge::<N, BITS>: a Fiat–Shamir challenge, the lowBITScanonical bits ofhash(transcript). It replaces the four copies inexamples/grumpkin_*, whose rows are the same.xark::select(bit, t, f)(in the prelude):bit ? t : ffor a pinned bit, over a field element or arrays of them (theSelecttrait, for a gadget's own types).xark-grumpkin's privatemuxandgrumpkin_complete_add's use it, with the same rows.xark-merklehas Merkle trees on Poseidon2 (xark_merkle::poseidon2):merkle_rootandmerkle_verifyas before,merkle_append(the root with a leaf written in an empty slot, one path proving both roots), and an indexed tree (Aztec's) for non-membership:indexed_non_membershipandindexed_insert, comparing values below2^BITS,BITS ≤ 252. They arecond_swapand Poseidon2 composed, with no new#[gadget].xark_merkle::treebuilds the trees on the host (Tree, filled from the left, with Poseidon2 or Poseidon nodes, andIndexedTree): roots, paths, empty-subtree roots, appends and insertions, for the paths a client hand-rolled. The Poseidonmerkle_root/merkle_verifyare unchanged. New example:nullifier_tree.xark::Address, a Solana address as an input: two field elements, its 16-byte halves big-endian (as a wallet passed as aHashor[Field; 2]was, so the rows are the same), namedAddressinschema.json. It's base58 in--inputsand decoded public inputs, a[u8; 32]or base58 in Rust, @solana/kit'sAddress(or its bytes) in a TypeScript client, and a[u8; 32]in the verifier crate'sPublicInputs.examples/bound_recipienttakes its recipient as one (its--inputsform is now the address in base58, not two hex halves; its digest is the same).xark_grumpkin::schnorr: Schnorr signatures over Grumpkin.verify(pubkey, sig, msg)requiress·G = R + e·Pwith a Poseidon2 challenge, in 5,051 constraints for a two-element message (an Ed25519 signature is ~397k);schnorr::hostmakes keys, signs with a deterministic nonce and verifies, overark-grumpkin. New examplegrumpkin_schnorr(a new digest line; no other changed).
What's Changed
- a verifier requires public inputs unless the circuit has none by @dhl in #80
- Xark 0.4 by @dhl in #82
Full Changelog: v0.3.1...v0.4.0