#zk-sync #blockchain #leaf-node

nightly circuit_definitions

ZKsync Era circuits definitions

18 releases

new 0.150.12 Nov 6, 2024
0.150.11 Oct 31, 2024
0.150.5 Sep 6, 2024
0.150.4 Aug 16, 2024
0.140.0-gpu-wrapper.0 Jul 8, 2024

#665 in Magic Beans

Download history 1395/week @ 2024-07-17 3975/week @ 2024-07-24 2906/week @ 2024-07-31 2245/week @ 2024-08-07 3411/week @ 2024-08-14 4874/week @ 2024-08-21 7954/week @ 2024-08-28 9280/week @ 2024-09-04 9593/week @ 2024-09-11 2487/week @ 2024-09-18 1994/week @ 2024-09-25 3107/week @ 2024-10-02 4001/week @ 2024-10-09 3268/week @ 2024-10-16 4301/week @ 2024-10-23 3289/week @ 2024-10-30

15,680 downloads per month
Used in 5 crates

MIT/Apache

390KB
9K SLoC

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

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)

Dependencies

~24MB
~441K SLoC