Skip to content

Commit

Permalink
Update dependencies
Browse files Browse the repository at this point in the history
- dusk-plonk -> 0.19.0
- dusk-hades -> 0.24.0
  • Loading branch information
moCello committed Jan 3, 2024
1 parent b3aff6f commit 52cb55a
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 61 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ license = "MPL-2.0"
dusk-bls12_381 = { version = "0.13", default-features = false }
dusk-jubjub = { version = "0.14", default-features = false }
dusk-bytes = "0.1"
dusk-hades = "0.23"
dusk-plonk = { version = "0.18", default-features = false, features = ["alloc"] }
dusk-hades = "0.24"
dusk-plonk = { version = "0.19", default-features = false, features = ["alloc"] }
rkyv = { version = "0.7", optional = true, default-features = false }
bytecheck = { version = "0.6", optional = true, default-features = false }

Expand Down
33 changes: 12 additions & 21 deletions src/cipher/zk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,12 @@ use dusk_plonk::prelude::*;

impl PoseidonCipher {
/// Returns the initial state of the encryption within a composer circuit
pub fn initial_state_circuit<C>(
composer: &mut C,
pub fn initial_state_circuit(
composer: &mut Composer,
ks0: Witness,
ks1: Witness,
nonce: Witness,
) -> [Witness; dusk_hades::WIDTH]
where
C: Composer,
{
) -> [Witness; dusk_hades::WIDTH] {
let domain = BlsScalar::from_raw([0x100000000u64, 0, 0, 0]);
let domain = composer.append_constant(domain);

Expand All @@ -35,19 +32,16 @@ impl PoseidonCipher {
/// and jubjub, perform the encryption of the message.
///
/// The returned set of variables is the cipher text
pub fn encrypt<C>(
composer: &mut C,
pub fn encrypt(
composer: &mut Composer,
shared_secret: &WitnessPoint,
nonce: Witness,
message: &[Witness],
) -> [Witness; PoseidonCipher::cipher_size()]
where
C: Composer,
{
) -> [Witness; PoseidonCipher::cipher_size()] {
let ks0 = *shared_secret.x();
let ks1 = *shared_secret.y();

let mut cipher = [C::ZERO; PoseidonCipher::cipher_size()];
let mut cipher = [Composer::ZERO; PoseidonCipher::cipher_size()];

let mut state =
PoseidonCipher::initial_state_circuit(composer, ks0, ks1, nonce);
Expand All @@ -58,7 +52,7 @@ where
let x = if i < message.len() {
message[i]
} else {
C::ZERO
Composer::ZERO
};

let constraint =
Expand All @@ -79,19 +73,16 @@ where
/// and jubjub, perform the decryption of the cipher.
///
/// The returned set of variables is the original message
pub fn decrypt<C>(
composer: &mut C,
pub fn decrypt(
composer: &mut Composer,
shared_secret: &WitnessPoint,
nonce: Witness,
cipher: &[Witness],
) -> [Witness; PoseidonCipher::capacity()]
where
C: Composer,
{
) -> [Witness; PoseidonCipher::capacity()] {
let ks0 = *shared_secret.x();
let ks1 = *shared_secret.y();

let mut message = [C::ZERO; PoseidonCipher::capacity()];
let mut message = [Composer::ZERO; PoseidonCipher::capacity()];
let mut state =
PoseidonCipher::initial_state_circuit(composer, ks0, ks1, nonce);

Expand Down
7 changes: 2 additions & 5 deletions src/sponge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,8 @@ pub fn hash(messages: &[BlsScalar]) -> BlsScalar {
///
/// [`hash`]: crate::sponge::hash
#[cfg(feature = "alloc")]
pub fn gadget<C>(composer: &mut C, messages: &[Witness]) -> Witness
where
C: Composer,
{
let mut state = [C::ZERO; WIDTH];
pub fn gadget(composer: &mut Composer, messages: &[Witness]) -> Witness {
let mut state = [Composer::ZERO; WIDTH];

let l = messages.len();
let m = l / (WIDTH - 1);
Expand Down
11 changes: 4 additions & 7 deletions src/sponge/merkle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,12 @@ pub fn hash<const A: usize>(messages: &[BlsScalar; A]) -> BlsScalar {
///
/// The returned value is the witness of the hash of the levels.
#[cfg(feature = "alloc")]
pub fn gadget<C, const A: usize>(
composer: &mut C,
pub fn gadget<const A: usize>(
composer: &mut Composer,
messages: &[Witness; A],
) -> Witness
where
C: Composer,
{
) -> Witness {
// initialize the state with the capacity
let mut state = [C::ZERO; WIDTH];
let mut state = [Composer::ZERO; WIDTH];
state[0] = composer.append_witness(BlsScalar::from(tag::<A>()));

messages.chunks(WIDTH - 1).for_each(|chunk| {
Expand Down
7 changes: 2 additions & 5 deletions src/sponge/truncated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,9 @@ pub fn hash(messages: &[BlsScalar]) -> JubJubScalar {
///
/// [`hash`]: crate::sponge::hash
#[cfg(feature = "alloc")]
pub fn gadget<C>(composer: &mut C, message: &[Witness]) -> Witness
where
C: Composer,
{
pub fn gadget(composer: &mut Composer, message: &[Witness]) -> Witness {
let h = sponge::gadget(composer, message);

// Truncate to 250 bits
composer.append_logic_xor::<125>(h, C::ZERO)
composer.append_logic_xor::<125>(h, Composer::ZERO)
}
9 changes: 3 additions & 6 deletions tests/cipher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ use dusk_jubjub::{
dhke, JubJubAffine, JubJubExtended, JubJubScalar, GENERATOR,
GENERATOR_EXTENDED,
};
use dusk_plonk::error::Error as PlonkError;
use dusk_poseidon::cipher::{self, PoseidonCipher};
use ff::Field;
use rand::rngs::{OsRng, StdRng};
use rand::{RngCore, SeedableRng};

use dusk_plonk::prelude::Error as PlonkError;
use dusk_plonk::prelude::*;

fn gen() -> (
Expand Down Expand Up @@ -168,18 +168,15 @@ impl<'a> Default for TestCipherCircuit<'a> {
}

impl<'a> Circuit for TestCipherCircuit<'a> {
fn circuit<C>(&self, composer: &mut C) -> Result<(), PlonkError>
where
C: Composer,
{
fn circuit(&self, composer: &mut Composer) -> Result<(), PlonkError> {
let nonce = composer.append_witness(self.nonce);

let secret = composer.append_witness(self.secret);
let public = composer.append_point(self.public);

let shared = composer.component_mul_point(secret, public);

let mut message_circuit = [C::ZERO; PoseidonCipher::capacity()];
let mut message_circuit = [Composer::ZERO; PoseidonCipher::capacity()];

self.message
.iter()
Expand Down
7 changes: 2 additions & 5 deletions tests/merkle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,8 @@ impl MerkleCircuit {
}

impl Circuit for MerkleCircuit {
fn circuit<C>(&self, composer: &mut C) -> Result<(), PlonkError>
where
C: Composer,
{
let mut input_witnesses = [C::ZERO; A];
fn circuit(&self, composer: &mut Composer) -> Result<(), PlonkError> {
let mut input_witnesses = [Composer::ZERO; A];
for (i, witness) in input_witnesses.iter_mut().enumerate() {
*witness = composer.append_witness(self.input[i]);
}
Expand Down
14 changes: 4 additions & 10 deletions tests/sponge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@

use dusk_bls12_381::BlsScalar;
use dusk_bytes::ParseHexStr;
use dusk_plonk::error::Error as PlonkError;
use dusk_poseidon::sponge;
use ff::Field;
use rand::rngs::{OsRng, StdRng};
use rand::SeedableRng;

use dusk_plonk::prelude::Error as PlonkError;
use dusk_plonk::prelude::*;

const TEST_INPUTS: [&str; 32] = [
Expand Down Expand Up @@ -78,11 +78,8 @@ impl TestSpongeCircuit {
}

impl Circuit for TestSpongeCircuit {
fn circuit<C>(&self, composer: &mut C) -> Result<(), PlonkError>
where
C: Composer,
{
let mut i_var = vec![C::ZERO; self.input.len()];
fn circuit(&self, composer: &mut Composer) -> Result<(), PlonkError> {
let mut i_var = vec![Composer::ZERO; self.input.len()];
self.input.iter().zip(i_var.iter_mut()).for_each(|(i, v)| {
*v = composer.append_witness(*i);
});
Expand Down Expand Up @@ -173,10 +170,7 @@ impl TestTruncatedCircuit {
}

impl Circuit for TestTruncatedCircuit {
fn circuit<C>(&self, composer: &mut C) -> Result<(), PlonkError>
where
C: Composer,
{
fn circuit(&self, composer: &mut Composer) -> Result<(), PlonkError> {
let h = sponge::truncated::hash(self.input.as_slice());
let p = JubJubAffine::from(dusk_jubjub::GENERATOR_EXTENDED * h);
let p = composer.append_point(p);
Expand Down

0 comments on commit 52cb55a

Please sign in to comment.