Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add new commitments #219

Merged
merged 7 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 10 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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 <hello@matterlabs.dev>"]
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
@@ -1,6 +1,2 @@
ALTER TABLE l1_batches
DROP COLUMN IF EXISTS events_queue_commitment;
ALTER TABLE l1_batches
DROP COLUMN IF EXISTS bootloader_initial_content_commitment;

DROP TABLE IF EXISTS commitments;
DROP TABLE IF EXISTS events_queue;
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
ALTER TABLE l1_batches
ADD COLUMN IF NOT EXISTS events_queue_commitment BYTEA;
ALTER TABLE l1_batches
ADD COLUMN IF NOT EXISTS bootloader_initial_content_commitment BYTEA;
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,
Expand Down