Skip to content

Commit

Permalink
use assert_eq, panic if eth response is invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
Santiago Pittella authored and Santiago Pittella committed Feb 22, 2024
1 parent ea4daa7 commit fcee5d1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
8 changes: 4 additions & 4 deletions core/lib/config/src/configs/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ pub enum L1BatchCommitDataGeneratorMode {
// If the bytes are "0x0000000000000000000000000000000000000000000000000000000000000001" i want the validium case,
// Else, an error.
impl L1BatchCommitDataGeneratorMode {
pub fn from_eth_response(response: &Bytes) -> Result<Self, String> {
pub fn from_eth_response(response: &Bytes) -> Self {
match &response.0.as_slice() {
&[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] => {
Ok(Self::Rollup)
Self::Rollup
}
&[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1] => {
Ok(Self::Validium)
Self::Validium
}
_ => Err("Invalid response".to_string()),
_response => panic!("Invalid response: {:?}", _response),
}
}
}
Expand Down
15 changes: 9 additions & 6 deletions core/lib/zksync_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -640,16 +640,19 @@ pub async fn initialize_components(
.build(),
)
.await
.unwrap();
.context("failed to get the current commitment mode from the Ethereum")?;

let current_commitment_mode = L1BatchCommitDataGeneratorMode::from_eth_response(
&current_commitment_mode_eth_response,
)
.unwrap();
);

if current_commitment_mode != state_keeper_config.l1_batch_commit_data_generator_mode {
panic!("The selected L1BatchCommitDataGeneratorMode does not match the existing commitment mode");
}
assert_eq!(
current_commitment_mode,
state_keeper_config.l1_batch_commit_data_generator_mode,
"The selected L1BatchCommitDataGeneratorMode ({:?}) does not match the existing commitment mode ({:?})",
state_keeper_config.l1_batch_commit_data_generator_mode,
current_commitment_mode
);

let eth_tx_aggregator_actor = EthTxAggregator::new(
eth_sender.sender.clone(),
Expand Down

0 comments on commit fcee5d1

Please sign in to comment.