Skip to content

Commit 71247d6

Browse files
Merge branch 'staging' into feataggmode/show-db-status-grafana
2 parents e180342 + 498f243 commit 71247d6

27 files changed

Lines changed: 449 additions & 1609 deletions

File tree

.github/workflows/build-and-test-rust.yml

Lines changed: 5 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ on:
1313
- ".github/workflows/build-and-test-rust.yml"
1414

1515
jobs:
16-
build:
16+
build-and-test:
1717
runs-on: aligned-runner
1818

1919
steps:
@@ -26,6 +26,9 @@ jobs:
2626
components: rustfmt, clippy
2727
override: true
2828

29+
- name: foundry-toolchain
30+
uses: foundry-rs/foundry-toolchain@v1.2.0
31+
2932
# Reference: https://github.com/succinctlabs/sp1/actions/runs/8886659400/workflow#L61-L65
3033
- name: Install sp1 toolchain
3134
run: |
@@ -82,54 +85,13 @@ jobs:
8285
# We need to skip the build as clippy does not support the riscv32im-risc0-zkvm-elf target
8386
RISC0_SKIP_BUILD=1 cargo clippy --all -- -D warnings
8487
85-
test:
86-
runs-on: aligned-runner
87-
needs: build
88-
steps:
89-
- name: Checkout code
90-
uses: actions/checkout@v4
91-
92-
- name: Set up Rust
93-
uses: actions-rs/toolchain@v1
94-
with:
95-
toolchain: 1.88.0
96-
components: rustfmt, clippy
97-
override: true
98-
99-
- name: foundry-toolchain
100-
uses: foundry-rs/foundry-toolchain@v1.2.0
101-
102-
# Reference: https://github.com/succinctlabs/sp1/actions/runs/8886659400/workflow#L61-L65
103-
- name: Install sp1 toolchain
104-
run: |
105-
curl -L https://sp1.succinct.xyz | bash
106-
source /home/runner/.bashrc
107-
~/.sp1/bin/sp1up
108-
109-
- name: Install risc0 toolchain
110-
run: |
111-
curl -L https://risczero.com/install | bash
112-
source ~/.bashrc
113-
~/.risc0/bin/rzup install
114-
115-
- name: Cache Rust dependencies
116-
uses: actions/cache@v3
117-
with:
118-
path: |
119-
~/.cargo/registry
120-
~/.cargo/git
121-
crates/target
122-
key: ${{ runner.os }}-rust-${{ hashFiles('**/Cargo.lock') }}
123-
restore-keys: |
124-
${{ runner.os }}-rust-
125-
12688
- name: Run Batcher tests
12789
run: |
12890
cd crates
12991
cargo test --all
13092
13193
- name: Run AggregationMode tests
13294
run: |
133-
cd aggregation_mode/proof_aggregator && cargo test
95+
cd aggregation_mode/proof_aggregator && SKIP_AGG_PROGRAMS_BUILD=1 cargo test
13496
cd ../gateway && cargo test
13597
cd ../payments_poller && cargo test

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ verify_aggregated_proof_sp1:
288288
--public-inputs ../../scripts/test_files/sp1/sp1_fibonacci_5_0_0.pub
289289

290290
proof_aggregator_install: ## Install the aggregation mode with proving enabled
291-
cargo install --path aggregation_mode --features prove,gpu --bin proof_aggregator_gpu --locked
291+
cargo install --path aggregation_mode/proof_aggregator --features prove,gpu --bin proof_aggregator_gpu --locked
292292

293293
proof_aggregator_write_program_ids: ## Write proof aggregator zkvm programs ids
294294
@cd aggregation_mode/proof_aggregator && ./scripts/build_programs.sh

aggregation_mode/Cargo.lock

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

aggregation_mode/docker-compose.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ volumes:
33

44
networks:
55
aligned-network:
6-
external: true
76
name: aligned-network
7+
driver: bridge
88

99
name: aggregation-mode
1010
services:

aggregation_mode/gateway/Cargo.toml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ name = "gateway"
33
version = "0.1.0"
44
edition = "2021"
55

6+
[features]
7+
default = []
8+
tls = ["dep:rustls"]
9+
610
[dependencies]
711
serde = { workspace = true }
812
serde_json = { workspace = true }
@@ -14,11 +18,11 @@ db = { workspace = true }
1418
tracing = { version = "0.1", features = ["log"] }
1519
tracing-subscriber = { version = "0.3.0", features = ["env-filter"] }
1620
bincode = "1.3.3"
17-
actix-web = "4"
21+
actix-web = { version = "4", features = ["rustls-0_23"] }
1822
actix-multipart = "0.7.2"
1923
actix-web-prometheus = "0.1.2"
24+
rustls = { version = "0.23", optional = true, default-features = false, features = ["std", "aws-lc-rs"] }
2025
alloy = { workspace = true }
2126
tokio = { version = "1", features = ["time", "macros", "rt-multi-thread"]}
22-
# TODO: enable tls
2327
sqlx = { version = "0.8", features = [ "runtime-tokio", "postgres", "uuid", "bigdecimal" ] }
2428
hex = "0.4"

aggregation_mode/gateway/src/config.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ pub struct Config {
1010
pub network: String,
1111
pub max_daily_proofs_per_user: i64,
1212
pub gateway_metrics_port: u16,
13+
#[cfg(feature = "tls")]
14+
pub tls_cert_path: String,
15+
#[cfg(feature = "tls")]
16+
pub tls_key_path: String,
17+
#[cfg(feature = "tls")]
18+
pub tls_port: u16,
1319
}
1420

1521
impl Config {

aggregation_mode/gateway/src/http.rs

Lines changed: 61 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ use std::{
44
time::{Instant, SystemTime, UNIX_EPOCH},
55
};
66

7+
#[cfg(feature = "tls")]
8+
use rustls::{
9+
pki_types::{pem::PemObject, CertificateDer, PrivateKeyDer},
10+
ServerConfig,
11+
};
12+
713
use actix_multipart::form::MultipartForm;
814
use actix_web::{
915
web::{self, Data},
@@ -56,9 +62,31 @@ impl GatewayServer {
5662
}
5763
}
5864

65+
#[cfg(feature = "tls")]
66+
fn load_tls_config(
67+
cert_path: &str,
68+
key_path: &str,
69+
) -> Result<ServerConfig, Box<dyn std::error::Error>> {
70+
// Install the default crypto provider
71+
let _ = rustls::crypto::aws_lc_rs::default_provider().install_default();
72+
73+
// Load certificate chain
74+
let certs: Vec<CertificateDer> =
75+
CertificateDer::pem_file_iter(cert_path)?.collect::<Result<Vec<_>, _>>()?;
76+
77+
// Load private key
78+
let private_key = PrivateKeyDer::from_pem_file(key_path)?;
79+
80+
let config = ServerConfig::builder()
81+
.with_no_client_auth()
82+
.with_single_cert(certs, private_key)?;
83+
84+
Ok(config)
85+
}
86+
5987
pub async fn start(&self) {
6088
// Note: GatewayServer is thread safe so we can just clone it (no need to add mutexes)
61-
let port = self.config.port;
89+
let http_port = self.config.port;
6290
let state = self.clone();
6391

6492
// Note: This creates a new Prometheus server different from the one created in GatewayServer::new. The created
@@ -68,8 +96,7 @@ impl GatewayServer {
6896
.build()
6997
.unwrap();
7098

71-
tracing::info!("Starting server at port {}", self.config.port);
72-
HttpServer::new(move || {
99+
let server = HttpServer::new(move || {
73100
App::new()
74101
.app_data(Data::new(state.clone()))
75102
.wrap(prometheus.clone())
@@ -79,12 +106,37 @@ impl GatewayServer {
79106
.route("/proof/sp1", web::post().to(Self::post_proof_sp1))
80107
.route("/proof/risc0", web::post().to(Self::post_proof_risc0))
81108
.route("/quotas/{address}", web::get().to(Self::get_quotas))
82-
})
83-
.bind((self.config.ip.as_str(), port))
84-
.expect("To bind socket correctly")
85-
.run()
86-
.await
87-
.expect("Server to never end");
109+
});
110+
111+
tracing::info!(
112+
"Starting HTTP server at http://{}:{}",
113+
self.config.ip,
114+
http_port
115+
);
116+
117+
let server = server
118+
.bind((self.config.ip.as_str(), http_port))
119+
.expect("To bind HTTP socket correctly");
120+
121+
#[cfg(feature = "tls")]
122+
let server = {
123+
let tls_port = self.config.tls_port;
124+
tracing::info!(
125+
"Starting HTTPS server at https://{}:{}",
126+
self.config.ip,
127+
tls_port
128+
);
129+
130+
let tls_config =
131+
Self::load_tls_config(&self.config.tls_cert_path, &self.config.tls_key_path)
132+
.expect("Failed to load TLS configuration");
133+
134+
server
135+
.bind_rustls_0_23((self.config.ip.as_str(), tls_port), tls_config)
136+
.expect("To bind HTTPS socket correctly with TLS")
137+
};
138+
139+
server.run().await.expect("Server to never end");
88140
}
89141

90142
// Returns an OK response (code 200), no matters what receives in the request

aggregation_mode/proof_aggregator/Cargo.toml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,27 +38,24 @@ risc0-build = { version = "3.0.3" }
3838
# Tell risc0 build to find method in ./aggregation_programs/risc0 package
3939
methods = ["./aggregation_programs/risc0"]
4040

41-
[profile.release]
42-
opt-level = 3
43-
4441
[features]
4542
default = []
4643
prove = []
4744
gpu = ["risc0-zkvm/cuda"]
4845

4946
[[bin]]
5047
name = "proof_aggregator_cpu"
51-
path = "./src/main.rs"
48+
path = "./src/bin/proof_aggregator_cpu.rs"
5249
required-features = ["prove"]
5350

5451
[[bin]]
5552
name = "proof_aggregator_gpu"
56-
path = "./src/main.rs"
53+
path = "./src/bin/proof_aggregator_gpu.rs"
5754
required-features = ["prove", "gpu"]
5855

5956
[[bin]]
6057
name = "proof_aggregator_dev"
61-
path = "./src/main.rs"
58+
path = "./src/bin/proof_aggregator_dev.rs"
6259

6360
[[bin]]
6461
name = "write_program_image_id_vk_hash"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#[tokio::main]
2+
async fn main() {
3+
proof_aggregator::run().await;
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#[tokio::main]
2+
async fn main() {
3+
proof_aggregator::run().await;
4+
}

0 commit comments

Comments
 (0)