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

Arkworks v0.5 #4927

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,14 @@ license = "MIT OR Apache-2.0"

[workspace.dependencies]
anyhow = { version = "1.0.75" }
ark-ec = { default-features = false, version = "0.4.2" }
ark-ff = { default-features = false, version = "0.4.2" }
ark-groth16 = { default-features = false, version = "0.4.0" }
ark-r1cs-std = { default-features = false, version = "0.4.0" }
ark-relations = { version = "0.4" }
ark-serialize = { version = "0.4.2" }
ark-snark = { version = "0.4.0" }
ark-std = { default-features = false, version = "0.4" }
ark-ec = { default-features = false, version = "0.5" }
ark-ff = { default-features = false, version = "0.5" }
ark-groth16 = { default-features = false, version = "0.5" }
ark-r1cs-std = { default-features = false, version = "0.5" }
ark-relations = { version = "0.5" }
ark-serialize = { version = "0.5" }
ark-snark = { version = "0.5" }
ark-std = { default-features = false, version = "0.5" }
assert_cmd = { version = "2.0" }
async-stream = { version = "0.3.5" }
async-trait = { version = "0.1.52" }
Expand All @@ -139,10 +139,10 @@ cnidarium = { default-features = false, path = "crates/cn
cnidarium-component = { default-features = false, path = "crates/cnidarium-component" }
cometindex = { path = "crates/util/cometindex" }
criterion = { version = "0.4" }
decaf377 = { default-features = false, version = "0.10.1" }
decaf377 = { default-features = false, git = "https://github.com/penumbra-zone/decaf377", branch = "arkworks-0.5" }
decaf377-fmd = { path = "crates/crypto/decaf377-fmd" }
decaf377-ka = { path = "crates/crypto/decaf377-ka" }
decaf377-rdsa = { version = "0.11.0" }
decaf377-rdsa = { git = "https://github.com/penumbra-zone/decaf377-rdsa", branch = "arkworks-0.5" }
derivative = { version = "2.2" }
directories = { version = "4.0.1" }
ed25519-consensus = { version = "2.1" }
Expand Down Expand Up @@ -200,7 +200,7 @@ penumbra-wallet = { path = "crates/wallet" }
penumbra-extension = { path = "crates/penumbra-extension", default-features = false }
pin-project = { version = "1.0.12" }
pin-project-lite = { version = "0.2.9" }
poseidon377 = { version = "1.2.0" }
poseidon377 = { git = "https://github.com/penumbra-zone/poseidon377", branch = "arkworks-0.5" }
proptest = { version = "1" }
proptest-derive = { version = "0.3" }
prost = { version = "0.12.3" }
Expand Down
2 changes: 1 addition & 1 deletion crates/bench/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ name = "arkworks"
harness = false

[dependencies]
ark-bls12-377 = "0.4.0"
ark-bls12-377 = "0.5.0"
ark-ec = {workspace = true}
ark-ff = {workspace = true, default-features = false}
ark-groth16 = {workspace = true, default-features = false}
Expand Down
7 changes: 5 additions & 2 deletions crates/core/asset/src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
use ark_ff::ToConstraintField;
use ark_r1cs_std::prelude::*;
use ark_relations::r1cs::SynthesisError;
use decaf377::{r1cs::FqVar, Fq};
use decaf377::{
r1cs::{fqvar_ext::FqVarExtension, FqVar},
Fq,
};

use std::{
convert::{TryFrom, TryInto},
Expand Down Expand Up @@ -319,7 +322,7 @@ impl EqGadget<Fq> for ValueVar {
fn is_eq(&self, other: &Self) -> Result<Boolean<Fq>, SynthesisError> {
let amount_eq = self.amount.is_eq(&other.amount)?;
let asset_id_eq = self.asset_id.is_eq(&other.asset_id)?;
amount_eq.and(&asset_id_eq)
FqVar::and(&amount_eq, &asset_id_eq)
}
}

Expand Down
10 changes: 6 additions & 4 deletions crates/core/component/shielded-pool/src/spend/proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ use tct::Root;

use anyhow::Result;
use ark_r1cs_std::{
prelude::{EqGadget, FieldVar},
prelude::{EqGadget, FieldVar, ToBitsGadget},
uint8::UInt8,
ToBitsGadget,
};
use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
use decaf377::{r1cs::FqVar, Bls12_377, Fq, Fr};
use decaf377::{
r1cs::{fqvar_ext::FqVarExtension, FqVar},
Bls12_377, Fq, Fr,
};

use ark_ff::ToConstraintField;
use ark_groth16::{
Expand Down Expand Up @@ -189,7 +191,7 @@ impl ConstraintSynthesizer<Fq> for SpendCircuit {
//
// We short circuit the merkle path verification if the note is a _dummy_ spend (a spend
// with zero value), since these are never committed to the state commitment tree.
let is_not_dummy = note_var.amount().is_eq(&FqVar::zero())?.not();
let is_not_dummy = FqVar::not(&note_var.amount().is_eq(&FqVar::zero())?)?;
merkle_path_var.verify(
cs.clone(),
&is_not_dummy,
Expand Down
15 changes: 8 additions & 7 deletions crates/core/keys/src/keys/ivk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use rand_core::{CryptoRng, RngCore};
use ark_r1cs_std::prelude::*;
use ark_relations::r1cs::SynthesisError;
use decaf377::{
r1cs::{ElementVar, FqVar},
r1cs::{fqvar_ext::FqVarExtension, ElementVar, FqVar},
Fq, Fr,
};

Expand Down Expand Up @@ -157,12 +157,13 @@ impl IncomingViewingKeyVar {
core::cmp::Ordering::Less,
false,
)?;
let overflows = a_var
.is_eq(&FqVar::new_constant(
cs.clone(),
&Fq::from(MOD_R_QUOTIENT as u64),
)?)?
.and(&is_less_than_q_minus_4_mod_r.not())?;
let overflows = FqVar::and(
&FqVar::is_eq(
&a_var,
&FqVar::new_constant(cs.clone(), &Fq::from(MOD_R_QUOTIENT as u64))?,
)?,
&FqVar::not(&is_less_than_q_minus_4_mod_r)?,
)?;
overflows.enforce_equal(&Boolean::FALSE)?;

Ok(IncomingViewingKeyVar { inner: ivk_mod_r })
Expand Down
20 changes: 15 additions & 5 deletions crates/core/num/src/amount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use serde::{Deserialize, Serialize};
use std::{fmt::Display, iter::Sum, num::NonZeroU128, ops};

use crate::fixpoint::{bit_constrain, U128x128, U128x128Var};
use decaf377::r1cs::fqvar_ext::FqVarExtension;
use decaf377::r1cs::FqVar;

#[derive(Serialize, Default, Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy)]
Expand Down Expand Up @@ -123,7 +124,7 @@ pub fn is_bit_constrained(
}

// Construct an FqVar from those n Boolean constraints
let constructed_fqvar = Boolean::<Fq>::le_bits_to_fp_var(&boolean_constraints.to_bits_le()?)
let constructed_fqvar = Boolean::<Fq>::le_bits_to_fp(&boolean_constraints.to_bits_le()?)
.expect("can convert to bits");
constructed_fqvar.is_eq(&value)
}
Expand Down Expand Up @@ -161,7 +162,8 @@ impl AmountVar {
// Constrain either quo_var or divisor_var to be 64 bits to guard against overflow
let q_is_64_bits = is_bit_constrained(self.cs(), quo_var.amount.clone(), 64)?;
let d_is_64_bits = is_bit_constrained(self.cs(), divisor_var.amount.clone(), 64)?;
let q_or_d_is_64_bits = q_is_64_bits.or(&d_is_64_bits)?;

let q_or_d_is_64_bits = FqVar::or(&q_is_64_bits, &d_is_64_bits)?;
q_or_d_is_64_bits.enforce_equal(&Boolean::constant(true))?;

// Constrain: numerator = quo * divisor + rem
Expand Down Expand Up @@ -528,10 +530,18 @@ impl U128x128Var {
impl From<U128x128Var> for AmountVar {
fn from(value: U128x128Var) -> Self {
let mut le_bits = Vec::new();
le_bits.extend_from_slice(&value.limbs[2].to_bits_le()[..]);
le_bits.extend_from_slice(&value.limbs[3].to_bits_le()[..]);
le_bits.extend_from_slice(
&value.limbs[2]
.to_bits_le()
.expect("limb can be converted to bits")[..],
);
le_bits.extend_from_slice(
&value.limbs[3]
.to_bits_le()
.expect("limb can be converted to bits")[..],
);
Self {
amount: Boolean::<Fq>::le_bits_to_fp_var(&le_bits[..]).expect("can convert to bits"),
amount: Boolean::<Fq>::le_bits_to_fp(&le_bits[..]).expect("can convert to bits"),
}
}
}
Expand Down
Loading
Loading