diff --git a/risc0-selective-privacy-poc/outer_methods/guest/src/bin/outer.rs b/risc0-selective-privacy-poc/outer_methods/guest/src/bin/outer.rs index d111bdd..0743fa7 100644 --- a/risc0-selective-privacy-poc/outer_methods/guest/src/bin/outer.rs +++ b/risc0-selective-privacy-poc/outer_methods/guest/src/bin/outer.rs @@ -1,42 +1,43 @@ use risc0_zkvm::{guest::env, sha::{Impl, Sha256}, serde::to_vec}; use toy_example_core::{Account, hash, compute_nullifier, is_in_commitment_tree}; -use transfer_methods::TRANSFER_ID; fn main() { // Read inputs - let sender_private_key: [u32; 8] = env::read(); - let sender: Account = env::read(); - let receiver: Account = env::read(); + let account_1_private_key: [u32; 8] = env::read(); + let account_1: Account = env::read(); + let account_2: Account = env::read(); let balance_to_move: u128 = env::read(); - let sender_post: Account = env::read(); - let receiver_post: Account = env::read(); + let account_1_post: Account = env::read(); + let account_2_post: Account = env::read(); let commitment_tree_root: [u32; 8] = env::read(); + let program_id: [u32; 8] = env::read(); - // Assert receiver account is fresh - assert_eq!(receiver.balance, 0); + // Assert account_2 account is fresh + assert_eq!(account_2.balance, 0); - // Prove ownership of sender account by proving + // Prove ownership of account_1 account by proving // knowledge of the pre-image of its address - assert_eq!(hash(&sender_private_key), sender.address); + assert_eq!(hash(&account_1_private_key), account_1.address); - // Compute sender account commitment and prove it belongs to commitments tree - let sender_commitment = sender.commitment(); - assert!(is_in_commitment_tree(sender_commitment, commitment_tree_root)); + // Compute account_1 account commitment and prove it belongs to commitments tree + let account_1_commitment = account_1.commitment(); + assert!(is_in_commitment_tree(account_1_commitment, commitment_tree_root)); - // Compute nullifier of sender account - let sender_nullifier = compute_nullifier(sender_commitment, sender_private_key); + // Compute nullifier of account_1 account + let account_1_nullifier = compute_nullifier(account_1_commitment, account_1_private_key); - // Compute receiver commitment - let receiver_commitment = receiver_post.commitment(); + // Compute accounts post states commitments + let account_1_post_commitment = account_1_post.commitment(); + let account_2_post_commitment = account_2_post.commitment(); // Verify pre states and post states of accounts are consistent - // with the execution of the TRANSFER_ELF program - env::verify(TRANSFER_ID, &to_vec(&(sender.clone(), receiver.clone(), sender_post.clone(), receiver_post.clone())).unwrap()).unwrap(); + // with the execution of the `program_id`` program + env::verify(program_id, &to_vec(&(account_1.clone(), account_2.clone(), account_1_post.clone(), account_2_post.clone())).unwrap()).unwrap(); - // Assert TRANSFER_ELF program didn't modify address fields - assert_eq!(sender.address, sender_post.address); - assert_eq!(receiver.address, receiver_post.address); + // Assert `program_id` program didn't modify address fields + assert_eq!(account_1.address, account_1_post.address); + assert_eq!(account_2.address, account_2_post.address); - // Output nullifier - env::commit(&(sender_nullifier, receiver_commitment)); + // Output nullifier and commitments of new private accounts + env::commit(&(account_1_nullifier, account_1_post_commitment, account_2_post_commitment)); } diff --git a/risc0-selective-privacy-poc/src/lib.rs b/risc0-selective-privacy-poc/src/lib.rs index b2b85bb..27e629a 100644 --- a/risc0-selective-privacy-poc/src/lib.rs +++ b/risc0-selective-privacy-poc/src/lib.rs @@ -62,6 +62,7 @@ pub fn run_private_execution_of_transfer_program() { env_builder.write(&sender_post).unwrap(); env_builder.write(&receiver_post).unwrap(); env_builder.write(&commitment_tree_root).unwrap(); + env_builder.write(&TRANSFER_ID).unwrap(); let env = env_builder.build().unwrap(); let prover = default_prover(); @@ -71,11 +72,13 @@ pub fn run_private_execution_of_transfer_program() { let receipt = prove_info.receipt; + // Sanity check receipt.verify(OUTER_ID).unwrap(); - let (nullifier, commitment): ([u32; 8], [u32; 8]) = receipt.journal.decode().unwrap(); - println!("nullifier: {:?}", nullifier); - println!("commitment: {:?}", commitment); + let output: [[u32; 8]; 3] = receipt.journal.decode().unwrap(); + println!("nullifier: {:?}", output[0]); + println!("commitment_1: {:?}", output[1]); + println!("commitment_2: {:?}", output[2]); } pub fn run_public_execution_of_transfer_program() {