Skip to content

Commit

Permalink
Merge branch 'master' into fix-1467
Browse files Browse the repository at this point in the history
  • Loading branch information
goshawk-3 authored Aug 5, 2024
2 parents 13e502f + 7f13eb5 commit 2f8cfa6
Show file tree
Hide file tree
Showing 91 changed files with 1,847 additions and 1,638 deletions.
5 changes: 4 additions & 1 deletion circuits/license/tests/prove_verify_license_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@

use dusk_plonk::prelude::*;
use dusk_poseidon::{Domain, Hash};
use execution_core::{JubJubAffine, PublicKey, SecretKey, GENERATOR_EXTENDED};
use execution_core::{
transfer::phoenix::{PublicKey, SecretKey},
JubJubAffine, GENERATOR_EXTENDED,
};
use ff::Field;
use license_circuits::{Error, LicenseCircuit, DEPTH};
use poseidon_merkle::{Item, Opening, Tree};
Expand Down
12 changes: 8 additions & 4 deletions consensus/src/aggregator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
use crate::user::cluster::Cluster;
use crate::user::committee::Committee;
use dusk_bytes::Serializable;
use execution_core::{BlsSigError, BlsSignature};
use execution_core::signatures::bls::{
Error as BlsSigError, MultisigSignature as BlsMultisigSignature,
};
use node_data::bls::{PublicKey, PublicKeyBytes};
use node_data::ledger::{to_str, StepVotes};
use node_data::message::payload::Vote;
Expand Down Expand Up @@ -184,12 +186,12 @@ impl<V> fmt::Display for Aggregator<V> {

#[derive(Default)]
pub(super) struct AggrSignature {
data: Option<BlsSignature>,
data: Option<BlsMultisigSignature>,
}

impl AggrSignature {
pub fn add(&mut self, data: &[u8; 48]) -> Result<(), BlsSigError> {
let sig = BlsSignature::from_bytes(data)?;
let sig = BlsMultisigSignature::from_bytes(data)?;

let aggr_sig = match self.data {
Some(data) => data.aggregate(&[sig]),
Expand All @@ -215,7 +217,9 @@ mod tests {
use crate::user::provisioners::{Provisioners, DUSK};
use crate::user::sortition::Config;
use dusk_bytes::DeserializableSlice;
use execution_core::{BlsPublicKey, BlsSecretKey};
use execution_core::signatures::bls::{
PublicKey as BlsPublicKey, SecretKey as BlsSecretKey,
};
use hex::FromHex;
use node_data::ledger::{Header, Seed};
use std::collections::HashMap;
Expand Down
6 changes: 3 additions & 3 deletions consensus/src/commons.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ use std::collections::HashMap;
use std::time::{Duration, SystemTime, UNIX_EPOCH};
use thiserror::Error;

use execution_core::{BlsSecretKey, BlsSigError};
use execution_core::signatures::bls::{
Error as BlsSigError, SecretKey as BlsSecretKey,
};
use node_data::bls::PublicKey;
use node_data::message::{AsyncQueue, Message, Payload};
use node_data::StepName;
Expand Down Expand Up @@ -91,8 +93,6 @@ pub enum StepSigError {
VoteSetTooSmall,
#[error("Verification error {0}")]
VerificationFailed(BlsSigError),
#[error("Empty Apk instance")]
EmptyApk,
#[error("Invalid Type")]
InvalidType,
}
Expand Down
2 changes: 1 addition & 1 deletion consensus/src/proposal/block_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl<T: Operations> Generator<T> {
// Sign seed
let seed = ru
.secret_key
.sign(ru.pubkey_bls.inner(), &ru.seed().inner()[..])
.sign_multisig(ru.pubkey_bls.inner(), &ru.seed().inner()[..])
.to_bytes();

let start = Instant::now();
Expand Down
21 changes: 8 additions & 13 deletions consensus/src/quorum/verifiers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ use crate::user::sortition;

use crate::config::CONSENSUS_MAX_ITER;
use dusk_bytes::Serializable as BytesSerializable;
use execution_core::{BlsAggPublicKey, BlsSignature};
use execution_core::signatures::bls::{
MultisigPublicKey as BlsMultisigPublicKey,
MultisigSignature as BlsMultisigSignature,
};
use tokio::sync::RwLock;

pub async fn verify_step_votes(
Expand Down Expand Up @@ -131,18 +134,10 @@ pub fn verify_votes(
}

impl Cluster<PublicKey> {
fn aggregate_pks(&self) -> Result<BlsAggPublicKey, StepSigError> {
fn aggregate_pks(&self) -> Result<BlsMultisigPublicKey, StepSigError> {
let pks: Vec<_> =
self.iter().map(|(pubkey, _)| *pubkey.inner()).collect();

match pks.split_first() {
Some((first, rest)) => {
let mut apk = BlsAggPublicKey::from(first);
apk.aggregate(rest)?;
Ok(apk)
}
None => Err(StepSigError::EmptyApk),
}
Ok(BlsMultisigPublicKey::aggregate(&pks)?)
}

pub fn to_voters(self) -> Vec<Voter> {
Expand All @@ -154,7 +149,7 @@ fn verify_step_signature(
header: &ConsensusHeader,
step: StepName,
vote: &Vote,
apk: BlsAggPublicKey,
apk: BlsMultisigPublicKey,
signature: &[u8; 48],
) -> Result<(), StepSigError> {
// Compile message to verify
Expand All @@ -164,7 +159,7 @@ fn verify_step_signature(
StepName::Proposal => Err(StepSigError::InvalidType)?,
};

let sig = BlsSignature::from_bytes(signature)?;
let sig = BlsMultisigSignature::from_bytes(signature)?;
let mut msg = header.signable();
msg.extend_from_slice(sign_seed);
vote.write(&mut msg).expect("Writing to vec should succeed");
Expand Down
4 changes: 3 additions & 1 deletion consensus/src/user/sortition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ mod tests {
use crate::user::provisioners::{Provisioners, DUSK};
use crate::user::sortition::Config;
use dusk_bytes::DeserializableSlice;
use execution_core::{BlsPublicKey, BlsSecretKey};
use execution_core::signatures::bls::{
PublicKey as BlsPublicKey, SecretKey as BlsSecretKey,
};

use node_data::ledger::Seed;

Expand Down
3 changes: 1 addition & 2 deletions contracts/alice/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
//
// Copyright (c) DUSK NETWORK. All rights reserved.

use execution_core::transfer::Withdraw;
use rusk_abi::TRANSFER_CONTRACT;
use execution_core::transfer::{withdraw::Withdraw, TRANSFER_CONTRACT};

/// Alice contract.
#[derive(Debug, Clone)]
Expand Down
14 changes: 10 additions & 4 deletions contracts/host_fn/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,14 @@ use alloc::vec::Vec;

use dusk_bytes::Serializable;
use execution_core::{
BlsPublicKey, BlsScalar, BlsSignature, PublicKey, SchnorrPublicKey,
SchnorrSignature,
signatures::{
bls::{PublicKey as BlsPublicKey, Signature as BlsSignature},
schnorr::{
PublicKey as SchnorrPublicKey, Signature as SchnorrSignature,
},
},
transfer::phoenix::PublicKey as PhoenixPublicKey,
BlsScalar,
};

static mut STATE: HostFnTest = HostFnTest;
Expand Down Expand Up @@ -62,11 +68,11 @@ impl HostFnTest {
rusk_abi::block_height()
}

pub fn owner(&self) -> PublicKey {
pub fn owner(&self) -> PhoenixPublicKey {
rusk_abi::self_owner()
}

pub fn owner_raw(&self) -> [u8; PublicKey::SIZE] {
pub fn owner_raw(&self) -> [u8; PhoenixPublicKey::SIZE] {
rusk_abi::self_owner_raw()
}
}
Expand Down
6 changes: 3 additions & 3 deletions contracts/license/tests/license.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ use zk_citadel::license::{
};

use execution_core::{
BlsScalar, JubJubAffine, PublicKey, SecretKey, StealthAddress, ViewKey,
GENERATOR_EXTENDED,
transfer::phoenix::{PublicKey, SecretKey, StealthAddress, ViewKey},
BlsScalar, ContractId, JubJubAffine, GENERATOR_EXTENDED,
};
use rusk_abi::{ContractData, ContractId, Session};
use rusk_abi::{ContractData, Session};
use rusk_profile::get_common_reference_string;

#[path = "../src/license_types.rs"]
Expand Down
10 changes: 6 additions & 4 deletions contracts/stake/benches/get_provisioners.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
// Copyright (c) DUSK NETWORK. All rights reserved.

use criterion::{criterion_group, criterion_main, Criterion};
use execution_core::{stake::StakeData, BlsPublicKey, BlsSecretKey};
use execution_core::{
stake::{StakeData, STAKE_CONTRACT},
transfer::TRANSFER_CONTRACT,
BlsPublicKey, BlsSecretKey,
};
use rand::rngs::StdRng;
use rand::{CryptoRng, RngCore, SeedableRng};
use rusk_abi::{
ContractData, PiecrustError, Session, STAKE_CONTRACT, TRANSFER_CONTRACT, VM,
};
use rusk_abi::{ContractData, PiecrustError, Session, VM};
use std::sync::mpsc;

const SAMPLE_SIZE: usize = 10;
Expand Down
6 changes: 3 additions & 3 deletions contracts/stake/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

extern crate alloc;

use rusk_abi::dusk::*;
use execution_core::{dusk, transfer::TRANSFER_CONTRACT, Dusk};

mod state;
use state::StakeState;
Expand Down Expand Up @@ -128,10 +128,10 @@ unsafe fn set_burnt_amount(arg_len: u32) -> u32 {
/// Asserts the call is made via the transfer contract.
///
/// # Panics
/// When the `caller` is not [`rusk_abi::TRANSFER_CONTRACT`].
/// When the `caller` is not [`TRANSFER_CONTRACT`].
fn assert_transfer_caller() {
const PANIC_MSG: &str = "Can only be called from the transfer contract";
if rusk_abi::caller().expect(PANIC_MSG) != rusk_abi::TRANSFER_CONTRACT {
if rusk_abi::caller().expect(PANIC_MSG) != TRANSFER_CONTRACT {
panic!("{PANIC_MSG}");
}
}
Expand Down
6 changes: 3 additions & 3 deletions contracts/stake/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ use core::cmp::min;
use dusk_bytes::Serializable;

use execution_core::{
signatures::bls::PublicKey as BlsPublicKey,
stake::{
next_epoch, Stake, StakeAmount, StakeData, StakeEvent, Withdraw, EPOCH,
STAKE_WARNINGS,
STAKE_CONTRACT, STAKE_WARNINGS,
},
BlsPublicKey,
transfer::TRANSFER_CONTRACT,
};
use rusk_abi::{STAKE_CONTRACT, TRANSFER_CONTRACT};

use crate::*;

Expand Down
5 changes: 3 additions & 2 deletions contracts/stake/tests/common/assert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
use dusk_bytes::Serializable;
use rkyv::{check_archived_root, Deserialize, Infallible};

use execution_core::{stake::StakeEvent, BlsPublicKey};
use rusk_abi::Event;
use execution_core::{
signatures::bls::PublicKey as BlsPublicKey, stake::StakeEvent, Event,
};

pub fn assert_event<S>(
events: &Vec<Event>,
Expand Down
13 changes: 10 additions & 3 deletions contracts/stake/tests/common/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,16 @@

use rand::{CryptoRng, RngCore};

use execution_core::{JubJubScalar, Note, PublicKey};
use execution_core::{
stake::STAKE_CONTRACT,
transfer::{
phoenix::{Note, PublicKey as PhoenixPublicKey},
TRANSFER_CONTRACT,
},
JubJubScalar,
};
use ff::Field;
use rusk_abi::{ContractData, Session, STAKE_CONTRACT, TRANSFER_CONTRACT, VM};
use rusk_abi::{ContractData, Session, VM};

use crate::common::utils::update_root;

Expand All @@ -20,7 +27,7 @@ const POINT_LIMIT: u64 = 0x100_000_000;
pub fn instantiate<Rng: RngCore + CryptoRng>(
rng: &mut Rng,
vm: &VM,
pk: &PublicKey,
pk: &PhoenixPublicKey,
genesis_value: u64,
) -> Session {
let transfer_bytecode = include_bytes!(
Expand Down
32 changes: 18 additions & 14 deletions contracts/stake/tests/common/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,20 @@ use rand::rngs::StdRng;
use rand::SeedableRng;

use execution_core::{
signatures::schnorr::SecretKey as SchnorrSecretKey,
transfer::{
ContractCall, ContractExec, Fee, PhoenixPayload, Transaction, TreeLeaf,
TRANSFER_TREE_DEPTH,
contract_exec::{ContractCall, ContractExec},
phoenix::{
value_commitment, Fee, Note, Payload as PhoenixPayload,
PublicKey as PhoenixPublicKey, SecretKey as PhoenixSecretKey,
Sender, TreeLeaf, TxSkeleton, ViewKey as PhoenixViewKey,
NOTES_TREE_DEPTH,
},
Transaction, TRANSFER_CONTRACT,
},
value_commitment, JubJubScalar, Note, PublicKey, SchnorrSecretKey,
SecretKey, Sender, TxSkeleton, ViewKey,
};
use rusk_abi::{
CallReceipt, ContractError, PiecrustError, Session, TRANSFER_CONTRACT,
ContractError, JubJubScalar,
};
use rusk_abi::{CallReceipt, PiecrustError, Session};

const POINT_LIMIT: u64 = 0x100000000;

Expand Down Expand Up @@ -83,7 +87,7 @@ pub fn root(session: &mut Session) -> Result<BlsScalar, PiecrustError> {
pub fn opening(
session: &mut Session,
pos: u64,
) -> Result<Option<PoseidonOpening<(), TRANSFER_TREE_DEPTH>>, PiecrustError> {
) -> Result<Option<PoseidonOpening<(), NOTES_TREE_DEPTH>>, PiecrustError> {
session
.call(TRANSFER_CONTRACT, "opening", &pos, POINT_LIMIT)
.map(|r| r.data)
Expand Down Expand Up @@ -113,7 +117,7 @@ pub fn prover_verifier(input_notes: usize) -> (Prover, Verifier) {
}

pub fn filter_notes_owned_by<I: IntoIterator<Item = Note>>(
vk: ViewKey,
vk: PhoenixViewKey,
iter: I,
) -> Vec<Note> {
iter.into_iter()
Expand Down Expand Up @@ -163,8 +167,8 @@ pub fn execute(
/// input note positions in the transaction tree and the new output-notes.
pub fn create_transaction<const I: usize>(
session: &mut Session,
sender_sk: &SecretKey,
receiver_pk: &PublicKey,
sender_sk: &PhoenixSecretKey,
receiver_pk: &PhoenixPublicKey,
gas_limit: u64,
gas_price: u64,
input_pos: [u64; I],
Expand All @@ -174,8 +178,8 @@ pub fn create_transaction<const I: usize>(
contract_call: Option<ContractCall>,
) -> Transaction {
let mut rng = StdRng::seed_from_u64(0xfeeb);
let sender_vk = ViewKey::from(sender_sk);
let sender_pk = PublicKey::from(sender_sk);
let sender_vk = PhoenixViewKey::from(sender_sk);
let sender_pk = PhoenixPublicKey::from(sender_sk);

// Create the transaction payload:

Expand Down Expand Up @@ -344,7 +348,7 @@ pub fn create_transaction<const I: usize>(
let sig_b = schnorr_sk_b.sign(&mut rng, payload_hash);

// Build the circuit
let circuit: TxCircuit<TRANSFER_TREE_DEPTH, I> = TxCircuit::new(
let circuit: TxCircuit<NOTES_TREE_DEPTH, I> = TxCircuit::new(
tx_input_notes
.try_into()
.expect("The input notes should be the correct ammount"),
Expand Down
Loading

0 comments on commit 2f8cfa6

Please sign in to comment.