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

Move rusk-abi functionalities to execution_core #2033

Merged
merged 15 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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
8 changes: 6 additions & 2 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::{BlsMultisigSignature, BlsSigError};
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 @@ -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
4 changes: 3 additions & 1 deletion 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
5 changes: 4 additions & 1 deletion 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::{BlsMultisigPublicKey, BlsMultisigSignature};
use execution_core::signatures::bls::{
MultisigPublicKey as BlsMultisigPublicKey,
MultisigSignature as BlsMultisigSignature,
};
use tokio::sync::RwLock;

pub async fn verify_step_votes(
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
22 changes: 14 additions & 8 deletions contracts/stake/tests/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,17 @@ use rand::rngs::StdRng;
use rand::SeedableRng;

use execution_core::{
stake::{StakeAmount, StakeData},
BlsPublicKey, BlsSecretKey, PublicKey, SecretKey,
dusk,
signatures::bls::{PublicKey as BlsPublicKey, SecretKey as BlsSecretKey},
stake::{StakeAmount, StakeData, STAKE_CONTRACT},
transfer::{
phoenix::{
PublicKey as PhoenixPublicKey, SecretKey as PhoenixSecretKey,
},
TRANSFER_CONTRACT,
},
};
use rusk_abi::dusk::dusk;
use rusk_abi::{PiecrustError, STAKE_CONTRACT, TRANSFER_CONTRACT};
use rusk_abi::PiecrustError;

use crate::common::assert::assert_event;
use crate::common::init::instantiate;
Expand All @@ -28,8 +34,8 @@ fn reward_slash() -> Result<(), PiecrustError> {
let vm = &mut rusk_abi::new_ephemeral_vm()
.expect("Creating ephemeral VM should work");

let sk = SecretKey::random(rng);
let pk = PublicKey::from(&sk);
let sk = PhoenixSecretKey::random(rng);
let pk = PhoenixPublicKey::from(&sk);

let stake_sk = BlsSecretKey::random(rng);
let stake_pk = BlsPublicKey::from(&stake_sk);
Expand Down Expand Up @@ -117,8 +123,8 @@ fn stake_hard_slash() -> Result<(), PiecrustError> {
let vm = &mut rusk_abi::new_ephemeral_vm()
.expect("Creating ephemeral VM should work");

let sk = SecretKey::random(rng);
let pk = PublicKey::from(&sk);
let sk = PhoenixSecretKey::random(rng);
let pk = PhoenixPublicKey::from(&sk);

let stake_sk = BlsSecretKey::random(rng);
let stake_pk = BlsPublicKey::from(&stake_sk);
Expand Down
Loading
Loading