Repository navigation
Releases
Releases · blueshift-gg/xark
xark 0.4.0
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 in `n...
xark 0.3.1
Immutable
release. Only release title and notes can be modified.
Fixes
- The verifier crate
xark exportwrites no longer inlinesverify,verify_strictor theverify_instruction_datafunctions. Inlined into a program's entrypoint under fat LTO, the pairing check took that frame past the SBF limit of 4,096 bytes (4,480 in xark-examples'over-9000), whichcargo build-sbfonly warns about and which corrupts the stack at run time. Re-runxark exportto pick it up; no circuit or key changes.
What's Changed
- xark-wasm publishes to crates.io by @deanmlittle in #76
- fix: show commit hash in xark CLI by @dhl in #77
- 0.3.1: the exported verifier stays out of the caller's stack frame by @deanmlittle in #78
- chore: centralize workspace member dependencies in workspace Cargo.toml by @dhl in #79
Full Changelog: v0.3.0...v0.3.1
xark 0.3.0
Immutable
release. Only release title and notes can be modified.
Circuits that changed
Every circuit. 0.3 compiles circuits with a new frontend (below), so every circuit built with 0.2 changes: rebuild and make new keys. Beyond that, these gadgets now check more:
xark-ed25519andxark-secp256k1: points must have canonical coordinates (each< p), so a point can't be given in two forms. About +1,000 constraints for an EdDSA verify and +560 for an ECDSA verify.xark-secp256r1: the same check, +3 constraints.xark-bignum:mod_neggave a wrong result for some inputs at full 256-bit width;mod_addcould overflow;mod_neg(0)is fixed.xark-bignum:mod_mul,mul_divmodandsub2derive their boundm − 1fromm(#62), and a typedBignumorfp!input range-checks its limbs when it's read (#63). Thebignum,bignum_ops,bignum_wide,fp_mul,sub2andis_lt_checkexamples change;bignum_wide,fp_mul,sub2andis_lt_checknow range-check the limbs they take as[Field; N]. The curve gadgets don't change.grumpkin_nova_foldtakes its inputs grouped by instance.- A
Time/Daysinput is checked to its range of steps, not just its bit width (Days<2024, 2024>is 366 days in 9 bits, and 366–511 were accepted):zkycchanges.scalar_rangechanges only in row order. - The bit and hash gadgets take fewer rows, each proven sound in Lean over the exact rows it emits (
formal/): XOR and OR with a constant fold to a linear form,to_bitscomputes bit 0 linearly,xor3/maj3/chi/chare one row each,reducehas tight carries, and a Merkle level swaps with one product. Every example using SHA-256, Keccak, BLAKE, AES, Merkle orto_bitschanges (27 of 71). - ECDSA on secp256k1 and P-256, and EdDSA on Ed25519, are rewritten around proven gadgets: non-native multiplication by pseudo-Mersenne certificates over 8×32-bit limbs, fused double-and-add over signed digits, and fake GLV (ePrint 2025/933) with a fixed-base comb, each gadget proven sound over its rows. Fewer rows (
examples/secp256k1_ecdsais 227,168 inxark inspect); the hintedR.xis checked canonical (< p), and Ed25519 keeps the cofactored check of RFC 8032. Keys for the ECDSA and EdDSA examples must be made again. - Grumpkin scalar multiplication (
scalar_mul,wide_scalar_mul,multi_scalar_mul) and the Pedersen hash are rewritten as proven gadgets: one fused incomplete step per bit over signed digits, and windowed lookups from constant tables for Pedersen (3,318 → 772 rows).scalar_mulpins its own bits boolean. The seven Grumpkin and Pedersen examples change. - The AES S-box is a select over its constant 256-byte table (687 → 34 rows), proven to output
S(x)for every byte:aesis 145,944 → 15,360 rows,aes256_gcm931,512 → 209,883. The five AES examples change.
Highlights
- Stable Rust only. Circuits compile with any stable Rust from 1.89, and are identical on every supported version. The pinned-nightly
xark-rustcis gone. - Typed inputs. One
xark::Inputtrait, implemented by#[input]or by hand, and everyday types (Timestamp,Days<FROM, TO>,Text,Choice<E>,Bitfield<E>,Country), in the circuit, in tests, on the command line and in clients. - Typed TypeScript clients.
xark clientgenerates a client that proves and verifies through xark-wasm, with the circuit's types and its Rust constructors. - A streaming Groth16 prover (
xark-groth16) that never holds the whole constraint system or key in memory, with arkworks' Groth16 removed. - Failing checks name their source line, everywhere inputs are checked.
- Gadgets proven in Lean over the rows they emit. 63 gadget templates (bits, hashes, AES, ECDSA, EdDSA, Grumpkin, Pedersen) are exported from the compiler and proven sound in
formal/; CI fails when the code stops emitting a proven template or a production call isn't covered, and the secp256k1 ECDSA circuit is composed in Lean from its calls, its rows hashed against the compiler's. Every minimizer run on the keyed path writes a certificate a Lean checker accepts, proven to mean the keyed rows have the same solutions and eliminate no input.
Changed
The npm package
@blueshift-gg/xark. The JS runtime is published as@blueshift-gg/xark; imports move from@blueshift-gg/xark-wasm(and its/client,/pool,/streamsubpaths) to the same subpaths of the new name.@blueshift-gg/xark-wasm@0.2.xstays published.
The toolchain and the frontend
- Stable Rust only. A circuit crate is compiled to wasm by the ambient stable
cargo(1.89 or later, for the CLI too) and lowered by the newxark-frontend. The pinned-nightly MIR compilerxark-rustcis removed. A circuit's R1CS is the same on every supported Rust version (cargo xtask digestschecks every example on 1.89, stable and beta in CI). - An integer input's range check is reused. Its bits serve a later
to_bits, bitwise operation or signed comparison of the input, so comparing twoi64(orTimestamp) inputs costs what comparing twou64s does (68 constraints, not 202). - What compiles is documented from the new frontend in docs/subset.md. Branches on witness values, small witness indices and short witness-bounded loops work. Constructs that can't compile soundly (a witness-sized
memory.grow, a circuit input declared inside a witness branch, a loop whose length depends on a witness and isn't provably short) are refused with a message naming the source line. - Circuit crates can use
std.#![cfg_attr(xark, no_std)]is no longer needed (xark initleaves it out): circuit code can usestdand crates that assume it.xarkand the gadgets stayno_stdlibraries, and the on-chain verifier doesn't depend on any of this. - Circuit code runs natively on the host. In a host build the
Fieldoperations compute instead of panicking: arithmetic on BN254, comparisons, and every hint as the solver computes it. A failedrequire/require_eqpanics at the caller's line, andwitness_begin/witness_endregions skip their checks as a circuit does. So a helper such asid.commitment(), or a whole gadget (xark_sha256::sha256, ECDSAverify), runs in tests and services. Only hint-lessField::advice()has no host value. - Packing narrow values into a word is free. An
|(or^) of values whose bits can't overlap (c << 16 | b << 8 | a) is their sum, and reading a piece back (>>, a mask,/or%by a power of two,as u8, a byte through memory) takes it off that sum instead of splitting the word into bits: such a round trip on threeu8inputs costs 28 constraints rather than 151. - Failing checks name their source line.
xark buildwritessources.json(which statement each constraint came from), and inputs that fail a check report that statement in Rust tests,xark prove/check, xark-wasm and clients:src/lib.rs:96:20 id.nationality.require_in(policy.allowed);rather than a constraint number. cargo testrebuilds a stale circuit, one older than any local source it came from (path-dependency gadgets andxarkincluded, from cargo's dep-info), instead of testing the previous build, and one built over another field (--field). Without anxarkto rebuild with, it warns (for another field, the tests fail, saying why).
Inputs
- One
Inputtrait for every circuit input. A type is a circuit input when it implementsxark::Input: itsTYPE(how clients see it, built from a fixed set of standard types) andread/writeof its field elements. The one impl serves the circuit build and the host (the prover's inputs,to_fields()for hashing, decoding public inputs), so a hand-written impl is a few lines with nocfgs.#[input]implements it for a struct (#[input(number(bits = B))]or#[input(bytes)]give it a standard encoding),xark::Enumfor a fieldless enum, and client functions for animplblock. It derivesClone,CopyandDebug(andPartialEq,Eqon an enum) unless listed;#[input(no_derive)]leaves them to you. It replaces#[derive(CircuitInput)],#[derive(Transparent)]andNativeInput. - Everyday input types:
Text,Choice<E>(one variant of an enum) andBitfield<E>(a set of them), each one field, with natural forms in tests ("A1938274",[US, GB]),--inputsand clients, and the ISO 3166Countryenum. Each compares withrequire_eqand==, as does an#[input]struct. Checks are sized to the enum: a set splits into one bit per variant, andChoice::require_in(set)costs about 510 constraints overCountry.Text::parseand the time types'parsereturn aResultfor input you didn't write. - Times, sized to their range.
Timestampis any moment as Unix seconds (ani64, as Solana'sClockand a JSDatehold it).Time<UNIT, FROM, TO>is a moment from the start of yearFROMto the end ofTOin wholeUNIT-second steps (SECOND…WEEK), andDays<FROM, TO>its days: in the circuit an unsigned integer just wide enough for the range (Days<1900, 2100>is 17 bits), range-checked on entry and compared at that width. A moment inside a step is that step (rounded down, as Unix time does), and one outside the range is refused with the range named. Both read"YYYY-MM-DD", an ISO 8601 date-time with a zone, or Unix seconds, are a JSDatein a generated client, and convert on the host (Days::from_timestamp,years_before), on chain too (const fns,no_std). Leap years count where a date is read or written; every day is 86,400 seconds.examples/zkycuses them: a privateIdentitychecked against a publicPolicybuilt withPolicy::default().on(today).min_age(18).worth_at_least(500_000). boolinputs. Aboolparameter or field is one field element, checked to be 0 or 1, usable as a condition and a value.- Struct fields are packed. An `#...