Skip to content

Commit

Permalink
rusk: Add Dusk's VM
Browse files Browse the repository at this point in the history
  • Loading branch information
moCello committed Dec 20, 2024
1 parent 5c694cd commit 16b189b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 24 deletions.
12 changes: 4 additions & 8 deletions rusk/src/lib/node/rusk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
}
Expand Down
5 changes: 3 additions & 2 deletions rusk/src/lib/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -48,7 +49,7 @@ pub fn verify_proof(tx: &PhoenixTransaction) -> Result<bool> {

// 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(),
Expand All @@ -57,7 +58,7 @@ pub fn verify_proof(tx: &PhoenixTransaction) -> Result<bool> {

/// Verifies the signature of the incoming transaction.
pub fn verify_signature(tx: &MoonlightTransaction) -> Result<bool> {
Ok(dusk_vm::verify_bls(
Ok(host_queries::verify_bls(
tx.signature_message(),
*tx.sender(),
*tx.signature(),
Expand Down
14 changes: 7 additions & 7 deletions rusk/tests/services/contract_deployment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
14 changes: 7 additions & 7 deletions rusk/tests/services/owner_calls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -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"),
);
}
Expand Down

0 comments on commit 16b189b

Please sign in to comment.