diff --git a/src/lib_crypto/base58.ml b/src/lib_crypto/base58.ml index ddf75e61d10a25d981c880e63968a62aa72e8f74..fe8cd281dd0c11e2eecc03c072c8100c7025a504 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 297d90dea993bbaebc73eb0324099201acc0c204..dbb13934764f436812463d33f9b7de4641149cfd 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 0000000000000000000000000000000000000000..2c5a0abe7aff7807c930895525a1d1ded164cfee --- /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 0000000000000000000000000000000000000000..70728aa0c07742c05b6590f93ceff6b9ba511a22 --- /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 7437e8ec0e75d797f36f9b3dc146ba35b1c061bd..4894d7f1f5aa2bee16afc77462ad3c0eea50e9cc 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 diff --git a/src/lib_protocol_environment/environment_V10.ml b/src/lib_protocol_environment/environment_V10.ml index 4c8ef9d71e825ff45c1b1e4cc1463bed168b7b14..d73054185334cf3dca32619c5c6951ff5faabf71 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 cb3c845524bdc4b7eabe09b7886e0fa13edbab30..f227964cee8b2ede652ea7c775acbf3d96540ad5 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 a3b72477d2621594c4705dbced685a3dde120224..df0ab695f92fbb7b0b6ea4c46c0bbce2c6aea9b7 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 0c404123416b82a5149eae6fc13e9ce9e993c1eb..fd73f696ae2b91c1839c4cd0d69fca18ac11ac7e 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 0000000000000000000000000000000000000000..753911a4c88c608867f46e8801b9ff75ca0aa724 --- /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 diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index f1cb6071a62b25342eaacb6f544296d8fc7e756c..ff4b9ff8c4229b52688854cf4fd9af1807bd0ea3 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 d383ebd9d01d742dfa2a9e988d96aa9dc83558e4..91f2ef976238564e03509c107849eb409551ceb4 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 c40cd4f80fb2516e1a68eee811331402c2cfff18..30e2f3315ba1a6beae2367690fc96f8e74f36e99 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