From 8662cddd31463043f05c6c4767678495d5610410 Mon Sep 17 00:00:00 2001 From: Valentin Chaboche Date: Fri, 20 Sep 2024 13:18:22 +0200 Subject: [PATCH 1/2] Etherlink: simulation uses a 0 transfer instead of null --- etherlink/bin_node/lib_dev/simulation.ml | 33 +++++++++++++++++++ etherlink/kernel_evm/kernel/src/simulation.rs | 2 +- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/etherlink/bin_node/lib_dev/simulation.ml b/etherlink/bin_node/lib_dev/simulation.ml index 24ef74d874d7..de5643672d73 100644 --- a/etherlink/bin_node/lib_dev/simulation.ml +++ b/etherlink/bin_node/lib_dev/simulation.ml @@ -98,6 +98,39 @@ let rlp_v2 ({call; with_da_fees; timestamp} : estimate_gas_input_v2) = (** Encoding used to forward the call to the kernel, to be used in simulation mode only. *) let rlp_encode input = + let input = + (* If the value is not provided, the kernel will put `None` for the transfer + object. It is not wanted, we want the kernel to put `Some(0)` instead. *) + match input with + | V0 call -> + V0 + { + call with + value = Some (Option.value ~default:(Qty Z.zero) call.value); + } + | V1 {call; with_da_fees} -> + V1 + { + call = + { + call with + value = Some (Option.value ~default:(Qty Z.zero) call.value); + }; + with_da_fees; + } + | V2 {call; with_da_fees; timestamp} -> + V2 + { + call = + { + call with + value = Some (Option.value ~default:(Qty Z.zero) call.value); + }; + with_da_fees; + timestamp; + } + in + let prefix, rlp = match input with | V0 call -> (None, rlp_v0 call) diff --git a/etherlink/kernel_evm/kernel/src/simulation.rs b/etherlink/kernel_evm/kernel/src/simulation.rs index 7e5b3d1d69d1..3436ec660b68 100644 --- a/etherlink/kernel_evm/kernel/src/simulation.rs +++ b/etherlink/kernel_evm/kernel/src/simulation.rs @@ -468,7 +468,7 @@ impl Evaluation { Some(u64::min(gas, MAXIMUM_GAS_LIMIT)) }), gas_price, - self.value, + Some(self.value.unwrap_or_default()), false, allocated_ticks, false, -- GitLab From c6da68309bbcbf372b7fc669d994f989a6671b4d Mon Sep 17 00:00:00 2001 From: Valentin Chaboche Date: Mon, 23 Sep 2024 16:32:30 +0200 Subject: [PATCH 2/2] EVM/Kernel: run_transaction always takes a value --- .../kernel_evm/evm_evaluation/src/runner.rs | 2 +- .../evm_execution/src/fa_bridge/test_utils.rs | 2 +- etherlink/kernel_evm/evm_execution/src/lib.rs | 108 +++++++++--------- etherlink/kernel_evm/kernel/src/apply.rs | 2 +- etherlink/kernel_evm/kernel/src/simulation.rs | 6 +- 5 files changed, 63 insertions(+), 57 deletions(-) diff --git a/etherlink/kernel_evm/evm_evaluation/src/runner.rs b/etherlink/kernel_evm/evm_evaluation/src/runner.rs index dd686f7d8c69..db46bc957dad 100644 --- a/etherlink/kernel_evm/evm_evaluation/src/runner.rs +++ b/etherlink/kernel_evm/evm_evaluation/src/runner.rs @@ -238,7 +238,7 @@ fn execute_transaction( call_data, Some(gas_limit), env.tx.gas_price, - Some(transaction_value), + transaction_value, pay_for_gas, u64::MAX, // don't account for ticks during the test false, diff --git a/etherlink/kernel_evm/evm_execution/src/fa_bridge/test_utils.rs b/etherlink/kernel_evm/evm_execution/src/fa_bridge/test_utils.rs index ed9860258ffc..84fd8cc36b8e 100644 --- a/etherlink/kernel_evm/evm_execution/src/fa_bridge/test_utils.rs +++ b/etherlink/kernel_evm/evm_execution/src/fa_bridge/test_utils.rs @@ -81,7 +81,7 @@ pub fn deploy_mock_wrapper( [code, calldata.abi_encode()].concat(), Some(300_000), U256::one(), - None, + U256::zero(), false, 1_000_000_000, false, diff --git a/etherlink/kernel_evm/evm_execution/src/lib.rs b/etherlink/kernel_evm/evm_execution/src/lib.rs index 408b2a152b28..efff45a85120 100755 --- a/etherlink/kernel_evm/evm_execution/src/lib.rs +++ b/etherlink/kernel_evm/evm_execution/src/lib.rs @@ -258,7 +258,7 @@ pub fn run_transaction<'a, Host>( call_data: Vec, gas_limit: Option, effective_gas_price: U256, - value: Option, + value: U256, pay_for_gas: bool, allocated_ticks: u64, retriable: bool, @@ -301,14 +301,20 @@ where { let (result, base_call_type) = if let Some(address) = address { ( - handler - .call_contract(caller, address, value, call_data, gas_limit, false), + handler.call_contract( + caller, + address, + Some(value), + call_data, + gas_limit, + false, + ), "CALL", ) } else { // This is a create-contract transaction ( - handler.create_contract(caller, value, call_data, gas_limit), + handler.create_contract(caller, Some(value), call_data, gas_limit), "CREATE", ) }; @@ -365,7 +371,7 @@ where call_data, caller, address, - value, + Some(value), gas_limit, with_logs, &result, @@ -395,7 +401,7 @@ where call_data, caller, address, - value, + Some(value), gas_limit, &e, transaction_hash, @@ -621,7 +627,7 @@ mod test { call_data, Some(22000), gas_price, - Some(transaction_value), + transaction_value, true, DUMMY_ALLOCATED_TICKS, false, @@ -686,7 +692,7 @@ mod test { call_data, Some(21000), gas_price, - Some(transaction_value), + transaction_value, true, DUMMY_ALLOCATED_TICKS, false, @@ -745,7 +751,7 @@ mod test { call_data, None, gas_price, - Some(transaction_value), + transaction_value, true, DUMMY_ALLOCATED_TICKS, false, @@ -801,7 +807,7 @@ mod test { call_data, Some(gas_limit), gas_price, - Some(transaction_value), + transaction_value, true, DUMMY_ALLOCATED_TICKS, false, @@ -839,7 +845,7 @@ mod test { call_data2, Some(31000), gas_price, - Some(U256::zero()), + U256::zero(), true, DUMMY_ALLOCATED_TICKS, false, @@ -873,7 +879,7 @@ mod test { call_data_set, Some(100000), gas_price, - Some(U256::zero()), + U256::zero(), true, DUMMY_ALLOCATED_TICKS, false, @@ -906,7 +912,7 @@ mod test { hex::decode(STORAGE_CONTRACT_CALL_NUM).unwrap(), Some(31000), gas_price, - Some(U256::zero()), + U256::zero(), true, DUMMY_ALLOCATED_TICKS, false, @@ -966,7 +972,7 @@ mod test { call_data, Some(gas_limit), gas_price, - Some(transaction_value), + transaction_value, true, DUMMY_ALLOCATED_TICKS, false, @@ -1019,7 +1025,7 @@ mod test { call_data, None, gas_price, - Some(transaction_value), + transaction_value, true, DUMMY_ALLOCATED_TICKS, false, @@ -1072,7 +1078,7 @@ mod test { vec![], Some(22000), gas_price, - None, + U256::zero(), true, DUMMY_ALLOCATED_TICKS, false, @@ -1218,7 +1224,7 @@ mod test { vec![], Some(all_the_gas), gas_price, - None, + U256::zero(), true, DUMMY_ALLOCATED_TICKS, false, @@ -1281,7 +1287,7 @@ mod test { vec![], Some(init_balance), gas_price, - None, + U256::zero(), true, DUMMY_ALLOCATED_TICKS, false, @@ -1343,7 +1349,7 @@ mod test { vec![], None, gas_price, - None, + U256::zero(), true, DUMMY_ALLOCATED_TICKS, false, @@ -1400,7 +1406,7 @@ mod test { vec![], None, gas_price, - Some(U256::from(100)), + U256::from(100), true, DUMMY_ALLOCATED_TICKS, false, @@ -1458,7 +1464,7 @@ mod test { data.to_vec(), Some(22001), gas_price, - None, + U256::zero(), true, DUMMY_ALLOCATED_TICKS, false, @@ -1518,7 +1524,7 @@ mod test { data.to_vec(), Some(gas_limit), gas_price, - None, + U256::zero(), true, DUMMY_ALLOCATED_TICKS, false, @@ -1633,7 +1639,7 @@ mod test { vec![], None, gas_price, - None, + U256::zero(), true, DUMMY_ALLOCATED_TICKS, false, @@ -1714,7 +1720,7 @@ mod test { vec![], Some(all_the_gas), gas_price, - None, + U256::zero(), true, DUMMY_ALLOCATED_TICKS, false, @@ -1807,7 +1813,7 @@ mod test { vec![], Some(all_the_gas), gas_price, - None, + U256::zero(), true, DUMMY_ALLOCATED_TICKS, false, @@ -1922,7 +1928,7 @@ mod test { vec![], Some(all_the_gas), gas_price, - None, + U256::zero(), true, 1_000_000_000, false, @@ -2034,7 +2040,7 @@ mod test { vec![], Some(all_the_gas), gas_price, - None, + U256::zero(), true, DUMMY_ALLOCATED_TICKS, false, @@ -2135,7 +2141,7 @@ mod test { vec![], Some(all_the_gas), gas_price, - None, + U256::zero(), true, DUMMY_ALLOCATED_TICKS, false, @@ -2252,7 +2258,7 @@ mod test { vec![], Some(all_the_gas), gas_price, - None, + U256::zero(), true, 10_000_000_000, false, @@ -2350,7 +2356,7 @@ mod test { vec![], Some(all_the_gas), gas_price, - None, + U256::zero(), true, DUMMY_ALLOCATED_TICKS, false, @@ -2435,7 +2441,7 @@ mod test { vec![], Some(all_the_gas), gas_price, - None, + U256::zero(), true, DUMMY_ALLOCATED_TICKS, false, @@ -2516,7 +2522,7 @@ mod test { vec![], None, gas_price, - Some(U256::from(100)), + U256::from(100), true, DUMMY_ALLOCATED_TICKS, false, @@ -2568,7 +2574,7 @@ mod test { call_data, Some(gas_limit), gas_price, - Some(transaction_value), + transaction_value, true, DUMMY_ALLOCATED_TICKS, false, @@ -2626,7 +2632,7 @@ mod test { create_data, Some(gas_limit), gas_price, - Some(transaction_value), + transaction_value, true, DUMMY_ALLOCATED_TICKS, false, @@ -2699,7 +2705,7 @@ mod test { data.to_vec(), Some(all_the_gas), gas_price, - None, + U256::zero(), true, DUMMY_ALLOCATED_TICKS, false, @@ -2769,7 +2775,7 @@ mod test { data.to_vec(), Some(all_the_gas), gas_price, - None, + U256::zero(), true, DUMMY_ALLOCATED_TICKS, false, @@ -2834,7 +2840,7 @@ mod test { data.to_vec(), Some(all_the_gas), gas_price, - None, + U256::zero(), true, DUMMY_ALLOCATED_TICKS, false, @@ -2939,7 +2945,7 @@ mod test { call_data, Some(gas_limit), gas_price, - None, + U256::zero(), true, 10_000_000_000, false, @@ -3022,7 +3028,7 @@ mod test { init_code, Some(gas_limit), gas_price, - None, + U256::zero(), true, 10_000_000_000, false, @@ -3132,7 +3138,7 @@ mod test { init_code, Some(gas_limit), gas_price, - None, + U256::zero(), true, 10_000_000_000, false, @@ -3213,7 +3219,7 @@ mod test { call_data, Some(gas_limit), gas_price, - None, + U256::zero(), true, 10_000_000_000, false, @@ -3261,7 +3267,7 @@ mod test { call_data, Some(gas_limit), gas_price, - Some(transaction_value), + transaction_value, true, DUMMY_ALLOCATED_TICKS, false, @@ -3317,7 +3323,7 @@ mod test { vec![], Some(20000000), U256::one(), - Some(U256::zero()), + U256::zero(), true, DUMMY_ALLOCATED_TICKS, false, @@ -3407,7 +3413,7 @@ mod test { code, Some(20000000), U256::one(), - Some(U256::zero()), + U256::zero(), true, DUMMY_ALLOCATED_TICKS, false, @@ -3506,7 +3512,7 @@ mod test { call_data, Some(gas_limit), gas_price, - Some(transaction_value), + transaction_value, true, 10_000, retriable, @@ -3638,7 +3644,7 @@ mod test { // gas limit comes from GeneralStateTests/stRevertTest/LoopCallsDepthThenRevert3.json Some(9214364837600034817), U256::one(), - None, + U256::zero(), false, u64::MAX, false, @@ -3724,7 +3730,7 @@ mod test { vec![], Some(9214364837600034817), // gas limit comes from GeneralStateTests/stRevertTest/LoopCallsDepthThenRevert3.json U256::one(), - None, + U256::zero(), false, u64::MAX, false, @@ -3764,7 +3770,7 @@ mod test { code, Some(u64::MAX), U256::one(), - None, + U256::zero(), false, u64::MAX, false, @@ -3845,7 +3851,7 @@ mod test { call_data, Some(15000000), U256::from(10), - None, + U256::zero(), true, DUMMY_ALLOCATED_TICKS * 100, false, @@ -3936,7 +3942,7 @@ mod test { call_data, Some(200000), U256::from(10), - None, + U256::zero(), true, DUMMY_ALLOCATED_TICKS, false, @@ -3997,7 +4003,7 @@ mod test { vec![], None, U256::one(), - None, + U256::zero(), false, DUMMY_ALLOCATED_TICKS, false, diff --git a/etherlink/kernel_evm/kernel/src/apply.rs b/etherlink/kernel_evm/kernel/src/apply.rs index 03b4ddd22e97..7795a091850b 100644 --- a/etherlink/kernel_evm/kernel/src/apply.rs +++ b/etherlink/kernel_evm/kernel/src/apply.rs @@ -351,7 +351,7 @@ fn apply_ethereum_transaction_common( call_data, Some(gas_limit), effective_gas_price, - Some(value), + value, true, allocated_ticks, retriable, diff --git a/etherlink/kernel_evm/kernel/src/simulation.rs b/etherlink/kernel_evm/kernel/src/simulation.rs index 3436ec660b68..a8f9d9b7afa6 100644 --- a/etherlink/kernel_evm/kernel/src/simulation.rs +++ b/etherlink/kernel_evm/kernel/src/simulation.rs @@ -468,7 +468,7 @@ impl Evaluation { Some(u64::min(gas, MAXIMUM_GAS_LIMIT)) }), gas_price, - Some(self.value.unwrap_or_default()), + self.value.unwrap_or_default(), false, allocated_ticks, false, @@ -574,7 +574,7 @@ impl TxValidation { transaction.data.clone(), Some(gas_limit), // gas could be omitted block_fees.base_fee_per_gas(), - Some(transaction.value), + transaction.value, true, allocated_ticks, false, @@ -934,7 +934,7 @@ mod tests { call_data, Some(gas_limit), gas_price, - Some(transaction_value), + transaction_value, false, DUMMY_ALLOCATED_TICKS, false, -- GitLab