From f1554de3ccda811c4f2c3971f27ac14e4525a774 Mon Sep 17 00:00:00 2001 From: Edgar Date: Fri, 15 Nov 2024 16:06:26 +0100 Subject: [PATCH] Change gas from u128 to u64 (#890) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Revert "Revert builtin cost rework (#874)" This reverts commit 355c250f37cf0977ef2776b1aae2cb2e87c9da3d. * x * fix gas * add paralel test * Add entry point info to AotContractExecutor (#889) * store entry point info, optimize abi storage * use felt * update hash * upd replay * try with thread local * try to fix with thread local in runtime2 * fix * upd ref ci * upd replay * fix macos * try to fix macos * try to fix bench * fix * try to fix bench ci * save space * upd rev * try to fix broken pipe * try to fix bench on ci * remove all features * add cache key * update replay rev * fix cargo.lock * Revert "update replay rev" This reverts commit 40f1acc5c10687ed6c43a0a7dbd09c581ca10ec6. * fix cargo.lock * works with leaks * fix * upd replay * fix bench * Reorder deps * start porting gas to u64 * u64 on syscalls * fix * Fix benches. * clippy * fix gas refund * fmt * fix * fix get gas * update resource bounds * upd ci * upd replay * fix ci * try * fix align * fix bench pr * better fix for u256 * upd replay * upd replay * fix * remove dbg! * upd replay * fix * Revert conversion of `ResourceBounds` field type. * Update sequencer revision (for CI runs). * Update replay dependency. * read invoke data end pad * upd ci --------- Co-authored-by: Pedro Fontana Co-authored-by: Franco Giachetta Co-authored-by: Julián González Calderón Co-authored-by: Esteve Soler Arderiu --- .github/workflows/bench-hyperfine.yml | 8 +- .github/workflows/daily.yml | 13 +- .github/workflows/starknet-blocks.yml | 4 +- benches/benches.rs | 12 +- benches/libfuncs.rs | 12 +- docs/gas_builtin_accounting.md | 3 +- docs/overview.md | 68 ++++--- examples/erc20.rs | 48 ++--- examples/starknet.rs | 48 ++--- programs/benches/factorial_2M.c | 4 +- programs/benches/fib_2M.c | 4 +- programs/benches/logistic_map.c | 4 +- src/arch/aarch64.rs | 11 +- src/arch/x86_64.rs | 11 +- src/bin/cairo-native-run.rs | 2 +- src/bin/cairo-native-stress/main.rs | 2 +- src/cache/aot.rs | 2 +- src/execution_result.rs | 4 +- src/executor.rs | 14 +- src/executor/aot.rs | 12 +- src/executor/contract.rs | 17 +- src/executor/jit.rs | 6 +- src/libfuncs/felt252_dict.rs | 7 +- src/libfuncs/gas.rs | 38 ++-- src/libfuncs/starknet.rs | 255 +++++++++++++------------- src/libfuncs/starknet/secp256.rs | 200 ++++++++++---------- src/metadata/gas.rs | 24 +-- src/starknet.rs | 190 ++++++++++--------- src/starknet_stub.rs | 46 ++--- src/types.rs | 4 +- src/types/gas_builtin.rs | 2 +- src/utils.rs | 2 +- tests/common.rs | 8 +- tests/tests/alexandria.rs | 2 +- tests/tests/arrays.rs | 4 +- tests/tests/boolean.rs | 14 +- tests/tests/dict.rs | 2 +- tests/tests/ec.rs | 10 +- tests/tests/felt252.rs | 8 +- tests/tests/programs.rs | 22 +-- tests/tests/starknet/keccak.rs | 5 +- tests/tests/starknet/secp256.rs | 114 ++++++------ tests/tests/starknet/syscalls.rs | 84 ++++----- tests/tests/starknet/u256.rs | 5 +- tests/tests/uint.rs | 50 ++--- 45 files changed, 691 insertions(+), 714 deletions(-) diff --git a/.github/workflows/bench-hyperfine.yml b/.github/workflows/bench-hyperfine.yml index 42f5efaff..d2948dd7f 100644 --- a/.github/workflows/bench-hyperfine.yml +++ b/.github/workflows/bench-hyperfine.yml @@ -215,10 +215,10 @@ jobs: --export-markdown "${f%.*}.md" \ --export-json "${f%.*}.json" \ --warmup 3 \ - -n "head $(basename $f) (JIT)" "./bin/cairo-native-run-head --run-mode=jit -s $f --opt-level 3 --available-gas 19446744073709551615" \ - -n "base $(basename $f) (JIT)" "./bin/cairo-native-run-base --run-mode=jit -s $f --opt-level 3 --available-gas 19446744073709551615" \ - -n "head $(basename $f) (AOT)" "CAIRO_NATIVE_RUNTIME_LIBRARY=lib/libcairo-native-runtime-head.a ./bin/cairo-native-run-head --run-mode=aot -s $f --opt-level 3 --available-gas 19446744073709551615" \ - -n "base $(basename $f) (AOT)" "CAIRO_NATIVE_RUNTIME_LIBRARY=lib/libcairo-native-runtime-base.a ./bin/cairo-native-run-base --run-mode=aot -s $f --opt-level 3 --available-gas 19446744073709551615" \ + -n "head $(basename $f) (JIT)" "./bin/cairo-native-run-head --run-mode=jit -s $f --opt-level 3 --available-gas 18446744073709551615" \ + -n "base $(basename $f) (JIT)" "./bin/cairo-native-run-base --run-mode=jit -s $f --opt-level 3 --available-gas 18446744073709551615" \ + -n "head $(basename $f) (AOT)" "CAIRO_NATIVE_RUNTIME_LIBRARY=lib/libcairo-native-runtime-head.a ./bin/cairo-native-run-head --run-mode=aot -s $f --opt-level 3 --available-gas 18446744073709551615" \ + -n "base $(basename $f) (AOT)" "CAIRO_NATIVE_RUNTIME_LIBRARY=lib/libcairo-native-runtime-base.a ./bin/cairo-native-run-base --run-mode=aot -s $f --opt-level 3 --available-gas 18446744073709551615" \ >> /dev/stderr done - name: Print tables diff --git a/.github/workflows/daily.yml b/.github/workflows/daily.yml index 14eec0878..274904a9f 100644 --- a/.github/workflows/daily.yml +++ b/.github/workflows/daily.yml @@ -2,12 +2,12 @@ name: Daily Block Run on: schedule: - # At the end of every day - - cron: "0 0 * * *" + # At the end of every day + - cron: "0 0 * * *" env: RANGE_SIZE: 25 - SEQUENCER_REV: 1b1b95cae7ae07b9bc778443ca75ee18008a6bc8 + SEQUENCER_REV: 93b6da848802297626556950a0c715952aca552d jobs: run: @@ -56,7 +56,7 @@ jobs: # Install dependencies - uses: ./cairo_native/.github/actions/install-linux-deps - name: Setup rust env - uses: dtolnay/rust-toolchain@1.80.0 + uses: dtolnay/rust-toolchain@1.82.0 - name: Retreive cached dependecies uses: Swatinem/rust-cache@v2 - name: Build Cairo Native Runtime Library @@ -65,7 +65,7 @@ jobs: cd ../cairo_native make runtime echo "CAIRO_NATIVE_RUNTIME_LIBRARY=$(pwd)/libcairo_native_runtime.a" > $GITHUB_ENV - + - name: Patch dependencies run: | # Patches native dependency to local path, to use current cairo native version @@ -79,7 +79,7 @@ jobs: NEW_REV="$SEQUENCER_REV" sed -Ei "s#(\"$GIT\" *, *rev *= *\").?*(\".*)#\1$NEW_REV\2#" Cargo.toml grep $GIT Cargo.toml - + - name: Run with Native if: ${{ matrix.runner == 'native' }} run: | @@ -101,7 +101,6 @@ jobs: name: dump-${{matrix.block}}-${{matrix.runner}} path: starknet-replay/state_dumps/${{matrix.runner}} - compare: needs: [run] runs-on: ubuntu-latest diff --git a/.github/workflows/starknet-blocks.yml b/.github/workflows/starknet-blocks.yml index 99665cace..74d9df246 100644 --- a/.github/workflows/starknet-blocks.yml +++ b/.github/workflows/starknet-blocks.yml @@ -27,7 +27,7 @@ jobs: components: clippy - uses: Swatinem/rust-cache@v2 with: - key: "ref-dc35685315f4df544d5d1cf006d3a2a25d8c2c9a" + key: "ref-3da09d1b6f3d5c089900f5521cf05b6444893e61" - name: Check and free hdd space left if: ${{ matrix.runner == 'native' }} @@ -76,7 +76,7 @@ jobs: uses: actions/checkout@v4 with: repository: lambdaclass/starknet-replay - ref: dc35685315f4df544d5d1cf006d3a2a25d8c2c9a + ref: 3da09d1b6f3d5c089900f5521cf05b6444893e61 path: replay - name: Install Starknet Replay deps diff --git a/benches/benches.rs b/benches/benches.rs index eca0d396b..b88a6f315 100644 --- a/benches/benches.rs +++ b/benches/benches.rs @@ -48,23 +48,23 @@ fn criterion_benchmark(c: &mut Criterion) { find_function_id(&logistic_map, "logistic_map::logistic_map::main").unwrap(); c.bench_function("Cached JIT factorial_2M", |b| { - b.iter(|| jit_factorial.invoke_dynamic(factorial_function_id, &[], Some(u128::MAX))); + b.iter(|| jit_factorial.invoke_dynamic(factorial_function_id, &[], Some(u64::MAX))); }); c.bench_function("Cached JIT fib_2M", |b| { - b.iter(|| jit_fibonacci.invoke_dynamic(fibonacci_function_id, &[], Some(u128::MAX))); + b.iter(|| jit_fibonacci.invoke_dynamic(fibonacci_function_id, &[], Some(u64::MAX))); }); c.bench_function("Cached JIT logistic_map", |b| { - b.iter(|| jit_logistic_map.invoke_dynamic(logistic_map_function_id, &[], Some(u128::MAX))); + b.iter(|| jit_logistic_map.invoke_dynamic(logistic_map_function_id, &[], Some(u64::MAX))); }); c.bench_function("Cached AOT factorial_2M", |b| { - b.iter(|| aot_factorial.invoke_dynamic(factorial_function_id, &[], Some(u128::MAX))); + b.iter(|| aot_factorial.invoke_dynamic(factorial_function_id, &[], Some(u64::MAX))); }); c.bench_function("Cached AOT fib_2M", |b| { - b.iter(|| aot_fibonacci.invoke_dynamic(fibonacci_function_id, &[], Some(u128::MAX))); + b.iter(|| aot_fibonacci.invoke_dynamic(fibonacci_function_id, &[], Some(u64::MAX))); }); c.bench_function("Cached AOT logistic_map", |b| { - b.iter(|| aot_logistic_map.invoke_dynamic(logistic_map_function_id, &[], Some(u128::MAX))); + b.iter(|| aot_logistic_map.invoke_dynamic(logistic_map_function_id, &[], Some(u64::MAX))); }); } diff --git a/benches/libfuncs.rs b/benches/libfuncs.rs index aed50aaae..3528d16e6 100644 --- a/benches/libfuncs.rs +++ b/benches/libfuncs.rs @@ -61,7 +61,7 @@ pub fn bench_libfuncs(c: &mut Criterion) { // Execute the program. let result = native_executor - .invoke_dynamic(&entry.id, &[], Some(u64::MAX as u128)) + .invoke_dynamic(&entry.id, &[], Some(u64::MAX)) .unwrap(); black_box(result) }) @@ -81,14 +81,14 @@ pub fn bench_libfuncs(c: &mut Criterion) { // warmup for _ in 0..5 { native_executor - .invoke_dynamic(&entry.id, &[], Some(u64::MAX as u128)) + .invoke_dynamic(&entry.id, &[], Some(u64::MAX)) .unwrap(); } b.iter(|| { // Execute the program. let result = native_executor - .invoke_dynamic(&entry.id, &[], Some(u64::MAX as u128)) + .invoke_dynamic(&entry.id, &[], Some(u64::MAX)) .unwrap(); black_box(result) }) @@ -108,7 +108,7 @@ pub fn bench_libfuncs(c: &mut Criterion) { // Execute the program. let result = native_executor - .invoke_dynamic(&entry.id, &[], Some(u64::MAX as u128)) + .invoke_dynamic(&entry.id, &[], Some(u64::MAX)) .unwrap(); black_box(result) }) @@ -128,14 +128,14 @@ pub fn bench_libfuncs(c: &mut Criterion) { // warmup for _ in 0..5 { native_executor - .invoke_dynamic(&entry.id, &[], Some(u64::MAX as u128)) + .invoke_dynamic(&entry.id, &[], Some(u64::MAX)) .unwrap(); } b.iter(|| { // Execute the program. let result = native_executor - .invoke_dynamic(&entry.id, &[], Some(u64::MAX as u128)) + .invoke_dynamic(&entry.id, &[], Some(u64::MAX)) .unwrap(); black_box(result) }) diff --git a/docs/gas_builtin_accounting.md b/docs/gas_builtin_accounting.md index a88636f8c..8f9cccb3e 100644 --- a/docs/gas_builtin_accounting.md +++ b/docs/gas_builtin_accounting.md @@ -21,7 +21,7 @@ and greged’s about ### Gas builtin The gas builtin is used in Sierra in order to perform gas accounting. It is passed as an input to all function calls and holds the current remaining -gas. It is represented in MLIR by a simple `u128`. +gas. It is represented in MLIR by a simple `u64`. ### Gas metadata The process of calculating gas begins at the very outset of the compilation @@ -236,4 +236,3 @@ constant 1. When this compiled MLIR code is called, the initial value of all builtin counters is set to `0` as can be seen in the [`invoke_dynamic` function](../src/executor.rs#L240). - diff --git a/docs/overview.md b/docs/overview.md index e524dd60a..15409d79b 100644 --- a/docs/overview.md +++ b/docs/overview.md @@ -1,32 +1,35 @@ # Overview -This crate is a compiler and JIT engine that transforms Sierra (or Cairo) -sources into MLIR, which can be +This crate is a compiler and JIT engine that transforms Sierra (or Cairo) +sources into MLIR, which can be [JIT-executed](https://en.wikipedia.org/wiki/Just-in-time_compilation) or further compiled into a binary [ahead of time](https://en.wikipedia.org/wiki/Ahead-of-time_compilation). ## Getting started as a developer -First make sure you have a working environment and are able to compile the -project without issues. Make sure to follow the [setup](/README.md#setup) guide + +First make sure you have a working environment and are able to compile the +project without issues. Make sure to follow the [setup](/README.md#setup) guide on steps on how to do this. -It is generally recommended to use the `optimized-dev` cargo profile when -testing or running programs, the make target `make build-dev` will be useful for +It is generally recommended to use the `optimized-dev` cargo profile when +testing or running programs, the make target `make build-dev` will be useful for this. ### Other tools -In addition to the tools included in Cairo Native, it is also recommended you -have `cairo-compile` and `cairo-run` installed to check how the generated sierra -code looks like, and to compare results manually (when required) which will help + +In addition to the tools included in Cairo Native, it is also recommended you +have `cairo-compile` and `cairo-run` installed to check how the generated sierra +code looks like, and to compare results manually (when required) which will help greatly when implementing functionality into Cairo Native. -You can check the [cairo](https://github.com/starkware-libs/cairo) repository +You can check the [cairo](https://github.com/starkware-libs/cairo) repository for more info on how to get those tools. ## Basic Workflow -After having implemented your desired feature or bug fix, you should check it -passes all tests and lints, also make sure to add any needed test cases for the + +After having implemented your desired feature or bug fix, you should check it +passes all tests and lints, also make sure to add any needed test cases for the added code. ```bash @@ -40,11 +43,14 @@ make test Then you are free to go and make a PR! ## High level project overview -This will explain how the project is structured, without going into much details + +This will explain how the project is structured, without going into much details yet: ### Project dependencies + The major dependencies of the project are the following: + - Melior: This is the crate that abstracts away most of the interfacing with MLIR, our compilation target, it uses mlir-sys and tries to safely abstract MLIR in Rust. @@ -60,6 +66,7 @@ The major dependencies of the project are the following: function in pseudo assembly). ### Common definitions + Within this project there are lots of functions with the same signature. As their arguments have all the same meaning, they are documented here: @@ -72,6 +79,7 @@ As their arguments have all the same meaning, they are documented here: - `metadata: &mut MetadataStorage`: Current compiler metadata. ## Project layout + The code is laid out in the following sections: ```txt @@ -80,12 +88,12 @@ The code is laid out in the following sections: ├─ arch/ Architecture-specific code for the trampoline. ├─ bin/ Binary programs ├─ block_ext.rs A melior (MLIR) block trait extension to write less code. - ├─ cache.rs Types and implementations of compiled program caches. + ├─ cache.rs Types and implementations of compiled program caches. ├─ compiler.rs The glue code of the compiler, has the codegen for the function signatures and calls the libfunc codegen implementations. ├─ context.rs The MLIR context wrapper, provides the compile method. - ├─ debug.rs + ├─ debug.rs ├─ docs.rs Documentation modules. ├─ error.rs Error handling, ├─ execution_result.rs Program result parsing. @@ -97,13 +105,14 @@ The code is laid out in the following sections: ├─ metadata.rs Metadata injector to use within the compilation process. ├─ module.rs The MLIR module wrapper. ├─ starknet.rs Starknet syscall handler glue code. - ├─ starknet_stub.rs + ├─ starknet_stub.rs ├─ types.rs Cairo to MLIR type information, ├─ utils.rs Internal utilities. └─ values.rs JIT serialization. ``` ### Library functions + Path: `src/libfuncs` Here are stored all the library function implementations in MLIR, this @@ -111,6 +120,7 @@ contains the majority of the code. To store information about the different types of library functions sierra has, we divide them into the following using the enum `SierraLibFunc`: + - **Branching**: These functions are implemented inline, adding blocks and jumping as necessary based on given conditions. - **Constant**: A constant value, this isn't represented as a function and @@ -120,6 +130,7 @@ has, we divide them into the following using the enum `SierraLibFunc`: problem. For example: `dup`, `store_temp` ### Statements + Path: `src/statements` Here is the code that processes the statements of non-library functions. @@ -127,10 +138,12 @@ It handles dataflow, branching, function calls, variable storage and also has implementations for the inline library functions. ### User functions + These are extra utility functions unrelated to sierra that aid in the development, such as wrapping return values and printing them. ## Basic API usage example + The API contains two structs, `NativeContext` and `NativeExecutor`. The main purpose of `NativeContext` is MLIR initialization, compilation and lowering to LLVM. @@ -176,6 +189,7 @@ println!("{:?}", result); ``` ## Running a Cairo program + This is a usage example using the API for an easy Cairo program that requires the least setup to get running. It allows you to compile and execute a program using the JIT. @@ -293,7 +307,7 @@ impl StarkNetSyscallHandler for SyscallHandler { fn get_block_hash( &mut self, block_number: u64, - _gas: &mut u128, + _gas: &mut u64, ) -> SyscallResult { println!("Called `get_block_hash({block_number})` from MLIR."); Ok(Felt::from_bytes_be_slice(b"get_block_hash ok")) @@ -301,7 +315,7 @@ impl StarkNetSyscallHandler for SyscallHandler { fn get_execution_info( &mut self, - _gas: &mut u128, + _gas: &mut u64, ) -> SyscallResult { println!("Called `get_execution_info()` from MLIR."); Ok(ExecutionInfo { @@ -331,7 +345,7 @@ impl StarkNetSyscallHandler for SyscallHandler { contract_address_salt: Felt, calldata: &[Felt], deploy_from_zero: bool, - _gas: &mut u128, + _gas: &mut u64, ) -> SyscallResult<(Felt, Vec)> { println!("Called `deploy({class_hash}, {contract_address_salt}, {calldata:?}, {deploy_from_zero})` from MLIR."); Ok(( @@ -343,7 +357,7 @@ impl StarkNetSyscallHandler for SyscallHandler { fn replace_class( &mut self, class_hash: Felt, - _gas: &mut u128, + _gas: &mut u64, ) -> SyscallResult<()> { println!("Called `replace_class({class_hash})` from MLIR."); Ok(()) @@ -354,7 +368,7 @@ impl StarkNetSyscallHandler for SyscallHandler { class_hash: Felt, function_selector: Felt, calldata: &[Felt], - _gas: &mut u128, + _gas: &mut u64, ) -> SyscallResult> { println!( "Called `library_call({class_hash}, {function_selector}, {calldata:?})` from MLIR." @@ -367,7 +381,7 @@ impl StarkNetSyscallHandler for SyscallHandler { address: Felt, entry_point_selector: Felt, calldata: &[Felt], - _gas: &mut u128, + _gas: &mut u64, ) -> SyscallResult> { println!( "Called `call_contract({address}, {entry_point_selector}, {calldata:?})` from MLIR." @@ -379,7 +393,7 @@ impl StarkNetSyscallHandler for SyscallHandler { &mut self, address_domain: u32, address: Felt, - _gas: &mut u128, + _gas: &mut u64, ) -> SyscallResult { println!("Called `storage_read({address_domain}, {address})` from MLIR."); Ok(address * Felt::from(3)) @@ -390,7 +404,7 @@ impl StarkNetSyscallHandler for SyscallHandler { address_domain: u32, address: Felt, value: Felt, - _gas: &mut u128, + _gas: &mut u64, ) -> SyscallResult<()> { println!("Called `storage_write({address_domain}, {address}, {value})` from MLIR."); Ok(()) @@ -400,7 +414,7 @@ impl StarkNetSyscallHandler for SyscallHandler { &mut self, keys: &[Felt], data: &[Felt], - _gas: &mut u128, + _gas: &mut u64, ) -> SyscallResult<()> { println!("Called `emit_event({keys:?}, {data:?})` from MLIR."); Ok(()) @@ -410,7 +424,7 @@ impl StarkNetSyscallHandler for SyscallHandler { &mut self, to_address: Felt, payload: &[Felt], - _gas: &mut u128, + _gas: &mut u64, ) -> SyscallResult<()> { println!("Called `send_message_to_l1({to_address}, {payload:?})` from MLIR."); Ok(()) @@ -419,7 +433,7 @@ impl StarkNetSyscallHandler for SyscallHandler { fn keccak( &mut self, input: &[u64], - _gas: &mut u128, + _gas: &mut u64, ) -> SyscallResult { println!("Called `keccak({input:?})` from MLIR."); Ok(U256(Felt::from(1234567890).to_le_bytes())) diff --git a/examples/erc20.rs b/examples/erc20.rs index 76917c32e..de61c0f78 100644 --- a/examples/erc20.rs +++ b/examples/erc20.rs @@ -17,14 +17,14 @@ use tracing_subscriber::{EnvFilter, FmtSubscriber}; struct SyscallHandler; impl StarknetSyscallHandler for SyscallHandler { - fn get_block_hash(&mut self, block_number: u64, _gas: &mut u128) -> SyscallResult { + fn get_block_hash(&mut self, block_number: u64, _gas: &mut u64) -> SyscallResult { println!("Called `get_block_hash({block_number})` from MLIR."); Ok(Felt::from_bytes_be_slice(b"get_block_hash ok")) } fn get_execution_info( &mut self, - _gas: &mut u128, + _gas: &mut u64, ) -> SyscallResult { println!("Called `get_execution_info()` from MLIR."); Ok(ExecutionInfo { @@ -50,7 +50,7 @@ impl StarknetSyscallHandler for SyscallHandler { fn get_execution_info_v2( &mut self, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult { println!("Called `get_execution_info_v2()` from MLIR."); Ok(ExecutionInfoV2 { @@ -90,7 +90,7 @@ impl StarknetSyscallHandler for SyscallHandler { contract_address_salt: Felt, calldata: &[Felt], deploy_from_zero: bool, - _gas: &mut u128, + _gas: &mut u64, ) -> SyscallResult<(Felt, Vec)> { println!("Called `deploy({class_hash}, {contract_address_salt}, {calldata:?}, {deploy_from_zero})` from MLIR."); Ok(( @@ -99,7 +99,7 @@ impl StarknetSyscallHandler for SyscallHandler { )) } - fn replace_class(&mut self, class_hash: Felt, _gas: &mut u128) -> SyscallResult<()> { + fn replace_class(&mut self, class_hash: Felt, _gas: &mut u64) -> SyscallResult<()> { println!("Called `replace_class({class_hash})` from MLIR."); Ok(()) } @@ -109,7 +109,7 @@ impl StarknetSyscallHandler for SyscallHandler { class_hash: Felt, function_selector: Felt, calldata: &[Felt], - _gas: &mut u128, + _gas: &mut u64, ) -> SyscallResult> { println!( "Called `library_call({class_hash}, {function_selector}, {calldata:?})` from MLIR." @@ -122,7 +122,7 @@ impl StarknetSyscallHandler for SyscallHandler { address: Felt, entry_point_selector: Felt, calldata: &[Felt], - _gas: &mut u128, + _gas: &mut u64, ) -> SyscallResult> { println!( "Called `call_contract({address}, {entry_point_selector}, {calldata:?})` from MLIR." @@ -134,7 +134,7 @@ impl StarknetSyscallHandler for SyscallHandler { &mut self, address_domain: u32, address: Felt, - _gas: &mut u128, + _gas: &mut u64, ) -> SyscallResult { println!("Called `storage_read({address_domain}, {address})` from MLIR."); Ok(address * Felt::from(3)) @@ -145,13 +145,13 @@ impl StarknetSyscallHandler for SyscallHandler { address_domain: u32, address: Felt, value: Felt, - _gas: &mut u128, + _gas: &mut u64, ) -> SyscallResult<()> { println!("Called `storage_write({address_domain}, {address}, {value})` from MLIR."); Ok(()) } - fn emit_event(&mut self, keys: &[Felt], data: &[Felt], _gas: &mut u128) -> SyscallResult<()> { + fn emit_event(&mut self, keys: &[Felt], data: &[Felt], _gas: &mut u64) -> SyscallResult<()> { println!("Called `emit_event({keys:?}, {data:?})` from MLIR."); Ok(()) } @@ -160,7 +160,7 @@ impl StarknetSyscallHandler for SyscallHandler { &mut self, to_address: Felt, payload: &[Felt], - _gas: &mut u128, + _gas: &mut u64, ) -> SyscallResult<()> { println!("Called `send_message_to_l1({to_address}, {payload:?})` from MLIR."); Ok(()) @@ -169,7 +169,7 @@ impl StarknetSyscallHandler for SyscallHandler { fn keccak( &mut self, input: &[u64], - _gas: &mut u128, + _gas: &mut u64, ) -> SyscallResult { println!("Called `keccak({input:?})` from MLIR."); Ok(U256 { @@ -182,7 +182,7 @@ impl StarknetSyscallHandler for SyscallHandler { &mut self, _x: U256, _y: U256, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult> { unimplemented!() } @@ -191,7 +191,7 @@ impl StarknetSyscallHandler for SyscallHandler { &mut self, _p0: Secp256k1Point, _p1: Secp256k1Point, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult { unimplemented!() } @@ -200,7 +200,7 @@ impl StarknetSyscallHandler for SyscallHandler { &mut self, _p: Secp256k1Point, _m: U256, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult { unimplemented!() } @@ -209,7 +209,7 @@ impl StarknetSyscallHandler for SyscallHandler { &mut self, _x: U256, _y_parity: bool, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult> { unimplemented!() } @@ -217,7 +217,7 @@ impl StarknetSyscallHandler for SyscallHandler { fn secp256k1_get_xy( &mut self, _p: Secp256k1Point, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult<(U256, U256)> { unimplemented!() } @@ -226,7 +226,7 @@ impl StarknetSyscallHandler for SyscallHandler { &mut self, _x: U256, _y: U256, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult> { unimplemented!() } @@ -235,7 +235,7 @@ impl StarknetSyscallHandler for SyscallHandler { &mut self, _p0: Secp256r1Point, _p1: Secp256r1Point, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult { unimplemented!() } @@ -244,7 +244,7 @@ impl StarknetSyscallHandler for SyscallHandler { &mut self, _p: Secp256r1Point, _m: U256, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult { unimplemented!() } @@ -253,7 +253,7 @@ impl StarknetSyscallHandler for SyscallHandler { &mut self, _x: U256, _y_parity: bool, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult> { unimplemented!() } @@ -261,7 +261,7 @@ impl StarknetSyscallHandler for SyscallHandler { fn secp256r1_get_xy( &mut self, _p: Secp256r1Point, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult<(U256, U256)> { unimplemented!() } @@ -270,7 +270,7 @@ impl StarknetSyscallHandler for SyscallHandler { &mut self, _state: &mut [u32; 8], _block: &[u32; 16], - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult<()> { unimplemented!() } @@ -324,7 +324,7 @@ fn main() { Felt::from(4), Felt::from(6), ], - Some(u128::MAX), + Some(u64::MAX), SyscallHandler, ) .expect("failed to execute the given contract"); diff --git a/examples/starknet.rs b/examples/starknet.rs index 28f987041..875051c84 100644 --- a/examples/starknet.rs +++ b/examples/starknet.rs @@ -56,14 +56,14 @@ impl SyscallHandler { } impl StarknetSyscallHandler for SyscallHandler { - fn get_block_hash(&mut self, block_number: u64, _gas: &mut u128) -> SyscallResult { + fn get_block_hash(&mut self, block_number: u64, _gas: &mut u64) -> SyscallResult { println!("Called `get_block_hash({block_number})` from MLIR."); Ok(Felt::from_bytes_be_slice(b"get_block_hash ok")) } fn get_execution_info( &mut self, - _gas: &mut u128, + _gas: &mut u64, ) -> SyscallResult { println!("Called `get_execution_info()` from MLIR."); Ok(ExecutionInfo { @@ -89,7 +89,7 @@ impl StarknetSyscallHandler for SyscallHandler { fn get_execution_info_v2( &mut self, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult { println!("Called `get_execution_info_v2()` from MLIR."); Ok(ExecutionInfoV2 { @@ -129,7 +129,7 @@ impl StarknetSyscallHandler for SyscallHandler { contract_address_salt: Felt, calldata: &[Felt], deploy_from_zero: bool, - _gas: &mut u128, + _gas: &mut u64, ) -> SyscallResult<(Felt, Vec)> { println!("Called `deploy({class_hash}, {contract_address_salt}, {calldata:?}, {deploy_from_zero})` from MLIR."); Ok(( @@ -138,7 +138,7 @@ impl StarknetSyscallHandler for SyscallHandler { )) } - fn replace_class(&mut self, class_hash: Felt, _gas: &mut u128) -> SyscallResult<()> { + fn replace_class(&mut self, class_hash: Felt, _gas: &mut u64) -> SyscallResult<()> { println!("Called `replace_class({class_hash})` from MLIR."); Ok(()) } @@ -148,7 +148,7 @@ impl StarknetSyscallHandler for SyscallHandler { class_hash: Felt, function_selector: Felt, calldata: &[Felt], - _gas: &mut u128, + _gas: &mut u64, ) -> SyscallResult> { println!( "Called `library_call({class_hash}, {function_selector}, {calldata:?})` from MLIR." @@ -161,7 +161,7 @@ impl StarknetSyscallHandler for SyscallHandler { address: Felt, entry_point_selector: Felt, calldata: &[Felt], - _gas: &mut u128, + _gas: &mut u64, ) -> SyscallResult> { println!( "Called `call_contract({address}, {entry_point_selector}, {calldata:?})` from MLIR." @@ -173,7 +173,7 @@ impl StarknetSyscallHandler for SyscallHandler { &mut self, address_domain: u32, address: Felt, - _gas: &mut u128, + _gas: &mut u64, ) -> SyscallResult { println!("Called `storage_read({address_domain}, {address})` from MLIR."); Ok(address * Felt::from(3)) @@ -184,13 +184,13 @@ impl StarknetSyscallHandler for SyscallHandler { address_domain: u32, address: Felt, value: Felt, - _gas: &mut u128, + _gas: &mut u64, ) -> SyscallResult<()> { println!("Called `storage_write({address_domain}, {address}, {value})` from MLIR."); Ok(()) } - fn emit_event(&mut self, keys: &[Felt], data: &[Felt], _gas: &mut u128) -> SyscallResult<()> { + fn emit_event(&mut self, keys: &[Felt], data: &[Felt], _gas: &mut u64) -> SyscallResult<()> { println!("Called `emit_event({keys:?}, {data:?})` from MLIR."); Ok(()) } @@ -199,7 +199,7 @@ impl StarknetSyscallHandler for SyscallHandler { &mut self, to_address: Felt, payload: &[Felt], - _gas: &mut u128, + _gas: &mut u64, ) -> SyscallResult<()> { println!("Called `send_message_to_l1({to_address}, {payload:?})` from MLIR."); Ok(()) @@ -208,7 +208,7 @@ impl StarknetSyscallHandler for SyscallHandler { fn keccak( &mut self, input: &[u64], - _gas: &mut u128, + _gas: &mut u64, ) -> SyscallResult { println!("Called `keccak({input:?})` from MLIR."); Ok(U256 { @@ -221,7 +221,7 @@ impl StarknetSyscallHandler for SyscallHandler { &mut self, _x: U256, _y: U256, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult> { unimplemented!() } @@ -230,7 +230,7 @@ impl StarknetSyscallHandler for SyscallHandler { &mut self, _p0: Secp256k1Point, _p1: Secp256k1Point, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult { unimplemented!() } @@ -239,7 +239,7 @@ impl StarknetSyscallHandler for SyscallHandler { &mut self, _p: Secp256k1Point, _m: U256, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult { unimplemented!() } @@ -248,7 +248,7 @@ impl StarknetSyscallHandler for SyscallHandler { &mut self, _x: U256, _y_parity: bool, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult> { unimplemented!() } @@ -256,7 +256,7 @@ impl StarknetSyscallHandler for SyscallHandler { fn secp256k1_get_xy( &mut self, _p: Secp256k1Point, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult<(U256, U256)> { unimplemented!() } @@ -265,7 +265,7 @@ impl StarknetSyscallHandler for SyscallHandler { &mut self, _x: U256, _y: U256, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult> { unimplemented!() } @@ -274,7 +274,7 @@ impl StarknetSyscallHandler for SyscallHandler { &mut self, _p0: Secp256r1Point, _p1: Secp256r1Point, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult { unimplemented!() } @@ -283,7 +283,7 @@ impl StarknetSyscallHandler for SyscallHandler { &mut self, _p: Secp256r1Point, _m: U256, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult { unimplemented!() } @@ -292,7 +292,7 @@ impl StarknetSyscallHandler for SyscallHandler { &mut self, _x: U256, _y_parity: bool, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult> { unimplemented!() } @@ -300,7 +300,7 @@ impl StarknetSyscallHandler for SyscallHandler { fn secp256r1_get_xy( &mut self, _p: Secp256r1Point, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult<(U256, U256)> { unimplemented!() } @@ -401,7 +401,7 @@ impl StarknetSyscallHandler for SyscallHandler { &mut self, _state: &mut [u32; 8], _block: &[u32; 16], - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult<()> { unimplemented!() } @@ -445,7 +445,7 @@ fn main() { let native_executor = JitNativeExecutor::from_native_module(native_program, Default::default()); let result = native_executor - .invoke_contract_dynamic(fn_id, &[Felt::ONE], Some(u128::MAX), SyscallHandler::new()) + .invoke_contract_dynamic(fn_id, &[Felt::ONE], Some(u64::MAX), SyscallHandler::new()) .expect("failed to execute the given contract"); println!(); diff --git a/programs/benches/factorial_2M.c b/programs/benches/factorial_2M.c index 992f8648d..15b811783 100644 --- a/programs/benches/factorial_2M.c +++ b/programs/benches/factorial_2M.c @@ -5,7 +5,7 @@ typedef struct factorial_return_values { uint64_t range_check_counter; - unsigned __int128 remaining_gas; + uint64_t remaining_gas; struct { uint8_t discriminant; struct { @@ -30,7 +30,7 @@ int main() cairo_native__set_costs_builtin(&BuiltinCosts[0]); - run_bench(&return_values, 0); + run_bench(&return_values, 0xFFFFFFFFFFFFFFFF); assert((return_values.result.discriminant & 0x1) == 0); return 0; diff --git a/programs/benches/fib_2M.c b/programs/benches/fib_2M.c index ffbec9785..696dc5f60 100644 --- a/programs/benches/fib_2M.c +++ b/programs/benches/fib_2M.c @@ -5,7 +5,7 @@ typedef struct fib_return_values { uint64_t range_check_counter; - unsigned __int128 remaining_gas; + uint64_t remaining_gas; struct { uint8_t discriminant; struct { @@ -30,7 +30,7 @@ int main() fib_return_values_t return_values; - run_bench(&return_values, 0); + run_bench(&return_values, 0xFFFFFFFFFFFFFFFF); assert((return_values.result.discriminant & 0x1) == 0); return 0; diff --git a/programs/benches/logistic_map.c b/programs/benches/logistic_map.c index 5d88dfb89..e8d118291 100644 --- a/programs/benches/logistic_map.c +++ b/programs/benches/logistic_map.c @@ -5,7 +5,7 @@ typedef struct map_return_values { uint64_t range_check_counter; - unsigned __int128 remaining_gas; + uint64_t remaining_gas; struct { uint8_t discriminant; struct { @@ -30,7 +30,7 @@ int main() map_return_values_t return_values; - run_bench(&return_values, 0); + run_bench(&return_values, 0xFFFFFFFFFFFFFFFF); assert((return_values.result.discriminant & 0x1) == 0); return 0; diff --git a/src/arch/aarch64.rs b/src/arch/aarch64.rs index b99d878a7..c020b0f93 100644 --- a/src/arch/aarch64.rs +++ b/src/arch/aarch64.rs @@ -164,15 +164,8 @@ impl AbiArgument for Felt { impl AbiArgument for U256 { fn to_bytes(&self, buffer: &mut Vec) -> Result<(), Error> { - if buffer.len() < 56 { - buffer.extend_from_slice(&self.lo.to_le_bytes()); - buffer.extend_from_slice(&self.hi.to_le_bytes()); - } else { - align_to(buffer, get_integer_layout(256).align()); - buffer.extend_from_slice(&self.lo.to_le_bytes()); - buffer.extend_from_slice(&self.hi.to_le_bytes()); - } - Ok(()) + self.lo.to_bytes(buffer)?; + self.hi.to_bytes(buffer) } } diff --git a/src/arch/x86_64.rs b/src/arch/x86_64.rs index e00e12bcf..1496868b3 100644 --- a/src/arch/x86_64.rs +++ b/src/arch/x86_64.rs @@ -164,15 +164,8 @@ impl AbiArgument for Felt { impl AbiArgument for U256 { fn to_bytes(&self, buffer: &mut Vec) -> Result<(), Error> { - if buffer.len() < 40 { - buffer.extend_from_slice(&self.lo.to_le_bytes()); - buffer.extend_from_slice(&self.hi.to_le_bytes()); - } else { - align_to(buffer, get_integer_layout(256).align()); - buffer.extend_from_slice(&self.lo.to_le_bytes()); - buffer.extend_from_slice(&self.hi.to_le_bytes()); - } - Ok(()) + self.lo.to_bytes(buffer)?; + self.hi.to_bytes(buffer) } } diff --git a/src/bin/cairo-native-run.rs b/src/bin/cairo-native-run.rs index 8aea5d665..c0932f78e 100644 --- a/src/bin/cairo-native-run.rs +++ b/src/bin/cairo-native-run.rs @@ -37,7 +37,7 @@ struct Args { allow_warnings: bool, /// In cases where gas is available, the amount of provided gas. #[arg(long)] - available_gas: Option, + available_gas: Option, /// Run with JIT or AOT (compiled). #[arg(long, value_enum, default_value_t = RunMode::Jit)] run_mode: RunMode, diff --git a/src/bin/cairo-native-stress/main.rs b/src/bin/cairo-native-stress/main.rs index 015d54961..1b74b1a00 100644 --- a/src/bin/cairo-native-stress/main.rs +++ b/src/bin/cairo-native-stress/main.rs @@ -125,7 +125,7 @@ fn main() { let execution_result = { let now = Instant::now(); let execution_result = executor - .invoke_contract_dynamic(&entry_point, &[], Some(u128::MAX), DummySyscallHandler) + .invoke_contract_dynamic(&entry_point, &[], Some(u64::MAX), DummySyscallHandler) .expect("failed to execute contract"); let elapsed = now.elapsed().as_millis(); let result = execution_result.return_values[0]; diff --git a/src/cache/aot.rs b/src/cache/aot.rs index 8c77ae7e7..f2b0869b0 100644 --- a/src/cache/aot.rs +++ b/src/cache/aot.rs @@ -105,7 +105,7 @@ mod tests { let executor = cache.compile_and_insert((), &program, OptLevel::default()); let res = executor .unwrap() - .invoke_dynamic(function_id, &[], Some(u128::MAX)) + .invoke_dynamic(function_id, &[], Some(u64::MAX)) .expect("should run"); // After compiling and inserting the program, we should be able to run it. diff --git a/src/execution_result.rs b/src/execution_result.rs index 37bc218a9..3ddee296a 100644 --- a/src/execution_result.rs +++ b/src/execution_result.rs @@ -33,7 +33,7 @@ pub struct BuiltinStats { /// The result of the JIT execution. #[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)] pub struct ExecutionResult { - pub remaining_gas: Option, + pub remaining_gas: Option, pub return_value: Value, pub builtin_stats: BuiltinStats, } @@ -52,7 +52,7 @@ pub struct ExecutionResult { serde::Deserialize, )] pub struct ContractExecutionResult { - pub remaining_gas: u128, + pub remaining_gas: u64, pub failure_flag: bool, pub return_values: Vec, pub error_msg: Option, diff --git a/src/executor.rs b/src/executor.rs index 5ab3fe2fe..4990d2100 100644 --- a/src/executor.rs +++ b/src/executor.rs @@ -73,7 +73,7 @@ fn invoke_dynamic( set_builtin_costs_fnptr: extern "C" fn(*const u64) -> *const u64, function_signature: &FunctionSignature, args: &[Value], - gas: u128, + gas: u64, mut syscall_handler: Option, ) -> Result { tracing::info!("Invoking function with signature: {function_signature:?}."); @@ -248,11 +248,11 @@ fn invoke_dynamic( match type_info { CoreTypeConcrete::GasBuiltin(_) => { remaining_gas = Some(match &mut return_ptr { - Some(return_ptr) => unsafe { *read_value::(return_ptr) }, + Some(return_ptr) => unsafe { *read_value::(return_ptr) }, None => { // If there's no return ptr then the function only returned the gas. We don't // need to bother with the syscall handler builtin. - ((ret_registers[1] as u128) << 64) | ret_registers[0] as u128 + ret_registers[0] } }); } @@ -690,7 +690,7 @@ mod tests { let entrypoint_function_id = &program.funcs.first().expect("should have a function").id; let result = executor - .invoke_dynamic(entrypoint_function_id, &[], Some(u128::MAX)) + .invoke_dynamic(entrypoint_function_id, &[], Some(u64::MAX)) .unwrap(); assert_eq!(result.return_value, Value::Felt252(Felt::from(42))); @@ -708,7 +708,7 @@ mod tests { let entrypoint_function_id = &program.funcs.first().expect("should have a function").id; let result = executor - .invoke_dynamic(entrypoint_function_id, &[], Some(u128::MAX)) + .invoke_dynamic(entrypoint_function_id, &[], Some(u64::MAX)) .unwrap(); assert_eq!(result.return_value, Value::Felt252(Felt::from(42))); @@ -733,7 +733,7 @@ mod tests { .invoke_contract_dynamic( entrypoint_function_id, &[], - Some(u128::MAX), + Some(u64::MAX), &mut StubSyscallHandler::default(), ) .unwrap(); @@ -760,7 +760,7 @@ mod tests { .invoke_contract_dynamic( entrypoint_function_id, &[], - Some(u128::MAX), + Some(u64::MAX), &mut StubSyscallHandler::default(), ) .unwrap(); diff --git a/src/executor/aot.rs b/src/executor/aot.rs index 41b1565e2..3305a00f6 100644 --- a/src/executor/aot.rs +++ b/src/executor/aot.rs @@ -75,7 +75,7 @@ impl AotNativeExecutor { &self, function_id: &FunctionId, args: &[Value], - gas: Option, + gas: Option, ) -> Result { let available_gas = self .gas_metadata @@ -108,7 +108,7 @@ impl AotNativeExecutor { &self, function_id: &FunctionId, args: &[Value], - gas: Option, + gas: Option, syscall_handler: impl StarknetSyscallHandler, ) -> Result { let available_gas = self @@ -142,7 +142,7 @@ impl AotNativeExecutor { &self, function_id: &FunctionId, args: &[Felt], - gas: Option, + gas: Option, syscall_handler: impl StarknetSyscallHandler, ) -> Result { let available_gas = self @@ -271,7 +271,7 @@ mod tests { let entrypoint_function_id = &program.funcs.first().expect("should have a function").id; let result = executor - .invoke_dynamic(entrypoint_function_id, &[], Some(u128::MAX)) + .invoke_dynamic(entrypoint_function_id, &[], Some(u64::MAX)) .unwrap(); assert_eq!(result.return_value, Value::Felt252(Felt::from(42))); @@ -299,7 +299,7 @@ mod tests { .invoke_dynamic_with_syscall_handler( entrypoint_function_id, &[], - Some(u128::MAX), + Some(u64::MAX), syscall_handler, ) .unwrap(); @@ -338,7 +338,7 @@ mod tests { .invoke_contract_dynamic( entrypoint_function_id, &[], - Some(u128::MAX), + Some(u64::MAX), &mut StubSyscallHandler::default(), ) .unwrap(); diff --git a/src/executor/contract.rs b/src/executor/contract.rs index a7a09ddbf..b002c414b 100644 --- a/src/executor/contract.rs +++ b/src/executor/contract.rs @@ -285,7 +285,7 @@ impl AotContractExecutor { &self, selector: Felt, args: &[Felt], - gas: Option, + gas: Option, builtin_costs: Option, mut syscall_handler: impl StarknetSyscallHandler, ) -> Result { @@ -331,7 +331,7 @@ impl AotContractExecutor { let token_cost = builtin_costs_stack[*offset as usize] * val; cost += token_cost; } - cost as u128 + cost }; let gas = gas .unwrap_or(initial_gas_cost) @@ -346,8 +346,7 @@ impl AotContractExecutor { // There is always a return ptr because contracts always return more than 1 thing (builtin counters, syscall, enum) let return_ptr = arena.alloc_layout(unsafe { - // 64 = size of enum + builtin sizes - // align is 16 because of the u128 from gas + // 56 = size of enum Layout::from_size_align_unchecked(128 + builtins_size, 16) }); @@ -441,7 +440,7 @@ impl AotContractExecutor { for b in &self.contract_info.entry_points_info[&function_id.id].builtins { match b { BuiltinType::Gas => { - remaining_gas = unsafe { *read_value::(return_ptr) }; + remaining_gas = unsafe { *read_value::(return_ptr) }; } BuiltinType::System => { unsafe { read_value::<*mut ()>(return_ptr) }; @@ -716,7 +715,7 @@ mod tests { .run( Felt::from(&selector), &[n.into()], - Some(u64::MAX as u128), + Some(u64::MAX), None, &mut StubSyscallHandler::default(), ) @@ -751,7 +750,7 @@ mod tests { .run( Felt::from(&selector), &[2.into()], - Some(u64::MAX as u128), + Some(u64::MAX), None, &mut StubSyscallHandler::default(), ) @@ -786,7 +785,7 @@ mod tests { .run( Felt::from(&selector), &[10.into()], - Some(u64::MAX as u128), + Some(u64::MAX), None, &mut StubSyscallHandler::default(), ) @@ -824,7 +823,7 @@ mod tests { .run( Felt::from(&selector), &[], - Some(u64::MAX as u128), + Some(u64::MAX), None, &mut StubSyscallHandler::default(), ) diff --git a/src/executor/jit.rs b/src/executor/jit.rs index 440c95caf..57ae68acc 100644 --- a/src/executor/jit.rs +++ b/src/executor/jit.rs @@ -69,7 +69,7 @@ impl<'m> JitNativeExecutor<'m> { &self, function_id: &FunctionId, args: &[Value], - gas: Option, + gas: Option, ) -> Result { let available_gas = self .gas_metadata @@ -95,7 +95,7 @@ impl<'m> JitNativeExecutor<'m> { &self, function_id: &FunctionId, args: &[Value], - gas: Option, + gas: Option, syscall_handler: impl StarknetSyscallHandler, ) -> Result { let available_gas = self @@ -121,7 +121,7 @@ impl<'m> JitNativeExecutor<'m> { &self, function_id: &FunctionId, args: &[Felt], - gas: Option, + gas: Option, syscall_handler: impl StarknetSyscallHandler, ) -> Result { let available_gas = self diff --git a/src/libfuncs/felt252_dict.rs b/src/libfuncs/felt252_dict.rs index 4fdc609b3..d1d539e41 100644 --- a/src/libfuncs/felt252_dict.rs +++ b/src/libfuncs/felt252_dict.rs @@ -16,7 +16,7 @@ use cairo_lang_sierra::{ }; use melior::{ dialect::arith, - ir::{r#type::IntegerType, Block, Location}, + ir::{Block, Location}, Context, }; @@ -86,11 +86,6 @@ pub fn build_squash<'ctx, 'this>( .dict_gas_refund(context, helper, entry, dict_ptr, location)? .result(0)? .into(); - let gas_refund = entry.append_op_result(arith::extui( - gas_refund, - IntegerType::new(context, 128).into(), - location, - ))?; let new_gas_builtin = entry.append_op_result(arith::addi(gas_builtin, gas_refund, location))?; diff --git a/src/libfuncs/gas.rs b/src/libfuncs/gas.rs index a3d2aea72..9d53e65ed 100644 --- a/src/libfuncs/gas.rs +++ b/src/libfuncs/gas.rs @@ -53,7 +53,7 @@ pub fn build<'ctx, 'this>( /// Generate MLIR operations for the `get_available_gas` libfunc. pub fn build_get_available_gas<'ctx, 'this>( - _context: &'ctx Context, + context: &'ctx Context, _registry: &ProgramRegistry, entry: &'this Block<'ctx>, location: Location<'ctx>, @@ -61,11 +61,14 @@ pub fn build_get_available_gas<'ctx, 'this>( _metadata: &mut MetadataStorage, _info: &SignatureOnlyConcreteLibfunc, ) -> Result<()> { - entry.append_operation(helper.br( - 0, - &[entry.argument(0)?.into(), entry.argument(0)?.into()], + let gas = entry.argument(0)?.into(); + let gas_u128 = entry.append_op_result(arith::extui( + gas, + IntegerType::new(context, 128).into(), location, - )); + ))?; + // The gas is returned as u128 on the second arg. + entry.append_operation(helper.br(0, &[entry.argument(0)?.into(), gas_u128], location)); Ok(()) } @@ -88,7 +91,6 @@ pub fn build_withdraw_gas<'ctx, 'this>( .expect("builtin_withdraw_gas should always have a gas cost") .clone(); - let u128_type: melior::ir::Type = IntegerType::new(context, 128).into(); let u64_type: melior::ir::Type = IntegerType::new(context, 64).into(); let builtin_ptr = { @@ -101,7 +103,7 @@ pub fn build_withdraw_gas<'ctx, 'this>( .into() }; - let mut total_gas_cost_value = entry.const_int_from_type(context, location, 0, u128_type)?; + let mut total_gas_cost_value = entry.const_int_from_type(context, location, 0, u64_type)?; for (cost_count, token_type) in &gas_cost.0 { if *cost_count == 0 { @@ -120,7 +122,7 @@ pub fn build_withdraw_gas<'ctx, 'this>( }; let cost_count_value = - entry.const_int_from_type(context, location, *cost_count, u128_type)?; + entry.const_int_from_type(context, location, *cost_count, u64_type)?; let builtin_costs_index_value = entry.const_int_from_type(context, location, builtin_costs_index, u64_type)?; @@ -132,10 +134,8 @@ pub fn build_withdraw_gas<'ctx, 'this>( u64_type, )?; let cost_value = entry.load(context, location, builtin_cost_value_ptr, u64_type)?; - let cost_value_ext = - entry.append_op_result(arith::extui(cost_value, u128_type, location))?; let gas_cost_value = - entry.append_op_result(arith::muli(cost_count_value, cost_value_ext, location))?; + entry.append_op_result(arith::muli(cost_count_value, cost_value, location))?; total_gas_cost_value = entry.append_op_result(arith::addi(total_gas_cost_value, gas_cost_value, location))?; } @@ -170,7 +170,7 @@ pub fn build_builtin_withdraw_gas<'ctx, 'this>( entry: &'this Block<'ctx>, location: Location<'ctx>, helper: &LibfuncHelper<'ctx, 'this>, - metadata: &MetadataStorage, + metadata: &mut MetadataStorage, _info: &SignatureOnlyConcreteLibfunc, ) -> Result<()> { let range_check = @@ -182,10 +182,9 @@ pub fn build_builtin_withdraw_gas<'ctx, 'this>( .get::() .expect("builtin_withdraw_gas should always have a gas cost"); - let u128_type: melior::ir::Type = IntegerType::new(context, 128).into(); let u64_type: melior::ir::Type = IntegerType::new(context, 64).into(); - let mut total_gas_cost_value = entry.const_int_from_type(context, location, 0, u128_type)?; + let mut total_gas_cost_value = entry.const_int_from_type(context, location, 0, u64_type)?; for (cost_count, token_type) in &gas_cost.0 { if *cost_count == 0 { @@ -204,7 +203,7 @@ pub fn build_builtin_withdraw_gas<'ctx, 'this>( }; let cost_count_value = - entry.const_int_from_type(context, location, *cost_count, u128_type)?; + entry.const_int_from_type(context, location, *cost_count, u64_type)?; let builtin_costs_index_value = entry.const_int_from_type(context, location, builtin_costs_index, u64_type)?; @@ -216,10 +215,8 @@ pub fn build_builtin_withdraw_gas<'ctx, 'this>( u64_type, )?; let cost_value = entry.load(context, location, builtin_cost_value_ptr, u64_type)?; - let cost_value_ext = - entry.append_op_result(arith::extui(cost_value, u128_type, location))?; let gas_cost_value = - entry.append_op_result(arith::muli(cost_count_value, cost_value_ext, location))?; + entry.append_op_result(arith::muli(cost_count_value, cost_value, location))?; total_gas_cost_value = entry.append_op_result(arith::addi(total_gas_cost_value, gas_cost_value, location))?; } @@ -305,9 +302,6 @@ mod test { ); let result = run_program(&program, "run_test", &[]); - assert_eq!( - result.remaining_gas, - Some(340282366920938463463374607431768205035), - ); + assert_eq!(result.remaining_gas, Some(18446744073709545195)); } } diff --git a/src/libfuncs/starknet.rs b/src/libfuncs/starknet.rs index f25dbdede..f90cd05ad 100644 --- a/src/libfuncs/starknet.rs +++ b/src/libfuncs/starknet.rs @@ -201,12 +201,17 @@ pub fn build_call_contract<'ctx, 'this>( )?; // Allocate space and write the current gas. - let gas_builtin_ptr = helper.init_block().alloca1( + let (gas_ty, gas_layout) = registry.build_type_with_layout( context, - location, - IntegerType::new(context, 128).into(), - get_integer_layout(128).align(), + helper, + registry, + metadata, + &info.param_signatures()[0].ty, )?; + let gas_builtin_ptr = + helper + .init_block() + .alloca1(context, location, gas_ty, gas_layout.align())?; entry.append_operation(llvm::store( context, entry.argument(0)?.into(), @@ -342,7 +347,7 @@ pub fn build_call_contract<'ctx, 'this>( context, location, gas_builtin_ptr, - IntegerType::new(context, 128).into(), + IntegerType::new(context, 64).into(), )?; entry.append_operation(helper.cond_br( @@ -560,12 +565,17 @@ pub fn build_storage_read<'ctx, 'this>( )?; // Allocate space and write the current gas. - let gas_builtin_ptr = helper.init_block().alloca1( + let (gas_ty, gas_layout) = registry.build_type_with_layout( context, - location, - IntegerType::new(context, 128).into(), - get_integer_layout(128).align(), + helper, + registry, + metadata, + &info.param_signatures()[0].ty, )?; + let gas_builtin_ptr = + helper + .init_block() + .alloca1(context, location, gas_ty, gas_layout.align())?; entry.store( context, location, @@ -656,12 +666,7 @@ pub fn build_storage_read<'ctx, 'this>( entry.load(context, location, ptr, variant_tys[1].0)? }; - let remaining_gas = entry.load( - context, - location, - gas_builtin_ptr, - IntegerType::new(context, 128).into(), - )?; + let remaining_gas = entry.load(context, location, gas_builtin_ptr, gas_ty)?; entry.append_operation(helper.cond_br( context, @@ -728,12 +733,17 @@ pub fn build_storage_write<'ctx, 'this>( )?; // Allocate space and write the current gas. - let gas_builtin_ptr = helper.init_block().alloca1( + let (gas_ty, gas_layout) = registry.build_type_with_layout( context, - location, - IntegerType::new(context, 128).into(), - get_integer_layout(128).align(), + helper, + registry, + metadata, + &info.param_signatures()[0].ty, )?; + let gas_builtin_ptr = + helper + .init_block() + .alloca1(context, location, gas_ty, gas_layout.align())?; entry.store( context, location, @@ -828,12 +838,7 @@ pub fn build_storage_write<'ctx, 'this>( entry.load(context, location, ptr, variant_tys[1].0)? }; - let remaining_gas = entry.load( - context, - location, - gas_builtin_ptr, - IntegerType::new(context, 128).into(), - )?; + let remaining_gas = entry.load(context, location, gas_builtin_ptr, gas_ty)?; entry.append_operation(helper.cond_br( context, @@ -1053,12 +1058,17 @@ pub fn build_emit_event<'ctx, 'this>( )?; // Allocate space and write the current gas. - let gas_builtin_ptr = helper.init_block().alloca1( + let (gas_ty, gas_layout) = registry.build_type_with_layout( context, - location, - IntegerType::new(context, 128).into(), - get_integer_layout(128).align(), + helper, + registry, + metadata, + &info.param_signatures()[0].ty, )?; + let gas_builtin_ptr = + helper + .init_block() + .alloca1(context, location, gas_ty, gas_layout.align())?; entry.append_operation(llvm::store( context, entry.argument(0)?.into(), @@ -1184,12 +1194,7 @@ pub fn build_emit_event<'ctx, 'this>( entry.load(context, location, ptr, variant_tys[1].0)? }; - let remaining_gas = entry.load( - context, - location, - gas_builtin_ptr, - IntegerType::new(context, 128).into(), - )?; + let remaining_gas = entry.load(context, location, gas_builtin_ptr, gas_ty)?; entry.append_operation(helper.cond_br( context, @@ -1252,12 +1257,17 @@ pub fn build_get_block_hash<'ctx, 'this>( )?; // Allocate space and write the current gas. - let gas_builtin_ptr = helper.init_block().alloca1( + let (gas_ty, gas_layout) = registry.build_type_with_layout( context, - location, - IntegerType::new(context, 128).into(), - get_integer_layout(128).align(), + helper, + registry, + metadata, + &info.param_signatures()[0].ty, )?; + let gas_builtin_ptr = + helper + .init_block() + .alloca1(context, location, gas_ty, gas_layout.align())?; entry.append_operation(llvm::store( context, entry.argument(0)?.into(), @@ -1339,12 +1349,7 @@ pub fn build_get_block_hash<'ctx, 'this>( entry.load(context, location, ptr, variant_tys[1].0)? }; - let remaining_gas = entry.load( - context, - location, - gas_builtin_ptr, - IntegerType::new(context, 128).into(), - )?; + let remaining_gas = entry.load(context, location, gas_builtin_ptr, gas_ty)?; entry.append_operation(helper.cond_br( context, @@ -1407,12 +1412,17 @@ pub fn build_get_execution_info<'ctx, 'this>( )?; // Allocate space and write the current gas. - let gas_builtin_ptr = helper.init_block().alloca1( + let (gas_ty, gas_layout) = registry.build_type_with_layout( context, - location, - IntegerType::new(context, 128).into(), - get_integer_layout(128).align(), + helper, + registry, + metadata, + &info.param_signatures()[0].ty, )?; + let gas_builtin_ptr = + helper + .init_block() + .alloca1(context, location, gas_ty, gas_layout.align())?; entry.store( context, location, @@ -1487,12 +1497,7 @@ pub fn build_get_execution_info<'ctx, 'this>( entry.load(context, location, ptr, variant_tys[1].0)? }; - let remaining_gas = entry.load( - context, - location, - gas_builtin_ptr, - IntegerType::new(context, 128).into(), - )?; + let remaining_gas = entry.load(context, location, gas_builtin_ptr, gas_ty)?; entry.append_operation(helper.cond_br( context, @@ -1555,12 +1560,17 @@ pub fn build_get_execution_info_v2<'ctx, 'this>( )?; // Allocate space and write the current gas. - let gas_builtin_ptr = helper.init_block().alloca1( + let (gas_ty, gas_layout) = registry.build_type_with_layout( context, - location, - IntegerType::new(context, 128).into(), - get_integer_layout(128).align(), + helper, + registry, + metadata, + &info.param_signatures()[0].ty, )?; + let gas_builtin_ptr = + helper + .init_block() + .alloca1(context, location, gas_ty, gas_layout.align())?; entry.store( context, location, @@ -1635,12 +1645,7 @@ pub fn build_get_execution_info_v2<'ctx, 'this>( entry.load(context, location, ptr, variant_tys[1].0)? }; - let remaining_gas = entry.load( - context, - location, - gas_builtin_ptr, - IntegerType::new(context, 128).into(), - )?; + let remaining_gas = entry.load(context, location, gas_builtin_ptr, gas_ty)?; entry.append_operation(helper.cond_br( context, @@ -1746,12 +1751,17 @@ pub fn build_deploy<'ctx, 'this>( )?; // Allocate space and write the current gas. - let gas_builtin_ptr = helper.init_block().alloca1( + let (gas_ty, gas_layout) = registry.build_type_with_layout( context, - location, - IntegerType::new(context, 128).into(), - get_integer_layout(128).align(), + helper, + registry, + metadata, + &info.param_signatures()[0].ty, )?; + let gas_builtin_ptr = + helper + .init_block() + .alloca1(context, location, gas_ty, gas_layout.align())?; entry.store( context, location, @@ -1888,12 +1898,7 @@ pub fn build_deploy<'ctx, 'this>( entry.load(context, location, ptr, variant_tys[1].0)? }; - let remaining_gas = entry.load( - context, - location, - gas_builtin_ptr, - IntegerType::new(context, 128).into(), - )?; + let remaining_gas = entry.load(context, location, gas_builtin_ptr, gas_ty)?; entry.append_operation(helper.cond_br( context, @@ -1973,12 +1978,17 @@ pub fn build_keccak<'ctx, 'this>( )?; // Allocate space and write the current gas. - let gas_builtin_ptr = helper.init_block().alloca1( + let (gas_ty, gas_layout) = registry.build_type_with_layout( context, - location, - IntegerType::new(context, 128).into(), - get_integer_layout(128).align(), + helper, + registry, + metadata, + &info.param_signatures()[0].ty, )?; + let gas_builtin_ptr = + helper + .init_block() + .alloca1(context, location, gas_ty, gas_layout.align())?; entry.store( context, location, @@ -2069,12 +2079,7 @@ pub fn build_keccak<'ctx, 'this>( )?; entry.load(context, location, ptr, variant_tys[1].0)? }; - let remaining_gas = entry.load( - context, - location, - gas_builtin_ptr, - IntegerType::new(context, 128).into(), - )?; + let remaining_gas = entry.load(context, location, gas_builtin_ptr, gas_ty)?; entry.append_operation(helper.cond_br( context, @@ -2137,12 +2142,17 @@ pub fn build_library_call<'ctx, 'this>( )?; // Allocate space and write the current gas. - let gas_builtin_ptr = helper.init_block().alloca1( + let (gas_ty, gas_layout) = registry.build_type_with_layout( context, - location, - IntegerType::new(context, 128).into(), - get_integer_layout(128).align(), + helper, + registry, + metadata, + &info.param_signatures()[0].ty, )?; + let gas_builtin_ptr = + helper + .init_block() + .alloca1(context, location, gas_ty, gas_layout.align())?; entry.store( context, location, @@ -2269,12 +2279,7 @@ pub fn build_library_call<'ctx, 'this>( entry.load(context, location, ptr, variant_tys[1].0)? }; - let remaining_gas = entry.load( - context, - location, - gas_builtin_ptr, - IntegerType::new(context, 128).into(), - )?; + let remaining_gas = entry.load(context, location, gas_builtin_ptr, gas_ty)?; entry.append_operation(helper.cond_br( context, @@ -2341,12 +2346,17 @@ pub fn build_replace_class<'ctx, 'this>( )?; // Allocate space and write the current gas. - let gas_builtin_ptr = helper.init_block().alloca1( + let (gas_ty, gas_layout) = registry.build_type_with_layout( context, - location, - IntegerType::new(context, 128).into(), - get_integer_layout(128).align(), + helper, + registry, + metadata, + &info.param_signatures()[0].ty, )?; + let gas_builtin_ptr = + helper + .init_block() + .alloca1(context, location, gas_ty, gas_layout.align())?; entry.store( context, location, @@ -2429,12 +2439,7 @@ pub fn build_replace_class<'ctx, 'this>( entry.load(context, location, ptr, variant_tys[1].0)? }; - let remaining_gas = entry.load( - context, - location, - gas_builtin_ptr, - IntegerType::new(context, 128).into(), - )?; + let remaining_gas = entry.load(context, location, gas_builtin_ptr, gas_ty)?; entry.append_operation(helper.cond_br( context, @@ -2501,12 +2506,17 @@ pub fn build_send_message_to_l1<'ctx, 'this>( )?; // Allocate space and write the current gas. - let gas_builtin_ptr = helper.init_block().alloca1( + let (gas_ty, gas_layout) = registry.build_type_with_layout( context, - location, - IntegerType::new(context, 128).into(), - get_integer_layout(128).align(), + helper, + registry, + metadata, + &info.param_signatures()[0].ty, )?; + let gas_builtin_ptr = + helper + .init_block() + .alloca1(context, location, gas_ty, gas_layout.align())?; entry.store( context, location, @@ -2619,12 +2629,7 @@ pub fn build_send_message_to_l1<'ctx, 'this>( entry.load(context, location, ptr, variant_tys[1].0)? }; - let remaining_gas = entry.load( - context, - location, - gas_builtin_ptr, - IntegerType::new(context, 128).into(), - )?; + let remaining_gas = entry.load(context, location, gas_builtin_ptr, gas_ty)?; entry.append_operation(helper.cond_br( context, @@ -2731,12 +2736,17 @@ pub fn build_sha256_process_block_syscall<'ctx, 'this>( )?; // Allocate space and write the current gas. - let gas_builtin_ptr = helper.init_block().alloca1( + let (gas_ty, gas_layout) = registry.build_type_with_layout( context, - location, - IntegerType::new(context, 128).into(), - get_integer_layout(128).align(), + helper, + registry, + metadata, + &info.param_signatures()[0].ty, )?; + let gas_builtin_ptr = + helper + .init_block() + .alloca1(context, location, gas_ty, gas_layout.align())?; entry.append_operation(llvm::store( context, entry.argument(0)?.into(), @@ -2811,12 +2821,7 @@ pub fn build_sha256_process_block_syscall<'ctx, 'this>( entry.extract_value(context, location, value, variant_tys[1].0, 1)? }; - let remaining_gas = entry.load( - context, - location, - gas_builtin_ptr, - IntegerType::new(context, 128).into(), - )?; + let remaining_gas = entry.load(context, location, gas_builtin_ptr, gas_ty)?; entry.append_operation(helper.cond_br( context, diff --git a/src/libfuncs/starknet/secp256.rs b/src/libfuncs/starknet/secp256.rs index d13560523..9aa3a1b1e 100644 --- a/src/libfuncs/starknet/secp256.rs +++ b/src/libfuncs/starknet/secp256.rs @@ -124,12 +124,17 @@ pub fn build_k1_new<'ctx, 'this>( )?; // Allocate space and write the current gas. - let gas_builtin_ptr = helper.init_block().alloca1( + let (gas_ty, gas_layout) = registry.build_type_with_layout( context, - location, - IntegerType::new(context, 128).into(), - get_integer_layout(128).align(), + helper, + registry, + metadata, + &info.param_signatures()[0].ty, )?; + let gas_builtin_ptr = + helper + .init_block() + .alloca1(context, location, gas_ty, gas_layout.align())?; entry.append_operation(llvm::store( context, entry.argument(0)?.into(), @@ -264,12 +269,7 @@ pub fn build_k1_new<'ctx, 'this>( entry.load(context, location, ptr, variant_tys[1].0)? }; - let remaining_gas = entry.load( - context, - location, - gas_builtin_ptr, - IntegerType::new(context, 128).into(), - )?; + let remaining_gas = entry.load(context, location, gas_builtin_ptr, gas_ty)?; entry.append_operation(helper.cond_br( context, @@ -336,12 +336,17 @@ pub fn build_k1_add<'ctx, 'this>( )?; // Allocate space and write the current gas. - let gas_builtin_ptr = helper.init_block().alloca1( + let (gas_ty, gas_layout) = registry.build_type_with_layout( context, - location, - IntegerType::new(context, 128).into(), - get_integer_layout(128).align(), + helper, + registry, + metadata, + &info.param_signatures()[0].ty, )?; + let gas_builtin_ptr = + helper + .init_block() + .alloca1(context, location, gas_ty, gas_layout.align())?; entry.append_operation(llvm::store( context, entry.argument(0)?.into(), @@ -477,12 +482,7 @@ pub fn build_k1_add<'ctx, 'this>( entry.load(context, location, ptr, variant_tys[1].0)? }; - let remaining_gas = entry.load( - context, - location, - gas_builtin_ptr, - IntegerType::new(context, 128).into(), - )?; + let remaining_gas = entry.load(context, location, gas_builtin_ptr, gas_ty)?; entry.append_operation(helper.cond_br( context, @@ -549,12 +549,17 @@ pub fn build_k1_mul<'ctx, 'this>( )?; // Allocate space and write the current gas. - let gas_builtin_ptr = helper.init_block().alloca1( + let (gas_ty, gas_layout) = registry.build_type_with_layout( context, - location, - IntegerType::new(context, 128).into(), - get_integer_layout(128).align(), + helper, + registry, + metadata, + &info.param_signatures()[0].ty, )?; + let gas_builtin_ptr = + helper + .init_block() + .alloca1(context, location, gas_ty, gas_layout.align())?; entry.append_operation(llvm::store( context, entry.argument(0)?.into(), @@ -690,12 +695,7 @@ pub fn build_k1_mul<'ctx, 'this>( entry.load(context, location, ptr, variant_tys[1].0)? }; - let remaining_gas = entry.load( - context, - location, - gas_builtin_ptr, - IntegerType::new(context, 128).into(), - )?; + let remaining_gas = entry.load(context, location, gas_builtin_ptr, gas_ty)?; entry.append_operation(helper.cond_br( context, @@ -762,12 +762,17 @@ pub fn build_k1_get_point_from_x<'ctx, 'this>( )?; // Allocate space and write the current gas. - let gas_builtin_ptr = helper.init_block().alloca1( + let (gas_ty, gas_layout) = registry.build_type_with_layout( context, - location, - IntegerType::new(context, 128).into(), - get_integer_layout(128).align(), + helper, + registry, + metadata, + &info.param_signatures()[0].ty, )?; + let gas_builtin_ptr = + helper + .init_block() + .alloca1(context, location, gas_ty, gas_layout.align())?; entry.append_operation(llvm::store( context, entry.argument(0)?.into(), @@ -895,12 +900,7 @@ pub fn build_k1_get_point_from_x<'ctx, 'this>( entry.load(context, location, ptr, variant_tys[1].0)? }; - let remaining_gas = entry.load( - context, - location, - gas_builtin_ptr, - IntegerType::new(context, 128).into(), - )?; + let remaining_gas = entry.load(context, location, gas_builtin_ptr, gas_ty)?; entry.append_operation(helper.cond_br( context, @@ -996,12 +996,17 @@ pub fn build_k1_get_xy<'ctx, 'this>( )?; // Allocate space and write the current gas. - let gas_builtin_ptr = helper.init_block().alloca1( + let (gas_ty, gas_layout) = registry.build_type_with_layout( context, - location, - IntegerType::new(context, 128).into(), - get_integer_layout(128).align(), + helper, + registry, + metadata, + &info.param_signatures()[0].ty, )?; + let gas_builtin_ptr = + helper + .init_block() + .alloca1(context, location, gas_ty, gas_layout.align())?; entry.append_operation(llvm::store( context, entry.argument(0)?.into(), @@ -1142,12 +1147,7 @@ pub fn build_k1_get_xy<'ctx, 'this>( entry.load(context, location, ptr, variant_tys[1].0)? }; - let remaining_gas = entry.load( - context, - location, - gas_builtin_ptr, - IntegerType::new(context, 128).into(), - )?; + let remaining_gas = entry.load(context, location, gas_builtin_ptr, gas_ty)?; entry.append_operation(helper.cond_br( context, @@ -1219,12 +1219,17 @@ pub fn build_r1_new<'ctx, 'this>( )?; // Allocate space and write the current gas. - let gas_builtin_ptr = helper.init_block().alloca1( + let (gas_ty, gas_layout) = registry.build_type_with_layout( context, - location, - IntegerType::new(context, 128).into(), - get_integer_layout(128).align(), + helper, + registry, + metadata, + &info.param_signatures()[0].ty, )?; + let gas_builtin_ptr = + helper + .init_block() + .alloca1(context, location, gas_ty, gas_layout.align())?; entry.append_operation(llvm::store( context, entry.argument(0)?.into(), @@ -1360,12 +1365,7 @@ pub fn build_r1_new<'ctx, 'this>( entry.load(context, location, ptr, variant_tys[1].0)? }; - let remaining_gas = entry.load( - context, - location, - gas_builtin_ptr, - IntegerType::new(context, 128).into(), - )?; + let remaining_gas = entry.load(context, location, gas_builtin_ptr, gas_ty)?; entry.append_operation(helper.cond_br( context, @@ -1432,12 +1432,17 @@ pub fn build_r1_add<'ctx, 'this>( )?; // Allocate space and write the current gas. - let gas_builtin_ptr = helper.init_block().alloca1( + let (gas_ty, gas_layout) = registry.build_type_with_layout( context, - location, - IntegerType::new(context, 128).into(), - get_integer_layout(128).align(), + helper, + registry, + metadata, + &info.param_signatures()[0].ty, )?; + let gas_builtin_ptr = + helper + .init_block() + .alloca1(context, location, gas_ty, gas_layout.align())?; entry.append_operation(llvm::store( context, entry.argument(0)?.into(), @@ -1573,12 +1578,7 @@ pub fn build_r1_add<'ctx, 'this>( entry.load(context, location, ptr, variant_tys[1].0)? }; - let remaining_gas = entry.load( - context, - location, - gas_builtin_ptr, - IntegerType::new(context, 128).into(), - )?; + let remaining_gas = entry.load(context, location, gas_builtin_ptr, gas_ty)?; entry.append_operation(helper.cond_br( context, @@ -1645,12 +1645,17 @@ pub fn build_r1_mul<'ctx, 'this>( )?; // Allocate space and write the current gas. - let gas_builtin_ptr = helper.init_block().alloca1( + let (gas_ty, gas_layout) = registry.build_type_with_layout( context, - location, - IntegerType::new(context, 128).into(), - get_integer_layout(128).align(), + helper, + registry, + metadata, + &info.param_signatures()[0].ty, )?; + let gas_builtin_ptr = + helper + .init_block() + .alloca1(context, location, gas_ty, gas_layout.align())?; entry.append_operation(llvm::store( context, entry.argument(0)?.into(), @@ -1789,12 +1794,7 @@ pub fn build_r1_mul<'ctx, 'this>( entry.load(context, location, ptr, variant_tys[1].0)? }; - let remaining_gas = entry.load( - context, - location, - gas_builtin_ptr, - IntegerType::new(context, 128).into(), - )?; + let remaining_gas = entry.load(context, location, gas_builtin_ptr, gas_ty)?; entry.append_operation(helper.cond_br( context, @@ -1861,12 +1861,17 @@ pub fn build_r1_get_point_from_x<'ctx, 'this>( )?; // Allocate space and write the current gas. - let gas_builtin_ptr = helper.init_block().alloca1( + let (gas_ty, gas_layout) = registry.build_type_with_layout( context, - location, - IntegerType::new(context, 128).into(), - get_integer_layout(128).align(), + helper, + registry, + metadata, + &info.param_signatures()[0].ty, )?; + let gas_builtin_ptr = + helper + .init_block() + .alloca1(context, location, gas_ty, gas_layout.align())?; entry.append_operation(llvm::store( context, entry.argument(0)?.into(), @@ -1995,12 +2000,7 @@ pub fn build_r1_get_point_from_x<'ctx, 'this>( entry.load(context, location, ptr, variant_tys[1].0)? }; - let remaining_gas = entry.load( - context, - location, - gas_builtin_ptr, - IntegerType::new(context, 128).into(), - )?; + let remaining_gas = entry.load(context, location, gas_builtin_ptr, gas_ty)?; entry.append_operation(helper.cond_br( context, @@ -2096,12 +2096,17 @@ pub fn build_r1_get_xy<'ctx, 'this>( )?; // Allocate space and write the current gas. - let gas_builtin_ptr = helper.init_block().alloca1( + let (gas_ty, gas_layout) = registry.build_type_with_layout( context, - location, - IntegerType::new(context, 128).into(), - get_integer_layout(128).align(), + helper, + registry, + metadata, + &info.param_signatures()[0].ty, )?; + let gas_builtin_ptr = + helper + .init_block() + .alloca1(context, location, gas_ty, gas_layout.align())?; entry.append_operation(llvm::store( context, entry.argument(0)?.into(), @@ -2244,12 +2249,7 @@ pub fn build_r1_get_xy<'ctx, 'this>( entry.load(context, location, ptr, variant_tys[1].0)? }; - let remaining_gas = entry.load( - context, - location, - gas_builtin_ptr, - IntegerType::new(context, 128).into(), - )?; + let remaining_gas = entry.load(context, location, gas_builtin_ptr, gas_ty)?; entry.append_operation(helper.cond_br( context, diff --git a/src/metadata/gas.rs b/src/metadata/gas.rs index d368c0c1c..8a1007f3b 100644 --- a/src/metadata/gas.rs +++ b/src/metadata/gas.rs @@ -1,5 +1,3 @@ -use std::collections::BTreeMap; - use cairo_lang_runner::token_gas_cost; use cairo_lang_sierra::{ extensions::gas::CostTokenType, @@ -14,6 +12,7 @@ use cairo_lang_sierra_gas::{ compute_postcost_info, compute_precost_info, gas_info::GasInfo, CostError, }; use cairo_lang_utils::{casts::IntoOrPanic, ordered_hash_map::OrderedHashMap}; +use std::collections::BTreeMap; /// Holds global gas info. #[derive(Debug, Default, PartialEq, Eq)] @@ -24,7 +23,7 @@ pub struct GasMetadata { #[derive(Debug, Clone, PartialEq, Eq, Hash)] // Cost, token type (index into builtin costs). -pub struct GasCost(pub Vec<(u128, CostTokenType)>); +pub struct GasCost(pub Vec<(u64, CostTokenType)>); /// Configuration for metadata computation. #[derive(Debug, Clone)] @@ -43,7 +42,7 @@ pub enum GasMetadataError { #[error(transparent)] CostError(#[from] CostError), #[error("Not enough gas to run the operation. Required: {:?}, Available: {:?}.", gas.0, gas.1)] - NotEnoughGas { gas: Box<(u128, u128)> }, + NotEnoughGas { gas: Box<(u64, u64)> }, } impl Default for MetadataComputationConfig { @@ -73,8 +72,8 @@ impl GasMetadata { pub fn get_initial_available_gas( &self, func: &FunctionId, - available_gas: Option, - ) -> Result { + available_gas: Option, + ) -> Result { let Some(available_gas) = available_gas else { return Ok(0); }; @@ -93,7 +92,7 @@ impl GasMetadata { }) } - pub fn initial_required_gas(&self, func: &FunctionId) -> Option { + pub fn initial_required_gas(&self, func: &FunctionId) -> Option { if self.gas_info.function_costs.is_empty() { return None; } @@ -101,7 +100,7 @@ impl GasMetadata { self.gas_info.function_costs[func] .iter() .map(|(token_type, val)| val.into_or_panic::() * token_gas_cost(*token_type)) - .sum::() as u128, + .sum::() as u64, ) } @@ -133,7 +132,7 @@ impl GasMetadata { .collect() } - pub fn get_gas_costs_for_statement(&self, idx: StatementIdx) -> Vec<(u128, CostTokenType)> { + pub fn get_gas_costs_for_statement(&self, idx: StatementIdx) -> Vec<(u64, CostTokenType)> { let mut costs = Vec::new(); for cost_type in CostTokenType::iter_casm_tokens() { if let Some(cost_count) = @@ -151,15 +150,12 @@ impl GasMetadata { &self, idx: StatementIdx, cost_type: CostTokenType, - ) -> Option { + ) -> Option { self.gas_info .variable_values .get(&(idx, cost_type)) .copied() - .map(|x| { - x.try_into() - .expect("gas cost couldn't be converted to u128, should never happen") - }) + .map(|x| x.try_into().expect("gas cost couldn't be converted to u64")) } } diff --git a/src/starknet.rs b/src/starknet.rs index 5371e0364..58dc42935 100644 --- a/src/starknet.rs +++ b/src/starknet.rs @@ -182,16 +182,12 @@ impl Secp256r1Point { } pub trait StarknetSyscallHandler { - fn get_block_hash( - &mut self, - block_number: u64, - remaining_gas: &mut u128, - ) -> SyscallResult; + fn get_block_hash(&mut self, block_number: u64, remaining_gas: &mut u64) + -> SyscallResult; - fn get_execution_info(&mut self, remaining_gas: &mut u128) -> SyscallResult; + fn get_execution_info(&mut self, remaining_gas: &mut u64) -> SyscallResult; - fn get_execution_info_v2(&mut self, remaining_gas: &mut u128) - -> SyscallResult; + fn get_execution_info_v2(&mut self, remaining_gas: &mut u64) -> SyscallResult; fn deploy( &mut self, @@ -199,16 +195,16 @@ pub trait StarknetSyscallHandler { contract_address_salt: Felt, calldata: &[Felt], deploy_from_zero: bool, - remaining_gas: &mut u128, + remaining_gas: &mut u64, ) -> SyscallResult<(Felt, Vec)>; - fn replace_class(&mut self, class_hash: Felt, remaining_gas: &mut u128) -> SyscallResult<()>; + fn replace_class(&mut self, class_hash: Felt, remaining_gas: &mut u64) -> SyscallResult<()>; fn library_call( &mut self, class_hash: Felt, function_selector: Felt, calldata: &[Felt], - remaining_gas: &mut u128, + remaining_gas: &mut u64, ) -> SyscallResult>; fn call_contract( @@ -216,14 +212,14 @@ pub trait StarknetSyscallHandler { address: Felt, entry_point_selector: Felt, calldata: &[Felt], - remaining_gas: &mut u128, + remaining_gas: &mut u64, ) -> SyscallResult>; fn storage_read( &mut self, address_domain: u32, address: Felt, - remaining_gas: &mut u128, + remaining_gas: &mut u64, ) -> SyscallResult; fn storage_write( @@ -231,98 +227,98 @@ pub trait StarknetSyscallHandler { address_domain: u32, address: Felt, value: Felt, - remaining_gas: &mut u128, + remaining_gas: &mut u64, ) -> SyscallResult<()>; fn emit_event( &mut self, keys: &[Felt], data: &[Felt], - remaining_gas: &mut u128, + remaining_gas: &mut u64, ) -> SyscallResult<()>; fn send_message_to_l1( &mut self, to_address: Felt, payload: &[Felt], - remaining_gas: &mut u128, + remaining_gas: &mut u64, ) -> SyscallResult<()>; - fn keccak(&mut self, input: &[u64], remaining_gas: &mut u128) -> SyscallResult; + fn keccak(&mut self, input: &[u64], remaining_gas: &mut u64) -> SyscallResult; fn secp256k1_new( &mut self, x: U256, y: U256, - remaining_gas: &mut u128, + remaining_gas: &mut u64, ) -> SyscallResult>; fn secp256k1_add( &mut self, p0: Secp256k1Point, p1: Secp256k1Point, - remaining_gas: &mut u128, + remaining_gas: &mut u64, ) -> SyscallResult; fn secp256k1_mul( &mut self, p: Secp256k1Point, m: U256, - remaining_gas: &mut u128, + remaining_gas: &mut u64, ) -> SyscallResult; fn secp256k1_get_point_from_x( &mut self, x: U256, y_parity: bool, - remaining_gas: &mut u128, + remaining_gas: &mut u64, ) -> SyscallResult>; fn secp256k1_get_xy( &mut self, p: Secp256k1Point, - remaining_gas: &mut u128, + remaining_gas: &mut u64, ) -> SyscallResult<(U256, U256)>; fn secp256r1_new( &mut self, x: U256, y: U256, - remaining_gas: &mut u128, + remaining_gas: &mut u64, ) -> SyscallResult>; fn secp256r1_add( &mut self, p0: Secp256r1Point, p1: Secp256r1Point, - remaining_gas: &mut u128, + remaining_gas: &mut u64, ) -> SyscallResult; fn secp256r1_mul( &mut self, p: Secp256r1Point, m: U256, - remaining_gas: &mut u128, + remaining_gas: &mut u64, ) -> SyscallResult; fn secp256r1_get_point_from_x( &mut self, x: U256, y_parity: bool, - remaining_gas: &mut u128, + remaining_gas: &mut u64, ) -> SyscallResult>; fn secp256r1_get_xy( &mut self, p: Secp256r1Point, - remaining_gas: &mut u128, + remaining_gas: &mut u64, ) -> SyscallResult<(U256, U256)>; fn sha256_process_block( &mut self, state: &mut [u32; 8], block: &[u32; 16], - remaining_gas: &mut u128, + remaining_gas: &mut u64, ) -> SyscallResult<()>; #[cfg(feature = "with-cheatcode")] @@ -337,18 +333,18 @@ impl StarknetSyscallHandler for DummySyscallHandler { fn get_block_hash( &mut self, _block_number: u64, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult { unimplemented!() } - fn get_execution_info(&mut self, _remaining_gas: &mut u128) -> SyscallResult { + fn get_execution_info(&mut self, _remaining_gas: &mut u64) -> SyscallResult { unimplemented!() } fn get_execution_info_v2( &mut self, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult { unimplemented!() } @@ -359,12 +355,12 @@ impl StarknetSyscallHandler for DummySyscallHandler { _contract_address_salt: Felt, _calldata: &[Felt], _deploy_from_zero: bool, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult<(Felt, Vec)> { unimplemented!() } - fn replace_class(&mut self, _class_hash: Felt, _remaining_gas: &mut u128) -> SyscallResult<()> { + fn replace_class(&mut self, _class_hash: Felt, _remaining_gas: &mut u64) -> SyscallResult<()> { unimplemented!() } @@ -373,7 +369,7 @@ impl StarknetSyscallHandler for DummySyscallHandler { _class_hash: Felt, _function_selector: Felt, _calldata: &[Felt], - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult> { unimplemented!() } @@ -383,7 +379,7 @@ impl StarknetSyscallHandler for DummySyscallHandler { _address: Felt, _entry_point_selector: Felt, _calldata: &[Felt], - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult> { unimplemented!() } @@ -392,7 +388,7 @@ impl StarknetSyscallHandler for DummySyscallHandler { &mut self, _address_domain: u32, _address: Felt, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult { unimplemented!() } @@ -402,7 +398,7 @@ impl StarknetSyscallHandler for DummySyscallHandler { _address_domain: u32, _address: Felt, _value: Felt, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult<()> { unimplemented!() } @@ -411,7 +407,7 @@ impl StarknetSyscallHandler for DummySyscallHandler { &mut self, _keys: &[Felt], _data: &[Felt], - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult<()> { unimplemented!() } @@ -420,12 +416,12 @@ impl StarknetSyscallHandler for DummySyscallHandler { &mut self, _to_address: Felt, _payload: &[Felt], - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult<()> { unimplemented!() } - fn keccak(&mut self, _input: &[u64], _remaining_gas: &mut u128) -> SyscallResult { + fn keccak(&mut self, _input: &[u64], _remaining_gas: &mut u64) -> SyscallResult { unimplemented!() } @@ -433,7 +429,7 @@ impl StarknetSyscallHandler for DummySyscallHandler { &mut self, _x: U256, _y: U256, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult> { unimplemented!() } @@ -442,7 +438,7 @@ impl StarknetSyscallHandler for DummySyscallHandler { &mut self, _p0: Secp256k1Point, _p1: Secp256k1Point, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult { unimplemented!() } @@ -451,7 +447,7 @@ impl StarknetSyscallHandler for DummySyscallHandler { &mut self, _p: Secp256k1Point, _m: U256, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult { unimplemented!() } @@ -460,7 +456,7 @@ impl StarknetSyscallHandler for DummySyscallHandler { &mut self, _x: U256, _y_parity: bool, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult> { unimplemented!() } @@ -468,7 +464,7 @@ impl StarknetSyscallHandler for DummySyscallHandler { fn secp256k1_get_xy( &mut self, _p: Secp256k1Point, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult<(U256, U256)> { unimplemented!() } @@ -477,7 +473,7 @@ impl StarknetSyscallHandler for DummySyscallHandler { &mut self, _x: U256, _y: U256, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult> { unimplemented!() } @@ -486,7 +482,7 @@ impl StarknetSyscallHandler for DummySyscallHandler { &mut self, _p0: Secp256r1Point, _p1: Secp256r1Point, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult { unimplemented!() } @@ -495,7 +491,7 @@ impl StarknetSyscallHandler for DummySyscallHandler { &mut self, _p: Secp256r1Point, _m: U256, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult { unimplemented!() } @@ -504,7 +500,7 @@ impl StarknetSyscallHandler for DummySyscallHandler { &mut self, _x: U256, _y_parity: bool, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult> { unimplemented!() } @@ -512,7 +508,7 @@ impl StarknetSyscallHandler for DummySyscallHandler { fn secp256r1_get_xy( &mut self, _p: Secp256r1Point, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult<(U256, U256)> { unimplemented!() } @@ -521,7 +517,7 @@ impl StarknetSyscallHandler for DummySyscallHandler { &mut self, _state: &mut [u32; 8], _block: &[u32; 16], - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult<()> { unimplemented!() } @@ -645,23 +641,23 @@ pub(crate) mod handler { get_block_hash: extern "C" fn( result_ptr: &mut SyscallResultAbi, ptr: &mut T, - gas: &mut u128, + gas: &mut u64, block_number: u64, ), get_execution_info: extern "C" fn( result_ptr: &mut SyscallResultAbi>, ptr: &mut T, - gas: &mut u128, + gas: &mut u64, ), get_execution_info_v2: extern "C" fn( result_ptr: &mut SyscallResultAbi>, ptr: &mut T, - gas: &mut u128, + gas: &mut u64, ), deploy: extern "C" fn( result_ptr: &mut SyscallResultAbi<(Felt252Abi, ArrayAbi)>, ptr: &mut T, - gas: &mut u128, + gas: &mut u64, class_hash: &Felt252Abi, contract_address_salt: &Felt252Abi, calldata: &ArrayAbi, @@ -670,13 +666,13 @@ pub(crate) mod handler { replace_class: extern "C" fn( result_ptr: &mut SyscallResultAbi<()>, ptr: &mut T, - _gas: &mut u128, + _gas: &mut u64, class_hash: &Felt252Abi, ), library_call: extern "C" fn( result_ptr: &mut SyscallResultAbi>, ptr: &mut T, - gas: &mut u128, + gas: &mut u64, class_hash: &Felt252Abi, function_selector: &Felt252Abi, calldata: &ArrayAbi, @@ -684,7 +680,7 @@ pub(crate) mod handler { call_contract: extern "C" fn( result_ptr: &mut SyscallResultAbi>, ptr: &mut T, - gas: &mut u128, + gas: &mut u64, address: &Felt252Abi, entry_point_selector: &Felt252Abi, calldata: &ArrayAbi, @@ -692,14 +688,14 @@ pub(crate) mod handler { storage_read: extern "C" fn( result_ptr: &mut SyscallResultAbi, ptr: &mut T, - gas: &mut u128, + gas: &mut u64, address_domain: u32, address: &Felt252Abi, ), storage_write: extern "C" fn( result_ptr: &mut SyscallResultAbi<()>, ptr: &mut T, - gas: &mut u128, + gas: &mut u64, address_domain: u32, address: &Felt252Abi, value: &Felt252Abi, @@ -707,97 +703,97 @@ pub(crate) mod handler { emit_event: extern "C" fn( result_ptr: &mut SyscallResultAbi<()>, ptr: &mut T, - gas: &mut u128, + gas: &mut u64, keys: &ArrayAbi, data: &ArrayAbi, ), send_message_to_l1: extern "C" fn( result_ptr: &mut SyscallResultAbi<()>, ptr: &mut T, - gas: &mut u128, + gas: &mut u64, to_address: &Felt252Abi, data: &ArrayAbi, ), keccak: extern "C" fn( result_ptr: &mut SyscallResultAbi, ptr: &mut T, - gas: &mut u128, + gas: &mut u64, input: &ArrayAbi, ), secp256k1_new: extern "C" fn( result_ptr: &mut SyscallResultAbi<(u8, MaybeUninit)>, ptr: &mut T, - gas: &mut u128, + gas: &mut u64, x: &U256, y: &U256, ), secp256k1_add: extern "C" fn( result_ptr: &mut SyscallResultAbi, ptr: &mut T, - gas: &mut u128, + gas: &mut u64, p0: &Secp256k1Point, p1: &Secp256k1Point, ), secp256k1_mul: extern "C" fn( result_ptr: &mut SyscallResultAbi, ptr: &mut T, - gas: &mut u128, + gas: &mut u64, p: &Secp256k1Point, scalar: &U256, ), secp256k1_get_point_from_x: extern "C" fn( result_ptr: &mut SyscallResultAbi<(u8, MaybeUninit)>, ptr: &mut T, - gas: &mut u128, + gas: &mut u64, x: &U256, y_parity: &bool, ), secp256k1_get_xy: extern "C" fn( result_ptr: &mut SyscallResultAbi<(U256, U256)>, ptr: &mut T, - gas: &mut u128, + gas: &mut u64, p: &Secp256k1Point, ), secp256r1_new: extern "C" fn( result_ptr: &mut SyscallResultAbi<(u8, MaybeUninit)>, ptr: &mut T, - gas: &mut u128, + gas: &mut u64, x: &U256, y: &U256, ), secp256r1_add: extern "C" fn( result_ptr: &mut SyscallResultAbi, ptr: &mut T, - gas: &mut u128, + gas: &mut u64, p0: &Secp256r1Point, p1: &Secp256r1Point, ), secp256r1_mul: extern "C" fn( result_ptr: &mut SyscallResultAbi, ptr: &mut T, - gas: &mut u128, + gas: &mut u64, p: &Secp256r1Point, scalar: &U256, ), secp256r1_get_point_from_x: extern "C" fn( result_ptr: &mut SyscallResultAbi<(u8, MaybeUninit)>, ptr: &mut T, - gas: &mut u128, + gas: &mut u64, x: &U256, y_parity: &bool, ), secp256r1_get_xy: extern "C" fn( result_ptr: &mut SyscallResultAbi<(U256, U256)>, ptr: &mut T, - gas: &mut u128, + gas: &mut u64, p: &Secp256r1Point, ), sha256_process_block: extern "C" fn( result_ptr: &mut SyscallResultAbi<*mut [u32; 8]>, ptr: &mut T, - gas: &mut u128, + gas: &mut u64, state: *mut [u32; 8], block: &[u32; 16], ), @@ -921,7 +917,7 @@ pub(crate) mod handler { extern "C" fn wrap_get_block_hash( result_ptr: &mut SyscallResultAbi, ptr: &mut T, - gas: &mut u128, + gas: &mut u64, block_number: u64, ) { let result = ptr.get_block_hash(block_number, gas); @@ -963,7 +959,7 @@ pub(crate) mod handler { extern "C" fn wrap_get_execution_info( result_ptr: &mut SyscallResultAbi>, ptr: &mut T, - gas: &mut u128, + gas: &mut u64, ) { let result = ptr.get_execution_info(gas); @@ -1027,7 +1023,7 @@ pub(crate) mod handler { extern "C" fn wrap_get_execution_info_v2( result_ptr: &mut SyscallResultAbi>, ptr: &mut T, - gas: &mut u128, + gas: &mut u64, ) { let result = ptr.get_execution_info_v2(gas); @@ -1125,7 +1121,7 @@ pub(crate) mod handler { extern "C" fn wrap_deploy( result_ptr: &mut SyscallResultAbi<(Felt252Abi, ArrayAbi)>, ptr: &mut T, - gas: &mut u128, + gas: &mut u64, class_hash: &Felt252Abi, contract_address_salt: &Felt252Abi, calldata: &ArrayAbi, @@ -1166,7 +1162,7 @@ pub(crate) mod handler { extern "C" fn wrap_replace_class( result_ptr: &mut SyscallResultAbi<()>, ptr: &mut T, - gas: &mut u128, + gas: &mut u64, class_hash: &Felt252Abi, ) { let class_hash = Felt::from(class_hash); @@ -1186,7 +1182,7 @@ pub(crate) mod handler { extern "C" fn wrap_library_call( result_ptr: &mut SyscallResultAbi>, ptr: &mut T, - gas: &mut u128, + gas: &mut u64, class_hash: &Felt252Abi, function_selector: &Felt252Abi, calldata: &ArrayAbi, @@ -1220,7 +1216,7 @@ pub(crate) mod handler { extern "C" fn wrap_call_contract( result_ptr: &mut SyscallResultAbi>, ptr: &mut T, - gas: &mut u128, + gas: &mut u64, address: &Felt252Abi, entry_point_selector: &Felt252Abi, calldata: &ArrayAbi, @@ -1254,7 +1250,7 @@ pub(crate) mod handler { extern "C" fn wrap_storage_read( result_ptr: &mut SyscallResultAbi, ptr: &mut T, - gas: &mut u128, + gas: &mut u64, address_domain: u32, address: &Felt252Abi, ) { @@ -1275,7 +1271,7 @@ pub(crate) mod handler { extern "C" fn wrap_storage_write( result_ptr: &mut SyscallResultAbi<()>, ptr: &mut T, - gas: &mut u128, + gas: &mut u64, address_domain: u32, address: &Felt252Abi, value: &Felt252Abi, @@ -1298,7 +1294,7 @@ pub(crate) mod handler { extern "C" fn wrap_emit_event( result_ptr: &mut SyscallResultAbi<()>, ptr: &mut T, - gas: &mut u128, + gas: &mut u64, keys: &ArrayAbi, data: &ArrayAbi, ) { @@ -1330,7 +1326,7 @@ pub(crate) mod handler { extern "C" fn wrap_send_message_to_l1( result_ptr: &mut SyscallResultAbi<()>, ptr: &mut T, - gas: &mut u128, + gas: &mut u64, to_address: &Felt252Abi, payload: &ArrayAbi, ) { @@ -1357,7 +1353,7 @@ pub(crate) mod handler { extern "C" fn wrap_keccak( result_ptr: &mut SyscallResultAbi, ptr: &mut T, - gas: &mut u128, + gas: &mut u64, input: &ArrayAbi, ) { let input_vec = unsafe { @@ -1390,7 +1386,7 @@ pub(crate) mod handler { extern "C" fn wrap_secp256k1_new( result_ptr: &mut SyscallResultAbi<(u8, MaybeUninit)>, ptr: &mut T, - gas: &mut u128, + gas: &mut u64, x: &U256, y: &U256, ) { @@ -1415,7 +1411,7 @@ pub(crate) mod handler { extern "C" fn wrap_secp256k1_add( result_ptr: &mut SyscallResultAbi, ptr: &mut T, - gas: &mut u128, + gas: &mut u64, p0: &Secp256k1Point, p1: &Secp256k1Point, ) { @@ -1437,7 +1433,7 @@ pub(crate) mod handler { extern "C" fn wrap_secp256k1_mul( result_ptr: &mut SyscallResultAbi, ptr: &mut T, - gas: &mut u128, + gas: &mut u64, p: &Secp256k1Point, scalar: &U256, ) { @@ -1460,7 +1456,7 @@ pub(crate) mod handler { extern "C" fn wrap_secp256k1_get_point_from_x( result_ptr: &mut SyscallResultAbi<(u8, MaybeUninit)>, ptr: &mut T, - gas: &mut u128, + gas: &mut u64, x: &U256, y_parity: &bool, ) { @@ -1485,7 +1481,7 @@ pub(crate) mod handler { extern "C" fn wrap_secp256k1_get_xy( result_ptr: &mut SyscallResultAbi<(U256, U256)>, ptr: &mut T, - gas: &mut u128, + gas: &mut u64, p: &Secp256k1Point, ) { let p = *p; @@ -1505,7 +1501,7 @@ pub(crate) mod handler { extern "C" fn wrap_secp256r1_new( result_ptr: &mut SyscallResultAbi<(u8, MaybeUninit)>, ptr: &mut T, - gas: &mut u128, + gas: &mut u64, x: &U256, y: &U256, ) { @@ -1530,7 +1526,7 @@ pub(crate) mod handler { extern "C" fn wrap_secp256r1_add( result_ptr: &mut SyscallResultAbi, ptr: &mut T, - gas: &mut u128, + gas: &mut u64, p0: &Secp256r1Point, p1: &Secp256r1Point, ) { @@ -1552,7 +1548,7 @@ pub(crate) mod handler { extern "C" fn wrap_secp256r1_mul( result_ptr: &mut SyscallResultAbi, ptr: &mut T, - gas: &mut u128, + gas: &mut u64, p: &Secp256r1Point, scalar: &U256, ) { @@ -1574,7 +1570,7 @@ pub(crate) mod handler { extern "C" fn wrap_secp256r1_get_point_from_x( result_ptr: &mut SyscallResultAbi<(u8, MaybeUninit)>, ptr: &mut T, - gas: &mut u128, + gas: &mut u64, x: &U256, y_parity: &bool, ) { @@ -1599,7 +1595,7 @@ pub(crate) mod handler { extern "C" fn wrap_secp256r1_get_xy( result_ptr: &mut SyscallResultAbi<(U256, U256)>, ptr: &mut T, - gas: &mut u128, + gas: &mut u64, p: &Secp256r1Point, ) { let p = *p; @@ -1619,7 +1615,7 @@ pub(crate) mod handler { extern "C" fn wrap_sha256_process_block( result_ptr: &mut SyscallResultAbi<*mut [u32; 8]>, ptr: &mut T, - gas: &mut u128, + gas: &mut u64, state: *mut [u32; 8], block: &[u32; 16], ) { diff --git a/src/starknet_stub.rs b/src/starknet_stub.rs index bf25d22c1..228dc722b 100644 --- a/src/starknet_stub.rs +++ b/src/starknet_stub.rs @@ -268,7 +268,7 @@ impl StarknetSyscallHandler for &mut StubSyscallHandler { fn get_block_hash( &mut self, block_number: u64, - remaining_gas: &mut u128, + remaining_gas: &mut u64, ) -> crate::starknet::SyscallResult { tracing::debug!("called"); Ok(block_number.into()) @@ -277,7 +277,7 @@ impl StarknetSyscallHandler for &mut StubSyscallHandler { #[instrument(skip(self))] fn get_execution_info( &mut self, - remaining_gas: &mut u128, + remaining_gas: &mut u64, ) -> crate::starknet::SyscallResult { tracing::debug!("called"); Ok(ExecutionInfo { @@ -300,7 +300,7 @@ impl StarknetSyscallHandler for &mut StubSyscallHandler { #[instrument(skip(self))] fn get_execution_info_v2( &mut self, - remaining_gas: &mut u128, + remaining_gas: &mut u64, ) -> crate::starknet::SyscallResult { tracing::debug!("called"); Ok(self.execution_info.clone()) @@ -313,7 +313,7 @@ impl StarknetSyscallHandler for &mut StubSyscallHandler { contract_address_salt: Felt, calldata: &[Felt], deploy_from_zero: bool, - remaining_gas: &mut u128, + remaining_gas: &mut u64, ) -> crate::starknet::SyscallResult<(Felt, Vec)> { tracing::debug!("called"); todo!() @@ -323,7 +323,7 @@ impl StarknetSyscallHandler for &mut StubSyscallHandler { fn replace_class( &mut self, class_hash: Felt, - remaining_gas: &mut u128, + remaining_gas: &mut u64, ) -> crate::starknet::SyscallResult<()> { tracing::debug!("called"); tracing::warn!("unimplemented"); @@ -336,7 +336,7 @@ impl StarknetSyscallHandler for &mut StubSyscallHandler { class_hash: Felt, function_selector: Felt, calldata: &[Felt], - remaining_gas: &mut u128, + remaining_gas: &mut u64, ) -> crate::starknet::SyscallResult> { tracing::debug!("called"); tracing::warn!("unimplemented"); @@ -349,7 +349,7 @@ impl StarknetSyscallHandler for &mut StubSyscallHandler { address: Felt, entry_point_selector: Felt, calldata: &[Felt], - remaining_gas: &mut u128, + remaining_gas: &mut u64, ) -> crate::starknet::SyscallResult> { tracing::debug!("called"); tracing::warn!("unimplemented"); @@ -360,7 +360,7 @@ impl StarknetSyscallHandler for &mut StubSyscallHandler { &mut self, address_domain: u32, address: Felt, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> crate::starknet::SyscallResult { tracing::debug!("called"); if let Some(value) = self.storage.get(&(address_domain, address)) { @@ -376,7 +376,7 @@ impl StarknetSyscallHandler for &mut StubSyscallHandler { address_domain: u32, address: Felt, value: Felt, - remaining_gas: &mut u128, + remaining_gas: &mut u64, ) -> crate::starknet::SyscallResult<()> { tracing::debug!("called"); self.storage.insert((address_domain, address), value); @@ -388,7 +388,7 @@ impl StarknetSyscallHandler for &mut StubSyscallHandler { &mut self, keys: &[Felt], data: &[Felt], - remaining_gas: &mut u128, + remaining_gas: &mut u64, ) -> crate::starknet::SyscallResult<()> { tracing::debug!("called"); tracing::warn!("unimplemented but stored"); @@ -404,7 +404,7 @@ impl StarknetSyscallHandler for &mut StubSyscallHandler { &mut self, to_address: Felt, payload: &[Felt], - remaining_gas: &mut u128, + remaining_gas: &mut u64, ) -> crate::starknet::SyscallResult<()> { tracing::debug!("called"); tracing::warn!("unimplemented"); @@ -412,7 +412,7 @@ impl StarknetSyscallHandler for &mut StubSyscallHandler { } #[instrument(skip(self))] - fn keccak(&mut self, input: &[u64], gas: &mut u128) -> SyscallResult { + fn keccak(&mut self, input: &[u64], gas: &mut u64) -> SyscallResult { const KECCAK_FULL_RATE_IN_WORDS: usize = 17; let length = input.len(); @@ -445,7 +445,7 @@ impl StarknetSyscallHandler for &mut StubSyscallHandler { &mut self, x: U256, y: U256, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult> { Secp256Point::new(x, y).map(|op| op.map(|p| p.into())) } @@ -455,7 +455,7 @@ impl StarknetSyscallHandler for &mut StubSyscallHandler { &mut self, p0: Secp256k1Point, p1: Secp256k1Point, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult { tracing::debug!("called"); @@ -467,7 +467,7 @@ impl StarknetSyscallHandler for &mut StubSyscallHandler { &mut self, p: Secp256k1Point, m: U256, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult { Ok(Secp256Point::mul(p.into(), m).into()) } @@ -477,7 +477,7 @@ impl StarknetSyscallHandler for &mut StubSyscallHandler { &mut self, x: U256, y_parity: bool, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult> { Secp256Point::get_point_from_x(x, y_parity).map(|op| op.map(|p| p.into())) } @@ -486,7 +486,7 @@ impl StarknetSyscallHandler for &mut StubSyscallHandler { fn secp256k1_get_xy( &mut self, p: Secp256k1Point, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult<(U256, U256)> { Ok((p.x, p.y)) } @@ -496,7 +496,7 @@ impl StarknetSyscallHandler for &mut StubSyscallHandler { &mut self, x: U256, y: U256, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult> { Secp256Point::new(x, y).map(|op| op.map(|p| p.into())) } @@ -506,7 +506,7 @@ impl StarknetSyscallHandler for &mut StubSyscallHandler { &mut self, p0: Secp256r1Point, p1: Secp256r1Point, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult { Ok(Secp256Point::add(p0.into(), p1.into()).into()) } @@ -516,7 +516,7 @@ impl StarknetSyscallHandler for &mut StubSyscallHandler { &mut self, p: Secp256r1Point, m: U256, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult { Ok(Secp256Point::mul(p.into(), m).into()) } @@ -526,7 +526,7 @@ impl StarknetSyscallHandler for &mut StubSyscallHandler { &mut self, x: U256, y_parity: bool, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult> { Secp256Point::get_point_from_x(x, y_parity).map(|op| op.map(|p| p.into())) } @@ -535,7 +535,7 @@ impl StarknetSyscallHandler for &mut StubSyscallHandler { fn secp256r1_get_xy( &mut self, p: Secp256r1Point, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult<(U256, U256)> { Ok((p.x, p.y)) } @@ -636,7 +636,7 @@ impl StarknetSyscallHandler for &mut StubSyscallHandler { &mut self, state: &mut [u32; 8], block: &[u32; 16], - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult<()> { // reference impl // https://github.com/starkware-libs/cairo/blob/ba3f82b4a09972b6a24bf791e344cabce579bf69/crates/cairo-lang-runner/src/casm_run/mod.rs#L1292 diff --git a/src/types.rs b/src/types.rs index e7da3200b..3878d8400 100644 --- a/src/types.rs +++ b/src/types.rs @@ -460,7 +460,7 @@ impl TypeBuilder for CoreTypeConcrete { // Builtins. CoreTypeConcrete::Bitwise(_) | CoreTypeConcrete::EcOp(_) - | CoreTypeConcrete::GasBuiltin(_) // u128 is not complex + | CoreTypeConcrete::GasBuiltin(_) | CoreTypeConcrete::BuiltinCosts(_) | CoreTypeConcrete::RangeCheck(_) | CoreTypeConcrete::Pedersen(_) @@ -636,7 +636,7 @@ impl TypeBuilder for CoreTypeConcrete { CoreTypeConcrete::EcPoint(_) => layout_repeat(&get_integer_layout(252), 2)?.0, CoreTypeConcrete::EcState(_) => layout_repeat(&get_integer_layout(252), 4)?.0, CoreTypeConcrete::Felt252(_) => get_integer_layout(252), - CoreTypeConcrete::GasBuiltin(_) => get_integer_layout(128), + CoreTypeConcrete::GasBuiltin(_) => get_integer_layout(64), CoreTypeConcrete::BuiltinCosts(_) => Layout::new::<*const ()>(), CoreTypeConcrete::Uint8(_) => get_integer_layout(8), CoreTypeConcrete::Uint16(_) => get_integer_layout(16), diff --git a/src/types/gas_builtin.rs b/src/types/gas_builtin.rs index b7a73053f..286104d59 100644 --- a/src/types/gas_builtin.rs +++ b/src/types/gas_builtin.rs @@ -27,5 +27,5 @@ pub fn build<'ctx>( _metadata: &mut MetadataStorage, _info: WithSelf, ) -> Result> { - Ok(IntegerType::new(context, 128).into()) + Ok(IntegerType::new(context, 64).into()) } diff --git a/src/utils.rs b/src/utils.rs index a2cfc77a3..172f777a5 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -711,7 +711,7 @@ pub mod test { .invoke_dynamic_with_syscall_handler( entry_point_id, args, - Some(u128::MAX), + Some(u64::MAX), &mut StubSyscallHandler::default(), ) .unwrap() diff --git a/tests/common.rs b/tests/common.rs index d2231ed4b..76398da67 100644 --- a/tests/common.rs +++ b/tests/common.rs @@ -211,7 +211,7 @@ pub fn run_native_program( program: &(String, Program, SierraCasmRunner), entry_point: &str, args: &[Value], - gas: Option, + gas: Option, syscall_handler: Option, ) -> ExecutionResult { let entry_point = format!("{0}::{0}::{1}", program.0, entry_point); @@ -400,7 +400,7 @@ pub fn compare_inputless_program(program_path: &str) { program, "main", &[], - Some(DEFAULT_GAS as u128), + Some(DEFAULT_GAS), Option::::None, ); @@ -429,7 +429,7 @@ pub fn run_native_starknet_contract( let native_executor = AotNativeExecutor::from_native_module(native_program, Default::default()); native_executor - .invoke_contract_dynamic(entry_point_id, args, u128::MAX.into(), handler) + .invoke_contract_dynamic(entry_point_id, args, u64::MAX.into(), handler) .expect("failed to execute the given contract") } @@ -446,7 +446,7 @@ pub fn run_native_starknet_aot_contract( ) .unwrap(); native_executor - .run(Felt::from(selector), args, u128::MAX.into(), None, handler) + .run(Felt::from(selector), args, u64::MAX.into(), None, handler) .expect("failed to execute the given contract") } diff --git a/tests/tests/alexandria.rs b/tests/tests/alexandria.rs index ae4c4009e..36eef40dd 100644 --- a/tests/tests/alexandria.rs +++ b/tests/tests/alexandria.rs @@ -29,7 +29,7 @@ fn compare_inputless_function(function_name: &str) { program, function_name, &[], - Some(DEFAULT_GAS as u128), + Some(DEFAULT_GAS), Option::::None, ); diff --git a/tests/tests/arrays.rs b/tests/tests/arrays.rs index 980dacbc6..768e3ee18 100644 --- a/tests/tests/arrays.rs +++ b/tests/tests/arrays.rs @@ -63,7 +63,7 @@ fn array_get_test() { program, "run_test", &[Value::Felt252(10.into()), Value::Felt252(5.into())], - Some(DEFAULT_GAS as u128), + Some(DEFAULT_GAS), Option::::None, ); @@ -88,7 +88,7 @@ proptest! { program, "run_test", &[Value::Felt252(value), Value::Felt252(idx.into())], - Some(DEFAULT_GAS as u128), + Some(DEFAULT_GAS), Option::::None, ); diff --git a/tests/tests/boolean.rs b/tests/tests/boolean.rs index 7e14f919f..679f8e527 100644 --- a/tests/tests/boolean.rs +++ b/tests/tests/boolean.rs @@ -121,7 +121,7 @@ fn felt252_to_bool_bug() { program, "run_test", &[Value::Felt252(a.into())], - Some(DEFAULT_GAS as u128), + Some(DEFAULT_GAS), Option::::None, ); @@ -145,7 +145,7 @@ fn felt252_to_bool_bug() { program, "run_test", &[Value::Felt252(a.into())], - Some(DEFAULT_GAS as u128), + Some(DEFAULT_GAS), Option::::None, ); @@ -169,7 +169,7 @@ proptest! { program, "run_test", &[Value::Felt252(a.into())], - Some(DEFAULT_GAS as u128), + Some(DEFAULT_GAS), Option::::None, ); @@ -192,7 +192,7 @@ proptest! { program, "run_test", &[Value::Felt252(a.into())], - Some(DEFAULT_GAS as u128), + Some(DEFAULT_GAS), Option::::None, ); @@ -216,7 +216,7 @@ proptest! { program, "run_test", &[Value::Felt252(a.into()), Value::Felt252(b.into())], - Some(DEFAULT_GAS as u128), + Some(DEFAULT_GAS), Option::::None, ); @@ -240,7 +240,7 @@ proptest! { program, "run_test", &[Value::Felt252(a.into()), Value::Felt252(b.into())], - Some(DEFAULT_GAS as u128), + Some(DEFAULT_GAS), Option::::None, ); @@ -264,7 +264,7 @@ proptest! { program, "run_test", &[Value::Felt252(a.into()), Value::Felt252(b.into())], - Some(DEFAULT_GAS as u128), + Some(DEFAULT_GAS), Option::::None, ); diff --git a/tests/tests/dict.rs b/tests/tests/dict.rs index 5017b27a9..1be5b1cd6 100644 --- a/tests/tests/dict.rs +++ b/tests/tests/dict.rs @@ -36,7 +36,7 @@ proptest! { program, "run_test", &[Value::Felt252(a), Value::Felt252(b)], - Some(DEFAULT_GAS as u128), + Some(DEFAULT_GAS), Option::::None, ); diff --git a/tests/tests/ec.rs b/tests/tests/ec.rs index c1160bd49..c13e2c944 100644 --- a/tests/tests/ec.rs +++ b/tests/tests/ec.rs @@ -44,7 +44,7 @@ fn ec_point_zero() { program, "run_test", &[], - Some(DEFAULT_GAS as u128), + Some(DEFAULT_GAS), Option::::None, ); @@ -77,7 +77,7 @@ fn ec_point_from_x_big() { program, "run_test", &[Value::Felt252(Felt::from_bytes_be(&x.to_bytes_be()))], - Some(DEFAULT_GAS as u128), + Some(DEFAULT_GAS), Option::::None, ); @@ -105,7 +105,7 @@ fn ec_point_from_x_small() { program, "run_test", &[Value::Felt252(Felt::from_bytes_be(&x.to_bytes_be()))], - Some(DEFAULT_GAS as u128), + Some(DEFAULT_GAS), Option::::None, ); @@ -133,7 +133,7 @@ proptest! { program, "run_test", &[Value::Felt252(a), Value::Felt252(b)], - Some(DEFAULT_GAS as u128), + Some(DEFAULT_GAS), Option::::None, ); @@ -159,7 +159,7 @@ proptest! { program, "run_test", &[Value::Felt252(a)], - Some(DEFAULT_GAS as u128), + Some(DEFAULT_GAS), Option::::None, ); diff --git a/tests/tests/felt252.rs b/tests/tests/felt252.rs index 7654560f4..9449fd549 100644 --- a/tests/tests/felt252.rs +++ b/tests/tests/felt252.rs @@ -71,7 +71,7 @@ proptest! { program, "run_test", &[Value::Felt252(a), Value::Felt252(b)], - Some(DEFAULT_GAS as u128), + Some(DEFAULT_GAS), Option::::None, ); @@ -97,7 +97,7 @@ proptest! { program, "run_test", &[Value::Felt252(a), Value::Felt252(b)], - Some(DEFAULT_GAS as u128), + Some(DEFAULT_GAS), Option::::None, ); @@ -123,7 +123,7 @@ proptest! { program, "run_test", &[Value::Felt252(a), Value::Felt252(b)], - Some(DEFAULT_GAS as u128), + Some(DEFAULT_GAS), Option::::None, ); @@ -149,7 +149,7 @@ proptest! { program, "run_test", &[Value::Felt252(a), Value::Felt252(b)], - Some(DEFAULT_GAS as u128), + Some(DEFAULT_GAS), Option::::None, ); diff --git a/tests/tests/programs.rs b/tests/tests/programs.rs index be558a272..96c7e6517 100644 --- a/tests/tests/programs.rs +++ b/tests/tests/programs.rs @@ -126,7 +126,7 @@ fn fib() { &FIB, "run_test", &[Value::Felt252(10.into())], - Some(DEFAULT_GAS as u128), + Some(DEFAULT_GAS), Option::::None, ); @@ -152,7 +152,7 @@ fn logistic_map() { &LOGISTIC_MAP, "run_test", &[Value::Felt252(1000.into())], - Some(DEFAULT_GAS as u128), + Some(DEFAULT_GAS), Option::::None, ); @@ -198,7 +198,7 @@ fn pedersen() { "2392090257937917229310563411601744459500735555884672871108624696010915493156", )), ], - Some(DEFAULT_GAS as u128), + Some(DEFAULT_GAS), Option::::None, ); @@ -224,7 +224,7 @@ fn factorial() { &FACTORIAL, "run_test", &[Value::Felt252(13.into())], - Some(DEFAULT_GAS as u128), + Some(DEFAULT_GAS), Option::::None, ); @@ -251,7 +251,7 @@ proptest! { &FIB, "run_test", &[Value::Felt252(n.into())], - Some(DEFAULT_GAS as u128), + Some(DEFAULT_GAS), Option::::None, ); @@ -276,7 +276,7 @@ proptest! { &LOGISTIC_MAP, "run_test", &[Value::Felt252(n.into())], - Some(DEFAULT_GAS as u128), + Some(DEFAULT_GAS), Option::::None, ); @@ -301,7 +301,7 @@ proptest! { &FACTORIAL, "run_test", &[Value::Felt252(n.into())], - Some(DEFAULT_GAS as u128), + Some(DEFAULT_GAS), Option::::None, ); @@ -327,7 +327,7 @@ proptest! { &PEDERSEN, "run_test", &[Value::Felt252(a), Value::Felt252(b)], - Some(DEFAULT_GAS as u128), + Some(DEFAULT_GAS), Option::::None, ); @@ -355,7 +355,7 @@ proptest! { &POSEIDON, "run_test", &[Value::Felt252(a), Value::Felt252(b), Value::Felt252(c)], - Some(DEFAULT_GAS as u128), + Some(DEFAULT_GAS), Option::::None, ); @@ -381,7 +381,7 @@ fn self_referencing_struct() { &SELF_REFERENCING, "run_test", &[], - Some(DEFAULT_GAS as u128), + Some(DEFAULT_GAS), Option::::None, ); @@ -401,7 +401,7 @@ fn no_op() { &NO_OP, "run_test", &[], - Some(DEFAULT_GAS as u128), + Some(DEFAULT_GAS), Option::::None, ); diff --git a/tests/tests/starknet/keccak.rs b/tests/tests/starknet/keccak.rs index a2365ab8c..9de56a5f8 100644 --- a/tests/tests/starknet/keccak.rs +++ b/tests/tests/starknet/keccak.rs @@ -36,10 +36,7 @@ fn keccak_test() { ); assert!(!result.failure_flag); - assert_eq!( - result.remaining_gas, - 340282366920938463463374607431768143515 - ); + assert_eq!(result.remaining_gas, 18446744073709483675); assert_eq!(result.return_values, vec![1.into()]); let result_aot_ct = run_native_starknet_aot_contract( diff --git a/tests/tests/starknet/secp256.rs b/tests/tests/starknet/secp256.rs index 28a8f9ce6..891efbcfe 100644 --- a/tests/tests/starknet/secp256.rs +++ b/tests/tests/starknet/secp256.rs @@ -35,21 +35,21 @@ impl StarknetSyscallHandler for &mut SyscallHandler { fn get_block_hash( &mut self, _block_number: u64, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult { unimplemented!() } fn get_execution_info( &mut self, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult { unimplemented!() } fn get_execution_info_v2( &mut self, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult { unimplemented!() } @@ -60,12 +60,12 @@ impl StarknetSyscallHandler for &mut SyscallHandler { _contract_address_salt: Felt, _calldata: &[Felt], _deploy_from_zero: bool, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult<(Felt, Vec)> { unimplemented!() } - fn replace_class(&mut self, _class_hash: Felt, _remaining_gas: &mut u128) -> SyscallResult<()> { + fn replace_class(&mut self, _class_hash: Felt, _remaining_gas: &mut u64) -> SyscallResult<()> { unimplemented!() } @@ -74,7 +74,7 @@ impl StarknetSyscallHandler for &mut SyscallHandler { _class_hash: Felt, _function_selector: Felt, _calldata: &[Felt], - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult> { unimplemented!() } @@ -84,7 +84,7 @@ impl StarknetSyscallHandler for &mut SyscallHandler { _address: Felt, _entry_point_selector: Felt, _calldata: &[Felt], - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult> { unimplemented!() } @@ -93,7 +93,7 @@ impl StarknetSyscallHandler for &mut SyscallHandler { &mut self, _address_domain: u32, _address: Felt, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult { unimplemented!() } @@ -103,7 +103,7 @@ impl StarknetSyscallHandler for &mut SyscallHandler { _address_domain: u32, _address: Felt, _value: Felt, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult<()> { unimplemented!() } @@ -112,7 +112,7 @@ impl StarknetSyscallHandler for &mut SyscallHandler { &mut self, _keys: &[Felt], _data: &[Felt], - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult<()> { unimplemented!() } @@ -121,12 +121,12 @@ impl StarknetSyscallHandler for &mut SyscallHandler { &mut self, _to_address: Felt, _payload: &[Felt], - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult<()> { unimplemented!() } - fn keccak(&mut self, _input: &[u64], _remaining_gas: &mut u128) -> SyscallResult { + fn keccak(&mut self, _input: &[u64], _remaining_gas: &mut u64) -> SyscallResult { unimplemented!() } @@ -134,7 +134,7 @@ impl StarknetSyscallHandler for &mut SyscallHandler { &mut self, x: U256, y: U256, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult> { let (args, rets) = &mut self.secp256k1_new; @@ -146,7 +146,7 @@ impl StarknetSyscallHandler for &mut SyscallHandler { &mut self, p0: Secp256k1Point, p1: Secp256k1Point, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult { let (args, rets) = &mut self.secp256k1_add; @@ -158,7 +158,7 @@ impl StarknetSyscallHandler for &mut SyscallHandler { &mut self, p: Secp256k1Point, m: U256, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult { let (args, rets) = &mut self.secp256k1_mul; @@ -170,7 +170,7 @@ impl StarknetSyscallHandler for &mut SyscallHandler { &mut self, x: U256, y_parity: bool, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult> { let (args, rets) = &mut self.secp256k1_get_point_from_x; @@ -181,7 +181,7 @@ impl StarknetSyscallHandler for &mut SyscallHandler { fn secp256k1_get_xy( &mut self, p: Secp256k1Point, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult<(U256, U256)> { let (args, rets) = &mut self.secp256k1_get_xy; @@ -193,7 +193,7 @@ impl StarknetSyscallHandler for &mut SyscallHandler { &mut self, x: U256, y: U256, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult> { let (args, rets) = &mut self.secp256r1_new; @@ -205,7 +205,7 @@ impl StarknetSyscallHandler for &mut SyscallHandler { &mut self, p0: Secp256r1Point, p1: Secp256r1Point, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult { let (args, rets) = &mut self.secp256r1_add; @@ -217,7 +217,7 @@ impl StarknetSyscallHandler for &mut SyscallHandler { &mut self, p: Secp256r1Point, m: U256, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult { let (args, rets) = &mut self.secp256r1_mul; @@ -229,7 +229,7 @@ impl StarknetSyscallHandler for &mut SyscallHandler { &mut self, x: U256, y_parity: bool, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult> { let (args, rets) = &mut self.secp256r1_get_point_from_x; @@ -240,7 +240,7 @@ impl StarknetSyscallHandler for &mut SyscallHandler { fn secp256r1_get_xy( &mut self, p: Secp256r1Point, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult<(U256, U256)> { let (args, rets) = &mut self.secp256r1_get_xy; @@ -252,7 +252,7 @@ impl StarknetSyscallHandler for &mut SyscallHandler { &mut self, _state: &mut [u32; 8], _block: &[u32; 16], - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult<()> { unimplemented!() } @@ -304,7 +304,7 @@ fn secp256k1_new() { debug_name: None, }, ], - Some(u128::MAX), + Some(u64::MAX), Some(&mut syscall_handler), ); assert_eq!( @@ -336,7 +336,7 @@ fn secp256k1_new() { debug_name: None, }, ], - Some(u128::MAX), + Some(u64::MAX), Some(&mut syscall_handler), ); assert_eq!( @@ -365,7 +365,7 @@ fn secp256k1_new() { debug_name: None, }, ], - Some(u128::MAX), + Some(u64::MAX), Some(&mut syscall_handler), ); assert_eq!( @@ -461,7 +461,7 @@ fn secp256k1_add() { Value::Secp256K1Point(Secp256k1Point::default()), Value::Secp256K1Point(Secp256k1Point::default()), ], - Some(u128::MAX), + Some(u64::MAX), Some(&mut syscall_handler), ); assert_eq!( @@ -480,7 +480,7 @@ fn secp256k1_add() { Value::Secp256K1Point(Secp256k1Point::new(0, u128::MAX, u128::MAX, 0, false)), Value::Secp256K1Point(Secp256k1Point::new(u128::MAX, 0, 0, u128::MAX, false)), ], - Some(u128::MAX), + Some(u64::MAX), Some(&mut syscall_handler), ); assert_eq!( @@ -517,7 +517,7 @@ fn secp256k1_add() { false, )), ], - Some(u128::MAX), + Some(u64::MAX), Some(&mut syscall_handler), ); assert_eq!( @@ -651,7 +651,7 @@ fn secp256k1_mul() { debug_name: None, }, ], - Some(u128::MAX), + Some(u64::MAX), Some(&mut syscall_handler), ); assert_eq!( @@ -673,7 +673,7 @@ fn secp256k1_mul() { debug_name: None, }, ], - Some(u128::MAX), + Some(u64::MAX), Some(&mut syscall_handler), ); assert_eq!( @@ -701,7 +701,7 @@ fn secp256k1_mul() { debug_name: None, }, ], - Some(u128::MAX), + Some(u64::MAX), Some(&mut syscall_handler), ); assert_eq!( @@ -798,7 +798,7 @@ fn secp256k1_get_point_from_x() { debug_name: None, }, ], - Some(u128::MAX), + Some(u64::MAX), Some(&mut syscall_handler), ); assert_eq!( @@ -834,7 +834,7 @@ fn secp256k1_get_point_from_x() { debug_name: None, }, ], - Some(u128::MAX), + Some(u64::MAX), Some(&mut syscall_handler), ); assert_eq!( @@ -867,7 +867,7 @@ fn secp256k1_get_point_from_x() { debug_name: None, }, ], - Some(u128::MAX), + Some(u64::MAX), Some(&mut syscall_handler), ); assert_eq!( @@ -906,7 +906,7 @@ fn secp256k1_get_point_from_x() { debug_name: None, }, ], - Some(u128::MAX), + Some(u64::MAX), Some(&mut syscall_handler), ); assert_eq!( @@ -1004,7 +1004,7 @@ fn secp256k1_get_xy() { &SECP256_PROGRAM, "secp256k1_get_xy", &[Value::Secp256K1Point(Secp256k1Point::default())], - Some(u128::MAX), + Some(u64::MAX), Some(&mut syscall_handler), ); assert_eq!( @@ -1038,7 +1038,7 @@ fn secp256k1_get_xy() { 0, false, ))], - Some(u128::MAX), + Some(u64::MAX), Some(&mut syscall_handler), ); assert_eq!( @@ -1072,7 +1072,7 @@ fn secp256k1_get_xy() { u128::MAX, false, ))], - Some(u128::MAX), + Some(u64::MAX), Some(&mut syscall_handler), ); assert_eq!( @@ -1106,7 +1106,7 @@ fn secp256k1_get_xy() { u128::MAX, false, ))], - Some(u128::MAX), + Some(u64::MAX), Some(&mut syscall_handler), ); assert_eq!( @@ -1217,7 +1217,7 @@ fn secp256r1_new() { debug_name: None, }, ], - Some(u128::MAX), + Some(u64::MAX), Some(&mut syscall_handler), ); assert_eq!( @@ -1249,7 +1249,7 @@ fn secp256r1_new() { debug_name: None, }, ], - Some(u128::MAX), + Some(u64::MAX), Some(&mut syscall_handler), ); assert_eq!( @@ -1278,7 +1278,7 @@ fn secp256r1_new() { debug_name: None, }, ], - Some(u128::MAX), + Some(u64::MAX), Some(&mut syscall_handler), ); assert_eq!( @@ -1374,7 +1374,7 @@ fn secp256r1_add() { Value::Secp256R1Point(Secp256r1Point::default()), Value::Secp256R1Point(Secp256r1Point::default()), ], - Some(u128::MAX), + Some(u64::MAX), Some(&mut syscall_handler), ); assert_eq!( @@ -1393,7 +1393,7 @@ fn secp256r1_add() { Value::Secp256R1Point(Secp256r1Point::new(u128::MAX, 0, 0, u128::MAX, false)), Value::Secp256R1Point(Secp256r1Point::new(0, u128::MAX, u128::MAX, 0, false)), ], - Some(u128::MAX), + Some(u64::MAX), Some(&mut syscall_handler), ); assert_eq!( @@ -1430,7 +1430,7 @@ fn secp256r1_add() { false, )), ], - Some(u128::MAX), + Some(u64::MAX), Some(&mut syscall_handler), ); assert_eq!( @@ -1513,7 +1513,7 @@ fn secp256r1_mul() { debug_name: None, }, ], - Some(u128::MAX), + Some(u64::MAX), Some(&mut syscall_handler), ); assert_eq!( @@ -1535,7 +1535,7 @@ fn secp256r1_mul() { debug_name: None, }, ], - Some(u128::MAX), + Some(u64::MAX), Some(&mut syscall_handler), ); assert_eq!( @@ -1563,7 +1563,7 @@ fn secp256r1_mul() { debug_name: None, }, ], - Some(u128::MAX), + Some(u64::MAX), Some(&mut syscall_handler), ); assert_eq!( @@ -1660,7 +1660,7 @@ fn secp256r1_get_point_from_x() { debug_name: None, }, ], - Some(u128::MAX), + Some(u64::MAX), Some(&mut syscall_handler), ); assert_eq!( @@ -1696,7 +1696,7 @@ fn secp256r1_get_point_from_x() { debug_name: None, }, ], - Some(u128::MAX), + Some(u64::MAX), Some(&mut syscall_handler), ); assert_eq!( @@ -1729,7 +1729,7 @@ fn secp256r1_get_point_from_x() { debug_name: None, }, ], - Some(u128::MAX), + Some(u64::MAX), Some(&mut syscall_handler), ); assert_eq!( @@ -1768,7 +1768,7 @@ fn secp256r1_get_point_from_x() { debug_name: None, }, ], - Some(u128::MAX), + Some(u64::MAX), Some(&mut syscall_handler), ); assert_eq!( @@ -1866,7 +1866,7 @@ fn secp256r1_get_xy() { &SECP256_PROGRAM, "secp256r1_get_xy", &[Value::Secp256R1Point(Secp256r1Point::default())], - Some(u128::MAX), + Some(u64::MAX), Some(&mut syscall_handler), ); assert_eq!( @@ -1900,7 +1900,7 @@ fn secp256r1_get_xy() { 0, false, ))], - Some(u128::MAX), + Some(u64::MAX), Some(&mut syscall_handler), ); assert_eq!( @@ -1934,7 +1934,7 @@ fn secp256r1_get_xy() { u128::MAX, false, ))], - Some(u128::MAX), + Some(u64::MAX), Some(&mut syscall_handler), ); assert_eq!( @@ -1968,7 +1968,7 @@ fn secp256r1_get_xy() { u128::MAX, false, ))], - Some(u128::MAX), + Some(u64::MAX), Some(&mut syscall_handler), ); assert_eq!( diff --git a/tests/tests/starknet/syscalls.rs b/tests/tests/starknet/syscalls.rs index fc52ee5f0..12c94f817 100644 --- a/tests/tests/starknet/syscalls.rs +++ b/tests/tests/starknet/syscalls.rs @@ -66,7 +66,7 @@ impl StarknetSyscallHandler for SyscallHandler { fn get_block_hash( &mut self, _block_number: u64, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult { Ok(Felt::from_dec_str( "1158579293198495875788224011889333769139150068959598053296510642728083832673", @@ -74,7 +74,7 @@ impl StarknetSyscallHandler for SyscallHandler { .unwrap()) } - fn get_execution_info(&mut self, _remaining_gas: &mut u128) -> SyscallResult { + fn get_execution_info(&mut self, _remaining_gas: &mut u64) -> SyscallResult { Ok(ExecutionInfo { block_info: BlockInfo { block_number: 10057862467973663535, @@ -125,7 +125,7 @@ impl StarknetSyscallHandler for SyscallHandler { fn get_execution_info_v2( &mut self, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult { Ok(ExecutionInfoV2 { block_info: BlockInfo { @@ -187,7 +187,7 @@ impl StarknetSyscallHandler for SyscallHandler { _contract_address_salt: Felt, _calldata: &[Felt], _deploy_from_zero: bool, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult<(Felt, Vec)> { Ok(( Felt::from_dec_str( @@ -198,7 +198,7 @@ impl StarknetSyscallHandler for SyscallHandler { )) } - fn replace_class(&mut self, _class_hash: Felt, _remaining_gas: &mut u128) -> SyscallResult<()> { + fn replace_class(&mut self, _class_hash: Felt, _remaining_gas: &mut u64) -> SyscallResult<()> { Ok(()) } @@ -207,7 +207,7 @@ impl StarknetSyscallHandler for SyscallHandler { _class_hash: Felt, _function_selector: Felt, _calldata: &[Felt], - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult> { Ok(vec![ Felt::from_dec_str( @@ -230,7 +230,7 @@ impl StarknetSyscallHandler for SyscallHandler { _address: Felt, _entry_point_selector: Felt, _calldata: &[Felt], - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult> { Ok(vec![ Felt::from_dec_str( @@ -252,7 +252,7 @@ impl StarknetSyscallHandler for SyscallHandler { &mut self, _address_domain: u32, _address: Felt, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult { Ok(Felt::from_dec_str( "1013181629378419652272218169322268188846114273878719855200100663863924329981", @@ -265,7 +265,7 @@ impl StarknetSyscallHandler for SyscallHandler { _address_domain: u32, _address: Felt, _value: Felt, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult<()> { Ok(()) } @@ -274,7 +274,7 @@ impl StarknetSyscallHandler for SyscallHandler { &mut self, _keys: &[Felt], _data: &[Felt], - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult<()> { Ok(()) } @@ -283,7 +283,7 @@ impl StarknetSyscallHandler for SyscallHandler { &mut self, to_address: Felt, payload: &[Felt], - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult<()> { assert_eq!( to_address, @@ -294,7 +294,7 @@ impl StarknetSyscallHandler for SyscallHandler { Ok(()) } - fn keccak(&mut self, _input: &[u64], _remaining_gas: &mut u128) -> SyscallResult { + fn keccak(&mut self, _input: &[u64], _remaining_gas: &mut u64) -> SyscallResult { Ok(U256 { hi: 330939983442938156232262046592599923289, lo: 288102973244655531496349286021939642254, @@ -305,7 +305,7 @@ impl StarknetSyscallHandler for SyscallHandler { &mut self, _x: U256, _y: U256, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult> { // Tested in `tests/tests/starknet/secp256.rs`. unimplemented!() @@ -315,7 +315,7 @@ impl StarknetSyscallHandler for SyscallHandler { &mut self, _p0: Secp256k1Point, _p1: Secp256k1Point, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult { // Tested in `tests/tests/starknet/secp256.rs`. unimplemented!() @@ -325,7 +325,7 @@ impl StarknetSyscallHandler for SyscallHandler { &mut self, _p: Secp256k1Point, _m: U256, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult { // Tested in `tests/tests/starknet/secp256.rs`. unimplemented!() @@ -335,7 +335,7 @@ impl StarknetSyscallHandler for SyscallHandler { &mut self, _x: U256, _y_parity: bool, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult> { // Tested in `tests/tests/starknet/secp256.rs`. unimplemented!() @@ -344,7 +344,7 @@ impl StarknetSyscallHandler for SyscallHandler { fn secp256k1_get_xy( &mut self, _p: Secp256k1Point, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult<(U256, U256)> { // Tested in `tests/tests/starknet/secp256.rs`. unimplemented!() @@ -354,7 +354,7 @@ impl StarknetSyscallHandler for SyscallHandler { &mut self, _x: U256, _y: U256, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult> { // Tested in `tests/tests/starknet/secp256.rs`. unimplemented!() @@ -364,7 +364,7 @@ impl StarknetSyscallHandler for SyscallHandler { &mut self, _p0: Secp256r1Point, _p1: Secp256r1Point, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult { // Tested in `tests/tests/starknet/secp256.rs`. unimplemented!() @@ -374,7 +374,7 @@ impl StarknetSyscallHandler for SyscallHandler { &mut self, _p: Secp256r1Point, _m: U256, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult { // Tested in `tests/tests/starknet/secp256.rs`. unimplemented!() @@ -384,7 +384,7 @@ impl StarknetSyscallHandler for SyscallHandler { &mut self, _x: U256, _y_parity: bool, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult> { // Tested in `tests/tests/starknet/secp256.rs`. unimplemented!() @@ -393,7 +393,7 @@ impl StarknetSyscallHandler for SyscallHandler { fn secp256r1_get_xy( &mut self, _p: Secp256r1Point, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult<(U256, U256)> { // Tested in `tests/tests/starknet/secp256.rs`. unimplemented!() @@ -498,7 +498,7 @@ impl StarknetSyscallHandler for SyscallHandler { &mut self, _state: &mut [u32; 8], _block: &[u32; 16], - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult<()> { Ok(()) } @@ -515,7 +515,7 @@ fn get_block_hash() { &SYSCALLS_PROGRAM, "get_block_hash", &[], - Some(u128::MAX), + Some(u64::MAX), Some(SyscallHandler::new()), ); @@ -540,7 +540,7 @@ fn get_execution_info() { &SYSCALLS_PROGRAM, "get_execution_info", &[], - Some(u128::MAX), + Some(u64::MAX), Some(SyscallHandler::new()), ); @@ -619,7 +619,7 @@ fn get_execution_info_v2() { &SYSCALLS_PROGRAM, "get_execution_info_v2", &[], - Some(u128::MAX), + Some(u64::MAX), Some(SyscallHandler::new()), ); @@ -711,7 +711,7 @@ fn deploy() { &SYSCALLS_PROGRAM, "deploy", &[], - Some(u128::MAX), + Some(u64::MAX), Some(SyscallHandler::new()), ); @@ -743,7 +743,7 @@ fn replace_class() { &SYSCALLS_PROGRAM, "replace_class", &[], - Some(u128::MAX), + Some(u64::MAX), Some(SyscallHandler::new()), ); @@ -766,7 +766,7 @@ fn library_call() { &SYSCALLS_PROGRAM, "library_call", &[], - Some(u128::MAX), + Some(u64::MAX), Some(SyscallHandler::new()), ); @@ -802,7 +802,7 @@ fn call_contract() { &SYSCALLS_PROGRAM, "call_contract", &[], - Some(u128::MAX), + Some(u64::MAX), Some(SyscallHandler::new()), ); @@ -838,7 +838,7 @@ fn storage_read() { &SYSCALLS_PROGRAM, "storage_read", &[], - Some(u128::MAX), + Some(u64::MAX), Some(SyscallHandler::new()), ); @@ -866,7 +866,7 @@ fn storage_write() { &SYSCALLS_PROGRAM, "storage_write", &[], - Some(u128::MAX), + Some(u64::MAX), Some(SyscallHandler::new()), ); @@ -892,7 +892,7 @@ fn emit_event() { &SYSCALLS_PROGRAM, "emit_event", &[], - Some(u128::MAX), + Some(u64::MAX), Some(SyscallHandler::new()), ); @@ -915,7 +915,7 @@ fn send_message_to_l1() { &SYSCALLS_PROGRAM, "send_message_to_l1", &[], - Some(u128::MAX), + Some(u64::MAX), Some(SyscallHandler::new()), ); @@ -938,7 +938,7 @@ fn keccak() { &SYSCALLS_PROGRAM, "keccak", &[], - Some(u128::MAX), + Some(u64::MAX), Some(SyscallHandler::new()), ); @@ -968,7 +968,7 @@ fn set_sequencer_address() { &SYSCALLS_PROGRAM, "set_sequencer_address", &[Value::Felt252(address)], - Some(u128::MAX), + Some(u64::MAX), Some(SyscallHandler::with(state.clone())), ); @@ -994,7 +994,7 @@ fn set_max_fee() { &SYSCALLS_PROGRAM, "set_max_fee", &[Value::Felt252(Felt::from(max_fee))], - Some(u128::MAX), + Some(u64::MAX), Some(SyscallHandler::with(state.clone())), ); @@ -1026,7 +1026,7 @@ fn set_signature() { &SYSCALLS_PROGRAM, "set_signature", &[Value::Array(signature_jit)], - Some(u128::MAX), + Some(u64::MAX), Some(SyscallHandler::with(state.clone())), ); @@ -1060,7 +1060,7 @@ fn pop_log() { &SYSCALLS_PROGRAM, "pop_log", &[Value::Felt252(log_index)], - Some(u128::MAX), + Some(u64::MAX), Some(SyscallHandler::with(state.clone())), ); @@ -1103,7 +1103,7 @@ fn pop_log_empty() { &SYSCALLS_PROGRAM, "pop_log", &[Value::Felt252(log_index)], - Some(u128::MAX), + Some(u64::MAX), Some(SyscallHandler::with(state.clone())), ); @@ -1134,7 +1134,7 @@ fn pop_l2_to_l1_message() { &SYSCALLS_PROGRAM, "pop_l2_to_l1_message", &[Value::Felt252(log_index)], - Some(u128::MAX), + Some(u64::MAX), Some(SyscallHandler::with(state.clone())), ); @@ -1172,7 +1172,7 @@ fn sha256_process() { &SYSCALLS_PROGRAM, "sha256_process", &[], - Some(u128::MAX), + Some(u64::MAX), Some(SyscallHandler::new()), ); diff --git a/tests/tests/starknet/u256.rs b/tests/tests/starknet/u256.rs index 4ac77b790..b87bff3ff 100644 --- a/tests/tests/starknet/u256.rs +++ b/tests/tests/starknet/u256.rs @@ -41,8 +41,5 @@ fn u256_test() { result.return_values, vec![Felt::from_hex("0xf70cba9bb86caa97b086fdfa3df602ed").unwrap()] ); - assert_eq!( - result.remaining_gas, - 340282366920938463463374607431768192415 - ); + assert_eq!(result.remaining_gas, 18446744073709532575); } diff --git a/tests/tests/uint.rs b/tests/tests/uint.rs index 33eacf235..b4529502e 100644 --- a/tests/tests/uint.rs +++ b/tests/tests/uint.rs @@ -450,7 +450,7 @@ proptest! { program, "run_test", &[Value::Felt252(a.into()), Value::Felt252(b.into())], - Some(DEFAULT_GAS as u128), + Some(DEFAULT_GAS), Option::::None, ); @@ -476,7 +476,7 @@ proptest! { program, "run_test", &[Value::Felt252(a.into()), Value::Felt252(b.into())], - Some(DEFAULT_GAS as u128), + Some(DEFAULT_GAS), Option::::None, ); @@ -502,7 +502,7 @@ proptest! { program, "run_test", &[Value::Felt252(a.into()), Value::Felt252(b.into())], - Some(DEFAULT_GAS as u128), + Some(DEFAULT_GAS), Option::::None, ); @@ -528,7 +528,7 @@ proptest! { program, "run_test", &[Value::Felt252(a.into()), Value::Felt252(b.into())], - Some(DEFAULT_GAS as u128), + Some(DEFAULT_GAS), Option::::None, ); @@ -554,7 +554,7 @@ proptest! { program, "run_test", &[Value::Felt252(a.into())], - Some(DEFAULT_GAS as u128), + Some(DEFAULT_GAS), Option::::None, ); @@ -582,7 +582,7 @@ proptest! { program, "run_test", &[Value::Felt252(a.into()), Value::Felt252(b.into())], - Some(DEFAULT_GAS as u128), + Some(DEFAULT_GAS), Option::::None, ); @@ -608,7 +608,7 @@ proptest! { program, "run_test", &[Value::Felt252(a.into()), Value::Felt252(b.into())], - Some(DEFAULT_GAS as u128), + Some(DEFAULT_GAS), Option::::None, ); @@ -634,7 +634,7 @@ proptest! { program, "run_test", &[Value::Felt252(a.into()), Value::Felt252(b.into())], - Some(DEFAULT_GAS as u128), + Some(DEFAULT_GAS), Option::::None, ); @@ -660,7 +660,7 @@ proptest! { program, "run_test", &[Value::Felt252(a.into()), Value::Felt252(b.into())], - Some(DEFAULT_GAS as u128), + Some(DEFAULT_GAS), Option::::None, ); @@ -686,7 +686,7 @@ proptest! { program, "run_test", &[Value::Felt252(a.into())], - Some(DEFAULT_GAS as u128), + Some(DEFAULT_GAS), Option::::None, ); @@ -714,7 +714,7 @@ proptest! { program, "run_test", &[Value::Felt252(a.into()), Value::Felt252(b.into())], - Some(DEFAULT_GAS as u128), + Some(DEFAULT_GAS), Option::::None, ); @@ -740,7 +740,7 @@ proptest! { program, "run_test", &[Value::Felt252(a.into()), Value::Felt252(b.into())], - Some(DEFAULT_GAS as u128), + Some(DEFAULT_GAS), Option::::None, ); @@ -766,7 +766,7 @@ proptest! { program, "run_test", &[Value::Felt252(a.into()), Value::Felt252(b.into())], - Some(DEFAULT_GAS as u128), + Some(DEFAULT_GAS), Option::::None, ); @@ -792,7 +792,7 @@ proptest! { program, "run_test", &[Value::Felt252(a.into()), Value::Felt252(b.into())], - Some(DEFAULT_GAS as u128), + Some(DEFAULT_GAS), Option::::None, ); @@ -818,7 +818,7 @@ proptest! { program, "run_test", &[Value::Felt252(a.into())], - Some(DEFAULT_GAS as u128), + Some(DEFAULT_GAS), Option::::None, ); @@ -846,7 +846,7 @@ proptest! { program, "run_test", &[Value::Felt252(a.into()), Value::Felt252(b.into())], - Some(DEFAULT_GAS as u128), + Some(DEFAULT_GAS), Option::::None, ); @@ -872,7 +872,7 @@ proptest! { program, "run_test", &[Value::Felt252(a.into()), Value::Felt252(b.into())], - Some(DEFAULT_GAS as u128), + Some(DEFAULT_GAS), Option::::None, ); @@ -898,7 +898,7 @@ proptest! { program, "run_test", &[Value::Felt252(a.into()), Value::Felt252(b.into())], - Some(DEFAULT_GAS as u128), + Some(DEFAULT_GAS), Option::::None, ); @@ -924,7 +924,7 @@ proptest! { program, "run_test", &[Value::Felt252(a.into()), Value::Felt252(b.into())], - Some(DEFAULT_GAS as u128), + Some(DEFAULT_GAS), Option::::None, ); @@ -950,7 +950,7 @@ proptest! { program, "run_test", &[Value::Felt252(a.into())], - Some(DEFAULT_GAS as u128), + Some(DEFAULT_GAS), Option::::None, ); @@ -978,7 +978,7 @@ proptest! { program, "run_test", &[Value::Felt252(a.into()), Value::Felt252(b.into())], - Some(DEFAULT_GAS as u128), + Some(DEFAULT_GAS), Option::::None, ); @@ -1004,7 +1004,7 @@ proptest! { program, "run_test", &[Value::Felt252(a.into()), Value::Felt252(b.into())], - Some(DEFAULT_GAS as u128), + Some(DEFAULT_GAS), Option::::None, ); @@ -1030,7 +1030,7 @@ proptest! { program, "run_test", &[Value::Felt252(a.into()), Value::Felt252(b.into())], - Some(DEFAULT_GAS as u128), + Some(DEFAULT_GAS), Option::::None, ); @@ -1056,7 +1056,7 @@ proptest! { program, "run_test", &[Value::Felt252(a.into()), Value::Felt252(b.into())], - Some(DEFAULT_GAS as u128), + Some(DEFAULT_GAS), Option::::None, ); @@ -1082,7 +1082,7 @@ proptest! { program, "run_test", &[Value::Felt252(a.into())], - Some(DEFAULT_GAS as u128), + Some(DEFAULT_GAS), Option::::None, );