Skip to content

Commit

Permalink
revert all changes but the imports
Browse files Browse the repository at this point in the history
  • Loading branch information
montekki committed Aug 19, 2024
1 parent ab84a58 commit 4dddaa5
Show file tree
Hide file tree
Showing 19 changed files with 341 additions and 401 deletions.
74 changes: 30 additions & 44 deletions eravm-stable-interface/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,60 +24,46 @@
//!
//! This is how you would add a new method to StateInterface and a new opcode.
//! ```
//! # use eravm_stable_interface as eravm_stable_interface_v1;
//! use eravm_stable_interface_v1::{StateInterface as StateInterfaceV1, Tracer as TracerV1, opcodes::NearCall};
//!
//! trait StateInterface: StateInterfaceV1 {
//! # trait StateInterface {}
//! # trait Tracer {
//! # #[inline(always)]
//! # fn before_old_opcode<S: StateInterface>(&mut self, _state: &mut S) {}
//! # #[inline(always)]
//! # fn after_old_opcode<S: StateInterface>(&mut self, _state: &mut S) {}
//! # }
//!
//! trait StateInterfaceV2: StateInterface {
//! fn get_some_new_field(&self) -> u32;
//! }
//!
//! pub struct NewOpcode;
//!
//! #[derive(PartialEq, Eq)]
//! enum Opcode {
//! NewOpcode,
//! NearCall,
//! // ...
//! }
//!
//! trait OpcodeType {
//! const VALUE: Opcode;
//! }
//!
//! impl OpcodeType for NewOpcode {
//! const VALUE: Opcode = Opcode::NewOpcode;
//! trait TracerV2 {
//! // redefine all existing opcodes
//! #[inline(always)]
//! fn before_old_opcode<S: StateInterfaceV2>(&mut self, _state: &mut S) {}
//! #[inline(always)]
//! fn after_old_opcode<S: StateInterfaceV2>(&mut self, _state: &mut S) {}
//!
//! #[inline(always)]
//! fn before_new_opcode<S: StateInterfaceV2>(&mut self, _state: &mut S) {}
//! #[inline(always)]
//! fn after_new_opcode<S: StateInterfaceV2>(&mut self, _state: &mut S) {}
//! }
//!
//! // Do this for every old opcode
//! impl OpcodeType for NearCall {
//! const VALUE: Opcode = Opcode::NearCall;
//! }
//!
//! trait Tracer {
//! fn before_instruction<OP: OpcodeType, S: StateInterface>(&mut self, _state: &mut S) {}
//! fn after_instruction<OP: OpcodeType, S: StateInterface>(&mut self, _state: &mut S) {}
//! }
//!
//! impl<T: TracerV1> Tracer for T {
//! fn before_instruction<OP: OpcodeType, S: StateInterface>(&mut self, state: &mut S) {
//! match OP::VALUE {
//! Opcode::NewOpcode => {}
//! // Do this for every old opcode
//! Opcode::NearCall => {
//! <Self as TracerV1>::before_instruction::<NearCall, _>(self, state)
//! }
//! }
//! impl<T: Tracer> TracerV2 for T {
//! // repeat this for all existing opcodes
//! fn before_old_opcode<S: StateInterfaceV2>(&mut self, state: &mut S) {
//! <Self as Tracer>::before_old_opcode(self, state);
//! }
//! fn after_old_opcode<S: StateInterfaceV2>(&mut self, state: &mut S) {
//! <Self as Tracer>::after_old_opcode(self, state);
//! }
//! fn after_instruction<OP: OpcodeType, S: StateInterface>(&mut self, _state: &mut S) {}
//! }
//!
//! // Now you can use the new features by implementing TracerV2
//! struct MyTracer;
//! impl Tracer for MyTracer {
//! fn before_instruction<OP: OpcodeType, S: StateInterface>(&mut self, state: &mut S) {
//! if OP::VALUE == Opcode::NewOpcode {
//! state.get_some_new_field();
//! }
//! impl TracerV2 for MyTracer {
//! fn before_new_opcode<S: StateInterfaceV2>(&mut self, state: &mut S) {
//! state.get_some_new_field();
//! }
//! }
//! ```
Expand Down
49 changes: 42 additions & 7 deletions eravm-stable-interface/src/state_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ pub trait StateInterface {

fn number_of_callframes(&self) -> usize;
/// zero is the current frame, one is the frame before that etc.
fn current_frame(&mut self) -> impl CallframeInterface + '_;
fn callframe(&mut self, n: usize) -> impl CallframeInterface + '_;

fn read_heap_byte(&self, heap: HeapId, index: u32) -> u8;
Expand All @@ -22,6 +21,10 @@ pub trait StateInterface {
fn set_context_u128_register(&mut self, value: u128);

fn get_storage_state(&self) -> impl Iterator<Item = ((H160, U256), U256)>;
/// Returns the new value and the amount of pubdata paid for it.
fn get_storage(&self, address: H160, slot: U256) -> Option<(U256, u32)>;
fn get_storage_initial_value(&self, address: H160, slot: U256) -> U256;
fn write_storage(&mut self, address: H160, slot: U256, value: U256);

fn get_transient_storage_state(&self) -> impl Iterator<Item = ((H160, U256), U256)>;
fn get_transient_storage(&self, address: H160, slot: U256) -> U256;
Expand All @@ -32,6 +35,11 @@ pub trait StateInterface {

fn pubdata(&self) -> i32;
fn set_pubdata(&mut self, value: i32);

/// it is run in kernel mode
fn run_arbitrary_code(code: &[u64]);

fn static_heap(&self) -> HeapId;
}

pub struct Flags {
Expand Down Expand Up @@ -83,8 +91,6 @@ pub trait CallframeInterface {
fn set_aux_heap_bound(&mut self, value: u32);

fn read_code_page(&self, slot: u16) -> U256;

fn last_precompile_cycles(&self) -> usize;
}

#[derive(Copy, Clone, PartialEq, Debug)]
Expand Down Expand Up @@ -186,6 +192,31 @@ impl StateInterface for DummyState {
std::iter::empty()
}

fn get_storage(
&self,
_: primitive_types::H160,
_: primitive_types::U256,
) -> Option<(primitive_types::U256, u32)> {
unimplemented!()
}

fn get_storage_initial_value(
&self,
_: primitive_types::H160,
_: primitive_types::U256,
) -> primitive_types::U256 {
unimplemented!()
}

fn write_storage(
&mut self,
_: primitive_types::H160,
_: primitive_types::U256,
_: primitive_types::U256,
) {
unimplemented!()
}

fn get_transient_storage_state(
&self,
) -> impl Iterator<
Expand Down Expand Up @@ -229,6 +260,14 @@ impl StateInterface for DummyState {
fn set_pubdata(&mut self, _: i32) {
unimplemented!()
}

fn run_arbitrary_code(_: &[u64]) {
unimplemented!()
}

fn static_heap(&self) -> crate::HeapId {
unimplemented!()
}
}

#[cfg(test)]
Expand Down Expand Up @@ -344,8 +383,4 @@ impl CallframeInterface for DummyState {
fn read_code_page(&self, _: u16) -> primitive_types::U256 {
unimplemented!()
}

fn last_precompile_cycles(&self) -> usize {
todo!()
}
}
Loading

0 comments on commit 4dddaa5

Please sign in to comment.