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

Bn254 Backend for Perpetual Powers of Tau #193

Merged
merged 82 commits into from
Aug 31, 2022
Merged
Show file tree
Hide file tree
Changes from 76 commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
057cbe6
feat: sized, pairing, config for ppot Bn254
GhostOfGauss Aug 2, 2022
2a45669
wip: deserializing ppot accumulator
GhostOfGauss Aug 2, 2022
044db77
Merge branch 'main' into feat/bn_backend
bhgomes Aug 2, 2022
8a6f820
feat: correct deserialization of g1 points
GhostOfGauss Aug 3, 2022
2b45546
feat: deserialize G2Affine with Mmap
GhostOfGauss Aug 3, 2022
cacb1d9
feat: consistent ratio check on deserialized accumulator
GhostOfGauss Aug 3, 2022
61b0deb
feat: read subaccumulator from file
GhostOfGauss Aug 3, 2022
19cc44a
feat: bn e2e test
GhostOfGauss Aug 3, 2022
6e3017a
wip: test for manta reclaim circuit, not working
GhostOfGauss Aug 4, 2022
f2a6240
wip: change curve to Bn in manta-pay config
GhostOfGauss Aug 4, 2022
60f24e2
feat: bn backend
GhostOfGauss Aug 5, 2022
a2908e7
changelog
GhostOfGauss Aug 5, 2022
7b46a45
change: groth16 test to bn254
GhostOfGauss Aug 5, 2022
d529334
merge main into bn_backend
GhostOfGauss Aug 6, 2022
7afa704
feat: bn end-to-end test
GhostOfGauss Aug 6, 2022
2a40390
add accumulator to manta-parameters
GhostOfGauss Aug 8, 2022
528409c
add accumulator file
GhostOfGauss Aug 8, 2022
6ce1baf
fixing serialization
GhostOfGauss Aug 8, 2022
f536ddd
fmt
GhostOfGauss Aug 8, 2022
d3b2e8d
-m
GhostOfGauss Aug 8, 2022
496ba7c
fix: remove unnec. file
GhostOfGauss Aug 8, 2022
2d7d26b
workspace-hack update
GhostOfGauss Aug 8, 2022
ec90d23
clean up
GhostOfGauss Aug 8, 2022
688d5c5
fix serialization for ppot accumulator
GhostOfGauss Aug 8, 2022
dab15ff
reorganize pk test, fix std issues
GhostOfGauss Aug 9, 2022
404d34b
fmt
GhostOfGauss Aug 9, 2022
0cdedd2
wip: change serialization for ppot
GhostOfGauss Aug 9, 2022
f08f5e9
fix CI lints
GhostOfGauss Aug 9, 2022
647f162
fmt
GhostOfGauss Aug 9, 2022
7cb2c35
fix lints
GhostOfGauss Aug 10, 2022
e1de7bf
fix: remove bls to bn changes from manta-pay config
GhostOfGauss Aug 10, 2022
ccbeb01
remove commented blocks
GhostOfGauss Aug 10, 2022
c59bdda
fmt
GhostOfGauss Aug 10, 2022
ce94d47
fix: remove file read tests
GhostOfGauss Aug 10, 2022
86bfb58
ignore ppot file tests
GhostOfGauss Aug 10, 2022
1129fb1
feat: factor out and document dummy public input constraints
GhostOfGauss Aug 16, 2022
dd3ac63
Update manta-trusted-setup/src/groth16/bn254/manta_pay.rs
GhostOfGauss Aug 17, 2022
6321856
fix: minor review changes
GhostOfGauss Aug 17, 2022
afdf58e
fmt
GhostOfGauss Aug 17, 2022
4e6ec70
fix: remove stray reclaim_pk file
GhostOfGauss Aug 17, 2022
7db4588
fix: ppot accumulator generic over size and serializer
GhostOfGauss Aug 22, 2022
f9ad379
feat: pairing_impl macro
GhostOfGauss Aug 22, 2022
caaab05
fix: ark-serialize import
GhostOfGauss Aug 22, 2022
5cebe5a
Merge branch 'main' into feat/bn_backend
bhgomes Aug 22, 2022
fd68da2
Merge branch 'main' into feat/bn_backend
bhgomes Aug 23, 2022
7262289
fix: restructure directories
bhgomes Aug 23, 2022
0c8136a
chore: nit g2 generation macro
bhgomes Aug 23, 2022
398d8ff
chore: update marker type
bhgomes Aug 23, 2022
e3c4146
fix: clean up implementations
bhgomes Aug 23, 2022
fafb53c
feat: generalize error conversion function
bhgomes Aug 23, 2022
fce64e0
fix: clean up imports
bhgomes Aug 23, 2022
424549d
Update manta-trusted-setup/src/groth16/test/bn254/ppot.rs
GhostOfGauss Aug 23, 2022
5da5ebd
fix formatting and derive for marker structs
GhostOfGauss Aug 23, 2022
ba8e0f6
fix documentation error
GhostOfGauss Aug 23, 2022
74f77e5
fix: remove unused fn
GhostOfGauss Aug 23, 2022
ef6803a
Merge branch 'main' into feat/bn_backend
bhgomes Aug 23, 2022
504e7b1
fix: std to ark-std
GhostOfGauss Aug 23, 2022
cdb7674
Merge branch 'feat/bn_backend' of https://github.com/Manta-Network/ma…
GhostOfGauss Aug 23, 2022
52548c8
fmt
GhostOfGauss Aug 23, 2022
6d0c0db
Merge branch 'main' into feat/bn_backend
bhgomes Aug 23, 2022
59ad6db
fix: use ppot distribution to hash to curve
GhostOfGauss Aug 24, 2022
1d3805f
fix bad macros in test
GhostOfGauss Aug 24, 2022
3bb1787
wip: make bn public
GhostOfGauss Aug 24, 2022
ca2411e
feat: make bn254 public
GhostOfGauss Aug 24, 2022
28483dd
remove old files
GhostOfGauss Aug 24, 2022
9a0a7d5
rename groth16::bn254 to ppot
GhostOfGauss Aug 24, 2022
a741e77
documentation
GhostOfGauss Aug 24, 2022
a50c1bb
fmt
GhostOfGauss Aug 24, 2022
476cade
fix: add ark_bn254 to dev dep.s
GhostOfGauss Aug 26, 2022
ad23497
fix: std dependency in tests
GhostOfGauss Aug 26, 2022
3dbf4b5
fmt
GhostOfGauss Aug 26, 2022
0b7a32a
Merge branch 'main' into feat/bn_backend
bhgomes Aug 29, 2022
e63f941
disable workspace hack
GhostOfGauss Aug 29, 2022
ab58f37
Merge branch 'feat/bn_backend' of https://github.com/Manta-Network/ma…
GhostOfGauss Aug 29, 2022
f915e02
fix: remove byteorder dependency
GhostOfGauss Aug 30, 2022
e44d305
fix merge conflicts
GhostOfGauss Aug 30, 2022
a750eb9
fix: changes to Types trait and std dependency
GhostOfGauss Aug 30, 2022
aa42226
fmt
GhostOfGauss Aug 30, 2022
a4bfa6e
fix: remove rand-chacha dep and other review comments
GhostOfGauss Aug 30, 2022
430ebb1
fix: std dependency
GhostOfGauss Aug 30, 2022
ba9b06c
fix: change mmap to dev dep
GhostOfGauss Aug 30, 2022
de2a029
fix error handling
GhostOfGauss Aug 30, 2022
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- [\#213](https://github.com/Manta-Network/manta-rs/pull/197) Add Ceremony Utilities
- [\#206](https://github.com/Manta-Network/manta-rs/pull/206) Move Poseidon sage script to test the hardcoded round constant values.
- [\#172](https://github.com/Manta-Network/manta-rs/pull/172) Add abstract Phase 2 for Groth16 trusted setup
- [\#193](https://github.com/Manta-Network/manta-rs/pull/193) Add Bn254 curve backend for Groth16 trusted setup
- [\#196](https://github.com/Manta-Network/manta-rs/pull/172) Add fixed base scalar multiplication using precomputed bases
- [\#197](https://github.com/Manta-Network/manta-rs/pull/197) Add ECLAIR utilities for next circuit upgrade

Expand Down
1 change: 1 addition & 0 deletions manta-parameters/data.checkfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ eb5c880bdf3c998a9a081f0259fd536e07f4bb71095bcef5664326bcb1ad6428 data/pay/testn
5719387f9625828f46835a8375656578e028d8fc6da6822b765f47e296c0aaac data/pay/testnet/verifying/mint.dat
29a8229b59490223372c1f2b918f10d806be64ac4ffa5695dbdfe97b4b52e404 data/pay/testnet/verifying/private-transfer.dat
bbe115020d563d63d404437c38741f0d527ab0441b4aaf4de463d9e9452dee09 data/pay/testnet/verifying/reclaim.dat
25d2368d77dc834774504ca9b001fd4b5926c24c51e87f8e208db5fe40040075 data/ppot/round72powers19.lfs
3 changes: 3 additions & 0 deletions manta-parameters/data/ppot/round72powers19.lfs
Git LFS file not shown
9 changes: 9 additions & 0 deletions manta-parameters/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,15 @@ macro_rules! define_lfs {
};
}

/// Perpetual Powers of Tau Accumulators
pub mod ppot {
define_lfs!(
Round72Powers19,
"Accumulator with 1 << 19 powers, Bn",
"/data/ppot/round72powers19",
);
}

/// Concrete Parameters for Manta Pay
pub mod pay {
/// Testnet Data
Expand Down
297 changes: 159 additions & 138 deletions manta-pay/src/crypto/constraint/arkworks/pairing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,162 +16,183 @@

//! Pairing Engine Utilities

/// BLS-12 Utilities
pub mod bls12 {
use crate::crypto::constraint::arkworks::codec::{HasDeserialization, HasSerialization};
use alloc::vec::Vec;
use manta_crypto::arkworks::{
ec::models::bls12::{g2, Bls12Parameters},
ff::Fp2,
serialize::{CanonicalDeserialize, CanonicalSerialize, Read, SerializationError, Write},
};
/// Generates the `G2Prepared` and `G2PreparedRef` structures for serialization compatibility
/// with arkworks canonical serialization.
macro_rules! pairing_impl {
($params:ident) => {
/// Line Evaluation Coefficients
pub type EllCoeff<F> = (F, F, F);

/// G2 Prepared Point
#[derive(derivative::Derivative, CanonicalSerialize, CanonicalDeserialize)]
#[derivative(Clone, Default, Debug, Eq, PartialEq)]
pub struct G2Prepared<P>
where
P: $params,
{
/// Coefficients
pub ell_coeffs: Vec<EllCoeff<Fp2<P::Fp2Params>>>,

/// Line Evaluation Coefficients
pub type EllCoeff<F> = (F, F, F);

/// G2 Prepared Point
#[derive(derivative::Derivative, CanonicalSerialize, CanonicalDeserialize)]
#[derivative(Clone, Default, Debug, Eq, PartialEq)]
pub struct G2Prepared<P>
where
P: Bls12Parameters,
{
/// Coefficients
pub ell_coeffs: Vec<EllCoeff<Fp2<P::Fp2Params>>>,

/// Infinity Flag
pub infinity: bool,
}

impl<P> From<g2::G2Prepared<P>> for G2Prepared<P>
where
P: Bls12Parameters,
{
#[inline]
fn from(point: g2::G2Prepared<P>) -> Self {
Self {
ell_coeffs: point.ell_coeffs,
infinity: point.infinity,
}
/// Infinity Flag
pub infinity: bool,
}
}

impl<P> From<G2Prepared<P>> for g2::G2Prepared<P>
where
P: Bls12Parameters,
{
#[inline]
fn from(point: G2Prepared<P>) -> Self {
Self {
ell_coeffs: point.ell_coeffs,
infinity: point.infinity,

impl<P> From<g2::G2Prepared<P>> for G2Prepared<P>
where
P: $params,
{
#[inline]
fn from(point: g2::G2Prepared<P>) -> Self {
Self {
ell_coeffs: point.ell_coeffs,
infinity: point.infinity,
}
}
}
}

/// G2 Prepared Point Reference
#[derive(derivative::Derivative)]
#[derivative(Debug, Eq, PartialEq)]
pub struct G2PreparedRef<'p, P>(pub &'p g2::G2Prepared<P>)
where
P: Bls12Parameters;

impl<'p, P> CanonicalSerialize for G2PreparedRef<'p, P>
where
P: Bls12Parameters,
{
#[inline]
fn serialize<W>(&self, mut writer: W) -> Result<(), SerializationError>

impl<P> From<G2Prepared<P>> for g2::G2Prepared<P>
where
W: Write,
P: $params,
{
let g2::G2Prepared {
ell_coeffs,
infinity,
} = &self.0;
ell_coeffs.serialize(&mut writer)?;
infinity.serialize(&mut writer)?;
Ok(())
#[inline]
fn from(point: G2Prepared<P>) -> Self {
Self {
ell_coeffs: point.ell_coeffs,
infinity: point.infinity,
}
}
}

#[inline]
fn serialized_size(&self) -> usize {
let g2::G2Prepared {
ell_coeffs,
infinity,
} = &self.0;
ell_coeffs.serialized_size() + infinity.serialized_size()
}
/// G2 Prepared Point Reference
#[derive(derivative::Derivative)]
#[derivative(Debug, Eq, PartialEq)]
pub struct G2PreparedRef<'p, P>(pub &'p g2::G2Prepared<P>)
where
P: $params;

#[inline]
fn serialize_uncompressed<W>(&self, mut writer: W) -> Result<(), SerializationError>
impl<'p, P> CanonicalSerialize for G2PreparedRef<'p, P>
where
W: Write,
P: $params,
{
let g2::G2Prepared {
ell_coeffs,
infinity,
} = &self.0;
ell_coeffs.serialize_uncompressed(&mut writer)?;
infinity.serialize_uncompressed(&mut writer)?;
Ok(())
#[inline]
fn serialize<W>(&self, mut writer: W) -> Result<(), SerializationError>
where
W: Write,
{
let g2::G2Prepared {
ell_coeffs,
infinity,
} = &self.0;
ell_coeffs.serialize(&mut writer)?;
infinity.serialize(&mut writer)?;
Ok(())
}

#[inline]
fn serialized_size(&self) -> usize {
let g2::G2Prepared {
ell_coeffs,
infinity,
} = &self.0;
ell_coeffs.serialized_size() + infinity.serialized_size()
}

#[inline]
fn serialize_uncompressed<W>(&self, mut writer: W) -> Result<(), SerializationError>
where
W: Write,
{
let g2::G2Prepared {
ell_coeffs,
infinity,
} = &self.0;
ell_coeffs.serialize_uncompressed(&mut writer)?;
infinity.serialize_uncompressed(&mut writer)?;
Ok(())
}

#[inline]
fn serialize_unchecked<W>(&self, mut writer: W) -> Result<(), SerializationError>
where
W: Write,
{
let g2::G2Prepared {
ell_coeffs,
infinity,
} = &self.0;
ell_coeffs.serialize_unchecked(&mut writer)?;
infinity.serialize_unchecked(&mut writer)?;
Ok(())
}

#[inline]
fn uncompressed_size(&self) -> usize {
let g2::G2Prepared {
ell_coeffs,
infinity,
} = &self.0;
ell_coeffs.uncompressed_size() + infinity.uncompressed_size()
}
}

#[inline]
fn serialize_unchecked<W>(&self, mut writer: W) -> Result<(), SerializationError>
impl<'p, P> From<&'p g2::G2Prepared<P>> for G2PreparedRef<'p, P>
where
W: Write,
P: $params,
{
let g2::G2Prepared {
ell_coeffs,
infinity,
} = &self.0;
ell_coeffs.serialize_unchecked(&mut writer)?;
infinity.serialize_unchecked(&mut writer)?;
Ok(())
#[inline]
fn from(point: &'p g2::G2Prepared<P>) -> Self {
Self(point)
}
}

#[inline]
fn uncompressed_size(&self) -> usize {
let g2::G2Prepared {
ell_coeffs,
infinity,
} = &self.0;
ell_coeffs.uncompressed_size() + infinity.uncompressed_size()
impl<'p, P> From<G2PreparedRef<'p, P>> for &'p g2::G2Prepared<P>
where
P: $params,
{
#[inline]
fn from(point: G2PreparedRef<'p, P>) -> Self {
point.0
}
}
}

impl<'p, P> From<&'p g2::G2Prepared<P>> for G2PreparedRef<'p, P>
where
P: Bls12Parameters,
{
#[inline]
fn from(point: &'p g2::G2Prepared<P>) -> Self {
Self(point)

impl<'p, P> HasSerialization<'p> for g2::G2Prepared<P>
where
P: $params,
{
type Serialize = G2PreparedRef<'p, P>;
}
}

impl<'p, P> From<G2PreparedRef<'p, P>> for &'p g2::G2Prepared<P>
where
P: Bls12Parameters,
{
#[inline]
fn from(point: G2PreparedRef<'p, P>) -> Self {
point.0

impl<P> HasDeserialization for g2::G2Prepared<P>
where
P: $params,
{
type Deserialize = G2Prepared<P>;
}
}

impl<'p, P> HasSerialization<'p> for g2::G2Prepared<P>
where
P: Bls12Parameters,
{
type Serialize = G2PreparedRef<'p, P>;
}

impl<P> HasDeserialization for g2::G2Prepared<P>
where
P: Bls12Parameters,
{
type Deserialize = G2Prepared<P>;
}
};
}

/// BLS12 Utilities
pub mod bls12 {
use crate::crypto::constraint::arkworks::codec::{HasDeserialization, HasSerialization};
use alloc::vec::Vec;
use manta_crypto::arkworks::{
ec::models::bls12::{g2, Bls12Parameters},
ff::Fp2,
serialize::{CanonicalDeserialize, CanonicalSerialize, Read, SerializationError, Write},
};

pairing_impl!(Bls12Parameters);
}

/// Bn254 Utilities
pub mod bn254 {
use crate::crypto::constraint::arkworks::codec::{HasDeserialization, HasSerialization};
use alloc::vec::Vec;
use manta_crypto::arkworks::{
ec::models::bn::{g2, BnParameters},
ff::Fp2,
serialize::{CanonicalDeserialize, CanonicalSerialize, Read, SerializationError, Write},
};

pairing_impl!(BnParameters);
}
15 changes: 13 additions & 2 deletions manta-trusted-setup/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ is-it-maintained-open-issues = { repository = "Manta-Network/manta-rs" }
maintenance = { status = "actively-developed" }

[features]
# Perpetual Powers of Tau Ceremony
ppot = ["ark-bn254", "memmap"]

# Rayon Parallelization
rayon = ["manta-util/rayon"]

Expand All @@ -42,18 +45,26 @@ std = ["manta-util/std"]
test = ["manta-crypto/test"]

[dependencies]
ark-bn254 = { version = "0.3.0", optional = true, default-features = false, features = ["curve", "scalar_field"] }
ark-groth16 = { version = "0.3.0", default-features = false }
ark-poly = { version = "0.3.0", default-features = false }
ark-relations = { version = "0.3.0", default-features = false }
ark-std = { version = "0.3.0", default-features = false }
bincode = { version = "1.3.3", optional = true, default-features = false }
blake2 = { version = "0.10.4", default-features = false }
byteorder = { version = "1.4.3", default-features = false }
derivative = { version = "2.2.0", default-features = false, features = ["use_core"] }
manta-crypto = { path = "../manta-crypto", default-features = false, features = ["arkworks", "getrandom", "rand_chacha"] }
manta-util = { path = "../manta-util", default-features = false }
memmap = { version = "0.7.0", optional = true, default-features = false }
GhostOfGauss marked this conversation as resolved.
Show resolved Hide resolved
rand_chacha = { version = "0.3.1", default-features = false }
bhgomes marked this conversation as resolved.
Show resolved Hide resolved

[dev-dependencies]
ark-bls12-381 = { version = "0.3.0", default-features = false, features = ["curve", "scalar_field"] }
ark-bn254 = { version = "0.3.0", default-features = false, features = ["curve", "scalar_field"] }
ark-r1cs-std = { version = "0.3.1", default-features = false }
ark-snark = { version = "0.3.0", default-features = false }
manta-pay = { path = "../manta-pay", default-features = false, features = ["groth16"] } # TODO: To be removed
manta-accounting = { path = "../manta-accounting", default-features = false }
manta-parameters = { path = "../manta-parameters", default-features = false, features = ["download"] }
manta-pay = { path = "../manta-pay", default-features = false, features = ["groth16", "test"] }
manta-trusted-setup = { path = ".", default-features = false, features = ["test"] }
tempfile = { version = "3.3.0", default-features = false }
Loading