diff --git a/risc0-selective-privacy-poc/core/src/account.rs b/risc0-selective-privacy-poc/core/src/account.rs index c4da8dd..7bf9c5a 100644 --- a/risc0-selective-privacy-poc/core/src/account.rs +++ b/risc0-selective-privacy-poc/core/src/account.rs @@ -4,6 +4,8 @@ use risc0_zkvm::{ }; use serde::{Deserialize, Serialize}; +pub type Commitment = u32; + #[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)] pub struct Account { pub address: [u32; 8], @@ -30,9 +32,9 @@ impl Account { } } - /// Returns Hash(Account) - pub fn commitment(&self) -> [u32; 8] { - hash(&to_vec(&self).unwrap()) + /// Returns Hash(Account)[0] (only first word for this POC) + pub fn commitment(&self) -> Commitment { + hash(&to_vec(&self).unwrap())[0] } } @@ -41,14 +43,14 @@ pub fn hash(bytes: &[u32]) -> [u32; 8] { } /// Dummy implementation -pub fn is_in_commitment_tree(_commitment: [u32; 8], _tree_root: [u32; 8]) -> bool { +pub fn is_in_commitment_tree(_commitment: Commitment, _tree_root: [u32; 8]) -> bool { true } /// Returns Hash(Commitment || private_key) -pub fn compute_nullifier(commitment: &[u32; 8], private_key: &[u32; 8]) -> [u32; 8] { - let mut bytes_to_hash = [0; 16]; - bytes_to_hash[..8].copy_from_slice(commitment); - bytes_to_hash[8..].copy_from_slice(private_key); +pub fn compute_nullifier(commitment: &Commitment, private_key: &[u32; 8]) -> [u32; 8] { + let mut bytes_to_hash = [0; 9]; // <- 1 word for the commitment, 8 words for the private key + bytes_to_hash[..1].copy_from_slice(&[*commitment]); + bytes_to_hash[1..].copy_from_slice(private_key); hash(&bytes_to_hash) } diff --git a/risc0-selective-privacy-poc/src/private_execution.rs b/risc0-selective-privacy-poc/src/private_execution.rs index 65e1a97..fae0ed6 100644 --- a/risc0-selective-privacy-poc/src/private_execution.rs +++ b/risc0-selective-privacy-poc/src/private_execution.rs @@ -1,7 +1,10 @@ use outer_methods::{OUTER_ELF, OUTER_ID}; use rand::{rngs::OsRng, Rng}; use risc0_zkvm::{default_prover, ExecutorEnv, Receipt}; -use toy_example_core::{account::Account, input::InputVisibiility}; +use toy_example_core::{ + account::{Account, Commitment}, + input::InputVisibiility, +}; use transfer_methods::{TRANSFER_ELF, TRANSFER_ID}; const COMMITMENT_TREE_ROOT: [u32; 8] = [0xdd, 0xee, 0xaa, 0xdd, 0xbb, 0xee, 0xee, 0xff]; @@ -46,6 +49,8 @@ fn run_private_execution_of_transfer_program() { ]; let num_inputs: u32 = inputs_outputs.len() as u32 / 2; + + // Sample fresh random nonces for the outputs of this execution let output_nonces: Vec<_> = (0..num_inputs).map(|_| new_random_nonce()).collect(); println!("output nonces {output_nonces:?}"); @@ -70,7 +75,7 @@ fn run_private_execution_of_transfer_program() { // Sanity check receipt.verify(OUTER_ID).unwrap(); - let output: (Vec, Vec<[u32; 8]>, Vec<[u32; 8]>) = receipt.journal.decode().unwrap(); + let output: (Vec, Vec<[u32; 8]>, Vec) = receipt.journal.decode().unwrap(); println!("public_outputs: {:?}", output.0); println!("nullifiers: {:?}", output.1); println!("commitments: {:?}", output.2);