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

Update plonk to 0.14 #942

Merged
merged 11 commits into from
Jul 6, 2023
13 changes: 7 additions & 6 deletions circuits/transfer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ rand_core = "0.6"
dusk-bytes = "0.1"
dusk-bls12_381 = "0.11"
dusk-jubjub = "0.12"
dusk-plonk = "0.13"
dusk-poseidon = "0.29.1-rc.0"
dusk-merkle = { version = "0.4.1-rc.0", features = ["poseidon", "zk"] }
dusk-pki ="0.11"
dusk-schnorr = "0.12"
phoenix-core = { version = "0.18", features = ["alloc"] }
dusk-plonk = "0.14"
dusk-poseidon = "0.30"
poseidon-merkle = { version = "0.2.1-rc.0", features = ["zk"] }
dusk-merkle = "0.5"
dusk-pki ="0.12"
dusk-schnorr = "0.13"
phoenix-core = { version = "0.20.0-rc.0", features = ["alloc"] }

code-hasher = { version = "0.4", path = "../../macros/code-hasher" }
rusk-profile = { version = "0.6", path = "../../rusk-profile", optional = true }
Expand Down
6 changes: 3 additions & 3 deletions circuits/transfer/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
use crate::{error::Error, gadgets};

use dusk_jubjub::{GENERATOR_EXTENDED, GENERATOR_NUMS_EXTENDED};
use dusk_merkle::poseidon::{Opening, Tree};
use dusk_merkle::Aggregate;
use dusk_pki::{Ownable, SecretSpendKey, ViewKey};
use dusk_poseidon::sponge;
use phoenix_core::{Crossover, Fee, Note};
use poseidon_merkle::{Opening, Tree};
use rand_core::{CryptoRng, RngCore};

use dusk_plonk::error::Error as PlonkError;
Expand Down Expand Up @@ -501,7 +501,7 @@ macro_rules! execute_circuit_variant {
composer.assert_equal_constant(
n,
BlsScalar::zero(),
Some(-witness.nullifier),
Some(witness.nullifier),
);

// 1.e commitment(ic,iv,ib,64)
Expand Down Expand Up @@ -540,7 +540,7 @@ macro_rules! execute_circuit_variant {
composer.assert_equal_constant(
crossover.fee_value_witness,
BlsScalar::zero(),
Some(-crossover.fee_value),
Some(crossover.fee_value),
);

// 3. ∀(o,v) ∈ O × V | O → V
Expand Down
11 changes: 4 additions & 7 deletions circuits/transfer/src/execute/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ use super::{
use crate::error::Error;
use crate::execute::ExecuteCircuit;

use dusk_merkle::poseidon::{Item, Tree};
use dusk_merkle::Aggregate;
use poseidon_merkle::{Item, Tree};

use dusk_pki::{PublicSpendKey, SecretSpendKey};
use phoenix_core::Note;
Expand Down Expand Up @@ -167,10 +167,7 @@ macro_rules! execute_circuit_variant {
rng: &mut R,
use_crossover: bool,
tx_hash: BlsScalar,
) -> Result<
(Self, Prover<Self>, Verifier<Self>, Proof, Vec<BlsScalar>),
Error,
>
) -> Result<(Self, Prover, Verifier, Proof, Vec<BlsScalar>), Error>
where
T: Clone + Default + Aggregate<A>,
{
Expand All @@ -184,8 +181,8 @@ macro_rules! execute_circuit_variant {
let pk = keys.get_prover()?;
let vd = keys.get_verifier()?;

let prover = Prover::<Self>::try_from_bytes(pk.as_slice())?;
let verifier = Verifier::<Self>::try_from_bytes(vd.as_slice())?;
let prover = Prover::try_from_bytes(pk.as_slice())?;
let verifier = Verifier::try_from_bytes(vd.as_slice())?;

let (proof, pi) = prover.prove(rng, &circuit)?;

Expand Down
23 changes: 2 additions & 21 deletions circuits/transfer/src/execute/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
//
// Copyright (c) DUSK NETWORK. All rights reserved.

use dusk_merkle::poseidon::Opening;
use dusk_pki::Ownable;
use dusk_poseidon::cipher::PoseidonCipher;
use phoenix_core::Note;
use poseidon_merkle::Opening;

use dusk_plonk::prelude::*;

Expand Down Expand Up @@ -92,23 +91,9 @@ impl<T, const H: usize, const A: usize> CircuitInput<T, H, A> {
let value_commitment = note.value_commitment();
let value_commitment = composer.append_point(value_commitment);

let nonce = hash_inputs[3];
let nonce = composer.append_witness(nonce);

let r = note.stealth_address().R();
let r = composer.append_point(r);

let pos = hash_inputs[8];
let pos = hash_inputs[5];
herr-seppia marked this conversation as resolved.
Show resolved Hide resolved
let pos = composer.append_witness(pos);

let mut cipher = [pos; PoseidonCipher::cipher_size()];
cipher
.iter_mut()
.zip(hash_inputs[9..].iter())
.for_each(|(c, i)| {
*c = composer.append_witness(*i);
});

let value = composer.append_witness(self.value);
let blinding_factor = composer.append_witness(self.blinding_factor);

Expand All @@ -125,11 +110,7 @@ impl<T, const H: usize, const A: usize> CircuitInput<T, H, A> {

note_type,
value_commitment,
nonce,
r,
pos,
cipher,

value,
blinding_factor,

Expand Down
13 changes: 1 addition & 12 deletions circuits/transfer/src/execute/input/witness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
//
// Copyright (c) DUSK NETWORK. All rights reserved.

use dusk_poseidon::cipher::PoseidonCipher;

use dusk_plonk::prelude::*;

/// Coupled code
Expand All @@ -31,30 +29,21 @@ pub struct WitnessInput {
pub schnorr_u: Witness,
pub schnorr_r: WitnessPoint,
pub schnorr_r_p: WitnessPoint,
pub r: WitnessPoint,
pub pos: Witness,
pub nonce: Witness,
pub cipher: [Witness; PoseidonCipher::cipher_size()],
pub note_hash: Witness,
pub nullifier: BlsScalar,
}

impl WitnessInput {
#[allow(clippy::wrong_self_convention)]
pub fn to_hash_inputs(&self) -> [Witness; 12] {
pub fn to_hash_inputs(&self) -> [Witness; 6] {
[
self.note_type,
*self.value_commitment.x(),
*self.value_commitment.y(),
self.nonce,
*self.pk_r.x(),
*self.pk_r.y(),
*self.r.x(),
*self.r.y(),
self.pos,
self.cipher[0],
self.cipher[1],
self.cipher[2],
]
}
}
5 changes: 2 additions & 3 deletions circuits/transfer/src/gadgets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ use dusk_merkle::Aggregate;
use dusk_plonk::prelude::*;
use dusk_poseidon::cipher;
use dusk_poseidon::sponge::truncated;

use dusk_merkle::poseidon::Opening;
use poseidon_merkle::{zk::opening_gadget, Opening};

pub use dusk_schnorr::gadgets::double_key_verify as schnorr_double_key_verify;
pub use dusk_schnorr::gadgets::single_key_verify as schnorr_single_key_verify;
Expand Down Expand Up @@ -52,7 +51,7 @@ pub fn merkle_opening<T, C, const H: usize, const A: usize>(
C: Composer,
{
// The gadget asserts the leaf is the expected
let root = branch.gadget(composer, leaf);
let root = opening_gadget(composer, branch, leaf);
composer.assert_equal(anchor, root);
}

Expand Down
2 changes: 1 addition & 1 deletion circuits/transfer/src/send_to_contract_obfuscated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ impl SendToContractObfuscatedCircuit {
}

#[allow(clippy::option_map_unit_fn)]
#[code_hasher::hash(name = "CIRCUIT_ID", version = "0.1.0")]
#[code_hasher::hash(name = "CIRCUIT_ID", version = "0.2.0")]
herr-seppia marked this conversation as resolved.
Show resolved Hide resolved
impl Circuit for SendToContractObfuscatedCircuit {
fn circuit<C: Composer>(&self, composer: &mut C) -> Result<(), PlonkError> {
let zero = C::ZERO;
Expand Down
2 changes: 1 addition & 1 deletion circuits/transfer/src/send_to_contract_transparent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ impl SendToContractTransparentCircuit {
}

#[allow(clippy::option_map_unit_fn)]
#[code_hasher::hash(name = "CIRCUIT_ID", version = "0.1.0")]
#[code_hasher::hash(name = "CIRCUIT_ID", version = "0.2.0")]
impl Circuit for SendToContractTransparentCircuit {
fn circuit<C: Composer>(&self, composer: &mut C) -> Result<(), PlonkError> {
// Witnesses
Expand Down
2 changes: 1 addition & 1 deletion circuits/transfer/src/withdraw_from_obfuscated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl WithdrawFromObfuscatedCircuit {
}
}

#[code_hasher::hash(name = "CIRCUIT_ID", version = "0.1.0")]
#[code_hasher::hash(name = "CIRCUIT_ID", version = "0.2.0")]
impl Circuit for WithdrawFromObfuscatedCircuit {
fn circuit<C: Composer>(&self, composer: &mut C) -> Result<(), PlonkError> {
let zero = C::ZERO;
Expand Down
2 changes: 1 addition & 1 deletion circuits/transfer/src/withdraw_from_transparent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl WithdrawFromTransparentCircuit {
}
}

#[code_hasher::hash(name = "CIRCUIT_ID", version = "0.1.0")]
#[code_hasher::hash(name = "CIRCUIT_ID", version = "0.2.0")]
impl Circuit for WithdrawFromTransparentCircuit {
fn circuit<C: Composer>(&self, composer: &mut C) -> Result<(), PlonkError> {
// Witnesses
Expand Down
7 changes: 1 addition & 6 deletions circuits/transfer/tests/keys/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,7 @@ use transfer_circuits::Error;

use dusk_plonk::prelude::*;

pub fn circuit_keys<C: Circuit>(
id: &[u8; 32],
) -> Result<(Prover<C>, Verifier<C>), Error>
where
C: Circuit,
{
pub fn circuit_keys(id: &[u8; 32]) -> Result<(Prover, Verifier), Error> {
let keys = rusk_profile::keys_for(id)?;
let pk = keys.get_prover()?;
let vd = keys.get_verifier()?;
Expand Down
2 changes: 1 addition & 1 deletion consensus/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ async-channel = "1.7.1"
async-trait = "0.1"
anyhow = "1.0"
node-data = { version = "0.1", path = "../node-data" }
dusk-merkle = "0.4.1-rc.0"
dusk-merkle = "0.5"

[dev-dependencies]
hex-literal = { version = "0.3.4" }
Expand Down
4 changes: 2 additions & 2 deletions contracts/alice/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ resolver = "2"
crate-type = ["cdylib", "rlib"]

[dependencies]
phoenix-core = { version = "0.18", default-features = false, features = ["rkyv-impl", "alloc"] }
phoenix-core = { version = "0.20.0-rc.0", default-features = false, features = ["rkyv-impl", "alloc"] }
rusk-abi = { version = "0.8.0-alpha", path = "../../rusk-abi", features = ["dlmalloc"] }
dusk-pki = { version = "0.11", default-features = false, features = ["rkyv-impl"] }
dusk-pki = { version = "0.12", default-features = false, features = ["rkyv-impl"] }

[dev-dependencies]
piecrust = "0.5"
2 changes: 1 addition & 1 deletion contracts/governance/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ crate-type = ["cdylib", "rlib"]
dusk-bls12_381 = { version = "0.11", default-features = false, features = ["rkyv-impl"] }
dusk-bls12_381-sign = { version = "0.4", default-features = false, features = ["rkyv-impl"] }
dusk-bytes = "0.1"
dusk-pki = { version = "0.11", default-features = false, features = ["rkyv-impl"] }
dusk-pki = { version = "0.12", default-features = false, features = ["rkyv-impl"] }
rusk-abi = { version = "0.8.0-alpha", path = "../../rusk-abi", features = ["dlmalloc"] }
rkyv = { version = "0.7", default-features = false }

Expand Down
8 changes: 4 additions & 4 deletions contracts/stake/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ dusk-bls12_381 = { version = "0.11", default-features = false, features = ["rkyv
dusk-bls12_381-sign = { version = "0.4", default-features = false, features = ["rkyv-impl"] }
dusk-bytes = "0.1"
dusk-jubjub = { version = "0.12", default-features = false, features = ["rkyv-impl"] }
dusk-pki = { version = "0.11", default-features = false, features = ["rkyv-impl"] }
phoenix-core = { version = "0.18", default-features = false, features = ["rkyv-impl", "alloc"] }
dusk-pki = { version = "0.12", default-features = false, features = ["rkyv-impl"] }
phoenix-core = { version = "0.20.0-rc.0", default-features = false, features = ["rkyv-impl", "alloc"] }
rusk-abi = { version = "0.8.0-alpha", path = "../../rusk-abi", features = ["dlmalloc"] }
dusk-plonk = { version = "0.13", default-features = false, features = ["rkyv-impl", "alloc"] }
dusk-plonk = { version = "0.14", default-features = false, features = ["rkyv-impl", "alloc"] }

[dev-dependencies]
piecrust = "0.5"
Expand All @@ -24,4 +24,4 @@ transfer-circuits = { version = "0.5", path = "../../circuits/transfer", feature
rkyv = { version = "0.7", default-features = false }
hex = "0.4"
rand = "0.8"
dusk-merkle = { version = "0.4.1-rc.0", features = ["poseidon", "rkyv-impl"] }
poseidon-merkle = { version = "0.2.1-rc.0", features = ["rkyv-impl"] }
6 changes: 2 additions & 4 deletions contracts/stake/tests/stake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ use dusk_bls12_381::BlsScalar;
use dusk_bls12_381_sign::{PublicKey, SecretKey};
use dusk_bytes::Serializable;
use dusk_jubjub::{JubJubScalar, GENERATOR_NUMS_EXTENDED};
use dusk_merkle::poseidon::Opening as PoseidonOpening;
use dusk_pki::{Ownable, PublicSpendKey, SecretSpendKey, ViewKey};
use dusk_plonk::prelude::*;
use phoenix_core::transaction::*;
use phoenix_core::{Fee, Note};
use piecrust::{ContractData, Error};
use piecrust::{Session, VM};
use poseidon_merkle::Opening as PoseidonOpening;
use rand::rngs::StdRng;
use rand::{CryptoRng, RngCore, SeedableRng};
use rusk_abi::dusk::{dusk, LUX};
Expand Down Expand Up @@ -121,9 +121,7 @@ fn opening(
session.call(TRANSFER_CONTRACT, "opening", &pos)
}

fn prover_verifier<C: Circuit>(
circuit_id: &[u8; 32],
) -> (Prover<C>, Verifier<C>) {
fn prover_verifier(circuit_id: &[u8; 32]) -> (Prover, Verifier) {
let (pk, vd) = prover_verifier_keys(circuit_id);

let prover = Prover::try_from_bytes(pk).unwrap();
Expand Down
10 changes: 5 additions & 5 deletions contracts/transfer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ crate-type = ["cdylib", "rlib"]
dusk-bls12_381 = { version = "0.11", default-features = false, features = ["rkyv-impl"] }
dusk-bytes = "0.1"
dusk-jubjub = { version = "0.12", default-features = false, features = ["rkyv-impl"] }
dusk-pki = { version = "0.11", default-features = false, features = ["rkyv-impl"] }
dusk-poseidon = { version = "0.29.1-rc.0", default-features = false, features = ["alloc"] }
dusk-merkle = { version = "0.4.1-rc.0", features = ["poseidon", "rkyv-impl"] }
phoenix-core = { version = "0.18", default-features = false, features = ["rkyv-impl", "alloc"] }
dusk-pki = { version = "0.12", default-features = false, features = ["rkyv-impl"] }
dusk-poseidon = { version = "0.30", default-features = false, features = ["alloc"] }
poseidon-merkle = { version = "0.2.1-rc.0", features = ["rkyv-impl"] }
phoenix-core = { version = "0.20.0-rc.0", default-features = false, features = ["rkyv-impl", "alloc"] }
rusk-abi = { version = "0.8.0-alpha", path = "../../rusk-abi", features = ["dlmalloc"] }
dusk-plonk = { version = "0.13", default-features = false, features = ["rkyv-impl", "alloc"] }
dusk-plonk = { version = "0.14", default-features = false, features = ["rkyv-impl", "alloc"] }

[dev-dependencies]
piecrust = "0.5"
Expand Down
42 changes: 33 additions & 9 deletions contracts/transfer/src/circuits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,39 @@
//
// Copyright (c) DUSK NETWORK. All rights reserved.

const VD_STCT: &[u8] = include_bytes!(concat!(env!("RUSK_PROFILE_PATH"), "/.rusk/keys/9d267dfe1d1ede4f2ffa35c3609f8662cd84e4df1066b2185a0f3b5b17721c79.vd"));
const VD_STCO: &[u8] = include_bytes!(concat!(env!("RUSK_PROFILE_PATH"), "/.rusk/keys/c8c7d7fa2fe8eeabd5505056ae3c00b44c1aa13d9578eeff3a4fc7ddb3035da4.vd"));
const VD_WFCT: &[u8] = include_bytes!(concat!(env!("RUSK_PROFILE_PATH"), "/.rusk/keys/dcc4561c1bbd8a10cd14c9e826d51373567dd41bb2cfd498f92230abc602ed47.vd"));
const VD_WFCO: &[u8] = include_bytes!(concat!(env!("RUSK_PROFILE_PATH"), "/.rusk/keys/8f7301b53f3af3eb14563c7e474a539a6e12c1248e1e9bdb4b07eeb2ef1a8f2e.vd"));

const VD_EXEC_1_2: &[u8] = include_bytes!(concat!(env!("RUSK_PROFILE_PATH"), "/.rusk/keys/4d5e60c2cdb7b3f273649487ad277eb0e380e44dd2f2effb0d2dcb3c1ff615d4.vd"));
const VD_EXEC_2_2: &[u8] = include_bytes!(concat!(env!("RUSK_PROFILE_PATH"), "/.rusk/keys/77d27ac80d397cfec7d621e61af4fa4b7fb4b9e503fa347082c5e1e187e08d48.vd"));
const VD_EXEC_3_2: &[u8] = include_bytes!(concat!(env!("RUSK_PROFILE_PATH"), "/.rusk/keys/4fb4e239548c5bdf9f5c6125cd07da64ce70edb99e79478f13140b53f136c441.vd"));
const VD_EXEC_4_2: &[u8] = include_bytes!(concat!(env!("RUSK_PROFILE_PATH"), "/.rusk/keys/05fb339e4fb471c745c8f90181a349ccf9226d8ee719073d45986fadcde466b4.vd"));
const VD_STCT: &[u8] = include_bytes!(concat!(
env!("RUSK_PROFILE_PATH"),
"/.rusk/keys/cfebfdcd309a070b44e1b407b7228ca9b900720e7cff283d653400357161899a.vd"
));
const VD_STCO: &[u8] = include_bytes!(concat!(
env!("RUSK_PROFILE_PATH"),
"/.rusk/keys/d7fbe016d385b7d3b44c510225388a0f2a9889d07294ba3e3f9c037801d3148e.vd"
));
const VD_WFCT: &[u8] = include_bytes!(concat!(
env!("RUSK_PROFILE_PATH"),
"/.rusk/keys/d0b52061b33cb2f2ef79448b53cd3d2dbca30819ca4a55e151c8af01e6c7efcd.vd"
));
const VD_WFCO: &[u8] = include_bytes!(concat!(
env!("RUSK_PROFILE_PATH"),
"/.rusk/keys/7824ae42a6208eb0eca9f7c5e7ca964efa04a500fc3275e1c89541a26876808a.vd"
));

const VD_EXEC_1_2: &[u8] = include_bytes!(concat!(
env!("RUSK_PROFILE_PATH"),
"/.rusk/keys/1aed4ea248e24d6eb71ca40dbc8aca90e1972f0c08cce0666df248e14627d299.vd"
));
const VD_EXEC_2_2: &[u8] = include_bytes!(concat!(
env!("RUSK_PROFILE_PATH"),
"/.rusk/keys/90369a00165fcf91b792bf6d64deaf39f5a16603588fe711838e1005e58458a6.vd"
));
const VD_EXEC_3_2: &[u8] = include_bytes!(concat!(
env!("RUSK_PROFILE_PATH"),
"/.rusk/keys/942a788cf56d9ef93bda7385e86e8620b127bb47eac46829f81bc48e61bdf00e.vd"
));
const VD_EXEC_4_2: &[u8] = include_bytes!(concat!(
env!("RUSK_PROFILE_PATH"),
"/.rusk/keys/076cdf6a1f160432941ac3cb14f8dece2c07da58559af4dfdda32b9be5cca884.vd"
));

/// Verifier data for the execute circuits.
pub const fn verifier_data_execute(inputs: usize) -> Option<&'static [u8]> {
Expand Down
2 changes: 1 addition & 1 deletion contracts/transfer/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ use core::ops::Range;
use dusk_bls12_381::BlsScalar;
use dusk_bytes::Serializable;
use dusk_jubjub::{JubJubAffine, JubJubExtended};
use dusk_merkle::poseidon::Opening as PoseidonOpening;
use dusk_pki::{Ownable, PublicKey, StealthAddress};
use phoenix_core::transaction::*;
use phoenix_core::{Crossover, Fee, Message, Note};
use poseidon_merkle::Opening as PoseidonOpening;
use rusk_abi::{ContractId, PaymentInfo, PublicInput, STAKE_CONTRACT};

/// Arity of the transfer tree.
Expand Down
Loading
Loading