Skip to content

Commit

Permalink
feat: set_active_context
Browse files Browse the repository at this point in the history
  • Loading branch information
enitrat committed Oct 3, 2023
1 parent 1332bec commit 7ebe35f
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
8 changes: 4 additions & 4 deletions crates/evm/src/context.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ impl DefaultBoxCallContext of Default<Box<CallContext>> {
/// Stores all data relevant to the current execution context.
#[derive(Drop, Default)]
struct ExecutionContext {
context_id: usize,
id: usize,
evm_address: EthAddress,
starknet_address: ContractAddress,
program_counter: u32,
Expand Down Expand Up @@ -154,7 +154,7 @@ impl ExecutionContextImpl of ExecutionContextTrait {
/// Create a new execution context instance.
#[inline(always)]
fn new(
context_id: usize,
id: usize,
evm_address: EthAddress,
starknet_address: ContractAddress,
call_context: CallContext,
Expand All @@ -163,7 +163,7 @@ impl ExecutionContextImpl of ExecutionContextTrait {
return_data: Array<u8>,
) -> ExecutionContext {
ExecutionContext {
context_id,
id,
evm_address,
starknet_address,
program_counter: Default::default(),
Expand Down Expand Up @@ -288,7 +288,7 @@ impl ExecutionContextImpl of ExecutionContextTrait {

#[inline(always)]
fn is_root(self: @ExecutionContext) -> bool {
*self.context_id == 0
*self.id == 0
}

// TODO: Implement print_debug
Expand Down
9 changes: 5 additions & 4 deletions crates/evm/src/machine.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,10 @@ impl MachineCurrentContextImpl of MachineCurrentContextTrait {
/// to divide a unique Stack/Memory simulated by a dict into
/// multiple sub-structures relative to a single context.
#[inline(always)]
fn set_active_execution_ctx(ref self: Machine, id: usize) {
self.memory.set_active_segment(id);
self.stack.set_active_segment(id);
fn set_active_execution_ctx(ref self: Machine, ctx: ExecutionContext) {
self.memory.set_active_segment(ctx.id);
self.stack.set_active_segment(ctx.id);
self.current_context = BoxTrait::new(ctx);
}

#[inline(always)]
Expand Down Expand Up @@ -240,7 +241,7 @@ impl MachineCurrentContextImpl of MachineCurrentContextTrait {
#[inline(always)]
fn is_root(ref self: Machine) -> bool {
let current_execution_ctx = self.current_context.unbox();
let is_root = current_execution_ctx.context_id == 0;
let is_root = current_execution_ctx.id == 0;
self.current_context = BoxTrait::new(current_execution_ctx);
is_root
}
Expand Down
2 changes: 1 addition & 1 deletion docs/general/execution_context.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fields
```mermaid
classDiagram
class ExecutionContext{
context_id: usize,
id: usize,
evm_address: EthAddress,
starknet_address: ContractAddress,
program_counter: u32,
Expand Down
5 changes: 2 additions & 3 deletions docs/general/machine.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ To overcome the problem stated above, we have come up with the following design:
context tree until the desired execution context is reached. The machine also
stores a pointer to the current execution context.
- The execution context tree is initialized with a single root execution
context, which has no parent and no child. It has `context_id` field equal
to 0.
context, which has no parent and no child. It has `id` field equal to 0.

The following diagram describes the model of the Kakarot Machine.

Expand All @@ -65,7 +64,7 @@ classDiagram
}
class ExecutionContext{
context_id: usize,
id: usize,
evm_address: EthAddress,
starknet_address: ContractAddress,
program_counter: u32,
Expand Down

0 comments on commit 7ebe35f

Please sign in to comment.