Skip to content

Commit f13648c

Browse files
StanislavBreadlessperekopskiyly0va
authored
fix(boojnet): various boojnet fixes (matter-labs#462)
## What ❔ - sanity checks for some system log values - bug fixed that real proofs can be sent before batches are committed - commitment is set only by full tree - fix eth_watcher index out of range for EOA-controlled upgrades ## Why ❔ bug fixes ## Checklist <!-- Check your PR fulfills the following items. --> <!-- For draft PRs check the boxes as you complete them. --> - [x] PR title corresponds to the body of PR (we generate changelog entries from PRs). - [ ] Tests for the changes have been added / updated. - [x] Documentation comments have been added / updated. - [x] Code has been formatted via `zk fmt` and `zk lint`. --------- Co-authored-by: “perekopskiy” <[email protected]> Co-authored-by: Lyova Potyomkin <[email protected]> Co-authored-by: perekopskiy <[email protected]>
1 parent 5f61d8d commit f13648c

File tree

8 files changed

+185
-75
lines changed

8 files changed

+185
-75
lines changed

core/lib/constants/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ pub mod crypto;
44
pub mod ethereum;
55
pub mod fees;
66
pub mod system_context;
7+
pub mod system_logs;
78
pub mod trusted_slots;
89

910
pub use blocks::*;
@@ -12,4 +13,5 @@ pub use crypto::*;
1213
pub use ethereum::*;
1314
pub use fees::*;
1415
pub use system_context::*;
16+
pub use system_logs::*;
1517
pub use trusted_slots::*;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/// The key of the system log with value of the L2->L1 logs tree root hash
2+
pub const L2_TO_L1_LOGS_TREE_ROOT_KEY: u32 = 0;
3+
4+
/// The key of the system log with value of the state diff hash
5+
pub const STATE_DIFF_HASH_KEY: u32 = 2;

core/lib/dal/sqlx-data.json

Lines changed: 72 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,26 @@
298298
},
299299
"query": "\n WITH events_select AS (\n SELECT\n address, topic1, topic2, topic3, topic4, value,\n miniblock_number, tx_hash, tx_index_in_block,\n event_index_in_block, event_index_in_tx\n FROM events\n WHERE miniblock_number > $1\n ORDER BY miniblock_number ASC, event_index_in_block ASC\n )\n SELECT miniblocks.hash as \"block_hash?\",\n address as \"address!\", topic1 as \"topic1!\", topic2 as \"topic2!\", topic3 as \"topic3!\", topic4 as \"topic4!\", value as \"value!\",\n miniblock_number as \"miniblock_number!\", miniblocks.l1_batch_number as \"l1_batch_number?\", tx_hash as \"tx_hash!\",\n tx_index_in_block as \"tx_index_in_block!\", event_index_in_block as \"event_index_in_block!\", event_index_in_tx as \"event_index_in_tx!\"\n FROM events_select\n INNER JOIN miniblocks ON events_select.miniblock_number = miniblocks.number\n ORDER BY miniblock_number ASC, event_index_in_block ASC\n "
300300
},
301+
"06d90ea65c1e06bd871f090a0fb0e8772ea5e923f1da5310bedd8dc90e0827f4": {
302+
"describe": {
303+
"columns": [
304+
{
305+
"name": "eth_commit_tx_id",
306+
"ordinal": 0,
307+
"type_info": "Int4"
308+
}
309+
],
310+
"nullable": [
311+
true
312+
],
313+
"parameters": {
314+
"Left": [
315+
"Int8"
316+
]
317+
}
318+
},
319+
"query": "SELECT eth_commit_tx_id FROM l1_batches WHERE number = $1"
320+
},
301321
"07310d96fc7e258154ad510684e33d196907ebd599e926d305e5ef9f26afa2fa": {
302322
"describe": {
303323
"columns": [
@@ -320,6 +340,30 @@
320340
},
321341
"query": "INSERT INTO eth_txs_history (eth_tx_id, base_fee_per_gas, priority_fee_per_gas, tx_hash, signed_raw_tx, created_at, updated_at, confirmed_at) VALUES ($1, 0, 0, $2, '\\x00', now(), now(), $3) RETURNING id"
322342
},
343+
"09768b376996b96add16a02d1a59231cb9b525cd5bd19d22a76149962d4c91c2": {
344+
"describe": {
345+
"columns": [],
346+
"nullable": [],
347+
"parameters": {
348+
"Left": [
349+
"Bytea",
350+
"Bytea",
351+
"Bytea",
352+
"Bytea",
353+
"Bytea",
354+
"Bytea",
355+
"Bool",
356+
"Bytea",
357+
"Int8",
358+
"Bytea",
359+
"Bytea",
360+
"Bytea",
361+
"Int8"
362+
]
363+
}
364+
},
365+
"query": "UPDATE l1_batches SET hash = $1, merkle_root_hash = $2, compressed_repeated_writes = $3, compressed_initial_writes = $4, l2_l1_compressed_messages = $5, l2_l1_merkle_root = $6, zkporter_is_available = $7, parent_hash = $8, rollup_last_leaf_index = $9, pass_through_data_hash = $10, meta_parameters_hash = $11, compressed_state_diffs = $12, updated_at = now() WHERE number = $13 AND hash IS NULL"
366+
},
323367
"0c212f47b9a0e719f947a419be8284837b1b01aa23994ba6401b420790b802b8": {
324368
"describe": {
325369
"columns": [],
@@ -1942,6 +1986,20 @@
19421986
},
19431987
"query": "SELECT recursion_scheduler_level_vk_hash, recursion_node_level_vk_hash, recursion_leaf_level_vk_hash, recursion_circuits_set_vks_hash\n FROM protocol_versions\n WHERE id = $1\n "
19441988
},
1989+
"21c29846f4253081057b86cc1b7ce4ef3ae618c5561c876502dc7f4e773ee91e": {
1990+
"describe": {
1991+
"columns": [],
1992+
"nullable": [],
1993+
"parameters": {
1994+
"Left": [
1995+
"Int8",
1996+
"Bytea",
1997+
"Bytea"
1998+
]
1999+
}
2000+
},
2001+
"query": "INSERT INTO commitments (l1_batch_number, events_queue_commitment, bootloader_initial_content_commitment) VALUES ($1, $2, $3) ON CONFLICT (l1_batch_number) DO NOTHING"
2002+
},
19452003
"22b57675a726d9cfeb82a60ba50c36cab1548d197ea56a7658d3f005df07c60b": {
19462004
"describe": {
19472005
"columns": [
@@ -5653,20 +5711,6 @@
56535711
},
56545712
"query": "\n UPDATE leaf_aggregation_witness_jobs\n SET status='queued'\n WHERE l1_batch_number IN\n (SELECT prover_jobs.l1_batch_number\n FROM prover_jobs\n JOIN leaf_aggregation_witness_jobs lawj ON prover_jobs.l1_batch_number = lawj.l1_batch_number\n WHERE lawj.status = 'waiting_for_proofs'\n AND prover_jobs.status = 'successful'\n AND prover_jobs.aggregation_round = 0\n GROUP BY prover_jobs.l1_batch_number, lawj.number_of_basic_circuits\n HAVING COUNT(*) = lawj.number_of_basic_circuits)\n RETURNING l1_batch_number;\n "
56555713
},
5656-
"68a9ba78f60674bc047e4af6eb2a379725da047f2e6c06bce96a33852565cc95": {
5657-
"describe": {
5658-
"columns": [],
5659-
"nullable": [],
5660-
"parameters": {
5661-
"Left": [
5662-
"Int8",
5663-
"Bytea",
5664-
"Bytea"
5665-
]
5666-
}
5667-
},
5668-
"query": "INSERT INTO commitments (l1_batch_number, events_queue_commitment, bootloader_initial_content_commitment) VALUES ($1, $2, $3) ON CONFLICT (l1_batch_number) DO UPDATE SET events_queue_commitment = $2, bootloader_initial_content_commitment = $3"
5669-
},
56705714
"6939e766e122458b2ac618d19b2759c4a7298ef72b81e8c3957e0a5cf35c9552": {
56715715
"describe": {
56725716
"columns": [
@@ -9736,6 +9780,20 @@
97369780
},
97379781
"query": "SELECT bytecode, bytecode_hash FROM factory_deps WHERE bytecode_hash = ANY($1)"
97389782
},
9783+
"c0904ee4179531cfb9d458a17f753085dc2ed957b30a89119d7534112add3876": {
9784+
"describe": {
9785+
"columns": [],
9786+
"nullable": [],
9787+
"parameters": {
9788+
"Left": [
9789+
"Int8",
9790+
"Bytea",
9791+
"Bytea"
9792+
]
9793+
}
9794+
},
9795+
"query": "UPDATE l1_batches SET commitment = $2, aux_data_hash = $3, updated_at = now() WHERE number = $1"
9796+
},
97399797
"c178e1574d2a16cb90bcc5d5333a4f8dd2a69e0c12b4e7e108a8dcc6000669a5": {
97409798
"describe": {
97419799
"columns": [
@@ -10731,32 +10789,6 @@
1073110789
},
1073210790
"query": "\n UPDATE witness_inputs\n SET status = 'in_progress', attempts = attempts + 1,\n updated_at = now(), processing_started_at = now()\n WHERE l1_batch_number = (\n SELECT l1_batch_number\n FROM witness_inputs\n WHERE l1_batch_number <= $3\n AND\n ( status = 'queued'\n OR (status = 'in_progress' AND processing_started_at < now() - $1::interval)\n OR (status = 'failed' AND attempts < $2)\n )\n AND protocol_version = ANY($4)\n ORDER BY l1_batch_number ASC\n LIMIT 1\n FOR UPDATE\n SKIP LOCKED\n )\n RETURNING witness_inputs.*\n "
1073310791
},
10734-
"e03756d19dfdf4cdffa81154e690dc7c36024dad5363e0c5440606a5a50eef53": {
10735-
"describe": {
10736-
"columns": [],
10737-
"nullable": [],
10738-
"parameters": {
10739-
"Left": [
10740-
"Bytea",
10741-
"Bytea",
10742-
"Bytea",
10743-
"Bytea",
10744-
"Bytea",
10745-
"Bytea",
10746-
"Bytea",
10747-
"Bool",
10748-
"Bytea",
10749-
"Int8",
10750-
"Bytea",
10751-
"Bytea",
10752-
"Bytea",
10753-
"Bytea",
10754-
"Int8"
10755-
]
10756-
}
10757-
},
10758-
"query": "UPDATE l1_batches SET hash = $1, merkle_root_hash = $2, commitment = $3, compressed_repeated_writes = $4, compressed_initial_writes = $5, l2_l1_compressed_messages = $6, l2_l1_merkle_root = $7, zkporter_is_available = $8, parent_hash = $9, rollup_last_leaf_index = $10, aux_data_hash = $11, pass_through_data_hash = $12, meta_parameters_hash = $13, compressed_state_diffs = $14, updated_at = now() WHERE number = $15 AND hash IS NULL"
10759-
},
1076010792
"e05a8c74653afc78c892ddfd08e60ab040d2b2f7c4b5ee110988eac2dd0dd90d": {
1076110793
"describe": {
1076210794
"columns": [

core/lib/dal/src/blocks_dal.rs

Lines changed: 54 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -587,24 +587,22 @@ impl BlocksDal<'_, '_> {
587587

588588
let update_result = sqlx::query!(
589589
"UPDATE l1_batches \
590-
SET hash = $1, merkle_root_hash = $2, commitment = $3, \
591-
compressed_repeated_writes = $4, compressed_initial_writes = $5, \
592-
l2_l1_compressed_messages = $6, l2_l1_merkle_root = $7, \
593-
zkporter_is_available = $8, parent_hash = $9, rollup_last_leaf_index = $10, \
594-
aux_data_hash = $11, pass_through_data_hash = $12, meta_parameters_hash = $13, \
595-
compressed_state_diffs = $14, updated_at = now() \
596-
WHERE number = $15 AND hash IS NULL",
590+
SET hash = $1, merkle_root_hash = $2, \
591+
compressed_repeated_writes = $3, compressed_initial_writes = $4, \
592+
l2_l1_compressed_messages = $5, l2_l1_merkle_root = $6, \
593+
zkporter_is_available = $7, parent_hash = $8, rollup_last_leaf_index = $9, \
594+
pass_through_data_hash = $10, meta_parameters_hash = $11, \
595+
compressed_state_diffs = $12, updated_at = now() \
596+
WHERE number = $13 AND hash IS NULL",
597597
metadata.root_hash.as_bytes(),
598598
metadata.merkle_root_hash.as_bytes(),
599-
metadata.commitment.as_bytes(),
600599
metadata.repeated_writes_compressed,
601600
metadata.initial_writes_compressed,
602601
metadata.l2_l1_messages_compressed,
603602
metadata.l2_l1_merkle_root.as_bytes(),
604603
metadata.block_meta_params.zkporter_is_available,
605604
previous_root_hash.as_bytes(),
606605
metadata.rollup_last_leaf_index as i64,
607-
metadata.aux_data_hash.as_bytes(),
608606
metadata.pass_through_data_hash.as_bytes(),
609607
metadata.meta_parameters_hash.as_bytes(),
610608
metadata.state_diffs_compressed,
@@ -616,21 +614,38 @@ impl BlocksDal<'_, '_> {
616614
.execute(transaction.conn())
617615
.await?;
618616

619-
sqlx::query!(
620-
"INSERT INTO commitments (l1_batch_number, events_queue_commitment, bootloader_initial_content_commitment) \
621-
VALUES ($1, $2, $3) \
622-
ON CONFLICT (l1_batch_number) DO UPDATE SET events_queue_commitment = $2, bootloader_initial_content_commitment = $3",
623-
number.0 as i64,
624-
metadata.events_queue_commitment.map(|h| h.0.to_vec()),
625-
metadata
626-
.bootloader_initial_content_commitment
627-
.map(|h| h.0.to_vec()),
628-
)
629-
.instrument("save_batch_commitments")
630-
.with_arg("number", &number)
631-
.report_latency()
632-
.execute(transaction.conn())
633-
.await?;
617+
if metadata.events_queue_commitment.is_some() {
618+
// Save `commitment`, `aux_data_hash`, `events_queue_commitment`, `bootloader_initial_content_commitment`.
619+
sqlx::query!(
620+
"INSERT INTO commitments (l1_batch_number, events_queue_commitment, bootloader_initial_content_commitment) \
621+
VALUES ($1, $2, $3) \
622+
ON CONFLICT (l1_batch_number) DO NOTHING",
623+
number.0 as i64,
624+
metadata.events_queue_commitment.map(|h| h.0.to_vec()),
625+
metadata
626+
.bootloader_initial_content_commitment
627+
.map(|h| h.0.to_vec()),
628+
)
629+
.instrument("save_batch_commitments")
630+
.with_arg("number", &number)
631+
.report_latency()
632+
.execute(transaction.conn())
633+
.await?;
634+
635+
sqlx::query!(
636+
"UPDATE l1_batches \
637+
SET commitment = $2, aux_data_hash = $3, updated_at = now() \
638+
WHERE number = $1",
639+
number.0 as i64,
640+
metadata.commitment.as_bytes(),
641+
metadata.aux_data_hash.as_bytes(),
642+
)
643+
.instrument("save_batch_aux_commitment")
644+
.with_arg("number", &number)
645+
.report_latency()
646+
.execute(transaction.conn())
647+
.await?;
648+
}
634649

635650
if update_result.rows_affected() == 0 {
636651
tracing::debug!(
@@ -739,6 +754,21 @@ impl BlocksDal<'_, '_> {
739754
Ok(L1BatchNumber(row.number as u32))
740755
}
741756

757+
pub async fn get_eth_commit_tx_id(
758+
&mut self,
759+
l1_batch_number: L1BatchNumber,
760+
) -> sqlx::Result<Option<u64>> {
761+
let row = sqlx::query!(
762+
"SELECT eth_commit_tx_id FROM l1_batches \
763+
WHERE number = $1",
764+
l1_batch_number.0 as i64
765+
)
766+
.fetch_optional(self.storage.conn())
767+
.await?;
768+
769+
Ok(row.and_then(|row| row.eth_commit_tx_id.map(|n| n as u64)))
770+
}
771+
742772
/// Returns the number of the last L1 batch for which an Ethereum prove tx was sent and confirmed.
743773
pub async fn get_number_of_last_l1_batch_proven_on_eth(
744774
&mut self,

core/lib/multivm/src/versions/vm_latest/tracers/pubdata_tracer.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ impl<S: WriteStorage, H: HistoryMode> VmTracer<S, H> for PubdataTracer<S> {
196196

197197
// Apply the pubdata to the current memory
198198
let mut memory_to_apply = vec![];
199+
199200
apply_pubdata_to_memory(&mut memory_to_apply, pubdata_input);
200201
state.memory.populate_page(
201202
BOOTLOADER_HEAP_PAGE as usize,

core/lib/types/src/commitment.rs

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@
77
//! transactions, thus the calculations are done separately and asynchronously.
88
99
use serde::{Deserialize, Serialize};
10+
use zksync_utils::u256_to_h256;
1011

1112
use std::{collections::HashMap, convert::TryFrom};
1213

1314
use zksync_mini_merkle_tree::MiniMerkleTree;
14-
use zksync_system_constants::ZKPORTER_IS_AVAILABLE;
15+
use zksync_system_constants::{
16+
L2_TO_L1_LOGS_TREE_ROOT_KEY, STATE_DIFF_HASH_KEY, ZKPORTER_IS_AVAILABLE,
17+
};
1518

1619
use crate::{
1720
block::L1BatchHeader,
@@ -353,6 +356,22 @@ impl L1BatchAuxiliaryOutput {
353356
events_state_queue_hash: H256,
354357
protocol_version: ProtocolVersionId,
355358
) -> Self {
359+
let state_diff_hash_from_logs = system_logs.iter().find_map(|log| {
360+
if log.0.key == u256_to_h256(STATE_DIFF_HASH_KEY.into()) {
361+
Some(log.0.value)
362+
} else {
363+
None
364+
}
365+
});
366+
367+
let merke_tree_root_from_logs = system_logs.iter().find_map(|log| {
368+
if log.0.key == u256_to_h256(L2_TO_L1_LOGS_TREE_ROOT_KEY.into()) {
369+
Some(log.0.value)
370+
} else {
371+
None
372+
}
373+
});
374+
356375
let (
357376
l2_l1_logs_compressed,
358377
initial_writes_compressed,
@@ -403,6 +422,19 @@ impl L1BatchAuxiliaryOutput {
403422
let l2_l1_logs_merkle_root =
404423
MiniMerkleTree::new(merkle_tree_leaves, Some(min_tree_size)).merkle_root();
405424

425+
if !system_logs.is_empty() {
426+
assert_eq!(
427+
state_diffs_hash,
428+
state_diff_hash_from_logs.unwrap(),
429+
"State diff hash mismatch"
430+
);
431+
assert_eq!(
432+
l2_l1_logs_merkle_root,
433+
merke_tree_root_from_logs.unwrap(),
434+
"L2 L1 logs tree root mismatch"
435+
);
436+
}
437+
406438
Self {
407439
l2_l1_logs_compressed,
408440
initial_writes_compressed,

core/lib/types/src/protocol_version.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -274,18 +274,19 @@ impl TryFrom<Log> for ProtocolUpgrade {
274274
ParamType::Uint(256), // version id
275275
ParamType::Address, // allow list address
276276
])],
277-
&init_calldata[4..],
277+
init_calldata
278+
.get(4..)
279+
.ok_or(crate::ethabi::Error::InvalidData)?,
278280
)?;
279281

280-
let mut decoded = match decoded.remove(0) {
281-
Token::Tuple(x) => x,
282-
_ => unreachable!(),
282+
let Token::Tuple(mut decoded) = decoded.remove(0) else {
283+
unreachable!();
283284
};
284285

285-
let mut transaction = match decoded.remove(0) {
286-
Token::Tuple(x) => x,
287-
_ => unreachable!(),
286+
let Token::Tuple(mut transaction) = decoded.remove(0) else {
287+
unreachable!()
288288
};
289+
289290
let factory_deps = decoded.remove(0).into_array().unwrap();
290291

291292
let tx = {
@@ -399,9 +400,8 @@ impl TryFrom<Log> for ProtocolUpgrade {
399400
let default_account_code_hash =
400401
H256::from_slice(&decoded.remove(0).into_fixed_bytes().unwrap());
401402
let verifier_address = decoded.remove(0).into_address().unwrap();
402-
let mut verifier_params = match decoded.remove(0) {
403-
Token::Tuple(tx) => tx,
404-
_ => unreachable!(),
403+
let Token::Tuple(mut verifier_params) = decoded.remove(0) else {
404+
unreachable!()
405405
};
406406
let recursion_node_level_vk_hash =
407407
H256::from_slice(&verifier_params.remove(0).into_fixed_bytes().unwrap());

0 commit comments

Comments
 (0)