Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rusk: Remove allowlist #1257

Merged
merged 22 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
5bcf0e5
rusk-recovery: remove allowlist
herr-seppia Jan 15, 2024
5d239fc
examples: remove allowlist
herr-seppia Jan 15, 2024
16b2bed
stake-contract: remove allowlist
herr-seppia Jan 15, 2024
36007e7
stake-type: remove allow related structs
herr-seppia Jan 15, 2024
de1be2e
rusk: remove allowlist
herr-seppia Jan 17, 2024
b6f16b5
rusk: remove deprecated tests
herr-seppia Jan 18, 2024
e230cc7
transfer-contract: add `sub_module_balance` callable by stake-contract
herr-seppia Jan 15, 2024
47a898c
stake-contract: add slash calls
herr-seppia Jan 15, 2024
ba41142
rusk: change `rusk::provisioners` to filter out slashed stakes
herr-seppia Jan 15, 2024
a47a56f
rusk-recovery: remove `MINIMUM_STAKE` const
herr-seppia Jan 17, 2024
f598c65
consensus: change VST to verify a Block instead of CallParams
herr-seppia Jan 16, 2024
e34676f
node: change VST to verify a Block instead of CallParams
herr-seppia Jan 16, 2024
340cd4a
rusk: change VST to verify a Block instead of CallParams
herr-seppia Jan 16, 2024
c5bc261
node-data: add Generator to IterationInfo
herr-seppia Jan 17, 2024
78c2423
consensus: add Generator to IterationInfo
herr-seppia Jan 17, 2024
7dbd800
node: add failed generator check during header validation
herr-seppia Jan 17, 2024
66fc2a0
consensus: change get_nil_certificates to return only nil quorums
herr-seppia Jan 17, 2024
fd72b61
node: change header validation to check nil quorums
herr-seppia Jan 17, 2024
88d7c57
rusk: change block processing to slash failed iterations provisioner
herr-seppia Jan 17, 2024
8a7e9ad
rusk: add slash tests
herr-seppia Jan 18, 2024
16b2446
node: update provisioners if slash has been applied
herr-seppia Jan 17, 2024
6421dc4
rusk: update `CHANGELOG.md`
herr-seppia Jan 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions consensus/src/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,24 @@

use std::fmt;

use node_data::ledger::{Header, SpentTransaction, Transaction};
use dusk_bls12_381_sign::PublicKey;
use node_data::ledger::{Block, Header, SpentTransaction, Transaction};

pub type StateRoot = [u8; 32];
pub type EventHash = [u8; 32];

#[derive(Debug)]
pub enum Error {
Failed,
InvalidIterationInfo,
}

#[derive(Default, Clone, Debug)]
pub struct CallParams {
pub round: u64,
pub block_gas_limit: u64,
pub generator_pubkey: node_data::bls::PublicKey,
pub missed_generators: Vec<PublicKey>,
}

#[derive(Default)]
Expand Down Expand Up @@ -57,8 +60,7 @@ pub trait Operations: Send + Sync {

async fn verify_state_transition(
&self,
params: CallParams,
txs: Vec<Transaction>,
blk: &Block,
) -> Result<VerificationOutput, Error>;

async fn execute_state_transition(
Expand Down
11 changes: 8 additions & 3 deletions consensus/src/proposal/block_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl<T: Operations> Generator<T> {
&self,
ru: &RoundUpdate,
iteration: u8,
failed_iterations: Vec<Option<Certificate>>,
failed_iterations: IterationsInfo,
) -> Result<Message, crate::operations::Error> {
// Sign seed
let seed = ru
Expand Down Expand Up @@ -80,14 +80,19 @@ impl<T: Operations> Generator<T> {
ru: &RoundUpdate,
seed: Seed,
iteration: u8,
failed_iterations: Vec<Option<Certificate>>,
failed_iterations: IterationsInfo,
) -> Result<Block, crate::operations::Error> {
let start_time = Instant::now();

let missed_generators = failed_iterations
.to_missed_generators()
.map_err(|_| crate::operations::Error::InvalidIterationInfo)?;

let call_params = CallParams {
round: ru.round,
block_gas_limit: config::DEFAULT_BLOCK_GAS_LIMIT,
generator_pubkey: ru.pubkey_bls.clone(),
missed_generators,
};

let result = self
Expand Down Expand Up @@ -118,7 +123,7 @@ impl<T: Operations> Generator<T> {
prev_block_cert: *ru.cert(),
txroot,
iteration,
failed_iterations: IterationsInfo::new(failed_iterations),
failed_iterations,
};

// Apply a delay in block generator accordingly
Expand Down
3 changes: 2 additions & 1 deletion consensus/src/proposal/step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use crate::commons::{ConsensusError, Database};
use crate::execution_ctx::ExecutionCtx;
use crate::msg_handler::{HandleMsgOutput, MsgHandler};
use crate::operations::Operations;
use node_data::ledger::IterationsInfo;
use node_data::message::Message;
use std::cmp;
use std::sync::Arc;
Expand Down Expand Up @@ -67,7 +68,7 @@ impl<T: Operations + 'static, D: Database> ProposalStep<T, D> {
.generate_candidate_message(
&ctx.round_update,
ctx.iteration,
failed_certificates,
IterationsInfo::new(failed_certificates),
)
.await
{
Expand Down
2 changes: 2 additions & 0 deletions consensus/src/ratification/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ impl MsgHandler<Message> for RatificationHandler {
ratification_sv,
SvType::Ratification,
quorum_reached,
committee.excluded().expect("Generator to be excluded"),
);

if quorum_reached {
Expand Down Expand Up @@ -131,6 +132,7 @@ impl MsgHandler<Message> for RatificationHandler {
sv,
SvType::Ratification,
quorum_reached,
committee.excluded().expect("Generator to be excluded"),
)
{
return Ok(HandleMsgOutput::Ready(quorum_msg));
Expand Down
29 changes: 21 additions & 8 deletions consensus/src/step_votes_reg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
// Copyright (c) DUSK NETWORK. All rights reserved.

use crate::commons::RoundUpdate;
use node_data::ledger::StepVotes;
use node_data::ledger::{to_str, Certificate};
use node_data::bls::PublicKeyBytes;
use node_data::ledger::{to_str, Certificate, IterationInfo, StepVotes};
use node_data::message::{payload, Message, Topics};
use std::collections::HashMap;
use std::fmt;
Expand Down Expand Up @@ -94,13 +94,22 @@ impl CertificateInfo {

pub type SafeCertificateInfoRegistry = Arc<Mutex<CertInfoRegistry>>;

#[derive(Default, Clone)]
#[derive(Clone)]
struct IterationCerts {
valid: Option<CertificateInfo>,
nil: CertificateInfo,
generator: PublicKeyBytes,
}

impl IterationCerts {
fn new(generator: PublicKeyBytes) -> Self {
Self {
valid: None,
nil: CertificateInfo::default(),
generator,
}
}

fn for_hash(&mut self, hash: [u8; 32]) -> Option<&mut CertificateInfo> {
if hash == [0u8; 32] {
return Some(&mut self.nil);
Expand Down Expand Up @@ -144,8 +153,12 @@ impl CertInfoRegistry {
sv: StepVotes,
svt: SvType,
quorum_reached: bool,
generator: &PublicKeyBytes,
) -> Option<Message> {
let cert = self.cert_list.entry(iteration).or_default();
let cert = self
.cert_list
.entry(iteration)
.or_insert_with(|| IterationCerts::new(*generator));

cert.for_hash(hash).and_then(|cert| {
cert.add_sv(iteration, sv, svt, quorum_reached).then(|| {
Expand Down Expand Up @@ -181,16 +194,16 @@ impl CertInfoRegistry {
pub(crate) fn get_nil_certificates(
&mut self,
to: u8,
) -> Vec<Option<Certificate>> {
) -> Vec<Option<IterationInfo>> {
let mut res = Vec::with_capacity(to as usize);

for iteration in 0u8..to {
res.push(
self.cert_list
.get(&iteration)
.map(|c| c.nil)
.filter(|ci| ci.has_votes())
.map(|ci| ci.cert),
.map(|c| (c.nil, c.generator))
.filter(|(ci, _)| ci.is_ready())
.map(|(ci, pk)| (ci.cert, pk)),
);
}

Expand Down
8 changes: 7 additions & 1 deletion consensus/src/user/committee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::user::sortition;

use super::cluster::Cluster;
use crate::config;
use node_data::bls::PublicKey;
use node_data::bls::{PublicKey, PublicKeyBytes};
use std::collections::{BTreeMap, HashMap};
use std::fmt;
use std::mem;
Expand All @@ -19,6 +19,7 @@ pub struct Committee {
members: BTreeMap<PublicKey, usize>,
quorum: usize,
nil_quorum: usize,
excluded: Option<PublicKeyBytes>,
}

impl Committee {
Expand Down Expand Up @@ -47,6 +48,7 @@ impl Committee {
members: BTreeMap::new(),
nil_quorum,
quorum,
excluded: cfg.exclusion().copied(),
};

for member_key in res {
Expand All @@ -56,6 +58,10 @@ impl Committee {
committee
}

pub fn excluded(&self) -> Option<&PublicKeyBytes> {
self.excluded.as_ref()
}

/// Returns true if `pubkey_bls` is a member of the generated committee.
pub fn is_member(&self, pubkey_bls: &PublicKey) -> bool {
self.members.contains_key(pubkey_bls)
Expand Down
2 changes: 2 additions & 0 deletions consensus/src/validation/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ impl MsgHandler<Message> for ValidationHandler {
sv,
SvType::Validation,
quorum_reached,
committee.excluded().expect("Generator to be excluded"),
);

if quorum_reached {
Expand Down Expand Up @@ -159,6 +160,7 @@ impl MsgHandler<Message> for ValidationHandler {
sv,
SvType::Validation,
quorum_reached,
committee.excluded().expect("Generator to be excluded"),
)
{
return Ok(HandleMsgOutput::Ready(quorum_msg));
Expand Down
29 changes: 3 additions & 26 deletions consensus/src/validation/step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@
use crate::commons::{ConsensusError, Database, RoundUpdate};
use crate::config;
use crate::execution_ctx::ExecutionCtx;
use crate::operations::{CallParams, Operations};
use crate::operations::Operations;
use crate::validation::handler;
use anyhow::anyhow;
use dusk_bytes::DeserializableSlice;
use node_data::bls::PublicKey;
use node_data::ledger::{to_str, Block};
use node_data::message::{self, AsyncQueue, Message, Payload, Topics};
use std::sync::Arc;
Expand Down Expand Up @@ -75,7 +73,7 @@ impl<T: Operations + 'static> ValidationStep<T> {
};

// Call Verify State Transition to make sure transactions set is valid
if let Err(err) = Self::call_vst(candidate, ru, executor).await {
if let Err(err) = Self::call_vst(candidate, executor).await {
error!(event = "failed_vst_call", ?err);
return;
}
Expand Down Expand Up @@ -122,33 +120,12 @@ impl<T: Operations + 'static> ValidationStep<T> {

async fn call_vst(
candidate: &Block,
ru: &RoundUpdate,
executor: Arc<Mutex<T>>,
) -> anyhow::Result<()> {
let pubkey = &candidate.header().generator_bls_pubkey.0;
let generator = match dusk_bls12_381_sign::PublicKey::from_slice(pubkey)
{
Ok(pubkey) => pubkey,
Err(e) => {
return Err(anyhow::anyhow!(
"invalid bls key {}, err: {:?}",
hex::encode(pubkey),
e,
));
}
};

match executor
.lock()
.await
.verify_state_transition(
CallParams {
round: ru.round,
block_gas_limit: candidate.header().gas_limit,
generator_pubkey: PublicKey::new(generator),
},
candidate.txs().clone(),
)
.verify_state_transition(candidate)
.await
{
Ok(output) => {
Expand Down
12 changes: 0 additions & 12 deletions contracts/stake-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,3 @@ pub struct Withdraw {
/// A nonce to prevent replay.
pub nonce: BlsScalar,
}

/// Allow a public key to stake.
#[derive(Debug, Clone, Archive, Deserialize, Serialize)]
#[archive_attr(derive(CheckBytes))]
pub struct Allow {
/// The public key to allow staking to.
pub public_key: PublicKey,
/// The "owner" of the smart contract.
pub owner: PublicKey,
/// Signature of the `owner` key.
pub signature: Signature,
}
16 changes: 0 additions & 16 deletions contracts/stake-types/src/sig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,13 @@
use alloc::vec::Vec;

use dusk_bls12_381::BlsScalar;
use dusk_bls12_381_sign::PublicKey;
use dusk_bytes::Serializable;
use dusk_pki::StealthAddress;

const ALLOW_MESSAGE_SIZE: usize = u64::SIZE + PublicKey::SIZE;
const STAKE_MESSAGE_SIZE: usize = u64::SIZE + u64::SIZE;
const WITHDRAW_MESSAGE_SIZE: usize =
u64::SIZE + StealthAddress::SIZE + BlsScalar::SIZE;

/// Signature message used for [`Allow`].
#[must_use]
pub fn allow_signature_message(
counter: u64,
staker: &PublicKey,
) -> [u8; ALLOW_MESSAGE_SIZE] {
let mut bytes = [0u8; ALLOW_MESSAGE_SIZE];

bytes[..u64::SIZE].copy_from_slice(&counter.to_bytes());
bytes[u64::SIZE..].copy_from_slice(&staker.to_bytes());

bytes
}

/// Return the digest to be signed in the `stake` function of the stake
/// contract.
#[must_use]
Expand Down
36 changes: 5 additions & 31 deletions contracts/stake/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,6 @@ unsafe fn withdraw(arg_len: u32) -> u32 {
})
}

#[no_mangle]
unsafe fn allow(arg_len: u32) -> u32 {
rusk_abi::wrap_call(arg_len, |arg| {
assert_transfer_caller();
STATE.allow(arg)
})
}

// Queries

#[no_mangle]
Expand All @@ -68,18 +60,8 @@ unsafe fn get_stake(arg_len: u32) -> u32 {
}

#[no_mangle]
unsafe fn allowlist(arg_len: u32) -> u32 {
rusk_abi::wrap_call(arg_len, |_: ()| STATE.stakers_allowlist())
}

#[no_mangle]
unsafe fn is_allowlisted(arg_len: u32) -> u32 {
rusk_abi::wrap_call(arg_len, |pk| STATE.is_allowlisted(&pk))
}

#[no_mangle]
unsafe fn owners(arg_len: u32) -> u32 {
rusk_abi::wrap_call(arg_len, |_: ()| STATE.owners())
unsafe fn slashed_amount(arg_len: u32) -> u32 {
rusk_abi::wrap_call(arg_len, |_: ()| STATE.slashed_amount())
}

// "Feeder" queries
Expand All @@ -99,14 +81,6 @@ unsafe fn insert_stake(arg_len: u32) -> u32 {
})
}

#[no_mangle]
unsafe fn insert_allowlist(arg_len: u32) -> u32 {
rusk_abi::wrap_call(arg_len, |pk| {
assert_external_caller();
STATE.insert_allowlist(pk);
})
}

#[no_mangle]
unsafe fn reward(arg_len: u32) -> u32 {
rusk_abi::wrap_call(arg_len, |(pk, value)| {
Expand All @@ -116,10 +90,10 @@ unsafe fn reward(arg_len: u32) -> u32 {
}

#[no_mangle]
unsafe fn add_owner(arg_len: u32) -> u32 {
rusk_abi::wrap_call(arg_len, |pk| {
unsafe fn slash(arg_len: u32) -> u32 {
rusk_abi::wrap_call(arg_len, |(pk, value)| {
assert_external_caller();
STATE.add_owner(pk);
STATE.slash(&pk, value);
})
}

Expand Down
Loading