Skip to content

Releases

xark 0.4.0

Choose a tag to compare

@github-actions github-actions released this 24 Nov 16:43
Immutable release. Only release title and notes can be modified.
v0.4.0
54a48f5

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 export now writes its verifier crate to <crate>/clients/rust/ (it was <crate>/<name>-verifier/; the crate's name is unchanged) and xark client its client to <crate>/clients/ts/: move them, or update the program's path dependency. To make it a project, run xark init <name> in a new directory and move the crate's src/ and dependencies into circuits/<name>/.
  • verify takes impl Into<Fields>: a PublicInputs, or the [[u8; 32]; N] you passed before, now by value (verify(&proof, inputs), or *inputs for a reference).
  • verify_instruction_data is gone: split the public inputs off after the proof's 256 bytes into Fields, and call verify.
  • Re-run xark export and xark client, and use @blueshift-gg/xark 0.4.

Changes

  • xark export and xark client write to clients/ beside the circuit's sources by default: the verifier crate to clients/rust/ (still named <name>-verifier) and the TypeScript client to clients/ts/<circuit>.ts. They were <name>-verifier/ and target/xark/<name>/<circuit>.ts, where cargo clean deleted the client. --out still picks the place. See docs/projects.md for where this is going.
  • The verifier crate xark export writes has a PublicInputs struct: 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 per Choice, a Bitfield per set), packed into field elements by to_fields(), a const fn, as #[input] packs them. Breaking: verify and verify_strict take impl Into<Fields> (Fields is [[u8; 32]; N]): a PublicInputs, the elements themselves, or a program's own struct with a From impl. A circuit with a public input of a type that has no Rust form yet (a limbed number, an Ed25519 point) gets no PublicInputs. 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 export writes no longer has verify_instruction_data, verify_instruction_data_strict or VK_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 into Fields for verify, as the program xark add program writes does. The bundled self-test checks the sample with verify, and that a changed public input fails.
  • xark_verifier::fields: the packing rules as const 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: a xark.toml, one Cargo workspace and the starter circuit in circuits/<name>/. xark add circuit <name> and xark add program <name> grow it: Pinocchio programs in programs/, and each circuit's generated clients in clients/<circuit>/{rust,ts}. A program comes with a LiteSVM test in tests/ that proves with the circuit's TypeScript client and verifies onchain. At the root, xark build builds every circuit, its keys and clients, then the programs (failing on the SBF 4 KiB stack-frame warning); xark test runs 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's default-members are the programs, so cargo build-sbf at the root just works.
  • A project commits its keys, in keys/<circuit>/ (xark setup's default there; the host prover and @blueshift-gg/xark/testing read them from there), since the verifier crate embedding the verifying key is committed too. With them goes the circuit.xbc they were made from: a key proves only with the build it was made from, so xark 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 build compares its constraints with the current build's to tell a changed circuit (new keys) from a new build of the same one. xark build and xark prove no 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 setup suggests 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 init writes .github/workflows/ci.yml, which runs it and xark test.
  • xark export keeps 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 test and xark add warn when this xark is another release than the project's xark.toml records.
  • A failing constraint's file is shown from where you ran the command: circuits/claim/src/lib.rs:6:16 at 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_done in xark 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 test builds 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 build at 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, and members is synced first. xark test runs the programs' tests, the verifier crates' self-tests and those of a library beside the circuits in release, and finds node_modules above the root too (an npm workspace's).
  • xark init <dir> --circuit <name> names the first circuit apart from the project. xark add program names the verifier crate as xark export does (shielded_transact → shielded-transact-verifier). xark test builds each circuit once, xark build leaves unchanged generated files alone (so cargo doesn't rebuild the programs), xark profile at a project's root profiles its circuit, and after xark prove in a project the next step is xark 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 …-program or …-verifier, or anything that isn't one crate name, so the crates xark add makes beside it can't clash in the workspace.
  • @blueshift-gg/xark: a proof's toFields() (its public inputs as an exported verifier's Fields) and toInstructionData() (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 and send, for the tests every example carried a copy of. It needs litesvm and @solana/kit beside it.
  • xark prove says how long the witness solve and the prove took, in one line under its summary. PROVE_TIME=1 (a --features debug build) still adds the constraint count and the row-cache marker.
  • Breaking: xark setup --streamable is gone: it was a second spelling of --r1cs-form reduced, which works as before.
  • Breaking: a proving key whose XKPK header has a version this xark doesn't know is refused by Groth16Keys::read_proving_key (and so by xark ceremony), as xark prove and xark-wasm already refused it: xark-backend reads the header with xark_groth16::pk::KeyFormat instead of a copy of it that guessed at the layout. Every key xark has written (headerless, v1 and v2) still loads.
  • Breaking: xark_backend::verify is gone: it only reordered the arguments of xark_groth16::verify(vk, public_inputs, proof), which returns the same result.
  • Breaking: xark_backend::solana no longer has the big-endian decoders decode_g1, decode_g2 and decode_fr, nor encode_fr: nothing used them. Its G1_BYTES, G2_BYTES and FR_BYTES are now xark_groth16::solana's; the little-endian encoders there (encode_*_le, assemble_*_bytes_le) are the on-chain format, and xark_groth16::solana::decode_proof_le reads a proof back.
  • The hidden xark::_FieldMarker type alias is gone; nothing used it.
  • xark_poseidon2::commit::<N> and nullifier::<N>: the sponge hash with its capacity lane seeded with 2^64 · domain + N (domain 1 and 2), so a commitment is never a nullifier, a hash or a hash2 (a Merkle node) short of a Poseidon2 collision. Use them where a circuit hashed a note or an identity with hash and its nullifier with hash2 or a hand-placed tag element. Natively in `n...
Read more

xark 0.3.1

Choose a tag to compare

@github-actions github-actions released this 24 Nov 16:43
Immutable release. Only release title and notes can be modified.
v0.3.1
28ae048

Fixes

  • The verifier crate xark export writes no longer inlines verify, verify_strict or the verify_instruction_data functions. 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), which cargo build-sbf only warns about and which corrupts the stack at run time. Re-run xark export to 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

Choose a tag to compare

@github-actions github-actions released this 24 Nov 16:42
Immutable release. Only release title and notes can be modified.
v0.3.0
9d148ac

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-ed25519 and xark-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_neg gave a wrong result for some inputs at full 256-bit width; mod_add could overflow; mod_neg(0) is fixed.
  • xark-bignum: mod_mul, mul_divmod and sub2 derive their bound m − 1 from m (#62), and a typed Bignum or fp! input range-checks its limbs when it's read (#63). The bignum, bignum_ops, bignum_wide, fp_mul, sub2 and is_lt_check examples change; bignum_wide, fp_mul, sub2 and is_lt_check now range-check the limbs they take as [Field; N]. The curve gadgets don't change.
  • grumpkin_nova_fold takes its inputs grouped by instance.
  • A Time/Days input 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): zkyc changes. scalar_range changes 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_bits computes bit 0 linearly, xor3/maj3/chi/ch are one row each, reduce has tight carries, and a Merkle level swaps with one product. Every example using SHA-256, Keccak, BLAKE, AES, Merkle or to_bits changes (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_ecdsa is 227,168 in xark inspect); the hinted R.x is 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_mul pins 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: aes is 145,944 → 15,360 rows, aes256_gcm 931,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-rustc is gone.
  • Typed inputs. One xark::Input trait, 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 client generates 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, /stream subpaths) to the same subpaths of the new name. @blueshift-gg/xark-wasm@0.2.x stays 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 new xark-frontend. The pinned-nightly MIR compiler xark-rustc is removed. A circuit's R1CS is the same on every supported Rust version (cargo xtask digests checks 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 two i64 (or Timestamp) inputs costs what comparing two u64s 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 init leaves it out): circuit code can use std and crates that assume it. xark and the gadgets stay no_std libraries, and the on-chain verifier doesn't depend on any of this.
  • Circuit code runs natively on the host. In a host build the Field operations compute instead of panicking: arithmetic on BN254, comparisons, and every hint as the solver computes it. A failed require/require_eq panics at the caller's line, and witness_begin/witness_end regions skip their checks as a circuit does. So a helper such as id.commitment(), or a whole gadget (xark_sha256::sha256, ECDSA verify), runs in tests and services. Only hint-less Field::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 three u8 inputs costs 28 constraints rather than 151.
  • Failing checks name their source line. xark build writes sources.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 test rebuilds a stale circuit, one older than any local source it came from (path-dependency gadgets and xark included, from cargo's dep-info), instead of testing the previous build, and one built over another field (--field). Without an xark to rebuild with, it warns (for another field, the tests fail, saying why).

Inputs

  • One Input trait for every circuit input. A type is a circuit input when it implements xark::Input: its TYPE (how clients see it, built from a fixed set of standard types) and read/write of 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 no cfgs. #[input] implements it for a struct (#[input(number(bits = B))] or #[input(bytes)] give it a standard encoding), xark::Enum for a fieldless enum, and client functions for an impl block. It derives Clone, Copy and Debug (and PartialEq, Eq on an enum) unless listed; #[input(no_derive)] leaves them to you. It replaces #[derive(CircuitInput)], #[derive(Transparent)] and NativeInput.
  • Everyday input types: Text, Choice<E> (one variant of an enum) and Bitfield<E> (a set of them), each one field, with natural forms in tests ("A1938274", [US, GB]), --inputs and clients, and the ISO 3166 Country enum. Each compares with require_eq and ==, as does an #[input] struct. Checks are sized to the enum: a set splits into one bit per variant, and Choice::require_in(set) costs about 510 constraints over Country. Text::parse and the time types' parse return a Result for input you didn't write.
  • Times, sized to their range. Timestamp is any moment as Unix seconds (an i64, as Solana's Clock and a JS Date hold it). Time<UNIT, FROM, TO> is a moment from the start of year FROM to the end of TO in whole UNIT-second steps (SECOND … WEEK), and Days<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 JS Date in 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/zkyc uses them: a private Identity checked against a public Policy built with Policy::default().on(today).min_age(18).worth_at_least(500_000).
  • bool inputs. A bool parameter or field is one field element, checked to be 0 or 1, usable as a condition and a value.
  • Struct fields are packed. An `#...
Read more