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

Trusted Setup Client v2 #268

Merged
merged 13 commits into from
Oct 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ concurrency:
cancel-in-progress: true
env:
CARGO_TERM_COLOR: always
RUSTFLAGS: -D warnings
RUSTFLAGS: -D warnings -A unknown-lints
RUST_BACKTRACE: full
jobs:
format:
Expand Down
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/),
- [\#267](https://github.com/Manta-Network/manta-rs/pull/267) Add trusted setup client downloader

### Changed
- [\#268](https://github.com/Manta-Network/manta-rs/pull/268) Trusted Setup Client v2

### Deprecated

Expand Down
4 changes: 3 additions & 1 deletion manta-accounting/src/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
//! [`Asset`] with a particular [`AssetId`] we use [`AssetMetadata`] to assign a symbol and decimals
//! for human-readable display purposes.

#![allow(clippy::uninlined_format_args)] // NOTE: Clippy false positive https://github.com/rust-lang/rust-clippy/issues/9715 on Display implementation on Asset below

use alloc::{
collections::btree_map::{BTreeMap, Entry as BTreeMapEntry},
format,
Expand Down Expand Up @@ -1166,7 +1168,7 @@ impl AssetMetadata {
let value_base_units = value.0 / (10u128.pow(self.decimals));
let fractional_digits = value.0 / (10u128.pow(self.decimals - FRACTIONAL_DIGITS))
% (10u128.pow(FRACTIONAL_DIGITS));
format!("{}.{:0>3}", value_base_units, fractional_digits)
format!("{value_base_units}.{fractional_digits:0>3}")
}

/// Returns a string formatting of `value` interpreted using `self` as the metadata including
Expand Down
4 changes: 2 additions & 2 deletions manta-accounting/src/fs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,8 @@ pub mod cocoon {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Self::IoError(err) => write!(f, "File I/O Error: {}", err),
Self::Cocoon(err) => write!(f, "Cocoon Error: {:?}", err),
Self::IoError(err) => write!(f, "File I/O Error: {err}"),
Self::Cocoon(err) => write!(f, "Cocoon Error: {err:?}"),
}
}
}
Expand Down
26 changes: 13 additions & 13 deletions manta-accounting/src/fs/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ pub mod ser {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Self::UnsupportedFeature(feature) => write!(f, "Unsupported Feature: {}", feature),
Self::Serialization(msg) => write!(f, "Serialization Error: {}", msg),
Self::Io(err) => write!(f, "File I/O Error: {}", err),
Self::UnsupportedFeature(feature) => write!(f, "Unsupported Feature: {feature}"),
Self::Serialization(msg) => write!(f, "Serialization Error: {msg}"),
Self::Io(err) => write!(f, "File I/O Error: {err}"),
}
}
}
Expand All @@ -109,7 +109,7 @@ pub mod ser {
where
T: Display,
{
Self::Serialization(format!("{}", msg))
Self::Serialization(format!("{msg}"))
}
}
}
Expand Down Expand Up @@ -717,15 +717,15 @@ pub mod de {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Self::Io(err) => write!(f, "File I/O Error: {}", err),
Self::Io(err) => write!(f, "File I/O Error: {err}"),
Self::MissingBytes => write!(f, "Missing Bytes"),
Self::UnsupportedFeature(feature) => write!(f, "Unsupported Feature: {}", feature),
Self::InvalidBoolTag(tag) => write!(f, "Invalid Bool Tag: {}", tag),
Self::InvalidOptionTag(tag) => write!(f, "Invalid Option Tag: {}", tag),
Self::InvalidCharacter(integer) => write!(f, "Invalid Character: {}", integer),
Self::LargeLengthTag(len) => write!(f, "Large Length Tag: {}", len),
Self::FromUtf8Error(err) => write!(f, "From UTF-8 Error: {}", err),
Self::Deserialization(msg) => write!(f, "Deserialization Error: {}", msg),
Self::UnsupportedFeature(feature) => write!(f, "Unsupported Feature: {feature}"),
Self::InvalidBoolTag(tag) => write!(f, "Invalid Bool Tag: {tag}"),
Self::InvalidOptionTag(tag) => write!(f, "Invalid Option Tag: {tag}"),
Self::InvalidCharacter(integer) => write!(f, "Invalid Character: {integer}"),
Self::LargeLengthTag(len) => write!(f, "Large Length Tag: {len}"),
Self::FromUtf8Error(err) => write!(f, "From UTF-8 Error: {err}"),
Self::Deserialization(msg) => write!(f, "Deserialization Error: {msg}"),
}
}
}
Expand All @@ -747,7 +747,7 @@ pub mod de {
where
T: Display,
{
Self::Deserialization(format!("{}", msg))
Self::Deserialization(format!("{msg}"))
}
}

Expand Down
2 changes: 1 addition & 1 deletion manta-crypto/src/accumulator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ pub mod test {
.collect::<Vec<_>>();
for (i, x) in outputs.iter().enumerate() {
for (j, y) in outputs.iter().enumerate().skip(i + 1) {
assert_ne!(x, y, "Found matching outputs at {:?} and {:?}.", i, j)
assert_ne!(x, y, "Found matching outputs at {i:?} and {j:?}.")
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion manta-crypto/src/constraint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ pub mod measure {
let before = self.base.measure();
let value = f(self.base);
self.measurements.push((
format!("{}", label),
format!("{label}"),
self.base
.measure()
.checked_sub(before)
Expand Down
4 changes: 2 additions & 2 deletions manta-parameters/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,14 +386,14 @@ mod test {
fn download_all_data() -> Result<()> {
let current_branch = get_current_branch()?;
let directory = tempfile::tempdir()?;
println!("[INFO] Temporary Directory: {:?}", directory);
println!("[INFO] Temporary Directory: {directory:?}");
let checksums = parse_checkfile("data.checkfile")?;
let directory_path = directory.path();
for file in walkdir::WalkDir::new("data") {
let file = file?;
let path = file.path();
if !path.is_dir() {
println!("[INFO] Checking path: {:?}", path);
println!("[INFO] Checking path: {path:?}");
let target = directory_path.join(path);
fs::create_dir_all(target.parent().unwrap())?;
github::download(
Expand Down
2 changes: 1 addition & 1 deletion manta-pay/src/bin/simulation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub fn main() {
Err(err) => Simulation::command()
.error(
ErrorKind::Io,
format_args!("Unable to start `tokio` runtime: {}", err),
format_args!("Unable to start `tokio` runtime: {err}"),
)
.exit(),
}
Expand Down
1 change: 1 addition & 0 deletions manta-pay/src/crypto/poseidon/round_constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ mod test {
use crate::crypto::constraint::arkworks::Fp;
use manta_crypto::arkworks::{bls12_381::Fr, ff::field_new};

#[allow(clippy::needless_borrow)] // NOTE: Clippy false positive https://github.com/rust-lang/rust-clippy/issues/9710
/// Checks if [`GrainLFSR`] matches hardcoded sage outputs.
#[test]
fn grain_lfsr_is_consistent() {
Expand Down
2 changes: 1 addition & 1 deletion manta-pay/src/simulation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ impl Simulation {
assert!(
self.config()
.run(ledger, signer, ChaCha20Rng::from_entropy, |event| {
let event = format!("{:?}\n", event);
let event = format!("{event:?}\n");
async move {
let _ = write_stdout(event.as_bytes()).await;
}
Expand Down
1 change: 1 addition & 0 deletions manta-trusted-setup/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
data
4 changes: 3 additions & 1 deletion manta-trusted-setup/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ cargo run --release --package manta-trusted-setup --all-features --bin groth16_p
```
You will see a screen like this ![register](./docs/ts_guide_register.png)

Enter the required information (Twitter handle and email address) and copy these together with the public key and signature generated by the client into the appropriate fields of [this form](https://4z64on4g0gg.typeform.com/to/N7afxPaU). DO NOT include the secret passphrase displayed in red. Save this secret phrase somewhere safe and do not share it with anyone. Without this secret you will not be able to participate in the ceremony. You are now registered; please wait until the ceremony begins to proceed to the next step. You will be notified by email when the ceremony is about to begin.
The output contains a link (green) that leads you to our registration form. Here you may answer some optional questions, then submit the form to complete your registration.

Take note of the secret passphrase displayed in red. Save this secret phrase somewhere safe and do not share it with anyone. Without this secret you will not be able to participate in the ceremony. You are now registered; please wait until the ceremony begins to proceed to the next step. You will be notified by email when the ceremony is about to begin.

> **NOTE**: There may be some lag between when you submit your registration info and when it has been uploaded to the server -- we perform some manual screening to prevent abuse.

Expand Down
Binary file modified manta-trusted-setup/docs/ts_guide_register.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions manta-trusted-setup/src/bin/groth16_phase2_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl Arguments {
/// Takes command line arguments and executes the corresponding operations.
#[inline]
pub fn run(self) -> Result<(), CeremonyError<Config>> {
println!("{}", TITLE);
println!("{TITLE}");
match self.command {
Command::Register => {
let twitter_account = Input::with_theme(&ColorfulTheme::default())
Expand All @@ -84,7 +84,7 @@ impl Arguments {
Command::Contribute => {
let (sk, pk) = match get_client_keys() {
Ok(keys) => keys,
Err(e) => panic!("Error while extracting the client keys: {}", e),
Err(e) => panic!("Error while extracting the client keys: {e}"),
};
match tokio::runtime::Builder::new_multi_thread()
.worker_threads(4)
Expand All @@ -97,7 +97,7 @@ impl Arguments {
runtime
.block_on(async { client_contribute::<Config>(sk, pk, self.url).await })
}
Err(e) => panic!("I/O Error while setting up the tokio Runtime: {:?}", e),
Err(e) => panic!("I/O Error while setting up the tokio Runtime: {e:?}"),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion manta-trusted-setup/src/groth16/ceremony/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ where
CeremonyError::Timeout
} else {
CeremonyError::Network {
message: format!("{}", err),
message: format!("{err}"),
}
}
}
Expand Down
45 changes: 19 additions & 26 deletions manta-trusted-setup/src/groth16/ceremony/config/ppot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,24 +306,9 @@ pub fn generate_keys(bytes: &[u8]) -> Option<(ed25519::SecretKey, ed25519::Publi
/// Registers a participant.
#[inline]
pub fn register(twitter_account: String, email: String) {
println!(
"Your {}: \nCopy the following text to the \"Twitter\" Section in Registration Form:\n {}\n",
"Twitter Account".italic(),
twitter_account.green(),
);
println!(
"Your {}: \nCopy the following text to the \"Email\" Section in Registration Form:\n {}\n",
"Email".italic(),
email.green(),
);
let mnemonic = Mnemonic::new(MnemonicType::Words12, Language::English);
let seed = Seed::new(&mnemonic, "manta-trusted-setup");
let keypair = generate_keys(seed.as_bytes()).expect("Should generate a key pair.");
println!(
"Your {}: \nCopy the following text to the \"Public Key\" Section in Registration Form:\n {}\n",
"Public Key".italic(),
bs58::encode(keypair.1).into_string().green(),
);
let signature = sign::<Ed25519<RawMessage<u64>>, _>(
&keypair.0,
Default::default(),
Expand All @@ -333,18 +318,26 @@ pub fn register(twitter_account: String, email: String) {
),
)
.expect("Signing message should succeed.");
println!(
"Your {}: \nCopy the following text to the \"Signature\" Section in Registration Form: \n {}\n",
"Signature".italic(),
bs58::encode(signature).into_string().green()
);
println!(
"Your {}: \nThe following text stores your secret for the trusted setup. \
Save the following text somewhere safe. \n DO NOT share this with anyone else! \
Please discard this data after the trusted setup ceremony.\n {}",
Please discard this data after the trusted setup ceremony.\n {} \n",
"Secret".italic(),
mnemonic.phrase().red().bold(),
);

println!("Your registration is not complete until you submit the following form: \nCopy this link to your browser and complete registration there \n \n{}\nBe sure to copy this link exactly! Do not leave out any characters!", register_link(twitter_account, email, bs58::encode(keypair.1).into_string(), bs58::encode(signature).into_string()).green());
}

/// Generates link to registration form with Twitter, Email, Public Key,
/// Signature fields pre-filled.
pub fn register_link(
twitter: String,
email: String,
public_key: String,
signature: String,
) -> String {
format!("https://mantanetwork.typeform.com/trustedsetup2#twitter={twitter}&email={email}&verifying_key={public_key}&signature={signature} \n")
}

/// Prompts the client information and get client keys.
Expand Down Expand Up @@ -457,7 +450,7 @@ where
Estimated Waiting Time: {}.",
style("[1/6]").bold(),
style(position).bold().red(),
style(format!("{:?} min", minutes)).bold().red(),
style(format!("{minutes:?} min")).bold().red(),
);
} else {
println!(
Expand Down Expand Up @@ -499,8 +492,8 @@ where
let contribution_hash = hex::encode(C::contribution_hash(&response));
let tweet = style(format!(
"I made contribution number {} to the #MantaNetworkTrustedSetup! \
My contribution's hash is {}",
response.index, contribution_hash
My contribution's hash is {contribution_hash}",
response.index
))
.bold()
.blue();
Expand Down Expand Up @@ -735,7 +728,7 @@ impl Circuits<Self> for Config {
for i in 0..3 {
let mut cs = R1CS::for_contexts();
dummy_circuit(&mut cs);
circuits.push((cs, format!("{}_{}", "dummy", i)));
circuits.push((cs, format!("dummy_{i}")));
}
circuits
}
Expand All @@ -759,7 +752,7 @@ where
E: Display,
{
if let Err(e) = result {
println!("{} {}", style("[ERROR]").bold().red(), e);
println!("{} {e}", style("[ERROR]").bold().red());
}
}

Expand Down
6 changes: 3 additions & 3 deletions manta-trusted-setup/src/groth16/ceremony/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ where
match self {
Self::NotRegistered => write!(
f,
"Registry update is taking longer than expected. \
Please make sure you have submitted your registration form and try again later.",
"Please make sure you have submitted your registration form. \
Check whether the ceremony has begun at https://ceremony.manta.network.",
GhostOfGauss marked this conversation as resolved.
Show resolved Hide resolved
),
Self::AlreadyContributed => {
write!(
Expand All @@ -209,7 +209,7 @@ where
"Unable to connect to the ceremony server: timeout. Please try again later.",
),
Self::Network { message } => {
write!(f, "Unable to connect to the ceremony server: {}", message)
write!(f, "Unable to connect to the ceremony server: {message}")
}
err => write!(
f,
Expand Down
8 changes: 4 additions & 4 deletions manta-trusted-setup/src/groth16/ppot/serialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,7 @@ mod tests {
match <PpotCeremony as Deserializer<G1Affine, G1>>::deserialize_compressed(&mut temp) {
Ok(point) => g1_deser.push(point),
Err(e) => {
println!("Error {:?} occurred on point {:?}", e, i);
println!("Error {e:?} occurred on point {i:?}");
}
}
}
Expand Down Expand Up @@ -844,7 +844,7 @@ mod tests {
{
Ok(point) => g1_deser.push(point),
Err(e) => {
println!("Error {:?} occurred on point {:?}", e, i);
println!("Error {e:?} occurred on point {i:?}");
}
}
}
Expand Down Expand Up @@ -873,7 +873,7 @@ mod tests {
match <PpotCeremony as Deserializer<G2Affine, G2>>::deserialize_compressed(&mut temp) {
Ok(point) => g2_deser.push(point),
Err(e) => {
println!("Error {:?} occurred on point {:?}", e, i);
println!("Error {e:?} occurred on point {i:?}");
}
}
}
Expand Down Expand Up @@ -903,7 +903,7 @@ mod tests {
{
Ok(point) => g2_deser.push(point),
Err(e) => {
println!("Error {:?} occurred on point {:?}", e, i);
println!("Error {e:?} occurred on point {i:?}");
}
}
}
Expand Down