mirror of
https://github.com/logos-blockchain/lssa-zkvm-testing.git
synced 2026-02-25 23:53:09 +00:00
rename
This commit is contained in:
parent
e1f24f3411
commit
25dd3cb931
@ -24,7 +24,7 @@ fn main() {
|
||||
let sender_addr = addresses[1];
|
||||
let receiver_addr = addresses[2];
|
||||
sequencer
|
||||
.invoke_public_execution::<TransferProgram>(&[sender_addr, receiver_addr], 10)
|
||||
.process_public_execution::<TransferProgram>(&[sender_addr, receiver_addr], 10)
|
||||
.unwrap();
|
||||
println!("🚀 Balances after transfer");
|
||||
sequencer.print();
|
||||
@ -60,7 +60,7 @@ fn main() {
|
||||
// A public execution of the Pinata program
|
||||
let preimage = bytes_to_words(b"NSSA Selective privacy is great!").to_vec();
|
||||
sequencer
|
||||
.invoke_public_execution::<PinataProgram>(&[addresses[0], addresses[3]], preimage)
|
||||
.process_public_execution::<PinataProgram>(&[addresses[0], addresses[3]], preimage)
|
||||
.unwrap();
|
||||
println!("🚀 Balances after public piñata execution");
|
||||
sequencer.print();
|
||||
|
||||
@ -16,11 +16,6 @@ pub mod transfer_shielded;
|
||||
pub struct MockedClient;
|
||||
|
||||
impl MockedClient {
|
||||
pub fn fresh_account_for_mint(address: Address) -> Account {
|
||||
let nonce = [0; 8];
|
||||
Account::new(address, nonce)
|
||||
}
|
||||
|
||||
fn prove_and_send_to_sequencer<P: nssa::Program>(
|
||||
input_accounts: &[Account],
|
||||
instruction_data: P::InstructionData,
|
||||
@ -40,9 +35,14 @@ impl MockedClient {
|
||||
|
||||
// Send to te sequencer
|
||||
sequencer
|
||||
.invoke_privacy_execution(receipt, &output.0, &output.1, &output.2)
|
||||
.process_privacy_execution(receipt, &output.0, &output.1, &output.2)
|
||||
.unwrap();
|
||||
|
||||
private_outputs
|
||||
}
|
||||
|
||||
pub fn fresh_account_for_mint(address: Address) -> Account {
|
||||
let nonce = [0; 8];
|
||||
Account::new(address, nonce)
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,76 +0,0 @@
|
||||
use core::{
|
||||
account::Account,
|
||||
types::{Commitment, Nullifier},
|
||||
};
|
||||
|
||||
use risc0_zkvm::Receipt;
|
||||
|
||||
use super::MockedSequencer;
|
||||
|
||||
impl MockedSequencer {
|
||||
pub fn invoke_privacy_execution(
|
||||
&mut self,
|
||||
receipt: Receipt,
|
||||
public_inputs_outputs: &[Account],
|
||||
nullifiers: &[Nullifier],
|
||||
commitments: &[Commitment],
|
||||
) -> Result<(), ()> {
|
||||
let commitments_tree_root = self.get_commitment_tree_root();
|
||||
if public_inputs_outputs.len() % 2 != 0 {
|
||||
return Err(());
|
||||
}
|
||||
|
||||
let num_input_public = public_inputs_outputs.len() >> 1;
|
||||
for account in public_inputs_outputs.iter().take(num_input_public) {
|
||||
let current_account = self.get_account(&account.address).ok_or(())?;
|
||||
if ¤t_account != account {
|
||||
return Err(());
|
||||
}
|
||||
}
|
||||
|
||||
// Check that nullifiers have not been added before
|
||||
if nullifiers
|
||||
.iter()
|
||||
.any(|nullifier| self.nullifier_set.contains(nullifier))
|
||||
{
|
||||
return Err(());
|
||||
}
|
||||
|
||||
// Check that commitments are new too
|
||||
if commitments
|
||||
.iter()
|
||||
.any(|commitment| self.commitment_tree.values().contains(commitment))
|
||||
{
|
||||
return Err(());
|
||||
}
|
||||
|
||||
// Verify consistency between public accounts, nullifiers and commitments
|
||||
nssa::verify_privacy_execution(
|
||||
receipt,
|
||||
public_inputs_outputs,
|
||||
nullifiers,
|
||||
commitments,
|
||||
&commitments_tree_root,
|
||||
)?;
|
||||
|
||||
// Update accounts
|
||||
public_inputs_outputs
|
||||
.iter()
|
||||
.cloned()
|
||||
.skip(num_input_public)
|
||||
.for_each(|account_post_state| {
|
||||
self.accounts
|
||||
.insert(account_post_state.address, account_post_state);
|
||||
});
|
||||
|
||||
// Add nullifiers
|
||||
self.nullifier_set.extend(nullifiers);
|
||||
|
||||
// Add commitments
|
||||
for commitment in commitments.iter() {
|
||||
self.commitment_tree.add_value(*commitment);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@ -1,72 +0,0 @@
|
||||
use core::{account::Account, types::Address};
|
||||
|
||||
use super::MockedSequencer;
|
||||
|
||||
impl MockedSequencer {
|
||||
pub fn invoke_public_execution<P: nssa::Program>(
|
||||
&mut self,
|
||||
input_account_addresses: &[Address],
|
||||
instruction_data: P::InstructionData,
|
||||
) -> Result<(), ()> {
|
||||
// Fetch accounts
|
||||
let input_accounts: Vec<Account> = input_account_addresses
|
||||
.iter()
|
||||
.map(|address| self.get_account(address).ok_or(()))
|
||||
.collect::<Result<_, _>>()?;
|
||||
|
||||
// Execute
|
||||
let inputs_outputs = nssa::execute::<P>(&input_accounts, instruction_data)?;
|
||||
|
||||
// Perform consistency checks
|
||||
if !self.inputs_outputs_are_consistent(&input_accounts, &inputs_outputs) {
|
||||
return Err(());
|
||||
}
|
||||
|
||||
// Update accounts
|
||||
inputs_outputs
|
||||
.into_iter()
|
||||
.skip(input_accounts.len())
|
||||
.for_each(|account_post_state| {
|
||||
self.accounts
|
||||
.insert(account_post_state.address, account_post_state);
|
||||
});
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn inputs_outputs_are_consistent(
|
||||
&self,
|
||||
input_accounts: &[Account],
|
||||
inputs_outputs: &[Account],
|
||||
) -> bool {
|
||||
let num_inputs = input_accounts.len();
|
||||
if inputs_outputs.len() != num_inputs * 2 {
|
||||
return false;
|
||||
}
|
||||
|
||||
let (claimed_accounts_pre, accounts_post) = inputs_outputs.split_at(num_inputs);
|
||||
if claimed_accounts_pre != input_accounts {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (account_pre, account_post) in input_accounts.iter().zip(accounts_post) {
|
||||
if account_pre.address != account_post.address {
|
||||
return false;
|
||||
}
|
||||
if account_pre.nonce != account_post.nonce {
|
||||
return false;
|
||||
}
|
||||
// Redundant with previous checks, but better make it explicit.
|
||||
if !self.accounts.contains_key(&account_post.address) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
let accounts_pre_total_balance: u128 =
|
||||
input_accounts.iter().map(|account| account.balance).sum();
|
||||
let accounts_post_total_balance: u128 =
|
||||
accounts_post.iter().map(|account| account.balance).sum();
|
||||
if accounts_pre_total_balance != accounts_post_total_balance {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -10,8 +10,8 @@ use sparse_merkle_tree::SparseMerkleTree;
|
||||
|
||||
use super::ACCOUNTS_PRIVATE_KEYS;
|
||||
|
||||
pub mod invoke_privacy_execution;
|
||||
pub mod invoke_public_execution;
|
||||
pub mod process_privacy_execution;
|
||||
pub mod process_public_execution;
|
||||
|
||||
pub struct MockedSequencer {
|
||||
accounts: BTreeMap<Address, Account>,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user