-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix tests * Add far_call test * fix build issues * restore far call op * fix tests * clippy * cargo fmt * move call frame to separate file * clippy, pr comments * fix build * format * pr comments --------- Co-authored-by: Fran <[email protected]>
- Loading branch information
Showing
11 changed files
with
246 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
.text | ||
.file "far_call.zasm" | ||
.globl __entry | ||
__entry: | ||
fake_routine: | ||
|
||
.func_begin0: | ||
sstore r0, r0 | ||
far_call r1, r1, @fake_routine | ||
ret | ||
|
||
.func_end0: | ||
|
||
.note.GNU-stack | ||
.rodata |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
use std::{cell::RefCell, num::Saturating, rc::Rc}; | ||
|
||
use u256::U256; | ||
|
||
use crate::{ | ||
state::Stack, | ||
store::{InMemory, Storage}, | ||
}; | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct CallFrame { | ||
// Max length for this is 1 << 16. Might want to enforce that at some point | ||
pub stack: Stack, | ||
pub heap: Vec<U256>, | ||
// Code memory is word addressable even though instructions are 64 bit wide. | ||
// TODO: this is a Vec of opcodes now but it's probably going to switch back to a | ||
// Vec<U256> later on, because I believe we have to record memory queries when | ||
// fetching code to execute. Check this | ||
pub code_page: Vec<U256>, | ||
pub pc: u64, | ||
/// Storage for the frame using a type that implements the Storage trait. | ||
/// The supported types are InMemory and RocksDB storage. | ||
pub storage: Rc<RefCell<dyn Storage>>, | ||
/// Transient storage should be used for temporary storage within a transaction and then discarded. | ||
pub transient_storage: InMemory, | ||
pub gas_left: Saturating<u32>, | ||
} | ||
impl CallFrame { | ||
pub fn new( | ||
program_code: Vec<U256>, | ||
gas_stipend: u32, | ||
storage: Rc<RefCell<dyn Storage>>, | ||
) -> Self { | ||
Self { | ||
stack: Stack::new(), | ||
heap: vec![], | ||
code_page: program_code, | ||
pc: 0, | ||
gas_left: Saturating(gas_stipend), | ||
storage, | ||
transient_storage: InMemory::default(), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
use std::{cell::RefCell, collections::HashMap, rc::Rc}; | ||
|
||
use zkevm_opcode_defs::FarCallOpcode; | ||
|
||
use crate::{state::VMState, store::InMemory}; | ||
|
||
pub fn far_call(vm: &mut VMState, opcode: &FarCallOpcode) { | ||
match opcode { | ||
FarCallOpcode::Normal => { | ||
let program_code = vm.current_context().code_page.clone(); | ||
let stipend = vm.current_context().gas_left; | ||
let storage = Rc::new(RefCell::new(InMemory(HashMap::new()))); | ||
vm.push_frame(program_code, stipend.0 / 32, storage) | ||
} | ||
_ => todo!(), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
pub mod add; | ||
pub mod and; | ||
pub mod div; | ||
pub mod far_call; | ||
pub mod jump; | ||
pub mod log; | ||
pub mod mul; | ||
|
Oops, something went wrong.