From c63337d2e868813286f5962d2ece1d880d044f9c Mon Sep 17 00:00:00 2001 From: Esteve Soler Arderiu Date: Fri, 15 Mar 2024 17:33:16 +0000 Subject: [PATCH 1/3] Fix space character (wrong unicode value). --- src/arch/aarch64.s | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/arch/aarch64.s b/src/arch/aarch64.s index 35a738be2..9c3e18907 100644 --- a/src/arch/aarch64.s +++ b/src/arch/aarch64.s @@ -32,7 +32,7 @@ _aot_trampoline: ldr x3, [x10, #-8]! // Decrement pointer, then load the value. str x3, [x4, #-8]! // Reserve stack memory, then write the value. - cmp x2, 8 // Check if there are more than 8 arguments. + cmp x2, 8 // Check if there are more than 8 arguments. bgt 1b // If there still are, loop back and repeat. mov sp, x4 From 0f104b644f38b4cafa2a598055efc48b5b53bd62 Mon Sep 17 00:00:00 2001 From: Esteve Soler Arderiu Date: Fri, 15 Mar 2024 17:40:51 +0000 Subject: [PATCH 2/3] Remove the `SyscallHandlerMeta` completely. --- benches/benches.rs | 16 +- benches/libfuncs.rs | 6 +- examples/easy_api.rs | 2 +- examples/erc20.rs | 7 +- examples/invoke.rs | 2 +- examples/starknet.rs | 12 +- src/bin/cairo-native-dump.rs | 51 ++--- src/bin/cairo-native-run.rs | 2 +- src/bin/cairo-native-test.rs | 2 +- src/context.rs | 4 + src/executor.rs | 58 ++++-- src/executor/aot.rs | 32 ++- src/executor/jit.rs | 35 +++- src/lib.rs | 4 +- src/libfuncs.rs | 4 +- src/libfuncs/{stark_net.rs => starknet.rs} | 28 +-- .../{stark_net => starknet}/secp256.rs | 22 +- src/metadata.rs | 1 - src/metadata/syscall_handler.rs | 43 ---- src/starknet.rs | 197 +++++++++++++++++- src/types.rs | 4 +- src/types/{stark_net.rs => starknet.rs} | 2 +- src/utils.rs | 14 +- tests/common.rs | 39 ++-- tests/tests/alexandria.rs | 10 +- tests/tests/arrays.rs | 5 +- tests/tests/dict.rs | 4 +- tests/tests/programs.rs | 19 +- tests/tests/starknet/keccak.rs | 6 +- tests/tests/starknet/secp256.rs | 73 ++++--- tests/tests/trampoline.rs | 4 +- tests/tests/uint.rs | 52 ++--- 32 files changed, 468 insertions(+), 292 deletions(-) rename src/libfuncs/{stark_net.rs => starknet.rs} (99%) rename src/libfuncs/{stark_net => starknet}/secp256.rs (99%) delete mode 100644 src/metadata/syscall_handler.rs rename src/types/{stark_net.rs => starknet.rs} (99%) diff --git a/benches/benches.rs b/benches/benches.rs index 262445ddc..99ae7c406 100644 --- a/benches/benches.rs +++ b/benches/benches.rs @@ -37,27 +37,23 @@ fn criterion_benchmark(c: &mut Criterion) { find_function_id(&logistic_map, "logistic_map::logistic_map::main"); c.bench_function("Cached JIT factorial_2M", |b| { - b.iter(|| jit_factorial.invoke_dynamic(factorial_function_id, &[], Some(u128::MAX), None)); + b.iter(|| jit_factorial.invoke_dynamic(factorial_function_id, &[], Some(u128::MAX))); }); c.bench_function("Cached JIT fib_2M", |b| { - b.iter(|| jit_fibonacci.invoke_dynamic(fibonacci_function_id, &[], Some(u128::MAX), None)); + b.iter(|| jit_fibonacci.invoke_dynamic(fibonacci_function_id, &[], Some(u128::MAX))); }); c.bench_function("Cached JIT logistic_map", |b| { - b.iter(|| { - jit_logistic_map.invoke_dynamic(logistic_map_function_id, &[], Some(u128::MAX), None) - }); + b.iter(|| jit_logistic_map.invoke_dynamic(logistic_map_function_id, &[], Some(u128::MAX))); }); c.bench_function("Cached AOT factorial_2M", |b| { - b.iter(|| aot_factorial.invoke_dynamic(factorial_function_id, &[], Some(u128::MAX), None)); + b.iter(|| aot_factorial.invoke_dynamic(factorial_function_id, &[], Some(u128::MAX))); }); c.bench_function("Cached AOT fib_2M", |b| { - b.iter(|| aot_fibonacci.invoke_dynamic(fibonacci_function_id, &[], Some(u128::MAX), None)); + b.iter(|| aot_fibonacci.invoke_dynamic(fibonacci_function_id, &[], Some(u128::MAX))); }); c.bench_function("Cached AOT logistic_map", |b| { - b.iter(|| { - aot_logistic_map.invoke_dynamic(logistic_map_function_id, &[], Some(u128::MAX), None) - }); + b.iter(|| aot_logistic_map.invoke_dynamic(logistic_map_function_id, &[], Some(u128::MAX))); }); #[cfg(target_arch = "x86_64")] diff --git a/benches/libfuncs.rs b/benches/libfuncs.rs index 6bf32c47b..c63a5cbc3 100644 --- a/benches/libfuncs.rs +++ b/benches/libfuncs.rs @@ -57,7 +57,7 @@ pub fn bench_libfuncs(c: &mut Criterion) { // Execute the program. let result = native_executor - .invoke_dynamic(&entry.id, &[], Some(u64::MAX as u128), None) + .invoke_dynamic(&entry.id, &[], Some(u64::MAX as u128)) .unwrap(); black_box(result) }) @@ -77,14 +77,14 @@ pub fn bench_libfuncs(c: &mut Criterion) { // warmup for _ in 0..5 { native_executor - .invoke_dynamic(&entry.id, &[], Some(u64::MAX as u128), None) + .invoke_dynamic(&entry.id, &[], Some(u64::MAX as u128)) .unwrap(); } b.iter(|| { // Execute the program. let result = native_executor - .invoke_dynamic(&entry.id, &[], Some(u64::MAX as u128), None) + .invoke_dynamic(&entry.id, &[], Some(u64::MAX as u128)) .unwrap(); black_box(result) }) diff --git a/examples/easy_api.rs b/examples/easy_api.rs index f4f888bdc..275eb69b2 100644 --- a/examples/easy_api.rs +++ b/examples/easy_api.rs @@ -26,7 +26,7 @@ fn main() { // Execute the program. let result = native_executor - .invoke_dynamic(entry_point_id, params, None, None) + .invoke_dynamic(entry_point_id, params, None) .unwrap(); println!("Cairo program was compiled and executed successfully."); diff --git a/examples/erc20.rs b/examples/erc20.rs index 98d0e93e8..972e2e9e2 100644 --- a/examples/erc20.rs +++ b/examples/erc20.rs @@ -3,10 +3,9 @@ use cairo_lang_starknet::contract_class::compile_path; use cairo_native::{ context::NativeContext, executor::JitNativeExecutor, - metadata::syscall_handler::SyscallHandlerMeta, starknet::{ BlockInfo, ExecutionInfo, ExecutionInfoV2, ResourceBounds, Secp256k1Point, Secp256r1Point, - StarkNetSyscallHandler, SyscallResult, TxInfo, TxV2Info, U256, + StarknetSyscallHandler, SyscallResult, TxInfo, TxV2Info, U256, }, utils::find_entry_point_by_idx, }; @@ -17,7 +16,7 @@ use tracing_subscriber::{EnvFilter, FmtSubscriber}; #[derive(Debug)] struct SyscallHandler; -impl StarkNetSyscallHandler for SyscallHandler { +impl StarknetSyscallHandler for SyscallHandler { fn get_block_hash(&mut self, block_number: u64, _gas: &mut u128) -> SyscallResult { println!("Called `get_block_hash({block_number})` from MLIR."); Ok(Felt::from_bytes_be_slice(b"get_block_hash ok")) @@ -317,7 +316,7 @@ fn main() { Felt::from(6), ], Some(u128::MAX), - Some(&SyscallHandlerMeta::new(&mut SyscallHandler)), + SyscallHandler, ) .expect("failed to execute the given contract"); diff --git a/examples/invoke.rs b/examples/invoke.rs index 98213ba64..3e29fb5af 100644 --- a/examples/invoke.rs +++ b/examples/invoke.rs @@ -30,7 +30,7 @@ fn main() { let native_executor = JitNativeExecutor::from_native_module(native_program, Default::default()); - let output = native_executor.invoke_dynamic(fn_id, &[JitValue::Felt252(1.into())], None, None); + let output = native_executor.invoke_dynamic(fn_id, &[JitValue::Felt252(1.into())], None); println!(); println!("Cairo program was compiled and executed successfully."); diff --git a/examples/starknet.rs b/examples/starknet.rs index eeb54f95c..d036c89d2 100644 --- a/examples/starknet.rs +++ b/examples/starknet.rs @@ -3,10 +3,9 @@ use cairo_lang_starknet::contract_class::compile_path; use cairo_native::{ context::NativeContext, executor::JitNativeExecutor, - metadata::syscall_handler::SyscallHandlerMeta, starknet::{ BlockInfo, ExecutionInfo, ExecutionInfoV2, ResourceBounds, Secp256k1Point, Secp256r1Point, - StarkNetSyscallHandler, SyscallResult, TxInfo, TxV2Info, U256, + StarknetSyscallHandler, SyscallResult, TxInfo, TxV2Info, U256, }, utils::find_entry_point_by_idx, }; @@ -17,7 +16,7 @@ use tracing_subscriber::{EnvFilter, FmtSubscriber}; #[derive(Debug)] struct SyscallHandler; -impl StarkNetSyscallHandler for SyscallHandler { +impl StarknetSyscallHandler for SyscallHandler { fn get_block_hash(&mut self, block_number: u64, _gas: &mut u128) -> SyscallResult { println!("Called `get_block_hash({block_number})` from MLIR."); Ok(Felt::from_bytes_be_slice(b"get_block_hash ok")) @@ -306,12 +305,7 @@ fn main() { let native_executor = JitNativeExecutor::from_native_module(native_program, Default::default()); let result = native_executor - .invoke_contract_dynamic( - fn_id, - &[Felt::from(1)], - Some(u128::MAX), - Some(&SyscallHandlerMeta::new(&mut SyscallHandler)), - ) + .invoke_contract_dynamic(fn_id, &[Felt::from(1)], Some(u128::MAX), SyscallHandler) .expect("failed to execute the given contract"); println!(); diff --git a/src/bin/cairo-native-dump.rs b/src/bin/cairo-native-dump.rs index a8396c426..ffdcbe53e 100644 --- a/src/bin/cairo-native-dump.rs +++ b/src/bin/cairo-native-dump.rs @@ -4,27 +4,17 @@ use cairo_lang_compiler::{ }; use cairo_lang_defs::plugin::NamedPlugin; use cairo_lang_semantic::plugin::PluginSuite; -use cairo_lang_sierra::{ - extensions::core::{CoreLibfunc, CoreType}, - program::Program, - program_registry::ProgramRegistry, - ProgramParser, -}; +use cairo_lang_sierra::{program::Program, ProgramParser}; use cairo_lang_starknet::{ contract_class::compile_contract_in_prepared_db, inline_macros::selector::SelectorMacro, plugin::StarkNetPlugin, }; use cairo_native::{ + context::NativeContext, debug_info::{DebugInfo, DebugLocations}, - metadata::{runtime_bindings::RuntimeBindingsMeta, MetadataStorage}, }; use clap::Parser; -use melior::{ - dialect::DialectRegistry, - ir::{operation::OperationPrintingFlags, Location, Module}, - utility::register_all_dialects, - Context, -}; +use melior::{ir::operation::OperationPrintingFlags, Context}; use std::{ ffi::OsStr, fs, @@ -45,37 +35,20 @@ fn main() -> Result<(), Box> { )?; // Load the program. - let context = Context::new(); - let (program, debug_info) = - load_program(Path::new(&args.input), Some(&context), args.starknet)?; - - // Initialize MLIR. - context.append_dialect_registry(&{ - let registry = DialectRegistry::new(); - register_all_dialects(®istry); - registry - }); - context.load_all_available_dialects(); + let context = NativeContext::new(); + // TODO: Reconnect debug information. + let (program, _debug_info) = load_program( + Path::new(&args.input), + Some(context.context()), + args.starknet, + )?; // Compile the program. - let module = Module::new(Location::unknown(&context)); - let mut metadata = MetadataStorage::new(); - let registry = ProgramRegistry::::new(&program)?; - - // Make the runtime library available. - metadata.insert(RuntimeBindingsMeta::default()).unwrap(); - - cairo_native::compile( - &context, - &module, - &program, - ®istry, - &mut metadata, - debug_info.as_ref(), - )?; + let module = context.compile(&program)?; // Write the output. let output_str = module + .module() .as_operation() .to_string_with_flags(OperationPrintingFlags::new().enable_debug_info(true, false))?; match args.output { diff --git a/src/bin/cairo-native-run.rs b/src/bin/cairo-native-run.rs index dc72fe439..fe3e19cc4 100644 --- a/src/bin/cairo-native-run.rs +++ b/src/bin/cairo-native-run.rs @@ -118,7 +118,7 @@ fn main() -> anyhow::Result<()> { .with_context(|| "not enough gas to run")?; let result = native_executor - .invoke_dynamic(&func.id, &[], Some(initial_gas), None) + .invoke_dynamic(&func.id, &[], Some(initial_gas)) .with_context(|| "Failed to run the function.")?; let run_result = result_to_runresult(&result)?; diff --git a/src/bin/cairo-native-test.rs b/src/bin/cairo-native-test.rs index 43ef7447d..951a44286 100644 --- a/src/bin/cairo-native-test.rs +++ b/src/bin/cairo-native-test.rs @@ -438,7 +438,7 @@ fn run_tests( .with_context(|| "not enough gas to run")?; let result = native_executor - .invoke_dynamic(&func.id, &[], Some(initial_gas), None) + .invoke_dynamic(&func.id, &[], Some(initial_gas)) .with_context(|| format!("Failed to run the function `{}`.", name.as_str()))?; let run_result = result_to_runresult(&result)?; diff --git a/src/context.rs b/src/context.rs index f7ef4713f..30c812a64 100644 --- a/src/context.rs +++ b/src/context.rs @@ -51,6 +51,10 @@ impl NativeContext { Self { context } } + pub fn context(&self) -> &Context { + &self.context + } + /// Compiles a sierra program into MLIR and then lowers to LLVM. /// Returns the corresponding NativeModule struct. pub fn compile(&self, program: &Program) -> Result { diff --git a/src/executor.rs b/src/executor.rs index c60fda1a8..187cc167d 100644 --- a/src/executor.rs +++ b/src/executor.rs @@ -2,7 +2,7 @@ pub use self::{aot::AotNativeExecutor, jit::JitNativeExecutor}; use crate::{ error::jit_engine::RunnerError, execution_result::{BuiltinStats, ContractExecutionResult, ExecutionResult}, - metadata::syscall_handler::SyscallHandlerMeta, + starknet::{handler::StarknetSyscallHandlerCallbacks, StarknetSyscallHandler}, types::TypeBuilder, utils::get_integer_layout, values::JitValue, @@ -59,15 +59,33 @@ impl<'a> NativeExecutor<'a> { function_id: &FunctionId, args: &[JitValue], gas: Option, - syscall_handler: Option<&SyscallHandlerMeta>, ) -> Result { match self { - NativeExecutor::Aot(executor) => { - executor.invoke_dynamic(function_id, args, gas, syscall_handler) - } - NativeExecutor::Jit(executor) => { - executor.invoke_dynamic(function_id, args, gas, syscall_handler) - } + NativeExecutor::Aot(executor) => executor.invoke_dynamic(function_id, args, gas), + NativeExecutor::Jit(executor) => executor.invoke_dynamic(function_id, args, gas), + } + } + + pub fn invoke_dynamic_with_syscall_handler( + &self, + function_id: &FunctionId, + args: &[JitValue], + gas: Option, + syscall_handler: impl StarknetSyscallHandler, + ) -> Result { + match self { + NativeExecutor::Aot(executor) => executor.invoke_dynamic_with_syscall_handler( + function_id, + args, + gas, + syscall_handler, + ), + NativeExecutor::Jit(executor) => executor.invoke_dynamic_with_syscall_handler( + function_id, + args, + gas, + syscall_handler, + ), } } @@ -76,7 +94,7 @@ impl<'a> NativeExecutor<'a> { function_id: &FunctionId, args: &[Felt], gas: Option, - syscall_handler: Option<&SyscallHandlerMeta>, + syscall_handler: impl StarknetSyscallHandler, ) -> Result { match self { NativeExecutor::Aot(executor) => { @@ -107,7 +125,7 @@ fn invoke_dynamic( function_signature: &FunctionSignature, args: &[JitValue], gas: u128, - syscall_handler: Option>, + mut syscall_handler: Option, ) -> ExecutionResult { tracing::info!("Invoking function with signature: {function_signature:?}."); @@ -176,13 +194,19 @@ fn invoke_dynamic( get_integer_layout(128).align(), &[gas as u64, (gas >> 64) as u64], ), - CoreTypeConcrete::StarkNet(StarkNetTypeConcrete::System(_)) => match syscall_handler { - Some(syscall_handler) => invoke_data.push_aligned( - get_integer_layout(64).align(), - &[syscall_handler.as_ptr() as u64], - ), - None => panic!("Syscall handler is required"), - }, + CoreTypeConcrete::StarkNet(StarkNetTypeConcrete::System(_)) => { + match syscall_handler.as_mut() { + Some(syscall_handler) => { + let syscall_handler = + arena.alloc(StarknetSyscallHandlerCallbacks::new(syscall_handler)); + invoke_data.push_aligned( + get_integer_layout(64).align(), + &[syscall_handler as *mut _ as u64], + ) + } + None => panic!("Syscall handler is required"), + } + } _ if is_builtin(type_info) => invoke_data .push(type_id, type_info, &JitValue::Uint64(0)) .unwrap(), diff --git a/src/executor/aot.rs b/src/executor/aot.rs index 9eb0174af..8047246f9 100644 --- a/src/executor/aot.rs +++ b/src/executor/aot.rs @@ -1,8 +1,9 @@ use crate::{ error::jit_engine::RunnerError, execution_result::{ContractExecutionResult, ExecutionResult}, - metadata::{gas::GasMetadata, syscall_handler::SyscallHandlerMeta}, + metadata::gas::GasMetadata, module::NativeModule, + starknet::{DummySyscallHandler, StarknetSyscallHandler}, utils::generate_function_name, values::JitValue, OptLevel, @@ -68,7 +69,6 @@ impl AotNativeExecutor { function_id: &FunctionId, args: &[JitValue], gas: Option, - syscall_handler: Option<&SyscallHandlerMeta>, ) -> Result { let available_gas = self .gas_metadata @@ -81,7 +81,29 @@ impl AotNativeExecutor { self.extract_signature(function_id), args, available_gas, - syscall_handler.map(SyscallHandlerMeta::as_ptr), + Option::::None, + )) + } + + pub fn invoke_dynamic_with_syscall_handler( + &self, + function_id: &FunctionId, + args: &[JitValue], + gas: Option, + syscall_handler: impl StarknetSyscallHandler, + ) -> Result { + let available_gas = self + .gas_metadata + .get_initial_available_gas(function_id, gas) + .map_err(|_| crate::error::jit_engine::ErrorImpl::InsufficientGasError)?; + + Ok(super::invoke_dynamic( + &self.registry, + self.find_function_ptr(function_id), + self.extract_signature(function_id), + args, + available_gas, + Some(syscall_handler), )) } @@ -90,7 +112,7 @@ impl AotNativeExecutor { function_id: &FunctionId, args: &[Felt], gas: Option, - syscall_handler: Option<&SyscallHandlerMeta>, + syscall_handler: impl StarknetSyscallHandler, ) -> Result { let available_gas = self .gas_metadata @@ -110,7 +132,7 @@ impl AotNativeExecutor { debug_name: None, }], available_gas, - syscall_handler.map(SyscallHandlerMeta::as_ptr), + Some(syscall_handler), ), )?) } diff --git a/src/executor/jit.rs b/src/executor/jit.rs index 78ba686b8..ed8bf3ae3 100644 --- a/src/executor/jit.rs +++ b/src/executor/jit.rs @@ -1,8 +1,9 @@ use crate::{ error::jit_engine::RunnerError, execution_result::{ContractExecutionResult, ExecutionResult}, - metadata::{gas::GasMetadata, syscall_handler::SyscallHandlerMeta}, + metadata::gas::GasMetadata, module::NativeModule, + starknet::{DummySyscallHandler, StarknetSyscallHandler}, utils::{create_engine, generate_function_name}, values::JitValue, OptLevel, @@ -68,7 +69,6 @@ impl<'m> JitNativeExecutor<'m> { function_id: &FunctionId, args: &[JitValue], gas: Option, - syscall_handler: Option<&SyscallHandlerMeta>, ) -> Result { let available_gas = self .gas_metadata @@ -81,7 +81,32 @@ impl<'m> JitNativeExecutor<'m> { self.extract_signature(function_id), args, available_gas, - syscall_handler.map(SyscallHandlerMeta::as_ptr), + Option::::None, + )) + } + + /// Execute a program with the given params. + /// + /// See [`cairo_native::jit_runner::execute`] + pub fn invoke_dynamic_with_syscall_handler( + &self, + function_id: &FunctionId, + args: &[JitValue], + gas: Option, + syscall_handler: impl StarknetSyscallHandler, + ) -> Result { + let available_gas = self + .gas_metadata + .get_initial_available_gas(function_id, gas) + .map_err(|_| crate::error::jit_engine::ErrorImpl::InsufficientGasError)?; + + Ok(super::invoke_dynamic( + &self.registry, + self.find_function_ptr(function_id), + self.extract_signature(function_id), + args, + available_gas, + Some(syscall_handler), )) } @@ -90,7 +115,7 @@ impl<'m> JitNativeExecutor<'m> { function_id: &FunctionId, args: &[Felt], gas: Option, - syscall_handler: Option<&SyscallHandlerMeta>, + syscall_handler: impl StarknetSyscallHandler, ) -> Result { let available_gas = self .gas_metadata @@ -111,7 +136,7 @@ impl<'m> JitNativeExecutor<'m> { debug_name: None, }], available_gas, - syscall_handler.map(SyscallHandlerMeta::as_ptr), + Some(syscall_handler), ), )?) } diff --git a/src/lib.rs b/src/lib.rs index e9737c0a0..444ec94d5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -44,13 +44,11 @@ //! //! // Execute the program. //! let result = native_executor -//! .invoke_dynamic(entry_point_id, params, None, None) +//! .invoke_dynamic(entry_point_id, params, None) //! .unwrap(); //! //! println!("Cairo program was compiled and executed successfully."); //! println!("{:?}", result); -//! -//! //! ``` //! //! ## Common definitions diff --git a/src/libfuncs.rs b/src/libfuncs.rs index 7ccfbc670..8abf4c285 100644 --- a/src/libfuncs.rs +++ b/src/libfuncs.rs @@ -47,7 +47,7 @@ pub mod sint32; pub mod sint64; pub mod sint8; pub mod snapshot_take; -pub mod stark_net; +pub mod starknet; pub mod r#struct; pub mod uint128; pub mod uint16; @@ -180,7 +180,7 @@ impl LibfuncBuilder for CoreConcreteLibfunc { Self::SnapshotTake(info) => self::snapshot_take::build( context, registry, entry, location, helper, metadata, info, ), - Self::StarkNet(selector) => self::stark_net::build( + Self::StarkNet(selector) => self::starknet::build( context, registry, entry, location, helper, metadata, selector, ), Self::Struct(selector) => self::r#struct::build( diff --git a/src/libfuncs/stark_net.rs b/src/libfuncs/starknet.rs similarity index 99% rename from src/libfuncs/stark_net.rs rename to src/libfuncs/starknet.rs index 22aa5b2f5..01c6d3792 100644 --- a/src/libfuncs/stark_net.rs +++ b/src/libfuncs/starknet.rs @@ -1,11 +1,11 @@ -//! # StarkNet libfuncs +//! # Starknet libfuncs use super::LibfuncHelper; use crate::{ error::libfuncs::Result, ffi::get_struct_field_type_at, metadata::MetadataStorage, - starknet::handler::StarkNetSyscallHandlerCallbacks, + starknet::handler::StarknetSyscallHandlerCallbacks, types::felt252::PRIME, utils::{get_integer_layout, ProgramRegistryExt}, }; @@ -365,7 +365,7 @@ pub fn build_call_contract<'ctx, 'this>( entry.argument(1)?.into(), DenseI32ArrayAttribute::new( context, - &[StarkNetSyscallHandlerCallbacks::<()>::CALL_CONTRACT.try_into()?], + &[StarknetSyscallHandlerCallbacks::<()>::CALL_CONTRACT.try_into()?], ), llvm::r#type::opaque_pointer(context), llvm::r#type::opaque_pointer(context), @@ -853,7 +853,7 @@ pub fn build_storage_read<'ctx, 'this>( entry.argument(1)?.into(), DenseI32ArrayAttribute::new( context, - &[StarkNetSyscallHandlerCallbacks::<()>::STORAGE_READ.try_into()?], + &[StarknetSyscallHandlerCallbacks::<()>::STORAGE_READ.try_into()?], ), llvm::r#type::opaque_pointer(context), llvm::r#type::opaque_pointer(context), @@ -1199,7 +1199,7 @@ pub fn build_storage_write<'ctx, 'this>( entry.argument(1)?.into(), DenseI32ArrayAttribute::new( context, - &[StarkNetSyscallHandlerCallbacks::<()>::STORAGE_WRITE.try_into()?], + &[StarknetSyscallHandlerCallbacks::<()>::STORAGE_WRITE.try_into()?], ), llvm::r#type::opaque_pointer(context), llvm::r#type::opaque_pointer(context), @@ -1747,7 +1747,7 @@ pub fn build_emit_event<'ctx, 'this>( entry.argument(1)?.into(), DenseI32ArrayAttribute::new( context, - &[StarkNetSyscallHandlerCallbacks::<()>::EMIT_EVENT.try_into()?], + &[StarknetSyscallHandlerCallbacks::<()>::EMIT_EVENT.try_into()?], ), llvm::r#type::opaque_pointer(context), llvm::r#type::opaque_pointer(context), @@ -2031,7 +2031,7 @@ pub fn build_get_block_hash<'ctx, 'this>( entry.argument(1)?.into(), DenseI32ArrayAttribute::new( context, - &[StarkNetSyscallHandlerCallbacks::<()>::GET_BLOCK_HASH.try_into()?], + &[StarknetSyscallHandlerCallbacks::<()>::GET_BLOCK_HASH.try_into()?], ), llvm::r#type::opaque_pointer(context), llvm::r#type::opaque_pointer(context), @@ -2313,7 +2313,7 @@ pub fn build_get_execution_info<'ctx, 'this>( entry.argument(1)?.into(), DenseI32ArrayAttribute::new( context, - &[StarkNetSyscallHandlerCallbacks::<()>::GET_EXECUTION_INFO.try_into()?], + &[StarknetSyscallHandlerCallbacks::<()>::GET_EXECUTION_INFO.try_into()?], ), llvm::r#type::opaque_pointer(context), llvm::r#type::opaque_pointer(context), @@ -2589,7 +2589,7 @@ pub fn build_get_execution_info_v2<'ctx, 'this>( entry.argument(1)?.into(), DenseI32ArrayAttribute::new( context, - &[StarkNetSyscallHandlerCallbacks::<()>::GET_EXECUTION_INFOV2.try_into()?], + &[StarknetSyscallHandlerCallbacks::<()>::GET_EXECUTION_INFOV2.try_into()?], ), llvm::r#type::opaque_pointer(context), llvm::r#type::opaque_pointer(context), @@ -3008,7 +3008,7 @@ pub fn build_deploy<'ctx, 'this>( entry.argument(1)?.into(), DenseI32ArrayAttribute::new( context, - &[StarkNetSyscallHandlerCallbacks::<()>::DEPLOY.try_into()?], + &[StarknetSyscallHandlerCallbacks::<()>::DEPLOY.try_into()?], ), llvm::r#type::opaque_pointer(context), llvm::r#type::opaque_pointer(context), @@ -3363,7 +3363,7 @@ pub fn build_keccak<'ctx, 'this>( entry.argument(1)?.into(), DenseI32ArrayAttribute::new( context, - &[StarkNetSyscallHandlerCallbacks::<()>::KECCAK.try_into()?], + &[StarknetSyscallHandlerCallbacks::<()>::KECCAK.try_into()?], ), llvm::r#type::opaque_pointer(context), llvm::r#type::opaque_pointer(context), @@ -3738,7 +3738,7 @@ pub fn build_library_call<'ctx, 'this>( entry.argument(1)?.into(), DenseI32ArrayAttribute::new( context, - &[StarkNetSyscallHandlerCallbacks::<()>::LIBRARY_CALL.try_into()?], + &[StarknetSyscallHandlerCallbacks::<()>::LIBRARY_CALL.try_into()?], ), llvm::r#type::opaque_pointer(context), llvm::r#type::opaque_pointer(context), @@ -4055,7 +4055,7 @@ pub fn build_replace_class<'ctx, 'this>( entry.argument(1)?.into(), DenseI32ArrayAttribute::new( context, - &[StarkNetSyscallHandlerCallbacks::<()>::REPLACE_CLASS.try_into()?], + &[StarknetSyscallHandlerCallbacks::<()>::REPLACE_CLASS.try_into()?], ), llvm::r#type::opaque_pointer(context), llvm::r#type::opaque_pointer(context), @@ -4404,7 +4404,7 @@ pub fn build_send_message_to_l1<'ctx, 'this>( entry.argument(1)?.into(), DenseI32ArrayAttribute::new( context, - &[StarkNetSyscallHandlerCallbacks::<()>::SEND_MESSAGE_TO_L1.try_into()?], + &[StarknetSyscallHandlerCallbacks::<()>::SEND_MESSAGE_TO_L1.try_into()?], ), llvm::r#type::opaque_pointer(context), llvm::r#type::opaque_pointer(context), diff --git a/src/libfuncs/stark_net/secp256.rs b/src/libfuncs/starknet/secp256.rs similarity index 99% rename from src/libfuncs/stark_net/secp256.rs rename to src/libfuncs/starknet/secp256.rs index ed8a667e6..bbadc5ff8 100644 --- a/src/libfuncs/stark_net/secp256.rs +++ b/src/libfuncs/starknet/secp256.rs @@ -2,7 +2,7 @@ use crate::{ error::libfuncs::Result, libfuncs::LibfuncHelper, metadata::MetadataStorage, - starknet::handler::StarkNetSyscallHandlerCallbacks, + starknet::handler::StarknetSyscallHandlerCallbacks, utils::{get_integer_layout, ProgramRegistryExt}, }; use cairo_lang_sierra::{ @@ -270,7 +270,7 @@ pub fn build_k1_new<'ctx, 'this>( entry.argument(1)?.into(), DenseI32ArrayAttribute::new( context, - &[StarkNetSyscallHandlerCallbacks::<()>::SECP256K1_NEW.try_into()?], + &[StarknetSyscallHandlerCallbacks::<()>::SECP256K1_NEW.try_into()?], ), llvm::r#type::opaque_pointer(context), llvm::r#type::opaque_pointer(context), @@ -647,7 +647,7 @@ pub fn build_k1_add<'ctx, 'this>( entry.argument(1)?.into(), DenseI32ArrayAttribute::new( context, - &[StarkNetSyscallHandlerCallbacks::<()>::SECP256K1_ADD.try_into()?], + &[StarknetSyscallHandlerCallbacks::<()>::SECP256K1_ADD.try_into()?], ), llvm::r#type::opaque_pointer(context), llvm::r#type::opaque_pointer(context), @@ -1022,7 +1022,7 @@ pub fn build_k1_mul<'ctx, 'this>( entry.argument(1)?.into(), DenseI32ArrayAttribute::new( context, - &[StarkNetSyscallHandlerCallbacks::<()>::SECP256K1_MUL.try_into()?], + &[StarknetSyscallHandlerCallbacks::<()>::SECP256K1_MUL.try_into()?], ), llvm::r#type::opaque_pointer(context), llvm::r#type::opaque_pointer(context), @@ -1365,7 +1365,7 @@ pub fn build_k1_get_point_from_x<'ctx, 'this>( entry.argument(1)?.into(), DenseI32ArrayAttribute::new( context, - &[StarkNetSyscallHandlerCallbacks::<()>::SECP256K1_GET_POINT_FROM_X.try_into()?], + &[StarknetSyscallHandlerCallbacks::<()>::SECP256K1_GET_POINT_FROM_X.try_into()?], ), llvm::r#type::opaque_pointer(context), llvm::r#type::opaque_pointer(context), @@ -1718,7 +1718,7 @@ pub fn build_k1_get_xy<'ctx, 'this>( entry.argument(1)?.into(), DenseI32ArrayAttribute::new( context, - &[StarkNetSyscallHandlerCallbacks::<()>::SECP256K1_GET_XY.try_into()?], + &[StarknetSyscallHandlerCallbacks::<()>::SECP256K1_GET_XY.try_into()?], ), llvm::r#type::opaque_pointer(context), llvm::r#type::opaque_pointer(context), @@ -2102,7 +2102,7 @@ pub fn build_r1_new<'ctx, 'this>( entry.argument(1)?.into(), DenseI32ArrayAttribute::new( context, - &[StarkNetSyscallHandlerCallbacks::<()>::SECP256R1_NEW.try_into()?], + &[StarknetSyscallHandlerCallbacks::<()>::SECP256R1_NEW.try_into()?], ), llvm::r#type::opaque_pointer(context), llvm::r#type::opaque_pointer(context), @@ -2479,7 +2479,7 @@ pub fn build_r1_add<'ctx, 'this>( entry.argument(1)?.into(), DenseI32ArrayAttribute::new( context, - &[StarkNetSyscallHandlerCallbacks::<()>::SECP256R1_ADD.try_into()?], + &[StarknetSyscallHandlerCallbacks::<()>::SECP256R1_ADD.try_into()?], ), llvm::r#type::opaque_pointer(context), llvm::r#type::opaque_pointer(context), @@ -2854,7 +2854,7 @@ pub fn build_r1_mul<'ctx, 'this>( entry.argument(1)?.into(), DenseI32ArrayAttribute::new( context, - &[StarkNetSyscallHandlerCallbacks::<()>::SECP256R1_MUL.try_into()?], + &[StarknetSyscallHandlerCallbacks::<()>::SECP256R1_MUL.try_into()?], ), llvm::r#type::opaque_pointer(context), llvm::r#type::opaque_pointer(context), @@ -3197,7 +3197,7 @@ pub fn build_r1_get_point_from_x<'ctx, 'this>( entry.argument(1)?.into(), DenseI32ArrayAttribute::new( context, - &[StarkNetSyscallHandlerCallbacks::<()>::SECP256R1_GET_POINT_FROM_X.try_into()?], + &[StarknetSyscallHandlerCallbacks::<()>::SECP256R1_GET_POINT_FROM_X.try_into()?], ), llvm::r#type::opaque_pointer(context), llvm::r#type::opaque_pointer(context), @@ -3550,7 +3550,7 @@ pub fn build_r1_get_xy<'ctx, 'this>( entry.argument(1)?.into(), DenseI32ArrayAttribute::new( context, - &[StarkNetSyscallHandlerCallbacks::<()>::SECP256R1_GET_XY.try_into()?], + &[StarknetSyscallHandlerCallbacks::<()>::SECP256R1_GET_XY.try_into()?], ), llvm::r#type::opaque_pointer(context), llvm::r#type::opaque_pointer(context), diff --git a/src/metadata.rs b/src/metadata.rs index 99371de15..e879b35b8 100644 --- a/src/metadata.rs +++ b/src/metadata.rs @@ -21,7 +21,6 @@ pub mod prime_modulo; pub mod realloc_bindings; pub mod runtime_bindings; pub mod snapshot_clones; -pub mod syscall_handler; pub mod tail_recursion; /// Metadata container. diff --git a/src/metadata/syscall_handler.rs b/src/metadata/syscall_handler.rs deleted file mode 100644 index 1c495b201..000000000 --- a/src/metadata/syscall_handler.rs +++ /dev/null @@ -1,43 +0,0 @@ -use crate::starknet::{handler::StarkNetSyscallHandlerCallbacks, StarkNetSyscallHandler}; -use std::{alloc::Layout, fmt::Debug, ptr::NonNull}; - -#[derive(Debug, Clone, PartialEq, Eq)] -pub struct SyscallHandlerMeta { - handler: NonNull<()>, - layout: Layout, -} - -impl SyscallHandlerMeta { - pub fn new(handler_impl: &mut T) -> Self - where - T: StarkNetSyscallHandler, - { - let layout = Layout::new::>(); - let mut handler = unsafe { - NonNull::new_unchecked( - std::alloc::alloc(layout) as *mut StarkNetSyscallHandlerCallbacks - ) - }; - - unsafe { - *handler.as_mut() = StarkNetSyscallHandlerCallbacks::new(handler_impl); - } - - Self { - handler: handler.cast(), - layout, - } - } - - pub fn as_ptr(&self) -> NonNull<()> { - self.handler - } -} - -impl Drop for SyscallHandlerMeta { - fn drop(&mut self) { - unsafe { - std::alloc::dealloc(self.handler.as_mut() as *mut _ as *mut u8, self.layout); - } - } -} diff --git a/src/starknet.rs b/src/starknet.rs index 5b21c7e19..21a1824a2 100644 --- a/src/starknet.rs +++ b/src/starknet.rs @@ -101,7 +101,7 @@ pub struct Secp256r1Point { pub y: U256, } -pub trait StarkNetSyscallHandler { +pub trait StarknetSyscallHandler { fn get_block_hash( &mut self, block_number: u64, @@ -292,6 +292,193 @@ pub trait StarkNetSyscallHandler { } } +pub struct DummySyscallHandler; + +impl StarknetSyscallHandler for DummySyscallHandler { + fn get_block_hash( + &mut self, + _block_number: u64, + _remaining_gas: &mut u128, + ) -> SyscallResult { + unimplemented!() + } + + fn get_execution_info(&mut self, _remaining_gas: &mut u128) -> SyscallResult { + unimplemented!() + } + + fn get_execution_info_v2( + &mut self, + _remaining_gas: &mut u128, + ) -> SyscallResult { + unimplemented!() + } + + fn deploy( + &mut self, + _class_hash: Felt, + _contract_address_salt: Felt, + _calldata: &[Felt], + _deploy_from_zero: bool, + _remaining_gas: &mut u128, + ) -> SyscallResult<(Felt, Vec)> { + unimplemented!() + } + + fn replace_class(&mut self, _class_hash: Felt, _remaining_gas: &mut u128) -> SyscallResult<()> { + unimplemented!() + } + + fn library_call( + &mut self, + _class_hash: Felt, + _function_selector: Felt, + _calldata: &[Felt], + _remaining_gas: &mut u128, + ) -> SyscallResult> { + unimplemented!() + } + + fn call_contract( + &mut self, + _address: Felt, + _entry_point_selector: Felt, + _calldata: &[Felt], + _remaining_gas: &mut u128, + ) -> SyscallResult> { + unimplemented!() + } + + fn storage_read( + &mut self, + _address_domain: u32, + _address: Felt, + _remaining_gas: &mut u128, + ) -> SyscallResult { + unimplemented!() + } + + fn storage_write( + &mut self, + _address_domain: u32, + _address: Felt, + _value: Felt, + _remaining_gas: &mut u128, + ) -> SyscallResult<()> { + unimplemented!() + } + + fn emit_event( + &mut self, + _keys: &[Felt], + _data: &[Felt], + _remaining_gas: &mut u128, + ) -> SyscallResult<()> { + unimplemented!() + } + + fn send_message_to_l1( + &mut self, + _to_address: Felt, + _payload: &[Felt], + _remaining_gas: &mut u128, + ) -> SyscallResult<()> { + unimplemented!() + } + + fn keccak(&mut self, _input: &[u64], _remaining_gas: &mut u128) -> SyscallResult { + unimplemented!() + } + + fn secp256k1_new( + &mut self, + _x: U256, + _y: U256, + _remaining_gas: &mut u128, + ) -> SyscallResult> { + unimplemented!() + } + + fn secp256k1_add( + &mut self, + _p0: Secp256k1Point, + _p1: Secp256k1Point, + _remaining_gas: &mut u128, + ) -> SyscallResult { + unimplemented!() + } + + fn secp256k1_mul( + &mut self, + _p: Secp256k1Point, + _m: U256, + _remaining_gas: &mut u128, + ) -> SyscallResult { + unimplemented!() + } + + fn secp256k1_get_point_from_x( + &mut self, + _x: U256, + _y_parity: bool, + _remaining_gas: &mut u128, + ) -> SyscallResult> { + unimplemented!() + } + + fn secp256k1_get_xy( + &mut self, + _p: Secp256k1Point, + _remaining_gas: &mut u128, + ) -> SyscallResult<(U256, U256)> { + unimplemented!() + } + + fn secp256r1_new( + &mut self, + _x: U256, + _y: U256, + _remaining_gas: &mut u128, + ) -> SyscallResult> { + unimplemented!() + } + + fn secp256r1_add( + &mut self, + _p0: Secp256r1Point, + _p1: Secp256r1Point, + _remaining_gas: &mut u128, + ) -> SyscallResult { + unimplemented!() + } + + fn secp256r1_mul( + &mut self, + _p: Secp256r1Point, + _m: U256, + _remaining_gas: &mut u128, + ) -> SyscallResult { + unimplemented!() + } + + fn secp256r1_get_point_from_x( + &mut self, + _x: U256, + _y_parity: bool, + _remaining_gas: &mut u128, + ) -> SyscallResult> { + unimplemented!() + } + + fn secp256r1_get_xy( + &mut self, + _p: Secp256r1Point, + _remaining_gas: &mut u128, + ) -> SyscallResult<(U256, U256)> { + unimplemented!() + } +} + // TODO: Move to the correct place or remove if unused. pub(crate) mod handler { use super::*; @@ -395,7 +582,7 @@ pub(crate) mod handler { #[repr(C)] #[derive(Debug)] - pub struct StarkNetSyscallHandlerCallbacks<'a, T> { + pub struct StarknetSyscallHandlerCallbacks<'a, T> { self_ptr: &'a mut T, get_block_hash: extern "C" fn( @@ -552,7 +739,7 @@ pub(crate) mod handler { ), } - impl<'a, T> StarkNetSyscallHandlerCallbacks<'a, T> + impl<'a, T> StarknetSyscallHandlerCallbacks<'a, T> where T: 'a, { @@ -585,9 +772,9 @@ pub(crate) mod handler { } #[allow(unused_variables)] - impl<'a, T> StarkNetSyscallHandlerCallbacks<'a, T> + impl<'a, T> StarknetSyscallHandlerCallbacks<'a, T> where - T: StarkNetSyscallHandler + 'a, + T: StarknetSyscallHandler + 'a, { pub fn new(handler: &'a mut T) -> Self { Self { diff --git a/src/types.rs b/src/types.rs index aecf52537..0fbd0063d 100644 --- a/src/types.rs +++ b/src/types.rs @@ -57,7 +57,7 @@ pub mod range_check; pub mod segment_arena; pub mod snapshot; pub mod squashed_felt252_dict; -pub mod stark_net; +pub mod starknet; pub mod r#struct; pub mod uint128; pub mod uint128_mul_guarantee; @@ -342,7 +342,7 @@ impl TypeBuilder for CoreTypeConcrete { metadata, WithSelf::new(self_ty, info), ), - Self::StarkNet(selector) => self::stark_net::build( + Self::StarkNet(selector) => self::starknet::build( context, module, registry, diff --git a/src/types/stark_net.rs b/src/types/starknet.rs similarity index 99% rename from src/types/stark_net.rs rename to src/types/starknet.rs index bc6a55a39..f29c76f8f 100644 --- a/src/types/stark_net.rs +++ b/src/types/starknet.rs @@ -1,4 +1,4 @@ -//! # StarkNet types +//! # Starknet types //! //! ## ClassHash //! Type for Starknet class hash, a value in the range [0, 2 ** 251). diff --git a/src/utils.rs b/src/utils.rs index 07071d68c..4907cba4a 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -612,12 +612,11 @@ pub mod test { metadata::{ gas::{GasMetadata, MetadataComputationConfig}, runtime_bindings::RuntimeBindingsMeta, - syscall_handler::SyscallHandlerMeta, MetadataStorage, }, module::NativeModule, starknet::{ - BlockInfo, ExecutionInfo, ExecutionInfoV2, ResourceBounds, StarkNetSyscallHandler, + BlockInfo, ExecutionInfo, ExecutionInfoV2, ResourceBounds, StarknetSyscallHandler, SyscallResult, TxInfo, TxV2Info, U256, }, utils::*, @@ -755,9 +754,6 @@ pub mod test { // Make the runtime library and syscall handler available. metadata.insert(RuntimeBindingsMeta::default()).unwrap(); - metadata - .insert(SyscallHandlerMeta::new(&mut TestSyscallHandler)) - .unwrap(); if program .type_declarations @@ -784,17 +780,15 @@ pub mod test { run_pass_manager(&context, &mut module) .expect("Could not apply passes to the compiled test program."); - let syscall_handler = metadata.remove::(); - let native_module = NativeModule::new(module, registry, metadata); // FIXME: There are some bugs with non-zero LLVM optimization levels. let executor = JitNativeExecutor::from_native_module(native_module, OptLevel::None); executor - .invoke_dynamic( + .invoke_dynamic_with_syscall_handler( entry_point_id, args, Some(u128::MAX), - syscall_handler.as_ref(), + TestSyscallHandler, ) .unwrap() } @@ -865,7 +859,7 @@ pub mod test { #[derive(Debug)] struct TestSyscallHandler; - impl StarkNetSyscallHandler for TestSyscallHandler { + impl StarknetSyscallHandler for TestSyscallHandler { fn get_block_hash(&mut self, _block_number: u64, _gas: &mut u128) -> SyscallResult { Ok(Felt::from_bytes_be_slice(b"get_block_hash ok")) } diff --git a/tests/common.rs b/tests/common.rs index 525154c16..2ffbd18ff 100644 --- a/tests/common.rs +++ b/tests/common.rs @@ -28,11 +28,10 @@ use cairo_native::{ metadata::{ gas::{GasMetadata, MetadataComputationConfig}, runtime_bindings::RuntimeBindingsMeta, - syscall_handler::SyscallHandlerMeta, MetadataStorage, }, module::NativeModule, - starknet::StarkNetSyscallHandler, + starknet::{DummySyscallHandler, StarknetSyscallHandler}, types::felt252::{HALF_PRIME, PRIME}, utils::{find_entry_point_by_idx, run_pass_manager}, values::JitValue, @@ -194,7 +193,7 @@ pub fn run_native_program( entry_point: &str, args: &[JitValue], gas: Option, - syscall_handler: Option<&SyscallHandlerMeta>, + syscall_handler: Option, ) -> ExecutionResult { let entry_point = format!("{0}::{0}::{1}", program.0, entry_point); let program = &program.1; @@ -252,9 +251,12 @@ pub fn run_native_program( let native_module = NativeModule::new(module, registry, metadata); // FIXME: There are some bugs with non-zero LLVM optimization levels. let executor = JitNativeExecutor::from_native_module(native_module, OptLevel::None); - executor - .invoke_dynamic(entry_point_id, args, gas, syscall_handler) - .unwrap() + match syscall_handler { + Some(syscall_handler) => executor + .invoke_dynamic_with_syscall_handler(entry_point_id, args, gas, syscall_handler) + .unwrap(), + None => executor.invoke_dynamic(entry_point_id, args, gas).unwrap(), + } } /// Runs the program on the cairo-vm @@ -279,7 +281,13 @@ pub fn compare_inputless_program(program_path: &str) { let program = &program; let result_vm = run_vm_program(program, "main", &[], Some(DEFAULT_GAS as usize)).unwrap(); - let result_native = run_native_program(program, "main", &[], Some(DEFAULT_GAS as u128), None); + let result_native = run_native_program( + program, + "main", + &[], + Some(DEFAULT_GAS as u128), + Option::::None, + ); compare_outputs( &program.1, @@ -291,15 +299,12 @@ pub fn compare_inputless_program(program_path: &str) { } /// Runs the program using cairo-native JIT. -pub fn run_native_starknet_contract( +pub fn run_native_starknet_contract( sierra_program: &Program, entry_point_function_idx: usize, args: &[Felt], - handler: &mut T, -) -> ContractExecutionResult -where - T: StarkNetSyscallHandler, -{ + handler: impl StarknetSyscallHandler, +) -> ContractExecutionResult { let native_context = NativeContext::new(); let native_program = native_context.compile(sierra_program).unwrap(); @@ -308,14 +313,8 @@ where let entry_point_id = &entry_point_fn.id; let native_executor = JitNativeExecutor::from_native_module(native_program, Default::default()); - native_executor - .invoke_contract_dynamic( - entry_point_id, - args, - u128::MAX.into(), - Some(&SyscallHandlerMeta::new(handler)), - ) + .invoke_contract_dynamic(entry_point_id, args, u128::MAX.into(), handler) .expect("failed to execute the given contract") } diff --git a/tests/tests/alexandria.rs b/tests/tests/alexandria.rs index 21986ebbf..75152fa76 100644 --- a/tests/tests/alexandria.rs +++ b/tests/tests/alexandria.rs @@ -1,6 +1,7 @@ use crate::common::{compare_outputs, run_native_program, run_vm_program, DEFAULT_GAS}; use cairo_lang_runner::SierraCasmRunner; use cairo_lang_sierra::program::Program; +use cairo_native::starknet::DummySyscallHandler; use std::{fs::File, io::BufReader}; use test_case::test_case; @@ -24,8 +25,13 @@ fn compare_inputless_function(function_name: &str) { let result_vm = run_vm_program(program, function_name, &[], Some(DEFAULT_GAS as usize)).unwrap(); - let result_native = - run_native_program(program, function_name, &[], Some(DEFAULT_GAS as u128), None); + let result_native = run_native_program( + program, + function_name, + &[], + Some(DEFAULT_GAS as u128), + Option::::None, + ); compare_outputs( &program.1, diff --git a/tests/tests/arrays.rs b/tests/tests/arrays.rs index 3a218d7b5..29e2e653a 100644 --- a/tests/tests/arrays.rs +++ b/tests/tests/arrays.rs @@ -3,6 +3,7 @@ use crate::common::{compare_outputs, DEFAULT_GAS}; use cairo_felt::Felt252 as DeprecatedFelt; use cairo_lang_runner::{Arg, SierraCasmRunner}; use cairo_lang_sierra::program::Program; +use cairo_native::starknet::DummySyscallHandler; use cairo_native::values::JitValue; use lazy_static::lazy_static; use proptest::prelude::*; @@ -66,7 +67,7 @@ fn array_get_test() { "run_test", &[JitValue::Felt252(10.into()), JitValue::Felt252(5.into())], Some(DEFAULT_GAS as u128), - None, + Option::::None, ); compare_outputs( @@ -91,7 +92,7 @@ proptest! { "run_test", &[JitValue::Felt252(value), JitValue::Felt252(idx.into())], Some(DEFAULT_GAS as u128), - None, + Option::::None, ); compare_outputs( diff --git a/tests/tests/dict.rs b/tests/tests/dict.rs index 057a4b36b..81c4feeae 100644 --- a/tests/tests/dict.rs +++ b/tests/tests/dict.rs @@ -4,7 +4,7 @@ use crate::common::{ use cairo_felt::Felt252 as DeprecatedFelt; use cairo_lang_runner::{Arg, SierraCasmRunner}; use cairo_lang_sierra::program::Program; -use cairo_native::values::JitValue; +use cairo_native::{starknet::DummySyscallHandler, values::JitValue}; use lazy_static::lazy_static; use proptest::prelude::*; @@ -38,7 +38,7 @@ proptest! { "run_test", &[JitValue::Felt252(a), JitValue::Felt252(b)], Some(DEFAULT_GAS as u128), - None, + Option::::None, ); compare_outputs( diff --git a/tests/tests/programs.rs b/tests/tests/programs.rs index fec6c911e..c7effe966 100644 --- a/tests/tests/programs.rs +++ b/tests/tests/programs.rs @@ -3,6 +3,7 @@ use crate::common::{compare_outputs, DEFAULT_GAS}; use cairo_felt::Felt252 as DeprecatedFelt; use cairo_lang_runner::{Arg, SierraCasmRunner}; use cairo_lang_sierra::program::Program; +use cairo_native::starknet::DummySyscallHandler; use cairo_native::values::JitValue; use lazy_static::lazy_static; use num_traits::Num; @@ -90,7 +91,7 @@ fn fib() { "run_test", &[JitValue::Felt252(10.into())], Some(DEFAULT_GAS as u128), - None, + Option::::None, ); compare_outputs( @@ -116,7 +117,7 @@ fn logistic_map() { "run_test", &[JitValue::Felt252(1000.into())], Some(DEFAULT_GAS as u128), - None, + Option::::None, ); compare_outputs( @@ -164,7 +165,7 @@ fn pedersen() { ), ], Some(DEFAULT_GAS as u128), - None, + Option::::None, ); compare_outputs( @@ -190,7 +191,7 @@ fn factorial() { "run_test", &[JitValue::Felt252(13.into())], Some(DEFAULT_GAS as u128), - None, + Option::::None, ); compare_outputs( @@ -217,7 +218,7 @@ proptest! { "run_test", &[JitValue::Felt252(n.into())], Some(DEFAULT_GAS as u128), - None, + Option::::None, ); compare_outputs( @@ -242,7 +243,7 @@ proptest! { "run_test", &[JitValue::Felt252(n.into())], Some(DEFAULT_GAS as u128), - None, + Option::::None, ); compare_outputs( @@ -267,7 +268,7 @@ proptest! { "run_test", &[JitValue::Felt252(n.into())], Some(DEFAULT_GAS as u128), - None, + Option::::None, ); compare_outputs( @@ -293,7 +294,7 @@ proptest! { "run_test", &[JitValue::Felt252(a), JitValue::Felt252(b)], Some(DEFAULT_GAS as u128), - None, + Option::::None, ); compare_outputs( @@ -321,7 +322,7 @@ proptest! { "run_test", &[JitValue::Felt252(a), JitValue::Felt252(b), JitValue::Felt252(c)], Some(DEFAULT_GAS as u128), - None, + Option::::None, ); compare_outputs( diff --git a/tests/tests/starknet/keccak.rs b/tests/tests/starknet/keccak.rs index ca0938916..b97b994cf 100644 --- a/tests/tests/starknet/keccak.rs +++ b/tests/tests/starknet/keccak.rs @@ -3,7 +3,7 @@ use cairo_lang_compiler::CompilerConfig; use cairo_lang_starknet::contract_class::{compile_path, ContractClass}; use cairo_native::starknet::{ BlockInfo, ExecutionInfo, ExecutionInfoV2, ResourceBounds, Secp256k1Point, Secp256r1Point, - StarkNetSyscallHandler, SyscallResult, TxInfo, TxV2Info, U256, + StarknetSyscallHandler, SyscallResult, TxInfo, TxV2Info, U256, }; use lazy_static::lazy_static; use starknet_types_core::felt::Felt; @@ -12,7 +12,7 @@ use std::path::Path; #[derive(Debug)] struct SyscallHandler; -impl StarkNetSyscallHandler for SyscallHandler { +impl StarknetSyscallHandler for SyscallHandler { fn get_block_hash(&mut self, block_number: u64, _gas: &mut u128) -> SyscallResult { println!("Called `get_block_hash({block_number})` from MLIR."); Ok(Felt::from_bytes_be_slice(b"get_block_hash ok")) @@ -288,7 +288,7 @@ fn keccak_test() { let program = contract.extract_sierra_program().unwrap(); let result = - run_native_starknet_contract(&program, entry_point.function_idx, &[], &mut SyscallHandler); + run_native_starknet_contract(&program, entry_point.function_idx, &[], SyscallHandler); assert!(!result.failure_flag); assert_eq!( diff --git a/tests/tests/starknet/secp256.rs b/tests/tests/starknet/secp256.rs index 012130649..e1c156b76 100644 --- a/tests/tests/starknet/secp256.rs +++ b/tests/tests/starknet/secp256.rs @@ -2,8 +2,7 @@ use crate::common::{load_cairo_path, run_native_program}; use cairo_lang_runner::SierraCasmRunner; use cairo_lang_sierra::program::Program; use cairo_native::{ - metadata::syscall_handler::SyscallHandlerMeta, - starknet::{Secp256k1Point, Secp256r1Point, StarkNetSyscallHandler, SyscallResult, U256}, + starknet::{Secp256k1Point, Secp256r1Point, StarknetSyscallHandler, SyscallResult, U256}, values::JitValue, }; use lazy_static::lazy_static; @@ -32,7 +31,7 @@ struct SyscallHandler { secp256r1_get_xy: (VecDeque, VecDeque<(U256, U256)>), } -impl StarkNetSyscallHandler for SyscallHandler { +impl StarknetSyscallHandler for &mut SyscallHandler { fn get_block_hash( &mut self, _block_number: u64, @@ -295,7 +294,7 @@ fn secp256k1_new() { }, ], Some(u128::MAX), - Some(&SyscallHandlerMeta::new(&mut syscall_handler)), + Some(&mut syscall_handler), ); assert_eq!( result.return_value, @@ -327,7 +326,7 @@ fn secp256k1_new() { }, ], Some(u128::MAX), - Some(&SyscallHandlerMeta::new(&mut syscall_handler)), + Some(&mut syscall_handler), ); assert_eq!( result.return_value, @@ -359,7 +358,7 @@ fn secp256k1_new() { }, ], Some(u128::MAX), - Some(&SyscallHandlerMeta::new(&mut syscall_handler)), + Some(&mut syscall_handler), ); assert_eq!( result.return_value, @@ -455,7 +454,7 @@ fn secp256k1_add() { }, ], Some(u128::MAX), - Some(&SyscallHandlerMeta::new(&mut syscall_handler)), + Some(&mut syscall_handler), ); assert_eq!( result.return_value, @@ -483,7 +482,7 @@ fn secp256k1_add() { }, ], Some(u128::MAX), - Some(&SyscallHandlerMeta::new(&mut syscall_handler)), + Some(&mut syscall_handler), ); assert_eq!( result.return_value, @@ -511,7 +510,7 @@ fn secp256k1_add() { }, ], Some(u128::MAX), - Some(&SyscallHandlerMeta::new(&mut syscall_handler)), + Some(&mut syscall_handler), ); assert_eq!( result.return_value, @@ -636,7 +635,7 @@ fn secp256k1_mul() { }, ], Some(u128::MAX), - Some(&SyscallHandlerMeta::new(&mut syscall_handler)), + Some(&mut syscall_handler), ); assert_eq!( result.return_value, @@ -664,7 +663,7 @@ fn secp256k1_mul() { }, ], Some(u128::MAX), - Some(&SyscallHandlerMeta::new(&mut syscall_handler)), + Some(&mut syscall_handler), ); assert_eq!( result.return_value, @@ -692,7 +691,7 @@ fn secp256k1_mul() { }, ], Some(u128::MAX), - Some(&SyscallHandlerMeta::new(&mut syscall_handler)), + Some(&mut syscall_handler), ); assert_eq!( result.return_value, @@ -807,7 +806,7 @@ fn secp256k1_get_point_from_x() { }, ], Some(u128::MAX), - Some(&SyscallHandlerMeta::new(&mut syscall_handler)), + Some(&mut syscall_handler), ); assert_eq!( result.return_value, @@ -843,7 +842,7 @@ fn secp256k1_get_point_from_x() { }, ], Some(u128::MAX), - Some(&SyscallHandlerMeta::new(&mut syscall_handler)), + Some(&mut syscall_handler), ); assert_eq!( result.return_value, @@ -879,7 +878,7 @@ fn secp256k1_get_point_from_x() { }, ], Some(u128::MAX), - Some(&SyscallHandlerMeta::new(&mut syscall_handler)), + Some(&mut syscall_handler), ); assert_eq!( result.return_value, @@ -915,7 +914,7 @@ fn secp256k1_get_point_from_x() { }, ], Some(u128::MAX), - Some(&SyscallHandlerMeta::new(&mut syscall_handler)), + Some(&mut syscall_handler), ); assert_eq!( result.return_value, @@ -1013,7 +1012,7 @@ fn secp256k1_get_xy() { y: (0, 0), }], Some(u128::MAX), - Some(&SyscallHandlerMeta::new(&mut syscall_handler)), + Some(&mut syscall_handler), ); assert_eq!( result.return_value, @@ -1044,7 +1043,7 @@ fn secp256k1_get_xy() { y: (u128::MAX, 0), }], Some(u128::MAX), - Some(&SyscallHandlerMeta::new(&mut syscall_handler)), + Some(&mut syscall_handler), ); assert_eq!( result.return_value, @@ -1075,7 +1074,7 @@ fn secp256k1_get_xy() { y: (0, u128::MAX), }], Some(u128::MAX), - Some(&SyscallHandlerMeta::new(&mut syscall_handler)), + Some(&mut syscall_handler), ); assert_eq!( result.return_value, @@ -1106,7 +1105,7 @@ fn secp256k1_get_xy() { y: (u128::MAX, u128::MAX), }], Some(u128::MAX), - Some(&SyscallHandlerMeta::new(&mut syscall_handler)), + Some(&mut syscall_handler), ); assert_eq!( result.return_value, @@ -1211,7 +1210,7 @@ fn secp256r1_new() { }, ], Some(u128::MAX), - Some(&SyscallHandlerMeta::new(&mut syscall_handler)), + Some(&mut syscall_handler), ); assert_eq!( result.return_value, @@ -1243,7 +1242,7 @@ fn secp256r1_new() { }, ], Some(u128::MAX), - Some(&SyscallHandlerMeta::new(&mut syscall_handler)), + Some(&mut syscall_handler), ); assert_eq!( result.return_value, @@ -1275,7 +1274,7 @@ fn secp256r1_new() { }, ], Some(u128::MAX), - Some(&SyscallHandlerMeta::new(&mut syscall_handler)), + Some(&mut syscall_handler), ); assert_eq!( result.return_value, @@ -1371,7 +1370,7 @@ fn secp256r1_add() { }, ], Some(u128::MAX), - Some(&SyscallHandlerMeta::new(&mut syscall_handler)), + Some(&mut syscall_handler), ); assert_eq!( result.return_value, @@ -1399,7 +1398,7 @@ fn secp256r1_add() { }, ], Some(u128::MAX), - Some(&SyscallHandlerMeta::new(&mut syscall_handler)), + Some(&mut syscall_handler), ); assert_eq!( result.return_value, @@ -1427,7 +1426,7 @@ fn secp256r1_add() { }, ], Some(u128::MAX), - Some(&SyscallHandlerMeta::new(&mut syscall_handler)), + Some(&mut syscall_handler), ); assert_eq!( result.return_value, @@ -1552,7 +1551,7 @@ fn secp256r1_mul() { }, ], Some(u128::MAX), - Some(&SyscallHandlerMeta::new(&mut syscall_handler)), + Some(&mut syscall_handler), ); assert_eq!( result.return_value, @@ -1580,7 +1579,7 @@ fn secp256r1_mul() { }, ], Some(u128::MAX), - Some(&SyscallHandlerMeta::new(&mut syscall_handler)), + Some(&mut syscall_handler), ); assert_eq!( result.return_value, @@ -1608,7 +1607,7 @@ fn secp256r1_mul() { }, ], Some(u128::MAX), - Some(&SyscallHandlerMeta::new(&mut syscall_handler)), + Some(&mut syscall_handler), ); assert_eq!( result.return_value, @@ -1723,7 +1722,7 @@ fn secp256r1_get_point_from_x() { }, ], Some(u128::MAX), - Some(&SyscallHandlerMeta::new(&mut syscall_handler)), + Some(&mut syscall_handler), ); assert_eq!( result.return_value, @@ -1759,7 +1758,7 @@ fn secp256r1_get_point_from_x() { }, ], Some(u128::MAX), - Some(&SyscallHandlerMeta::new(&mut syscall_handler)), + Some(&mut syscall_handler), ); assert_eq!( result.return_value, @@ -1795,7 +1794,7 @@ fn secp256r1_get_point_from_x() { }, ], Some(u128::MAX), - Some(&SyscallHandlerMeta::new(&mut syscall_handler)), + Some(&mut syscall_handler), ); assert_eq!( result.return_value, @@ -1831,7 +1830,7 @@ fn secp256r1_get_point_from_x() { }, ], Some(u128::MAX), - Some(&SyscallHandlerMeta::new(&mut syscall_handler)), + Some(&mut syscall_handler), ); assert_eq!( result.return_value, @@ -1929,7 +1928,7 @@ fn secp256r1_get_xy() { y: (0, 0), }], Some(u128::MAX), - Some(&SyscallHandlerMeta::new(&mut syscall_handler)), + Some(&mut syscall_handler), ); assert_eq!( result.return_value, @@ -1960,7 +1959,7 @@ fn secp256r1_get_xy() { y: (u128::MAX, 0), }], Some(u128::MAX), - Some(&SyscallHandlerMeta::new(&mut syscall_handler)), + Some(&mut syscall_handler), ); assert_eq!( result.return_value, @@ -1991,7 +1990,7 @@ fn secp256r1_get_xy() { y: (0, u128::MAX), }], Some(u128::MAX), - Some(&SyscallHandlerMeta::new(&mut syscall_handler)), + Some(&mut syscall_handler), ); assert_eq!( result.return_value, @@ -2022,7 +2021,7 @@ fn secp256r1_get_xy() { y: (u128::MAX, u128::MAX), }], Some(u128::MAX), - Some(&SyscallHandlerMeta::new(&mut syscall_handler)), + Some(&mut syscall_handler), ); assert_eq!( result.return_value, diff --git a/tests/tests/trampoline.rs b/tests/tests/trampoline.rs index b5009847d..3c9517f6d 100644 --- a/tests/tests/trampoline.rs +++ b/tests/tests/trampoline.rs @@ -18,9 +18,7 @@ fn run_program(program: &Program, entry_point: &str, args: &[JitValue]) -> Execu // FIXME: There are some bugs with non-zero LLVM optimization levels. let executor = JitNativeExecutor::from_native_module(module, OptLevel::None); - executor - .invoke_dynamic(entry_point_id, args, None, None) - .unwrap() + executor.invoke_dynamic(entry_point_id, args, None).unwrap() } #[test] diff --git a/tests/tests/uint.rs b/tests/tests/uint.rs index 57ba133e9..5dd9ac7d4 100644 --- a/tests/tests/uint.rs +++ b/tests/tests/uint.rs @@ -1,7 +1,7 @@ use crate::common::{compare_outputs, load_cairo, run_native_program, run_vm_program, DEFAULT_GAS}; use cairo_lang_runner::{Arg, SierraCasmRunner}; use cairo_lang_sierra::program::Program; -use cairo_native::values::JitValue; +use cairo_native::{starknet::DummySyscallHandler, values::JitValue}; use lazy_static::lazy_static; use proptest::prelude::*; @@ -451,7 +451,7 @@ proptest! { "run_test", &[JitValue::Felt252(a.into()), JitValue::Felt252(b.into())], Some(DEFAULT_GAS as u128), - None, + Option::::None, ); compare_outputs( @@ -477,7 +477,7 @@ proptest! { "run_test", &[JitValue::Felt252(a.into()), JitValue::Felt252(b.into())], Some(DEFAULT_GAS as u128), - None, + Option::::None, ); compare_outputs( @@ -503,7 +503,7 @@ proptest! { "run_test", &[JitValue::Felt252(a.into()), JitValue::Felt252(b.into())], Some(DEFAULT_GAS as u128), - None, + Option::::None, ); compare_outputs( @@ -529,7 +529,7 @@ proptest! { "run_test", &[JitValue::Felt252(a.into()), JitValue::Felt252(b.into())], Some(DEFAULT_GAS as u128), - None, + Option::::None, ); compare_outputs( @@ -555,7 +555,7 @@ proptest! { "run_test", &[JitValue::Felt252(a.into())], Some(DEFAULT_GAS as u128), - None, + Option::::None, ); compare_outputs( @@ -583,7 +583,7 @@ proptest! { "run_test", &[JitValue::Felt252(a.into()), JitValue::Felt252(b.into())], Some(DEFAULT_GAS as u128), - None, + Option::::None, ); compare_outputs( @@ -609,7 +609,7 @@ proptest! { "run_test", &[JitValue::Felt252(a.into()), JitValue::Felt252(b.into())], Some(DEFAULT_GAS as u128), - None, + Option::::None, ); compare_outputs( @@ -635,7 +635,7 @@ proptest! { "run_test", &[JitValue::Felt252(a.into()), JitValue::Felt252(b.into())], Some(DEFAULT_GAS as u128), - None, + Option::::None, ); compare_outputs( @@ -661,7 +661,7 @@ proptest! { "run_test", &[JitValue::Felt252(a.into()), JitValue::Felt252(b.into())], Some(DEFAULT_GAS as u128), - None, + Option::::None, ); compare_outputs( @@ -687,7 +687,7 @@ proptest! { "run_test", &[JitValue::Felt252(a.into())], Some(DEFAULT_GAS as u128), - None, + Option::::None, ); compare_outputs( @@ -715,7 +715,7 @@ proptest! { "run_test", &[JitValue::Felt252(a.into()), JitValue::Felt252(b.into())], Some(DEFAULT_GAS as u128), - None, + Option::::None, ); compare_outputs( @@ -741,7 +741,7 @@ proptest! { "run_test", &[JitValue::Felt252(a.into()), JitValue::Felt252(b.into())], Some(DEFAULT_GAS as u128), - None, + Option::::None, ); compare_outputs( @@ -767,7 +767,7 @@ proptest! { "run_test", &[JitValue::Felt252(a.into()), JitValue::Felt252(b.into())], Some(DEFAULT_GAS as u128), - None, + Option::::None, ); compare_outputs( @@ -793,7 +793,7 @@ proptest! { "run_test", &[JitValue::Felt252(a.into()), JitValue::Felt252(b.into())], Some(DEFAULT_GAS as u128), - None, + Option::::None, ); compare_outputs( @@ -819,7 +819,7 @@ proptest! { "run_test", &[JitValue::Felt252(a.into())], Some(DEFAULT_GAS as u128), - None, + Option::::None, ); compare_outputs( @@ -847,7 +847,7 @@ proptest! { "run_test", &[JitValue::Felt252(a.into()), JitValue::Felt252(b.into())], Some(DEFAULT_GAS as u128), - None, + Option::::None, ); compare_outputs( @@ -873,7 +873,7 @@ proptest! { "run_test", &[JitValue::Felt252(a.into()), JitValue::Felt252(b.into())], Some(DEFAULT_GAS as u128), - None, + Option::::None, ); compare_outputs( @@ -899,7 +899,7 @@ proptest! { "run_test", &[JitValue::Felt252(a.into()), JitValue::Felt252(b.into())], Some(DEFAULT_GAS as u128), - None, + Option::::None, ); compare_outputs( @@ -925,7 +925,7 @@ proptest! { "run_test", &[JitValue::Felt252(a.into()), JitValue::Felt252(b.into())], Some(DEFAULT_GAS as u128), - None, + Option::::None, ); compare_outputs( @@ -951,7 +951,7 @@ proptest! { "run_test", &[JitValue::Felt252(a.into())], Some(DEFAULT_GAS as u128), - None, + Option::::None, ); compare_outputs( @@ -979,7 +979,7 @@ proptest! { "run_test", &[JitValue::Felt252(a.into()), JitValue::Felt252(b.into())], Some(DEFAULT_GAS as u128), - None, + Option::::None, ); compare_outputs( @@ -1005,7 +1005,7 @@ proptest! { "run_test", &[JitValue::Felt252(a.into()), JitValue::Felt252(b.into())], Some(DEFAULT_GAS as u128), - None, + Option::::None, ); compare_outputs( @@ -1031,7 +1031,7 @@ proptest! { "run_test", &[JitValue::Felt252(a.into()), JitValue::Felt252(b.into())], Some(DEFAULT_GAS as u128), - None, + Option::::None, ); compare_outputs( @@ -1057,7 +1057,7 @@ proptest! { "run_test", &[JitValue::Felt252(a.into()), JitValue::Felt252(b.into())], Some(DEFAULT_GAS as u128), - None, + Option::::None, ); compare_outputs( @@ -1083,7 +1083,7 @@ proptest! { "run_test", &[JitValue::Felt252(a.into())], Some(DEFAULT_GAS as u128), - None, + Option::::None, ); compare_outputs( From 7a7fe478862a31447961e4948d204880a705c293 Mon Sep 17 00:00:00 2001 From: Esteve Soler Arderiu Date: Wed, 20 Mar 2024 12:56:47 +0000 Subject: [PATCH 3/3] Fix merge errors. --- tests/tests/boolean.rs | 16 ++++++++-------- tests/tests/ec.rs | 19 ++++++++++++------- tests/tests/felt252.rs | 10 +++++----- tests/tests/libfuncs.rs | 25 ++++++++++++++++++++++--- 4 files changed, 47 insertions(+), 23 deletions(-) diff --git a/tests/tests/boolean.rs b/tests/tests/boolean.rs index 537b4a0b0..848554ff4 100644 --- a/tests/tests/boolean.rs +++ b/tests/tests/boolean.rs @@ -2,7 +2,7 @@ use crate::common::{compare_outputs, load_cairo, run_native_program, run_vm_prog use cairo_felt::Felt252 as DeprecatedFelt; use cairo_lang_runner::{Arg, SierraCasmRunner}; use cairo_lang_sierra::program::Program; -use cairo_native::values::JitValue; +use cairo_native::{starknet::DummySyscallHandler, values::JitValue}; use lazy_static::lazy_static; use proptest::prelude::*; @@ -125,7 +125,7 @@ fn felt252_to_bool_bug() { "run_test", &[JitValue::Felt252(a.into())], Some(DEFAULT_GAS as u128), - None, + Option::::None, ); compare_outputs( @@ -149,7 +149,7 @@ fn felt252_to_bool_bug() { "run_test", &[JitValue::Felt252(a.into())], Some(DEFAULT_GAS as u128), - None, + Option::::None, ); compare_outputs( @@ -173,7 +173,7 @@ proptest! { "run_test", &[JitValue::Felt252(a.into())], Some(DEFAULT_GAS as u128), - None, + Option::::None, ); compare_outputs( @@ -196,7 +196,7 @@ proptest! { "run_test", &[JitValue::Felt252(a.into())], Some(DEFAULT_GAS as u128), - None, + Option::::None, ); compare_outputs( @@ -220,7 +220,7 @@ proptest! { "run_test", &[JitValue::Felt252(a.into()), JitValue::Felt252(b.into())], Some(DEFAULT_GAS as u128), - None, + Option::::None, ); compare_outputs( @@ -244,7 +244,7 @@ proptest! { "run_test", &[JitValue::Felt252(a.into()), JitValue::Felt252(b.into())], Some(DEFAULT_GAS as u128), - None, + Option::::None, ); compare_outputs( @@ -268,7 +268,7 @@ proptest! { "run_test", &[JitValue::Felt252(a.into()), JitValue::Felt252(b.into())], Some(DEFAULT_GAS as u128), - None, + Option::::None, ); compare_outputs( diff --git a/tests/tests/ec.rs b/tests/tests/ec.rs index 8cbfd436b..c8178eaac 100644 --- a/tests/tests/ec.rs +++ b/tests/tests/ec.rs @@ -4,7 +4,7 @@ use crate::common::{ use cairo_felt::Felt252 as DeprecatedFelt; use cairo_lang_runner::{Arg, SierraCasmRunner}; use cairo_lang_sierra::program::Program; -use cairo_native::values::JitValue; +use cairo_native::{starknet::DummySyscallHandler, values::JitValue}; use lazy_static::lazy_static; use num_bigint::BigUint; use proptest::prelude::*; @@ -41,8 +41,13 @@ lazy_static! { fn ec_point_zero() { let program = &EC_POINT_ZERO; let result_vm = run_vm_program(program, "run_test", &[], Some(DEFAULT_GAS as usize)).unwrap(); - let result_native = - run_native_program(program, "run_test", &[], Some(DEFAULT_GAS as u128), None); + let result_native = run_native_program( + program, + "run_test", + &[], + Some(DEFAULT_GAS as u128), + Option::::None, + ); compare_outputs( &program.1, @@ -74,7 +79,7 @@ fn ec_point_from_x_big() { "run_test", &[JitValue::Felt252(Felt::from_bytes_be(&x.to_be_bytes()))], Some(DEFAULT_GAS as u128), - None, + Option::::None, ); compare_outputs( @@ -102,7 +107,7 @@ fn ec_point_from_x_small() { "run_test", &[JitValue::Felt252(Felt::from_bytes_be(&x.to_be_bytes()))], Some(DEFAULT_GAS as u128), - None, + Option::::None, ); compare_outputs( @@ -130,7 +135,7 @@ proptest! { "run_test", &[JitValue::Felt252(a), JitValue::Felt252(b)], Some(DEFAULT_GAS as u128), - None, + Option::::None, ); compare_outputs( @@ -156,7 +161,7 @@ proptest! { "run_test", &[JitValue::Felt252(a)], Some(DEFAULT_GAS as u128), - None, + Option::::None, ); compare_outputs( diff --git a/tests/tests/felt252.rs b/tests/tests/felt252.rs index ce5b29033..d14ff053d 100644 --- a/tests/tests/felt252.rs +++ b/tests/tests/felt252.rs @@ -5,7 +5,7 @@ use crate::common::{ use cairo_felt::Felt252 as DeprecatedFelt; use cairo_lang_runner::{Arg, SierraCasmRunner}; use cairo_lang_sierra::program::Program; -use cairo_native::values::JitValue; +use cairo_native::{starknet::DummySyscallHandler, values::JitValue}; use lazy_static::lazy_static; use proptest::prelude::*; @@ -72,7 +72,7 @@ proptest! { "run_test", &[JitValue::Felt252(a), JitValue::Felt252(b)], Some(DEFAULT_GAS as u128), - None, + Option::::None, ); compare_outputs( @@ -98,7 +98,7 @@ proptest! { "run_test", &[JitValue::Felt252(a), JitValue::Felt252(b)], Some(DEFAULT_GAS as u128), - None, + Option::::None, ); compare_outputs( @@ -124,7 +124,7 @@ proptest! { "run_test", &[JitValue::Felt252(a), JitValue::Felt252(b)], Some(DEFAULT_GAS as u128), - None, + Option::::None, ); compare_outputs( @@ -150,7 +150,7 @@ proptest! { "run_test", &[JitValue::Felt252(a), JitValue::Felt252(b)], Some(DEFAULT_GAS as u128), - None, + Option::::None, ); compare_outputs( diff --git a/tests/tests/libfuncs.rs b/tests/tests/libfuncs.rs index 0863839a5..08446ada0 100644 --- a/tests/tests/libfuncs.rs +++ b/tests/tests/libfuncs.rs @@ -1,4 +1,5 @@ use crate::common::{compare_outputs, load_cairo, run_native_program, run_vm_program}; +use cairo_native::starknet::DummySyscallHandler; #[test] fn enum_init() { @@ -28,7 +29,13 @@ fn enum_init() { }; let result_vm = run_vm_program(&program, "run_test", &[], None).unwrap(); - let result_native = run_native_program(&program, "run_test", &[], None, None); + let result_native = run_native_program( + &program, + "run_test", + &[], + None, + Option::::None, + ); compare_outputs( &program.1, @@ -74,7 +81,13 @@ fn enum_match() { }; let result_vm = run_vm_program(&program, "match_a", &[], None).unwrap(); - let result_native = run_native_program(&program, "match_a", &[], None, None); + let result_native = run_native_program( + &program, + "match_a", + &[], + None, + Option::::None, + ); compare_outputs( &program.1, @@ -85,7 +98,13 @@ fn enum_match() { .unwrap(); let result_vm = run_vm_program(&program, "match_b", &[], None).unwrap(); - let result_native = run_native_program(&program, "match_b", &[], None, None); + let result_native = run_native_program( + &program, + "match_b", + &[], + None, + Option::::None, + ); compare_outputs( &program.1,