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

Initial setup #3

Merged
merged 7 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 2 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[env]
RUST_MIN_STACK = "8388608"
3 changes: 3 additions & 0 deletions .config/nextest.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[profile.default]
slow-timeout = { period = "180s", terminate-after = 5, grace-period = "30s" }

58 changes: 58 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: "Rust CI"
on:
pull_request:

jobs:
build:
name: cargo build
runs-on: [ubuntu-22.04-github-hosted-32core]
steps:
- uses: actions/checkout@v3
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
rustflags: ""
- name: Setup rust
run: |
rustup set profile minimal
rustup toolchain install nightly-2023-08-23
rustup default nightly-2023-08-23
cargo install cargo-nextest
- name: Compile
run: cargo build

test:
name: cargo test
runs-on: [ubuntu-22.04-github-hosted-32core]
needs: build
steps:
- uses: actions/checkout@v3
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
rustflags: ""
- name: Setup rust
run: |
rustup set profile minimal
rustup toolchain install nightly-2023-08-23
rustup default nightly-2023-08-23
cargo install cargo-nextest
- name: zkevm_test_harness - Main test
run: cargo nextest run --release --manifest-path crates/zkevm_test_harness/Cargo.toml --test-threads 2
- name: Encodings test
run: cargo nextest run --release --manifest-path crates/circuit_encodings/Cargo.toml
- name: Api tests
run: cargo nextest run --release --manifest-path crates/circuit_sequencer_api/Cargo.toml
- name: Definitions test
run: cargo nextest run --release --manifest-path crates/circuit_definitions/Cargo.toml
- name: Kzg tests
run: cargo nextest run --release --manifest-path crates/kzg/Cargo.toml

formatting:
name: cargo fmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
components: rustfmt
- name: Rustfmt Check
uses: actions-rust-lang/rustfmt@v1
8 changes: 8 additions & 0 deletions .github/workflows/deny.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
name: Cargo deny check
on: pull_request
jobs:
cargo-deny:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: EmbarkStudios/cargo-deny-action@v1
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ target/
Cargo.lock
.vscode
*.log
tmp_copy*
4 changes: 4 additions & 0 deletions crates/circuit_definitions/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/target
Cargo.lock
.idea
.DS_Store
27 changes: 27 additions & 0 deletions crates/circuit_definitions/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[package]
name = "circuit_definitions"
version = "0.150.2"
edition = "2021"
authors = ["The Matter Labs Team <[email protected]>"]
homepage = "https://zksync.io/"
repository = "https://github.com/matter-labs/era-zkevm_test_harness/"
license = "MIT OR Apache-2.0"
keywords = ["blockchain", "zksync"]
categories = ["cryptography"]
description = "ZKsync Era circuits definitions"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
circuit_encodings = { version = "0.150.2", path = "../circuit_encodings" }
snark_wrapper = "=0.1.2"

derivative = "2.2"
serde = {version = "1", features = ["derive"]}
crossbeam = "0.8"
seq-macro = "0.3.5"

[features]
default = []
log_tracing = ["circuit_encodings/log_tracing"]
verbose_circuits = ["circuit_encodings/verbose_circuits"]
55 changes: 55 additions & 0 deletions crates/circuit_definitions/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Circuits definitions crate

This crate contains the 'outer layer' for multiple circuits. The concrete circuits code is in `era-zkevm_circuits`
repository.

## Code structure

We have 13 different 'base layer' circuits (for example MainVM, Decomitter), and 3 recursive circuits (Leaf, Node and
Scheduler).

Base layer circuits are located in `src/base_layer`, Recursive circuits are in `src/recursion_layer`.

We also have 'AUX' circuits: compressors and wrapper, that are run on top of the final Scheduler proof, and they are
located in `src/aux_layer`.

![circuits](https://user-images.githubusercontent.com/128217157/275817097-0a543476-52e5-437b-a7d3-10603d5833fa.png)

`src/encodings` directory contain some helper structs that are used by the test harness (and should match the ones used
in circuits themselves).

## Circuit types

We have 12 different circuit types (in witness, you might notice 13, as one circuit (events_dedup_and_sort) is used for
both L1 messages and events).

| Circuit name | Location | Description |
| ------------------------ | ---------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Main VM | vm_main.rs | Executes OpCodes from the VM |
| CodeDecommittmentsSorter | sort_code_decommit.rs | Verifies the order of requests for code decommitment (fetching bytecode based on hash). |
| CodeDecommiter | code_decommiter.rs | Unpacks the bytecode matching a given hash into memory. |
| LogDemuxer | log_demux.rs | Splits the queue into 6 output ones (like keccak, sha, storage). |
| KeccakRoundFunction | keccak256_round_functions.rs | Round of the keccak hash |
| Sha256RoundFunction | sha256_round_function.rs | Round of sha256 hash |
| ECRecover | ecrecover.rs | Verifies ECRecover |
| RAMPermutation | ram_permutation.rs | Verifies the correctness of the RAM accesses - looking at the access queue, and checking that correct bytes values were read |
| StorageSorter | storage_sort_dedup.rs | Similar to RAM permutation, but for storage - checking that correct bytes were stored / read. |
| StorageApplication | storage_apply.rs | Verifies the final merkle root and storage diffs based on the data that was written during computation. |
| EventsSorter | events_sort_dedup.rs | Verifies that a given 'unsorted' queue is matching the sorted one, without any repetitions. In this case, used for System Events. |
| L1MessagesSorter | events_sort_dedup.rs | It reuses the circuit above, but this time to sort user generated events (L2 -> L1 messages). |
| L1MessageHasher | linear_hasher.rs | Verifies that linear hash of L1 messages matches the content of the queue. |

3 recursive circuits:

| Circuit name | Location | Description |
| ------------ | ------------- | --------------------------------------------------------- |
| Leaf | leaf_layer.rs | Aggregates 32 basic circuits of the same type |
| Node | node_layer.rs | Aggregates 32 leaf (or node) circruits of the same type |
| Scheduler | scheduler.rs | Aggregates 13 nodes (1 from each type) into a final proof |

And 'wrapper'/AUX circuits on top:

| Circuit name | Location | Description |
| ------------ | -------------- | ---------------------------------------------------------------------------------------- |
| Compression | compression.rs | Compresses the final scheduler proof |
| Wrapper | wrapper.rs | Wraps the compressed proof into a SNARK to be verifierd on L1. (This is a SNARK circuit) |
2 changes: 2 additions & 0 deletions crates/circuit_definitions/rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[toolchain]
channel = "nightly-2024-08-01"
1 change: 1 addition & 0 deletions crates/circuit_definitions/src/aux_definitions/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod witness_oracle;
Loading
Loading