From b3e53bc32ae77186c6313e536081a7b45382216c Mon Sep 17 00:00:00 2001 From: Sergio Chouhy Date: Wed, 30 Jul 2025 13:40:22 -0300 Subject: [PATCH] fetch accounts with zero balance when not seen before --- risc0-selective-privacy-poc/examples/happy_path.rs | 10 +++++++++- .../mocked_components/client/transfer_deshielded.rs | 2 +- .../mocked_components/client/transfer_shielded.rs | 2 +- .../examples/mocked_components/sequencer/error.rs | 2 -- .../examples/mocked_components/sequencer/mod.rs | 4 ++-- .../sequencer/process_privacy_execution.rs | 2 +- .../sequencer/process_public_execution.rs | 4 ++-- 7 files changed, 16 insertions(+), 10 deletions(-) diff --git a/risc0-selective-privacy-poc/examples/happy_path.rs b/risc0-selective-privacy-poc/examples/happy_path.rs index f6b3fbc..67d87f0 100644 --- a/risc0-selective-privacy-poc/examples/happy_path.rs +++ b/risc0-selective-privacy-poc/examples/happy_path.rs @@ -13,6 +13,14 @@ fn main() { println!("📝 Initial balances"); print_accounts(&sequencer, &[]); + // A public execution of the Transfer Program + // User1 sends 3 tokens to another account + USER_CLIENTS[1] + .transfer_public(&[0xdeadbeef; 8], 3, &mut sequencer) + .unwrap(); + println!("📝 Balances after transfer"); + print_accounts(&sequencer, &[]); + // A public execution of the Transfer Program // User1 sends 51 tokens to the piñata account USER_CLIENTS[1] @@ -58,7 +66,7 @@ fn main() { // User1 claims the prize of the Piñata program to a new self-owned private account let another_private_account_user_1 = { // All of this is executed locally by the User1 - let pinata_account = sequencer.get_account(&PINATA_ADDRESS).unwrap(); + let pinata_account = sequencer.get_account(&PINATA_ADDRESS); let receiver_account = MockedClient::fresh_account_for_mint(USER_CLIENTS[1].user_address()); let visibilities = [AccountVisibility::Public, AccountVisibility::Private(None)]; let preimage = bytes_to_words(b"NSSA Selective privacy is great!").to_vec(); diff --git a/risc0-selective-privacy-poc/examples/mocked_components/client/transfer_deshielded.rs b/risc0-selective-privacy-poc/examples/mocked_components/client/transfer_deshielded.rs index b86ba9d..06c372d 100644 --- a/risc0-selective-privacy-poc/examples/mocked_components/client/transfer_deshielded.rs +++ b/risc0-selective-privacy-poc/examples/mocked_components/client/transfer_deshielded.rs @@ -21,7 +21,7 @@ impl MockedClient { let sender_commitment_auth_path = sequencer.get_authentication_path_for(&from_account.commitment()); // Fetch public account to deshield to - let to_account = sequencer.get_account(to_address).unwrap(); + let to_account = sequencer.get_account(to_address); // Set account visibilities // First entry is the private sender. Second entry is the public receiver diff --git a/risc0-selective-privacy-poc/examples/mocked_components/client/transfer_shielded.rs b/risc0-selective-privacy-poc/examples/mocked_components/client/transfer_shielded.rs index 58a4c06..4298388 100644 --- a/risc0-selective-privacy-poc/examples/mocked_components/client/transfer_shielded.rs +++ b/risc0-selective-privacy-poc/examples/mocked_components/client/transfer_shielded.rs @@ -18,7 +18,7 @@ impl MockedClient { let commitment_tree_root = sequencer.get_commitment_tree_root(); // Fetch sender account from the sequencer - let from_account = sequencer.get_account(&self.user_address()).ok_or(Error::NotFound)?; + let from_account = sequencer.get_account(&self.user_address()); // Create a new default private account for the receiver let to_account = Self::fresh_account_for_mint(*to_address); diff --git a/risc0-selective-privacy-poc/examples/mocked_components/sequencer/error.rs b/risc0-selective-privacy-poc/examples/mocked_components/sequencer/error.rs index f3b3fbc..821c702 100644 --- a/risc0-selective-privacy-poc/examples/mocked_components/sequencer/error.rs +++ b/risc0-selective-privacy-poc/examples/mocked_components/sequencer/error.rs @@ -1,13 +1,11 @@ #[derive(Debug)] pub enum Error { - NotFound, BadInput, } impl std::fmt::Display for Error { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - Error::NotFound => write!(f, "Not found"), Error::BadInput => write!(f, "Bad input"), } } 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 e66bf83..ed3c14f 100644 --- a/risc0-selective-privacy-poc/examples/mocked_components/sequencer/mod.rs +++ b/risc0-selective-privacy-poc/examples/mocked_components/sequencer/mod.rs @@ -54,8 +54,8 @@ impl MockedSequencer { } /// Returns the current state of the account for the given address - pub fn get_account(&self, address: &Address) -> Option { - self.accounts.get(address).cloned() + pub fn get_account(&self, address: &Address) -> Account { + self.accounts.get(address).cloned().unwrap_or(Account::new(*address, 0)) } /// Returns the root of the commitment tree diff --git a/risc0-selective-privacy-poc/examples/mocked_components/sequencer/process_privacy_execution.rs b/risc0-selective-privacy-poc/examples/mocked_components/sequencer/process_privacy_execution.rs index 0b278cd..a8970ee 100644 --- a/risc0-selective-privacy-poc/examples/mocked_components/sequencer/process_privacy_execution.rs +++ b/risc0-selective-privacy-poc/examples/mocked_components/sequencer/process_privacy_execution.rs @@ -15,7 +15,7 @@ impl MockedSequencer { // Reject if the states of the public input accounts used in the inner execution do not // coincide with the on-chain state. for account in output.public_accounts_pre.iter() { - let current_account = self.get_account(&account.address).ok_or(Error::NotFound)?; + let current_account = self.get_account(&account.address); if ¤t_account != account { return Err(Error::BadInput); } 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 fcf7562..1d9ed13 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 @@ -14,8 +14,8 @@ impl MockedSequencer { // Fetch the current state of the input accounts. let input_accounts: Vec = input_account_addresses .iter() - .map(|address| self.get_account(address).ok_or(Error::NotFound)) - .collect::>()?; + .map(|address| self.get_account(address)) + .collect(); // Execute the program let program_output =