diff --git a/risc0-selective-privacy-poc/examples/happy_path.rs b/risc0-selective-privacy-poc/examples/happy_path.rs index d0827a8..d4425ff 100644 --- a/risc0-selective-privacy-poc/examples/happy_path.rs +++ b/risc0-selective-privacy-poc/examples/happy_path.rs @@ -34,7 +34,7 @@ fn main() { let [private_account_user_1, private_account_user_2] = USER_CLIENTS[1] .transfer_private(private_account_user_1, &addresses[2], 8, &mut sequencer) .unwrap(); - println!("📝 Balances after shielded execution"); + println!("📝 Balances after private execution"); print_accounts(&sequencer, &[&private_account_user_1, &private_account_user_2]); // A deshielded execution of the Transfer Program @@ -77,7 +77,11 @@ fn main() { println!("📝 Balances after private piñata execution"); print_accounts( &sequencer, - &[&private_account_user_1, &private_account_user_2, &private_account_user_0], + &[ + &private_account_user_1, + &private_account_user_2, + &private_account_user_0, + ], ); println!("Ok!"); diff --git a/risc0-selective-privacy-poc/examples/mocked_components/client/mod.rs b/risc0-selective-privacy-poc/examples/mocked_components/client/mod.rs index eb43c96..a3861ad 100644 --- a/risc0-selective-privacy-poc/examples/mocked_components/client/mod.rs +++ b/risc0-selective-privacy-poc/examples/mocked_components/client/mod.rs @@ -13,15 +13,11 @@ pub mod transfer_shielded; /// A client that creates and submits transfer transactions pub struct MockedClient { user_private_key: Key, - private_accounts: Vec, } impl MockedClient { pub const fn new(user_private_key: Key) -> Self { - Self { - user_private_key, - private_accounts: Vec::new(), - } + Self { user_private_key } } pub fn user_address(&self) -> Address { @@ -39,8 +35,7 @@ impl MockedClient { ) -> Result, ()> { // Execute and generate proof of the outer program let (receipt, private_outputs) = - nssa::invoke_privacy_execution::

(input_accounts, instruction_data, visibilities, commitment_tree_root) - .unwrap(); + nssa::execute_offchain::

(input_accounts, instruction_data, visibilities, commitment_tree_root).unwrap(); // Send proof to the sequencer sequencer.process_privacy_execution(receipt)?; diff --git a/risc0-selective-privacy-poc/examples/mocked_components/sequencer/mod.rs b/risc0-selective-privacy-poc/examples/mocked_components/sequencer/mod.rs index 2bacc97..aab2710 100644 --- a/risc0-selective-privacy-poc/examples/mocked_components/sequencer/mod.rs +++ b/risc0-selective-privacy-poc/examples/mocked_components/sequencer/mod.rs @@ -17,11 +17,8 @@ pub struct MockedSequencer { accounts: BTreeMap, commitment_tree: SparseMerkleTree, nullifier_set: HashSet, - deployed_program_ids: HashSet, } -/// List of deployed programs -const DEPLOYED_PROGRAM_IDS: [ProgramId; 3] = [TRANSFER_ID, TRANSFER_MULTIPLE_ID, PINATA_ID]; /// The initial balance of the genesis accounts const INITIAL_BALANCE: u128 = 150; /// The address of the piñata program account @@ -45,7 +42,6 @@ impl MockedSequencer { accounts, commitment_tree, nullifier_set, - deployed_program_ids: DEPLOYED_PROGRAM_IDS.iter().cloned().collect(), } } diff --git a/risc0-selective-privacy-poc/examples/mocked_components/sequencer/process_public_execution.rs b/risc0-selective-privacy-poc/examples/mocked_components/sequencer/process_public_execution.rs index 2ab7f55..c6c1366 100644 --- a/risc0-selective-privacy-poc/examples/mocked_components/sequencer/process_public_execution.rs +++ b/risc0-selective-privacy-poc/examples/mocked_components/sequencer/process_public_execution.rs @@ -16,7 +16,7 @@ impl MockedSequencer { .collect::>()?; // Execute the program - let inputs_outputs = nssa::execute::

(&input_accounts, instruction_data)?; + let inputs_outputs = nssa::execute_onchain::

(&input_accounts, instruction_data)?; // Perform consistency checks if !self.inputs_outputs_are_consistent(&input_accounts, &inputs_outputs) { diff --git a/risc0-selective-privacy-poc/examples/private_execution.rs b/risc0-selective-privacy-poc/examples/private_execution.rs index a7d4d7f..1e55b70 100644 --- a/risc0-selective-privacy-poc/examples/private_execution.rs +++ b/risc0-selective-privacy-poc/examples/private_execution.rs @@ -51,7 +51,8 @@ fn main() { let balance_to_move = vec![30, 40]; // Execute and prove the outer program for the TransferMultipleProgram. - let (receipt, _) = nssa::invoke_privacy_execution::( + // This is executed off-chain by the sender. + let (receipt, _) = nssa::execute_offchain::( &[sender, receiver_1, receiver_2], balance_to_move, &visibilities, diff --git a/risc0-selective-privacy-poc/examples/public_execution.rs b/risc0-selective-privacy-poc/examples/public_execution.rs index 9ce0f76..68dabf3 100644 --- a/risc0-selective-privacy-poc/examples/public_execution.rs +++ b/risc0-selective-privacy-poc/examples/public_execution.rs @@ -20,7 +20,7 @@ pub fn main() { let balance_to_move = vec![10, 20]; let inputs_outputs = - nssa::execute::(&[sender, receiver_1, receiver_2], balance_to_move).unwrap(); + nssa::execute_onchain::(&[sender, receiver_1, receiver_2], balance_to_move).unwrap(); println!("OK!"); } diff --git a/risc0-selective-privacy-poc/src/lib.rs b/risc0-selective-privacy-poc/src/lib.rs index 8c09e0f..a3e29d9 100644 --- a/risc0-selective-privacy-poc/src/lib.rs +++ b/risc0-selective-privacy-poc/src/lib.rs @@ -50,30 +50,9 @@ fn execute_and_prove_inner( Ok((receipt, inputs_outputs)) } -/// Executes the program `P` without generating a proof. -/// Returns the list of accounts pre and post states. -pub fn execute( - input_accounts: &[Account], - instruction_data: P::InstructionData, -) -> Result, ()> { - // Write inputs to the program - let mut env_builder = ExecutorEnv::builder(); - write_inputs::

(input_accounts, instruction_data, &mut env_builder)?; - let env = env_builder.build().unwrap(); - - // Execute the program (without proving) - let executor = default_executor(); - let session_info = executor.execute(env, P::PROGRAM_ELF).map_err(|_| ())?; - - // Get (inputs and) outputs - let inputs_outputs: Vec = session_info.journal.decode().map_err(|_| ())?; - - Ok(inputs_outputs) -} - /// Builds the private outputs from the results of the execution of an inner program. /// Populates the nonces with the ones provided. -pub fn build_private_outputs_from_inner_results( +fn build_private_outputs_from_inner_results( inputs_outputs: &[Account], num_inputs: usize, visibilities: &[InputVisibiility], @@ -93,10 +72,31 @@ pub fn build_private_outputs_from_inner_results( .collect() } +/// Executes the program `P` without generating a proof. +/// Returns the list of accounts pre and post states. +pub fn execute_onchain( + input_accounts: &[Account], + instruction_data: P::InstructionData, +) -> Result, ()> { + // Write inputs to the program + let mut env_builder = ExecutorEnv::builder(); + write_inputs::

(input_accounts, instruction_data, &mut env_builder)?; + let env = env_builder.build().unwrap(); + + // Execute the program (without proving) + let executor = default_executor(); + let session_info = executor.execute(env, P::PROGRAM_ELF).map_err(|_| ())?; + + // Get (inputs and) outputs + let inputs_outputs: Vec = session_info.journal.decode().map_err(|_| ())?; + + Ok(inputs_outputs) +} + /// Executes and proves the inner program `P` and executes and proves the outer program on top of it. /// Returns the proof of execution of the outer program and the list of new private accounts /// resulted from this execution. -pub fn invoke_privacy_execution( +pub fn execute_offchain( inputs: &[Account], instruction_data: P::InstructionData, visibilities: &[InputVisibiility],