Skip to content

Commit 60bec31

Browse files
committed
refactor: update is_proof_verified_in_aggregation_mode comments
1 parent 7774c88 commit 60bec31

1 file changed

Lines changed: 25 additions & 22 deletions

File tree

batcher/aligned-sdk/src/agg_mode.rs

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use ethers::{
66
providers::{Http, Middleware, Provider},
77
types::Filter,
88
};
9-
use log::warn;
109
use sha3::{Digest, Keccak256};
1110

1211
/// How much to go back from current block if from_block is not provided
@@ -44,24 +43,24 @@ pub enum ProofVerificationAggModeError {
4443
EventDecoding,
4544
}
4645

47-
/// Given aligned verification data, this function checks whether a proof was included
46+
/// Given the [`ProofData`], this function checks whether a proof was included
4847
/// in the most recent aggregated proof and verifies the corresponding Merkle root commitment.
4948
///
5049
/// Note: This functionality is currently in Beta. As a result, we cannot determine with certainty
51-
/// which specific aggregation a proof belongs to. Instead, we optimistically check the latest one.
50+
/// which specific aggregation a proof belongs to. Instead, we optimistically check the from the specified `from_block`.
5251
///
53-
/// ⚠️ The `from` block used in the verification process must not be older than 18 days,
52+
/// Note: The `from_block` must not be older than 18 days,
5453
/// as blobs expire after that period and will no longer be retrievable.
55-
/// If not provided, it defaults to fetch logs from the past 25hs
54+
/// If not provided, it defaults to fetch logs from [`FROM_BLOCKS_AGO_DEFAULT`]
5655
///
5756
/// The step-by-step verification process includes:
58-
/// 1. Querying the blob versioned hash from the latest event emitted by the aligned proof aggregation service contract
57+
/// 1. Querying the blob versioned hash from the events emitted by the aligned proof aggregation service contract since `from_block`
5958
/// 2. Retrieving the corresponding beacon block using the block’s parent beacon root
6059
/// 3. Fetching the blobs associated with that slot
6160
/// 4. Filtering the blob that matches the queried blob versioned hash
62-
/// 5. Decoding the blob to extract the proofs
63-
/// 6. Checking if the given proof hash exists within the blob’s proofs
64-
/// 7. Reconstructing the Merkle root and verifying it against the commitment stored in the contract
61+
/// 5. Decoding the blob to extract the proofs commitments
62+
/// 6. Checking if the given proof commitment exists within the blob’s proofs
63+
/// 7. Reconstructing the Merkle root and verifying it against the root stored in the contract
6564
pub async fn is_proof_verified_in_aggregation_mode(
6665
proof_data: ProofData,
6766
network: Network,
@@ -80,7 +79,10 @@ pub async fn is_proof_verified_in_aggregation_mode(
8079
.get_block_number()
8180
.await
8281
.map_err(|e| ProofVerificationAggModeError::EthereumProviderError(e.to_string()))?;
83-
block_number.as_u64() - FROM_BLOCKS_AGO_DEFAULT
82+
83+
block_number
84+
.as_u64()
85+
.saturating_sub(FROM_BLOCKS_AGO_DEFAULT)
8486
}
8587
};
8688

@@ -119,24 +121,24 @@ pub async fn is_proof_verified_in_aggregation_mode(
119121
continue;
120122
};
121123

122-
let Some(blob) = beacon_client
123-
.get_blob_by_versioned_hash(
124-
beacon_block
125-
.header
126-
.message
127-
.slot
128-
.parse()
129-
.expect("Slot to be parsable number"),
130-
blob_versioned_hash,
131-
)
124+
let slot: u64 = beacon_block
125+
.header
126+
.message
127+
.slot
128+
.parse()
129+
.expect("Slot to be parsable number");
130+
131+
let Some(blob_data) = beacon_client
132+
.get_blob_by_versioned_hash(slot, blob_versioned_hash)
132133
.await
133134
.map_err(ProofVerificationAggModeError::BeaconClient)?
134135
else {
135136
continue;
136137
};
137138

138-
let blob_data = hex::decode(blob.blob.replace("0x", "")).expect("A valid hex encoded data");
139-
let proof_commitments = decoded_blob(blob_data);
139+
let blob_bytes =
140+
hex::decode(blob_data.blob.replace("0x", "")).expect("A valid hex encoded data");
141+
let proof_commitments = decoded_blob(blob_bytes);
140142

141143
if proof_commitments.contains(&proof_data.commitment()) {
142144
if verify_blob_merkle_root(proof_commitments, merkle_root) {
@@ -170,6 +172,7 @@ fn decoded_blob(blob_data: Vec<u8>) -> Vec<[u8; 32]> {
170172
current_hash[current_hash_count] = blob_data[total_bytes_count];
171173

172174
if current_hash_count + 1 == 32 {
175+
// if the current_hash is the zero hash, then there are no more proofs in the blob
173176
if current_hash == [0u8; 32] {
174177
break;
175178
}

0 commit comments

Comments
 (0)