Skip to content

Commit

Permalink
Merge pull request #90 from anoma/grarco/io-refactor-rebase-phase2
Browse files Browse the repository at this point in the history
I/O refactor
  • Loading branch information
grarco authored Nov 17, 2022
2 parents 684dc4b + 06a33bd commit be500fc
Show file tree
Hide file tree
Showing 36 changed files with 302 additions and 393 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,15 @@ and input them to:
```
namada-ts verify-contribution $public_key $contribution_hash $contribution_hash_signature
```
### Client Contribution Flow

1. The client will generate a secret mnemonic that derives your key pair. Back up your mnemonic and keep it in a safe place! This is the only way to prove your contribution.

2. Then, you will need to provide the unique token for your cohort you received by email. If the token is valid, you will join the queue of the ceremony. You will need to wait a bit until it is your turn. Each round lasts between 4 min and 20 min. During the whole ceremony, please neither close your terminal, nor your internet connection. If you stay offline for more than 2 min, the coordinator will kick you out from the queue.

3. When it is your turn, the client will download the challenge from the coordinator and save it to the root folder. You have at most 20 minutes to compute your contribution and send it back to the coordinator. Be creative and good luck!
<!-- #### Flowchart
![Alt text](./ceremony-contribution-diagram.png?raw=true "Ceremony Contribution Flow") -->

## Client Contribution Flow

Expand Down
2 changes: 1 addition & 1 deletion install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

set -u

LAST_BINARY_VERSION="1.0.0-beta.10"
LAST_BINARY_VERSION="1.0.0-beta.11"
BINARY_NAME="namada-ts"
BINARY_FOLDER="$HOME/.namada-ts"
BINARY_PATH="$BINARY_FOLDER/$BINARY_NAME"
Expand Down
2 changes: 1 addition & 1 deletion phase2-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ homepage = "https://github.com/AleoHQ/aleo-setup"
license = "MIT/Apache-2.0"
name = "phase2-cli"
repository = "https://github.com/AleoHQ/aleo-setup"
version = "1.0.0-beta.10"
version = "1.0.0-beta.11"

[dependencies]
phase2 = {path = "../phase2"}
Expand Down
26 changes: 13 additions & 13 deletions phase2-cli/src/ascii_logo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ pub const ASCII_LOGO: &str = r"
";

#[rustfmt::skip]
pub const ASCII_CONTRIBUTION_DONE: &str = "
_________________
| |_____ __
| Hello Privacy! | |__| |_________
|_________________| |::| | /
/\\**/\\ | \\._____|::|__| <
( o_o )_ | \\::/ \\.________\\
(u--u \\_) |
(||___ )==\\
,dP\"/b/=( /P\"/b\\
|8 || 8\\=== || 8
pub const ASCII_CONTRIBUTION_DONE: &str = r#"
___________________________
| |____ __
| Hello Interchain Privacy! | |__| |________
|___________________________| |::| | /
/\**/\ | \.____|::|__| <
( o_o )_ | \::/ \______\
(u--u \_) |
(||___ )==\
,dP"/b/=( /P"/b\
|8 || 8\=== || 8
`b, ,P `b, ,P
\"\"\"` \"\"\"`
";
"""` """`
"#;
21 changes: 10 additions & 11 deletions phase2-cli/src/bin/namada-ts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@ use futures_util::StreamExt;
use phase2_cli::{
ascii_logo::{ASCII_CONTRIBUTION_DONE, ASCII_LOGO},
keys::{self, EncryptedKeypair, TomlConfig},
requests,
CeremonyOpt,
CoordinatorUrl,
Token,
VerifySignatureContribution,
requests, CeremonyOpt, CoordinatorUrl, Token, VerifySignatureContribution,
};
use serde_json;
use setup_utils::calculate_hash;
Expand Down Expand Up @@ -511,9 +507,9 @@ async fn contribution_loop(
.expect(&format!("{}", "Couldn't read the contributor info file".red().bold()));
let contrib_info: ContributionInfo = serde_json::from_slice(&content).unwrap();

println!("{}\n{}\n\nI've contributed to @namadanetwork Trusted Setup Ceremony at round #{} with the contribution hash {}. Let's enable interchain privacy. #InterchainPrivacy\n\n{}",
"Done! Thank you for your contribution! If your contribution is valid, it will appear on namada.net. Check it out!".green().bold(),
"Share your attestation that proves your contribution to the world:".bright_cyan(),
println!("{}\n{}\n\nI've contributed to @namadanetwork #NamadaTrustedSetup at round #{} with the contribution hash {}. Let's enable #interchain privacy.\n\n{}",
"Done! Thank you for your contribution! If your contribution is valid, it will appear on ceremony.namada.net. Check it out!".green().bold(),
"If you’d like to share that you contributed with your frens and the world, you can use:".bright_cyan(),
round_height,
contrib_info.contribution_hash,
format!("You also find all the metadata of your contribution (ceremony round, contribution hash, public key, timestamps etc.) in the \"namada_contributior_info_round_{}.json\"",round_height).as_str().bright_cyan()
Expand All @@ -531,9 +527,12 @@ async fn contribution_loop(
break;
} else {
loop {
let attestation_url =
io::get_user_input("Please enter a valid url for your attestation:".bright_yellow(), None)
.unwrap();
let attestation_url = io::get_user_input(
"Please enter a valid url for your attestation (starting with http or https):"
.bright_yellow(),
None,
)
.unwrap();
if Url::parse(attestation_url.as_str()).is_ok() {
// Send attestation to coordinator
requests::post_attestation(
Expand Down
2 changes: 1 addition & 1 deletion phase2-cli/src/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ impl EncryptedKeypair {
/// Make encryption secret key from a password.
fn encryption_key(salt: &kdf::Salt, password: &[u8]) -> kdf::SecretKey {
kdf::Password::from_slice(password)
.and_then(|password| kdf::derive_key(&password, salt, 3, 1 << 16, 32))
.and_then(|password| kdf::derive_key(&password, salt, 3, 1 << 17, 32))
.expect("Generation of encryption secret key shouldn't fail")
}

Expand Down
17 changes: 5 additions & 12 deletions phase2-cli/src/requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,20 @@ use phase2_coordinator::{
authentication::{KeyPair, Production, Signature},
objects::ContributionInfo,
rest_utils::{
RequestContent,
SignatureHeaders,
ACCESS_SECRET_HEADER,
BODY_DIGEST_HEADER,
CONTENT_LENGTH_HEADER,
PUBKEY_HEADER,
SIGNATURE_HEADER,
RequestContent, SignatureHeaders, ACCESS_SECRET_HEADER, BODY_DIGEST_HEADER, CONTENT_LENGTH_HEADER,
PUBKEY_HEADER, SIGNATURE_HEADER,
},
ContributionFileSignature,
};
use reqwest::{
header::{HeaderMap, HeaderValue, CONTENT_TYPE},
Client,
RequestBuilder,
Response,
Url,
Client, RequestBuilder, Response, Url,
};
use serde::Serialize;
use sha2::{Digest, Sha256};
use std::convert::{TryFrom, TryInto};
use thiserror::Error;
use tracing::debug;

use crate::{ContributorStatus, LockedLocators, PostChunkRequest};

Expand Down Expand Up @@ -161,7 +154,7 @@ where
match decapsulate_response(response).await {
Ok(response) => return Ok(response),
Err(e) => match e {
RequestError::Proxy(_) => eprintln!("CDN timeout expired, resubmitting the request..."),
RequestError::Proxy(_) => debug!("CDN timeout expired, resubmitting the request..."),
_ => return Err(e),
},
}
Expand Down
98 changes: 47 additions & 51 deletions phase2-cli/tests/e2e.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,17 @@ use phase2_coordinator::{
rest_utils::{self, PostChunkRequest, TOKENS_ZIP_FILE},
storage::{ContributionLocator, ContributionSignatureLocator, Object},
testing::coordinator,
ContributionFileSignature,
ContributionState,
Coordinator,
Participant,
ContributionFileSignature, ContributionState, Coordinator, Participant,
};
use rocket::{
catchers,
routes,
catchers, routes,
tokio::{
self,
sync::RwLock,
task::JoinHandle,
time::{self, Duration},
},
Error,
Ignite,
Rocket,
Error, Ignite, Rocket,
};

use async_stream::try_stream;
Expand Down Expand Up @@ -141,34 +135,40 @@ async fn test_prelude() -> (TestCtx, JoinHandle<Result<Rocket<Ignite>, Error>>)
let coordinator: Arc<RwLock<Coordinator>> = Arc::new(RwLock::new(coordinator));

let build = rocket::build()
.mount("/", routes![
rest::join_queue,
rest::lock_chunk,
rest::contribute_chunk,
rest::update_coordinator,
rest::heartbeat,
rest::stop_coordinator,
rest::verify_chunks,
rest::get_contributor_queue_status,
rest::post_contribution_info,
rest::get_contributions_info,
rest::get_healthcheck,
rest::get_contribution_url,
rest::get_challenge_url,
rest::get_coordinator_state,
rest::update_cohorts,
rest::post_attestation
])
.mount(
"/",
routes![
rest::join_queue,
rest::lock_chunk,
rest::contribute_chunk,
rest::update_coordinator,
rest::heartbeat,
rest::stop_coordinator,
rest::verify_chunks,
rest::get_contributor_queue_status,
rest::post_contribution_info,
rest::get_contributions_info,
rest::get_healthcheck,
rest::get_contribution_url,
rest::get_challenge_url,
rest::get_coordinator_state,
rest::update_cohorts,
rest::post_attestation
],
)
.manage(coordinator)
.register("/", catchers![
rest_utils::invalid_signature,
rest_utils::unauthorized,
rest_utils::missing_required_header,
rest_utils::io_error,
rest_utils::unprocessable_entity,
rest_utils::mismatching_checksum,
rest_utils::invalid_header
]);
.register(
"/",
catchers![
rest_utils::invalid_signature,
rest_utils::unauthorized,
rest_utils::missing_required_header,
rest_utils::io_error,
rest_utils::unprocessable_entity,
rest_utils::mismatching_checksum,
rest_utils::invalid_header
],
);

let ignite = build.ignite().await.unwrap();
let handle = tokio::spawn(ignite.launch());
Expand Down Expand Up @@ -387,11 +387,9 @@ async fn update_coordinator() {

// Wrong, request from non-coordinator
let url = Url::parse(&ctx.coordinator_url).unwrap();
assert!(
requests::get_update(&client, &url, &ctx.contributors[0].keypair)
.await
.is_err()
);
assert!(requests::get_update(&client, &url, &ctx.contributors[0].keypair)
.await
.is_err());

// Ok
requests::get_update(&client, &url, &ctx.coordinator.keypair)
Expand All @@ -412,16 +410,14 @@ async fn wrong_post_attestation() {

// Wrong, missing contribution
let url = Url::parse(&ctx.coordinator_url).unwrap();
assert!(
requests::post_attestation(
&client,
&url,
&ctx.contributors[0].keypair,
&(1, String::from("https://namada.net"))
)
.await
.is_err()
);
assert!(requests::post_attestation(
&client,
&url,
&ctx.contributors[0].keypair,
&(1, String::from("https://namada.net"))
)
.await
.is_err());
}

#[tokio::test]
Expand Down
2 changes: 1 addition & 1 deletion phase2-coordinator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ homepage = "https://github.com/AleoHQ/aleo-setup"
license = "MIT/Apache-2.0"
name = "phase2-coordinator"
repository = "https://github.com/AleoHQ/aleo-setup"
version = "1.0.0-beta.10"
version = "1.0.0-beta.11"

[[bin]]
name = "phase2-coordinator"
Expand Down
8 changes: 1 addition & 7 deletions phase2-coordinator/src/commands/verification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,7 @@ use crate::{
commands::SigningKey,
environment::Environment,
storage::{
ContributionLocator,
ContributionSignatureLocator,
Disk,
Locator,
Object,
StorageLocator,
StorageObject,
ContributionLocator, ContributionSignatureLocator, Disk, Locator, Object, StorageLocator, StorageObject,
},
CoordinatorError,
};
Expand Down
Loading

0 comments on commit be500fc

Please sign in to comment.