From 9bb11e77ca2ddc3c41351a52dd12399e628d4f39 Mon Sep 17 00:00:00 2001 From: Adam Allombert-Goget Date: Tue, 22 Oct 2024 14:19:01 +0200 Subject: [PATCH 01/20] Crypto: add signature_v2 (copy of signature_v1) --- src/lib_crypto/signature_v2.ml | 1015 +++++++++++++++++++++++++++++++ src/lib_crypto/signature_v2.mli | 115 ++++ 2 files changed, 1130 insertions(+) create mode 100644 src/lib_crypto/signature_v2.ml create mode 100644 src/lib_crypto/signature_v2.mli diff --git a/src/lib_crypto/signature_v2.ml b/src/lib_crypto/signature_v2.ml new file mode 100644 index 000000000000..92bfed38e647 --- /dev/null +++ b/src/lib_crypto/signature_v2.ml @@ -0,0 +1,1015 @@ +(*****************************************************************************) +(* *) +(* SPDX-License-Identifier: MIT *) +(* SPDX-FileCopyrightText: 2025 Nomadic Labs *) +(* *) +(*****************************************************************************) + +open Error_monad + +type public_key_hash = + | Ed25519 of Ed25519.Public_key_hash.t + | Secp256k1 of Secp256k1.Public_key_hash.t + | P256 of P256.Public_key_hash.t + | Bls of Bls.Public_key_hash.t + +type public_key = + | Ed25519 of Ed25519.Public_key.t + | Secp256k1 of Secp256k1.Public_key.t + | P256 of P256.Public_key.t + | Bls of Bls.Public_key.t + +type secret_key = + | Ed25519 of Ed25519.Secret_key.t + | Secp256k1 of Secp256k1.Secret_key.t + | P256 of P256.Secret_key.t + | Bls of Bls.Secret_key.t + +type watermark = Signature_v0.watermark = + | Block_header of Chain_id.t + | Endorsement of Chain_id.t + | Generic_operation + | Custom of Bytes.t + +module Public_key_hash = struct + type t = public_key_hash = + | Ed25519 of Ed25519.Public_key_hash.t + | Secp256k1 of Secp256k1.Public_key_hash.t + | P256 of P256.Public_key_hash.t + | Bls of Bls.Public_key_hash.t + + let name = "Signature.Public_key_hash" + + let title = "A Ed25519, Secp256k1, P256, or BLS public key hash" + + type Base58.data += Data of t (* unused *) + + let b58check_encoding = + (* unused *) + Base58.register_encoding + ~prefix:"\255\255" + ~length:2 + ~to_raw:(fun _ -> assert false) + ~of_raw:(fun _ -> assert false) + ~wrap:(fun x -> Data x) + + let raw_encoding = + let open Data_encoding in + def "public_key_hash" ~description:title + @@ union + [ + case + (Tag 0) + Ed25519.Public_key_hash.encoding + ~title:"Ed25519" + (function Ed25519 x -> Some x | _ -> None) + (function x -> Ed25519 x); + case + (Tag 1) + Secp256k1.Public_key_hash.encoding + ~title:"Secp256k1" + (function Secp256k1 x -> Some x | _ -> None) + (function x -> Secp256k1 x); + case + (Tag 2) + ~title:"P256" + P256.Public_key_hash.encoding + (function P256 x -> Some x | _ -> None) + (function x -> P256 x); + case + (Tag 3) + ~title:"Bls" + Bls.Public_key_hash.encoding + (function Bls x -> Some x | _ -> None) + (function x -> Bls x); + ] + + let to_bytes s = Data_encoding.Binary.to_bytes_exn raw_encoding s + + let of_bytes_opt s = Data_encoding.Binary.of_bytes_opt raw_encoding s + + let to_string s = Bytes.to_string (to_bytes s) + + let of_string_opt s = of_bytes_opt (Bytes.of_string s) + + let size = 1 + Ed25519.size + + let zero = Ed25519 Ed25519.Public_key_hash.zero + + include Helpers.MakeRaw (struct + type nonrec t = t + + let name = name + + let of_bytes_opt = of_bytes_opt + + let of_string_opt = of_string_opt + + let to_string = to_string + end) + + let of_b58check_opt s = + match Base58.decode s with + | Some (Ed25519.Public_key_hash.Data pkh) -> Some (Ed25519 pkh) + | Some (Secp256k1.Public_key_hash.Data pkh) -> Some (Secp256k1 pkh) + | Some (P256.Public_key_hash.Data pkh) -> Some (P256 pkh) + | Some (Bls.Public_key_hash.Data pkh) -> Some (Bls pkh) + | _ -> None + + let of_b58check_exn s = + match of_b58check_opt s with + | Some x -> x + | None -> Format.kasprintf Stdlib.failwith "Unexpected data (%s)" name + + let of_b58check s = + match of_b58check_opt s with + | Some x -> Ok x + | None -> + error_with "Failed to read a b58check_encoding data (%s): %S" name s + + let to_b58check = function + | Ed25519 pkh -> Ed25519.Public_key_hash.to_b58check pkh + | Secp256k1 pkh -> Secp256k1.Public_key_hash.to_b58check pkh + | P256 pkh -> P256.Public_key_hash.to_b58check pkh + | Bls pkh -> Bls.Public_key_hash.to_b58check pkh + + let to_short_b58check = function + | Ed25519 pkh -> Ed25519.Public_key_hash.to_short_b58check pkh + | Secp256k1 pkh -> Secp256k1.Public_key_hash.to_short_b58check pkh + | P256 pkh -> P256.Public_key_hash.to_short_b58check pkh + | Bls pkh -> Bls.Public_key_hash.to_short_b58check pkh + + let to_path key l = + match key with + | Ed25519 h -> "ed25519" :: Ed25519.Public_key_hash.to_path h l + | Secp256k1 h -> "secp256k1" :: Secp256k1.Public_key_hash.to_path h l + | P256 h -> "p256" :: P256.Public_key_hash.to_path h l + | Bls h -> "bls" :: Bls.Public_key_hash.to_path h l + + let of_path = function + | "ed25519" :: q -> ( + match Ed25519.Public_key_hash.of_path q with + | Some pkh -> Some (Ed25519 pkh) + | None -> None) + | "secp256k1" :: q -> ( + match Secp256k1.Public_key_hash.of_path q with + | Some pkh -> Some (Secp256k1 pkh) + | None -> None) + | "p256" :: q -> ( + match P256.Public_key_hash.of_path q with + | Some pkh -> Some (P256 pkh) + | None -> None) + | "bls" :: q -> ( + match Bls.Public_key_hash.of_path q with + | Some pkh -> Some (Bls pkh) + | None -> None) + | _ -> assert false + + (* FIXME classification des erreurs *) + + let of_path_exn = function + | "ed25519" :: q -> Ed25519 (Ed25519.Public_key_hash.of_path_exn q) + | "secp256k1" :: q -> Secp256k1 (Secp256k1.Public_key_hash.of_path_exn q) + | "p256" :: q -> P256 (P256.Public_key_hash.of_path_exn q) + | "bls" :: q -> Bls (Bls.Public_key_hash.of_path_exn q) + | _ -> assert false + + (* FIXME classification des erreurs *) + + let path_length = + let l1 = Ed25519.Public_key_hash.path_length + and l2 = Secp256k1.Public_key_hash.path_length + and l3 = P256.Public_key_hash.path_length + and l4 = Bls.Public_key_hash.path_length in + assert (Compare.Int.(l1 = l2)) ; + assert (Compare.Int.(l1 = l3)) ; + assert (Compare.Int.(l1 = l4)) ; + 1 + l1 + + let prefix_path _ = assert false (* unused *) + + let seeded_hash = Stdlib.Hashtbl.seeded_hash + + let hash = Stdlib.Hashtbl.hash + + include Compare.Make (struct + type nonrec t = t + + let compare a b = + match (a, b) with + | Ed25519 x, Ed25519 y -> Ed25519.Public_key_hash.compare x y + | Secp256k1 x, Secp256k1 y -> Secp256k1.Public_key_hash.compare x y + | P256 x, P256 y -> P256.Public_key_hash.compare x y + | Bls x, Bls y -> Bls.Public_key_hash.compare x y + | _ -> Stdlib.compare a b + end) + + include Helpers.MakeEncoder (struct + type nonrec t = t + + let name = name + + let title = title + + let raw_encoding = raw_encoding + + let of_b58check = of_b58check + + let of_b58check_opt = of_b58check_opt + + let of_b58check_exn = of_b58check_exn + + let to_b58check = to_b58check + + let to_short_b58check = to_short_b58check + end) + + include Helpers.MakeIterator (struct + type nonrec t = t + + let hash = hash + + let seeded_hash = seeded_hash + + let compare = compare + + let equal = equal + + let encoding = encoding + end) + + let rpc_arg = + Tezos_rpc.Arg.like + rpc_arg + ~descr:"A Secp256k1 of a Ed25519 public key hash (Base58Check-encoded)" + "pkh" + + module Logging = struct + let tag = Tag.def ~doc:title name pp + end +end + +module Public_key = struct + type t = public_key = + | Ed25519 of Ed25519.Public_key.t + | Secp256k1 of Secp256k1.Public_key.t + | P256 of P256.Public_key.t + | Bls of Bls.Public_key.t + + let name = "Signature.Public_key" + + let title = "A Ed25519, Secp256k1, or P256 public key" + + let hash pk = + match pk with + | Ed25519 pk -> Public_key_hash.Ed25519 (Ed25519.Public_key.hash pk) + | Secp256k1 pk -> Public_key_hash.Secp256k1 (Secp256k1.Public_key.hash pk) + | P256 pk -> Public_key_hash.P256 (P256.Public_key.hash pk) + | Bls pk -> Public_key_hash.Bls (Bls.Public_key.hash pk) + + include Compare.Make (struct + type nonrec t = t + + let compare a b = + match (a, b) with + | Ed25519 x, Ed25519 y -> Ed25519.Public_key.compare x y + | Secp256k1 x, Secp256k1 y -> Secp256k1.Public_key.compare x y + | P256 x, P256 y -> P256.Public_key.compare x y + | Bls x, Bls y -> Bls.Public_key.compare x y + | Ed25519 _, (Secp256k1 _ | P256 _ | Bls _) -> -1 + | Secp256k1 _, (P256 _ | Bls _) -> -1 + | P256 _, Bls _ -> -1 + | Bls _, (P256 _ | Secp256k1 _ | Ed25519 _) -> 1 + | P256 _, (Secp256k1 _ | Ed25519 _) -> 1 + | Secp256k1 _, Ed25519 _ -> 1 + end) + + type Base58.data += Data of t (* unused *) + + let b58check_encoding = + (* unused *) + Base58.register_encoding + ~prefix:"\255\255" + ~length:2 + ~to_raw:(fun _ -> assert false) + ~of_raw:(fun _ -> assert false) + ~wrap:(fun x -> Data x) + + let of_b58check_opt s = + match Base58.decode s with + | Some (Ed25519.Public_key.Data public_key) -> Some (Ed25519 public_key) + | Some (Secp256k1.Public_key.Data public_key) -> Some (Secp256k1 public_key) + | Some (P256.Public_key.Data public_key) -> Some (P256 public_key) + | Some (Bls.Public_key.Data public_key) -> Some (Bls public_key) + | _ -> None + + let of_b58check_exn s = + match of_b58check_opt s with + | Some x -> x + | None -> Format.kasprintf Stdlib.failwith "Unexpected data (%s)" name + + let of_b58check s = + match of_b58check_opt s with + | Some x -> Ok x + | None -> + error_with "Failed to read a b58check_encoding data (%s): %S" name s + + let to_b58check = function + | Ed25519 pk -> Ed25519.Public_key.to_b58check pk + | Secp256k1 pk -> Secp256k1.Public_key.to_b58check pk + | P256 pk -> P256.Public_key.to_b58check pk + | Bls pk -> Bls.Public_key.to_b58check pk + + let to_short_b58check = function + | Ed25519 pk -> Ed25519.Public_key.to_short_b58check pk + | Secp256k1 pk -> Secp256k1.Public_key.to_short_b58check pk + | P256 pk -> P256.Public_key.to_short_b58check pk + | Bls pk -> Bls.Public_key.to_short_b58check pk + + let of_bytes_without_validation b = + let tag = Bytes.(get_int8 b 0) in + let b = Bytes.(sub b 1 (length b - 1)) in + match tag with + | 0 -> + Option.bind + (Ed25519.Public_key.of_bytes_without_validation b) + (fun pk -> Some (Ed25519 pk)) + | 1 -> + Option.bind + (Secp256k1.Public_key.of_bytes_without_validation b) + (fun pk -> Some (Secp256k1 pk)) + | 2 -> + Option.bind (P256.Public_key.of_bytes_without_validation b) (fun pk -> + Some (P256 pk)) + | 3 -> + Option.bind (Bls.Public_key.of_bytes_without_validation b) (fun pk -> + Some (Bls pk)) + | _ -> None + + include Helpers.MakeEncoder (struct + type nonrec t = t + + let name = name + + let title = title + + let raw_encoding = + let open Data_encoding in + def "public_key" ~description:title + @@ union + [ + case + (Tag 0) + Ed25519.Public_key.encoding + ~title:"Ed25519" + (function Ed25519 x -> Some x | _ -> None) + (function x -> Ed25519 x); + case + (Tag 1) + Secp256k1.Public_key.encoding + ~title:"Secp256k1" + (function Secp256k1 x -> Some x | _ -> None) + (function x -> Secp256k1 x); + case + ~title:"P256" + (Tag 2) + P256.Public_key.encoding + (function P256 x -> Some x | _ -> None) + (function x -> P256 x); + case + ~title:"Bls" + (Tag 3) + Bls.Public_key.encoding + (function Bls x -> Some x | _ -> None) + (function x -> Bls x); + ] + + let of_b58check = of_b58check + + let of_b58check_opt = of_b58check_opt + + let of_b58check_exn = of_b58check_exn + + let to_b58check = to_b58check + + let to_short_b58check = to_short_b58check + end) + + let size pk = Data_encoding.Binary.length encoding pk + + let pp ppf t = Format.fprintf ppf "%s" (to_b58check t) +end + +module Secret_key = struct + type t = secret_key = + | Ed25519 of Ed25519.Secret_key.t + | Secp256k1 of Secp256k1.Secret_key.t + | P256 of P256.Secret_key.t + | Bls of Bls.Secret_key.t + + let name = "Signature.Secret_key" + + let title = "A Ed25519, Secp256k1 or P256 secret key" + + let to_public_key = function + | Ed25519 sk -> Public_key.Ed25519 (Ed25519.Secret_key.to_public_key sk) + | Secp256k1 sk -> + Public_key.Secp256k1 (Secp256k1.Secret_key.to_public_key sk) + | P256 sk -> Public_key.P256 (P256.Secret_key.to_public_key sk) + | Bls sk -> Public_key.Bls (Bls.Secret_key.to_public_key sk) + + include Compare.Make (struct + type nonrec t = t + + let compare a b = + match (a, b) with + | Ed25519 x, Ed25519 y -> Ed25519.Secret_key.compare x y + | Secp256k1 x, Secp256k1 y -> Secp256k1.Secret_key.compare x y + | P256 x, P256 y -> P256.Secret_key.compare x y + | Bls x, Bls y -> Bls.Secret_key.compare x y + | _ -> Stdlib.compare a b + end) + + type Base58.data += Data of t (* unused *) + + let b58check_encoding = + (* unused *) + Base58.register_encoding + ~prefix:"\255\255" + ~length:2 + ~to_raw:(fun _ -> assert false) + ~of_raw:(fun _ -> assert false) + ~wrap:(fun x -> Data x) + + let of_b58check_opt b = + match Base58.decode b with + | Some (Ed25519.Secret_key.Data sk) -> Some (Ed25519 sk) + | Some (Secp256k1.Secret_key.Data sk) -> Some (Secp256k1 sk) + | Some (P256.Secret_key.Data sk) -> Some (P256 sk) + | Some (Bls.Secret_key.Data sk) -> Some (Bls sk) + | _ -> None + + let of_b58check_exn s = + match of_b58check_opt s with + | Some x -> x + | None -> Format.kasprintf Stdlib.failwith "Unexpected data (%s)" name + + let of_b58check s = + match of_b58check_opt s with + | Some x -> Ok x + | None -> + error_with "Failed to read a b58check_encoding data (%s): %S" name s + + let to_b58check = function + | Ed25519 sk -> Ed25519.Secret_key.to_b58check sk + | Secp256k1 sk -> Secp256k1.Secret_key.to_b58check sk + | P256 sk -> P256.Secret_key.to_b58check sk + | Bls sk -> Bls.Secret_key.to_b58check sk + + let to_short_b58check = function + | Ed25519 sk -> Ed25519.Secret_key.to_short_b58check sk + | Secp256k1 sk -> Secp256k1.Secret_key.to_short_b58check sk + | P256 sk -> P256.Secret_key.to_short_b58check sk + | Bls sk -> Bls.Secret_key.to_short_b58check sk + + include Helpers.MakeEncoder (struct + type nonrec t = t + + let name = name + + let title = title + + let raw_encoding = + let open Data_encoding in + def "secret_key" ~description:title + @@ union + [ + case + (Tag 0) + Ed25519.Secret_key.encoding + ~title:"Ed25519" + (function Ed25519 x -> Some x | _ -> None) + (function x -> Ed25519 x); + case + (Tag 1) + Secp256k1.Secret_key.encoding + ~title:"Secp256k1" + (function Secp256k1 x -> Some x | _ -> None) + (function x -> Secp256k1 x); + case + (Tag 2) + ~title:"P256" + P256.Secret_key.encoding + (function P256 x -> Some x | _ -> None) + (function x -> P256 x); + case + (Tag 3) + ~title:"Bls" + Bls.Secret_key.encoding + (function Bls x -> Some x | _ -> None) + (function x -> Bls x); + ] + + let of_b58check = of_b58check + + let of_b58check_opt = of_b58check_opt + + let of_b58check_exn = of_b58check_exn + + let to_b58check = to_b58check + + let to_short_b58check = to_short_b58check + end) + + let pp ppf t = Format.fprintf ppf "%s" (to_b58check t) +end + +type signature = + | Ed25519 of Ed25519.t + | Secp256k1 of Secp256k1.t + | P256 of P256.t + | Bls of Bls.t + | Unknown of Bytes.t + +type prefix = Bls_prefix of Bytes.t + +type splitted = {prefix : prefix option; suffix : Bytes.t} + +type t = signature + +let name = "Signature.V1" + +let title = "A Ed25519, Secp256k1, P256 or BLS signature" + +let to_bytes = function + | Ed25519 b -> Ed25519.to_bytes b + | Secp256k1 b -> Secp256k1.to_bytes b + | P256 b -> P256.to_bytes b + | Bls b -> Bls.to_bytes b + | Unknown b -> b + +let of_bytes_opt s = + let len = Bytes.length s in + if len = Bls.size then Option.map (fun b -> Bls b) (Bls.of_bytes_opt s) + else if len = Ed25519.size then Some (Unknown s) + else None + +let () = + assert (Ed25519.size = 64) ; + assert (Secp256k1.size = 64) ; + assert (P256.size = 64) ; + assert (Bls.size = 96) + +type Base58.data += Data_unknown of Bytes.t + +let unknown_b58check_encoding = + Base58.register_encoding + ~prefix:Base58.Prefix.generic_signature + ~length:Ed25519.size + ~to_raw:Bytes.to_string + ~of_raw:(fun s -> Some (Bytes.of_string s)) + ~wrap:(fun x -> Data_unknown x) + +let () = Base58.check_encoded_prefix unknown_b58check_encoding "sig" 96 + +type Base58.data += Data of t (* unused *) + +let b58check_encoding = + (* unused *) + Base58.register_encoding + ~prefix:"\255\255" + ~length:2 + ~to_raw:(fun _ -> assert false) + ~of_raw:(fun _ -> assert false) + ~wrap:(fun x -> Data x) + +include Compare.Make (struct + type nonrec t = t + + let compare a b = + let a = to_bytes a and b = to_bytes b in + Bytes.compare a b +end) + +let of_b58check_opt s = + if TzString.has_prefix ~prefix:Ed25519.b58check_encoding.encoded_prefix s then + Option.map (fun x -> Ed25519 x) (Ed25519.of_b58check_opt s) + else if + TzString.has_prefix ~prefix:Secp256k1.b58check_encoding.encoded_prefix s + then Option.map (fun x -> Secp256k1 x) (Secp256k1.of_b58check_opt s) + else if TzString.has_prefix ~prefix:P256.b58check_encoding.encoded_prefix s + then Option.map (fun x -> P256 x) (P256.of_b58check_opt s) + else if TzString.has_prefix ~prefix:Bls.b58check_encoding.encoded_prefix s + then Option.map (fun x -> Bls x) (Bls.of_b58check_opt s) + else + Option.map + (fun x -> Unknown x) + (Base58.simple_decode unknown_b58check_encoding s) + +let of_b58check_exn s = + match of_b58check_opt s with + | Some x -> x + | None -> Format.kasprintf Stdlib.failwith "Unexpected data (%s)" name + +let of_b58check s = + match of_b58check_opt s with + | Some x -> Ok x + | None -> error_with "Failed to read a b58check_encoding data (%s): %S" name s + +let to_b58check = function + | Ed25519 b -> Ed25519.to_b58check b + | Secp256k1 b -> Secp256k1.to_b58check b + | P256 b -> P256.to_b58check b + | Bls b -> Bls.to_b58check b + | Unknown b -> Base58.simple_encode unknown_b58check_encoding b + +let to_short_b58check = function + | Ed25519 b -> Ed25519.to_short_b58check b + | Secp256k1 b -> Secp256k1.to_short_b58check b + | P256 b -> P256.to_short_b58check b + | Bls b -> Bls.to_short_b58check b + | Unknown b -> Base58.simple_encode unknown_b58check_encoding b + +let raw_encoding = + conv + to_bytes + (fun b -> + match of_bytes_opt b with + | None -> + Format.kasprintf + Stdlib.failwith + "Not a valid signature: %a" + Hex.pp + (Hex.of_bytes b) + | Some s -> s) + Variable.bytes + +include Helpers.MakeEncoder (struct + type nonrec t = t + + let name = name + + let title = title + + let raw_encoding = raw_encoding + + let of_b58check = of_b58check + + let of_b58check_opt = of_b58check_opt + + let of_b58check_exn = of_b58check_exn + + let to_b58check = to_b58check + + let to_short_b58check = to_short_b58check +end) + +let to_bytes s = Data_encoding.Binary.to_bytes_exn raw_encoding s + +let of_bytes_opt s = Data_encoding.Binary.of_bytes_opt raw_encoding s + +let to_string s = Bytes.to_string (to_bytes s) + +let of_string_opt s = of_bytes_opt (Bytes.of_string s) + +include Helpers.MakeRaw (struct + type nonrec t = t + + let name = name + + let of_bytes_opt = of_bytes_opt + + let of_string_opt = of_string_opt + + let to_string = to_string +end) + +let size t = Data_encoding.Binary.length encoding t + +let pp ppf t = Format.fprintf ppf "%s" (to_b58check t) + +let of_ed25519 s = Ed25519 s + +let of_secp256k1 s = Secp256k1 s + +let of_p256 s = P256 s + +let of_bls s = Bls s + +let zero = of_ed25519 Ed25519.zero + +(* NOTE: At the moment, only BLS signatures can be encoded with a tag. We impose + this restriction so that there is only one valid binary representation for a + same signature (modulo malleability). + + We reserve the tags 0, 1, 2 and 255 for tags of the other signatures if we + decide to unify signature representation one day.*) +let prefix_encoding = + let open Data_encoding in + def + "bls_signature_prefix" + ~description:"The prefix of a BLS signature, i.e. the first 32 bytes." + @@ union + [ + case + (Tag 3) + ~title:"Bls_prefix" + (Fixed.bytes (Bls.size - Ed25519.size)) + (function Bls_prefix x -> Some x) + (function x -> Bls_prefix x); + ] + +let split_signature = function + | (Ed25519 _ | Secp256k1 _ | P256 _) as s -> + {prefix = None; suffix = to_bytes s} + | Bls s -> + let s = Bls.to_bytes s in + let prefix = Bytes.sub s 0 32 in + let suffix = Bytes.sub s 32 64 in + {prefix = Some (Bls_prefix prefix); suffix} + | Unknown s -> + assert (Compare.Int.(Bytes.length s = 64)) ; + {prefix = None; suffix = s} + +let of_splitted {prefix; suffix} = + let open Option_syntax in + match prefix with + | None -> of_bytes_opt suffix + | Some (Bls_prefix prefix) -> + let+ s = Bls.of_bytes_opt (Bytes.cat prefix suffix) in + Bls s + +let bytes_of_watermark = function + | Block_header chain_id -> + Bytes.cat (Bytes.of_string "\x01") (Chain_id.to_bytes chain_id) + | Endorsement chain_id -> + Bytes.cat (Bytes.of_string "\x02") (Chain_id.to_bytes chain_id) + | Generic_operation -> Bytes.of_string "\x03" + | Custom bytes -> bytes + +let pp_watermark ppf = + let open Format in + function + | Block_header chain_id -> fprintf ppf "Block-header: %a" Chain_id.pp chain_id + | Endorsement chain_id -> fprintf ppf "Endorsement: %a" Chain_id.pp chain_id + | Generic_operation -> pp_print_string ppf "Generic-operation" + | Custom bytes -> + let hexed = Hex.of_bytes bytes |> Hex.show in + fprintf + ppf + "Custom: 0x%s" + (try String.sub hexed 0 10 ^ "..." with Invalid_argument _ -> hexed) + +let sign ?watermark secret_key message = + let watermark = Option.map bytes_of_watermark watermark in + match secret_key with + | Secret_key.Ed25519 sk -> of_ed25519 (Ed25519.sign ?watermark sk message) + | Secp256k1 sk -> of_secp256k1 (Secp256k1.sign ?watermark sk message) + | P256 sk -> of_p256 (P256.sign ?watermark sk message) + | Bls sk -> of_bls (Bls.sign ?watermark sk message) + +let check ?watermark public_key signature message = + let watermark = Option.map bytes_of_watermark watermark in + match (public_key, signature) with + | Public_key.Ed25519 pk, Unknown signature -> ( + match Ed25519.of_bytes_opt signature with + | Some s -> Ed25519.check ?watermark pk s message + | None -> false) + | Public_key.Secp256k1 pk, Unknown signature -> ( + match Secp256k1.of_bytes_opt signature with + | Some s -> Secp256k1.check ?watermark pk s message + | None -> false) + | Public_key.P256 pk, Unknown signature -> ( + match P256.of_bytes_opt signature with + | Some s -> P256.check ?watermark pk s message + | None -> false) + | Public_key.Bls pk, Unknown signature -> ( + match Bls.of_bytes_opt signature with + | Some s -> Bls.check ?watermark pk s message + | None -> false) + | Public_key.Ed25519 pk, Ed25519 signature -> + Ed25519.check ?watermark pk signature message + | Public_key.Secp256k1 pk, Secp256k1 signature -> + Secp256k1.check ?watermark pk signature message + | Public_key.P256 pk, P256 signature -> + P256.check ?watermark pk signature message + | Public_key.Bls pk, Bls signature -> + Bls.check ?watermark pk signature message + | _ -> false + +let fake_sign_from_pk pk msg = + let pk_bytes = Data_encoding.Binary.to_bytes_exn Public_key.encoding pk in + let size = Ed25519.size in + let msg = Blake2B.to_bytes @@ Blake2B.hash_bytes [msg] in + let half = size / 2 in + let tmp = Bytes.init size (fun _ -> '0') in + let all_or_half buf = Stdlib.min (Bytes.length buf) half in + Bytes.blit pk_bytes 0 tmp 0 (all_or_half pk_bytes) ; + Bytes.blit msg 0 tmp half (all_or_half msg) ; + of_bytes_exn tmp + +type algo = Ed25519 | Secp256k1 | P256 | Bls + +let fake_sign ?watermark:_ secret_key msg = + let pk = Secret_key.to_public_key secret_key in + fake_sign_from_pk pk msg + +let hardcoded_sk algo : secret_key = + match algo with + | Ed25519 -> + Secret_key.of_b58check_exn + "edsk3gUfUPyBSfrS9CCgmCiQsTCHGkviBDusMxDJstFtojtc1zcpsh" + | Secp256k1 -> + Secret_key.of_b58check_exn + "spsk2XJu4wuYsHeuDaCktD3ECnnpn574ceSWHEJVvXTt7JP6ztySCL" + | P256 -> + Secret_key.of_b58check_exn + "p2sk2k6YAkNJ8CySZCS3vGA5Ht6Lj6LXG3yb8UrHvMKZy7Ab8JUtWh" + | Bls -> + Secret_key.of_b58check_exn + "BLsk1hfuv6V8JJRaLDBJgPTRGLKusTZnTmWGrvSKYzUaMuzvPLmeGG" + +let hardcoded_pk = + (* precompute signatures *) + let ed, secp, p, bls = + ( Secret_key.to_public_key (hardcoded_sk Ed25519), + Secret_key.to_public_key (hardcoded_sk Secp256k1), + Secret_key.to_public_key (hardcoded_sk P256), + Secret_key.to_public_key (hardcoded_sk Bls) ) + in + function Ed25519 -> ed | Secp256k1 -> secp | P256 -> p | Bls -> bls + +let hardcoded_msg = Bytes.of_string "Cheers" + +let hardcoded_sig = + (* precompute signatures *) + let ed, secp, p, bls = + ( sign (hardcoded_sk Ed25519) hardcoded_msg, + sign (hardcoded_sk Secp256k1) hardcoded_msg, + sign (hardcoded_sk P256) hardcoded_msg, + sign (hardcoded_sk Bls) hardcoded_msg ) + in + function Ed25519 -> ed | Secp256k1 -> secp | P256 -> p | Bls -> bls + +let algo_of_pk (pk : Public_key.t) = + match pk with + | Ed25519 _ -> Ed25519 + | Secp256k1 _ -> Secp256k1 + | P256 _ -> P256 + | Bls _ -> Bls + +let fast_fake_sign ?watermark:_ sk _msg = + let pk = Secret_key.to_public_key sk in + hardcoded_sig (algo_of_pk pk) + +let check_harcoded_signature pk = + let algo = algo_of_pk pk in + check (hardcoded_pk algo) (hardcoded_sig algo) hardcoded_msg + +(* The following cache is a hack to work around a quadratic algorithm + in Tezos Mainnet protocols up to Edo. *) + +module type ENDORSEMENT_CACHE_MAKER = functor (H : Stdlib.Hashtbl.HashedType) -> + Aches.Vache.MAP with type key = H.t + +let make_endorsement_cache : (module ENDORSEMENT_CACHE_MAKER) = + match Sys.getenv_opt "TEZOS_DISABLE_ENDORSEMENT_SIGNATURE_CACHE" with + | Some _ -> (module Aches.Vache.EmptyMap) + | None -> + (module Aches.Vache.Map (Aches.Vache.FIFO_Sloppy) (Aches.Vache.Strong)) + +module Endorsement_cache = + (val make_endorsement_cache) + (struct + type nonrec t = t + + let equal = equal + + let hash = Hashtbl.hash + end) + +let endorsement_cache = Endorsement_cache.create 300 + +let check ?watermark public_key signature message = + match watermark with + | Some (Endorsement _) -> ( + (* signature check cache only applies to endorsements *) + match Endorsement_cache.find_opt endorsement_cache signature with + | Some (key, msg) -> + (* we rely on this property : signature_1 = signature_2 => key_1 = key_2 /\ message_1 = message_2 *) + Public_key.equal public_key key && Bytes.equal msg message + | None -> + let res = check ?watermark public_key signature message in + if res then + Endorsement_cache.replace + endorsement_cache + signature + (public_key, message) ; + res) + | _ -> check ?watermark public_key signature message + +let fake_check ?watermark:_ pk _signature msg = + (* computing the fake signature do hash the message, + this operation is linear in the size of the message *) + ignore (fake_sign_from_pk pk msg) ; + (* checking a valid, harcoded signature, to do at least once the crypto maths *) + let _ = check_harcoded_signature pk in + true + +(* Fast checking does not simulate computation and directly returns true*) +let fast_fake_check ?watermark:_ _pk _signature _msg = true + +let sign = + match Helpers.yes_crypto_kind with + | Fast -> fast_fake_sign + | Yes -> fake_sign + | No -> sign + +let check = + match Helpers.yes_crypto_kind with + | Fast -> fast_fake_check + | Yes -> fake_check + | No -> check + +let append ?watermark sk msg = Bytes.cat msg (to_bytes (sign ?watermark sk msg)) + +let concat msg signature = Bytes.cat msg (to_bytes signature) + +let algos = [Ed25519; Secp256k1; P256; Bls] + +let fake_generate_key (pkh, pk, _) = + let sk_of_pk (pk : public_key) : secret_key = + let pk_b = Data_encoding.Binary.to_bytes_exn Public_key.encoding pk in + let sk_b = Bytes.sub pk_b 0 33 in + let sk = Data_encoding.Binary.of_bytes_exn Secret_key.encoding sk_b in + sk + in + let fake_sk = sk_of_pk pk in + (pkh, pk, fake_sk) + +let generate_key ?(algo = Ed25519) ?seed () = + match algo with + | Ed25519 -> + let pkh, pk, sk = Ed25519.generate_key ?seed () in + (Public_key_hash.Ed25519 pkh, Public_key.Ed25519 pk, Secret_key.Ed25519 sk) + | Secp256k1 -> + let pkh, pk, sk = Secp256k1.generate_key ?seed () in + ( Public_key_hash.Secp256k1 pkh, + Public_key.Secp256k1 pk, + Secret_key.Secp256k1 sk ) + | P256 -> + let pkh, pk, sk = P256.generate_key ?seed () in + (Public_key_hash.P256 pkh, Public_key.P256 pk, Secret_key.P256 sk) + | Bls -> + let pkh, pk, sk = Bls.generate_key ?seed () in + (Public_key_hash.Bls pkh, Public_key.Bls pk, Secret_key.Bls sk) + +let fake_generate_key ?(algo = Ed25519) ?seed () = + let true_keys = generate_key ~algo ?seed () in + fake_generate_key true_keys + +let generate_key = + match Helpers.yes_crypto_kind with + | Fast | Yes -> + (* We keep the original keys generation to stay as close as possible of the + initial performance. *) + fake_generate_key + | No -> generate_key + +let deterministic_nonce sk msg = + match sk with + | Secret_key.Ed25519 sk -> Ed25519.deterministic_nonce sk msg + | Secret_key.Secp256k1 sk -> Secp256k1.deterministic_nonce sk msg + | Secret_key.P256 sk -> P256.deterministic_nonce sk msg + | Secret_key.Bls sk -> Bls.deterministic_nonce sk msg + +let deterministic_nonce_hash sk msg = + match sk with + | Secret_key.Ed25519 sk -> Ed25519.deterministic_nonce_hash sk msg + | Secret_key.Secp256k1 sk -> Secp256k1.deterministic_nonce_hash sk msg + | Secret_key.P256 sk -> P256.deterministic_nonce_hash sk msg + | Secret_key.Bls sk -> Bls.deterministic_nonce_hash sk msg + +module Of_V0 = struct + let public_key_hash : Signature_v0.Public_key_hash.t -> Public_key_hash.t = + function + | Signature_v0.Ed25519 k -> Ed25519 k + | Signature_v0.Secp256k1 k -> Secp256k1 k + | Signature_v0.P256 k -> P256 k + + let public_key : Signature_v0.Public_key.t -> Public_key.t = function + | Signature_v0.Ed25519 k -> Ed25519 k + | Signature_v0.Secp256k1 k -> Secp256k1 k + | Signature_v0.P256 k -> P256 k + + let secret_key : Signature_v0.Secret_key.t -> Secret_key.t = function + | Signature_v0.Ed25519 k -> Ed25519 k + | Signature_v0.Secp256k1 k -> Secp256k1 k + | Signature_v0.P256 k -> P256 k + + let signature : Signature_v0.t -> t = function + | Signature_v0.Ed25519 k -> Ed25519 k + | Signature_v0.Secp256k1 k -> Secp256k1 k + | Signature_v0.P256 k -> P256 k + | Signature_v0.Unknown k -> Unknown k +end diff --git a/src/lib_crypto/signature_v2.mli b/src/lib_crypto/signature_v2.mli new file mode 100644 index 000000000000..a3c9f7994baa --- /dev/null +++ b/src/lib_crypto/signature_v2.mli @@ -0,0 +1,115 @@ +(*****************************************************************************) +(* *) +(* SPDX-License-Identifier: MIT *) +(* SPDX-FileCopyrightText: 2025 Nomadic Labs *) +(* *) +(*****************************************************************************) + +type public_key_hash = + | Ed25519 of Ed25519.Public_key_hash.t + | Secp256k1 of Secp256k1.Public_key_hash.t + | P256 of P256.Public_key_hash.t + | Bls of Bls.Public_key_hash.t + +type public_key = + | Ed25519 of Ed25519.Public_key.t + | Secp256k1 of Secp256k1.Public_key.t + | P256 of P256.Public_key.t + | Bls of Bls.Public_key.t + +type secret_key = + | Ed25519 of Ed25519.Secret_key.t + | Secp256k1 of Secp256k1.Secret_key.t + | P256 of P256.Secret_key.t + | Bls of Bls.Secret_key.t + +type watermark = Signature_v0.watermark = + | Block_header of Chain_id.t + | Endorsement of Chain_id.t + | Generic_operation + | Custom of Bytes.t + +val bytes_of_watermark : watermark -> Bytes.t + +val pp_watermark : Format.formatter -> watermark -> unit + +type signature = + | Ed25519 of Ed25519.t + | Secp256k1 of Secp256k1.t + | P256 of P256.t + | Bls of Bls.t + | Unknown of Bytes.t + +(** A signature prefix holds data only for signature that are more than 64 bytes + long. *) +type prefix = Bls_prefix of Bytes.t + +include + S.SPLIT_SIGNATURE + with type Public_key_hash.t = public_key_hash + and type Public_key.t = public_key + and type Secret_key.t = secret_key + and type watermark := watermark + and type prefix := prefix + and type t = signature + +(** [append sk buf] is the concatenation of [buf] and the + serialization of the signature of [buf] signed by [sk]. *) +val append : ?watermark:watermark -> secret_key -> Bytes.t -> Bytes.t + +(** [concat buf t] is the concatenation of [buf] and the serialization + of [t]. *) +val concat : Bytes.t -> t -> Bytes.t + +include S.RAW_DATA with type t := t + +(** The size of the signature in bytes. Can be [64] for Ed25519, Secp256k1 and + P256 signatures or [96] for BLS signatures. *) +val size : t -> int + +(** [of_secp256k1 s] returns a wrapped version of the Secp256k1 signature [s] in + {!t}. *) +val of_secp256k1 : Secp256k1.t -> t + +(** [of_ed25519 s] returns a wrapped version of the Ed25519 signature [s] in + {!t}. *) +val of_ed25519 : Ed25519.t -> t + +(** [of_p256 s] returns a wrapped version of the P256 signature [s] in {!t}. *) +val of_p256 : P256.t -> t + +(** [of_bls s] returns a wrapped version of the BLS signature [s] in {!t}. *) +val of_bls : Bls.t -> t + +(** The type of signing algorithms. *) +type algo = Ed25519 | Secp256k1 | P256 | Bls + +(** The list of signing algorithm supported, i.e. all constructors of type + {!algo}. *) +val algos : algo list + +(** [generate_key ~algo ~seed ()] generates a key pair for the signing algorithm + [algo] from the random seed [seed]. *) +val generate_key : + ?algo:algo -> + ?seed:Bytes.t -> + unit -> + public_key_hash * public_key * secret_key + +(** This module provides conversion functions for values (of keys and + signatures) of the module {!Signature_V0}. Note that these functions are + total because [Signature_v1] supports more signature kinds than + {!Signature_v0}. *) +module Of_V0 : sig + (** Convert a public key hash from V0 to V1. *) + val public_key_hash : Signature_v0.Public_key_hash.t -> Public_key_hash.t + + (** Convert a public key from V0 to V1. *) + val public_key : Signature_v0.Public_key.t -> Public_key.t + + (** Convert a secret key from V0 to V1. *) + val secret_key : Signature_v0.Secret_key.t -> Secret_key.t + + (** Convert a signature from V0 to V1. *) + val signature : Signature_v0.t -> t +end -- GitLab From 5fbd6346b2d703071e3328c200afd196ee5548ad Mon Sep 17 00:00:00 2001 From: Adam Allombert-Goget Date: Tue, 22 Oct 2024 14:24:42 +0200 Subject: [PATCH 02/20] Crypto: update signature_v2 --- src/lib_crypto/signature_v2.ml | 28 ++++++++++++++++++++++++++++ src/lib_crypto/signature_v2.mli | 18 ++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/src/lib_crypto/signature_v2.ml b/src/lib_crypto/signature_v2.ml index 92bfed38e647..4375503a3332 100644 --- a/src/lib_crypto/signature_v2.ml +++ b/src/lib_crypto/signature_v2.ml @@ -1013,3 +1013,31 @@ module Of_V0 = struct | Signature_v0.P256 k -> P256 k | Signature_v0.Unknown k -> Unknown k end + +module Of_V1 = struct + let public_key_hash : Signature_v1.Public_key_hash.t -> Public_key_hash.t = + function + | Signature_v1.Ed25519 k -> Ed25519 k + | Signature_v1.Secp256k1 k -> Secp256k1 k + | Signature_v1.P256 k -> P256 k + | Signature_v1.Bls k -> Bls k + + let public_key : Signature_v1.Public_key.t -> Public_key.t = function + | Signature_v1.Ed25519 k -> Ed25519 k + | Signature_v1.Secp256k1 k -> Secp256k1 k + | Signature_v1.P256 k -> P256 k + | Signature_v1.Bls k -> Bls k + + let secret_key : Signature_v1.Secret_key.t -> Secret_key.t = function + | Signature_v1.Ed25519 k -> Ed25519 k + | Signature_v1.Secp256k1 k -> Secp256k1 k + | Signature_v1.P256 k -> P256 k + | Signature_v1.Bls k -> Bls k + + let signature : Signature_v1.t -> t = function + | Signature_v1.Ed25519 k -> Ed25519 k + | Signature_v1.Secp256k1 k -> Secp256k1 k + | Signature_v1.P256 k -> P256 k + | Signature_v1.Unknown k -> Unknown k + | Signature_v1.Bls k -> Bls k +end diff --git a/src/lib_crypto/signature_v2.mli b/src/lib_crypto/signature_v2.mli index a3c9f7994baa..cc9217248cda 100644 --- a/src/lib_crypto/signature_v2.mli +++ b/src/lib_crypto/signature_v2.mli @@ -113,3 +113,21 @@ module Of_V0 : sig (** Convert a signature from V0 to V1. *) val signature : Signature_v0.t -> t end + +(** This module provides conversion functions for values (of keys and + signatures) of the module {!Signature_V1}. Note that these functions are + total because [Signature_v1] supports more signature kinds than + {!Signature_v0}. *) +module Of_V1 : sig + (** Convert a public key hash from V1 to V2. *) + val public_key_hash : Signature_v1.Public_key_hash.t -> Public_key_hash.t + + (** Convert a public key from V1 to V2. *) + val public_key : Signature_v1.Public_key.t -> Public_key.t + + (** Convert a secret key from V1 to V2. *) + val secret_key : Signature_v1.Secret_key.t -> Secret_key.t + + (** Convert a signature from V1 to V2. *) + val signature : Signature_v1.t -> t +end -- GitLab From 4eb96401a5ea2e7197e1e9e5c628805a44d4bc1d Mon Sep 17 00:00:00 2001 From: Adam Allombert-Goget Date: Tue, 22 Oct 2024 14:30:24 +0200 Subject: [PATCH 03/20] Crypto: add signature_v2 in signature.ml and set it as the latest --- src/lib_crypto/signature.ml | 40 +++++++++++++++++++++++++++++++++--- src/lib_crypto/signature.mli | 18 +++++++++++++--- 2 files changed, 52 insertions(+), 6 deletions(-) diff --git a/src/lib_crypto/signature.ml b/src/lib_crypto/signature.ml index 03b05a8c4663..7aa61b2d519d 100644 --- a/src/lib_crypto/signature.ml +++ b/src/lib_crypto/signature.ml @@ -54,7 +54,7 @@ module type CONV_OPT = sig val signature : V_from.t -> V_to.t option end -module V_latest = Signature_v1 +module V_latest = Signature_v2 module V0 = struct include Signature_v0 @@ -95,6 +95,40 @@ module V1 = struct module Of_V_latest : CONV_OPT with module V_from := V_latest and module V_to := Signature_v1 = + struct + let public_key_hash : V_latest.Public_key_hash.t -> Public_key_hash.t option + = function + | V_latest.Ed25519 k -> Some (Ed25519 k) + | V_latest.Secp256k1 k -> Some (Secp256k1 k) + | V_latest.P256 k -> Some (P256 k) + | V_latest.Bls k -> Some (Bls k) + + let public_key : V_latest.Public_key.t -> Public_key.t option = function + | V_latest.Ed25519 k -> Some (Ed25519 k) + | V_latest.Secp256k1 k -> Some (Secp256k1 k) + | V_latest.P256 k -> Some (P256 k) + | V_latest.Bls k -> Some (Bls k) + + let secret_key : V_latest.Secret_key.t -> Secret_key.t option = function + | V_latest.Ed25519 k -> Some (Ed25519 k) + | V_latest.Secp256k1 k -> Some (Secp256k1 k) + | V_latest.P256 k -> Some (P256 k) + | V_latest.Bls k -> Some (Bls k) + + let signature : V_latest.t -> t option = function + | V_latest.Ed25519 k -> Some (Ed25519 k) + | V_latest.Secp256k1 k -> Some (Secp256k1 k) + | V_latest.P256 k -> Some (P256 k) + | V_latest.Unknown k -> Some (Unknown k) + | V_latest.Bls k -> Some (Bls k) + end +end + +module V2 = struct + include Signature_v2 + + module Of_V_latest : + CONV_OPT with module V_from := V_latest and module V_to := Signature_v2 = struct let public_key_hash = Option.some @@ -107,9 +141,9 @@ module V1 = struct end include V_latest -module Of_V_latest = V1.Of_V_latest +module Of_V_latest = V2.Of_V_latest -module Of_V1 : CONV with module V_from := V1 and module V_to := V1 = struct +module Of_V2 : CONV with module V_from := V2 and module V_to := V2 = struct let public_key_hash = Fun.id let public_key = Fun.id diff --git a/src/lib_crypto/signature.mli b/src/lib_crypto/signature.mli index 01a26a7546c2..83befd6a2e85 100644 --- a/src/lib_crypto/signature.mli +++ b/src/lib_crypto/signature.mli @@ -61,7 +61,7 @@ end (** The module [V_latest] is to be used by the shell and points to the latest available version of signatures. *) -module V_latest : module type of Signature_v1 +module V_latest : module type of Signature_v2 (** [V0] supports Ed25519, Secp256k1, and P256. *) module V0 : sig @@ -72,7 +72,7 @@ module V0 : sig CONV_OPT with module V_from := V_latest and module V_to := Signature_v0 end -(** [V1] supports Ed25519, Secp256k1, P256, and BLS. *) +(** [V1] supports Ed25519, Secp256k1, P256, and BLS (aug). *) module V1 : sig include module type of Signature_v1 @@ -81,12 +81,21 @@ module V1 : sig CONV_OPT with module V_from := V_latest and module V_to := Signature_v1 end +(** [V2] supports Ed25519, Secp256k1, P256, and BLS (aug). *) +module V2 : sig + include module type of Signature_v2 + + (** Converting from signatures of {!V_latest} to {!V2}. *) + module Of_V_latest : + CONV_OPT with module V_from := V_latest and module V_to := Signature_v2 +end + include module type of V_latest (** Converting from signatures of {!V_latest} to {!V_latest}. This module implements conversions which are the identity, so total, but we keep the signature as {!CONV_OPT} for compatibility with {!V0.Of_V_latest} and - {!V1.Of_V_latest} and to ease snapshotting. *) + {!V1.Of_V_latest} and to ease snapshotting. TODO ADAPT THIS WITH V2*) module Of_V_latest : CONV_OPT with module V_from := V_latest and module V_to := V_latest @@ -95,3 +104,6 @@ module Of_V0 : CONV with module V_from := V0 and module V_to := V_latest (** Converting from signatures of {!V1} to {!V_latest}. *) module Of_V1 : CONV with module V_from := V1 and module V_to := V_latest + +(** Converting from signatures of {!V2} to {!V_latest}. *) +module Of_V2 : CONV with module V_from := V2 and module V_to := V_latest -- GitLab From 4d6a9c1624b274665185f62dcaaefe303bea77b6 Mon Sep 17 00:00:00 2001 From: Adam Allombert-Goget Date: Tue, 22 Oct 2024 14:42:49 +0200 Subject: [PATCH 04/20] Client_base: update client_keys to handle signature V2 --- src/lib_client_base/client_keys.ml | 35 +++++++++++++++++++++++++++++ src/lib_client_base/client_keys.mli | 8 +++++++ 2 files changed, 43 insertions(+) diff --git a/src/lib_client_base/client_keys.ml b/src/lib_client_base/client_keys.ml index 01b8adea0dd3..bb8213e143aa 100644 --- a/src/lib_client_base/client_keys.ml +++ b/src/lib_client_base/client_keys.ml @@ -908,6 +908,41 @@ module V1 = Make (struct let generate_key = generate_key ?algo:None + module Adapter = struct + let public_key_hash : + Tezos_crypto.Signature.Public_key_hash.t -> Public_key_hash.t tzresult = + let open Result_syntax in + function + | Bls k -> return (Bls k : Public_key_hash.t) + | Ed25519 k -> return (Ed25519 k : Public_key_hash.t) + | Secp256k1 k -> return (Secp256k1 k : Public_key_hash.t) + | P256 k -> return (P256 k : Public_key_hash.t) + + let public_key : + Tezos_crypto.Signature.Public_key.t -> Public_key.t tzresult = + let open Result_syntax in + function + | Bls k -> return (Bls k : Public_key.t) + | Ed25519 k -> return (Ed25519 k : Public_key.t) + | Secp256k1 k -> return (Secp256k1 k : Public_key.t) + | P256 k -> return (P256 k : Public_key.t) + + let signature : Tezos_crypto.Signature.t -> t tzresult = + let open Result_syntax in + function + | Bls k -> return (Bls k : t) + | Ed25519 k -> return (Ed25519 k : t) + | Secp256k1 k -> return (Secp256k1 k : t) + | P256 k -> return (P256 k : t) + | Unknown k -> return (Unknown k : t) + end +end) + +module V2 = Make (struct + include Tezos_crypto.Signature.V2 + + let generate_key = generate_key ?algo:None + module Adapter = struct let identity x = Ok x diff --git a/src/lib_client_base/client_keys.mli b/src/lib_client_base/client_keys.mli index f16b65f46308..cf9cdb76bb80 100644 --- a/src/lib_client_base/client_keys.mli +++ b/src/lib_client_base/client_keys.mli @@ -288,6 +288,14 @@ module V1 : and type watermark := Tezos_crypto.Signature.V1.watermark and type signature := Tezos_crypto.Signature.V1.t +module V2 : + S + with type public_key_hash := Tezos_crypto.Signature.V2.Public_key_hash.t + and type public_key := Tezos_crypto.Signature.V2.Public_key.t + and type secret_key := Tezos_crypto.Signature.V2.Secret_key.t + and type watermark := Tezos_crypto.Signature.V2.watermark + and type signature := Tezos_crypto.Signature.V2.t + module V_latest : S with type public_key_hash := -- GitLab From 2e11b1eef9f605f1de98e43cc909dbec3b1ab95b Mon Sep 17 00:00:00 2001 From: Adam Allombert-Goget Date: Tue, 22 Oct 2024 15:38:29 +0200 Subject: [PATCH 05/20] Client_base: add client_keys_v2 --- src/lib_client_base/client_keys_v2.ml | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 src/lib_client_base/client_keys_v2.ml diff --git a/src/lib_client_base/client_keys_v2.ml b/src/lib_client_base/client_keys_v2.ml new file mode 100644 index 000000000000..7b1c872c50eb --- /dev/null +++ b/src/lib_client_base/client_keys_v2.ml @@ -0,0 +1,11 @@ +(*****************************************************************************) +(* *) +(* SPDX-License-Identifier: MIT *) +(* SPDX-FileCopyrightText: 2025 Nomadic Labs *) +(* *) +(*****************************************************************************) + +(** Module to use keys over {!Tezos_crypto.Signature.V2} *) + +include Client_keys +include Client_keys.V2 -- GitLab From 1ce1e13f10569ae2863db376e7883fb19628448f Mon Sep 17 00:00:00 2001 From: Albin Coquereau Date: Fri, 7 Feb 2025 12:32:46 +0100 Subject: [PATCH 06/20] Crypto: introduce signature compatibility helper functions --- src/lib_crypto/signature.ml | 159 +++++++++++++++++++++++++++++++++++ src/lib_crypto/signature.mli | 15 ++++ 2 files changed, 174 insertions(+) diff --git a/src/lib_crypto/signature.ml b/src/lib_crypto/signature.ml index 7aa61b2d519d..ccac7d958a26 100644 --- a/src/lib_crypto/signature.ml +++ b/src/lib_crypto/signature.ml @@ -52,6 +52,21 @@ module type CONV_OPT = sig val secret_key : V_from.Secret_key.t -> V_to.Secret_key.t option val signature : V_from.t -> V_to.t option + + val get_public_key : + V_from.Public_key.t -> V_to.Public_key.t Error_monad.tzresult + + val get_public_key_exn : V_from.Public_key.t -> V_to.Public_key.t + + val get_public_key_hash : + V_from.Public_key_hash.t -> V_to.Public_key_hash.t Error_monad.tzresult + + val get_public_key_hash_exn : + V_from.Public_key_hash.t -> V_to.Public_key_hash.t + + val get_signature : V_from.t -> V_to.t Error_monad.tzresult + + val get_signature_exn : V_from.t -> V_to.t end module V_latest = Signature_v2 @@ -87,6 +102,54 @@ module V0 = struct | V_latest.P256 k -> Some (P256 k) | V_latest.Unknown k -> Some (Unknown k) | V_latest.Bls _ -> None + + let get_public_key pk = + match public_key pk with + | Some pk -> Ok pk + | None -> + Error_monad.error_with + "Conversion of public key from latest signature version to V0 \ + impossible." + + let get_public_key_exn pk = + match public_key pk with + | Some pk -> pk + | None -> + Stdlib.failwith + "Conversion of public key hash from latest signature version to V0 \ + impossible." + + let get_public_key_hash pkh = + match public_key_hash pkh with + | Some pkh -> Ok pkh + | None -> + Error_monad.error_with + "Conversion of public key hash from latest signature version to V0 \ + impossible." + + let get_public_key_hash_exn pkh = + match public_key_hash pkh with + | Some pkh -> pkh + | None -> + Stdlib.failwith + "Conversion of public key hash from latest signature version to V0 \ + impossible." + + let get_signature s = + match signature s with + | Some s -> Ok s + | None -> + Error_monad.error_with + "Conversion of signature from latest signature version to V0 \ + impossible." + + let get_signature_exn s = + match signature s with + | Some s -> s + | None -> + Stdlib.failwith + "Conversion of signature from latest signature version to V0 \ + impossible." end end @@ -121,6 +184,54 @@ module V1 = struct | V_latest.P256 k -> Some (P256 k) | V_latest.Unknown k -> Some (Unknown k) | V_latest.Bls k -> Some (Bls k) + + let get_public_key pk = + match public_key pk with + | Some pk -> Ok pk + | None -> + Error_monad.error_with + "Conversion of public key from latest signature version to V1 \ + impossible." + + let get_public_key_exn pk = + match public_key pk with + | Some pk -> pk + | None -> + Stdlib.failwith + "Conversion of public key hash from latest signature version to V1 \ + impossible." + + let get_public_key_hash pkh = + match public_key_hash pkh with + | Some pkh -> Ok pkh + | None -> + Error_monad.error_with + "Conversion of public key hash from latest signature version to V1 \ + impossible." + + let get_public_key_hash_exn pkh = + match public_key_hash pkh with + | Some pkh -> pkh + | None -> + Stdlib.failwith + "Conversion of public key hash from latest signature version to V1 \ + impossible." + + let get_signature s = + match signature s with + | Some s -> Ok s + | None -> + Error_monad.error_with + "Conversion of signature from latest signature version to V1 \ + impossible." + + let get_signature_exn s = + match signature s with + | Some s -> s + | None -> + Stdlib.failwith + "Conversion of signature from latest signature version to V1 \ + impossible." end end @@ -137,6 +248,54 @@ module V2 = struct let secret_key = Option.some let signature = Option.some + + let get_public_key pk = + match public_key pk with + | Some pk -> Ok pk + | None -> + Error_monad.error_with + "Conversion of public key from latest signature version to V2 \ + impossible." + + let get_public_key_exn pk = + match public_key pk with + | Some pk -> pk + | None -> + Stdlib.failwith + "Conversion of public key hash from latest signature version to V2 \ + impossible." + + let get_public_key_hash pkh = + match public_key_hash pkh with + | Some pkh -> Ok pkh + | None -> + Error_monad.error_with + "Conversion of public key hash from latest signature version to V2 \ + impossible." + + let get_public_key_hash_exn pkh = + match public_key_hash pkh with + | Some pkh -> pkh + | None -> + Stdlib.failwith + "Conversion of public key hash from latest signature version to V2 \ + impossible." + + let get_signature s = + match signature s with + | Some s -> Ok s + | None -> + Error_monad.error_with + "Conversion of signature from latest signature version to V2 \ + impossible." + + let get_signature_exn s = + match signature s with + | Some s -> s + | None -> + Stdlib.failwith + "Conversion of signature from latest signature version to V2 \ + impossible." end end diff --git a/src/lib_crypto/signature.mli b/src/lib_crypto/signature.mli index 83befd6a2e85..e7faf48a6f95 100644 --- a/src/lib_crypto/signature.mli +++ b/src/lib_crypto/signature.mli @@ -57,6 +57,21 @@ module type CONV_OPT = sig val secret_key : V_from.Secret_key.t -> V_to.Secret_key.t option val signature : V_from.t -> V_to.t option + + val get_public_key : + V_from.Public_key.t -> V_to.Public_key.t Error_monad.tzresult + + val get_public_key_exn : V_from.Public_key.t -> V_to.Public_key.t + + val get_public_key_hash : + V_from.Public_key_hash.t -> V_to.Public_key_hash.t Error_monad.tzresult + + val get_public_key_hash_exn : + V_from.Public_key_hash.t -> V_to.Public_key_hash.t + + val get_signature : V_from.t -> V_to.t Error_monad.tzresult + + val get_signature_exn : V_from.t -> V_to.t end (** The module [V_latest] is to be used by the shell and points to the latest -- GitLab From 4da2eb0e502b82bbba810450f2ccc7ac9d1912e9 Mon Sep 17 00:00:00 2001 From: Albin Coquereau Date: Mon, 27 Jan 2025 17:48:04 +0100 Subject: [PATCH 07/20] Manifest: fix signature versioning compatibility --- manifest/product_octez.ml | 64 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/manifest/product_octez.ml b/manifest/product_octez.ml index e3bb50774175..c6c2ea7b0cf8 100644 --- a/manifest/product_octez.ml +++ b/manifest/product_octez.ml @@ -6431,6 +6431,33 @@ let hash = Protocol.hash let {Lib_protocol.main; lifted; embedded} = Lib_protocol.make ~name ~status in + let dune_signatures_version_rule = + Dune.targets_rule + ["signature.ml"] + ~action: + [ + S "write-file"; + S "%{targets}"; + S + (sf + {| module Bls = Tezos_crypto.Signature.Bls + module Ed25519 = Tezos_crypto.Signature.Ed25519 + module P256 = Tezos_crypto.Signature.P256 + module Secp256k1 = Tezos_crypto.Signature.Secp256k1 + include Tezos_crypto.Signature.V1|}); + ] + in + let dune_client_keys_version_rule = + Dune.( + targets_rule + ["client_keys.ml"] + ~action: + [ + S "write-file"; + S "%{targets}"; + S (sf {|include Tezos_client_base.Client_keys_v1|}); + ]) + in let parameters = only_if (N.(number >= 011) && not_overridden) @@ fun () -> public_lib @@ -6444,6 +6471,7 @@ let hash = Protocol.hash main |> open_; ] ~linkall:true + ~dune:(if N.(number >= 016) then [dune_signatures_version_rule] else []) in let _parameters_exe = opt_map parameters @@ fun parameters -> @@ -6521,6 +6549,7 @@ let hash = Protocol.hash ] ~all_modules_except:["Plugin_registerer"] ~bisect_ppx:(if N.(number >= 008) then Yes else No) + ~dune:(if N.(number >= 016) then [dune_signatures_version_rule] else []) in let plugin_registerer = opt_map plugin @@ fun plugin -> @@ -6583,6 +6612,10 @@ let hash = Protocol.hash Some ["-cclib"; "-lblst"; "-cclib"; "-loctez_rustzcash_deps"] else None) ~linkall:true + ~dune: + (if N.(number >= 016) then + [dune_client_keys_version_rule; dune_signatures_version_rule] + else []) in let test_helpers = only_if active @@ fun () -> @@ -6613,6 +6646,7 @@ let hash = Protocol.hash octez_crypto_dal |> if_ N.(number >= 016) |> open_; octez_sc_rollup |> if_some |> if_ N.(number >= 018) |> open_; ] + ~dune:[dune_signatures_version_rule] in let _plugin_tests = opt_map (both plugin test_helpers) @@ fun (plugin, test_helpers) -> @@ -6706,6 +6740,10 @@ let hash = Protocol.hash ~bisect_ppx:(if N.(number >= 008) then Yes else No) ~linkall:true ~all_modules_except:["alpha_commands_registration"] + ~dune: + (if N.(number >= 016) then + [dune_signatures_version_rule; dune_client_keys_version_rule] + else []) in let client_sapling = only_if (N.(number >= 011) && not_overridden) @@ fun () -> @@ -6807,6 +6845,7 @@ let hash = Protocol.hash (if N.(number <= 011) then ["Delegate_commands"; "Delegate_commands_registration"] else ["Baking_commands"; "Baking_commands_registration"]) + ~dune:[dune_signatures_version_rule; dune_client_keys_version_rule] in let tenderbrute = only_if active @@ fun () -> @@ -6826,6 +6865,7 @@ let hash = Protocol.hash client |> if_some |> open_; ] ~bisect_ppx:No + ~dune:[dune_signatures_version_rule] in let _tenderbrute_exe = only_if (active && N.(number >= 013)) @@ fun () -> @@ -6876,6 +6916,7 @@ let hash = Protocol.hash tezt_core_lib |> open_; ] ~bisect_ppx:No + ~dune:[dune_client_keys_version_rule] in tezt ["test_scenario"] @@ -7030,6 +7071,7 @@ let hash = Protocol.hash ~inline_tests_link_flags: ["-cclib"; "-lblst"; "-cclib"; "-loctez_rustzcash_deps"] ~linkall:true + ~dune:[dune_signatures_version_rule] in let _dal_tests = only_if (active && N.(number >= 016)) @@ fun () -> @@ -7068,6 +7110,7 @@ let hash = Protocol.hash plugin |> if_some |> open_; ] ~linkall:true + ~dune:[dune_client_keys_version_rule; dune_signatures_version_rule] in let octez_sc_rollup_layer2 = only_if N.(number >= 016) @@ fun () -> @@ -7147,6 +7190,7 @@ let hash = Protocol.hash octez_version_value; ] ~conflicts:[Conflicts.checkseum] + ~dune:[dune_signatures_version_rule] in let _octez_sc_rollup_node_test = only_if (active && N.(number >= 016)) @@ fun () -> @@ -7232,6 +7276,25 @@ let hash = Protocol.hash ~linkall:true ~private_modules:["kernel"; "rules"; "state_space"] ~bisect_ppx:(if N.(number <= 012) then Yes else No) + ~dune: + [ + Dune.targets_rule + ["crypto_samplers.mli"] + ~action: + [ + S "write-file"; + S "%{targets}"; + S "include module type of Tezos_benchmark.Crypto_samplers.V1"; + ]; + Dune.targets_rule + ["crypto_samplers.ml"] + ~action: + [ + S "write-file"; + S "%{targets}"; + S "include Tezos_benchmark.Crypto_samplers.V1"; + ]; + ] in let _benchmark_tests = opt_map (both benchmark test_helpers) @@ fun (benchmark, test_helpers) -> @@ -7307,6 +7370,7 @@ let hash = Protocol.hash octez_protocol_environment; ] ~linkall:true + ~dune:[dune_signatures_version_rule] in let _ = if active then -- GitLab From e6d95662c8253c7b76360c58869f5abf4f939ba0 Mon Sep 17 00:00:00 2001 From: Albin Coquereau Date: Mon, 27 Jan 2025 17:57:42 +0100 Subject: [PATCH 08/20] Devtools: fix signature versioning compatibility --- devtools/testnet_experiment_tools/tool_021_PsQuebec.ml | 2 +- devtools/testnet_experiment_tools/tool_alpha.ml | 2 +- devtools/testnet_experiment_tools/tool_next.ml | 2 +- devtools/yes_wallet/get_delegates_021_PsQuebec.ml | 4 ++-- devtools/yes_wallet/get_delegates_alpha.ml | 4 ++-- devtools/yes_wallet/get_delegates_next.ml | 4 ++-- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/devtools/testnet_experiment_tools/tool_021_PsQuebec.ml b/devtools/testnet_experiment_tools/tool_021_PsQuebec.ml index 0e6d09814dec..0749e4b5f6f9 100644 --- a/devtools/testnet_experiment_tools/tool_021_PsQuebec.ml +++ b/devtools/testnet_experiment_tools/tool_021_PsQuebec.ml @@ -163,7 +163,7 @@ let load_client_context (cctxt : ctxt_kind) = in let i = Random.bits () |> Int32.of_int in Bytes.set_int32_be b 0 i ; - let _, _, sk = V_latest.generate_key ~algo ~seed:b () in + let _, _, sk = generate_key ~algo ~seed:b () in sk in let* delegates_l = diff --git a/devtools/testnet_experiment_tools/tool_alpha.ml b/devtools/testnet_experiment_tools/tool_alpha.ml index 55833eaf0edb..3552440fb7aa 100644 --- a/devtools/testnet_experiment_tools/tool_alpha.ml +++ b/devtools/testnet_experiment_tools/tool_alpha.ml @@ -162,7 +162,7 @@ let load_client_context (cctxt : ctxt_kind) = in let i = Random.bits () |> Int32.of_int in Bytes.set_int32_be b 0 i ; - let _, _, sk = V_latest.generate_key ~algo ~seed:b () in + let _, _, sk = generate_key ~algo ~seed:b () in sk in let* delegates_l = diff --git a/devtools/testnet_experiment_tools/tool_next.ml b/devtools/testnet_experiment_tools/tool_next.ml index 2bccf621950a..beeaadefcac0 100644 --- a/devtools/testnet_experiment_tools/tool_next.ml +++ b/devtools/testnet_experiment_tools/tool_next.ml @@ -162,7 +162,7 @@ let load_client_context (cctxt : ctxt_kind) = in let i = Random.bits () |> Int32.of_int in Bytes.set_int32_be b 0 i ; - let _, _, sk = V_latest.generate_key ~algo ~seed:b () in + let _, _, sk = generate_key ~algo ~seed:b () in sk in let* delegates_l = diff --git a/devtools/yes_wallet/get_delegates_021_PsQuebec.ml b/devtools/yes_wallet/get_delegates_021_PsQuebec.ml index 8dc5c3380511..2126fad98610 100644 --- a/devtools/yes_wallet/get_delegates_021_PsQuebec.ml +++ b/devtools/yes_wallet/get_delegates_021_PsQuebec.ml @@ -41,8 +41,8 @@ module Get_delegates = struct module Signature = struct include Tezos_crypto.Signature.V1 - module To_latest = Tezos_crypto.Signature.Of_V1 - module Of_latest = Tezos_crypto.Signature.Of_V_latest + module To_latest = Tezos_crypto.Signature.V_latest.Of_V1 + module Of_latest = Tezos_crypto.Signature.V1.Of_V_latest end module Contract = struct diff --git a/devtools/yes_wallet/get_delegates_alpha.ml b/devtools/yes_wallet/get_delegates_alpha.ml index f19a7971ee98..e76e68a1b31c 100644 --- a/devtools/yes_wallet/get_delegates_alpha.ml +++ b/devtools/yes_wallet/get_delegates_alpha.ml @@ -41,8 +41,8 @@ module Get_delegates = struct module Signature = struct include Tezos_crypto.Signature.V1 - module To_latest = Tezos_crypto.Signature.Of_V1 - module Of_latest = Tezos_crypto.Signature.Of_V_latest + module To_latest = Tezos_crypto.Signature.V_latest.Of_V1 + module Of_latest = Tezos_crypto.Signature.V1.Of_V_latest end module Contract = struct diff --git a/devtools/yes_wallet/get_delegates_next.ml b/devtools/yes_wallet/get_delegates_next.ml index 99749942cc71..4fae3bacd188 100644 --- a/devtools/yes_wallet/get_delegates_next.ml +++ b/devtools/yes_wallet/get_delegates_next.ml @@ -41,8 +41,8 @@ module Get_delegates = struct module Signature = struct include Tezos_crypto.Signature.V1 - module To_latest = Tezos_crypto.Signature.Of_V1 - module Of_latest = Tezos_crypto.Signature.Of_V_latest + module To_latest = Tezos_crypto.Signature.V_latest.Of_V1 + module Of_latest = Tezos_crypto.Signature.V1.Of_V_latest end module Contract = struct -- GitLab From 27f227a8815384a70f583c5d4d35f7e1cd7ff8a3 Mon Sep 17 00:00:00 2001 From: Albin Coquereau Date: Mon, 27 Jan 2025 17:57:57 +0100 Subject: [PATCH 09/20] Lib_benchmark: fix signature versioning compatibility --- src/lib_benchmark/crypto_samplers.ml | 11 +++++++++++ src/lib_benchmark/crypto_samplers.mli | 13 +++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/lib_benchmark/crypto_samplers.ml b/src/lib_benchmark/crypto_samplers.ml index 305e41b93ce0..d1d209ddb64d 100644 --- a/src/lib_benchmark/crypto_samplers.ml +++ b/src/lib_benchmark/crypto_samplers.ml @@ -142,6 +142,17 @@ module V1 = struct Make_p_finite_key_pool (Tezos_crypto.Signature.V1) end +module V2 = struct + module type Finite_key_pool_S = + P_Finite_key_pool_S + with type public_key_hash := Tezos_crypto.Signature.V2.Public_key_hash.t + and type public_key := Tezos_crypto.Signature.V2.Public_key.t + and type secret_key := Tezos_crypto.Signature.V2.Secret_key.t + + module Make_finite_key_pool = + Make_p_finite_key_pool (Tezos_crypto.Signature.V2) +end + module V_latest = struct module type Finite_key_pool_S = P_Finite_key_pool_S diff --git a/src/lib_benchmark/crypto_samplers.mli b/src/lib_benchmark/crypto_samplers.mli index ce0910455f5d..2fbbf8848cf1 100644 --- a/src/lib_benchmark/crypto_samplers.mli +++ b/src/lib_benchmark/crypto_samplers.mli @@ -87,6 +87,19 @@ module V1 : sig Finite_key_pool_S end +module V2 : sig + module type Finite_key_pool_S = + P_Finite_key_pool_S + with type public_key_hash := Tezos_crypto.Signature.V2.Public_key_hash.t + and type public_key := Tezos_crypto.Signature.V2.Public_key.t + and type secret_key := Tezos_crypto.Signature.V2.Secret_key.t + + (** Create a finite key pool. *) + module Make_finite_key_pool + (Arg : Param_S with type algo := Tezos_crypto.Signature.V2.algo) : + Finite_key_pool_S +end + module V_latest : sig module type Finite_key_pool_S = P_Finite_key_pool_S -- GitLab From 822ca4a2074c77a954a2c2ccfd66fde39dffdaf1 Mon Sep 17 00:00:00 2001 From: Albin Coquereau Date: Tue, 28 Jan 2025 15:47:06 +0100 Subject: [PATCH 10/20] Lib_wasm_debugger: fix signature versioning compatibility --- src/lib_wasm_debugger/messages.ml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/lib_wasm_debugger/messages.ml b/src/lib_wasm_debugger/messages.ml index 6c944837a154..23cfc807ae1b 100644 --- a/src/lib_wasm_debugger/messages.ml +++ b/src/lib_wasm_debugger/messages.ml @@ -72,9 +72,15 @@ let input_encoding default_sender default_source default_destination : | `Inbox_message Sc_rollup.Inbox_message.( Internal (Transfer {payload; sender; source; destination})) -> + let source = + Tezos_crypto.Signature.Of_V1.public_key_hash source + in Some (payload, sender, source, destination) | _ -> None) (fun (payload, sender, source, destination) -> + let source = + Signature.V1.Of_V_latest.get_public_key_hash_exn source + in `Inbox_message (Internal (Transfer {payload; sender; source; destination}))); case -- GitLab From d8ff77328a970688a2a6fedf40c75df15f78e7e6 Mon Sep 17 00:00:00 2001 From: Albin Coquereau Date: Mon, 27 Jan 2025 17:57:25 +0100 Subject: [PATCH 11/20] Teztale: fix signature versioning compatibility --- .../Proxford_machine.real.ml | 20 +++++++++++++------ .../PsParisC_machine.real.ml | 20 +++++++++++++------ .../PsQuebec_machine.real.ml | 20 +++++++++++++------ .../PtMumbai_machine.real.ml | 20 +++++++++++++------ .../PtNairob_machine.real.ml | 20 +++++++++++++------ .../PtParisB_machine.real.ml | 20 +++++++++++++------ .../alpha_machine.real.ml | 20 +++++++++++++------ .../bin_teztale_archiver/next_machine.real.ml | 20 +++++++++++++------ teztale/lib_teztale_base/consensus_ops.mli | 2 +- 9 files changed, 113 insertions(+), 49 deletions(-) diff --git a/teztale/bin_teztale_archiver/Proxford_machine.real.ml b/teztale/bin_teztale_archiver/Proxford_machine.real.ml index 9b2f62a499e5..f584cfdfb774 100644 --- a/teztale/bin_teztale_archiver/Proxford_machine.real.ml +++ b/teztale/bin_teztale_archiver/Proxford_machine.real.ml @@ -45,7 +45,8 @@ module Services : Protocol_machinery.PROTOCOL_SERVICES = struct {delegate; first_slot; attestation_power; _} -> Consensus_ops. { - address = delegate; + address = + Tezos_crypto.Signature.Of_V1.public_key_hash delegate; first_slot = slot_to_int first_slot; power = attestation_power; }) @@ -153,7 +154,10 @@ module Services : Protocol_machinery.PROTOCOL_SERVICES = struct let* cycle_info = cycle_info metadata cctxt (cctxt#chain, `Hash (hash, 0)) in - return (metadata.protocol_data.baker.delegate, cycle_info) + return + ( Tezos_crypto.Signature.Of_V1.public_key_hash + metadata.protocol_data.baker.delegate, + cycle_info ) let baking_rights cctxt level round = let* baking_rights = @@ -167,7 +171,10 @@ module Services : Protocol_machinery.PROTOCOL_SERVICES = struct match List.rev_map (fun ({delegate; round; _} : RPC.Baking_rights.t) -> - {Data.delegate; round = Protocol.Alpha_context.Round.to_int32 round}) + { + Data.delegate = Tezos_crypto.Signature.Of_V1.public_key_hash delegate; + round = Protocol.Alpha_context.Round.to_int32 round; + }) baking_rights with | [] -> fail_with_exn Not_found @@ -231,7 +238,7 @@ module Services : Protocol_machinery.PROTOCOL_SERVICES = struct round = Some (get_preattestation_round protocol_data); kind = Consensus_ops.Preattestation; }; - delegate; + delegate = Tezos_crypto.Signature.Of_V1.public_key_hash delegate; power = consensus_power; } :: acc @@ -251,7 +258,7 @@ module Services : Protocol_machinery.PROTOCOL_SERVICES = struct round = Some (get_attestation_round protocol_data); kind = Consensus_ops.Attestation; }; - delegate; + delegate = Tezos_crypto.Signature.Of_V1.public_key_hash delegate; power = consensus_power; } :: acc @@ -270,7 +277,8 @@ module Services : Protocol_machinery.PROTOCOL_SERVICES = struct let*? round = raw_block_round header.shell in let* cycle_info = cycle_info metadata cctxt (cctxt#chain, `Level level) in return - ( ( metadata.protocol_data.baker.delegate, + ( ( Tezos_crypto.Signature.Of_V1.public_key_hash + metadata.protocol_data.baker.delegate, header.shell.timestamp, round, header.hash, diff --git a/teztale/bin_teztale_archiver/PsParisC_machine.real.ml b/teztale/bin_teztale_archiver/PsParisC_machine.real.ml index c1ffa4662766..f073618a1b7f 100644 --- a/teztale/bin_teztale_archiver/PsParisC_machine.real.ml +++ b/teztale/bin_teztale_archiver/PsParisC_machine.real.ml @@ -45,7 +45,8 @@ module Services : Protocol_machinery.PROTOCOL_SERVICES = struct {delegate; first_slot; attestation_power; _} -> Consensus_ops. { - address = delegate; + address = + Tezos_crypto.Signature.Of_V1.public_key_hash delegate; first_slot = slot_to_int first_slot; power = attestation_power; }) @@ -158,7 +159,10 @@ module Services : Protocol_machinery.PROTOCOL_SERVICES = struct let* cycle_info = cycle_info metadata cctxt (cctxt#chain, `Hash (hash, 0)) in - return (metadata.protocol_data.baker.delegate, cycle_info) + return + ( Tezos_crypto.Signature.Of_V1.public_key_hash + metadata.protocol_data.baker.delegate, + cycle_info ) let baking_rights cctxt level round = let* baking_rights = @@ -172,7 +176,10 @@ module Services : Protocol_machinery.PROTOCOL_SERVICES = struct match List.rev_map (fun ({delegate; round; _} : RPC.Baking_rights.t) -> - {Data.delegate; round = Protocol.Alpha_context.Round.to_int32 round}) + { + Data.delegate = Tezos_crypto.Signature.Of_V1.public_key_hash delegate; + round = Protocol.Alpha_context.Round.to_int32 round; + }) baking_rights with | [] -> fail_with_exn Not_found @@ -236,7 +243,7 @@ module Services : Protocol_machinery.PROTOCOL_SERVICES = struct round = Some (get_preattestation_round protocol_data); kind = Consensus_ops.Preattestation; }; - delegate; + delegate = Tezos_crypto.Signature.Of_V1.public_key_hash delegate; power = consensus_power; } :: acc @@ -256,7 +263,7 @@ module Services : Protocol_machinery.PROTOCOL_SERVICES = struct round = Some (get_attestation_round protocol_data); kind = Consensus_ops.Attestation; }; - delegate; + delegate = Tezos_crypto.Signature.Of_V1.public_key_hash delegate; power = consensus_power; } :: acc @@ -275,7 +282,8 @@ module Services : Protocol_machinery.PROTOCOL_SERVICES = struct let*? round = raw_block_round header.shell in let* cycle_info = cycle_info metadata cctxt (cctxt#chain, `Level level) in return - ( ( metadata.protocol_data.baker.delegate, + ( ( Tezos_crypto.Signature.Of_V1.public_key_hash + metadata.protocol_data.baker.delegate, header.shell.timestamp, round, header.hash, diff --git a/teztale/bin_teztale_archiver/PsQuebec_machine.real.ml b/teztale/bin_teztale_archiver/PsQuebec_machine.real.ml index 663b93633e06..16d10a04acd9 100644 --- a/teztale/bin_teztale_archiver/PsQuebec_machine.real.ml +++ b/teztale/bin_teztale_archiver/PsQuebec_machine.real.ml @@ -45,7 +45,8 @@ module Services : Protocol_machinery.PROTOCOL_SERVICES = struct {delegate; first_slot; attestation_power; _} -> Consensus_ops. { - address = delegate; + address = + Tezos_crypto.Signature.Of_V1.public_key_hash delegate; first_slot = slot_to_int first_slot; power = attestation_power; }) @@ -158,7 +159,10 @@ module Services : Protocol_machinery.PROTOCOL_SERVICES = struct let* cycle_info = cycle_info metadata cctxt (cctxt#chain, `Hash (hash, 0)) in - return (metadata.protocol_data.baker.delegate, cycle_info) + return + ( Tezos_crypto.Signature.Of_V1.public_key_hash + metadata.protocol_data.baker.delegate, + cycle_info ) let baking_rights cctxt level round = let* baking_rights = @@ -172,7 +176,10 @@ module Services : Protocol_machinery.PROTOCOL_SERVICES = struct match List.rev_map (fun ({delegate; round; _} : RPC.Baking_rights.t) -> - {Data.delegate; round = Protocol.Alpha_context.Round.to_int32 round}) + { + Data.delegate = Tezos_crypto.Signature.Of_V1.public_key_hash delegate; + round = Protocol.Alpha_context.Round.to_int32 round; + }) baking_rights with | [] -> fail_with_exn Not_found @@ -236,7 +243,7 @@ module Services : Protocol_machinery.PROTOCOL_SERVICES = struct round = Some (get_preattestation_round protocol_data); kind = Consensus_ops.Preattestation; }; - delegate; + delegate = Tezos_crypto.Signature.Of_V1.public_key_hash delegate; power = consensus_power; } :: acc @@ -256,7 +263,7 @@ module Services : Protocol_machinery.PROTOCOL_SERVICES = struct round = Some (get_attestation_round protocol_data); kind = Consensus_ops.Attestation; }; - delegate; + delegate = Tezos_crypto.Signature.Of_V1.public_key_hash delegate; power = consensus_power; } :: acc @@ -275,7 +282,8 @@ module Services : Protocol_machinery.PROTOCOL_SERVICES = struct let*? round = raw_block_round header.shell in let* cycle_info = cycle_info metadata cctxt (cctxt#chain, `Level level) in return - ( ( metadata.protocol_data.baker.delegate, + ( ( Tezos_crypto.Signature.Of_V1.public_key_hash + metadata.protocol_data.baker.delegate, header.shell.timestamp, round, header.hash, diff --git a/teztale/bin_teztale_archiver/PtMumbai_machine.real.ml b/teztale/bin_teztale_archiver/PtMumbai_machine.real.ml index b490e304d9c3..72a2b7814cc3 100644 --- a/teztale/bin_teztale_archiver/PtMumbai_machine.real.ml +++ b/teztale/bin_teztale_archiver/PtMumbai_machine.real.ml @@ -45,7 +45,8 @@ module Services : Protocol_machinery.PROTOCOL_SERVICES = struct {delegate; first_slot; endorsing_power; _} -> Consensus_ops. { - address = delegate; + address = + Tezos_crypto.Signature.Of_V1.public_key_hash delegate; first_slot = slot_to_int first_slot; power = endorsing_power; }) @@ -153,7 +154,10 @@ module Services : Protocol_machinery.PROTOCOL_SERVICES = struct let* cycle_info = cycle_info metadata cctxt (cctxt#chain, `Hash (hash, 0)) in - return (metadata.protocol_data.baker.delegate, cycle_info) + return + ( Tezos_crypto.Signature.Of_V1.public_key_hash + metadata.protocol_data.baker.delegate, + cycle_info ) let baking_rights cctxt level round = let* baking_rights = @@ -167,7 +171,10 @@ module Services : Protocol_machinery.PROTOCOL_SERVICES = struct match List.rev_map (fun ({delegate; round; _} : RPC.Baking_rights.t) -> - {Data.delegate; round = Protocol.Alpha_context.Round.to_int32 round}) + { + Data.delegate = Tezos_crypto.Signature.Of_V1.public_key_hash delegate; + round = Protocol.Alpha_context.Round.to_int32 round; + }) baking_rights with | [] -> fail_with_exn Not_found @@ -231,7 +238,7 @@ module Services : Protocol_machinery.PROTOCOL_SERVICES = struct round = Some (get_preattestation_round protocol_data); kind = Consensus_ops.Preattestation; }; - delegate; + delegate = Tezos_crypto.Signature.Of_V1.public_key_hash delegate; power = preendorsement_power; } :: acc @@ -251,7 +258,7 @@ module Services : Protocol_machinery.PROTOCOL_SERVICES = struct round = Some (get_attestation_round protocol_data); kind = Consensus_ops.Attestation; }; - delegate; + delegate = Tezos_crypto.Signature.Of_V1.public_key_hash delegate; power = endorsement_power; } :: acc @@ -270,7 +277,8 @@ module Services : Protocol_machinery.PROTOCOL_SERVICES = struct let*? round = raw_block_round header.shell in let* cycle_info = cycle_info metadata cctxt (cctxt#chain, `Level level) in return - ( ( metadata.protocol_data.baker.delegate, + ( ( Tezos_crypto.Signature.Of_V1.public_key_hash + metadata.protocol_data.baker.delegate, header.shell.timestamp, round, header.hash, diff --git a/teztale/bin_teztale_archiver/PtNairob_machine.real.ml b/teztale/bin_teztale_archiver/PtNairob_machine.real.ml index e3acaf988e75..2387abcacc5c 100644 --- a/teztale/bin_teztale_archiver/PtNairob_machine.real.ml +++ b/teztale/bin_teztale_archiver/PtNairob_machine.real.ml @@ -45,7 +45,8 @@ module Services : Protocol_machinery.PROTOCOL_SERVICES = struct {delegate; first_slot; attestation_power; _} -> Consensus_ops. { - address = delegate; + address = + Tezos_crypto.Signature.Of_V1.public_key_hash delegate; first_slot = slot_to_int first_slot; power = attestation_power; }) @@ -153,7 +154,10 @@ module Services : Protocol_machinery.PROTOCOL_SERVICES = struct let* cycle_info = cycle_info metadata cctxt (cctxt#chain, `Hash (hash, 0)) in - return (metadata.protocol_data.baker.delegate, cycle_info) + return + ( Tezos_crypto.Signature.Of_V1.public_key_hash + metadata.protocol_data.baker.delegate, + cycle_info ) let baking_rights cctxt level round = let* baking_rights = @@ -167,7 +171,10 @@ module Services : Protocol_machinery.PROTOCOL_SERVICES = struct match List.rev_map (fun ({delegate; round; _} : RPC.Baking_rights.t) -> - {Data.delegate; round = Protocol.Alpha_context.Round.to_int32 round}) + { + Data.delegate = Tezos_crypto.Signature.Of_V1.public_key_hash delegate; + round = Protocol.Alpha_context.Round.to_int32 round; + }) baking_rights with | [] -> fail_with_exn Not_found @@ -231,7 +238,7 @@ module Services : Protocol_machinery.PROTOCOL_SERVICES = struct round = Some (get_preattestation_round protocol_data); kind = Consensus_ops.Preattestation; }; - delegate; + delegate = Tezos_crypto.Signature.Of_V1.public_key_hash delegate; power = preendorsement_power; } :: acc @@ -251,7 +258,7 @@ module Services : Protocol_machinery.PROTOCOL_SERVICES = struct round = Some (get_attestation_round protocol_data); kind = Consensus_ops.Attestation; }; - delegate; + delegate = Tezos_crypto.Signature.Of_V1.public_key_hash delegate; power = endorsement_power; } :: acc @@ -270,7 +277,8 @@ module Services : Protocol_machinery.PROTOCOL_SERVICES = struct let*? round = raw_block_round header.shell in let* cycle_info = cycle_info metadata cctxt (cctxt#chain, `Level level) in return - ( ( metadata.protocol_data.baker.delegate, + ( ( Tezos_crypto.Signature.Of_V1.public_key_hash + metadata.protocol_data.baker.delegate, header.shell.timestamp, round, header.hash, diff --git a/teztale/bin_teztale_archiver/PtParisB_machine.real.ml b/teztale/bin_teztale_archiver/PtParisB_machine.real.ml index 72ddb8254d95..3eec043a5f60 100644 --- a/teztale/bin_teztale_archiver/PtParisB_machine.real.ml +++ b/teztale/bin_teztale_archiver/PtParisB_machine.real.ml @@ -45,7 +45,8 @@ module Services : Protocol_machinery.PROTOCOL_SERVICES = struct {delegate; first_slot; attestation_power; _} -> Consensus_ops. { - address = delegate; + address = + Tezos_crypto.Signature.Of_V1.public_key_hash delegate; first_slot = slot_to_int first_slot; power = attestation_power; }) @@ -158,7 +159,10 @@ module Services : Protocol_machinery.PROTOCOL_SERVICES = struct let* cycle_info = cycle_info metadata cctxt (cctxt#chain, `Hash (hash, 0)) in - return (metadata.protocol_data.baker.delegate, cycle_info) + return + ( Tezos_crypto.Signature.Of_V1.public_key_hash + metadata.protocol_data.baker.delegate, + cycle_info ) let baking_rights cctxt level round = let* baking_rights = @@ -172,7 +176,10 @@ module Services : Protocol_machinery.PROTOCOL_SERVICES = struct match List.rev_map (fun ({delegate; round; _} : RPC.Baking_rights.t) -> - {Data.delegate; round = Protocol.Alpha_context.Round.to_int32 round}) + { + Data.delegate = Tezos_crypto.Signature.Of_V1.public_key_hash delegate; + round = Protocol.Alpha_context.Round.to_int32 round; + }) baking_rights with | [] -> fail_with_exn Not_found @@ -236,7 +243,7 @@ module Services : Protocol_machinery.PROTOCOL_SERVICES = struct round = Some (get_preattestation_round protocol_data); kind = Consensus_ops.Preattestation; }; - delegate; + delegate = Tezos_crypto.Signature.Of_V1.public_key_hash delegate; power = consensus_power; } :: acc @@ -256,7 +263,7 @@ module Services : Protocol_machinery.PROTOCOL_SERVICES = struct round = Some (get_attestation_round protocol_data); kind = Consensus_ops.Attestation; }; - delegate; + delegate = Tezos_crypto.Signature.Of_V1.public_key_hash delegate; power = consensus_power; } :: acc @@ -275,7 +282,8 @@ module Services : Protocol_machinery.PROTOCOL_SERVICES = struct let*? round = raw_block_round header.shell in let* cycle_info = cycle_info metadata cctxt (cctxt#chain, `Level level) in return - ( ( metadata.protocol_data.baker.delegate, + ( ( Tezos_crypto.Signature.Of_V1.public_key_hash + metadata.protocol_data.baker.delegate, header.shell.timestamp, round, header.hash, diff --git a/teztale/bin_teztale_archiver/alpha_machine.real.ml b/teztale/bin_teztale_archiver/alpha_machine.real.ml index 4c8fc1822191..6778f95186df 100644 --- a/teztale/bin_teztale_archiver/alpha_machine.real.ml +++ b/teztale/bin_teztale_archiver/alpha_machine.real.ml @@ -45,7 +45,8 @@ module Services : Protocol_machinery.PROTOCOL_SERVICES = struct {delegate; first_slot; attestation_power; _} -> Consensus_ops. { - address = delegate; + address = + Tezos_crypto.Signature.Of_V1.public_key_hash delegate; first_slot = slot_to_int first_slot; power = attestation_power; }) @@ -158,7 +159,10 @@ module Services : Protocol_machinery.PROTOCOL_SERVICES = struct let* cycle_info = cycle_info metadata cctxt (cctxt#chain, `Hash (hash, 0)) in - return (metadata.protocol_data.baker.delegate, cycle_info) + return + ( Tezos_crypto.Signature.Of_V1.public_key_hash + metadata.protocol_data.baker.delegate, + cycle_info ) let baking_rights cctxt level round = let* baking_rights = @@ -172,7 +176,10 @@ module Services : Protocol_machinery.PROTOCOL_SERVICES = struct match List.rev_map (fun ({delegate; round; _} : RPC.Baking_rights.t) -> - {Data.delegate; round = Protocol.Alpha_context.Round.to_int32 round}) + { + Data.delegate = Tezos_crypto.Signature.Of_V1.public_key_hash delegate; + round = Protocol.Alpha_context.Round.to_int32 round; + }) baking_rights with | [] -> fail_with_exn Not_found @@ -236,7 +243,7 @@ module Services : Protocol_machinery.PROTOCOL_SERVICES = struct round = Some (get_preattestation_round protocol_data); kind = Consensus_ops.Preattestation; }; - delegate; + delegate = Tezos_crypto.Signature.Of_V1.public_key_hash delegate; power = consensus_power; } :: acc @@ -256,7 +263,7 @@ module Services : Protocol_machinery.PROTOCOL_SERVICES = struct round = Some (get_attestation_round protocol_data); kind = Consensus_ops.Attestation; }; - delegate; + delegate = Tezos_crypto.Signature.Of_V1.public_key_hash delegate; power = consensus_power; } :: acc @@ -275,7 +282,8 @@ module Services : Protocol_machinery.PROTOCOL_SERVICES = struct let*? round = raw_block_round header.shell in let* cycle_info = cycle_info metadata cctxt (cctxt#chain, `Level level) in return - ( ( metadata.protocol_data.baker.delegate, + ( ( Tezos_crypto.Signature.Of_V1.public_key_hash + metadata.protocol_data.baker.delegate, header.shell.timestamp, round, header.hash, diff --git a/teztale/bin_teztale_archiver/next_machine.real.ml b/teztale/bin_teztale_archiver/next_machine.real.ml index b3e72eada107..01887525055b 100644 --- a/teztale/bin_teztale_archiver/next_machine.real.ml +++ b/teztale/bin_teztale_archiver/next_machine.real.ml @@ -45,7 +45,8 @@ module Services : Protocol_machinery.PROTOCOL_SERVICES = struct {delegate; first_slot; attestation_power; _} -> Consensus_ops. { - address = delegate; + address = + Tezos_crypto.Signature.Of_V1.public_key_hash delegate; first_slot = slot_to_int first_slot; power = attestation_power; }) @@ -158,7 +159,10 @@ module Services : Protocol_machinery.PROTOCOL_SERVICES = struct let* cycle_info = cycle_info metadata cctxt (cctxt#chain, `Hash (hash, 0)) in - return (metadata.protocol_data.baker.delegate, cycle_info) + return + ( Tezos_crypto.Signature.Of_V1.public_key_hash + metadata.protocol_data.baker.delegate, + cycle_info ) let baking_rights cctxt level round = let* baking_rights = @@ -172,7 +176,10 @@ module Services : Protocol_machinery.PROTOCOL_SERVICES = struct match List.rev_map (fun ({delegate; round; _} : RPC.Baking_rights.t) -> - {Data.delegate; round = Protocol.Alpha_context.Round.to_int32 round}) + { + Data.delegate = Tezos_crypto.Signature.Of_V1.public_key_hash delegate; + round = Protocol.Alpha_context.Round.to_int32 round; + }) baking_rights with | [] -> fail_with_exn Not_found @@ -236,7 +243,7 @@ module Services : Protocol_machinery.PROTOCOL_SERVICES = struct round = Some (get_preattestation_round protocol_data); kind = Consensus_ops.Preattestation; }; - delegate; + delegate = Tezos_crypto.Signature.Of_V1.public_key_hash delegate; power = consensus_power; } :: acc @@ -256,7 +263,7 @@ module Services : Protocol_machinery.PROTOCOL_SERVICES = struct round = Some (get_attestation_round protocol_data); kind = Consensus_ops.Attestation; }; - delegate; + delegate = Tezos_crypto.Signature.Of_V1.public_key_hash delegate; power = consensus_power; } :: acc @@ -275,7 +282,8 @@ module Services : Protocol_machinery.PROTOCOL_SERVICES = struct let*? round = raw_block_round header.shell in let* cycle_info = cycle_info metadata cctxt (cctxt#chain, `Level level) in return - ( ( metadata.protocol_data.baker.delegate, + ( ( Tezos_crypto.Signature.Of_V1.public_key_hash + metadata.protocol_data.baker.delegate, header.shell.timestamp, round, header.hash, diff --git a/teztale/lib_teztale_base/consensus_ops.mli b/teztale/lib_teztale_base/consensus_ops.mli index 51eefdf0d1f1..32ef2a3445d7 100644 --- a/teztale/lib_teztale_base/consensus_ops.mli +++ b/teztale/lib_teztale_base/consensus_ops.mli @@ -6,7 +6,7 @@ (*****************************************************************************) type right = { - address : Tezos_crypto.Signature.Public_key_hash.t; + address : Signature.Public_key_hash.t; first_slot : int; power : int; } -- GitLab From 1bb6119d64dc8ced7ec4cd37770384814f1cc0aa Mon Sep 17 00:00:00 2001 From: Albin Coquereau Date: Tue, 28 Jan 2025 15:47:26 +0100 Subject: [PATCH 12/20] Env: fix signature versioning compatibility --- src/lib_protocol_environment/environment_V14.ml | 3 +++ src/lib_protocol_environment/environment_V15.ml | 3 +++ 2 files changed, 6 insertions(+) diff --git a/src/lib_protocol_environment/environment_V14.ml b/src/lib_protocol_environment/environment_V14.ml index 2641ed79ab85..6ac9746abda4 100644 --- a/src/lib_protocol_environment/environment_V14.ml +++ b/src/lib_protocol_environment/environment_V14.ml @@ -1589,6 +1589,9 @@ struct | Ok () -> Ok true let share_is_trap delegate share ~traps_fraction = + let delegate = + Tezos_crypto.Signature.V_latest.Of_V1.public_key_hash delegate + in match Tezos_crypto_dal.Trap.share_is_trap delegate share ~traps_fraction with diff --git a/src/lib_protocol_environment/environment_V15.ml b/src/lib_protocol_environment/environment_V15.ml index 427e81e1d99c..51e7db2003e1 100644 --- a/src/lib_protocol_environment/environment_V15.ml +++ b/src/lib_protocol_environment/environment_V15.ml @@ -1589,6 +1589,9 @@ struct | Ok () -> Ok true let share_is_trap delegate share ~traps_fraction = + let delegate = + Tezos_crypto.Signature.V_latest.Of_V1.public_key_hash delegate + in match Tezos_crypto_dal.Trap.share_is_trap delegate share ~traps_fraction with -- GitLab From 5fec9e3dd8386efae01e5835e816b936e756c7b8 Mon Sep 17 00:00:00 2001 From: Albin Coquereau Date: Mon, 27 Jan 2025 17:49:31 +0100 Subject: [PATCH 13/20] Mumbai: fix signature versioning compatibility --- .../lib_client/client_proto_args.ml | 2 +- .../lib_client/client_proto_args.mli | 5 +- .../lib_client/client_proto_context.ml | 17 +++-- .../lib_client/client_proto_context.mli | 58 ++++++++-------- .../lib_client/client_proto_fa12.mli | 2 +- .../lib_client/client_proto_multisig.ml | 39 ++++------- .../lib_client/client_proto_multisig.mli | 4 +- .../lib_client/client_proto_programs.ml | 2 +- .../lib_client/client_proto_programs.mli | 2 +- .../lib_client/client_proto_utils.ml | 8 +-- .../lib_client/client_proto_utils.mli | 4 +- src/proto_016_PtMumbai/lib_client/dune | 11 +++ .../lib_client/injection.ml | 8 +-- .../lib_client/injection.mli | 4 +- .../lib_client/managed_contract.ml | 18 ++--- .../lib_client/managed_contract.mli | 2 +- src/proto_016_PtMumbai/lib_client/mockup.ml | 20 +++--- .../lib_client/operation_result.ml | 43 +++++------- .../client_proto_fa12_commands.ml | 3 +- .../client_proto_multisig_commands.ml | 12 ++-- .../client_proto_programs_commands.ml | 6 +- .../client_proto_stresstest_commands.ml | 69 ++++++++----------- .../client_proto_utils_commands.ml | 8 +-- .../lib_client_commands/dune | 11 +++ .../client_sapling_commands.ml | 4 +- .../lib_parameters/default_parameters.ml | 4 +- .../lib_parameters/default_parameters.mli | 8 +-- src/proto_016_PtMumbai/lib_parameters/dune | 7 ++ src/proto_016_PtMumbai/lib_plugin/RPC.ml | 63 ++++++++--------- src/proto_016_PtMumbai/lib_plugin/dune | 7 ++ .../sc_rollup_proto_types.ml | 12 ++-- 31 files changed, 224 insertions(+), 239 deletions(-) diff --git a/src/proto_016_PtMumbai/lib_client/client_proto_args.ml b/src/proto_016_PtMumbai/lib_client/client_proto_args.ml index 335748a7c091..43e10e604c15 100644 --- a/src/proto_016_PtMumbai/lib_client/client_proto_args.ml +++ b/src/proto_016_PtMumbai/lib_client/client_proto_args.ml @@ -564,7 +564,7 @@ let no_confirmation = let signature_parameter = Tezos_clic.parameter (fun _cctxt s -> - match Tezos_crypto.Signature.of_b58check_opt s with + match Signature.of_b58check_opt s with | Some s -> return s | None -> failwith "Not given a valid signature") diff --git a/src/proto_016_PtMumbai/lib_client/client_proto_args.mli b/src/proto_016_PtMumbai/lib_client/client_proto_args.mli index 92ac95ab54b4..5de70c7fc187 100644 --- a/src/proto_016_PtMumbai/lib_client/client_proto_args.mli +++ b/src/proto_016_PtMumbai/lib_client/client_proto_args.mli @@ -60,8 +60,7 @@ val entrypoint_arg : (Entrypoint.t option, full) Tezos_clic.arg val default_entrypoint_arg : (Entrypoint.t option, full) Tezos_clic.arg -val delegate_arg : - (Tezos_crypto.Signature.Public_key_hash.t option, full) Tezos_clic.arg +val delegate_arg : (Signature.Public_key_hash.t option, full) Tezos_clic.arg val max_priority_arg : (int option, full) Tezos_clic.arg @@ -126,7 +125,7 @@ val global_constant_param : ('a, full) Tezos_clic.params -> (string -> 'a, full) Tezos_clic.params -val signature_parameter : (Tezos_crypto.Signature.t, full) Tezos_clic.parameter +val signature_parameter : (Signature.t, full) Tezos_clic.parameter module Daemon : sig val baking_switch : (bool, full) Tezos_clic.arg diff --git a/src/proto_016_PtMumbai/lib_client/client_proto_context.ml b/src/proto_016_PtMumbai/lib_client/client_proto_context.ml index 1f6ce39e72a9..371beb4bb259 100644 --- a/src/proto_016_PtMumbai/lib_client/client_proto_context.ml +++ b/src/proto_016_PtMumbai/lib_client/client_proto_context.ml @@ -28,7 +28,6 @@ open Alpha_context open Protocol_client_context open Tezos_micheline open Client_proto_contracts -open Client_keys let get_balance (rpc : #rpc_context) ~chain ~block contract = Alpha_services.Contract.balance rpc (chain, block) contract @@ -275,7 +274,7 @@ let list_contract_labels cctxt ~chain ~block = (fun h -> (match (h : Contract.t) with | Implicit m -> ( - Public_key_hash.rev_find cctxt m >>=? function + Client_keys.Public_key_hash.rev_find cctxt m >>=? function | None -> return "" | Some nm -> ( Raw_contract_alias.find_opt cctxt nm >>=? function @@ -324,7 +323,7 @@ let build_update_consensus_key ?fee ?gas_limit ?storage_limit consensus_pk = let register_as_delegate cctxt ~chain ~block ?confirmations ?dry_run ?verbose_signing ?fee ~manager_sk ~fee_parameter ?consensus_pk src_pk = - let source = Tezos_crypto.Signature.Public_key.hash src_pk in + let source = Signature.Public_key.hash src_pk in let delegate_op = build_delegate_operation ?fee (Some source) in match consensus_pk with | None -> ( @@ -385,7 +384,7 @@ let register_as_delegate cctxt ~chain ~block ?confirmations ?dry_run let update_consensus_key cctxt ~chain ~block ?confirmations ?dry_run ?verbose_signing ?simulation ?fee ~consensus_pk ~manager_sk ~fee_parameter src_pk = - let source = Tezos_crypto.Signature.Public_key.hash src_pk in + let source = Signature.Public_key.hash src_pk in let operation = build_update_consensus_key ?fee consensus_pk in let operation = Annotated_manager_operation.Single_manager operation in Injection.inject_manager_operation @@ -715,14 +714,14 @@ let read_key key = in let sk = Bip39.to_seed ~passphrase t in let sk = Bytes.sub sk 0 32 in - let sk : Tezos_crypto.Signature.Secret_key.t = + let sk : Signature.Secret_key.t = Ed25519 (Data_encoding.Binary.of_bytes_exn Tezos_crypto.Signature.Ed25519.Secret_key.encoding sk) in - let pk = Tezos_crypto.Signature.Secret_key.to_public_key sk in - let pkh = Tezos_crypto.Signature.Public_key.hash pk in + let pk = Signature.Secret_key.to_public_key sk in + let pkh = Signature.Public_key.hash pk in return (pkh, pk, sk) let inject_activate_operation cctxt ~chain ~block ?confirmations ?dry_run alias @@ -762,11 +761,11 @@ let activate_account (cctxt : #full) ~chain ~block ?confirmations ?dry_run ?(encrypted = false) ?force key name = read_key key >>=? fun (pkh, pk, sk) -> fail_unless - (Tezos_crypto.Signature.Public_key_hash.equal pkh (Ed25519 key.pkh)) + (Signature.Public_key_hash.equal pkh (Ed25519 key.pkh)) (error_of_fmt "@[Inconsistent activation key:@ Computed pkh: %a@ Embedded pkh: \ %a @]" - Tezos_crypto.Signature.Public_key_hash.pp + Signature.Public_key_hash.pp pkh Tezos_crypto.Signature.Ed25519.Public_key_hash.pp key.pkh) diff --git a/src/proto_016_PtMumbai/lib_client/client_proto_context.mli b/src/proto_016_PtMumbai/lib_client/client_proto_context.mli index 893f1863dcbc..f0edc7b8d778 100644 --- a/src/proto_016_PtMumbai/lib_client/client_proto_context.mli +++ b/src/proto_016_PtMumbai/lib_client/client_proto_context.mli @@ -81,8 +81,8 @@ val register_global_constant : ?gas_limit:Gas.Arith.integral -> ?storage_limit:Z.t -> ?counter:Manager_counter.t -> - source:Tezos_crypto.Signature.public_key_hash -> - src_pk:Tezos_crypto.Signature.public_key -> + source:Signature.public_key_hash -> + src_pk:Signature.public_key -> src_sk:Client_keys.sk_uri -> fee_parameter:Injection.fee_parameter -> constant:string -> @@ -151,7 +151,7 @@ val get_frozen_deposits_limit : #Protocol_client_context.rpc_context -> chain:Shell_services.chain -> block:Shell_services.block -> - Tezos_crypto.Signature.Public_key_hash.t -> + Signature.Public_key_hash.t -> Tez.t option tzresult Lwt.t (** Calls {!Injection.prepare_manager_operation} @@ -191,10 +191,10 @@ val update_consensus_key : ?verbose_signing:bool -> ?simulation:bool -> ?fee:Tez.tez -> - consensus_pk:Tezos_crypto.Signature.public_key -> + consensus_pk:Signature.public_key -> manager_sk:Client_keys.sk_uri -> fee_parameter:Injection.fee_parameter -> - Tezos_crypto.Signature.public_key -> + Signature.public_key -> Kind.update_consensus_key Kind.manager Injection.result tzresult Lwt.t val drain_delegate : @@ -206,9 +206,9 @@ val drain_delegate : ?verbose_signing:bool -> ?simulation:bool -> consensus_sk:Client_keys.sk_uri -> - consensus_pkh:Tezos_crypto.Signature.public_key_hash -> - ?destination:Tezos_crypto.Signature.public_key_hash -> - delegate:Tezos_crypto.Signature.public_key_hash -> + consensus_pkh:Signature.public_key_hash -> + ?destination:Signature.public_key_hash -> + delegate:Signature.public_key_hash -> unit -> Kind.drain_delegate Injection.result tzresult Lwt.t @@ -254,7 +254,7 @@ val increase_paid_storage : Kind.increase_paid_storage Kind.manager Injection.result tzresult Lwt.t (** Same as {!set_delegate} but the [~source] argument of {!Injection.inject_manager_operation} - is {!Tezos_crypto.Signature.Public_key.hash} [src_pk]. *) + is {!Signature.Public_key.hash} [src_pk]. *) val register_as_delegate : #Protocol_client_context.full -> chain:Shell_services.chain -> @@ -592,8 +592,8 @@ val originate_tx_rollup : ?gas_limit:Gas.Arith.integral -> ?storage_limit:Z.t -> ?counter:Manager_counter.t -> - source:Tezos_crypto.Signature.public_key_hash -> - src_pk:Tezos_crypto.Signature.public_key -> + source:Signature.public_key_hash -> + src_pk:Signature.public_key -> src_sk:Client_keys.sk_uri -> fee_parameter:Injection.fee_parameter -> unit -> @@ -616,8 +616,8 @@ val submit_tx_rollup_batch : ?gas_limit:Gas.Arith.integral -> ?storage_limit:Z.t -> ?counter:Manager_counter.t -> - source:Tezos_crypto.Signature.public_key_hash -> - src_pk:Tezos_crypto.Signature.public_key -> + source:Signature.public_key_hash -> + src_pk:Signature.public_key -> src_sk:Client_keys.sk_uri -> fee_parameter:Injection.fee_parameter -> content:string -> @@ -641,8 +641,8 @@ val submit_tx_rollup_commitment : ?gas_limit:Gas.Arith.integral -> ?storage_limit:Z.t -> ?counter:Manager_counter.t -> - source:Tezos_crypto.Signature.public_key_hash -> - src_pk:Tezos_crypto.Signature.public_key -> + source:Signature.public_key_hash -> + src_pk:Signature.public_key -> src_sk:Client_keys.sk_uri -> fee_parameter:Injection.fee_parameter -> level:Tx_rollup_level.t -> @@ -669,8 +669,8 @@ val submit_tx_rollup_finalize_commitment : ?gas_limit:Gas.Arith.integral -> ?storage_limit:Z.t -> ?counter:Manager_counter.t -> - source:Tezos_crypto.Signature.public_key_hash -> - src_pk:Tezos_crypto.Signature.public_key -> + source:Signature.public_key_hash -> + src_pk:Signature.public_key -> src_sk:Client_keys.sk_uri -> fee_parameter:Injection.fee_parameter -> tx_rollup:Tx_rollup.t -> @@ -694,8 +694,8 @@ val submit_tx_rollup_remove_commitment : ?gas_limit:Gas.Arith.integral -> ?storage_limit:Z.t -> ?counter:Manager_counter.t -> - source:Tezos_crypto.Signature.public_key_hash -> - src_pk:Tezos_crypto.Signature.public_key -> + source:Signature.public_key_hash -> + src_pk:Signature.public_key -> src_sk:Client_keys.sk_uri -> fee_parameter:Injection.fee_parameter -> tx_rollup:Tx_rollup.t -> @@ -718,8 +718,8 @@ val submit_tx_rollup_rejection : ?gas_limit:Gas.Arith.integral -> ?storage_limit:Z.t -> ?counter:Manager_counter.t -> - source:Tezos_crypto.Signature.public_key_hash -> - src_pk:Tezos_crypto.Signature.public_key -> + source:Signature.public_key_hash -> + src_pk:Signature.public_key -> src_sk:Client_keys.sk_uri -> fee_parameter:Injection.fee_parameter -> level:Tx_rollup_level.t -> @@ -752,8 +752,8 @@ val submit_tx_rollup_return_bond : ?gas_limit:Gas.Arith.integral -> ?storage_limit:Z.t -> ?counter:Manager_counter.t -> - source:Tezos_crypto.Signature.public_key_hash -> - src_pk:Tezos_crypto.Signature.public_key -> + source:Signature.public_key_hash -> + src_pk:Signature.public_key -> src_sk:Client_keys.sk_uri -> fee_parameter:Injection.fee_parameter -> tx_rollup:Tx_rollup.t -> @@ -776,8 +776,8 @@ val tx_rollup_dispatch_tickets : ?gas_limit:Gas.Arith.integral -> ?storage_limit:Z.t -> ?counter:Manager_counter.t -> - source:Tezos_crypto.Signature.public_key_hash -> - src_pk:Tezos_crypto.Signature.public_key -> + source:Signature.public_key_hash -> + src_pk:Signature.public_key -> src_sk:Client_keys.sk_uri -> fee_parameter:Injection.fee_parameter -> level:Tx_rollup_level.t -> @@ -805,8 +805,8 @@ val transfer_ticket : ?gas_limit:Gas.Arith.integral -> ?storage_limit:Z.t -> ?counter:Manager_counter.t -> - source:Tezos_crypto.Signature.public_key_hash -> - src_pk:Tezos_crypto.Signature.public_key -> + source:Signature.public_key_hash -> + src_pk:Signature.public_key -> src_sk:Client_keys.sk_uri -> fee_parameter:Injection.fee_parameter -> contents:string -> @@ -963,8 +963,8 @@ val sc_rollup_recover_bond : ?gas_limit:Gas.Arith.integral -> ?storage_limit:Z.t -> ?counter:Manager_counter.t -> - source:Tezos_crypto.Signature.public_key_hash -> - src_pk:Tezos_crypto.Signature.public_key -> + source:Signature.public_key_hash -> + src_pk:Signature.public_key -> src_sk:Client_keys.sk_uri -> fee_parameter:Injection.fee_parameter -> sc_rollup:Sc_rollup.t -> diff --git a/src/proto_016_PtMumbai/lib_client/client_proto_fa12.mli b/src/proto_016_PtMumbai/lib_client/client_proto_fa12.mli index 8dccc6bbca64..56c3f4d609b4 100644 --- a/src/proto_016_PtMumbai/lib_client/client_proto_fa12.mli +++ b/src/proto_016_PtMumbai/lib_client/client_proto_fa12.mli @@ -155,7 +155,7 @@ val run_view_action : ?source:Contract.t -> contract:Contract_hash.t -> action:action -> - ?payer:Tezos_crypto.Signature.public_key_hash -> + ?payer:public_key_hash -> ?gas:Gas.Arith.integral -> unparsing_mode:Script_ir_unparser.unparsing_mode -> unit -> diff --git a/src/proto_016_PtMumbai/lib_client/client_proto_multisig.ml b/src/proto_016_PtMumbai/lib_client/client_proto_multisig.ml index 891572c2e10e..108233e7b2ab 100644 --- a/src/proto_016_PtMumbai/lib_client/client_proto_multisig.ml +++ b/src/proto_016_PtMumbai/lib_client/client_proto_multisig.ml @@ -136,12 +136,8 @@ let () = "A signature was given for a multisig contract that matched none of the \ public keys of the contract signers" ~pp:(fun ppf s -> - Format.fprintf - ppf - "Invalid signature %s." - (Tezos_crypto.Signature.to_b58check s)) - Data_encoding.( - obj1 (req "invalid_signature" Tezos_crypto.Signature.encoding)) + Format.fprintf ppf "Invalid signature %s." (Signature.to_b58check s)) + Data_encoding.(obj1 (req "invalid_signature" Signature.encoding)) (function Invalid_signature s -> Some s | _ -> None) (fun s -> Invalid_signature s) ; register_error_kind @@ -588,12 +584,11 @@ let lambda_action_t ~loc = lambda_t ~loc (unit_t ~loc) (operations_t ~loc) (* Conversion functions from common types to Script_expr using the optimized representation *) let mutez ~loc (amount : Tez.t) = int ~loc (Z.of_int64 (Tez.to_mutez amount)) -let optimized_key_hash ~loc - (key_hash : Tezos_crypto.Signature.Public_key_hash.t) = +let optimized_key_hash ~loc (key_hash : Signature.Public_key_hash.t) = bytes ~loc (Data_encoding.Binary.to_bytes_exn - Tezos_crypto.Signature.Public_key_hash.encoding + Signature.Public_key_hash.encoding key_hash) let optimized_address ~loc ~(address : Contract.t) ~(entrypoint : Entrypoint.t) @@ -604,12 +599,10 @@ let optimized_address ~loc ~(address : Contract.t) ~(entrypoint : Entrypoint.t) Data_encoding.(tup2 Contract.encoding Entrypoint.value_encoding) (address, entrypoint)) -let optimized_key ~loc (key : Tezos_crypto.Signature.Public_key.t) = +let optimized_key ~loc (key : Signature.Public_key.t) = bytes ~loc - (Data_encoding.Binary.to_bytes_exn - Tezos_crypto.Signature.Public_key.encoding - key) + (Data_encoding.Binary.to_bytes_exn Signature.Public_key.encoding key) (** * Actions *) @@ -714,7 +707,7 @@ let action_of_expr_generic e = | Tezos_micheline.Micheline.Bytes (_, s) -> return @@ Data_encoding.Binary.of_bytes_exn - Tezos_crypto.Signature.Public_key.encoding + Signature.Public_key.encoding s | _ -> fail ()) key_bytes @@ -790,7 +783,7 @@ let action_of_expr_not_generic e = @@ Change_delegate (Some (Data_encoding.Binary.of_bytes_exn - Tezos_crypto.Signature.Public_key_hash.encoding + Signature.Public_key_hash.encoding s)) | Tezos_micheline.Micheline.Prim ( _, @@ -817,7 +810,7 @@ let action_of_expr_not_generic e = | Tezos_micheline.Micheline.Bytes (_, s) -> return @@ Data_encoding.Binary.of_bytes_exn - Tezos_crypto.Signature.Public_key.encoding + Signature.Public_key.encoding s | _ -> fail ()) key_bytes @@ -827,7 +820,7 @@ let action_of_expr_not_generic e = let action_of_expr ~generic = if generic then action_of_expr_generic else action_of_expr_not_generic -type key_list = Tezos_crypto.Signature.Public_key.t list +type key_list = Signature.Public_key.t list (* The relevant information that we can get about a multisig smart contract *) type multisig_contract_information = { @@ -854,8 +847,7 @@ let multisig_get_information (cctxt : #Protocol_client_context.full) ~chain List.map_es (function | String (_, key_str) -> - return - @@ Tezos_crypto.Signature.Public_key.of_b58check_exn key_str + return @@ Signature.Public_key.of_b58check_exn key_str | _ -> fail (Contract_has_unexpected_storage contract)) key_nodes >>=? fun keys -> return {counter; threshold; keys} @@ -867,7 +859,7 @@ let multisig_create_storage ~counter ~threshold ~keys () : let open Tezos_micheline.Micheline in List.map_es (fun key -> - let key_str = Tezos_crypto.Signature.Public_key.to_b58check key in + let key_str = Signature.Public_key.to_b58check key in return (String (loc, key_str))) keys >>=? fun l -> @@ -888,10 +880,7 @@ let multisig_create_param ~counter ~generic ~action ~optional_signatures () : match sig_opt with | None -> return @@ none ~loc () | Some signature -> - return - @@ some - ~loc - (String (loc, Tezos_crypto.Signature.to_b58check signature))) + return @@ some ~loc (String (loc, Signature.to_b58check signature))) optional_signatures >>=? fun l -> Lwt.return @@ action_to_expr ~loc ~generic action >>=? fun expr -> @@ -1056,7 +1045,7 @@ let check_multisig_signatures ~bytes ~threshold ~keys signatures = let opt_sigs_arr = Array.make nkeys None in let matching_key_found = ref false in let check_signature_against_key_number signature i key = - if Tezos_crypto.Signature.check key signature bytes then ( + if Signature.check key signature bytes then ( matching_key_found := true ; opt_sigs_arr.(i) <- Some signature) in diff --git a/src/proto_016_PtMumbai/lib_client/client_proto_multisig.mli b/src/proto_016_PtMumbai/lib_client/client_proto_multisig.mli index cb82be9493a1..5ebfd1448d0f 100644 --- a/src/proto_016_PtMumbai/lib_client/client_proto_multisig.mli +++ b/src/proto_016_PtMumbai/lib_client/client_proto_multisig.mli @@ -112,7 +112,7 @@ val call_multisig : src_sk:Client_keys.sk_uri -> multisig_contract:Contract_hash.t -> action:multisig_action -> - signatures:Tezos_crypto.Signature.t list -> + signatures:Signature.t list -> amount:Tez.t -> ?fee:Tez.t -> ?gas_limit:Gas.Arith.integral -> @@ -139,7 +139,7 @@ val call_multisig_on_bytes : src_sk:Client_keys.sk_uri -> multisig_contract:Contract_hash.t -> bytes:Bytes.t -> - signatures:Tezos_crypto.Signature.t list -> + signatures:Signature.t list -> amount:Tez.t -> ?fee:Tez.t -> ?gas_limit:Gas.Arith.integral -> diff --git a/src/proto_016_PtMumbai/lib_client/client_proto_programs.ml b/src/proto_016_PtMumbai/lib_client/client_proto_programs.ml index a7edc7314f98..111c6e443319 100644 --- a/src/proto_016_PtMumbai/lib_client/client_proto_programs.ml +++ b/src/proto_016_PtMumbai/lib_client/client_proto_programs.ml @@ -126,7 +126,7 @@ type simulation_params = { now : Script_timestamp.t option; level : Script_int.n Script_int.num option; source : Contract.t option; - payer : Tezos_crypto.Signature.public_key_hash option; + payer : Signature.public_key_hash option; gas : Gas.Arith.integral option; } diff --git a/src/proto_016_PtMumbai/lib_client/client_proto_programs.mli b/src/proto_016_PtMumbai/lib_client/client_proto_programs.mli index 3b6d1380ce13..8aaaa139b6e9 100644 --- a/src/proto_016_PtMumbai/lib_client/client_proto_programs.mli +++ b/src/proto_016_PtMumbai/lib_client/client_proto_programs.mli @@ -39,7 +39,7 @@ type simulation_params = { now : Script_timestamp.t option; level : Script_int.n Script_int.num option; source : Contract.t option; - payer : Tezos_crypto.Signature.public_key_hash option; + payer : Signature.public_key_hash option; gas : Gas.Arith.integral option; } diff --git a/src/proto_016_PtMumbai/lib_client/client_proto_utils.ml b/src/proto_016_PtMumbai/lib_client/client_proto_utils.ml index 9f67616f2e9d..78f9efe73712 100644 --- a/src/proto_016_PtMumbai/lib_client/client_proto_utils.ml +++ b/src/proto_016_PtMumbai/lib_client/client_proto_utils.ml @@ -40,11 +40,7 @@ let sign_message (cctxt : #full) ~src_sk ~block ~message = let json, bytes = to_json_and_bytes block message in cctxt#message "signed content: @[%a@]" Data_encoding.Json.pp json >>= fun () -> - Client_keys.sign - cctxt - ~watermark:Tezos_crypto.Signature.Generic_operation - src_sk - bytes + Client_keys.sign cctxt ~watermark:Signature.Generic_operation src_sk bytes let check_message (cctxt : #full) ~block ~key_locator ~quiet ~message ~signature = @@ -53,7 +49,7 @@ let check_message (cctxt : #full) ~block ~key_locator ~quiet ~message ~signature else cctxt#message "checked content: @[%a@]" Data_encoding.Json.pp json) >>= fun () -> Client_keys.check - ~watermark:Tezos_crypto.Signature.Generic_operation + ~watermark:Signature.Generic_operation key_locator signature bytes diff --git a/src/proto_016_PtMumbai/lib_client/client_proto_utils.mli b/src/proto_016_PtMumbai/lib_client/client_proto_utils.mli index 3c06f0108ea8..c535e4b24ecb 100644 --- a/src/proto_016_PtMumbai/lib_client/client_proto_utils.mli +++ b/src/proto_016_PtMumbai/lib_client/client_proto_utils.mli @@ -28,7 +28,7 @@ val sign_message : src_sk:Client_keys.sk_uri -> block:Block_hash.t -> message:string -> - Tezos_crypto.Signature.t tzresult Lwt.t + Signature.t tzresult Lwt.t val check_message : #Protocol_client_context.full -> @@ -36,5 +36,5 @@ val check_message : key_locator:Client_keys.pk_uri -> quiet:bool -> message:string -> - signature:Tezos_crypto.Signature.t -> + signature:Signature.t -> bool tzresult Lwt.t diff --git a/src/proto_016_PtMumbai/lib_client/dune b/src/proto_016_PtMumbai/lib_client/dune index 4d5f401a58bb..5ae1fe251a59 100644 --- a/src/proto_016_PtMumbai/lib_client/dune +++ b/src/proto_016_PtMumbai/lib_client/dune @@ -38,3 +38,14 @@ -open Tezos_protocol_plugin_016_PtMumbai -open Tezos_protocol_016_PtMumbai_parameters -open Tezos_smart_rollup_016_PtMumbai)) + +(rule + (targets client_keys.ml) + (action (write-file %{targets} "include Tezos_client_base.Client_keys_v1"))) + +(rule + (targets signature.ml) + (action + (write-file + %{targets} + " module Bls = Tezos_crypto.Signature.Bls\n module Ed25519 = Tezos_crypto.Signature.Ed25519\n module P256 = Tezos_crypto.Signature.P256\n module Secp256k1 = Tezos_crypto.Signature.Secp256k1\n include Tezos_crypto.Signature.V1"))) diff --git a/src/proto_016_PtMumbai/lib_client/injection.ml b/src/proto_016_PtMumbai/lib_client/injection.ml index 55033fd726b5..5f7f769a2b89 100644 --- a/src/proto_016_PtMumbai/lib_client/injection.ml +++ b/src/proto_016_PtMumbai/lib_client/injection.ml @@ -1223,10 +1223,10 @@ let pending_applied_operations_of_source (cctxt : #full) chain src : (fun acc (_oph, {protocol_data = Operation_data {contents; _}; _}) -> match contents with | Single (Manager_operation {source; _} as _op) - when Tezos_crypto.Signature.Public_key_hash.equal source src -> + when Signature.Public_key_hash.equal source src -> Contents_list contents :: acc | Cons (Manager_operation {source; _}, _rest) as _op - when Tezos_crypto.Signature.Public_key_hash.equal source src -> + when Signature.Public_key_hash.equal source src -> Contents_list contents :: acc | _ -> acc) [] @@ -1349,14 +1349,14 @@ let replace_operation (type kind) (cctxt : #full) chain source cctxt#error "Cannot replace! No applied manager operation found for %a in \ mempool@." - Tezos_crypto.Signature.Public_key_hash.pp + Signature.Public_key_hash.pp source >>= fun () -> exit 1 | _ :: _ :: _ as l -> cctxt#error "More than one applied manager operation found for %a in mempool. \ Found %d operations. Are you sure the node is in precheck mode?@." - Tezos_crypto.Signature.Public_key_hash.pp + Signature.Public_key_hash.pp source (List.length l) >>= fun () -> exit 1 diff --git a/src/proto_016_PtMumbai/lib_client/injection.mli b/src/proto_016_PtMumbai/lib_client/injection.mli index 18d87a3c0ba7..d66775157c80 100644 --- a/src/proto_016_PtMumbai/lib_client/injection.mli +++ b/src/proto_016_PtMumbai/lib_client/injection.mli @@ -103,8 +103,8 @@ val inject_manager_operation : ?verbose_signing:bool -> ?simulation:bool -> ?force:bool -> - source:Tezos_crypto.Signature.Public_key_hash.t -> - src_pk:Tezos_crypto.Signature.public_key -> + source:Signature.Public_key_hash.t -> + src_pk:Signature.public_key -> src_sk:Client_keys.sk_uri -> fee:Tez.t Limit.t -> gas_limit:Gas.Arith.integral Limit.t -> diff --git a/src/proto_016_PtMumbai/lib_client/managed_contract.ml b/src/proto_016_PtMumbai/lib_client/managed_contract.ml index 3edbaae33415..5d406c127648 100644 --- a/src/proto_016_PtMumbai/lib_client/managed_contract.ml +++ b/src/proto_016_PtMumbai/lib_client/managed_contract.ml @@ -51,7 +51,7 @@ let get_contract_manager (cctxt : #full) contract = | Prim (_, D_Pair, Bytes (_, bytes) :: _, _) | Bytes (_, bytes) -> ( match Data_encoding.Binary.of_bytes_opt - Tezos_crypto.Signature.Public_key_hash.encoding + Signature.Public_key_hash.encoding bytes with | Some k -> return k @@ -62,7 +62,7 @@ let get_contract_manager (cctxt : #full) contract = Transfer from scripted contract are currently only supported for \ \"manager\" contract.") | Prim (_, D_Pair, String (_, value) :: _, _) | String (_, value) -> ( - match Tezos_crypto.Signature.Public_key_hash.of_b58check_opt value with + match Signature.Public_key_hash.of_b58check_opt value with | Some k -> return k | None -> cctxt#error @@ -89,9 +89,7 @@ let parse code = let build_lambda_for_set_delegate ~delegate = match delegate with | Some delegate -> - let (`Hex delegate) = - Tezos_crypto.Signature.Public_key_hash.to_hex delegate - in + let (`Hex delegate) = Signature.Public_key_hash.to_hex delegate in Format.asprintf "{ DROP ; NIL operation ; PUSH key_hash 0x%s ; SOME ; SET_DELEGATE ; \ CONS }" @@ -106,7 +104,7 @@ let entrypoint_remove_delegate = Entrypoint.remove_delegate let build_delegate_operation (cctxt : #full) ~chain ~block ?fee contract (* the KT1 to delegate *) - (delegate : Tezos_crypto.Signature.public_key_hash option) = + (delegate : Signature.public_key_hash option) = let entrypoint = entrypoint_do in (Michelson_v1_entrypoints.contract_entrypoint_type cctxt @@ -141,7 +139,7 @@ let build_delegate_operation (cctxt : #full) ~chain ~block ?fee match delegate with | Some delegate -> let (`Hex delegate) = - Tezos_crypto.Signature.Public_key_hash.to_hex delegate + Signature.Public_key_hash.to_hex delegate in "0x" ^ delegate | None -> "Unit" @@ -162,7 +160,7 @@ let build_delegate_operation (cctxt : #full) ~chain ~block ?fee let set_delegate (cctxt : #full) ~chain ~block ?confirmations ?dry_run ?verbose_signing ?simulation ?branch ~fee_parameter ?fee ~source ~src_pk ~src_sk contract (* the KT1 to delegate *) - (delegate : Tezos_crypto.Signature.public_key_hash option) = + (delegate : Signature.public_key_hash option) = build_delegate_operation cctxt ~chain ~block ?fee contract delegate >>=? fun operation -> let operation = Annotated_manager_operation.Single_manager operation in @@ -192,9 +190,7 @@ let t_unit = Micheline.strip_locations (Prim (0, Michelson_v1_primitives.T_unit, [], [])) let build_lambda_for_transfer_to_implicit ~destination ~amount = - let (`Hex destination) = - Tezos_crypto.Signature.Public_key_hash.to_hex destination - in + let (`Hex destination) = Signature.Public_key_hash.to_hex destination in Format.asprintf "{ DROP ; NIL operation ;PUSH key_hash 0x%s; IMPLICIT_ACCOUNT;PUSH mutez \ %Ld ;UNIT;TRANSFER_TOKENS ; CONS }" diff --git a/src/proto_016_PtMumbai/lib_client/managed_contract.mli b/src/proto_016_PtMumbai/lib_client/managed_contract.mli index b459230ae8b3..92f241b68c76 100644 --- a/src/proto_016_PtMumbai/lib_client/managed_contract.mli +++ b/src/proto_016_PtMumbai/lib_client/managed_contract.mli @@ -37,7 +37,7 @@ val check_smart_contract : #full -> 'a option -> ('a -> 'b Lwt.t) -> 'b Lwt.t The storage has to be of type `pair key_hash 'a`. *) val get_contract_manager : - #full -> Contract_hash.t -> public_key_hash tzresult Lwt.t + #full -> Contract_hash.t -> Signature.public_key_hash tzresult Lwt.t (** Builds a delegation operation ready for injection *) val build_delegate_operation : diff --git a/src/proto_016_PtMumbai/lib_client/mockup.ml b/src/proto_016_PtMumbai/lib_client/mockup.ml index 68fe34f0dbff..bf750d2822bd 100644 --- a/src/proto_016_PtMumbai/lib_client/mockup.ml +++ b/src/proto_016_PtMumbai/lib_client/mockup.ml @@ -97,9 +97,9 @@ module Parsed_account = struct (req "amount" Tez.encoding)) let to_bootstrap_account repr = - Tezos_client_base.Client_keys.neuterize repr.sk_uri >>=? fun pk_uri -> - Tezos_client_base.Client_keys.public_key pk_uri >>=? fun public_key -> - let public_key_hash = Tezos_crypto.Signature.Public_key.hash public_key in + Client_keys.neuterize repr.sk_uri >>=? fun pk_uri -> + Client_keys.public_key pk_uri >>=? fun public_key -> + let public_key_hash = Signature.Public_key.hash public_key in return Parameters. { @@ -165,11 +165,11 @@ module Bootstrap_account = struct (fun (public_key_hash, public_key, amount, delegate_to, consensus_key) -> {public_key_hash; public_key; amount; delegate_to; consensus_key}) (obj5 - (req "public_key_hash" Tezos_crypto.Signature.Public_key_hash.encoding) - (opt "public_key" Tezos_crypto.Signature.Public_key.encoding) + (req "public_key_hash" Signature.Public_key_hash.encoding) + (opt "public_key" Signature.Public_key.encoding) (req "amount" Tez.encoding) - (opt "delegate_to" Tezos_crypto.Signature.Public_key_hash.encoding) - (opt "consensus_key" Tezos_crypto.Signature.Public_key.encoding)) + (opt "delegate_to" Signature.Public_key_hash.encoding) + (opt "consensus_key" Signature.Public_key.encoding)) end module Bootstrap_contract = struct @@ -180,7 +180,7 @@ module Bootstrap_contract = struct (fun {delegate; amount; script} -> (delegate, amount, script)) (fun (delegate, amount, script) -> {delegate; amount; script}) (obj3 - (opt "delegate" Tezos_crypto.Signature.Public_key_hash.encoding) + (opt "delegate" Signature.Public_key_hash.encoding) (req "amount" Tez.encoding) (req "script" Script.encoding)) end @@ -498,7 +498,7 @@ let mem_init : [Block_hash.to_bytes hash; Operation_list_hash.(to_bytes @@ compute [])] in let open Protocol.Alpha_context.Block_header in - let _, _, sk = Tezos_crypto.Signature.generate_key () in + let _, _, sk = Signature.generate_key () in let proof_of_work_nonce = Bytes.create Protocol.Alpha_context.Constants.proof_of_work_nonce_size in @@ -518,7 +518,7 @@ let mem_init : (shell_header, contents) in let signature = - Tezos_crypto.Signature.sign + Signature.sign ~watermark: Protocol.Alpha_context.Block_header.( to_watermark (Block_header chain_id)) diff --git a/src/proto_016_PtMumbai/lib_client/operation_result.ml b/src/proto_016_PtMumbai/lib_client/operation_result.ml index 5d64fa545937..a0957e326d9a 100644 --- a/src/proto_016_PtMumbai/lib_client/operation_result.ml +++ b/src/proto_016_PtMumbai/lib_client/operation_result.ml @@ -96,13 +96,13 @@ let pp_internal_operation ppf (Internal_operation {operation; source; _}) = Format.fprintf ppf "@,Delegate: %a" - Tezos_crypto.Signature.Public_key_hash.pp + Signature.Public_key_hash.pp delegate) | Delegation delegate_opt -> ( Format.fprintf ppf "Delegation:@,Contract: %a@,To: " Destination.pp source ; match delegate_opt with | None -> Format.pp_print_string ppf "nobody" - | Some delegate -> Tezos_crypto.Signature.Public_key_hash.pp ppf delegate) + | Some delegate -> Signature.Public_key_hash.pp ppf delegate) | Event {ty; tag; payload} -> Format.fprintf ppf @@ -169,7 +169,7 @@ let pp_manager_operation_content (type kind) source ppf Format.fprintf ppf "@,Delegate: %a" - Tezos_crypto.Signature.Public_key_hash.pp + Signature.Public_key_hash.pp delegate) | Reveal key -> Format.fprintf @@ -177,13 +177,13 @@ let pp_manager_operation_content (type kind) source ppf "Revelation of manager public key:@,Contract: %a@,Key: %a" Contract.pp source - Tezos_crypto.Signature.Public_key.pp + Signature.Public_key.pp key | Delegation delegate_opt -> ( Format.fprintf ppf "Delegation:@,Contract: %a@,To: " Contract.pp source ; match delegate_opt with | None -> Format.pp_print_string ppf "nobody" - | Some delegate -> Tezos_crypto.Signature.Public_key_hash.pp ppf delegate) + | Some delegate -> Signature.Public_key_hash.pp ppf delegate) | Register_global_constant {value} -> Format.fprintf ppf @@ -213,8 +213,8 @@ let pp_manager_operation_content (type kind) source ppf Format.fprintf ppf "Update_consensus_key:@,Public key hash: %a" - Tezos_crypto.Signature.Public_key_hash.pp - (Tezos_crypto.Signature.Public_key.hash pk) + Signature.Public_key_hash.pp + (Signature.Public_key.hash pk) | Tx_rollup_origination -> Format.fprintf ppf @@ -389,7 +389,7 @@ let pp_manager_operation_content (type kind) source ppf "Smart rollup bond retrieval:@,Address: %a@,Staker: %a" Sc_rollup.Address.pp sc_rollup - Tezos_crypto.Signature.Public_key_hash.pp + Signature.Public_key_hash.pp staker | Dal_publish_slot_header slot_header -> Format.fprintf @@ -410,12 +410,9 @@ let pp_balance_updates ppf balance_updates = (tz1Ke2h7sDdakHJQh8WX4Z372du1KChsksyU). Instead of printing this key hash, we want to make the result more informative. *) let pp_baker ppf baker = - if - Tezos_crypto.Signature.Public_key_hash.equal - baker - Tezos_crypto.Signature.Public_key_hash.zero - then Format.fprintf ppf "the baker who will include this operation" - else Tezos_crypto.Signature.Public_key_hash.pp ppf baker + if Signature.Public_key_hash.equal baker Signature.Public_key_hash.zero then + Format.fprintf ppf "the baker who will include this operation" + else Signature.Public_key_hash.pp ppf baker in let balance_updates = List.map @@ -970,11 +967,7 @@ let pp_manager_operation_result ppf Manager_operation_result {balance_updates; operation_result; internal_operation_results} ) = Format.fprintf ppf "@[Manager signed operations:" ; - Format.fprintf - ppf - "@,From: %a" - Tezos_crypto.Signature.Public_key_hash.pp - source ; + Format.fprintf ppf "@,From: %a" Signature.Public_key_hash.pp source ; Format.fprintf ppf "@,Fee to the baker: %s%a" tez_sym Tez.pp fee ; Format.fprintf ppf "@,Expected counter: %a" Manager_counter.pp counter ; Format.fprintf ppf "@,Gas limit: %a" Gas.Arith.pp_integral gas_limit ; @@ -1069,7 +1062,7 @@ let pp_contents_and_result : Format.fprintf ppf "@[Slot attestation:@,Delegate: %a@]" - Tezos_crypto.Signature.Public_key_hash.pp + Signature.Public_key_hash.pp delegate | ( Double_endorsement_evidence {op1; op2}, Double_endorsement_evidence_result bus ) -> @@ -1116,7 +1109,7 @@ let pp_contents_and_result : Format.fprintf ppf "@[Proposals:@,From: %a@,Period: %ld@,Protocols:@, @[%a@]@]" - Tezos_crypto.Signature.Public_key_hash.pp + Signature.Public_key_hash.pp source period (Format.pp_print_list Protocol_hash.pp) @@ -1125,7 +1118,7 @@ let pp_contents_and_result : Format.fprintf ppf "@[Ballot:@,From: %a@,Period: %ld@,Protocol: %a@,Vote: %a@]" - Tezos_crypto.Signature.Public_key_hash.pp + Signature.Public_key_hash.pp source period Protocol_hash.pp @@ -1141,11 +1134,11 @@ let pp_contents_and_result : Consensus key hash: %a@,\ Delegate: %a@,\ Destination: %a%s%a@]" - Tezos_crypto.Signature.Public_key_hash.pp + Signature.Public_key_hash.pp consensus_key - Tezos_crypto.Signature.Public_key_hash.pp + Signature.Public_key_hash.pp delegate - Tezos_crypto.Signature.Public_key_hash.pp + Signature.Public_key_hash.pp destination (if allocated_destination_contract then " (allocated)" else "") pp_balance_updates diff --git a/src/proto_016_PtMumbai/lib_client_commands/client_proto_fa12_commands.ml b/src/proto_016_PtMumbai/lib_client_commands/client_proto_fa12_commands.ml index 154313a4040f..a9a782fafded 100644 --- a/src/proto_016_PtMumbai/lib_client_commands/client_proto_fa12_commands.ml +++ b/src/proto_016_PtMumbai/lib_client_commands/client_proto_fa12_commands.ml @@ -109,8 +109,7 @@ let view_options = payer_arg (unparsing_mode_arg ~default:"Readable") -let dummy_callback = - Contract.Implicit Tezos_crypto.Signature.Public_key_hash.zero +let dummy_callback = Contract.Implicit Signature.Public_key_hash.zero let get_contract_caller_keys cctxt (caller : Contract.t) = let open Lwt_result_syntax in diff --git a/src/proto_016_PtMumbai/lib_client_commands/client_proto_multisig_commands.ml b/src/proto_016_PtMumbai/lib_client_commands/client_proto_multisig_commands.ml index f0bac893e082..805ba43b2e2a 100644 --- a/src/proto_016_PtMumbai/lib_client_commands/client_proto_multisig_commands.ml +++ b/src/proto_016_PtMumbai/lib_client_commands/client_proto_multisig_commands.ml @@ -128,7 +128,7 @@ let prepare_command_display prepared_command bytes_only = "@[<2>Public keys of the signers:@ %a@]" (Format.pp_print_list ~pp_sep:(fun ppf () -> Format.fprintf ppf "@ ") - Tezos_crypto.Signature.Public_key.pp)) + Signature.Public_key.pp)) prepared_command.Client_proto_multisig.keys let get_parameter_type (cctxt : #Protocol_client_context.full) @@ -336,7 +336,7 @@ let commands_rw () : #Protocol_client_context.full Tezos_clic.command list = () in let* signature = Client_keys.sign cctxt sk prepared_command.bytes in - Format.printf "%a@." Tezos_crypto.Signature.pp signature ; + Format.printf "%a@." Signature.pp signature ; return_unit); command ~group @@ -370,7 +370,7 @@ let commands_rw () : #Protocol_client_context.full Tezos_clic.command list = () in let* signature = Client_keys.sign cctxt sk prepared_command.bytes in - Format.printf "%a@." Tezos_crypto.Signature.pp signature ; + Format.printf "%a@." Signature.pp signature ; return_unit); command ~group @@ -402,7 +402,7 @@ let commands_rw () : #Protocol_client_context.full Tezos_clic.command list = () in let* signature = Client_keys.sign cctxt sk prepared_command.bytes in - Format.printf "%a@." Tezos_crypto.Signature.pp signature ; + Format.printf "%a@." Signature.pp signature ; return_unit); command ~group @@ -427,7 +427,7 @@ let commands_rw () : #Protocol_client_context.full Tezos_clic.command list = () in let* signature = Client_keys.sign cctxt sk prepared_command.bytes in - Format.printf "%a@." Tezos_crypto.Signature.pp signature ; + Format.printf "%a@." Signature.pp signature ; return_unit); command ~group @@ -467,7 +467,7 @@ let commands_rw () : #Protocol_client_context.full Tezos_clic.command list = () in let* signature = Client_keys.sign cctxt sk prepared_command.bytes in - Format.printf "%a@." Tezos_crypto.Signature.pp signature ; + Format.printf "%a@." Signature.pp signature ; return_unit); command ~group diff --git a/src/proto_016_PtMumbai/lib_client_commands/client_proto_programs_commands.ml b/src/proto_016_PtMumbai/lib_client_commands/client_proto_programs_commands.ml index 310eea8f9dc9..87db7021d209 100644 --- a/src/proto_016_PtMumbai/lib_client_commands/client_proto_programs_commands.ml +++ b/src/proto_016_PtMumbai/lib_client_commands/client_proto_programs_commands.ml @@ -136,7 +136,7 @@ let commands () = in let signature_parameter = parameter (fun _cctxt s -> - match Tezos_crypto.Signature.of_b58check_opt s with + match Signature.of_b58check_opt s with | Some s -> Lwt_result_syntax.return s | None -> failwith "Not given a valid signature") in @@ -779,9 +779,7 @@ let commands () = (fun () bytes sk cctxt -> let open Lwt_result_syntax in let* signature = Client_keys.sign cctxt sk bytes in - let*! () = - cctxt#message "Signature: %a" Tezos_crypto.Signature.pp signature - in + let*! () = cctxt#message "Signature: %a" Signature.pp signature in return_unit); command ~group diff --git a/src/proto_016_PtMumbai/lib_client_commands/client_proto_stresstest_commands.ml b/src/proto_016_PtMumbai/lib_client_commands/client_proto_stresstest_commands.ml index 9c0b9e58f05a..bc90d4d4e411 100644 --- a/src/proto_016_PtMumbai/lib_client_commands/client_proto_stresstest_commands.ml +++ b/src/proto_016_PtMumbai/lib_client_commands/client_proto_stresstest_commands.ml @@ -64,14 +64,14 @@ type origin = Explicit | Wallet_pkh | Wallet_alias of string type source = { pkh : public_key_hash; pk : public_key; - sk : Tezos_crypto.Signature.secret_key; + sk : Signature.secret_key; } type source_with_uri = { pkh : public_key_hash; pk : public_key; pk_uri : Client_keys.pk_uri; - sk : Tezos_crypto.Signature.secret_key; + sk : Signature.secret_key; sk_uri : Client_keys.sk_uri; } @@ -85,7 +85,7 @@ type source_origin = {source : source; origin : origin} (** Destination of a call: either an implicit contract or an originated one with all the necessary data (entrypoint and the argument). *) type destination = - | Implicit of Tezos_crypto.Signature.Public_key_hash.t + | Implicit of Signature.Public_key_hash.t | Originated of Smart_contracts.invocation_parameters type transfer = { @@ -104,7 +104,7 @@ type state = { mutable pool : source_origin list; mutable pool_size : int; mutable shuffled_pool : source list; - mutable revealed : Tezos_crypto.Signature.Public_key_hash.Set.t; + mutable revealed : Signature.Public_key_hash.Set.t; mutable last_block : Block_hash.t; mutable last_level : int; mutable target_block : Block_hash.t; @@ -161,9 +161,9 @@ let input_source_encoding = ~title:"explicit" (Tag 0) (obj3 - (req "pkh" Tezos_crypto.Signature.Public_key_hash.encoding) - (req "pk" Tezos_crypto.Signature.Public_key.encoding) - (req "sk" Tezos_crypto.Signature.Secret_key.encoding)) + (req "pkh" Signature.Public_key_hash.encoding) + (req "pk" Signature.Public_key.encoding) + (req "sk" Signature.Secret_key.encoding)) (function Explicit {pkh; pk; sk} -> Some (pkh, pk, sk) | _ -> None) (fun (pkh, pk, sk) -> Explicit {pkh; pk; sk}); case @@ -175,7 +175,7 @@ let input_source_encoding = case ~title:"pkh" (Tag 2) - (obj1 (req "pkh" Tezos_crypto.Signature.Public_key_hash.encoding)) + (obj1 (req "pkh" Signature.Public_key_hash.encoding)) (function Wallet_pkh pkh -> Some pkh | _ -> None) (fun pkh -> Wallet_pkh pkh); ] @@ -241,14 +241,14 @@ let normalize_source cctxt = let open Lwt_syntax in let sk_of_sk_uri sk_uri = match - Tezos_crypto.Signature.Secret_key.of_b58check + Signature.Secret_key.of_b58check (Uri.path (sk_uri : Client_keys.sk_uri :> Uri.t)) with | Ok sk -> Lwt.return_some sk | Error _ -> let+ r = Tezos_signer_backends.Encrypted.decrypt cctxt sk_uri in let sk = Option.of_result r in - Option.bind sk Tezos_crypto.Signature.Of_V_latest.secret_key + Option.bind sk Signature.Of_V_latest.secret_key in let key_from_alias alias = let warning msg alias = @@ -283,9 +283,7 @@ let normalize_source cctxt = in let key_from_wallet pkh = let warning msg pkh = - let* () = - cctxt#warning msg Tezos_crypto.Signature.Public_key_hash.pp pkh - in + let* () = cctxt#warning msg Signature.Public_key_hash.pp pkh in return_none in let* key = @@ -300,7 +298,7 @@ let normalize_source cctxt = cctxt#warning "Cannot extract the secret key form the pkh \"%a\" (alias: \ \"%s\") of the wallet" - Tezos_crypto.Signature.Public_key_hash.pp + Signature.Public_key_hash.pp pkh alias in @@ -365,7 +363,7 @@ let random_seed rng = let generate_fresh_source state = let seed = random_seed state.rng_state in - let pkh, pk, sk = Tezos_crypto.Signature.generate_key ~seed () in + let pkh, pk, sk = Signature.generate_key ~seed () in let fresh = {source = {pkh; pk; sk}; origin = Explicit} in state.pool <- fresh :: state.pool ; state.pool_size <- state.pool_size + 1 ; @@ -456,7 +454,7 @@ let rec sample_transfer (cctxt : Protocol_client_context.full) chain block log Debug (fun () -> cctxt#message "sample_transfer: invalid balance %a" - Tezos_crypto.Signature.Public_key_hash.pp + Signature.Public_key_hash.pp src.pkh) in (* Sampled source has zero balance: the transfer that created that @@ -502,11 +500,7 @@ let inject_contents (cctxt : Protocol_client_context.full) branch sk contents = ({branch}, Contents_list contents) in let signature = - Some - (Tezos_crypto.Signature.sign - ~watermark:Tezos_crypto.Signature.Generic_operation - sk - bytes) + Some (Signature.sign ~watermark:Signature.Generic_operation sk bytes) in let op : _ Operation.t = {shell = {branch}; protocol_data = {contents; signature}} @@ -559,19 +553,14 @@ let inject_transfer (cctxt : Protocol_client_context.full) parameters state Alpha_services.Contract.counter cctxt (`Main, `Head 0) transfer.src.pkh in let* already_revealed = - if - Tezos_crypto.Signature.Public_key_hash.Set.mem - transfer.src.pkh - state.revealed - then return true + if Signature.Public_key_hash.Set.mem transfer.src.pkh state.revealed then + return true else ( (* Either the [manager_key] RPC tells us the key is already revealed, or we immediately inject a reveal operation: in any case the key is revealed in the end. *) state.revealed <- - Tezos_crypto.Signature.Public_key_hash.Set.add - transfer.src.pkh - state.revealed ; + Signature.Public_key_hash.Set.add transfer.src.pkh state.revealed ; let* pk_opt = Alpha_services.Contract.manager_key cctxt @@ -605,7 +594,7 @@ let inject_transfer (cctxt : Protocol_client_context.full) parameters state log Info (fun () -> cctxt#message "injecting reveal+transfer from %a (counters=%a,%a) to %a" - Tezos_crypto.Signature.Public_key_hash.pp + Signature.Public_key_hash.pp transfer.src.pkh Manager_counter.pp reveal_counter @@ -631,7 +620,7 @@ let inject_transfer (cctxt : Protocol_client_context.full) parameters state log Info (fun () -> cctxt#message "injecting transfer from %a (counter=%a) to %a" - Tezos_crypto.Signature.Public_key_hash.pp + Signature.Public_key_hash.pp transfer.src.pkh Manager_counter.pp transf_counter @@ -1189,9 +1178,7 @@ let generate_random_transactions = let sources = List.sort_uniq (fun src1 src2 -> - Tezos_crypto.Signature.Secret_key.compare - src1.source.sk - src2.source.sk) + Signature.Secret_key.compare src1.source.sk src2.source.sk) sources in let rng_state = Random.State.make [|parameters.seed|] in @@ -1222,7 +1209,7 @@ let generate_random_transactions = List.shuffle ~rng:rng_state (List.map (fun src_org -> src_org.source) sources); - revealed = Tezos_crypto.Signature.Public_key_hash.Set.empty; + revealed = Signature.Public_key_hash.Set.empty; last_block = current_head_on_start; last_level = Int32.to_int header_on_start.level; target_block = current_target_block; @@ -1507,14 +1494,14 @@ let load_wallet cctxt ~source_pkh = | [] -> return acc | (alias, pkh, _, _) :: tl when List.exists (String.equal alias) to_ban - || Tezos_crypto.Signature.Public_key_hash.equal pkh source_pkh -> + || Signature.Public_key_hash.equal pkh source_pkh -> aux acc tl | (_, pkh, pk, sk_uri) :: tl -> let* pk_uri = Client_keys.neuterize sk_uri in let payload = Uri.path (sk_uri : Tezos_signer_backends.Unencrypted.sk_uri :> Uri.t) in - let sk = Tezos_crypto.Signature.Secret_key.of_b58check_exn payload in + let sk = Signature.Secret_key.of_b58check_exn payload in aux ({pkh; pk; pk_uri; sk; sk_uri} :: acc) tl in aux [] keys @@ -1527,7 +1514,7 @@ let source_key_arg = "Source key public key hash from which the tokens will be transferred to \ start the funding." (parameter (fun _ s -> - let r = Tezos_crypto.Signature.Public_key_hash.of_b58check s in + let r = Signature.Public_key_hash.of_b58check s in match r with | Ok pkh -> Lwt_result_syntax.return pkh | Error e -> @@ -1812,7 +1799,7 @@ let fund_accounts_from_source : Protocol_client_context.full Tezos_clic.command cctxt#message "Starting funding from %a with parameters:@.- batch_size %d@.- \ batches_per_block %d@.- initial_amount %a@." - Tezos_crypto.Signature.Public_key_hash.pp + Signature.Public_key_hash.pp source_pkh batch_size batches_per_block @@ -1879,7 +1866,7 @@ let fund_accounts_from_source : Protocol_client_context.full Tezos_clic.command source_balance Tez.pp req_balance - Tezos_crypto.Signature.Public_key_hash.pp + Signature.Public_key_hash.pp source_pkh else let*! () = @@ -1888,7 +1875,7 @@ let fund_accounts_from_source : Protocol_client_context.full Tezos_clic.command "Transfering %a tz from %a (out of %a)@." Tez.pp req_balance - Tezos_crypto.Signature.Public_key_hash.pp + Signature.Public_key_hash.pp source_pkh Tez.pp source_balance) diff --git a/src/proto_016_PtMumbai/lib_client_commands/client_proto_utils_commands.ml b/src/proto_016_PtMumbai/lib_client_commands/client_proto_utils_commands.ml index 837defaed600..0c210d59cfb6 100644 --- a/src/proto_016_PtMumbai/lib_client_commands/client_proto_utils_commands.ml +++ b/src/proto_016_PtMumbai/lib_client_commands/client_proto_utils_commands.ml @@ -95,9 +95,7 @@ let commands () = () in let* signature = sign_message cctxt ~src_sk ~block ~message in - let*! () = - cctxt#message "Signature: %a" Tezos_crypto.Signature.pp signature - in + let*! () = cctxt#message "Signature: %a" Signature.pp signature in return_unit); command ~group @@ -177,8 +175,6 @@ let commands () = sk unsigned_header in - let*! () = - cctxt#message "%a" Hex.pp (Tezos_crypto.Signature.to_hex s) - in + let*! () = cctxt#message "%a" Hex.pp (Signature.to_hex s) in return_unit); ] diff --git a/src/proto_016_PtMumbai/lib_client_commands/dune b/src/proto_016_PtMumbai/lib_client_commands/dune index 9929baf24940..2eb84a3959c7 100644 --- a/src/proto_016_PtMumbai/lib_client_commands/dune +++ b/src/proto_016_PtMumbai/lib_client_commands/dune @@ -38,6 +38,17 @@ -open Tezos_protocol_plugin_016_PtMumbai) (modules (:standard \ alpha_commands_registration))) +(rule + (targets signature.ml) + (action + (write-file + %{targets} + " module Bls = Tezos_crypto.Signature.Bls\n module Ed25519 = Tezos_crypto.Signature.Ed25519\n module P256 = Tezos_crypto.Signature.P256\n module Secp256k1 = Tezos_crypto.Signature.Secp256k1\n include Tezos_crypto.Signature.V1"))) + +(rule + (targets client_keys.ml) + (action (write-file %{targets} "include Tezos_client_base.Client_keys_v1"))) + (library (name tezos_client_016_PtMumbai_commands_registration) (public_name octez-protocol-016-PtMumbai-libs.client.commands-registration) diff --git a/src/proto_016_PtMumbai/lib_client_sapling/client_sapling_commands.ml b/src/proto_016_PtMumbai/lib_client_sapling/client_sapling_commands.ml index 40b7267112ae..b40b3d9576be 100644 --- a/src/proto_016_PtMumbai/lib_client_sapling/client_sapling_commands.ml +++ b/src/proto_016_PtMumbai/lib_client_sapling/client_sapling_commands.ml @@ -70,9 +70,7 @@ let bound_data_of_public_key_hash cctxt dst = let open Tezos_micheline in let open Protocol.Michelson_v1_primitives in let pkh_bytes = - Data_encoding.Binary.to_bytes_exn - Tezos_crypto.Signature.Public_key_hash.encoding - dst + Data_encoding.Binary.to_bytes_exn Signature.Public_key_hash.encoding dst in let micheline_bytes = Micheline.(Bytes (0, pkh_bytes) |> strip_locations) in let micheline_pkh_type = diff --git a/src/proto_016_PtMumbai/lib_parameters/default_parameters.ml b/src/proto_016_PtMumbai/lib_parameters/default_parameters.ml index ced9867d4202..53eb6a107ee1 100644 --- a/src/proto_016_PtMumbai/lib_parameters/default_parameters.ml +++ b/src/proto_016_PtMumbai/lib_parameters/default_parameters.ml @@ -416,8 +416,8 @@ let bootstrap_balance = Tez.of_mutez_exn 4_000_000_000_000L let compute_accounts = List.map (fun s -> - let public_key = Tezos_crypto.Signature.Public_key.of_b58check_exn s in - let public_key_hash = Tezos_crypto.Signature.Public_key.hash public_key in + let public_key = Signature.Public_key.of_b58check_exn s in + let public_key_hash = Signature.Public_key.hash public_key in Parameters. { public_key_hash; diff --git a/src/proto_016_PtMumbai/lib_parameters/default_parameters.mli b/src/proto_016_PtMumbai/lib_parameters/default_parameters.mli index f930bc38fd87..eff7da674972 100644 --- a/src/proto_016_PtMumbai/lib_parameters/default_parameters.mli +++ b/src/proto_016_PtMumbai/lib_parameters/default_parameters.mli @@ -35,11 +35,11 @@ val constants_test : Constants.Parametric.t val test_commitments : Commitment.t list lazy_t val make_bootstrap_account : - Tezos_crypto.Signature.public_key_hash - * Tezos_crypto.Signature.public_key + Signature.public_key_hash + * Signature.public_key * Tez.t - * Tezos_crypto.Signature.public_key_hash option - * Tezos_crypto.Signature.public_key option -> + * Signature.public_key_hash option + * Signature.public_key option -> Parameters.bootstrap_account val parameters_of_constants : diff --git a/src/proto_016_PtMumbai/lib_parameters/dune b/src/proto_016_PtMumbai/lib_parameters/dune index b43f931191a3..82dcf16996a0 100644 --- a/src/proto_016_PtMumbai/lib_parameters/dune +++ b/src/proto_016_PtMumbai/lib_parameters/dune @@ -16,6 +16,13 @@ -open Tezos_protocol_016_PtMumbai) (modules (:standard \ gen))) +(rule + (targets signature.ml) + (action + (write-file + %{targets} + " module Bls = Tezos_crypto.Signature.Bls\n module Ed25519 = Tezos_crypto.Signature.Ed25519\n module P256 = Tezos_crypto.Signature.P256\n module Secp256k1 = Tezos_crypto.Signature.Secp256k1\n include Tezos_crypto.Signature.V1"))) + (executable (name gen) (libraries diff --git a/src/proto_016_PtMumbai/lib_plugin/RPC.ml b/src/proto_016_PtMumbai/lib_plugin/RPC.ml index 93e852d1383e..74eb7259f265 100644 --- a/src/proto_016_PtMumbai/lib_plugin/RPC.ml +++ b/src/proto_016_PtMumbai/lib_plugin/RPC.ml @@ -940,7 +940,7 @@ module Scripts = struct type run_code_config = { balance : Tez.t; self : Contract_hash.t; - payer : Tezos_crypto.Signature.public_key_hash; + payer : Signature.public_key_hash; source : Contract.t; } @@ -970,9 +970,8 @@ module Scripts = struct let source_and_payer ~src_opt ~pay_opt ~default_src = match (src_opt, pay_opt) with | None, None -> - ( Contract.Originated default_src, - Tezos_crypto.Signature.Public_key_hash.zero ) - | Some c, None -> (c, Tezos_crypto.Signature.Public_key_hash.zero) + (Contract.Originated default_src, Signature.Public_key_hash.zero) + | Some c, None -> (c, Signature.Public_key_hash.zero) | None, Some c -> (Contract.Implicit c, c) | Some src, Some pay -> (src, pay) in @@ -3073,10 +3072,10 @@ module Baking_rights = struct {level; delegate; consensus_key; round; timestamp}) (obj5 (req "level" Raw_level.encoding) - (req "delegate" Tezos_crypto.Signature.Public_key_hash.encoding) + (req "delegate" Signature.Public_key_hash.encoding) (req "round" Round.encoding) (opt "estimated_time" Timestamp.encoding) - (req "consensus_key" Tezos_crypto.Signature.Public_key_hash.encoding)) + (req "consensus_key" Signature.Public_key_hash.encoding)) let default_max_round = 64 @@ -3088,8 +3087,8 @@ module Baking_rights = struct type baking_rights_query = { levels : Raw_level.t list; cycle : Cycle.t option; - delegates : Tezos_crypto.Signature.Public_key_hash.t list; - consensus_keys : Tezos_crypto.Signature.Public_key_hash.t list; + delegates : Signature.Public_key_hash.t list; + consensus_keys : Signature.Public_key_hash.t list; max_round : int option; all : bool; } @@ -3179,16 +3178,12 @@ module Baking_rights = struct @@ List.fold_left (fun (acc, previous) r -> if - Tezos_crypto.Signature.Public_key_hash.Set.exists - (Tezos_crypto.Signature.Public_key_hash.equal r.delegate) + Signature.Public_key_hash.Set.exists + (Signature.Public_key_hash.equal r.delegate) previous then (acc, previous) - else - ( r :: acc, - Tezos_crypto.Signature.Public_key_hash.Set.add - r.delegate - previous )) - ([], Tezos_crypto.Signature.Public_key_hash.Set.empty) + else (r :: acc, Signature.Public_key_hash.Set.add r.delegate previous)) + ([], Signature.Public_key_hash.Set.empty) rights let register () = @@ -3224,7 +3219,7 @@ module Baking_rights = struct | _ :: _ as delegates -> let is_requested p = List.exists - (Tezos_crypto.Signature.Public_key_hash.equal p.delegate) + (Signature.Public_key_hash.equal p.delegate) delegates in List.filter is_requested rights @@ -3235,7 +3230,7 @@ module Baking_rights = struct | _ :: _ as delegates -> let is_requested p = List.exists - (Tezos_crypto.Signature.Public_key_hash.equal p.consensus_key) + (Signature.Public_key_hash.equal p.consensus_key) delegates in List.filter is_requested rights @@ -3254,8 +3249,8 @@ end module Endorsing_rights = struct type delegate_rights = { - delegate : Tezos_crypto.Signature.Public_key_hash.t; - consensus_key : Tezos_crypto.Signature.Public_key_hash.t; + delegate : Signature.Public_key_hash.t; + consensus_key : Signature.Public_key_hash.t; first_slot : Slot.t; endorsing_power : int; } @@ -3274,10 +3269,10 @@ module Endorsing_rights = struct (fun (delegate, first_slot, endorsing_power, consensus_key) -> {delegate; first_slot; endorsing_power; consensus_key}) (obj4 - (req "delegate" Tezos_crypto.Signature.Public_key_hash.encoding) + (req "delegate" Signature.Public_key_hash.encoding) (req "first_slot" Slot.encoding) (req "endorsing_power" uint16) - (req "consensus_key" Tezos_crypto.Signature.Public_key_hash.encoding)) + (req "consensus_key" Signature.Public_key_hash.encoding)) let encoding = let open Data_encoding in @@ -3299,8 +3294,8 @@ module Endorsing_rights = struct type endorsing_rights_query = { levels : Raw_level.t list; cycle : Cycle.t option; - delegates : Tezos_crypto.Signature.Public_key_hash.t list; - consensus_keys : Tezos_crypto.Signature.Public_key_hash.t list; + delegates : Signature.Public_key_hash.t list; + consensus_keys : Signature.Public_key_hash.t list; } let endorsing_rights_query = @@ -3388,10 +3383,10 @@ module Endorsing_rights = struct | _, _ -> let is_requested p = List.exists - (Tezos_crypto.Signature.Public_key_hash.equal p.consensus_key) + (Signature.Public_key_hash.equal p.consensus_key) q.consensus_keys || List.exists - (Tezos_crypto.Signature.Public_key_hash.equal p.delegate) + (Signature.Public_key_hash.equal p.delegate) q.delegates in List.filter_map @@ -3419,8 +3414,8 @@ end module Validators = struct type t = { level : Raw_level.t; - delegate : Tezos_crypto.Signature.Public_key_hash.t; - consensus_key : Tezos_crypto.Signature.public_key_hash; + delegate : Signature.Public_key_hash.t; + consensus_key : Signature.public_key_hash; slots : Slot.t list; } @@ -3433,9 +3428,9 @@ module Validators = struct {level; delegate; consensus_key; slots}) (obj4 (req "level" Raw_level.encoding) - (req "delegate" Tezos_crypto.Signature.Public_key_hash.encoding) + (req "delegate" Signature.Public_key_hash.encoding) (req "slots" (list Slot.encoding)) - (req "consensus_key" Tezos_crypto.Signature.Public_key_hash.encoding)) + (req "consensus_key" Signature.Public_key_hash.encoding)) module S = struct open Data_encoding @@ -3444,8 +3439,8 @@ module Validators = struct type validators_query = { levels : Raw_level.t list; - delegates : Tezos_crypto.Signature.Public_key_hash.t list; - consensus_keys : Tezos_crypto.Signature.Public_key_hash.t list; + delegates : Signature.Public_key_hash.t list; + consensus_keys : Signature.Public_key_hash.t list; } let validators_query = @@ -3500,7 +3495,7 @@ module Validators = struct | _ :: _ as delegates -> let is_requested p = List.exists - (Tezos_crypto.Signature.Public_key_hash.equal p.delegate) + (Signature.Public_key_hash.equal p.delegate) delegates in List.filter is_requested rights @@ -3511,7 +3506,7 @@ module Validators = struct | _ :: _ as delegates -> let is_requested p = List.exists - (Tezos_crypto.Signature.Public_key_hash.equal p.consensus_key) + (Signature.Public_key_hash.equal p.consensus_key) delegates in List.filter is_requested rights diff --git a/src/proto_016_PtMumbai/lib_plugin/dune b/src/proto_016_PtMumbai/lib_plugin/dune index 697a74f3b7b8..827678002475 100644 --- a/src/proto_016_PtMumbai/lib_plugin/dune +++ b/src/proto_016_PtMumbai/lib_plugin/dune @@ -19,6 +19,13 @@ (documentation (package octez-protocol-016-PtMumbai-libs)) +(rule + (targets signature.ml) + (action + (write-file + %{targets} + " module Bls = Tezos_crypto.Signature.Bls\n module Ed25519 = Tezos_crypto.Signature.Ed25519\n module P256 = Tezos_crypto.Signature.P256\n module Secp256k1 = Tezos_crypto.Signature.Secp256k1\n include Tezos_crypto.Signature.V1"))) + (library (name tezos_protocol_plugin_016_PtMumbai_registerer) (public_name octez-protocol-016-PtMumbai-libs.plugin-registerer) diff --git a/src/proto_016_PtMumbai/lib_sc_rollup_layer2/sc_rollup_proto_types.ml b/src/proto_016_PtMumbai/lib_sc_rollup_layer2/sc_rollup_proto_types.ml index ae786aad04fa..b93fc9d5f5ff 100644 --- a/src/proto_016_PtMumbai/lib_sc_rollup_layer2/sc_rollup_proto_types.ml +++ b/src/proto_016_PtMumbai/lib_sc_rollup_layer2/sc_rollup_proto_types.ml @@ -359,10 +359,14 @@ module Game = struct Move {choice = Sc_rollup.Tick.to_z choice; step = step_to_octez step} let index_of_octez Octez_smart_rollup.Game.{alice; bob} = - Sc_rollup.Game.Index.make alice bob + Sc_rollup.Game.Index.make + (Signature.V1.Of_V_latest.get_public_key_hash_exn alice) + (Signature.V1.Of_V_latest.get_public_key_hash_exn bob) let index_to_octez Sc_rollup.Game.Index.{alice; bob} = - Octez_smart_rollup.Game.make_index alice bob + Octez_smart_rollup.Game.make_index + (Tezos_crypto.Signature.V_latest.Of_V1.public_key_hash alice) + (Tezos_crypto.Signature.V_latest.Of_V1.public_key_hash bob) let player_of_octez : Octez_smart_rollup.Game.player -> player = function | Alice -> Alice @@ -445,7 +449,7 @@ module Game = struct {other; their_commitment; our_commitment; parent_commitment} : conflict = { - other; + other = Signature.V1.Of_V_latest.get_public_key_hash_exn other; their_commitment = Commitment.of_octez their_commitment; our_commitment = Commitment.of_octez our_commitment; parent_commitment = Commitment_hash.of_octez parent_commitment; @@ -456,7 +460,7 @@ module Game = struct {other; their_commitment; our_commitment; parent_commitment} : Octez_smart_rollup.Game.conflict = { - other; + other = Tezos_crypto.Signature.Of_V1.public_key_hash other; their_commitment = Commitment.to_octez their_commitment; our_commitment = Commitment.to_octez our_commitment; parent_commitment = Commitment_hash.to_octez parent_commitment; -- GitLab From b66c8ddbfb4bd4c153ffafe970ac3adcfcb4f75f Mon Sep 17 00:00:00 2001 From: Albin Coquereau Date: Mon, 27 Jan 2025 17:53:02 +0100 Subject: [PATCH 14/20] Nairobi: fix signature versioning compatibility --- .../lib_client/client_proto_context.ml | 7 +++--- src/proto_017_PtNairob/lib_client/dune | 11 ++++++++++ src/proto_017_PtNairob/lib_client/mockup.ml | 4 ++-- .../lib_client_commands/dune | 11 ++++++++++ src/proto_017_PtNairob/lib_parameters/dune | 7 ++++++ src/proto_017_PtNairob/lib_plugin/dune | 7 ++++++ .../sc_rollup_proto_types.ml | 12 ++++++---- .../lib_sc_rollup_node/daemon_helpers.ml | 22 +++++++++++++++---- .../lib_sc_rollup_node/dune | 7 ++++++ .../lib_sc_rollup_node/layer1_helpers.ml | 4 +++- .../refutation_game_helpers.ml | 12 ++++++++-- .../lib_sc_rollup_node/sc_rollup_injector.ml | 8 ++++++- 12 files changed, 94 insertions(+), 18 deletions(-) diff --git a/src/proto_017_PtNairob/lib_client/client_proto_context.ml b/src/proto_017_PtNairob/lib_client/client_proto_context.ml index aacce59cb12e..e2b49fd04a2c 100644 --- a/src/proto_017_PtNairob/lib_client/client_proto_context.ml +++ b/src/proto_017_PtNairob/lib_client/client_proto_context.ml @@ -28,7 +28,6 @@ open Alpha_context open Protocol_client_context open Tezos_micheline open Client_proto_contracts -open Client_keys let get_balance (rpc : #rpc_context) ~chain ~block contract = Alpha_services.Contract.balance rpc (chain, block) contract @@ -278,7 +277,7 @@ let list_contract_labels cctxt ~chain ~block = (fun h -> (match (h : Contract.t) with | Implicit m -> ( - Public_key_hash.rev_find cctxt m >>=? function + Client_keys.Public_key_hash.rev_find cctxt m >>=? function | None -> return "" | Some nm -> ( Raw_contract_alias.find_opt cctxt nm >>=? function @@ -776,8 +775,8 @@ let activate_account (cctxt : #full) ~chain ~block ?confirmations ?dry_run Signature.Ed25519.Public_key_hash.pp key.pkh) >>=? fun () -> - let pk = Signature.Of_V1.public_key pk in - let sk = Signature.Of_V1.secret_key sk in + let pk = Tezos_crypto.Signature.Of_V1.public_key pk in + let sk = Tezos_crypto.Signature.Of_V1.secret_key sk in Tezos_signer_backends.Unencrypted.make_pk pk >>?= fun pk_uri -> (if encrypted then Tezos_signer_backends.Encrypted.prompt_twice_and_encrypt cctxt sk diff --git a/src/proto_017_PtNairob/lib_client/dune b/src/proto_017_PtNairob/lib_client/dune index 10f40f5333bf..8151f63434a5 100644 --- a/src/proto_017_PtNairob/lib_client/dune +++ b/src/proto_017_PtNairob/lib_client/dune @@ -38,3 +38,14 @@ -open Tezos_protocol_plugin_017_PtNairob -open Tezos_protocol_017_PtNairob_parameters -open Tezos_smart_rollup_017_PtNairob)) + +(rule + (targets client_keys.ml) + (action (write-file %{targets} "include Tezos_client_base.Client_keys_v1"))) + +(rule + (targets signature.ml) + (action + (write-file + %{targets} + " module Bls = Tezos_crypto.Signature.Bls\n module Ed25519 = Tezos_crypto.Signature.Ed25519\n module P256 = Tezos_crypto.Signature.P256\n module Secp256k1 = Tezos_crypto.Signature.Secp256k1\n include Tezos_crypto.Signature.V1"))) diff --git a/src/proto_017_PtNairob/lib_client/mockup.ml b/src/proto_017_PtNairob/lib_client/mockup.ml index 9f7fe4af6034..71b514d4f44a 100644 --- a/src/proto_017_PtNairob/lib_client/mockup.ml +++ b/src/proto_017_PtNairob/lib_client/mockup.ml @@ -97,8 +97,8 @@ module Parsed_account = struct (req "amount" Tez.encoding)) let to_bootstrap_account repr = - Tezos_client_base.Client_keys.neuterize repr.sk_uri >>=? fun pk_uri -> - Tezos_client_base.Client_keys.public_key pk_uri >>=? fun public_key -> + Client_keys.neuterize repr.sk_uri >>=? fun pk_uri -> + Client_keys.public_key pk_uri >>=? fun public_key -> let public_key_hash = Signature.Public_key.hash public_key in return Parameters. diff --git a/src/proto_017_PtNairob/lib_client_commands/dune b/src/proto_017_PtNairob/lib_client_commands/dune index 37d2b9df602b..ad8ebfc541ee 100644 --- a/src/proto_017_PtNairob/lib_client_commands/dune +++ b/src/proto_017_PtNairob/lib_client_commands/dune @@ -38,6 +38,17 @@ -open Tezos_protocol_plugin_017_PtNairob) (modules (:standard \ alpha_commands_registration))) +(rule + (targets signature.ml) + (action + (write-file + %{targets} + " module Bls = Tezos_crypto.Signature.Bls\n module Ed25519 = Tezos_crypto.Signature.Ed25519\n module P256 = Tezos_crypto.Signature.P256\n module Secp256k1 = Tezos_crypto.Signature.Secp256k1\n include Tezos_crypto.Signature.V1"))) + +(rule + (targets client_keys.ml) + (action (write-file %{targets} "include Tezos_client_base.Client_keys_v1"))) + (library (name tezos_client_017_PtNairob_commands_registration) (public_name octez-protocol-017-PtNairob-libs.client.commands-registration) diff --git a/src/proto_017_PtNairob/lib_parameters/dune b/src/proto_017_PtNairob/lib_parameters/dune index 79653c75c3e4..084f13d2bce5 100644 --- a/src/proto_017_PtNairob/lib_parameters/dune +++ b/src/proto_017_PtNairob/lib_parameters/dune @@ -16,6 +16,13 @@ -open Tezos_protocol_017_PtNairob) (modules (:standard \ gen))) +(rule + (targets signature.ml) + (action + (write-file + %{targets} + " module Bls = Tezos_crypto.Signature.Bls\n module Ed25519 = Tezos_crypto.Signature.Ed25519\n module P256 = Tezos_crypto.Signature.P256\n module Secp256k1 = Tezos_crypto.Signature.Secp256k1\n include Tezos_crypto.Signature.V1"))) + (executable (name gen) (libraries diff --git a/src/proto_017_PtNairob/lib_plugin/dune b/src/proto_017_PtNairob/lib_plugin/dune index feb3b8c63d26..f385fd162cb2 100644 --- a/src/proto_017_PtNairob/lib_plugin/dune +++ b/src/proto_017_PtNairob/lib_plugin/dune @@ -19,6 +19,13 @@ (documentation (package octez-protocol-017-PtNairob-libs)) +(rule + (targets signature.ml) + (action + (write-file + %{targets} + " module Bls = Tezos_crypto.Signature.Bls\n module Ed25519 = Tezos_crypto.Signature.Ed25519\n module P256 = Tezos_crypto.Signature.P256\n module Secp256k1 = Tezos_crypto.Signature.Secp256k1\n include Tezos_crypto.Signature.V1"))) + (library (name tezos_protocol_plugin_017_PtNairob_registerer) (public_name octez-protocol-017-PtNairob-libs.plugin-registerer) diff --git a/src/proto_017_PtNairob/lib_sc_rollup_layer2/sc_rollup_proto_types.ml b/src/proto_017_PtNairob/lib_sc_rollup_layer2/sc_rollup_proto_types.ml index e9c942bb236a..62fed566cd59 100644 --- a/src/proto_017_PtNairob/lib_sc_rollup_layer2/sc_rollup_proto_types.ml +++ b/src/proto_017_PtNairob/lib_sc_rollup_layer2/sc_rollup_proto_types.ml @@ -361,10 +361,14 @@ module Game = struct Move {choice = Sc_rollup.Tick.to_z choice; step = step_to_octez step} let index_of_octez Octez_smart_rollup.Game.{alice; bob} = - Sc_rollup.Game.Index.make alice bob + Sc_rollup.Game.Index.make + (Signature.V1.Of_V_latest.get_public_key_hash_exn alice) + (Signature.V1.Of_V_latest.get_public_key_hash_exn bob) let index_to_octez Sc_rollup.Game.Index.{alice; bob} = - Octez_smart_rollup.Game.make_index alice bob + Octez_smart_rollup.Game.make_index + (Tezos_crypto.Signature.V_latest.Of_V1.public_key_hash alice) + (Tezos_crypto.Signature.V_latest.Of_V1.public_key_hash bob) let player_of_octez : Octez_smart_rollup.Game.player -> player = function | Alice -> Alice @@ -464,7 +468,7 @@ module Game = struct {other; their_commitment; our_commitment; parent_commitment} : conflict = { - other; + other = Signature.V1.Of_V_latest.get_public_key_hash_exn other; their_commitment = Commitment.of_octez their_commitment; our_commitment = Commitment.of_octez our_commitment; parent_commitment = Commitment_hash.of_octez parent_commitment; @@ -475,7 +479,7 @@ module Game = struct {other; their_commitment; our_commitment; parent_commitment} : Octez_smart_rollup.Game.conflict = { - other; + other = Tezos_crypto.Signature.Of_V1.public_key_hash other; their_commitment = Commitment.to_octez their_commitment; our_commitment = Commitment.to_octez our_commitment; parent_commitment = Commitment_hash.to_octez parent_commitment; diff --git a/src/proto_017_PtNairob/lib_sc_rollup_node/daemon_helpers.ml b/src/proto_017_PtNairob/lib_sc_rollup_node/daemon_helpers.ml index ae7c7a096d7d..978dca06cba7 100644 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/daemon_helpers.ml +++ b/src/proto_017_PtNairob/lib_sc_rollup_node/daemon_helpers.ml @@ -112,6 +112,9 @@ let maybe_recover_bond node_ctxt = match operating_pkh with | None -> return_unit | Some (Single operating_pkh) -> ( + let*? operating_pkh = + Signature.Of_V_latest.get_public_key_hash operating_pkh + in let* staked_on_commitment = RPC.Sc_rollup.staked_on_commitment (new Protocol_client_context.wrap_full node_ctxt.cctxt) @@ -214,7 +217,10 @@ let process_included_l1_operation (type kind) (node_ctxt : Node_context.rw) | ( Sc_rollup_timeout _, Sc_rollup_timeout_result {game_status = Ended end_status; _} ) -> ( match end_status with - | Loser {loser; reason} when Node_context.is_operator node_ctxt loser -> + | Loser {loser; reason} + when Node_context.is_operator + node_ctxt + (Tezos_crypto.Signature.Of_V1.public_key_hash loser) -> let result = match reason with | Conflict_resolved -> Sc_rollup_node_errors.Conflict_resolved @@ -227,8 +233,13 @@ let process_included_l1_operation (type kind) (node_ctxt : Node_context.rw) | Draw -> let stakers = match operation with - | Sc_rollup_refute {opponent; _} -> [source; opponent] - | Sc_rollup_timeout {stakers = {alice; bob}; _} -> [alice; bob] + | Sc_rollup_refute {opponent; _} -> + [source; Tezos_crypto.Signature.Of_V1.public_key_hash opponent] + | Sc_rollup_timeout {stakers = {alice; bob}; _} -> + [ + Tezos_crypto.Signature.Of_V1.public_key_hash alice; + Tezos_crypto.Signature.Of_V1.public_key_hash bob; + ] | _ -> assert false in fail_when @@ -252,7 +263,9 @@ let process_included_l1_operation (type kind) (node_ctxt : Node_context.rw) match Node_context.get_operator node_ctxt Operating with | Some (Single operating_pkh) -> fail_when - Signature.Public_key_hash.(operating_pkh = staker) + Tezos_crypto.Signature.Public_key_hash.( + operating_pkh + = Tezos_crypto.Signature.Of_V1.public_key_hash staker) Sc_rollup_node_errors.Exit_bond_recovered_bailout_mode | _ -> return_unit) | _, _ -> @@ -323,6 +336,7 @@ let process_l1_block_operations ~catching_up:_ node_ctxt (head : Layer1.header) = let open Lwt_result_syntax in let* () = accu in + let source = Tezos_crypto.Signature.Of_V1.public_key_hash source in process_l1_operation node_ctxt head ~source operation result in let apply_internal (type kind) accu ~source:_ diff --git a/src/proto_017_PtNairob/lib_sc_rollup_node/dune b/src/proto_017_PtNairob/lib_sc_rollup_node/dune index 56df22649daf..f12335716415 100644 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/dune +++ b/src/proto_017_PtNairob/lib_sc_rollup_node/dune @@ -71,3 +71,10 @@ -open Octez_injector -open Octez_smart_rollup_node -open Tezos_crypto_dal)) + +(rule + (targets signature.ml) + (action + (write-file + %{targets} + " module Bls = Tezos_crypto.Signature.Bls\n module Ed25519 = Tezos_crypto.Signature.Ed25519\n module P256 = Tezos_crypto.Signature.P256\n module Secp256k1 = Tezos_crypto.Signature.Secp256k1\n include Tezos_crypto.Signature.V1"))) diff --git a/src/proto_017_PtNairob/lib_sc_rollup_node/layer1_helpers.ml b/src/proto_017_PtNairob/lib_sc_rollup_node/layer1_helpers.ml index befcf4983b6c..cf87e038cf28 100644 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/layer1_helpers.ml +++ b/src/proto_017_PtNairob/lib_sc_rollup_node/layer1_helpers.ml @@ -78,6 +78,7 @@ let get_last_published_commitment ?(allow_unstake = true) let cctxt = new Protocol_client_context.wrap_full (cctxt :> Client_context.full) in + let*? operator = Signature.Of_V_latest.get_public_key_hash operator in let rollup_address = Sc_rollup_proto_types.Address.of_octez rollup_address in let*! res = Plugin.RPC.Sc_rollup.staked_on_commitment @@ -238,7 +239,7 @@ let get_boot_sector block_hash (node_ctxt : _ Node_context.t) = | _ -> missing_boot_sector ()) let find_whitelist _cctxt ?block:_ _rollup_address : - Signature.public_key_hash trace option tzresult Lwt.t = + Tezos_crypto.Signature.public_key_hash trace option tzresult Lwt.t = return None let find_last_whitelist_update _cctxt _rollup_address = return_none @@ -260,6 +261,7 @@ let get_balance_mutez cctxt ?block pkh = let cctxt = new Protocol_client_context.wrap_full (cctxt :> Client_context.full) in + let*? pkh = Signature.Of_V_latest.get_public_key_hash pkh in let+ balance = Protocol.Contract_services.balance cctxt (cctxt#chain, block) (Implicit pkh) in diff --git a/src/proto_017_PtNairob/lib_sc_rollup_node/refutation_game_helpers.ml b/src/proto_017_PtNairob/lib_sc_rollup_node/refutation_game_helpers.ml index 11e0c3abc94e..94fd0862fe38 100644 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/refutation_game_helpers.ml +++ b/src/proto_017_PtNairob/lib_sc_rollup_node/refutation_game_helpers.ml @@ -303,6 +303,8 @@ let make_dissection plugin (node_ctxt : _ Node_context.t) state_cache let timeout_reached node_ctxt ~self ~opponent = let open Lwt_result_syntax in let Node_context.{config; cctxt; _} = node_ctxt in + let*? self = Signature.Of_V_latest.get_public_key_hash self in + let*? opponent = Signature.Of_V_latest.get_public_key_hash opponent in let+ game_result = Plugin.RPC.Sc_rollup.timeout_reached (new Protocol_client_context.wrap_full cctxt) @@ -314,13 +316,15 @@ let timeout_reached node_ctxt ~self ~opponent = let open Sc_rollup.Game in match game_result with | Some (Loser {loser; _}) -> - let is_it_me = Signature.Public_key_hash.(self = loser) in + let is_it_me = Environment.Signature.Public_key_hash.(self = loser) in not is_it_me | _ -> false let timeout node_ctxt ~self ~opponent = let open Lwt_result_syntax in let Node_context.{config; cctxt; _} = node_ctxt in + let*? self = Signature.Of_V_latest.get_public_key_hash self in + let*? opponent = Signature.Of_V_latest.get_public_key_hash opponent in let+ timeout = Plugin.RPC.Sc_rollup.timeout (new Protocol_client_context.wrap_full cctxt) @@ -334,6 +338,7 @@ let timeout node_ctxt ~self ~opponent = let get_conflicts cctxt rollup staker = let open Lwt_result_syntax in let cctxt = new Protocol_client_context.wrap_full cctxt in + let*? staker = Signature.Of_V_latest.get_public_key_hash staker in let+ conflicts = Plugin.RPC.Sc_rollup.conflicts cctxt @@ -346,6 +351,7 @@ let get_conflicts cctxt rollup staker = let get_ongoing_games cctxt rollup staker = let open Lwt_result_syntax in let cctxt = new Protocol_client_context.wrap_full cctxt in + let*? staker = Signature.Of_V_latest.get_public_key_hash staker in let+ games = Plugin.RPC.Sc_rollup.ongoing_refutation_games cctxt @@ -355,5 +361,7 @@ let get_ongoing_games cctxt rollup staker = in List.map (fun (game, staker1, staker2) -> - (Sc_rollup_proto_types.Game.to_octez game, staker1, staker2)) + ( Sc_rollup_proto_types.Game.to_octez game, + Tezos_crypto.Signature.Of_V1.public_key_hash staker1, + Tezos_crypto.Signature.Of_V1.public_key_hash staker2 )) games diff --git a/src/proto_017_PtNairob/lib_sc_rollup_node/sc_rollup_injector.ml b/src/proto_017_PtNairob/lib_sc_rollup_node/sc_rollup_injector.ml index 7c29b325d043..e3ec4112f7ce 100644 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/sc_rollup_injector.ml +++ b/src/proto_017_PtNairob/lib_sc_rollup_node/sc_rollup_injector.ml @@ -50,6 +50,7 @@ let injector_operation_to_manager : let refutation = Sc_rollup_proto_types.Game.refutation_of_octez refutation in + let opponent = Signature.Of_V_latest.get_public_key_hash_exn opponent in Manager (Sc_rollup_refute {rollup; opponent; refutation}) | Timeout {rollup; stakers} -> let rollup = Sc_rollup_proto_types.Address.of_octez rollup in @@ -57,6 +58,7 @@ let injector_operation_to_manager : Manager (Sc_rollup_timeout {rollup; stakers}) | Recover_bond {rollup; staker} -> let rollup = Sc_rollup_proto_types.Address.of_octez rollup in + let staker = Signature.Of_V_latest.get_public_key_hash_exn staker in Manager (Sc_rollup_recover_bond {sc_rollup = rollup; staker}) | Execute_outbox_message {rollup; cemented_commitment; output_proof} -> let rollup = Sc_rollup_proto_types.Address.of_octez rollup in @@ -89,6 +91,7 @@ let injector_operation_of_manager : let refutation = Sc_rollup_proto_types.Game.refutation_to_octez refutation in + let opponent = Tezos_crypto.Signature.Of_V1.public_key_hash opponent in Some (Refute {rollup; opponent; refutation}) | Sc_rollup_timeout {rollup; stakers} -> let rollup = Sc_rollup_proto_types.Address.to_octez rollup in @@ -259,7 +262,7 @@ module Proto_client = struct let dummy_sk_uri = WithExceptions.Result.get_ok ~loc:__LOC__ @@ Tezos_signer_backends.Unencrypted.make_sk - @@ Signature.Secret_key.of_b58check_exn + @@ Tezos_crypto.Signature.Secret_key.of_b58check_exn "edsk3UqeiQWXX7NFEY1wUs6J1t2ez5aQ3hEWdqX5Jr5edZiGLW8nZr" let simulate_operations cctxt ~force ~source ~src_pk ~successor_level @@ -297,6 +300,8 @@ module Proto_client = struct in let safety_guard = Option.map Gas.Arith.integral_of_int_exn safety_guard in let*! simulation_result = + let*? source = Signature.Of_V_latest.get_public_key_hash source in + let*? src_pk = Signature.Of_V_latest.get_public_key src_pk in Injection.inject_manager_operation cctxt ~simulation:true (* Only simulation here *) @@ -480,6 +485,7 @@ module Proto_client = struct let cctxt = new Protocol_client_context.wrap_full (cctxt :> Client_context.full) in + let*? pkh = Signature.Of_V_latest.get_public_key_hash pkh in let+ balance = Protocol.Alpha_services.Contract.balance cctxt -- GitLab From b9b6178e75a5c168e67d6c75789bfc00932df7cc Mon Sep 17 00:00:00 2001 From: Albin Coquereau Date: Mon, 27 Jan 2025 17:53:44 +0100 Subject: [PATCH 15/20] Oxford: fix signature versioning compatibility --- .../lib_client/client_proto_context.ml | 7 +++-- src/proto_018_Proxford/lib_client/dune | 11 ++++++++ src/proto_018_Proxford/lib_client/mockup.ml | 4 +-- .../lib_client_commands/dune | 11 ++++++++ src/proto_018_Proxford/lib_parameters/dune | 7 +++++ src/proto_018_Proxford/lib_plugin/dune | 7 +++++ .../sc_rollup_proto_types.ml | 12 ++++++--- .../lib_sc_rollup_node/daemon_helpers.ml | 27 ++++++++++++++++--- .../lib_sc_rollup_node/dune | 7 +++++ .../lib_sc_rollup_node/layer1_helpers.ml | 17 +++++++++--- .../lib_sc_rollup_node/pvm_plugin.ml | 5 +++- .../refutation_game_helpers.ml | 12 ++++++++- .../lib_sc_rollup_node/sc_rollup_injector.ml | 8 +++++- 13 files changed, 114 insertions(+), 21 deletions(-) diff --git a/src/proto_018_Proxford/lib_client/client_proto_context.ml b/src/proto_018_Proxford/lib_client/client_proto_context.ml index 38dd59f19f6a..48aa9e3bd470 100644 --- a/src/proto_018_Proxford/lib_client/client_proto_context.ml +++ b/src/proto_018_Proxford/lib_client/client_proto_context.ml @@ -29,7 +29,6 @@ open Alpha_context open Protocol_client_context open Tezos_micheline open Client_proto_contracts -open Client_keys let get_balance (rpc : #rpc_context) ~chain ~block contract = Alpha_services.Contract.balance rpc (chain, block) contract @@ -292,7 +291,7 @@ let list_contract_labels cctxt ~chain ~block = let* nm = match (h : Contract.t) with | Implicit m -> ( - let* nm_opt = Public_key_hash.rev_find cctxt m in + let* nm_opt = Client_keys.Public_key_hash.rev_find cctxt m in match nm_opt with | None -> return "" | Some nm -> ( @@ -812,8 +811,8 @@ let activate_account (cctxt : #full) ~chain ~block ?confirmations ?dry_run Signature.Ed25519.Public_key_hash.pp key.pkh) in - let pk = Signature.Of_V1.public_key pk in - let sk = Signature.Of_V1.secret_key sk in + let pk = Tezos_crypto.Signature.Of_V1.public_key pk in + let sk = Tezos_crypto.Signature.Of_V1.secret_key sk in let*? pk_uri = Tezos_signer_backends.Unencrypted.make_pk pk in let* sk_uri = if encrypted then diff --git a/src/proto_018_Proxford/lib_client/dune b/src/proto_018_Proxford/lib_client/dune index 4c43da1ffcad..d1c056a7b12a 100644 --- a/src/proto_018_Proxford/lib_client/dune +++ b/src/proto_018_Proxford/lib_client/dune @@ -39,3 +39,14 @@ -open Tezos_protocol_plugin_018_Proxford -open Tezos_protocol_018_Proxford_parameters -open Tezos_smart_rollup_018_Proxford)) + +(rule + (targets client_keys.ml) + (action (write-file %{targets} "include Tezos_client_base.Client_keys_v1"))) + +(rule + (targets signature.ml) + (action + (write-file + %{targets} + " module Bls = Tezos_crypto.Signature.Bls\n module Ed25519 = Tezos_crypto.Signature.Ed25519\n module P256 = Tezos_crypto.Signature.P256\n module Secp256k1 = Tezos_crypto.Signature.Secp256k1\n include Tezos_crypto.Signature.V1"))) diff --git a/src/proto_018_Proxford/lib_client/mockup.ml b/src/proto_018_Proxford/lib_client/mockup.ml index d9b140c6c6fc..a0b83ea939cd 100644 --- a/src/proto_018_Proxford/lib_client/mockup.ml +++ b/src/proto_018_Proxford/lib_client/mockup.ml @@ -101,8 +101,8 @@ module Parsed_account = struct let to_bootstrap_account repr = let open Lwt_result_syntax in - let* pk_uri = Tezos_client_base.Client_keys.neuterize repr.sk_uri in - let* public_key = Tezos_client_base.Client_keys.public_key pk_uri in + let* pk_uri = Client_keys.neuterize repr.sk_uri in + let* public_key = Client_keys.public_key pk_uri in let public_key_hash = Signature.Public_key.hash public_key in return Parameters. diff --git a/src/proto_018_Proxford/lib_client_commands/dune b/src/proto_018_Proxford/lib_client_commands/dune index 46e40828ab13..9897cb663f3e 100644 --- a/src/proto_018_Proxford/lib_client_commands/dune +++ b/src/proto_018_Proxford/lib_client_commands/dune @@ -38,6 +38,17 @@ -open Tezos_protocol_plugin_018_Proxford) (modules (:standard \ alpha_commands_registration))) +(rule + (targets signature.ml) + (action + (write-file + %{targets} + " module Bls = Tezos_crypto.Signature.Bls\n module Ed25519 = Tezos_crypto.Signature.Ed25519\n module P256 = Tezos_crypto.Signature.P256\n module Secp256k1 = Tezos_crypto.Signature.Secp256k1\n include Tezos_crypto.Signature.V1"))) + +(rule + (targets client_keys.ml) + (action (write-file %{targets} "include Tezos_client_base.Client_keys_v1"))) + (library (name tezos_client_018_Proxford_commands_registration) (public_name octez-protocol-018-Proxford-libs.client.commands-registration) diff --git a/src/proto_018_Proxford/lib_parameters/dune b/src/proto_018_Proxford/lib_parameters/dune index c744259d91ca..4d645024d982 100644 --- a/src/proto_018_Proxford/lib_parameters/dune +++ b/src/proto_018_Proxford/lib_parameters/dune @@ -16,6 +16,13 @@ -open Tezos_protocol_018_Proxford) (modules (:standard \ gen))) +(rule + (targets signature.ml) + (action + (write-file + %{targets} + " module Bls = Tezos_crypto.Signature.Bls\n module Ed25519 = Tezos_crypto.Signature.Ed25519\n module P256 = Tezos_crypto.Signature.P256\n module Secp256k1 = Tezos_crypto.Signature.Secp256k1\n include Tezos_crypto.Signature.V1"))) + (executable (name gen) (libraries diff --git a/src/proto_018_Proxford/lib_plugin/dune b/src/proto_018_Proxford/lib_plugin/dune index 94eb290ea03b..63d7d4e6f0db 100644 --- a/src/proto_018_Proxford/lib_plugin/dune +++ b/src/proto_018_Proxford/lib_plugin/dune @@ -19,6 +19,13 @@ (documentation (package octez-protocol-018-Proxford-libs)) +(rule + (targets signature.ml) + (action + (write-file + %{targets} + " module Bls = Tezos_crypto.Signature.Bls\n module Ed25519 = Tezos_crypto.Signature.Ed25519\n module P256 = Tezos_crypto.Signature.P256\n module Secp256k1 = Tezos_crypto.Signature.Secp256k1\n include Tezos_crypto.Signature.V1"))) + (library (name tezos_protocol_plugin_018_Proxford_registerer) (public_name octez-protocol-018-Proxford-libs.plugin-registerer) diff --git a/src/proto_018_Proxford/lib_sc_rollup_layer2/sc_rollup_proto_types.ml b/src/proto_018_Proxford/lib_sc_rollup_layer2/sc_rollup_proto_types.ml index 384f7c4ab64b..4e08f0790fa6 100644 --- a/src/proto_018_Proxford/lib_sc_rollup_layer2/sc_rollup_proto_types.ml +++ b/src/proto_018_Proxford/lib_sc_rollup_layer2/sc_rollup_proto_types.ml @@ -331,10 +331,14 @@ module Game = struct Move {choice = Sc_rollup.Tick.to_z choice; step = step_to_octez step} let index_of_octez Octez_smart_rollup.Game.{alice; bob} = - Sc_rollup.Game.Index.make alice bob + Sc_rollup.Game.Index.make + (Signature.V1.Of_V_latest.get_public_key_hash_exn alice) + (Signature.V1.Of_V_latest.get_public_key_hash_exn bob) let index_to_octez Sc_rollup.Game.Index.{alice; bob} = - Octez_smart_rollup.Game.make_index alice bob + Octez_smart_rollup.Game.make_index + (Tezos_crypto.Signature.V_latest.Of_V1.public_key_hash alice) + (Tezos_crypto.Signature.V_latest.Of_V1.public_key_hash bob) let player_of_octez : Octez_smart_rollup.Game.player -> player = function | Alice -> Alice @@ -434,7 +438,7 @@ module Game = struct {other; their_commitment; our_commitment; parent_commitment} : conflict = { - other; + other = Signature.V1.Of_V_latest.get_public_key_hash_exn other; their_commitment = Commitment.of_octez their_commitment; our_commitment = Commitment.of_octez our_commitment; parent_commitment; @@ -445,7 +449,7 @@ module Game = struct {other; their_commitment; our_commitment; parent_commitment} : Octez_smart_rollup.Game.conflict = { - other; + other = Tezos_crypto.Signature.Of_V1.public_key_hash other; their_commitment = Commitment.to_octez their_commitment; our_commitment = Commitment.to_octez our_commitment; parent_commitment; diff --git a/src/proto_018_Proxford/lib_sc_rollup_node/daemon_helpers.ml b/src/proto_018_Proxford/lib_sc_rollup_node/daemon_helpers.ml index b48493b230ed..44f9d5bf5789 100644 --- a/src/proto_018_Proxford/lib_sc_rollup_node/daemon_helpers.ml +++ b/src/proto_018_Proxford/lib_sc_rollup_node/daemon_helpers.ml @@ -138,6 +138,9 @@ let maybe_recover_bond node_ctxt = match operating_pkh with | None -> return_unit | Some (Single operating_pkh) -> ( + let*? operating_pkh = + Signature.Of_V_latest.get_public_key_hash operating_pkh + in let* staked_on_commitment = RPC.Sc_rollup.staked_on_commitment (new Protocol_client_context.wrap_full node_ctxt.cctxt) @@ -239,7 +242,10 @@ let process_included_l1_operation (type kind) ~catching_up | ( Sc_rollup_timeout _, Sc_rollup_timeout_result {game_status = Ended end_status; _} ) -> ( match end_status with - | Loser {loser; reason} when Node_context.is_operator node_ctxt loser -> + | Loser {loser; reason} + when Node_context.is_operator + node_ctxt + (Tezos_crypto.Signature.Of_V1.public_key_hash loser) -> let result = match reason with | Conflict_resolved -> Sc_rollup_node_errors.Conflict_resolved @@ -252,8 +258,13 @@ let process_included_l1_operation (type kind) ~catching_up | Draw -> let stakers = match operation with - | Sc_rollup_refute {opponent; _} -> [source; opponent] - | Sc_rollup_timeout {stakers = {alice; bob}; _} -> [alice; bob] + | Sc_rollup_refute {opponent; _} -> + [source; Tezos_crypto.Signature.Of_V1.public_key_hash opponent] + | Sc_rollup_timeout {stakers = {alice; bob}; _} -> + [ + Tezos_crypto.Signature.Of_V1.public_key_hash alice; + Tezos_crypto.Signature.Of_V1.public_key_hash bob; + ] | _ -> assert false in fail_when @@ -277,7 +288,9 @@ let process_included_l1_operation (type kind) ~catching_up match Node_context.get_operator node_ctxt Operating with | Some (Single operating_pkh) -> fail_when - Signature.Public_key_hash.(operating_pkh = staker) + Tezos_crypto.Signature.Public_key_hash.( + operating_pkh + = Tezos_crypto.Signature.Of_V1.public_key_hash staker) Sc_rollup_node_errors.Exit_bond_recovered_bailout_mode | _ -> return_unit) | ( Sc_rollup_execute_outbox_message {output_proof; _}, @@ -320,6 +333,11 @@ let process_included_l1_operation (type kind) ~catching_up (* No need to check whitelist updates for historical data. *) then return_unit else + let whitelist_update = + List.map + Tezos_crypto.Signature.Of_V1.public_key_hash + whitelist_update + in let*? () = Node_context.check_op_in_whitelist_or_bailout_mode node_ctxt @@ -393,6 +411,7 @@ let process_l1_block_operations ~catching_up node_ctxt (head : Layer1.header) = = let open Lwt_result_syntax in let* () = accu in + let source = Tezos_crypto.Signature.Of_V1.public_key_hash source in process_l1_operation ~catching_up node_ctxt head ~source operation result in let apply_internal (type kind) accu ~source:_ diff --git a/src/proto_018_Proxford/lib_sc_rollup_node/dune b/src/proto_018_Proxford/lib_sc_rollup_node/dune index 7a73e0540009..66bbc57edddd 100644 --- a/src/proto_018_Proxford/lib_sc_rollup_node/dune +++ b/src/proto_018_Proxford/lib_sc_rollup_node/dune @@ -71,3 +71,10 @@ -open Octez_injector -open Octez_smart_rollup_node -open Tezos_crypto_dal)) + +(rule + (targets signature.ml) + (action + (write-file + %{targets} + " module Bls = Tezos_crypto.Signature.Bls\n module Ed25519 = Tezos_crypto.Signature.Ed25519\n module P256 = Tezos_crypto.Signature.P256\n module Secp256k1 = Tezos_crypto.Signature.Secp256k1\n include Tezos_crypto.Signature.V1"))) diff --git a/src/proto_018_Proxford/lib_sc_rollup_node/layer1_helpers.ml b/src/proto_018_Proxford/lib_sc_rollup_node/layer1_helpers.ml index e22943fc4503..69fbaad853c1 100644 --- a/src/proto_018_Proxford/lib_sc_rollup_node/layer1_helpers.ml +++ b/src/proto_018_Proxford/lib_sc_rollup_node/layer1_helpers.ml @@ -78,6 +78,7 @@ let get_last_published_commitment ?(allow_unstake = true) let cctxt = new Protocol_client_context.wrap_full (cctxt :> Client_context.full) in + let*? operator = Signature.Of_V_latest.get_public_key_hash operator in let rollup_address = Sc_rollup_proto_types.Address.of_octez rollup_address in let*! res = Plugin.RPC.Sc_rollup.staked_on_commitment @@ -237,11 +238,18 @@ let get_boot_sector block_hash (node_ctxt : _ Node_context.t) = | _ -> missing_boot_sector ()) let find_whitelist cctxt ?block rollup_address = + let open Lwt_result_syntax in let block = match block with Some b -> `Hash (b, 0) | None -> `Head 0 in - Plugin.RPC.Sc_rollup.whitelist - (new Protocol_client_context.wrap_full (cctxt :> Client_context.full)) - (cctxt#chain, block) - rollup_address + let* whitelist = + Plugin.RPC.Sc_rollup.whitelist + (new Protocol_client_context.wrap_full (cctxt :> Client_context.full)) + (cctxt#chain, block) + rollup_address + in + return + @@ Option.map + (List.map Tezos_crypto.Signature.V_latest.Of_V1.public_key_hash) + whitelist let find_last_whitelist_update cctxt rollup_address = let open Lwt_result_syntax in @@ -275,6 +283,7 @@ let get_balance_mutez cctxt ?block pkh = let cctxt = new Protocol_client_context.wrap_full (cctxt :> Client_context.full) in + let*? pkh = Signature.Of_V_latest.get_public_key_hash pkh in let+ balance = Protocol.Contract_services.balance cctxt (cctxt#chain, block) (Implicit pkh) in diff --git a/src/proto_018_Proxford/lib_sc_rollup_node/pvm_plugin.ml b/src/proto_018_Proxford/lib_sc_rollup_node/pvm_plugin.ml index 3f277c9185c0..15b639f3170d 100644 --- a/src/proto_018_Proxford/lib_sc_rollup_node/pvm_plugin.ml +++ b/src/proto_018_Proxford/lib_sc_rollup_node/pvm_plugin.ml @@ -150,7 +150,10 @@ let outbox_message_summary (output : Sc_rollup.output) = let summary = match output with | {message = Whitelist_update pkhs; _} -> - Outbox_message.Whitelist_update pkhs + Outbox_message.Whitelist_update + (Option.map + (List.map Tezos_crypto.Signature.Of_V1.public_key_hash) + pkhs) | {message = Atomic_transaction_batch {transactions}; _} -> let transactions = List.map outbox_transaction_summary transactions in Transaction_batch transactions diff --git a/src/proto_018_Proxford/lib_sc_rollup_node/refutation_game_helpers.ml b/src/proto_018_Proxford/lib_sc_rollup_node/refutation_game_helpers.ml index a2d0162bffa3..46f3062ba168 100644 --- a/src/proto_018_Proxford/lib_sc_rollup_node/refutation_game_helpers.ml +++ b/src/proto_018_Proxford/lib_sc_rollup_node/refutation_game_helpers.ml @@ -329,6 +329,8 @@ let make_dissection plugin (node_ctxt : _ Node_context.t) state_cache let timeout_reached node_ctxt ~self ~opponent = let open Lwt_result_syntax in let Node_context.{config; cctxt; _} = node_ctxt in + let*? self = Signature.Of_V_latest.get_public_key_hash self in + let*? opponent = Signature.Of_V_latest.get_public_key_hash opponent in let+ game_result = Plugin.RPC.Sc_rollup.timeout_reached (new Protocol_client_context.wrap_full cctxt) @@ -347,6 +349,9 @@ let timeout_reached node_ctxt ~self ~opponent = let timeout node_ctxt ~self ~opponent = let open Lwt_result_syntax in let Node_context.{config; cctxt; _} = node_ctxt in + let*? self = Signature.Of_V_latest.get_public_key_hash self in + let*? opponent = Signature.Of_V_latest.get_public_key_hash opponent in + let+ timeout = Plugin.RPC.Sc_rollup.timeout (new Protocol_client_context.wrap_full cctxt) @@ -360,6 +365,8 @@ let timeout node_ctxt ~self ~opponent = let get_conflicts cctxt rollup staker = let open Lwt_result_syntax in let cctxt = new Protocol_client_context.wrap_full cctxt in + let*? staker = Signature.Of_V_latest.get_public_key_hash staker in + let+ conflicts = Plugin.RPC.Sc_rollup.conflicts cctxt (cctxt#chain, `Head 0) rollup staker in @@ -368,6 +375,7 @@ let get_conflicts cctxt rollup staker = let get_ongoing_games cctxt rollup staker = let open Lwt_result_syntax in let cctxt = new Protocol_client_context.wrap_full cctxt in + let*? staker = Signature.Of_V_latest.get_public_key_hash staker in let+ games = Plugin.RPC.Sc_rollup.ongoing_refutation_games cctxt @@ -377,5 +385,7 @@ let get_ongoing_games cctxt rollup staker = in List.map (fun (game, staker1, staker2) -> - (Sc_rollup_proto_types.Game.to_octez game, staker1, staker2)) + ( Sc_rollup_proto_types.Game.to_octez game, + Tezos_crypto.Signature.Of_V1.public_key_hash staker1, + Tezos_crypto.Signature.Of_V1.public_key_hash staker2 )) games diff --git a/src/proto_018_Proxford/lib_sc_rollup_node/sc_rollup_injector.ml b/src/proto_018_Proxford/lib_sc_rollup_node/sc_rollup_injector.ml index 270f6db65a27..9b20c3dbca6d 100644 --- a/src/proto_018_Proxford/lib_sc_rollup_node/sc_rollup_injector.ml +++ b/src/proto_018_Proxford/lib_sc_rollup_node/sc_rollup_injector.ml @@ -47,6 +47,7 @@ let injector_operation_to_manager : let refutation = Sc_rollup_proto_types.Game.refutation_of_octez refutation in + let opponent = Signature.Of_V_latest.get_public_key_hash_exn opponent in Manager (Sc_rollup_refute {rollup; opponent; refutation}) | Timeout {rollup; stakers} -> let rollup = Sc_rollup_proto_types.Address.of_octez rollup in @@ -54,6 +55,7 @@ let injector_operation_to_manager : Manager (Sc_rollup_timeout {rollup; stakers}) | Recover_bond {rollup; staker} -> let rollup = Sc_rollup_proto_types.Address.of_octez rollup in + let staker = Signature.Of_V_latest.get_public_key_hash_exn staker in Manager (Sc_rollup_recover_bond {sc_rollup = rollup; staker}) | Execute_outbox_message {rollup; cemented_commitment; output_proof} -> let rollup = Sc_rollup_proto_types.Address.of_octez rollup in @@ -85,6 +87,7 @@ let injector_operation_of_manager : let refutation = Sc_rollup_proto_types.Game.refutation_to_octez refutation in + let opponent = Tezos_crypto.Signature.Of_V1.public_key_hash opponent in Some (Refute {rollup; opponent; refutation}) | Sc_rollup_timeout {rollup; stakers} -> let rollup = Sc_rollup_proto_types.Address.to_octez rollup in @@ -259,7 +262,7 @@ module Proto_client = struct let dummy_sk_uri = WithExceptions.Result.get_ok ~loc:__LOC__ @@ Tezos_signer_backends.Unencrypted.make_sk - @@ Signature.Secret_key.of_b58check_exn + @@ Tezos_crypto.Signature.Secret_key.of_b58check_exn "edsk3UqeiQWXX7NFEY1wUs6J1t2ez5aQ3hEWdqX5Jr5edZiGLW8nZr" let simulate_operations cctxt ~force ~source ~src_pk ~successor_level @@ -297,6 +300,8 @@ module Proto_client = struct in let safety_guard = Option.map Gas.Arith.integral_of_int_exn safety_guard in let*! simulation_result = + let*? source = Signature.Of_V_latest.get_public_key_hash source in + let*? src_pk = Signature.Of_V_latest.get_public_key src_pk in Injection.inject_manager_operation cctxt ~simulation:true (* Only simulation here *) @@ -484,6 +489,7 @@ module Proto_client = struct let cctxt = new Protocol_client_context.wrap_full (cctxt :> Client_context.full) in + let*? pkh = Signature.Of_V_latest.get_public_key_hash pkh in let+ balance = Protocol.Alpha_services.Contract.balance cctxt -- GitLab From ab659c4d82bc30a0c1b0e29ce5333ebf6baec46d Mon Sep 17 00:00:00 2001 From: Albin Coquereau Date: Mon, 27 Jan 2025 17:54:37 +0100 Subject: [PATCH 16/20] ParisB: fix signature versioning compatibility --- .../lib_client/client_proto_context.ml | 7 +++-- src/proto_019_PtParisB/lib_client/dune | 11 ++++++++ src/proto_019_PtParisB/lib_client/mockup.ml | 4 +-- .../client_proto_context_commands.ml | 4 +-- .../lib_client_commands/dune | 11 ++++++++ src/proto_019_PtParisB/lib_parameters/dune | 7 +++++ src/proto_019_PtParisB/lib_plugin/dune | 7 +++++ .../sc_rollup_proto_types.ml | 12 ++++++--- .../lib_sc_rollup_node/daemon_helpers.ml | 27 ++++++++++++++++--- .../lib_sc_rollup_node/dune | 7 +++++ .../lib_sc_rollup_node/layer1_helpers.ml | 17 +++++++++--- .../lib_sc_rollup_node/pvm_plugin.ml | 5 +++- .../refutation_game_helpers.ml | 13 ++++++++- .../lib_sc_rollup_node/sc_rollup_injector.ml | 9 ++++++- 14 files changed, 117 insertions(+), 24 deletions(-) diff --git a/src/proto_019_PtParisB/lib_client/client_proto_context.ml b/src/proto_019_PtParisB/lib_client/client_proto_context.ml index 9a071294f152..d1e534db735c 100644 --- a/src/proto_019_PtParisB/lib_client/client_proto_context.ml +++ b/src/proto_019_PtParisB/lib_client/client_proto_context.ml @@ -29,7 +29,6 @@ open Alpha_context open Protocol_client_context open Tezos_micheline open Client_proto_contracts -open Client_keys let get_balance (rpc : #rpc_context) ~chain ~block contract = Alpha_services.Contract.balance rpc (chain, block) contract @@ -292,7 +291,7 @@ let list_contract_labels cctxt ~chain ~block = let* nm = match (h : Contract.t) with | Implicit m -> ( - let* nm_opt = Public_key_hash.rev_find cctxt m in + let* nm_opt = Client_keys.Public_key_hash.rev_find cctxt m in match nm_opt with | None -> return "" | Some nm -> ( @@ -813,8 +812,8 @@ let activate_account (cctxt : #full) ~chain ~block ?confirmations ?dry_run Signature.Ed25519.Public_key_hash.pp key.pkh) in - let pk = Signature.Of_V1.public_key pk in - let sk = Signature.Of_V1.secret_key sk in + let pk = Tezos_crypto.Signature.Of_V1.public_key pk in + let sk = Tezos_crypto.Signature.Of_V1.secret_key sk in let*? pk_uri = Tezos_signer_backends.Unencrypted.make_pk pk in let* sk_uri = if encrypted then diff --git a/src/proto_019_PtParisB/lib_client/dune b/src/proto_019_PtParisB/lib_client/dune index 42cc4f14ed70..d7ae5a34a628 100644 --- a/src/proto_019_PtParisB/lib_client/dune +++ b/src/proto_019_PtParisB/lib_client/dune @@ -38,3 +38,14 @@ -open Tezos_protocol_plugin_019_PtParisB -open Tezos_protocol_019_PtParisB_parameters -open Tezos_smart_rollup_019_PtParisB)) + +(rule + (targets client_keys.ml) + (action (write-file %{targets} "include Tezos_client_base.Client_keys_v1"))) + +(rule + (targets signature.ml) + (action + (write-file + %{targets} + " module Bls = Tezos_crypto.Signature.Bls\n module Ed25519 = Tezos_crypto.Signature.Ed25519\n module P256 = Tezos_crypto.Signature.P256\n module Secp256k1 = Tezos_crypto.Signature.Secp256k1\n include Tezos_crypto.Signature.V1"))) diff --git a/src/proto_019_PtParisB/lib_client/mockup.ml b/src/proto_019_PtParisB/lib_client/mockup.ml index d9b140c6c6fc..a0b83ea939cd 100644 --- a/src/proto_019_PtParisB/lib_client/mockup.ml +++ b/src/proto_019_PtParisB/lib_client/mockup.ml @@ -101,8 +101,8 @@ module Parsed_account = struct let to_bootstrap_account repr = let open Lwt_result_syntax in - let* pk_uri = Tezos_client_base.Client_keys.neuterize repr.sk_uri in - let* public_key = Tezos_client_base.Client_keys.public_key pk_uri in + let* pk_uri = Client_keys.neuterize repr.sk_uri in + let* public_key = Client_keys.public_key pk_uri in let public_key_hash = Signature.Public_key.hash public_key in return Parameters. diff --git a/src/proto_019_PtParisB/lib_client_commands/client_proto_context_commands.ml b/src/proto_019_PtParisB/lib_client_commands/client_proto_context_commands.ml index 52e8ca1f3552..f0cd573f46ea 100644 --- a/src/proto_019_PtParisB/lib_client_commands/client_proto_context_commands.ml +++ b/src/proto_019_PtParisB/lib_client_commands/client_proto_context_commands.ml @@ -846,9 +846,7 @@ let commands_ro () = ~desc:"Get the frozen deposits limit of a delegate." no_options (prefixes ["get"; "deposits"; "limit"; "for"] - @@ Client_keys.Public_key_hash.source_param - ~name:"src" - ~desc:"source delegate" + @@ Public_key_hash.source_param ~name:"src" ~desc:"source delegate" @@ stop) (fun () delegate (cctxt : Protocol_client_context.full) -> let open Lwt_result_syntax in diff --git a/src/proto_019_PtParisB/lib_client_commands/dune b/src/proto_019_PtParisB/lib_client_commands/dune index ed33aaddf65c..a87368b989d4 100644 --- a/src/proto_019_PtParisB/lib_client_commands/dune +++ b/src/proto_019_PtParisB/lib_client_commands/dune @@ -38,6 +38,17 @@ -open Tezos_protocol_plugin_019_PtParisB) (modules (:standard \ alpha_commands_registration))) +(rule + (targets signature.ml) + (action + (write-file + %{targets} + " module Bls = Tezos_crypto.Signature.Bls\n module Ed25519 = Tezos_crypto.Signature.Ed25519\n module P256 = Tezos_crypto.Signature.P256\n module Secp256k1 = Tezos_crypto.Signature.Secp256k1\n include Tezos_crypto.Signature.V1"))) + +(rule + (targets client_keys.ml) + (action (write-file %{targets} "include Tezos_client_base.Client_keys_v1"))) + (library (name tezos_client_019_PtParisB_commands_registration) (public_name octez-protocol-019-PtParisB-libs.client.commands-registration) diff --git a/src/proto_019_PtParisB/lib_parameters/dune b/src/proto_019_PtParisB/lib_parameters/dune index 546667b6d904..16ee09d2ecb7 100644 --- a/src/proto_019_PtParisB/lib_parameters/dune +++ b/src/proto_019_PtParisB/lib_parameters/dune @@ -16,6 +16,13 @@ -open Tezos_protocol_019_PtParisB) (modules (:standard \ gen))) +(rule + (targets signature.ml) + (action + (write-file + %{targets} + " module Bls = Tezos_crypto.Signature.Bls\n module Ed25519 = Tezos_crypto.Signature.Ed25519\n module P256 = Tezos_crypto.Signature.P256\n module Secp256k1 = Tezos_crypto.Signature.Secp256k1\n include Tezos_crypto.Signature.V1"))) + (executable (name gen) (libraries diff --git a/src/proto_019_PtParisB/lib_plugin/dune b/src/proto_019_PtParisB/lib_plugin/dune index f9f974d571fb..379c5deee4d8 100644 --- a/src/proto_019_PtParisB/lib_plugin/dune +++ b/src/proto_019_PtParisB/lib_plugin/dune @@ -18,6 +18,13 @@ (documentation (package octez-protocol-019-PtParisB-libs)) +(rule + (targets signature.ml) + (action + (write-file + %{targets} + " module Bls = Tezos_crypto.Signature.Bls\n module Ed25519 = Tezos_crypto.Signature.Ed25519\n module P256 = Tezos_crypto.Signature.P256\n module Secp256k1 = Tezos_crypto.Signature.Secp256k1\n include Tezos_crypto.Signature.V1"))) + (library (name tezos_protocol_plugin_019_PtParisB_registerer) (public_name octez-protocol-019-PtParisB-libs.plugin-registerer) diff --git a/src/proto_019_PtParisB/lib_sc_rollup_layer2/sc_rollup_proto_types.ml b/src/proto_019_PtParisB/lib_sc_rollup_layer2/sc_rollup_proto_types.ml index 691e55a6ecc2..bbe78eb63568 100644 --- a/src/proto_019_PtParisB/lib_sc_rollup_layer2/sc_rollup_proto_types.ml +++ b/src/proto_019_PtParisB/lib_sc_rollup_layer2/sc_rollup_proto_types.ml @@ -331,10 +331,14 @@ module Game = struct Move {choice = Sc_rollup.Tick.to_z choice; step = step_to_octez step} let index_of_octez Octez_smart_rollup.Game.{alice; bob} = - Sc_rollup.Game.Index.make alice bob + Sc_rollup.Game.Index.make + (Signature.V1.Of_V_latest.get_public_key_hash_exn alice) + (Signature.V1.Of_V_latest.get_public_key_hash_exn bob) let index_to_octez Sc_rollup.Game.Index.{alice; bob} = - Octez_smart_rollup.Game.make_index alice bob + Octez_smart_rollup.Game.make_index + (Signature.V_latest.Of_V1.public_key_hash alice) + (Signature.V_latest.Of_V1.public_key_hash bob) let player_of_octez : Octez_smart_rollup.Game.player -> player = function | Alice -> Alice @@ -434,7 +438,7 @@ module Game = struct {other; their_commitment; our_commitment; parent_commitment} : conflict = { - other; + other = Signature.V1.Of_V_latest.get_public_key_hash_exn other; their_commitment = Commitment.of_octez their_commitment; our_commitment = Commitment.of_octez our_commitment; parent_commitment; @@ -445,7 +449,7 @@ module Game = struct {other; their_commitment; our_commitment; parent_commitment} : Octez_smart_rollup.Game.conflict = { - other; + other = Signature.Of_V1.public_key_hash other; their_commitment = Commitment.to_octez their_commitment; our_commitment = Commitment.to_octez our_commitment; parent_commitment; diff --git a/src/proto_019_PtParisB/lib_sc_rollup_node/daemon_helpers.ml b/src/proto_019_PtParisB/lib_sc_rollup_node/daemon_helpers.ml index b0c37467a82a..26d70bb463e2 100644 --- a/src/proto_019_PtParisB/lib_sc_rollup_node/daemon_helpers.ml +++ b/src/proto_019_PtParisB/lib_sc_rollup_node/daemon_helpers.ml @@ -112,6 +112,9 @@ let maybe_recover_bond node_ctxt = match operating_pkh with | None -> return_unit | Some (Single operating_pkh) -> ( + let*? operating_pkh = + Signature.Of_V_latest.get_public_key_hash operating_pkh + in let* staked_on_commitment = RPC.Sc_rollup.staked_on_commitment (new Protocol_client_context.wrap_full node_ctxt.cctxt) @@ -213,7 +216,10 @@ let process_included_l1_operation (type kind) ~catching_up | ( Sc_rollup_timeout _, Sc_rollup_timeout_result {game_status = Ended end_status; _} ) -> ( match end_status with - | Loser {loser; reason} when Node_context.is_operator node_ctxt loser -> + | Loser {loser; reason} + when Node_context.is_operator + node_ctxt + (Tezos_crypto.Signature.Of_V1.public_key_hash loser) -> let result = match reason with | Conflict_resolved -> Sc_rollup_node_errors.Conflict_resolved @@ -226,8 +232,13 @@ let process_included_l1_operation (type kind) ~catching_up | Draw -> let stakers = match operation with - | Sc_rollup_refute {opponent; _} -> [source; opponent] - | Sc_rollup_timeout {stakers = {alice; bob}; _} -> [alice; bob] + | Sc_rollup_refute {opponent; _} -> + [source; Tezos_crypto.Signature.Of_V1.public_key_hash opponent] + | Sc_rollup_timeout {stakers = {alice; bob}; _} -> + [ + Tezos_crypto.Signature.Of_V1.public_key_hash alice; + Tezos_crypto.Signature.Of_V1.public_key_hash bob; + ] | _ -> assert false in fail_when @@ -251,7 +262,9 @@ let process_included_l1_operation (type kind) ~catching_up match Node_context.get_operator node_ctxt Operating with | Some (Single operating_pkh) -> fail_when - Signature.Public_key_hash.(operating_pkh = staker) + Tezos_crypto.Signature.Public_key_hash.( + operating_pkh + = Tezos_crypto.Signature.Of_V1.public_key_hash staker) Sc_rollup_node_errors.Exit_bond_recovered_bailout_mode | _ -> return_unit) | ( Sc_rollup_execute_outbox_message {output_proof; _}, @@ -294,6 +307,11 @@ let process_included_l1_operation (type kind) ~catching_up (* No need to check whitelist updates for historical data. *) then return_unit else + let whitelist_update = + List.map + Tezos_crypto.Signature.Of_V1.public_key_hash + whitelist_update + in let*? () = Node_context.check_op_in_whitelist_or_bailout_mode node_ctxt @@ -367,6 +385,7 @@ let process_l1_block_operations ~catching_up node_ctxt (head : Layer1.header) = = let open Lwt_result_syntax in let* () = accu in + let source = Tezos_crypto.Signature.Of_V1.public_key_hash source in process_l1_operation ~catching_up node_ctxt head ~source operation result in let apply_internal (type kind) accu ~source:_ diff --git a/src/proto_019_PtParisB/lib_sc_rollup_node/dune b/src/proto_019_PtParisB/lib_sc_rollup_node/dune index d55baaf5b105..126a91072841 100644 --- a/src/proto_019_PtParisB/lib_sc_rollup_node/dune +++ b/src/proto_019_PtParisB/lib_sc_rollup_node/dune @@ -70,3 +70,10 @@ -open Octez_injector -open Octez_smart_rollup_node -open Tezos_crypto_dal)) + +(rule + (targets signature.ml) + (action + (write-file + %{targets} + " module Bls = Tezos_crypto.Signature.Bls\n module Ed25519 = Tezos_crypto.Signature.Ed25519\n module P256 = Tezos_crypto.Signature.P256\n module Secp256k1 = Tezos_crypto.Signature.Secp256k1\n include Tezos_crypto.Signature.V1"))) diff --git a/src/proto_019_PtParisB/lib_sc_rollup_node/layer1_helpers.ml b/src/proto_019_PtParisB/lib_sc_rollup_node/layer1_helpers.ml index e22943fc4503..69fbaad853c1 100644 --- a/src/proto_019_PtParisB/lib_sc_rollup_node/layer1_helpers.ml +++ b/src/proto_019_PtParisB/lib_sc_rollup_node/layer1_helpers.ml @@ -78,6 +78,7 @@ let get_last_published_commitment ?(allow_unstake = true) let cctxt = new Protocol_client_context.wrap_full (cctxt :> Client_context.full) in + let*? operator = Signature.Of_V_latest.get_public_key_hash operator in let rollup_address = Sc_rollup_proto_types.Address.of_octez rollup_address in let*! res = Plugin.RPC.Sc_rollup.staked_on_commitment @@ -237,11 +238,18 @@ let get_boot_sector block_hash (node_ctxt : _ Node_context.t) = | _ -> missing_boot_sector ()) let find_whitelist cctxt ?block rollup_address = + let open Lwt_result_syntax in let block = match block with Some b -> `Hash (b, 0) | None -> `Head 0 in - Plugin.RPC.Sc_rollup.whitelist - (new Protocol_client_context.wrap_full (cctxt :> Client_context.full)) - (cctxt#chain, block) - rollup_address + let* whitelist = + Plugin.RPC.Sc_rollup.whitelist + (new Protocol_client_context.wrap_full (cctxt :> Client_context.full)) + (cctxt#chain, block) + rollup_address + in + return + @@ Option.map + (List.map Tezos_crypto.Signature.V_latest.Of_V1.public_key_hash) + whitelist let find_last_whitelist_update cctxt rollup_address = let open Lwt_result_syntax in @@ -275,6 +283,7 @@ let get_balance_mutez cctxt ?block pkh = let cctxt = new Protocol_client_context.wrap_full (cctxt :> Client_context.full) in + let*? pkh = Signature.Of_V_latest.get_public_key_hash pkh in let+ balance = Protocol.Contract_services.balance cctxt (cctxt#chain, block) (Implicit pkh) in diff --git a/src/proto_019_PtParisB/lib_sc_rollup_node/pvm_plugin.ml b/src/proto_019_PtParisB/lib_sc_rollup_node/pvm_plugin.ml index 8d0a4fd39c02..ebf34f1de592 100644 --- a/src/proto_019_PtParisB/lib_sc_rollup_node/pvm_plugin.ml +++ b/src/proto_019_PtParisB/lib_sc_rollup_node/pvm_plugin.ml @@ -155,7 +155,10 @@ let outbox_message_summary (output : Sc_rollup.output) = let summary = match output with | {message = Whitelist_update pkhs; _} -> - Outbox_message.Whitelist_update pkhs + Outbox_message.Whitelist_update + (Option.map + (List.map Tezos_crypto.Signature.Of_V1.public_key_hash) + pkhs) | {message = Atomic_transaction_batch {transactions}; _} -> let transactions = List.map outbox_transaction_summary transactions in Transaction_batch transactions diff --git a/src/proto_019_PtParisB/lib_sc_rollup_node/refutation_game_helpers.ml b/src/proto_019_PtParisB/lib_sc_rollup_node/refutation_game_helpers.ml index 53211c554a80..364f4cf4786d 100644 --- a/src/proto_019_PtParisB/lib_sc_rollup_node/refutation_game_helpers.ml +++ b/src/proto_019_PtParisB/lib_sc_rollup_node/refutation_game_helpers.ml @@ -350,6 +350,9 @@ let make_dissection plugin (node_ctxt : _ Node_context.t) state_cache let timeout_reached node_ctxt ~self ~opponent = let open Lwt_result_syntax in let Node_context.{config; cctxt; _} = node_ctxt in + let*? self = Signature.Of_V_latest.get_public_key_hash self in + let*? opponent = Signature.Of_V_latest.get_public_key_hash opponent in + let+ game_result = Plugin.RPC.Sc_rollup.timeout_reached (new Protocol_client_context.wrap_full cctxt) @@ -368,6 +371,9 @@ let timeout_reached node_ctxt ~self ~opponent = let timeout node_ctxt ~self ~opponent = let open Lwt_result_syntax in let Node_context.{config; cctxt; _} = node_ctxt in + let*? self = Signature.Of_V_latest.get_public_key_hash self in + let*? opponent = Signature.Of_V_latest.get_public_key_hash opponent in + let+ timeout = Plugin.RPC.Sc_rollup.timeout (new Protocol_client_context.wrap_full cctxt) @@ -381,6 +387,8 @@ let timeout node_ctxt ~self ~opponent = let get_conflicts cctxt rollup staker = let open Lwt_result_syntax in let cctxt = new Protocol_client_context.wrap_full cctxt in + let*? staker = Signature.Of_V_latest.get_public_key_hash staker in + let+ conflicts = Plugin.RPC.Sc_rollup.conflicts cctxt (cctxt#chain, `Head 0) rollup staker in @@ -389,6 +397,7 @@ let get_conflicts cctxt rollup staker = let get_ongoing_games cctxt rollup staker = let open Lwt_result_syntax in let cctxt = new Protocol_client_context.wrap_full cctxt in + let*? staker = Signature.Of_V_latest.get_public_key_hash staker in let+ games = Plugin.RPC.Sc_rollup.ongoing_refutation_games cctxt @@ -398,5 +407,7 @@ let get_ongoing_games cctxt rollup staker = in List.map (fun (game, staker1, staker2) -> - (Sc_rollup_proto_types.Game.to_octez game, staker1, staker2)) + ( Sc_rollup_proto_types.Game.to_octez game, + Tezos_crypto.Signature.Of_V1.public_key_hash staker1, + Tezos_crypto.Signature.Of_V1.public_key_hash staker2 )) games diff --git a/src/proto_019_PtParisB/lib_sc_rollup_node/sc_rollup_injector.ml b/src/proto_019_PtParisB/lib_sc_rollup_node/sc_rollup_injector.ml index 707060162d8a..d108ced97550 100644 --- a/src/proto_019_PtParisB/lib_sc_rollup_node/sc_rollup_injector.ml +++ b/src/proto_019_PtParisB/lib_sc_rollup_node/sc_rollup_injector.ml @@ -47,6 +47,7 @@ let injector_operation_to_manager : let refutation = Sc_rollup_proto_types.Game.refutation_of_octez refutation in + let opponent = Signature.Of_V_latest.get_public_key_hash_exn opponent in Manager (Sc_rollup_refute {rollup; opponent; refutation}) | Timeout {rollup; stakers} -> let rollup = Sc_rollup_proto_types.Address.of_octez rollup in @@ -54,6 +55,7 @@ let injector_operation_to_manager : Manager (Sc_rollup_timeout {rollup; stakers}) | Recover_bond {rollup; staker} -> let rollup = Sc_rollup_proto_types.Address.of_octez rollup in + let staker = Signature.Of_V_latest.get_public_key_hash_exn staker in Manager (Sc_rollup_recover_bond {sc_rollup = rollup; staker}) | Execute_outbox_message {rollup; cemented_commitment; output_proof} -> let rollup = Sc_rollup_proto_types.Address.of_octez rollup in @@ -102,6 +104,7 @@ let injector_operation_of_manager : let refutation = Sc_rollup_proto_types.Game.refutation_to_octez refutation in + let opponent = Tezos_crypto.Signature.Of_V1.public_key_hash opponent in Some (Refute {rollup; opponent; refutation}) | Sc_rollup_timeout {rollup; stakers} -> let rollup = Sc_rollup_proto_types.Address.to_octez rollup in @@ -282,7 +285,7 @@ module Proto_client = struct let dummy_sk_uri = WithExceptions.Result.get_ok ~loc:__LOC__ @@ Tezos_signer_backends.Unencrypted.make_sk - @@ Signature.Secret_key.of_b58check_exn + @@ Tezos_crypto.Signature.Secret_key.of_b58check_exn "edsk3UqeiQWXX7NFEY1wUs6J1t2ez5aQ3hEWdqX5Jr5edZiGLW8nZr" let simulate_operations cctxt ~force ~source ~src_pk ~successor_level @@ -320,6 +323,8 @@ module Proto_client = struct in let safety_guard = Option.map Gas.Arith.integral_of_int_exn safety_guard in let*! simulation_result = + let*? source = Signature.Of_V_latest.get_public_key_hash source in + let*? src_pk = Signature.Of_V_latest.get_public_key src_pk in Injection.inject_manager_operation cctxt ~simulation:true (* Only simulation here *) @@ -503,6 +508,8 @@ module Proto_client = struct let cctxt = new Protocol_client_context.wrap_full (cctxt :> Client_context.full) in + let*? pkh = Signature.Of_V_latest.get_public_key_hash pkh in + let+ balance = Protocol.Alpha_services.Contract.balance cctxt -- GitLab From 3e70a140a59e1ace3dd762a6ae5fd14f4a4aa125 Mon Sep 17 00:00:00 2001 From: Albin Coquereau Date: Mon, 27 Jan 2025 17:55:13 +0100 Subject: [PATCH 17/20] ParisC: fix signature versioning compatibility --- .../lib_client/client_proto_context.ml | 4 +-- src/proto_020_PsParisC/lib_client/dune | 11 ++++++++ src/proto_020_PsParisC/lib_client/mockup.ml | 4 +-- .../lib_client_commands/dune | 11 ++++++++ src/proto_020_PsParisC/lib_parameters/dune | 7 +++++ src/proto_020_PsParisC/lib_plugin/dune | 7 +++++ .../sc_rollup_proto_types.ml | 12 ++++++--- .../lib_sc_rollup_node/daemon_helpers.ml | 27 ++++++++++++++++--- .../lib_sc_rollup_node/dune | 7 +++++ .../lib_sc_rollup_node/layer1_helpers.ml | 17 +++++++++--- .../lib_sc_rollup_node/pvm_plugin.ml | 5 +++- .../refutation_game_helpers.ml | 10 ++++++- .../lib_sc_rollup_node/sc_rollup_injector.ml | 8 +++++- src/proto_next/lib_plugin/mempool.ml | 11 ++++---- src/proto_next/lib_plugin/mempool.mli | 2 +- 15 files changed, 118 insertions(+), 25 deletions(-) diff --git a/src/proto_020_PsParisC/lib_client/client_proto_context.ml b/src/proto_020_PsParisC/lib_client/client_proto_context.ml index 9a071294f152..b83e2a8bee5a 100644 --- a/src/proto_020_PsParisC/lib_client/client_proto_context.ml +++ b/src/proto_020_PsParisC/lib_client/client_proto_context.ml @@ -813,8 +813,8 @@ let activate_account (cctxt : #full) ~chain ~block ?confirmations ?dry_run Signature.Ed25519.Public_key_hash.pp key.pkh) in - let pk = Signature.Of_V1.public_key pk in - let sk = Signature.Of_V1.secret_key sk in + let pk = Tezos_crypto.Signature.Of_V1.public_key pk in + let sk = Tezos_crypto.Signature.Of_V1.secret_key sk in let*? pk_uri = Tezos_signer_backends.Unencrypted.make_pk pk in let* sk_uri = if encrypted then diff --git a/src/proto_020_PsParisC/lib_client/dune b/src/proto_020_PsParisC/lib_client/dune index a38af0a026ab..880f420f3f47 100644 --- a/src/proto_020_PsParisC/lib_client/dune +++ b/src/proto_020_PsParisC/lib_client/dune @@ -38,3 +38,14 @@ -open Tezos_protocol_plugin_020_PsParisC -open Tezos_protocol_020_PsParisC_parameters -open Tezos_smart_rollup_020_PsParisC)) + +(rule + (targets client_keys.ml) + (action (write-file %{targets} "include Tezos_client_base.Client_keys_v1"))) + +(rule + (targets signature.ml) + (action + (write-file + %{targets} + " module Bls = Tezos_crypto.Signature.Bls\n module Ed25519 = Tezos_crypto.Signature.Ed25519\n module P256 = Tezos_crypto.Signature.P256\n module Secp256k1 = Tezos_crypto.Signature.Secp256k1\n include Tezos_crypto.Signature.V1"))) diff --git a/src/proto_020_PsParisC/lib_client/mockup.ml b/src/proto_020_PsParisC/lib_client/mockup.ml index d9b140c6c6fc..a0b83ea939cd 100644 --- a/src/proto_020_PsParisC/lib_client/mockup.ml +++ b/src/proto_020_PsParisC/lib_client/mockup.ml @@ -101,8 +101,8 @@ module Parsed_account = struct let to_bootstrap_account repr = let open Lwt_result_syntax in - let* pk_uri = Tezos_client_base.Client_keys.neuterize repr.sk_uri in - let* public_key = Tezos_client_base.Client_keys.public_key pk_uri in + let* pk_uri = Client_keys.neuterize repr.sk_uri in + let* public_key = Client_keys.public_key pk_uri in let public_key_hash = Signature.Public_key.hash public_key in return Parameters. diff --git a/src/proto_020_PsParisC/lib_client_commands/dune b/src/proto_020_PsParisC/lib_client_commands/dune index 5a66524c3be1..8fda293b9f41 100644 --- a/src/proto_020_PsParisC/lib_client_commands/dune +++ b/src/proto_020_PsParisC/lib_client_commands/dune @@ -38,6 +38,17 @@ -open Tezos_protocol_plugin_020_PsParisC) (modules (:standard \ alpha_commands_registration))) +(rule + (targets signature.ml) + (action + (write-file + %{targets} + " module Bls = Tezos_crypto.Signature.Bls\n module Ed25519 = Tezos_crypto.Signature.Ed25519\n module P256 = Tezos_crypto.Signature.P256\n module Secp256k1 = Tezos_crypto.Signature.Secp256k1\n include Tezos_crypto.Signature.V1"))) + +(rule + (targets client_keys.ml) + (action (write-file %{targets} "include Tezos_client_base.Client_keys_v1"))) + (library (name tezos_client_020_PsParisC_commands_registration) (public_name octez-protocol-020-PsParisC-libs.client.commands-registration) diff --git a/src/proto_020_PsParisC/lib_parameters/dune b/src/proto_020_PsParisC/lib_parameters/dune index 6f286ddcfc21..944c599acf9c 100644 --- a/src/proto_020_PsParisC/lib_parameters/dune +++ b/src/proto_020_PsParisC/lib_parameters/dune @@ -16,6 +16,13 @@ -open Tezos_protocol_020_PsParisC) (modules (:standard \ gen))) +(rule + (targets signature.ml) + (action + (write-file + %{targets} + " module Bls = Tezos_crypto.Signature.Bls\n module Ed25519 = Tezos_crypto.Signature.Ed25519\n module P256 = Tezos_crypto.Signature.P256\n module Secp256k1 = Tezos_crypto.Signature.Secp256k1\n include Tezos_crypto.Signature.V1"))) + (executable (name gen) (libraries diff --git a/src/proto_020_PsParisC/lib_plugin/dune b/src/proto_020_PsParisC/lib_plugin/dune index 3adf033c524f..4111fad4ab52 100644 --- a/src/proto_020_PsParisC/lib_plugin/dune +++ b/src/proto_020_PsParisC/lib_plugin/dune @@ -18,6 +18,13 @@ (documentation (package octez-protocol-020-PsParisC-libs)) +(rule + (targets signature.ml) + (action + (write-file + %{targets} + " module Bls = Tezos_crypto.Signature.Bls\n module Ed25519 = Tezos_crypto.Signature.Ed25519\n module P256 = Tezos_crypto.Signature.P256\n module Secp256k1 = Tezos_crypto.Signature.Secp256k1\n include Tezos_crypto.Signature.V1"))) + (library (name tezos_protocol_plugin_020_PsParisC_registerer) (public_name octez-protocol-020-PsParisC-libs.plugin-registerer) diff --git a/src/proto_020_PsParisC/lib_sc_rollup_layer2/sc_rollup_proto_types.ml b/src/proto_020_PsParisC/lib_sc_rollup_layer2/sc_rollup_proto_types.ml index 691e55a6ecc2..bbe78eb63568 100644 --- a/src/proto_020_PsParisC/lib_sc_rollup_layer2/sc_rollup_proto_types.ml +++ b/src/proto_020_PsParisC/lib_sc_rollup_layer2/sc_rollup_proto_types.ml @@ -331,10 +331,14 @@ module Game = struct Move {choice = Sc_rollup.Tick.to_z choice; step = step_to_octez step} let index_of_octez Octez_smart_rollup.Game.{alice; bob} = - Sc_rollup.Game.Index.make alice bob + Sc_rollup.Game.Index.make + (Signature.V1.Of_V_latest.get_public_key_hash_exn alice) + (Signature.V1.Of_V_latest.get_public_key_hash_exn bob) let index_to_octez Sc_rollup.Game.Index.{alice; bob} = - Octez_smart_rollup.Game.make_index alice bob + Octez_smart_rollup.Game.make_index + (Signature.V_latest.Of_V1.public_key_hash alice) + (Signature.V_latest.Of_V1.public_key_hash bob) let player_of_octez : Octez_smart_rollup.Game.player -> player = function | Alice -> Alice @@ -434,7 +438,7 @@ module Game = struct {other; their_commitment; our_commitment; parent_commitment} : conflict = { - other; + other = Signature.V1.Of_V_latest.get_public_key_hash_exn other; their_commitment = Commitment.of_octez their_commitment; our_commitment = Commitment.of_octez our_commitment; parent_commitment; @@ -445,7 +449,7 @@ module Game = struct {other; their_commitment; our_commitment; parent_commitment} : Octez_smart_rollup.Game.conflict = { - other; + other = Signature.Of_V1.public_key_hash other; their_commitment = Commitment.to_octez their_commitment; our_commitment = Commitment.to_octez our_commitment; parent_commitment; diff --git a/src/proto_020_PsParisC/lib_sc_rollup_node/daemon_helpers.ml b/src/proto_020_PsParisC/lib_sc_rollup_node/daemon_helpers.ml index b0c37467a82a..26d70bb463e2 100644 --- a/src/proto_020_PsParisC/lib_sc_rollup_node/daemon_helpers.ml +++ b/src/proto_020_PsParisC/lib_sc_rollup_node/daemon_helpers.ml @@ -112,6 +112,9 @@ let maybe_recover_bond node_ctxt = match operating_pkh with | None -> return_unit | Some (Single operating_pkh) -> ( + let*? operating_pkh = + Signature.Of_V_latest.get_public_key_hash operating_pkh + in let* staked_on_commitment = RPC.Sc_rollup.staked_on_commitment (new Protocol_client_context.wrap_full node_ctxt.cctxt) @@ -213,7 +216,10 @@ let process_included_l1_operation (type kind) ~catching_up | ( Sc_rollup_timeout _, Sc_rollup_timeout_result {game_status = Ended end_status; _} ) -> ( match end_status with - | Loser {loser; reason} when Node_context.is_operator node_ctxt loser -> + | Loser {loser; reason} + when Node_context.is_operator + node_ctxt + (Tezos_crypto.Signature.Of_V1.public_key_hash loser) -> let result = match reason with | Conflict_resolved -> Sc_rollup_node_errors.Conflict_resolved @@ -226,8 +232,13 @@ let process_included_l1_operation (type kind) ~catching_up | Draw -> let stakers = match operation with - | Sc_rollup_refute {opponent; _} -> [source; opponent] - | Sc_rollup_timeout {stakers = {alice; bob}; _} -> [alice; bob] + | Sc_rollup_refute {opponent; _} -> + [source; Tezos_crypto.Signature.Of_V1.public_key_hash opponent] + | Sc_rollup_timeout {stakers = {alice; bob}; _} -> + [ + Tezos_crypto.Signature.Of_V1.public_key_hash alice; + Tezos_crypto.Signature.Of_V1.public_key_hash bob; + ] | _ -> assert false in fail_when @@ -251,7 +262,9 @@ let process_included_l1_operation (type kind) ~catching_up match Node_context.get_operator node_ctxt Operating with | Some (Single operating_pkh) -> fail_when - Signature.Public_key_hash.(operating_pkh = staker) + Tezos_crypto.Signature.Public_key_hash.( + operating_pkh + = Tezos_crypto.Signature.Of_V1.public_key_hash staker) Sc_rollup_node_errors.Exit_bond_recovered_bailout_mode | _ -> return_unit) | ( Sc_rollup_execute_outbox_message {output_proof; _}, @@ -294,6 +307,11 @@ let process_included_l1_operation (type kind) ~catching_up (* No need to check whitelist updates for historical data. *) then return_unit else + let whitelist_update = + List.map + Tezos_crypto.Signature.Of_V1.public_key_hash + whitelist_update + in let*? () = Node_context.check_op_in_whitelist_or_bailout_mode node_ctxt @@ -367,6 +385,7 @@ let process_l1_block_operations ~catching_up node_ctxt (head : Layer1.header) = = let open Lwt_result_syntax in let* () = accu in + let source = Tezos_crypto.Signature.Of_V1.public_key_hash source in process_l1_operation ~catching_up node_ctxt head ~source operation result in let apply_internal (type kind) accu ~source:_ diff --git a/src/proto_020_PsParisC/lib_sc_rollup_node/dune b/src/proto_020_PsParisC/lib_sc_rollup_node/dune index 483bd42a7bd8..6ab5832a816f 100644 --- a/src/proto_020_PsParisC/lib_sc_rollup_node/dune +++ b/src/proto_020_PsParisC/lib_sc_rollup_node/dune @@ -70,3 +70,10 @@ -open Octez_injector -open Octez_smart_rollup_node -open Tezos_crypto_dal)) + +(rule + (targets signature.ml) + (action + (write-file + %{targets} + " module Bls = Tezos_crypto.Signature.Bls\n module Ed25519 = Tezos_crypto.Signature.Ed25519\n module P256 = Tezos_crypto.Signature.P256\n module Secp256k1 = Tezos_crypto.Signature.Secp256k1\n include Tezos_crypto.Signature.V1"))) diff --git a/src/proto_020_PsParisC/lib_sc_rollup_node/layer1_helpers.ml b/src/proto_020_PsParisC/lib_sc_rollup_node/layer1_helpers.ml index e22943fc4503..be34d0530273 100644 --- a/src/proto_020_PsParisC/lib_sc_rollup_node/layer1_helpers.ml +++ b/src/proto_020_PsParisC/lib_sc_rollup_node/layer1_helpers.ml @@ -78,6 +78,7 @@ let get_last_published_commitment ?(allow_unstake = true) let cctxt = new Protocol_client_context.wrap_full (cctxt :> Client_context.full) in + let*? operator = Signature.Of_V_latest.get_public_key_hash operator in let rollup_address = Sc_rollup_proto_types.Address.of_octez rollup_address in let*! res = Plugin.RPC.Sc_rollup.staked_on_commitment @@ -237,11 +238,18 @@ let get_boot_sector block_hash (node_ctxt : _ Node_context.t) = | _ -> missing_boot_sector ()) let find_whitelist cctxt ?block rollup_address = + let open Lwt_result_syntax in let block = match block with Some b -> `Hash (b, 0) | None -> `Head 0 in - Plugin.RPC.Sc_rollup.whitelist - (new Protocol_client_context.wrap_full (cctxt :> Client_context.full)) - (cctxt#chain, block) - rollup_address + let* whitelist = + Plugin.RPC.Sc_rollup.whitelist + (new Protocol_client_context.wrap_full (cctxt :> Client_context.full)) + (cctxt#chain, block) + rollup_address + in + return + @@ Option.map + (List.map Tezos_crypto.Signature.Of_V1.public_key_hash) + whitelist let find_last_whitelist_update cctxt rollup_address = let open Lwt_result_syntax in @@ -275,6 +283,7 @@ let get_balance_mutez cctxt ?block pkh = let cctxt = new Protocol_client_context.wrap_full (cctxt :> Client_context.full) in + let*? pkh = Signature.Of_V_latest.get_public_key_hash pkh in let+ balance = Protocol.Contract_services.balance cctxt (cctxt#chain, block) (Implicit pkh) in diff --git a/src/proto_020_PsParisC/lib_sc_rollup_node/pvm_plugin.ml b/src/proto_020_PsParisC/lib_sc_rollup_node/pvm_plugin.ml index 8d0a4fd39c02..ebf34f1de592 100644 --- a/src/proto_020_PsParisC/lib_sc_rollup_node/pvm_plugin.ml +++ b/src/proto_020_PsParisC/lib_sc_rollup_node/pvm_plugin.ml @@ -155,7 +155,10 @@ let outbox_message_summary (output : Sc_rollup.output) = let summary = match output with | {message = Whitelist_update pkhs; _} -> - Outbox_message.Whitelist_update pkhs + Outbox_message.Whitelist_update + (Option.map + (List.map Tezos_crypto.Signature.Of_V1.public_key_hash) + pkhs) | {message = Atomic_transaction_batch {transactions}; _} -> let transactions = List.map outbox_transaction_summary transactions in Transaction_batch transactions diff --git a/src/proto_020_PsParisC/lib_sc_rollup_node/refutation_game_helpers.ml b/src/proto_020_PsParisC/lib_sc_rollup_node/refutation_game_helpers.ml index 53211c554a80..28308b40e2b7 100644 --- a/src/proto_020_PsParisC/lib_sc_rollup_node/refutation_game_helpers.ml +++ b/src/proto_020_PsParisC/lib_sc_rollup_node/refutation_game_helpers.ml @@ -350,6 +350,8 @@ let make_dissection plugin (node_ctxt : _ Node_context.t) state_cache let timeout_reached node_ctxt ~self ~opponent = let open Lwt_result_syntax in let Node_context.{config; cctxt; _} = node_ctxt in + let*? self = Signature.Of_V_latest.get_public_key_hash self in + let*? opponent = Signature.Of_V_latest.get_public_key_hash opponent in let+ game_result = Plugin.RPC.Sc_rollup.timeout_reached (new Protocol_client_context.wrap_full cctxt) @@ -368,6 +370,8 @@ let timeout_reached node_ctxt ~self ~opponent = let timeout node_ctxt ~self ~opponent = let open Lwt_result_syntax in let Node_context.{config; cctxt; _} = node_ctxt in + let*? self = Signature.Of_V_latest.get_public_key_hash self in + let*? opponent = Signature.Of_V_latest.get_public_key_hash opponent in let+ timeout = Plugin.RPC.Sc_rollup.timeout (new Protocol_client_context.wrap_full cctxt) @@ -381,6 +385,7 @@ let timeout node_ctxt ~self ~opponent = let get_conflicts cctxt rollup staker = let open Lwt_result_syntax in let cctxt = new Protocol_client_context.wrap_full cctxt in + let*? staker = Signature.Of_V_latest.get_public_key_hash staker in let+ conflicts = Plugin.RPC.Sc_rollup.conflicts cctxt (cctxt#chain, `Head 0) rollup staker in @@ -389,6 +394,7 @@ let get_conflicts cctxt rollup staker = let get_ongoing_games cctxt rollup staker = let open Lwt_result_syntax in let cctxt = new Protocol_client_context.wrap_full cctxt in + let*? staker = Signature.Of_V_latest.get_public_key_hash staker in let+ games = Plugin.RPC.Sc_rollup.ongoing_refutation_games cctxt @@ -398,5 +404,7 @@ let get_ongoing_games cctxt rollup staker = in List.map (fun (game, staker1, staker2) -> - (Sc_rollup_proto_types.Game.to_octez game, staker1, staker2)) + ( Sc_rollup_proto_types.Game.to_octez game, + Tezos_crypto.Signature.Of_V1.public_key_hash staker1, + Tezos_crypto.Signature.Of_V1.public_key_hash staker2 )) games diff --git a/src/proto_020_PsParisC/lib_sc_rollup_node/sc_rollup_injector.ml b/src/proto_020_PsParisC/lib_sc_rollup_node/sc_rollup_injector.ml index cb48470e1c64..24f6cb015bba 100644 --- a/src/proto_020_PsParisC/lib_sc_rollup_node/sc_rollup_injector.ml +++ b/src/proto_020_PsParisC/lib_sc_rollup_node/sc_rollup_injector.ml @@ -47,6 +47,7 @@ let injector_operation_to_manager : let refutation = Sc_rollup_proto_types.Game.refutation_of_octez refutation in + let opponent = Signature.Of_V_latest.get_public_key_hash_exn opponent in Manager (Sc_rollup_refute {rollup; opponent; refutation}) | Timeout {rollup; stakers} -> let rollup = Sc_rollup_proto_types.Address.of_octez rollup in @@ -54,6 +55,7 @@ let injector_operation_to_manager : Manager (Sc_rollup_timeout {rollup; stakers}) | Recover_bond {rollup; staker} -> let rollup = Sc_rollup_proto_types.Address.of_octez rollup in + let staker = Signature.Of_V_latest.get_public_key_hash_exn staker in Manager (Sc_rollup_recover_bond {sc_rollup = rollup; staker}) | Execute_outbox_message {rollup; cemented_commitment; output_proof} -> let rollup = Sc_rollup_proto_types.Address.of_octez rollup in @@ -102,6 +104,7 @@ let injector_operation_of_manager : let refutation = Sc_rollup_proto_types.Game.refutation_to_octez refutation in + let opponent = Tezos_crypto.Signature.Of_V1.public_key_hash opponent in Some (Refute {rollup; opponent; refutation}) | Sc_rollup_timeout {rollup; stakers} -> let rollup = Sc_rollup_proto_types.Address.to_octez rollup in @@ -282,7 +285,7 @@ module Proto_client = struct let dummy_sk_uri = WithExceptions.Result.get_ok ~loc:__LOC__ @@ Tezos_signer_backends.Unencrypted.make_sk - @@ Signature.Secret_key.of_b58check_exn + @@ Tezos_crypto.Signature.Secret_key.of_b58check_exn "edsk3UqeiQWXX7NFEY1wUs6J1t2ez5aQ3hEWdqX5Jr5edZiGLW8nZr" let simulate_operations cctxt ~force ~source ~src_pk ~successor_level @@ -320,6 +323,8 @@ module Proto_client = struct in let safety_guard = Option.map Gas.Arith.integral_of_int_exn safety_guard in let*! simulation_result = + let*? source = Signature.Of_V_latest.get_public_key_hash source in + let*? src_pk = Signature.Of_V_latest.get_public_key src_pk in Injection.inject_manager_operation cctxt ~simulation:true (* Only simulation here *) @@ -503,6 +508,7 @@ module Proto_client = struct let cctxt = new Protocol_client_context.wrap_full (cctxt :> Client_context.full) in + let*? pkh = Signature.Of_V_latest.get_public_key_hash pkh in let+ balance = Protocol.Alpha_services.Contract.balance cctxt diff --git a/src/proto_next/lib_plugin/mempool.ml b/src/proto_next/lib_plugin/mempool.ml index 84df0640e5ca..b1f3e473d77f 100644 --- a/src/proto_next/lib_plugin/mempool.ml +++ b/src/proto_next/lib_plugin/mempool.ml @@ -804,6 +804,7 @@ let sources_from_operation ctxt ({shell = _; protocol_data = Operation_data {contents; _}} : Main.operation) = let open Lwt_syntax in + let map_pkh_env = List.map Tezos_crypto.Signature.Of_V1.public_key_hash in match contents with | Single (Failing_noop _) -> return_nil | Single (Preattestation consensus_content) @@ -814,7 +815,7 @@ let sources_from_operation ctxt in match slot_owner with | Ok (_ctxt, {delegate; consensus_pkh; consensus_pk = _}) -> - return [delegate; consensus_pkh] + return @@ map_pkh_env [delegate; consensus_pkh] | Error _ -> return_nil) | Single (Attestations_aggregate {consensus_content; committee}) -> let level = Level.from_raw ctxt consensus_content.level in @@ -839,10 +840,10 @@ let sources_from_operation ctxt | Single (Vdf_revelation _) -> return_nil | Single (Proposals {source; _}) | Single (Ballot {source; _}) -> - return [source] - | Single (Drain_delegate {delegate; _}) -> return [delegate] - | Single (Manager_operation {source; _}) -> return [source] - | Cons (Manager_operation {source; _}, _) -> return [source] + return @@ map_pkh_env [source] + | Single (Drain_delegate {delegate; _}) -> return @@ map_pkh_env [delegate] + | Single (Manager_operation {source; _}) -> return @@ map_pkh_env [source] + | Cons (Manager_operation {source; _}, _) -> return @@ map_pkh_env [source] module Internal_for_tests = struct let default_config_with_clock_drift clock_drift = diff --git a/src/proto_next/lib_plugin/mempool.mli b/src/proto_next/lib_plugin/mempool.mli index 2690bb5797d9..80f9f004fcf4 100644 --- a/src/proto_next/lib_plugin/mempool.mli +++ b/src/proto_next/lib_plugin/mempool.mli @@ -192,7 +192,7 @@ val get_context : val sources_from_operation : ctxt -> Protocol.Alpha_context.packed_operation -> - Signature.public_key_hash list Lwt.t + Tezos_crypto.Signature.public_key_hash list Lwt.t module Internal_for_tests : sig open Protocol.Alpha_context -- GitLab From b38658be99038a765ffb28096c1094c8067b2151 Mon Sep 17 00:00:00 2001 From: Albin Coquereau Date: Mon, 27 Jan 2025 17:56:32 +0100 Subject: [PATCH 18/20] Quebec: fix signature versioning compatibility --- src/proto_021_PsQuebec/lib_benchmark/dune | 11 ++++++++ .../lib_benchmark/michelson_samplers.ml | 8 +++--- .../lib_benchmarks_proto/dune | 7 +++++ .../lib_client/client_proto_context.ml | 4 +-- src/proto_021_PsQuebec/lib_client/dune | 11 ++++++++ src/proto_021_PsQuebec/lib_client/mockup.ml | 4 +-- .../lib_client_commands/dune | 11 ++++++++ .../lib_dal/dal_plugin_registration.ml | 12 ++++++--- src/proto_021_PsQuebec/lib_dal/dune | 7 +++++ .../lib_delegate/baking_scheduling.ml | 3 ++- src/proto_021_PsQuebec/lib_delegate/dune | 11 ++++++++ .../lib_delegate/node_rpc.ml | 8 ++++-- .../lib_delegate/test/mockup_simulator/dune | 4 +++ .../test/mockup_simulator/mockup_simulator.ml | 4 +-- .../lib_delegate/test/tenderbrute/lib/dune | 7 +++++ src/proto_021_PsQuebec/lib_injector/dune | 11 ++++++++ .../lib_injector/injector_plugin.ml | 6 +++-- src/proto_021_PsQuebec/lib_parameters/dune | 7 +++++ src/proto_021_PsQuebec/lib_plugin/dune | 7 +++++ src/proto_021_PsQuebec/lib_plugin/mempool.ml | 11 ++++---- src/proto_021_PsQuebec/lib_plugin/mempool.mli | 2 +- .../lib_protocol/test/helpers/dune | 7 +++++ .../michelson/test_script_typed_ir_size.ml | 3 +-- .../test/pbt/test_script_comparison.ml | 3 +-- .../test/pbt/test_script_roundtrip.ml | 3 +-- .../sc_rollup_proto_types.ml | 12 ++++++--- .../lib_sc_rollup_node/daemon_helpers.ml | 27 ++++++++++++++++--- .../lib_sc_rollup_node/dune | 7 +++++ .../lib_sc_rollup_node/layer1_helpers.ml | 17 +++++++++--- .../lib_sc_rollup_node/pvm_plugin.ml | 5 +++- .../refutation_game_helpers.ml | 14 ++++++++-- .../lib_sc_rollup_node/sc_rollup_injector.ml | 8 +++++- .../test/test_octez_conversions.ml | 5 ++-- 33 files changed, 219 insertions(+), 48 deletions(-) diff --git a/src/proto_021_PsQuebec/lib_benchmark/dune b/src/proto_021_PsQuebec/lib_benchmark/dune index a1ee30f958c3..16063dab5363 100644 --- a/src/proto_021_PsQuebec/lib_benchmark/dune +++ b/src/proto_021_PsQuebec/lib_benchmark/dune @@ -31,3 +31,14 @@ -open Tezos_protocol_021_PsQuebec -open Tezos_021_PsQuebec_test_helpers) (private_modules kernel rules state_space)) + +(rule + (targets crypto_samplers.mli) + (action + (write-file + %{targets} + "include module type of Tezos_benchmark.Crypto_samplers.V1"))) + +(rule + (targets crypto_samplers.ml) + (action (write-file %{targets} "include Tezos_benchmark.Crypto_samplers.V1"))) diff --git a/src/proto_021_PsQuebec/lib_benchmark/michelson_samplers.ml b/src/proto_021_PsQuebec/lib_benchmark/michelson_samplers.ml index a872dc08ca63..469df205b720 100644 --- a/src/proto_021_PsQuebec/lib_benchmark/michelson_samplers.ml +++ b/src/proto_021_PsQuebec/lib_benchmark/michelson_samplers.ml @@ -604,7 +604,9 @@ module Make Data_encoding.Binary.of_string_exn Script_chain_id.encoding string let signature rng_state = - Script_signature.make (Michelson_base.signature rng_state) + Script_signature.make + (Tezos_crypto.Signature.V1.Of_V_latest.get_signature_exn + (Michelson_base.signature rng_state)) let rec value : type a ac. (a, ac) Script_typed_ir.ty -> a sampler = let open Script_typed_ir in @@ -618,8 +620,8 @@ module Make | String_t -> Michelson_base.string | Bytes_t -> Michelson_base.bytes | Mutez_t -> Michelson_base.tez - | Key_hash_t -> Crypto_samplers.pkh - | Key_t -> Crypto_samplers.pk + | Key_hash_t -> fun pkh -> Crypto_samplers.pkh pkh + | Key_t -> fun pk -> Crypto_samplers.pk pk | Timestamp_t -> Michelson_base.timestamp | Bool_t -> Base_samplers.uniform_bool | Address_t -> address diff --git a/src/proto_021_PsQuebec/lib_benchmarks_proto/dune b/src/proto_021_PsQuebec/lib_benchmarks_proto/dune index 0a97dbe34853..d8ea8515999d 100644 --- a/src/proto_021_PsQuebec/lib_benchmarks_proto/dune +++ b/src/proto_021_PsQuebec/lib_benchmarks_proto/dune @@ -42,3 +42,10 @@ -open Tezos_021_PsQuebec_test_helpers -open Tezos_client_021_PsQuebec -open Tezos_protocol_plugin_021_PsQuebec)) + +(rule + (targets signature.ml) + (action + (write-file + %{targets} + " module Bls = Tezos_crypto.Signature.Bls\n module Ed25519 = Tezos_crypto.Signature.Ed25519\n module P256 = Tezos_crypto.Signature.P256\n module Secp256k1 = Tezos_crypto.Signature.Secp256k1\n include Tezos_crypto.Signature.V1"))) diff --git a/src/proto_021_PsQuebec/lib_client/client_proto_context.ml b/src/proto_021_PsQuebec/lib_client/client_proto_context.ml index 1d3f63ee6480..ed36f6ab00c2 100644 --- a/src/proto_021_PsQuebec/lib_client/client_proto_context.ml +++ b/src/proto_021_PsQuebec/lib_client/client_proto_context.ml @@ -814,8 +814,8 @@ let activate_account (cctxt : #full) ~chain ~block ?confirmations ?dry_run Signature.Ed25519.Public_key_hash.pp key.pkh) in - let pk = Signature.Of_V1.public_key pk in - let sk = Signature.Of_V1.secret_key sk in + let pk = Tezos_crypto.Signature.Of_V1.public_key pk in + let sk = Tezos_crypto.Signature.Of_V1.secret_key sk in let*? pk_uri = Tezos_signer_backends.Unencrypted.make_pk pk in let* sk_uri = if encrypted then diff --git a/src/proto_021_PsQuebec/lib_client/dune b/src/proto_021_PsQuebec/lib_client/dune index 6f7c8d0f1c17..761ef6a9a5e0 100644 --- a/src/proto_021_PsQuebec/lib_client/dune +++ b/src/proto_021_PsQuebec/lib_client/dune @@ -38,3 +38,14 @@ -open Tezos_protocol_plugin_021_PsQuebec -open Tezos_protocol_021_PsQuebec_parameters -open Tezos_smart_rollup_021_PsQuebec)) + +(rule + (targets client_keys.ml) + (action (write-file %{targets} "include Tezos_client_base.Client_keys_v1"))) + +(rule + (targets signature.ml) + (action + (write-file + %{targets} + " module Bls = Tezos_crypto.Signature.Bls\n module Ed25519 = Tezos_crypto.Signature.Ed25519\n module P256 = Tezos_crypto.Signature.P256\n module Secp256k1 = Tezos_crypto.Signature.Secp256k1\n include Tezos_crypto.Signature.V1"))) diff --git a/src/proto_021_PsQuebec/lib_client/mockup.ml b/src/proto_021_PsQuebec/lib_client/mockup.ml index d9b140c6c6fc..a0b83ea939cd 100644 --- a/src/proto_021_PsQuebec/lib_client/mockup.ml +++ b/src/proto_021_PsQuebec/lib_client/mockup.ml @@ -101,8 +101,8 @@ module Parsed_account = struct let to_bootstrap_account repr = let open Lwt_result_syntax in - let* pk_uri = Tezos_client_base.Client_keys.neuterize repr.sk_uri in - let* public_key = Tezos_client_base.Client_keys.public_key pk_uri in + let* pk_uri = Client_keys.neuterize repr.sk_uri in + let* public_key = Client_keys.public_key pk_uri in let public_key_hash = Signature.Public_key.hash public_key in return Parameters. diff --git a/src/proto_021_PsQuebec/lib_client_commands/dune b/src/proto_021_PsQuebec/lib_client_commands/dune index e08e14fd6d94..516dbb13792a 100644 --- a/src/proto_021_PsQuebec/lib_client_commands/dune +++ b/src/proto_021_PsQuebec/lib_client_commands/dune @@ -38,6 +38,17 @@ -open Tezos_protocol_plugin_021_PsQuebec) (modules (:standard \ alpha_commands_registration))) +(rule + (targets signature.ml) + (action + (write-file + %{targets} + " module Bls = Tezos_crypto.Signature.Bls\n module Ed25519 = Tezos_crypto.Signature.Ed25519\n module P256 = Tezos_crypto.Signature.P256\n module Secp256k1 = Tezos_crypto.Signature.Secp256k1\n include Tezos_crypto.Signature.V1"))) + +(rule + (targets client_keys.ml) + (action (write-file %{targets} "include Tezos_client_base.Client_keys_v1"))) + (library (name tezos_client_021_PsQuebec_commands_registration) (public_name octez-protocol-021-PsQuebec-libs.client.commands-registration) diff --git a/src/proto_021_PsQuebec/lib_dal/dal_plugin_registration.ml b/src/proto_021_PsQuebec/lib_dal/dal_plugin_registration.ml index 00fe7bcfed34..a6c81852ed77 100644 --- a/src/proto_021_PsQuebec/lib_dal/dal_plugin_registration.ml +++ b/src/proto_021_PsQuebec/lib_dal/dal_plugin_registration.ml @@ -163,9 +163,13 @@ module Plugin = struct | Receipt (Operation_metadata operation_metadata) -> ( match operation_metadata.contents with | Single_result (Attestation_result result) -> + let delegate = + Tezos_crypto.Signature.Of_V1.public_key_hash + result.delegate + in Some ( tb_slot, - Some result.delegate, + Some delegate, packed_operation, dal_attestation ) | _ -> @@ -187,8 +191,9 @@ module Plugin = struct in List.fold_left (fun acc ({delegate; indexes} : Plugin.RPC.Dal.S.shards_assignment) -> - Signature.Public_key_hash.Map.add delegate indexes acc) - Signature.Public_key_hash.Map.empty + let delegate = Tezos_crypto.Signature.Of_V1.public_key_hash delegate in + Tezos_crypto.Signature.Public_key_hash.Map.add delegate indexes acc) + Tezos_crypto.Signature.Public_key_hash.Map.empty pkh_to_shards let dal_attestation (block : block_info) = @@ -206,6 +211,7 @@ module Plugin = struct let is_delegate ctxt ~pkh = let open Lwt_result_syntax in + let*? pkh = Signature.Of_V_latest.get_public_key_hash pkh in let cpctxt = new Protocol_client_context.wrap_rpc_context ctxt in (* We just want to know whether is a delegate. We call 'context/delegates//deactivated' just because it should be cheaper diff --git a/src/proto_021_PsQuebec/lib_dal/dune b/src/proto_021_PsQuebec/lib_dal/dune index 2bc3c492d48d..e274b9397341 100644 --- a/src/proto_021_PsQuebec/lib_dal/dune +++ b/src/proto_021_PsQuebec/lib_dal/dune @@ -36,3 +36,10 @@ -open Tezos_embedded_protocol_021_PsQuebec -open Tezos_layer2_utils_021_PsQuebec -open Tezos_protocol_021_PsQuebec)) + +(rule + (targets signature.ml) + (action + (write-file + %{targets} + " module Bls = Tezos_crypto.Signature.Bls\n module Ed25519 = Tezos_crypto.Signature.Ed25519\n module P256 = Tezos_crypto.Signature.P256\n module Secp256k1 = Tezos_crypto.Signature.Secp256k1\n include Tezos_crypto.Signature.V1"))) diff --git a/src/proto_021_PsQuebec/lib_delegate/baking_scheduling.ml b/src/proto_021_PsQuebec/lib_delegate/baking_scheduling.ml index be73d489d5dd..5ac7a664c115 100644 --- a/src/proto_021_PsQuebec/lib_delegate/baking_scheduling.ml +++ b/src/proto_021_PsQuebec/lib_delegate/baking_scheduling.ml @@ -1003,7 +1003,8 @@ let register_dal_profiles cctxt dal_node_rpc_ctxt delegates = let attesters = Tezos_dal_node_services.Operator_profile.attesters operator_profile in - if Signature.Public_key_hash.Set.is_empty attesters then warn () + if Tezos_crypto.Signature.Public_key_hash.Set.is_empty attesters then + warn () else Lwt.return_unit in Node_rpc.register_dal_profiles dal_ctxt delegates diff --git a/src/proto_021_PsQuebec/lib_delegate/dune b/src/proto_021_PsQuebec/lib_delegate/dune index c76706c728b0..264a9f9b1bec 100644 --- a/src/proto_021_PsQuebec/lib_delegate/dune +++ b/src/proto_021_PsQuebec/lib_delegate/dune @@ -53,6 +53,17 @@ -open Tezos_crypto_dal) (modules (:standard \ Baking_commands Baking_commands_registration))) +(rule + (targets signature.ml) + (action + (write-file + %{targets} + " module Bls = Tezos_crypto.Signature.Bls\n module Ed25519 = Tezos_crypto.Signature.Ed25519\n module P256 = Tezos_crypto.Signature.P256\n module Secp256k1 = Tezos_crypto.Signature.Secp256k1\n include Tezos_crypto.Signature.V1"))) + +(rule + (targets client_keys.ml) + (action (write-file %{targets} "include Tezos_client_base.Client_keys_v1"))) + (library (name tezos_baking_021_PsQuebec_commands) (public_name octez-protocol-021-PsQuebec-libs.baking-commands) diff --git a/src/proto_021_PsQuebec/lib_delegate/node_rpc.ml b/src/proto_021_PsQuebec/lib_delegate/node_rpc.ml index cac8a3cdb762..ec23febc0f2e 100644 --- a/src/proto_021_PsQuebec/lib_delegate/node_rpc.ml +++ b/src/proto_021_PsQuebec/lib_delegate/node_rpc.ml @@ -380,7 +380,7 @@ let get_attestable_slots dal_node_rpc_ctxt pkh ~attested_level = Tezos_rpc.Context.make_call Tezos_dal_node_services.Services.get_attestable_slots dal_node_rpc_ctxt - (((), pkh), attested_level) + (((), Tezos_crypto.Signature.Of_V1.public_key_hash pkh), attested_level) () () @@ -404,7 +404,11 @@ let get_dal_profiles dal_node_rpc_ctxt = let register_dal_profiles dal_node_rpc_ctxt delegates = let profiles = Tezos_dal_node_services.Operator_profile.make - ~attesters:(List.map (fun k -> k.public_key_hash) delegates) + ~attesters: + (List.map + (fun k -> + Tezos_crypto.Signature.Of_V1.public_key_hash k.public_key_hash) + delegates) () in Tezos_rpc.Context.make_call diff --git a/src/proto_021_PsQuebec/lib_delegate/test/mockup_simulator/dune b/src/proto_021_PsQuebec/lib_delegate/test/mockup_simulator/dune index 096d34793e2a..cbec739b4309 100644 --- a/src/proto_021_PsQuebec/lib_delegate/test/mockup_simulator/dune +++ b/src/proto_021_PsQuebec/lib_delegate/test/mockup_simulator/dune @@ -31,3 +31,7 @@ -open Tezos_protocol_021_PsQuebec_parameters -open Tenderbrute_021_PsQuebec -open Tezt_core)) + +(rule + (targets client_keys.ml) + (action (write-file %{targets} "include Tezos_client_base.Client_keys_v1"))) diff --git a/src/proto_021_PsQuebec/lib_delegate/test/mockup_simulator/mockup_simulator.ml b/src/proto_021_PsQuebec/lib_delegate/test/mockup_simulator/mockup_simulator.ml index 96a99d358e05..1a91de65db3a 100644 --- a/src/proto_021_PsQuebec/lib_delegate/test/mockup_simulator/mockup_simulator.ml +++ b/src/proto_021_PsQuebec/lib_delegate/test/mockup_simulator/mockup_simulator.ml @@ -967,7 +967,6 @@ let baker_process ~(delegates : Baking_state.consensus_key list) ~base_dir List.iter_es (fun ({alias; public_key; public_key_hash; secret_key_uri} : Baking_state.consensus_key) -> - let open Tezos_client_base in let name = alias |> WithExceptions.Option.get ~loc:__LOC__ in let* public_key_uri = Client_keys.neuterize secret_key_uri in Client_keys.register_key @@ -1299,8 +1298,7 @@ let make_baking_delegate let run ?(config = default_config) bakers_spec = let open Lwt_result_syntax in - Tezos_client_base.Client_keys.register_signer - (module Tezos_signer_backends.Unencrypted) ; + Client_keys.register_signer (module Tezos_signer_backends.Unencrypted) ; let total_accounts = List.fold_left (fun acc (n, _) -> acc + n) 0 bakers_spec in diff --git a/src/proto_021_PsQuebec/lib_delegate/test/tenderbrute/lib/dune b/src/proto_021_PsQuebec/lib_delegate/test/tenderbrute/lib/dune index 52340d461b94..5b97211d170f 100644 --- a/src/proto_021_PsQuebec/lib_delegate/test/tenderbrute/lib/dune +++ b/src/proto_021_PsQuebec/lib_delegate/test/tenderbrute/lib/dune @@ -19,3 +19,10 @@ -open Tezos_protocol_021_PsQuebec -open Tezos_client_base -open Tezos_client_021_PsQuebec)) + +(rule + (targets signature.ml) + (action + (write-file + %{targets} + " module Bls = Tezos_crypto.Signature.Bls\n module Ed25519 = Tezos_crypto.Signature.Ed25519\n module P256 = Tezos_crypto.Signature.P256\n module Secp256k1 = Tezos_crypto.Signature.Secp256k1\n include Tezos_crypto.Signature.V1"))) diff --git a/src/proto_021_PsQuebec/lib_injector/dune b/src/proto_021_PsQuebec/lib_injector/dune index 964f0d4a2002..caa994288e29 100644 --- a/src/proto_021_PsQuebec/lib_injector/dune +++ b/src/proto_021_PsQuebec/lib_injector/dune @@ -21,3 +21,14 @@ -open Tezos_client_021_PsQuebec -open Tezos_client_base -open Tezos_protocol_plugin_021_PsQuebec)) + +(rule + (targets client_keys.ml) + (action (write-file %{targets} "include Tezos_client_base.Client_keys_v1"))) + +(rule + (targets signature.ml) + (action + (write-file + %{targets} + " module Bls = Tezos_crypto.Signature.Bls\n module Ed25519 = Tezos_crypto.Signature.Ed25519\n module P256 = Tezos_crypto.Signature.P256\n module Secp256k1 = Tezos_crypto.Signature.Secp256k1\n include Tezos_crypto.Signature.V1"))) diff --git a/src/proto_021_PsQuebec/lib_injector/injector_plugin.ml b/src/proto_021_PsQuebec/lib_injector/injector_plugin.ml index 3b3134a43a37..c7f19d73a63b 100644 --- a/src/proto_021_PsQuebec/lib_injector/injector_plugin.ml +++ b/src/proto_021_PsQuebec/lib_injector/injector_plugin.ml @@ -232,7 +232,7 @@ module Proto_client = struct let dummy_sk_uri = WithExceptions.Result.get_ok ~loc:__LOC__ @@ Tezos_signer_backends.Unencrypted.make_sk - @@ Signature.Secret_key.of_b58check_exn + @@ Tezos_crypto.Signature.Secret_key.of_b58check_exn "edsk3UqeiQWXX7NFEY1wUs6J1t2ez5aQ3hEWdqX5Jr5edZiGLW8nZr" let simulate_operations cctxt ~force ~source ~src_pk ~successor_level @@ -270,6 +270,8 @@ module Proto_client = struct in let safety_guard = Option.map Gas.Arith.integral_of_int_exn safety_guard in let*! simulation_result = + let*? source = Signature.Of_V_latest.get_public_key_hash source in + let*? src_pk = Signature.Of_V_latest.get_public_key src_pk in Injection.inject_manager_operation cctxt ~simulation:true (* Only simulation here *) @@ -444,7 +446,7 @@ module Proto_client = struct let cctxt = new Protocol_client_context.wrap_full (cctxt :> Client_context.full) in - + let*? pkh = Signature.Of_V_latest.get_public_key_hash pkh in let+ balance = Plugin.Alpha_services.Contract.balance cctxt diff --git a/src/proto_021_PsQuebec/lib_parameters/dune b/src/proto_021_PsQuebec/lib_parameters/dune index a89ce37f7cf8..8e522ecf12f9 100644 --- a/src/proto_021_PsQuebec/lib_parameters/dune +++ b/src/proto_021_PsQuebec/lib_parameters/dune @@ -16,6 +16,13 @@ -open Tezos_protocol_021_PsQuebec) (modules (:standard \ gen))) +(rule + (targets signature.ml) + (action + (write-file + %{targets} + " module Bls = Tezos_crypto.Signature.Bls\n module Ed25519 = Tezos_crypto.Signature.Ed25519\n module P256 = Tezos_crypto.Signature.P256\n module Secp256k1 = Tezos_crypto.Signature.Secp256k1\n include Tezos_crypto.Signature.V1"))) + (executable (name gen) (libraries diff --git a/src/proto_021_PsQuebec/lib_plugin/dune b/src/proto_021_PsQuebec/lib_plugin/dune index 02c40b41a79e..365cb65412b9 100644 --- a/src/proto_021_PsQuebec/lib_plugin/dune +++ b/src/proto_021_PsQuebec/lib_plugin/dune @@ -18,6 +18,13 @@ (documentation (package octez-protocol-021-PsQuebec-libs)) +(rule + (targets signature.ml) + (action + (write-file + %{targets} + " module Bls = Tezos_crypto.Signature.Bls\n module Ed25519 = Tezos_crypto.Signature.Ed25519\n module P256 = Tezos_crypto.Signature.P256\n module Secp256k1 = Tezos_crypto.Signature.Secp256k1\n include Tezos_crypto.Signature.V1"))) + (library (name tezos_protocol_plugin_021_PsQuebec_registerer) (public_name octez-protocol-021-PsQuebec-libs.plugin-registerer) diff --git a/src/proto_021_PsQuebec/lib_plugin/mempool.ml b/src/proto_021_PsQuebec/lib_plugin/mempool.ml index bc4dacf05049..016000801ff3 100644 --- a/src/proto_021_PsQuebec/lib_plugin/mempool.ml +++ b/src/proto_021_PsQuebec/lib_plugin/mempool.ml @@ -798,6 +798,7 @@ let sources_from_operation ctxt ({shell = _; protocol_data = Operation_data {contents; _}} : Main.operation) = let open Lwt_syntax in + let map_pkh_env = List.map Tezos_crypto.Signature.Of_V1.public_key_hash in match contents with | Single (Failing_noop _) -> return_nil | Single (Preattestation consensus_content) @@ -808,7 +809,7 @@ let sources_from_operation ctxt in match slot_owner with | Ok (_ctxt, {delegate; consensus_pkh; consensus_pk = _}) -> - return [delegate; consensus_pkh] + return @@ map_pkh_env [delegate; consensus_pkh] | Error _ -> return_nil) | Single (Seed_nonce_revelation _) | Single (Double_preattestation_evidence _) @@ -818,10 +819,10 @@ let sources_from_operation ctxt | Single (Vdf_revelation _) -> return_nil | Single (Proposals {source; _}) | Single (Ballot {source; _}) -> - return [source] - | Single (Drain_delegate {delegate; _}) -> return [delegate] - | Single (Manager_operation {source; _}) -> return [source] - | Cons (Manager_operation {source; _}, _) -> return [source] + return @@ map_pkh_env [source] + | Single (Drain_delegate {delegate; _}) -> return @@ map_pkh_env [delegate] + | Single (Manager_operation {source; _}) -> return @@ map_pkh_env [source] + | Cons (Manager_operation {source; _}, _) -> return @@ map_pkh_env [source] module Internal_for_tests = struct let default_config_with_clock_drift clock_drift = diff --git a/src/proto_021_PsQuebec/lib_plugin/mempool.mli b/src/proto_021_PsQuebec/lib_plugin/mempool.mli index 2690bb5797d9..80f9f004fcf4 100644 --- a/src/proto_021_PsQuebec/lib_plugin/mempool.mli +++ b/src/proto_021_PsQuebec/lib_plugin/mempool.mli @@ -192,7 +192,7 @@ val get_context : val sources_from_operation : ctxt -> Protocol.Alpha_context.packed_operation -> - Signature.public_key_hash list Lwt.t + Tezos_crypto.Signature.public_key_hash list Lwt.t module Internal_for_tests : sig open Protocol.Alpha_context diff --git a/src/proto_021_PsQuebec/lib_protocol/test/helpers/dune b/src/proto_021_PsQuebec/lib_protocol/test/helpers/dune index f945cee62547..9f062a78655e 100644 --- a/src/proto_021_PsQuebec/lib_protocol/test/helpers/dune +++ b/src/proto_021_PsQuebec/lib_protocol/test/helpers/dune @@ -37,3 +37,10 @@ -open Tezos_shell_services -open Tezos_crypto_dal -open Tezos_smart_rollup_021_PsQuebec)) + +(rule + (targets signature.ml) + (action + (write-file + %{targets} + " module Bls = Tezos_crypto.Signature.Bls\n module Ed25519 = Tezos_crypto.Signature.Ed25519\n module P256 = Tezos_crypto.Signature.P256\n module Secp256k1 = Tezos_crypto.Signature.Secp256k1\n include Tezos_crypto.Signature.V1"))) diff --git a/src/proto_021_PsQuebec/lib_protocol/test/integration/michelson/test_script_typed_ir_size.ml b/src/proto_021_PsQuebec/lib_protocol/test/integration/michelson/test_script_typed_ir_size.ml index 1e6bd1433ed5..987aeab8097e 100644 --- a/src/proto_021_PsQuebec/lib_protocol/test/integration/michelson/test_script_typed_ir_size.ml +++ b/src/proto_021_PsQuebec/lib_protocol/test/integration/michelson/test_script_typed_ir_size.ml @@ -96,8 +96,7 @@ let dont_show _fmt _ = () let size = {Tezos_benchmark.Base_samplers.min = 4; max = 32} -module Crypto_samplers = -Tezos_benchmark.Crypto_samplers.Make_finite_key_pool (struct +module Crypto_samplers = Crypto_samplers.Make_finite_key_pool (struct let size = 10 let algo = `Default diff --git a/src/proto_021_PsQuebec/lib_protocol/test/pbt/test_script_comparison.ml b/src/proto_021_PsQuebec/lib_protocol/test/pbt/test_script_comparison.ml index 823ea7c35f1d..765a8a9cf06a 100644 --- a/src/proto_021_PsQuebec/lib_protocol/test/pbt/test_script_comparison.ml +++ b/src/proto_021_PsQuebec/lib_protocol/test/pbt/test_script_comparison.ml @@ -113,8 +113,7 @@ module Parameters = struct } end -module Crypto_samplers = -Tezos_benchmark.Crypto_samplers.Make_finite_key_pool (struct +module Crypto_samplers = Crypto_samplers.Make_finite_key_pool (struct let size = 1000 let algo = `Default diff --git a/src/proto_021_PsQuebec/lib_protocol/test/pbt/test_script_roundtrip.ml b/src/proto_021_PsQuebec/lib_protocol/test/pbt/test_script_roundtrip.ml index 03c38787ca5d..7c4f399588fb 100644 --- a/src/proto_021_PsQuebec/lib_protocol/test/pbt/test_script_roundtrip.ml +++ b/src/proto_021_PsQuebec/lib_protocol/test/pbt/test_script_roundtrip.ml @@ -46,8 +46,7 @@ module Parameters = struct } end -module Crypto_samplers = -Tezos_benchmark.Crypto_samplers.Make_finite_key_pool (struct +module Crypto_samplers = Crypto_samplers.Make_finite_key_pool (struct let size = 1000 let algo = `Default diff --git a/src/proto_021_PsQuebec/lib_sc_rollup_layer2/sc_rollup_proto_types.ml b/src/proto_021_PsQuebec/lib_sc_rollup_layer2/sc_rollup_proto_types.ml index 691e55a6ecc2..bbe78eb63568 100644 --- a/src/proto_021_PsQuebec/lib_sc_rollup_layer2/sc_rollup_proto_types.ml +++ b/src/proto_021_PsQuebec/lib_sc_rollup_layer2/sc_rollup_proto_types.ml @@ -331,10 +331,14 @@ module Game = struct Move {choice = Sc_rollup.Tick.to_z choice; step = step_to_octez step} let index_of_octez Octez_smart_rollup.Game.{alice; bob} = - Sc_rollup.Game.Index.make alice bob + Sc_rollup.Game.Index.make + (Signature.V1.Of_V_latest.get_public_key_hash_exn alice) + (Signature.V1.Of_V_latest.get_public_key_hash_exn bob) let index_to_octez Sc_rollup.Game.Index.{alice; bob} = - Octez_smart_rollup.Game.make_index alice bob + Octez_smart_rollup.Game.make_index + (Signature.V_latest.Of_V1.public_key_hash alice) + (Signature.V_latest.Of_V1.public_key_hash bob) let player_of_octez : Octez_smart_rollup.Game.player -> player = function | Alice -> Alice @@ -434,7 +438,7 @@ module Game = struct {other; their_commitment; our_commitment; parent_commitment} : conflict = { - other; + other = Signature.V1.Of_V_latest.get_public_key_hash_exn other; their_commitment = Commitment.of_octez their_commitment; our_commitment = Commitment.of_octez our_commitment; parent_commitment; @@ -445,7 +449,7 @@ module Game = struct {other; their_commitment; our_commitment; parent_commitment} : Octez_smart_rollup.Game.conflict = { - other; + other = Signature.Of_V1.public_key_hash other; their_commitment = Commitment.to_octez their_commitment; our_commitment = Commitment.to_octez our_commitment; parent_commitment; diff --git a/src/proto_021_PsQuebec/lib_sc_rollup_node/daemon_helpers.ml b/src/proto_021_PsQuebec/lib_sc_rollup_node/daemon_helpers.ml index b0c37467a82a..4c9adf86a501 100644 --- a/src/proto_021_PsQuebec/lib_sc_rollup_node/daemon_helpers.ml +++ b/src/proto_021_PsQuebec/lib_sc_rollup_node/daemon_helpers.ml @@ -113,6 +113,9 @@ let maybe_recover_bond node_ctxt = | None -> return_unit | Some (Single operating_pkh) -> ( let* staked_on_commitment = + let*? operating_pkh = + Signature.Of_V_latest.get_public_key_hash operating_pkh + in RPC.Sc_rollup.staked_on_commitment (new Protocol_client_context.wrap_full node_ctxt.cctxt) (node_ctxt.cctxt#chain, `Head 0) @@ -213,7 +216,10 @@ let process_included_l1_operation (type kind) ~catching_up | ( Sc_rollup_timeout _, Sc_rollup_timeout_result {game_status = Ended end_status; _} ) -> ( match end_status with - | Loser {loser; reason} when Node_context.is_operator node_ctxt loser -> + | Loser {loser; reason} + when Node_context.is_operator + node_ctxt + (Tezos_crypto.Signature.Of_V1.public_key_hash loser) -> let result = match reason with | Conflict_resolved -> Sc_rollup_node_errors.Conflict_resolved @@ -226,8 +232,13 @@ let process_included_l1_operation (type kind) ~catching_up | Draw -> let stakers = match operation with - | Sc_rollup_refute {opponent; _} -> [source; opponent] - | Sc_rollup_timeout {stakers = {alice; bob}; _} -> [alice; bob] + | Sc_rollup_refute {opponent; _} -> + [source; Tezos_crypto.Signature.Of_V1.public_key_hash opponent] + | Sc_rollup_timeout {stakers = {alice; bob}; _} -> + [ + Tezos_crypto.Signature.Of_V1.public_key_hash alice; + Tezos_crypto.Signature.Of_V1.public_key_hash bob; + ] | _ -> assert false in fail_when @@ -251,7 +262,9 @@ let process_included_l1_operation (type kind) ~catching_up match Node_context.get_operator node_ctxt Operating with | Some (Single operating_pkh) -> fail_when - Signature.Public_key_hash.(operating_pkh = staker) + Tezos_crypto.Signature.Public_key_hash.( + operating_pkh + = Tezos_crypto.Signature.Of_V1.public_key_hash staker) Sc_rollup_node_errors.Exit_bond_recovered_bailout_mode | _ -> return_unit) | ( Sc_rollup_execute_outbox_message {output_proof; _}, @@ -294,6 +307,11 @@ let process_included_l1_operation (type kind) ~catching_up (* No need to check whitelist updates for historical data. *) then return_unit else + let whitelist_update = + List.map + Tezos_crypto.Signature.Of_V1.public_key_hash + whitelist_update + in let*? () = Node_context.check_op_in_whitelist_or_bailout_mode node_ctxt @@ -367,6 +385,7 @@ let process_l1_block_operations ~catching_up node_ctxt (head : Layer1.header) = = let open Lwt_result_syntax in let* () = accu in + let source = Tezos_crypto.Signature.Of_V1.public_key_hash source in process_l1_operation ~catching_up node_ctxt head ~source operation result in let apply_internal (type kind) accu ~source:_ diff --git a/src/proto_021_PsQuebec/lib_sc_rollup_node/dune b/src/proto_021_PsQuebec/lib_sc_rollup_node/dune index 8892955ef334..1c4c6b4d119d 100644 --- a/src/proto_021_PsQuebec/lib_sc_rollup_node/dune +++ b/src/proto_021_PsQuebec/lib_sc_rollup_node/dune @@ -73,3 +73,10 @@ -open Octez_injector -open Octez_smart_rollup_node -open Tezos_crypto_dal)) + +(rule + (targets signature.ml) + (action + (write-file + %{targets} + " module Bls = Tezos_crypto.Signature.Bls\n module Ed25519 = Tezos_crypto.Signature.Ed25519\n module P256 = Tezos_crypto.Signature.P256\n module Secp256k1 = Tezos_crypto.Signature.Secp256k1\n include Tezos_crypto.Signature.V1"))) diff --git a/src/proto_021_PsQuebec/lib_sc_rollup_node/layer1_helpers.ml b/src/proto_021_PsQuebec/lib_sc_rollup_node/layer1_helpers.ml index 1f4ef7b394fa..51a92aaf6971 100644 --- a/src/proto_021_PsQuebec/lib_sc_rollup_node/layer1_helpers.ml +++ b/src/proto_021_PsQuebec/lib_sc_rollup_node/layer1_helpers.ml @@ -78,6 +78,7 @@ let get_last_published_commitment ?(allow_unstake = true) let cctxt = new Protocol_client_context.wrap_full (cctxt :> Client_context.full) in + let*? operator = Signature.Of_V_latest.get_public_key_hash operator in let rollup_address = Sc_rollup_proto_types.Address.of_octez rollup_address in let*! res = Plugin.RPC.Sc_rollup.staked_on_commitment @@ -237,11 +238,18 @@ let get_boot_sector block_hash (node_ctxt : _ Node_context.t) = | _ -> missing_boot_sector ()) let find_whitelist cctxt ?block rollup_address = + let open Lwt_result_syntax in let block = match block with Some b -> `Hash (b, 0) | None -> `Head 0 in - Plugin.RPC.Sc_rollup.whitelist - (new Protocol_client_context.wrap_full (cctxt :> Client_context.full)) - (cctxt#chain, block) - rollup_address + let* whitelist = + Plugin.RPC.Sc_rollup.whitelist + (new Protocol_client_context.wrap_full (cctxt :> Client_context.full)) + (cctxt#chain, block) + rollup_address + in + return + @@ Option.map + (List.map Tezos_crypto.Signature.V_latest.Of_V1.public_key_hash) + whitelist let find_last_whitelist_update cctxt rollup_address = let open Lwt_result_syntax in @@ -275,6 +283,7 @@ let get_balance_mutez cctxt ?block pkh = let cctxt = new Protocol_client_context.wrap_full (cctxt :> Client_context.full) in + let*? pkh = Signature.Of_V_latest.get_public_key_hash pkh in let+ balance = Plugin.Alpha_services.Contract.balance cctxt diff --git a/src/proto_021_PsQuebec/lib_sc_rollup_node/pvm_plugin.ml b/src/proto_021_PsQuebec/lib_sc_rollup_node/pvm_plugin.ml index 8d0a4fd39c02..56c66fb72230 100644 --- a/src/proto_021_PsQuebec/lib_sc_rollup_node/pvm_plugin.ml +++ b/src/proto_021_PsQuebec/lib_sc_rollup_node/pvm_plugin.ml @@ -155,7 +155,10 @@ let outbox_message_summary (output : Sc_rollup.output) = let summary = match output with | {message = Whitelist_update pkhs; _} -> - Outbox_message.Whitelist_update pkhs + Outbox_message.Whitelist_update + (Option.map + (List.map Tezos_crypto.Signature.V_latest.Of_V1.public_key_hash) + pkhs) | {message = Atomic_transaction_batch {transactions}; _} -> let transactions = List.map outbox_transaction_summary transactions in Transaction_batch transactions diff --git a/src/proto_021_PsQuebec/lib_sc_rollup_node/refutation_game_helpers.ml b/src/proto_021_PsQuebec/lib_sc_rollup_node/refutation_game_helpers.ml index 53211c554a80..f6c8785ccabc 100644 --- a/src/proto_021_PsQuebec/lib_sc_rollup_node/refutation_game_helpers.ml +++ b/src/proto_021_PsQuebec/lib_sc_rollup_node/refutation_game_helpers.ml @@ -350,6 +350,9 @@ let make_dissection plugin (node_ctxt : _ Node_context.t) state_cache let timeout_reached node_ctxt ~self ~opponent = let open Lwt_result_syntax in let Node_context.{config; cctxt; _} = node_ctxt in + let*? self = Signature.Of_V_latest.get_public_key_hash self in + let*? opponent = Signature.Of_V_latest.get_public_key_hash opponent in + let+ game_result = Plugin.RPC.Sc_rollup.timeout_reached (new Protocol_client_context.wrap_full cctxt) @@ -361,13 +364,16 @@ let timeout_reached node_ctxt ~self ~opponent = let open Sc_rollup.Game in match game_result with | Some (Loser {loser; _}) -> - let is_it_me = Signature.Public_key_hash.(self = loser) in + let is_it_me = Environment.Signature.Public_key_hash.(self = loser) in not is_it_me | _ -> false let timeout node_ctxt ~self ~opponent = let open Lwt_result_syntax in let Node_context.{config; cctxt; _} = node_ctxt in + let*? self = Signature.Of_V_latest.get_public_key_hash self in + let*? opponent = Signature.Of_V_latest.get_public_key_hash opponent in + let+ timeout = Plugin.RPC.Sc_rollup.timeout (new Protocol_client_context.wrap_full cctxt) @@ -381,6 +387,7 @@ let timeout node_ctxt ~self ~opponent = let get_conflicts cctxt rollup staker = let open Lwt_result_syntax in let cctxt = new Protocol_client_context.wrap_full cctxt in + let*? staker = Signature.Of_V_latest.get_public_key_hash staker in let+ conflicts = Plugin.RPC.Sc_rollup.conflicts cctxt (cctxt#chain, `Head 0) rollup staker in @@ -389,6 +396,7 @@ let get_conflicts cctxt rollup staker = let get_ongoing_games cctxt rollup staker = let open Lwt_result_syntax in let cctxt = new Protocol_client_context.wrap_full cctxt in + let*? staker = Signature.Of_V_latest.get_public_key_hash staker in let+ games = Plugin.RPC.Sc_rollup.ongoing_refutation_games cctxt @@ -398,5 +406,7 @@ let get_ongoing_games cctxt rollup staker = in List.map (fun (game, staker1, staker2) -> - (Sc_rollup_proto_types.Game.to_octez game, staker1, staker2)) + ( Sc_rollup_proto_types.Game.to_octez game, + Tezos_crypto.Signature.Of_V1.public_key_hash staker1, + Tezos_crypto.Signature.Of_V1.public_key_hash staker2 )) games diff --git a/src/proto_021_PsQuebec/lib_sc_rollup_node/sc_rollup_injector.ml b/src/proto_021_PsQuebec/lib_sc_rollup_node/sc_rollup_injector.ml index 2cb82691c2dc..d1cbba9872e9 100644 --- a/src/proto_021_PsQuebec/lib_sc_rollup_node/sc_rollup_injector.ml +++ b/src/proto_021_PsQuebec/lib_sc_rollup_node/sc_rollup_injector.ml @@ -47,6 +47,7 @@ let injector_operation_to_manager : let refutation = Sc_rollup_proto_types.Game.refutation_of_octez refutation in + let opponent = Signature.Of_V_latest.get_public_key_hash_exn opponent in Manager (Sc_rollup_refute {rollup; opponent; refutation}) | Timeout {rollup; stakers} -> let rollup = Sc_rollup_proto_types.Address.of_octez rollup in @@ -54,6 +55,7 @@ let injector_operation_to_manager : Manager (Sc_rollup_timeout {rollup; stakers}) | Recover_bond {rollup; staker} -> let rollup = Sc_rollup_proto_types.Address.of_octez rollup in + let staker = Signature.Of_V_latest.get_public_key_hash_exn staker in Manager (Sc_rollup_recover_bond {sc_rollup = rollup; staker}) | Execute_outbox_message {rollup; cemented_commitment; output_proof} -> let rollup = Sc_rollup_proto_types.Address.of_octez rollup in @@ -102,6 +104,7 @@ let injector_operation_of_manager : let refutation = Sc_rollup_proto_types.Game.refutation_to_octez refutation in + let opponent = Tezos_crypto.Signature.Of_V1.public_key_hash opponent in Some (Refute {rollup; opponent; refutation}) | Sc_rollup_timeout {rollup; stakers} -> let rollup = Sc_rollup_proto_types.Address.to_octez rollup in @@ -282,7 +285,7 @@ module Proto_client = struct let dummy_sk_uri = WithExceptions.Result.get_ok ~loc:__LOC__ @@ Tezos_signer_backends.Unencrypted.make_sk - @@ Signature.Secret_key.of_b58check_exn + @@ Tezos_crypto.Signature.Secret_key.of_b58check_exn "edsk3UqeiQWXX7NFEY1wUs6J1t2ez5aQ3hEWdqX5Jr5edZiGLW8nZr" let simulate_operations cctxt ~force ~source ~src_pk ~successor_level @@ -320,6 +323,8 @@ module Proto_client = struct in let safety_guard = Option.map Gas.Arith.integral_of_int_exn safety_guard in let*! simulation_result = + let*? source = Signature.Of_V_latest.get_public_key_hash source in + let*? src_pk = Signature.Of_V_latest.get_public_key src_pk in Injection.inject_manager_operation cctxt ~simulation:true (* Only simulation here *) @@ -496,6 +501,7 @@ module Proto_client = struct let cctxt = new Protocol_client_context.wrap_full (cctxt :> Client_context.full) in + let*? pkh = Signature.Of_V_latest.get_public_key_hash pkh in let+ balance = Plugin.Alpha_services.Contract.balance cctxt diff --git a/src/proto_021_PsQuebec/lib_sc_rollup_node/test/test_octez_conversions.ml b/src/proto_021_PsQuebec/lib_sc_rollup_node/test/test_octez_conversions.ml index 791be285b83d..ba6e0c7c646a 100644 --- a/src/proto_021_PsQuebec/lib_sc_rollup_node/test/test_octez_conversions.ml +++ b/src/proto_021_PsQuebec/lib_sc_rollup_node/test/test_octez_conversions.ml @@ -118,12 +118,13 @@ let random_algo ~rng_state : Signature.algo = | 3 -> Bls | _ -> assert false -let gen_algo = QCheck2.Gen.oneofl [Signature.Ed25519; Secp256k1; P256; Bls] +let gen_algo = + QCheck2.Gen.oneofl [Tezos_crypto.Signature.Ed25519; Secp256k1; P256; Bls] let gen_pkh = let open QCheck2.Gen in let+ algo = gen_algo in - let pkh, _pk, _sk = Signature.generate_key ~algo () in + let pkh, _pk, _sk = Tezos_crypto.Signature.generate_key ~algo () in pkh let gen_stakers = -- GitLab From 48dad13a2cf99d50a05bb30f4acfcc200cd7d75c Mon Sep 17 00:00:00 2001 From: Albin Coquereau Date: Thu, 30 Jan 2025 10:22:00 +0100 Subject: [PATCH 19/20] Next: fix signature versioning compatibility --- src/proto_next/lib_benchmark/dune | 11 ++++++++ .../lib_benchmark/michelson_samplers.ml | 8 +++--- src/proto_next/lib_benchmarks_proto/dune | 7 +++++ .../lib_client/client_proto_context.ml | 4 +-- src/proto_next/lib_client/dune | 11 ++++++++ src/proto_next/lib_client/mockup.ml | 4 +-- src/proto_next/lib_client_commands/dune | 11 ++++++++ .../lib_dal/dal_plugin_registration.ml | 12 ++++++--- src/proto_next/lib_dal/dune | 7 +++++ .../lib_delegate/baking_scheduling.ml | 3 ++- src/proto_next/lib_delegate/dune | 11 ++++++++ src/proto_next/lib_delegate/node_rpc.ml | 6 +++-- .../lib_delegate/test/mockup_simulator/dune | 4 +++ .../test/mockup_simulator/mockup_simulator.ml | 4 +-- .../lib_delegate/test/tenderbrute/lib/dune | 7 +++++ src/proto_next/lib_injector/dune | 11 ++++++++ .../lib_injector/injector_plugin.ml | 6 +++-- src/proto_next/lib_parameters/dune | 7 +++++ src/proto_next/lib_plugin/dune | 7 +++++ src/proto_next/lib_plugin/mempool.ml | 2 +- src/proto_next/lib_protocol/test/helpers/dune | 7 +++++ .../michelson/test_script_typed_ir_size.ml | 3 +-- .../test/pbt/test_script_comparison.ml | 3 +-- .../test/pbt/test_script_roundtrip.ml | 3 +-- .../sc_rollup_proto_types.ml | 12 ++++++--- .../lib_sc_rollup_node/daemon_helpers.ml | 27 ++++++++++++++++--- src/proto_next/lib_sc_rollup_node/dune | 7 +++++ .../lib_sc_rollup_node/layer1_helpers.ml | 17 +++++++++--- .../lib_sc_rollup_node/pvm_plugin.ml | 5 +++- .../refutation_game_helpers.ml | 14 ++++++++-- .../lib_sc_rollup_node/sc_rollup_injector.ml | 8 +++++- .../test/test_octez_conversions.ml | 11 ++++++-- 32 files changed, 217 insertions(+), 43 deletions(-) diff --git a/src/proto_next/lib_benchmark/dune b/src/proto_next/lib_benchmark/dune index a207795e8dcb..f66c68e87797 100644 --- a/src/proto_next/lib_benchmark/dune +++ b/src/proto_next/lib_benchmark/dune @@ -31,3 +31,14 @@ -open Tezos_protocol_next -open Tezos_next_test_helpers) (private_modules kernel rules state_space)) + +(rule + (targets crypto_samplers.mli) + (action + (write-file + %{targets} + "include module type of Tezos_benchmark.Crypto_samplers.V1"))) + +(rule + (targets crypto_samplers.ml) + (action (write-file %{targets} "include Tezos_benchmark.Crypto_samplers.V1"))) diff --git a/src/proto_next/lib_benchmark/michelson_samplers.ml b/src/proto_next/lib_benchmark/michelson_samplers.ml index a872dc08ca63..469df205b720 100644 --- a/src/proto_next/lib_benchmark/michelson_samplers.ml +++ b/src/proto_next/lib_benchmark/michelson_samplers.ml @@ -604,7 +604,9 @@ module Make Data_encoding.Binary.of_string_exn Script_chain_id.encoding string let signature rng_state = - Script_signature.make (Michelson_base.signature rng_state) + Script_signature.make + (Tezos_crypto.Signature.V1.Of_V_latest.get_signature_exn + (Michelson_base.signature rng_state)) let rec value : type a ac. (a, ac) Script_typed_ir.ty -> a sampler = let open Script_typed_ir in @@ -618,8 +620,8 @@ module Make | String_t -> Michelson_base.string | Bytes_t -> Michelson_base.bytes | Mutez_t -> Michelson_base.tez - | Key_hash_t -> Crypto_samplers.pkh - | Key_t -> Crypto_samplers.pk + | Key_hash_t -> fun pkh -> Crypto_samplers.pkh pkh + | Key_t -> fun pk -> Crypto_samplers.pk pk | Timestamp_t -> Michelson_base.timestamp | Bool_t -> Base_samplers.uniform_bool | Address_t -> address diff --git a/src/proto_next/lib_benchmarks_proto/dune b/src/proto_next/lib_benchmarks_proto/dune index 9ae1b83e0636..12f19f8c36cb 100644 --- a/src/proto_next/lib_benchmarks_proto/dune +++ b/src/proto_next/lib_benchmarks_proto/dune @@ -42,3 +42,10 @@ -open Tezos_next_test_helpers -open Tezos_client_next -open Tezos_protocol_plugin_next)) + +(rule + (targets signature.ml) + (action + (write-file + %{targets} + " module Bls = Tezos_crypto.Signature.Bls\n module Ed25519 = Tezos_crypto.Signature.Ed25519\n module P256 = Tezos_crypto.Signature.P256\n module Secp256k1 = Tezos_crypto.Signature.Secp256k1\n include Tezos_crypto.Signature.V1"))) diff --git a/src/proto_next/lib_client/client_proto_context.ml b/src/proto_next/lib_client/client_proto_context.ml index 0d89a4117bc4..bb4c72523518 100644 --- a/src/proto_next/lib_client/client_proto_context.ml +++ b/src/proto_next/lib_client/client_proto_context.ml @@ -833,8 +833,8 @@ let activate_account (cctxt : #full) ~chain ~block ?confirmations ?dry_run Signature.Ed25519.Public_key_hash.pp key.pkh) in - let pk = Signature.Of_V1.public_key pk in - let sk = Signature.Of_V1.secret_key sk in + let pk = Tezos_crypto.Signature.Of_V1.public_key pk in + let sk = Tezos_crypto.Signature.Of_V1.secret_key sk in let*? pk_uri = Tezos_signer_backends.Unencrypted.make_pk pk in let* sk_uri = if encrypted then diff --git a/src/proto_next/lib_client/dune b/src/proto_next/lib_client/dune index 7b12f8fbc7e6..fc5b2b58855f 100644 --- a/src/proto_next/lib_client/dune +++ b/src/proto_next/lib_client/dune @@ -38,3 +38,14 @@ -open Tezos_protocol_plugin_next -open Tezos_protocol_next_parameters -open Tezos_smart_rollup_next)) + +(rule + (targets client_keys.ml) + (action (write-file %{targets} "include Tezos_client_base.Client_keys_v1"))) + +(rule + (targets signature.ml) + (action + (write-file + %{targets} + " module Bls = Tezos_crypto.Signature.Bls\n module Ed25519 = Tezos_crypto.Signature.Ed25519\n module P256 = Tezos_crypto.Signature.P256\n module Secp256k1 = Tezos_crypto.Signature.Secp256k1\n include Tezos_crypto.Signature.V1"))) diff --git a/src/proto_next/lib_client/mockup.ml b/src/proto_next/lib_client/mockup.ml index e6e8d1c951dc..958500a2ecb1 100644 --- a/src/proto_next/lib_client/mockup.ml +++ b/src/proto_next/lib_client/mockup.ml @@ -101,8 +101,8 @@ module Parsed_account = struct let to_bootstrap_account repr = let open Lwt_result_syntax in - let* pk_uri = Tezos_client_base.Client_keys.neuterize repr.sk_uri in - let* public_key = Tezos_client_base.Client_keys.public_key pk_uri in + let* pk_uri = Client_keys.neuterize repr.sk_uri in + let* public_key = Client_keys.public_key pk_uri in let public_key_hash = Signature.Public_key.hash public_key in return Parameters. diff --git a/src/proto_next/lib_client_commands/dune b/src/proto_next/lib_client_commands/dune index 330cba49fc18..515ae070e15b 100644 --- a/src/proto_next/lib_client_commands/dune +++ b/src/proto_next/lib_client_commands/dune @@ -38,6 +38,17 @@ -open Tezos_protocol_plugin_next) (modules (:standard \ alpha_commands_registration))) +(rule + (targets signature.ml) + (action + (write-file + %{targets} + " module Bls = Tezos_crypto.Signature.Bls\n module Ed25519 = Tezos_crypto.Signature.Ed25519\n module P256 = Tezos_crypto.Signature.P256\n module Secp256k1 = Tezos_crypto.Signature.Secp256k1\n include Tezos_crypto.Signature.V1"))) + +(rule + (targets client_keys.ml) + (action (write-file %{targets} "include Tezos_client_base.Client_keys_v1"))) + (library (name tezos_client_next_commands_registration) (public_name octez-protocol-next-libs.client.commands-registration) diff --git a/src/proto_next/lib_dal/dal_plugin_registration.ml b/src/proto_next/lib_dal/dal_plugin_registration.ml index f132674c363a..311cdbaafe27 100644 --- a/src/proto_next/lib_dal/dal_plugin_registration.ml +++ b/src/proto_next/lib_dal/dal_plugin_registration.ml @@ -202,9 +202,13 @@ module Plugin = struct | Receipt (Operation_metadata operation_metadata) -> ( match operation_metadata.contents with | Single_result (Attestation_result result) -> + let delegate = + Tezos_crypto.Signature.Of_V1.public_key_hash + result.delegate + in Some ( tb_slot, - Some result.delegate, + Some delegate, packed_operation, dal_attestation ) | _ -> @@ -226,8 +230,9 @@ module Plugin = struct in List.fold_left (fun acc ({delegate; indexes} : Plugin.RPC.Dal.S.shards_assignment) -> - Signature.Public_key_hash.Map.add delegate indexes acc) - Signature.Public_key_hash.Map.empty + let delegate = Tezos_crypto.Signature.Of_V1.public_key_hash delegate in + Tezos_crypto.Signature.Public_key_hash.Map.add delegate indexes acc) + Tezos_crypto.Signature.Public_key_hash.Map.empty pkh_to_shards let dal_attestation (block : block_info) = @@ -247,6 +252,7 @@ module Plugin = struct let is_delegate ctxt ~pkh = let open Lwt_result_syntax in + let*? pkh = Signature.Of_V_latest.get_public_key_hash pkh in let cpctxt = new Protocol_client_context.wrap_rpc_context ctxt in (* We just want to know whether is a delegate. We call 'context/delegates//deactivated' just because it should be cheaper diff --git a/src/proto_next/lib_dal/dune b/src/proto_next/lib_dal/dune index 10261ebc80e6..04cae27df5eb 100644 --- a/src/proto_next/lib_dal/dune +++ b/src/proto_next/lib_dal/dune @@ -36,3 +36,10 @@ -open Tezos_embedded_protocol_next -open Tezos_layer2_utils_next -open Tezos_protocol_next)) + +(rule + (targets signature.ml) + (action + (write-file + %{targets} + " module Bls = Tezos_crypto.Signature.Bls\n module Ed25519 = Tezos_crypto.Signature.Ed25519\n module P256 = Tezos_crypto.Signature.P256\n module Secp256k1 = Tezos_crypto.Signature.Secp256k1\n include Tezos_crypto.Signature.V1"))) diff --git a/src/proto_next/lib_delegate/baking_scheduling.ml b/src/proto_next/lib_delegate/baking_scheduling.ml index d0da8c2c64db..64fc10c6f096 100644 --- a/src/proto_next/lib_delegate/baking_scheduling.ml +++ b/src/proto_next/lib_delegate/baking_scheduling.ml @@ -995,7 +995,8 @@ let register_dal_profiles cctxt dal_node_rpc_ctxt delegates = let attesters = Tezos_dal_node_services.Operator_profile.attesters operator_profile in - if Signature.Public_key_hash.Set.is_empty attesters then warn () + if Tezos_crypto.Signature.Public_key_hash.Set.is_empty attesters then + warn () else Lwt.return_unit in Node_rpc.register_dal_profiles dal_ctxt delegates diff --git a/src/proto_next/lib_delegate/dune b/src/proto_next/lib_delegate/dune index c0acf2db3e85..5c151d3aa36e 100644 --- a/src/proto_next/lib_delegate/dune +++ b/src/proto_next/lib_delegate/dune @@ -53,6 +53,17 @@ -open Tezos_crypto_dal) (modules (:standard \ Baking_commands Baking_commands_registration))) +(rule + (targets signature.ml) + (action + (write-file + %{targets} + " module Bls = Tezos_crypto.Signature.Bls\n module Ed25519 = Tezos_crypto.Signature.Ed25519\n module P256 = Tezos_crypto.Signature.P256\n module Secp256k1 = Tezos_crypto.Signature.Secp256k1\n include Tezos_crypto.Signature.V1"))) + +(rule + (targets client_keys.ml) + (action (write-file %{targets} "include Tezos_client_base.Client_keys_v1"))) + (library (name tezos_baking_next_commands) (public_name octez-protocol-next-libs.baking-commands) diff --git a/src/proto_next/lib_delegate/node_rpc.ml b/src/proto_next/lib_delegate/node_rpc.ml index ebad32dd2f15..3beb0f29b942 100644 --- a/src/proto_next/lib_delegate/node_rpc.ml +++ b/src/proto_next/lib_delegate/node_rpc.ml @@ -380,7 +380,7 @@ let get_attestable_slots dal_node_rpc_ctxt delegate_id ~attested_level = Tezos_rpc.Context.make_call Tezos_dal_node_services.Services.get_attestable_slots dal_node_rpc_ctxt - (((), pkh), attested_level) + (((), Tezos_crypto.Signature.Of_V1.public_key_hash pkh), attested_level) () () @@ -407,7 +407,9 @@ let register_dal_profiles dal_node_rpc_ctxt delegates = Tezos_dal_node_services.Operator_profile.make ~attesters: (List.map - (fun k -> Consensus_key_id.to_pkh k.Consensus_key.id) + (fun k -> + Tezos_crypto.Signature.Of_V1.public_key_hash + @@ Consensus_key_id.to_pkh k.Consensus_key.id) delegates) () in diff --git a/src/proto_next/lib_delegate/test/mockup_simulator/dune b/src/proto_next/lib_delegate/test/mockup_simulator/dune index c6fb7d4b0756..54585b38f59a 100644 --- a/src/proto_next/lib_delegate/test/mockup_simulator/dune +++ b/src/proto_next/lib_delegate/test/mockup_simulator/dune @@ -31,3 +31,7 @@ -open Tezos_protocol_next_parameters -open Tenderbrute_next -open Tezt_core)) + +(rule + (targets client_keys.ml) + (action (write-file %{targets} "include Tezos_client_base.Client_keys_v1"))) diff --git a/src/proto_next/lib_delegate/test/mockup_simulator/mockup_simulator.ml b/src/proto_next/lib_delegate/test/mockup_simulator/mockup_simulator.ml index 1aade797bce2..eace277cae55 100644 --- a/src/proto_next/lib_delegate/test/mockup_simulator/mockup_simulator.ml +++ b/src/proto_next/lib_delegate/test/mockup_simulator/mockup_simulator.ml @@ -967,7 +967,6 @@ let baker_process ~(delegates : Baking_state.Consensus_key.t list) ~base_dir List.iter_es (fun ({alias; public_key; id; secret_key_uri} : Baking_state.Consensus_key.t) -> - let open Tezos_client_base in let name = alias |> WithExceptions.Option.get ~loc:__LOC__ in let* public_key_uri = Client_keys.neuterize secret_key_uri in let pkh = Baking_state.Consensus_key_id.to_pkh id in @@ -1298,8 +1297,7 @@ let make_baking_delegate let run ?(config = default_config) bakers_spec = let open Lwt_result_syntax in - Tezos_client_base.Client_keys.register_signer - (module Tezos_signer_backends.Unencrypted) ; + Client_keys.register_signer (module Tezos_signer_backends.Unencrypted) ; let total_accounts = List.fold_left (fun acc (n, _) -> acc + n) 0 bakers_spec in diff --git a/src/proto_next/lib_delegate/test/tenderbrute/lib/dune b/src/proto_next/lib_delegate/test/tenderbrute/lib/dune index b87d464d23fe..041a19c241fd 100644 --- a/src/proto_next/lib_delegate/test/tenderbrute/lib/dune +++ b/src/proto_next/lib_delegate/test/tenderbrute/lib/dune @@ -19,3 +19,10 @@ -open Tezos_protocol_next -open Tezos_client_base -open Tezos_client_next)) + +(rule + (targets signature.ml) + (action + (write-file + %{targets} + " module Bls = Tezos_crypto.Signature.Bls\n module Ed25519 = Tezos_crypto.Signature.Ed25519\n module P256 = Tezos_crypto.Signature.P256\n module Secp256k1 = Tezos_crypto.Signature.Secp256k1\n include Tezos_crypto.Signature.V1"))) diff --git a/src/proto_next/lib_injector/dune b/src/proto_next/lib_injector/dune index 53d9f9122eb4..e6393948ef7e 100644 --- a/src/proto_next/lib_injector/dune +++ b/src/proto_next/lib_injector/dune @@ -21,3 +21,14 @@ -open Tezos_client_next -open Tezos_client_base -open Tezos_protocol_plugin_next)) + +(rule + (targets client_keys.ml) + (action (write-file %{targets} "include Tezos_client_base.Client_keys_v1"))) + +(rule + (targets signature.ml) + (action + (write-file + %{targets} + " module Bls = Tezos_crypto.Signature.Bls\n module Ed25519 = Tezos_crypto.Signature.Ed25519\n module P256 = Tezos_crypto.Signature.P256\n module Secp256k1 = Tezos_crypto.Signature.Secp256k1\n include Tezos_crypto.Signature.V1"))) diff --git a/src/proto_next/lib_injector/injector_plugin.ml b/src/proto_next/lib_injector/injector_plugin.ml index f9afe4f07348..1818a39f8187 100644 --- a/src/proto_next/lib_injector/injector_plugin.ml +++ b/src/proto_next/lib_injector/injector_plugin.ml @@ -234,7 +234,7 @@ module Proto_client = struct let dummy_sk_uri = WithExceptions.Result.get_ok ~loc:__LOC__ @@ Tezos_signer_backends.Unencrypted.make_sk - @@ Signature.Secret_key.of_b58check_exn + @@ Tezos_crypto.Signature.Secret_key.of_b58check_exn "edsk3UqeiQWXX7NFEY1wUs6J1t2ez5aQ3hEWdqX5Jr5edZiGLW8nZr" let simulate_operations cctxt ~force ~source ~src_pk ~successor_level @@ -272,6 +272,8 @@ module Proto_client = struct in let safety_guard = Option.map Gas.Arith.integral_of_int_exn safety_guard in let*! simulation_result = + let*? source = Signature.Of_V_latest.get_public_key_hash source in + let*? src_pk = Signature.Of_V_latest.get_public_key src_pk in Injection.inject_manager_operation cctxt ~simulation:true (* Only simulation here *) @@ -446,7 +448,7 @@ module Proto_client = struct let cctxt = new Protocol_client_context.wrap_full (cctxt :> Client_context.full) in - + let*? pkh = Signature.Of_V_latest.get_public_key_hash pkh in let+ balance = Plugin.Alpha_services.Contract.balance cctxt diff --git a/src/proto_next/lib_parameters/dune b/src/proto_next/lib_parameters/dune index f9472bca8955..18865fdeedca 100644 --- a/src/proto_next/lib_parameters/dune +++ b/src/proto_next/lib_parameters/dune @@ -16,6 +16,13 @@ -open Tezos_protocol_next) (modules (:standard \ gen))) +(rule + (targets signature.ml) + (action + (write-file + %{targets} + " module Bls = Tezos_crypto.Signature.Bls\n module Ed25519 = Tezos_crypto.Signature.Ed25519\n module P256 = Tezos_crypto.Signature.P256\n module Secp256k1 = Tezos_crypto.Signature.Secp256k1\n include Tezos_crypto.Signature.V1"))) + (executable (name gen) (libraries diff --git a/src/proto_next/lib_plugin/dune b/src/proto_next/lib_plugin/dune index 427156c97330..d287a0c5dd5e 100644 --- a/src/proto_next/lib_plugin/dune +++ b/src/proto_next/lib_plugin/dune @@ -18,6 +18,13 @@ (documentation (package octez-protocol-next-libs)) +(rule + (targets signature.ml) + (action + (write-file + %{targets} + " module Bls = Tezos_crypto.Signature.Bls\n module Ed25519 = Tezos_crypto.Signature.Ed25519\n module P256 = Tezos_crypto.Signature.P256\n module Secp256k1 = Tezos_crypto.Signature.Secp256k1\n include Tezos_crypto.Signature.V1"))) + (library (name tezos_protocol_plugin_next_registerer) (public_name octez-protocol-next-libs.plugin-registerer) diff --git a/src/proto_next/lib_plugin/mempool.ml b/src/proto_next/lib_plugin/mempool.ml index b1f3e473d77f..ec10e413c976 100644 --- a/src/proto_next/lib_plugin/mempool.ml +++ b/src/proto_next/lib_plugin/mempool.ml @@ -830,7 +830,7 @@ let sources_from_operation ctxt [] committee in - return sources + return @@ map_pkh_env sources | Single (Seed_nonce_revelation _) | Single (Double_preattestation_evidence _) | Single (Double_attestation_evidence _) diff --git a/src/proto_next/lib_protocol/test/helpers/dune b/src/proto_next/lib_protocol/test/helpers/dune index 3b2e19727cf0..14242d70c6f4 100644 --- a/src/proto_next/lib_protocol/test/helpers/dune +++ b/src/proto_next/lib_protocol/test/helpers/dune @@ -37,3 +37,10 @@ -open Tezos_shell_services -open Tezos_crypto_dal -open Tezos_smart_rollup_next)) + +(rule + (targets signature.ml) + (action + (write-file + %{targets} + " module Bls = Tezos_crypto.Signature.Bls\n module Ed25519 = Tezos_crypto.Signature.Ed25519\n module P256 = Tezos_crypto.Signature.P256\n module Secp256k1 = Tezos_crypto.Signature.Secp256k1\n include Tezos_crypto.Signature.V1"))) diff --git a/src/proto_next/lib_protocol/test/integration/michelson/test_script_typed_ir_size.ml b/src/proto_next/lib_protocol/test/integration/michelson/test_script_typed_ir_size.ml index e2c5c62a349b..862bec289990 100644 --- a/src/proto_next/lib_protocol/test/integration/michelson/test_script_typed_ir_size.ml +++ b/src/proto_next/lib_protocol/test/integration/michelson/test_script_typed_ir_size.ml @@ -96,8 +96,7 @@ let dont_show _fmt _ = () let size = {Tezos_benchmark.Base_samplers.min = 4; max = 32} -module Crypto_samplers = -Tezos_benchmark.Crypto_samplers.Make_finite_key_pool (struct +module Crypto_samplers = Crypto_samplers.Make_finite_key_pool (struct let size = 10 let algo = `Default diff --git a/src/proto_next/lib_protocol/test/pbt/test_script_comparison.ml b/src/proto_next/lib_protocol/test/pbt/test_script_comparison.ml index bdd2b93a1c5e..6413c5d30a03 100644 --- a/src/proto_next/lib_protocol/test/pbt/test_script_comparison.ml +++ b/src/proto_next/lib_protocol/test/pbt/test_script_comparison.ml @@ -113,8 +113,7 @@ module Parameters = struct } end -module Crypto_samplers = -Tezos_benchmark.Crypto_samplers.Make_finite_key_pool (struct +module Crypto_samplers = Crypto_samplers.Make_finite_key_pool (struct let size = 1000 let algo = `Default diff --git a/src/proto_next/lib_protocol/test/pbt/test_script_roundtrip.ml b/src/proto_next/lib_protocol/test/pbt/test_script_roundtrip.ml index d6517039b0ed..e28ce44dc362 100644 --- a/src/proto_next/lib_protocol/test/pbt/test_script_roundtrip.ml +++ b/src/proto_next/lib_protocol/test/pbt/test_script_roundtrip.ml @@ -46,8 +46,7 @@ module Parameters = struct } end -module Crypto_samplers = -Tezos_benchmark.Crypto_samplers.Make_finite_key_pool (struct +module Crypto_samplers = Crypto_samplers.Make_finite_key_pool (struct let size = 1000 let algo = `Default diff --git a/src/proto_next/lib_sc_rollup_layer2/sc_rollup_proto_types.ml b/src/proto_next/lib_sc_rollup_layer2/sc_rollup_proto_types.ml index 691e55a6ecc2..bbe78eb63568 100644 --- a/src/proto_next/lib_sc_rollup_layer2/sc_rollup_proto_types.ml +++ b/src/proto_next/lib_sc_rollup_layer2/sc_rollup_proto_types.ml @@ -331,10 +331,14 @@ module Game = struct Move {choice = Sc_rollup.Tick.to_z choice; step = step_to_octez step} let index_of_octez Octez_smart_rollup.Game.{alice; bob} = - Sc_rollup.Game.Index.make alice bob + Sc_rollup.Game.Index.make + (Signature.V1.Of_V_latest.get_public_key_hash_exn alice) + (Signature.V1.Of_V_latest.get_public_key_hash_exn bob) let index_to_octez Sc_rollup.Game.Index.{alice; bob} = - Octez_smart_rollup.Game.make_index alice bob + Octez_smart_rollup.Game.make_index + (Signature.V_latest.Of_V1.public_key_hash alice) + (Signature.V_latest.Of_V1.public_key_hash bob) let player_of_octez : Octez_smart_rollup.Game.player -> player = function | Alice -> Alice @@ -434,7 +438,7 @@ module Game = struct {other; their_commitment; our_commitment; parent_commitment} : conflict = { - other; + other = Signature.V1.Of_V_latest.get_public_key_hash_exn other; their_commitment = Commitment.of_octez their_commitment; our_commitment = Commitment.of_octez our_commitment; parent_commitment; @@ -445,7 +449,7 @@ module Game = struct {other; their_commitment; our_commitment; parent_commitment} : Octez_smart_rollup.Game.conflict = { - other; + other = Signature.Of_V1.public_key_hash other; their_commitment = Commitment.to_octez their_commitment; our_commitment = Commitment.to_octez our_commitment; parent_commitment; diff --git a/src/proto_next/lib_sc_rollup_node/daemon_helpers.ml b/src/proto_next/lib_sc_rollup_node/daemon_helpers.ml index b0c37467a82a..26d70bb463e2 100644 --- a/src/proto_next/lib_sc_rollup_node/daemon_helpers.ml +++ b/src/proto_next/lib_sc_rollup_node/daemon_helpers.ml @@ -112,6 +112,9 @@ let maybe_recover_bond node_ctxt = match operating_pkh with | None -> return_unit | Some (Single operating_pkh) -> ( + let*? operating_pkh = + Signature.Of_V_latest.get_public_key_hash operating_pkh + in let* staked_on_commitment = RPC.Sc_rollup.staked_on_commitment (new Protocol_client_context.wrap_full node_ctxt.cctxt) @@ -213,7 +216,10 @@ let process_included_l1_operation (type kind) ~catching_up | ( Sc_rollup_timeout _, Sc_rollup_timeout_result {game_status = Ended end_status; _} ) -> ( match end_status with - | Loser {loser; reason} when Node_context.is_operator node_ctxt loser -> + | Loser {loser; reason} + when Node_context.is_operator + node_ctxt + (Tezos_crypto.Signature.Of_V1.public_key_hash loser) -> let result = match reason with | Conflict_resolved -> Sc_rollup_node_errors.Conflict_resolved @@ -226,8 +232,13 @@ let process_included_l1_operation (type kind) ~catching_up | Draw -> let stakers = match operation with - | Sc_rollup_refute {opponent; _} -> [source; opponent] - | Sc_rollup_timeout {stakers = {alice; bob}; _} -> [alice; bob] + | Sc_rollup_refute {opponent; _} -> + [source; Tezos_crypto.Signature.Of_V1.public_key_hash opponent] + | Sc_rollup_timeout {stakers = {alice; bob}; _} -> + [ + Tezos_crypto.Signature.Of_V1.public_key_hash alice; + Tezos_crypto.Signature.Of_V1.public_key_hash bob; + ] | _ -> assert false in fail_when @@ -251,7 +262,9 @@ let process_included_l1_operation (type kind) ~catching_up match Node_context.get_operator node_ctxt Operating with | Some (Single operating_pkh) -> fail_when - Signature.Public_key_hash.(operating_pkh = staker) + Tezos_crypto.Signature.Public_key_hash.( + operating_pkh + = Tezos_crypto.Signature.Of_V1.public_key_hash staker) Sc_rollup_node_errors.Exit_bond_recovered_bailout_mode | _ -> return_unit) | ( Sc_rollup_execute_outbox_message {output_proof; _}, @@ -294,6 +307,11 @@ let process_included_l1_operation (type kind) ~catching_up (* No need to check whitelist updates for historical data. *) then return_unit else + let whitelist_update = + List.map + Tezos_crypto.Signature.Of_V1.public_key_hash + whitelist_update + in let*? () = Node_context.check_op_in_whitelist_or_bailout_mode node_ctxt @@ -367,6 +385,7 @@ let process_l1_block_operations ~catching_up node_ctxt (head : Layer1.header) = = let open Lwt_result_syntax in let* () = accu in + let source = Tezos_crypto.Signature.Of_V1.public_key_hash source in process_l1_operation ~catching_up node_ctxt head ~source operation result in let apply_internal (type kind) accu ~source:_ diff --git a/src/proto_next/lib_sc_rollup_node/dune b/src/proto_next/lib_sc_rollup_node/dune index 45368be83da4..ba0ff371184b 100644 --- a/src/proto_next/lib_sc_rollup_node/dune +++ b/src/proto_next/lib_sc_rollup_node/dune @@ -73,3 +73,10 @@ -open Octez_injector -open Octez_smart_rollup_node -open Tezos_crypto_dal)) + +(rule + (targets signature.ml) + (action + (write-file + %{targets} + " module Bls = Tezos_crypto.Signature.Bls\n module Ed25519 = Tezos_crypto.Signature.Ed25519\n module P256 = Tezos_crypto.Signature.P256\n module Secp256k1 = Tezos_crypto.Signature.Secp256k1\n include Tezos_crypto.Signature.V1"))) diff --git a/src/proto_next/lib_sc_rollup_node/layer1_helpers.ml b/src/proto_next/lib_sc_rollup_node/layer1_helpers.ml index 1f4ef7b394fa..51a92aaf6971 100644 --- a/src/proto_next/lib_sc_rollup_node/layer1_helpers.ml +++ b/src/proto_next/lib_sc_rollup_node/layer1_helpers.ml @@ -78,6 +78,7 @@ let get_last_published_commitment ?(allow_unstake = true) let cctxt = new Protocol_client_context.wrap_full (cctxt :> Client_context.full) in + let*? operator = Signature.Of_V_latest.get_public_key_hash operator in let rollup_address = Sc_rollup_proto_types.Address.of_octez rollup_address in let*! res = Plugin.RPC.Sc_rollup.staked_on_commitment @@ -237,11 +238,18 @@ let get_boot_sector block_hash (node_ctxt : _ Node_context.t) = | _ -> missing_boot_sector ()) let find_whitelist cctxt ?block rollup_address = + let open Lwt_result_syntax in let block = match block with Some b -> `Hash (b, 0) | None -> `Head 0 in - Plugin.RPC.Sc_rollup.whitelist - (new Protocol_client_context.wrap_full (cctxt :> Client_context.full)) - (cctxt#chain, block) - rollup_address + let* whitelist = + Plugin.RPC.Sc_rollup.whitelist + (new Protocol_client_context.wrap_full (cctxt :> Client_context.full)) + (cctxt#chain, block) + rollup_address + in + return + @@ Option.map + (List.map Tezos_crypto.Signature.V_latest.Of_V1.public_key_hash) + whitelist let find_last_whitelist_update cctxt rollup_address = let open Lwt_result_syntax in @@ -275,6 +283,7 @@ let get_balance_mutez cctxt ?block pkh = let cctxt = new Protocol_client_context.wrap_full (cctxt :> Client_context.full) in + let*? pkh = Signature.Of_V_latest.get_public_key_hash pkh in let+ balance = Plugin.Alpha_services.Contract.balance cctxt diff --git a/src/proto_next/lib_sc_rollup_node/pvm_plugin.ml b/src/proto_next/lib_sc_rollup_node/pvm_plugin.ml index 8d0a4fd39c02..56c66fb72230 100644 --- a/src/proto_next/lib_sc_rollup_node/pvm_plugin.ml +++ b/src/proto_next/lib_sc_rollup_node/pvm_plugin.ml @@ -155,7 +155,10 @@ let outbox_message_summary (output : Sc_rollup.output) = let summary = match output with | {message = Whitelist_update pkhs; _} -> - Outbox_message.Whitelist_update pkhs + Outbox_message.Whitelist_update + (Option.map + (List.map Tezos_crypto.Signature.V_latest.Of_V1.public_key_hash) + pkhs) | {message = Atomic_transaction_batch {transactions}; _} -> let transactions = List.map outbox_transaction_summary transactions in Transaction_batch transactions diff --git a/src/proto_next/lib_sc_rollup_node/refutation_game_helpers.ml b/src/proto_next/lib_sc_rollup_node/refutation_game_helpers.ml index 60b64f51c477..2ba0bb671b53 100644 --- a/src/proto_next/lib_sc_rollup_node/refutation_game_helpers.ml +++ b/src/proto_next/lib_sc_rollup_node/refutation_game_helpers.ml @@ -357,6 +357,9 @@ let make_dissection plugin (node_ctxt : _ Node_context.t) state_cache let timeout_reached node_ctxt ~self ~opponent = let open Lwt_result_syntax in let Node_context.{config; cctxt; _} = node_ctxt in + let*? self = Signature.Of_V_latest.get_public_key_hash self in + let*? opponent = Signature.Of_V_latest.get_public_key_hash opponent in + let+ game_result = Plugin.RPC.Sc_rollup.timeout_reached (new Protocol_client_context.wrap_full cctxt) @@ -368,13 +371,16 @@ let timeout_reached node_ctxt ~self ~opponent = let open Sc_rollup.Game in match game_result with | Some (Loser {loser; _}) -> - let is_it_me = Signature.Public_key_hash.(self = loser) in + let is_it_me = Environment.Signature.Public_key_hash.(self = loser) in not is_it_me | _ -> false let timeout node_ctxt ~self ~opponent = let open Lwt_result_syntax in let Node_context.{config; cctxt; _} = node_ctxt in + let*? self = Signature.Of_V_latest.get_public_key_hash self in + let*? opponent = Signature.Of_V_latest.get_public_key_hash opponent in + let+ timeout = Plugin.RPC.Sc_rollup.timeout (new Protocol_client_context.wrap_full cctxt) @@ -388,6 +394,7 @@ let timeout node_ctxt ~self ~opponent = let get_conflicts cctxt rollup staker = let open Lwt_result_syntax in let cctxt = new Protocol_client_context.wrap_full cctxt in + let*? staker = Signature.Of_V_latest.get_public_key_hash staker in let+ conflicts = Plugin.RPC.Sc_rollup.conflicts cctxt (cctxt#chain, `Head 0) rollup staker in @@ -396,6 +403,7 @@ let get_conflicts cctxt rollup staker = let get_ongoing_games cctxt rollup staker = let open Lwt_result_syntax in let cctxt = new Protocol_client_context.wrap_full cctxt in + let*? staker = Signature.Of_V_latest.get_public_key_hash staker in let+ games = Plugin.RPC.Sc_rollup.ongoing_refutation_games cctxt @@ -405,5 +413,7 @@ let get_ongoing_games cctxt rollup staker = in List.map (fun (game, staker1, staker2) -> - (Sc_rollup_proto_types.Game.to_octez game, staker1, staker2)) + ( Sc_rollup_proto_types.Game.to_octez game, + Tezos_crypto.Signature.Of_V1.public_key_hash staker1, + Tezos_crypto.Signature.Of_V1.public_key_hash staker2 )) games diff --git a/src/proto_next/lib_sc_rollup_node/sc_rollup_injector.ml b/src/proto_next/lib_sc_rollup_node/sc_rollup_injector.ml index 53337355fb6f..3a393a0517b8 100644 --- a/src/proto_next/lib_sc_rollup_node/sc_rollup_injector.ml +++ b/src/proto_next/lib_sc_rollup_node/sc_rollup_injector.ml @@ -47,6 +47,7 @@ let injector_operation_to_manager : let refutation = Sc_rollup_proto_types.Game.refutation_of_octez refutation in + let opponent = Signature.Of_V_latest.get_public_key_hash_exn opponent in Manager (Sc_rollup_refute {rollup; opponent; refutation}) | Timeout {rollup; stakers} -> let rollup = Sc_rollup_proto_types.Address.of_octez rollup in @@ -54,6 +55,7 @@ let injector_operation_to_manager : Manager (Sc_rollup_timeout {rollup; stakers}) | Recover_bond {rollup; staker} -> let rollup = Sc_rollup_proto_types.Address.of_octez rollup in + let staker = Signature.Of_V_latest.get_public_key_hash_exn staker in Manager (Sc_rollup_recover_bond {sc_rollup = rollup; staker}) | Execute_outbox_message {rollup; cemented_commitment; output_proof} -> let rollup = Sc_rollup_proto_types.Address.of_octez rollup in @@ -102,6 +104,7 @@ let injector_operation_of_manager : let refutation = Sc_rollup_proto_types.Game.refutation_to_octez refutation in + let opponent = Tezos_crypto.Signature.Of_V1.public_key_hash opponent in Some (Refute {rollup; opponent; refutation}) | Sc_rollup_timeout {rollup; stakers} -> let rollup = Sc_rollup_proto_types.Address.to_octez rollup in @@ -284,7 +287,7 @@ module Proto_client = struct let dummy_sk_uri = WithExceptions.Result.get_ok ~loc:__LOC__ @@ Tezos_signer_backends.Unencrypted.make_sk - @@ Signature.Secret_key.of_b58check_exn + @@ Tezos_crypto.Signature.Secret_key.of_b58check_exn "edsk3UqeiQWXX7NFEY1wUs6J1t2ez5aQ3hEWdqX5Jr5edZiGLW8nZr" let simulate_operations cctxt ~force ~source ~src_pk ~successor_level @@ -322,6 +325,8 @@ module Proto_client = struct in let safety_guard = Option.map Gas.Arith.integral_of_int_exn safety_guard in let*! simulation_result = + let*? source = Signature.Of_V_latest.get_public_key_hash source in + let*? src_pk = Signature.Of_V_latest.get_public_key src_pk in Injection.inject_manager_operation cctxt ~simulation:true (* Only simulation here *) @@ -498,6 +503,7 @@ module Proto_client = struct let cctxt = new Protocol_client_context.wrap_full (cctxt :> Client_context.full) in + let*? pkh = Signature.Of_V_latest.get_public_key_hash pkh in let+ balance = Plugin.Alpha_services.Contract.balance cctxt diff --git a/src/proto_next/lib_sc_rollup_node/test/test_octez_conversions.ml b/src/proto_next/lib_sc_rollup_node/test/test_octez_conversions.ml index 9aa7bab4a73b..b29e542a3dc3 100644 --- a/src/proto_next/lib_sc_rollup_node/test/test_octez_conversions.ml +++ b/src/proto_next/lib_sc_rollup_node/test/test_octez_conversions.ml @@ -118,12 +118,13 @@ let random_algo ~rng_state : Signature.algo = | 3 -> Bls | _ -> assert false -let gen_algo = QCheck2.Gen.oneofl [Signature.Ed25519; Secp256k1; P256; Bls] +let gen_algo = + QCheck2.Gen.oneofl [Tezos_crypto.Signature.Ed25519; Secp256k1; P256; Bls] let gen_pkh = let open QCheck2.Gen in let+ algo = gen_algo in - let pkh, _pk, _sk = Signature.generate_key ~algo () in + let pkh, _pk, _sk = Tezos_crypto.Signature.generate_key ~algo () in pkh let gen_stakers = @@ -266,6 +267,9 @@ let gen_slot_history = ( Raw_level.of_int32_exn lvl, List.map (fun (h, publisher, status) -> + let publisher = + Signature.Of_V_latest.get_public_key_hash_exn publisher + in ( Sc_rollup_proto_types.Dal.Slot_header.of_octez ~number_of_slots h, Contract.Implicit publisher, status )) @@ -297,6 +301,9 @@ let gen_slot_history_cache = ( Raw_level.of_int32_exn lvl, List.map (fun (h, publisher, status) -> + let publisher = + Signature.Of_V_latest.get_public_key_hash_exn publisher + in ( Sc_rollup_proto_types.Dal.Slot_header.of_octez ~number_of_slots h, Contract.Implicit publisher, status )) -- GitLab From dbd239038147454a838a96d46b7244f642ba80d3 Mon Sep 17 00:00:00 2001 From: Albin Coquereau Date: Tue, 28 Jan 2025 15:06:11 +0100 Subject: [PATCH 20/20] Alpha: fix signature versioning compatibility --- src/proto_alpha/lib_benchmark/dune | 11 ++++++++ .../lib_benchmark/michelson_samplers.ml | 8 +++--- src/proto_alpha/lib_benchmarks_proto/dune | 7 +++++ .../lib_client/client_proto_context.ml | 4 +-- src/proto_alpha/lib_client/dune | 11 ++++++++ src/proto_alpha/lib_client/mockup.ml | 4 +-- src/proto_alpha/lib_client_commands/dune | 11 ++++++++ .../lib_dal/dal_plugin_registration.ml | 12 ++++++--- src/proto_alpha/lib_dal/dune | 7 +++++ .../lib_delegate/baking_scheduling.ml | 3 ++- src/proto_alpha/lib_delegate/dune | 11 ++++++++ src/proto_alpha/lib_delegate/node_rpc.ml | 6 +++-- .../lib_delegate/test/mockup_simulator/dune | 4 +++ .../test/mockup_simulator/mockup_simulator.ml | 4 +-- .../lib_delegate/test/tenderbrute/lib/dune | 7 +++++ src/proto_alpha/lib_injector/dune | 11 ++++++++ .../lib_injector/injector_plugin.ml | 6 +++-- src/proto_alpha/lib_parameters/dune | 7 +++++ src/proto_alpha/lib_plugin/dune | 7 +++++ src/proto_alpha/lib_plugin/mempool.ml | 13 ++++----- src/proto_alpha/lib_plugin/mempool.mli | 2 +- .../lib_protocol/test/helpers/dune | 7 +++++ .../michelson/test_script_typed_ir_size.ml | 3 +-- .../test/pbt/test_script_comparison.ml | 3 +-- .../test/pbt/test_script_roundtrip.ml | 3 +-- .../sc_rollup_proto_types.ml | 12 ++++++--- .../lib_sc_rollup_node/daemon_helpers.ml | 27 ++++++++++++++++--- src/proto_alpha/lib_sc_rollup_node/dune | 7 +++++ .../lib_sc_rollup_node/layer1_helpers.ml | 17 +++++++++--- .../lib_sc_rollup_node/pvm_plugin.ml | 5 +++- .../refutation_game_helpers.ml | 12 +++++++-- .../lib_sc_rollup_node/sc_rollup_injector.ml | 8 +++++- .../test/test_octez_conversions.ml | 11 ++++++-- 33 files changed, 222 insertions(+), 49 deletions(-) diff --git a/src/proto_alpha/lib_benchmark/dune b/src/proto_alpha/lib_benchmark/dune index b6472e4a2318..64a0fb6e287d 100644 --- a/src/proto_alpha/lib_benchmark/dune +++ b/src/proto_alpha/lib_benchmark/dune @@ -31,3 +31,14 @@ -open Tezos_protocol_alpha -open Tezos_alpha_test_helpers) (private_modules kernel rules state_space)) + +(rule + (targets crypto_samplers.mli) + (action + (write-file + %{targets} + "include module type of Tezos_benchmark.Crypto_samplers.V1"))) + +(rule + (targets crypto_samplers.ml) + (action (write-file %{targets} "include Tezos_benchmark.Crypto_samplers.V1"))) diff --git a/src/proto_alpha/lib_benchmark/michelson_samplers.ml b/src/proto_alpha/lib_benchmark/michelson_samplers.ml index a872dc08ca63..469df205b720 100644 --- a/src/proto_alpha/lib_benchmark/michelson_samplers.ml +++ b/src/proto_alpha/lib_benchmark/michelson_samplers.ml @@ -604,7 +604,9 @@ module Make Data_encoding.Binary.of_string_exn Script_chain_id.encoding string let signature rng_state = - Script_signature.make (Michelson_base.signature rng_state) + Script_signature.make + (Tezos_crypto.Signature.V1.Of_V_latest.get_signature_exn + (Michelson_base.signature rng_state)) let rec value : type a ac. (a, ac) Script_typed_ir.ty -> a sampler = let open Script_typed_ir in @@ -618,8 +620,8 @@ module Make | String_t -> Michelson_base.string | Bytes_t -> Michelson_base.bytes | Mutez_t -> Michelson_base.tez - | Key_hash_t -> Crypto_samplers.pkh - | Key_t -> Crypto_samplers.pk + | Key_hash_t -> fun pkh -> Crypto_samplers.pkh pkh + | Key_t -> fun pk -> Crypto_samplers.pk pk | Timestamp_t -> Michelson_base.timestamp | Bool_t -> Base_samplers.uniform_bool | Address_t -> address diff --git a/src/proto_alpha/lib_benchmarks_proto/dune b/src/proto_alpha/lib_benchmarks_proto/dune index 8abe61305a1b..1f7fd4dd2cd4 100644 --- a/src/proto_alpha/lib_benchmarks_proto/dune +++ b/src/proto_alpha/lib_benchmarks_proto/dune @@ -42,3 +42,10 @@ -open Tezos_alpha_test_helpers -open Tezos_client_alpha -open Tezos_protocol_plugin_alpha)) + +(rule + (targets signature.ml) + (action + (write-file + %{targets} + " module Bls = Tezos_crypto.Signature.Bls\n module Ed25519 = Tezos_crypto.Signature.Ed25519\n module P256 = Tezos_crypto.Signature.P256\n module Secp256k1 = Tezos_crypto.Signature.Secp256k1\n include Tezos_crypto.Signature.V1"))) diff --git a/src/proto_alpha/lib_client/client_proto_context.ml b/src/proto_alpha/lib_client/client_proto_context.ml index 0d89a4117bc4..bb4c72523518 100644 --- a/src/proto_alpha/lib_client/client_proto_context.ml +++ b/src/proto_alpha/lib_client/client_proto_context.ml @@ -833,8 +833,8 @@ let activate_account (cctxt : #full) ~chain ~block ?confirmations ?dry_run Signature.Ed25519.Public_key_hash.pp key.pkh) in - let pk = Signature.Of_V1.public_key pk in - let sk = Signature.Of_V1.secret_key sk in + let pk = Tezos_crypto.Signature.Of_V1.public_key pk in + let sk = Tezos_crypto.Signature.Of_V1.secret_key sk in let*? pk_uri = Tezos_signer_backends.Unencrypted.make_pk pk in let* sk_uri = if encrypted then diff --git a/src/proto_alpha/lib_client/dune b/src/proto_alpha/lib_client/dune index afd1b37eca20..b609baa80d62 100644 --- a/src/proto_alpha/lib_client/dune +++ b/src/proto_alpha/lib_client/dune @@ -38,3 +38,14 @@ -open Tezos_protocol_plugin_alpha -open Tezos_protocol_alpha_parameters -open Tezos_smart_rollup_alpha)) + +(rule + (targets client_keys.ml) + (action (write-file %{targets} "include Tezos_client_base.Client_keys_v1"))) + +(rule + (targets signature.ml) + (action + (write-file + %{targets} + " module Bls = Tezos_crypto.Signature.Bls\n module Ed25519 = Tezos_crypto.Signature.Ed25519\n module P256 = Tezos_crypto.Signature.P256\n module Secp256k1 = Tezos_crypto.Signature.Secp256k1\n include Tezos_crypto.Signature.V1"))) diff --git a/src/proto_alpha/lib_client/mockup.ml b/src/proto_alpha/lib_client/mockup.ml index e6e8d1c951dc..958500a2ecb1 100644 --- a/src/proto_alpha/lib_client/mockup.ml +++ b/src/proto_alpha/lib_client/mockup.ml @@ -101,8 +101,8 @@ module Parsed_account = struct let to_bootstrap_account repr = let open Lwt_result_syntax in - let* pk_uri = Tezos_client_base.Client_keys.neuterize repr.sk_uri in - let* public_key = Tezos_client_base.Client_keys.public_key pk_uri in + let* pk_uri = Client_keys.neuterize repr.sk_uri in + let* public_key = Client_keys.public_key pk_uri in let public_key_hash = Signature.Public_key.hash public_key in return Parameters. diff --git a/src/proto_alpha/lib_client_commands/dune b/src/proto_alpha/lib_client_commands/dune index 726fbd533057..5f6379ca6229 100644 --- a/src/proto_alpha/lib_client_commands/dune +++ b/src/proto_alpha/lib_client_commands/dune @@ -38,6 +38,17 @@ -open Tezos_protocol_plugin_alpha) (modules (:standard \ alpha_commands_registration))) +(rule + (targets signature.ml) + (action + (write-file + %{targets} + " module Bls = Tezos_crypto.Signature.Bls\n module Ed25519 = Tezos_crypto.Signature.Ed25519\n module P256 = Tezos_crypto.Signature.P256\n module Secp256k1 = Tezos_crypto.Signature.Secp256k1\n include Tezos_crypto.Signature.V1"))) + +(rule + (targets client_keys.ml) + (action (write-file %{targets} "include Tezos_client_base.Client_keys_v1"))) + (library (name tezos_client_alpha_commands_registration) (public_name octez-protocol-alpha-libs.client.commands-registration) diff --git a/src/proto_alpha/lib_dal/dal_plugin_registration.ml b/src/proto_alpha/lib_dal/dal_plugin_registration.ml index f132674c363a..311cdbaafe27 100644 --- a/src/proto_alpha/lib_dal/dal_plugin_registration.ml +++ b/src/proto_alpha/lib_dal/dal_plugin_registration.ml @@ -202,9 +202,13 @@ module Plugin = struct | Receipt (Operation_metadata operation_metadata) -> ( match operation_metadata.contents with | Single_result (Attestation_result result) -> + let delegate = + Tezos_crypto.Signature.Of_V1.public_key_hash + result.delegate + in Some ( tb_slot, - Some result.delegate, + Some delegate, packed_operation, dal_attestation ) | _ -> @@ -226,8 +230,9 @@ module Plugin = struct in List.fold_left (fun acc ({delegate; indexes} : Plugin.RPC.Dal.S.shards_assignment) -> - Signature.Public_key_hash.Map.add delegate indexes acc) - Signature.Public_key_hash.Map.empty + let delegate = Tezos_crypto.Signature.Of_V1.public_key_hash delegate in + Tezos_crypto.Signature.Public_key_hash.Map.add delegate indexes acc) + Tezos_crypto.Signature.Public_key_hash.Map.empty pkh_to_shards let dal_attestation (block : block_info) = @@ -247,6 +252,7 @@ module Plugin = struct let is_delegate ctxt ~pkh = let open Lwt_result_syntax in + let*? pkh = Signature.Of_V_latest.get_public_key_hash pkh in let cpctxt = new Protocol_client_context.wrap_rpc_context ctxt in (* We just want to know whether is a delegate. We call 'context/delegates//deactivated' just because it should be cheaper diff --git a/src/proto_alpha/lib_dal/dune b/src/proto_alpha/lib_dal/dune index f261457a9a5e..93d502ab07d8 100644 --- a/src/proto_alpha/lib_dal/dune +++ b/src/proto_alpha/lib_dal/dune @@ -36,3 +36,10 @@ -open Tezos_embedded_protocol_alpha -open Tezos_layer2_utils_alpha -open Tezos_protocol_alpha)) + +(rule + (targets signature.ml) + (action + (write-file + %{targets} + " module Bls = Tezos_crypto.Signature.Bls\n module Ed25519 = Tezos_crypto.Signature.Ed25519\n module P256 = Tezos_crypto.Signature.P256\n module Secp256k1 = Tezos_crypto.Signature.Secp256k1\n include Tezos_crypto.Signature.V1"))) diff --git a/src/proto_alpha/lib_delegate/baking_scheduling.ml b/src/proto_alpha/lib_delegate/baking_scheduling.ml index d0da8c2c64db..64fc10c6f096 100644 --- a/src/proto_alpha/lib_delegate/baking_scheduling.ml +++ b/src/proto_alpha/lib_delegate/baking_scheduling.ml @@ -995,7 +995,8 @@ let register_dal_profiles cctxt dal_node_rpc_ctxt delegates = let attesters = Tezos_dal_node_services.Operator_profile.attesters operator_profile in - if Signature.Public_key_hash.Set.is_empty attesters then warn () + if Tezos_crypto.Signature.Public_key_hash.Set.is_empty attesters then + warn () else Lwt.return_unit in Node_rpc.register_dal_profiles dal_ctxt delegates diff --git a/src/proto_alpha/lib_delegate/dune b/src/proto_alpha/lib_delegate/dune index e9f78e780b1d..1f629c21bad3 100644 --- a/src/proto_alpha/lib_delegate/dune +++ b/src/proto_alpha/lib_delegate/dune @@ -53,6 +53,17 @@ -open Tezos_crypto_dal) (modules (:standard \ Baking_commands Baking_commands_registration))) +(rule + (targets signature.ml) + (action + (write-file + %{targets} + " module Bls = Tezos_crypto.Signature.Bls\n module Ed25519 = Tezos_crypto.Signature.Ed25519\n module P256 = Tezos_crypto.Signature.P256\n module Secp256k1 = Tezos_crypto.Signature.Secp256k1\n include Tezos_crypto.Signature.V1"))) + +(rule + (targets client_keys.ml) + (action (write-file %{targets} "include Tezos_client_base.Client_keys_v1"))) + (library (name tezos_baking_alpha_commands) (public_name octez-protocol-alpha-libs.baking-commands) diff --git a/src/proto_alpha/lib_delegate/node_rpc.ml b/src/proto_alpha/lib_delegate/node_rpc.ml index ebad32dd2f15..3beb0f29b942 100644 --- a/src/proto_alpha/lib_delegate/node_rpc.ml +++ b/src/proto_alpha/lib_delegate/node_rpc.ml @@ -380,7 +380,7 @@ let get_attestable_slots dal_node_rpc_ctxt delegate_id ~attested_level = Tezos_rpc.Context.make_call Tezos_dal_node_services.Services.get_attestable_slots dal_node_rpc_ctxt - (((), pkh), attested_level) + (((), Tezos_crypto.Signature.Of_V1.public_key_hash pkh), attested_level) () () @@ -407,7 +407,9 @@ let register_dal_profiles dal_node_rpc_ctxt delegates = Tezos_dal_node_services.Operator_profile.make ~attesters: (List.map - (fun k -> Consensus_key_id.to_pkh k.Consensus_key.id) + (fun k -> + Tezos_crypto.Signature.Of_V1.public_key_hash + @@ Consensus_key_id.to_pkh k.Consensus_key.id) delegates) () in diff --git a/src/proto_alpha/lib_delegate/test/mockup_simulator/dune b/src/proto_alpha/lib_delegate/test/mockup_simulator/dune index 5000219b5b02..585a8363dd33 100644 --- a/src/proto_alpha/lib_delegate/test/mockup_simulator/dune +++ b/src/proto_alpha/lib_delegate/test/mockup_simulator/dune @@ -31,3 +31,7 @@ -open Tezos_protocol_alpha_parameters -open Tenderbrute_alpha -open Tezt_core)) + +(rule + (targets client_keys.ml) + (action (write-file %{targets} "include Tezos_client_base.Client_keys_v1"))) diff --git a/src/proto_alpha/lib_delegate/test/mockup_simulator/mockup_simulator.ml b/src/proto_alpha/lib_delegate/test/mockup_simulator/mockup_simulator.ml index 1aade797bce2..eace277cae55 100644 --- a/src/proto_alpha/lib_delegate/test/mockup_simulator/mockup_simulator.ml +++ b/src/proto_alpha/lib_delegate/test/mockup_simulator/mockup_simulator.ml @@ -967,7 +967,6 @@ let baker_process ~(delegates : Baking_state.Consensus_key.t list) ~base_dir List.iter_es (fun ({alias; public_key; id; secret_key_uri} : Baking_state.Consensus_key.t) -> - let open Tezos_client_base in let name = alias |> WithExceptions.Option.get ~loc:__LOC__ in let* public_key_uri = Client_keys.neuterize secret_key_uri in let pkh = Baking_state.Consensus_key_id.to_pkh id in @@ -1298,8 +1297,7 @@ let make_baking_delegate let run ?(config = default_config) bakers_spec = let open Lwt_result_syntax in - Tezos_client_base.Client_keys.register_signer - (module Tezos_signer_backends.Unencrypted) ; + Client_keys.register_signer (module Tezos_signer_backends.Unencrypted) ; let total_accounts = List.fold_left (fun acc (n, _) -> acc + n) 0 bakers_spec in diff --git a/src/proto_alpha/lib_delegate/test/tenderbrute/lib/dune b/src/proto_alpha/lib_delegate/test/tenderbrute/lib/dune index 2c5f1970f6f3..1754a62aeb67 100644 --- a/src/proto_alpha/lib_delegate/test/tenderbrute/lib/dune +++ b/src/proto_alpha/lib_delegate/test/tenderbrute/lib/dune @@ -19,3 +19,10 @@ -open Tezos_protocol_alpha -open Tezos_client_base -open Tezos_client_alpha)) + +(rule + (targets signature.ml) + (action + (write-file + %{targets} + " module Bls = Tezos_crypto.Signature.Bls\n module Ed25519 = Tezos_crypto.Signature.Ed25519\n module P256 = Tezos_crypto.Signature.P256\n module Secp256k1 = Tezos_crypto.Signature.Secp256k1\n include Tezos_crypto.Signature.V1"))) diff --git a/src/proto_alpha/lib_injector/dune b/src/proto_alpha/lib_injector/dune index 5d09216ad2ee..b25f426e0187 100644 --- a/src/proto_alpha/lib_injector/dune +++ b/src/proto_alpha/lib_injector/dune @@ -21,3 +21,14 @@ -open Tezos_client_alpha -open Tezos_client_base -open Tezos_protocol_plugin_alpha)) + +(rule + (targets client_keys.ml) + (action (write-file %{targets} "include Tezos_client_base.Client_keys_v1"))) + +(rule + (targets signature.ml) + (action + (write-file + %{targets} + " module Bls = Tezos_crypto.Signature.Bls\n module Ed25519 = Tezos_crypto.Signature.Ed25519\n module P256 = Tezos_crypto.Signature.P256\n module Secp256k1 = Tezos_crypto.Signature.Secp256k1\n include Tezos_crypto.Signature.V1"))) diff --git a/src/proto_alpha/lib_injector/injector_plugin.ml b/src/proto_alpha/lib_injector/injector_plugin.ml index f9afe4f07348..1818a39f8187 100644 --- a/src/proto_alpha/lib_injector/injector_plugin.ml +++ b/src/proto_alpha/lib_injector/injector_plugin.ml @@ -234,7 +234,7 @@ module Proto_client = struct let dummy_sk_uri = WithExceptions.Result.get_ok ~loc:__LOC__ @@ Tezos_signer_backends.Unencrypted.make_sk - @@ Signature.Secret_key.of_b58check_exn + @@ Tezos_crypto.Signature.Secret_key.of_b58check_exn "edsk3UqeiQWXX7NFEY1wUs6J1t2ez5aQ3hEWdqX5Jr5edZiGLW8nZr" let simulate_operations cctxt ~force ~source ~src_pk ~successor_level @@ -272,6 +272,8 @@ module Proto_client = struct in let safety_guard = Option.map Gas.Arith.integral_of_int_exn safety_guard in let*! simulation_result = + let*? source = Signature.Of_V_latest.get_public_key_hash source in + let*? src_pk = Signature.Of_V_latest.get_public_key src_pk in Injection.inject_manager_operation cctxt ~simulation:true (* Only simulation here *) @@ -446,7 +448,7 @@ module Proto_client = struct let cctxt = new Protocol_client_context.wrap_full (cctxt :> Client_context.full) in - + let*? pkh = Signature.Of_V_latest.get_public_key_hash pkh in let+ balance = Plugin.Alpha_services.Contract.balance cctxt diff --git a/src/proto_alpha/lib_parameters/dune b/src/proto_alpha/lib_parameters/dune index c3a03c7f82db..d16d636f906c 100644 --- a/src/proto_alpha/lib_parameters/dune +++ b/src/proto_alpha/lib_parameters/dune @@ -16,6 +16,13 @@ -open Tezos_protocol_alpha) (modules (:standard \ gen))) +(rule + (targets signature.ml) + (action + (write-file + %{targets} + " module Bls = Tezos_crypto.Signature.Bls\n module Ed25519 = Tezos_crypto.Signature.Ed25519\n module P256 = Tezos_crypto.Signature.P256\n module Secp256k1 = Tezos_crypto.Signature.Secp256k1\n include Tezos_crypto.Signature.V1"))) + (executable (name gen) (libraries diff --git a/src/proto_alpha/lib_plugin/dune b/src/proto_alpha/lib_plugin/dune index 5997d8940477..eaba3e58437e 100644 --- a/src/proto_alpha/lib_plugin/dune +++ b/src/proto_alpha/lib_plugin/dune @@ -18,6 +18,13 @@ (documentation (package octez-protocol-alpha-libs)) +(rule + (targets signature.ml) + (action + (write-file + %{targets} + " module Bls = Tezos_crypto.Signature.Bls\n module Ed25519 = Tezos_crypto.Signature.Ed25519\n module P256 = Tezos_crypto.Signature.P256\n module Secp256k1 = Tezos_crypto.Signature.Secp256k1\n include Tezos_crypto.Signature.V1"))) + (library (name tezos_protocol_plugin_alpha_registerer) (public_name octez-protocol-alpha-libs.plugin-registerer) diff --git a/src/proto_alpha/lib_plugin/mempool.ml b/src/proto_alpha/lib_plugin/mempool.ml index 84df0640e5ca..ec10e413c976 100644 --- a/src/proto_alpha/lib_plugin/mempool.ml +++ b/src/proto_alpha/lib_plugin/mempool.ml @@ -804,6 +804,7 @@ let sources_from_operation ctxt ({shell = _; protocol_data = Operation_data {contents; _}} : Main.operation) = let open Lwt_syntax in + let map_pkh_env = List.map Tezos_crypto.Signature.Of_V1.public_key_hash in match contents with | Single (Failing_noop _) -> return_nil | Single (Preattestation consensus_content) @@ -814,7 +815,7 @@ let sources_from_operation ctxt in match slot_owner with | Ok (_ctxt, {delegate; consensus_pkh; consensus_pk = _}) -> - return [delegate; consensus_pkh] + return @@ map_pkh_env [delegate; consensus_pkh] | Error _ -> return_nil) | Single (Attestations_aggregate {consensus_content; committee}) -> let level = Level.from_raw ctxt consensus_content.level in @@ -829,7 +830,7 @@ let sources_from_operation ctxt [] committee in - return sources + return @@ map_pkh_env sources | Single (Seed_nonce_revelation _) | Single (Double_preattestation_evidence _) | Single (Double_attestation_evidence _) @@ -839,10 +840,10 @@ let sources_from_operation ctxt | Single (Vdf_revelation _) -> return_nil | Single (Proposals {source; _}) | Single (Ballot {source; _}) -> - return [source] - | Single (Drain_delegate {delegate; _}) -> return [delegate] - | Single (Manager_operation {source; _}) -> return [source] - | Cons (Manager_operation {source; _}, _) -> return [source] + return @@ map_pkh_env [source] + | Single (Drain_delegate {delegate; _}) -> return @@ map_pkh_env [delegate] + | Single (Manager_operation {source; _}) -> return @@ map_pkh_env [source] + | Cons (Manager_operation {source; _}, _) -> return @@ map_pkh_env [source] module Internal_for_tests = struct let default_config_with_clock_drift clock_drift = diff --git a/src/proto_alpha/lib_plugin/mempool.mli b/src/proto_alpha/lib_plugin/mempool.mli index 2690bb5797d9..80f9f004fcf4 100644 --- a/src/proto_alpha/lib_plugin/mempool.mli +++ b/src/proto_alpha/lib_plugin/mempool.mli @@ -192,7 +192,7 @@ val get_context : val sources_from_operation : ctxt -> Protocol.Alpha_context.packed_operation -> - Signature.public_key_hash list Lwt.t + Tezos_crypto.Signature.public_key_hash list Lwt.t module Internal_for_tests : sig open Protocol.Alpha_context diff --git a/src/proto_alpha/lib_protocol/test/helpers/dune b/src/proto_alpha/lib_protocol/test/helpers/dune index 961f4e986965..9a67c96dbb94 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/dune +++ b/src/proto_alpha/lib_protocol/test/helpers/dune @@ -37,3 +37,10 @@ -open Tezos_shell_services -open Tezos_crypto_dal -open Tezos_smart_rollup_alpha)) + +(rule + (targets signature.ml) + (action + (write-file + %{targets} + " module Bls = Tezos_crypto.Signature.Bls\n module Ed25519 = Tezos_crypto.Signature.Ed25519\n module P256 = Tezos_crypto.Signature.P256\n module Secp256k1 = Tezos_crypto.Signature.Secp256k1\n include Tezos_crypto.Signature.V1"))) diff --git a/src/proto_alpha/lib_protocol/test/integration/michelson/test_script_typed_ir_size.ml b/src/proto_alpha/lib_protocol/test/integration/michelson/test_script_typed_ir_size.ml index e0407beba755..58526c517067 100644 --- a/src/proto_alpha/lib_protocol/test/integration/michelson/test_script_typed_ir_size.ml +++ b/src/proto_alpha/lib_protocol/test/integration/michelson/test_script_typed_ir_size.ml @@ -96,8 +96,7 @@ let dont_show _fmt _ = () let size = {Tezos_benchmark.Base_samplers.min = 4; max = 32} -module Crypto_samplers = -Tezos_benchmark.Crypto_samplers.Make_finite_key_pool (struct +module Crypto_samplers = Crypto_samplers.Make_finite_key_pool (struct let size = 10 let algo = `Default diff --git a/src/proto_alpha/lib_protocol/test/pbt/test_script_comparison.ml b/src/proto_alpha/lib_protocol/test/pbt/test_script_comparison.ml index 0b30815b89fe..cc1e96f6d472 100644 --- a/src/proto_alpha/lib_protocol/test/pbt/test_script_comparison.ml +++ b/src/proto_alpha/lib_protocol/test/pbt/test_script_comparison.ml @@ -113,8 +113,7 @@ module Parameters = struct } end -module Crypto_samplers = -Tezos_benchmark.Crypto_samplers.Make_finite_key_pool (struct +module Crypto_samplers = Crypto_samplers.Make_finite_key_pool (struct let size = 1000 let algo = `Default diff --git a/src/proto_alpha/lib_protocol/test/pbt/test_script_roundtrip.ml b/src/proto_alpha/lib_protocol/test/pbt/test_script_roundtrip.ml index b680d4f73f74..18b2e6484caf 100644 --- a/src/proto_alpha/lib_protocol/test/pbt/test_script_roundtrip.ml +++ b/src/proto_alpha/lib_protocol/test/pbt/test_script_roundtrip.ml @@ -46,8 +46,7 @@ module Parameters = struct } end -module Crypto_samplers = -Tezos_benchmark.Crypto_samplers.Make_finite_key_pool (struct +module Crypto_samplers = Crypto_samplers.Make_finite_key_pool (struct let size = 1000 let algo = `Default diff --git a/src/proto_alpha/lib_sc_rollup_layer2/sc_rollup_proto_types.ml b/src/proto_alpha/lib_sc_rollup_layer2/sc_rollup_proto_types.ml index 691e55a6ecc2..c3ef8ca13b04 100644 --- a/src/proto_alpha/lib_sc_rollup_layer2/sc_rollup_proto_types.ml +++ b/src/proto_alpha/lib_sc_rollup_layer2/sc_rollup_proto_types.ml @@ -331,10 +331,14 @@ module Game = struct Move {choice = Sc_rollup.Tick.to_z choice; step = step_to_octez step} let index_of_octez Octez_smart_rollup.Game.{alice; bob} = - Sc_rollup.Game.Index.make alice bob + Sc_rollup.Game.Index.make + (Signature.V1.Of_V_latest.get_public_key_hash_exn alice) + (Signature.V1.Of_V_latest.get_public_key_hash_exn bob) let index_to_octez Sc_rollup.Game.Index.{alice; bob} = - Octez_smart_rollup.Game.make_index alice bob + Octez_smart_rollup.Game.make_index + (Signature.Of_V1.public_key_hash alice) + (Signature.Of_V1.public_key_hash bob) let player_of_octez : Octez_smart_rollup.Game.player -> player = function | Alice -> Alice @@ -434,7 +438,7 @@ module Game = struct {other; their_commitment; our_commitment; parent_commitment} : conflict = { - other; + other = Signature.V1.Of_V_latest.get_public_key_hash_exn other; their_commitment = Commitment.of_octez their_commitment; our_commitment = Commitment.of_octez our_commitment; parent_commitment; @@ -445,7 +449,7 @@ module Game = struct {other; their_commitment; our_commitment; parent_commitment} : Octez_smart_rollup.Game.conflict = { - other; + other = Signature.Of_V1.public_key_hash other; their_commitment = Commitment.to_octez their_commitment; our_commitment = Commitment.to_octez our_commitment; parent_commitment; diff --git a/src/proto_alpha/lib_sc_rollup_node/daemon_helpers.ml b/src/proto_alpha/lib_sc_rollup_node/daemon_helpers.ml index 3f781d3f663e..fe5dd0cb5c04 100644 --- a/src/proto_alpha/lib_sc_rollup_node/daemon_helpers.ml +++ b/src/proto_alpha/lib_sc_rollup_node/daemon_helpers.ml @@ -112,6 +112,9 @@ let maybe_recover_bond node_ctxt = match operating_pkh with | None -> return_unit | Some (Single operating_pkh) -> ( + let*? operating_pkh = + Signature.Of_V_latest.get_public_key_hash operating_pkh + in let* staked_on_commitment = RPC.Sc_rollup.staked_on_commitment (new Protocol_client_context.wrap_full node_ctxt.cctxt) @@ -213,7 +216,10 @@ let process_included_l1_operation (type kind) ~catching_up | ( Sc_rollup_timeout _, Sc_rollup_timeout_result {game_status = Ended end_status; _} ) -> ( match end_status with - | Loser {loser; reason} when Node_context.is_operator node_ctxt loser -> + | Loser {loser; reason} + when Node_context.is_operator + node_ctxt + (Tezos_crypto.Signature.Of_V1.public_key_hash loser) -> let result = match reason with | Conflict_resolved -> Sc_rollup_node_errors.Conflict_resolved @@ -226,8 +232,13 @@ let process_included_l1_operation (type kind) ~catching_up | Draw -> let stakers = match operation with - | Sc_rollup_refute {opponent; _} -> [source; opponent] - | Sc_rollup_timeout {stakers = {alice; bob}; _} -> [alice; bob] + | Sc_rollup_refute {opponent; _} -> + [source; Tezos_crypto.Signature.Of_V1.public_key_hash opponent] + | Sc_rollup_timeout {stakers = {alice; bob}; _} -> + [ + Tezos_crypto.Signature.Of_V1.public_key_hash alice; + Tezos_crypto.Signature.Of_V1.public_key_hash bob; + ] | _ -> assert false in fail_when @@ -251,7 +262,9 @@ let process_included_l1_operation (type kind) ~catching_up match Node_context.get_operator node_ctxt Operating with | Some (Single operating_pkh) -> fail_when - Signature.Public_key_hash.(operating_pkh = staker) + Tezos_crypto.Signature.Public_key_hash.( + operating_pkh + = Tezos_crypto.Signature.Of_V1.public_key_hash staker) Sc_rollup_node_errors.Exit_bond_recovered_bailout_mode | _ -> return_unit) | ( Sc_rollup_execute_outbox_message {output_proof; _}, @@ -294,6 +307,11 @@ let process_included_l1_operation (type kind) ~catching_up (* No need to check whitelist updates for historical data. *) then return_unit else + let whitelist_update = + List.map + Tezos_crypto.Signature.Of_V1.public_key_hash + whitelist_update + in let*? () = Node_context.check_op_in_whitelist_or_bailout_mode node_ctxt @@ -367,6 +385,7 @@ let process_l1_block_operations ~catching_up node_ctxt (head : Layer1.header) = = let open Lwt_result_syntax in let* () = accu in + let source = Tezos_crypto.Signature.Of_V1.public_key_hash source in process_l1_operation ~catching_up node_ctxt head ~source operation result in let apply_internal (type kind) accu ~source:_ diff --git a/src/proto_alpha/lib_sc_rollup_node/dune b/src/proto_alpha/lib_sc_rollup_node/dune index 45b355b7e371..556fb5d82662 100644 --- a/src/proto_alpha/lib_sc_rollup_node/dune +++ b/src/proto_alpha/lib_sc_rollup_node/dune @@ -73,3 +73,10 @@ -open Octez_injector -open Octez_smart_rollup_node -open Tezos_crypto_dal)) + +(rule + (targets signature.ml) + (action + (write-file + %{targets} + " module Bls = Tezos_crypto.Signature.Bls\n module Ed25519 = Tezos_crypto.Signature.Ed25519\n module P256 = Tezos_crypto.Signature.P256\n module Secp256k1 = Tezos_crypto.Signature.Secp256k1\n include Tezos_crypto.Signature.V1"))) diff --git a/src/proto_alpha/lib_sc_rollup_node/layer1_helpers.ml b/src/proto_alpha/lib_sc_rollup_node/layer1_helpers.ml index 1f4ef7b394fa..3fce20a4ca9d 100644 --- a/src/proto_alpha/lib_sc_rollup_node/layer1_helpers.ml +++ b/src/proto_alpha/lib_sc_rollup_node/layer1_helpers.ml @@ -78,6 +78,7 @@ let get_last_published_commitment ?(allow_unstake = true) let cctxt = new Protocol_client_context.wrap_full (cctxt :> Client_context.full) in + let*? operator = Signature.Of_V_latest.get_public_key_hash operator in let rollup_address = Sc_rollup_proto_types.Address.of_octez rollup_address in let*! res = Plugin.RPC.Sc_rollup.staked_on_commitment @@ -237,11 +238,18 @@ let get_boot_sector block_hash (node_ctxt : _ Node_context.t) = | _ -> missing_boot_sector ()) let find_whitelist cctxt ?block rollup_address = + let open Lwt_result_syntax in let block = match block with Some b -> `Hash (b, 0) | None -> `Head 0 in - Plugin.RPC.Sc_rollup.whitelist - (new Protocol_client_context.wrap_full (cctxt :> Client_context.full)) - (cctxt#chain, block) - rollup_address + let* whitelist = + Plugin.RPC.Sc_rollup.whitelist + (new Protocol_client_context.wrap_full (cctxt :> Client_context.full)) + (cctxt#chain, block) + rollup_address + in + return + @@ Option.map + (List.map Tezos_crypto.Signature.Of_V1.public_key_hash) + whitelist let find_last_whitelist_update cctxt rollup_address = let open Lwt_result_syntax in @@ -275,6 +283,7 @@ let get_balance_mutez cctxt ?block pkh = let cctxt = new Protocol_client_context.wrap_full (cctxt :> Client_context.full) in + let*? pkh = Signature.Of_V_latest.get_public_key_hash pkh in let+ balance = Plugin.Alpha_services.Contract.balance cctxt diff --git a/src/proto_alpha/lib_sc_rollup_node/pvm_plugin.ml b/src/proto_alpha/lib_sc_rollup_node/pvm_plugin.ml index 66be48a5013a..a257b8e54882 100644 --- a/src/proto_alpha/lib_sc_rollup_node/pvm_plugin.ml +++ b/src/proto_alpha/lib_sc_rollup_node/pvm_plugin.ml @@ -155,7 +155,10 @@ let outbox_message_summary (output : Sc_rollup.output) = let summary = match output with | {message = Whitelist_update pkhs; _} -> - Outbox_message.Whitelist_update pkhs + Outbox_message.Whitelist_update + (Option.map + (List.map Tezos_crypto.Signature.Of_V1.public_key_hash) + pkhs) | {message = Atomic_transaction_batch {transactions}; _} -> let transactions = List.map outbox_transaction_summary transactions in Transaction_batch transactions diff --git a/src/proto_alpha/lib_sc_rollup_node/refutation_game_helpers.ml b/src/proto_alpha/lib_sc_rollup_node/refutation_game_helpers.ml index 60b64f51c477..8378d7ace894 100644 --- a/src/proto_alpha/lib_sc_rollup_node/refutation_game_helpers.ml +++ b/src/proto_alpha/lib_sc_rollup_node/refutation_game_helpers.ml @@ -357,6 +357,8 @@ let make_dissection plugin (node_ctxt : _ Node_context.t) state_cache let timeout_reached node_ctxt ~self ~opponent = let open Lwt_result_syntax in let Node_context.{config; cctxt; _} = node_ctxt in + let*? self = Signature.Of_V_latest.get_public_key_hash self in + let*? opponent = Signature.Of_V_latest.get_public_key_hash opponent in let+ game_result = Plugin.RPC.Sc_rollup.timeout_reached (new Protocol_client_context.wrap_full cctxt) @@ -368,13 +370,15 @@ let timeout_reached node_ctxt ~self ~opponent = let open Sc_rollup.Game in match game_result with | Some (Loser {loser; _}) -> - let is_it_me = Signature.Public_key_hash.(self = loser) in + let is_it_me = Environment.Signature.Public_key_hash.(self = loser) in not is_it_me | _ -> false let timeout node_ctxt ~self ~opponent = let open Lwt_result_syntax in let Node_context.{config; cctxt; _} = node_ctxt in + let*? self = Signature.Of_V_latest.get_public_key_hash self in + let*? opponent = Signature.Of_V_latest.get_public_key_hash opponent in let+ timeout = Plugin.RPC.Sc_rollup.timeout (new Protocol_client_context.wrap_full cctxt) @@ -388,6 +392,7 @@ let timeout node_ctxt ~self ~opponent = let get_conflicts cctxt rollup staker = let open Lwt_result_syntax in let cctxt = new Protocol_client_context.wrap_full cctxt in + let*? staker = Signature.Of_V_latest.get_public_key_hash staker in let+ conflicts = Plugin.RPC.Sc_rollup.conflicts cctxt (cctxt#chain, `Head 0) rollup staker in @@ -396,6 +401,7 @@ let get_conflicts cctxt rollup staker = let get_ongoing_games cctxt rollup staker = let open Lwt_result_syntax in let cctxt = new Protocol_client_context.wrap_full cctxt in + let*? staker = Signature.Of_V_latest.get_public_key_hash staker in let+ games = Plugin.RPC.Sc_rollup.ongoing_refutation_games cctxt @@ -405,5 +411,7 @@ let get_ongoing_games cctxt rollup staker = in List.map (fun (game, staker1, staker2) -> - (Sc_rollup_proto_types.Game.to_octez game, staker1, staker2)) + ( Sc_rollup_proto_types.Game.to_octez game, + Tezos_crypto.Signature.Of_V1.public_key_hash staker1, + Tezos_crypto.Signature.Of_V1.public_key_hash staker2 )) games diff --git a/src/proto_alpha/lib_sc_rollup_node/sc_rollup_injector.ml b/src/proto_alpha/lib_sc_rollup_node/sc_rollup_injector.ml index 53337355fb6f..3a393a0517b8 100644 --- a/src/proto_alpha/lib_sc_rollup_node/sc_rollup_injector.ml +++ b/src/proto_alpha/lib_sc_rollup_node/sc_rollup_injector.ml @@ -47,6 +47,7 @@ let injector_operation_to_manager : let refutation = Sc_rollup_proto_types.Game.refutation_of_octez refutation in + let opponent = Signature.Of_V_latest.get_public_key_hash_exn opponent in Manager (Sc_rollup_refute {rollup; opponent; refutation}) | Timeout {rollup; stakers} -> let rollup = Sc_rollup_proto_types.Address.of_octez rollup in @@ -54,6 +55,7 @@ let injector_operation_to_manager : Manager (Sc_rollup_timeout {rollup; stakers}) | Recover_bond {rollup; staker} -> let rollup = Sc_rollup_proto_types.Address.of_octez rollup in + let staker = Signature.Of_V_latest.get_public_key_hash_exn staker in Manager (Sc_rollup_recover_bond {sc_rollup = rollup; staker}) | Execute_outbox_message {rollup; cemented_commitment; output_proof} -> let rollup = Sc_rollup_proto_types.Address.of_octez rollup in @@ -102,6 +104,7 @@ let injector_operation_of_manager : let refutation = Sc_rollup_proto_types.Game.refutation_to_octez refutation in + let opponent = Tezos_crypto.Signature.Of_V1.public_key_hash opponent in Some (Refute {rollup; opponent; refutation}) | Sc_rollup_timeout {rollup; stakers} -> let rollup = Sc_rollup_proto_types.Address.to_octez rollup in @@ -284,7 +287,7 @@ module Proto_client = struct let dummy_sk_uri = WithExceptions.Result.get_ok ~loc:__LOC__ @@ Tezos_signer_backends.Unencrypted.make_sk - @@ Signature.Secret_key.of_b58check_exn + @@ Tezos_crypto.Signature.Secret_key.of_b58check_exn "edsk3UqeiQWXX7NFEY1wUs6J1t2ez5aQ3hEWdqX5Jr5edZiGLW8nZr" let simulate_operations cctxt ~force ~source ~src_pk ~successor_level @@ -322,6 +325,8 @@ module Proto_client = struct in let safety_guard = Option.map Gas.Arith.integral_of_int_exn safety_guard in let*! simulation_result = + let*? source = Signature.Of_V_latest.get_public_key_hash source in + let*? src_pk = Signature.Of_V_latest.get_public_key src_pk in Injection.inject_manager_operation cctxt ~simulation:true (* Only simulation here *) @@ -498,6 +503,7 @@ module Proto_client = struct let cctxt = new Protocol_client_context.wrap_full (cctxt :> Client_context.full) in + let*? pkh = Signature.Of_V_latest.get_public_key_hash pkh in let+ balance = Plugin.Alpha_services.Contract.balance cctxt diff --git a/src/proto_alpha/lib_sc_rollup_node/test/test_octez_conversions.ml b/src/proto_alpha/lib_sc_rollup_node/test/test_octez_conversions.ml index a52144ba564c..8e8b1de49f4d 100644 --- a/src/proto_alpha/lib_sc_rollup_node/test/test_octez_conversions.ml +++ b/src/proto_alpha/lib_sc_rollup_node/test/test_octez_conversions.ml @@ -118,12 +118,13 @@ let random_algo ~rng_state : Signature.algo = | 3 -> Bls | _ -> assert false -let gen_algo = QCheck2.Gen.oneofl [Signature.Ed25519; Secp256k1; P256; Bls] +let gen_algo = + QCheck2.Gen.oneofl [Tezos_crypto.Signature.Ed25519; Secp256k1; P256; Bls] let gen_pkh = let open QCheck2.Gen in let+ algo = gen_algo in - let pkh, _pk, _sk = Signature.generate_key ~algo () in + let pkh, _pk, _sk = Tezos_crypto.Signature.generate_key ~algo () in pkh let gen_stakers = @@ -266,6 +267,9 @@ let gen_slot_history = ( Raw_level.of_int32_exn lvl, List.map (fun (h, publisher, status) -> + let publisher = + Signature.Of_V_latest.get_public_key_hash_exn publisher + in ( Sc_rollup_proto_types.Dal.Slot_header.of_octez ~number_of_slots h, Contract.Implicit publisher, status )) @@ -297,6 +301,9 @@ let gen_slot_history_cache = ( Raw_level.of_int32_exn lvl, List.map (fun (h, publisher, status) -> + let publisher = + Signature.Of_V_latest.get_public_key_hash_exn publisher + in ( Sc_rollup_proto_types.Dal.Slot_header.of_octez ~number_of_slots h, Contract.Implicit publisher, status )) -- GitLab