From 2ced225145a76c41a828eee58ab3a8fc60c533e2 Mon Sep 17 00:00:00 2001 From: Pierre-Louis Date: Fri, 15 Dec 2023 19:16:52 +0100 Subject: [PATCH 1/2] evm/kernel: add deposit in the delayed inbox --- .../kernel_evm/kernel/src/delayed_inbox.rs | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/etherlink/kernel_evm/kernel/src/delayed_inbox.rs b/etherlink/kernel_evm/kernel/src/delayed_inbox.rs index dbb0c8952a78..7b8d782119dc 100644 --- a/etherlink/kernel_evm/kernel/src/delayed_inbox.rs +++ b/etherlink/kernel_evm/kernel/src/delayed_inbox.rs @@ -1,13 +1,14 @@ // SPDX-FileCopyrightText: 2023 Marigold use crate::{ - inbox::{Transaction, TransactionContent}, + inbox::{Deposit, Transaction, TransactionContent}, linked_list::LinkedList, }; use anyhow::Result; use rlp::{Decodable, DecoderError, Encodable}; use tezos_ethereum::{ - transaction::TRANSACTION_HASH_SIZE, tx_common::EthereumTransactionCommon, + rlp_helpers::FromRlpBytes, transaction::TRANSACTION_HASH_SIZE, + tx_common::EthereumTransactionCommon, }; use tezos_smart_rollup_host::{path::RefPath, runtime::Runtime}; @@ -15,9 +16,12 @@ pub struct DelayedInbox(LinkedList); pub const DELAYED_INBOX_PATH: RefPath = RefPath::assert_from(b"/delayed-inbox"); -// Tags that indicates the delayed transaction is a eth transaction. +// Tag that indicates the delayed transaction is a eth transaction. pub const DELAYED_TRANSACTION_TAG: u8 = 0x00; +// Tag that indicates the delayed transaction is a deposit. +pub const DELAYED_DEPOSIT_TAG: u8 = 0x01; + /// Hash of a transaction /// /// It represents the key of the transaction in the delayed inbox. @@ -47,12 +51,13 @@ impl AsRef<[u8]> for Hash { } /// Delayed transaction -/// Later it might be turn into a struct +/// Later it might be turned into a struct /// And fields like the timestamp might be added #[allow(clippy::large_enum_variant)] #[derive(Clone)] pub enum DelayedTransaction { Ethereum(EthereumTransactionCommon), + Deposit(Deposit), } impl Encodable for DelayedTransaction { @@ -63,6 +68,10 @@ impl Encodable for DelayedTransaction { stream.append(&DELAYED_TRANSACTION_TAG); stream.append(&delayed_tx.to_bytes()); } + DelayedTransaction::Deposit(delayed_deposit) => { + stream.append(&DELAYED_DEPOSIT_TAG); + stream.append(delayed_deposit); + } } } } @@ -83,6 +92,11 @@ impl Decodable for DelayedTransaction { let delayed_tx = EthereumTransactionCommon::from_bytes(&payload)?; Ok(Self::Ethereum(delayed_tx)) } + DELAYED_DEPOSIT_TAG => { + let payload: Vec = payload.as_val()?; + let delayed_tx = FromRlpBytes::from_rlp_bytes(&payload)?; + Ok(DelayedTransaction::Deposit(delayed_tx)) + } _ => Err(DecoderError::Custom("unknown tag")), } } @@ -102,10 +116,7 @@ impl DelayedInbox { let Transaction { tx_hash, content } = tx; let delayed_transaction = match content { TransactionContent::Ethereum(tx) => DelayedTransaction::Ethereum(tx), - _ => { - // not yet supported - return Ok(()); - } + TransactionContent::Deposit(deposit) => DelayedTransaction::Deposit(deposit), }; self.0.push(host, &Hash(tx_hash), &delayed_transaction)?; Ok(()) -- GitLab From a0a6af2f1736d2cd3bfcc2701e131b1eed740062 Mon Sep 17 00:00:00 2001 From: Pierre-Louis Date: Fri, 15 Dec 2023 19:19:46 +0100 Subject: [PATCH 2/2] evm/sequencer: test send deposit to delayted inbox --- tezt/lib_ethereum/contract_path.ml | 23 ++++++ tezt/tests/evm_rollup.ml | 13 +--- tezt/tests/evm_sequencer.ml | 110 ++++++++++++++++++++++++++--- 3 files changed, 124 insertions(+), 22 deletions(-) create mode 100644 tezt/lib_ethereum/contract_path.ml diff --git a/tezt/lib_ethereum/contract_path.ml b/tezt/lib_ethereum/contract_path.ml new file mode 100644 index 000000000000..fd7fd31e3783 --- /dev/null +++ b/tezt/lib_ethereum/contract_path.ml @@ -0,0 +1,23 @@ +(*****************************************************************************) +(* *) +(* SPDX-License-Identifier: MIT *) +(* Copyright (c) 2024 Nomadic Labs *) +(* *) +(*****************************************************************************) + +let exchanger_path () = + Base.(project_root // "etherlink/kernel_evm/l1_bridge/exchanger.tz") + +let bridge_path () = + Base.(project_root // "etherlink/kernel_evm/l1_bridge/evm_bridge.tz") + +let admin_path () = + Base.(project_root // "etherlink/kernel_evm/l1_bridge/admin.tz") + +let withdrawal_abi_path () = + Base.(project_root // "etherlink/kernel_evm/l1_bridge/withdrawal.abi") + +let delayed_path () = + Base.( + project_root + // "etherlink/kernel_evm/l1_bridge/delayed_transaction_bridge.tz") diff --git a/tezt/tests/evm_rollup.ml b/tezt/tests/evm_rollup.ml index efbcf9c7a154..b035d667c5bb 100644 --- a/tezt/tests/evm_rollup.ml +++ b/tezt/tests/evm_rollup.ml @@ -18,23 +18,12 @@ open Sc_rollup_helpers open Helpers open Rpc.Syntax +open Contract_path let pvm_kind = "wasm_2_0_0" let kernel_inputs_path = "tezt/tests/evm_kernel_inputs" -let exchanger_path () = - Base.(project_root // "etherlink/kernel_evm/l1_bridge/exchanger.tz") - -let bridge_path () = - Base.(project_root // "etherlink/kernel_evm/l1_bridge/evm_bridge.tz") - -let admin_path () = - Base.(project_root // "etherlink/kernel_evm/l1_bridge/admin.tz") - -let withdrawal_abi_path () = - Base.(project_root // "etherlink/kernel_evm/l1_bridge/withdrawal.abi") - type l1_contracts = {exchanger : string; bridge : string; admin : string} type full_evm_setup = { diff --git a/tezt/tests/evm_sequencer.ml b/tezt/tests/evm_sequencer.ml index 060e4aa1805d..5a05c7bd21f7 100644 --- a/tezt/tests/evm_sequencer.ml +++ b/tezt/tests/evm_sequencer.ml @@ -7,6 +7,7 @@ open Sc_rollup_helpers open Rpc.Syntax +open Contract_path let uses _protocol = [ @@ -18,9 +19,13 @@ let uses _protocol = (** Renaming the helper to avoid confusion on its behavior. *) let next_rollup_node_level = Helpers.next_evm_level -type l1_contracts = {delayed_transaction_bridge : string} +type l1_contracts = { + delayed_transaction_bridge : string; + exchanger : string; + bridge : string; +} -type setup = { +type sequencer_setup = { node : Node.t; client : Client.t; sc_rollup_address : string; @@ -29,11 +34,6 @@ type setup = { l1_contracts : l1_contracts; } -let delayed_path () = - Base.( - project_root - // "etherlink/kernel_evm/l1_bridge/delayed_transaction_bridge.tz") - let setup_l1_contracts client = (* Originates the delayed transaction bridge. *) let* delayed_transaction_bridge = @@ -46,8 +46,31 @@ let setup_l1_contracts client = client in let* () = Client.bake_for_and_wait client in - - return {delayed_transaction_bridge} + (* Originates the exchanger. *) + let* exchanger = + Client.originate_contract + ~alias:"exchanger" + ~amount:Tez.zero + ~src:Constant.bootstrap1.public_key_hash + ~init:"Unit" + ~prg:(exchanger_path ()) + ~burn_cap:Tez.one + client + in + let* () = Client.bake_for_and_wait client in + (* Originates the bridge. *) + let* bridge = + Client.originate_contract + ~alias:"evm-bridge" + ~amount:Tez.zero + ~src:Constant.bootstrap1.public_key_hash + ~init:(sf "Pair %S None" exchanger) + ~prg:(bridge_path ()) + ~burn_cap:Tez.one + client + in + let* () = Client.bake_for_and_wait client in + return {delayed_transaction_bridge; exchanger; bridge} let setup_sequencer ?(bootstrap_accounts = Eth_account.bootstrap_accounts) protocol = @@ -66,6 +89,7 @@ let setup_sequencer ?(bootstrap_accounts = Eth_account.bootstrap_accounts) ~bootstrap_accounts ~sequencer:true ~delayed_bridge:l1_contracts.delayed_transaction_bridge + ~ticketer:l1_contracts.exchanger () in let* {output; _} = @@ -116,6 +140,22 @@ let send_raw_transaction_to_delayed_inbox ?(amount = Tez.one) ?expect_failure let* _ = next_rollup_node_level ~sc_rollup_node ~node ~client in Lwt.return expected_hash +let send_deposit_to_delayed_inbox ~amount ~l1_contracts ~depositor ~receiver + ~sc_rollup_node ~sc_rollup_address ~node client = + let* () = + Client.transfer + ~entrypoint:"deposit" + ~arg:(sf "Pair %S %s" sc_rollup_address receiver) + ~amount + ~giver:depositor.Account.public_key_hash + ~receiver:l1_contracts.bridge + ~burn_cap:Tez.one + client + in + let* () = Client.bake_for_and_wait client in + let* _ = next_rollup_node_level ~sc_rollup_node ~node ~client in + unit + let test_persistent_state = Protocol.register_test ~__FILE__ @@ -229,7 +269,57 @@ let test_send_transaction_to_delayed_inbox = in unit +let test_send_deposit_to_delayed_inbox = + Protocol.register_test + ~__FILE__ + ~tags:["evm"; "sequencer"; "delayed_inbox"; "deposit"] + ~title:"Send a deposit to the delayed inbox" + ~uses + @@ fun protocol -> + let* {client; node; l1_contracts; sc_rollup_address; sc_rollup_node; _} = + setup_sequencer protocol + in + let amount = Tez.of_int 16 in + let depositor = Constant.bootstrap5 in + let receiver = + Eth_account. + { + address = "0x1074Fd1EC02cbeaa5A90450505cF3B48D834f3EB"; + private_key = + "0xb7c548b5442f5b28236f0dcd619f65aaaafd952240908adcf9642d8e616587ee"; + public_key = + "0466ed90f9a86c0908746475fbe0a40c72237de22d89076302e22c2a8da259b4aba5c7ee1f3dc3fd0b240645462620ae62b6fe8fe5b3464c3b1b4ae6c06c97b7b6"; + } + in + let* () = + send_deposit_to_delayed_inbox + ~amount + ~l1_contracts + ~depositor + ~receiver:receiver.address + ~sc_rollup_node + ~sc_rollup_address + ~node + client + in + let* delayed_transactions_hashes = + Sc_rollup_node.RPC.call sc_rollup_node + @@ Sc_rollup_rpc.get_global_block_durable_state_value + ~pvm_kind:"wasm_2_0_0" + ~operation:Sc_rollup_rpc.Subkeys + ~key:"/evm/delayed-inbox" + () + in + Check.( + list_mem + string + "a07feb67aff94089c8d944f5f8ffb5acc37306da9102fc310264e90999a42eb1" + delayed_transactions_hashes) + ~error_msg:"the deposit is not present in the delayed inbox" ; + unit + let register ~protocols = test_persistent_state protocols ; test_publish_blueprints protocols ; - test_send_transaction_to_delayed_inbox protocols + test_send_transaction_to_delayed_inbox protocols ; + test_send_deposit_to_delayed_inbox protocols -- GitLab