Skip to content

Commit

Permalink
feat: Add new commitments (matter-labs#219)
Browse files Browse the repository at this point in the history
# What ❔

- `events_queue_commitment` and `bootloader_initial_content_commitment`
are calculated in full tree and saved into DB.
- nightly rust is used
- lints found by clippy are fixed

## Why ❔

Preparation for boojum upgrade

## 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).
- [x] 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: Stanislav Bezkorovainyi <[email protected]>
  • Loading branch information
perekopskiy and StanislavBreadless authored Oct 17, 2023
1 parent afdfcb4 commit a19256e
Show file tree
Hide file tree
Showing 41 changed files with 3,228 additions and 2,530 deletions.
340 changes: 327 additions & 13 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ members = [
"core/lib/contracts",
"core/lib/crypto",
"core/lib/circuit_breaker",
"core/lib/commitment_utils",
"core/lib/dal",
"core/lib/db_test_macro",
"core/lib/eth_client",
Expand Down
15 changes: 15 additions & 0 deletions core/lib/commitment_utils/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "zksync_commitment_utils"
version = "0.1.0"
edition = "2018"
authors = ["The Matter Labs Team <[email protected]>"]
homepage = "https://zksync.io/"
repository = "https://github.com/matter-labs/zksync-era"
license = "MIT OR Apache-2.0"
keywords = ["blockchain", "zksync"]
categories = ["cryptography"]

[dependencies]
zksync_types = { path = "../../lib/types" }
zksync_utils = { path = "../../lib/utils" }
zkevm_test_harness = { git = "https://github.com/matter-labs/era-zkevm_test_harness.git", branch = "v1.4.0" }
34 changes: 34 additions & 0 deletions core/lib/commitment_utils/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//! Utils for commitment calculation.
use zkevm_test_harness::witness::utils::{
events_queue_commitment_fixed, initial_heap_content_commitment_fixed,
};
use zksync_types::{LogQuery, ProtocolVersionId, H256, U256, USED_BOOTLOADER_MEMORY_BYTES};
use zksync_utils::expand_memory_contents;

pub fn events_queue_commitment(
events_queue: &Vec<LogQuery>,
protocol_version: ProtocolVersionId,
) -> Option<H256> {
match protocol_version {
id if id < ProtocolVersionId::Version17 => None,
ProtocolVersionId::Version17 => Some(H256(events_queue_commitment_fixed(events_queue))),
id => unimplemented!("events_queue_commitment is not implemented for {id:?}"),
}
}

pub fn bootloader_initial_content_commitment(
initial_bootloader_contents: &[(usize, U256)],
protocol_version: ProtocolVersionId,
) -> Option<H256> {
match protocol_version {
id if id < ProtocolVersionId::Version17 => None,
ProtocolVersionId::Version17 => {
let full_bootloader_memory =
expand_memory_contents(initial_bootloader_contents, USED_BOOTLOADER_MEMORY_BYTES);
Some(H256(initial_heap_content_commitment_fixed(
&full_bootloader_memory,
)))
}
id => unimplemented!("events_queue_commitment is not implemented for {id:?}"),
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
DROP TABLE IF EXISTS commitments;
DROP TABLE IF EXISTS events_queue;
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
CREATE TABLE IF NOT EXISTS commitments (
l1_batch_number BIGINT PRIMARY KEY REFERENCES l1_batches(number) ON DELETE CASCADE,
events_queue_commitment BYTEA,
bootloader_initial_content_commitment BYTEA
);

CREATE TABLE IF NOT EXISTS events_queue (
l1_batch_number BIGINT PRIMARY KEY REFERENCES l1_batches(number) ON DELETE CASCADE,
serialized_events_queue JSONB NOT NULL
);
Loading

0 comments on commit a19256e

Please sign in to comment.