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

Feat/#24 calc commitment in mpc #26

Merged
merged 19 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
69ca352
:recycle: Separate pedersen circuit and Create circuits modules
sheagrief Oct 24, 2023
aaa3511
:construction: WIP, Implement Mpc-Edwards-curve(Bls12-377)
sheagrief Oct 24, 2023
7b24ae8
:sparkles: Implement PubUniformRand for Elliptic Curve
sheagrief Oct 24, 2023
8d7de77
:art: Unify local & mpc Pedersen circuit
sheagrief Oct 29, 2023
19c91cb
:test_tube: WIP. Add mpc-commitment test for marlin
sheagrief Oct 29, 2023
504896e
:sparkles: Implement PubUniformRand for PedersenRandomness & MpcGroup
sheagrief Oct 31, 2023
7418db6
:bug: Revise ScalarField of edwards curve
sheagrief Oct 31, 2023
9889517
:construction: WIP: Implement some calc in MpcField & Fix MpcMarlin
sheagrief Oct 31, 2023
b64983c
:sparkles: Implement msm for Mpc
sheagrief Oct 31, 2023
9cebdec
:white_check_mark: Update main function and others for new pedersen
sheagrief Oct 31, 2023
740adae
:bug: Replace Window param in PedersenCommitment
sheagrief Nov 2, 2023
a445f80
:sparkles: Implement todos (publicize, lift to MPC or local)
sheagrief Nov 2, 2023
69fafa6
:white_check_mark: Add additivity test for commitment
sheagrief Nov 2, 2023
068a6d4
:white_check_mark: Update Marlin Pedersen commitmnet test.
sheagrief Nov 2, 2023
a87a070
:sparkles: Implement online circuit. and Pass its marlin public test.
sheagrief Nov 3, 2023
275fc55
:memo: Update usage binary
sheagrief Nov 3, 2023
f5423af
:white_check_mark: Update commitment-related tests
sheagrief Nov 3, 2023
686a2d2
:sparkles: Implement Reveal for commitment & Add test
sheagrief Nov 4, 2023
9d1432a
:sparkles: Implement online phase for marlin
sheagrief Nov 4, 2023
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
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
Loading