From 16b189b16243779e4500c30ca43029777c581a31 Mon Sep 17 00:00:00 2001 From: moana Date: Fri, 20 Dec 2024 16:34:51 +0100 Subject: [PATCH] rusk: Add Dusk's `VM` --- rusk/src/lib/node/rusk.rs | 12 ++++-------- rusk/src/lib/verifier.rs | 5 +++-- rusk/tests/services/contract_deployment.rs | 14 +++++++------- rusk/tests/services/owner_calls.rs | 14 +++++++------- 4 files changed, 21 insertions(+), 24 deletions(-) diff --git a/rusk/src/lib/node/rusk.rs b/rusk/src/lib/node/rusk.rs index 7b82e854a..612a427a5 100644 --- a/rusk/src/lib/node/rusk.rs +++ b/rusk/src/lib/node/rusk.rs @@ -27,7 +27,7 @@ use dusk_core::transfer::{ TRANSFER_CONTRACT, }; use dusk_core::{BlsScalar, Dusk}; -use dusk_vm::{CallReceipt, PiecrustError, Session}; +use dusk_vm::{new_session, CallReceipt, PiecrustError, Session, VM}; use node::vm::bytecode_charge; use node_data::events::contract::{ContractEvent, ContractTxEvent}; use node_data::ledger::{Hash, Slash, SpentTransaction, Transaction}; @@ -85,7 +85,7 @@ impl Rusk { let mut base_commit = [0u8; 32]; base_commit.copy_from_slice(&base_commit_bytes); - let vm = Arc::new(dusk_vm::new_vm(dir)?); + let vm = Arc::new(VM::new(dir)?); let tip = Arc::new(RwLock::new(RuskTip { current: base_commit, @@ -537,12 +537,8 @@ impl Rusk { tip.current }); - let session = dusk_vm::new_session( - &self.vm, - commit, - self.chain_id, - block_height, - )?; + let session = + new_session(&self.vm, commit, self.chain_id, block_height)?; Ok(session) } diff --git a/rusk/src/lib/verifier.rs b/rusk/src/lib/verifier.rs index 65cce3ec9..112d7cfce 100644 --- a/rusk/src/lib/verifier.rs +++ b/rusk/src/lib/verifier.rs @@ -13,6 +13,7 @@ use dusk_core::transfer::{ moonlight::Transaction as MoonlightTransaction, phoenix::Transaction as PhoenixTransaction, }; +use dusk_vm::host_queries; use rusk_profile::Circuit as CircuitProfile; use std::sync::LazyLock; @@ -48,7 +49,7 @@ pub fn verify_proof(tx: &PhoenixTransaction) -> Result { // Maybe we want to handle internal serialization error too, // currently they map to `false`. - Ok(dusk_vm::verify_plonk( + Ok(host_queries::verify_plonk( vd.to_vec(), tx.proof().to_vec(), tx.public_inputs(), @@ -57,7 +58,7 @@ pub fn verify_proof(tx: &PhoenixTransaction) -> Result { /// Verifies the signature of the incoming transaction. pub fn verify_signature(tx: &MoonlightTransaction) -> Result { - Ok(dusk_vm::verify_bls( + Ok(host_queries::verify_bls( tx.signature_message(), *tx.sender(), *tx.signature(), diff --git a/rusk/tests/services/contract_deployment.rs b/rusk/tests/services/contract_deployment.rs index 7d906435b..57dcfb6c6 100644 --- a/rusk/tests/services/contract_deployment.rs +++ b/rusk/tests/services/contract_deployment.rs @@ -12,7 +12,7 @@ use dusk_core::abi::ContractId; use dusk_core::transfer::data::{ ContractBytecode, ContractDeploy, TransactionData, }; -use dusk_vm::{ContractData, PiecrustError}; +use dusk_vm::{new_session, ContractData, PiecrustError, VM}; use rand::prelude::*; use rand::rngs::StdRng; use rusk::gen_id::gen_contract_id; @@ -230,9 +230,9 @@ impl Fixture { pub fn assert_bob_contract_is_not_deployed(&self) { let commit = self.rusk.state_root(); - let vm = dusk_vm::new_vm(self.path.as_path()) - .expect("VM creation should succeed"); - let mut session = dusk_vm::new_session(&vm, commit, CHAIN_ID, 0) + let vm = + VM::new(self.path.as_path()).expect("VM creation should succeed"); + let mut session = new_session(&vm, commit, CHAIN_ID, 0) .expect("Session creation should succeed"); let result = session.call::<_, u64>( self.contract_id, @@ -248,9 +248,9 @@ impl Fixture { pub fn assert_bob_contract_is_deployed(&self) { let commit = self.rusk.state_root(); - let vm = dusk_vm::new_vm(self.path.as_path()) - .expect("VM creation should succeed"); - let mut session = dusk_vm::new_session(&vm, commit, CHAIN_ID, 0) + let vm = + VM::new(self.path.as_path()).expect("VM creation should succeed"); + let mut session = new_session(&vm, commit, CHAIN_ID, 0) .expect("Session creation should succeed"); let result = session.call::<_, u64>( self.contract_id, diff --git a/rusk/tests/services/owner_calls.rs b/rusk/tests/services/owner_calls.rs index d22e65585..451614150 100644 --- a/rusk/tests/services/owner_calls.rs +++ b/rusk/tests/services/owner_calls.rs @@ -19,7 +19,7 @@ use dusk_core::signatures::bls::{ PublicKey as BlsPublicKey, SecretKey as BlsSecretKey, Signature as BlsSignature, }; -use dusk_vm::{CallReceipt, ContractData, Session}; +use dusk_vm::{new_session, CallReceipt, ContractData, Session, VM}; use rusk::gen_id::gen_contract_id; use rusk::{Error, Result, Rusk}; use rusk_recovery_tools::state; @@ -144,9 +144,9 @@ impl Fixture { pub fn assert_bob_contract_is_deployed(&self) { const BOB_ECHO_VALUE: u64 = 775; let commit = self.rusk.state_root(); - let vm = dusk_vm::new_vm(self.path.as_path()) - .expect("VM creation should succeed"); - let mut session = dusk_vm::new_session(&vm, commit, CHAIN_ID, 0) + let vm = + VM::new(self.path.as_path()).expect("VM creation should succeed"); + let mut session = new_session(&vm, commit, CHAIN_ID, 0) .expect("Session creation should succeed"); let result = session.call::<_, u64>( self.contract_id, @@ -168,10 +168,10 @@ impl Fixture { pub fn set_session(&mut self) { let commit = self.rusk.state_root(); - let vm = dusk_vm::new_vm(self.path.as_path()) - .expect("VM creation should succeed"); + let vm = + VM::new(self.path.as_path()).expect("VM creation should succeed"); self.session = Some( - dusk_vm::new_session(&vm, commit, CHAIN_ID, 0) + new_session(&vm, commit, CHAIN_ID, 0) .expect("Session creation should succeed"), ); }