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

TS Client and Server Binaries #259

Merged
merged 204 commits into from
Jan 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
204 commits
Select commit Hold shift + click to select a range
14dc682
wip: commit save point
SupremoUGH Sep 23, 2022
d104285
Config struct created implementing Ceremony
SupremoUGH Sep 24, 2022
b80229f
now it should work
SupremoUGH Sep 26, 2022
fc794dd
Features sorted
SupremoUGH Sep 26, 2022
10ed04e
changelog + minor changes
SupremoUGH Sep 26, 2022
2e10dbf
fmt
SupremoUGH Sep 26, 2022
7a84fb5
Cleaner features. Improved error handling
SupremoUGH Sep 26, 2022
bdf93a3
Comments addressed
SupremoUGH Sep 27, 2022
6e56204
feat: add basic ContributeResponse mechanism
bhgomes Sep 27, 2022
a1130f6
wip: commit save point
bhgomes Sep 27, 2022
f9f69a2
feat: add basic challenge hash response
bhgomes Sep 27, 2022
4002518
server binary
SupremoUGH Sep 27, 2022
f1f6fc9
wip: commit save point
SupremoUGH Sep 27, 2022
bfeb7f6
feat: deserialize state unchecked
GhostOfGauss Sep 27, 2022
3c12c7a
merge commits
GhostOfGauss Sep 27, 2022
0f28444
fix: missing docs
GhostOfGauss Sep 27, 2022
e1ebf1c
Loop in Client::build
SupremoUGH Sep 28, 2022
03221a5
Todd's comments addressed
SupremoUGH Sep 28, 2022
72e3f17
contribution_hash in terms of response
SupremoUGH Sep 28, 2022
8d04af6
Merge branch 'feat/client-server-bin' into feat/server-bin
SupremoUGH Sep 28, 2022
d813205
checkpoint
SupremoUGH Sep 28, 2022
4814cf3
comments addressed
SupremoUGH Sep 28, 2022
57d3b6f
Better messages for waiting clients
SupremoUGH Sep 28, 2022
1ae6d7f
clippy issues
SupremoUGH Sep 28, 2022
bc1f152
Merge branch 'feat/client-server-bin' into feat/server-bin
SupremoUGH Sep 28, 2022
da43e41
coordinator split into groups
SupremoUGH Sep 28, 2022
da7e176
derived traits + moved check_lock
SupremoUGH Sep 28, 2022
b6f2f12
Apply suggestions from code review
bhgomes Sep 28, 2022
1cad2cb
more splitting
SupremoUGH Sep 28, 2022
13c92a2
Update manta-trusted-setup/src/groth16/ceremony/client.rs
SupremoUGH Sep 29, 2022
2ad92fc
server split into pieces
SupremoUGH Sep 29, 2022
6dd2cd7
drop lock
SupremoUGH Sep 29, 2022
28c6e7b
Merge branch 'feat/client-server-bin' into feat/server-bin
SupremoUGH Sep 29, 2022
79395c9
fix: use better bounds/docs for checks
bhgomes Sep 29, 2022
915f699
chore: fix blake2 hashing issue
bhgomes Sep 29, 2022
759fc1e
load_skip
SupremoUGH Sep 29, 2022
1263536
Merge branch 'feat/server-bin' of https://github.com/Manta-Network/ma…
SupremoUGH Sep 29, 2022
d3ea70e
functions factored, load registry
SupremoUGH Sep 29, 2022
a008e25
checkpoint
SupremoUGH Sep 29, 2022
9c84002
checkpoint
SupremoUGH Sep 29, 2022
bf88f4c
wip: init_server can load registry, not states
GhostOfGauss Sep 29, 2022
ef06bd7
logging
SupremoUGH Sep 29, 2022
53fed18
wip: server load from files
GhostOfGauss Sep 29, 2022
f2c6505
impl error for ceremony_error
GhostOfGauss Sep 30, 2022
2036eee
make server bin async
GhostOfGauss Sep 30, 2022
85b4cb5
logging
SupremoUGH Sep 30, 2022
241e14d
init_server takes parameter file paths
GhostOfGauss Sep 30, 2022
a682ed7
merge
GhostOfGauss Sep 30, 2022
3bb22b7
hex-encode contribution message
SupremoUGH Sep 30, 2022
6a664e0
hex-encode works now
SupremoUGH Sep 30, 2022
61523d0
generalize server initialization
GhostOfGauss Sep 30, 2022
e52de69
commit before merge
SupremoUGH Sep 30, 2022
d3f88fd
wip: commit save point
SupremoUGH Sep 30, 2022
6ba44b2
fix prepare fn
GhostOfGauss Sep 30, 2022
d1203b7
save point
GhostOfGauss Sep 30, 2022
a495588
commit before merge
SupremoUGH Sep 30, 2022
c1f2f5e
Merge branch 'feat/server-bin' of https://github.com/Manta-Network/ma…
SupremoUGH Sep 30, 2022
d0e727d
merge
GhostOfGauss Sep 30, 2022
a63ef3d
wip: server prepare
GhostOfGauss Oct 1, 2022
1f823f8
wip: circuit to ceremony trait
GhostOfGauss Oct 1, 2022
832974e
add missing
GhostOfGauss Oct 1, 2022
d740be7
fix prepare
GhostOfGauss Oct 1, 2022
76c87b9
feat: server::prepare works
GhostOfGauss Oct 1, 2022
88104c7
feat: prepare and recover mode work in binary
GhostOfGauss Oct 1, 2022
4d75c92
fix: inconsistent serialization methods
GhostOfGauss Oct 3, 2022
36f4d4f
fix: server update endpoint
GhostOfGauss Oct 3, 2022
83da5b2
fix: queuing bug
GhostOfGauss Oct 3, 2022
865f89c
chore: cleanup unused
GhostOfGauss Oct 4, 2022
4e3f350
fix: add error wrapper
bhgomes Oct 4, 2022
495a07b
chore: merge upstream
bhgomes Oct 4, 2022
cefce56
fix: error wrapper on client side
GhostOfGauss Oct 4, 2022
9f487e1
wip: debugging timeout errors
GhostOfGauss Oct 4, 2022
edc9eeb
lock and queue bugs fixed
SupremoUGH Oct 4, 2022
fa97b53
fix round number
GhostOfGauss Oct 4, 2022
4c7a63a
change registry path, client URL
GhostOfGauss Oct 4, 2022
eed1607
commit before merge
SupremoUGH Oct 4, 2022
080431c
fix link
GhostOfGauss Oct 4, 2022
22ba233
commit before merge
SupremoUGH Oct 4, 2022
ba47877
fix link
GhostOfGauss Oct 4, 2022
95f23fa
Merge branch 'feat/server-bin' of https://github.com/Manta-Network/ma…
SupremoUGH Oct 4, 2022
c7ec5ef
chore: update TLS
bhgomes Oct 4, 2022
85e5277
Merge branch 'feat/server-bin' of https://github.com/Manta-Network/ma…
SupremoUGH Oct 4, 2022
6d0ae75
save server separated into functions
SupremoUGH Oct 4, 2022
bf31ac1
feat: improved client status messages
GhostOfGauss Oct 5, 2022
adf7634
remove extraneous data files
GhostOfGauss Oct 5, 2022
4d5b14d
feat: move server time limit
GhostOfGauss Oct 5, 2022
5362887
tiny client message fix
GhostOfGauss Oct 5, 2022
2599095
update returns challenge + some cleanup
SupremoUGH Oct 5, 2022
ffb5c59
client takes url as CL input
SupremoUGH Oct 5, 2022
6ecdf44
add registry
GhostOfGauss Oct 6, 2022
3057213
fix: priority queue
GhostOfGauss Oct 6, 2022
6ee1495
update registry
GhostOfGauss Oct 6, 2022
758ab0d
update registry
GhostOfGauss Oct 6, 2022
326918c
registry update fix
GhostOfGauss Oct 6, 2022
b953b65
fix case-sensitivity in registry csv
GhostOfGauss Oct 6, 2022
823f035
update registry
GhostOfGauss Oct 6, 2022
6581755
update registry
GhostOfGauss Oct 6, 2022
0d0c8e0
less logs
GhostOfGauss Oct 6, 2022
682befd
update registry
GhostOfGauss Oct 6, 2022
acbd490
update registry
GhostOfGauss Oct 6, 2022
4d49d89
update registry
GhostOfGauss Oct 6, 2022
8b9e5eb
update registry
GhostOfGauss Oct 6, 2022
73ab0d9
debug registry updates
GhostOfGauss Oct 6, 2022
bf453d6
update registry
GhostOfGauss Oct 6, 2022
623bb87
fix: registry parsing and updating
GhostOfGauss Oct 6, 2022
ca9a30a
improved client register messages
GhostOfGauss Oct 7, 2022
3b8545e
fix: unregistered client behavior
GhostOfGauss Oct 7, 2022
d2beada
feat: pretty client messages, deser unchecked for state
GhostOfGauss Oct 7, 2022
ad6e757
feat: circuit description trait
GhostOfGauss Oct 7, 2022
3543f65
update recovery files
GhostOfGauss Oct 7, 2022
72c2545
fix: missing names file
GhostOfGauss Oct 7, 2022
f197f3d
update registry
GhostOfGauss Oct 7, 2022
8ae4ac3
update registry
GhostOfGauss Oct 7, 2022
f93dd26
update registry
GhostOfGauss Oct 7, 2022
1bba969
update registry: vegetables
GhostOfGauss Oct 8, 2022
ff85abe
merged main
SupremoUGH Oct 10, 2022
ab37b2d
final merge details
SupremoUGH Oct 10, 2022
ccef1ab
now registry is updated every 30 secs
SupremoUGH Oct 10, 2022
97a17c6
lock gets updated if empty
SupremoUGH Oct 10, 2022
199dae7
changelog conflict
SupremoUGH Oct 10, 2022
6e9f8c7
wip: commit save point
SupremoUGH Oct 10, 2022
7d0f994
updated registry with vegetables + sleep for testing
SupremoUGH Oct 10, 2022
b5049c8
update registry now prints where parsing errors happened
SupremoUGH Oct 10, 2022
439032e
improved logging
SupremoUGH Oct 11, 2022
bac29b8
update registry
GhostOfGauss Oct 11, 2022
c064607
merge upstream
GhostOfGauss Oct 11, 2022
7c08e60
update registry with newline
GhostOfGauss Oct 11, 2022
09169b8
update registry
GhostOfGauss Oct 11, 2022
a71247f
nonce fix
SupremoUGH Oct 12, 2022
94a8c60
documentation + cleanup
SupremoUGH Oct 12, 2022
367c6c9
add deser check to coordinator update, remove extra files
GhostOfGauss Oct 12, 2022
24a4141
merge from server-bin
GhostOfGauss Oct 12, 2022
6958a6f
merge from server-bin
GhostOfGauss Oct 12, 2022
a818bab
merge upstream
GhostOfGauss Oct 12, 2022
792ce2f
save point
GhostOfGauss Oct 12, 2022
9c07984
feat: raw registration data to registry processing
GhostOfGauss Oct 13, 2022
6f3634b
refactor server prepare, use PathBuf
GhostOfGauss Oct 13, 2022
2b892e3
change server filesystem
GhostOfGauss Oct 13, 2022
f34cb82
wip: registration processing
GhostOfGauss Oct 13, 2022
5a3645f
feat: registration form processing
GhostOfGauss Oct 13, 2022
7f2af53
feat: default recovery, registry paths
GhostOfGauss Oct 14, 2022
b9a432c
simplify bins
GhostOfGauss Oct 14, 2022
69ccb28
join for pathbuf
GhostOfGauss Oct 14, 2022
271834d
cleanup
GhostOfGauss Oct 19, 2022
18ee329
feat: custom registration link
GhostOfGauss Oct 19, 2022
5b75b68
fix: registry update panic
GhostOfGauss Oct 19, 2022
537c738
fix: remove unnecessary async
GhostOfGauss Oct 19, 2022
988a2dc
cleanup
GhostOfGauss Oct 19, 2022
c9d4009
feat: priority for registry processing
GhostOfGauss Oct 19, 2022
55d2ace
fix: change link to typeform
GhostOfGauss Oct 19, 2022
48a55df
fix bin dependencies
GhostOfGauss Oct 19, 2022
afdd157
remove cargo run comments
GhostOfGauss Oct 19, 2022
f608541
fix CI failure
GhostOfGauss Oct 20, 2022
7a0ca25
ignore registry processing tests
GhostOfGauss Oct 20, 2022
94e68bf
update registry headers
GhostOfGauss Oct 21, 2022
8273881
add landing page
GhostOfGauss Oct 21, 2022
fae05b3
add landing page
GhostOfGauss Oct 21, 2022
077ea59
fix landing page
GhostOfGauss Oct 21, 2022
9e65c05
add server prepare files
GhostOfGauss Oct 21, 2022
040ea34
add dummy registry
GhostOfGauss Oct 21, 2022
01b5081
update default server args
GhostOfGauss Oct 21, 2022
82eb4fb
informative serialization errors
GhostOfGauss Oct 21, 2022
5bda40c
update landing page
GhostOfGauss Oct 21, 2022
0a32186
feat: customized registration link
GhostOfGauss Oct 21, 2022
06a72fb
changelog
GhostOfGauss Oct 21, 2022
d5234cd
update registration form processing
GhostOfGauss Oct 24, 2022
d476a8b
update readme
GhostOfGauss Oct 24, 2022
32bbbee
update registry screenshot, link
GhostOfGauss Oct 25, 2022
5320a19
clippy
GhostOfGauss Oct 25, 2022
c10286d
fmt
GhostOfGauss Oct 25, 2022
2e7603a
fmt
GhostOfGauss Oct 25, 2022
95c55c3
fmt
GhostOfGauss Oct 25, 2022
af138d5
fmt
GhostOfGauss Oct 25, 2022
56320cb
undo fmt change
GhostOfGauss Oct 25, 2022
e17e578
fix: clippy false positive
GhostOfGauss Oct 25, 2022
b610205
Update ci.yml
bhgomes Oct 25, 2022
1558536
add gitignore for data
GhostOfGauss Oct 25, 2022
f496ff1
clippy format warnings
GhostOfGauss Oct 25, 2022
f4c9856
fmt
GhostOfGauss Oct 25, 2022
846ea92
fix clippy
GhostOfGauss Oct 25, 2022
8cdd847
merge feat/client_v2 into feat/server_bin
GhostOfGauss Oct 27, 2022
4ac2aa2
CI allow unknown lints
GhostOfGauss Oct 27, 2022
bd54318
fix format error
GhostOfGauss Oct 27, 2022
8deae0c
clippy
GhostOfGauss Oct 27, 2022
eb40995
feat: process both registration forms
GhostOfGauss Oct 27, 2022
3cf9b1a
merge main into feat/server-bin
GhostOfGauss Oct 27, 2022
cf8b8e2
fix: changelog
GhostOfGauss Oct 27, 2022
a06f0b3
fmt
GhostOfGauss Oct 27, 2022
09a9820
fix test
GhostOfGauss Nov 1, 2022
62fa59c
merge main into feat/server-bin
GhostOfGauss Nov 1, 2022
63cf80b
remove default paths from bins, remove unused test
GhostOfGauss Nov 1, 2022
551658e
change default priority to high
GhostOfGauss Nov 1, 2022
f840ce8
merge main into feat/server-bin
GhostOfGauss Nov 1, 2022
cdc87cf
Merge branch 'main' into feat/server-bin
bhgomes Nov 7, 2022
3169eb5
wip: remote test debugging
GhostOfGauss Nov 13, 2022
6a49cb2
remove empty registry update messages
GhostOfGauss Nov 15, 2022
3f41f33
remove empty registry update messages
GhostOfGauss Nov 15, 2022
ca30906
Merge branch 'main' into feat/server-bin
bhgomes Jan 10, 2023
49f0811
merge main
GhostOfGauss Jan 16, 2023
48abcef
simplify trusted setup features
GhostOfGauss Jan 16, 2023
588b8a3
fix feature gating
GhostOfGauss Jan 16, 2023
a184024
cleanup
GhostOfGauss Jan 16, 2023
10a369d
fix: landing page as server bin argument
GhostOfGauss Jan 17, 2023
e6f5a52
Merge branch 'main' into feat/server-bin
bhgomes Jan 17, 2023
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 @@ -5,6 +5,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## [Unreleased]
### Added
- [\#259](https://github.com/Manta-Network/manta-rs/pull/257) Add server binaries for the trusted setup
- [\#303](https://github.com/Manta-Network/manta-rs/pull/303) Poseidon Hash and AES decryption WASM benchmarks.

### Changed
Expand Down
31 changes: 22 additions & 9 deletions manta-crypto/src/dalek/ed25519.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,10 @@ macro_rules! byte_conversion {
///
/// We don't need to return an error here because `bytes` already has the correct length.
#[inline]
pub fn $name(bytes: [u8; $len]) -> $type {
pub fn $name(bytes: [u8; $len]) -> Result<$type, ByteConversionError> {
match $type::from_bytes(&bytes) {
Ok(value) => value,
_ => unreachable!(concat!(
"We are guaranteed the correct number of bytes from `",
stringify!($len),
"`."
)),
Ok(value) => Ok(value),
_ => Err(ByteConversionError::IncorrectByteSize),
}
}
};
Expand All @@ -57,10 +53,17 @@ 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);

#[derive(Clone, Copy, Debug, PartialEq, Eq)]
/// Errors that can occur when converting from bytes
pub enum ByteConversionError {
/// Incorrect Number of Bytes
IncorrectByteSize,
}

/// Clones the `secret_key` by serializing and then deserializing.
#[inline]
pub fn clone_secret_key(secret_key: &SecretKey) -> SecretKey {
secret_key_from_bytes(secret_key.to_bytes())
secret_key_from_bytes(secret_key.to_bytes()).expect("Byte conversion cannot fail here.")
}

/// Generates a [`Keypair`] from `secret_key`.
Expand All @@ -78,7 +81,7 @@ pub fn generate_secret_key<R>(rng: &mut R) -> SecretKey
where
R: CryptoRng + RngCore,
{
secret_key_from_bytes(rng.gen())
secret_key_from_bytes(rng.gen()).expect("RNG will generate correct number of bytes.")
}

/// Generates a [`Keypair`] from `rng`.
Expand All @@ -99,6 +102,16 @@ where
#[derivative(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct Ed25519<M>(PhantomData<M>);

/// The serialization of a [`PublicKey`].
#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct VerifyingKey(Array<u8, 32>);

impl From<PublicKey> for VerifyingKey {
fn from(k: PublicKey) -> Self {
Self(Array::from_unchecked(*k.as_bytes()))
}
}

impl<M> MessageType for Ed25519<M> {
type Message = M;
}
Expand Down
45 changes: 30 additions & 15 deletions manta-trusted-setup/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,40 +26,56 @@ maintenance = { status = "actively-developed" }

[[bin]]
name = "groth16_phase2_client"
required-features = ["clap", "ppot-client", "reqwest", "tokio"]
required-features = ["client"]

[[bin]]
name = "groth16_phase2_prepare"
required-features = ["clap", "memmap", "ppot-client", "serde", "tokio"]
required-features = ["coordinator"]

[[bin]]
name = "groth16_phase2_server"
required-features = ["coordinator"]

[[bin]]
name = "groth16_phase2_verifier"
required-features = ["clap", "memmap", "ppot-client", "reqwest", "tokio"]
required-features = ["coordinator"]

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

# PPoT Client Features
ppot-client = [
# Trusted Setup Ceremony
ceremony = [
"bincode",
"bs58",
"chrono",
"clap",
"colored",
"console",
"csv",
"dialoguer",
"manta-crypto/ark-bn254",
"reqwest",
"serde",
"tiny-bip39",
"tokio"
]

# Trusted Setup Client
client = [
"async-std",
"ceremony",
"hex/std",
"manta-util/tide",
"parking_lot",
"ppot",
"tiny-bip39",
]

# Trusted Setup Coordinator
coordinator = ["client", "memmap", "parking_lot", "serde_json", "std",]

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

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

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

Expand All @@ -76,21 +92,20 @@ serde = [
]

# Standard Library
std = ["ark-std/std", "manta-util/std"]
std = ["ark-std/std", "hex/std", "manta-util/std"]

# Testing Frameworks
test = ["manta-crypto/test"]

# Tide HTTP Server
tide = ["manta-util/tide"]

[dependencies]
ark-groth16 = { version = "0.3.0", default-features = false }
ark-poly = { version = "0.3.0", default-features = false }
ark-std = { version = "0.3.0", default-features = false }
async-std = { version = "1.6.0", optional = true, features = ["attributes", "tokio1"] }
bincode = { version = "1.3.3", optional = true, default-features = false }
blake2 = { version = "0.10.6", default-features = false }
bs58 = { version = "0.4.0", optional = true, default-features = false, features = ["alloc"] }
chrono = { version = "0.4.19", optional = true, default-features = false, features = ["clock"] }
clap = { version = "3.2.23", optional = true, default-features = false, features = ["color", "derive", "std", "suggestions", "unicode", "wrap_help"] }
colored = { version = "2.0.0", optional = true, default-features = false }
console = { version = "0.15.4", optional = true, default-features = false }
Expand All @@ -105,7 +120,7 @@ memmap = { version = "0.7.0", optional = true, default-features = false }
parking_lot = { version = "0.12.1", optional = true, default-features = false }
serde_json = { version = "1.0.91", optional = true, default-features = false, features = ["alloc"] }
tiny-bip39 = { version = "1.0.0", optional = true, default-features = false }
tokio = { version = "1.24.1", optional = true, default-features = false, features = ["rt-multi-thread", "io-std"] }
tokio = { version = "1.24.1", optional = true, default-features = false, features = ["rt-multi-thread", "io-std", "io-util", "time"] }

[dev-dependencies]
ark-snark = { version = "0.3.0", default-features = false }
Expand Down
91 changes: 91 additions & 0 deletions manta-trusted-setup/src/bin/groth16_phase2_server.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// 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 Server

use clap::Parser;
use manta_trusted_setup::groth16::ceremony::{
config::ppot::{Config, Participant},
server::Server,
CeremonyError,
};
use manta_util::{
http::tide::{self, execute},
Array,
};
use std::{collections::HashMap, path::PathBuf, time::Duration};

/// Registry type
type Registry = HashMap<Array<u8, 32>, Participant>;

/// Current server configuration
type S = Server<Config, Registry, 2, 3>;

/// Contribution time limit in seconds
const TIME_LIMIT: u64 = 60;

/// Server CLI
#[derive(Debug, Parser)]
pub struct Arguments {
/// Path to directory where server recovers/saves state
recovery_dir_path: String,

/// Path to file from which server updates internal registry
registry_path: String,

/// Path to html file to serve to web browsers
homepage_path: String,
}

impl Arguments {
/// Runs a server.
#[inline]
pub async fn run(self) -> Result<(), CeremonyError<Config>> {
let server = S::recover(
PathBuf::from(self.recovery_dir_path),
PathBuf::from(self.registry_path),
Duration::from_secs(TIME_LIMIT),
)
.expect("Unable to recover from file");

println!("Network is running!");
let mut api = tide::Server::with_state(server);
api.at("/").serve_file(&self.homepage_path).map_err(|_| {
CeremonyError::<Config>::Network {
message: "Cannot load landing page.".to_string(),
}
})?;
api.at("/start")
.post(|r| execute(r, Server::start_endpoint));
api.at("/query")
.post(|r| execute(r, Server::query_endpoint));
api.at("/update")
.post(|r| execute(r, Server::update_endpoint));

api.listen("127.0.0.1:8080")
.await
.expect("Should create a listener.");
Ok(())
}
}

#[async_std::main]
async fn main() {
Arguments::parse()
.run()
.await
.expect("Server error occurred");
}
62 changes: 57 additions & 5 deletions manta-trusted-setup/src/ceremony/registry/csv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,13 @@
//! Trusted Setup Ceremony Registry CSV Compatibility

use crate::ceremony::registry::Registry;
use core::fmt::Debug;
use manta_util::serde::de::DeserializeOwned;
use std::{fs::File, path::Path};
use std::{
fs::{File, OpenOptions},
io::{Seek, SeekFrom},
path::Path,
};

/// CSV Record
pub trait Record<I, V>: DeserializeOwned {
Expand Down Expand Up @@ -56,11 +61,58 @@ where
T: Record<I, V>,
R: Registry<I, V>,
P: AsRef<Path>,
T::Error: Debug,
{
let mut registry = R::new();
for record in csv::Reader::from_reader(File::open(path)?).deserialize() {
let (identifier, participant) = T::parse(record?).map_err(Error::Parse)?;
registry.insert(identifier, participant);
}
load_append_entries::<_, _, T, _, _>(path, &mut registry)?;
Ok(registry)
}

/// Loads new entries into `registry` from `path` using `T` as the record type without overwriting
/// existing entries. Returns the number of new entries added.
#[inline]
pub fn load_append_entries<I, V, T, R, P>(
path: P,
registry: &mut R,
) -> Result<usize, Error<T::Error>>
where
T: Record<I, V>,
R: Registry<I, V>,
P: AsRef<Path>,
T::Error: Debug,
{
let length = registry.len();

for (number, record) in csv::Reader::from_reader(File::open(path)?)
.deserialize()
.flatten()
.enumerate()
{
match T::parse(record) {
Ok((identifier, participant)) => {
registry.insert(identifier, participant);
}
Err(e) => {
println!("Line: {} Parsing error {e:?}", number + 2);
}
};
}
Ok(registry.len() - length)
}

/// Build an append-only CSV writer from a file path.
/// Missing files are created.
pub fn append_only_csv_writer<E, P>(path: P) -> Result<csv::Writer<File>, E>
where
P: AsRef<Path>,
E: From<std::io::Error>,
{
let mut file = OpenOptions::new().write(true).create(true).open(&path)?;
let mut file_is_empty = false;
if file.seek(SeekFrom::End(0))? == 0 {
file_is_empty = true;
}
Ok(csv::WriterBuilder::new()
.has_headers(file_is_empty)
.from_writer(file))
}
4 changes: 2 additions & 2 deletions manta-trusted-setup/src/groth16/ceremony/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@

//! Groth16 Trusted Setup Ceremony Configurations

#[cfg(feature = "ppot-client")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "ppot-client")))]
#[cfg(feature = "client")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "client")))]
pub mod ppot;
Loading