Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "sunspot_wasm"
version = "2.0.1"
version = "2.1.0"
edition = "2024"

[lib]
Expand Down
2 changes: 1 addition & 1 deletion js/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ import { init, prove } from '@reilabs/sunspot_js/sisd-st'; // scalar fallback, s
- `class ZKey(pk, r1cs)` — bundles a proving key and R1CS.
- `ZKey.from(pkResponse, r1csResponse)` — load both from `fetch()` responses.
- `ZKey.fromUnchecked(pkResponse, r1csResponse)` — same but skips on-curve checks on the PK. Only safe for trusted keys.
- `class Witness(circuit, witnessStackBytes)` — build the gnark-ordered partial witness from a Noir `CompiledCircuit` and the `Noir#execute(...).witness` witness map. Exposes `privateBytes()` and `publicBytes()` (concatenated 32-byte big-endian limbs).
- `class Witness(circuit, witnessStackBytes)` — gnark-ordered partial witness. Exposes `publicBytes()` / `privateBytes()` (concatenated 32-byte BE limbs), and `gnarkFormatPublicBytes()` (public witness in gnark `MarshalBinary` / `.pw` format — the form Sunspot-produced verifiers expect).
- `class Proof` — `asBytes()`, `arBytes()`, `bsBytes()`, `krsBytes()`, `commitmentsBytes()`, `commitmentPokBytes()`, `nbCommitments()`, `isValid()`.
- `prove(input, circuit, zkey): Promise<Proof>` — witness-gen + prove in one call.

Expand Down
2 changes: 1 addition & 1 deletion js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@reilabs/sunspot_js",
"version": "2.0.1",
"version": "2.1.0",
"description": "Groth16 prover for Noir circuits in browser.",
"license": "Apache-2.0",
"repository": {
Expand Down
2 changes: 2 additions & 0 deletions js/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ export class Witness {
publicBytes(): Uint8Array { return this.inner.public_bytes(); }
/** Concatenated 32-byte big-endian limbs of the private witness slots. */
privateBytes(): Uint8Array { return this.inner.private_bytes(); }
/** Public witness in gnark's `MarshalBinary` format. */
gnarkFormatPublicBytes(): Uint8Array { return this.inner.gnark_format_public_bytes(); }
free(): void { this.inner.free(); }
[Symbol.dispose](): void { this.inner[Symbol.dispose](); }
}
Expand Down
14 changes: 14 additions & 0 deletions src/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,20 @@ impl Witness {
pub fn private_bytes(&self) -> Vec<u8> {
flatten(&self.0.private)
}

/// Public witness in gnark's `MarshalBinary` format:
/// 12-byte big-endian header followed by the concatenated
/// 32-byte big-endian public entries.
pub fn gnark_format_public_bytes(&self) -> Vec<u8> {
let body = self.public_bytes();
let n = self.0.public.len() as u32;
let mut out = Vec::with_capacity(12 + body.len());
out.extend_from_slice(&n.to_be_bytes());
out.extend_from_slice(&0u32.to_be_bytes());
out.extend_from_slice(&n.to_be_bytes());
out.extend_from_slice(&body);
out
}
}

fn flatten(elems: &[acir::FieldElement]) -> Vec<u8> {
Expand Down
Loading