mirror of
https://github.com/logos-blockchain/lssa-zkvm-testing.git
synced 2026-01-02 13:23:08 +00:00
add sequencer error
This commit is contained in:
parent
39b8085a3b
commit
7f43adfa1c
@ -5,6 +5,8 @@ use core::{
|
||||
visibility::AccountVisibility,
|
||||
};
|
||||
|
||||
use super::sequencer::error::Error;
|
||||
|
||||
pub mod transfer_deshielded;
|
||||
pub mod transfer_private;
|
||||
pub mod transfer_public;
|
||||
@ -32,10 +34,11 @@ impl MockedClient {
|
||||
visibilities: &[AccountVisibility],
|
||||
commitment_tree_root: [u32; 8],
|
||||
sequencer: &mut MockedSequencer,
|
||||
) -> Result<Vec<Account>, nssa::Error> {
|
||||
) -> Result<Vec<Account>, Error> {
|
||||
// Execute and generate proof of the outer program
|
||||
let (receipt, private_outputs) =
|
||||
nssa::execute_offchain::<P>(input_accounts, instruction_data, visibilities, commitment_tree_root)?;
|
||||
nssa::execute_offchain::<P>(input_accounts, instruction_data, visibilities, commitment_tree_root)
|
||||
.map_err(|_| Error::Generic)?;
|
||||
|
||||
// Send proof to the sequencer
|
||||
sequencer.process_privacy_execution(receipt)?;
|
||||
|
||||
@ -1,11 +1,10 @@
|
||||
use super::{MockedClient, MockedSequencer};
|
||||
use crate::mocked_components::sequencer::error::Error;
|
||||
use core::account::Account;
|
||||
use core::types::Address;
|
||||
use core::visibility::AccountVisibility;
|
||||
|
||||
use nssa::program::TransferProgram;
|
||||
|
||||
use super::{MockedClient, MockedSequencer};
|
||||
|
||||
impl MockedClient {
|
||||
/// A deshielded transaction of the Transfer program.
|
||||
/// All of this is executed locally by the sender
|
||||
@ -15,7 +14,7 @@ impl MockedClient {
|
||||
to_address: &Address,
|
||||
balance_to_move: u128,
|
||||
sequencer: &mut MockedSequencer,
|
||||
) -> Result<Account, nssa::Error> {
|
||||
) -> Result<Account, Error> {
|
||||
// Fetch commitment tree root from the sequencer
|
||||
let commitment_tree_root = sequencer.get_commitment_tree_root();
|
||||
// Compute authenticaton path for the input private account
|
||||
|
||||
@ -1,11 +1,10 @@
|
||||
use super::{MockedClient, MockedSequencer};
|
||||
use crate::mocked_components::sequencer::error::Error;
|
||||
use core::account::Account;
|
||||
use core::types::Address;
|
||||
use core::visibility::AccountVisibility;
|
||||
|
||||
use nssa::program::TransferProgram;
|
||||
|
||||
use super::{MockedClient, MockedSequencer};
|
||||
|
||||
impl MockedClient {
|
||||
/// A private execution of the Transfer program
|
||||
// All of this is executed locally by the sender
|
||||
@ -15,7 +14,7 @@ impl MockedClient {
|
||||
to_address: &Address,
|
||||
balance_to_move: u128,
|
||||
sequencer: &mut MockedSequencer,
|
||||
) -> Result<[Account; 2], nssa::Error> {
|
||||
) -> Result<[Account; 2], Error> {
|
||||
// Fetch commitment tree root from the sequencer
|
||||
let commitment_tree_root = sequencer.get_commitment_tree_root();
|
||||
// Compute authenticaton path for the input private account
|
||||
|
||||
@ -1,11 +1,10 @@
|
||||
use super::{MockedClient, MockedSequencer};
|
||||
use crate::mocked_components::sequencer::error::Error;
|
||||
use core::account::Account;
|
||||
use core::types::Address;
|
||||
use core::visibility::AccountVisibility;
|
||||
|
||||
use nssa::program::TransferProgram;
|
||||
|
||||
use super::{MockedClient, MockedSequencer};
|
||||
|
||||
impl MockedClient {
|
||||
/// A shielded execution of the Transfer program
|
||||
// All of this is executed locally by the sender
|
||||
@ -14,14 +13,12 @@ impl MockedClient {
|
||||
to_address: &Address,
|
||||
balance_to_move: u128,
|
||||
sequencer: &mut MockedSequencer,
|
||||
) -> Result<Account, nssa::Error> {
|
||||
) -> Result<Account, Error> {
|
||||
// Fetch commitment tree root from the sequencer
|
||||
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(nssa::Error::Generic)?;
|
||||
let from_account = sequencer.get_account(&self.user_address()).ok_or(Error::Generic)?;
|
||||
|
||||
// Create a new default private account for the receiver
|
||||
let to_account = Self::fresh_account_for_mint(*to_address);
|
||||
|
||||
@ -0,0 +1,15 @@
|
||||
#[derive(Debug)]
|
||||
pub enum Error {
|
||||
/// For simplicity, this POC uses a generic error
|
||||
Generic,
|
||||
}
|
||||
|
||||
impl std::fmt::Display for Error {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Error::Generic => write!(f, "An unexpected error occurred"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::error::Error for Error {}
|
||||
@ -9,6 +9,7 @@ use sparse_merkle_tree::SparseMerkleTree;
|
||||
|
||||
use crate::mocked_components::USER_CLIENTS;
|
||||
|
||||
pub mod error;
|
||||
pub mod process_privacy_execution;
|
||||
pub mod process_public_execution;
|
||||
|
||||
|
||||
@ -2,31 +2,32 @@ use core::types::PrivacyExecutionOutput;
|
||||
|
||||
use risc0_zkvm::Receipt;
|
||||
|
||||
use super::error::Error;
|
||||
use super::MockedSequencer;
|
||||
|
||||
impl MockedSequencer {
|
||||
/// Processes a privacy execution request.
|
||||
/// Verifies the proof of the privacy execution and updates the state of the chain.
|
||||
pub fn process_privacy_execution(&mut self, receipt: Receipt) -> Result<(), nssa::Error> {
|
||||
pub fn process_privacy_execution(&mut self, receipt: Receipt) -> Result<(), Error> {
|
||||
// Parse the output of the "outer" program
|
||||
let output: PrivacyExecutionOutput = receipt.journal.decode().unwrap();
|
||||
|
||||
// Reject in case the root used in the privacy execution is not the current root.
|
||||
if output.commitment_tree_root != self.get_commitment_tree_root() {
|
||||
return Err(nssa::Error::Generic);
|
||||
return Err(Error::Generic);
|
||||
}
|
||||
|
||||
// Reject in case the number of accounts pre states is different from the post states
|
||||
if output.public_accounts_pre.len() != output.public_accounts_post.len() {
|
||||
return Err(nssa::Error::Generic);
|
||||
return Err(Error::Generic);
|
||||
}
|
||||
|
||||
// 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(nssa::Error::Generic)?;
|
||||
let current_account = self.get_account(&account.address).ok_or(Error::Generic)?;
|
||||
if ¤t_account != account {
|
||||
return Err(nssa::Error::Generic);
|
||||
return Err(Error::Generic);
|
||||
}
|
||||
}
|
||||
|
||||
@ -36,7 +37,7 @@ impl MockedSequencer {
|
||||
.iter()
|
||||
.any(|nullifier| self.nullifier_set.contains(nullifier))
|
||||
{
|
||||
return Err(nssa::Error::Generic);
|
||||
return Err(Error::Generic);
|
||||
}
|
||||
|
||||
// Reject if the commitments have already been seen.
|
||||
@ -45,7 +46,7 @@ impl MockedSequencer {
|
||||
.iter()
|
||||
.any(|commitment| self.commitment_tree.values().contains(commitment))
|
||||
{
|
||||
return Err(nssa::Error::Generic);
|
||||
return Err(Error::Generic);
|
||||
}
|
||||
|
||||
// Verify the proof of the privacy execution.
|
||||
@ -55,7 +56,7 @@ impl MockedSequencer {
|
||||
// - The given nullifiers correctly correspond to commitments that currently belong to
|
||||
// the commitment tree.
|
||||
// - The given commitments are correctly computed from valid accounts.
|
||||
nssa::verify_privacy_execution(receipt)?;
|
||||
nssa::verify_privacy_execution(receipt).map_err(|_| Error::Generic)?;
|
||||
|
||||
// At this point the privacy execution is considered valid.
|
||||
//
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user