|
1 | 1 | use crate::{ |
2 | 2 | beacon::{BeaconClient, BeaconClientError}, |
3 | 3 | core::types::Network, |
| 4 | + eth::aligned_proof_agg_service::aligned_proof_aggregation_service, |
4 | 5 | }; |
5 | 6 | use ethers::{ |
6 | 7 | providers::{Http, Middleware, Provider}, |
@@ -133,6 +134,43 @@ pub async fn is_proof_verified_in_aggregation_mode( |
133 | 134 | Err(ProofVerificationAggModeError::ProofNotFoundInLogs) |
134 | 135 | } |
135 | 136 |
|
| 137 | +pub async fn verify_agg_proof_on_chain( |
| 138 | + network: Network, |
| 139 | + eth_rpc_url: String, |
| 140 | + beacon_client_url: String, |
| 141 | + from_block: Option<u64>, |
| 142 | + proof_commitment: [u8; 32], |
| 143 | +) -> Result<bool, ProofVerificationAggModeError> { |
| 144 | + let Some(merkle_path) = get_merkle_path_for_proof( |
| 145 | + network.clone(), |
| 146 | + eth_rpc_url.clone(), |
| 147 | + beacon_client_url, |
| 148 | + from_block, |
| 149 | + proof_commitment, |
| 150 | + ) |
| 151 | + .await? |
| 152 | + else { |
| 153 | + return Ok(false); |
| 154 | + }; |
| 155 | + |
| 156 | + let eth_rpc_provider = Provider::<Http>::try_from(eth_rpc_url) |
| 157 | + .map_err(|e| ProofVerificationAggModeError::EthereumProviderError(e.to_string()))?; |
| 158 | + let contract_provider = aligned_proof_aggregation_service( |
| 159 | + eth_rpc_provider, |
| 160 | + network.get_aligned_proof_agg_service_address(), |
| 161 | + ) |
| 162 | + .await |
| 163 | + .map_err(|e| ProofVerificationAggModeError::EthereumProviderError(e.to_string()))?; |
| 164 | + |
| 165 | + let res: bool = contract_provider |
| 166 | + .verify_proof_inclusion(merkle_path, proof_commitment) |
| 167 | + .call() |
| 168 | + .await |
| 169 | + .expect("Message to be sent"); |
| 170 | + |
| 171 | + Ok(res) |
| 172 | +} |
| 173 | + |
136 | 174 | pub async fn get_merkle_path_for_proof( |
137 | 175 | network: Network, |
138 | 176 | eth_rpc_url: String, |
|
0 commit comments