Skip to content

Commit 04940fd

Browse files
committed
api: add script to fetch certs/keys
1 parent d14358b commit 04940fd

File tree

7 files changed

+263
-22
lines changed

7 files changed

+263
-22
lines changed

mpc-server/.gitignore

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
/target/
22
/Cargo.lock
33

4-
/data/
5-
/config*.toml
6-
/run.sh
4+
/data/*
5+
!/data/circuit.json
6+
7+
/config/
78

89
.env

mpc-server/certs.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env bash
2+
3+
rm -rf data
4+
mkdir -p data
5+
6+
[[ -f "data/key0.der" ]] || cargo run --bin gen_cert -- -k data/key0.der -c data/cert0.der -s localhost -s ip6-localhost -s 127.0.0.1 -s party0
7+
[[ -f "data/key1.der" ]] || cargo run --bin gen_cert -- -k data/key1.der -c data/cert1.der -s localhost -s ip6-localhost -s 127.0.0.1 -s party1
8+
[[ -f "data/key2.der" ]] || cargo run --bin gen_cert -- -k data/key2.der -c data/cert2.der -s localhost -s ip6-localhost -s 127.0.0.1 -s party2
9+
10+
cargo run -- --config-file config1.toml &
11+
cargo run -- --config-file config2.toml &
12+
cargo run -- --config-file config3.toml

mpc-server/config.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
3+
GITHUB_URL=https://github.com/TaceoLabs/co-snarks/raw/refs/heads/main/co-noir/co-noir/examples/data/
4+
5+
DIR=./config
6+
mkdir -p $DIR
7+
8+
curl -L -o $DIR/cert0.der $GITHUB_URL/cert0.der
9+
curl -L -o $DIR/cert1.der $GITHUB_URL/cert1.der
10+
curl -L -o $DIR/cert2.der $GITHUB_URL/cert2.der
11+
curl -L -o $DIR/key0.der $GITHUB_URL/key0.der
12+
curl -L -o $DIR/key1.der $GITHUB_URL/key1.der
13+
curl -L -o $DIR/key2.der $GITHUB_URL/key2.der
14+
15+
16+
GITHUB_URL=https://github.com/TaceoLabs/co-snarks/raw/refs/heads/main/co-noir/co-noir/examples/test_vectors/
17+
18+
curl -L -o $DIR/bn254_g1.dat $GITHUB_URL/bn254_g1.dat
19+
curl -L -o $DIR/bn254_g2.dat $GITHUB_URL/bn254_g2.dat

mpc-server/data/circuit.json

Lines changed: 208 additions & 0 deletions
Large diffs are not rendered by default.

mpc-server/src/db.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
use std::collections::HashSet;
2-
31
use rusqlite::{Connection, Error, params_from_iter};
2+
use std::collections::HashSet;
43

5-
use crate::matching::DIR;
4+
use crate::matching::DATA_DIR;
65

76
#[derive(Debug, Clone)]
87
pub struct User {
@@ -19,7 +18,7 @@ pub struct Match {
1918
}
2019

2120
pub fn connect_db() -> Result<Connection, Box<dyn std::error::Error + Send + Sync>> {
22-
let conn = Connection::open(DIR.join("db.sqlite"))?;
21+
let conn = Connection::open(DATA_DIR.join("db.sqlite"))?;
2322
Ok(conn)
2423
}
2524

mpc-server/src/main.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use std::sync::{Arc, Mutex};
2-
31
use axum::{
42
Json, Router,
53
extract::{Multipart, Query},
@@ -11,6 +9,7 @@ use co_ultrahonk::prelude::ZeroKnowledge;
119
use rustls::pki_types::CertificateDer;
1210
use serde::Deserialize;
1311
use serde_json::json;
12+
use std::sync::Arc;
1413
use token::Token;
1514
use tower_http::{
1615
cors::{Any, CorsLayer},
@@ -29,7 +28,7 @@ mod shares;
2928
mod token;
3029

3130
use db::{connect_db, get_matches, setup_db};
32-
use matching::{DIR, run_matches};
31+
use matching::{CONFIG_DIR, DATA_DIR, run_matches};
3332
use shares::upload;
3433

3534
#[derive(Debug, Deserialize)]
@@ -61,21 +60,21 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
6160
NetworkParty::new(
6261
PartyID::ID0.into(),
6362
Address::new("localhost".to_string(), 10000),
64-
CertificateDer::from(std::fs::read(DIR.join("cert0.der"))?).into_owned(),
63+
CertificateDer::from(std::fs::read(CONFIG_DIR.join("cert0.der"))?).into_owned(),
6564
),
6665
NetworkParty::new(
6766
PartyID::ID1.into(),
6867
Address::new("localhost".to_string(), 10001),
69-
CertificateDer::from(std::fs::read(DIR.join("cert1.der"))?).into_owned(),
68+
CertificateDer::from(std::fs::read(CONFIG_DIR.join("cert1.der"))?).into_owned(),
7069
),
7170
NetworkParty::new(
7271
PartyID::ID2.into(),
7372
Address::new("localhost".to_string(), 10002),
74-
CertificateDer::from(std::fs::read(DIR.join("cert2.der"))?).into_owned(),
73+
CertificateDer::from(std::fs::read(CONFIG_DIR.join("cert2.der"))?).into_owned(),
7574
),
7675
];
7776

78-
let program_artifact = Utils::get_program_artifact_from_file(DIR.join("circuit.json"))?;
77+
let program_artifact = Utils::get_program_artifact_from_file(DATA_DIR.join("circuit.json"))?;
7978
let constraint_system = Arc::new(Utils::get_constraint_system_from_artifact(
8079
&program_artifact,
8180
true,
@@ -86,8 +85,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
8685

8786
let crs_size = co_noir::compute_circuit_size::<Bn254>(&constraint_system, recursive)?;
8887
let crs = CrsParser::<Bn254>::get_crs(
89-
DIR.join("bn254_g1.dat"),
90-
DIR.join("bn254_g2.dat"),
88+
CONFIG_DIR.join("bn254_g1.dat"),
89+
CONFIG_DIR.join("bn254_g2.dat"),
9190
crs_size,
9291
has_zk,
9392
)?;

mpc-server/src/matching.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,12 @@ use std::{
1616
use crate::db::{connect_db, get_all_users, get_user, insert_matches, update_checked};
1717
use crate::shares::{Share, get_shares};
1818

19-
pub const DIR: Lazy<PathBuf> = Lazy::new(|| PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("data"));
20-
pub const SHARES_DIR_1: Lazy<PathBuf> = Lazy::new(|| DIR.join("user1"));
21-
pub const SHARES_DIR_2: Lazy<PathBuf> = Lazy::new(|| DIR.join("user2"));
19+
pub const DATA_DIR: Lazy<PathBuf> =
20+
Lazy::new(|| PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("data"));
21+
pub const CONFIG_DIR: Lazy<PathBuf> =
22+
Lazy::new(|| PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("config"));
23+
pub const SHARES_DIR_1: Lazy<PathBuf> = Lazy::new(|| DATA_DIR.join("user1"));
24+
pub const SHARES_DIR_2: Lazy<PathBuf> = Lazy::new(|| DATA_DIR.join("user2"));
2225

2326
pub async fn run_matches(
2427
user_id: String,
@@ -105,7 +108,7 @@ async fn run_match(
105108
id: PartyID::ID0,
106109
port: 10000,
107110
key: PrivateKeyDer::Pkcs8(PrivatePkcs8KeyDer::from(std::fs::read(
108-
DIR.join("key0.der"),
111+
CONFIG_DIR.join("key0.der"),
109112
)?))
110113
.clone_key(),
111114
parties: parties.clone(),
@@ -120,7 +123,7 @@ async fn run_match(
120123
id: PartyID::ID1,
121124
port: 10001,
122125
key: PrivateKeyDer::Pkcs8(PrivatePkcs8KeyDer::from(std::fs::read(
123-
DIR.join("key1.der"),
126+
CONFIG_DIR.join("key1.der"),
124127
)?))
125128
.clone_key(),
126129
parties: parties.clone(),
@@ -135,7 +138,7 @@ async fn run_match(
135138
id: PartyID::ID2,
136139
port: 10002,
137140
key: PrivateKeyDer::Pkcs8(PrivatePkcs8KeyDer::from(std::fs::read(
138-
DIR.join("key2.der"),
141+
CONFIG_DIR.join("key2.der"),
139142
)?))
140143
.clone_key(),
141144
parties: parties.clone(),

0 commit comments

Comments
 (0)