Skip to content
This repository has been archived by the owner on Nov 9, 2023. It is now read-only.

Commit

Permalink
Update dusk-plonk and canonical and related dependencies
Browse files Browse the repository at this point in the history
- Update `dusk-pki` from `v0.6` to `v0.7.0-rc.0`.
- Update `dusk-poseidon` from `v0.20.0` to `v0.21.0-rc.0`.
- Update `dusk-bls12_381` from `v0.6.0` to `v0.8.0-rc.0`.
- Update `dusk-jubjub` from `v0.8.0` to `v0.10.0-rc.0`.
- Update `dusk-plonk` from `v0.5` to `v0.8.0-rc.1`.
- Update `rand-core` from `v0.5` to `v0.6`.
- Update `canonical` from `v0.5` to `v0.6`.
- Update `rand` from `v0.7` to `v0.8`.
- Update `plonk_gadgets` from `v0.5` to `v0.6.0-rc.0`.
- Remove `MemStore` references from tests.
- Remove `canonical-host` from dev-deps.
- Update tests according to the new `dusk-plonk` API.
- Change `Bid::pos` method to return &u64 instead of `u64` directly.

Resolves: #127
Resolves: #129
  • Loading branch information
CPerezz committed Apr 30, 2021
1 parent 5762848 commit e9572e7
Show file tree
Hide file tree
Showing 7 changed files with 175 additions and 270 deletions.
28 changes: 14 additions & 14 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,26 @@ exclude = [
]

[dependencies]
dusk-pki = {version = "0.6", default-features = false}
dusk-poseidon = {version = "0.18", default-features = false }
dusk-bls12_381 = {version = "0.6", default-features = false}
dusk-jubjub = {version = "0.8", default-features = false}
dusk-plonk = {version = "0.5", features = ["trace-print"], optional = true}
dusk-pki = {version = "0.7.0-rc.0", default-features = false}
dusk-poseidon = {version = "0.21.0-rc.0", default-features = false }
dusk-bls12_381 = {version = "0.8.0-rc.0", default-features = false}
dusk-jubjub = {version = "0.10.0-rc.0", default-features = false}
dusk-plonk = {version = "0.8.0-rc.1", optional = true}
num-bigint = {version = "0.3", optional = true }
num-traits = {version = "0.2", optional = true }
plonk_gadgets = {version = "0.5", optional = true}
rand_core = {version = "0.5", default-features = false}
lazy_static = "1"
rand = {version = "0.7", default-features = false, optional = true }
canonical = { version = "0.5", optional = true }
canonical_derive = { version = "0.5", optional = true }
plonk_gadgets = {version = "0.6.0-rc.0", optional = true}
rand_core = {version = "0.6", default-features = false}
lazy_static = "1.4"
canonical = { version = "0.6", optional = true }
canonical_derive = { version = "0.6", optional = true }
rand = {version = "0.8"}
anyhow = {version = "1", optional = true}
dusk-bytes = "0.1"
cfg-if = "1.0"

[dev-dependencies]
canonical_host = "0.5"
microkelvin = "0.7.1"


[features]
default = ["std", "canon"]
Expand All @@ -49,12 +50,11 @@ std = [
"plonk_gadgets",
"num-bigint",
"num-traits",
"rand/default",
"rand_core/std",
]
canon = [
"canonical",
"canonical_derive",
"dusk-poseidon/canon",
"dusk-pki/canon",
]

6 changes: 3 additions & 3 deletions src/bid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,8 @@ impl Bid {
}

/// Returns the `pos` field of the Bid.
pub fn pos(&self) -> u64 {
self.pos
pub fn pos(&self) -> &u64 {
&self.pos
}

/// Sets a new value for the position of the Bid.
Expand Down Expand Up @@ -389,7 +389,7 @@ mod bid_serialization {
let stealth_addr = pk_r.gen_stealth_address(&secret);
let secret = GENERATOR_EXTENDED * secret;
let value: u64 =
(&mut rand::thread_rng()).gen_range(V_RAW_MIN, V_RAW_MAX);
(&mut rand::thread_rng()).gen_range(V_RAW_MIN..V_RAW_MAX);
let value = JubJubScalar::from(value);
// Set the timestamps as the max values so the proofs do not fail
// for them (never expired or non-elegible).
Expand Down
20 changes: 7 additions & 13 deletions src/bid/encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ mod tests {
let stealth_addr = pk_r.gen_stealth_address(&secret);
let secret = GENERATOR_EXTENDED * secret;
let value: u64 = (&mut rand::thread_rng())
.gen_range(crate::V_RAW_MIN, crate::V_RAW_MAX);
.gen_range(crate::V_RAW_MIN..crate::V_RAW_MAX);
let value = JubJubScalar::from(value);

let eligibility = u64::MAX;
Expand All @@ -194,7 +194,7 @@ mod tests {
}

#[test]
fn bid_preimage_gadget() -> Result<()> {
fn bid_preimage_gadget() -> Result<(), Error> {
// Generate Composer & Public Parameters
let pub_params =
PublicParameters::setup(1 << 14, &mut rand::thread_rng())?;
Expand All @@ -212,16 +212,10 @@ mod tests {
composer.add_input(bid.encrypted_data.cipher()[0]),
composer.add_input(bid.encrypted_data.cipher()[1]),
);
let bid_commitment = Point::from_private_affine(composer, bid.c);
let bid_commitment = composer.add_affine(bid.c);
let bid_stealth_addr = (
Point::from_private_affine(
composer,
bid.stealth_address.pk_r().as_ref().into(),
),
Point::from_private_affine(
composer,
bid.stealth_address.R().into(),
),
composer.add_affine(bid.stealth_address.pk_r().as_ref().into()),
composer.add_affine(bid.stealth_address.R().into()),
);
let eligibility = AllocatedScalar::allocate(
composer,
Expand Down Expand Up @@ -249,7 +243,7 @@ mod tests {
composer.constrain_to_constant(
bid_hash,
BlsScalar::zero(),
-storage_bid,
Some(-storage_bid),
);
};
// Proving
Expand All @@ -262,7 +256,7 @@ mod tests {
let mut verifier = Verifier::new(b"testing");
circuit(verifier.mut_cs(), &bid);
verifier.preprocess(&ck)?;
let pi = verifier.mut_cs().public_inputs.clone();
let pi = verifier.mut_cs().construct_dense_pi_vec();
verifier.verify(&proof, &vk, &pi)
}
}
26 changes: 11 additions & 15 deletions src/bid/score.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ impl Score {
two_pow_128,
-BlsScalar::one(),
BlsScalar::zero(),
BlsScalar::zero(),
None,
);
// 3.(r1 < |Fr|/2^128 AND Y' < 2^128) OR (r1 = |Fr|/2^128 AND Y' < |Fr|
// mod 2^128).
Expand Down Expand Up @@ -269,15 +269,15 @@ impl Score {
first_cond,
second_cond,
BlsScalar::zero(),
BlsScalar::zero(),
None,
);
// (r1 = |Fr|/2^128 AND Y' < |Fr| mod 2^128)
let right_assign = composer.mul(
BlsScalar::one(),
third_cond,
fourth_cond,
BlsScalar::zero(),
BlsScalar::zero(),
None,
);
// left_assign XOR right_assign = 1
// This is possible since condition 1. and 3. are mutually exclusive.
Expand All @@ -295,15 +295,15 @@ impl Score {
BlsScalar::one(),
BlsScalar::zero(),
-BlsScalar::one(),
BlsScalar::zero(),
None,
);

// 4. r2 < Y'
let r2_min_y_prime = composer.add(
(BlsScalar::one(), r2.var),
(-BlsScalar::one(), y_prime.var),
BlsScalar::zero(),
BlsScalar::zero(),
None,
);
let r2_min_y_prime_scalar = r2.scalar - y_prime.scalar;
let r2_min_y_prime = AllocatedScalar {
Expand All @@ -320,11 +320,7 @@ impl Score {

// Check that the result of the range_proof is indeed 0 to assert it
// passed.
composer.constrain_to_constant(
should_be_one.0,
BlsScalar::one(),
BlsScalar::zero(),
);
composer.constrain_to_constant(should_be_one.0, BlsScalar::one(), None);

// 5. q < 2^120
composer.range_gate(score_alloc_scalar.var, 120usize);
Expand All @@ -336,14 +332,14 @@ impl Score {
score_alloc_scalar.var,
y_prime.var,
BlsScalar::zero(),
BlsScalar::zero(),
None,
);
// q*Y' + r2
let left = composer.add(
(BlsScalar::one(), f_y_prime_prod),
(BlsScalar::one(), r2.var),
BlsScalar::zero(),
BlsScalar::zero(),
None,
);
// (q*Y' + r2) - v*2^128 = 0
composer.add_gate(
Expand All @@ -354,7 +350,7 @@ impl Score {
-two_pow_128,
BlsScalar::zero(),
BlsScalar::zero(),
BlsScalar::zero(),
None,
);

score_alloc_scalar.var
Expand Down Expand Up @@ -392,7 +388,7 @@ mod tests {
let stealth_addr = pk_r.gen_stealth_address(&secret);
let secret = GENERATOR_EXTENDED * secret;
let value: u64 = (&mut rand::thread_rng())
.gen_range(crate::V_RAW_MIN, crate::V_RAW_MAX);
.gen_range(crate::V_RAW_MIN..crate::V_RAW_MAX);
let value = JubJubScalar::from(value);
let eligibility = u64::MAX;
let expiration = u64::MAX;
Expand Down Expand Up @@ -454,7 +450,7 @@ mod tests {
}

#[test]
fn correct_score_gen_proof() -> Result<()> {
fn correct_score_gen_proof() -> Result<(), Error> {
// Generate Composer & Public Parameters
let pub_params =
PublicParameters::setup(1 << 17, &mut rand::thread_rng())?;
Expand Down
Loading

0 comments on commit e9572e7

Please sign in to comment.