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

Zksync-era basic tests integration #191

Closed
wants to merge 5 commits into from
Closed
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[submodule "era-compiler-tester"]
path = era-compiler-tester
url = https://github.com/lambdaclass/era-compiler-tester.git
branch = zksync-era-tests
4 changes: 2 additions & 2 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::{state::Stack, store::SnapShot, utils::is_kernel};

#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq)]
pub struct CallFrame {
pub pc: u64,
pub transient_storage_snapshot: SnapShot,
Expand All @@ -14,7 +14,7 @@ pub struct CallFrame {
pub storage_snapshot: SnapShot,
}

#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq)]
pub struct Context {
pub frame: CallFrame,
pub near_call_frames: Vec<CallFrame>,
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, state::Heap};

#[derive(Debug, Clone, Default)]
#[derive(Debug, Clone, Default, PartialEq)]
pub struct Heaps {
heaps: Vec<Heap>,
}
Expand Down
13 changes: 6 additions & 7 deletions src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ 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 VMState {
// The first register, r0, is actually always zero and not really used.
// Writing to it does nothing.
Expand All @@ -50,8 +50,6 @@ pub struct VMState {
pub use_hooks: bool,
}

// Totally arbitrary, probably we will have to change it later.
pub const DEFAULT_INITIAL_GAS: u32 = 1 << 16;
impl VMState {
#[allow(clippy::too_many_arguments)]
pub fn new(
Expand All @@ -64,6 +62,7 @@ impl VMState {
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 @@ -77,7 +76,7 @@ impl VMState {

let context = Context::new(
program_code.clone(),
u32::MAX - 0x80000000,
initial_gas,
contract_address,
contract_address,
caller,
Expand Down Expand Up @@ -478,7 +477,7 @@ impl Heap {
}
}

#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq)]
pub struct Event {
pub key: U256,
pub value: U256,
Expand Down
9 changes: 7 additions & 2 deletions src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ impl InitialStorage for InitialStorageMemory {

pub trait ContractStorage: Debug {
fn decommit(&self, hash: U256) -> Result<Option<Vec<U256>>, StorageError>;
fn hash_map(&self) -> Result<HashMap<U256, Vec<U256>>, StorageError>;
}
#[derive(Debug)]
pub struct ContractStorageMemory {
Expand All @@ -50,13 +51,17 @@ impl ContractStorage for ContractStorageMemory {
fn decommit(&self, hash: U256) -> Result<Option<Vec<U256>>, StorageError> {
Ok(self.contract_storage.get(&hash).cloned())
}

fn hash_map(&self) -> Result<HashMap<U256, Vec<U256>>, StorageError> {
Ok(self.contract_storage.clone())
}
Comment on lines +55 to +57
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand the reason for this change.

}

#[derive(Debug)]
pub struct StateStorage {
pub storage_changes: HashMap<StorageKey, U256>,
pub initial_storage: Rc<RefCell<dyn InitialStorage>>,
l2_to_l1_logs: Vec<L2ToL1Log>,
pub l2_to_l1_logs: Vec<L2ToL1Log>,
}

impl Default for StateStorage {
Expand Down Expand Up @@ -125,7 +130,7 @@ impl StateStorage {
}
}

#[derive(Debug, Clone, Default)]
#[derive(Debug, Clone, Default, PartialEq)]
pub struct SnapShot {
pub storage_changes: HashMap<StorageKey, U256>,
}
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