From 1be8fc309a150d65e41dbb0cfb590f5b533e7700 Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Tue, 17 May 2022 11:24:33 +0200 Subject: [PATCH 1/8] Proto/Sc_rollup_repr: move Staker after t-related things --- src/proto_alpha/lib_protocol/sc_rollup_repr.ml | 4 ++-- src/proto_alpha/lib_protocol/sc_rollup_repr.mli | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/proto_alpha/lib_protocol/sc_rollup_repr.ml b/src/proto_alpha/lib_protocol/sc_rollup_repr.ml index 3a9b343ded22..022a2830d5b8 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_repr.ml +++ b/src/proto_alpha/lib_protocol/sc_rollup_repr.ml @@ -111,8 +111,6 @@ end type t = Address.t -module Staker = Signature.Public_key_hash - let description = "A smart contract rollup is identified by a base58 address starting with " ^ Address.prefix @@ -164,6 +162,8 @@ let rpc_arg = ~destruct () +module Staker = Signature.Public_key_hash + module Index = struct type t = Address.t diff --git a/src/proto_alpha/lib_protocol/sc_rollup_repr.mli b/src/proto_alpha/lib_protocol/sc_rollup_repr.mli index 2f7229e31336..8095d1fafa56 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_repr.mli +++ b/src/proto_alpha/lib_protocol/sc_rollup_repr.mli @@ -75,16 +75,16 @@ module Number_of_ticks : Bounded.Int32.S (** A smart contract rollup is identified by its address. *) type t = Address.t -(** A [Staker] is an implicit account, identified by its public key hash. *) -module Staker : - S.SIGNATURE_PUBLIC_KEY_HASH with type t = Signature.Public_key_hash.t - val encoding : t Data_encoding.t val rpc_arg : t RPC_arg.t val pp : Format.formatter -> t -> unit +(** A [Staker] is an implicit account, identified by its public key hash. *) +module Staker : + S.SIGNATURE_PUBLIC_KEY_HASH with type t = Signature.Public_key_hash.t + (** The data model uses an index of these addresses. *) module Index : Storage_description.INDEX with type t = Address.t -- GitLab From ea27b0aed7f532e0c509b4ff3fd83e4f71277e37 Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Tue, 17 May 2022 11:45:24 +0200 Subject: [PATCH 2/8] Proto: move modules --- src/proto_alpha/lib_protocol/TEZOS_PROTOCOL | 6 ++--- src/proto_alpha/lib_protocol/dune | 30 ++++++++++----------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/proto_alpha/lib_protocol/TEZOS_PROTOCOL b/src/proto_alpha/lib_protocol/TEZOS_PROTOCOL index 6d543cc1a6c0..0a8af4e50aaf 100644 --- a/src/proto_alpha/lib_protocol/TEZOS_PROTOCOL +++ b/src/proto_alpha/lib_protocol/TEZOS_PROTOCOL @@ -17,6 +17,7 @@ "Merkle_list", "Bitset", + "Michelson_v1_primitives", "Slot_repr", "Tez_repr", "Period_repr", @@ -34,6 +35,8 @@ "Fitness_repr", "Cycle_repr", "Level_repr", + "Script_repr", + "Cache_memory_helpers", "Sc_rollup_repr", "Skip_list_repr", "Sc_rollup_inbox_repr", @@ -44,9 +47,6 @@ "Sampler", "Voting_period_repr", "Ticket_hash_repr", - "Michelson_v1_primitives", - "Script_repr", - "Cache_memory_helpers", "Contract_repr", "Indexable", "Entrypoint_repr", diff --git a/src/proto_alpha/lib_protocol/dune b/src/proto_alpha/lib_protocol/dune index 77b107fe2f60..2679c5eea843 100644 --- a/src/proto_alpha/lib_protocol/dune +++ b/src/proto_alpha/lib_protocol/dune @@ -48,6 +48,7 @@ Tx_rollup_prefixes Merkle_list Bitset + Michelson_v1_primitives Slot_repr Tez_repr Period_repr @@ -65,6 +66,8 @@ Fitness_repr Cycle_repr Level_repr + Script_repr + Cache_memory_helpers Sc_rollup_repr Skip_list_repr Sc_rollup_inbox_repr @@ -75,9 +78,6 @@ Sampler Voting_period_repr Ticket_hash_repr - Michelson_v1_primitives - Script_repr - Cache_memory_helpers Contract_repr Indexable Entrypoint_repr @@ -259,6 +259,7 @@ tx_rollup_prefixes.ml tx_rollup_prefixes.mli merkle_list.ml merkle_list.mli bitset.ml bitset.mli + michelson_v1_primitives.ml michelson_v1_primitives.mli slot_repr.ml slot_repr.mli tez_repr.ml tez_repr.mli period_repr.ml period_repr.mli @@ -277,6 +278,8 @@ fitness_repr.ml fitness_repr.mli cycle_repr.ml cycle_repr.mli level_repr.ml level_repr.mli + script_repr.ml script_repr.mli + cache_memory_helpers.ml sc_rollup_repr.ml sc_rollup_repr.mli skip_list_repr.ml skip_list_repr.mli sc_rollup_inbox_repr.ml sc_rollup_inbox_repr.mli @@ -287,9 +290,6 @@ sampler.ml sampler.mli voting_period_repr.ml voting_period_repr.mli ticket_hash_repr.ml ticket_hash_repr.mli - michelson_v1_primitives.ml michelson_v1_primitives.mli - script_repr.ml script_repr.mli - cache_memory_helpers.ml contract_repr.ml contract_repr.mli indexable.ml indexable.mli entrypoint_repr.ml entrypoint_repr.mli @@ -458,6 +458,7 @@ tx_rollup_prefixes.ml tx_rollup_prefixes.mli merkle_list.ml merkle_list.mli bitset.ml bitset.mli + michelson_v1_primitives.ml michelson_v1_primitives.mli slot_repr.ml slot_repr.mli tez_repr.ml tez_repr.mli period_repr.ml period_repr.mli @@ -476,6 +477,8 @@ fitness_repr.ml fitness_repr.mli cycle_repr.ml cycle_repr.mli level_repr.ml level_repr.mli + script_repr.ml script_repr.mli + cache_memory_helpers.ml sc_rollup_repr.ml sc_rollup_repr.mli skip_list_repr.ml skip_list_repr.mli sc_rollup_inbox_repr.ml sc_rollup_inbox_repr.mli @@ -486,9 +489,6 @@ sampler.ml sampler.mli voting_period_repr.ml voting_period_repr.mli ticket_hash_repr.ml ticket_hash_repr.mli - michelson_v1_primitives.ml michelson_v1_primitives.mli - script_repr.ml script_repr.mli - cache_memory_helpers.ml contract_repr.ml contract_repr.mli indexable.ml indexable.mli entrypoint_repr.ml entrypoint_repr.mli @@ -678,6 +678,7 @@ tx_rollup_prefixes.ml tx_rollup_prefixes.mli merkle_list.ml merkle_list.mli bitset.ml bitset.mli + michelson_v1_primitives.ml michelson_v1_primitives.mli slot_repr.ml slot_repr.mli tez_repr.ml tez_repr.mli period_repr.ml period_repr.mli @@ -696,6 +697,8 @@ fitness_repr.ml fitness_repr.mli cycle_repr.ml cycle_repr.mli level_repr.ml level_repr.mli + script_repr.ml script_repr.mli + cache_memory_helpers.ml sc_rollup_repr.ml sc_rollup_repr.mli skip_list_repr.ml skip_list_repr.mli sc_rollup_inbox_repr.ml sc_rollup_inbox_repr.mli @@ -706,9 +709,6 @@ sampler.ml sampler.mli voting_period_repr.ml voting_period_repr.mli ticket_hash_repr.ml ticket_hash_repr.mli - michelson_v1_primitives.ml michelson_v1_primitives.mli - script_repr.ml script_repr.mli - cache_memory_helpers.ml contract_repr.ml contract_repr.mli indexable.ml indexable.mli entrypoint_repr.ml entrypoint_repr.mli @@ -893,6 +893,7 @@ tx_rollup_prefixes.ml tx_rollup_prefixes.mli merkle_list.ml merkle_list.mli bitset.ml bitset.mli + michelson_v1_primitives.ml michelson_v1_primitives.mli slot_repr.ml slot_repr.mli tez_repr.ml tez_repr.mli period_repr.ml period_repr.mli @@ -911,6 +912,8 @@ fitness_repr.ml fitness_repr.mli cycle_repr.ml cycle_repr.mli level_repr.ml level_repr.mli + script_repr.ml script_repr.mli + cache_memory_helpers.ml sc_rollup_repr.ml sc_rollup_repr.mli skip_list_repr.ml skip_list_repr.mli sc_rollup_inbox_repr.ml sc_rollup_inbox_repr.mli @@ -921,9 +924,6 @@ sampler.ml sampler.mli voting_period_repr.ml voting_period_repr.mli ticket_hash_repr.ml ticket_hash_repr.mli - michelson_v1_primitives.ml michelson_v1_primitives.mli - script_repr.ml script_repr.mli - cache_memory_helpers.ml contract_repr.ml contract_repr.mli indexable.ml indexable.mli entrypoint_repr.ml entrypoint_repr.mli -- GitLab From 5ed4025c9e2bbd937251e7f8bec953529238246e Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Tue, 17 May 2022 15:11:35 +0200 Subject: [PATCH 3/8] Proto/Alpha_context: move Destination further down --- .../lib_protocol/alpha_context.mli | 42 +++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index 69802ef467b0..e7030491ce21 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -2144,27 +2144,6 @@ module Bond_id : sig end end -(** This simply re-exports {!Destination_repr}. *) -module Destination : sig - type t = Contract of Contract.t | Tx_rollup of Tx_rollup.t - - val encoding : t Data_encoding.t - - val pp : Format.formatter -> t -> unit - - val compare : t -> t -> int - - val equal : t -> t -> bool - - val to_b58check : t -> string - - val of_b58check : string -> t tzresult - - val in_memory_size : t -> Cache_memory_helpers.sint - - type error += Invalid_destination_b58check of string -end - module Receipt : sig type balance = | Contract of Contract.t @@ -2731,6 +2710,27 @@ module Sc_rollup : sig end end +(** This simply re-exports {!Destination_repr}. *) +module Destination : sig + type t = Contract of Contract.t | Tx_rollup of Tx_rollup.t + + val encoding : t Data_encoding.t + + val pp : Format.formatter -> t -> unit + + val compare : t -> t -> int + + val equal : t -> t -> bool + + val to_b58check : t -> string + + val of_b58check : string -> t tzresult + + val in_memory_size : t -> Cache_memory_helpers.sint + + type error += Invalid_destination_b58check of string +end + module Block_payload : sig val hash : predecessor:Block_hash.t -> -- GitLab From 3a3d6fbe978a45f06382a885cc20155569f603dc Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Tue, 17 May 2022 11:47:35 +0200 Subject: [PATCH 4/8] Proto/Sc_rollup_repr: add in_memory_size --- src/proto_alpha/lib_protocol/sc_rollup_repr.ml | 4 ++++ src/proto_alpha/lib_protocol/sc_rollup_repr.mli | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/proto_alpha/lib_protocol/sc_rollup_repr.ml b/src/proto_alpha/lib_protocol/sc_rollup_repr.ml index 022a2830d5b8..0068e78f5dd0 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_repr.ml +++ b/src/proto_alpha/lib_protocol/sc_rollup_repr.ml @@ -162,6 +162,10 @@ let rpc_arg = ~destruct () +let in_memory_size (_ : t) = + let open Cache_memory_helpers in + h1w +! string_size_gen Address.size + module Staker = Signature.Public_key_hash module Index = struct diff --git a/src/proto_alpha/lib_protocol/sc_rollup_repr.mli b/src/proto_alpha/lib_protocol/sc_rollup_repr.mli index 8095d1fafa56..eb8d9b74f054 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_repr.mli +++ b/src/proto_alpha/lib_protocol/sc_rollup_repr.mli @@ -81,6 +81,10 @@ val rpc_arg : t RPC_arg.t val pp : Format.formatter -> t -> unit +(** [in_memory_size sc_rollup] returns the number of bytes [sc_rollup] + uses in RAM. *) +val in_memory_size : t -> Cache_memory_helpers.sint + (** A [Staker] is an implicit account, identified by its public key hash. *) module Staker : S.SIGNATURE_PUBLIC_KEY_HASH with type t = Signature.Public_key_hash.t -- GitLab From 23aa637ff5d3766205ceea1890bbef2d929eee6d Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Wed, 18 May 2022 15:27:23 +0200 Subject: [PATCH 5/8] Proto/Sc_rollup_repr: add Address.of_b58data --- src/proto_alpha/lib_protocol/sc_rollup_repr.ml | 2 ++ src/proto_alpha/lib_protocol/sc_rollup_repr.mli | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/proto_alpha/lib_protocol/sc_rollup_repr.ml b/src/proto_alpha/lib_protocol/sc_rollup_repr.ml index 0068e78f5dd0..63c2886a1a44 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_repr.ml +++ b/src/proto_alpha/lib_protocol/sc_rollup_repr.ml @@ -70,6 +70,8 @@ module Address = struct |> function | None -> error Error_sc_rollup_address_generation | Some nonce -> ok @@ hash_bytes [nonce] + + let of_b58data = function H.Data h -> Some h | _ -> None end module Internal_for_tests = struct diff --git a/src/proto_alpha/lib_protocol/sc_rollup_repr.mli b/src/proto_alpha/lib_protocol/sc_rollup_repr.mli index eb8d9b74f054..b198a7c43e73 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_repr.mli +++ b/src/proto_alpha/lib_protocol/sc_rollup_repr.mli @@ -50,6 +50,8 @@ module Address : sig (** [encoded_size] is the number of bytes needed to represent an address. *) val encoded_size : int + + val of_b58data : Base58.data -> t option end module Internal_for_tests : sig -- GitLab From 63356650015c70f1689045df63364c702cf212b0 Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Tue, 17 May 2022 11:56:35 +0200 Subject: [PATCH 6/8] Proto/Destination_repr: add Sc_rollup --- .../lib_protocol/alpha_context.mli | 5 ++- .../lib_protocol/destination_repr.ml | 32 +++++++++++++++---- .../lib_protocol/destination_repr.mli | 5 ++- .../lib_protocol/script_interpreter.ml | 2 +- .../lib_protocol/script_interpreter_defs.ml | 6 +++- .../lib_protocol/script_ir_translator.ml | 10 +++++- .../lib_protocol/script_tc_errors.ml | 4 +++ .../script_tc_errors_registration.ml | 10 ++++++ .../test/unit/test_destination_repr.ml | 9 ++++++ 9 files changed, 71 insertions(+), 12 deletions(-) diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index e7030491ce21..dd2be744c943 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -2712,7 +2712,10 @@ end (** This simply re-exports {!Destination_repr}. *) module Destination : sig - type t = Contract of Contract.t | Tx_rollup of Tx_rollup.t + type t = + | Contract of Contract.t + | Tx_rollup of Tx_rollup.t + | Sc_rollup of Sc_rollup.t val encoding : t Data_encoding.t diff --git a/src/proto_alpha/lib_protocol/destination_repr.ml b/src/proto_alpha/lib_protocol/destination_repr.ml index 15d0f87bc816..638fcfe83b3c 100644 --- a/src/proto_alpha/lib_protocol/destination_repr.ml +++ b/src/proto_alpha/lib_protocol/destination_repr.ml @@ -25,10 +25,13 @@ (* *) (*****************************************************************************) -type t = Contract of Contract_repr.t | Tx_rollup of Tx_rollup_repr.t +type t = + | Contract of Contract_repr.t + | Tx_rollup of Tx_rollup_repr.t + | Sc_rollup of Sc_rollup_repr.t (* If you add more cases to this type, please update the [test_compare_destination] test in - [test/unit/test_destinatino_repr.ml] to ensure that the compare + [test/unit/test_destination_repr.ml] to ensure that the compare function keeps its expected behavior to distinguish between implicit accounts and smart contracts. *) @@ -39,6 +42,7 @@ include Compare.Make (struct match (l1, l2) with | Contract k1, Contract k2 -> Contract_repr.compare k1 k2 | Tx_rollup k1, Tx_rollup k2 -> Tx_rollup_repr.compare k1 k2 + | Sc_rollup k1, Sc_rollup k2 -> Sc_rollup_repr.Address.compare k1 k2 (* This function is used by the Michelson interpreter to compare addresses. It is of significant importance to remember that in Michelson, address comparison is used to distinguish between @@ -48,11 +52,14 @@ include Compare.Make (struct modified when new constructors are added to [t]. *) | Contract _, _ -> -1 | _, Contract _ -> 1 + | Tx_rollup _, Sc_rollup _ -> -1 + | Sc_rollup _, Tx_rollup _ -> 1 end) let to_b58check = function | Contract k -> Contract_repr.to_b58check k | Tx_rollup k -> Tx_rollup_repr.to_b58check k + | Sc_rollup k -> Sc_rollup_repr.Address.to_b58check k type error += Invalid_destination_b58check of string @@ -71,9 +78,12 @@ let () = let of_b58data data = match Contract_repr.of_b58data data with | Some c -> Some (Contract c) - | None -> - Tx_rollup_repr.of_b58data data - |> Option.map (fun tx_rollup -> Tx_rollup tx_rollup) + | None -> ( + match Tx_rollup_repr.of_b58data data with + | Some tx_rollup -> Some (Tx_rollup tx_rollup) + | None -> + Sc_rollup_repr.Address.of_b58data data + |> Option.map (fun sc_rollup -> Sc_rollup sc_rollup)) let of_b58check_opt s = Option.bind (Base58.decode s) of_b58data @@ -90,8 +100,8 @@ let encoding = ~description: "A destination notation compatible with the contract notation as given \ to an RPC or inside scripts. Can be a base58 implicit contract hash, a \ - base58 originated contract hash, or a base58 originated transaction \ - rollup." + base58 originated contract hash, a base58 originated transaction \ + rollup, or a base58 originated smart-contract rollup." @@ splitted ~binary: (union @@ -106,6 +116,12 @@ let encoding = ~title:"Tx_rollup" (function Tx_rollup k -> Some k | _ -> None) (fun k -> Tx_rollup k); + case + (Tag 3) + (Fixed.add_padding Sc_rollup_repr.Address.encoding 1) + ~title:"Sc_rollup" + (function Sc_rollup k -> Some k | _ -> None) + (fun k -> Sc_rollup k); ])) ~json: (conv @@ -122,9 +138,11 @@ let pp : Format.formatter -> t -> unit = fun fmt -> function | Contract k -> Contract_repr.pp fmt k | Tx_rollup k -> Tx_rollup_repr.pp fmt k + | Sc_rollup k -> Sc_rollup_repr.pp fmt k let in_memory_size = let open Cache_memory_helpers in function | Contract k -> h1w +! Contract_repr.in_memory_size k | Tx_rollup k -> h1w +! Tx_rollup_repr.in_memory_size k + | Sc_rollup k -> h1w +! Sc_rollup_repr.in_memory_size k diff --git a/src/proto_alpha/lib_protocol/destination_repr.mli b/src/proto_alpha/lib_protocol/destination_repr.mli index 7b93a92aef8a..2b0c3e57f0c5 100644 --- a/src/proto_alpha/lib_protocol/destination_repr.mli +++ b/src/proto_alpha/lib_protocol/destination_repr.mli @@ -41,7 +41,10 @@ remains compatible with {!Contract_repr.encoding}, for the introduction to this type to remain transparent from the existing tooling perspective. *) -type t = Contract of Contract_repr.t | Tx_rollup of Tx_rollup_repr.t +type t = + | Contract of Contract_repr.t + | Tx_rollup of Tx_rollup_repr.t + | Sc_rollup of Sc_rollup_repr.t include Compare.S with type t := t diff --git a/src/proto_alpha/lib_protocol/script_interpreter.ml b/src/proto_alpha/lib_protocol/script_interpreter.ml index 34db31cf3b3c..48703975164b 100644 --- a/src/proto_alpha/lib_protocol/script_interpreter.ml +++ b/src/proto_alpha/lib_protocol/script_interpreter.ml @@ -1038,7 +1038,7 @@ and step : type a s b t r f. (a, s, b, t, r, f) step_type = (step [@ocaml.tailcall]) (ctxt, sc) gas k ks None stack in match c with - | Contract (Implicit _) | Tx_rollup _ -> + | Contract (Implicit _) | Tx_rollup _ | Sc_rollup _ -> (return_none [@ocaml.tailcall]) ctxt | Contract (Originated _contract_hash as c) -> ( Contract.get_script ctxt c >>=? fun (ctxt, script_opt) -> diff --git a/src/proto_alpha/lib_protocol/script_interpreter_defs.ml b/src/proto_alpha/lib_protocol/script_interpreter_defs.ml index e629a28bf519..9aa149aef72a 100644 --- a/src/proto_alpha/lib_protocol/script_interpreter_defs.ml +++ b/src/proto_alpha/lib_protocol/script_interpreter_defs.ml @@ -618,7 +618,11 @@ let transfer (ctxt, sc) gas amount location parameters_ty parameters ~amount ~entrypoint ~parameters_ty - ~parameters) + ~parameters + | Sc_rollup _ -> + (* TODO #2801 + Implement transfers to sc rollups. *) + failwith "Transferring to smart-contract rollups is not yet supported") >>=? fun (operation, ctxt) -> fresh_internal_nonce ctxt >>?= fun (ctxt, nonce) -> let iop = {source = sc.self; operation; nonce} in diff --git a/src/proto_alpha/lib_protocol/script_ir_translator.ml b/src/proto_alpha/lib_protocol/script_ir_translator.ml index 78213e0b0ad2..6d0664f6ea0f 100644 --- a/src/proto_alpha/lib_protocol/script_ir_translator.ml +++ b/src/proto_alpha/lib_protocol/script_ir_translator.ml @@ -2058,6 +2058,8 @@ let parse_address ctxt : Script.node -> (address * context) tzresult = match destination with | Destination.Tx_rollup _ when not (Constants.tx_rollup_enable ctxt) -> error @@ Tx_rollup_addresses_disabled loc + | Destination.Sc_rollup _ when not (Constants.sc_rollup_enable ctxt) -> + error @@ Sc_rollup_disabled loc | _ -> Ok ({destination; entrypoint}, ctxt) in function @@ -2434,7 +2436,8 @@ let[@coq_axiom_with_reason "gadt"] rec parse_data : >>=? fun (({destination; entrypoint = _}, (contents, amount)), ctxt) -> match destination with | Contract ticketer -> return ({ticketer; contents; amount}, ctxt) - | Tx_rollup _ -> fail (Unexpected_ticket_owner destination) + | Tx_rollup _ | Sc_rollup _ -> + fail (Unexpected_ticket_owner destination) else traced_fail (Unexpected_forged_value (location expr)) (* Sets *) | Set_t (t, _ty_name), (Seq (loc, vs) as expr) -> @@ -4858,6 +4861,10 @@ and[@coq_axiom_with_reason "complex mutually recursive definition"] parse_contra fail @@ Tx_rollup_bad_deposit_parameter (loc, serialize_ty_for_error arg) else fail (No_such_entrypoint entrypoint) + | Sc_rollup _ -> + (* TODO #2800 + Implement typechecking of sc rollup deposits. *) + fail (No_such_entrypoint entrypoint) and parse_view_name ctxt : Script.node -> (Script_string.t * context) tzresult = function @@ -5068,6 +5075,7 @@ let parse_contract_for_script : (ctxt, Some (Typed_contract {arg_ty = arg; address})) | ctxt, None -> (ctxt, None)) | _ -> return (ctxt, None)) + | Sc_rollup _ -> return (ctxt, None) let view_size view = let open Script_typed_ir_size in diff --git a/src/proto_alpha/lib_protocol/script_tc_errors.ml b/src/proto_alpha/lib_protocol/script_tc_errors.ml index fa83dad68a1c..1f0c39d222b8 100644 --- a/src/proto_alpha/lib_protocol/script_tc_errors.ml +++ b/src/proto_alpha/lib_protocol/script_tc_errors.ml @@ -76,6 +76,10 @@ type error += Tx_rollup_invalid_ticket_amount of Z.t type error += Tx_rollup_addresses_disabled of Script.location +(* Smart-contract rollup errors *) + +type error += Sc_rollup_disabled of Script.location + (* Instruction typing errors *) type error += Fail_not_in_tail_position of Script.location diff --git a/src/proto_alpha/lib_protocol/script_tc_errors_registration.ml b/src/proto_alpha/lib_protocol/script_tc_errors_registration.ml index ef1974cc3e79..70b586a528ed 100644 --- a/src/proto_alpha/lib_protocol/script_tc_errors_registration.ml +++ b/src/proto_alpha/lib_protocol/script_tc_errors_registration.ml @@ -263,6 +263,16 @@ let () = (obj1 (req "location" Script.location_encoding)) (function Tx_rollup_addresses_disabled loc -> Some loc | _ -> None) (fun loc -> Tx_rollup_addresses_disabled loc) ; + (* Sc rollup disabled *) + register_error_kind + `Permanent + ~id:"michelson_v1.sc_rollup_disabled" + ~title:"Sc rollup are disabled" + ~description: + "Cannot use smart-contract rollup features as they are disabled." + (obj1 (req "location" Script.location_encoding)) + (function Sc_rollup_disabled loc -> Some loc | _ -> None) + (fun loc -> Sc_rollup_disabled loc) ; (* Duplicate entrypoint *) register_error_kind `Permanent diff --git a/src/proto_alpha/lib_protocol/test/unit/test_destination_repr.ml b/src/proto_alpha/lib_protocol/test/unit/test_destination_repr.ml index 78153e63ed95..6bb7638b99f2 100644 --- a/src/proto_alpha/lib_protocol/test/unit/test_destination_repr.ml +++ b/src/proto_alpha/lib_protocol/test/unit/test_destination_repr.ml @@ -74,6 +74,13 @@ let liquidity_baking_dex = "KT1TxqZ8QtKvLu3V3JH7Gx58n7Co8pgtpQU5" let tx_rollup_address = "txr1YNMEtkj5Vkqsbdmt7xaxBTMRZjzS96UAi" +(* The following address has been extracted like this: + - turn [sc_rollup_enable] to [true] in [src/proto_alpha/parameters/test-parameters.json] + - [./tezos-client -M mockup create mockup --protocol-constants src/proto_alpha/parameters/test-parameters.json] + - [./tezos-client -M mockup originate sc rollup from bootstrap1 of kind arith booting with '' --burn-cap 2] +*) +let sc_rollup_address = "scr1HLXM32GacPNDrhHDLAssZG88eWqCUbyLF" + let assert_compat contract destination = match destination with | Destination_repr.Contract contract' @@ -172,10 +179,12 @@ let test_compare_destination () = let tz1 = !!(Destination_repr.of_b58check null_address) in let kt1 = !!(Destination_repr.of_b58check liquidity_baking_dex) in let txr1 = !!(Destination_repr.of_b58check tx_rollup_address) in + let scr1 = !!(Destination_repr.of_b58check sc_rollup_address) in assert (Destination_repr.(tz1 < kt1)) ; assert (Destination_repr.(kt1 < txr1)) ; assert (Destination_repr.(tz1 < txr1)) ; + assert (Destination_repr.(txr1 < scr1)) ; return_unit -- GitLab From 756fd1afbc6c0416607f196c15454874de9af464 Mon Sep 17 00:00:00 2001 From: Joel Bjornson Date: Mon, 30 May 2022 15:20:49 +0200 Subject: [PATCH 7/8] Proto/Tests/Typechecking: allow enabling sc rollups --- .../test/integration/michelson/test_typechecking.ml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/proto_alpha/lib_protocol/test/integration/michelson/test_typechecking.ml b/src/proto_alpha/lib_protocol/test/integration/michelson/test_typechecking.ml index 3b01b3a77c76..c8f1c969e7b4 100644 --- a/src/proto_alpha/lib_protocol/test/integration/michelson/test_typechecking.ml +++ b/src/proto_alpha/lib_protocol/test/integration/michelson/test_typechecking.ml @@ -70,8 +70,10 @@ let test_context () = Incremental.begin_construction b >>=? fun v -> return (Incremental.alpha_ctxt v) -let test_context_with_nat_nat_big_map () = - Context.init3 () >>=? fun (b, (source, _c2, _c3)) -> +let test_context_with_nat_nat_big_map ?(sc_rollup_enable = false) () = + Context.init_with_constants1 + {Context.default_test_constants with sc_rollup_enable} + >>=? fun (b, source) -> Op.contract_origination (B b) source ~script:Op.dummy_script >>=? fun (operation, originated) -> Block.bake ~operation b >>=? fun b -> -- GitLab From 678181c05e6649d2f56a2feaa4e27869d19a4d57 Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Mon, 23 May 2022 18:28:28 +0200 Subject: [PATCH 8/8] Proto/Tests: checks that scr1 addresses are recognized as Michelson addresses --- .../michelson/test_typechecking.ml | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/proto_alpha/lib_protocol/test/integration/michelson/test_typechecking.ml b/src/proto_alpha/lib_protocol/test/integration/michelson/test_typechecking.ml index c8f1c969e7b4..31e534d3e881 100644 --- a/src/proto_alpha/lib_protocol/test/integration/michelson/test_typechecking.ml +++ b/src/proto_alpha/lib_protocol/test/integration/michelson/test_typechecking.ml @@ -498,7 +498,8 @@ let test_parse_comb_data () = let test_parse_address () = let open Script_typed_ir in - test_context_with_nat_nat_big_map () >>=? fun (ctxt, _big_map_id) -> + test_context_with_nat_nat_big_map ~sc_rollup_enable:true () + >>=? fun (ctxt, _big_map_id) -> (* KT1% (empty entrypoint) *) wrap_error_lwt (Lwt.return (Contract.of_b58check "KT1FAKEFAKEFAKEFAKEFAKEFAKEFAKGGSE2x")) @@ -520,6 +521,26 @@ let test_parse_address () = address_t (String (-1, "tz1fakefakefakefakefakefakefakcphLA5%")) {destination = Contract tz1fake; entrypoint = Entrypoint.default} + >>=? fun ctxt -> + (* scr1% (empty entrypoint) *) + wrap_error_lwt + (Lwt.return + (Destination.of_b58check "scr1HLXM32GacPNDrhHDLAssZG88eWqCUbyLF")) + >>=? fun scr1 -> + test_parse_data + __LOC__ + ctxt + address_t + (String (-1, "scr1HLXM32GacPNDrhHDLAssZG88eWqCUbyLF")) + {destination = scr1; entrypoint = Entrypoint.default} + >>=? fun ctxt -> + (* scr1% (default entrypoint) *) + test_parse_data + __LOC__ + ctxt + address_t + (String (-1, "scr1HLXM32GacPNDrhHDLAssZG88eWqCUbyLF%")) + {destination = scr1; entrypoint = Entrypoint.default} >|=? fun _ctxt -> () let test_unparse_data loc ctxt ty x ~expected_readable ~expected_optimized = -- GitLab