Implement codesize/codecopy for interpreter

This commit is contained in:
Robin Salen 2023-04-10 12:17:26 -04:00
parent 0f3285c33b
commit 6946eacaca
No known key found for this signature in database
GPG Key ID: FB87BACFB3CB2007

View File

@ -340,8 +340,8 @@ impl<'a> Interpreter<'a> {
0x35 => self.run_calldataload(), // "CALLDATALOAD",
0x36 => self.run_calldatasize(), // "CALLDATASIZE",
0x37 => self.run_calldatacopy(), // "CALLDATACOPY",
0x38 => todo!(), // "CODESIZE",
0x39 => todo!(), // "CODECOPY",
0x38 => self.run_codesize(), // "CODESIZE",
0x39 => self.run_codecopy(), // "CODECOPY",
0x3a => self.run_gasprice(), // "GASPRICE",
0x3b => todo!(), // "EXTCODESIZE",
0x3c => todo!(), // "EXTCODECOPY",
@ -804,6 +804,32 @@ impl<'a> Interpreter<'a> {
}
}
fn run_codesize(&mut self) {
self.push(
self.generation_state.memory.contexts[self.context].segments
[Segment::ContextMetadata as usize]
.get(ContextMetadata::CodeSize as usize),
)
}
fn run_codecopy(&mut self) {
let dest_offset = self.pop().as_usize();
let offset = self.pop().as_usize();
let size = self.pop().as_usize();
for i in 0..size {
let code_byte =
self.generation_state
.memory
.mload_general(self.context, Segment::Code, offset + i);
self.generation_state.memory.mstore_general(
self.context,
Segment::MainMemory,
dest_offset + i,
code_byte,
);
}
}
fn run_gasprice(&mut self) {
self.push(self.get_txn_field(NormalizedTxnField::ComputedFeePerGas))
}