Skip to content

Commit daf0344

Browse files
feat(aggregation): have constant costs proof sending (#2179)
Co-authored-by: Marcos Nicolau <[email protected]>
1 parent 75a88de commit daf0344

File tree

9 files changed

+347
-7
lines changed

9 files changed

+347
-7
lines changed

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,9 @@ proof_aggregator_start_dev: is_aggregator_set reset_last_aggregated_block ./aggr
252252
proof_aggregator_start_dev_ethereum_package: is_aggregator_set reset_last_aggregated_block ./aggregation_mode/target/release/proof_aggregator_dev ## Starts proof aggregator with mock proofs (DEV mode) in ethereum package. Parameters: AGGREGATOR=<sp1|risc0>
253253
AGGREGATOR=$(AGGREGATOR) RISC0_DEV_MODE=1 ./aggregation_mode/target/release/proof_aggregator_dev config-files/config-proof-aggregator-mock-ethereum-package.yaml
254254

255+
proof_aggregator_test_without_compiling_agg_programs:
256+
cd aggregation_mode && SKIP_AGG_PROGRAMS_BUILD=1 cargo test -p proof_aggregator --tests -- --nocapture
257+
255258
### All CPU proof aggregator receipts
256259
./aggregation_mode/target/release/proof_aggregator_cpu: $(AGGREGATION_MODE_SOURCES)
257260
AGGREGATOR=$(AGGREGATOR) cargo build --features prove --manifest-path ./aggregation_mode/Cargo.toml --release --bin proof_aggregator_cpu

aggregation_mode/proof_aggregator/build.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,32 @@
11
use risc0_build::{DockerOptionsBuilder, GuestOptionsBuilder};
22
use std::collections::HashMap;
3+
use std::path::PathBuf;
4+
5+
// This allows us to skip the guest build in CI or local environments where it's not needed (reducing the build time)
6+
// Note: To use this flag, the aggregation programs should be already compiled, otherwise the compilation will be done anyway.
7+
fn should_skip_build() -> bool {
8+
if std::env::var("SKIP_AGG_PROGRAMS_BUILD")
9+
.map(|v| v == "1")
10+
.unwrap_or(false)
11+
{
12+
let out_dir = std::env::var("OUT_DIR").unwrap();
13+
let methods_path = PathBuf::from(out_dir).join("methods.rs");
14+
15+
methods_path.exists()
16+
} else {
17+
false
18+
}
19+
}
320

421
// Reference: https://docs.succinct.xyz/docs/sp1/writing-programs/compiling#advanced-build-options-1
522
fn main() {
23+
if should_skip_build() {
24+
println!("cargo:warning=SKIP_AGG_PROGRAMS_BUILD=1: methods.rs already exists, skipping aggregation programs build");
25+
return;
26+
} else {
27+
println!("cargo:warning=SKIP_AGG_PROGRAMS_BUILD=1 set, but path does not exist, running full build");
28+
}
29+
630
sp1_build::build_program_with_args("./aggregation_programs/sp1", {
731
sp1_build::BuildArgs {
832
output_directory: Some("./aggregation_programs/sp1/elf".to_string()),

aggregation_mode/proof_aggregator/src/backend/config.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ pub struct Config {
2323
pub ecdsa: ECDSAConfig,
2424
pub proofs_per_chunk: u16,
2525
pub total_proofs_limit: u16,
26-
pub sp1_chunk_aggregator_vk_hash: String,
2726
pub risc0_chunk_aggregator_image_id: String,
27+
pub sp1_chunk_aggregator_vk_hash: String,
28+
pub monthly_budget_eth: f64,
2829
}
2930

3031
impl Config {

aggregation_mode/proof_aggregator/src/backend/fetcher.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,25 @@ pub struct ProofsFetcher {
3333
}
3434

3535
impl ProofsFetcher {
36+
#[cfg(test)]
37+
pub fn new_for_testing(config: &Config) -> Self {
38+
let rpc_url = config.eth_rpc_url.parse().expect("RPC URL should be valid");
39+
let rpc_provider = ProviderBuilder::new().connect_http(rpc_url);
40+
let aligned_service_manager = AlignedLayerServiceManager::new(
41+
Address::from_str(&config.aligned_service_manager_address)
42+
.expect("AlignedProofAggregationService address should be valid"),
43+
rpc_provider.clone(),
44+
);
45+
46+
let last_aggregated_block = 0;
47+
48+
Self {
49+
rpc_provider,
50+
aligned_service_manager,
51+
last_aggregated_block,
52+
}
53+
}
54+
3655
pub fn new(config: &Config) -> Self {
3756
let rpc_url = config.eth_rpc_url.parse().expect("RPC URL should be valid");
3857
let rpc_provider = ProviderBuilder::new().connect_http(rpc_url);

0 commit comments

Comments
 (0)