diff --git a/rusk/src/lib/error.rs b/rusk/src/lib/error.rs index 57777deda0..bc93586601 100644 --- a/rusk/src/lib/error.rs +++ b/rusk/src/lib/error.rs @@ -8,8 +8,8 @@ use std::{fmt, io}; use dusk_bytes::Serializable; use execution_core::{ - signatures::bls::PublicKey as BlsPublicKey, - transfer::phoenix::Error as PhoenixError, BlsScalar, Dusk, + signatures::bls::PublicKey as BlsPublicKey, transfer::phoenix::CoreError, + BlsScalar, Dusk, Error as ExecErr, }; use rusk_abi::PiecrustError; @@ -37,8 +37,10 @@ pub enum Error { OpeningNoteUndefined(u64), /// Bytes Serialization Errors Serialization(dusk_bytes::Error), + /// Originating from transaction-creation + Transaction(ExecErr), /// Originating from Phoenix. - Phoenix(PhoenixError), + Phoenix(CoreError), /// Piecrust VM internal Errors Vm(PiecrustError), /// IO Errors @@ -47,9 +49,6 @@ pub enum Error { CoinbaseBlockHeight(u64, u64), /// Bad dusk spent in coinbase (got, expected). CoinbaseDuskSpent(Dusk, Dusk), - /// Proof creation error - #[cfg(feature = "prover")] - ProofCreation(rusk_prover::ProverError), /// Failed to produce proper state #[cfg(feature = "node")] InconsistentState(dusk_consensus::operations::VerificationOutput), @@ -75,10 +74,39 @@ impl From for Error { } } -#[cfg(feature = "prover")] -impl From for Error { - fn from(err: rusk_prover::ProverError) -> Self { - Error::ProofCreation(err) +impl From for Error { + fn from(err: ExecErr) -> Self { + match err { + ExecErr::InsufficientBalance => { + Self::Transaction(ExecErr::InsufficientBalance) + } + ExecErr::Replay => Self::Transaction(ExecErr::Replay), + ExecErr::PhoenixOwnership => { + Self::Transaction(ExecErr::PhoenixOwnership) + } + ExecErr::PhoenixCircuit(e) => { + Self::Transaction(ExecErr::PhoenixCircuit(e)) + } + ExecErr::PhoenixProver(e) => { + Self::Transaction(ExecErr::PhoenixProver(e)) + } + ExecErr::InvalidData => { + Self::Serialization(dusk_bytes::Error::InvalidData) + } + ExecErr::BadLength(found, expected) => { + Self::Serialization(dusk_bytes::Error::BadLength { + found, + expected, + }) + } + ExecErr::InvalidChar(ch, index) => { + Self::Serialization(dusk_bytes::Error::InvalidChar { + ch, + index, + }) + } + ExecErr::Rkyv(e) => Self::Transaction(ExecErr::Rkyv(e)), + } } } @@ -88,8 +116,8 @@ impl From for Error { } } -impl From for Error { - fn from(pe: PhoenixError) -> Self { +impl From for Error { + fn from(pe: CoreError) -> Self { Self::Phoenix(pe) } } @@ -123,6 +151,7 @@ impl fmt::Display for Error { } Error::Vm(err) => write!(f, "VM Error: {err}"), Error::Io(err) => write!(f, "IO Error: {err}"), + Error::Transaction(err) => write!(f, "Transaction Error: {err}"), Error::Phoenix(err) => write!(f, "Phoenix error: {err}"), Error::Other(err) => write!(f, "Other error: {err}"), Error::CoinbaseBlockHeight(got, expected) => write!( @@ -145,10 +174,6 @@ impl fmt::Display for Error { Error::InvalidCircuitArguments(inputs_len, outputs_len) => { write!(f,"Expected: 0 < (inputs: {inputs_len}) < 5, 0 ≤ (outputs: {outputs_len}) < 3") } - #[cfg(feature = "prover")] - Error::ProofCreation(e) => { - write!(f, "Proof creation error: {e}") - } #[cfg(feature = "node")] Error::InconsistentState(verification_output) => { write!( diff --git a/rusk/src/lib/http/prover.rs b/rusk/src/lib/http/prover.rs index b24852cf00..936b624d74 100644 --- a/rusk/src/lib/http/prover.rs +++ b/rusk/src/lib/http/prover.rs @@ -4,6 +4,8 @@ // // Copyright (c) DUSK NETWORK. All rights reserved. +use anyhow::anyhow; + use execution_core::transfer::phoenix::Prove; use rusk_prover::LocalProver; @@ -21,7 +23,8 @@ impl HandleRequest for LocalProver { ) -> anyhow::Result { let topic = request.event.topic.as_str(); let response = match topic { - "prove_tx_circuit" => LocalProver::prove(request.event_data())?, + "prove_execute" => LocalProver::prove(request.event_data()) + .map_err(|e| anyhow!(e))?, _ => anyhow::bail!("Unsupported"), }; Ok(ResponseData::new(response)) diff --git a/rusk/tests/common/wallet.rs b/rusk/tests/common/wallet.rs index 4712d047aa..7b164edf88 100644 --- a/rusk/tests/common/wallet.rs +++ b/rusk/tests/common/wallet.rs @@ -16,18 +16,13 @@ use execution_core::{ stake::StakeData, transfer::{ moonlight::AccountData, - phoenix::{ - Note, Prove, Transaction as PhoenixTransaction, ViewKey, - NOTES_TREE_DEPTH, - }, - Transaction, + phoenix::{Note, ViewKey, NOTES_TREE_DEPTH}, }, BlsScalar, }; use futures::StreamExt; use poseidon_merkle::Opening as PoseidonOpening; use rusk::{Error, Result, Rusk}; -use rusk_prover::LocalProver; use test_wallet::{self as wallet, Store}; use tracing::info; @@ -128,33 +123,6 @@ impl wallet::StateClient for TestStateClient { } } -#[derive(Default)] -pub struct TestProverClient(); - -impl Debug for TestProverClient { - fn fmt(&self, _: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - Ok(()) - } -} - -impl wallet::ProverClient for TestProverClient { - type Error = Error; - /// Requests that a node prove the given transaction and later propagates it - fn compute_proof_and_propagate( - utx: &PhoenixTransaction, - ) -> Result { - let circuit_bytes = &utx.proof()[..]; - let proof_bytes = LocalProver::prove(circuit_bytes)?; - info!("circuit: {}", hex::encode(circuit_bytes)); - let mut tx = utx.clone(); - tx.replace_proof(proof_bytes); - - //Propagate is not required yet - - Ok(tx.into()) - } -} - #[derive(Default, Debug, Clone)] pub struct DummyCacheItem { notes: Vec<(Note, u64)>, diff --git a/rusk/tests/rusk-state.rs b/rusk/tests/rusk-state.rs index c34b87238a..813ca14eb4 100644 --- a/rusk/tests/rusk-state.rs +++ b/rusk/tests/rusk-state.rs @@ -175,7 +175,7 @@ pub fn rusk_state_finalized() -> Result<()> { #[allow(dead_code)] // #[tokio::test(flavor = "multi_thread")] async fn generate_phoenix_txs() -> Result<(), Box> { - use common::wallet::{TestProverClient, TestStateClient, TestStore}; + use common::wallet::{TestStateClient, TestStore}; use std::io::Write; common::logger(); @@ -189,11 +189,8 @@ async fn generate_phoenix_txs() -> Result<(), Box> { let cache = Arc::new(std::sync::RwLock::new(std::collections::HashMap::new())); - let wallet = test_wallet::Wallet::new( - TestStore, - TestStateClient { rusk, cache }, - TestProverClient::default(), - ); + let wallet = + test_wallet::Wallet::new(TestStore, TestStateClient { rusk, cache }); const N_ADDRESSES: usize = 100; @@ -240,7 +237,7 @@ async fn generate_phoenix_txs() -> Result<(), Box> { #[allow(dead_code)] // #[tokio::test(flavor = "multi_thread")] async fn generate_moonlight_txs() -> Result<(), Box> { - use common::wallet::{TestProverClient, TestStateClient, TestStore}; + use common::wallet::{TestStateClient, TestStore}; use std::io::Write; common::logger(); @@ -254,11 +251,8 @@ async fn generate_moonlight_txs() -> Result<(), Box> { let cache = Arc::new(std::sync::RwLock::new(std::collections::HashMap::new())); - let wallet = test_wallet::Wallet::new( - TestStore, - TestStateClient { rusk, cache }, - TestProverClient::default(), - ); + let wallet = + test_wallet::Wallet::new(TestStore, TestStateClient { rusk, cache }); const N_ADDRESSES: usize = 100; diff --git a/rusk/tests/services/contract_deployment.rs b/rusk/tests/services/contract_deployment.rs index aa4269770d..1761dd6a54 100644 --- a/rusk/tests/services/contract_deployment.rs +++ b/rusk/tests/services/contract_deployment.rs @@ -25,7 +25,7 @@ use tracing::info; use crate::common::logger; use crate::common::state::{generator_procedure, ExecuteResult}; -use crate::common::wallet::{TestProverClient, TestStateClient, TestStore}; +use crate::common::wallet::{TestStateClient, TestStore}; const BLOCK_HEIGHT: u64 = 1; const BLOCK_GAS_LIMIT: u64 = 1_000_000_000_000; @@ -107,7 +107,7 @@ fn bytecode_hash(bytecode: impl AsRef<[u8]>) -> ContractId { fn make_and_execute_transaction_deploy( rusk: &Rusk, - wallet: &wallet::Wallet, + wallet: &wallet::Wallet, bytecode: impl AsRef<[u8]>, gas_limit: u64, init_value: u8, @@ -168,7 +168,7 @@ fn make_and_execute_transaction_deploy( struct Fixture { pub rusk: Rusk, - pub wallet: Wallet, + pub wallet: Wallet, pub bob_bytecode: Vec, pub contract_id: ContractId, pub path: PathBuf, @@ -189,7 +189,6 @@ impl Fixture { rusk: rusk.clone(), cache, }, - TestProverClient::default(), ); let original_root = rusk.state_root(); diff --git a/rusk/tests/services/gas_behavior.rs b/rusk/tests/services/gas_behavior.rs index c8fa0e7ad7..17d148c4c9 100644 --- a/rusk/tests/services/gas_behavior.rs +++ b/rusk/tests/services/gas_behavior.rs @@ -21,7 +21,7 @@ use tracing::info; use crate::common::logger; use crate::common::state::{generator_procedure, new_state}; -use crate::common::wallet::{TestProverClient, TestStateClient, TestStore}; +use crate::common::wallet::{TestStateClient, TestStore}; const BLOCK_HEIGHT: u64 = 1; const BLOCK_GAS_LIMIT: u64 = 1_000_000_000_000; @@ -45,7 +45,7 @@ const SENDER_INDEX_1: u8 = 1; fn make_transactions( rusk: &Rusk, - wallet: &wallet::Wallet, + wallet: &wallet::Wallet, ) { let initial_balance_0 = wallet .get_balance(SENDER_INDEX_0) @@ -149,7 +149,6 @@ pub async fn erroring_tx_charged_full() -> Result<()> { rusk: rusk.clone(), cache, }, - TestProverClient::default(), ); let original_root = rusk.state_root(); diff --git a/rusk/tests/services/multi_transfer.rs b/rusk/tests/services/multi_transfer.rs index 92d0aa5fe5..f3cf71cc56 100644 --- a/rusk/tests/services/multi_transfer.rs +++ b/rusk/tests/services/multi_transfer.rs @@ -17,7 +17,7 @@ use tracing::info; use crate::common::logger; use crate::common::state::{generator_procedure, new_state, ExecuteResult}; -use crate::common::wallet::{TestProverClient, TestStateClient, TestStore}; +use crate::common::wallet::{TestStateClient, TestStore}; const BLOCK_HEIGHT: u64 = 1; // This is purposefully chosen to be low to trigger the discarding of a @@ -39,7 +39,7 @@ fn initial_state>(dir: P) -> Result { /// to be included due to exceeding the block gas limit fn wallet_transfer( rusk: &Rusk, - wallet: &wallet::Wallet, + wallet: &wallet::Wallet, amount: u64, ) { // Generate a receiver pk @@ -192,7 +192,6 @@ pub async fn multi_transfer() -> Result<()> { rusk: rusk.clone(), cache, }, - TestProverClient::default(), ); let original_root = rusk.state_root(); diff --git a/rusk/tests/services/stake.rs b/rusk/tests/services/stake.rs index 9e6124575e..5033db1407 100644 --- a/rusk/tests/services/stake.rs +++ b/rusk/tests/services/stake.rs @@ -24,7 +24,7 @@ use test_wallet::{self as wallet}; use tracing::info; use crate::common::state::{generator_procedure, new_state}; -use crate::common::wallet::{TestProverClient, TestStateClient, TestStore}; +use crate::common::wallet::{TestStateClient, TestStore}; use crate::common::*; const BLOCK_HEIGHT: u64 = 1; @@ -54,7 +54,7 @@ fn slash_state>(dir: P) -> Result { /// stake and checking it is correctly withdrawn. fn wallet_stake( rusk: &Rusk, - wallet: &wallet::Wallet, + wallet: &wallet::Wallet, value: u64, ) { let mut rng = StdRng::seed_from_u64(0xdead); @@ -157,7 +157,6 @@ pub async fn stake() -> Result<()> { rusk: rusk.clone(), cache, }, - TestProverClient::default(), ); let original_root = rusk.state_root(); @@ -188,7 +187,7 @@ pub async fn stake() -> Result<()> { /// fails fn wallet_reward( rusk: &Rusk, - wallet: &wallet::Wallet, + wallet: &wallet::Wallet, ) { let mut rng = StdRng::seed_from_u64(0xdead); @@ -251,7 +250,6 @@ pub async fn reward() -> Result<()> { rusk: rusk.clone(), cache, }, - TestProverClient::default(), ); let original_root = rusk.state_root(); @@ -289,7 +287,6 @@ pub async fn slash() -> Result<()> { rusk: rusk.clone(), cache, }, - TestProverClient::default(), ); let original_root = rusk.state_root(); diff --git a/rusk/tests/services/transfer.rs b/rusk/tests/services/transfer.rs index f4978efcff..0b6ec460d0 100644 --- a/rusk/tests/services/transfer.rs +++ b/rusk/tests/services/transfer.rs @@ -18,7 +18,7 @@ use tracing::info; use crate::common::logger; use crate::common::state::{generator_procedure, new_state}; -use crate::common::wallet::{TestProverClient, TestStateClient, TestStore}; +use crate::common::wallet::{TestStateClient, TestStore}; const BLOCK_GAS_LIMIT: u64 = 100_000_000_000; const INITIAL_BALANCE: u64 = 10_000_000_000; @@ -37,7 +37,7 @@ fn initial_state>(dir: P) -> Result { /// successfully. fn wallet_transfer( rusk: &Rusk, - wallet: &wallet::Wallet, + wallet: &wallet::Wallet, amount: u64, block_height: u64, ) { @@ -145,7 +145,6 @@ pub async fn wallet() -> Result<()> { rusk: rusk.clone(), cache: cache.clone(), }, - TestProverClient::default(), ); let original_root = rusk.state_root(); diff --git a/rusk/tests/services/unspendable.rs b/rusk/tests/services/unspendable.rs index 67a565ed23..490d64e528 100644 --- a/rusk/tests/services/unspendable.rs +++ b/rusk/tests/services/unspendable.rs @@ -21,7 +21,7 @@ use tracing::info; use crate::common::logger; use crate::common::state::{generator_procedure, new_state, ExecuteResult}; -use crate::common::wallet::{TestProverClient, TestStateClient, TestStore}; +use crate::common::wallet::{TestStateClient, TestStore}; const BLOCK_HEIGHT: u64 = 1; const BLOCK_GAS_LIMIT: u64 = 1_000_000_000_000; @@ -47,7 +47,7 @@ const SENDER_INDEX_2: u8 = 2; fn make_transactions( rusk: &Rusk, - wallet: &wallet::Wallet, + wallet: &wallet::Wallet, ) { let initial_balance_0 = wallet .get_balance(SENDER_INDEX_0) @@ -179,7 +179,6 @@ pub async fn unspendable() -> Result<()> { rusk: rusk.clone(), cache, }, - TestProverClient::default(), ); let original_root = rusk.state_root();