Skip to content

Commit 28757e0

Browse files
committed
feat: attach blob to contract transaction instead of being separate
1 parent 7efb80e commit 28757e0

File tree

2 files changed

+27
-56
lines changed

2 files changed

+27
-56
lines changed

aggregation-mode/src/backend/mod.rs

Lines changed: 27 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ use alloy::{
1313
consensus::{Blob, BlobTransactionSidecar},
1414
eips::eip4844::BYTES_PER_BLOB,
1515
hex,
16-
network::{EthereumWallet, TransactionBuilder4844},
16+
network::EthereumWallet,
1717
primitives::{Address, FixedBytes},
18-
providers::{PendingTransactionError, Provider, ProviderBuilder, WalletProvider},
19-
rpc::types::{TransactionReceipt, TransactionRequest},
18+
providers::{PendingTransactionError, ProviderBuilder},
19+
rpc::types::TransactionReceipt,
2020
signers::local::LocalSigner,
2121
};
2222
use config::Config;
@@ -25,22 +25,21 @@ use merkle_tree::compute_proofs_merkle_root;
2525
use sp1_sdk::HashableKey;
2626
use std::str::FromStr;
2727
use tracing::{error, info, warn};
28-
use types::{
29-
AlignedProofAggregationService, AlignedProofAggregationServiceContract, RPCProviderWithSigner,
30-
};
28+
use types::{AlignedProofAggregationService, AlignedProofAggregationServiceContract};
3129

3230
#[derive(Debug)]
3331
pub enum AggregatedProofSubmissionError {
3432
Aggregation(ProofAggregationError),
35-
SendBlobTransaction,
33+
BuildingBlobCommitment,
34+
BuildingBlobProof,
35+
BuildingBlobVersionedHash,
3636
SendVerifyAggregatedProofTransaction(alloy::contract::Error),
3737
ReceiptError(PendingTransactionError),
3838
FetchingProofs(ProofsFetcherError),
3939
}
4040

4141
pub struct ProofAggregator {
4242
engine: ZKVMEngine,
43-
rpc_provider: RPCProviderWithSigner,
4443
proof_aggregation_service: AlignedProofAggregationServiceContract,
4544
fetcher: ProofsFetcher,
4645
}
@@ -58,15 +57,14 @@ impl ProofAggregator {
5857
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(
5958
Address::from_str(&config.proof_aggregation_service_address)
6059
.expect("Address to be correct"),
61-
rpc_provider.clone(),
60+
rpc_provider,
6261
);
6362
let fetcher = ProofsFetcher::new(config);
6463

6564
Self {
6665
engine: ZKVMEngine::SP1,
6766
proof_aggregation_service,
6867
fetcher,
69-
rpc_provider,
7068
}
7169
}
7270

@@ -131,16 +129,16 @@ impl ProofAggregator {
131129
};
132130
info!("Proof aggregation program finished");
133131

134-
info!("Sending blob transaction...");
135-
let blob_receipt = self.send_blob_transaction(leaves).await?;
132+
info!("Constructing blob...");
133+
let (blob, blob_versioned_hash) = self.construct_blob(leaves).await?;
136134
info!(
137-
"Blob transaction sent, hash: {:?}",
138-
blob_receipt.transaction_hash
135+
"Blob constructed, versioned hash: {}",
136+
hex::encode(blob_versioned_hash)
139137
);
140138

141139
info!("Sending proof to ProofAggregationService contract...");
142140
let receipt = self
143-
.send_proof_to_verify_on_chain(&blob_receipt.transaction_hash, output.proof)
141+
.send_proof_to_verify_on_chain(blob, blob_versioned_hash, output.proof)
144142
.await?;
145143
info!(
146144
"Proof sent and verified, tx hash {:?}",
@@ -152,19 +150,21 @@ impl ProofAggregator {
152150

153151
async fn send_proof_to_verify_on_chain(
154152
&self,
155-
blob_tx_hash: &[u8; 32],
153+
blob: BlobTransactionSidecar,
154+
blob_versioned_hash: [u8; 32],
156155
aggregated_proof: AggregatedProof,
157156
) -> Result<TransactionReceipt, AggregatedProofSubmissionError> {
158157
match aggregated_proof {
159158
AggregatedProof::SP1(proof) => {
160159
let res = self
161160
.proof_aggregation_service
162161
.verify(
163-
blob_tx_hash.into(),
162+
blob_versioned_hash.into(),
164163
proof.vk().bytes32_raw().into(),
165164
proof.proof.public_values.to_vec().into(),
166165
proof.proof.bytes().into(),
167166
)
167+
.sidecar(blob)
168168
.send()
169169
.await
170170
.map_err(
@@ -178,10 +178,10 @@ impl ProofAggregator {
178178
}
179179
}
180180

181-
async fn send_blob_transaction(
181+
async fn construct_blob(
182182
&self,
183183
leaves: Vec<[u8; 32]>,
184-
) -> Result<TransactionReceipt, AggregatedProofSubmissionError> {
184+
) -> Result<(BlobTransactionSidecar, [u8; 32]), AggregatedProofSubmissionError> {
185185
let data: Vec<u8> = leaves.iter().flat_map(|arr| arr.iter().copied()).collect();
186186
let mut blob_data: [u8; BYTES_PER_BLOB] = [0u8; BYTES_PER_BLOB];
187187

@@ -193,32 +193,23 @@ impl ProofAggregator {
193193
let settings = c_kzg::ethereum_kzg_settings();
194194
let blob = c_kzg::Blob::new(blob_data);
195195
let commitment = c_kzg::KzgCommitment::blob_to_kzg_commitment(&blob, settings)
196-
.map_err(|_| AggregatedProofSubmissionError::SendBlobTransaction)?;
196+
.map_err(|_| AggregatedProofSubmissionError::BuildingBlobCommitment)?;
197197
let proof =
198198
c_kzg::KzgProof::compute_blob_kzg_proof(&blob, &commitment.to_bytes(), settings)
199-
.map_err(|_| AggregatedProofSubmissionError::SendBlobTransaction)?;
199+
.map_err(|_| AggregatedProofSubmissionError::BuildingBlobProof)?;
200200

201201
// convert to alloy types
202202
let blob = Blob::from_slice(&blob_data);
203203
let commitment: FixedBytes<48> = FixedBytes::from_slice(commitment.to_bytes().as_slice());
204204
let proof: FixedBytes<48> = FixedBytes::from_slice(proof.to_bytes().as_slice());
205205

206-
let blob_sidecar = BlobTransactionSidecar::new(vec![blob], vec![commitment], vec![proof]);
207-
// send transaction to itself
208-
let to = self.rpc_provider.signer_addresses().collect::<Vec<_>>()[0];
209-
let tx = TransactionRequest::default()
210-
.to(to)
211-
.with_blob_sidecar(blob_sidecar);
212-
213-
let res = self
214-
.rpc_provider
215-
.send_transaction(tx)
216-
.await
217-
.map_err(|_| AggregatedProofSubmissionError::SendBlobTransaction)?;
206+
let blob = BlobTransactionSidecar::new(vec![blob], vec![commitment], vec![proof]);
207+
let blob_versioned_hash = blob
208+
.versioned_hash_for_blob(0)
209+
.ok_or(AggregatedProofSubmissionError::BuildingBlobVersionedHash)?
210+
.0;
218211

219-
res.get_receipt()
220-
.await
221-
.map_err(AggregatedProofSubmissionError::ReceiptError)
212+
Ok((blob, blob_versioned_hash))
222213
}
223214

224215
async fn set_aggregated_proof_as_missed(

aggregation-mode/src/backend/types.rs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -65,23 +65,3 @@ pub type RPCProvider = alloy::providers::fillers::FillProvider<
6565
>,
6666
alloy::providers::RootProvider,
6767
>;
68-
69-
pub type RPCProviderWithSigner = alloy::providers::fillers::FillProvider<
70-
alloy::providers::fillers::JoinFill<
71-
alloy::providers::fillers::JoinFill<
72-
alloy::providers::Identity,
73-
alloy::providers::fillers::JoinFill<
74-
alloy::providers::fillers::GasFiller,
75-
alloy::providers::fillers::JoinFill<
76-
alloy::providers::fillers::BlobGasFiller,
77-
alloy::providers::fillers::JoinFill<
78-
alloy::providers::fillers::NonceFiller,
79-
alloy::providers::fillers::ChainIdFiller,
80-
>,
81-
>,
82-
>,
83-
>,
84-
alloy::providers::fillers::WalletFiller<EthereumWallet>,
85-
>,
86-
alloy::providers::RootProvider,
87-
>;

0 commit comments

Comments
 (0)