Skip to content

Commit

Permalink
Merge pull request #1804 from dusk-network/mocello/1780_core
Browse files Browse the repository at this point in the history
Add execution-core library
  • Loading branch information
moCello authored May 28, 2024
2 parents aab520a + 20de520 commit 304a8b2
Show file tree
Hide file tree
Showing 83 changed files with 470 additions and 915 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ members = [
"contracts/alice",
"contracts/bob",
"contracts/stake",
"contracts/stake-types",
"contracts/transfer",
"contracts/transfer-types",
"contracts/license",

"execution-core",

"rusk-prover",

"rusk-recovery",
Expand Down
2 changes: 1 addition & 1 deletion consensus/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ rand = { version = "0.8", default-features = false, features = ["std_rng"] }
tokio = { version = "1", features = ["full"] }
tracing-subscriber = "0.2"
tracing = "0.1"
bls12_381-bls = { version = "0.2" }
sha3 = { version = "0.10" }
num-bigint = { version = "0.4.3", default-features = false }
hex = { version = "0.4.3" }
Expand All @@ -29,6 +28,7 @@ async-channel = "1.7.1"
async-trait = "0.1"
anyhow = "1.0"
node-data = { version = "0.1", path = "../node-data" }
execution-core = { version = "0.1.0", path = "../execution-core" }
dusk-merkle = { version = "0.5", features = ["size_32"] }
thiserror = "1"
time-util = { version = "0.3", features = ["chrono"] }
Expand Down
22 changes: 12 additions & 10 deletions consensus/src/aggregator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use crate::user::cluster::Cluster;
use crate::user::committee::Committee;
use dusk_bytes::Serializable;
use execution_core::{BlsSigError, BlsSignature};
use node_data::bls::PublicKey;
use node_data::ledger::{to_str, StepVotes};
use node_data::message::payload::Vote;
Expand All @@ -31,11 +32,11 @@ pub enum AggregatorError {
#[error("Vote from member not in the committee")]
NotCommitteeMember,
#[error("Invalid signature to aggregate {0}")]
InvalidSignature(bls12_381_bls::Error),
InvalidSignature(BlsSigError),
}

impl From<bls12_381_bls::Error> for AggregatorError {
fn from(value: bls12_381_bls::Error) -> Self {
impl From<BlsSigError> for AggregatorError {
fn from(value: BlsSigError) -> Self {
Self::InvalidSignature(value)
}
}
Expand Down Expand Up @@ -152,12 +153,12 @@ impl fmt::Display for Aggregator {

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

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

let aggr_sig = match self.data {
Some(data) => data.aggregate(&[sig]),
Expand All @@ -182,8 +183,8 @@ mod tests {
use crate::user::committee::Committee;
use crate::user::provisioners::{Provisioners, DUSK};
use crate::user::sortition::Config;
use bls12_381_bls::{PublicKey, SecretKey};
use dusk_bytes::DeserializableSlice;
use execution_core::{StakePublicKey, StakeSecretKey};
use hex::FromHex;
use node_data::ledger::{Header, Seed};
use node_data::message::StepMessage;
Expand Down Expand Up @@ -216,7 +217,7 @@ mod tests {
.iter()
.map(|hex| hex::decode(hex).expect("valid hex"))
.map(|data| {
SecretKey::from_slice(&data[..]).expect("valid secret key")
StakeSecretKey::from_slice(&data[..]).expect("valid secret key")
})
.collect();

Expand All @@ -237,8 +238,9 @@ mod tests {
mrb_header.height = 0;

for secret_key in sks {
let pubkey_bls =
node_data::bls::PublicKey::new(PublicKey::from(&secret_key));
let pubkey_bls = node_data::bls::PublicKey::new(
StakePublicKey::from(&secret_key),
);

p.add_member_with_value(pubkey_bls.clone(), 1000 * DUSK);

Expand Down
18 changes: 9 additions & 9 deletions consensus/src/commons.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use std::collections::HashMap;
use std::time::{Duration, SystemTime, UNIX_EPOCH};
use thiserror::Error;

use bls12_381_bls::SecretKey;
use execution_core::{BlsSigError, StakeSecretKey};
use node_data::bls::PublicKey;
use node_data::message::{AsyncQueue, Message, Payload};
use node_data::StepName;
Expand All @@ -29,7 +29,7 @@ pub struct RoundUpdate {

// This provisioner consensus keys
pub pubkey_bls: PublicKey,
pub secret_key: SecretKey,
pub secret_key: StakeSecretKey,

seed: Seed,
hash: [u8; 32],
Expand All @@ -41,7 +41,7 @@ pub struct RoundUpdate {
impl RoundUpdate {
pub fn new(
pubkey_bls: PublicKey,
secret_key: SecretKey,
secret_key: StakeSecretKey,
mrb_header: &Header,
base_timeouts: TimeoutSet,
) -> Self {
Expand Down Expand Up @@ -75,15 +75,15 @@ pub enum StepSigError {
#[error("Failed to reach a quorum")]
VoteSetTooSmall,
#[error("Verification error {0}")]
VerificationFailed(bls12_381_bls::Error),
VerificationFailed(BlsSigError),
#[error("Empty Apk instance")]
EmptyApk,
#[error("Invalid Type")]
InvalidType,
}

impl From<bls12_381_bls::Error> for StepSigError {
fn from(inner: bls12_381_bls::Error) -> Self {
impl From<BlsSigError> for StepSigError {
fn from(inner: BlsSigError) -> Self {
Self::VerificationFailed(inner)
}
}
Expand All @@ -92,7 +92,7 @@ impl From<bls12_381_bls::Error> for StepSigError {
pub enum ConsensusError {
InvalidBlock,
InvalidBlockHash,
InvalidSignature(bls12_381_bls::Error),
InvalidSignature(BlsSigError),
InvalidMsgType,
InvalidValidationStepVotes(StepSigError),
InvalidValidation(QuorumType),
Expand All @@ -116,8 +116,8 @@ impl From<StepSigError> for ConsensusError {
Self::InvalidValidationStepVotes(e)
}
}
impl From<bls12_381_bls::Error> for ConsensusError {
fn from(e: bls12_381_bls::Error) -> Self {
impl From<BlsSigError> for ConsensusError {
fn from(e: BlsSigError) -> Self {
Self::InvalidSignature(e)
}
}
Expand Down
4 changes: 2 additions & 2 deletions consensus/src/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use std::fmt;
use std::time::Duration;

use bls12_381_bls::PublicKey;
use execution_core::StakePublicKey;
use node_data::ledger::{Block, Header, SpentTransaction, Transaction};
use node_data::StepName;

Expand All @@ -25,7 +25,7 @@ pub struct CallParams {
pub round: u64,
pub block_gas_limit: u64,
pub generator_pubkey: node_data::bls::PublicKey,
pub missed_generators: Vec<PublicKey>,
pub missed_generators: Vec<StakePublicKey>,
}

#[derive(Default)]
Expand Down
9 changes: 5 additions & 4 deletions consensus/src/quorum/verifiers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use crate::user::committee::{Committee, CommitteeSet};
use crate::user::sortition;

use dusk_bytes::Serializable as BytesSerializable;
use execution_core::{StakeAggPublicKey, StakeSignature};
use tokio::sync::RwLock;
use tracing::error;

Expand Down Expand Up @@ -161,13 +162,13 @@ pub fn verify_votes(
}

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

match pks.split_first() {
Some((first, rest)) => {
let mut apk = bls12_381_bls::APK::from(first);
let mut apk = StakeAggPublicKey::from(first);
apk.aggregate(rest);
Ok(apk)
}
Expand All @@ -180,7 +181,7 @@ fn verify_step_signature(
header: &ConsensusHeader,
step: StepName,
vote: &Vote,
apk: bls12_381_bls::APK,
apk: StakeAggPublicKey,
signature: &[u8; 48],
) -> Result<(), StepSigError> {
// Compile message to verify
Expand All @@ -190,7 +191,7 @@ fn verify_step_signature(
StepName::Proposal => Err(StepSigError::InvalidType)?,
};

let sig = bls12_381_bls::Signature::from_bytes(signature)?;
let sig = StakeSignature::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: 1 addition & 3 deletions consensus/src/user/sortition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,8 @@ mod tests {
use crate::user::committee::Committee;
use crate::user::provisioners::{Provisioners, DUSK};
use crate::user::sortition::Config;
use bls12_381_bls::{
PublicKey as StakePublicKey, SecretKey as StakeSecretKey,
};
use dusk_bytes::DeserializableSlice;
use execution_core::{StakePublicKey, StakeSecretKey};

use node_data::ledger::Seed;

Expand Down
2 changes: 1 addition & 1 deletion contracts/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SUBDIRS := stake-types transfer-types alice bob transfer stake license
SUBDIRS := alice bob license transfer stake

all: $(SUBDIRS) ## Build all the contracts

Expand Down
2 changes: 1 addition & 1 deletion contracts/alice/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ resolver = "2"
crate-type = ["cdylib", "rlib"]

[dependencies]
phoenix-core = { version = "0.26", default-features = false, features = ["rkyv-impl", "alloc"] }
execution-core = { version = "0.1.0", path = "../../execution-core" }
rusk-abi = { version = "0.13.0-rc", path = "../../rusk-abi", features = ["dlmalloc"] }
2 changes: 1 addition & 1 deletion contracts/alice/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//
// Copyright (c) DUSK NETWORK. All rights reserved.

use phoenix_core::transaction::*;
use execution_core::transfer::{Wfct, Wfctc};
use rusk_abi::TRANSFER_CONTRACT;

/// Alice contract.
Expand Down
5 changes: 1 addition & 4 deletions contracts/license/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@ edition = "2021"
crate-type = ["cdylib", "rlib"]

[dependencies]
dusk-bls12_381 = { version = "0.13", default-features = false, features = ["rkyv-impl"] }
execution-core = { version = "0.1.0", path = "../../execution-core" }
dusk-bytes = "0.1"
dusk-jubjub = { version = "0.14", default-features = false, features = ["rkyv-impl"] }
dusk-poseidon = { version = "0.33", default-features = false, features = ["rkyv-impl", "alloc"] }
poseidon-merkle = { version = "0.5", features = ["rkyv-impl", "zk", "size_32"] }
dusk-plonk = { version = "0.19", default-features = false, features = ["rkyv-impl", "alloc"] }
rkyv = { version = "0.7", default-features = false, features = ["size_32"] }
bytecheck = { version = "0.6", default-features = false }
jubjub-schnorr = { version = "0.2", default-features = false, features = ["rkyv-impl"] }

[target.'cfg(target_family = "wasm")'.dependencies]
rusk-abi = { version = "0.13.0-rc", path = "../../rusk-abi" }
Expand All @@ -28,7 +26,6 @@ rkyv = { version = "0.7", default-features = false, features = ["size_32"] }
hex = "0.4"
rand = "0.8"
zk-citadel = "0.11"
phoenix-core = { version = "0.26", default-features = false, features = ["rkyv-impl"] }
ff = { version = "0.13", default-features = false }

[build-dependencies]
Expand Down
3 changes: 2 additions & 1 deletion contracts/license/src/license_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ use alloc::vec::Vec;
use bytecheck::CheckBytes;
use rkyv::{Archive, Deserialize, Serialize};

use dusk_bls12_381::BlsScalar;
use execution_core::BlsScalar;

use dusk_plonk::prelude::Proof;
use poseidon_merkle::Item;

Expand Down
9 changes: 6 additions & 3 deletions contracts/license/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@
//
// Copyright (c) DUSK NETWORK. All rights reserved.

use crate::error::Error;
use alloc::vec::Vec;
use core::ops::Range;
use dusk_bls12_381::BlsScalar;

use alloc::vec::Vec;

use dusk_bytes::Serializable;
use poseidon_merkle::{Opening, Tree};

use execution_core::BlsScalar;
use rusk_abi::PublicInput;

use crate::collection::Map;
use crate::error::Error;
use crate::license_types::{
LicenseSession, LicenseSessionId, PoseidonItem, UseLicenseArg,
};
Expand Down
23 changes: 12 additions & 11 deletions contracts/license/tests/license.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,32 @@

extern crate alloc;

use dusk_bls12_381::BlsScalar;
use dusk_jubjub::{JubJubAffine, GENERATOR_EXTENDED};
use dusk_plonk::prelude::*;
use dusk_poseidon::sponge;
use phoenix_core::{PublicKey, SecretKey, StealthAddress, ViewKey};
use std::ops::Range;
use std::sync::mpsc;

use dusk_plonk::prelude::*;
use dusk_poseidon::sponge;
use ff::Field;
use poseidon_merkle::Opening;
use rand::rngs::StdRng;
use rand::{CryptoRng, RngCore, SeedableRng};
use rkyv::{check_archived_root, Deserialize, Infallible};
use zk_citadel::license::{License, Request};
use zk_citadel::utils::CitadelUtils;

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

#[path = "../src/license_types.rs"]
mod license_types;
use license_types::*;

use license_circuits::LicenseCircuit;

use ff::Field;
use rusk_abi::{ContractData, ContractId, Session};
use rusk_profile::get_common_reference_string;
use zk_citadel::license::{License, Request};
use zk_citadel::utils::CitadelUtils;

const LICENSE_CONTRACT_ID: ContractId = {
let mut bytes = [0u8; 32];
bytes[0] = 0xf8;
Expand Down
15 changes: 0 additions & 15 deletions contracts/stake-types/Cargo.toml

This file was deleted.

Loading

0 comments on commit 304a8b2

Please sign in to comment.