Skip to content

Commit ab20668

Browse files
committed
feat: default from_block to 24hs ago if not provided
1 parent 4192543 commit ab20668

2 files changed

Lines changed: 28 additions & 13 deletions

File tree

batcher/aligned-sdk/src/agg_mode.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ use ethers::{
88
};
99
use sha3::{Digest, Keccak256};
1010

11+
/// How much to go back from current block if from_block is not provided
12+
/// 7500 blocks = 25hr
13+
const FROM_BLOCKS_AGO_DEFAULT: u64 = 7500;
14+
1115
#[derive(Debug)]
1216
pub enum ProofVerificationAggModeError {
1317
ProvingSystemNotSupportedInAggMode,
@@ -26,6 +30,7 @@ pub enum ProofVerificationAggModeError {
2630
///
2731
/// ⚠️ The `from` block used in the verification process must not be older than 18 days,
2832
/// as blobs expire after that period and will no longer be retrievable.
33+
/// If not provided, it defaults to fetch logs from the past 25hs
2934
///
3035
/// The step-by-step verification process includes:
3136
/// 1. Querying the blob versioned hash from the latest event emitted by the aligned proof aggregation service contract
@@ -40,12 +45,23 @@ pub async fn is_proof_verified_in_aggregation_mode(
4045
network: Network,
4146
eth_rpc_url: String,
4247
beacon_client_url: String,
43-
from_block: u64,
48+
from_block: Option<u64>,
4449
) -> Result<[u8; 32], ProofVerificationAggModeError> {
4550
let eth_rpc_provider = Provider::<Http>::try_from(eth_rpc_url)
4651
.map_err(|e| ProofVerificationAggModeError::EthereumProviderError(e.to_string()))?;
4752
let beacon_client = BeaconClient::new(beacon_client_url);
4853

54+
let from_block = match from_block {
55+
Some(from_block) => from_block,
56+
None => {
57+
let block_number = eth_rpc_provider
58+
.get_block_number()
59+
.await
60+
.map_err(|e| ProofVerificationAggModeError::EthereumProviderError(e.to_string()))?;
61+
block_number.as_u64() - FROM_BLOCKS_AGO_DEFAULT
62+
}
63+
};
64+
4965
let filter = Filter::new()
5066
.address(network.get_aligned_proof_agg_service_address())
5167
.event("AggregatedProofVerified(bytes32,bytes32)")
@@ -111,7 +127,7 @@ pub async fn is_proof_verified_in_aggregation_mode(
111127
}
112128
}
113129

114-
return Err(ProofVerificationAggModeError::ProofNotFoundInLogs);
130+
Err(ProofVerificationAggModeError::ProofNotFoundInLogs)
115131
}
116132

117133
fn decoded_blob(blob_data: Vec<u8>) -> Vec<[u8; 32]> {

batcher/aligned/src/main.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -289,20 +289,19 @@ pub struct VerifyProofInAggModeArgs {
289289
#[arg(
290290
name = "Ethereum RPC provider url",
291291
long = "rpc_url",
292-
default_value = "https://ethereum-holesky-rpc.publicnode.com"
292+
default_value = "http://localhost:8545"
293293
)]
294294
eth_rpc_url: String,
295-
#[arg(
296-
name = "Ethereum Beacon client url",
297-
long = "beacon_url",
298-
default_value = "http://100.90.212.34:5052"
299-
)]
295+
#[arg(name = "Ethereum Beacon client url", long = "beacon_url")]
300296
beacon_client_url: String,
301-
#[arg(name = "Proof Hash", long = "proof-hash")]
302-
proof_hash: String,
297+
#[arg(name = "Proof commitment", long = "proof-commitment")]
298+
proof_commitment: String,
303299
#[clap(flatten)]
304300
network: NetworkArg,
305-
#[arg(name = "From which block to start", long = "from-block")]
301+
#[arg(
302+
name = "From which block to start, if not provided it defaults to fetch logs from the past 25hs",
303+
long = "from-block"
304+
)]
306305
from_block: Option<u64>,
307306
}
308307

@@ -759,7 +758,7 @@ async fn main() -> Result<(), AlignedError> {
759758
return Ok(());
760759
}
761760
AlignedCommands::VerifyProofInAggMode(args) => {
762-
let proof_hash_bytes: [u8; 32] = hex::decode(args.proof_hash.replace("0x", ""))
761+
let proof_hash_bytes: [u8; 32] = hex::decode(args.proof_commitment.replace("0x", ""))
763762
.expect("Proof to be a valid hex encoded hash")
764763
.try_into()
765764
.expect("Proof be raw bytes to be of len 32");
@@ -769,7 +768,7 @@ async fn main() -> Result<(), AlignedError> {
769768
args.network.into(),
770769
args.eth_rpc_url,
771770
args.beacon_client_url,
772-
args.from_block.unwrap_or(0),
771+
args.from_block,
773772
)
774773
.await
775774
{

0 commit comments

Comments
 (0)