Skip to content

Commit

Permalink
chore: add common crate for project wide definitions (#500)
Browse files Browse the repository at this point in the history
* chore: add common crate for project wide definitions

* fix: labeling

* fix: review

* fix: nitpick
  • Loading branch information
atanmarko authored Aug 15, 2024
1 parent fb1aa3d commit cdd0824
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 19 deletions.
7 changes: 6 additions & 1 deletion .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,9 @@
# Add 'specs' label to any changes within 'docs' folder.
'specs':
- changed-files:
- any-glob-to-any-file: docs/**
- any-glob-to-any-file: docs/**

# Add 'crate: common' label to any changes within 'common' folder.
'crate: common':
- changed-files:
- any-glob-to-any-file: common/**
12 changes: 12 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[workspace]
members = [
"common",
"compat",
"evm_arithmetization",
"mpt_trie",
Expand Down Expand Up @@ -114,6 +115,7 @@ mpt_trie = { path = "mpt_trie", version = "0.4.1" }
proof_gen = { path = "proof_gen", version = "0.4.0" }
smt_trie = { path = "smt_trie", version = "0.1.1" }
trace_decoder = { path = "trace_decoder", version = "0.6.0" }
zk_evm_common = { path = "common", version = "0.1.0" }
zk_evm_proc_macro = { path = "proc_macro", version = "0.1.0" }

# zero-bin related dependencies
Expand Down
17 changes: 17 additions & 0 deletions common/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[package]
name = "zk_evm_common"
version = "0.1.0"
edition.workspace = true
license.workspace = true
repository.workspace = true
homepage.workspace = true
keywords.workspace = true
categories.workspace = true

[dependencies]
ethereum-types = { workspace = true }
keccak-hash = { workspace = true }

[dev-dependencies]
bytes = { workspace = true }
rlp = { workspace = true }
28 changes: 28 additions & 0 deletions common/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use ethereum_types::H256;

/// The hash value of an account empty EVM code.
/// 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470
pub const EMPTY_CODE_HASH: H256 = H256([
197, 210, 70, 1, 134, 247, 35, 60, 146, 126, 125, 178, 220, 199, 3, 192, 229, 0, 182, 83, 202,
130, 39, 59, 123, 250, 216, 4, 93, 133, 164, 112,
]);

/// The hash of an empty Merkle Patricia trie.
/// 0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421
pub const EMPTY_TRIE_HASH: H256 = H256([
86, 232, 31, 23, 27, 204, 85, 166, 255, 131, 69, 230, 146, 192, 248, 110, 91, 72, 224, 27, 153,
108, 173, 192, 1, 98, 47, 181, 227, 99, 180, 33,
]);

#[test]
fn test_empty_code_hash() {
assert_eq!(EMPTY_CODE_HASH, keccak_hash::keccak([]));
}

#[test]
fn test_empty_trie_hash() {
assert_eq!(
EMPTY_TRIE_HASH,
keccak_hash::keccak(bytes::Bytes::from_static(&rlp::NULL_RLP))
);
}
1 change: 1 addition & 0 deletions mpt_trie/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ impl-rlp = { workspace = true }
impl-codec = { workspace = true }
impl-serde = { workspace = true }
impl-num-traits = { workspace = true }
zk_evm_common = {workspace = true}

[dev-dependencies]
eth_trie = { workspace = true }
Expand Down
7 changes: 1 addition & 6 deletions mpt_trie/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,13 @@ use std::sync::Arc;
use ethereum_types::H256;
use keccak_hash::keccak;
use rlp::{Prototype, Rlp};
use zk_evm_common::EMPTY_TRIE_HASH;

use super::{
nibbles::Nibbles,
partial_trie::{Node, PartialTrie, WrappedNode},
};

/// The hash of an empty trie.
const EMPTY_TRIE_HASH: H256 = H256([
0x56, 0xe8, 0x1f, 0x17, 0x1b, 0xcc, 0x55, 0xa6, 0xff, 0x83, 0x45, 0xe6, 0x92, 0xc0, 0xf8, 0x6e,
0x5b, 0x48, 0xe0, 0x1b, 0x99, 0x6c, 0xad, 0xc0, 0x01, 0x62, 0x2f, 0xb5, 0xe3, 0x63, 0xb4, 0x21,
]);

#[derive(Clone, Debug)]
/// A builder for constructing a partial trie from a collection of nodes.
pub struct PartialTrieBuilder<T> {
Expand Down
1 change: 1 addition & 0 deletions trace_decoder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ strum = { version = "0.26.3", features = ["derive"] }
thiserror = { workspace = true }
u4 = { workspace = true }
winnow = { workspace = true }
zk_evm_common = {workspace = true}

[dev-dependencies]
criterion = { workspace = true }
Expand Down
13 changes: 1 addition & 12 deletions trace_decoder/src/processed_block_trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,13 @@ use std::iter::once;

use ethereum_types::{Address, H256, U256};
use evm_arithmetization::generation::mpt::{AccountRlp, LegacyReceiptRlp};
use zk_evm_common::{EMPTY_CODE_HASH, EMPTY_TRIE_HASH};

use crate::hash;
use crate::typed_mpt::TrieKey;
use crate::PartialTriePreImages;
use crate::{ContractCodeUsage, TxnInfo};

// 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470
const EMPTY_CODE_HASH: H256 = H256([
197, 210, 70, 1, 134, 247, 35, 60, 146, 126, 125, 178, 220, 199, 3, 192, 229, 0, 182, 83, 202,
130, 39, 59, 123, 250, 216, 4, 93, 133, 164, 112,
]);

/// 0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421
pub const EMPTY_TRIE_HASH: H256 = H256([
86, 232, 31, 23, 27, 204, 85, 166, 255, 131, 69, 230, 146, 192, 248, 110, 91, 72, 224, 27, 153,
108, 173, 192, 1, 98, 47, 181, 227, 99, 180, 33,
]);

const FIRST_PRECOMPILE_ADDRESS: U256 = U256([1, 0, 0, 0]);
const LAST_PRECOMPILE_ADDRESS: U256 = U256([10, 0, 0, 0]);

Expand Down

0 comments on commit cdd0824

Please sign in to comment.