mirror of
https://github.com/logos-blockchain/lssa-zkvm-testing.git
synced 2026-01-05 06:43:12 +00:00
refactor
This commit is contained in:
parent
f66f62c041
commit
5de2fd05a8
@ -8,8 +8,8 @@ use core::{
|
||||
use nssa::program::{PinataProgram, TransferProgram};
|
||||
use risc0_zkvm::Receipt;
|
||||
|
||||
use crate::mocked_components::client::MockedClient;
|
||||
use crate::mocked_components::sequencer::{MockedSequencer, ACCOUNTS_PRIVATE_KEYS};
|
||||
use crate::mocked_components::sequencer::MockedSequencer;
|
||||
use crate::mocked_components::{client::MockedClient, ACCOUNTS_PRIVATE_KEYS};
|
||||
|
||||
mod mocked_components;
|
||||
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
use core::types::Key;
|
||||
|
||||
pub mod client;
|
||||
pub mod sequencer;
|
||||
|
||||
|
||||
@ -17,8 +17,10 @@ impl MockedSequencer {
|
||||
// Execute
|
||||
let inputs_outputs = nssa::execute::<P>(&input_accounts, instruction_data)?;
|
||||
|
||||
// Consistency checks
|
||||
self.inputs_outputs_are_consistent(&input_accounts, &inputs_outputs)?;
|
||||
// Perform consistency checks
|
||||
if !self.inputs_outputs_are_consistent(&input_accounts, &inputs_outputs) {
|
||||
return Err(());
|
||||
}
|
||||
|
||||
// Update accounts
|
||||
inputs_outputs
|
||||
@ -35,27 +37,27 @@ impl MockedSequencer {
|
||||
&self,
|
||||
input_accounts: &[Account],
|
||||
inputs_outputs: &[Account],
|
||||
) -> Result<(), ()> {
|
||||
) -> bool {
|
||||
let num_inputs = input_accounts.len();
|
||||
if inputs_outputs.len() != num_inputs * 2 {
|
||||
return Err(());
|
||||
return false;
|
||||
}
|
||||
|
||||
let (claimed_accounts_pre, accounts_post) = inputs_outputs.split_at(num_inputs);
|
||||
if claimed_accounts_pre != input_accounts {
|
||||
return Err(());
|
||||
return false;
|
||||
}
|
||||
|
||||
for (account_pre, account_post) in input_accounts.iter().zip(accounts_post) {
|
||||
if account_pre.address != account_post.address {
|
||||
return Err(());
|
||||
return false;
|
||||
}
|
||||
if account_pre.nonce != account_post.nonce {
|
||||
return Err(());
|
||||
return false;
|
||||
}
|
||||
// Redundant with previous checks, but better make it explicit.
|
||||
if !self.accounts.contains_key(&account_post.address) {
|
||||
return Err(());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
let accounts_pre_total_balance: u128 =
|
||||
@ -63,9 +65,8 @@ impl MockedSequencer {
|
||||
let accounts_post_total_balance: u128 =
|
||||
accounts_post.iter().map(|account| account.balance).sum();
|
||||
if accounts_pre_total_balance != accounts_post_total_balance {
|
||||
return Err(());
|
||||
return false;
|
||||
}
|
||||
return Ok(());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -10,7 +10,7 @@ use program_methods::{PINATA_ID, TRANSFER_ID, TRANSFER_MULTIPLE_ID};
|
||||
use risc0_zkvm::Receipt;
|
||||
use sparse_merkle_tree::SparseMerkleTree;
|
||||
|
||||
use crate::mocked_components::ACCOUNTS_PRIVATE_KEYS;
|
||||
use super::ACCOUNTS_PRIVATE_KEYS;
|
||||
|
||||
pub mod invoke_privacy_execution;
|
||||
pub mod invoke_public_execution;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user