Skip to content

Commit 6831ab4

Browse files
committed
Merge remote-tracking branch 'origin/staging' into feat/aggregation-mode-explorer
2 parents 7ad8641 + 43a1084 commit 6831ab4

File tree

69 files changed

+6425
-1999
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+6425
-1999
lines changed

Makefile

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ CONFIG_FILE?=config-files/config.yaml
77
export OPERATOR_ADDRESS ?= $(shell yq -r '.operator.address' $(CONFIG_FILE))
88
AGG_CONFIG_FILE?=config-files/config-aggregator.yaml
99

10-
OPERATOR_VERSION=v0.15.0
10+
OPERATOR_VERSION=v0.15.1
1111
EIGEN_SDK_GO_VERSION_TESTNET=v0.2.0-beta.1
1212
EIGEN_SDK_GO_VERSION_MAINNET=v0.1.13
1313

@@ -20,8 +20,8 @@ ifeq ($(OS),Darwin)
2020
endif
2121

2222
ifeq ($(OS),Linux)
23-
export LD_LIBRARY_PATH+=$(CURDIR)/operator/risc_zero/lib
24-
OPERATOR_FFIS=$(CURDIR)/operator/risc_zero/lib
23+
export LD_LIBRARY_PATH+=$(CURDIR)/operator/risc_zero/lib:$(CURDIR)/operator/sp1/lib
24+
OPERATOR_FFIS=$(CURDIR)/operator/risc_zero/lib:$(CURDIR)/operator/sp1/lib
2525
endif
2626

2727
ifeq ($(OS),Linux)
@@ -150,11 +150,11 @@ anvil_start_with_block_time_with_more_prefunded_accounts:
150150
@echo "Starting Anvil..."
151151
anvil --load-state contracts/scripts/anvil/state/alignedlayer-deployed-anvil-state.json --block-time 7 -a 2000
152152

153-
__AGGREGATION_MODE__:
154-
start_proof_aggregator_local:
153+
__AGGREGATION_MODE__: ## ____
154+
start_proof_aggregator_local: ## Start the proof aggregator locally using Mock Verifier Contract
155155
cargo run --manifest-path ./aggregation_mode/Cargo.toml --release -- config-files/config-proof-aggregator.yaml
156156

157-
start_proof_aggregator_local_with_proving:
157+
start_proof_aggregator_local_with_proving: ## Start the proof aggregator locally using SP1 Verifier Contract
158158
cargo run --manifest-path ./aggregation_mode/Cargo.toml --release --features prove -- config-files/config-proof-aggregator.yaml
159159

160160
_AGGREGATOR_:
@@ -425,19 +425,19 @@ batcher_send_risc0_task:
425425
@echo "Sending Risc0 fibonacci task to Batcher..."
426426
@cd batcher/aligned/ && cargo run --release -- submit \
427427
--proving_system Risc0 \
428-
--proof ../../scripts/test_files/risc_zero/fibonacci_proof_generator/risc_zero_fibonacci.proof \
429-
--vm_program ../../scripts/test_files/risc_zero/fibonacci_proof_generator/fibonacci_id.bin \
430-
--public_input ../../scripts/test_files/risc_zero/fibonacci_proof_generator/risc_zero_fibonacci.pub \
428+
--proof ../../scripts/test_files/risc_zero/fibonacci_proof_generator/risc_zero_fibonacci_2_0.proof \
429+
--vm_program ../../scripts/test_files/risc_zero/fibonacci_proof_generator/fibonacci_id_2_0.bin \
430+
--public_input ../../scripts/test_files/risc_zero/fibonacci_proof_generator/risc_zero_fibonacci_2_0.pub \
431431
--proof_generator_addr 0x66f9664f97F2b50F62D13eA064982f936dE76657 \
432432
--rpc_url $(RPC_URL) \
433433
--network $(NETWORK)
434434

435435
batcher_send_risc0_task_no_pub_input:
436-
@echo "Sending Risc0 fibonacci task to Batcher..."
436+
@echo "Sending Risc0 no pub input task to Batcher..."
437437
@cd batcher/aligned/ && cargo run --release -- submit \
438438
--proving_system Risc0 \
439-
--proof ../../scripts/test_files/risc_zero/no_public_inputs/risc_zero_no_pub_input.proof \
440-
--vm_program ../../scripts/test_files/risc_zero/no_public_inputs/no_pub_input_id.bin \
439+
--proof ../../scripts/test_files/risc_zero/no_public_inputs/risc_zero_no_pub_input_2_0.proof \
440+
--vm_program ../../scripts/test_files/risc_zero/no_public_inputs/no_pub_input_id_2_0.bin \
441441
--proof_generator_addr 0x66f9664f97F2b50F62D13eA064982f936dE76657 \
442442
--rpc_url $(RPC_URL) \
443443
--network $(NETWORK)
@@ -446,9 +446,9 @@ batcher_send_risc0_burst:
446446
@echo "Sending Risc0 fibonacci task to Batcher..."
447447
@cd batcher/aligned/ && cargo run --release -- submit \
448448
--proving_system Risc0 \
449-
--proof ../../scripts/test_files/risc_zero/fibonacci_proof_generator/risc_zero_fibonacci.proof \
450-
--vm_program ../../scripts/test_files/risc_zero/fibonacci_proof_generator/fibonacci_id.bin \
451-
--public_input ../../scripts/test_files/risc_zero/fibonacci_proof_generator/risc_zero_fibonacci.pub \
449+
--proof ../../scripts/test_files/risc_zero/fibonacci_proof_generator/risc_zero_fibonacci_2_0.proof \
450+
--vm_program ../../scripts/test_files/risc_zero/fibonacci_proof_generator/fibonacci_id_2_0.bin \
451+
--public_input ../../scripts/test_files/risc_zero/fibonacci_proof_generator/risc_zero_fibonacci_2_0.pub \
452452
--repetitions $(BURST_SIZE) \
453453
--proof_generator_addr 0x66f9664f97F2b50F62D13eA064982f936dE76657 \
454454
--rpc_url $(RPC_URL) \
@@ -952,9 +952,9 @@ docker_batcher_send_risc0_burst:
952952
docker exec $(shell docker ps | grep batcher | awk '{print $$1}') aligned submit \
953953
--private_key $(DOCKER_PROOFS_PRIVATE_KEY) \
954954
--proving_system Risc0 \
955-
--proof ./scripts/test_files/risc_zero/fibonacci_proof_generator/risc_zero_fibonacci.proof \
956-
--vm_program ./scripts/test_files/risc_zero/fibonacci_proof_generator/fibonacci_id.bin \
957-
--public_input ./scripts/test_files/risc_zero/fibonacci_proof_generator/risc_zero_fibonacci.pub \
955+
--proof ./scripts/test_files/risc_zero/fibonacci_proof_generator/risc_zero_fibonacci_2_0.proof \
956+
--vm_program ./scripts/test_files/risc_zero/fibonacci_proof_generator/fibonacci_id_2_0.bin \
957+
--public_input ./scripts/test_files/risc_zero/fibonacci_proof_generator/risc_zero_fibonacci_2_0.pub \
958958
--repetitions $(DOCKER_BURST_SIZE) \
959959
--proof_generator_addr $(PROOF_GENERATOR_ADDRESS) \
960960
--rpc_url $(DOCKER_RPC_URL) \

aggregation_mode/Cargo.lock

Lines changed: 18 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: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ serde_json = "1.0.117"
1212
serde_yaml = "0.9"
1313
tracing = { version = "0.1", features = ["log"] }
1414
tracing-subscriber = { version = "0.3.0", features = ["env-filter"] }
15-
alloy = { version = "0.11", features = ["default", "signer-keystore"] }
15+
alloy = { version = "0.11", features = ["default", "signer-keystore", "kzg"] }
1616
c-kzg = "1.0.3"
1717
bincode = "1.3.3"
1818
tokio = { version = "1", features = ["time"]}
@@ -27,7 +27,6 @@ sp1-build = { version = "4.1.3" }
2727

2828
[profile.release]
2929
opt-level = 3
30-
lto = true
3130

3231
[features]
3332
prove = []

aggregation_mode/README.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
2+
# Aligned aggregation mode
3+
4+
## How to run it locally
5+
6+
1. Deploy aligned contracts on anvil:
7+
8+
```shell
9+
make deploy_aligned_contracts
10+
```
11+
12+
2. Start anvil:
13+
14+
```shell
15+
make anvil_start_with_block_time
16+
```
17+
18+
3. Start batcher
19+
20+
```shell
21+
make start_batcher_local
22+
```
23+
24+
4. Send SP1 proofs:
25+
26+
```shell
27+
make batcher_send_sp1_burst
28+
```
29+
30+
5. Start proof aggregator:
31+
32+
```shell
33+
# This will not run a real prover but a mocked one see below to run a real prover
34+
make start_proof_aggregator_local
35+
```
36+
37+
or
38+
39+
```shell
40+
make start_proof_aggregator_local_with_proving
41+
```
42+
43+
Note: Proving can be quite slow without GPUs
44+
45+
### Check the logs
46+
47+
1. Get latest aggregated proof:
48+
49+
```shell
50+
cast call 0xcbEAF3BDe82155F56486Fb5a1072cb8baAf547cc "currentAggregatedProofNumber()" --rpc-url http://localhost:8545
51+
```
52+
53+
2. Get aggregated proof info:
54+
55+
```shell
56+
cast call 0xcbEAF3BDe82155F56486Fb5a1072cb8baAf547cc "getAggregatedProof(uint64)(uint8,bytes32,bytes32)" <AGG_PROOF_NUMBER> --rpc-url http://localhost:8545
57+
```

aggregation_mode/src/backend/config.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ pub struct ECDSAConfig {
1111
pub struct Config {
1212
pub eth_rpc_url: String,
1313
pub eth_ws_url: String,
14-
pub private_key: String,
1514
pub max_proofs_in_queue: u16,
1615
pub proof_aggregation_service_address: String,
1716
pub aligned_service_manager_address: String,

aggregation_mode/src/backend/fetcher.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ use super::{
55
types::{AlignedLayerServiceManager, AlignedLayerServiceManagerContract, RPCProvider},
66
};
77
use crate::{
8-
aggregators::{sp1_aggregator::SP1ProofWithPubValuesAndElf, AlignedProof}, backend::s3::get_aligned_batch_from_s3
8+
aggregators::{sp1_aggregator::SP1ProofWithPubValuesAndElf, AlignedProof},
9+
backend::s3::get_aligned_batch_from_s3,
910
};
1011
use aligned_sdk::core::types::ProvingSystemId;
1112
use alloy::{
@@ -29,11 +30,11 @@ pub struct ProofsFetcher {
2930

3031
impl ProofsFetcher {
3132
pub fn new(config: &Config) -> Self {
32-
let rpc_url = config.eth_rpc_url.parse().expect("correct url");
33+
let rpc_url = config.eth_rpc_url.parse().expect("RPC URL should be valid");
3334
let rpc_provider = ProviderBuilder::new().on_http(rpc_url);
3435
let aligned_service_manager = AlignedLayerServiceManager::new(
3536
Address::from_str(&config.aligned_service_manager_address)
36-
.expect("Address to be correct"),
37+
.expect("AlignedProofAggregationService address should be valid"),
3738
rpc_provider.clone(),
3839
);
3940

@@ -88,7 +89,10 @@ impl ProofsFetcher {
8889
ProvingSystemId::SP1 => {
8990
let elf = p.vm_program_code?;
9091
let proof_with_pub_values = bincode::deserialize(&p.proof).ok()?;
91-
let sp1_proof = SP1ProofWithPubValuesAndElf { proof_with_pub_values, elf };
92+
let sp1_proof = SP1ProofWithPubValuesAndElf {
93+
proof_with_pub_values,
94+
elf,
95+
};
9296

9397
Some(AlignedProof::SP1(sp1_proof))
9498
}

aggregation_mode/src/backend/merkle_tree.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,7 @@ pub fn combine_hashes(hash_a: &[u8; 32], hash_b: &[u8; 32]) -> [u8; 32] {
1010

1111
/// Returns (merkle_root, leaves)
1212
pub fn compute_proofs_merkle_root(proofs: &[AlignedProof]) -> ([u8; 32], Vec<[u8; 32]>) {
13-
let leaves: Vec<[u8; 32]> = proofs
14-
.chunks(2)
15-
.map(|chunk| match chunk {
16-
[a, b] => combine_hashes(&a.hash(), &b.hash()),
17-
[a] => combine_hashes(&a.hash(), &a.hash()),
18-
_ => panic!("Unexpected chunk leaves"),
19-
})
20-
.collect();
13+
let leaves: Vec<[u8; 32]> = proofs.iter().map(|proof| proof.hash()).collect();
2114

2215
let mut root = leaves.clone();
2316

aggregation_mode/src/backend/mod.rs

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,18 @@ mod merkle_tree;
44
mod s3;
55
mod types;
66

7-
use crate::aggregators::{lib::{AggregatedProof, ProofAggregationError}, sp1_aggregator::{aggregate_proofs, SP1AggregationInput}, AlignedProof, ZKVMEngine};
8-
7+
use crate::aggregators::{
8+
lib::{AggregatedProof, ProofAggregationError},
9+
sp1_aggregator::{aggregate_proofs, SP1AggregationInput},
10+
AlignedProof, ZKVMEngine,
11+
};
912

1013
use alloy::{
11-
consensus::{Blob, BlobTransactionSidecar},
14+
consensus::BlobTransactionSidecar,
1215
eips::eip4844::BYTES_PER_BLOB,
1316
hex,
1417
network::EthereumWallet,
15-
primitives::{Address, FixedBytes},
18+
primitives::Address,
1619
providers::{PendingTransactionError, ProviderBuilder},
1720
rpc::types::TransactionReceipt,
1821
signers::local::LocalSigner,
@@ -25,7 +28,6 @@ use std::str::FromStr;
2528
use tracing::{error, info, warn};
2629
use types::{AlignedProofAggregationService, AlignedProofAggregationServiceContract};
2730

28-
2931
#[derive(Debug)]
3032
pub enum AggregatedProofSubmissionError {
3133
Aggregation(ProofAggregationError),
@@ -45,17 +47,17 @@ pub struct ProofAggregator {
4547

4648
impl ProofAggregator {
4749
pub fn new(config: &Config) -> Self {
48-
let rpc_url = config.eth_rpc_url.parse().expect("correct url");
50+
let rpc_url = config.eth_rpc_url.parse().expect("RPC URL should be valid");
4951
let signer = LocalSigner::decrypt_keystore(
5052
config.ecdsa.private_key_store_path.clone(),
5153
config.ecdsa.private_key_store_password.clone(),
5254
)
53-
.expect("Correct keystore signer");
55+
.expect("Keystore signer should be `cast wallet` compliant");
5456
let wallet = EthereumWallet::from(signer);
5557
let rpc_provider = ProviderBuilder::new().wallet(wallet).on_http(rpc_url);
56-
let proof_aggregation_service: AlignedProofAggregationService::AlignedProofAggregationServiceInstance<(), alloy::providers::fillers::FillProvider<alloy::providers::fillers::JoinFill<alloy::providers::fillers::JoinFill<alloy::providers::Identity, alloy::providers::fillers::JoinFill<alloy::providers::fillers::GasFiller, alloy::providers::fillers::JoinFill<alloy::providers::fillers::BlobGasFiller, alloy::providers::fillers::JoinFill<alloy::providers::fillers::NonceFiller, alloy::providers::fillers::ChainIdFiller>>>>, alloy::providers::fillers::WalletFiller<EthereumWallet>>, alloy::providers::RootProvider>> = AlignedProofAggregationService::new(
58+
let proof_aggregation_service = AlignedProofAggregationService::new(
5759
Address::from_str(&config.proof_aggregation_service_address)
58-
.expect("Address to be correct"),
60+
.expect("AlignedProofAggregationService address should be valid"),
5961
rpc_provider,
6062
);
6163
let fetcher = ProofsFetcher::new(config);
@@ -122,8 +124,7 @@ impl ProofAggregator {
122124
merkle_root,
123125
};
124126

125-
aggregate_proofs(input)
126-
.map_err(AggregatedProofSubmissionError::Aggregation)?
127+
aggregate_proofs(input).map_err(AggregatedProofSubmissionError::Aggregation)?
127128
}
128129
};
129130
info!("Proof aggregation program finished");
@@ -184,8 +185,17 @@ impl ProofAggregator {
184185
let data: Vec<u8> = leaves.iter().flat_map(|arr| arr.iter().copied()).collect();
185186
let mut blob_data: [u8; BYTES_PER_BLOB] = [0u8; BYTES_PER_BLOB];
186187

187-
for (i, byte) in data.iter().enumerate() {
188-
blob_data[i] = *byte;
188+
// We pad the data with 0x0 byte every 31 bytes so that the field elements
189+
// constructed from the bytes are less than BLS_MODULUS.
190+
//
191+
// See https://github.com/ethereum/consensus-specs/blob/86fb82b221474cc89387fa6436806507b3849d88/specs/deneb/polynomial-commitments.md#bytes_to_bls_field
192+
let mut offset = 0;
193+
for chunk in data.chunks(31) {
194+
blob_data[offset] = 0x00;
195+
let start = offset + 1;
196+
let end = start + chunk.len();
197+
blob_data[start..end].copy_from_slice(chunk);
198+
offset += 32;
189199
}
190200

191201
// calculate kzg commitments for blob
@@ -197,12 +207,11 @@ impl ProofAggregator {
197207
c_kzg::KzgProof::compute_blob_kzg_proof(&blob, &commitment.to_bytes(), settings)
198208
.map_err(|_| AggregatedProofSubmissionError::BuildingBlobProof)?;
199209

200-
// convert to alloy types
201-
let blob = Blob::from_slice(&blob_data);
202-
let commitment: FixedBytes<48> = FixedBytes::from_slice(commitment.to_bytes().as_slice());
203-
let proof: FixedBytes<48> = FixedBytes::from_slice(proof.to_bytes().as_slice());
204-
205-
let blob = BlobTransactionSidecar::new(vec![blob], vec![commitment], vec![proof]);
210+
let blob = BlobTransactionSidecar::from_kzg(
211+
vec![blob],
212+
vec![commitment.to_bytes()],
213+
vec![proof.to_bytes()],
214+
);
206215
let blob_versioned_hash = blob
207216
.versioned_hash_for_blob(0)
208217
.ok_or(AggregatedProofSubmissionError::BuildingBlobVersionedHash)?

aggregation_mode/src/backend/s3.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,25 @@ pub enum GetBatchProofsError {
66
Deserialization,
77
EmptyBody,
88
StatusFailed,
9+
ReqwestClientFailed,
910
}
1011

12+
// needed to make S3 bucket work
13+
const DEFAULT_USER_AGENT: &str = "proof-aggregator/aligned-layer";
14+
1115
pub async fn get_aligned_batch_from_s3(
1216
url: String,
1317
) -> Result<Vec<VerificationData>, GetBatchProofsError> {
14-
let response = reqwest::get(url)
18+
let client = reqwest::Client::builder()
19+
.user_agent(DEFAULT_USER_AGENT)
20+
.build()
21+
.map_err(|_| GetBatchProofsError::ReqwestClientFailed)?;
22+
23+
let response = client
24+
.get(url)
25+
.send()
1526
.await
1627
.map_err(|_| GetBatchProofsError::Fetching)?;
17-
1828
if !response.status().is_success() {
1929
return Err(GetBatchProofsError::StatusFailed);
2030
}

0 commit comments

Comments
 (0)