Skip to content

Commit

Permalink
implement ContextMeta
Browse files Browse the repository at this point in the history
  • Loading branch information
joonazan committed Dec 11, 2023
1 parent f08de5b commit 5afdc6b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,10 @@ fn decode(raw: u64) -> Instruction {
zkevm_opcode_defs::ContextOpcode::Sp => {
Instruction::from_context_sp(out.try_into().unwrap(), predicate)
}
/*zkevm_opcode_defs::ContextOpcode::Meta => ,
zkevm_opcode_defs::ContextOpcode::SetErgsPerPubdataByte => ,
zkevm_opcode_defs::ContextOpcode::Meta => {
Instruction::from_context_meta(out.try_into().unwrap(), predicate)
}
/*zkevm_opcode_defs::ContextOpcode::SetErgsPerPubdataByte => ,
zkevm_opcode_defs::ContextOpcode::IncrementTxNumber => ,*/
x => unimplemented_instruction(zkevm_opcode_defs::Opcode::Context(x)),
},
Expand Down
19 changes: 19 additions & 0 deletions src/instruction_handlers/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::{
Instruction, Predicate, State,
};
use u256::U256;
use zkevm_opcode_defs::VmMetaParameters;

fn context<Op: ContextOp>(state: &mut State, instruction: *const Instruction) -> InstructionResult {
instruction_boilerplate(state, instruction, |state, args| {
Expand Down Expand Up @@ -59,6 +60,21 @@ impl ContextOp for SP {
}
}

struct Meta;
impl ContextOp for Meta {
fn get(state: &State) -> U256 {
VmMetaParameters {
ergs_per_pubdata_byte: 1,
heap_size: state.heaps[state.current_frame.heap as usize].len() as u32,
aux_heap_size: state.heaps[state.current_frame.aux_heap as usize].len() as u32,
this_shard_id: 0, // TODO properly implement shards
caller_shard_id: 0,
code_shard_id: 0,
}
.to_u256()
}
}

fn set_context_u128(state: &mut State, instruction: *const Instruction) -> InstructionResult {
instruction_boilerplate(state, instruction, |state, args| {
let value = Register1::get(args, state).low_u128();
Expand Down Expand Up @@ -92,6 +108,9 @@ impl Instruction {
pub fn from_context_sp(out: Register1, predicate: Predicate) -> Self {
Self::from_context::<SP>(out, predicate)
}
pub fn from_context_meta(out: Register1, predicate: Predicate) -> Self {
Self::from_context::<Meta>(out, predicate)
}
pub fn from_set_context_u128(src: Register1, predicate: Predicate) -> Self {
Self {
handler: set_context_u128,
Expand Down

0 comments on commit 5afdc6b

Please sign in to comment.