diff --git a/contracts/stake/src/lib.rs b/contracts/stake/src/lib.rs index 3bc2d29d35..d6ea1d1138 100644 --- a/contracts/stake/src/lib.rs +++ b/contracts/stake/src/lib.rs @@ -50,6 +50,11 @@ unsafe fn get_stake(arg_len: u32) -> u32 { rusk_abi::wrap_call(arg_len, |pk| STATE.get_stake(&pk).cloned()) } +#[no_mangle] +unsafe fn get_stake_keys(arg_len: u32) -> u32 { + rusk_abi::wrap_call(arg_len, |pk| STATE.get_stake_keys(&pk).cloned()) +} + #[no_mangle] unsafe fn burnt_amount(arg_len: u32) -> u32 { rusk_abi::wrap_call(arg_len, |_: ()| STATE.burnt_amount()) diff --git a/contracts/stake/src/state.rs b/contracts/stake/src/state.rs index 0ad8f083fb..9af11b4508 100644 --- a/contracts/stake/src/state.rs +++ b/contracts/stake/src/state.rs @@ -15,7 +15,7 @@ use execution_core::{ signatures::bls::PublicKey as BlsPublicKey, stake::{ next_epoch, Reward, SlashEvent, Stake, StakeAmount, StakeData, - StakeEvent, Withdraw, EPOCH, MINIMUM_STAKE, STAKE_CONTRACT, + StakeEvent, StakeKeys, Withdraw, EPOCH, MINIMUM_STAKE, STAKE_CONTRACT, STAKE_WARNINGS, }, transfer::TRANSFER_CONTRACT, @@ -33,7 +33,7 @@ use crate::*; /// valid stake. #[derive(Debug, Default, Clone)] pub struct StakeState { - stakes: BTreeMap<[u8; BlsPublicKey::SIZE], (StakeData, BlsPublicKey)>, + stakes: BTreeMap<[u8; BlsPublicKey::SIZE], (StakeData, StakeKeys)>, burnt_amount: u64, previous_block_state: BTreeMap<[u8; BlsPublicKey::SIZE], (Option, BlsPublicKey)>, @@ -71,7 +71,8 @@ impl StakeState { self.check_new_block(); let value = stake.value(); - let account = *stake.account(); + let keys = *stake.keys(); + let account = keys.account; let nonce = stake.nonce(); let signature = *stake.signature(); @@ -80,7 +81,11 @@ impl StakeState { } let prev_stake = self.get_stake(&account).copied(); - let loaded_stake = self.load_or_create_stake_mut(&account); + let (loaded_stake, loaded_keys) = self.load_or_create_stake_mut(&keys); + + // Update the funds key with the newly provided one + // This operation will rollback if the signature is invalid + *loaded_keys = keys; // ensure the stake is at least the minimum and that there isn't an // amount staked already @@ -103,7 +108,9 @@ impl StakeState { } let digest = stake.signature_message().to_vec(); - if !rusk_abi::verify_bls(digest, account, signature) { + let pk = keys.multisig_pk().expect("Invalid MultisigPublicKey"); + + if !rusk_abi::verify_bls_multisig(digest, pk, signature) { panic!("Invalid signature!"); } @@ -118,7 +125,7 @@ impl StakeState { loaded_stake.amount = Some(StakeAmount::new(value, rusk_abi::block_height())); - rusk_abi::emit("stake", StakeEvent { account, value }); + rusk_abi::emit("stake", StakeEvent { keys, value }); let key = account.to_bytes(); self.previous_block_state @@ -134,7 +141,7 @@ impl StakeState { let value = transfer_withdraw.value(); let signature = *unstake.signature(); - let loaded_stake = self + let (loaded_stake, keys) = self .get_stake_mut(&account) .expect("A stake should exist in the map to be unstaked!"); let prev_stake = Some(*loaded_stake); @@ -153,7 +160,9 @@ impl StakeState { // check signature is correct let digest = unstake.signature_message().to_vec(); - if !rusk_abi::verify_bls(digest, account, signature) { + let pk = keys.multisig_pk().expect("Invalid MultisigPublicKey"); + + if !rusk_abi::verify_bls_multisig(digest, pk, signature) { panic!("Invalid signature!"); } @@ -166,7 +175,7 @@ impl StakeState { // update the state accordingly loaded_stake.amount = None; - rusk_abi::emit("unstake", StakeEvent { account, value }); + rusk_abi::emit("unstake", StakeEvent { keys: *keys, value }); let key = account.to_bytes(); self.previous_block_state @@ -176,12 +185,12 @@ impl StakeState { pub fn withdraw(&mut self, withdraw: Withdraw) { let transfer_withdraw = withdraw.transfer_withdraw(); - let account = *withdraw.account(); + let account = withdraw.account(); let value = transfer_withdraw.value(); let signature = *withdraw.signature(); - let loaded_stake = self - .get_stake_mut(&account) + let (loaded_stake, keys) = self + .get_stake_mut(account) .expect("A stake should exist in the map to be unstaked!"); // ensure there is a non-zero reward, and that the withdrawal is exactly @@ -196,7 +205,8 @@ impl StakeState { // check signature is correct let digest = withdraw.signature_message().to_vec(); - if !rusk_abi::verify_bls(digest, account, signature) { + let pk = keys.multisig_pk().expect("Invalid MultisigPublicKey"); + if !rusk_abi::verify_bls_multisig(digest, pk, signature) { panic!("Invalid signature!"); } @@ -208,7 +218,7 @@ impl StakeState { // update the state accordingly loaded_stake.reward -= value; - rusk_abi::emit("withdraw", StakeEvent { account, value }); + rusk_abi::emit("withdraw", StakeEvent { keys: *keys, value }); } /// Gets a reference to a stake. @@ -216,42 +226,46 @@ impl StakeState { self.stakes.get(&key.to_bytes()).map(|(s, _)| s) } + /// Gets the keys linked to to a stake. + pub fn get_stake_keys(&self, key: &BlsPublicKey) -> Option<&StakeKeys> { + self.stakes.get(&key.to_bytes()).map(|(_, k)| k) + } + /// Gets a mutable reference to a stake. pub fn get_stake_mut( &mut self, key: &BlsPublicKey, - ) -> Option<&mut StakeData> { - self.stakes.get_mut(&key.to_bytes()).map(|(s, _)| s) + ) -> Option<&mut (StakeData, StakeKeys)> { + self.stakes.get_mut(&key.to_bytes()) } - /// Pushes the given `stake` onto the state for a given `account`. - pub fn insert_stake(&mut self, account: BlsPublicKey, stake: StakeData) { - self.stakes.insert(account.to_bytes(), (stake, account)); + /// Pushes the given `stake` onto the state for a given `keys`. + pub fn insert_stake(&mut self, keys: StakeKeys, stake: StakeData) { + self.stakes.insert(keys.account.to_bytes(), (stake, keys)); } - /// Gets a mutable reference to the stake of a given key. If said stake + /// Gets a mutable reference to the stake of a given `keys`. If said stake /// doesn't exist, a default one is inserted and a mutable reference /// returned. pub(crate) fn load_or_create_stake_mut( &mut self, - account: &BlsPublicKey, - ) -> &mut StakeData { - let is_missing = self.stakes.get(&account.to_bytes()).is_none(); + keys: &StakeKeys, + ) -> &mut (StakeData, StakeKeys) { + let key = keys.account.to_bytes(); + let is_missing = self.stakes.get(&key).is_none(); if is_missing { let stake = StakeData::EMPTY; - self.stakes.insert(account.to_bytes(), (stake, *account)); + self.stakes.insert(key, (stake, *keys)); } // SAFETY: unwrap is ok since we're sure we inserted an element - self.stakes - .get_mut(&account.to_bytes()) - .map(|(s, _)| s) - .unwrap() + self.stakes.get_mut(&key).unwrap() } - /// Rewards a `account` with the given `value`. If a stake does not exist - /// in the map for the key one will be created. + /// Rewards a `account` with the given `value`. + /// + /// *PANIC* If a stake does not exist in the map pub fn reward(&mut self, rewards: Vec) { // since we assure that reward is called at least once per block, this // call is necessary to ensure that there are no inconsistencies in @@ -259,7 +273,9 @@ impl StakeState { self.check_new_block(); for reward in &rewards { - let stake = self.load_or_create_stake_mut(&reward.account); + let (stake, _) = self + .get_stake_mut(&reward.account) + .expect("Stake to exists to be rewarded"); // Reset faults counters stake.faults = 0; @@ -289,7 +305,7 @@ impl StakeState { pub fn slash(&mut self, account: &BlsPublicKey, to_slash: Option) { self.check_new_block(); - let stake = self + let (stake, _) = self .get_stake_mut(account) .expect("The stake to slash should exist"); let prev_stake = Some(*stake); @@ -340,7 +356,7 @@ impl StakeState { let key = account.to_bytes(); self.previous_block_state .entry(key) - .or_insert((prev_stake, *account)); + .or_insert_with(|| (prev_stake, *account)); } /// Slash the given `to_slash` amount from an `account`'s stake. @@ -355,7 +371,7 @@ impl StakeState { ) { self.check_new_block(); - let stake = self + let (stake, _) = self .get_stake_mut(account) .expect("The stake to slash should exist"); @@ -405,7 +421,7 @@ impl StakeState { let key = account.to_bytes(); self.previous_block_state .entry(key) - .or_insert((prev_stake, *account)); + .or_insert_with(|| (prev_stake, *account)); } /// Sets the burnt amount diff --git a/contracts/stake/tests/common/assert.rs b/contracts/stake/tests/common/assert.rs index b9bd456428..88867e0070 100644 --- a/contracts/stake/tests/common/assert.rs +++ b/contracts/stake/tests/common/assert.rs @@ -42,7 +42,10 @@ pub fn assert_event( .deserialize(&mut Infallible) .expect("Infallible"); assert_eq!(staking_event_data.value, should_amount); - assert_eq!(staking_event_data.account.to_bytes(), should_pk.to_bytes()); + assert_eq!( + staking_event_data.keys.account.to_bytes(), + should_pk.to_bytes() + ); } } diff --git a/contracts/stake/tests/events.rs b/contracts/stake/tests/events.rs index d9aaea48ec..1123efc0b0 100644 --- a/contracts/stake/tests/events.rs +++ b/contracts/stake/tests/events.rs @@ -13,7 +13,9 @@ use rand::SeedableRng; use execution_core::{ dusk, signatures::bls::{PublicKey as BlsPublicKey, SecretKey as BlsSecretKey}, - stake::{Reward, RewardReason, StakeAmount, StakeData, STAKE_CONTRACT}, + stake::{ + Reward, RewardReason, StakeAmount, StakeData, StakeKeys, STAKE_CONTRACT, + }, transfer::{ phoenix::{ PublicKey as PhoenixPublicKey, SecretKey as PhoenixSecretKey, @@ -40,6 +42,10 @@ fn reward_slash() -> Result<(), PiecrustError> { let stake_sk = BlsSecretKey::random(rng); let stake_pk = BlsPublicKey::from(&stake_sk); + let stake_pks = StakeKeys { + account: stake_pk, + funds: stake_pk, + }; let mut session = instantiate(rng, vm, &pk, GENESIS_VALUE); @@ -69,7 +75,7 @@ fn reward_slash() -> Result<(), PiecrustError> { session.call::<_, ()>( STAKE_CONTRACT, "insert_stake", - &(stake_pk, stake_data), + &(stake_pks, stake_data), u64::MAX, )?; @@ -130,6 +136,10 @@ fn stake_hard_slash() -> Result<(), PiecrustError> { let stake_sk = BlsSecretKey::random(rng); let stake_pk = BlsPublicKey::from(&stake_sk); + let stake_pks = StakeKeys { + account: stake_pk, + funds: stake_pk, + }; let mut session = instantiate(rng, vm, &pk, GENESIS_VALUE); @@ -161,7 +171,7 @@ fn stake_hard_slash() -> Result<(), PiecrustError> { session.call::<_, ()>( STAKE_CONTRACT, "insert_stake", - &(stake_pk, stake_data), + &(stake_pks, stake_data), u64::MAX, )?; diff --git a/execution-core/src/stake.rs b/execution-core/src/stake.rs index 710fef84c3..cb7b40986e 100644 --- a/execution-core/src/stake.rs +++ b/execution-core/src/stake.rs @@ -14,8 +14,9 @@ use rkyv::{Archive, Deserialize, Serialize}; use crate::{ signatures::bls::{ - PublicKey as BlsPublicKey, SecretKey as BlsSecretKey, - Signature as BlsSignature, + Error as BlsError, MultisigPublicKey as BlsMultisigPublicKey, + MultisigSignature as BlsMultisigSignature, PublicKey as BlsPublicKey, + SecretKey as BlsSecretKey, }, transfer::withdraw::Withdraw as TransferWithdraw, ContractId, @@ -44,14 +45,15 @@ pub const fn next_epoch(block_height: u64) -> u64 { #[archive_attr(derive(CheckBytes))] pub struct Stake { chain_id: u8, - account: BlsPublicKey, + keys: StakeKeys, value: u64, nonce: u64, - signature: BlsSignature, + signature: BlsMultisigSignature, } impl Stake { - const MESSAGE_SIZE: usize = 1 + BlsPublicKey::SIZE + u64::SIZE + u64::SIZE; + const MESSAGE_SIZE: usize = + 1 + BlsPublicKey::SIZE + BlsPublicKey::SIZE + u64::SIZE + u64::SIZE; /// Create a new stake. #[must_use] @@ -61,24 +63,37 @@ impl Stake { nonce: u64, chain_id: u8, ) -> Self { + let key = BlsPublicKey::from(sk); + let mut stake = Stake { chain_id, - account: BlsPublicKey::from(sk), + keys: StakeKeys { + account: key, + funds: key, + }, value, nonce, - signature: BlsSignature::default(), + signature: BlsMultisigSignature::default(), }; let msg = stake.signature_message(); - stake.signature = sk.sign(&msg); + + let first_sig = sk.sign_multisig(&key, &msg); + stake.signature = first_sig.aggregate(&[first_sig]); stake } + /// Account to which the stake will belong. + #[must_use] + pub fn keys(&self) -> &StakeKeys { + &self.keys + } + /// Account to which the stake will belong. #[must_use] pub fn account(&self) -> &BlsPublicKey { - &self.account + &self.keys.account } /// Value to stake. @@ -106,7 +121,7 @@ impl Stake { /// Signature of the stake. #[must_use] - pub fn signature(&self) -> &BlsSignature { + pub fn signature(&self) -> &BlsMultisigSignature { &self.signature } @@ -119,7 +134,11 @@ impl Stake { let mut offset = 1; bytes[offset..offset + BlsPublicKey::SIZE] - .copy_from_slice(&self.account.to_bytes()); + .copy_from_slice(&self.keys.account.to_bytes()); + offset += BlsPublicKey::SIZE; + + bytes[offset..offset + BlsPublicKey::SIZE] + .copy_from_slice(&self.keys.funds.to_bytes()); offset += BlsPublicKey::SIZE; bytes[offset..offset + u64::SIZE] @@ -141,21 +160,24 @@ impl Stake { pub struct Withdraw { account: BlsPublicKey, withdraw: TransferWithdraw, - signature: BlsSignature, + signature: BlsMultisigSignature, } impl Withdraw { /// Create a new withdraw call. #[must_use] pub fn new(sk: &BlsSecretKey, withdraw: TransferWithdraw) -> Self { + let account = BlsPublicKey::from(sk); let mut stake_withdraw = Withdraw { - account: BlsPublicKey::from(sk), + account, withdraw, - signature: BlsSignature::default(), + signature: BlsMultisigSignature::default(), }; let msg = stake_withdraw.signature_message(); - stake_withdraw.signature = sk.sign(&msg); + + let first_sig = sk.sign_multisig(&account, &msg); + stake_withdraw.signature = first_sig.aggregate(&[first_sig]); stake_withdraw } @@ -174,7 +196,7 @@ impl Withdraw { /// Signature of the withdraw. #[must_use] - pub fn signature(&self) -> &BlsSignature { + pub fn signature(&self) -> &BlsMultisigSignature { &self.signature } @@ -194,8 +216,8 @@ impl Withdraw { #[derive(Debug, Clone, Archive, Deserialize, Serialize)] #[archive_attr(derive(CheckBytes))] pub struct StakeEvent { - /// Account associated to the event. - pub account: BlsPublicKey, + /// Keys associated to the event. + pub keys: StakeKeys, /// Value of the relevant operation, be it `stake`, `unstake`,`withdraw` pub value: u64, } @@ -248,6 +270,29 @@ pub struct StakeData { pub hard_faults: u8, } +/// Keys that identify a stake +#[derive( + Debug, Default, Clone, Copy, PartialEq, Eq, Archive, Deserialize, Serialize, +)] +#[archive_attr(derive(CheckBytes))] +pub struct StakeKeys { + /// Key used for the consensus + pub account: BlsPublicKey, + /// Key used for handle funds (stake/unstake/withdraw) + pub funds: BlsPublicKey, +} + +impl StakeKeys { + /// Return the `MultisigPublicKey` associated to this `StakeKeys` + /// + /// # Errors + /// + /// Look at `MultisigPublicKey::aggregate` + pub fn multisig_pk(&self) -> Result { + BlsMultisigPublicKey::aggregate(&[self.account, self.funds]) + } +} + impl StakeData { /// An empty stake. pub const EMPTY: Self = Self { diff --git a/rusk-abi/src/abi.rs b/rusk-abi/src/abi.rs index 8e2ae2d9cd..17f76f174c 100644 --- a/rusk-abi/src/abi.rs +++ b/rusk-abi/src/abi.rs @@ -9,7 +9,10 @@ use alloc::vec::Vec; use dusk_bytes::Serializable; use execution_core::{ signatures::{ - bls::{PublicKey as BlsPublicKey, Signature as BlsSignature}, + bls::{ + MultisigPublicKey, MultisigSignature, PublicKey as BlsPublicKey, + Signature as BlsSignature, + }, schnorr::{ PublicKey as SchnorrPublicKey, Signature as SchnorrSignature, }, @@ -54,6 +57,15 @@ pub fn verify_bls(msg: Vec, pk: BlsPublicKey, sig: BlsSignature) -> bool { host_query(Query::VERIFY_BLS, (msg, pk, sig)) } +/// Verify a BLS signature is valid for the given public key and message +pub fn verify_bls_multisig( + msg: Vec, + pk: MultisigPublicKey, + sig: MultisigSignature, +) -> bool { + host_query(Query::VERIFY_BLS_MULTISIG, (msg, pk, sig)) +} + /// Get the chain ID. pub fn chain_id() -> u8 { meta_data(Metadata::CHAIN_ID).unwrap() diff --git a/rusk-abi/src/host.rs b/rusk-abi/src/host.rs index 13cefec46d..3a9a8490b0 100644 --- a/rusk-abi/src/host.rs +++ b/rusk-abi/src/host.rs @@ -12,7 +12,10 @@ use dusk_poseidon::{Domain, Hash as PoseidonHash}; use execution_core::{ plonk::{Proof, Verifier}, signatures::{ - bls::{PublicKey as BlsPublicKey, Signature as BlsSignature}, + bls::{ + MultisigPublicKey, MultisigSignature, PublicKey as BlsPublicKey, + Signature as BlsSignature, + }, schnorr::{ PublicKey as SchnorrPublicKey, Signature as SchnorrSignature, }, @@ -78,6 +81,10 @@ fn register_host_queries(vm: &mut VM) { vm.register_host_query(Query::VERIFY_PROOF, host_verify_proof); vm.register_host_query(Query::VERIFY_SCHNORR, host_verify_schnorr); vm.register_host_query(Query::VERIFY_BLS, host_verify_bls); + vm.register_host_query( + Query::VERIFY_BLS_MULTISIG, + host_verify_bls_multisig, + ); } fn wrap_host_query(arg_buf: &mut [u8], arg_len: u32, closure: F) -> u32 @@ -135,6 +142,12 @@ fn host_verify_bls(arg_buf: &mut [u8], arg_len: u32) -> u32 { }) } +fn host_verify_bls_multisig(arg_buf: &mut [u8], arg_len: u32) -> u32 { + wrap_host_query(arg_buf, arg_len, |(msg, pk, sig)| { + verify_bls_multisig(msg, pk, sig) + }) +} + /// Compute the blake2b hash of the given scalars, returning the resulting /// scalar. The hash is computed in such a way that it will always return a /// valid scalar. @@ -176,3 +189,12 @@ pub fn verify_schnorr( pub fn verify_bls(msg: Vec, pk: BlsPublicKey, sig: BlsSignature) -> bool { pk.verify(&sig, &msg).is_ok() } + +/// Verify a BLS signature is valid for the given public key and message +pub fn verify_bls_multisig( + msg: Vec, + pk: MultisigPublicKey, + sig: MultisigSignature, +) -> bool { + pk.verify(&sig, &msg).is_ok() +} diff --git a/rusk-abi/src/lib.rs b/rusk-abi/src/lib.rs index 52712d2449..34ecbe343a 100644 --- a/rusk-abi/src/lib.rs +++ b/rusk-abi/src/lib.rs @@ -29,7 +29,8 @@ mod abi; #[cfg(feature = "abi")] pub use abi::{ block_height, chain_id, hash, owner, owner_raw, poseidon_hash, self_owner, - self_owner_raw, verify_bls, verify_proof, verify_schnorr, + self_owner_raw, verify_bls, verify_bls_multisig, verify_proof, + verify_schnorr, }; #[cfg(feature = "abi")] @@ -54,7 +55,8 @@ mod host; #[cfg(feature = "host")] pub use host::{ hash, new_ephemeral_vm, new_genesis_session, new_session, new_vm, - poseidon_hash, verify_bls, verify_proof, verify_schnorr, + poseidon_hash, verify_bls, verify_bls_multisig, verify_proof, + verify_schnorr, }; #[cfg(feature = "host")] pub use piecrust::{ @@ -79,4 +81,5 @@ impl Query { pub const VERIFY_PROOF: &'static str = "verify_proof"; pub const VERIFY_SCHNORR: &'static str = "verify_schnorr"; pub const VERIFY_BLS: &'static str = "verify_bls"; + pub const VERIFY_BLS_MULTISIG: &'static str = "verify_bls_multisig"; } diff --git a/rusk-recovery/src/state.rs b/rusk-recovery/src/state.rs index 6b63b4079c..fcd9bfe746 100644 --- a/rusk-recovery/src/state.rs +++ b/rusk-recovery/src/state.rs @@ -54,6 +54,12 @@ pub static FAUCET_KEY: Lazy = Lazy::new(|| { PublicKey::from_slice(&bytes).expect("faucet should have a valid key") }); +pub static DUSK_CONSENSUS_KEY: Lazy = Lazy::new(|| { + let dusk_cpk_bytes = include_bytes!("../../rusk/src/assets/dusk.cpk"); + AccountPublicKey::from_slice(dusk_cpk_bytes) + .expect("Dusk consensus public key to be valid") +}); + fn generate_transfer_state( session: &mut Session, snapshot: &Snapshot, @@ -121,6 +127,18 @@ fn generate_stake_state( snapshot: &Snapshot, ) -> Result<(), Box> { let theme = Theme::default(); + session + .call::<_, ()>( + STAKE_CONTRACT, + "insert_stake", + &( + *DUSK_CONSENSUS_KEY, + *DUSK_CONSENSUS_KEY, + StakeData::default(), + ), + u64::MAX, + ) + .expect("stake to be inserted into the state"); snapshot.stakes().enumerate().for_each(|(idx, staker)| { info!("{} provisioner #{}", theme.action("Generating"), idx); @@ -142,7 +160,7 @@ fn generate_stake_state( .call::<_, ()>( STAKE_CONTRACT, "insert_stake", - &(*staker.address(), stake), + &(staker.to_stake_keys(), stake), u64::MAX, ) .expect("stake to be inserted into the state"); diff --git a/rusk-recovery/src/state/snapshot/stake.rs b/rusk-recovery/src/state/snapshot/stake.rs index a31e6ae6a9..8d09973b0a 100644 --- a/rusk-recovery/src/state/snapshot/stake.rs +++ b/rusk-recovery/src/state/snapshot/stake.rs @@ -7,7 +7,9 @@ use dusk_bytes::Serializable; use serde_derive::{Deserialize, Serialize}; -use execution_core::{signatures::bls::PublicKey as BlsPublicKey, Dusk}; +use execution_core::{ + signatures::bls::PublicKey as BlsPublicKey, stake::StakeKeys, Dusk, +}; use super::wrapper::Wrapper; @@ -23,4 +25,11 @@ impl GenesisStake { pub fn address(&self) -> &BlsPublicKey { &self.address } + + pub fn to_stake_keys(&self) -> StakeKeys { + StakeKeys { + account: *self.address(), + funds: *self.address(), + } + } } diff --git a/rusk/src/lib/http/rusk.rs b/rusk/src/lib/http/rusk.rs index 7c9a66edcc..2b4c80bfcd 100644 --- a/rusk/src/lib/http/rusk.rs +++ b/rusk/src/lib/http/rusk.rs @@ -137,7 +137,7 @@ impl Rusk { .provisioners(None) .expect("Cannot query state for provisioners") .map(|(key, stake)| { - let key = bs58::encode(key.to_bytes()).into_string(); + let key = bs58::encode(key.account.to_bytes()).into_string(); let amount = stake.amount.unwrap_or_default(); Provisioner { diff --git a/rusk/src/lib/node/rusk.rs b/rusk/src/lib/node/rusk.rs index 935270224d..79c14c0535 100644 --- a/rusk/src/lib/node/rusk.rs +++ b/rusk/src/lib/node/rusk.rs @@ -9,6 +9,7 @@ use std::sync::{mpsc, Arc, LazyLock}; use std::time::{Duration, Instant}; use std::{fs, io}; +use execution_core::stake::StakeKeys; use execution_core::transfer::PANIC_NONCE_NOT_READY; use parking_lot::RwLock; use sha3::{Digest, Sha3_256}; @@ -396,12 +397,12 @@ impl Rusk { pub fn provisioners( &self, base_commit: Option<[u8; 32]>, - ) -> Result> { + ) -> Result> { let (sender, receiver) = mpsc::channel(); self.feeder_query(STAKE_CONTRACT, "stakes", &(), sender, base_commit)?; Ok(receiver.into_iter().map(|bytes| { - rkyv::from_bytes::<(BlsPublicKey, StakeData)>(&bytes).expect( - "The contract should only return (pk, stake_data) tuples", + rkyv::from_bytes::<(StakeKeys, StakeData)>(&bytes).expect( + "The contract should only return (StakeKeys, StakeData) tuples", ) })) } diff --git a/rusk/src/lib/node/vm.rs b/rusk/src/lib/node/vm.rs index 2b8fcbfb45..f6b3240a7a 100644 --- a/rusk/src/lib/node/vm.rs +++ b/rusk/src/lib/node/vm.rs @@ -17,6 +17,7 @@ use execution_core::{ transfer::Transaction as ProtocolTransaction, Event, }; use node::vm::VMExecution; +use node_data::bls::PublicKey; use node_data::ledger::{Block, Slash, SpentTransaction, Transaction}; use super::Rusk; @@ -189,7 +190,7 @@ impl VMExecution for Rusk { fn get_changed_provisioners( &self, base_commit: [u8; 32], - ) -> anyhow::Result)>> { + ) -> anyhow::Result)>> { self.query_provisioners_change(Some(base_commit)) } @@ -243,7 +244,7 @@ impl Rusk { .provisioners(base_commit) .map_err(|e| anyhow::anyhow!("Cannot get provisioners {e}"))? .map(|(pk, stake)| { - (node_data::bls::PublicKey::new(pk), Self::to_stake(stake)) + (PublicKey::new(pk.account), Self::to_stake(stake)) }); let mut ret = Provisioners::empty(); for (pubkey_bls, stake) in provisioners { @@ -256,7 +257,7 @@ impl Rusk { fn query_provisioners_change( &self, base_commit: Option<[u8; 32]>, - ) -> anyhow::Result)>> { + ) -> anyhow::Result)>> { info!("Received get_provisioners_change request"); Ok(self .last_provisioners_change(base_commit) @@ -264,12 +265,7 @@ impl Rusk { anyhow::anyhow!("Cannot get provisioners change: {e}") })? .into_iter() - .map(|(pk, stake)| { - ( - node_data::bls::PublicKey::new(pk), - stake.map(Self::to_stake), - ) - }) + .map(|(pk, stake)| (PublicKey::new(pk), stake.map(Self::to_stake))) .collect()) } diff --git a/rusk/tests/common/keys.rs b/rusk/tests/common/keys.rs deleted file mode 100644 index 7815d79885..0000000000 --- a/rusk/tests/common/keys.rs +++ /dev/null @@ -1,21 +0,0 @@ -// This Source Code Form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at http://mozilla.org/MPL/2.0/. -// -// Copyright (c) DUSK NETWORK. All rights reserved. - -use std::sync::LazyLock; - -use rand::prelude::*; -use rand::rngs::StdRng; -use tracing::info; - -use execution_core::signatures::bls::SecretKey as BlsSecretKey; - -#[allow(dead_code)] -pub static STAKE_SK: LazyLock = LazyLock::new(|| { - info!("Generating BlsSecretKey"); - let mut rng = StdRng::seed_from_u64(0xdead); - - BlsSecretKey::random(&mut rng) -}); diff --git a/rusk/tests/common/mod.rs b/rusk/tests/common/mod.rs index fd3062315d..597097922a 100644 --- a/rusk/tests/common/mod.rs +++ b/rusk/tests/common/mod.rs @@ -5,7 +5,6 @@ // Copyright (c) DUSK NETWORK. All rights reserved. pub mod block; -pub mod keys; pub mod state; pub mod wallet; diff --git a/rusk/tests/common/state.rs b/rusk/tests/common/state.rs index 798591e65f..2bb8e78c1f 100644 --- a/rusk/tests/common/state.rs +++ b/rusk/tests/common/state.rs @@ -4,13 +4,12 @@ // // Copyright (c) DUSK NETWORK. All rights reserved. -use std::sync::LazyLock; use std::{path::Path, usize}; use dusk_bytes::Serializable; use node::vm::VMExecution; use rusk::{Result, Rusk}; -use rusk_recovery_tools::state::{self, Snapshot}; +use rusk_recovery_tools::state::{self, Snapshot, DUSK_CONSENSUS_KEY}; use dusk_consensus::operations::CallParams; use execution_core::{ @@ -27,8 +26,6 @@ use node_data::{ use tokio::sync::broadcast; use tracing::info; -use crate::common::keys::STAKE_SK; - const CHAIN_ID: u8 = 0xFA; // Creates a Rusk initial state in the given directory @@ -99,8 +96,7 @@ pub fn generator_procedure( rusk.preverify(tx)?; } - let generator = BlsPublicKey::from(LazyLock::force(&STAKE_SK)); - let generator_pubkey = node_data::bls::PublicKey::new(generator); + let generator_pubkey = node_data::bls::PublicKey::new(*DUSK_CONSENSUS_KEY); let generator_pubkey_bytes = *generator_pubkey.bytes(); let round = block_height; diff --git a/rusk/tests/config/bench.toml b/rusk/tests/config/bench.toml index c6e3cdb25d..f8cf3b33d6 100644 --- a/rusk/tests/config/bench.toml +++ b/rusk/tests/config/bench.toml @@ -1,7 +1,3 @@ -[acl.stake] -owners = [] -allowlist = [] - [[phoenix_balance]] address = "ivmscertKgRyX8wNMJJsQcSVEyPsfSMUQXSAgeAPQXsndqFq9Pmknzhm61QvcEEdxPaGgxDS4RHpb6KKccrnSKN" seed = 57005 diff --git a/rusk/tests/config/gas-behavior.toml b/rusk/tests/config/gas-behavior.toml index 2674bfa893..ff19967a12 100644 --- a/rusk/tests/config/gas-behavior.toml +++ b/rusk/tests/config/gas-behavior.toml @@ -7,4 +7,3 @@ notes = [10_000_000_000] address = "3MoVQ6VfGNu8fJ5GeHPRDVUfxcsDEmGXpWhvKhXY7F2dKCp7QWRw8RqPcbuJGdRqeTtxpuiwETnGAJLnhT4Kq4e8" seed = 57005 notes = [10_000_000_000] -