minor changes

This commit is contained in:
Sergio Chouhy 2025-07-11 19:44:43 -03:00
parent 296fc2c5ba
commit 2175fcd497
4 changed files with 27 additions and 15 deletions

View File

@ -5,11 +5,12 @@ use toy_example_core::{Account, hash, compute_nullifier, is_in_commitment_tree};
/// Circuit for proving correct execution of some program with program id
/// equal to `program_id` (last input).
///
/// Currently only supports private execution of a program with two inputs, one
/// of which must be a fresh new account (for example a private transfer function)
/// Currently only supports private execution of a program with two input accounts, one
/// of which must be a fresh new account (`account_2`) (for example a private transfer function).
///
/// This circuit checks:
/// - That accounts pre states and post states are consistent with the execution of the given `program_id`.
/// - That `account_2` is fresh (meaning, for this toy example, that it has 0 balance).
/// - That `program_id` execution didn't change addresses of the accounts.
///
/// Outputs:
@ -20,13 +21,12 @@ fn main() {
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 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 account_2 account is fresh
// Assert account_2 is a fresh account
assert_eq!(account_2.balance, 0);
// Prove ownership of account_1 account by proving

View File

@ -9,14 +9,18 @@ use toy_example_core::Account;
/// A private execution of the transfer function.
/// This actually "burns" a sender private account and "mints" two new private accounts:
/// one for the recepient with the transfered balance, and another owned by the sender with the remaining balance.
/// one for the recipient with the transferred balance, and another owned by the sender with the remaining balance.
fn run_private_execution_of_transfer_program() {
let commitment_tree_root = [0xdd, 0xee, 0xaa, 0xdd, 0xbb, 0xee, 0xee, 0xff];
// This is supposed to be an existing private account (UTXO) with balance equal to 150.
// And it is supposed to be a private account of the user running this private execution (hence the access to the private key)
let sender_private_key = [0; 8];
let mut sender = Account::new_from_private_key(sender_private_key, [1; 8]);
sender.balance = 150;
let sender = {
// Creating it now but it's supposed to be already created by other previous transactions.
let mut account = Account::new_from_private_key(sender_private_key, [1; 8]);
account.balance = 150;
account
};
let balance_to_move: u128 = 3;
// This is the new private account (UTXO) being minted by this private execution.
@ -35,7 +39,6 @@ fn run_private_execution_of_transfer_program() {
env_builder.write(&sender_private_key).unwrap();
env_builder.write(&sender).unwrap();
env_builder.write(&receiver) .unwrap();
env_builder.write(&balance_to_move).unwrap();
env_builder.write(&sender_post).unwrap();
env_builder.write(&receiver_post).unwrap();
env_builder.write(&commitment_tree_root).unwrap();

View File

@ -2,14 +2,23 @@ use risc0_zkvm::{default_executor, ExecutorEnv};
use toy_example_core::Account;
use transfer_methods::TRANSFER_ELF;
/// A public execution.
/// This would be executed by the runtime after checking that
/// the initiating transaction includes the sender's signature.
pub fn run_public_execution_of_transfer_program() {
let sender_private_key = [0; 8];
let mut sender = Account::new_from_private_key(sender_private_key, [1; 8]);
sender.balance = 150;
// Account fetched from the chain state with 150 in its balance.
let sender = {
let mut account = Account::new([5; 8], [98; 8]);
account.balance = 150;
account
};
let receiver_private_key = [99; 8];
let mut receiver = Account::new_from_private_key(receiver_private_key, [1; 8]);
receiver.balance = 900;
// Account fetched from the chain state with 900 in its balance.
let receiver = {
let mut account = Account::new([6; 8], [99; 8]);
account.balance = 900;
account
};
let balance_to_move: u128 = 3;

View File

@ -3,7 +3,7 @@ use toy_example_core::Account;
/// A transfer of balance program.
/// To be used both in public and private contexts
/// To be used both in public and private contexts.
fn main() {
let sender: Account = env::read();
let receiver: Account = env::read();