Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use ruint::aliases::B160;
use zk_ee::common_structs::GenericEventContentWithTxRef;
use zk_ee::logger_log;
use zk_ee::storage_types::MAX_EVENT_TOPICS;
use zk_ee::system::errors::system::SystemError;
use zk_ee::system::logger::Logger;
use zk_ee::system::IOSubsystemExt;
use zk_ee::system::System;
use zk_ee::system::MAX_EVENT_TOPICS;
use zk_ee::system::{EthereumLikeTypes, IOTeardown};
use zk_ee::types_config::EthereumIOTypesConfig;
use zk_ee::utils::Bytes32;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use super::*;
use crate::bootloader::rlp;
use crate::bootloader::transaction_flow::ethereum::LogsBloom;
use basic_system::system_implementation::ethereum_storage_model::ByteBuffer;
use zk_ee::storage_types::MAX_EVENT_TOPICS;
use zk_ee::system::MAX_EVENT_TOPICS;
use zk_ee::{common_structs::GenericEventContentRef, types_config::EthereumIOTypesConfig};

impl<'a> RLPEncodable for GenericEventContentRef<'a, MAX_EVENT_TOPICS, EthereumIOTypesConfig> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ use zk_ee::execution_environment_type::ExecutionEnvironmentType;
use zk_ee::interface_error;
use zk_ee::internal_error;
use zk_ee::out_of_native_resources;
use zk_ee::storage_types::MAX_EVENT_TOPICS;
use zk_ee::system::errors::root_cause::GetRootCause;
use zk_ee::system::errors::root_cause::RootCause;
use zk_ee::system::errors::runtime::RuntimeError;
use zk_ee::system::errors::subsystem::SubsystemError;
use zk_ee::system::logger::Logger;
use zk_ee::system::MAX_EVENT_TOPICS;
use zk_ee::system::*;
use zk_ee::system_log;
use zk_ee::types_config::EthereumIOTypesConfig;
Expand Down
3 changes: 1 addition & 2 deletions basic_system/src/system_implementation/system/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ use zk_ee::utils::Bytes32;
use zk_ee::{
memory::stack_trait::StackFactory,
oracle::IOOracle,
storage_types::MAX_EVENT_TOPICS,
system::{errors::internal::InternalError, logger::Logger, Resources, *},
system::{errors::internal::InternalError, logger::Logger, Resources, MAX_EVENT_TOPICS, *},
};

pub mod interop_roots;
Expand Down
2 changes: 1 addition & 1 deletion evm_interpreter/src/instructions/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ use gas_constants::{CALL_STIPEND, INITCODE_WORD_COST, SHA3WORD};

use native_resource_constants::*;
use zk_ee::common_structs::system_hooks::HooksStorage;
use zk_ee::storage_types::MAX_EVENT_TOPICS;
use zk_ee::system::tracer::evm_tracer::EvmTracer;
use zk_ee::system::tracer::Tracer;
use zk_ee::system::MAX_EVENT_TOPICS;
use zk_ee::{system::*, wrap_error};

use super::*;
Expand Down
2 changes: 1 addition & 1 deletion forward_system/src/run/result_keeper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use zk_ee::common_structs::{
GenericEventContent, GenericEventContentWithTxRef, GenericLogContent,
GenericLogContentWithTxRef, PreimageType,
};
use zk_ee::storage_types::MAX_EVENT_TOPICS;
use zk_ee::system::IOResultKeeper;
use zk_ee::system::MAX_EVENT_TOPICS;
use zk_ee::types_config::EthereumIOTypesConfig;
use zk_ee::utils::{Bytes32, UsizeAlignedByteBox};

Expand Down
2 changes: 1 addition & 1 deletion system_hooks/src/event_hooks/interop_root_reporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use zk_ee::types_config::SystemIOTypesConfig;
use zk_ee::{
common_structs::interop_root_storage::InteropRoot,
execution_environment_type::ExecutionEnvironmentType, internal_error,
storage_types::MAX_EVENT_TOPICS, system::errors::system::SystemError, utils::Bytes32,
system::errors::system::SystemError, system::MAX_EVENT_TOPICS, utils::Bytes32,
};

// InteropRootAdded(uint256,uint256,bytes32[]) - 6b451b8422636e45b93bf7f594fa2c1769d039766c4254a6e7f9c0ee1715cdb0
Expand Down
2 changes: 1 addition & 1 deletion system_hooks/src/event_hooks/system_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use ruint::aliases::U256;
use zk_ee::types_config::SystemIOTypesConfig;
use zk_ee::{
execution_environment_type::ExecutionEnvironmentType, internal_error,
storage_types::MAX_EVENT_TOPICS, system::errors::system::SystemError,
system::errors::system::SystemError, system::MAX_EVENT_TOPICS,
};

// SettlementLayerChainIdUpdated(uint256) - 208daf0b9291c1e9a1697737d736630c808045f81f5bc5ae7b8ed740eb5a4d7a
Expand Down
1 change: 0 additions & 1 deletion zk_ee/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ serde = { workspace = true, default-features = false, features = ["derive"], opt

cfg-if = { workspace = true }
crypto = { path = "../crypto", default-features = false }
bitflags = { version = "2.6.0", default-features = false }
cycle_marker = { path = "../cycle_marker" }
strum_macros = { workspace = true }
paste = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion zk_ee/src/common_structs/system_hooks.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::internal_error;
use crate::storage_types::MAX_EVENT_TOPICS;
use crate::system::errors::internal::InternalError;
use crate::system::{
errors::system::SystemError, CompletedExecution, ExternalCallRequest, System, SystemTypes,
MAX_EVENT_TOPICS,
};
use crate::types_config::SystemIOTypesConfig;
use alloc::collections::BTreeMap;
Expand Down
37 changes: 37 additions & 0 deletions zk_ee/src/storage_types/initial_storage_slot_data.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
use crate::oracle::usize_serialization::{UsizeDeserializable, UsizeSerializable};
use crate::utils::exact_size_chain::ExactSizeChain;
use crate::{system::errors::internal::InternalError, types_config::SystemIOTypesConfig};

#[derive(Clone, Copy, Debug, Default)]
pub struct InitialStorageSlotData<IOTypes: SystemIOTypesConfig> {
// We need to know what was a value of the storage slot,
// and whether it existed in the state or has to be created
// (so additional information is needed to reconstruct creation location).
pub is_new_storage_slot: bool,
pub initial_value: IOTypes::StorageValue,
}

impl<IOTypes: SystemIOTypesConfig> UsizeSerializable for InitialStorageSlotData<IOTypes> {
const USIZE_LEN: usize = <bool as UsizeSerializable>::USIZE_LEN
+ <IOTypes::StorageValue as UsizeSerializable>::USIZE_LEN;

fn iter(&self) -> impl ExactSizeIterator<Item = usize> {
ExactSizeChain::new(
UsizeSerializable::iter(&self.is_new_storage_slot),
UsizeSerializable::iter(&self.initial_value),
)
}
}

impl<IOTypes: SystemIOTypesConfig> UsizeDeserializable for InitialStorageSlotData<IOTypes> {
const USIZE_LEN: usize = <Self as UsizeSerializable>::USIZE_LEN;

fn from_iter(src: &mut impl ExactSizeIterator<Item = usize>) -> Result<Self, InternalError> {
let is_new_storage_slot = UsizeDeserializable::from_iter(src)?;
let initial_value = UsizeDeserializable::from_iter(src)?;
Ok(Self {
is_new_storage_slot,
initial_value,
})
}
}
113 changes: 5 additions & 108 deletions zk_ee/src/storage_types/mod.rs
Original file line number Diff line number Diff line change
@@ -1,110 +1,7 @@
//! Serialization and deserialization helpers for keys and values for storage.
//! Serialization and deserialization helpers for storage-related keys and values.

use crate::oracle::usize_serialization::{UsizeDeserializable, UsizeSerializable};
use crate::utils::exact_size_chain::ExactSizeChain;
mod initial_storage_slot_data;
mod storage_address;

use super::system::errors::internal::InternalError;
use super::types_config::SystemIOTypesConfig;

// TODO(EVM-1167): cleanup

bitflags::bitflags! {
/// Represents a set of flags.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct EmptyBitflags: u32 {}
}

pub trait ReadonlyKVMarker: 'static {
const CAN_BE_COLD_AND_WARM_READ: bool = true;

type Key: UsizeSerializable;
type Value: UsizeDeserializable;
type AccessStatsBitmask: bitflags::Flags<Bits = u32>;
}

pub trait ReadWriteKVMarker: ReadonlyKVMarker
where
Self::Value: UsizeSerializable,
{
const CAN_BE_COLD_AND_WARM_WRITE: bool = true;
}

// helper structs for most of the cases

#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub struct StorageAddress<IOTypes: SystemIOTypesConfig> {
pub address: IOTypes::Address,
pub key: IOTypes::StorageKey,
}

impl<IOTypes: SystemIOTypesConfig> UsizeSerializable for StorageAddress<IOTypes> {
const USIZE_LEN: usize = <IOTypes::Address as UsizeSerializable>::USIZE_LEN
+ <IOTypes::StorageKey as UsizeSerializable>::USIZE_LEN;

fn iter(&self) -> impl ExactSizeIterator<Item = usize> {
ExactSizeChain::new(
UsizeSerializable::iter(&self.address),
UsizeSerializable::iter(&self.key),
)
}
}

impl<IOTypes: SystemIOTypesConfig> UsizeDeserializable for StorageAddress<IOTypes> {
const USIZE_LEN: usize = <Self as UsizeSerializable>::USIZE_LEN;

fn from_iter(src: &mut impl ExactSizeIterator<Item = usize>) -> Result<Self, InternalError> {
let address = UsizeDeserializable::from_iter(src)?;
let key = UsizeDeserializable::from_iter(src)?;

let new = Self { address, key };

Ok(new)
}
}

#[derive(Clone, Copy, Debug)]
pub struct InitialStorageSlotData<IOTypes: SystemIOTypesConfig> {
// we need to know what was a value of the storage slot,
// and whether it existed in the state or has to be created
// (so additional information is needed to reconstruct creation location)
pub is_new_storage_slot: bool,
pub initial_value: IOTypes::StorageValue,
}

impl<IOTypes: SystemIOTypesConfig> Default for InitialStorageSlotData<IOTypes> {
fn default() -> Self {
Self {
is_new_storage_slot: false,
initial_value: IOTypes::StorageValue::default(),
}
}
}

impl<IOTypes: SystemIOTypesConfig> UsizeSerializable for InitialStorageSlotData<IOTypes> {
const USIZE_LEN: usize = <bool as UsizeSerializable>::USIZE_LEN
+ <IOTypes::StorageValue as UsizeSerializable>::USIZE_LEN;
fn iter(&self) -> impl ExactSizeIterator<Item = usize> {
ExactSizeChain::new(
UsizeSerializable::iter(&self.is_new_storage_slot),
UsizeSerializable::iter(&self.initial_value),
)
}
}

impl<IOTypes: SystemIOTypesConfig> UsizeDeserializable for InitialStorageSlotData<IOTypes> {
const USIZE_LEN: usize = <Self as UsizeSerializable>::USIZE_LEN;

fn from_iter(src: &mut impl ExactSizeIterator<Item = usize>) -> Result<Self, InternalError> {
let is_new_storage_slot = UsizeDeserializable::from_iter(src)?;
let initial_value = UsizeDeserializable::from_iter(src)?;

let new = Self {
is_new_storage_slot,
initial_value,
};

Ok(new)
}
}

pub const MAX_EVENT_TOPICS: usize = 4;
pub use initial_storage_slot_data::InitialStorageSlotData;
pub use storage_address::StorageAddress;
31 changes: 31 additions & 0 deletions zk_ee/src/storage_types/storage_address.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use crate::oracle::usize_serialization::{UsizeDeserializable, UsizeSerializable};
use crate::utils::exact_size_chain::ExactSizeChain;
use crate::{system::errors::internal::InternalError, types_config::SystemIOTypesConfig};

#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub struct StorageAddress<IOTypes: SystemIOTypesConfig> {
pub address: IOTypes::Address,
pub key: IOTypes::StorageKey,
}

impl<IOTypes: SystemIOTypesConfig> UsizeSerializable for StorageAddress<IOTypes> {
const USIZE_LEN: usize = <IOTypes::Address as UsizeSerializable>::USIZE_LEN
+ <IOTypes::StorageKey as UsizeSerializable>::USIZE_LEN;

fn iter(&self) -> impl ExactSizeIterator<Item = usize> {
ExactSizeChain::new(
UsizeSerializable::iter(&self.address),
UsizeSerializable::iter(&self.key),
)
}
}

impl<IOTypes: SystemIOTypesConfig> UsizeDeserializable for StorageAddress<IOTypes> {
const USIZE_LEN: usize = <Self as UsizeSerializable>::USIZE_LEN;

fn from_iter(src: &mut impl ExactSizeIterator<Item = usize>) -> Result<Self, InternalError> {
let address = UsizeDeserializable::from_iter(src)?;
let key = UsizeDeserializable::from_iter(src)?;
Ok(Self { address, key })
}
}
1 change: 1 addition & 0 deletions zk_ee/src/system/constants.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub const MAX_SCRATCH_SPACE_USIZE_WORDS: usize = 128;
pub const MAX_EVENT_TOPICS: usize = 4;

pub const BLAKE_DELEGATION_COEFFICIENT: u64 = 16;
pub const BIGINT_DELEGATION_COEFFICIENT: u64 = 4;
Expand Down
2 changes: 1 addition & 1 deletion zk_ee/src/system/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::common_structs::GenericEventContentRef;
use crate::define_subsystem;
use crate::execution_environment_type::ExecutionEnvironmentType;
use crate::oracle::IOOracle;
use crate::storage_types::MAX_EVENT_TOPICS;
use crate::system::MAX_EVENT_TOPICS;
use crate::types_config::{EthereumIOTypesConfig, SystemIOTypesConfig};
use crate::utils::Bytes32;
use arrayvec::ArrayVec;
Expand Down
1 change: 0 additions & 1 deletion zk_ee/src/system/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ use crate::utils::Bytes32;
use crate::{
execution_environment_type::ExecutionEnvironmentType,
oracle::IOOracle,
storage_types::MAX_EVENT_TOPICS,
types_config::{EthereumIOTypesConfig, SystemIOTypesConfig},
};

Expand Down
2 changes: 1 addition & 1 deletion zk_ee/src/system/result_keeper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use crate::common_structs::{
GenericEventContentWithTxRef, GenericLogContentWithTxRef, PreimageType,
};
use crate::storage_types::MAX_EVENT_TOPICS;
use crate::system::MAX_EVENT_TOPICS;
use crate::types_config::SystemIOTypesConfig;

pub trait IOResultKeeper<IOTypes: SystemIOTypesConfig> {
Expand Down
Loading