diff --git a/goas/.gitignore b/goas/.gitignore index f4247e1..f444679 100644 --- a/goas/.gitignore +++ b/goas/.gitignore @@ -2,3 +2,5 @@ Cargo.lock methods/guest/Cargo.lock target/ +output/ +proof.stark diff --git a/goas/host/src/main.rs b/goas/host/src/main.rs index dd26265..15d0974 100644 --- a/goas/host/src/main.rs +++ b/goas/host/src/main.rs @@ -7,8 +7,9 @@ use common::*; use cl::note::NoteWitness; use cl::input::InputWitness; use cl::output::OutputWitness; -use cl::nullifier::{NullifierCommitment, Nullifier +use cl::nullifier::NullifierSecret; use cl::partial_tx::{PartialTx, PartialTxWitness}; +use cl::merkle; fn main() { // Initialize tracing. In order to view logs, run `RUST_LOG=info cargo run` @@ -26,42 +27,46 @@ fn main() { amount: 10, }; - let in_state_cm = calculate_state_hash(&state), - let in_journal_cm = calculate_journal_hash(&journal), - let in_state_root = merkle::node(in_start_cm, in_journal_cm); + let in_state_cm = calculate_state_hash(&state); + let in_journal_cm = calculate_journal_hash(&journal); + let in_state_root = merkle::node(in_state_cm, in_journal_cm); let in_note = NoteWitness::new(1, "ZONE", in_state_root, &mut rng); let mut out_journal = journal.clone(); out_journal.push(zone_input); - let out_state_cm = calculate_state_hash(&stf(state.clone(), zone_input)), - let out_journal_cm = calculate_journal_hash(&out_journal), + let out_state_cm = calculate_state_hash(&stf(state.clone(), zone_input)); + let out_journal_cm = calculate_journal_hash(&out_journal); let out_state_root = merkle::node(out_state_cm, out_journal_cm); - let out_note = NoteWitness::new(1, "ZONE", out_state_root, &mut rng); + let out_note = NoteWitness::new(1, "ZONE", out_state_root, &mut rng); + let input = InputWitness::random(in_note, &mut rng); + let output = OutputWitness::random(out_note, NullifierSecret::random(&mut rng).commit(), &mut rng); let ptx = PartialTx::from_witness(PartialTxWitness { - inputs: vec![InputWitness::random(in_note, &mut rng)], - outputs: vec![OutputWitness::random(out_note, NullifierCommitment::random(&mut rng), &mut rng)], + inputs: vec![input.clone()], + outputs: vec![output.clone()], }); - let ptx_root = ptx.root(); + let ptx_root = ptx.root().0; let in_ptx_path = ptx.input_merkle_path(0); let out_ptx_path = ptx.output_merkle_path(0); let env = ExecutorEnv::builder() .write(&ptx_root) .unwrap() - .write(&ptx.input_root) + .write(&ptx.input_root()) .unwrap() - .write(&ptx.output_root) + .write(&ptx.output_root()) .unwrap() .write(&in_ptx_path) .unwrap() .write(&out_ptx_path) .unwrap() - .write(&in_note) + .write(&input) .unwrap() - .write(&out_note) + .write(&output) + .unwrap() + .write(&zone_input) .unwrap() .write(&state) .unwrap() diff --git a/goas/methods/guest/Cargo.toml b/goas/methods/guest/Cargo.toml index cb06bf3..4bbf258 100644 --- a/goas/methods/guest/Cargo.toml +++ b/goas/methods/guest/Cargo.toml @@ -10,4 +10,5 @@ risc0-zkvm = { version = "1.0.1", default-features = false, features = ['std'] } blake2 = "0.10" serde = { version = "1.0", features = ["derive"] } bincode = "1" -common = { path = "../../common" } \ No newline at end of file +common = { path = "../../common" } +cl = { path = "../../../cl" } \ No newline at end of file diff --git a/goas/methods/guest/src/main.rs b/goas/methods/guest/src/main.rs index 25070aa..a2f6543 100644 --- a/goas/methods/guest/src/main.rs +++ b/goas/methods/guest/src/main.rs @@ -2,34 +2,23 @@ use blake2::{Blake2s256, Digest}; use risc0_zkvm::guest::env; use common::*; use cl::merkle; -use cl::note::NoteWitness +use cl::note::NoteWitness; +use cl::input::InputWitness; +use cl::output::OutputWitness; /// Public Inputs: /// * ptx_root: the root of the partial tx merkle tree of inputs/outputs /// Private inputs: /// TODO -/// Glue the zone and the cl together, specifically, it verifies the note requesting -/// a transfer is included as part of the same transaction in the cl -fn verify_ptx_inputs(ptx_root: [u8; 32], ptx_path: &[[u8; 32]], note: &Note) { - assert!(verify_path(&ptx_root, &ptx_path, ¬e)); -} - -/// Glue the zone and the cl together, specifically, it verifies an output note -/// containing the zone state is included as part of the same transaction in the cl -/// (this is done in the death condition to disallow burning) -fn verify_ptx_outputs(ptx_root: [u8; 32], ptx_path: &[[u8; 32]], note: &Note) { - assert!(verify_path(&ptx_root, &ptx_path, ¬e)); -} - fn execute( ptx_root: [u8; 32], input_root: [u8; 32], output_root: [u8; 32], in_ptx_path: Vec, out_ptx_path: Vec, - in_note: NoteWitness, - out_note: NotWitness, + in_note: InputWitness, + out_note: OutputWitness, input: Input, state: State, mut journal: Journal, @@ -37,13 +26,16 @@ fn execute( // verify ptx/cl preconditions assert_eq!(ptx_root, merkle::node(input_root, output_root)); - assert!(merkle::verify_path(in_note.commit().0, in_ptx_path, input_root)); + + // Glue the zone and the cl together, specifically, it verifies the note requesting + // a transfer is included as part of the same transaction in the cl + assert!(merkle::verify_path(merkle::leaf(&in_note.commit().to_bytes()), &in_ptx_path, input_root)); // check the commitments match the actual data let state_cm = calculate_state_hash(&state); let journal_cm = calculate_journal_hash(&journal); let state_root = merkle::node(state_cm, journal_cm); - assert_eq!(state_root, in_note.state); + assert_eq!(state_root, in_note.note.state); // then run the state transition function let state = stf(state, input); @@ -55,8 +47,12 @@ fn execute( let out_journal_cm = calculate_journal_hash(&journal); let out_state_root = merkle::node(out_state_cm, out_journal_cm); // TODO: verify death constraints are propagated - assert_eq!(out_state_root, out_note.state); - assert!(merkle::verify_path(out_note.commit().0, out_ptx_path, output_root)); + assert_eq!(out_state_root, out_note.note.state); + + // Glue the zone and the cl together, specifically, it verifies an output note + // containing the zone state is included as part of the same transaction in the cl + // (this is done in the death condition to disallow burning) + assert!(merkle::verify_path(merkle::leaf(&out_note.commit().to_bytes()), &out_ptx_path, output_root)); } fn main() { @@ -68,9 +64,9 @@ fn main() { let output_root: [u8; 32] = env::read(); let in_ptx_path: Vec = env::read(); let out_ptx_path: Vec = env::read(); - let in_note: NoteWitness = env::read(); - let out_note: NoteWitness = env::read(); - let input: Input = env::read() + let in_note: InputWitness = env::read(); + let out_note: OutputWitness = env::read(); + let input: Input = env::read(); let state: State = env::read(); let journal: Journal = env::read(); @@ -86,8 +82,3 @@ fn calculate_journal_hash(journal: &Journal) -> [u8; 32] { let bytes = bincode::serialize(journal).unwrap(); Blake2s256::digest(&bytes).into() } - -fn verify_path(_ptx_root: &[u8; 32], _ptx_path: &[[u8; 32]], _note: &Note) -> bool { - // for now we just return true - true -}