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: Trusted Setup Ceremony Primitives #238

Merged
merged 64 commits into from
Sep 23, 2022
Merged
Show file tree
Hide file tree
Changes from 61 commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
5ec16fa
wip: trusted setup client and server
tsunrise Aug 30, 2022
41eff54
wip: server and message
tsunrise Aug 31, 2022
e1b15a0
Merge branch 'main' into feat/ts_ceremony
tsunrise Sep 4, 2022
cc1c2b8
wip: save point
tsunrise Sep 4, 2022
9945ff0
wip: fix compilation issues
Sep 6, 2022
5ad55c7
wip: serde
Sep 7, 2022
7fdc20c
feat: serde
Sep 7, 2022
6976813
chore: fix comments
Sep 7, 2022
aacf8fe
feat: server
Sep 8, 2022
320731c
wip: server
Sep 8, 2022
a1bb0d5
Merge branch 'main' into feat/ts_ceremony
bhgomes Sep 8, 2022
bd95e32
wip: server checkpoint
Sep 8, 2022
6dacc1b
feat: serde
Sep 9, 2022
f61a089
wip: fix comments
Sep 9, 2022
9507913
feat: fix comments
Sep 9, 2022
4698fde
chore: fix comments
Sep 9, 2022
5a3b51e
feat: finish server
Sep 9, 2022
ff3a8de
Merge branch 'main' into feat/ts_ceremony
bhgomes Sep 9, 2022
c1b0b8b
wip: client
Sep 9, 2022
8de6be7
fix: clean up interfaces and add abstract priority
bhgomes Sep 9, 2022
40a6be4
feat: use macro for dalek byte conversions
bhgomes Sep 9, 2022
7fa08c4
wip: client
Sep 9, 2022
ec8712c
chore: clean up ceremony size
bhgomes Sep 9, 2022
e0c726f
Merge branch 'feat/ts_ceremony' of https://github.com/Manta-Network/m…
bhgomes Sep 9, 2022
e10d914
wip: client
Sep 9, 2022
178032b
feat: client
Sep 10, 2022
c573a4c
chore: fix clippy errors
bhgomes Sep 10, 2022
42fe5a3
chore: fix docs
bhgomes Sep 10, 2022
3ba388c
chore: move AsBytes into macro
bhgomes Sep 10, 2022
f1b1830
chore: fix issues
Sep 10, 2022
3bb877c
chore: fix issues
Sep 10, 2022
6db0b03
chore: changelog
Sep 10, 2022
6f8fd41
chore: fix a typo
Sep 10, 2022
f26b978
chore: fix ci issue
Sep 10, 2022
023aff3
chore: fix a ci issue
Sep 10, 2022
b388f22
chore: typo
Sep 10, 2022
e3f020c
chore: clean up signature abstraction layers
bhgomes Sep 11, 2022
0b4fda7
chore: start restructuring signature/message schemes
bhgomes Sep 11, 2022
baa2f73
wip: commit save point
bhgomes Sep 11, 2022
b6db0f3
chore: fix abstraction layers
bhgomes Sep 12, 2022
87ddc1e
fix: remove extra gitignore
bhgomes Sep 12, 2022
13406b6
wip: commit save point
bhgomes Sep 13, 2022
ff3a1f3
wip: save point
Sep 13, 2022
d049730
feat: priority, participant, record for ppot
Sep 13, 2022
2e9281d
chore: nit
Sep 13, 2022
cadfd61
chore: fix client
Sep 14, 2022
bd612d9
chore: fix `generate_keys`
Sep 14, 2022
81778b4
fix: ci
Sep 15, 2022
db8b9ce
wip: commit save point
bhgomes Sep 17, 2022
c8efda8
wip: commit save point
bhgomes Sep 18, 2022
da3effc
wip: commit save point
bhgomes Sep 19, 2022
5de8d41
wip: commit save point
bhgomes Sep 19, 2022
bc81d08
wip: commit save point
bhgomes Sep 19, 2022
8d83915
wip: commit save point
bhgomes Sep 20, 2022
feeea85
wip: commit save point
bhgomes Sep 20, 2022
c42bb86
wip: commit save point
bhgomes Sep 20, 2022
b69677b
wip: commit save point
bhgomes Sep 20, 2022
c8a59e9
wip: commit save point
bhgomes Sep 20, 2022
ecb58f0
wip: commit save point
bhgomes Sep 20, 2022
5d4dd28
chore: finalize APIs
bhgomes Sep 20, 2022
2e22efe
fix: address some review comments
bhgomes Sep 20, 2022
55df7f3
Apply suggestions from code review
bhgomes Sep 22, 2022
576e45d
fix: address comments
bhgomes Sep 22, 2022
e448a1d
chore: update workspace
bhgomes Sep 22, 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
7 changes: 4 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## [Unreleased]
### Added
- [\#238](https://github.com/Manta-Network/manta-rs/pull/238) Add trusted setup ceremony primitives for server and client
- [\#237](https://github.com/Manta-Network/manta-rs/pull/237) Public input fuzzing tests for transfer protocol
- [\#215](https://github.com/Manta-Network/manta-rs/pull/215) Add windowed multiplication algorithm for groups
- [\#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
- [\#196](https://github.com/Manta-Network/manta-rs/pull/172) Add fixed base scalar multiplication using precomputed bases
- [\#193](https://github.com/Manta-Network/manta-rs/pull/193) Add Bn254 curve backend for Groth16 trusted setup
- [\#172](https://github.com/Manta-Network/manta-rs/pull/172) Add abstract Phase 2 for Groth16 trusted setup

### Changed
- [\#247](https://github.com/Manta-Network/manta-rs/pull/247) Moved BLS12-381 and BN254 curves (and Edwards counterparts) to `manta-crypto`
Expand Down
6 changes: 2 additions & 4 deletions manta-benchmark/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,13 @@ name = "reclaim"
harness = false

[dependencies]
ark-ec = { version = "0.3.0", default-features = false }
ark-ff = { version = "0.3.0", default-features = false }
getrandom = { version = "0.2.6", default-features = false, features = ["js"] }
instant = { version = "0.1.12", default-features = false, features = [ "wasm-bindgen" ] }
manta-accounting = { path = "../manta-accounting", default-features = false, features = ["test"] }
manta-crypto = { path = "../manta-crypto", default-features = false, features = ["ark-bls12-381", "getrandom", "test"] }
manta-pay = { path = "../manta-pay", default-features = false, features = ["groth16", "test"] }
wasm-bindgen = { version = "0.2.82", default-features = false }
wasm-bindgen-test = { version = "0.3.30", default-features = false }
wasm-bindgen = { version = "0.2.83", default-features = false }
wasm-bindgen-test = { version = "0.3.33", default-features = false }
web-sys = { version = "0.3.59", default-features = false, features = ["console"] }

[dev-dependencies]
Expand Down
10 changes: 7 additions & 3 deletions manta-benchmark/src/ecc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@

//! Elliptic Curve Cryptography Utilities

use ark_ec::{AffineCurve, ProjectiveCurve};
use ark_ff::UniformRand;
use core::ops::AddAssign;
use manta_crypto::rand::RngCore;
use manta_crypto::{
arkworks::{
ec::{AffineCurve, ProjectiveCurve},
ff::UniformRand,
},
rand::RngCore,
};

/// Samples an affine point.
#[inline]
Expand Down
3 changes: 2 additions & 1 deletion manta-crypto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ getrandom = ["rand_core/getrandom"]

# Serde Serialization
serde = [
"ed25519-dalek?/serde",
"manta-util/serde-alloc",
"manta-util/serde-array",
"rand_chacha?/serde1"
"rand_chacha?/serde1",
]

# Standard Library
Expand Down
2 changes: 1 addition & 1 deletion manta-crypto/src/arkworks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
pub use ark_ec as ec;
pub use ark_r1cs_std as r1cs_std;
pub use ark_relations as relations;
pub use ark_serialize as serialize;

#[cfg(feature = "ark-bls12-381")]
pub use ark_bls12_381 as bls12_381;
Expand All @@ -39,3 +38,4 @@ pub mod ff;
pub mod pairing;
pub mod rand;
pub mod ratio;
pub mod serialize;
54 changes: 54 additions & 0 deletions manta-crypto/src/arkworks/serialize.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright 2019-2022 Manta Network.
// This file is part of manta-rs.
//
// manta-rs is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// manta-rs is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with manta-rs. If not, see <http://www.gnu.org/licenses/>.

//! Arkworks Canonical Serialize and Deserialize Backend

#[cfg(feature = "serde")]
use {
alloc::vec::Vec,
manta_util::serde::{de, ser, Deserialize, Deserializer, Serialize, Serializer},
};

#[doc(inline)]
pub use ark_serialize::*;

/// Serializes `data` using the [`CanonicalSerialize`] format with `S` as the [`Serializer`].
#[cfg(feature = "serde")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "serde")))]
#[inline]
bhgomes marked this conversation as resolved.
Show resolved Hide resolved
pub fn canonical_serialize<T, S>(data: &T, serializer: S) -> Result<S::Ok, S::Error>
where
T: CanonicalSerialize,
S: Serializer,
{
let mut bytes = Vec::new();
data.serialize(&mut bytes).map_err(ser::Error::custom)?;
Serialize::serialize(&bytes, serializer)
}

/// Deserializes data of type `T` using the [`CanonicalDeserialize`] format with `D` as the
/// [`Deserializer`].
#[cfg(feature = "serde")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "serde")))]
#[inline]
pub fn canonical_deserialize<'de, D, T>(deserializer: D) -> Result<T, D::Error>
bhgomes marked this conversation as resolved.
Show resolved Hide resolved
where
D: Deserializer<'de>,
T: CanonicalDeserialize,
{
let bytes: Vec<u8> = Deserialize::deserialize(deserializer)?;
CanonicalDeserialize::deserialize(bytes.as_slice()).map_err(de::Error::custom)
}
41 changes: 31 additions & 10 deletions manta-crypto/src/dalek/ed25519.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with manta-rs. If not, see <http://www.gnu.org/licenses/>.

//! Dalek Cryptography `ed25519` Backend
//! Dalek Cryptography [`ed25519`](ed25519_dalek) Backend

use crate::{
rand::{CryptoRng, Rand, RngCore},
Expand All @@ -27,17 +27,36 @@ use manta_util::AsBytes;

pub use ed25519_dalek::*;

/// Converts `bytes` into a [`SecretKey`].
#[inline]
pub fn secret_key_from_bytes(bytes: [u8; SECRET_KEY_LENGTH]) -> SecretKey {
match SecretKey::from_bytes(&bytes) {
Ok(secret_key) => secret_key,
_ => {
unreachable!("We are guaranteed the correct number of bytes from `SECRET_KEY_LENGTH`.")
/// Implements byte conversion from an array of bytes of length `$len` into the given `$type`. These
/// implementations are prefered over the ones provided by [`ed25519_dalek`] because they have no
/// error branch.
macro_rules! byte_conversion {
($name:ident, $type:tt, $len:ident) => {
#[doc = "Converts the `bytes` fixed-length array into [`"]
#[doc = stringify!($type)]
#[doc = "`]."]
///
/// # Note
///
/// We don't need to return an error here because `bytes` already has the correct length.
#[inline]
pub fn $name(bytes: [u8; $len]) -> $type {
match $type::from_bytes(&bytes) {
Ok(value) => value,
_ => unreachable!(concat!(
"We are guaranteed the correct number of bytes from `",
stringify!($len),
"`."
)),
}
}
}
};
}

byte_conversion!(secret_key_from_bytes, SecretKey, SECRET_KEY_LENGTH);
byte_conversion!(public_key_from_bytes, PublicKey, PUBLIC_KEY_LENGTH);
byte_conversion!(signature_from_bytes, Signature, SIGNATURE_LENGTH);
bhgomes marked this conversation as resolved.
Show resolved Hide resolved

/// Clones the `secret_key` by serializing and then deserializing.
#[inline]
pub fn clone_secret_key(secret_key: &SecretKey) -> SecretKey {
Expand Down Expand Up @@ -85,7 +104,9 @@ impl<M> MessageType for Ed25519<M> {
}

impl<M> RandomnessType for Ed25519<M> {
/// The `ed25519_dalek` crate provides randomness internally so we set it as `()` here.
/// Empty Randomness
///
/// The [`ed25519_dalek`] crate provides randomness internally so we set it as `()` here.
type Randomness = ();
}

Expand Down
4 changes: 2 additions & 2 deletions manta-parameters/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ download = ["anyhow", "attohttpc", "std"]
std = ["anyhow?/std"]

[dependencies]
anyhow = { version = "1.0.64", optional = true, default-features = false }
anyhow = { version = "1.0.65", optional = true, default-features = false }
attohttpc = { version = "0.22.0", optional = true }
blake3 = { version = "1.3.1", default-features = false }

Expand All @@ -44,7 +44,7 @@ tempfile = { version = "3.3.0", default-features = false }
walkdir = { version = "2.3.2", default-features = false }

[build-dependencies]
anyhow = { version = "1.0.64", default-features = false, features = ["std"] }
anyhow = { version = "1.0.65", default-features = false, features = ["std"] }
blake3 = { version = "1.3.1", default-features = false, features = ["std"] }
gitignore = { version = "1.0.7", default-features = false }
hex = { version = "0.4.3", default-features = false, features = ["std"] }
Expand Down
4 changes: 2 additions & 2 deletions manta-pay/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ ark-std = { version = "0.3.0", optional = true, default-features = false }
bip32 = { version = "0.3.0", optional = true, default-features = false, features = ["bip39", "secp256k1"] }
blake2 = { version = "0.10.4", default-features = false }
bs58 = { version = "0.4.0", optional = true, default-features = false, features = ["alloc"] }
clap = { version = "3.2.20", optional = true, default-features = false, features = ["color", "derive", "std", "suggestions", "unicode", "wrap_help"] }
clap = { version = "3.2.22", optional = true, default-features = false, features = ["color", "derive", "std", "suggestions", "unicode", "wrap_help"] }
derivative = { version = "2.2.0", default-features = false, features = ["use_core"] }
futures = { version = "0.3.24", optional = true, default-features = false }
indexmap = { version = "1.9.1", optional = true, default-features = false }
Expand All @@ -119,7 +119,7 @@ scale-codec = { package = "parity-scale-codec", version = "3.1.2", optional = tr
scale-info = { version = "2.1.2", optional = true, default-features = false, features = ["derive"] }
serde_json = { version = "1.0.85", optional = true, default-features = false, features = ["alloc"] }
tempfile = { version = "3.3.0", optional = true, default-features = false }
tokio = { version = "1.21.0", optional = true, default-features = false }
tokio = { version = "1.21.1", optional = true, default-features = false }
tokio-tungstenite = { version = "0.17.2", optional = true, default-features = false, features = ["native-tls"] }
ws_stream_wasm = { version = "0.7.3", optional = true, default-features = false }

Expand Down
18 changes: 16 additions & 2 deletions manta-trusted-setup/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ is-it-maintained-open-issues = { repository = "Manta-Network/manta-rs" }
maintenance = { status = "actively-developed" }

[features]
# Bincode for Message Signing
bincode = ["dep:bincode", "serde"]

# CSV for Ceremony Registries
csv = ["dep:csv", "serde", "std"]

# Perpetual Powers of Tau Ceremony
ppot = ["manta-crypto/ark-bn254"]

Expand All @@ -33,6 +39,7 @@ rayon = ["manta-util/rayon"]

# Serde Serialization
serde = [
"manta-crypto/serde",
"manta-util/serde",
"manta-util/serde-alloc",
"manta-util/serde-array"
Expand All @@ -50,9 +57,16 @@ ark-poly = { 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 }
bs58 = { version = "0.4", default-features = false, features = ["alloc"] }
colored = { version = "2.0.0", default-features = false }
console = { version = "0.15.1", default-features = false }
csv = { version = "1.1.6", optional = true, 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 }
dialoguer = { version = "0.10.2", default-features = false }
manta-crypto = { path = "../manta-crypto", default-features = false, features = ["arkworks", "getrandom", "rand_chacha", "dalek"] }
manta-util = { path = "../manta-util", default-features = false, features = ["reqwest"] }
parking_lot = { version = "0.12.1", default-features = false }
tiny-bip39 = { version = "1.0.0", default-features = false }

[dev-dependencies]
ark-snark = { version = "0.3.0", default-features = false }
Expand Down
25 changes: 25 additions & 0 deletions manta-trusted-setup/src/ceremony/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright 2019-2022 Manta Network.
// This file is part of manta-rs.
//
// manta-rs is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// manta-rs is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with manta-rs. If not, see <http://www.gnu.org/licenses/>.

//! Trusted Setup Ceremonies

pub mod participant;
pub mod registry;
pub mod signature;

#[cfg(all(feature = "bincode", feature = "std"))]
#[cfg_attr(doc_cfg, doc(cfg(all(feature = "bincode", feature = "std"))))]
pub mod util;
59 changes: 59 additions & 0 deletions manta-trusted-setup/src/ceremony/participant.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright 2019-2022 Manta Network.
// This file is part of manta-rs.
//
// manta-rs is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// manta-rs is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with manta-rs. If not, see <http://www.gnu.org/licenses/>.

//! Trusted Setup Ceremony Participants

/// Participant
pub trait Participant {
/// Identifier Type
type Identifier;

/// Verifying Key Type
type VerifyingKey;

/// Nonce Type
type Nonce;

/// Returns the [`Identifier`](Self::Identifier) for `self`.
fn id(&self) -> &Self::Identifier;

/// Returns the [`VerifyingKey`](Self::VerifyingKey) for `self`.
fn verifying_key(&self) -> &Self::VerifyingKey;

/// Checks if the participant has contributed.
fn has_contributed(&self) -> bool;

/// Sets contributed.
fn set_contributed(&mut self);

/// Returns the current nonce for `self`.
fn nonce(&self) -> &Self::Nonce;

/// Increments the current nonce of `self` by one.
fn increment_nonce(&mut self);
}

/// Priority
pub trait Priority {
/// Priority Type
type Priority;

/// Returns the priority level for `self`.
fn priority(&self) -> Self::Priority;

/// Reduces the priority.
fn reduce_priority(&mut self);
}
Loading