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 93d7196 + fa4ebf1 commit 8a8bd6e
Show file tree
Hide file tree
Showing 36 changed files with 122 additions and 136 deletions.
5 changes: 3 additions & 2 deletions consensus/src/user/provisioners.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

use crate::user::sortition;
use crate::user::stake::Stake;
use execution_core::dusk;
use execution_core::stake::MINIMUM_STAKE;
use node_data::bls::{PublicKey, PublicKeyBytes};
use node_data::StepName;

Expand All @@ -16,8 +18,7 @@ use std::mem;

use super::committee::Committee;

pub const DUSK: u64 = 1_000_000_000;
const MINIMUM_STAKE: u64 = 1_000 * DUSK;
pub const DUSK: u64 = dusk(1.0);

#[derive(Clone, Debug)]
pub struct Provisioners {
Expand Down
1 change: 0 additions & 1 deletion contracts/host_fn/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,4 @@ crate-type = ["cdylib", "rlib"]
[dependencies]
execution-core = { version = "0.1.0", path = "../../execution-core" }
dusk-bytes = "0.1"
dusk-plonk = { version = "0.16", default-features = false, features = ["rkyv-impl", "alloc"] }
rusk-abi = { version = "0.13.0-rc", path = "../../rusk-abi" }
3 changes: 1 addition & 2 deletions contracts/license/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ edition = "2021"
crate-type = ["cdylib", "rlib"]

[dependencies]
execution-core = { version = "0.1.0", path = "../../execution-core" }
execution-core = { version = "0.1.0", path = "../../execution-core", features = ["zk"] }
dusk-bytes = "0.1"
dusk-poseidon = "0.39"
poseidon-merkle = { version = "0.6", 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 }

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

use execution_core::BlsScalar;
use execution_core::{plonk::Proof, BlsScalar};

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

#[allow(dead_code)]
Expand Down
4 changes: 2 additions & 2 deletions contracts/license/tests/license.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ extern crate alloc;
use std::ops::Range;
use std::sync::mpsc;

use dusk_plonk::prelude::*;
use dusk_poseidon::{Domain, Hash};
use ff::Field;
use poseidon_merkle::Opening;
Expand All @@ -21,8 +20,9 @@ use zk_citadel::license::{
};

use execution_core::{
plonk::{Compiler, PublicParameters},
transfer::phoenix::{PublicKey, SecretKey, StealthAddress, ViewKey},
BlsScalar, ContractId, JubJubAffine, GENERATOR_EXTENDED,
BlsScalar, ContractId, JubJubAffine, JubJubScalar, GENERATOR_EXTENDED,
};
use rusk_abi::{ContractData, Session};
use rusk_profile::get_common_reference_string;
Expand Down
3 changes: 1 addition & 2 deletions contracts/stake/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ crate-type = ["cdylib", "rlib"]
[dependencies]
execution-core = { version = "0.1.0", path = "../../execution-core" }
dusk-bytes = "0.1"
dusk-plonk = { version = "0.19", default-features = false, features = ["rkyv-impl", "alloc"] }
rkyv = { version = "0.7", default-features = false, features = ["size_32"] }

[target.'cfg(target_family = "wasm")'.dependencies]
Expand All @@ -18,7 +17,7 @@ rusk-abi = { version = "0.13.0-rc", path = "../../rusk-abi" }
[dev-dependencies]
rusk-profile = { version = "0.6", path = "../../rusk-profile" }
rusk-abi = { version = "0.13.0-rc", path = "../../rusk-abi", default-features = false, features = ["host"] }
phoenix-circuits = "0.2.1-rc"
execution-core = { version = "0.1.0", path = "../../execution-core", features = ["zk"] }
rkyv = { version = "0.7", default-features = false, features = ["size_32"] }
hex = "0.4"
rand = "0.8"
Expand Down
5 changes: 1 addition & 4 deletions contracts/stake/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,11 @@

extern crate alloc;

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

mod state;
use state::StakeState;

/// The minimum amount of Dusk one can stake.
pub const MINIMUM_STAKE: Dusk = dusk(1_000.0);

static mut STATE: StakeState = StakeState::new();

// Transactions
Expand Down
2 changes: 1 addition & 1 deletion contracts/stake/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use execution_core::{
signatures::bls::PublicKey as BlsPublicKey,
stake::{
next_epoch, Stake, StakeAmount, StakeData, StakeEvent, Withdraw, EPOCH,
STAKE_CONTRACT, STAKE_WARNINGS,
MINIMUM_STAKE, STAKE_CONTRACT, STAKE_WARNINGS,
},
transfer::TRANSFER_CONTRACT,
};
Expand Down
9 changes: 4 additions & 5 deletions contracts/stake/tests/common/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,25 @@
use std::sync::mpsc;

use dusk_bytes::Serializable;
use dusk_plonk::prelude::*;
use ff::Field;
use phoenix_circuits::transaction::{TxCircuit, TxInputNote, TxOutputNote};
use poseidon_merkle::Opening as PoseidonOpening;
use rand::rngs::StdRng;
use rand::SeedableRng;

use execution_core::{
plonk::{Prover, Verifier},
signatures::schnorr::SecretKey as SchnorrSecretKey,
transfer::{
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,
Sender, TreeLeaf, TxCircuit, TxInputNote, TxOutputNote, TxSkeleton,
ViewKey as PhoenixViewKey, NOTES_TREE_DEPTH,
},
Transaction, TRANSFER_CONTRACT,
},
ContractError, JubJubScalar,
BlsScalar, ContractError, JubJubAffine, JubJubScalar,
};
use rusk_abi::{CallReceipt, PiecrustError, Session};

Expand Down
3 changes: 1 addition & 2 deletions contracts/transfer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ crate-type = ["cdylib", "rlib"]
execution-core = { version = "0.1.0", path = "../../execution-core" }
dusk-bytes = "0.1"
poseidon-merkle = { version = "0.6", features = ["rkyv-impl"] }
dusk-plonk = { version = "0.19", default-features = false, features = ["rkyv-impl", "alloc"] }
rkyv = { version = "0.7", default-features = false, features = ["size_32"] }
ringbuffer = "0.15"

Expand All @@ -21,7 +20,7 @@ rusk-abi = { version = "0.13.0-rc", path = "../../rusk-abi" }
[dev-dependencies]
rusk-profile = { version = "0.6", path = "../../rusk-profile" }
rusk-abi = { version = "0.13.0-rc", path = "../../rusk-abi", default-features = false, features = ["host"] }
phoenix-circuits = "0.2.1-rc"
execution-core = { version = "0.1.0", path = "../../execution-core", features = ["zk"] }
rkyv = { version = "0.7", default-features = false, features = ["size_32"] }
bytecheck = { version = "0.6", default-features = false }
hex = "0.4"
Expand Down
8 changes: 4 additions & 4 deletions contracts/transfer/tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use std::sync::mpsc;

use execution_core::{
plonk::{Prover, Verifier},
signatures::{
bls::{PublicKey as AccountPublicKey, SecretKey as AccountSecretKey},
schnorr::SecretKey as SchnorrSecretKey,
Expand All @@ -20,18 +21,17 @@ use execution_core::{
phoenix::{
value_commitment, Fee, Note, Payload as PhoenixPayload, PublicKey,
SecretKey, Sender, Transaction as PhoenixTransaction, TreeLeaf,
TxSkeleton, ViewKey, NOTES_TREE_DEPTH,
TxCircuit, TxInputNote, TxOutputNote, TxSkeleton, ViewKey,
NOTES_TREE_DEPTH,
},
Transaction, TRANSFER_CONTRACT,
},
BlsScalar, ContractError, ContractId, JubJubScalar,
BlsScalar, ContractError, ContractId, JubJubAffine, JubJubScalar,
};
use rusk_abi::{CallReceipt, PiecrustError, Session};

use dusk_bytes::Serializable;
use dusk_plonk::prelude::*;
use ff::Field;
use phoenix_circuits::transaction::{TxCircuit, TxInputNote, TxOutputNote};
use poseidon_merkle::Opening as PoseidonOpening;
use rand::rngs::StdRng;
use rand::SeedableRng;
Expand Down
28 changes: 27 additions & 1 deletion execution-core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ signatures::{
PublicKey,
SecretKey,
Signature,
APK as AggPublicKey,
MutlisigPublicKey,
MultisigSignature
};
schnorr::{
PublicKey,
Expand Down Expand Up @@ -104,6 +105,31 @@ stake::{
};
licence::LICENSE_CONTRACT;
```
- under the `"zk"` feature:
```rust
plonk::{
pub use dusk_plonk::{
Circuit,
Compiler,
Composer,
Constraint,
Error,
Proof,
Prover,
PublicParameters,
Verifier,
Witness,
WitnessPoint,
}
};
transfer::phoenix::{
pub use phoenix_circuits{
TxCircuit,
TxInputNote,
TxOutputNote,
};
};
```

[Unreleased]: https://github.com/dusk-network/rusk/compare/execution-core-0.1.0...HEAD
[0.1.0]: https://github.com/dusk-network/dusk-abi/releases/tag/execution-core-0.1.0
10 changes: 10 additions & 0 deletions execution-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,19 @@ bytecheck = { version = "0.6", default-features = false }
rand = { version = "0.8", default-features = false }
ff = { version = "0.13", default-features = false }

# zk-dependencies
dusk-plonk = { version = "0.19", default-features = false, features = ["rkyv-impl", "alloc"], optional = true }
phoenix-circuits = { version = "0.2.1-rc", optional = true }

[dev-dependencies]
rand = "0.8"

[features]
# It enables parallel thread aggregation of BlsPublicKey
parallel = ["bls12_381-bls/parallel"]

# It enables zk-capabilities
zk = ["dusk-plonk", "phoenix-circuits"]

# Enables std feature for dusk-plonk
std = ["dusk-plonk/std"]
14 changes: 12 additions & 2 deletions execution-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ pub use dusk_jubjub::{

/// Signatures used in the Dusk protocol.
pub mod signatures {
/// Types for the bls-signature scheme.
/// Types for the bls-signature scheme operating on the `bls12_381` curve.
pub mod bls {
pub use bls12_381_bls::{
Error, MultisigPublicKey, MultisigSignature, PublicKey, SecretKey,
Signature,
};
}

/// Types for the schnorr-signature scheme.
/// Types for the schnorr-signature scheme operating on the `jubjub` curve.
pub mod schnorr {
pub use jubjub_schnorr::{
PublicKey, SecretKey, Signature, SignatureDouble,
Expand All @@ -52,6 +52,16 @@ pub use piecrust_uplink::{
CONTRACT_ID_BYTES,
};

/// Types and traits to create plonk circuits and generate and verify plonk
/// proofs.
#[cfg(feature = "zk")]
pub mod plonk {
pub use dusk_plonk::prelude::{
Circuit, Compiler, Composer, Constraint, Error, Proof, Prover,
PublicParameters, Verifier, Witness, WitnessPoint,
};
}

#[inline]
const fn reserved(b: u8) -> ContractId {
let mut bytes = [0u8; CONTRACT_ID_BYTES];
Expand Down
5 changes: 5 additions & 0 deletions execution-core/src/stake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ use crate::{
ContractId,
};

use crate::{dusk, Dusk};

/// ID of the genesis stake contract
pub const STAKE_CONTRACT: ContractId = crate::reserved(0x2);

Expand Down Expand Up @@ -188,6 +190,9 @@ pub struct StakeEvent {
pub receiver: Option<WithdrawReceiver>,
}

/// The minimum amount of Dusk one can stake.
pub const MINIMUM_STAKE: Dusk = dusk(1_000.0);

/// The representation of a public key's stake.
///
/// A user can stake for a particular `amount` larger in value than the
Expand Down
5 changes: 4 additions & 1 deletion execution-core/src/transfer/phoenix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ pub use phoenix_core::{
StealthAddress, TxSkeleton, ViewKey, NOTE_VAL_ENC_SIZE, OUTPUT_NOTES,
};

#[cfg(feature = "zk")]
pub use phoenix_circuits::transaction::{TxCircuit, TxInputNote, TxOutputNote};

/// Label used for the ZK transcript initialization. Must be the same for prover
/// and verifier.
pub const TRANSCRIPT_LABEL: &[u8] = b"dusk-network";
Expand All @@ -46,7 +49,7 @@ pub struct Fee {
pub gas_price: u64,
/// Address to send the remainder note
pub stealth_address: StealthAddress,
/// Sender to use for the remainder
/// Sender to use for the remainder note
pub sender: Sender,
}

Expand Down
24 changes: 11 additions & 13 deletions node/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub use header_validation::verify_att;
use node_data::ledger::{to_str, BlockWithLabel, Label};
use node_data::message::AsyncQueue;
use node_data::message::{Payload, Topics};
use std::ops::Deref;
use std::sync::Arc;
use std::time::Duration;
use tokio::sync::RwLock;
Expand Down Expand Up @@ -62,7 +63,9 @@ impl<N: Network, DB: database::DB, VM: vm::VMExecution>
db: Arc<RwLock<DB>>,
vm: Arc<RwLock<VM>>,
) -> anyhow::Result<()> {
let tip = Self::load_tip(db.clone(), vm.clone()).await?;
let tip =
Self::load_tip(db.read().await.deref(), vm.read().await.deref())
.await?;

let state_hash = tip.inner().header().state_hash;
let provisioners_list = vm.read().await.get_provisioners(state_hash)?;
Expand All @@ -73,8 +76,8 @@ impl<N: Network, DB: database::DB, VM: vm::VMExecution>
tip,
provisioners_list,
db,
network.clone(),
vm.clone(),
network,
vm,
self.max_consensus_queue_size,
)
.await?;
Expand Down Expand Up @@ -254,12 +257,9 @@ impl<N: Network, DB: database::DB, VM: vm::VMExecution> ChainSrv<N, DB, VM> {
/// Panics
///
/// If register entry is read but block is not found.
async fn load_tip(
db: Arc<RwLock<DB>>,
vm: Arc<RwLock<VM>>,
) -> Result<BlockWithLabel> {
let stored_block = db.read().await.update(|t| {
Ok(t.op_read(MD_HASH_KEY)?.and_then(|tip_hash| {
async fn load_tip(db: &DB, vm: &VM) -> Result<BlockWithLabel> {
let stored_block = db.view(|t| {
anyhow::Ok(t.op_read(MD_HASH_KEY)?.and_then(|tip_hash| {
t.fetch_block(&tip_hash[..])
.expect("block to be found if metadata is set")
}))
Expand All @@ -268,8 +268,6 @@ impl<N: Network, DB: database::DB, VM: vm::VMExecution> ChainSrv<N, DB, VM> {
let block = match stored_block {
Some(blk) => {
let (_, label) = db
.read()
.await
.view(|t| {
t.fetch_block_label_by_height(blk.header().height)
})?
Expand All @@ -280,9 +278,9 @@ impl<N: Network, DB: database::DB, VM: vm::VMExecution> ChainSrv<N, DB, VM> {
None => {
// Lack of register record means the loaded database is
// either malformed or empty.
let state = vm.read().await.get_state_root()?;
let state = vm.get_state_root()?;
let genesis_blk = genesis::generate_state(state);
db.write().await.update(|t| {
db.update(|t| {
// Persist genesis block
t.store_block(
genesis_blk.header(),
Expand Down
Loading

0 comments on commit 8a8bd6e

Please sign in to comment.