diff --git a/cairo_vm_hints/src/cairo_types/dict_access.rs b/cairo_vm_hints/src/cairo_types/dict_access.rs deleted file mode 100644 index 366fe7a0..00000000 --- a/cairo_vm_hints/src/cairo_types/dict_access.rs +++ /dev/null @@ -1,12 +0,0 @@ -use cairo_type_derive::FieldOffsetGetters; -use cairo_vm::Felt252; - -#[derive(FieldOffsetGetters)] -pub struct DictAccess { - #[allow(unused)] - pub key: Felt252, - #[allow(unused)] - pub prev_value: Felt252, - #[allow(unused)] - pub new_value: Felt252, -} diff --git a/cairo_vm_hints/src/cairo_types/mod.rs b/cairo_vm_hints/src/cairo_types/mod.rs index 580aa237..2ec96e9c 100644 --- a/cairo_vm_hints/src/cairo_types/mod.rs +++ b/cairo_vm_hints/src/cairo_types/mod.rs @@ -1,4 +1,3 @@ -pub(crate) mod dict_access; pub(crate) mod new_syscalls; pub(crate) mod structs; pub(crate) mod traits; diff --git a/cairo_vm_hints/src/cairo_types/new_syscalls.rs b/cairo_vm_hints/src/cairo_types/new_syscalls.rs index fe1f1361..aeddedfd 100644 --- a/cairo_vm_hints/src/cairo_types/new_syscalls.rs +++ b/cairo_vm_hints/src/cairo_types/new_syscalls.rs @@ -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, } diff --git a/cairo_vm_hints/src/cairo_types/structs.rs b/cairo_vm_hints/src/cairo_types/structs.rs index b4f57c62..c7bf615a 100644 --- a/cairo_vm_hints/src/cairo_types/structs.rs +++ b/cairo_vm_hints/src/cairo_types/structs.rs @@ -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 { diff --git a/cairo_vm_hints/src/syscall_handler/call_contract.rs b/cairo_vm_hints/src/syscall_handler/call_contract.rs index 7b1e71c3..12abb061 100644 --- a/cairo_vm_hints/src/syscall_handler/call_contract.rs +++ b/cairo_vm_hints/src/syscall_handler/call_contract.rs @@ -1,6 +1,9 @@ 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; @@ -8,19 +11,26 @@ impl SyscallHandler for CallContractHandler { type Request = CallContractRequest; type Response = CallContractResponse; - fn read_request(_vm: &VirtualMachine, _ptr: &mut Relocatable) -> SyscallResult { - todo!() + fn read_request(vm: &VirtualMachine, ptr: &mut Relocatable) -> SyscallResult { + 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 { - 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(()) } }