Skip to content

Commit

Permalink
Merge branch 'main' into ci/add_era_benches
Browse files Browse the repository at this point in the history
  • Loading branch information
fkrause98 committed Aug 19, 2024
2 parents 3f4510d + c1c1d2e commit 4276990
Show file tree
Hide file tree
Showing 14 changed files with 99 additions and 34 deletions.
47 changes: 41 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -449,12 +449,6 @@ jobs:
uses: actions/checkout@v4

- name: Fetch submodules
run: make submodules

- name: Setup nodejs + yarn
uses: actions/setup-node@v4
with:
node-version: 18.20.2
cache-dependency-path: |
${{ github.workspace }}/zksync-era/contracts-test-data/yarn.lock
${{ github.workspace }}/zksync-era/contracts/l1-contracts/yarn.lock
Expand Down Expand Up @@ -519,3 +513,44 @@ jobs:
comment-on-alert: true
# Enable Job Summary for PRs
summary-always: true
zksync_era_tests:
runs-on: ubuntu-latest
steps:
- name: Checkout vm sources
uses: actions/checkout@v4
with:
path: ${{ github.workspace }}/era_vm

- name: Setup compiler-tester submodule
working-directory: ${{ github.workspace }}/era_vm
run: make submodules

- name: Setup nodejs + yarn
uses: actions/setup-node@v4
with:
node-version: 18.20.2
- uses: Swatinem/rust-cache@v2
with:
workspaces: ${{ github.workspace }}

- name: Rustup toolchain install
uses: dtolnay/rust-toolchain@stable
with:
toolchain: ${{ env.RUST_VERSION }}

- name: Setup zksync-era
working-directory: ${{ github.workspace }}/era_vm/zksync-era
run: |
cargo install sqlx-cli --version 0.8.0
mkdir -p ./volumes/reth/data
mkdir -p ./volumes/postgres
docker compose -v up -d
sleep 15
export ZKSYNC_HOME=$(pwd)
export PATH=$PATH:./bin
zk
zk init
- name: Run tests
working-directory: ${{ github.workspace }}/era_vm
run: make era-test
1 change: 1 addition & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[submodule "era-compiler-tester"]
path = era-compiler-tester
url = https://github.com/lambdaclass/era-compiler-tester.git
[submodule "zksync-era"]
path = zksync-era
url = https://github.com/lambdaclass/zksync-era.git
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: clean lint test deps submodules bench
.PHONY: clean lint test deps submodules bench era-test

LLVM_PATH?=$(shell pwd)/era-compiler-tester/target-llvm/target-final/
ZKSYNC_ROOT=$(shell realpath ./zksync-era)
Expand Down Expand Up @@ -69,3 +69,5 @@ bench:

clean-contracts:
rm -rfv $(ZKSYNC_BENCH_CONTRACTS) $(ZKSYNC_SYS_CONTRACTS) $(ZKSYNC_BOOTLOADER_CONTRACT) $(ZKSYNC_L1_CONTRACTS) $(ZKSYNC_L2_CONTRACTS)
era-test: submodules
cd ./zksync-era/core/lib/multivm && cargo t era_vm
2 changes: 1 addition & 1 deletion era-compiler-tester
6 changes: 3 additions & 3 deletions src/call_frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use zkevm_opcode_defs::ethereum_types::Address;

use crate::{execution::Stack, state::StateSnapshot, utils::is_kernel};

#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq)]
pub struct CallFrame {
pub pc: u64,
pub gas_left: Saturating<u32>,
Expand All @@ -13,7 +13,7 @@ pub struct CallFrame {
pub snapshot: StateSnapshot,
}

#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq)]
pub struct CodePage(Vec<U256>);

impl CodePage {
Expand All @@ -25,7 +25,7 @@ impl CodePage {
}
}

#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq)]
pub struct Context {
pub frame: CallFrame,
pub near_call_frames: Vec<CallFrame>,
Expand Down
12 changes: 6 additions & 6 deletions src/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,17 @@ pub const CALLDATA_HEAP: u32 = 1;
pub const FIRST_HEAP: u32 = 2;
pub const FIRST_AUX_HEAP: u32 = 3;

#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq)]
pub struct Stack {
pub stack: Vec<TaggedValue>,
}

#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq)]
pub struct Heap {
heap: Vec<u8>,
}
#[derive(Debug, Clone)]

#[derive(Debug, Clone, PartialEq)]
pub struct Execution {
// The first register, r0, is actually always zero and not really used.
// Writing to it does nothing.
Expand All @@ -49,8 +50,6 @@ pub struct Execution {
pub use_hooks: bool,
}

// Totally arbitrary, probably we will have to change it later.
pub const DEFAULT_INITIAL_GAS: u32 = 1 << 16;
impl Execution {
#[allow(clippy::too_many_arguments)]
pub fn new(
Expand All @@ -63,6 +62,7 @@ impl Execution {
evm_interpreter_code_hash: [u8; 32],
hook_address: u32,
use_hooks: bool,
initial_gas: u32,
) -> Self {
let mut registers = [TaggedValue::default(); 15];
let calldata_ptr = FatPointer {
Expand All @@ -76,7 +76,7 @@ impl Execution {

let context = Context::new(
program_code.clone(),
u32::MAX - 0x80000000,
initial_gas,
contract_address,
contract_address,
caller,
Expand Down
2 changes: 1 addition & 1 deletion src/heaps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use zkevm_opcode_defs::system_params::NEW_FRAME_MEMORY_STIPEND;

use crate::{eravm_error::HeapError, execution::Heap};

#[derive(Debug, Clone, Default)]
#[derive(Debug, Clone, Default, PartialEq)]
pub struct Heaps {
heaps: Vec<Heap>,
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ pub mod vm;
pub use execution::Execution;
pub use opcode::Opcode;
pub use vm::EraVM;
mod rollbacks;
pub mod rollbacks;
pub mod state;
use zkevm_opcode_defs::Opcode as Variant;
40 changes: 33 additions & 7 deletions src/rollbacks.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
use std::collections::{HashMap, HashSet};
use std::{
collections::{HashMap, HashSet},
hash::Hash,
};

pub trait Rollbackable {
type Snapshot;
fn rollback(&mut self, snapshot: Self::Snapshot);
fn snapshot(&self) -> Self::Snapshot;
}

#[derive(Debug, Default)]
pub struct RollbackableHashMap<K: Clone, V: Clone> {
#[derive(Debug, Default, Clone)]
pub struct RollbackableHashMap<K: Clone + Hash, V: Clone> {
pub map: HashMap<K, V>,
}

impl<K: Clone, V: Clone> Rollbackable for RollbackableHashMap<K, V> {
impl<K: Clone + Hash, V: Clone> RollbackableHashMap<K, V> {
pub fn new() -> Self {
Self {
map: HashMap::new(),
}
}
}

impl<K: Clone + Hash, V: Clone> Rollbackable for RollbackableHashMap<K, V> {
type Snapshot = HashMap<K, V>;
fn rollback(&mut self, snapshot: Self::Snapshot) {
self.map = snapshot;
Expand All @@ -22,11 +33,26 @@ impl<K: Clone, V: Clone> Rollbackable for RollbackableHashMap<K, V> {
}
}

#[derive(Debug, Default)]
impl<K: Clone + Hash, V: Clone> Iterator for RollbackableHashMap<K, V> {
type Item = (K, V);
fn next(&mut self) -> Option<Self::Item> {
self.map.iter().next().map(|(k, v)| (k.clone(), v.clone()))
}
}

#[derive(Debug, Default, Clone)]
pub struct RollbackableVec<T: Clone> {
pub entries: Vec<T>,
}

impl<T: Clone> RollbackableVec<T> {
pub fn new() -> Self {
Self {
entries: Vec::new(),
}
}
}

impl<T: Clone> Rollbackable for RollbackableVec<T> {
type Snapshot = Vec<T>;

Expand All @@ -38,7 +64,7 @@ impl<T: Clone> Rollbackable for RollbackableVec<T> {
}
}

#[derive(Debug, Default)]
#[derive(Debug, Default, Clone)]
pub struct RollbackablePrimitive<T: Copy> {
pub value: T,
}
Expand All @@ -54,7 +80,7 @@ impl<T: Copy> Rollbackable for RollbackablePrimitive<T> {
}
}

#[derive(Debug, Default)]
#[derive(Debug, Default, Clone)]
pub struct RollbackableHashSet<K: Clone> {
pub map: HashSet<K>,
}
Expand Down
10 changes: 5 additions & 5 deletions src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ pub struct Event {
pub tx_number: u16,
}

#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct VMState {
pub storage: Rc<RefCell<dyn Storage>>,
storage_changes: RollbackableHashMap<StorageKey, U256>,
transient_storage: RollbackableHashMap<StorageKey, U256>,
l2_to_l1_logs: RollbackableVec<L2ToL1Log>,
events: RollbackableVec<Event>,
pub storage_changes: RollbackableHashMap<StorageKey, U256>,
pub transient_storage: RollbackableHashMap<StorageKey, U256>,
pub l2_to_l1_logs: RollbackableVec<L2ToL1Log>,
pub events: RollbackableVec<Event>,
// holds the sum of pubdata_costs
pubdata: RollbackablePrimitive<i32>,
pubdata_costs: RollbackableVec<i32>,
Expand Down
2 changes: 1 addition & 1 deletion src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ impl Storage for InitialStorageMemory {
}

/// Error type for storage operations.
#[derive(Error, Debug)]
#[derive(Error, Debug, PartialEq)]
pub enum StorageError {
#[error("Key not present in storage")]
KeyNotPresent,
Expand Down
1 change: 1 addition & 0 deletions src/tracers/last_state_saver_tracer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ impl LastStateSaverTracer {
Default::default(),
0,
false,
0,
),
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use u256::U256;

/// In the zkEVM, all data in the stack and on registers is tagged to determine
/// whether they are a pointer or not.
#[derive(Debug, Clone, Copy)]
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct TaggedValue {
pub value: U256,
pub is_pointer: bool,
Expand Down
2 changes: 1 addition & 1 deletion src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub enum ExecutionOutput {
SuspendedOnHook { hook: u32, pc_to_resume_from: u16 },
}

#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct EraVM {
pub state: VMState,
pub execution: Execution,
Expand Down

0 comments on commit 4276990

Please sign in to comment.