Skip to content

Commit 7d4e14b

Browse files
committed
feat: read config from yaml file
1 parent 0217c99 commit 7d4e14b

5 files changed

Lines changed: 191 additions & 37 deletions

File tree

aggregation-mode/Cargo.lock

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

aggregation-mode/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ sp1-sdk = "4.1.3"
99
sp1_aggregator = { path = "./zkvm/sp1/" }
1010
serde = { version = "1.0.203", features = ["derive"] }
1111
serde_json = "1.0.117"
12+
serde_yaml = "0.9"
1213
tracing = { version = "0.1", features = ["log"] }
1314
tracing-subscriber = { version = "0.3.0", features = ["env-filter"] }
14-
alloy = { version = "0.11", features = [] }
15+
alloy = { version = "0.11", features = ["default", "signer-keystore"] }
1516
bincode = "1.3.3"
1617
tokio = { version = "1", features = ["time"]}
1718
sha3 = "0.10.8"
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
use serde::Deserialize;
2+
use std::{fs::File, io::Read};
3+
4+
#[derive(Debug, Deserialize)]
5+
pub struct ECDSAConfig {
6+
pub private_key_store_path: String,
7+
pub private_key_store_password: String,
8+
}
9+
10+
#[derive(Debug, Deserialize)]
11+
pub struct Config {
12+
pub eth_rpc_url: String,
13+
pub private_key: String,
14+
pub submit_proofs_every_secs: u64,
15+
pub max_proofs_in_queue: u16,
16+
pub proof_aggregation_service_address: String,
17+
pub ecdsa: ECDSAConfig,
18+
}
19+
20+
impl Config {
21+
pub fn from_file(file_path: &str) -> Result<Config, Box<dyn std::error::Error>> {
22+
let mut file = File::open(file_path)?;
23+
let mut contents = String::new();
24+
file.read_to_string(&mut contents)?;
25+
let config: Config = serde_yaml::from_str(&contents)?;
26+
Ok(config)
27+
}
28+
}

aggregation-mode/src/backend/mod.rs

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
use std::{str::FromStr, time::Duration};
1+
pub mod config;
2+
mod merkle_tree;
3+
mod types;
24

5+
use crate::zk::{
6+
aggregator::{self, AggregatedProof, ProgramInput, ProofAggregationError},
7+
backends::sp1::SP1AggregationInput,
8+
Proof, VerificationError, ZKVMEngine,
9+
};
310
use alloy::{
411
network::EthereumWallet,
512
primitives::Address,
613
providers::{PendingTransactionError, ProviderBuilder},
714
rpc::types::TransactionReceipt,
8-
signers::local::PrivateKeySigner,
15+
signers::local::LocalSigner,
916
};
17+
use config::Config;
1018
use merkle_tree::compute_proofs_merkle_root;
1119
use sp1_sdk::HashableKey;
20+
use std::{str::FromStr, time::Duration};
1221
use tracing::{error, info, warn};
1322
use types::{AlignedProofAggregationService, AlignedProofAggregationServiceContract};
1423

15-
use crate::zk::{
16-
aggregator::{self, AggregatedProof, ProgramInput, ProofAggregationError},
17-
backends::sp1::SP1AggregationInput,
18-
Proof, VerificationError, ZKVMEngine,
19-
};
20-
21-
mod merkle_tree;
22-
mod types;
23-
2424
#[derive(Debug)]
2525
pub enum ProofQueueError {
2626
QueueMaxCapacity,
@@ -43,18 +43,14 @@ pub struct ProofAggregator {
4343
proof_aggregation_service: AlignedProofAggregationServiceContract,
4444
}
4545

46-
pub struct Config {
47-
pub rpc_url: String,
48-
pub private_key: String,
49-
pub submit_proofs_every_secs: u64,
50-
pub max_proofs_in_queue: u16,
51-
pub proof_aggregation_service_address: String,
52-
}
53-
5446
impl ProofAggregator {
5547
pub fn new(config: Config) -> Self {
56-
let rpc_url = config.rpc_url.parse().expect("correct url");
57-
let signer = PrivateKeySigner::from_str(&config.private_key).expect("valid string");
48+
let rpc_url = config.eth_rpc_url.parse().expect("correct url");
49+
let signer = LocalSigner::decrypt_keystore(
50+
config.ecdsa.private_key_store_path,
51+
config.ecdsa.private_key_store_password,
52+
)
53+
.expect("Correct keystore signer");
5854
let wallet = EthereumWallet::from(signer);
5955
let provider = ProviderBuilder::new().wallet(wallet).on_http(rpc_url);
6056
let proof_aggregation_service = AlignedProofAggregationService::new(

aggregation-mode/src/main.rs

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
use std::fs;
1+
use std::{env, fs};
22

33
use proof_aggregator::{
4-
backend::{Config, ProofAggregator},
4+
backend::{config::Config, ProofAggregator},
55
zk::{
66
backends::sp1::{vk_from_elf, SP1Proof},
77
Proof,
@@ -10,29 +10,35 @@ use proof_aggregator::{
1010
use sp1_sdk::SP1ProofWithPublicValues;
1111
use tracing_subscriber::FmtSubscriber;
1212

13+
fn read_config_filepath_from_args() -> String {
14+
let args: Vec<String> = env::args().collect();
15+
if args.len() < 2 {
16+
panic!(
17+
"You mus provide a config file. Usage: {} <config-file-path>",
18+
args[0]
19+
);
20+
}
21+
22+
args[1].clone()
23+
}
24+
1325
#[tokio::main]
1426
async fn main() {
1527
let subscriber = FmtSubscriber::builder().finish();
1628
tracing::subscriber::set_global_default(subscriber).expect("setting default subscriber failed");
1729

18-
let proofs_to_push = 2;
19-
20-
// TODO read proof aggregator yaml config file
21-
let config = Config {
22-
proof_aggregation_service_address: "0xcbEAF3BDe82155F56486Fb5a1072cb8baAf547cc".into(),
23-
private_key: "0x2a871d0798f97d79848a013d4936a73bf4cc922c825d33c1cf7073dff6d409c6".into(),
24-
rpc_url: "http://localhost:8545".into(),
25-
max_proofs_in_queue: proofs_to_push,
26-
submit_proofs_every_secs: 2,
27-
};
30+
// init proof aggregator
31+
let config_file_path = read_config_filepath_from_args();
32+
let config = Config::from_file(&config_file_path).expect("Config is valid");
2833
let mut proof_aggregator = ProofAggregator::new(config);
2934

30-
for _ in 0..proofs_to_push {
35+
// push some proofs from fs
36+
for _ in 0..2 {
3137
let sp1_proof =
32-
SP1ProofWithPublicValues::load("../scripts/test_files/sp1/sp1_fibonacci_4_1_3.proof")
38+
SP1ProofWithPublicValues::load("scripts/test_files/sp1/sp1_fibonacci_4_1_3.proof")
3339
.expect("loading proof failed");
3440
let proof_elf =
35-
fs::read("../scripts/test_files/sp1/sp1_fibonacci_4_1_3.elf").expect("elf bytes");
41+
fs::read("scripts/test_files/sp1/sp1_fibonacci_4_1_3.elf").expect("elf bytes");
3642
let proof = Proof::SP1(SP1Proof {
3743
proof: sp1_proof,
3844
vk: vk_from_elf(&proof_elf),
@@ -43,5 +49,6 @@ async fn main() {
4349
.expect("Proof to be valid");
4450
}
4551

52+
// start service
4653
proof_aggregator.start().await;
4754
}

0 commit comments

Comments
 (0)