Skip to content

Commit 2956517

Browse files
committed
Merge branch 'refs/heads/feat/aggregation-mode' into integrate-sp1-into-aggregation-mode
2 parents 5de80ab + 078a648 commit 2956517

File tree

5 files changed

+30
-21
lines changed

5 files changed

+30
-21
lines changed

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/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: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@ 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::{
1114
consensus::{Blob, BlobTransactionSidecar},
@@ -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),
@@ -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

aggregation_mode/src/backend/s3.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,23 @@ 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.get(url).send()
1524
.await
1625
.map_err(|_| GetBatchProofsError::Fetching)?;
17-
1826
if !response.status().is_success() {
1927
return Err(GetBatchProofsError::StatusFailed);
2028
}
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
aligned_service_manager_address: "0x851356ae760d987E095750cCeb3bC6014560891C"
22
proof_aggregation_service_address: "0xcbEAF3BDe82155F56486Fb5a1072cb8baAf547cc"
3-
private_key: "0x2a871d0798f97d79848a013d4936a73bf4cc922c825d33c1cf7073dff6d409c6"
43
eth_rpc_url: "http://localhost:8545"
54
eth_ws_url: "ws://localhost:8545"
65
max_proofs_in_queue: 1000
@@ -10,5 +9,5 @@ fetch_logs_from_secs_ago: 86400 # 24hs
109
block_time_secs: 7
1110

1211
ecdsa:
13-
private_key_store_path: "config-files/anvil.proof-aggregator.ecdsa.key.json"
14-
private_key_store_password: ""
12+
private_key_store_path: "config-files/anvil.proof-aggregator.ecdsa.key.json"
13+
private_key_store_password: ""

0 commit comments

Comments
 (0)