Skip to content

Commit

Permalink
refactor: remove _current_ctx prefix and suffix
Browse files Browse the repository at this point in the history
  • Loading branch information
Eikix committed Oct 2, 2023
1 parent f94c811 commit 5045664
Show file tree
Hide file tree
Showing 13 changed files with 109 additions and 109 deletions.
4 changes: 2 additions & 2 deletions crates/evm/src/instructions/block_information.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl BlockInformation of BlockInformationTrait {
/// Get gas limit
/// # Specification: https://www.evm.codes/#45?fork=shanghai
fn exec_gaslimit(ref self: Machine) -> Result<(), EVMError> {
self.stack.push(self.current_ctx_gas_limit().into())
self.stack.push(self.gas_limit().into())
}

/// 0x46 - CHAINID
Expand All @@ -75,6 +75,6 @@ impl BlockInformation of BlockInformationTrait {
fn exec_basefee(ref self: Machine) -> Result<(), EVMError> {
// Get the current base fee. (Kakarot doesn't use EIP 1559 so basefee
// doesn't really exists there so we just use the gas price)
self.stack.push(self.current_ctx_gas_price().into())
self.stack.push(self.gas_price().into())
}
}
20 changes: 10 additions & 10 deletions crates/evm/src/instructions/environmental_information.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ impl EnvironmentInformationImpl of EnvironmentInformationTrait {
/// Get address of currently executing account.
/// # Specification: https://www.evm.codes/#30?fork=shanghai
fn exec_address(ref self: Machine) -> Result<(), EVMError> {
self.stack.push(self.current_ctx_evm_address().into())
self.stack.push(self.evm_address().into())
}

/// 0x31 - BALANCE opcode.
Expand Down Expand Up @@ -43,7 +43,7 @@ impl EnvironmentInformationImpl of EnvironmentInformationTrait {
/// Get deposited value by the instruction/transaction responsible for this execution.
/// # Specification: https://www.evm.codes/#34?fork=shanghai
fn exec_callvalue(ref self: Machine) -> Result<(), EVMError> {
self.stack.push(self.current_ctx_value())
self.stack.push(self.value())
}

/// 0x35 - CALLDATALOAD
Expand All @@ -52,7 +52,7 @@ impl EnvironmentInformationImpl of EnvironmentInformationTrait {
fn exec_calldataload(ref self: Machine) -> Result<(), EVMError> {
let offset: usize = self.stack.pop_usize()?;

let calldata = self.current_ctx_calldata();
let calldata = self.calldata();
let calldata_len = calldata.len();

// All bytes after the end of the calldata are set to 0.
Expand Down Expand Up @@ -85,7 +85,7 @@ impl EnvironmentInformationImpl of EnvironmentInformationTrait {
/// Get the size of return data.
/// # Specification: https://www.evm.codes/#36?fork=shanghai
fn exec_calldatasize(ref self: Machine) -> Result<(), EVMError> {
let size: u256 = self.current_ctx_calldata().len().into();
let size: u256 = self.calldata().len().into();
self.stack.push(size)
}

Expand All @@ -97,7 +97,7 @@ impl EnvironmentInformationImpl of EnvironmentInformationTrait {
let offset = self.stack.pop_usize()?;
let size = self.stack.pop_usize()?;

let calldata: Span<u8> = self.current_ctx_calldata();
let calldata: Span<u8> = self.calldata();

let copied: Span<u8> = if (offset + size > calldata.len()) {
calldata.slice(offset, calldata.len() - offset)
Expand All @@ -114,7 +114,7 @@ impl EnvironmentInformationImpl of EnvironmentInformationTrait {
/// Get size of bytecode running in current environment.
/// # Specification: https://www.evm.codes/#38?fork=shanghai
fn exec_codesize(ref self: Machine) -> Result<(), EVMError> {
let size: u256 = self.current_ctx_bytecode().len().into();
let size: u256 = self.bytecode().len().into();
self.stack.push(size)
}

Expand All @@ -126,7 +126,7 @@ impl EnvironmentInformationImpl of EnvironmentInformationTrait {
let offset = self.stack.pop_usize()?;
let size = self.stack.pop_usize()?;

let bytecode: Span<u8> = self.current_ctx_bytecode();
let bytecode: Span<u8> = self.bytecode();

let copied: Span<u8> = if offset > bytecode.len() {
array![].span()
Expand All @@ -145,7 +145,7 @@ impl EnvironmentInformationImpl of EnvironmentInformationTrait {
/// Get price of gas in current environment.
/// # Specification: https://www.evm.codes/#3a?fork=shanghai
fn exec_gasprice(ref self: Machine) -> Result<(), EVMError> {
self.stack.push(self.current_ctx_gas_price().into())
self.stack.push(self.gas_price().into())
}

/// 0x3B - EXTCODESIZE
Expand All @@ -166,7 +166,7 @@ impl EnvironmentInformationImpl of EnvironmentInformationTrait {
/// Get the size of return data.
/// # Specification: https://www.evm.codes/#3d?fork=shanghai
fn exec_returndatasize(ref self: Machine) -> Result<(), EVMError> {
let size: u32 = self.current_ctx_return_data().len();
let size: u32 = self.return_data().len();
self.stack.push(size.into())
}

Expand All @@ -178,7 +178,7 @@ impl EnvironmentInformationImpl of EnvironmentInformationTrait {
let offset = self.stack.pop_usize()?;
let size = self.stack.pop_usize()?;

let return_data: Span<u8> = self.current_ctx_return_data();
let return_data: Span<u8> = self.return_data();

match u32_overflowing_add(offset, size) {
Result::Ok(x) => {
Expand Down
6 changes: 3 additions & 3 deletions crates/evm/src/instructions/memory_operations.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl MemoryOperation of MemoryOperationTrait {
/// Get the value of the program counter prior to the increment.
/// # Specification: https://www.evm.codes/#58?fork=shanghai
fn exec_pc(ref self: Machine) -> Result<(), EVMError> {
let pc = self.current_ctx_pc().into();
let pc = self.pc().into();
self.stack.push(pc)
}

Expand Down Expand Up @@ -65,7 +65,7 @@ impl MemoryOperation of MemoryOperationTrait {
// present in that list
//
// Check if idx in bytecode points to `JUMPDEST` opcode
match self.current_ctx_bytecode().get(index) {
match self.bytecode().get(index) {
Option::Some(opcode) => {
if *opcode.unbox() != 0x5B {
return Result::Err(EVMError::JumpError(INVALID_DESTINATION));
Expand All @@ -75,7 +75,7 @@ impl MemoryOperation of MemoryOperationTrait {
return Result::Err(EVMError::JumpError(INVALID_DESTINATION));
}
}
self.set_pc_current_ctx(index);
self.set_pc(index);
Result::Ok(())
}

Expand Down
4 changes: 2 additions & 2 deletions crates/evm/src/instructions/push_operations.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ mod internal {
#[inline(always)]
fn exec_push_i(ref machine: Machine, i: u8) -> Result<(), EVMError> {
let i = i.into();
let data = machine.read_code_current_ctx(i);
let data = machine.read_code(i);

machine.set_pc_current_ctx(machine.current_ctx_pc() + i);
machine.set_pc(machine.pc() + i);

machine.stack.push(load_word(i, data))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ impl StopAndArithmeticOperations of StopAndArithmeticOperationsTrait {
/// Halts the execution of the current program.
/// # Specification: https://www.evm.codes/#00?fork=shanghai
fn exec_stop(ref self: Machine) -> Result<(), EVMError> {
self.stop_current_ctx();
self.stop();
Result::Ok(())
}

Expand Down
4 changes: 2 additions & 2 deletions crates/evm/src/instructions/system_operations.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ impl SystemOperations of SystemOperationsTrait {
let size = self.stack.pop_usize()?;
let mut return_data = array![];
self.memory.load_n(size, ref return_data, offset);
self.set_return_data_current_ctx(return_data);
self.stop_current_ctx();
self.set_return_data(return_data);
self.stop();
Result::Ok(())
}

Expand Down
14 changes: 7 additions & 7 deletions crates/evm/src/interpreter.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,19 @@ impl EVMInterpreterImpl of EVMInterpreterTrait {
match result {
Result::Ok(_) => {
// Check if the execution is complete.
if !(machine.current_ctx_stopped()) {
if !(machine.stopped()) {
// Execute the next opcode.
self.run(ref machine);
}
if machine.current_ctx_reverted() { // TODO: Revert logic
if machine.reverted() { // TODO: Revert logic
}
if machine.current_ctx_stopped() { // TODO: stopped logic
if machine.stopped() { // TODO: stopped logic
}
},
Result::Err(error) => {
// If an error occurred, revert execution machine.
// Currently, revert reason is a Span<u8>.
machine.revert_current_ctx(u256_to_bytes_array(error.into()).span());
machine.revert(u256_to_bytes_array(error.into()).span());
// TODO: Revert logic
}
}
Expand All @@ -64,8 +64,8 @@ impl EVMInterpreterImpl of EVMInterpreterTrait {
/// Decode the current opcode and execute associated function.
fn decode_and_execute(ref self: EVMInterpreter, ref machine: Machine) -> Result<(), EVMError> {
// Retrieve the current program counter.
let pc = machine.current_ctx_pc();
let bytecode = machine.current_ctx_call_context().bytecode();
let pc = machine.pc();
let bytecode = machine.call_context().bytecode();
let bytecode_len = bytecode.len();

// Check if PC is not out of bounds.
Expand All @@ -76,7 +76,7 @@ impl EVMInterpreterImpl of EVMInterpreterTrait {
let opcode: u8 = *bytecode.at(pc);

// Increment pc
machine.set_pc_current_ctx(pc + 1);
machine.set_pc(pc + 1);

// Call the appropriate function based on the opcode.
if opcode == 0 {
Expand Down
Loading

0 comments on commit 5045664

Please sign in to comment.