Skip to content

Commit 76dcc15

Browse files
committed
✨ Add v2 for Noir parser for blob abstraction
1 parent 53fab88 commit 76dcc15

File tree

7 files changed

+413
-96
lines changed

7 files changed

+413
-96
lines changed

crates/hyli-verifiers/src/lib.rs

Lines changed: 81 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -285,10 +285,7 @@ pub mod sp1_4 {
285285
mod tests {
286286
use std::{fs::File, io::Read};
287287

288-
use hyli_model::{
289-
Blob, BlobData, BlobIndex, HyliOutput, Identity, IndexedBlobs, ProgramId, ProofData,
290-
StateCommitment, TxHash,
291-
};
288+
use hyli_model::{BlobIndex, Identity, ProgramId, ProofData, StateCommitment, TxHash};
292289

293290
use super::noir::verify as noir_proof_verifier;
294291

@@ -303,74 +300,94 @@ mod tests {
303300
/*
304301
For this test, the proof/vk and the output are obtained running this simple Noir code
305302
```
306-
fn main(
307-
version: pub u32,
308-
initial_state_len: pub u32,
309-
initial_state: pub [u8; 4],
310-
next_state_len: pub u32,
311-
next_state: pub [u8; 4],
312-
identity_len: pub u8,
313-
identity: pub str<56>,
314-
tx_hash_len: pub u32,
315-
tx_hash: pub [u8; 0],
316-
index: pub u32,
317-
blobs_len: pub u32,
318-
blobs: pub [Field; 10],
319-
success: pub bool
320-
) {}
321-
```
322-
With the values:
323-
```
324-
version = 1
325-
blobs = [3, 1, 1, 2, 1, 1, 2, 1, 1, 0]
326-
initial_state_len = 4
327-
initial_state = [0, 0, 0, 0]
328-
next_state_len = 4
329-
next_state = [0, 0, 0, 0]
330-
identity_len = 56
331-
identity = "3f368bf90c71946fc7b0cde9161ace42985d235f@ecdsa_secp256r1"
332-
tx_hash_len = 0
333-
tx_hash = []
334-
blobs_len = 9
335-
index = 0
336-
success = 1
303+
struct BlobInput<let NAME_MAX: u32, let DATA_MAX: u32> {
304+
index: u32,
305+
contract_name_len: u32,
306+
contract_name: str<NAME_MAX>,
307+
data_capacity: u32,
308+
data_len: u32,
309+
data: [u8; DATA_MAX],
310+
}
311+
struct HyliOutput<
312+
let INITIAL_STATE_MAX: u32,
313+
let NEXT_STATE_MAX: u32,
314+
let IDENTITY_MAX: u32,
315+
let BLOBS_MAX: u32,
316+
let BLOB_NAME_MAX: u32,
317+
let BLOB_DATA_MAX: u32,
318+
let PROGRAM_OUTPUT_MAX: u32
319+
> {
320+
version: u32,
321+
initial_state_len: u32,
322+
initial_state_max: u32,
323+
initial_state: [u8; INITIAL_STATE_MAX],
324+
next_state_len: u32,
325+
next_state_max: u32,
326+
next_state: [u8; NEXT_STATE_MAX],
327+
identity_len: u32,
328+
identity_max: u32,
329+
identity: str<IDENTITY_MAX>,
330+
index: u32,
331+
blob_count: u32,
332+
blob_slots: u32,
333+
blob_name_max: u32,
334+
blob_data_max: u32,
335+
blobs: [BlobInput<BLOB_NAME_MAX, BLOB_DATA_MAX>; BLOBS_MAX],
336+
tx_blob_count: u32,
337+
tx_hash: [u8; 32],
338+
success: bool,
339+
program_outputs_max: u32,
340+
program_outputs_len: u32,
341+
program_outputs: [u8; PROGRAM_OUTPUT_MAX],
342+
}
343+
344+
fn main(hyli_output: pub HyliOutput<4, 4, 56, 2, 8, 4, 2>) {
345+
assert(hyli_output.version == 2);
346+
assert(hyli_output.initial_state_len == 4);
347+
assert(hyli_output.initial_state_max == INITIAL_STATE_MAX);
348+
assert(hyli_output.next_state_len == 4);
349+
assert(hyli_output.next_state_max == NEXT_STATE_MAX);
350+
assert(hyli_output.identity_len == 56);
351+
assert(hyli_output.identity_max == IDENTITY_MAX);
352+
assert(hyli_output.blob_slots == BLOB_SLOTS);
353+
assert(hyli_output.blob_name_max == BLOB_NAME_MAX);
354+
assert(hyli_output.blob_data_max == BLOB_DATA_MAX);
355+
assert(hyli_output.blob_count <= hyli_output.blob_slots);
356+
assert(hyli_output.tx_hash_len == 32);
357+
assert(hyli_output.program_outputs_max == PROGRAM_OUTPUT_MAX);
358+
assert(hyli_output.program_outputs_len <= hyli_output.program_outputs_max);
359+
assert(hyli_output.program_outputs_len == 2);
360+
assert(hyli_output.success);
361+
}
337362
```
338363
*/
339364
#[ignore = "manual test"]
340365
#[test_log::test]
341-
fn test_noir_proof_verifier() {
342-
let noir_proof = load_file_as_bytes("./tests/proofs/webauthn.noir.proof");
343-
let image_id = load_file_as_bytes("./tests/proofs/webauthn.noir.vk");
366+
fn test_noir_proof_verifier_v2() {
367+
let mut noir_proof = load_file_as_bytes("../../tests/proofs/parserv2.noir.public_inputs");
368+
noir_proof.extend(load_file_as_bytes("../../tests/proofs/parserv2.noir.proof"));
369+
let image_id = load_file_as_bytes("../../tests/proofs/parserv2.noir.vk");
344370

345371
let result = noir_proof_verifier(&ProofData(noir_proof), &ProgramId(image_id));
346372
match result {
347373
Ok(outputs) => {
348-
assert_eq!(
349-
outputs,
350-
vec![HyliOutput {
351-
version: 1,
352-
initial_state: StateCommitment(vec![0, 0, 0, 0]),
353-
next_state: StateCommitment(vec![0, 0, 0, 0]),
354-
identity: Identity(
355-
"3f368bf90c71946fc7b0cde9161ace42985d235f@ecdsa_secp256r1".to_owned()
356-
),
357-
index: BlobIndex(0),
358-
blobs: IndexedBlobs(vec![(
359-
BlobIndex(0),
360-
Blob {
361-
contract_name: "webauthn".into(),
362-
data: BlobData(vec![3, 1, 1, 2, 1, 1, 2, 1, 1, 0])
363-
}
364-
)]),
365-
tx_blob_count: 1,
366-
success: true,
367-
tx_hash: TxHash::default(), // TODO
368-
state_reads: vec![],
369-
tx_ctx: None,
370-
onchain_effects: vec![],
371-
program_outputs: vec![]
372-
}]
373-
);
374+
assert_eq!(outputs.len(), 1);
375+
let output = &outputs[0];
376+
assert_eq!(output.version, 2);
377+
assert_eq!(output.initial_state, StateCommitment(vec![0, 0, 0, 0]));
378+
assert_eq!(output.next_state, StateCommitment(vec![0, 0, 0, 0]));
379+
assert_eq!(output.identity, Identity("transfer@hyli_utxo".to_owned()));
380+
assert_eq!(output.index, BlobIndex(1));
381+
assert_eq!(output.tx_blob_count, 2);
382+
assert!(output.success);
383+
assert_eq!(output.tx_hash, TxHash(vec![0; 32]));
384+
assert!(output.program_outputs.is_empty());
385+
386+
assert_eq!(output.blobs.0.len(), 1);
387+
let (blob_index, blob) = &output.blobs.0[0];
388+
assert_eq!(*blob_index, BlobIndex(1));
389+
assert_eq!(blob.contract_name.0, "hyli_utxo");
390+
assert!(!blob.data.0.is_empty());
374391
}
375392
Err(e) => panic!("Noir verification failed: {e:?}"),
376393
}

0 commit comments

Comments
 (0)