From f3d218cada2a60d2ac45c0b43fe6934fcd82e562 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Cauderlier?= Date: Mon, 21 Oct 2024 17:53:23 +0200 Subject: [PATCH 1/2] Etherlink/Tests helpers: originate delayed_transaction_bridge.tez when using old kernels --- etherlink/tezt/lib/contract_path.ml | 15 +++++++++++---- etherlink/tezt/lib/setup.ml | 8 +++++--- etherlink/tezt/lib/setup.mli | 7 ++++--- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/etherlink/tezt/lib/contract_path.ml b/etherlink/tezt/lib/contract_path.ml index 085a530c2b09..db7a6c2a9181 100644 --- a/etherlink/tezt/lib/contract_path.ml +++ b/etherlink/tezt/lib/contract_path.ml @@ -19,10 +19,17 @@ let withdrawal_abi_path () = let fa_withdrawal_abi_path () = Base.(project_root // "etherlink/tezos_contracts/fa_withdrawal.abi") -let delayed_path () = - Base.( - project_root - // "etherlink/tezos_contracts/chunked_delayed_transaction_bridge.tz") +let delayed_path ~kernel = + (* The path to the delayed transaction bridge depends on the version + of the kernel. The versions which don't support chunking must use + "delayed_transaction_bridge.tz", the versions which do support + chunking must use "chunked_delayed_transaction_bridge.tz" *) + let contract_basename = + match kernel with + | Kernel.Latest -> "chunked_delayed_transaction_bridge" + | Mainnet | Ghostnet -> "delayed_transaction_bridge" + in + Base.(project_root // sf "etherlink/tezos_contracts/%s.tz" contract_basename) let ticket_router_tester_path () = Base.( diff --git a/etherlink/tezt/lib/setup.ml b/etherlink/tezt/lib/setup.ml index 02c063463b6e..186d8593e2b7 100644 --- a/etherlink/tezt/lib/setup.ml +++ b/etherlink/tezt/lib/setup.ml @@ -40,14 +40,14 @@ let uses _protocol = Constant.smart_rollup_installer; ] -let setup_l1_contracts ?(dictator = Constant.bootstrap2) client = +let setup_l1_contracts ?(dictator = Constant.bootstrap2) ~kernel client = (* Originates the delayed transaction bridge. *) let* delayed_transaction_bridge = Client.originate_contract ~alias:"evm-seq-delayed-bridge" ~amount:Tez.zero ~src:Constant.bootstrap1.public_key_hash - ~prg:(delayed_path ()) + ~prg:(delayed_path ~kernel) ~burn_cap:Tez.one client in @@ -193,7 +193,9 @@ let setup_sequencer ?next_wasm_runtime ?block_storage_sqlite3 else none in let client = Client.with_dal_node client ?dal_node in - let* l1_contracts = setup_l1_contracts client in + let* l1_contracts = + setup_l1_contracts ~kernel:(Kernel.of_use kernel) client + in let sc_rollup_node = Sc_rollup_node.create ~default_operator:Constant.bootstrap1.public_key_hash diff --git a/etherlink/tezt/lib/setup.mli b/etherlink/tezt/lib/setup.mli index 84834c3b7401..2fcdd88ad4e5 100644 --- a/etherlink/tezt/lib/setup.mli +++ b/etherlink/tezt/lib/setup.mli @@ -33,9 +33,10 @@ type sequencer_setup = { (** [uses protocol] returns the list of dependencies for the tests. *) val uses : Protocol.t -> Uses.t list -(** [setup_l1_contracts ~dictator client] setups the necessary contracts for the - rollup. *) -val setup_l1_contracts : ?dictator:Account.key -> Client.t -> l1_contracts Lwt.t +(** [setup_l1_contracts ~dictator ~kernel client] setups the necessary + contracts for the rollup. *) +val setup_l1_contracts : + ?dictator:Account.key -> kernel:Kernel.t -> Client.t -> l1_contracts Lwt.t (** [run_new_rpc_endpoint node] starts a new rpc node following the setup. *) val run_new_rpc_endpoint : Evm_node.t -> Evm_node.t Lwt.t -- GitLab From 482bf5cacca4bd1e6c365e082b6d1d969f0f38be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Cauderlier?= Date: Mon, 21 Oct 2024 15:43:06 +0200 Subject: [PATCH 2/2] Etherlink/Contracts: remove special case of 1-chunk delayed tx --- .../chunked_delayed_transaction_bridge.mligo | 23 +++--- .../chunked_delayed_transaction_bridge.tz | 75 ++++++++----------- 2 files changed, 42 insertions(+), 56 deletions(-) diff --git a/etherlink/tezos_contracts/chunked_delayed_transaction_bridge.mligo b/etherlink/tezos_contracts/chunked_delayed_transaction_bridge.mligo index ee54065fca05..80c7e468430e 100644 --- a/etherlink/tezos_contracts/chunked_delayed_transaction_bridge.mligo +++ b/etherlink/tezos_contracts/chunked_delayed_transaction_bridge.mligo @@ -42,21 +42,18 @@ let main {transaction; evm_rollup} store : return = let chunks = chunk_bytes transaction in let n_chunks : nat = List.length chunks in let operations = - if n_chunks = 1n then - [Tezos.transaction (Other transaction) 0mutez evm_rollup] - else - // First message to announce the chunk bytes - let new_chunk_payload = Bytes.concat 0x00 (bytes n_chunks) in - let announce = - Tezos.transaction (Other new_chunk_payload) 0mutez evm_rollup - in - let chunks = - List.fold_left (fun (acc, chunk) -> + // First message to announce the chunk bytes + let new_chunk_payload = Bytes.concat 0x00 (bytes n_chunks) in + let announce = + Tezos.transaction (Other new_chunk_payload) 0mutez evm_rollup + in + let chunks = + List.fold_left (fun (acc, chunk) -> let chunk_payload = Bytes.concat 0x01 chunk in Tezos.transaction (Other chunk_payload) 0mutez evm_rollup :: acc) - [] chunks - in - announce :: chunks + [] chunks + in + announce :: chunks in // Burn the tez let burn_contract = diff --git a/etherlink/tezos_contracts/chunked_delayed_transaction_bridge.tz b/etherlink/tezos_contracts/chunked_delayed_transaction_bridge.tz index a1d9cfa7c17f..f18fc1e7537a 100644 --- a/etherlink/tezos_contracts/chunked_delayed_transaction_bridge.tz +++ b/etherlink/tezos_contracts/chunked_delayed_transaction_bridge.tz @@ -58,57 +58,46 @@ PAIR ; LEFT (list bytes) } } } ; SWAP ; + DIG 3 ; DIG 5 ; - DROP 2 ; + DROP 3 ; DUP ; SIZE ; - PUSH nat 1 ; - DUP 2 ; - COMPARE ; - EQ ; - IF { DROP 2 ; - NIL operation ; - SWAP ; - PUSH mutez 0 ; - DIG 3 ; - RIGHT (pair bytes (ticket (pair nat (option bytes)))) ; - LEFT bytes ; - TRANSFER_TOKENS } - { DIG 3 ; - DROP ; - BYTES ; - PUSH bytes 0x00 ; - PAIR ; - DUP 3 ; - PUSH mutez 0 ; - DIG 2 ; - UNPAIR ; - CONCAT ; - RIGHT (pair bytes (ticket (pair nat (option bytes)))) ; - LEFT bytes ; - TRANSFER_TOKENS ; - NIL operation ; - DIG 2 ; - ITER { SWAP ; - DUP 4 ; - PUSH mutez 0 ; - DIG 3 ; - PUSH bytes 0x01 ; - CONCAT ; - RIGHT (pair bytes (ticket (pair nat (option bytes)))) ; - LEFT bytes ; - TRANSFER_TOKENS ; - CONS } ; - DIG 2 ; - DROP ; - SWAP } ; - CONS ; + BYTES ; + PUSH bytes 0x00 ; + PAIR ; + DUP 3 ; + PUSH mutez 0 ; + DIG 2 ; + UNPAIR ; + CONCAT ; + RIGHT (pair bytes (ticket (pair nat (option bytes)))) ; + LEFT bytes ; + TRANSFER_TOKENS ; + NIL operation ; + DIG 2 ; + ITER { SWAP ; + DUP 4 ; + PUSH mutez 0 ; + DIG 3 ; + PUSH bytes 0x01 ; + CONCAT ; + RIGHT (pair bytes (ticket (pair nat (option bytes)))) ; + LEFT bytes ; + TRANSFER_TOKENS ; + CONS } ; + DIG 2 ; + DROP ; PUSH address "tz1burnburnburnburnburnburnburjAYjjX" ; CONTRACT unit ; IF_NONE { PUSH string "Invalid burn address" ; FAILWITH } {} ; PUSH mutez 1000000 ; UNIT ; TRANSFER_TOKENS ; + DIG 3 ; + DIG 2 ; + DIG 3 ; + CONS ; + DIG 2 ; CONS ; PAIR } } } - -- GitLab