diff --git a/Cargo.toml b/Cargo.toml index d1f290c..64f1aae 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,35 +4,35 @@ version = "0.1.0" edition = "2021" [dependencies] -cairo-lang-compiler = "2.8.2" -cairo-lang-filesystem = "2.8.2" -cairo-lang-sierra = "2.8.0" -cairo-lang-sierra-ap-change = "2.8.0" -cairo-lang-sierra-gas = "2.8.0" -cairo-lang-utils = "2.8.0" -clap = { version = "4.5.16", features = ["derive"] } -k256 = "0.13.3" +cairo-lang-compiler = "2.8.4" +cairo-lang-filesystem = "2.8.4" +cairo-lang-sierra = "2.8.4" +cairo-lang-sierra-ap-change = "2.8.4" +cairo-lang-sierra-gas = "2.8.4" +cairo-lang-utils = "2.8.4" +clap = { version = "4.5.20", features = ["derive"] } +k256 = "0.13.4" keccak = "0.1.5" num-bigint = "0.4.6" num-traits = "0.2.19" p256 = "0.13.2" rand = "0.8.5" sec1 = { version = "0.7.3", features = ["std"] } -serde = { version = "1.0.209", features = ["derive"] } -serde_json = "1.0.127" +serde = { version = "1.0.214", features = ["derive"] } +serde_json = "1.0.132" sha2 = { version = "0.10.8", features = ["compress"] } smallvec = "1.13.2" -starknet-crypto = "0.7.1" -starknet-curve = "0.5.0" -starknet-types-core = "0.1.2" -tempfile = "3.13.0" -thiserror = "1.0.63" +starknet-crypto = "0.7.3" +starknet-curve = "0.5.1" +starknet-types-core = "0.1.7" +tempfile = "3.14.0" +thiserror = "2.0.3" tracing = "0.1.40" tracing-subscriber = { version = "0.3.18", features = ["env-filter"] } [dev-dependencies] -cairo-lang-compiler = "2.8.0" -cairo-lang-starknet = "2.8.0" +cairo-lang-compiler = "2.8.4" +cairo-lang-starknet = "2.8.4" # On dev optimize dependencies a bit so it's not as slow. [profile.dev.package."*"] diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 4fdc48f..0127c34 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,4 +1,4 @@ [toolchain] -channel = "1.80.1" +channel = "1.82.0" components = ["rustfmt", "clippy"] profile = "minimal" diff --git a/src/args.rs b/src/args.rs index 3c86665..2108748 100644 --- a/src/args.rs +++ b/src/args.rs @@ -8,7 +8,7 @@ pub struct CmdArgs { pub args: Vec, #[clap(long)] - pub available_gas: Option, + pub available_gas: Option, #[clap(long, short)] pub output: Option, diff --git a/src/dump.rs b/src/dump.rs index ab625c1..2ac2fd5 100644 --- a/src/dump.rs +++ b/src/dump.rs @@ -55,7 +55,7 @@ impl Serialize for StateDump { #[derive(Debug, Clone)] pub struct ContractExecutionResult { - pub remaining_gas: u128, + pub remaining_gas: u64, pub failure_flag: bool, pub return_values: Vec, pub error_msg: Option, @@ -72,7 +72,7 @@ impl ContractExecutionResult { for value in last.items.values() { match value { - Value::U128(gas) => remaining_gas = Some(*gas), + Value::U64(gas) => remaining_gas = Some(*gas), Value::Enum { self_ty: _, index, diff --git a/src/gas.rs b/src/gas.rs index 4792983..3fb01d3 100644 --- a/src/gas.rs +++ b/src/gas.rs @@ -46,7 +46,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 GasMetadata { @@ -66,8 +66,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); }; @@ -86,7 +86,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; } @@ -94,17 +94,17 @@ 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, ) } - pub fn get_gas_cost_for_statement(&self, idx: StatementIdx) -> Option { + pub fn get_gas_cost_for_statement(&self, idx: StatementIdx) -> Option { let mut cost = None; for cost_type in CostTokenType::iter_casm_tokens() { if let Some(amount) = self.get_gas_cost_for_statement_and_cost_token_type(idx, *cost_type) { - *cost.get_or_insert(0) += amount * token_gas_cost(*cost_type) as u128; + *cost.get_or_insert(0) += amount * token_gas_cost(*cost_type) as u64; } } cost @@ -114,7 +114,7 @@ impl GasMetadata { &self, idx: StatementIdx, cost_type: CostTokenType, - ) -> Option { + ) -> Option { self.gas_info .variable_values .get(&(idx, cost_type)) diff --git a/src/main.rs b/src/main.rs index 265d1d0..214b907 100644 --- a/src/main.rs +++ b/src/main.rs @@ -65,7 +65,7 @@ fn main() -> Result<(), Box> { let type_info = vm.registry().get_type(type_id).unwrap(); match type_info { CoreTypeConcrete::Felt252(_) => Value::parse_felt(&iter.next().unwrap()), - CoreTypeConcrete::GasBuiltin(_) => Value::U128(args.available_gas.unwrap()), + CoreTypeConcrete::GasBuiltin(_) => Value::U64(args.available_gas.unwrap()), CoreTypeConcrete::RangeCheck(_) | CoreTypeConcrete::RangeCheck96(_) | CoreTypeConcrete::Bitwise(_) diff --git a/src/starknet.rs b/src/starknet.rs index 48af30b..23915be 100644 --- a/src/starknet.rs +++ b/src/starknet.rs @@ -29,16 +29,12 @@ mod u256; pub type SyscallResult = Result>; 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, @@ -46,17 +42,17 @@ pub trait StarknetSyscallHandler { contract_address_salt: Felt, calldata: Vec, 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: Vec, - remaining_gas: &mut u128, + remaining_gas: &mut u64, ) -> SyscallResult>; fn call_contract( @@ -64,14 +60,14 @@ pub trait StarknetSyscallHandler { address: Felt, entry_point_selector: Felt, calldata: Vec, - 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( @@ -79,98 +75,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: Vec, data: Vec, - remaining_gas: &mut u128, + remaining_gas: &mut u64, ) -> SyscallResult<()>; fn send_message_to_l1( &mut self, to_address: Felt, payload: Vec, - remaining_gas: &mut u128, + remaining_gas: &mut u64, ) -> SyscallResult<()>; - fn keccak(&mut self, input: Vec, remaining_gas: &mut u128) -> SyscallResult; + fn keccak(&mut self, input: Vec, 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, prev_state: [u32; 8], current_block: [u32; 16], - remaining_gas: &mut u128, + remaining_gas: &mut u64, ) -> SyscallResult<[u32; 8]>; fn cheatcode(&mut self, _selector: Felt, _input: Vec) -> Vec { @@ -246,12 +242,12 @@ impl StarknetSyscallHandler for StubSyscallHandler { fn get_block_hash( &mut self, block_number: u64, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult { Ok(block_number.into()) } - 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: self.execution_info.block_info, tx_info: TxInfo { @@ -271,7 +267,7 @@ impl StarknetSyscallHandler for StubSyscallHandler { fn get_execution_info_v2( &mut self, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult { Ok(self.execution_info.clone()) } @@ -282,12 +278,12 @@ impl StarknetSyscallHandler for StubSyscallHandler { _contract_address_salt: Felt, _calldata: Vec, _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!() } @@ -296,7 +292,7 @@ impl StarknetSyscallHandler for StubSyscallHandler { _class_hash: Felt, _function_selector: Felt, _calldata: Vec, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult> { unimplemented!() } @@ -306,7 +302,7 @@ impl StarknetSyscallHandler for StubSyscallHandler { _address: Felt, _entry_point_selector: Felt, _calldata: Vec, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult> { unimplemented!() } @@ -315,7 +311,7 @@ impl StarknetSyscallHandler for StubSyscallHandler { &mut self, address_domain: u32, address: Felt, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult { if let Some(value) = self.storage.get(&(address_domain, address)) { Ok(*value) @@ -329,7 +325,7 @@ impl StarknetSyscallHandler for StubSyscallHandler { address_domain: u32, address: Felt, value: Felt, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult<()> { self.storage.insert((address_domain, address), value); Ok(()) @@ -339,7 +335,7 @@ impl StarknetSyscallHandler for StubSyscallHandler { &mut self, keys: Vec, data: Vec, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult<()> { self.events.push(StubEvent { keys: keys.to_vec(), @@ -352,12 +348,12 @@ impl StarknetSyscallHandler for StubSyscallHandler { &mut self, _to_address: Felt, _payload: Vec, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult<()> { unimplemented!() } - fn keccak(&mut self, input: Vec, gas: &mut u128) -> SyscallResult { + fn keccak(&mut self, input: Vec, gas: &mut u64) -> SyscallResult { let length = input.len(); if length % 17 != 0 { @@ -369,13 +365,14 @@ impl StarknetSyscallHandler for StubSyscallHandler { let n_chunks = length / 17; let mut state = [0u64; 25]; + const KECCAK_ROUND_COST: u64 = 180000; for i in 0..n_chunks { if *gas < KECCAK_ROUND_COST { let error_msg = b"Syscall out of gas"; let felt_error = Felt::from_bytes_be_slice(error_msg); return Err(vec![felt_error]); } - const KECCAK_ROUND_COST: u128 = 180000; + *gas -= KECCAK_ROUND_COST; let chunk = &input[i * 17..(i + 1) * 17]; //(request.input_start + i * 17)?; for (i, val) in chunk.iter().enumerate() { @@ -396,7 +393,7 @@ impl StarknetSyscallHandler for StubSyscallHandler { &mut self, x: U256, y: U256, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult> { // The following unwraps should be unreachable because the iterator we provide has the // expected number of bytes. @@ -425,7 +422,7 @@ impl StarknetSyscallHandler for StubSyscallHandler { &mut self, p0: Secp256k1Point, p1: Secp256k1Point, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult { // The inner unwraps should be unreachable because the iterator we provide has the expected // number of bytes. The outer unwraps depend on the felt values, which should be valid since @@ -503,7 +500,7 @@ impl StarknetSyscallHandler for StubSyscallHandler { &mut self, p: Secp256k1Point, m: U256, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult { // The inner unwrap should be unreachable because the iterator we provide has the expected // number of bytes. The outer unwrap depends on the felt values, which should be valid since @@ -567,7 +564,7 @@ impl StarknetSyscallHandler for StubSyscallHandler { &mut self, x: U256, y_parity: bool, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult> { // The inner unwrap should be unreachable because the iterator we provide has the expected // number of bytes. The outer unwrap depends on the encoding format, which should be valid @@ -617,7 +614,7 @@ impl StarknetSyscallHandler for 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)) } @@ -626,7 +623,7 @@ impl StarknetSyscallHandler for StubSyscallHandler { &mut self, x: U256, y: U256, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult> { // The following unwraps should be unreachable because the iterator we provide has the // expected number of bytes. @@ -655,7 +652,7 @@ impl StarknetSyscallHandler for StubSyscallHandler { &mut self, p0: Secp256r1Point, p1: Secp256r1Point, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult { // The inner unwraps should be unreachable because the iterator we provide has the expected // number of bytes. The outer unwraps depend on the felt values, which should be valid since @@ -733,7 +730,7 @@ impl StarknetSyscallHandler for StubSyscallHandler { &mut self, p: Secp256r1Point, m: U256, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult { // The inner unwrap should be unreachable because the iterator we provide has the expected // number of bytes. The outer unwrap depends on the felt values, which should be valid since @@ -796,7 +793,7 @@ impl StarknetSyscallHandler for StubSyscallHandler { &mut self, x: U256, y_parity: bool, - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult> { let point = p256::ProjectivePoint::from_encoded_point( &p256::EncodedPoint::from_bytes( @@ -835,7 +832,7 @@ impl StarknetSyscallHandler for 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)) } @@ -844,7 +841,7 @@ impl StarknetSyscallHandler for StubSyscallHandler { &mut self, prev_state: [u32; 8], current_block: [u32; 16], - _remaining_gas: &mut u128, + _remaining_gas: &mut u64, ) -> SyscallResult<[u32; 8]> { let mut state = prev_state; let data_as_bytes = sha2::digest::generic_array::GenericArray::from_exact_iter( diff --git a/src/value.rs b/src/value.rs index c8729e4..4bbe50b 100644 --- a/src/value.rs +++ b/src/value.rs @@ -107,7 +107,7 @@ impl Value { CoreTypeConcrete::Felt252Dict(info) => { matches!(self, Self::FeltDict { ty, .. } if *ty == info.ty) } - CoreTypeConcrete::GasBuiltin(_) => matches!(self, Self::U128(_)), + CoreTypeConcrete::GasBuiltin(_) => matches!(self, Self::U64(_)), CoreTypeConcrete::NonZero(info) => self.is(registry, &info.ty), CoreTypeConcrete::Sint128(_) => matches!(self, Self::I128(_)), CoreTypeConcrete::Sint32(_) => matches!(self, Self::I32(_)), diff --git a/src/vm.rs b/src/vm.rs index 422ac47..0d6b27d 100644 --- a/src/vm.rs +++ b/src/vm.rs @@ -98,7 +98,7 @@ impl VirtualMachine { pub fn call_contract( &mut self, function: &GenFunction, - initial_gas: u128, + initial_gas: u64, calldata: I, ) where I: IntoIterator, @@ -115,7 +115,7 @@ impl VirtualMachine { .map(|type_id| { let type_info = self.registry().get_type(type_id).unwrap(); match type_info { - CoreTypeConcrete::GasBuiltin(_) => Value::U128(initial_gas), + CoreTypeConcrete::GasBuiltin(_) => Value::U64(initial_gas), // Add the calldata structure CoreTypeConcrete::Struct(inner) => { let member = self.registry().get_type(&inner.members[0]).unwrap(); diff --git a/src/vm/array.rs b/src/vm/array.rs index 4f45f56..d5eecf9 100644 --- a/src/vm/array.rs +++ b/src/vm/array.rs @@ -58,7 +58,7 @@ fn eval_span_from_tuple( data, }; - return EvalAction::NormalBranch(0, smallvec![value]); + EvalAction::NormalBranch(0, smallvec![value]) } pub fn eval_new( diff --git a/src/vm/cast.rs b/src/vm/cast.rs index 10aaacf..fd1f15f 100644 --- a/src/vm/cast.rs +++ b/src/vm/cast.rs @@ -97,7 +97,7 @@ pub fn eval_upcast( CoreTypeConcrete::Uint32(_) => Value::U32(value.try_into().unwrap()), CoreTypeConcrete::Uint64(_) => Value::U64(value.try_into().unwrap()), CoreTypeConcrete::Uint128(_) => Value::U128(value.try_into().unwrap()), - CoreTypeConcrete::Felt252(_) => Value::Felt(value.try_into().unwrap()), + CoreTypeConcrete::Felt252(_) => Value::Felt(value.into()), CoreTypeConcrete::Sint16(_) => todo!("Sint16"), CoreTypeConcrete::Sint64(_) => todo!("Sint64"), CoreTypeConcrete::BoundedInt(_) => todo!("BoundedInt"), diff --git a/src/vm/gas.rs b/src/vm/gas.rs index 2bfda50..06b809b 100644 --- a/src/vm/gas.rs +++ b/src/vm/gas.rs @@ -38,7 +38,7 @@ pub fn eval_builtin_withdraw_gas( gas_meta: &GasMetadata, statement_idx: StatementIdx, ) -> EvalAction { - let [range_check @ Value::Unit, Value::U128(gas), _builtin_costs @ Value::Unit]: [Value; 3] = + let [range_check @ Value::Unit, Value::U64(gas), _builtin_costs @ Value::Unit]: [Value; 3] = args.try_into().unwrap() else { panic!() @@ -49,12 +49,12 @@ pub fn eval_builtin_withdraw_gas( if let Some(gas_cost) = gas_cost { let new_gas = gas.saturating_sub(gas_cost); if gas >= gas_cost { - EvalAction::NormalBranch(0, smallvec![range_check, Value::U128(new_gas)]) + EvalAction::NormalBranch(0, smallvec![range_check, Value::U64(new_gas)]) } else { - EvalAction::NormalBranch(1, smallvec![range_check, Value::U128(new_gas)]) + EvalAction::NormalBranch(1, smallvec![range_check, Value::U64(new_gas)]) } } else { - EvalAction::NormalBranch(1, smallvec![range_check, Value::U128(gas)]) + EvalAction::NormalBranch(1, smallvec![range_check, Value::U64(gas)]) } } @@ -65,7 +65,7 @@ pub fn eval_withdraw_gas( gas_meta: &GasMetadata, statement_idx: StatementIdx, ) -> EvalAction { - let [range_check @ Value::Unit, Value::U128(gas)]: [Value; 2] = args.try_into().unwrap() else { + let [range_check @ Value::Unit, Value::U64(gas)]: [Value; 2] = args.try_into().unwrap() else { panic!() }; @@ -74,12 +74,12 @@ pub fn eval_withdraw_gas( if let Some(gas_cost) = gas_cost { let new_gas = gas.saturating_sub(gas_cost); if gas >= gas_cost { - EvalAction::NormalBranch(0, smallvec![range_check, Value::U128(new_gas)]) + EvalAction::NormalBranch(0, smallvec![range_check, Value::U64(new_gas)]) } else { - EvalAction::NormalBranch(1, smallvec![range_check, Value::U128(new_gas)]) + EvalAction::NormalBranch(1, smallvec![range_check, Value::U64(new_gas)]) } } else { - EvalAction::NormalBranch(1, smallvec![range_check, Value::U128(gas)]) + EvalAction::NormalBranch(1, smallvec![range_check, Value::U64(gas)]) } } diff --git a/src/vm/starknet.rs b/src/vm/starknet.rs index 6a30346..502b11e 100644 --- a/src/vm/starknet.rs +++ b/src/vm/starknet.rs @@ -131,7 +131,7 @@ fn eval_secp_r_add( args: Vec, syscall_handler: &mut impl StarknetSyscallHandler, ) -> EvalAction { - let [Value::U128(mut gas), system @ Value::Unit, x, y]: [Value; 4] = args.try_into().unwrap() + let [Value::U64(mut gas), system @ Value::Unit, x, y]: [Value; 4] = args.try_into().unwrap() else { panic!() }; @@ -140,10 +140,10 @@ fn eval_secp_r_add( let y = Secp256r1Point::from_value(y); match syscall_handler.secp256r1_add(x, y, &mut gas) { - Ok(x) => EvalAction::NormalBranch(0, smallvec![Value::U128(gas), system, x.into_value()]), + Ok(x) => EvalAction::NormalBranch(0, smallvec![Value::U64(gas), system, x.into_value()]), Err(r) => { let r = Value::Struct(r.into_iter().map(Value::Felt).collect::>()); - EvalAction::NormalBranch(1, smallvec![Value::U128(gas), system, r]) + EvalAction::NormalBranch(1, smallvec![Value::U64(gas), system, r]) } } } @@ -154,7 +154,7 @@ fn eval_secp_r_mul( args: Vec, syscall_handler: &mut impl StarknetSyscallHandler, ) -> EvalAction { - let [Value::U128(mut gas), system @ Value::Unit, x, n]: [Value; 4] = args.try_into().unwrap() + let [Value::U64(mut gas), system @ Value::Unit, x, n]: [Value; 4] = args.try_into().unwrap() else { panic!() }; @@ -163,10 +163,10 @@ fn eval_secp_r_mul( let n = U256::from_value(n); match syscall_handler.secp256r1_mul(x, n, &mut gas) { - Ok(x) => EvalAction::NormalBranch(0, smallvec![Value::U128(gas), system, x.into_value()]), + Ok(x) => EvalAction::NormalBranch(0, smallvec![Value::U64(gas), system, x.into_value()]), Err(r) => { let r = Value::Struct(r.into_iter().map(Value::Felt).collect::>()); - EvalAction::NormalBranch(1, smallvec![Value::U128(gas), system, r]) + EvalAction::NormalBranch(1, smallvec![Value::U64(gas), system, r]) } } } @@ -177,7 +177,7 @@ fn eval_secp_r_new( args: Vec, syscall_handler: &mut impl StarknetSyscallHandler, ) -> EvalAction { - let [Value::U128(mut gas), system @ Value::Unit, Value::Struct(x), Value::Struct(y)]: [Value; + let [Value::U64(mut gas), system @ Value::Unit, Value::Struct(x), Value::Struct(y)]: [Value; 4] = args.try_into().unwrap() else { panic!() @@ -206,7 +206,7 @@ fn eval_secp_r_new( }, }; - EvalAction::NormalBranch(0, smallvec![Value::U128(gas), system, value]) + EvalAction::NormalBranch(0, smallvec![Value::U64(gas), system, value]) } Err(payload) => { // get felt type from the error branch array @@ -224,7 +224,7 @@ fn eval_secp_r_new( EvalAction::NormalBranch( 1, smallvec![ - Value::U128(gas), + Value::U64(gas), system, Value::Array { ty: felt_ty, @@ -242,7 +242,7 @@ fn eval_secp_r_get_point_from_x( args: Vec, syscall_handler: &mut impl StarknetSyscallHandler, ) -> EvalAction { - let [Value::U128(mut gas), system @ Value::Unit, Value::Struct(x), Value::Enum { + let [Value::U64(mut gas), system @ Value::Unit, Value::Struct(x), Value::Enum { index: y_parity, .. }]: [Value; 4] = args.try_into().unwrap() else { @@ -270,7 +270,7 @@ fn eval_secp_r_get_point_from_x( }, }; - EvalAction::NormalBranch(0, smallvec![Value::U128(gas), system, value]) + EvalAction::NormalBranch(0, smallvec![Value::U64(gas), system, value]) } Err(payload) => { // get felt type from the error branch array @@ -288,7 +288,7 @@ fn eval_secp_r_get_point_from_x( EvalAction::NormalBranch( 1, smallvec![ - Value::U128(gas), + Value::U64(gas), system, Value::Array { ty: felt_ty, @@ -306,7 +306,7 @@ fn secp_r_get_xy( args: Vec, syscall_handler: &mut impl StarknetSyscallHandler, ) -> EvalAction { - let [Value::U128(mut gas), system @ Value::Unit, secp_value]: [Value; 3] = + let [Value::U64(mut gas), system @ Value::Unit, secp_value]: [Value; 3] = args.try_into().unwrap() else { panic!() @@ -317,7 +317,7 @@ fn secp_r_get_xy( match syscall_handler.secp256r1_get_xy(secp_value, &mut gas) { Ok(payload) => { let (x, y) = (payload.0.into_value(), payload.1.into_value()); - EvalAction::NormalBranch(0, smallvec![Value::U128(gas), system, x, y]) + EvalAction::NormalBranch(0, smallvec![Value::U64(gas), system, x, y]) } Err(payload) => { let felt_ty = { @@ -334,7 +334,7 @@ fn secp_r_get_xy( EvalAction::NormalBranch( 0, smallvec![ - Value::U128(gas), + Value::U64(gas), system, Value::Array { ty: felt_ty, @@ -505,7 +505,7 @@ fn eval_call_contract( args: Vec, syscall_handler: &mut impl StarknetSyscallHandler, ) -> EvalAction { - let [Value::U128(mut gas), system, Value::Felt(address), Value::Felt(entry_point_selector), Value::Struct(calldata)]: [Value; 5] = + let [Value::U64(mut gas), system, Value::Felt(address), Value::Felt(entry_point_selector), Value::Struct(calldata)]: [Value; 5] = args.try_into().unwrap() else { panic!() @@ -544,7 +544,7 @@ fn eval_call_contract( Ok(return_values) => EvalAction::NormalBranch( 0, smallvec![ - Value::U128(gas), + Value::U64(gas), system, Value::Struct(vec![Value::Array { ty: felt_ty, @@ -558,7 +558,7 @@ fn eval_call_contract( Err(e) => EvalAction::NormalBranch( 1, smallvec![ - Value::U128(gas), + Value::U64(gas), system, Value::Array { ty: felt_ty, @@ -575,7 +575,9 @@ fn eval_storage_read( args: Vec, syscall_handler: &mut impl StarknetSyscallHandler, ) -> EvalAction { - let [Value::U128(mut gas), system, Value::U32(address_domain), Value::Felt(storage_key)]: [Value; 4] = args.try_into().unwrap() else { + let [Value::U64(mut gas), system, Value::U32(address_domain), Value::Felt(storage_key)]: [Value; + 4] = args.try_into().unwrap() + else { panic!() }; let error_felt_ty = { @@ -592,12 +594,12 @@ fn eval_storage_read( match result { Ok(value) => { - EvalAction::NormalBranch(0, smallvec![Value::U128(gas), system, Value::Felt(value)]) + EvalAction::NormalBranch(0, smallvec![Value::U64(gas), system, Value::Felt(value)]) } Err(e) => EvalAction::NormalBranch( 1, smallvec![ - Value::U128(gas), + Value::U64(gas), system, Value::Array { ty: error_felt_ty, @@ -614,7 +616,7 @@ fn eval_storage_write( args: Vec, syscall_handler: &mut impl StarknetSyscallHandler, ) -> EvalAction { - let [Value::U128(mut gas), system, Value::U32(address_domain), Value::Felt(storage_key), Value::Felt(value)]: [Value; 5] = args.try_into().unwrap() else { + let [Value::U64(mut gas), system, Value::U32(address_domain), Value::Felt(storage_key), Value::Felt(value)]: [Value; 5] = args.try_into().unwrap() else { panic!() }; @@ -631,11 +633,11 @@ fn eval_storage_write( let result = syscall_handler.storage_write(address_domain, storage_key, value, &mut gas); match result { - Ok(_) => EvalAction::NormalBranch(0, smallvec![Value::U128(gas), system]), + Ok(_) => EvalAction::NormalBranch(0, smallvec![Value::U64(gas), system]), Err(e) => EvalAction::NormalBranch( 1, smallvec![ - Value::U128(gas), + Value::U64(gas), system, Value::Array { ty: error_felt_ty, @@ -652,8 +654,8 @@ fn eval_emit_event( args: Vec, syscall_handler: &mut impl StarknetSyscallHandler, ) -> EvalAction { - let [Value::U128(mut gas), system, Value::Struct(key_arr), Value::Struct(data_arr)]: [Value; - 4] = args.try_into().unwrap() + let [Value::U64(mut gas), system, Value::Struct(key_arr), Value::Struct(data_arr)]: [Value; 4] = + args.try_into().unwrap() else { panic!() }; @@ -694,11 +696,11 @@ fn eval_emit_event( let result = syscall_handler.emit_event(keys, data, &mut gas); match result { - Ok(_) => EvalAction::NormalBranch(0, smallvec![Value::U128(gas), system]), + Ok(_) => EvalAction::NormalBranch(0, smallvec![Value::U64(gas), system]), Err(e) => EvalAction::NormalBranch( 1, smallvec![ - Value::U128(gas), + Value::U64(gas), system, Value::Array { ty: error_felt_ty, @@ -715,7 +717,7 @@ fn eval_get_block_hash( args: Vec, syscall_handler: &mut impl StarknetSyscallHandler, ) -> EvalAction { - let [Value::U128(mut gas), system, Value::U64(block_number)]: [Value; 3] = + let [Value::U64(mut gas), system, Value::U64(block_number)]: [Value; 3] = args.try_into().unwrap() else { panic!() @@ -734,12 +736,12 @@ fn eval_get_block_hash( match result { Ok(res) => { - EvalAction::NormalBranch(0, smallvec![Value::U128(gas), system, Value::Felt(res)]) + EvalAction::NormalBranch(0, smallvec![Value::U64(gas), system, Value::Felt(res)]) } Err(e) => EvalAction::NormalBranch( 1, smallvec![ - Value::U128(gas), + Value::U64(gas), system, Value::Array { ty: error_felt_ty, @@ -756,7 +758,7 @@ fn eval_get_execution_info( args: Vec, syscall_handler: &mut impl StarknetSyscallHandler, ) -> EvalAction { - let [Value::U128(mut gas), system]: [Value; 2] = args.try_into().unwrap() else { + let [Value::U64(mut gas), system]: [Value; 2] = args.try_into().unwrap() else { panic!() }; // get felt type from the error branch array @@ -775,12 +777,12 @@ fn eval_get_execution_info( match result { Ok(res) => EvalAction::NormalBranch( 0, - smallvec![Value::U128(gas), system, res.into_value(felt_ty)], + smallvec![Value::U64(gas), system, res.into_value(felt_ty)], ), Err(e) => EvalAction::NormalBranch( 1, smallvec![ - Value::U128(gas), + Value::U64(gas), system, Value::Array { ty: felt_ty, @@ -797,7 +799,7 @@ fn eval_get_execution_info_v2( args: Vec, syscall_handler: &mut impl StarknetSyscallHandler, ) -> EvalAction { - let [Value::U128(mut gas), system]: [Value; 2] = args.try_into().unwrap() else { + let [Value::U64(mut gas), system]: [Value; 2] = args.try_into().unwrap() else { panic!() }; // get felt type from the error branch array @@ -854,7 +856,7 @@ fn eval_get_execution_info_v2( Ok(res) => EvalAction::NormalBranch( 0, smallvec![ - Value::U128(gas), + Value::U64(gas), system, res.into_value(felt_ty, out_ty_id.clone()) ], @@ -862,7 +864,7 @@ fn eval_get_execution_info_v2( Err(e) => EvalAction::NormalBranch( 1, smallvec![ - Value::U128(gas), + Value::U64(gas), system, Value::Array { ty: felt_ty, @@ -879,7 +881,7 @@ fn eval_deploy( args: Vec, syscall_handler: &mut impl StarknetSyscallHandler, ) -> EvalAction { - let [Value::U128(mut gas), system, Value::Felt(class_hash), Value::Felt(contract_address_salt), Value::Struct(calldata), Value::Enum { + let [Value::U64(mut gas), system, Value::Felt(class_hash), Value::Felt(contract_address_salt), Value::Struct(calldata), Value::Enum { self_ty: _, index: deploy_from_zero, payload: _, @@ -929,7 +931,7 @@ fn eval_deploy( Ok((contract_address, return_values)) => EvalAction::NormalBranch( 0, smallvec![ - Value::U128(gas), + Value::U64(gas), system, Value::Felt(contract_address), Value::Struct(vec![Value::Array { @@ -944,7 +946,7 @@ fn eval_deploy( Err(e) => EvalAction::NormalBranch( 1, smallvec![ - Value::U128(gas), + Value::U64(gas), system, Value::Array { ty: felt_ty, @@ -961,7 +963,7 @@ fn eval_keccak( args: Vec, syscall_handler: &mut impl StarknetSyscallHandler, ) -> EvalAction { - let [Value::U128(mut gas), system, Value::Struct(input)]: [Value; 3] = args.try_into().unwrap() + let [Value::U64(mut gas), system, Value::Struct(input)]: [Value; 3] = args.try_into().unwrap() else { panic!() }; @@ -993,12 +995,12 @@ fn eval_keccak( match result { Ok(res) => { - EvalAction::NormalBranch(0, smallvec![Value::U128(gas), system, res.into_value()]) + EvalAction::NormalBranch(0, smallvec![Value::U64(gas), system, res.into_value()]) } Err(e) => EvalAction::NormalBranch( 1, smallvec![ - Value::U128(gas), + Value::U64(gas), system, Value::Array { ty: felt_ty, @@ -1015,7 +1017,7 @@ fn eval_library_call( args: Vec, syscall_handler: &mut impl StarknetSyscallHandler, ) -> EvalAction { - let [Value::U128(mut gas), system, Value::Felt(class_hash), Value::Felt(function_selector), Value::Struct(calldata)]: [Value; 5] = + let [Value::U64(mut gas), system, Value::Felt(class_hash), Value::Felt(function_selector), Value::Struct(calldata)]: [Value; 5] = args.try_into().unwrap() else { panic!() @@ -1054,7 +1056,7 @@ fn eval_library_call( Ok(return_values) => EvalAction::NormalBranch( 0, smallvec![ - Value::U128(gas), + Value::U64(gas), system, Value::Struct(vec![Value::Array { ty: felt_ty, @@ -1068,7 +1070,7 @@ fn eval_library_call( Err(e) => EvalAction::NormalBranch( 1, smallvec![ - Value::U128(gas), + Value::U64(gas), system, Value::Array { ty: felt_ty, @@ -1085,7 +1087,7 @@ fn eval_replace_class( args: Vec, syscall_handler: &mut impl StarknetSyscallHandler, ) -> EvalAction { - let [Value::U128(mut gas), system, Value::Felt(class_hash)]: [Value; 3] = + let [Value::U64(mut gas), system, Value::Felt(class_hash)]: [Value; 3] = args.try_into().unwrap() else { panic!() @@ -1104,11 +1106,11 @@ fn eval_replace_class( let result = syscall_handler.replace_class(class_hash, &mut gas); match result { - Ok(()) => EvalAction::NormalBranch(0, smallvec![Value::U128(gas), system]), + Ok(()) => EvalAction::NormalBranch(0, smallvec![Value::U64(gas), system]), Err(e) => EvalAction::NormalBranch( 1, smallvec![ - Value::U128(gas), + Value::U64(gas), system, Value::Array { ty: felt_ty, @@ -1125,7 +1127,7 @@ fn eval_send_message_to_l1( args: Vec, syscall_handler: &mut impl StarknetSyscallHandler, ) -> EvalAction { - let [Value::U128(mut gas), system, Value::Felt(address), Value::Struct(payload)]: [Value; 4] = + let [Value::U64(mut gas), system, Value::Felt(address), Value::Struct(payload)]: [Value; 4] = args.try_into().unwrap() else { panic!() @@ -1161,11 +1163,11 @@ fn eval_send_message_to_l1( let result = syscall_handler.send_message_to_l1(address, payload, &mut gas); match result { - Ok(()) => EvalAction::NormalBranch(0, smallvec![Value::U128(gas), system]), + Ok(()) => EvalAction::NormalBranch(0, smallvec![Value::U64(gas), system]), Err(e) => EvalAction::NormalBranch( 1, smallvec![ - Value::U128(gas), + Value::U64(gas), system, Value::Array { ty: felt_ty, @@ -1204,7 +1206,7 @@ fn eval_sha256_process_block( args: Vec, syscall_handler: &mut impl StarknetSyscallHandler, ) -> EvalAction { - let [Value::U128(mut gas), system, Value::Struct(prev_state), Value::Struct(current_block)]: [Value; 4] = args.try_into().unwrap() else { + let [Value::U64(mut gas), system, Value::Struct(prev_state), Value::Struct(current_block)]: [Value; 4] = args.try_into().unwrap() else { panic!() }; @@ -1243,13 +1245,13 @@ fn eval_sha256_process_block( let payload = payload.into_iter().map(Value::U32).collect::>(); EvalAction::NormalBranch( 0, - smallvec![Value::U128(gas), system, Value::Struct(payload)], + smallvec![Value::U64(gas), system, Value::Struct(payload)], ) } Err(payload) => EvalAction::NormalBranch( 1, smallvec![ - Value::U128(gas), + Value::U64(gas), system, Value::Array { ty: felt_ty,