Skip to content

Commit 7692f31

Browse files
authored
fix(en): allow to disable sanity checks for commitment generation (#4487)
## What ❔ Disabling sanity checks for commitment generation ## Why ❔ Our external node is designed around commitment generation and verification. Now it's possible to be in a situation, that we have incorrect block and we can't revert it, because we don't have a commitment for it. EN is not able to produce any commitment => EN can't verify the commitment => EN can't revert incorrect block. ## Is this a breaking change? - [ ] Yes - [ ] No ## Operational changes <!-- Any config changes? Any new flags? Any changes to any scripts? --> <!-- Please add anything that non-Matter Labs entities running their own ZK Chain may need to know --> ## Checklist <!-- Check your PR fulfills the following items. --> <!-- For draft PRs check the boxes as you complete them. --> - [ ] PR title corresponds to the body of PR (we generate changelog entries from PRs). - [ ] Tests for the changes have been added / updated. - [ ] Documentation comments have been added / updated. - [ ] Code has been formatted via `zkstack dev fmt` and `zkstack dev lint`. Signed-off-by: Danil <[email protected]>
1 parent 99e0423 commit 7692f31

File tree

8 files changed

+33
-13
lines changed

8 files changed

+33
-13
lines changed

core/bin/external_node/src/node_builder.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,11 @@ impl ExternalNodeBuilder {
271271

272272
fn add_commitment_generator_layer(mut self) -> anyhow::Result<Self> {
273273
let config = &self.config.local.commitment_generator;
274-
let layer =
275-
CommitmentGeneratorLayer::default().with_max_parallelism(config.max_parallelism);
274+
let layer = CommitmentGeneratorLayer::default()
275+
.with_max_parallelism(config.max_parallelism)
276+
// For external node, we need to disable all sanity checks, because it will allow to generate wrong commitments,
277+
// which will eventually lead to consistency errors and node will revert the incorrect state.
278+
.disable_sanity_checks();
276279
self.node.add_layer(layer);
277280
Ok(self)
278281
}

core/lib/types/src/commitment/mod.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,10 @@ pub enum L1BatchAuxiliaryOutput {
351351
}
352352

353353
impl L1BatchAuxiliaryOutput {
354-
fn new(input: CommitmentInput) -> Result<Self, CommitmentValidationError> {
354+
fn new(
355+
input: CommitmentInput,
356+
disable_sanity_checks: bool,
357+
) -> Result<Self, CommitmentValidationError> {
355358
match input {
356359
CommitmentInput::PreBoojum {
357360
common: common_input,
@@ -426,7 +429,7 @@ impl L1BatchAuxiliaryOutput {
426429
let state_diffs_compressed = compress_state_diffs(state_diffs);
427430

428431
// Sanity checks. System logs are empty for the genesis batch, so we can't do checks for it.
429-
if !system_logs.is_empty() {
432+
if !system_logs.is_empty() && !disable_sanity_checks {
430433
if common_input.protocol_version.is_pre_gateway() {
431434
let state_diff_hash_from_logs = system_logs
432435
.iter()
@@ -650,7 +653,12 @@ pub struct L1BatchCommitmentHash {
650653
}
651654

652655
impl L1BatchCommitment {
653-
pub fn new(input: CommitmentInput) -> Result<Self, CommitmentValidationError> {
656+
pub fn new(
657+
input: CommitmentInput,
658+
// Sanity checks are disabled for external node, because it's a sign of incorrect
659+
// state inside external node, the commitment correctness will be double checked on l1
660+
disable_sanity_checks: bool,
661+
) -> Result<Self, CommitmentValidationError> {
654662
let meta_parameters = L1BatchMetaParameters {
655663
zkporter_is_available: ZKPORTER_IS_AVAILABLE,
656664
bootloader_code_hash: input.common().bootloader_code_hash,
@@ -673,7 +681,7 @@ impl L1BatchCommitment {
673681
},
674682
],
675683
},
676-
auxiliary_output: L1BatchAuxiliaryOutput::new(input)?,
684+
auxiliary_output: L1BatchAuxiliaryOutput::new(input, disable_sanity_checks)?,
677685
meta_parameters,
678686
})
679687
}

core/lib/types/src/commitment/tests/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ fn run_test(test_name: &str) {
1717
let contents = read_to_string(format!("src/commitment/tests/{test_name}.json")).unwrap();
1818
let commitment_test: CommitmentTest = serde_json::from_str(&contents).unwrap();
1919

20-
let commitment = L1BatchCommitment::new(commitment_test.input).unwrap();
20+
let commitment = L1BatchCommitment::new(commitment_test.input, true).unwrap();
2121

2222
assert_eq!(
2323
commitment.pass_through_data,

core/node/commitment_generator/src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,18 @@ pub struct CommitmentGenerator {
4343
connection_pool: ConnectionPool<Core>,
4444
health_updater: HealthUpdater,
4545
parallelism: NonZeroU32,
46+
disable_sanity_checks: bool,
4647
}
4748

4849
impl CommitmentGenerator {
4950
/// Creates a commitment generator with the provided mode.
50-
pub fn new(connection_pool: ConnectionPool<Core>) -> Self {
51+
pub fn new(connection_pool: ConnectionPool<Core>, disable_sanity_checks: bool) -> Self {
5152
Self {
5253
computer: Arc::new(RealCommitmentComputer),
5354
connection_pool,
5455
health_updater: ReactiveHealthCheck::new("commitment_generator").1,
5556
parallelism: Self::default_parallelism(),
57+
disable_sanity_checks,
5658
}
5759
}
5860

@@ -337,7 +339,7 @@ impl CommitmentGenerator {
337339

338340
let latency =
339341
METRICS.generate_commitment_latency_stage[&CommitmentStage::Calculate].start();
340-
let mut commitment = L1BatchCommitment::new(input)?;
342+
let mut commitment = L1BatchCommitment::new(input, self.disable_sanity_checks)?;
341343
self.post_process_commitment(&mut commitment, commitment_mode);
342344
let artifacts = commitment.artifacts()?;
343345
let latency = latency.observe();

core/node/commitment_generator/src/node/commitment_generator.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use crate::CommitmentGenerator;
1717
#[derive(Debug, Default)]
1818
pub struct CommitmentGeneratorLayer {
1919
max_parallelism: Option<NonZero<u32>>,
20+
disable_sanity_checks: bool,
2021
}
2122

2223
#[derive(Debug, FromContext)]
@@ -37,6 +38,11 @@ impl CommitmentGeneratorLayer {
3738
self.max_parallelism = max_parallelism;
3839
self
3940
}
41+
42+
pub fn disable_sanity_checks(mut self) -> Self {
43+
self.disable_sanity_checks = true;
44+
self
45+
}
4046
}
4147

4248
#[async_trait::async_trait]
@@ -55,7 +61,8 @@ impl WiringLayer for CommitmentGeneratorLayer {
5561
.get();
5662
let main_pool = input.master_pool.get_custom(pool_size).await?;
5763

58-
let mut commitment_generator = CommitmentGenerator::new(main_pool);
64+
let mut commitment_generator =
65+
CommitmentGenerator::new(main_pool, self.disable_sanity_checks);
5966
if let Some(max_parallelism) = self.max_parallelism {
6067
commitment_generator.set_max_parallelism(max_parallelism);
6168
}

core/node/commitment_generator/src/tests/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ impl CommitmentComputer for MockCommitmentComputer {
9595
}
9696

9797
fn create_commitment_generator(pool: ConnectionPool<Core>) -> CommitmentGenerator {
98-
let mut generator = CommitmentGenerator::new(pool);
98+
let mut generator = CommitmentGenerator::new(pool, false);
9999
generator.computer = Arc::new(MockCommitmentComputer {
100100
delay: Duration::from_millis(20),
101101
});

core/node/fee_model/src/l1_gas_price/blob_base_fee_predictor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ mod tests {
152152

153153
let cap = predict_blob_fee_cap(blobs_total, l1_blocks_total, l1_blob_base_fee);
154154
// Expect only safety margin applied to base fee = 1
155-
let expected = ((1u128 * SAFETY_BPS as u128) / 10_000u128) as u64;
155+
let expected = ((SAFETY_BPS as u128) / 10_000u128) as u64;
156156
assert_eq!(
157157
cap, expected,
158158
"fee cap should equal base fee * safety when no backlog"

core/node/genesis/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ pub fn make_genesis_batch_params(
218218
base_system_contract_hashes,
219219
protocol_version,
220220
);
221-
let block_commitment = L1BatchCommitment::new(commitment_input)?;
221+
let block_commitment = L1BatchCommitment::new(commitment_input, true)?;
222222
let commitment = block_commitment.hash()?.commitment;
223223

224224
Ok((

0 commit comments

Comments
 (0)