From a3fb1a91beabb86f64dd401347c9b2dba20568e5 Mon Sep 17 00:00:00 2001 From: Alain Mebsout Date: Tue, 25 Apr 2023 14:33:34 +0200 Subject: [PATCH 1/3] Crypto: smart rollup address as primitive hash --- src/lib_crypto/base58.ml | 2 ++ src/lib_crypto/base58.mli | 2 ++ src/lib_crypto/smart_rollup_address.ml | 42 +++++++++++++++++++++++++ src/lib_crypto/smart_rollup_address.mli | 29 +++++++++++++++++ src/lib_crypto/tezos_crypto.ml | 1 + 5 files changed, 76 insertions(+) create mode 100644 src/lib_crypto/smart_rollup_address.ml create mode 100644 src/lib_crypto/smart_rollup_address.mli diff --git a/src/lib_crypto/base58.ml b/src/lib_crypto/base58.ml index ddf75e61d10a..fe8cd281dd0c 100644 --- a/src/lib_crypto/base58.ml +++ b/src/lib_crypto/base58.ml @@ -384,6 +384,8 @@ module Prefix = struct let bls12_381_public_key_hash = "\006\161\166" (* tz4(36) *) + let smart_rollup_address = "\006\124\117" (* sr1(36) *) + (* 16 *) let cryptobox_public_key_hash = "\153\103" (* id(30) *) diff --git a/src/lib_crypto/base58.mli b/src/lib_crypto/base58.mli index 297d90dea993..dbb13934764f 100644 --- a/src/lib_crypto/base58.mli +++ b/src/lib_crypto/base58.mli @@ -55,6 +55,8 @@ module Prefix : sig val bls12_381_public_key_hash : string + val smart_rollup_address : string + val cryptobox_public_key_hash : string val ed25519_seed : string diff --git a/src/lib_crypto/smart_rollup_address.ml b/src/lib_crypto/smart_rollup_address.ml new file mode 100644 index 000000000000..2c5a0abe7aff --- /dev/null +++ b/src/lib_crypto/smart_rollup_address.ml @@ -0,0 +1,42 @@ +(*****************************************************************************) +(* *) +(* Open Source License *) +(* Copyright (c) 2021 Nomadic Labs *) +(* Copyright (c) 2022 Trili Tech, *) +(* Copyright (c) 2022 Marigold, *) +(* Copyright (c) 2023 Functori, *) +(* *) +(* Permission is hereby granted, free of charge, to any person obtaining a *) +(* copy of this software and associated documentation files (the "Software"),*) +(* to deal in the Software without restriction, including without limitation *) +(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *) +(* and/or sell copies of the Software, and to permit persons to whom the *) +(* Software is furnished to do so, subject to the following conditions: *) +(* *) +(* The above copyright notice and this permission notice shall be included *) +(* in all copies or substantial portions of the Software. *) +(* *) +(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*) +(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *) +(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *) +(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*) +(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *) +(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *) +(* DEALINGS IN THE SOFTWARE. *) +(* *) +(*****************************************************************************) + +include + Blake2B.Make + (Base58) + (struct + let name = "Smart_rollup_address" + + let title = "A smart rollup address" + + let b58check_prefix = Base58.Prefix.smart_rollup_address + + let size = Some 20 + end) + +let () = Base58.check_encoded_prefix b58check_encoding "sr1" 36 diff --git a/src/lib_crypto/smart_rollup_address.mli b/src/lib_crypto/smart_rollup_address.mli new file mode 100644 index 000000000000..70728aa0c077 --- /dev/null +++ b/src/lib_crypto/smart_rollup_address.mli @@ -0,0 +1,29 @@ +(*****************************************************************************) +(* *) +(* Open Source License *) +(* Copyright (c) 2021 Nomadic Labs *) +(* Copyright (c) 2022 Trili Tech, *) +(* Copyright (c) 2022 Marigold, *) +(* Copyright (c) 2023 Functori, *) +(* *) +(* Permission is hereby granted, free of charge, to any person obtaining a *) +(* copy of this software and associated documentation files (the "Software"),*) +(* to deal in the Software without restriction, including without limitation *) +(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *) +(* and/or sell copies of the Software, and to permit persons to whom the *) +(* Software is furnished to do so, subject to the following conditions: *) +(* *) +(* The above copyright notice and this permission notice shall be included *) +(* in all copies or substantial portions of the Software. *) +(* *) +(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*) +(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *) +(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *) +(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*) +(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *) +(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *) +(* DEALINGS IN THE SOFTWARE. *) +(* *) +(*****************************************************************************) + +include S.HASH diff --git a/src/lib_crypto/tezos_crypto.ml b/src/lib_crypto/tezos_crypto.ml index 7437e8ec0e75..4894d7f1f5aa 100644 --- a/src/lib_crypto/tezos_crypto.ml +++ b/src/lib_crypto/tezos_crypto.ml @@ -37,6 +37,7 @@ module Hashed = struct module Operation_metadata_list_hash = Operation_metadata_list_hash module Operation_metadata_list_list_hash = Operation_metadata_list_list_hash module Protocol_hash = Protocol_hash + module Smart_rollup_address = Smart_rollup_address end module Signature = struct -- GitLab From 2a22661feda4bfaf90ea701cda3acc7da0ab0fed Mon Sep 17 00:00:00 2001 From: Alain Mebsout Date: Tue, 25 Apr 2023 14:49:36 +0200 Subject: [PATCH 2/3] Environment: expose smart rollup address --- .../environment_V10.ml | 4 +++ .../environment_V10.mli | 2 ++ src/lib_protocol_environment/sigs/v10.in.ml | 2 ++ src/lib_protocol_environment/sigs/v10.ml | 33 +++++++++++++++++++ .../sigs/v10/smart_rollup_address.mli | 27 +++++++++++++++ 5 files changed, 68 insertions(+) create mode 100644 src/lib_protocol_environment/sigs/v10/smart_rollup_address.mli diff --git a/src/lib_protocol_environment/environment_V10.ml b/src/lib_protocol_environment/environment_V10.ml index 4c8ef9d71e82..d73054185334 100644 --- a/src/lib_protocol_environment/environment_V10.ml +++ b/src/lib_protocol_environment/environment_V10.ml @@ -123,6 +123,8 @@ module type T = sig and type Wasm_2_0_0.input_request = Tezos_scoru_wasm.Wasm_pvm_state.input_request and type Wasm_2_0_0.info = Tezos_scoru_wasm.Wasm_pvm_state.info + and type Smart_rollup_address.t = + Tezos_crypto.Hashed.Smart_rollup_address.t type error += Ecoproto_error of Error_monad.error @@ -1463,4 +1465,6 @@ struct Ok false | Ok () -> Ok true end + + module Smart_rollup_address = Tezos_crypto.Hashed.Smart_rollup_address end diff --git a/src/lib_protocol_environment/environment_V10.mli b/src/lib_protocol_environment/environment_V10.mli index cb3c845524bd..f227964cee8b 100644 --- a/src/lib_protocol_environment/environment_V10.mli +++ b/src/lib_protocol_environment/environment_V10.mli @@ -123,6 +123,8 @@ module type T = sig and type Wasm_2_0_0.input_request = Tezos_scoru_wasm.Wasm_pvm_state.input_request and type Wasm_2_0_0.info = Tezos_scoru_wasm.Wasm_pvm_state.info + and type Smart_rollup_address.t = + Tezos_crypto.Hashed.Smart_rollup_address.t (** An [Ecoproto_error e] is a shell error that carry a protocol error. diff --git a/src/lib_protocol_environment/sigs/v10.in.ml b/src/lib_protocol_environment/sigs/v10.in.ml index a3b72477d262..df0ab695f92f 100644 --- a/src/lib_protocol_environment/sigs/v10.in.ml +++ b/src/lib_protocol_environment/sigs/v10.in.ml @@ -134,4 +134,6 @@ module type T = sig module Plonk : [%sig "v10/plonk.mli"] module Dal : [%sig "v10/dal.mli"] + + module Smart_rollup_address : [%sig "v10/smart_rollup_address.mli"] end diff --git a/src/lib_protocol_environment/sigs/v10.ml b/src/lib_protocol_environment/sigs/v10.ml index 0c404123416b..fd73f696ae2b 100644 --- a/src/lib_protocol_environment/sigs/v10.ml +++ b/src/lib_protocol_environment/sigs/v10.ml @@ -12309,4 +12309,37 @@ val verify_page : end # 136 "v10.in.ml" + + module Smart_rollup_address : sig +# 1 "v10/smart_rollup_address.mli" +(*****************************************************************************) +(* *) +(* Open Source License *) +(* Copyright (c) 2023 Functori, *) +(* *) +(* Permission is hereby granted, free of charge, to any person obtaining a *) +(* copy of this software and associated documentation files (the "Software"),*) +(* to deal in the Software without restriction, including without limitation *) +(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *) +(* and/or sell copies of the Software, and to permit persons to whom the *) +(* Software is furnished to do so, subject to the following conditions: *) +(* *) +(* The above copyright notice and this permission notice shall be included *) +(* in all copies or substantial portions of the Software. *) +(* *) +(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*) +(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *) +(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *) +(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*) +(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *) +(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *) +(* DEALINGS IN THE SOFTWARE. *) +(* *) +(*****************************************************************************) + +(** Smart rollup addresses *) +include S.HASH +end +# 138 "v10.in.ml" + end diff --git a/src/lib_protocol_environment/sigs/v10/smart_rollup_address.mli b/src/lib_protocol_environment/sigs/v10/smart_rollup_address.mli new file mode 100644 index 000000000000..753911a4c88c --- /dev/null +++ b/src/lib_protocol_environment/sigs/v10/smart_rollup_address.mli @@ -0,0 +1,27 @@ +(*****************************************************************************) +(* *) +(* Open Source License *) +(* Copyright (c) 2023 Functori, *) +(* *) +(* Permission is hereby granted, free of charge, to any person obtaining a *) +(* copy of this software and associated documentation files (the "Software"),*) +(* to deal in the Software without restriction, including without limitation *) +(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *) +(* and/or sell copies of the Software, and to permit persons to whom the *) +(* Software is furnished to do so, subject to the following conditions: *) +(* *) +(* The above copyright notice and this permission notice shall be included *) +(* in all copies or substantial portions of the Software. *) +(* *) +(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*) +(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *) +(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *) +(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*) +(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *) +(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *) +(* DEALINGS IN THE SOFTWARE. *) +(* *) +(*****************************************************************************) + +(** Smart rollup addresses *) +include S.HASH -- GitLab From 5eadeabd38ff914c0bb93a1689f2ed9e36f2fd60 Mon Sep 17 00:00:00 2001 From: Alain Mebsout Date: Tue, 25 Apr 2023 15:11:39 +0200 Subject: [PATCH 3/3] Proto/SCORU: use environment smart rollup address --- .../lib_protocol/alpha_context.mli | 19 +++---- .../lib_protocol/sc_rollup_repr.ml | 50 ++++--------------- .../lib_protocol/sc_rollup_repr.mli | 8 ++- 3 files changed, 19 insertions(+), 58 deletions(-) diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index f1cb6071a62b..ff4b9ff8c422 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -2345,21 +2345,11 @@ module Tx_rollup_errors : sig [`Inbox | `Commitment] -> int -> count_limit:int -> unit tzresult end -(** This is a forward declaration to avoid circular dependencies. - Use module [Sc_rollup] instead whenever possible. - TODO : find a better way to resolve the circular dependency - https://gitlab.com/tezos/tezos/-/issues/3147 *) -module Sc_rollup_repr : sig - module Address : S.HASH - - type t = Address.t -end - (** This module re-exports definitions from {!Bond_id_repr}. *) module Bond_id : sig type t = | Tx_rollup_bond_id of Tx_rollup.t - | Sc_rollup_bond_id of Sc_rollup_repr.t + | Sc_rollup_bond_id of Smart_rollup_address.t val pp : Format.formatter -> t -> unit @@ -3209,9 +3199,12 @@ module Sc_rollup : sig module Map : Map.S with type key = t end - module Address = Sc_rollup_repr.Address + module Address : sig + include + module type of Smart_rollup_address with type t = Smart_rollup_address.t + end - type t = Sc_rollup_repr.t + type t = Smart_rollup_address.t type rollup := t diff --git a/src/proto_alpha/lib_protocol/sc_rollup_repr.ml b/src/proto_alpha/lib_protocol/sc_rollup_repr.ml index d383ebd9d01d..91f2ef976238 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_repr.ml +++ b/src/proto_alpha/lib_protocol/sc_rollup_repr.ml @@ -26,32 +26,13 @@ (*****************************************************************************) module Address = struct - let prefix = "sr1" - - let encoded_size = 36 - - let decoded_prefix = "\006\124\117" (* "sr1(36)" decoded from base 58. *) - - module H = - Blake2B.Make - (Base58) - (struct - let name = "Smart_rollup_hash" - - let title = "A smart rollup address" - - let b58check_prefix = decoded_prefix + include Smart_rollup_address - let size = Some 20 - end) - - include H - - let () = Base58.check_encoded_prefix b58check_encoding prefix encoded_size + let prefix = "sr1" - include Path_encoding.Make_hex (H) + let () = Base58.check_encoded_prefix b58check_encoding prefix 36 - let of_b58data = function H.Data h -> Some h | _ -> None + let of_b58data = function Smart_rollup_address.Data h -> Some h | _ -> None end module Internal_for_tests = struct @@ -106,27 +87,16 @@ module State_hash = struct let hash_string = function (_ : unreachable) -> . end -type t = Address.t +(* TODO: https://gitlab.com/tezos/tezos/-/issues/5506 + Remove type and module aliases for Smart_rollup_address. *) -let description = - "A smart rollup is identified by a base58 address starting with " - ^ Address.prefix +type t = Address.t let pp = Address.pp -let encoding = - let open Data_encoding in - def - "smart_rollup_address" - ~title:"A smart rollup address" - ~description - Address.encoding - -let rpc_arg = - RPC_arg.like - Address.rpc_arg - ~descr:"A smart rollup address." - "smart_rollup_address" +let encoding = Address.encoding + +let rpc_arg = Address.rpc_arg let in_memory_size (_ : t) = let open Cache_memory_helpers in diff --git a/src/proto_alpha/lib_protocol/sc_rollup_repr.mli b/src/proto_alpha/lib_protocol/sc_rollup_repr.mli index c40cd4f80fb2..30e2f3315ba1 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_repr.mli +++ b/src/proto_alpha/lib_protocol/sc_rollup_repr.mli @@ -42,14 +42,12 @@ (** A smart rollup has an address starting with "sr1". *) module Address : sig - include S.HASH - - (** [encoded_size] is the number of bytes needed to represent an address. *) - val encoded_size : int + include + module type of Smart_rollup_address with type t = Smart_rollup_address.t val of_b58data : Base58.data -> t option - (** [prefix] is the prefix of smart contract rollup addresses. *) + (** Prefix of smart rollup addresses in base58-check. *) val prefix : string end -- GitLab