Skip to content

Commit 6e8f526

Browse files
authored
feat(en): Check commitment allonside with roothashes (#4492)
## What ❔ During the reorg detection take into account not only root hash, but the whole commitment ## Why ❔ We have at least one example, where during wrong execution we have correct root hash, but wrong commitment ## 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 634b6dd commit 6e8f526

16 files changed

+336
-60
lines changed

core/bin/external_node/src/tests/utils.rs

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ pub(super) struct TestEnvironment {
6363
pub(super) components: ComponentsToRun,
6464
pub(super) config: ExternalNodeConfig,
6565
pub(super) genesis_root_hash: H256,
66+
pub(super) genesis_commitment: H256,
6667
pub(super) genesis_l2_block: L2BlockHeader,
6768
pub(super) settlement_layer_specific_contracts: SettlementLayerSpecificContracts,
6869
}
@@ -77,18 +78,29 @@ impl TestEnvironment {
7778
// in the network.
7879
let mut storage = connection_pool.connection().await.unwrap();
7980
let genesis_needed = storage.blocks_dal().is_genesis_needed().await.unwrap();
80-
let genesis_root_hash = if genesis_needed {
81-
insert_genesis_batch(&mut storage, &GenesisParams::mock())
81+
let (genesis_root_hash, genesis_commitment) = if genesis_needed {
82+
let genesis_batch_params = insert_genesis_batch(&mut storage, &GenesisParams::mock())
8283
.await
83-
.unwrap()
84-
.root_hash
84+
.unwrap();
85+
(
86+
genesis_batch_params.root_hash,
87+
genesis_batch_params.commitment,
88+
)
8589
} else {
86-
storage
87-
.blocks_dal()
88-
.get_l1_batch_state_root(L1BatchNumber(0))
89-
.await
90-
.unwrap()
91-
.expect("no genesis batch root hash")
90+
(
91+
storage
92+
.blocks_dal()
93+
.get_l1_batch_state_root(L1BatchNumber(0))
94+
.await
95+
.unwrap()
96+
.expect("no genesis batch root hash"),
97+
storage
98+
.blocks_dal()
99+
.get_commitment_for_l1_batch(L1BatchNumber(0))
100+
.await
101+
.unwrap()
102+
.expect("no genesis batch root hash"),
103+
)
92104
};
93105
let genesis_l2_block = storage
94106
.blocks_dal()
@@ -113,6 +125,7 @@ impl TestEnvironment {
113125
components,
114126
config,
115127
genesis_root_hash,
128+
genesis_commitment,
116129
genesis_l2_block,
117130
settlement_layer_specific_contracts: SettlementLayerSpecificContracts {
118131
ecosystem_contracts: EcosystemCommonContracts {
@@ -261,6 +274,7 @@ pub(super) fn mock_eth_client(
261274
/// Creates a mock L2 client with the genesis block information.
262275
pub(super) fn mock_l2_client(env: &TestEnvironment) -> MockClient<L2> {
263276
let genesis_root_hash = env.genesis_root_hash;
277+
let genesis_commitment = env.genesis_commitment;
264278
let genesis_l2_block_hash = env.genesis_l2_block.hash;
265279

266280
let contracts = env.settlement_layer_specific_contracts.clone();
@@ -272,6 +286,7 @@ pub(super) fn mock_l2_client(env: &TestEnvironment) -> MockClient<L2> {
272286
assert_eq!(number, L1BatchNumber(0));
273287
Ok(api::L1BatchDetails {
274288
number: L1BatchNumber(0),
289+
commitment: Some(genesis_commitment),
275290
base: utils::block_details_base(genesis_root_hash),
276291
})
277292
})

core/lib/dal/.sqlx/query-24fa1ab88fa7a7ee98b5f18db5b83ea2cb407502e053daaf591f278bfe05b1fa.json

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/lib/dal/.sqlx/query-2ea0fe7e1812835d646454569b6595e609f9ce26f9c922227dc4225849d8ef29.json

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/lib/dal/.sqlx/query-f91790ae5cc4b087bf942ba52dd63a1e89945f8d5e0f4da42ecf6313c4f5967e.json renamed to core/lib/dal/.sqlx/query-37c17ef5a1cb5e55cd0c8303a47e77358e46a854fe57fe81dff30c344babc478.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/lib/dal/.sqlx/query-34da3f27bb96d273e13a871278b47fc00a060da8065626273ccb429dcf2d4754.json renamed to core/lib/dal/.sqlx/query-853c3759b37f9b0c57eff5dd4328eb1e9326b3f7fde61f6a4d55dc724904b408.json

Lines changed: 8 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)