mirror of
https://github.com/logos-blockchain/lssa-zkvm-testing.git
synced 2026-01-06 23:33:08 +00:00
moved examples to examples dir
This commit is contained in:
parent
8feb17db1a
commit
d4a306d67a
@ -1,5 +1,7 @@
|
||||
mod programs;
|
||||
|
||||
use outer_methods::{OUTER_ELF, OUTER_ID};
|
||||
use rand::{rngs::OsRng, Rng};
|
||||
use programs::TransferProgram;
|
||||
use risc0_zkvm::{default_prover, ExecutorEnv, ProveInfo, Receipt};
|
||||
use sparse_merkle_tree::SparseMerkleTree;
|
||||
use toy_example_core::{
|
||||
@ -9,14 +11,7 @@ use toy_example_core::{
|
||||
types::{Address, AuthenticationPath, Commitment, Nonce, Nullifier},
|
||||
};
|
||||
use transfer_methods::{TRANSFER_ELF, TRANSFER_ID};
|
||||
|
||||
use crate::program::{execute_and_prove, prove_privacy_execution, Program};
|
||||
use crate::TransferProgram;
|
||||
|
||||
pub fn new_random_nonce() -> Nonce {
|
||||
let mut rng = OsRng;
|
||||
std::array::from_fn(|_| rng.gen())
|
||||
}
|
||||
use tuki::program::{prove_privacy_execution, Program};
|
||||
|
||||
fn mint_fresh_account(address: Address) -> Account {
|
||||
let nonce = [0; 8];
|
||||
@ -26,7 +21,7 @@ fn mint_fresh_account(address: Address) -> Account {
|
||||
/// A private execution of the transfer function.
|
||||
/// This actually "burns" a sender private account and "mints" two new private accounts:
|
||||
/// 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() {
|
||||
fn main() {
|
||||
// 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 = [1, 2, 3, 4, 4, 3, 2, 1];
|
||||
@ -74,13 +69,3 @@ fn run_private_execution_of_transfer_program() {
|
||||
println!("nullifiers: {:?}", output.1);
|
||||
println!("commitments: {:?}", output.2);
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_private() {
|
||||
run_private_execution_of_transfer_program();
|
||||
}
|
||||
}
|
||||
11
risc0-selective-privacy-poc/examples/programs/mod.rs
Normal file
11
risc0-selective-privacy-poc/examples/programs/mod.rs
Normal file
@ -0,0 +1,11 @@
|
||||
use transfer_methods::{TRANSFER_ELF, TRANSFER_ID};
|
||||
use tuki::program::Program;
|
||||
|
||||
pub struct TransferProgram;
|
||||
|
||||
impl Program for TransferProgram {
|
||||
const PROGRAM_ID: [u32; 8] = TRANSFER_ID;
|
||||
const PROGRAM_ELF: &[u8] = TRANSFER_ELF;
|
||||
// Amount to transfer
|
||||
type InstructionData = u128;
|
||||
}
|
||||
@ -1,16 +1,17 @@
|
||||
mod programs;
|
||||
|
||||
use risc0_zkvm::{default_executor, ExecutorEnv};
|
||||
use toy_example_core::account::Account;
|
||||
use transfer_methods::TRANSFER_ELF;
|
||||
|
||||
use crate::{
|
||||
program::{execute, Program},
|
||||
TransferProgram,
|
||||
};
|
||||
use tuki::program::{execute, Program};
|
||||
|
||||
use crate::programs::TransferProgram;
|
||||
|
||||
/// 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() {
|
||||
pub fn main() {
|
||||
// Account fetched from the chain state with 150 in its balance.
|
||||
let sender = {
|
||||
let mut account = Account::new([5; 8], [98; 8]);
|
||||
@ -38,13 +39,3 @@ pub fn run_public_execution_of_transfer_program() {
|
||||
inputs_outputs[1], inputs_outputs[3],
|
||||
);
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_public() {
|
||||
run_public_execution_of_transfer_program();
|
||||
}
|
||||
}
|
||||
@ -1,15 +1,2 @@
|
||||
mod private_execution;
|
||||
mod program;
|
||||
mod public_execution;
|
||||
pub mod program;
|
||||
|
||||
use program::Program;
|
||||
use transfer_methods::{TRANSFER_ELF, TRANSFER_ID};
|
||||
|
||||
struct TransferProgram;
|
||||
|
||||
impl Program for TransferProgram {
|
||||
const PROGRAM_ID: [u32; 8] = TRANSFER_ID;
|
||||
const PROGRAM_ELF: &[u8] = TRANSFER_ELF;
|
||||
// Amount to transfer
|
||||
type InstructionData = u128;
|
||||
}
|
||||
|
||||
@ -1,13 +1,17 @@
|
||||
use outer_methods::OUTER_ELF;
|
||||
use rand::{rngs::OsRng, Rng};
|
||||
use risc0_zkvm::{
|
||||
default_executor, default_prover, ExecutorEnv, ExecutorEnvBuilder, ProveInfo, Receipt,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use toy_example_core::{account::Account, input::InputVisibiility};
|
||||
use toy_example_core::{account::Account, input::InputVisibiility, types::Nonce};
|
||||
|
||||
use crate::private_execution::new_random_nonce;
|
||||
pub fn new_random_nonce() -> Nonce {
|
||||
let mut rng = OsRng;
|
||||
std::array::from_fn(|_| rng.gen())
|
||||
}
|
||||
|
||||
pub(crate) trait Program {
|
||||
pub trait Program {
|
||||
const PROGRAM_ID: [u32; 8];
|
||||
const PROGRAM_ELF: &[u8];
|
||||
type InstructionData: Serialize + for<'de> Deserialize<'de>;
|
||||
@ -45,7 +49,7 @@ pub(crate) fn execute_and_prove<P: Program>(
|
||||
Ok((receipt, inputs_outputs))
|
||||
}
|
||||
|
||||
pub(crate) fn execute<P: Program>(
|
||||
pub fn execute<P: Program>(
|
||||
input_accounts: &[Account],
|
||||
instruction_data: &P::InstructionData,
|
||||
) -> Result<Vec<Account>, ()> {
|
||||
@ -64,7 +68,7 @@ pub(crate) fn execute<P: Program>(
|
||||
Ok(inputs_outputs)
|
||||
}
|
||||
|
||||
pub(crate) fn prove_privacy_execution<P: Program>(
|
||||
pub fn prove_privacy_execution<P: Program>(
|
||||
inputs: &[Account],
|
||||
instruction_data: &P::InstructionData,
|
||||
visibilities: &[InputVisibiility],
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user