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 5 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
4 changes: 2 additions & 2 deletions manta-trusted-setup/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ 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 }
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 }
manta-crypto = { path = "../manta-crypto", default-features = false, features = ["arkworks", "getrandom", "rand_chacha", "dalek"] }
manta-util = { path = "../manta-util", default-features = false, features = ["serde"] }

[dev-dependencies]
ark-bls12-381 = { version = "0.3.0", default-features = false, features = ["curve", "scalar_field"] }
Expand Down
35 changes: 35 additions & 0 deletions manta-trusted-setup/src/groth16/ceremony/client.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// 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 Client

// use crate::groth16::ceremony::{signature::Nonce, Ceremony, Participant};
// use manta_crypto::dalek::ed25519::Ed25519;
//
// /// Client
// pub struct Client<C, const CIRCUIT_COUNT: usize>
// where
// C: Ceremony,
// {
// /// Identifier
// Identifier: C::Identifier,
//
// /// Current Nonce
// nonce: u64,
//
// /// Private Key
// private_key: Ed25519,
// }
60 changes: 29 additions & 31 deletions manta-trusted-setup/src/groth16/ceremony/coordinator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
// You should have received a copy of the GNU General Public License
// along with manta-rs. If not, see <http://www.gnu.org/licenses/>.

//! Groth16 Trusted Setup Ceremony Coordinator
//! Coordinator

use crate::{
groth16::{
ceremony::{registry::Registry, Ceremony, Participant},
ceremony::{registry::Registry, Ceremony, Nonce, Participant},
mpc::StateSize,
},
mpc::{Challenge, Proof, State},
Expand Down Expand Up @@ -47,24 +47,20 @@ pub type Queue<C, const LEVEL_COUNT: usize> =
derive(Deserialize, Serialize),
serde(
bound(
deserialize = r"
R: Deserialize<'de>,
Queue<C, LEVEL_COUNT>: Deserialize<'de>,
C::Identifier: Deserialize<'de>,
State<C>: Deserialize<'de>,
Challenge<C>: Deserialize<'de>,
Proof<C>: Deserialize<'de>,
C::Participant: Deserialize<'de>,
",
serialize = r"
R: Serialize,
Queue<C, LEVEL_COUNT>: Serialize,
C::Identifier: Serialize,
State<C>: Serialize,
Challenge<C>: Serialize,
Proof<C>: Serialize,
C::Participant: Serialize,
"
R: Serialize,
State<C>: Serialize,
Challenge<C>: Serialize,
Proof<C>: Serialize,
C::Participant: Serialize,
",
deserialize = r"
R: Deserialize<'de>,
State<C>: Deserialize<'de>,
Challenge<C>: Deserialize<'de>,
Proof<C>: Deserialize<'de>,
C::Participant: Deserialize<'de>,
"
),
crate = "manta_util::serde",
deny_unknown_fields
Expand All @@ -78,12 +74,6 @@ where
/// Participant Registry
pub registry: R,

/// Participant Queue
pub queue: Queue<C, LEVEL_COUNT>,

/// Participant Lock
pub participant_lock: Timed<Option<C::Identifier>>,

/// State
pub state: StateArray<C, CIRCUIT_COUNT>,

Expand All @@ -103,6 +93,14 @@ where

/// Current Round Number
pub round: usize,

/// Participant Queue
#[serde(skip)]
pub queue: Queue<C, LEVEL_COUNT>,

/// Participant Lock
#[serde(skip)]
pub participant_lock: Timed<Option<C::Identifier>>,
BoyuanFeng marked this conversation as resolved.
Show resolved Hide resolved
}

impl<C, R, const CIRCUIT_COUNT: usize, const LEVEL_COUNT: usize>
Expand All @@ -111,12 +109,6 @@ where
C: Ceremony,
R: Registry<C::Identifier, C::Participant>,
{
/// Returns the current round number.
#[inline]
pub fn round(&self) -> usize {
self.round
}

/// Returns a shared reference to the participant data for `id` from the registry.
#[inline]
pub fn participant(&self, id: &C::Identifier) -> Option<&C::Participant> {
Expand All @@ -141,4 +133,10 @@ where
self.queue
.push_back_at(participant.level(), participant.id().clone());
}

/// Gets nonce of a participant with `id`.
BoyuanFeng marked this conversation as resolved.
Show resolved Hide resolved
#[inline]
pub fn nonce(&self, id: &C::Identifier) -> Option<Nonce<C>> {
Some(self.registry.get(id)?.get_nonce())
}
}
196 changes: 196 additions & 0 deletions manta-trusted-setup/src/groth16/ceremony/message.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
// 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/>.

//! Messages through Network

use crate::{
groth16::{
ceremony::{signature::sign, Ceremony, CeremonyError, Nonce, Proof, Signature, SigningKey},
mpc::{State, StateSize},
},
mpc::Challenge,
};
use manta_crypto::arkworks::serialize::{CanonicalDeserialize, CanonicalSerialize};
use manta_util::{
serde::{Deserialize, Serialize},
Array, BytesRepr,
};

/// MPC States
#[derive(Deserialize, Serialize)]
#[serde(
bound(
serialize = "State<C::Pairing>: CanonicalSerialize, Challenge<C>: CanonicalSerialize",
deserialize = "State<C::Pairing>: CanonicalDeserialize, Challenge<C>: CanonicalDeserialize"
),
crate = "manta_util::serde",
deny_unknown_fields
)]
pub struct MPCState<C, const N: usize>
where
C: Ceremony,
{
/// State
pub state: Array<BytesRepr<State<C::Pairing>>, N>,
BoyuanFeng marked this conversation as resolved.
Show resolved Hide resolved

/// Challenge
pub challenge: Array<BytesRepr<Challenge<C>>, N>,
}

/// Contribute States
#[derive(Deserialize, Serialize)]
#[serde(
bound(
serialize = "State<C::Pairing>: CanonicalSerialize, Proof<C>: CanonicalSerialize",
deserialize = "State<C::Pairing>: CanonicalDeserialize, Proof<C>: CanonicalDeserialize"
),
crate = "manta_util::serde",
deny_unknown_fields
)]
pub struct ContributeState<C, const CIRCUIT_COUNT: usize>
where
C: Ceremony,
{
/// State
pub state: Array<BytesRepr<State<C::Pairing>>, CIRCUIT_COUNT>,

/// Proof
pub proof: Array<BytesRepr<Proof<C>>, CIRCUIT_COUNT>,
}

/// Response for State Sizes
#[derive(Clone, Serialize, Deserialize)]
#[serde(crate = "manta_util::serde", deny_unknown_fields)]
pub struct ServerSize<const CIRCUIT_COUNT: usize>(pub Array<StateSize, CIRCUIT_COUNT>);

impl<const CIRCUIT_COUNT: usize> From<Array<StateSize, CIRCUIT_COUNT>>
for ServerSize<CIRCUIT_COUNT>
{
fn from(inner: Array<StateSize, CIRCUIT_COUNT>) -> Self {
ServerSize(inner)
}
}

/// Query Request
#[derive(Deserialize, Serialize)]
#[serde(crate = "manta_util::serde", deny_unknown_fields)]
pub struct QueryRequest;

/// Response for [`QueryRequest`]
#[derive(Deserialize, Serialize)]
#[serde(
bound(
serialize = "MPCState<C, CIRCUIT_COUNT>: Serialize",
deserialize = "MPCState<C, CIRCUIT_COUNT>: Deserialize<'de>"
),
crate = "manta_util::serde",
deny_unknown_fields
)]
pub enum QueryResponse<C, const CIRCUIT_COUNT: usize>
where
C: Ceremony,
{
/// Queue Position
QueuePosition(usize),

/// MPC State
Mpc(MPCState<C, CIRCUIT_COUNT>),
}

/// Contribute Request
#[derive(Serialize, Deserialize)]
#[serde(
bound(
serialize = "ContributeState<C, CIRCUIT_COUNT>: Serialize",
deserialize = "ContributeState<C, CIRCUIT_COUNT>: Deserialize<'de>"
),
crate = "manta_util::serde",
deny_unknown_fields
)]
pub struct ContributeRequest<C, const CIRCUIT_COUNT: usize>
where
C: Ceremony,
{
/// Contribute state including state and proof
pub contribute_state: ContributeState<C, CIRCUIT_COUNT>,
BoyuanFeng marked this conversation as resolved.
Show resolved Hide resolved
}

/// Signed Message
#[derive(Deserialize, Serialize)]
#[serde(
bound(
serialize = r"
C::Identifier: Serialize,
T: Serialize,
Nonce<C>: Serialize,
Signature<C>: Serialize,
",
deserialize = r"
C::Identifier: Deserialize<'de>,
T: Deserialize<'de>,
Nonce<C>: Deserialize<'de>,
Signature<C>: Deserialize<'de>,
",
),
crate = "manta_util::serde",
deny_unknown_fields
)]
pub struct Signed<T, C>
where
C: Ceremony,
{
/// Message
pub message: T,

/// Nonce
pub nonce: Nonce<C>,

/// Signature
pub signature: Signature<C>,

/// Participant Identifier
pub identifier: C::Identifier,
}

impl<T, C> Signed<T, C>
where
C: Ceremony,
{
/// Generates a signed message with `signing_key` on `message` and `nonce`.
#[inline]
pub fn new(
message: T,
nonce: &Nonce<C>,
signing_key: &SigningKey<C>,
identifier: C::Identifier,
) -> Result<Self, CeremonyError<C>>
where
T: Serialize,
Nonce<C>: Clone,
{
let signature = match sign::<_, C::SignatureScheme>(signing_key, nonce.clone(), &message) {
Ok(signature) => signature,
Err(_) => return Err(CeremonyError::<C>::BadRequest),
BoyuanFeng marked this conversation as resolved.
Show resolved Hide resolved
};
let message = Signed {
message,
nonce: nonce.clone(),
signature,
identifier,
};
Ok(message)
}
}
Loading