Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(eigen-client-extra-features): address PR comments (part 3) #376

Merged
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 8 additions & 32 deletions core/node/da_clients/src/eigen/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use std::{collections::HashMap, fs::File, io::copy, path::Path};
use ark_bn254::{Fq, G1Affine};
use ethabi::{encode, ParamType, Token};
use rust_kzg_bn254::{blob::Blob, kzg::Kzg, polynomial::PolynomialFormat};
use tiny_keccak::{Hasher, Keccak};
use url::Url;
use zksync_basic_types::web3::CallRequest;
use zksync_eth_client::{clients::PKSigningClient, EnrichedClientResult};
Expand Down Expand Up @@ -206,12 +205,7 @@ impl Verifier {
]);

let encoded = encode(&[blob_header]);

let mut keccak = Keccak::v256();
keccak.update(&encoded);
let mut hash = [0u8; 32];
keccak.finalize(&mut hash);
hash.to_vec()
web3::keccak256(&encoded).to_vec()
}

pub fn process_inclusion_proof(
Expand All @@ -234,11 +228,7 @@ impl Verifier {
buffer[..32].copy_from_slice(&proof[i * 32..(i + 1) * 32]);
buffer[32..].copy_from_slice(&computed_hash);
}
let mut keccak = Keccak::v256();
keccak.update(&buffer);
let mut hash = [0u8; 32];
keccak.finalize(&mut hash);
computed_hash = hash.to_vec();
computed_hash = web3::keccak256(&buffer).to_vec();
index /= 2;
}

Expand All @@ -257,10 +247,7 @@ impl Verifier {
let blob_header = &cert.blob_header;

let blob_header_hash = self.hash_encode_blob_header(blob_header);
let mut keccak = Keccak::v256();
keccak.update(&blob_header_hash);
let mut leaf_hash = [0u8; 32];
keccak.finalize(&mut leaf_hash);
let leaf_hash = web3::keccak256(&blob_header_hash).to_vec();

let generated_root =
self.process_inclusion_proof(inclusion_proof, &leaf_hash, blob_index)?;
Expand All @@ -285,11 +272,7 @@ impl Verifier {
]);

let encoded = encode(&[batch_header_token]);

let mut keccak = Keccak::v256();
keccak.update(&encoded);
let mut header_hash = [0u8; 32];
keccak.finalize(&mut header_hash);
let header_hash = web3::keccak256(&encoded).to_vec();

let hash_token = Token::Tuple(vec![
Token::FixedBytes(header_hash.to_vec()),
Expand All @@ -299,13 +282,7 @@ impl Verifier {
let mut hash_encoded = encode(&[hash_token]);

hash_encoded.append(&mut confirmation_block_number.to_be_bytes().to_vec());

let mut keccak = Keccak::v256();
keccak.update(&hash_encoded);
let mut hash = [0u8; 32];
keccak.finalize(&mut hash);

hash.to_vec()
web3::keccak256(&hash_encoded).to_vec()
}

/// Retrieves the block to make the request to the service manager
Expand All @@ -318,10 +295,9 @@ impl Verifier {
.map_err(|_| VerificationError::ServiceManagerError)?
.as_u64();

if self.cfg.settlement_layer_confirmation_depth == 0 {
return Ok(latest);
}
Ok(latest - (self.cfg.settlement_layer_confirmation_depth as u64 - 1))
let depth = self.cfg.settlement_layer_confirmation_depth.saturating_sub(1);
let block_to_return = latest - depth as u64;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use saturating sub here because if latest < depth this will crash

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are correct! I've made the change.

Ok(block_to_return)
}

async fn call_batch_id_to_metadata_hash(
Expand Down
Loading