diff --git a/circuits/CHANGELOG.md b/circuits/CHANGELOG.md index 777f3a6..8cac56b 100644 --- a/circuits/CHANGELOG.md +++ b/circuits/CHANGELOG.md @@ -16,8 +16,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Change the gadget input to match the order of the circuits public inputs [#177] +- Update `dusk-poseidon` to v0.39 [#179] +- Update `jubjub-schnorr` to v0.4 [#179] +- Update `poseidon-merkle` to v0.6 [#179] +[#179]: https://github.com/dusk-network/phoenix/issues/179 [#177]: https://github.com/dusk-network/phoenix/issues/177 [#171]: https://github.com/dusk-network/phoenix/issues/171 [#169]: https://github.com/dusk-network/phoenix/issues/169 diff --git a/circuits/Cargo.toml b/circuits/Cargo.toml index 567de09..ebd4922 100644 --- a/circuits/Cargo.toml +++ b/circuits/Cargo.toml @@ -13,9 +13,9 @@ exclude = [".github/workflows/dusk-ci.yml", ".gitignore"] phoenix-core = { path = "../core" } dusk-plonk = { version = "0.19", default-features = false } dusk-jubjub = { version = "0.14", default-features = false } -poseidon-merkle = { version = "0.5", features = ["rkyv-impl", "zk", "size_32"] } -dusk-poseidon = { version = "0.33", default-features = false } -jubjub-schnorr = { version = "0.3", default-features = false, features = ["double", "alloc"] } +poseidon-merkle = { version = "0.6", features = ["rkyv-impl", "zk", "size_32"] } +dusk-poseidon = { version = "0.39", features = ["zk"] } +jubjub-schnorr = { version = "0.4", features = ["zk"] } rand_core = { version = "0.6", default-features = false } rand = "0.8" diff --git a/circuits/src/transaction.rs b/circuits/src/transaction.rs index 4730a6f..e0b568f 100644 --- a/circuits/src/transaction.rs +++ b/circuits/src/transaction.rs @@ -8,7 +8,7 @@ use dusk_jubjub::{ JubJubScalar, GENERATOR, GENERATOR_NUMS, GENERATOR_NUMS_EXTENDED, }; use dusk_plonk::prelude::*; -use dusk_poseidon::sponge; +use dusk_poseidon::{Domain, Hash, HashGadget}; use jubjub_schnorr::{gadgets, SignatureDouble}; use poseidon_merkle::{zk::opening_gadget, Item, Opening, Tree}; @@ -25,8 +25,8 @@ const TX_OUTPUT_NOTES: usize = 2; /// Struct representing a note willing to be spent, in a way /// suitable for being introduced in the transfer circuit #[derive(Debug, Clone)] -pub struct TxInputNote { - pub(crate) merkle_opening: Opening<(), H, A>, +pub struct TxInputNote { + pub(crate) merkle_opening: Opening<(), H>, pub(crate) note: Note, pub(crate) note_pk_p: JubJubAffine, pub(crate) value: u64, @@ -49,15 +49,15 @@ struct WitnessTxInputNote { signature_r_p: WitnessPoint, } -impl TxInputNote { +impl TxInputNote { /// Create a tx input note pub fn new( note: &Note, - merkle_opening: poseidon_merkle::Opening<(), H, A>, + merkle_opening: poseidon_merkle::Opening<(), H>, sk: &SecretKey, skeleteon_hash: BlsScalar, rng: &mut (impl RngCore + CryptoRng), - ) -> Result, PhoenixError> { + ) -> Result, PhoenixError> { let note_sk = sk.gen_note_sk(note); let note_pk_p = JubJubAffine::from(GENERATOR_NUMS_EXTENDED * note_sk.as_ref()); @@ -66,11 +66,10 @@ impl TxInputNote { let value = note.value(Some(&vk))?; let blinding_factor = note.blinding_factor(Some(&vk))?; - let nullifier = sponge::hash(&[ - note_pk_p.get_u(), - note_pk_p.get_v(), - (*note.pos()).into(), - ]); + let nullifier = Hash::digest( + Domain::Other, + &[note_pk_p.get_u(), note_pk_p.get_v(), (*note.pos()).into()], + )[0]; let signature = note_sk.sign_double(rng, skeleteon_hash); @@ -189,11 +188,11 @@ impl TxOutputNote { /// - `[output_value_commitment; 2]` /// - `max_fee` /// - `crossover` -pub fn gadget( +pub fn gadget( composer: &mut Composer, skeleton_hash: &BlsScalar, root: &BlsScalar, - tx_input_notes: &[TxInputNote; I], + tx_input_notes: &[TxInputNote; I], tx_output_notes: &[TxOutputNote; TX_OUTPUT_NOTES], max_fee: u64, crossover: u64, @@ -220,14 +219,15 @@ pub fn gadget( )?; // COMPUTE AND ASSERT THE NULLIFIER - let nullifier = sponge::gadget( + let nullifier = HashGadget::digest( composer, + Domain::Other, &[ *w_tx_input_note.note_pk_p.x(), *w_tx_input_note.note_pk_p.y(), w_tx_input_note.pos, ], - ); + )[0]; composer.assert_equal(nullifier, w_tx_input_note.nullifier); // PERFORM A RANGE CHECK ([0, 2^64 - 1]) ON THE VALUE OF THE NOTE @@ -251,8 +251,9 @@ pub fn gadget( let value_commitment = composer.component_add_point(pc_1, pc_2); // COMPUTE THE NOTE HASH - let note_hash = sponge::gadget( + let note_hash = HashGadget::digest( composer, + Domain::Other, &[ w_tx_input_note.note_type, *value_commitment.x(), @@ -261,7 +262,7 @@ pub fn gadget( *w_tx_input_note.note_pk.y(), w_tx_input_note.pos, ], - ); + )[0]; // VERIFY THE MERKLE OPENING let root = @@ -323,8 +324,8 @@ pub fn gadget( /// Declaration of the transaction circuit calling the [`gadget`]. #[derive(Debug)] -pub struct TxCircuit { - tx_input_notes: [TxInputNote; I], +pub struct TxCircuit { + tx_input_notes: [TxInputNote; I], tx_output_notes: [TxOutputNote; TX_OUTPUT_NOTES], skeleton_hash: BlsScalar, root: BlsScalar, @@ -332,16 +333,14 @@ pub struct TxCircuit { max_fee: u64, } -impl Default - for TxCircuit -{ +impl Default for TxCircuit { fn default() -> Self { let mut rng = StdRng::seed_from_u64(0xbeef); let sk = SecretKey::random(&mut rng); let vk = ViewKey::from(&sk); - let mut tree = Tree::<(), H, A>::new(); + let mut tree = Tree::<(), H>::new(); let skeleton_hash = BlsScalar::default(); let mut tx_input_notes = Vec::new(); @@ -388,10 +387,10 @@ impl Default } } -impl TxCircuit { +impl TxCircuit { /// Create a new transfer circuit pub fn new( - tx_input_notes: [TxInputNote; I], + tx_input_notes: [TxInputNote; I], tx_output_notes: [TxOutputNote; TX_OUTPUT_NOTES], skeleton_hash: BlsScalar, root: BlsScalar, @@ -409,11 +408,9 @@ impl TxCircuit { } } -impl Circuit - for TxCircuit -{ +impl Circuit for TxCircuit { fn circuit(&self, composer: &mut Composer) -> Result<(), Error> { - gadget::( + gadget::( composer, &self.skeleton_hash, &self.root, diff --git a/circuits/tests/transaction.rs b/circuits/tests/transaction.rs index a833e38..fc1856f 100644 --- a/circuits/tests/transaction.rs +++ b/circuits/tests/transaction.rs @@ -19,12 +19,11 @@ static LABEL: &[u8; 12] = b"dusk-network"; const CAPACITY: usize = 17; // capacity required for the setup const HEIGHT: usize = 17; -const ARITY: usize = 4; struct TestingParameters { sk: SecretKey, pp: PublicParameters, - tx_input_notes: [TxInputNote; 4], + tx_input_notes: [TxInputNote; 4], skeleton_hash: BlsScalar, root: BlsScalar, crossover: u64, @@ -36,7 +35,7 @@ lazy_static! { let pp = PublicParameters::setup(1 << CAPACITY, &mut OsRng).unwrap(); let sk = SecretKey::random(&mut OsRng); - let mut tree = Tree::<(), HEIGHT, ARITY>::new(); + let mut tree = Tree::<(), HEIGHT>::new(); let skeleton_hash = BlsScalar::from(1234u64); // create and insert into the tree 4 testing tx input notes @@ -54,7 +53,7 @@ lazy_static! { } fn create_and_insert_test_note( - tree: &mut Tree<(), HEIGHT, ARITY>, + tree: &mut Tree<(), HEIGHT>, pk: &PublicKey, pos: u64, value: u64, @@ -73,11 +72,11 @@ fn create_and_insert_test_note( } fn create_test_tx_input_notes( - tree: &mut Tree<(), HEIGHT, ARITY>, + tree: &mut Tree<(), HEIGHT>, sk: &SecretKey, skeleton_hash: BlsScalar, rng: &mut (impl RngCore + CryptoRng), -) -> [TxInputNote; I] { +) -> [TxInputNote; I] { let pk = PublicKey::from(sk); let mut notes = Vec::new(); @@ -122,7 +121,7 @@ fn create_test_tx_output_note( #[test] fn test_transfer_circuit_1_2() { let (prover, verifier) = - Compiler::compile::>(&TP.pp, LABEL) + Compiler::compile::>(&TP.pp, LABEL) .expect("failed to compile circuit"); let input_notes = [TP.tx_input_notes[0].clone()]; @@ -155,7 +154,7 @@ fn test_transfer_circuit_1_2() { #[test] fn test_transfer_circuit_2_2() { let (prover, verifier) = - Compiler::compile::>(&TP.pp, LABEL) + Compiler::compile::>(&TP.pp, LABEL) .expect("failed to compile circuit"); let input_notes = @@ -189,7 +188,7 @@ fn test_transfer_circuit_2_2() { #[test] fn test_transfer_circuit_3_2() { let (prover, verifier) = - Compiler::compile::>(&TP.pp, LABEL) + Compiler::compile::>(&TP.pp, LABEL) .expect("failed to compile circuit"); let input_notes = [ @@ -226,7 +225,7 @@ fn test_transfer_circuit_3_2() { #[test] fn test_transfer_circuit_4_2() { let (prover, verifier) = - Compiler::compile::>(&TP.pp, LABEL) + Compiler::compile::>(&TP.pp, LABEL) .expect("failed to compile circuit"); // create 2 testing tx output notes