Skip to content

Commit

Permalink
Merge pull request #26 from Yoii-Inc/feat/#24_calc_commitment_in_mpc
Browse files Browse the repository at this point in the history
Feat/#24 calc commitment in mpc
  • Loading branch information
sheagrief authored Nov 6, 2023
2 parents 34030c1 + 9d1432a commit e505e67
Show file tree
Hide file tree
Showing 32 changed files with 1,389 additions and 230 deletions.
6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,8 @@ path = "src/bin_test_marlin.rs"

[[bin]]
name = "bin-test-groth16"
path = "src/bin_test_groth16.rs"
path = "src/bin_test_groth16.rs"

[[bin]]
name = "online"
path = "src/online.rs"
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ cargo build

run(by groth16):
```
cargo run groth16 ./inputs/inputs.json
cargo run --bin main groth16 ./inputs/inputs.json
```
or run(by marlin):
```
cargo run marlin ./inputs/inputs.json
cargo run --bin main marlin ./inputs/inputs.json
```

## Tests
Expand Down
2 changes: 2 additions & 0 deletions arkworks/algebra/ec/src/group.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
use ark_std::PubUniformRand;
use core::{
fmt::{Debug, Display},
hash::Hash,
Expand Down Expand Up @@ -27,6 +28,7 @@ pub trait Group:
+ Hash
+ Neg<Output = Self>
+ UniformRand
+ PubUniformRand
+ Zero
+ Add<Self, Output = Self>
+ Sub<Self, Output = Self>
Expand Down
2 changes: 2 additions & 0 deletions arkworks/algebra/ec/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use ark_std::{
hash::Hash,
ops::{Add, AddAssign, MulAssign, Neg, Sub, SubAssign},
vec::Vec,
PubUniformRand,
};
use num_traits::Zero;
use zeroize::Zeroize;
Expand Down Expand Up @@ -138,6 +139,7 @@ pub trait ProjectiveCurve:
+ Debug
+ Display
+ UniformRand
+ PubUniformRand
+ Zeroize
+ Zero
+ Neg<Output = Self>
Expand Down
6 changes: 5 additions & 1 deletion arkworks/algebra/ec/src/models/short_weierstrass_jacobian.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use ark_std::{
use ark_ff::{
bytes::{FromBytes, ToBytes},
fields::{BitIteratorBE, Field, PrimeField, SquareRootField},
ToConstraintField, UniformRand,
PubUniformRand, ToConstraintField, UniformRand,
};

use crate::{models::SWModelParameters as Parameters, AffineCurve, ProjectiveCurve};
Expand Down Expand Up @@ -352,6 +352,8 @@ impl<'a, P: Parameters> core::iter::Sum<&'a Self> for GroupAffine<P> {
}
}

impl<P: Parameters> PubUniformRand for GroupAffine<P> {}

mod group_impl {
use super::*;
use crate::group::Group;
Expand Down Expand Up @@ -433,6 +435,8 @@ impl<P: Parameters> Distribution<GroupProjective<P>> for Standard {
}
}

impl<P: Parameters> PubUniformRand for GroupProjective<P> {}

impl<P: Parameters> ToBytes for GroupProjective<P> {
#[inline]
fn write<W: Write>(&self, mut writer: W) -> IoResult<()> {
Expand Down
18 changes: 17 additions & 1 deletion arkworks/algebra/ec/src/models/twisted_edwards_extended.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use zeroize::Zeroize;
use ark_ff::{
bytes::{FromBytes, ToBytes},
fields::{BitIteratorBE, Field, PrimeField, SquareRootField},
ToConstraintField, UniformRand,
PubUniformRand, ToConstraintField, UniformRand,
};

#[cfg(feature = "parallel")]
Expand Down Expand Up @@ -269,6 +269,8 @@ impl<P: Parameters> Distribution<GroupAffine<P>> for Standard {
}
}

impl<P: Parameters> PubUniformRand for GroupAffine<P> {}

mod group_impl {
use super::*;
use crate::group::Group;
Expand Down Expand Up @@ -365,6 +367,20 @@ impl<P: Parameters> Distribution<GroupProjective<P>> for Standard {
}
}

impl<P: Parameters> PubUniformRand for GroupProjective<P> {
#[inline]
fn pub_rand<R: Rng + ?Sized>(rng: &mut R) -> GroupProjective<P> {
loop {
let x = P::BaseField::pub_rand(rng);
let greatest = rng.gen();

if let Some(p) = GroupAffine::get_point_from_x(x, greatest) {
return p.scale_by_cofactor();
}
}
}
}

impl<P: Parameters> ToBytes for GroupProjective<P> {
#[inline]
fn write<W: Write>(&self, mut writer: W) -> IoResult<()> {
Expand Down
2 changes: 2 additions & 0 deletions arkworks/crypto-primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ rayon = { version = "1.0", optional = true }
derivative = { version = "2.0", features = ["use_core"] }
tracing = { version = "0.1", default-features = false, features = [ "attributes" ], optional = true }

mpc-trait = { path = "../../mpc-trait" }

[features]
default = ["std"]
std = [ "ark-ff/std", "ark-ec/std", "ark-std/std", "ark-relations/std" ]
Expand Down
12 changes: 11 additions & 1 deletion arkworks/crypto-primitives/src/commitment/pedersen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ use ark_ff::{bytes::ToBytes, BitIteratorLE, Field, FpParameters, PrimeField, ToC
use ark_std::io::{Result as IoResult, Write};
use ark_std::marker::PhantomData;
use ark_std::rand::Rng;
use ark_std::UniformRand;
use ark_std::{PubUniformRand, UniformRand};
use mpc_trait::MpcWire;

use super::CommitmentScheme;

Expand Down Expand Up @@ -36,6 +37,15 @@ impl<C: ProjectiveCurve> UniformRand for Randomness<C> {
}
}

impl<C: ProjectiveCurve> MpcWire for Randomness<C> {}

impl<C: ProjectiveCurve> PubUniformRand for Randomness<C> {
#[inline]
fn pub_rand<R: Rng + ?Sized>(rng: &mut R) -> Self {
Randomness(PubUniformRand::pub_rand(rng))
}
}

impl<C: ProjectiveCurve> ToBytes for Randomness<C> {
fn write<W: Write>(&self, writer: W) -> IoResult<()> {
self.0.write(writer)
Expand Down
2 changes: 1 addition & 1 deletion arkworks/crypto-primitives/src/crh/pedersen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl<C: ProjectiveCurve, W: Window> CRH<C, W> {

pub fn generator_powers<R: Rng>(num_powers: usize, rng: &mut R) -> Vec<C> {
let mut cur_gen_powers = Vec::with_capacity(num_powers);
let mut base = C::rand(rng);
let mut base = C::pub_rand(rng);
for _ in 0..num_powers {
cur_gen_powers.push(base);
base.double_in_place();
Expand Down
13 changes: 11 additions & 2 deletions arkworks/marlin/src/ahp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,12 @@ impl<F: PrimeField> AHPForR1CS<F> {
(-beta * g_1_at_beta, LCTerm::One),
],
);
debug_assert!(evals.get_lc_eval(&outer_sumcheck, beta)?.is_zero());
#[cfg(debug_assertions)]
{
let mut e = evals.get_lc_eval(&outer_sumcheck, beta)?;
e.publicize();
debug_assert!(e.is_zero(), "Evaluation of lc is\n{}\n, not zero", e);
}

linear_combinations.push(z_b);
linear_combinations.push(g_1);
Expand Down Expand Up @@ -244,7 +249,11 @@ impl<F: PrimeField> AHPForR1CS<F> {

a.label = "inner_sumcheck".into();
let inner_sumcheck = a;
debug_assert!(evals.get_lc_eval(&inner_sumcheck, gamma)?.is_zero());
debug_assert!({
let mut e = evals.get_lc_eval(&inner_sumcheck, gamma)?;
e.publicize();
e.is_zero()
});

linear_combinations.push(g_2);
linear_combinations.push(a_denom);
Expand Down
4 changes: 3 additions & 1 deletion inputs/inputs.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{
"x": 4
"x": 4,
"y": 5,
"z": 6
}
8 changes: 7 additions & 1 deletion mpc-algebra/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ ark-ff = { path = "../arkworks/algebra/ff", version = "0.3.0" }
ark-poly = { path = "../arkworks/algebra/poly", version = "0.3.0" }
ark-serialize = { path = "../arkworks/algebra/serialize", version = "0.3.0" }
ark-std = { path = "../arkworks/std", version = "0.3.0", features = ["std", "print-trace"] }
ark-r1cs-std = { path = "../arkworks/r1cs-std", version = "0.3.0", default-features = false, optional = true }
ark-crypto-primitives = { path = "../arkworks/crypto-primitives", version = "0.3.0" }

ark-bls12-377 = { path = "../arkworks/curves/bls12_377", version = "0.3.0" }
ark-ed-on-bls12-377 = { path = "../arkworks/curves/ed_on_bls12_377", version = "0.3.0" }

rand = "0.8.5"
num-bigint = { version = "0.4.3", features = ["rand"] }
Expand All @@ -24,4 +27,7 @@ mpc-net = { path = "../mpc-net" }
mpc-trait = { path = "../mpc-trait" }

structopt = "0.3"
env_logger = "0.8"
env_logger = "0.8"

[features]
default = ["ark-r1cs-std"]
2 changes: 2 additions & 0 deletions mpc-algebra/src/share.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ pub mod field;
pub use field::*;
pub mod group;
pub use group::*;
pub mod msm;
pub use msm::*;
pub mod pairing;
pub use pairing::*;

Expand Down
Loading

0 comments on commit e505e67

Please sign in to comment.