Skip to content

Commit

Permalink
contract syscall handler sketch
Browse files Browse the repository at this point in the history
  • Loading branch information
Okm165 committed Nov 26, 2024
1 parent 9748d27 commit ba8fc63
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 48 deletions.
12 changes: 0 additions & 12 deletions cairo_vm_hints/src/cairo_types/dict_access.rs

This file was deleted.

1 change: 0 additions & 1 deletion cairo_vm_hints/src/cairo_types/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
pub(crate) mod dict_access;
pub(crate) mod new_syscalls;
pub(crate) mod structs;
pub(crate) mod traits;
22 changes: 13 additions & 9 deletions cairo_vm_hints/src/cairo_types/new_syscalls.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
use cairo_type_derive::FieldOffsetGetters;
use crate::cairo_types::traits::CairoType;
use cairo_type_derive::{CairoType, FieldOffsetGetters};
use cairo_vm::types::relocatable::Relocatable;
use cairo_vm::vm::errors::memory_errors::MemoryError;
use cairo_vm::vm::vm_core::VirtualMachine;
use cairo_vm::Felt252;

#[allow(unused)]
#[derive(FieldOffsetGetters)]
#[derive(FieldOffsetGetters, CairoType)]
pub struct CallContractRequest {
// The address of the L2 contract to call.
contract_address: Felt252,
pub contract_address: Felt252,
// The selector of the function to call.
selector: Felt252,
pub selector: Felt252,
// The calldata.
calldata_start: Felt252,
calldata_end: Felt252,
pub calldata_start: Felt252,
pub calldata_end: Felt252,
}

#[allow(unused)]
#[derive(FieldOffsetGetters)]
#[derive(FieldOffsetGetters, CairoType)]
pub struct CallContractResponse {
retdata_start: Felt252,
retdata_end: Felt252,
pub retdata_start: Felt252,
pub retdata_end: Felt252,
}
17 changes: 0 additions & 17 deletions cairo_vm_hints/src/cairo_types/structs.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,6 @@
use cairo_type_derive::FieldOffsetGetters;
use cairo_vm::types::relocatable::Relocatable;
use cairo_vm::Felt252;

#[derive(FieldOffsetGetters)]
pub struct ExecutionContext {
#[allow(unused)]
pub entry_point_type: Felt252,
#[allow(unused)]
pub class_hash: Felt252,
#[allow(unused)]
pub calldata_size: Felt252,
#[allow(unused)]
pub calldata: Relocatable,
#[allow(unused)]
pub execution_info: Relocatable,
#[allow(unused)]
pub deprecated_tx_info: Relocatable,
}

#[allow(unused)]
#[derive(FieldOffsetGetters)]
pub struct CompiledClassFact {
Expand Down
28 changes: 19 additions & 9 deletions cairo_vm_hints/src/syscall_handler/call_contract.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,36 @@
use super::utils::{SyscallHandler, SyscallResult, WriteResponseResult};
use crate::cairo_types::new_syscalls::{CallContractRequest, CallContractResponse};
use cairo_vm::{types::relocatable::Relocatable, vm::vm_core::VirtualMachine};
use crate::cairo_types::{
new_syscalls::{CallContractRequest, CallContractResponse},
traits::CairoType,
};
use cairo_vm::{types::relocatable::Relocatable, vm::vm_core::VirtualMachine, Felt252};

pub struct CallContractHandler;

impl SyscallHandler for CallContractHandler {
type Request = CallContractRequest;
type Response = CallContractResponse;

fn read_request(_vm: &VirtualMachine, _ptr: &mut Relocatable) -> SyscallResult<Self::Request> {
todo!()
fn read_request(vm: &VirtualMachine, ptr: &mut Relocatable) -> SyscallResult<Self::Request> {
let ret = Self::Request::from_memory(vm, *ptr)?;
*ptr = (*ptr + Self::Request::cairo_size())?;
Ok(ret)
}

fn execute(_request: Self::Request, _vm: &mut VirtualMachine) -> SyscallResult<Self::Response> {
todo!()
Ok(Self::Response {
retdata_start: Felt252::from(6_u32),
retdata_end: Felt252::from(9_u32),
})
}

fn write_response(
_response: Self::Response,
_vm: &mut VirtualMachine,
_ptr: &mut Relocatable,
response: Self::Response,
vm: &mut VirtualMachine,
ptr: &mut Relocatable,
) -> WriteResponseResult {
todo!()
response.to_memory(vm, *ptr)?;
*ptr = (*ptr + Self::Response::cairo_size())?;
Ok(())
}
}

0 comments on commit ba8fc63

Please sign in to comment.