From 7fef6a7fb13f704390232a6fc898207944d26d51 Mon Sep 17 00:00:00 2001 From: Albin Coquereau Date: Wed, 5 Feb 2025 16:29:23 +0100 Subject: [PATCH 01/10] Crypto/base58: add prefixes for tz5 Bls addresses --- src/lib_crypto/base58.ml | 15 +++++++++++++++ src/lib_crypto/base58.mli | 10 ++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/lib_crypto/base58.ml b/src/lib_crypto/base58.ml index 0c8d96f57008..c6cb36f9c0fc 100644 --- a/src/lib_crypto/base58.ml +++ b/src/lib_crypto/base58.ml @@ -384,6 +384,8 @@ module Prefix = struct let bls12_381_public_key_hash = "\006\161\166" (* tz4(36) *) + let bls12_381_pop_public_key_hash = "\006\161\169" (* tz5(36) *) + let smart_rollup_address = "\006\124\117" (* sr1(36) *) (* 16 *) @@ -451,15 +453,28 @@ module Prefix = struct (* 96 *) let bls12_381_signature = "\040\171\064\207" (* BLsig(142) *) + (* 96 *) + let bls12_381_pop_signature = "\009\054\155\082\153" (* BLpsig(143) *) + (* 48 *) let bls12_381_public_key = "\006\149\135\204" (* BLpk(76) *) + (* 48 *) + let bls12_381_pop_public_key = "\001\125\224\254\251" (* BLppk(77) *) + (* 32 *) let bls12_381_secret_key = "\003\150\192\040" (* BLsk(54) *) + (* 32 *) + let bls12_381_pop_secret_key = "\208\035\037\024" (* BLpsk(55) *) + (* 56 *) let bls12_381_encrypted_secret_key = "\002\005\030\053\025" (* BLesk(88) *) + (* 56 *) + let bls12_381_pop_encrypted_secret_key = + "\117\049\070\179\236" (* BLpesk(89) *) + (* 48 *) let slot_header = "\002\116\180" (* sh(74) *) end diff --git a/src/lib_crypto/base58.mli b/src/lib_crypto/base58.mli index 7e9c3a12d8bf..c3c7f082184f 100644 --- a/src/lib_crypto/base58.mli +++ b/src/lib_crypto/base58.mli @@ -55,6 +55,8 @@ module Prefix : sig val bls12_381_public_key_hash : string + val bls12_381_pop_public_key_hash : string + val smart_rollup_address : string val smart_rollup_commitment : string @@ -95,6 +97,8 @@ module Prefix : sig val bls12_381_encrypted_secret_key : string + val bls12_381_pop_encrypted_secret_key : string + val secp256k1_encrypted_scalar : string val generic_signature : string @@ -117,6 +121,12 @@ module Prefix : sig val bls12_381_secret_key : string + val bls12_381_pop_signature : string + + val bls12_381_pop_public_key : string + + val bls12_381_pop_secret_key : string + val slot_header : string end -- GitLab From ac8fcc106aaea01f384146153820dd052d89cd1f Mon Sep 17 00:00:00 2001 From: Albin Coquereau Date: Fri, 14 Feb 2025 09:36:42 +0100 Subject: [PATCH 02/10] Crypto: add bls pop module (copy of bls_aug) --- src/lib_crypto/bls_pop.ml | 384 +++++++++++++++++++++++++++++++++++++ src/lib_crypto/bls_pop.mli | 46 +++++ 2 files changed, 430 insertions(+) create mode 100644 src/lib_crypto/bls_pop.ml create mode 100644 src/lib_crypto/bls_pop.mli diff --git a/src/lib_crypto/bls_pop.ml b/src/lib_crypto/bls_pop.ml new file mode 100644 index 000000000000..8918679b47eb --- /dev/null +++ b/src/lib_crypto/bls_pop.ml @@ -0,0 +1,384 @@ +(*****************************************************************************) +(* *) +(* Open Source License *) +(* Copyright (c) 2021 Nomadic Labs *) +(* *) +(* Permission is hereby granted, free of charge, to any person obtaining a *) +(* copy of this software and associated documentation files (the "Software"),*) +(* to deal in the Software without restriction, including without limitation *) +(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *) +(* and/or sell copies of the Software, and to permit persons to whom the *) +(* Software is furnished to do so, subject to the following conditions: *) +(* *) +(* The above copyright notice and this permission notice shall be included *) +(* in all copies or substantial portions of the Software. *) +(* *) +(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*) +(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *) +(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *) +(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*) +(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *) +(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *) +(* DEALINGS IN THE SOFTWARE. *) +(* *) +(*****************************************************************************) + +module Public_key_hash = struct + include + Blake2B.Make + (Base58) + (struct + let name = "Bls12_381.Public_key_hash" + + let title = "A Bls12_381 public key hash" + + let b58check_prefix = Base58.Prefix.bls12_381_public_key_hash + + let size = Some 20 + end) + + module Logging = struct + let tag = Tag.def ~doc:title name pp + end +end + +let () = Base58.check_encoded_prefix Public_key_hash.b58check_encoding "tz4" 36 + +module Public_key = struct + open Bls12_381_signature.MinPk + + type t = Bls12_381_signature.MinPk.pk + + let name = "Bls12_381.Public_key" + + let title = "A Bls12_381 public key" + + let to_bytes = pk_to_bytes + + let to_string s = Bytes.to_string (to_bytes s) + + let of_bytes_opt = pk_of_bytes_opt + + let of_string_opt s = of_bytes_opt (Bytes.of_string s) + + let of_bytes_without_validation = of_bytes_opt + + let size _pk = Bls12_381_signature.MinPk.pk_size_in_bytes + + type Base58.data += Data of t + + let b58check_encoding = + Base58.register_encoding + ~prefix:Base58.Prefix.bls12_381_public_key + ~length:(size ()) + ~to_raw:to_string + ~of_raw:of_string_opt + ~wrap:(fun x -> Data x) + + let () = Base58.check_encoded_prefix b58check_encoding "BLpk" 76 + + let hash v = Public_key_hash.hash_bytes [to_bytes v] + + include Compare.Make (struct + type nonrec t = t + + let compare a b = + Bytes.compare + (Bls12_381_signature.MinPk.pk_to_bytes a) + (Bls12_381_signature.MinPk.pk_to_bytes b) + end) + + 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) + + include Helpers.MakeB58 (struct + type nonrec t = t + + let name = name + + let b58check_encoding = b58check_encoding + end) + + include Helpers.MakeEncoder (struct + type nonrec t = t + + let name = name + + let title = title + + let raw_encoding = + let open Data_encoding in + conv to_bytes of_bytes_exn (Fixed.bytes (size ())) + + 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 + +module Secret_key = struct + type t = Bls12_381_signature.sk + + let name = "Bls12_381.Secret_key" + + let title = "A Bls12_381 secret key" + + include Compare.Make (struct + type nonrec t = t + + let compare a b = + let a = Bls12_381_signature.sk_to_bytes a + and b = Bls12_381_signature.sk_to_bytes b in + Bytes.compare a b + end) + + let size = Bls12_381_signature.sk_size_in_bytes + + let to_bytes = Bls12_381_signature.sk_to_bytes + + let to_string s = Bytes.to_string (to_bytes s) + + let of_bytes_opt = Bls12_381_signature.sk_of_bytes_opt + + let of_string_opt s = of_bytes_opt (Bytes.of_string s) + + let to_public_key = Bls12_381_signature.MinPk.derive_pk + + type Base58.data += Data of t + + let b58check_encoding = + Base58.register_encoding + ~prefix:Base58.Prefix.bls12_381_secret_key + ~length:size + ~to_raw:to_string + ~of_raw:of_string_opt + ~wrap:(fun sk -> Data sk) + + let of_b58check_opt s = + match Base58.simple_decode b58check_encoding s with + | Some x -> Some x + | None -> Format.kasprintf Stdlib.failwith "Unexpected data (%s)" name + + 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_monad.error_with + "Failed to read a b58check_encoding data (%s): %S" + name + s + + let to_b58check s = Base58.simple_encode b58check_encoding s + + let to_short_b58check s = + String.sub + (to_b58check s) + 0 + (10 + String.length (Base58.prefix b58check_encoding)) + + let () = Base58.check_encoded_prefix b58check_encoding "BLsk" 54 + + 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) + + include Helpers.MakeEncoder (struct + type nonrec t = t + + let name = name + + let title = title + + let raw_encoding = + let open Data_encoding in + conv to_bytes of_bytes_exn (Fixed.bytes size) + + 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 t = Bls12_381_signature.MinPk.signature + +type watermark = Bytes.t + +let name = "Bls12_381_signature" + +let title = "A Bls12_381 signature" + +let size = Bls12_381_signature.MinPk.signature_size_in_bytes + +let to_bytes = Bls12_381_signature.MinPk.signature_to_bytes + +let of_bytes_opt s = + if Bytes.length s = size then + Bls12_381_signature.MinPk.signature_of_bytes_opt s + else None + +let to_string s = Bytes.to_string (to_bytes s) + +let of_string_opt s = of_bytes_opt (Bytes.of_string s) + +type Base58.data += Data of t + +let b58check_encoding = + Base58.register_encoding + ~prefix:Base58.Prefix.bls12_381_signature + ~length:size + ~to_raw:to_string + ~of_raw:of_string_opt + ~wrap:(fun x -> Data x) + +let () = Base58.check_encoded_prefix b58check_encoding "BLsig" 142 + +include Helpers.MakeB58 (struct + type nonrec t = t + + let name = name + + let b58check_encoding = b58check_encoding +end) + +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) + +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) + +include Helpers.MakeEncoder (struct + type nonrec t = t + + let name = name + + let title = title + + let raw_encoding = + Data_encoding.conv to_bytes of_bytes_exn (Data_encoding.Fixed.bytes size) + + 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) + +let zero = + Bls12_381_signature.MinPk.signature_of_bytes_exn + @@ Bytes.of_string + "\192\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000" + +let sign ?watermark sk msg = + let msg = + match watermark with None -> msg | Some prefix -> Bytes.cat prefix msg + in + Bls12_381_signature.MinPk.Aug.sign sk msg + +let check ?watermark pk signature msg = + let msg = + match watermark with None -> msg | Some prefix -> Bytes.cat prefix msg + in + Bls12_381_signature.MinPk.Aug.verify pk msg signature + +(* [seed] must be at least of 32 bytes or [Bls12_381_signature.generate_sk] will + throw an error. *) +let generate_key ?seed () = + let seed = + match seed with + | Some seed -> seed + | None -> + (* same source of random as other signature, should be safe. Bls needs + bytes of 32 *) + Hacl.Rand.gen 32 + in + let sk = Bls12_381_signature.generate_sk seed in + let pk = Bls12_381_signature.MinPk.derive_pk sk in + let pkh = Public_key.hash pk in + (pkh, pk, sk) + +let deterministic_nonce sk msg = + let key = Secret_key.to_bytes sk in + Hacl.Hash.SHA256.HMAC.digest ~key ~msg + +let deterministic_nonce_hash sk msg = + Blake2B.to_bytes (Blake2B.hash_bytes [deterministic_nonce sk msg]) + +let aggregate_check pk_msg_list signature = + let pk_msg_list = + List.map + (fun (pk, watermark, msg) -> + let msg = + match watermark with + | None -> msg + | Some prefix -> Bytes.cat prefix msg + in + (pk, msg)) + pk_msg_list + in + Bls12_381_signature.MinPk.Aug.aggregate_verify pk_msg_list signature + +let aggregate_signature_opt = Bls12_381_signature.MinPk.aggregate_signature_opt + +module Primitive = struct + include Bls12_381 + + let pairing_check = Bls12_381.Pairing.pairing_check +end diff --git a/src/lib_crypto/bls_pop.mli b/src/lib_crypto/bls_pop.mli new file mode 100644 index 000000000000..2827c7fd263c --- /dev/null +++ b/src/lib_crypto/bls_pop.mli @@ -0,0 +1,46 @@ +(*****************************************************************************) +(* *) +(* Open Source License *) +(* Copyright (c) 2022 Nomadic Labs *) +(* *) +(* Permission is hereby granted, free of charge, to any person obtaining a *) +(* copy of this software and associated documentation files (the "Software"),*) +(* to deal in the Software without restriction, including without limitation *) +(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *) +(* and/or sell copies of the Software, and to permit persons to whom the *) +(* Software is furnished to do so, subject to the following conditions: *) +(* *) +(* The above copyright notice and this permission notice shall be included *) +(* in all copies or substantial portions of the Software. *) +(* *) +(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*) +(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *) +(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *) +(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*) +(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *) +(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *) +(* DEALINGS IN THE SOFTWARE. *) +(* *) +(*****************************************************************************) + +(** Tezos - BLS12-381 cryptography *) + +include + S.AGGREGATE_SIGNATURE + with type Public_key.t = Bls12_381_signature.MinPk.pk + and type Secret_key.t = Bls12_381_signature.sk + and type t = Bls12_381_signature.MinPk.signature + and type watermark = Bytes.t + +include S.RAW_DATA with type t := t + +(** Module to access/expose the primitives of BLS12-381 *) +module Primitive : sig + module Fr : S.PRIME_FIELD with type t = Bls12_381.Fr.t + + module G1 : S.CURVE with type Scalar.t = Fr.t + + module G2 : S.CURVE with type Scalar.t = Fr.t + + val pairing_check : (G1.t * G2.t) list -> bool +end -- GitLab From d42ef985fdfd1bf7367d939b254188dace3e1fbd Mon Sep 17 00:00:00 2001 From: Albin Coquereau Date: Wed, 5 Feb 2025 16:30:33 +0100 Subject: [PATCH 03/10] Crypto: implement bls_pop module --- src/lib_crypto/bls_pop.ml | 34 ++++++++++------------------------ src/lib_crypto/bls_pop.mli | 9 +++------ 2 files changed, 13 insertions(+), 30 deletions(-) diff --git a/src/lib_crypto/bls_pop.ml b/src/lib_crypto/bls_pop.ml index 8918679b47eb..9cd350772f91 100644 --- a/src/lib_crypto/bls_pop.ml +++ b/src/lib_crypto/bls_pop.ml @@ -32,7 +32,7 @@ module Public_key_hash = struct let title = "A Bls12_381 public key hash" - let b58check_prefix = Base58.Prefix.bls12_381_public_key_hash + let b58check_prefix = Base58.Prefix.bls12_381_pop_public_key_hash let size = Some 20 end) @@ -42,7 +42,7 @@ module Public_key_hash = struct end end -let () = Base58.check_encoded_prefix Public_key_hash.b58check_encoding "tz4" 36 +let () = Base58.check_encoded_prefix Public_key_hash.b58check_encoding "tz5" 36 module Public_key = struct open Bls12_381_signature.MinPk @@ -69,13 +69,13 @@ module Public_key = struct let b58check_encoding = Base58.register_encoding - ~prefix:Base58.Prefix.bls12_381_public_key + ~prefix:Base58.Prefix.bls12_381_pop_public_key ~length:(size ()) ~to_raw:to_string ~of_raw:of_string_opt ~wrap:(fun x -> Data x) - let () = Base58.check_encoded_prefix b58check_encoding "BLpk" 76 + let () = Base58.check_encoded_prefix b58check_encoding "BLppk" 77 let hash v = Public_key_hash.hash_bytes [to_bytes v] @@ -165,7 +165,7 @@ module Secret_key = struct let b58check_encoding = Base58.register_encoding - ~prefix:Base58.Prefix.bls12_381_secret_key + ~prefix:Base58.Prefix.bls12_381_pop_secret_key ~length:size ~to_raw:to_string ~of_raw:of_string_opt @@ -198,7 +198,7 @@ module Secret_key = struct 0 (10 + String.length (Base58.prefix b58check_encoding)) - let () = Base58.check_encoded_prefix b58check_encoding "BLsk" 54 + let () = Base58.check_encoded_prefix b58check_encoding "BLpsk" 55 include Helpers.MakeRaw (struct type nonrec t = t @@ -262,13 +262,13 @@ type Base58.data += Data of t let b58check_encoding = Base58.register_encoding - ~prefix:Base58.Prefix.bls12_381_signature + ~prefix:Base58.Prefix.bls12_381_pop_signature ~length:size ~to_raw:to_string ~of_raw:of_string_opt ~wrap:(fun x -> Data x) -let () = Base58.check_encoded_prefix b58check_encoding "BLsig" 142 +let () = Base58.check_encoded_prefix b58check_encoding "BLpsig" 143 include Helpers.MakeB58 (struct type nonrec t = t @@ -330,13 +330,13 @@ let sign ?watermark sk msg = let msg = match watermark with None -> msg | Some prefix -> Bytes.cat prefix msg in - Bls12_381_signature.MinPk.Aug.sign sk msg + Bls12_381_signature.MinPk.Pop.sign sk msg let check ?watermark pk signature msg = let msg = match watermark with None -> msg | Some prefix -> Bytes.cat prefix msg in - Bls12_381_signature.MinPk.Aug.verify pk msg signature + Bls12_381_signature.MinPk.Pop.verify pk msg signature (* [seed] must be at least of 32 bytes or [Bls12_381_signature.generate_sk] will throw an error. *) @@ -361,20 +361,6 @@ let deterministic_nonce sk msg = let deterministic_nonce_hash sk msg = Blake2B.to_bytes (Blake2B.hash_bytes [deterministic_nonce sk msg]) -let aggregate_check pk_msg_list signature = - let pk_msg_list = - List.map - (fun (pk, watermark, msg) -> - let msg = - match watermark with - | None -> msg - | Some prefix -> Bytes.cat prefix msg - in - (pk, msg)) - pk_msg_list - in - Bls12_381_signature.MinPk.Aug.aggregate_verify pk_msg_list signature - let aggregate_signature_opt = Bls12_381_signature.MinPk.aggregate_signature_opt module Primitive = struct diff --git a/src/lib_crypto/bls_pop.mli b/src/lib_crypto/bls_pop.mli index 2827c7fd263c..2b652d9e0c98 100644 --- a/src/lib_crypto/bls_pop.mli +++ b/src/lib_crypto/bls_pop.mli @@ -25,12 +25,7 @@ (** Tezos - BLS12-381 cryptography *) -include - S.AGGREGATE_SIGNATURE - with type Public_key.t = Bls12_381_signature.MinPk.pk - and type Secret_key.t = Bls12_381_signature.sk - and type t = Bls12_381_signature.MinPk.signature - and type watermark = Bytes.t +include S.SIGNATURE with type watermark = Bytes.t include S.RAW_DATA with type t := t @@ -44,3 +39,5 @@ module Primitive : sig val pairing_check : (G1.t * G2.t) list -> bool end + +val aggregate_signature_opt : t list -> t option -- GitLab From b863a8955ca919d65ebd3fa5c05adf06795da76e Mon Sep 17 00:00:00 2001 From: Albin Coquereau Date: Wed, 5 Feb 2025 16:32:23 +0100 Subject: [PATCH 04/10] Crypto: add bls_pop variant in signature module --- .../yes_wallet/test/bench_signature_perf.ml | 11 ++- .../EVM node- list events regression.out | 8 +- src/lib_client_base/client_keys.ml | 12 ++- .../client_keys_commands.ml | 10 +- src/lib_crypto/signature.ml | 9 +- src/lib_crypto/signature_v2.ml | 99 ++++++++++++++++--- src/lib_crypto/signature_v2.mli | 10 +- src/lib_crypto/tezos_crypto.ml | 1 + .../encoding_benchmarks.ml | 1 + src/lib_signer_backends/encrypted.ml | 19 +++- .../lib_client/injection.ml | 4 + .../dal.ml/DAL Node- P2P message encoding.out | 12 +++ 12 files changed, 168 insertions(+), 28 deletions(-) diff --git a/devtools/yes_wallet/test/bench_signature_perf.ml b/devtools/yes_wallet/test/bench_signature_perf.ml index 1af12fa4ea5c..fcf57fb19502 100644 --- a/devtools/yes_wallet/test/bench_signature_perf.ml +++ b/devtools/yes_wallet/test/bench_signature_perf.ml @@ -33,22 +33,26 @@ let keys = let keys_e = Tezos_crypto.Signature.generate_key ~algo:Ed25519 () in let keys_s = Tezos_crypto.Signature.generate_key ~algo:Secp256k1 () in let keys_b = Tezos_crypto.Signature.generate_key ~algo:Bls_aug () in + let keys_bp = Tezos_crypto.Signature.generate_key ~algo:Bls_pop () in function | Tezos_crypto.Signature.P256 -> keys_p | Ed25519 -> keys_e | Secp256k1 -> keys_s | Bls_aug -> keys_b + | Bls_pop -> keys_bp let wrong_keys = let keys_p = Tezos_crypto.Signature.generate_key ~algo:P256 () in let keys_e = Tezos_crypto.Signature.generate_key ~algo:Ed25519 () in let keys_s = Tezos_crypto.Signature.generate_key ~algo:Secp256k1 () in - let keys_b = Tezos_crypto.Signature.generate_key ~algo:Bls_aug () in + let keys_bls_aug = Tezos_crypto.Signature.generate_key ~algo:Bls_aug () in + let keys_bls_pop = Tezos_crypto.Signature.generate_key ~algo:Bls_pop () in function | Tezos_crypto.Signature.P256 -> keys_p | Ed25519 -> keys_e | Secp256k1 -> keys_s - | Bls_aug -> keys_b + | Bls_aug -> keys_bls_aug + | Bls_pop -> keys_bls_pop let wrong_pk algo = let _, pk, _ = wrong_keys algo in @@ -106,7 +110,8 @@ let str_of_algo = function | Tezos_crypto.Signature.Ed25519 -> "Ed25519" | Tezos_crypto.Signature.Secp256k1 -> "Secp256k1" | Tezos_crypto.Signature.P256 -> "P256" - | Tezos_crypto.Signature.Bls_aug -> "Bls" + | Tezos_crypto.Signature.Bls_aug -> "Bls_aug" + | Tezos_crypto.Signature.Bls_pop -> "Bls_pop" let time ~yes_crypto ~algo size datas = Format.eprintf "generating signatures...@?" ; diff --git a/etherlink/tezt/tests/expected/evm_rollup.ml/EVM node- list events regression.out b/etherlink/tezt/tests/expected/evm_rollup.ml/EVM node- list events regression.out index 5d8fbfa35c57..e42d37aa8ecd 100644 --- a/etherlink/tezt/tests/expected/evm_rollup.ml/EVM node- list events regression.out +++ b/etherlink/tezt/tests/expected/evm_rollup.ml/EVM node- list events regression.out @@ -889,7 +889,7 @@ blueprints_publisher_request_failed: "number": $unistring, "nb_chunks": integer ∈ [-2^30, 2^30], "chunk_index": integer ∈ [-2^30, 2^30], - "signature": $Signature.V1 } ... ], + "signature": $Signature.V2 } ... ], "inbox_payload": [ $unistring ... ] } || [ $unistring ... ] /* Inbox */ } @@ -897,7 +897,7 @@ blueprints_publisher_request_failed: "request": "new_l2_head", "rollup_head": integer ∈ [-2^31-1, 2^31] }, "errors": any } } - $Signature.V1: + $Signature.V2: /* A Ed25519, Secp256k1, P256 or BLS signature (Base58Check-encoded) */ $unistring $positive_bignum: @@ -2120,7 +2120,7 @@ blueprints_publisher_request_failed: "number": $unistring, "nb_chunks": integer ∈ [-2^30, 2^30], "chunk_index": integer ∈ [-2^30, 2^30], - "signature": $Signature.V1 } ... ], + "signature": $Signature.V2 } ... ], "inbox_payload": [ $unistring ... ] } || [ $unistring ... ] /* Inbox */ } @@ -2128,7 +2128,7 @@ blueprints_publisher_request_failed: "request": "new_l2_head", "rollup_head": integer ∈ [-2^31-1, 2^31] }, "errors": any } } - $Signature.V1: + $Signature.V2: /* A Ed25519, Secp256k1, P256 or BLS signature (Base58Check-encoded) */ $unistring $positive_bignum: diff --git a/src/lib_client_base/client_keys.ml b/src/lib_client_base/client_keys.ml index fd4412e80c00..e3a2e2b4d5aa 100644 --- a/src/lib_client_base/client_keys.ml +++ b/src/lib_client_base/client_keys.ml @@ -877,7 +877,7 @@ module V0 = Make (struct Tezos_crypto.Signature.Public_key_hash.t -> Public_key_hash.t tzresult = let open Result_syntax in function - | Bls_aug _ -> + | Bls_aug _ | Bls_pop _ -> tzfail (Exn (Failure "BLS public key hash not supported by V0")) | Ed25519 k -> return (Ed25519 k : Public_key_hash.t) | Secp256k1 k -> return (Secp256k1 k : Public_key_hash.t) @@ -888,6 +888,8 @@ module V0 = Make (struct let open Result_syntax in function | Bls_aug _ -> tzfail (Exn (Failure "BLS public key not supported by V0")) + | Bls_pop _ -> + tzfail (Exn (Failure "BLS POP public key not supported by V0")) | Ed25519 k -> return (Ed25519 k : Public_key.t) | Secp256k1 k -> return (Secp256k1 k : Public_key.t) | P256 k -> return (P256 k : Public_key.t) @@ -896,6 +898,8 @@ module V0 = Make (struct let open Result_syntax in function | Bls_aug _ -> tzfail (Exn (Failure "BLS signature not supported by V0")) + | Bls_pop _ -> + tzfail (Exn (Failure "BLS POP signature not supported by V0")) | Ed25519 k -> return (Ed25519 k : t) | Secp256k1 k -> return (Secp256k1 k : t) | P256 k -> return (P256 k : t) @@ -913,6 +917,8 @@ module V1 = Make (struct Tezos_crypto.Signature.Public_key_hash.t -> Public_key_hash.t tzresult = let open Result_syntax in function + | Bls_pop _ -> + tzfail (Exn (Failure "BLS POP public key hash not supported by V1")) | Bls_aug 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) @@ -923,6 +929,8 @@ module V1 = Make (struct let open Result_syntax in function | Bls_aug k -> return (Bls k : Public_key.t) + | Bls_pop _ -> + tzfail (Exn (Failure "BLS POP public key not supported by V1")) | Ed25519 k -> return (Ed25519 k : Public_key.t) | Secp256k1 k -> return (Secp256k1 k : Public_key.t) | P256 k -> return (P256 k : Public_key.t) @@ -931,6 +939,8 @@ module V1 = Make (struct let open Result_syntax in function | Bls_aug k -> return (Bls k : t) + | Bls_pop _ -> + tzfail (Exn (Failure "BLS POP signature not supported by V1")) | Ed25519 k -> return (Ed25519 k : t) | Secp256k1 k -> return (Secp256k1 k : t) | P256 k -> return (P256 k : t) diff --git a/src/lib_client_commands/client_keys_commands.ml b/src/lib_client_commands/client_keys_commands.ml index e40f59fac8ca..7efc91ad924d 100644 --- a/src/lib_client_commands/client_keys_commands.ml +++ b/src/lib_client_commands/client_keys_commands.ml @@ -34,17 +34,19 @@ let group = let algo_param () = let open Lwt_result_syntax in Tezos_clic.parameter - ~autocomplete:(fun _ -> return ["ed25519"; "secp256k1"; "p256"; "bls"]) + ~autocomplete:(fun _ -> + return ["ed25519"; "secp256k1"; "p256"; "bls"; "bls_aug"; "bls_pop"]) (fun _ name -> match name with | "ed25519" -> return Signature.Ed25519 | "secp256k1" -> return Signature.Secp256k1 | "p256" -> return Signature.P256 - | "bls" -> return Signature.Bls_aug + | "bls_aug" | "bls" -> return Signature.Bls_aug + | "bls_pop" -> return Signature.Bls_pop | name -> failwith "Unknown signature algorithm (%s). Available: 'ed25519', \ - 'secp256k1','p256' or 'bls'" + 'secp256k1','p256', 'bls', 'bls_aug' or 'bls_pop'" name) let sig_algo_arg = @@ -52,7 +54,7 @@ let sig_algo_arg = ~doc:"use custom signature algorithm" ~long:"sig" ~short:'s' - ~placeholder:"ed25519|secp256k1|p256|bls" + ~placeholder:"ed25519|secp256k1|p256|bls|bls_aug|bls_pop" ~default:"ed25519" (algo_param ()) diff --git a/src/lib_crypto/signature.ml b/src/lib_crypto/signature.ml index f6644977c3ca..2b4c0a286035 100644 --- a/src/lib_crypto/signature.ml +++ b/src/lib_crypto/signature.ml @@ -82,19 +82,21 @@ module V0 = struct | V_latest.Ed25519 k -> Some (Ed25519 k) | V_latest.Secp256k1 k -> Some (Secp256k1 k) | V_latest.P256 k -> Some (P256 k) - | V_latest.Bls_aug _ -> None + | V_latest.Bls_aug _ | V_latest.Bls_pop _ -> None 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_aug _ -> None + | V_latest.Bls_pop _ -> None 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_aug _ -> None + | V_latest.Bls_pop _ -> None let signature : V_latest.t -> t option = function | V_latest.Ed25519 k -> Some (Ed25519 k) @@ -102,6 +104,7 @@ module V0 = struct | V_latest.P256 k -> Some (P256 k) | V_latest.Unknown k -> Some (Unknown k) | V_latest.Bls_aug _ -> None + | V_latest.Bls_pop _ -> None let get_public_key pk = match public_key pk with @@ -165,18 +168,21 @@ module V1 = struct | V_latest.Secp256k1 k -> Some (Secp256k1 k) | V_latest.P256 k -> Some (P256 k) | V_latest.Bls_aug k -> Some (Bls k) + | V_latest.Bls_pop _ -> None 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_aug k -> Some (Bls k) + | V_latest.Bls_pop _ -> None 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_aug k -> Some (Bls k) + | V_latest.Bls_pop _ -> None let signature : V_latest.t -> t option = function | V_latest.Ed25519 k -> Some (Ed25519 k) @@ -184,6 +190,7 @@ module V1 = struct | V_latest.P256 k -> Some (P256 k) | V_latest.Unknown k -> Some (Unknown k) | V_latest.Bls_aug k -> Some (Bls k) + | V_latest.Bls_pop _ -> None let get_public_key pk = match public_key pk with diff --git a/src/lib_crypto/signature_v2.ml b/src/lib_crypto/signature_v2.ml index 4b7d8cda8101..1ad425c5667d 100644 --- a/src/lib_crypto/signature_v2.ml +++ b/src/lib_crypto/signature_v2.ml @@ -12,18 +12,21 @@ type public_key_hash = | Secp256k1 of Secp256k1.Public_key_hash.t | P256 of P256.Public_key_hash.t | Bls_aug of Bls_aug.Public_key_hash.t + | Bls_pop of Bls_pop.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_aug of Bls_aug.Public_key.t + | Bls_pop of Bls_pop.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_aug of Bls_aug.Secret_key.t + | Bls_pop of Bls_pop.Secret_key.t type watermark = Signature_v0.watermark = | Block_header of Chain_id.t @@ -37,6 +40,7 @@ module Public_key_hash = struct | Secp256k1 of Secp256k1.Public_key_hash.t | P256 of P256.Public_key_hash.t | Bls_aug of Bls_aug.Public_key_hash.t + | Bls_pop of Bls_pop.Public_key_hash.t let name = "Signature.Public_key_hash" @@ -82,6 +86,12 @@ module Public_key_hash = struct Bls_aug.Public_key_hash.encoding (function Bls_aug x -> Some x | _ -> None) (function x -> Bls_aug x); + case + (Tag 4) + ~title:"Bls_pop" + Bls_pop.Public_key_hash.encoding + (function Bls_pop x -> Some x | _ -> None) + (function x -> Bls_pop x); ] let to_bytes s = Data_encoding.Binary.to_bytes_exn raw_encoding s @@ -114,6 +124,7 @@ module Public_key_hash = struct | Some (Secp256k1.Public_key_hash.Data pkh) -> Some (Secp256k1 pkh) | Some (P256.Public_key_hash.Data pkh) -> Some (P256 pkh) | Some (Bls_aug.Public_key_hash.Data pkh) -> Some (Bls_aug pkh) + | Some (Bls_pop.Public_key_hash.Data pkh) -> Some (Bls_pop pkh) | _ -> None let of_b58check_exn s = @@ -132,12 +143,14 @@ module Public_key_hash = struct | Secp256k1 pkh -> Secp256k1.Public_key_hash.to_b58check pkh | P256 pkh -> P256.Public_key_hash.to_b58check pkh | Bls_aug pkh -> Bls_aug.Public_key_hash.to_b58check pkh + | Bls_pop pkh -> Bls_pop.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_aug pkh -> Bls_aug.Public_key_hash.to_short_b58check pkh + | Bls_pop pkh -> Bls_pop.Public_key_hash.to_short_b58check pkh let to_path key l = match key with @@ -145,6 +158,7 @@ module Public_key_hash = struct | Secp256k1 h -> "secp256k1" :: Secp256k1.Public_key_hash.to_path h l | P256 h -> "p256" :: P256.Public_key_hash.to_path h l | Bls_aug h -> "bls" :: Bls_aug.Public_key_hash.to_path h l + | Bls_pop h -> "bls_pop" :: Bls_pop.Public_key_hash.to_path h l let of_path = function | "ed25519" :: q -> ( @@ -163,6 +177,10 @@ module Public_key_hash = struct match Bls_aug.Public_key_hash.of_path q with | Some pkh -> Some (Bls_aug pkh) | None -> None) + | "bls_pop" :: q -> ( + match Bls_pop.Public_key_hash.of_path q with + | Some pkh -> Some (Bls_pop pkh) + | None -> None) | _ -> assert false (* FIXME classification des erreurs *) @@ -172,6 +190,7 @@ module Public_key_hash = struct | "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_aug (Bls_aug.Public_key_hash.of_path_exn q) + | "bls_pop" :: q -> Bls_pop (Bls_pop.Public_key_hash.of_path_exn q) | _ -> assert false (* FIXME classification des erreurs *) @@ -180,10 +199,12 @@ module Public_key_hash = struct 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_aug.Public_key_hash.path_length in + and l4 = Bls_aug.Public_key_hash.path_length + and l5 = Bls_pop.Public_key_hash.path_length in assert (Compare.Int.(l1 = l2)) ; assert (Compare.Int.(l1 = l3)) ; assert (Compare.Int.(l1 = l4)) ; + assert (Compare.Int.(l1 = l5)) ; 1 + l1 let prefix_path _ = assert false (* unused *) @@ -201,6 +222,7 @@ module Public_key_hash = struct | Secp256k1 x, Secp256k1 y -> Secp256k1.Public_key_hash.compare x y | P256 x, P256 y -> P256.Public_key_hash.compare x y | Bls_aug x, Bls_aug y -> Bls_aug.Public_key_hash.compare x y + | Bls_pop x, Bls_pop y -> Bls_pop.Public_key_hash.compare x y | _ -> Stdlib.compare a b end) @@ -255,6 +277,7 @@ module Public_key = struct | Secp256k1 of Secp256k1.Public_key.t | P256 of P256.Public_key.t | Bls_aug of Bls_aug.Public_key.t + | Bls_pop of Bls_pop.Public_key.t let name = "Signature.Public_key" @@ -266,6 +289,7 @@ module Public_key = struct | Secp256k1 pk -> Public_key_hash.Secp256k1 (Secp256k1.Public_key.hash pk) | P256 pk -> Public_key_hash.P256 (P256.Public_key.hash pk) | Bls_aug pk -> Public_key_hash.Bls_aug (Bls_aug.Public_key.hash pk) + | Bls_pop pk -> Public_key_hash.Bls_pop (Bls_pop.Public_key.hash pk) include Compare.Make (struct type nonrec t = t @@ -276,9 +300,12 @@ module Public_key = struct | Secp256k1 x, Secp256k1 y -> Secp256k1.Public_key.compare x y | P256 x, P256 y -> P256.Public_key.compare x y | Bls_aug x, Bls_aug y -> Bls_aug.Public_key.compare x y - | Ed25519 _, (Secp256k1 _ | P256 _ | Bls_aug _) -> -1 - | Secp256k1 _, (P256 _ | Bls_aug _) -> -1 - | P256 _, Bls_aug _ -> -1 + | Bls_pop x, Bls_pop y -> Bls_pop.Public_key.compare x y + | Ed25519 _, (Secp256k1 _ | P256 _ | Bls_aug _ | Bls_pop _) -> -1 + | Secp256k1 _, (P256 _ | Bls_aug _ | Bls_pop _) -> -1 + | P256 _, (Bls_aug _ | Bls_pop _) -> -1 + | Bls_aug _, Bls_pop _ -> -1 + | Bls_pop _, (Bls_aug _ | P256 _ | Secp256k1 _ | Ed25519 _) -> 1 | Bls_aug _, (P256 _ | Secp256k1 _ | Ed25519 _) -> 1 | P256 _, (Secp256k1 _ | Ed25519 _) -> 1 | Secp256k1 _, Ed25519 _ -> 1 @@ -319,12 +346,14 @@ module Public_key = struct | Secp256k1 pk -> Secp256k1.Public_key.to_b58check pk | P256 pk -> P256.Public_key.to_b58check pk | Bls_aug pk -> Bls_aug.Public_key.to_b58check pk + | Bls_pop pk -> Bls_pop.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_aug pk -> Bls_aug.Public_key.to_short_b58check pk + | Bls_pop pk -> Bls_pop.Public_key.to_short_b58check pk let of_bytes_without_validation b = let tag = Bytes.(get_int8 b 0) in @@ -407,6 +436,7 @@ module Secret_key = struct | Secp256k1 of Secp256k1.Secret_key.t | P256 of P256.Secret_key.t | Bls_aug of Bls_aug.Secret_key.t + | Bls_pop of Bls_pop.Secret_key.t let name = "Signature.Secret_key" @@ -418,6 +448,7 @@ module Secret_key = struct Public_key.Secp256k1 (Secp256k1.Secret_key.to_public_key sk) | P256 sk -> Public_key.P256 (P256.Secret_key.to_public_key sk) | Bls_aug sk -> Public_key.Bls_aug (Bls_aug.Secret_key.to_public_key sk) + | Bls_pop sk -> Public_key.Bls_pop (Bls_pop.Secret_key.to_public_key sk) include Compare.Make (struct type nonrec t = t @@ -428,6 +459,7 @@ module Secret_key = struct | Secp256k1 x, Secp256k1 y -> Secp256k1.Secret_key.compare x y | P256 x, P256 y -> P256.Secret_key.compare x y | Bls_aug x, Bls_aug y -> Bls_aug.Secret_key.compare x y + | Bls_pop x, Bls_pop y -> Bls_pop.Secret_key.compare x y | _ -> Stdlib.compare a b end) @@ -448,6 +480,7 @@ module Secret_key = struct | Some (Secp256k1.Secret_key.Data sk) -> Some (Secp256k1 sk) | Some (P256.Secret_key.Data sk) -> Some (P256 sk) | Some (Bls_aug.Secret_key.Data sk) -> Some (Bls_aug sk) + | Some (Bls_pop.Secret_key.Data sk) -> Some (Bls_pop sk) | _ -> None let of_b58check_exn s = @@ -466,12 +499,14 @@ module Secret_key = struct | Secp256k1 sk -> Secp256k1.Secret_key.to_b58check sk | P256 sk -> P256.Secret_key.to_b58check sk | Bls_aug sk -> Bls_aug.Secret_key.to_b58check sk + | Bls_pop sk -> Bls_pop.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_aug sk -> Bls_aug.Secret_key.to_short_b58check sk + | Bls_pop sk -> Bls_pop.Secret_key.to_short_b58check sk include Helpers.MakeEncoder (struct type nonrec t = t @@ -509,6 +544,12 @@ module Secret_key = struct Bls_aug.Secret_key.encoding (function Bls_aug x -> Some x | _ -> None) (function x -> Bls_aug x); + case + (Tag 4) + ~title:"Bls_pop" + Bls_pop.Secret_key.encoding + (function Bls_pop x -> Some x | _ -> None) + (function x -> Bls_pop x); ] let of_b58check = of_b58check @@ -530,6 +571,7 @@ type signature = | Secp256k1 of Secp256k1.t | P256 of P256.t | Bls_aug of Bls_aug.t + | Bls_pop of Bls_pop.t | Unknown of Bytes.t type prefix = Bls_prefix of Bytes.t @@ -538,7 +580,7 @@ type splitted = {prefix : prefix option; suffix : Bytes.t} type t = signature -let name = "Signature.V1" +let name = "Signature.V2" let title = "A Ed25519, Secp256k1, P256 or BLS signature" @@ -547,6 +589,7 @@ let to_bytes = function | Secp256k1 b -> Secp256k1.to_bytes b | P256 b -> P256.to_bytes b | Bls_aug b -> Bls_aug.to_bytes b + | Bls_pop b -> Bls_pop.to_bytes b | Unknown b -> b let of_bytes_opt s = @@ -560,7 +603,8 @@ let () = assert (Ed25519.size = 64) ; assert (Secp256k1.size = 64) ; assert (P256.size = 64) ; - assert (Bls_aug.size = 96) + assert (Bls_aug.size = 96) ; + assert (Bls_pop.size = 96) type Base58.data += Data_unknown of Bytes.t @@ -603,6 +647,8 @@ let of_b58check_opt s = then Option.map (fun x -> P256 x) (P256.of_b58check_opt s) else if TzString.has_prefix ~prefix:Bls_aug.b58check_encoding.encoded_prefix s then Option.map (fun x -> Bls_aug x) (Bls_aug.of_b58check_opt s) + else if TzString.has_prefix ~prefix:Bls_pop.b58check_encoding.encoded_prefix s + then Option.map (fun x -> Bls_pop x) (Bls_pop.of_b58check_opt s) else Option.map (fun x -> Unknown x) @@ -623,6 +669,7 @@ let to_b58check = function | Secp256k1 b -> Secp256k1.to_b58check b | P256 b -> P256.to_b58check b | Bls_aug b -> Bls_aug.to_b58check b + | Bls_pop b -> Bls_pop.to_b58check b | Unknown b -> Base58.simple_encode unknown_b58check_encoding b let to_short_b58check = function @@ -630,6 +677,7 @@ let to_short_b58check = function | Secp256k1 b -> Secp256k1.to_short_b58check b | P256 b -> P256.to_short_b58check b | Bls_aug b -> Bls_aug.to_short_b58check b + | Bls_pop b -> Bls_pop.to_short_b58check b | Unknown b -> Base58.simple_encode unknown_b58check_encoding b let raw_encoding = @@ -698,6 +746,8 @@ let of_p256 s = P256 s let of_bls s = Bls_aug s +let of_bls_pop s = Bls_pop s + let zero = of_ed25519 Ed25519.zero (* NOTE: At the moment, only BLS signatures can be encoded with a tag. We impose @@ -729,6 +779,7 @@ let split_signature = function let prefix = Bytes.sub s 0 32 in let suffix = Bytes.sub s 32 64 in {prefix = Some (Bls_prefix prefix); suffix} + | Bls_pop _ -> assert false | Unknown s -> assert (Compare.Int.(Bytes.length s = 64)) ; {prefix = None; suffix = s} @@ -769,6 +820,7 @@ let sign ?watermark secret_key message = | Secp256k1 sk -> of_secp256k1 (Secp256k1.sign ?watermark sk message) | P256 sk -> of_p256 (P256.sign ?watermark sk message) | Bls_aug sk -> of_bls (Bls_aug.sign ?watermark sk message) + | Bls_pop sk -> of_bls_pop (Bls_pop.sign ?watermark sk message) let check ?watermark public_key signature message = let watermark = Option.map bytes_of_watermark watermark in @@ -810,7 +862,7 @@ let fake_sign_from_pk pk msg = Bytes.blit msg 0 tmp half (all_or_half msg) ; of_bytes_exn tmp -type algo = Ed25519 | Secp256k1 | P256 | Bls_aug +type algo = Ed25519 | Secp256k1 | P256 | Bls_aug | Bls_pop let fake_sign ?watermark:_ secret_key msg = let pk = Secret_key.to_public_key secret_key in @@ -830,28 +882,43 @@ let hardcoded_sk algo : secret_key = | Bls_aug -> Secret_key.of_b58check_exn "BLsk1hfuv6V8JJRaLDBJgPTRGLKusTZnTmWGrvSKYzUaMuzvPLmeGG" + | Bls_pop -> + Secret_key.of_b58check_exn + "BLpsk4MvDCyuBXnHHTPn72yneLprM8xXSyJcyPt9nbWdLwnQUC5qbA8" let hardcoded_pk = (* precompute signatures *) - let ed, secp, p, bls = + let ed, secp, p, bls_aug, bls_pop = ( 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_aug) ) + Secret_key.to_public_key (hardcoded_sk Bls_aug), + Secret_key.to_public_key (hardcoded_sk Bls_pop) ) in - function Ed25519 -> ed | Secp256k1 -> secp | P256 -> p | Bls_aug -> bls + function + | Ed25519 -> ed + | Secp256k1 -> secp + | P256 -> p + | Bls_aug -> bls_aug + | Bls_pop -> bls_pop let hardcoded_msg = Bytes.of_string "Cheers" let hardcoded_sig = (* precompute signatures *) - let ed, secp, p, bls = + let ed, secp, p, bls_aug, bls_pop = ( sign (hardcoded_sk Ed25519) hardcoded_msg, sign (hardcoded_sk Secp256k1) hardcoded_msg, sign (hardcoded_sk P256) hardcoded_msg, - sign (hardcoded_sk Bls_aug) hardcoded_msg ) + sign (hardcoded_sk Bls_aug) hardcoded_msg, + sign (hardcoded_sk Bls_pop) hardcoded_msg ) in - function Ed25519 -> ed | Secp256k1 -> secp | P256 -> p | Bls_aug -> bls + function + | Ed25519 -> ed + | Secp256k1 -> secp + | P256 -> p + | Bls_aug -> bls_aug + | Bls_pop -> bls_pop let algo_of_pk (pk : Public_key.t) = match pk with @@ -859,6 +926,7 @@ let algo_of_pk (pk : Public_key.t) = | Secp256k1 _ -> Secp256k1 | P256 _ -> P256 | Bls_aug _ -> Bls_aug + | Bls_pop _ -> Bls_pop let fast_fake_sign ?watermark:_ sk _msg = let pk = Secret_key.to_public_key sk in @@ -965,6 +1033,9 @@ let generate_key ?(algo = Ed25519) ?seed () = | Bls_aug -> let pkh, pk, sk = Bls_aug.generate_key ?seed () in (Public_key_hash.Bls_aug pkh, Public_key.Bls_aug pk, Secret_key.Bls_aug sk) + | Bls_pop -> + let pkh, pk, sk = Bls_pop.generate_key ?seed () in + (Public_key_hash.Bls_pop pkh, Public_key.Bls_pop pk, Secret_key.Bls_pop sk) let fake_generate_key ?(algo = Ed25519) ?seed () = let true_keys = generate_key ~algo ?seed () in @@ -984,6 +1055,7 @@ let 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_aug sk -> Bls_aug.deterministic_nonce sk msg + | Secret_key.Bls_pop sk -> Bls_pop.deterministic_nonce sk msg let deterministic_nonce_hash sk msg = match sk with @@ -991,6 +1063,7 @@ let 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_aug sk -> Bls_aug.deterministic_nonce_hash sk msg + | Secret_key.Bls_pop sk -> Bls_pop.deterministic_nonce_hash sk msg module Of_V0 = struct let public_key_hash : Signature_v0.Public_key_hash.t -> Public_key_hash.t = diff --git a/src/lib_crypto/signature_v2.mli b/src/lib_crypto/signature_v2.mli index e8d03eefe4b6..1254450cb955 100644 --- a/src/lib_crypto/signature_v2.mli +++ b/src/lib_crypto/signature_v2.mli @@ -10,18 +10,21 @@ type public_key_hash = | Secp256k1 of Secp256k1.Public_key_hash.t | P256 of P256.Public_key_hash.t | Bls_aug of Bls_aug.Public_key_hash.t + | Bls_pop of Bls_pop.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_aug of Bls_aug.Public_key.t + | Bls_pop of Bls_pop.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_aug of Bls_aug.Secret_key.t + | Bls_pop of Bls_pop.Secret_key.t type watermark = Signature_v0.watermark = | Block_header of Chain_id.t @@ -38,6 +41,7 @@ type signature = | Secp256k1 of Secp256k1.t | P256 of P256.t | Bls_aug of Bls_aug.t + | Bls_pop of Bls_pop.t | Unknown of Bytes.t (** A signature prefix holds data only for signature that are more than 64 bytes @@ -81,8 +85,12 @@ val of_p256 : P256.t -> t (** [of_bls s] returns a wrapped version of the BLS signature [s] in {!t}. *) val of_bls : Bls_aug.t -> t +(** [of_bls_pop s] returns a wrapped version of the BLS POP signature [s] in + {!t}. *) +val of_bls_pop : Bls_pop.t -> t + (** The type of signing algorithms. *) -type algo = Ed25519 | Secp256k1 | P256 | Bls_aug +type algo = Ed25519 | Secp256k1 | P256 | Bls_aug | Bls_pop (** The list of signing algorithm supported, i.e. all constructors of type {!algo}. *) diff --git a/src/lib_crypto/tezos_crypto.ml b/src/lib_crypto/tezos_crypto.ml index d02b83e8d467..227b31085fcb 100644 --- a/src/lib_crypto/tezos_crypto.ml +++ b/src/lib_crypto/tezos_crypto.ml @@ -48,6 +48,7 @@ end module Signature = struct module Bls_aug = Bls_aug + module Bls_pop = Bls_pop module Ed25519 = Ed25519 module P256 = P256 module Secp256k1 = Secp256k1 diff --git a/src/lib_shell_benchmarks/encoding_benchmarks.ml b/src/lib_shell_benchmarks/encoding_benchmarks.ml index 560064490c32..8a8de2d44851 100644 --- a/src/lib_shell_benchmarks/encoding_benchmarks.ml +++ b/src/lib_shell_benchmarks/encoding_benchmarks.ml @@ -48,6 +48,7 @@ struct | Tezos_crypto.Signature.Secp256k1 -> "secp256k1" | Tezos_crypto.Signature.P256 -> "p256" | Tezos_crypto.Signature.Bls_aug -> "bls" + | Tezos_crypto.Signature.Bls_pop -> "Bls_pop" module Sampler = Crypto_samplers.Make_finite_key_pool (struct let size = 256 diff --git a/src/lib_signer_backends/encrypted.ml b/src/lib_signer_backends/encrypted.ml index 9c137f51a4b7..0c10517a957e 100644 --- a/src/lib_signer_backends/encrypted.ml +++ b/src/lib_signer_backends/encrypted.ml @@ -87,6 +87,10 @@ module Raw = struct Data_encoding.Binary.to_bytes_exn Signature.Bls_aug.Secret_key.encoding sk + | Decrypted_sk (Bls_pop sk) -> + Data_encoding.Binary.to_bytes_exn + Signature.Bls_pop.Secret_key.encoding + sk in Bytes.cat salt (Tezos_crypto.Crypto_box.Secretbox.secretbox key msg nonce) @@ -150,6 +154,19 @@ module Raw = struct failwith "Corrupted wallet, deciphered key is not a valid BLS12_381 \ secret key") + | Some bytes, Encrypted_sk Signature.Bls_pop -> ( + match + Data_encoding.Binary.of_bytes_opt + Signature.Bls_pop.Secret_key.encoding + bytes + with + | Some sk -> + return_some + (Decrypted_sk (Bls_pop sk : Tezos_crypto.Signature.Secret_key.t)) + | None -> + failwith + "Corrupted wallet, deciphered key is not a valid BLS12_381 \ + secret key") end module Encodings = struct @@ -371,7 +388,7 @@ let common_encrypt sk password = | Decrypted_sk (Ed25519 _) -> Encodings.ed25519 | Decrypted_sk (Secp256k1 _) -> Encodings.secp256k1 | Decrypted_sk (P256 _) -> Encodings.p256 - | Decrypted_sk (Bls_aug _) -> Encodings.bls12_381 + | Decrypted_sk (Bls_aug _) | Decrypted_sk (Bls_pop _) -> Encodings.bls12_381 in Tezos_crypto.Base58.simple_encode encoding payload diff --git a/src/proto_016_PtMumbai/lib_client/injection.ml b/src/proto_016_PtMumbai/lib_client/injection.ml index b0e5b7284796..dbf00bf9693f 100644 --- a/src/proto_016_PtMumbai/lib_client/injection.ml +++ b/src/proto_016_PtMumbai/lib_client/injection.ml @@ -639,6 +639,10 @@ let signature_size_of_algo : Tezos_crypto.Signature.algo -> int = function (* BLS signatures in operations are encoded with 2 extra bytes: a [ff] prefix and a tag [03]. *) Tezos_crypto.Signature.Bls_aug.size + 2 + | Bls_pop -> + (* BLS signatures in operations are encoded with 2 extra bytes: a [ff] + prefix and a tag [03]. *) + Tezos_crypto.Signature.Bls_pop.size + 2 (* This value is used as a safety guard for gas limit. *) let safety_guard = Gas.Arith.(integral_of_int_exn 100) diff --git a/tezt/tests/expected/dal.ml/DAL Node- P2P message encoding.out b/tezt/tests/expected/dal.ml/DAL Node- P2P message encoding.out index b3441110b14c..66434931a981 100644 --- a/tezt/tests/expected/dal.ml/DAL Node- P2P message encoding.out +++ b/tezt/tests/expected/dal.ml/DAL Node- P2P message encoding.out @@ -70,6 +70,18 @@ Bls (tag 3) +---------------------------+----------+------------------------+ +Bls_pop (tag 4) +=============== + ++---------------------------+----------+------------------------+ +| Name | Size | Contents | ++===========================+==========+========================+ +| Tag | 1 byte | unsigned 8-bit integer | ++---------------------------+----------+------------------------+ +| Bls12_381.Public_key_hash | 20 bytes | bytes | ++---------------------------+----------+------------------------+ + + X_1 *** -- GitLab From c25246614277ed85e6e429ccdc74cd93ef4ceda9 Mon Sep 17 00:00:00 2001 From: Albin Coquereau Date: Fri, 7 Feb 2025 16:12:29 +0100 Subject: [PATCH 05/10] Kaitai: update struct files --- .../kaitai-struct-files/files/signer_messages__request.ksy | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/client-libs/kaitai-struct-files/files/signer_messages__request.ksy b/client-libs/kaitai-struct-files/files/signer_messages__request.ksy index 33ab87f6034b..3823ae73037d 100644 --- a/client-libs/kaitai-struct-files/files/signer_messages__request.ksy +++ b/client-libs/kaitai-struct-files/files/signer_messages__request.ksy @@ -54,6 +54,9 @@ types: - id: bls size: 20 if: (public_key_hash_tag == public_key_hash_tag::bls) + - id: bls_pop + size: 20 + if: (public_key_hash_tag == public_key_hash_tag::bls_pop) sign: seq: - id: pkh @@ -86,6 +89,7 @@ enums: 1: secp256k1 2: p256 3: bls + 4: bls_pop signer_messages__request_tag: 0: sign 1: public_key -- GitLab From ad5c2a4a1b9b295eb89e5ba4c8cde63342c5ee0d Mon Sep 17 00:00:00 2001 From: Albin Coquereau Date: Fri, 14 Feb 2025 14:25:23 +0100 Subject: [PATCH 06/10] Alpha/v15: explicitely use bls_aug --- .../environment_V15.ml | 10 +- .../environment_V15.mli | 7 +- src/lib_protocol_environment/sigs/v15.in.ml | 2 + src/lib_protocol_environment/sigs/v15.ml | 108 ++++++++++++------ src/lib_protocol_environment/sigs/v15/bls.mli | 2 - .../sigs/v15/bls_aug.mli | 40 +++++++ .../sigs/v15/signature.mli | 6 +- src/proto_alpha/lib_protocol/apply.ml | 2 +- .../lib_protocol/contract_delegate_storage.ml | 7 +- .../contract_delegate_storage.mli | 2 +- src/proto_alpha/lib_protocol/contract_repr.ml | 2 +- .../lib_protocol/delegate_consensus_key.ml | 8 +- .../lib_protocol/delegate_consensus_key.mli | 2 +- src/proto_alpha/lib_protocol/storage.ml | 8 +- .../lib_protocol/tx_rollup_l2_address.ml | 6 +- .../lib_protocol/tx_rollup_l2_address.mli | 3 +- src/proto_alpha/lib_protocol/validate.ml | 2 +- 17 files changed, 153 insertions(+), 64 deletions(-) create mode 100644 src/lib_protocol_environment/sigs/v15/bls_aug.mli diff --git a/src/lib_protocol_environment/environment_V15.ml b/src/lib_protocol_environment/environment_V15.ml index 82594d3516df..b8af8baa0cc8 100644 --- a/src/lib_protocol_environment/environment_V15.ml +++ b/src/lib_protocol_environment/environment_V15.ml @@ -78,10 +78,11 @@ module type T = sig Tezos_crypto.Signature.P256.Public_key_hash.t and type P256.Public_key.t = Tezos_crypto.Signature.P256.Public_key.t and type P256.t = Tezos_crypto.Signature.P256.t - and type Bls.Public_key_hash.t = + and type Bls_aug.Public_key_hash.t = Tezos_crypto.Signature.Bls_aug.Public_key_hash.t - and type Bls.Public_key.t = Tezos_crypto.Signature.Bls_aug.Public_key.t - and type Bls.t = Tezos_crypto.Signature.Bls_aug.t + and type Bls_aug.Public_key.t = + Tezos_crypto.Signature.Bls_aug.Public_key.t + and type Bls_aug.t = Tezos_crypto.Signature.Bls_aug.t and type Signature.public_key_hash = Tezos_crypto.Signature.V1.public_key_hash and type Signature.public_key = Tezos_crypto.Signature.V1.public_key @@ -336,6 +337,7 @@ struct module Secp256k1 = Tezos_crypto.Signature.Secp256k1 module P256 = Tezos_crypto.Signature.P256 module Bls = Tezos_crypto.Signature.Bls_aug + module Bls_aug = Tezos_crypto.Signature.Bls_aug module Signature = struct include Tezos_crypto.Signature.V1 @@ -353,7 +355,7 @@ struct | Ed25519 _ -> "check_signature_ed25519" | Secp256k1 _ -> "check_signature_secp256k1" | P256 _ -> "check_signature_p256" - | Bls _ -> "check_signature_bls"); + | Bls_aug _ -> "check_signature_bls_aug"); ]]) end diff --git a/src/lib_protocol_environment/environment_V15.mli b/src/lib_protocol_environment/environment_V15.mli index 2ec09e3d877b..798322d16d68 100644 --- a/src/lib_protocol_environment/environment_V15.mli +++ b/src/lib_protocol_environment/environment_V15.mli @@ -78,10 +78,11 @@ module type T = sig Tezos_crypto.Signature.P256.Public_key_hash.t and type P256.Public_key.t = Tezos_crypto.Signature.P256.Public_key.t and type P256.t = Tezos_crypto.Signature.P256.t - and type Bls.Public_key_hash.t = + and type Bls_aug.Public_key_hash.t = Tezos_crypto.Signature.Bls_aug.Public_key_hash.t - and type Bls.Public_key.t = Tezos_crypto.Signature.Bls_aug.Public_key.t - and type Bls.t = Tezos_crypto.Signature.Bls_aug.t + and type Bls_aug.Public_key.t = + Tezos_crypto.Signature.Bls_aug.Public_key.t + and type Bls_aug.t = Tezos_crypto.Signature.Bls_aug.t and type Signature.public_key_hash = Tezos_crypto.Signature.V1.public_key_hash and type Signature.public_key = Tezos_crypto.Signature.V1.public_key diff --git a/src/lib_protocol_environment/sigs/v15.in.ml b/src/lib_protocol_environment/sigs/v15.in.ml index a9820536d50e..a4b59db0fe8c 100644 --- a/src/lib_protocol_environment/sigs/v15.in.ml +++ b/src/lib_protocol_environment/sigs/v15.in.ml @@ -87,6 +87,8 @@ module type T = sig module Bls : [%sig "v15/bls.mli"] + module Bls_aug : [%sig "v15/bls_aug.mli"] + module Ed25519 : [%sig "v15/ed25519.mli"] module Secp256k1 : [%sig "v15/secp256k1.mli"] diff --git a/src/lib_protocol_environment/sigs/v15.ml b/src/lib_protocol_environment/sigs/v15.ml index 973d4e40d4e2..9206b7b126f7 100644 --- a/src/lib_protocol_environment/sigs/v15.ml +++ b/src/lib_protocol_environment/sigs/v15.ml @@ -9699,6 +9699,50 @@ end (** Tezos - BLS12-381 cryptography *) +(** Module to access/expose the primitives of BLS12-381 *) +module Primitive : sig + module Fr : S.PRIME_FIELD + + module G1 : S.CURVE with type Scalar.t = Fr.t + + module G2 : S.CURVE with type Scalar.t = Fr.t + + val pairing_check : (G1.t * G2.t) list -> bool +end +end +# 88 "v15.in.ml" + + + module Bls_aug : sig +# 1 "v15/bls_aug.mli" +(*****************************************************************************) +(* *) +(* Open Source License *) +(* Copyright (c) 2018 Dynamic Ledger Solutions, Inc. *) +(* Copyright (c) 2022 Nomadic Labs. *) +(* *) +(* Permission is hereby granted, free of charge, to any person obtaining a *) +(* copy of this software and associated documentation files (the "Software"),*) +(* to deal in the Software without restriction, including without limitation *) +(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *) +(* and/or sell copies of the Software, and to permit persons to whom the *) +(* Software is furnished to do so, subject to the following conditions: *) +(* *) +(* The above copyright notice and this permission notice shall be included *) +(* in all copies or substantial portions of the Software. *) +(* *) +(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*) +(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *) +(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *) +(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*) +(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *) +(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *) +(* DEALINGS IN THE SOFTWARE. *) +(* *) +(*****************************************************************************) + +(** Tezos - BLS12-381 cryptography *) + include S.AGGREGATE_SIGNATURE with type watermark := bytes (** Module to access/expose the primitives of BLS12-381 *) @@ -9712,7 +9756,7 @@ module Primitive : sig val pairing_check : (G1.t * G2.t) list -> bool end end -# 88 "v15.in.ml" +# 90 "v15.in.ml" module Ed25519 : sig @@ -9746,7 +9790,7 @@ end include S.SIGNATURE with type watermark := bytes end -# 90 "v15.in.ml" +# 92 "v15.in.ml" module Secp256k1 : sig @@ -9780,7 +9824,7 @@ end include S.SIGNATURE with type watermark := bytes end -# 92 "v15.in.ml" +# 94 "v15.in.ml" module P256 : sig @@ -9814,7 +9858,7 @@ end include S.SIGNATURE with type watermark := bytes end -# 94 "v15.in.ml" +# 96 "v15.in.ml" module Chain_id : sig @@ -9846,7 +9890,7 @@ end include S.HASH end -# 96 "v15.in.ml" +# 98 "v15.in.ml" module Signature : sig @@ -9881,13 +9925,13 @@ 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 + | Bls of Bls_aug.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 + | Bls of Bls_aug.Public_key.t type watermark = | Block_header of Chain_id.t @@ -9899,7 +9943,7 @@ type signature = | Ed25519 of Ed25519.t | Secp256k1 of Secp256k1.t | P256 of P256.t - | Bls of Bls.t + | Bls of Bls_aug.t | Unknown of Bytes.t type prefix = Bls_prefix of Bytes.t @@ -9914,7 +9958,7 @@ include val size : t -> int end -# 98 "v15.in.ml" +# 100 "v15.in.ml" module Block_hash : sig @@ -9947,7 +9991,7 @@ end (** Blocks hashes / IDs. *) include S.HASH end -# 100 "v15.in.ml" +# 102 "v15.in.ml" module Operation_hash : sig @@ -9980,7 +10024,7 @@ end (** Operations hashes / IDs. *) include S.HASH end -# 102 "v15.in.ml" +# 104 "v15.in.ml" module Operation_list_hash : sig @@ -10013,7 +10057,7 @@ end (** Blocks hashes / IDs. *) include S.MERKLE_TREE with type elt = Operation_hash.t end -# 104 "v15.in.ml" +# 106 "v15.in.ml" module Operation_list_list_hash : sig @@ -10046,7 +10090,7 @@ end (** Blocks hashes / IDs. *) include S.MERKLE_TREE with type elt = Operation_list_hash.t end -# 106 "v15.in.ml" +# 108 "v15.in.ml" module Protocol_hash : sig @@ -10079,7 +10123,7 @@ end (** Protocol hashes / IDs. *) include S.HASH end -# 108 "v15.in.ml" +# 110 "v15.in.ml" module Context_hash : sig @@ -10132,7 +10176,7 @@ end type version = Version.t end -# 110 "v15.in.ml" +# 112 "v15.in.ml" module Sapling : sig @@ -10280,7 +10324,7 @@ module Verification : sig val final_check : t -> UTXO.transaction -> string -> bool end end -# 112 "v15.in.ml" +# 114 "v15.in.ml" module Timelock : sig @@ -10337,7 +10381,7 @@ val open_chest : chest -> chest_key -> time:int -> opening_result Used for gas accounting*) val get_plaintext_size : chest -> int end -# 114 "v15.in.ml" +# 116 "v15.in.ml" module Vdf : sig @@ -10425,7 +10469,7 @@ val prove : discriminant -> challenge -> difficulty -> result * proof @raise Invalid_argument when inputs are invalid *) val verify : discriminant -> challenge -> difficulty -> result -> proof -> bool end -# 116 "v15.in.ml" +# 118 "v15.in.ml" module Micheline : sig @@ -10485,7 +10529,7 @@ val annotations : ('l, 'p) node -> string list val strip_locations : (_, 'p) node -> 'p canonical end -# 118 "v15.in.ml" +# 120 "v15.in.ml" module Block_header : sig @@ -10542,7 +10586,7 @@ type t = {shell : shell_header; protocol_data : bytes} include S.HASHABLE with type t := t and type hash := Block_hash.t end -# 120 "v15.in.ml" +# 122 "v15.in.ml" module Bounded : sig @@ -10691,7 +10735,7 @@ module Int8 (B : BOUNDS with type ocaml_type := int) : module Uint8 (B : BOUNDS with type ocaml_type := int) : S with type ocaml_type := int end -# 122 "v15.in.ml" +# 124 "v15.in.ml" module Fitness : sig @@ -10725,7 +10769,7 @@ end compared in a lexicographical order (longer list are greater). *) include S.T with type t = bytes list end -# 124 "v15.in.ml" +# 126 "v15.in.ml" module Operation : sig @@ -10769,7 +10813,7 @@ type t = {shell : shell_header; proto : bytes} include S.HASHABLE with type t := t and type hash := Operation_hash.t end -# 126 "v15.in.ml" +# 128 "v15.in.ml" module Context : sig @@ -11406,7 +11450,7 @@ module Cache : and type key = cache_key and type value = cache_value end -# 128 "v15.in.ml" +# 130 "v15.in.ml" module Updater : sig @@ -11935,7 +11979,7 @@ end not complete until [init] in invoked. *) val activate : Context.t -> Protocol_hash.t -> Context.t Lwt.t end -# 130 "v15.in.ml" +# 132 "v15.in.ml" module RPC_context : sig @@ -12089,7 +12133,7 @@ val make_opt_call3 : 'i -> 'o option shell_tzresult Lwt.t end -# 132 "v15.in.ml" +# 134 "v15.in.ml" module Context_binary : sig @@ -12132,7 +12176,7 @@ module Tree : val make_empty_context : ?root:string -> unit -> t end -# 134 "v15.in.ml" +# 136 "v15.in.ml" module Wasm_2_0_0 : sig @@ -12206,7 +12250,7 @@ module Make val get_info : Tree.tree -> info Lwt.t end end -# 136 "v15.in.ml" +# 138 "v15.in.ml" module Plonk : sig @@ -12325,7 +12369,7 @@ val scalar_array_encoding : scalar array Data_encoding.t on the given [inputs] according to the [public_parameters]. *) val verify : public_parameters -> verifier_inputs -> proof -> bool end -# 138 "v15.in.ml" +# 140 "v15.in.ml" module Dal : sig @@ -12480,7 +12524,7 @@ val share_is_trap : traps_fraction:Q.t -> (bool, [> `Decoding_error]) Result.t end -# 140 "v15.in.ml" +# 142 "v15.in.ml" module Skip_list : sig @@ -12712,7 +12756,7 @@ module Make (_ : sig val basis : int end) : S end -# 142 "v15.in.ml" +# 144 "v15.in.ml" module Smart_rollup : sig @@ -12769,6 +12813,6 @@ module Inbox_hash : S.HASH (** Smart rollup merkelized payload hashes' hash *) module Merkelized_payload_hashes_hash : S.HASH end -# 144 "v15.in.ml" +# 146 "v15.in.ml" end diff --git a/src/lib_protocol_environment/sigs/v15/bls.mli b/src/lib_protocol_environment/sigs/v15/bls.mli index a016a71904ee..a754ba009288 100644 --- a/src/lib_protocol_environment/sigs/v15/bls.mli +++ b/src/lib_protocol_environment/sigs/v15/bls.mli @@ -26,8 +26,6 @@ (** Tezos - BLS12-381 cryptography *) -include S.AGGREGATE_SIGNATURE with type watermark := bytes - (** Module to access/expose the primitives of BLS12-381 *) module Primitive : sig module Fr : S.PRIME_FIELD diff --git a/src/lib_protocol_environment/sigs/v15/bls_aug.mli b/src/lib_protocol_environment/sigs/v15/bls_aug.mli new file mode 100644 index 000000000000..a016a71904ee --- /dev/null +++ b/src/lib_protocol_environment/sigs/v15/bls_aug.mli @@ -0,0 +1,40 @@ +(*****************************************************************************) +(* *) +(* Open Source License *) +(* Copyright (c) 2018 Dynamic Ledger Solutions, Inc. *) +(* Copyright (c) 2022 Nomadic Labs. *) +(* *) +(* Permission is hereby granted, free of charge, to any person obtaining a *) +(* copy of this software and associated documentation files (the "Software"),*) +(* to deal in the Software without restriction, including without limitation *) +(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *) +(* and/or sell copies of the Software, and to permit persons to whom the *) +(* Software is furnished to do so, subject to the following conditions: *) +(* *) +(* The above copyright notice and this permission notice shall be included *) +(* in all copies or substantial portions of the Software. *) +(* *) +(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*) +(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *) +(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *) +(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*) +(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *) +(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *) +(* DEALINGS IN THE SOFTWARE. *) +(* *) +(*****************************************************************************) + +(** Tezos - BLS12-381 cryptography *) + +include S.AGGREGATE_SIGNATURE with type watermark := bytes + +(** Module to access/expose the primitives of BLS12-381 *) +module Primitive : sig + module Fr : S.PRIME_FIELD + + module G1 : S.CURVE with type Scalar.t = Fr.t + + module G2 : S.CURVE with type Scalar.t = Fr.t + + val pairing_check : (G1.t * G2.t) list -> bool +end diff --git a/src/lib_protocol_environment/sigs/v15/signature.mli b/src/lib_protocol_environment/sigs/v15/signature.mli index 67b9dd7aca16..d97623b867bd 100644 --- a/src/lib_protocol_environment/sigs/v15/signature.mli +++ b/src/lib_protocol_environment/sigs/v15/signature.mli @@ -28,13 +28,13 @@ 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 + | Bls of Bls_aug.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 + | Bls of Bls_aug.Public_key.t type watermark = | Block_header of Chain_id.t @@ -46,7 +46,7 @@ type signature = | Ed25519 of Ed25519.t | Secp256k1 of Secp256k1.t | P256 of P256.t - | Bls of Bls.t + | Bls of Bls_aug.t | Unknown of Bytes.t type prefix = Bls_prefix of Bytes.t diff --git a/src/proto_alpha/lib_protocol/apply.ml b/src/proto_alpha/lib_protocol/apply.ml index dea20068c272..e90b67ca03ec 100644 --- a/src/proto_alpha/lib_protocol/apply.ml +++ b/src/proto_alpha/lib_protocol/apply.ml @@ -1437,7 +1437,7 @@ let apply_manager_operation : let*? ctxt = let gas_cost_for_sig_check = let open Saturation_repr.Syntax in - let size = Bls.Public_key.size bls_public_key in + let size = Bls_aug.Public_key.size bls_public_key in Operation_costs.serialization_cost size + Michelson_v1_gas.Cost_of.Interpreter.check_signature_on_algo Bls diff --git a/src/proto_alpha/lib_protocol/contract_delegate_storage.ml b/src/proto_alpha/lib_protocol/contract_delegate_storage.ml index 6fda4fde2dc5..c3d7df0f2db2 100644 --- a/src/proto_alpha/lib_protocol/contract_delegate_storage.ml +++ b/src/proto_alpha/lib_protocol/contract_delegate_storage.ml @@ -23,7 +23,8 @@ (* *) (*****************************************************************************) -type error += (* `Permanent *) Forbidden_tz4_delegate of Bls.Public_key_hash.t +type error += + | (* `Permanent *) Forbidden_tz4_delegate of Bls_aug.Public_key_hash.t let () = register_error_kind @@ -35,9 +36,9 @@ let () = Format.fprintf ppf "The delegate %a is forbidden as it is a BLS public key hash." - Bls.Public_key_hash.pp + Bls_aug.Public_key_hash.pp implicit) - Data_encoding.(obj1 (req "delegate" Bls.Public_key_hash.encoding)) + Data_encoding.(obj1 (req "delegate" Bls_aug.Public_key_hash.encoding)) (function Forbidden_tz4_delegate d -> Some d | _ -> None) (fun d -> Forbidden_tz4_delegate d) diff --git a/src/proto_alpha/lib_protocol/contract_delegate_storage.mli b/src/proto_alpha/lib_protocol/contract_delegate_storage.mli index eeecd7367325..dbbad19bff7d 100644 --- a/src/proto_alpha/lib_protocol/contract_delegate_storage.mli +++ b/src/proto_alpha/lib_protocol/contract_delegate_storage.mli @@ -29,7 +29,7 @@ type error += | (* `Permanent *) - Forbidden_tz4_delegate of Bls.Public_key_hash.t + Forbidden_tz4_delegate of Bls_aug.Public_key_hash.t (** Delegates cannot be tz4 accounts (i.e. BLS public key hashes). This error is returned when we try to register such a delegate. *) diff --git a/src/proto_alpha/lib_protocol/contract_repr.ml b/src/proto_alpha/lib_protocol/contract_repr.ml index 96d9cc493312..3c304f3d9852 100644 --- a/src/proto_alpha/lib_protocol/contract_repr.ml +++ b/src/proto_alpha/lib_protocol/contract_repr.ml @@ -56,7 +56,7 @@ let implicit_of_b58data : Base58.data -> Signature.public_key_hash option = | Ed25519.Public_key_hash.Data h -> Some (Signature.Ed25519 h) | Secp256k1.Public_key_hash.Data h -> Some (Signature.Secp256k1 h) | P256.Public_key_hash.Data h -> Some (Signature.P256 h) - | Bls.Public_key_hash.Data h -> Some (Signature.Bls h) + | Bls_aug.Public_key_hash.Data h -> Some (Signature.Bls h) | _ -> None let originated_of_b58data = function diff --git a/src/proto_alpha/lib_protocol/delegate_consensus_key.ml b/src/proto_alpha/lib_protocol/delegate_consensus_key.ml index 004dd0d6816c..38cb284086bf 100644 --- a/src/proto_alpha/lib_protocol/delegate_consensus_key.ml +++ b/src/proto_alpha/lib_protocol/delegate_consensus_key.ml @@ -26,7 +26,7 @@ type error += | Invalid_consensus_key_update_noop of Cycle_repr.t | Invalid_consensus_key_update_active - | Invalid_consensus_key_update_tz4 of Bls.Public_key.t + | Invalid_consensus_key_update_tz4 of Bls_aug.Public_key.t let () = register_error_kind @@ -65,9 +65,9 @@ let () = Format.fprintf ppf "The consensus key %a is forbidden as it is a BLS public key." - Bls.Public_key_hash.pp - (Bls.Public_key.hash pk)) - Data_encoding.(obj1 (req "delegate_pk" Bls.Public_key.encoding)) + Bls_aug.Public_key_hash.pp + (Bls_aug.Public_key.hash pk)) + Data_encoding.(obj1 (req "delegate_pk" Bls_aug.Public_key.encoding)) (function Invalid_consensus_key_update_tz4 pk -> Some pk | _ -> None) (fun pk -> Invalid_consensus_key_update_tz4 pk) diff --git a/src/proto_alpha/lib_protocol/delegate_consensus_key.mli b/src/proto_alpha/lib_protocol/delegate_consensus_key.mli index 920ec51e028c..8ab26b700545 100644 --- a/src/proto_alpha/lib_protocol/delegate_consensus_key.mli +++ b/src/proto_alpha/lib_protocol/delegate_consensus_key.mli @@ -32,7 +32,7 @@ type error += | Invalid_consensus_key_update_noop of Cycle_repr.t | Invalid_consensus_key_update_active - | Invalid_consensus_key_update_tz4 of Bls.Public_key.t + | Invalid_consensus_key_update_tz4 of Bls_aug.Public_key.t (** The public key of a consensus key and the associated delegate. *) type pk = Raw_context.consensus_pk = { diff --git a/src/proto_alpha/lib_protocol/storage.ml b/src/proto_alpha/lib_protocol/storage.ml index c88f8dd04805..db7ac5b27737 100644 --- a/src/proto_alpha/lib_protocol/storage.ml +++ b/src/proto_alpha/lib_protocol/storage.ml @@ -1066,14 +1066,14 @@ module Public_key_hash = struct module Path_Ed25519 = Path_encoding.Make_hex (Ed25519.Public_key_hash) module Path_Secp256k1 = Path_encoding.Make_hex (Secp256k1.Public_key_hash) module Path_P256 = Path_encoding.Make_hex (P256.Public_key_hash) - module Path_Bls = Path_encoding.Make_hex (Bls.Public_key_hash) + module Path_Bls_aug = Path_encoding.Make_hex (Bls_aug.Public_key_hash) let to_path (key : public_key_hash) l = match key with | Ed25519 h -> "ed25519" :: Path_Ed25519.to_path h l | Secp256k1 h -> "secp256k1" :: Path_Secp256k1.to_path h l | P256 h -> "p256" :: Path_P256.to_path h l - | Bls h -> "bls" :: Path_Bls.to_path h l + | Bls h -> "bls" :: Path_Bls_aug.to_path h l let of_path : _ -> public_key_hash option = function | "ed25519" :: rest -> ( @@ -1089,7 +1089,7 @@ module Public_key_hash = struct | Some pkh -> Some (P256 pkh) | None -> None) | "bls" :: rest -> ( - match Path_Bls.of_path rest with + match Path_Bls_aug.of_path rest with | Some pkh -> Some (Bls pkh) | None -> None) | _ -> None @@ -1098,7 +1098,7 @@ module Public_key_hash = struct let l1 = Path_Ed25519.path_length and l2 = Path_Secp256k1.path_length and l3 = Path_P256.path_length - and l4 = Path_Bls.path_length in + and l4 = Path_Bls_aug.path_length in assert (Compare.Int.(l1 = l2 && l2 = l3 && l3 = l4)) ; l1 + 1 end diff --git a/src/proto_alpha/lib_protocol/tx_rollup_l2_address.ml b/src/proto_alpha/lib_protocol/tx_rollup_l2_address.ml index 8959062241ae..b90e17df89de 100644 --- a/src/proto_alpha/lib_protocol/tx_rollup_l2_address.ml +++ b/src/proto_alpha/lib_protocol/tx_rollup_l2_address.ml @@ -25,16 +25,16 @@ (* *) (*****************************************************************************) -include Bls.Public_key_hash +include Bls_aug.Public_key_hash type address = t let in_memory_size : t -> Cache_memory_helpers.sint = fun _ -> let open Cache_memory_helpers in - header_size +! word_size +! string_size_gen Bls.Public_key_hash.size + header_size +! word_size +! string_size_gen Bls_aug.Public_key_hash.size -let size _ = Bls.Public_key_hash.size +let size _ = Bls_aug.Public_key_hash.size module Indexable = struct include Indexable.Make (struct diff --git a/src/proto_alpha/lib_protocol/tx_rollup_l2_address.mli b/src/proto_alpha/lib_protocol/tx_rollup_l2_address.mli index 534551d427df..01aa5d103c39 100644 --- a/src/proto_alpha/lib_protocol/tx_rollup_l2_address.mli +++ b/src/proto_alpha/lib_protocol/tx_rollup_l2_address.mli @@ -30,7 +30,8 @@ (** The hash of a BLS public key is used as the primary identifier of ticket holders within a transaction rollup. *) -include module type of Bls.Public_key_hash with type t = Bls.Public_key_hash.t +include + module type of Bls_aug.Public_key_hash with type t = Bls_aug.Public_key_hash.t type address = t diff --git a/src/proto_alpha/lib_protocol/validate.ml b/src/proto_alpha/lib_protocol/validate.ml index 1380ec715b56..67c90412733d 100644 --- a/src/proto_alpha/lib_protocol/validate.ml +++ b/src/proto_alpha/lib_protocol/validate.ml @@ -2371,7 +2371,7 @@ module Manager = struct check the proof. *) let gas_cost_for_sig_check = let open Saturation_repr.Syntax in - let size = Bls.Public_key.size bls_public_key in + let size = Bls_aug.Public_key.size bls_public_key in Operation_costs.serialization_cost size + Michelson_v1_gas.Cost_of.Interpreter.check_signature_on_algo Bls -- GitLab From e133bfacf69279ba7f41fba7ef97f50ed0719337 Mon Sep 17 00:00:00 2001 From: Albin Coquereau Date: Fri, 14 Feb 2025 14:43:00 +0100 Subject: [PATCH 07/10] Env15: add bls_pop support --- .../environment_V15.ml | 6 ++ .../environment_V15.mli | 5 + src/lib_protocol_environment/sigs/v15.in.ml | 2 + src/lib_protocol_environment/sigs/v15.ml | 102 +++++++++++++----- .../sigs/v15/bls_pop.mli | 40 +++++++ 5 files changed, 127 insertions(+), 28 deletions(-) create mode 100644 src/lib_protocol_environment/sigs/v15/bls_pop.mli diff --git a/src/lib_protocol_environment/environment_V15.ml b/src/lib_protocol_environment/environment_V15.ml index b8af8baa0cc8..5b4485063671 100644 --- a/src/lib_protocol_environment/environment_V15.ml +++ b/src/lib_protocol_environment/environment_V15.ml @@ -83,6 +83,11 @@ module type T = sig and type Bls_aug.Public_key.t = Tezos_crypto.Signature.Bls_aug.Public_key.t and type Bls_aug.t = Tezos_crypto.Signature.Bls_aug.t + and type Bls_pop.Public_key_hash.t = + Tezos_crypto.Signature.Bls_pop.Public_key_hash.t + and type Bls_pop.Public_key.t = + Tezos_crypto.Signature.Bls_pop.Public_key.t + and type Bls_pop.t = Tezos_crypto.Signature.Bls_pop.t and type Signature.public_key_hash = Tezos_crypto.Signature.V1.public_key_hash and type Signature.public_key = Tezos_crypto.Signature.V1.public_key @@ -338,6 +343,7 @@ struct module P256 = Tezos_crypto.Signature.P256 module Bls = Tezos_crypto.Signature.Bls_aug module Bls_aug = Tezos_crypto.Signature.Bls_aug + module Bls_pop = Tezos_crypto.Signature.Bls_pop module Signature = struct include Tezos_crypto.Signature.V1 diff --git a/src/lib_protocol_environment/environment_V15.mli b/src/lib_protocol_environment/environment_V15.mli index 798322d16d68..b8a944fc2837 100644 --- a/src/lib_protocol_environment/environment_V15.mli +++ b/src/lib_protocol_environment/environment_V15.mli @@ -83,6 +83,11 @@ module type T = sig and type Bls_aug.Public_key.t = Tezos_crypto.Signature.Bls_aug.Public_key.t and type Bls_aug.t = Tezos_crypto.Signature.Bls_aug.t + and type Bls_pop.Public_key_hash.t = + Tezos_crypto.Signature.Bls_pop.Public_key_hash.t + and type Bls_pop.Public_key.t = + Tezos_crypto.Signature.Bls_pop.Public_key.t + and type Bls_pop.t = Tezos_crypto.Signature.Bls_pop.t and type Signature.public_key_hash = Tezos_crypto.Signature.V1.public_key_hash and type Signature.public_key = Tezos_crypto.Signature.V1.public_key diff --git a/src/lib_protocol_environment/sigs/v15.in.ml b/src/lib_protocol_environment/sigs/v15.in.ml index a4b59db0fe8c..840ffcdac4c9 100644 --- a/src/lib_protocol_environment/sigs/v15.in.ml +++ b/src/lib_protocol_environment/sigs/v15.in.ml @@ -89,6 +89,8 @@ module type T = sig module Bls_aug : [%sig "v15/bls_aug.mli"] + module Bls_pop : [%sig "v15/bls_pop.mli"] + module Ed25519 : [%sig "v15/ed25519.mli"] module Secp256k1 : [%sig "v15/secp256k1.mli"] diff --git a/src/lib_protocol_environment/sigs/v15.ml b/src/lib_protocol_environment/sigs/v15.ml index 9206b7b126f7..012baf93f3e3 100644 --- a/src/lib_protocol_environment/sigs/v15.ml +++ b/src/lib_protocol_environment/sigs/v15.ml @@ -9759,6 +9759,52 @@ end # 90 "v15.in.ml" + module Bls_pop : sig +# 1 "v15/bls_pop.mli" +(*****************************************************************************) +(* *) +(* Open Source License *) +(* Copyright (c) 2018 Dynamic Ledger Solutions, Inc. *) +(* Copyright (c) 2022 Nomadic Labs. *) +(* *) +(* Permission is hereby granted, free of charge, to any person obtaining a *) +(* copy of this software and associated documentation files (the "Software"),*) +(* to deal in the Software without restriction, including without limitation *) +(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *) +(* and/or sell copies of the Software, and to permit persons to whom the *) +(* Software is furnished to do so, subject to the following conditions: *) +(* *) +(* The above copyright notice and this permission notice shall be included *) +(* in all copies or substantial portions of the Software. *) +(* *) +(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*) +(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *) +(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *) +(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*) +(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *) +(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *) +(* DEALINGS IN THE SOFTWARE. *) +(* *) +(*****************************************************************************) + +(** Tezos - BLS12-381 cryptography *) + +include S.SIGNATURE with type watermark := bytes + +(** Module to access/expose the primitives of BLS12-381 *) +module Primitive : sig + module Fr : S.PRIME_FIELD + + module G1 : S.CURVE with type Scalar.t = Fr.t + + module G2 : S.CURVE with type Scalar.t = Fr.t + + val pairing_check : (G1.t * G2.t) list -> bool +end +end +# 92 "v15.in.ml" + + module Ed25519 : sig # 1 "v15/ed25519.mli" (*****************************************************************************) @@ -9790,7 +9836,7 @@ end include S.SIGNATURE with type watermark := bytes end -# 92 "v15.in.ml" +# 94 "v15.in.ml" module Secp256k1 : sig @@ -9824,7 +9870,7 @@ end include S.SIGNATURE with type watermark := bytes end -# 94 "v15.in.ml" +# 96 "v15.in.ml" module P256 : sig @@ -9858,7 +9904,7 @@ end include S.SIGNATURE with type watermark := bytes end -# 96 "v15.in.ml" +# 98 "v15.in.ml" module Chain_id : sig @@ -9890,7 +9936,7 @@ end include S.HASH end -# 98 "v15.in.ml" +# 100 "v15.in.ml" module Signature : sig @@ -9958,7 +10004,7 @@ include val size : t -> int end -# 100 "v15.in.ml" +# 102 "v15.in.ml" module Block_hash : sig @@ -9991,7 +10037,7 @@ end (** Blocks hashes / IDs. *) include S.HASH end -# 102 "v15.in.ml" +# 104 "v15.in.ml" module Operation_hash : sig @@ -10024,7 +10070,7 @@ end (** Operations hashes / IDs. *) include S.HASH end -# 104 "v15.in.ml" +# 106 "v15.in.ml" module Operation_list_hash : sig @@ -10057,7 +10103,7 @@ end (** Blocks hashes / IDs. *) include S.MERKLE_TREE with type elt = Operation_hash.t end -# 106 "v15.in.ml" +# 108 "v15.in.ml" module Operation_list_list_hash : sig @@ -10090,7 +10136,7 @@ end (** Blocks hashes / IDs. *) include S.MERKLE_TREE with type elt = Operation_list_hash.t end -# 108 "v15.in.ml" +# 110 "v15.in.ml" module Protocol_hash : sig @@ -10123,7 +10169,7 @@ end (** Protocol hashes / IDs. *) include S.HASH end -# 110 "v15.in.ml" +# 112 "v15.in.ml" module Context_hash : sig @@ -10176,7 +10222,7 @@ end type version = Version.t end -# 112 "v15.in.ml" +# 114 "v15.in.ml" module Sapling : sig @@ -10324,7 +10370,7 @@ module Verification : sig val final_check : t -> UTXO.transaction -> string -> bool end end -# 114 "v15.in.ml" +# 116 "v15.in.ml" module Timelock : sig @@ -10381,7 +10427,7 @@ val open_chest : chest -> chest_key -> time:int -> opening_result Used for gas accounting*) val get_plaintext_size : chest -> int end -# 116 "v15.in.ml" +# 118 "v15.in.ml" module Vdf : sig @@ -10469,7 +10515,7 @@ val prove : discriminant -> challenge -> difficulty -> result * proof @raise Invalid_argument when inputs are invalid *) val verify : discriminant -> challenge -> difficulty -> result -> proof -> bool end -# 118 "v15.in.ml" +# 120 "v15.in.ml" module Micheline : sig @@ -10529,7 +10575,7 @@ val annotations : ('l, 'p) node -> string list val strip_locations : (_, 'p) node -> 'p canonical end -# 120 "v15.in.ml" +# 122 "v15.in.ml" module Block_header : sig @@ -10586,7 +10632,7 @@ type t = {shell : shell_header; protocol_data : bytes} include S.HASHABLE with type t := t and type hash := Block_hash.t end -# 122 "v15.in.ml" +# 124 "v15.in.ml" module Bounded : sig @@ -10735,7 +10781,7 @@ module Int8 (B : BOUNDS with type ocaml_type := int) : module Uint8 (B : BOUNDS with type ocaml_type := int) : S with type ocaml_type := int end -# 124 "v15.in.ml" +# 126 "v15.in.ml" module Fitness : sig @@ -10769,7 +10815,7 @@ end compared in a lexicographical order (longer list are greater). *) include S.T with type t = bytes list end -# 126 "v15.in.ml" +# 128 "v15.in.ml" module Operation : sig @@ -10813,7 +10859,7 @@ type t = {shell : shell_header; proto : bytes} include S.HASHABLE with type t := t and type hash := Operation_hash.t end -# 128 "v15.in.ml" +# 130 "v15.in.ml" module Context : sig @@ -11450,7 +11496,7 @@ module Cache : and type key = cache_key and type value = cache_value end -# 130 "v15.in.ml" +# 132 "v15.in.ml" module Updater : sig @@ -11979,7 +12025,7 @@ end not complete until [init] in invoked. *) val activate : Context.t -> Protocol_hash.t -> Context.t Lwt.t end -# 132 "v15.in.ml" +# 134 "v15.in.ml" module RPC_context : sig @@ -12133,7 +12179,7 @@ val make_opt_call3 : 'i -> 'o option shell_tzresult Lwt.t end -# 134 "v15.in.ml" +# 136 "v15.in.ml" module Context_binary : sig @@ -12176,7 +12222,7 @@ module Tree : val make_empty_context : ?root:string -> unit -> t end -# 136 "v15.in.ml" +# 138 "v15.in.ml" module Wasm_2_0_0 : sig @@ -12250,7 +12296,7 @@ module Make val get_info : Tree.tree -> info Lwt.t end end -# 138 "v15.in.ml" +# 140 "v15.in.ml" module Plonk : sig @@ -12369,7 +12415,7 @@ val scalar_array_encoding : scalar array Data_encoding.t on the given [inputs] according to the [public_parameters]. *) val verify : public_parameters -> verifier_inputs -> proof -> bool end -# 140 "v15.in.ml" +# 142 "v15.in.ml" module Dal : sig @@ -12524,7 +12570,7 @@ val share_is_trap : traps_fraction:Q.t -> (bool, [> `Decoding_error]) Result.t end -# 142 "v15.in.ml" +# 144 "v15.in.ml" module Skip_list : sig @@ -12756,7 +12802,7 @@ module Make (_ : sig val basis : int end) : S end -# 144 "v15.in.ml" +# 146 "v15.in.ml" module Smart_rollup : sig @@ -12813,6 +12859,6 @@ module Inbox_hash : S.HASH (** Smart rollup merkelized payload hashes' hash *) module Merkelized_payload_hashes_hash : S.HASH end -# 146 "v15.in.ml" +# 148 "v15.in.ml" end diff --git a/src/lib_protocol_environment/sigs/v15/bls_pop.mli b/src/lib_protocol_environment/sigs/v15/bls_pop.mli new file mode 100644 index 000000000000..b9f04fe1a975 --- /dev/null +++ b/src/lib_protocol_environment/sigs/v15/bls_pop.mli @@ -0,0 +1,40 @@ +(*****************************************************************************) +(* *) +(* Open Source License *) +(* Copyright (c) 2018 Dynamic Ledger Solutions, Inc. *) +(* Copyright (c) 2022 Nomadic Labs. *) +(* *) +(* Permission is hereby granted, free of charge, to any person obtaining a *) +(* copy of this software and associated documentation files (the "Software"),*) +(* to deal in the Software without restriction, including without limitation *) +(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *) +(* and/or sell copies of the Software, and to permit persons to whom the *) +(* Software is furnished to do so, subject to the following conditions: *) +(* *) +(* The above copyright notice and this permission notice shall be included *) +(* in all copies or substantial portions of the Software. *) +(* *) +(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*) +(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *) +(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *) +(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*) +(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *) +(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *) +(* DEALINGS IN THE SOFTWARE. *) +(* *) +(*****************************************************************************) + +(** Tezos - BLS12-381 cryptography *) + +include S.SIGNATURE with type watermark := bytes + +(** Module to access/expose the primitives of BLS12-381 *) +module Primitive : sig + module Fr : S.PRIME_FIELD + + module G1 : S.CURVE with type Scalar.t = Fr.t + + module G2 : S.CURVE with type Scalar.t = Fr.t + + val pairing_check : (G1.t * G2.t) list -> bool +end -- GitLab From 469b04afaa04909870d62fb5b8bbba22b7243aad Mon Sep 17 00:00:00 2001 From: Albin Coquereau Date: Fri, 14 Feb 2025 15:29:36 +0100 Subject: [PATCH 08/10] Env15: upgrade signature version to V2 --- devtools/yes_wallet/get_delegates_alpha.ml | 16 ++++++++++--- manifest/product_octez.ml | 23 +++++++++++++++---- .../environment_V15.ml | 18 +++++++-------- .../environment_V15.mli | 10 ++++---- src/lib_protocol_environment/sigs/v15.ml | 9 +++++--- .../sigs/v15/signature.mli | 9 +++++--- src/lib_wasm_debugger/messages.ml | 4 ++-- src/proto_alpha/lib_benchmark/dune | 4 ++-- .../lib_benchmark/michelson_samplers.ml | 2 +- src/proto_alpha/lib_benchmarks_proto/dune | 2 +- .../interpreter_benchmarks.ml | 7 ++++-- .../interpreter_workload.ml | 7 +++++- .../lib_client/client_proto_context.ml | 6 ++--- src/proto_alpha/lib_client/dune | 4 ++-- src/proto_alpha/lib_client/injection.ml | 9 ++++++-- .../client_proto_context_commands.ml | 4 ++-- src/proto_alpha/lib_client_commands/dune | 4 ++-- .../lib_dal/dal_plugin_registration.ml | 4 ++-- src/proto_alpha/lib_dal/dune | 2 +- .../lib_delegate/baking_actions.ml | 2 +- src/proto_alpha/lib_delegate/dune | 4 ++-- src/proto_alpha/lib_delegate/node_rpc.ml | 4 ++-- .../lib_delegate/test/mockup_simulator/dune | 2 +- .../lib_delegate/test/tenderbrute/lib/dune | 2 +- src/proto_alpha/lib_injector/dune | 4 ++-- src/proto_alpha/lib_parameters/dune | 2 +- src/proto_alpha/lib_plugin/dune | 2 +- src/proto_alpha/lib_plugin/mempool.ml | 2 +- src/proto_alpha/lib_protocol/alpha_context.ml | 2 +- src/proto_alpha/lib_protocol/apply.ml | 6 ++--- .../lib_protocol/contract_delegate_storage.ml | 4 ++-- src/proto_alpha/lib_protocol/contract_repr.ml | 3 ++- .../lib_protocol/delegate_consensus_key.ml | 4 ++-- .../lib_protocol/michelson_v1_gas.ml | 11 +++++---- .../lib_protocol/michelson_v1_gas.mli | 2 +- .../lib_protocol/script_typed_ir_size.ml | 5 ++-- src/proto_alpha/lib_protocol/storage.ml | 15 ++++++++---- .../lib_protocol/test/helpers/account.ml | 3 ++- .../lib_protocol/test/helpers/dune | 2 +- .../lib_protocol/test/helpers/op.ml | 11 ++++----- .../test/helpers/operation_generator.ml | 21 +++++++++++++---- .../integration/consensus/test_aggregate.ml | 2 +- .../consensus/test_consensus_key.ml | 4 ++-- .../integration/consensus/test_delegation.ml | 4 ++-- .../validate/generator_descriptors.ml | 2 +- .../test/unit/test_operation_repr.ml | 2 +- src/proto_alpha/lib_protocol/validate.ml | 19 +++++++-------- .../sc_rollup_proto_types.ml | 12 +++++----- .../lib_sc_rollup_node/daemon_helpers.ml | 14 +++++------ src/proto_alpha/lib_sc_rollup_node/dune | 2 +- .../lib_sc_rollup_node/layer1_helpers.ml | 2 +- .../lib_sc_rollup_node/pvm_plugin.ml | 2 +- .../refutation_game_helpers.ml | 4 ++-- .../lib_sc_rollup_node/sc_rollup_injector.ml | 2 +- .../test/test_octez_conversions.ml | 8 ++++--- .../alpha_machine.real.ml | 12 +++++----- 56 files changed, 209 insertions(+), 139 deletions(-) diff --git a/devtools/yes_wallet/get_delegates_alpha.ml b/devtools/yes_wallet/get_delegates_alpha.ml index e76e68a1b31c..bd31bb98f63e 100644 --- a/devtools/yes_wallet/get_delegates_alpha.ml +++ b/devtools/yes_wallet/get_delegates_alpha.ml @@ -40,9 +40,19 @@ module Get_delegates = struct end module Signature = struct - include Tezos_crypto.Signature.V1 - module To_latest = Tezos_crypto.Signature.V_latest.Of_V1 - module Of_latest = Tezos_crypto.Signature.V1.Of_V_latest + include Tezos_crypto.Signature.V2 + + module To_latest = struct + let public_key_hash = Fun.id + + let public_key = Fun.id + + let secret_key = Fun.id + + let signature = Fun.id + end + + module Of_latest = Tezos_crypto.Signature.V2.Of_V_latest end module Contract = struct diff --git a/manifest/product_octez.ml b/manifest/product_octez.ml index 37525b4f2ae5..69e0f9cb52fd 100644 --- a/manifest/product_octez.ml +++ b/manifest/product_octez.ml @@ -6453,7 +6453,12 @@ let hash = Protocol.hash module Ed25519 = Tezos_crypto.Signature.Ed25519 module P256 = Tezos_crypto.Signature.P256 module Secp256k1 = Tezos_crypto.Signature.Secp256k1 - include Tezos_crypto.Signature.V1|}); + %s|} + (if N.(number <= 022) then + {|include Tezos_crypto.Signature.V1|} + else + {|module Bls_pop = Tezos_crypto.Signature.Bls_pop + include Tezos_crypto.Signature.V2|})); ] in let dune_client_keys_version_rule = @@ -6464,7 +6469,10 @@ let hash = Protocol.hash [ S "write-file"; S "%{targets}"; - S (sf {|include Tezos_client_base.Client_keys_v1|}); + S + (sf + {|include Tezos_client_base.Client_keys_v%d|} + (if N.(number <= 022) then 1 else 2)); ]) in let parameters = @@ -7294,7 +7302,11 @@ let hash = Protocol.hash [ S "write-file"; S "%{targets}"; - S "include module type of Tezos_benchmark.Crypto_samplers.V1"; + S + (sf + "include module type of \ + Tezos_benchmark.Crypto_samplers.V%d" + (if N.(number <= 22) then 1 else 2)); ]; Dune.targets_rule ["crypto_samplers.ml"] @@ -7302,7 +7314,10 @@ let hash = Protocol.hash [ S "write-file"; S "%{targets}"; - S "include Tezos_benchmark.Crypto_samplers.V1"; + S + (sf + "include Tezos_benchmark.Crypto_samplers.V%d" + (if N.(number <= 22) then 1 else 2)); ]; ] in diff --git a/src/lib_protocol_environment/environment_V15.ml b/src/lib_protocol_environment/environment_V15.ml index 5b4485063671..ace0632bbbbe 100644 --- a/src/lib_protocol_environment/environment_V15.ml +++ b/src/lib_protocol_environment/environment_V15.ml @@ -89,11 +89,11 @@ module type T = sig Tezos_crypto.Signature.Bls_pop.Public_key.t and type Bls_pop.t = Tezos_crypto.Signature.Bls_pop.t and type Signature.public_key_hash = - Tezos_crypto.Signature.V1.public_key_hash - and type Signature.public_key = Tezos_crypto.Signature.V1.public_key - and type Signature.signature = Tezos_crypto.Signature.V1.signature - and type Signature.t = Tezos_crypto.Signature.V1.t - and type Signature.watermark = Tezos_crypto.Signature.V1.watermark + Tezos_crypto.Signature.V2.public_key_hash + and type Signature.public_key = Tezos_crypto.Signature.V2.public_key + and type Signature.signature = Tezos_crypto.Signature.V2.signature + and type Signature.t = Tezos_crypto.Signature.V2.t + and type Signature.watermark = Tezos_crypto.Signature.V2.watermark and type Micheline.canonical_location = Micheline.canonical_location and type 'a Micheline.canonical = 'a Micheline.canonical and type Z.t = Z.t @@ -346,7 +346,7 @@ struct module Bls_pop = Tezos_crypto.Signature.Bls_pop module Signature = struct - include Tezos_crypto.Signature.V1 + include Tezos_crypto.Signature.V2 let check ?watermark pk s bytes = (check @@ -361,7 +361,8 @@ struct | Ed25519 _ -> "check_signature_ed25519" | Secp256k1 _ -> "check_signature_secp256k1" | P256 _ -> "check_signature_p256" - | Bls_aug _ -> "check_signature_bls_aug"); + | Bls_aug _ -> "check_signature_bls_aug" + | Bls_pop _ -> "check_signature_bls_pop"); ]]) end @@ -1597,9 +1598,6 @@ 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.mli b/src/lib_protocol_environment/environment_V15.mli index b8a944fc2837..6cd1f336665a 100644 --- a/src/lib_protocol_environment/environment_V15.mli +++ b/src/lib_protocol_environment/environment_V15.mli @@ -89,11 +89,11 @@ module type T = sig Tezos_crypto.Signature.Bls_pop.Public_key.t and type Bls_pop.t = Tezos_crypto.Signature.Bls_pop.t and type Signature.public_key_hash = - Tezos_crypto.Signature.V1.public_key_hash - and type Signature.public_key = Tezos_crypto.Signature.V1.public_key - and type Signature.signature = Tezos_crypto.Signature.V1.signature - and type Signature.t = Tezos_crypto.Signature.V1.t - and type Signature.watermark = Tezos_crypto.Signature.V1.watermark + Tezos_crypto.Signature.V2.public_key_hash + and type Signature.public_key = Tezos_crypto.Signature.V2.public_key + and type Signature.signature = Tezos_crypto.Signature.V2.signature + and type Signature.t = Tezos_crypto.Signature.V2.t + and type Signature.watermark = Tezos_crypto.Signature.V2.watermark and type Micheline.canonical_location = Micheline.canonical_location and type 'a Micheline.canonical = 'a Micheline.canonical and type Z.t = Z.t diff --git a/src/lib_protocol_environment/sigs/v15.ml b/src/lib_protocol_environment/sigs/v15.ml index 012baf93f3e3..e9c628f6eb63 100644 --- a/src/lib_protocol_environment/sigs/v15.ml +++ b/src/lib_protocol_environment/sigs/v15.ml @@ -9971,13 +9971,15 @@ 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_aug.Public_key_hash.t + | Bls_aug of Bls_aug.Public_key_hash.t + | Bls_pop of Bls_pop.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_aug.Public_key.t + | Bls_aug of Bls_aug.Public_key.t + | Bls_pop of Bls_pop.Public_key.t type watermark = | Block_header of Chain_id.t @@ -9989,7 +9991,8 @@ type signature = | Ed25519 of Ed25519.t | Secp256k1 of Secp256k1.t | P256 of P256.t - | Bls of Bls_aug.t + | Bls_aug of Bls_aug.t + | Bls_pop of Bls_pop.t | Unknown of Bytes.t type prefix = Bls_prefix of Bytes.t diff --git a/src/lib_protocol_environment/sigs/v15/signature.mli b/src/lib_protocol_environment/sigs/v15/signature.mli index d97623b867bd..4565219aa6a1 100644 --- a/src/lib_protocol_environment/sigs/v15/signature.mli +++ b/src/lib_protocol_environment/sigs/v15/signature.mli @@ -28,13 +28,15 @@ 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_aug.Public_key_hash.t + | Bls_aug of Bls_aug.Public_key_hash.t + | Bls_pop of Bls_pop.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_aug.Public_key.t + | Bls_aug of Bls_aug.Public_key.t + | Bls_pop of Bls_pop.Public_key.t type watermark = | Block_header of Chain_id.t @@ -46,7 +48,8 @@ type signature = | Ed25519 of Ed25519.t | Secp256k1 of Secp256k1.t | P256 of P256.t - | Bls of Bls_aug.t + | Bls_aug of Bls_aug.t + | Bls_pop of Bls_pop.t | Unknown of Bytes.t type prefix = Bls_prefix of Bytes.t diff --git a/src/lib_wasm_debugger/messages.ml b/src/lib_wasm_debugger/messages.ml index 23cfc807ae1b..bee9fbae7e66 100644 --- a/src/lib_wasm_debugger/messages.ml +++ b/src/lib_wasm_debugger/messages.ml @@ -73,13 +73,13 @@ let input_encoding default_sender default_source default_destination : Sc_rollup.Inbox_message.( Internal (Transfer {payload; sender; source; destination})) -> let source = - Tezos_crypto.Signature.Of_V1.public_key_hash source + Tezos_crypto.Signature.Of_V2.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 + Signature.V2.Of_V_latest.get_public_key_hash_exn source in `Inbox_message (Internal (Transfer {payload; sender; source; destination}))); diff --git a/src/proto_alpha/lib_benchmark/dune b/src/proto_alpha/lib_benchmark/dune index 64a0fb6e287d..84af6abdc23e 100644 --- a/src/proto_alpha/lib_benchmark/dune +++ b/src/proto_alpha/lib_benchmark/dune @@ -37,8 +37,8 @@ (action (write-file %{targets} - "include module type of Tezos_benchmark.Crypto_samplers.V1"))) + "include module type of Tezos_benchmark.Crypto_samplers.V2"))) (rule (targets crypto_samplers.ml) - (action (write-file %{targets} "include Tezos_benchmark.Crypto_samplers.V1"))) + (action (write-file %{targets} "include Tezos_benchmark.Crypto_samplers.V2"))) diff --git a/src/proto_alpha/lib_benchmark/michelson_samplers.ml b/src/proto_alpha/lib_benchmark/michelson_samplers.ml index 469df205b720..d048ecf46c14 100644 --- a/src/proto_alpha/lib_benchmark/michelson_samplers.ml +++ b/src/proto_alpha/lib_benchmark/michelson_samplers.ml @@ -605,7 +605,7 @@ module Make let signature rng_state = Script_signature.make - (Tezos_crypto.Signature.V1.Of_V_latest.get_signature_exn + (Tezos_crypto.Signature.V2.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 = diff --git a/src/proto_alpha/lib_benchmarks_proto/dune b/src/proto_alpha/lib_benchmarks_proto/dune index 49c990be9ef0..b1dbb68a2590 100644 --- a/src/proto_alpha/lib_benchmarks_proto/dune +++ b/src/proto_alpha/lib_benchmarks_proto/dune @@ -48,4 +48,4 @@ (action (write-file %{targets} - " module Bls_aug = Tezos_crypto.Signature.Bls_aug\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"))) + " module Bls_aug = Tezos_crypto.Signature.Bls_aug\n module Ed25519 = Tezos_crypto.Signature.Ed25519\n module P256 = Tezos_crypto.Signature.P256\n module Secp256k1 = Tezos_crypto.Signature.Secp256k1\n module Bls_pop = Tezos_crypto.Signature.Bls_pop\n include Tezos_crypto.Signature.V2"))) diff --git a/src/proto_alpha/lib_benchmarks_proto/interpreter_benchmarks.ml b/src/proto_alpha/lib_benchmarks_proto/interpreter_benchmarks.ml index ed15db1546c9..415e6f8b81db 100644 --- a/src/proto_alpha/lib_benchmarks_proto/interpreter_benchmarks.ml +++ b/src/proto_alpha/lib_benchmarks_proto/interpreter_benchmarks.ml @@ -3084,7 +3084,8 @@ module Registration_section = struct | Signature.Ed25519 -> Interpreter_workload.N_ICheck_signature_ed25519 | Signature.Secp256k1 -> Interpreter_workload.N_ICheck_signature_secp256k1 | Signature.P256 -> Interpreter_workload.N_ICheck_signature_p256 - | Signature.Bls -> Interpreter_workload.N_ICheck_signature_bls + | Signature.Bls_aug -> Interpreter_workload.N_ICheck_signature_bls + | Signature.Bls_pop -> Interpreter_workload.N_ICheck_signature_bls let check_signature (algo : Signature.algo) ~benchmark_type ~for_intercept = benchmark_with_stack_sampler @@ -3120,7 +3121,9 @@ module Registration_section = struct let () = check_signature Signature.P256 - let () = check_signature Signature.Bls + let () = check_signature Signature.Bls_aug + + let () = check_signature Signature.Bls_pop let () = simple_time_alloc_benchmark diff --git a/src/proto_alpha/lib_benchmarks_proto/interpreter_workload.ml b/src/proto_alpha/lib_benchmarks_proto/interpreter_workload.ml index d18e6316cbd6..8dfb60450414 100644 --- a/src/proto_alpha/lib_benchmarks_proto/interpreter_workload.ml +++ b/src/proto_alpha/lib_benchmarks_proto/interpreter_workload.ml @@ -1459,10 +1459,15 @@ let extract_ir_sized_step : let signature = Size.of_int Signature.P256.size in let message = Size.bytes message in Instructions.check_signature_p256 pk signature message - | Signature.Bls pk -> + | Signature.Bls_aug pk -> let pk = Size.of_int (Signature.Bls_aug.Public_key.size pk) in let signature = Size.of_int Signature.Bls_aug.size in let message = Size.bytes message in + Instructions.check_signature_bls pk signature message + | Signature.Bls_pop pk -> + let pk = Size.of_int (Signature.Bls_pop.Public_key.size pk) in + let signature = Size.of_int Signature.Bls_pop.size in + let message = Size.bytes message in Instructions.check_signature_bls pk signature message) | IHash_key (_, _), _ -> Instructions.hash_key | IPack (_, ty, _), (v, _) -> ( diff --git a/src/proto_alpha/lib_client/client_proto_context.ml b/src/proto_alpha/lib_client/client_proto_context.ml index bb4c72523518..3bde6c0e24de 100644 --- a/src/proto_alpha/lib_client/client_proto_context.ml +++ b/src/proto_alpha/lib_client/client_proto_context.ml @@ -341,7 +341,7 @@ let build_update_consensus_key cctxt ?fee ?gas_limit ?storage_limit let open Lwt_result_syntax in let* proof = match ((public_key : Signature.public_key), secret_key_uri) with - | Bls _, Some secret_key_uri -> + | Bls_pop _, Some secret_key_uri -> let bytes = Data_encoding.Binary.to_bytes_exn Signature.Public_key.encoding @@ -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 = Tezos_crypto.Signature.Of_V1.public_key pk in - let sk = Tezos_crypto.Signature.Of_V1.secret_key sk in + let pk = Tezos_crypto.Signature.Of_V2.public_key pk in + let sk = Tezos_crypto.Signature.Of_V2.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 a6f90f08bf78..944bfcddc910 100644 --- a/src/proto_alpha/lib_client/dune +++ b/src/proto_alpha/lib_client/dune @@ -41,11 +41,11 @@ (rule (targets client_keys.ml) - (action (write-file %{targets} "include Tezos_client_base.Client_keys_v1"))) + (action (write-file %{targets} "include Tezos_client_base.Client_keys_v2"))) (rule (targets signature.ml) (action (write-file %{targets} - " module Bls_aug = Tezos_crypto.Signature.Bls_aug\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"))) + " module Bls_aug = Tezos_crypto.Signature.Bls_aug\n module Ed25519 = Tezos_crypto.Signature.Ed25519\n module P256 = Tezos_crypto.Signature.P256\n module Secp256k1 = Tezos_crypto.Signature.Secp256k1\n module Bls_pop = Tezos_crypto.Signature.Bls_pop\n include Tezos_crypto.Signature.V2"))) diff --git a/src/proto_alpha/lib_client/injection.ml b/src/proto_alpha/lib_client/injection.ml index 0644eeeae20f..59378b90319a 100644 --- a/src/proto_alpha/lib_client/injection.ml +++ b/src/proto_alpha/lib_client/injection.ml @@ -616,10 +616,14 @@ let signature_size_of_algo : Signature.algo -> int = function | Ed25519 -> Signature.Ed25519.size | Secp256k1 -> Signature.Secp256k1.size | P256 -> Signature.P256.size - | Bls -> + | Bls_aug -> (* BLS signatures in operations are encoded with 2 extra bytes: a [ff] prefix and a tag [03]. *) Signature.Bls_aug.size + 2 + | Bls_pop -> + (* BLS signatures in operations are encoded with 2 extra bytes: a [ff] + prefix and a tag [03]. *) + Signature.Bls_pop.size + 2 (* This value is used as a safety guard for gas limit. *) let default_safety_guard = Gas.Arith.(integral_of_int_exn 100) @@ -1502,7 +1506,8 @@ let inject_manager_operation cctxt ~chain ~block ?successor_level ?branch | Ed25519 _ -> Signature.Ed25519 | Secp256k1 _ -> Secp256k1 | P256 _ -> P256 - | Bls _ -> Bls + | Bls_aug _ -> Bls_aug + | Bls_pop _ -> Bls_pop in match key with | None when not (has_reveal operations) -> ( diff --git a/src/proto_alpha/lib_client_commands/client_proto_context_commands.ml b/src/proto_alpha/lib_client_commands/client_proto_context_commands.ml index e58f81f0b19c..72f045722217 100644 --- a/src/proto_alpha/lib_client_commands/client_proto_context_commands.ml +++ b/src/proto_alpha/lib_client_commands/client_proto_context_commands.ml @@ -2345,7 +2345,7 @@ let commands_rw () = in let* secret_key_uri = match public_key with - | Bls _ -> + | Bls_pop _ -> let pkh = Signature.Public_key.hash public_key in let* _, _, secret_key_uri = Client_keys.get_key cctxt pkh in return_some secret_key_uri @@ -2401,7 +2401,7 @@ let commands_rw () = in let* secret_key_uri = match public_key with - | Bls _ -> + | Bls_pop _ -> let pkh = Signature.Public_key.hash public_key in let* _, _, secret_key_uri = Client_keys.get_key cctxt pkh in return_some secret_key_uri diff --git a/src/proto_alpha/lib_client_commands/dune b/src/proto_alpha/lib_client_commands/dune index 75ff918c1fe0..44c1c41cd228 100644 --- a/src/proto_alpha/lib_client_commands/dune +++ b/src/proto_alpha/lib_client_commands/dune @@ -43,11 +43,11 @@ (action (write-file %{targets} - " module Bls_aug = Tezos_crypto.Signature.Bls_aug\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"))) + " module Bls_aug = Tezos_crypto.Signature.Bls_aug\n module Ed25519 = Tezos_crypto.Signature.Ed25519\n module P256 = Tezos_crypto.Signature.P256\n module Secp256k1 = Tezos_crypto.Signature.Secp256k1\n module Bls_pop = Tezos_crypto.Signature.Bls_pop\n include Tezos_crypto.Signature.V2"))) (rule (targets client_keys.ml) - (action (write-file %{targets} "include Tezos_client_base.Client_keys_v1"))) + (action (write-file %{targets} "include Tezos_client_base.Client_keys_v2"))) (library (name tezos_client_alpha_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 6c6a735d7967..de94df4be339 100644 --- a/src/proto_alpha/lib_dal/dal_plugin_registration.ml +++ b/src/proto_alpha/lib_dal/dal_plugin_registration.ml @@ -203,7 +203,7 @@ module Plugin = struct match operation_metadata.contents with | Single_result (Attestation_result result) -> let delegate = - Tezos_crypto.Signature.Of_V1.public_key_hash + Tezos_crypto.Signature.Of_V2.public_key_hash result.delegate in Some @@ -230,7 +230,7 @@ module Plugin = struct in List.fold_left (fun acc ({delegate; indexes} : Plugin.RPC.Dal.S.shards_assignment) -> - let delegate = Tezos_crypto.Signature.Of_V1.public_key_hash delegate in + let delegate = Tezos_crypto.Signature.Of_V2.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 diff --git a/src/proto_alpha/lib_dal/dune b/src/proto_alpha/lib_dal/dune index 23cc3edbe6ee..e5535884fe05 100644 --- a/src/proto_alpha/lib_dal/dune +++ b/src/proto_alpha/lib_dal/dune @@ -42,4 +42,4 @@ (action (write-file %{targets} - " module Bls_aug = Tezos_crypto.Signature.Bls_aug\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"))) + " module Bls_aug = Tezos_crypto.Signature.Bls_aug\n module Ed25519 = Tezos_crypto.Signature.Ed25519\n module P256 = Tezos_crypto.Signature.P256\n module Secp256k1 = Tezos_crypto.Signature.Secp256k1\n module Bls_pop = Tezos_crypto.Signature.Bls_pop\n include Tezos_crypto.Signature.V2"))) diff --git a/src/proto_alpha/lib_delegate/baking_actions.ml b/src/proto_alpha/lib_delegate/baking_actions.ml index 7e80347a0cc3..ac49e48988bd 100644 --- a/src/proto_alpha/lib_delegate/baking_actions.ml +++ b/src/proto_alpha/lib_delegate/baking_actions.ml @@ -680,7 +680,7 @@ let forge_and_sign_consensus_vote global_state ~branch unsigned_consensus_vote : let unsigned_operation = (shell, Contents_list contents) in let bls_mode = match delegate.consensus_key.public_key with - | Bls _ -> global_state.constants.parametric.aggregate_attestation + | Bls_pop _ -> global_state.constants.parametric.aggregate_attestation | _ -> false in let encoding = diff --git a/src/proto_alpha/lib_delegate/dune b/src/proto_alpha/lib_delegate/dune index 5ee936b1de7c..ed0233816721 100644 --- a/src/proto_alpha/lib_delegate/dune +++ b/src/proto_alpha/lib_delegate/dune @@ -58,11 +58,11 @@ (action (write-file %{targets} - " module Bls_aug = Tezos_crypto.Signature.Bls_aug\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"))) + " module Bls_aug = Tezos_crypto.Signature.Bls_aug\n module Ed25519 = Tezos_crypto.Signature.Ed25519\n module P256 = Tezos_crypto.Signature.P256\n module Secp256k1 = Tezos_crypto.Signature.Secp256k1\n module Bls_pop = Tezos_crypto.Signature.Bls_pop\n include Tezos_crypto.Signature.V2"))) (rule (targets client_keys.ml) - (action (write-file %{targets} "include Tezos_client_base.Client_keys_v1"))) + (action (write-file %{targets} "include Tezos_client_base.Client_keys_v2"))) (library (name tezos_baking_alpha_commands) diff --git a/src/proto_alpha/lib_delegate/node_rpc.ml b/src/proto_alpha/lib_delegate/node_rpc.ml index 3beb0f29b942..2f91fbc14337 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 - (((), Tezos_crypto.Signature.Of_V1.public_key_hash pkh), attested_level) + (((), Tezos_crypto.Signature.Of_V2.public_key_hash pkh), attested_level) () () @@ -408,7 +408,7 @@ let register_dal_profiles dal_node_rpc_ctxt delegates = ~attesters: (List.map (fun k -> - Tezos_crypto.Signature.Of_V1.public_key_hash + Tezos_crypto.Signature.Of_V2.public_key_hash @@ Consensus_key_id.to_pkh k.Consensus_key.id) delegates) () diff --git a/src/proto_alpha/lib_delegate/test/mockup_simulator/dune b/src/proto_alpha/lib_delegate/test/mockup_simulator/dune index 585a8363dd33..8ace2bb902ed 100644 --- a/src/proto_alpha/lib_delegate/test/mockup_simulator/dune +++ b/src/proto_alpha/lib_delegate/test/mockup_simulator/dune @@ -34,4 +34,4 @@ (rule (targets client_keys.ml) - (action (write-file %{targets} "include Tezos_client_base.Client_keys_v1"))) + (action (write-file %{targets} "include Tezos_client_base.Client_keys_v2"))) diff --git a/src/proto_alpha/lib_delegate/test/tenderbrute/lib/dune b/src/proto_alpha/lib_delegate/test/tenderbrute/lib/dune index a9dd124d7e93..32302b2c1f6f 100644 --- a/src/proto_alpha/lib_delegate/test/tenderbrute/lib/dune +++ b/src/proto_alpha/lib_delegate/test/tenderbrute/lib/dune @@ -25,4 +25,4 @@ (action (write-file %{targets} - " module Bls_aug = Tezos_crypto.Signature.Bls_aug\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"))) + " module Bls_aug = Tezos_crypto.Signature.Bls_aug\n module Ed25519 = Tezos_crypto.Signature.Ed25519\n module P256 = Tezos_crypto.Signature.P256\n module Secp256k1 = Tezos_crypto.Signature.Secp256k1\n module Bls_pop = Tezos_crypto.Signature.Bls_pop\n include Tezos_crypto.Signature.V2"))) diff --git a/src/proto_alpha/lib_injector/dune b/src/proto_alpha/lib_injector/dune index c787cbcc0990..248a7b8efb3c 100644 --- a/src/proto_alpha/lib_injector/dune +++ b/src/proto_alpha/lib_injector/dune @@ -24,11 +24,11 @@ (rule (targets client_keys.ml) - (action (write-file %{targets} "include Tezos_client_base.Client_keys_v1"))) + (action (write-file %{targets} "include Tezos_client_base.Client_keys_v2"))) (rule (targets signature.ml) (action (write-file %{targets} - " module Bls_aug = Tezos_crypto.Signature.Bls_aug\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"))) + " module Bls_aug = Tezos_crypto.Signature.Bls_aug\n module Ed25519 = Tezos_crypto.Signature.Ed25519\n module P256 = Tezos_crypto.Signature.P256\n module Secp256k1 = Tezos_crypto.Signature.Secp256k1\n module Bls_pop = Tezos_crypto.Signature.Bls_pop\n include Tezos_crypto.Signature.V2"))) diff --git a/src/proto_alpha/lib_parameters/dune b/src/proto_alpha/lib_parameters/dune index 1d511b572382..f0c121dca3bc 100644 --- a/src/proto_alpha/lib_parameters/dune +++ b/src/proto_alpha/lib_parameters/dune @@ -21,7 +21,7 @@ (action (write-file %{targets} - " module Bls_aug = Tezos_crypto.Signature.Bls_aug\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"))) + " module Bls_aug = Tezos_crypto.Signature.Bls_aug\n module Ed25519 = Tezos_crypto.Signature.Ed25519\n module P256 = Tezos_crypto.Signature.P256\n module Secp256k1 = Tezos_crypto.Signature.Secp256k1\n module Bls_pop = Tezos_crypto.Signature.Bls_pop\n include Tezos_crypto.Signature.V2"))) (executable (name gen) diff --git a/src/proto_alpha/lib_plugin/dune b/src/proto_alpha/lib_plugin/dune index ea6dc08c60a8..42538025632b 100644 --- a/src/proto_alpha/lib_plugin/dune +++ b/src/proto_alpha/lib_plugin/dune @@ -23,7 +23,7 @@ (action (write-file %{targets} - " module Bls_aug = Tezos_crypto.Signature.Bls_aug\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"))) + " module Bls_aug = Tezos_crypto.Signature.Bls_aug\n module Ed25519 = Tezos_crypto.Signature.Ed25519\n module P256 = Tezos_crypto.Signature.P256\n module Secp256k1 = Tezos_crypto.Signature.Secp256k1\n module Bls_pop = Tezos_crypto.Signature.Bls_pop\n include Tezos_crypto.Signature.V2"))) (library (name tezos_protocol_plugin_alpha_registerer) diff --git a/src/proto_alpha/lib_plugin/mempool.ml b/src/proto_alpha/lib_plugin/mempool.ml index ec10e413c976..402b0b6c57e2 100644 --- a/src/proto_alpha/lib_plugin/mempool.ml +++ b/src/proto_alpha/lib_plugin/mempool.ml @@ -804,7 +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 + let map_pkh_env = List.map Tezos_crypto.Signature.Of_V2.public_key_hash in match contents with | Single (Failing_noop _) -> return_nil | Single (Preattestation consensus_content) diff --git a/src/proto_alpha/lib_protocol/alpha_context.ml b/src/proto_alpha/lib_protocol/alpha_context.ml index 3ea45f381fc8..dda3070d4ad0 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.ml +++ b/src/proto_alpha/lib_protocol/alpha_context.ml @@ -224,7 +224,7 @@ module Operation = struct if Constants.aggregate_attestation ctxt then (* attestations signed by BLS keys uses a dedicated serialization encoding *) match (op.protocol_data.contents, key) with - | Single (Attestation _), Bls _ -> bls_mode_unsigned_encoding + | Single (Attestation _), Bls_pop _ -> bls_mode_unsigned_encoding | _ -> unsigned_encoding else unsigned_encoding in diff --git a/src/proto_alpha/lib_protocol/apply.ml b/src/proto_alpha/lib_protocol/apply.ml index e90b67ca03ec..3ce6a4ff9c81 100644 --- a/src/proto_alpha/lib_protocol/apply.ml +++ b/src/proto_alpha/lib_protocol/apply.ml @@ -1433,14 +1433,14 @@ let apply_manager_operation : in let* ctxt = match (public_key, proof) with - | Bls bls_public_key, Some (Bls _ as proof) -> + | Bls_pop bls_public_key, Some (Bls_pop _ as proof) -> let*? ctxt = let gas_cost_for_sig_check = let open Saturation_repr.Syntax in - let size = Bls_aug.Public_key.size bls_public_key in + let size = Bls_pop.Public_key.size bls_public_key in Operation_costs.serialization_cost size + Michelson_v1_gas.Cost_of.Interpreter.check_signature_on_algo - Bls + Bls_pop size in Gas.consume ctxt gas_cost_for_sig_check diff --git a/src/proto_alpha/lib_protocol/contract_delegate_storage.ml b/src/proto_alpha/lib_protocol/contract_delegate_storage.ml index c3d7df0f2db2..5949a4ee2253 100644 --- a/src/proto_alpha/lib_protocol/contract_delegate_storage.ml +++ b/src/proto_alpha/lib_protocol/contract_delegate_storage.ml @@ -45,8 +45,8 @@ let () = let check_not_tz4 : Signature.Public_key_hash.t -> unit tzresult = let open Result_syntax in function - | Bls tz4 -> tzfail (Forbidden_tz4_delegate tz4) - | Ed25519 _ | Secp256k1 _ | P256 _ -> return_unit + | Bls_aug tz4 -> tzfail (Forbidden_tz4_delegate tz4) + | Ed25519 _ | Secp256k1 _ | P256 _ | Bls_pop _ -> return_unit let find = Storage.Contract.Delegate.find diff --git a/src/proto_alpha/lib_protocol/contract_repr.ml b/src/proto_alpha/lib_protocol/contract_repr.ml index 3c304f3d9852..b10aff3fcc48 100644 --- a/src/proto_alpha/lib_protocol/contract_repr.ml +++ b/src/proto_alpha/lib_protocol/contract_repr.ml @@ -56,7 +56,8 @@ let implicit_of_b58data : Base58.data -> Signature.public_key_hash option = | Ed25519.Public_key_hash.Data h -> Some (Signature.Ed25519 h) | Secp256k1.Public_key_hash.Data h -> Some (Signature.Secp256k1 h) | P256.Public_key_hash.Data h -> Some (Signature.P256 h) - | Bls_aug.Public_key_hash.Data h -> Some (Signature.Bls h) + | Bls_aug.Public_key_hash.Data h -> Some (Signature.Bls_aug h) + | Bls_pop.Public_key_hash.Data h -> Some (Signature.Bls_pop h) | _ -> None let originated_of_b58data = function diff --git a/src/proto_alpha/lib_protocol/delegate_consensus_key.ml b/src/proto_alpha/lib_protocol/delegate_consensus_key.ml index 38cb284086bf..675b43aa0d2d 100644 --- a/src/proto_alpha/lib_protocol/delegate_consensus_key.ml +++ b/src/proto_alpha/lib_protocol/delegate_consensus_key.ml @@ -124,8 +124,8 @@ let check_unused ctxt pkh = let check_not_tz4 : Signature.Public_key.t -> unit tzresult = let open Result_syntax in function - | Bls pk -> tzfail (Invalid_consensus_key_update_tz4 pk) - | Ed25519 _ | Secp256k1 _ | P256 _ -> return_unit + | Bls_aug pk -> tzfail (Invalid_consensus_key_update_tz4 pk) + | Ed25519 _ | Secp256k1 _ | P256 _ | Bls_pop _ -> return_unit let set_unused = Storage.Consensus_keys.remove diff --git a/src/proto_alpha/lib_protocol/michelson_v1_gas.ml b/src/proto_alpha/lib_protocol/michelson_v1_gas.ml index 7598a54cee07..9390782e74e4 100644 --- a/src/proto_alpha/lib_protocol/michelson_v1_gas.ml +++ b/src/proto_alpha/lib_protocol/michelson_v1_gas.ml @@ -304,28 +304,31 @@ module Cost_of = struct let view = atomic_step_cost cost_N_IView - type algo = Ed25519 | Secp256k1 | P256 | Bls + type algo = Ed25519 | Secp256k1 | P256 | Bls_aug | Bls_pop let algo_of_public_key (pkey : Signature.public_key) = match pkey with | Ed25519 _ -> Ed25519 | Secp256k1 _ -> Secp256k1 | P256 _ -> P256 - | Bls _ -> Bls + | Bls_aug _ -> Bls_aug + | Bls_pop _ -> Bls_pop let algo_of_public_key_hash (pkh : Signature.public_key_hash) = match pkh with | Ed25519 _ -> Ed25519 | Secp256k1 _ -> Secp256k1 | P256 _ -> P256 - | Bls _ -> Bls + | Bls_aug _ -> Bls_aug + | Bls_pop _ -> Bls_pop let check_signature_on_algo algo length = match algo with | Ed25519 -> cost_N_ICheck_signature_ed25519 length | Secp256k1 -> cost_N_ICheck_signature_secp256k1 length | P256 -> cost_N_ICheck_signature_p256 length - | Bls -> cost_N_ICheck_signature_bls length + | Bls_aug -> cost_N_ICheck_signature_bls length + | Bls_pop -> cost_N_ICheck_signature_bls length let check_signature pkey b = check_signature_on_algo (algo_of_public_key pkey) (Bytes.length b) diff --git a/src/proto_alpha/lib_protocol/michelson_v1_gas.mli b/src/proto_alpha/lib_protocol/michelson_v1_gas.mli index 530321c16332..f0650fe01d1d 100644 --- a/src/proto_alpha/lib_protocol/michelson_v1_gas.mli +++ b/src/proto_alpha/lib_protocol/michelson_v1_gas.mli @@ -239,7 +239,7 @@ module Cost_of : sig val dip : Gas.cost - type algo = Ed25519 | Secp256k1 | P256 | Bls + type algo = Ed25519 | Secp256k1 | P256 | Bls_aug | Bls_pop val algo_of_public_key : Signature.public_key -> algo diff --git a/src/proto_alpha/lib_protocol/script_typed_ir_size.ml b/src/proto_alpha/lib_protocol/script_typed_ir_size.ml index e3ade406d01d..95ba5df7ca08 100644 --- a/src/proto_alpha/lib_protocol/script_typed_ir_size.ml +++ b/src/proto_alpha/lib_protocol/script_typed_ir_size.ml @@ -127,7 +127,7 @@ let signature_size (Script_signature.Signature_tag x) = match x with (* By Obj.reachable_words. *) | Ed25519 _ | Secp256k1 _ | P256 _ | Unknown _ -> !!96 - | Bls _ -> !!128 + | Bls_aug _ | Bls_pop _ -> !!128 let key_hash_size (_x : Signature.public_key_hash) = !!64 (* By Obj.reachable_words. *) @@ -139,7 +139,8 @@ let public_key_size (x : public_key) = | Ed25519 _ -> 64 | Secp256k1 _ -> 72 | P256 _ -> 96 - | Bls _ -> 64 + | Bls_aug _ -> 64 + | Bls_pop _ -> 64 let mutez_size = h2w diff --git a/src/proto_alpha/lib_protocol/storage.ml b/src/proto_alpha/lib_protocol/storage.ml index db7ac5b27737..1570780aef4a 100644 --- a/src/proto_alpha/lib_protocol/storage.ml +++ b/src/proto_alpha/lib_protocol/storage.ml @@ -1067,13 +1067,15 @@ module Public_key_hash = struct module Path_Secp256k1 = Path_encoding.Make_hex (Secp256k1.Public_key_hash) module Path_P256 = Path_encoding.Make_hex (P256.Public_key_hash) module Path_Bls_aug = Path_encoding.Make_hex (Bls_aug.Public_key_hash) + module Path_Bls_pop = Path_encoding.Make_hex (Bls_pop.Public_key_hash) let to_path (key : public_key_hash) l = match key with | Ed25519 h -> "ed25519" :: Path_Ed25519.to_path h l | Secp256k1 h -> "secp256k1" :: Path_Secp256k1.to_path h l | P256 h -> "p256" :: Path_P256.to_path h l - | Bls h -> "bls" :: Path_Bls_aug.to_path h l + | Bls_aug h -> "bls" :: Path_Bls_aug.to_path h l + | Bls_pop h -> "bls_pop" :: Path_Bls_pop.to_path h l let of_path : _ -> public_key_hash option = function | "ed25519" :: rest -> ( @@ -1090,7 +1092,11 @@ module Public_key_hash = struct | None -> None) | "bls" :: rest -> ( match Path_Bls_aug.of_path rest with - | Some pkh -> Some (Bls pkh) + | Some pkh -> Some (Bls_aug pkh) + | None -> None) + | "bls_pop" :: rest -> ( + match Path_Bls_pop.of_path rest with + | Some pkh -> Some (Bls_pop pkh) | None -> None) | _ -> None @@ -1098,8 +1104,9 @@ module Public_key_hash = struct let l1 = Path_Ed25519.path_length and l2 = Path_Secp256k1.path_length and l3 = Path_P256.path_length - and l4 = Path_Bls_aug.path_length in - assert (Compare.Int.(l1 = l2 && l2 = l3 && l3 = l4)) ; + and l4 = Path_Bls_aug.path_length + and l5 = Path_Bls_pop.path_length in + assert (Compare.Int.(l1 = l2 && l2 = l3 && l3 = l4 && l4 = l5)) ; l1 + 1 end diff --git a/src/proto_alpha/lib_protocol/test/helpers/account.ml b/src/proto_alpha/lib_protocol/test/helpers/account.ml index c784bada9a14..29a69f894467 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/account.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/account.ml @@ -45,7 +45,8 @@ let random_algo ~rng_state : Signature.algo = | 0 -> Ed25519 | 1 -> Secp256k1 | 2 -> P256 - | 3 -> Bls + | 3 -> Bls_aug + | 4 -> Bls_pop | _ -> assert false let new_account ?(rng_state = Random.State.make_self_init ()) diff --git a/src/proto_alpha/lib_protocol/test/helpers/dune b/src/proto_alpha/lib_protocol/test/helpers/dune index e97e8678e805..6edd765b99ff 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/dune +++ b/src/proto_alpha/lib_protocol/test/helpers/dune @@ -43,4 +43,4 @@ (action (write-file %{targets} - " module Bls_aug = Tezos_crypto.Signature.Bls_aug\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"))) + " module Bls_aug = Tezos_crypto.Signature.Bls_aug\n module Ed25519 = Tezos_crypto.Signature.Ed25519\n module P256 = Tezos_crypto.Signature.P256\n module Secp256k1 = Tezos_crypto.Signature.Secp256k1\n module Bls_pop = Tezos_crypto.Signature.Bls_pop\n include Tezos_crypto.Signature.V2"))) diff --git a/src/proto_alpha/lib_protocol/test/helpers/op.ml b/src/proto_alpha/lib_protocol/test/helpers/op.ml index 527b8c92a083..bca6e255eee4 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/op.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/op.ml @@ -142,7 +142,8 @@ let aggregate attestations = op in match (contents, signature) with - | Single (Attestation {consensus_content; _}), Some (Bls bls_sig) -> ( + | Single (Attestation {consensus_content; _}), Some (Bls_pop bls_sig) + -> ( let {slot; _} = consensus_content in match acc with | Some (shell, proposal, slots, signatures) -> @@ -157,14 +158,12 @@ let aggregate attestations = in let open Option_syntax in let* shell, consensus_content, committee, signatures = aggregate_content in - let+ signature = - Bls12_381_signature.MinPk.aggregate_signature_opt signatures - in + let+ signature = Signature.Bls_pop.aggregate_signature_opt signatures in let contents = Single (Attestations_aggregate {consensus_content; committee}) in let protocol_data = - Operation_data {contents; signature = Some (Bls signature)} + Operation_data {contents; signature = Some (Bls_pop signature)} in {shell; protocol_data} @@ -196,7 +195,7 @@ let attestations_aggregate ?committee ?level ?round ?block_payload_hash ?branch @@ List.filter_map (fun attester -> match attester.Plugin.RPC.Validators.consensus_key with - | Bls _ -> Some attester.delegate + | Bls_pop _ -> Some attester.delegate | _ -> None) attesters in diff --git a/src/proto_alpha/lib_protocol/test/helpers/operation_generator.ml b/src/proto_alpha/lib_protocol/test/helpers/operation_generator.ml index 0e2f77e32de6..43d4fbf253fb 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/operation_generator.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/operation_generator.ml @@ -168,7 +168,14 @@ let random_tz3 = let random_tz4 = let open QCheck2.Gen in let+ str = string_size (pure Signature.Bls_aug.Public_key_hash.size) in - (Bls (Signature.Bls_aug.Public_key_hash.of_string_exn str) : public_key_hash) + (Bls_aug (Signature.Bls_aug.Public_key_hash.of_string_exn str) + : public_key_hash) + +let random_tz5 = + let open QCheck2.Gen in + let+ str = string_size (pure Signature.Bls_pop.Public_key_hash.size) in + (Bls_pop (Signature.Bls_pop.Public_key_hash.of_string_exn str) + : public_key_hash) let random_pkh = let open QCheck2.Gen in @@ -177,7 +184,8 @@ let random_pkh = | Ed25519 -> random_tz1 | Secp256k1 -> random_tz2 | P256 -> random_tz3 - | Bls -> random_tz4 + | Bls_aug -> random_tz4 + | Bls_pop -> random_tz5 let random_pk = let open QCheck2.Gen in @@ -200,9 +208,13 @@ let random_signature = | Some P256 -> let+ str = string_size (pure Signature.P256.size) in (P256 (Signature.P256.of_string_exn str) : Signature.t) - | Some Bls -> + | Some Bls_aug -> + let+ seed = random_seed in + let _, _, sk = Signature.generate_key ~algo:Bls_aug ~seed () in + Signature.sign sk Bytes.empty + | Some Bls_pop -> let+ seed = random_seed in - let _, _, sk = Signature.generate_key ~algo:Bls ~seed () in + let _, _, sk = Signature.generate_key ~algo:Bls_pop ~seed () in Signature.sign sk Bytes.empty let random_signature = @@ -215,6 +227,7 @@ let random_signature = of_secp256k1 Signature.Secp256k1.zero; of_p256 Signature.P256.zero; of_bls Signature.Bls_aug.zero; + of_bls_pop Signature.Bls_pop.zero; Unknown (Bytes.make 64 '\000'); ] () diff --git a/src/proto_alpha/lib_protocol/test/integration/consensus/test_aggregate.ml b/src/proto_alpha/lib_protocol/test/integration/consensus/test_aggregate.ml index feaa83e51025..e768e30366e2 100644 --- a/src/proto_alpha/lib_protocol/test/integration/consensus/test_aggregate.ml +++ b/src/proto_alpha/lib_protocol/test/integration/consensus/test_aggregate.ml @@ -21,7 +21,7 @@ let init_genesis_with_some_bls_accounts ?policy ?dal_enable let*? random_accounts = Account.generate_accounts 3 in let*? bls_accounts = List.init ~when_negative_length:[] 2 (fun _ -> - Account.new_account ~algo:Signature.Bls ()) + Account.new_account ~algo:Signature.Bls_pop ()) in let bootstrap_accounts = Account.make_bootstrap_accounts (random_accounts @ bls_accounts) diff --git a/src/proto_alpha/lib_protocol/test/integration/consensus/test_consensus_key.ml b/src/proto_alpha/lib_protocol/test/integration/consensus/test_consensus_key.ml index 4b34ea5ffcd4..ee481b758941 100644 --- a/src/proto_alpha/lib_protocol/test/integration/consensus/test_consensus_key.ml +++ b/src/proto_alpha/lib_protocol/test/integration/consensus/test_consensus_key.ml @@ -214,7 +214,7 @@ let test_tz4_consensus_key ~allow_tz4_delegate_enable () = Context.init_with_constants1 {constants with allow_tz4_delegate_enable} in let account1_pkh = Context.Contract.pkh contract in - let consensus_account = Account.new_account ~algo:Bls () in + let consensus_account = Account.new_account ~algo:Bls_aug () in let delegate = account1_pkh in let consensus_pk = consensus_account.pk in let consensus_pkh = consensus_account.pkh in @@ -224,7 +224,7 @@ let test_tz4_consensus_key ~allow_tz4_delegate_enable () = let* operation = Op.update_consensus_key (B blk') (Contract.Implicit delegate) consensus_pk in - let tz4_pk = match consensus_pk with Bls pk -> pk | _ -> assert false in + let tz4_pk = match consensus_pk with Bls_aug pk -> pk | _ -> assert false in let* inc = Incremental.begin_construction blk' in if allow_tz4_delegate_enable then let expect_failure = function diff --git a/src/proto_alpha/lib_protocol/test/integration/consensus/test_delegation.ml b/src/proto_alpha/lib_protocol/test/integration/consensus/test_delegation.ml index 823913dfe20c..0ab0c0482231 100644 --- a/src/proto_alpha/lib_protocol/test/integration/consensus/test_delegation.ml +++ b/src/proto_alpha/lib_protocol/test/integration/consensus/test_delegation.ml @@ -1557,7 +1557,7 @@ let test_bls_account_self_delegate ~allow_tz4_delegate_enable () = Context.init1 ~consensus_threshold_size:0 ~allow_tz4_delegate_enable () in let {Account.pkh = tz4_pkh; pk = tz4_pk; _} = - Account.new_account ~algo:Bls () + Account.new_account ~algo:Bls_aug () in let tz4_contract = Alpha_context.Contract.Implicit tz4_pkh in let* operation = @@ -1573,7 +1573,7 @@ let test_bls_account_self_delegate ~allow_tz4_delegate_enable () = let* b = Block.bake ~operation b in let* operation = Op.delegation (B b) tz4_contract (Some tz4_pkh) in let* inc = Incremental.begin_construction b in - let tz4_pkh = match tz4_pkh with Bls pkh -> pkh | _ -> assert false in + let tz4_pkh = match tz4_pkh with Bls_aug pkh -> pkh | _ -> assert false in if allow_tz4_delegate_enable then let* (_i : Incremental.t) = Incremental.validate_operation inc operation in return_unit diff --git a/src/proto_alpha/lib_protocol/test/integration/validate/generator_descriptors.ml b/src/proto_alpha/lib_protocol/test/integration/validate/generator_descriptors.ml index c82f7520c2e8..9e5e7fadd397 100644 --- a/src/proto_alpha/lib_protocol/test/integration/validate/generator_descriptors.ml +++ b/src/proto_alpha/lib_protocol/test/integration/validate/generator_descriptors.ml @@ -665,7 +665,7 @@ let attestations_aggregate_descriptor = let delegate = Option.value ~default:delegate consensus_key_opt in let* signer = Account.find delegate in match (slots_opt, signer.sk) with - | Some (_ :: _), Bls _ -> + | Some (_ :: _), Bls_pop _ -> let* op = Op.raw_attestation ~delegate state.block in return (Some op) | _, _ -> return_none) diff --git a/src/proto_alpha/lib_protocol/test/unit/test_operation_repr.ml b/src/proto_alpha/lib_protocol/test/unit/test_operation_repr.ml index ff4731b53c0b..4994da84ddc9 100644 --- a/src/proto_alpha/lib_protocol/test/unit/test_operation_repr.ml +++ b/src/proto_alpha/lib_protocol/test/unit/test_operation_repr.ml @@ -96,7 +96,7 @@ module Test_operation_repr = struct | Error _ -> return_unit let zero_bls = - match Signature.(split_signature (Bls Signature.Bls_aug.zero)) with + match Signature.(split_signature (Bls_aug Signature.Bls_aug.zero)) with | {prefix = None; _} -> assert false | {prefix = Some prefix; suffix} -> let prefix = diff --git a/src/proto_alpha/lib_protocol/validate.ml b/src/proto_alpha/lib_protocol/validate.ml index 67c90412733d..13979cb47c84 100644 --- a/src/proto_alpha/lib_protocol/validate.ml +++ b/src/proto_alpha/lib_protocol/validate.ml @@ -2355,26 +2355,27 @@ module Manager = struct let open Result_syntax in if Constants.allow_tz4_delegate_enable vi.ctxt then match (public_key, proof) with - | Bls _bls_public_key, None -> + | Bls_pop _bls_public_key, None -> result_error (Validate_errors.Manager.Update_consensus_key_with_tz4_without_proof {source; public_key}) - | ( Bls _bls_public_key, + | ( Bls_pop _bls_public_key, Some - ((Signature.Ed25519 _ | Signature.Secp256k1 _ | Signature.P256 _) as - proof) ) -> + (( Signature.Ed25519 _ | Signature.Secp256k1 _ | Signature.P256 _ + | Signature.Bls_aug _ ) as proof) ) -> result_error (Validate_errors.Manager.Update_consensus_key_with_incorrect_proof {public_key; proof}) - | Bls bls_public_key, Some (Signature.Bls _ | Signature.Unknown _) -> + | Bls_pop bls_public_key, Some (Signature.Bls_pop _ | Signature.Unknown _) + -> (* Compute the gas cost to encode the consensus public key and check the proof. *) let gas_cost_for_sig_check = let open Saturation_repr.Syntax in - let size = Bls_aug.Public_key.size bls_public_key in + let size = Bls_pop.Public_key.size bls_public_key in Operation_costs.serialization_cost size + Michelson_v1_gas.Cost_of.Interpreter.check_signature_on_algo - Bls + Bls_pop size in let* (_ : Gas.Arith.fp) = @@ -2385,11 +2386,11 @@ module Manager = struct gas_cost_for_sig_check) in return_unit - | (Ed25519 _ | Secp256k1 _ | P256 _), Some _proof -> + | (Ed25519 _ | Secp256k1 _ | P256 _ | Bls_aug _), Some _proof -> result_error (Validate_errors.Manager.Update_consensus_key_with_unused_proof {source; public_key}) - | (Ed25519 _ | Secp256k1 _ | P256 _), None -> return_unit + | (Ed25519 _ | Secp256k1 _ | P256 _ | Bls_aug _), None -> return_unit else let* () = Delegate.Consensus_key.check_not_tz4 public_key in if Option.is_some proof then 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 c3ef8ca13b04..6e7071b54b95 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 @@ -332,13 +332,13 @@ module Game = struct let index_of_octez Octez_smart_rollup.Game.{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) + (Signature.V2.Of_V_latest.get_public_key_hash_exn alice) + (Signature.V2.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 - (Signature.Of_V1.public_key_hash alice) - (Signature.Of_V1.public_key_hash bob) + (Signature.Of_V2.public_key_hash alice) + (Signature.Of_V2.public_key_hash bob) let player_of_octez : Octez_smart_rollup.Game.player -> player = function | Alice -> Alice @@ -438,7 +438,7 @@ module Game = struct {other; their_commitment; our_commitment; parent_commitment} : conflict = { - other = Signature.V1.Of_V_latest.get_public_key_hash_exn other; + other = Signature.V2.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; @@ -449,7 +449,7 @@ module Game = struct {other; their_commitment; our_commitment; parent_commitment} : Octez_smart_rollup.Game.conflict = { - other = Signature.Of_V1.public_key_hash other; + other = Signature.Of_V2.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 fe5dd0cb5c04..6ffbfe183ed9 100644 --- a/src/proto_alpha/lib_sc_rollup_node/daemon_helpers.ml +++ b/src/proto_alpha/lib_sc_rollup_node/daemon_helpers.ml @@ -219,7 +219,7 @@ let process_included_l1_operation (type kind) ~catching_up | Loser {loser; reason} when Node_context.is_operator node_ctxt - (Tezos_crypto.Signature.Of_V1.public_key_hash loser) -> + (Tezos_crypto.Signature.Of_V2.public_key_hash loser) -> let result = match reason with | Conflict_resolved -> Sc_rollup_node_errors.Conflict_resolved @@ -233,11 +233,11 @@ let process_included_l1_operation (type kind) ~catching_up let stakers = match operation with | Sc_rollup_refute {opponent; _} -> - [source; Tezos_crypto.Signature.Of_V1.public_key_hash opponent] + [source; Tezos_crypto.Signature.Of_V2.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; + Tezos_crypto.Signature.Of_V2.public_key_hash alice; + Tezos_crypto.Signature.Of_V2.public_key_hash bob; ] | _ -> assert false in @@ -264,7 +264,7 @@ let process_included_l1_operation (type kind) ~catching_up fail_when Tezos_crypto.Signature.Public_key_hash.( operating_pkh - = Tezos_crypto.Signature.Of_V1.public_key_hash staker) + = Tezos_crypto.Signature.Of_V2.public_key_hash staker) Sc_rollup_node_errors.Exit_bond_recovered_bailout_mode | _ -> return_unit) | ( Sc_rollup_execute_outbox_message {output_proof; _}, @@ -309,7 +309,7 @@ let process_included_l1_operation (type kind) ~catching_up else let whitelist_update = List.map - Tezos_crypto.Signature.Of_V1.public_key_hash + Tezos_crypto.Signature.Of_V2.public_key_hash whitelist_update in let*? () = @@ -385,7 +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 + let source = Tezos_crypto.Signature.Of_V2.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 a341906fa2b3..47a88d6dc224 100644 --- a/src/proto_alpha/lib_sc_rollup_node/dune +++ b/src/proto_alpha/lib_sc_rollup_node/dune @@ -79,4 +79,4 @@ (action (write-file %{targets} - " module Bls_aug = Tezos_crypto.Signature.Bls_aug\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"))) + " module Bls_aug = Tezos_crypto.Signature.Bls_aug\n module Ed25519 = Tezos_crypto.Signature.Ed25519\n module P256 = Tezos_crypto.Signature.P256\n module Secp256k1 = Tezos_crypto.Signature.Secp256k1\n module Bls_pop = Tezos_crypto.Signature.Bls_pop\n include Tezos_crypto.Signature.V2"))) 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 3fce20a4ca9d..6aae50684e54 100644 --- a/src/proto_alpha/lib_sc_rollup_node/layer1_helpers.ml +++ b/src/proto_alpha/lib_sc_rollup_node/layer1_helpers.ml @@ -248,7 +248,7 @@ let find_whitelist cctxt ?block rollup_address = in return @@ Option.map - (List.map Tezos_crypto.Signature.Of_V1.public_key_hash) + (List.map Tezos_crypto.Signature.Of_V2.public_key_hash) whitelist let find_last_whitelist_update cctxt rollup_address = 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 a257b8e54882..c82840b2ba18 100644 --- a/src/proto_alpha/lib_sc_rollup_node/pvm_plugin.ml +++ b/src/proto_alpha/lib_sc_rollup_node/pvm_plugin.ml @@ -157,7 +157,7 @@ let outbox_message_summary (output : Sc_rollup.output) = | {message = Whitelist_update pkhs; _} -> Outbox_message.Whitelist_update (Option.map - (List.map Tezos_crypto.Signature.Of_V1.public_key_hash) + (List.map Tezos_crypto.Signature.Of_V2.public_key_hash) pkhs) | {message = Atomic_transaction_batch {transactions}; _} -> let transactions = List.map outbox_transaction_summary transactions in 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 8378d7ace894..e56084bdca8a 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 @@ -412,6 +412,6 @@ let get_ongoing_games cctxt rollup staker = List.map (fun (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 )) + Tezos_crypto.Signature.Of_V2.public_key_hash staker1, + Tezos_crypto.Signature.Of_V2.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 3a393a0517b8..05ffd2e39309 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 @@ -104,7 +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 + let opponent = Tezos_crypto.Signature.Of_V2.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 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 0ca3339ea0a6..6acc5ba6df14 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 @@ -111,15 +111,17 @@ let random_seed ~rng_state = Char.chr (Random.State.int rng_state 256)) let random_algo ~rng_state : Signature.algo = - match Random.State.int rng_state 3 with + match Random.State.int rng_state 4 with | 0 -> Ed25519 | 1 -> Secp256k1 | 2 -> P256 - | 3 -> Bls + | 3 -> Bls_aug + | 4 -> Bls_pop | _ -> assert false let gen_algo = - QCheck2.Gen.oneofl [Tezos_crypto.Signature.Ed25519; Secp256k1; P256; Bls_aug] + QCheck2.Gen.oneofl + [Tezos_crypto.Signature.Ed25519; Secp256k1; P256; Bls_aug; Bls_pop] let gen_pkh = let open QCheck2.Gen in diff --git a/teztale/bin_teztale_archiver/alpha_machine.real.ml b/teztale/bin_teztale_archiver/alpha_machine.real.ml index 6778f95186df..07f2d4f4b774 100644 --- a/teztale/bin_teztale_archiver/alpha_machine.real.ml +++ b/teztale/bin_teztale_archiver/alpha_machine.real.ml @@ -46,7 +46,7 @@ module Services : Protocol_machinery.PROTOCOL_SERVICES = struct Consensus_ops. { address = - Tezos_crypto.Signature.Of_V1.public_key_hash delegate; + Tezos_crypto.Signature.Of_V2.public_key_hash delegate; first_slot = slot_to_int first_slot; power = attestation_power; }) @@ -160,7 +160,7 @@ module Services : Protocol_machinery.PROTOCOL_SERVICES = struct cycle_info metadata cctxt (cctxt#chain, `Hash (hash, 0)) in return - ( Tezos_crypto.Signature.Of_V1.public_key_hash + ( Tezos_crypto.Signature.Of_V2.public_key_hash metadata.protocol_data.baker.delegate, cycle_info ) @@ -177,7 +177,7 @@ module Services : Protocol_machinery.PROTOCOL_SERVICES = struct List.rev_map (fun ({delegate; round; _} : RPC.Baking_rights.t) -> { - Data.delegate = Tezos_crypto.Signature.Of_V1.public_key_hash delegate; + Data.delegate = Tezos_crypto.Signature.Of_V2.public_key_hash delegate; round = Protocol.Alpha_context.Round.to_int32 round; }) baking_rights @@ -243,7 +243,7 @@ module Services : Protocol_machinery.PROTOCOL_SERVICES = struct round = Some (get_preattestation_round protocol_data); kind = Consensus_ops.Preattestation; }; - delegate = Tezos_crypto.Signature.Of_V1.public_key_hash delegate; + delegate = Tezos_crypto.Signature.Of_V2.public_key_hash delegate; power = consensus_power; } :: acc @@ -263,7 +263,7 @@ module Services : Protocol_machinery.PROTOCOL_SERVICES = struct round = Some (get_attestation_round protocol_data); kind = Consensus_ops.Attestation; }; - delegate = Tezos_crypto.Signature.Of_V1.public_key_hash delegate; + delegate = Tezos_crypto.Signature.Of_V2.public_key_hash delegate; power = consensus_power; } :: acc @@ -282,7 +282,7 @@ 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 - ( ( Tezos_crypto.Signature.Of_V1.public_key_hash + ( ( Tezos_crypto.Signature.Of_V2.public_key_hash metadata.protocol_data.baker.delegate, header.shell.timestamp, round, -- GitLab From 8fa19c6fc4106d1d75635a729b87ab569fed99ba Mon Sep 17 00:00:00 2001 From: Albin Coquereau Date: Thu, 30 Jan 2025 14:05:52 +0100 Subject: [PATCH 09/10] bls: add new aggregate functions --- src/lib_bls12_381/bls12_381.ml | 4 + src/lib_bls12_381/bls12_381.mli | 5 ++ src/lib_bls12_381/g1.ml | 12 ++- src/lib_bls12_381/g2.ml | 9 +++ .../bls12_381_signature.ml | 74 +++++++++++++++++++ .../bls12_381_signature.mli | 16 ++++ 6 files changed, 118 insertions(+), 2 deletions(-) diff --git a/src/lib_bls12_381/bls12_381.ml b/src/lib_bls12_381/bls12_381.ml index 953efe3e32cb..1770d8011fd1 100644 --- a/src/lib_bls12_381/bls12_381.ml +++ b/src/lib_bls12_381/bls12_381.ml @@ -81,6 +81,10 @@ module type CURVE = sig representing a point in compressed form. *) val of_compressed_bytes_opt : Bytes.t -> t option + (** Similar to [of_compressed_bytes_opt] but does not check if the point is in + the prim subgroup. *) + val of_compressed_bytes_without_check_opt : Bytes.t -> t option + (** Allocates a new point from a byte array of length [size_in_bytes / 2] representing a point in compressed form. Raise {!Not_on_curve} if the point is not on the curve. *) diff --git a/src/lib_bls12_381/bls12_381.mli b/src/lib_bls12_381/bls12_381.mli index 492e2ff65226..12161dc4a7e4 100644 --- a/src/lib_bls12_381/bls12_381.mli +++ b/src/lib_bls12_381/bls12_381.mli @@ -163,6 +163,11 @@ module type CURVE = sig *) val of_compressed_bytes_opt : Bytes.t -> t option + (** Similar to [of_compressed_bytes_opt] but does not check if the point is in + the prim subgroup + *) + val of_compressed_bytes_without_check_opt : Bytes.t -> t option + (** Allocates a new point from a byte array of length [size_in_bytes / 2] representing a point in compressed form. Raise {!Not_on_curve} if the point is not on the curve and in the prime subgroup. *) diff --git a/src/lib_bls12_381/g1.ml b/src/lib_bls12_381/g1.ml index 16a719b7c07c..a345be35b4f1 100644 --- a/src/lib_bls12_381/g1.ml +++ b/src/lib_bls12_381/g1.ml @@ -199,13 +199,21 @@ module G1 = struct let size_in_memory = Obj.reachable_words (Obj.repr one) * 8 let of_compressed_bytes_opt bs = + let buffer_affine = Stubs.allocate_g1_affine () in + let res = Stubs.uncompress buffer_affine bs in + if res = 0 then + let buffer = Stubs.allocate_g1 () in + let is_in_prime_subgroup = Stubs.in_g1 buffer in + if is_in_prime_subgroup then Some buffer else None + else None + + let of_compressed_bytes_without_check_opt bs = let buffer_affine = Stubs.allocate_g1_affine () in let res = Stubs.uncompress buffer_affine bs in if res = 0 then ( let buffer = Stubs.allocate_g1 () in ignore @@ Stubs.from_affine buffer buffer_affine ; - let is_in_prime_subgroup = Stubs.in_g1 buffer in - if is_in_prime_subgroup then Some buffer else None) + Some buffer) else None let of_compressed_bytes_exn bs = diff --git a/src/lib_bls12_381/g2.ml b/src/lib_bls12_381/g2.ml index 4fb5452cb1a3..15172bf34063 100644 --- a/src/lib_bls12_381/g2.ml +++ b/src/lib_bls12_381/g2.ml @@ -187,6 +187,15 @@ module G2 = struct if is_in_prime_subgroup then Some buffer else None) else None + let of_compressed_bytes_without_check_opt bs = + let buffer_affine = Stubs.allocate_g2_affine () in + let res = Stubs.uncompress buffer_affine bs in + if res = 0 then ( + let buffer = Stubs.allocate_g2 () in + ignore @@ Stubs.from_affine buffer buffer_affine ; + Some buffer) + else None + let of_compressed_bytes_exn bs = match of_compressed_bytes_opt bs with | None -> raise (Not_on_curve bs) diff --git a/src/lib_bls12_381_signature/bls12_381_signature.ml b/src/lib_bls12_381_signature/bls12_381_signature.ml index 72779d7c39bd..5195bcabcff9 100644 --- a/src/lib_bls12_381_signature/bls12_381_signature.ml +++ b/src/lib_bls12_381_signature/bls12_381_signature.ml @@ -418,6 +418,43 @@ module MinPk = struct pks_with_pops in pop_checks && signature_check + + let aggregate_pks pks = + let rec go acc = function + | [] -> Some acc + | pk :: pks -> ( + let pk_opt = + Bls12_381.G1.of_compressed_bytes_without_check_opt pk + in + match pk_opt with + | None -> None + | Some pk -> + let acc = Bls12_381.G1.add acc pk in + go acc pks) + in + if List.is_empty pks then None + else + Option.map Bls12_381.G1.to_compressed_bytes (go Bls12_381.G1.zero pks) + + let remove_pks_from_aggregate pks aggregated_pk = + let rec go acc = function + | [] -> Some acc + | pk :: pks -> ( + let pk_opt = + Bls12_381.G1.of_compressed_bytes_without_check_opt pk + in + match pk_opt with + | None -> None + | Some pk -> + let acc = Bls12_381.G1.(add acc (negate pk)) in + go acc pks) + in + match + Bls12_381.G1.of_compressed_bytes_without_check_opt aggregated_pk + with + | None -> None + | Some aggregated_pks -> + Option.map Bls12_381.G1.to_compressed_bytes (go aggregated_pks pks) end end @@ -725,5 +762,42 @@ module MinSig = struct pks_with_pops in pop_checks && signature_check + + let aggregate_pks pks = + let rec go acc = function + | [] -> Some acc + | pk :: pks -> ( + let pk_opt = + Bls12_381.G2.of_compressed_bytes_without_check_opt pk + in + match pk_opt with + | None -> None + | Some pk -> + let acc = Bls12_381.G2.add acc pk in + go acc pks) + in + if List.is_empty pks then None + else + Option.map Bls12_381.G2.to_compressed_bytes (go Bls12_381.G2.zero pks) + + let remove_pks_from_aggregate pks aggregated_pk = + let rec go acc = function + | [] -> Some acc + | pk :: pks -> ( + let pk_opt = + Bls12_381.G2.of_compressed_bytes_without_check_opt pk + in + match pk_opt with + | None -> None + | Some pk -> + let acc = Bls12_381.G2.(add acc (negate pk)) in + go acc pks) + in + match + Bls12_381.G2.of_compressed_bytes_without_check_opt aggregated_pk + with + | None -> None + | Some aggregated_pks -> + Option.map Bls12_381.G2.to_compressed_bytes (go aggregated_pks pks) end end diff --git a/src/lib_bls12_381_signature/bls12_381_signature.mli b/src/lib_bls12_381_signature/bls12_381_signature.mli index a29bf3573329..243a8b647307 100644 --- a/src/lib_bls12_381_signature/bls12_381_signature.mli +++ b/src/lib_bls12_381_signature/bls12_381_signature.mli @@ -207,6 +207,14 @@ module MinPk : sig {{:https://datatracker.ietf.org/doc/html/draft-irtf-cfrg-bls-signature-04#section-3.3.4} section 3.3.4}. *) val aggregate_verify : (pk * proof) list -> Bytes.t -> signature -> bool + + (** [aggregate_pks pks] only perform the aggregation of public key part of + [aggregate_verify] and return the aggregated public key. *) + val aggregate_pks : pk list -> pk option + + (** [remove_pks_from_aggregate pks aggregate] remove the list of public keys + [pks] from the [aggregate]. *) + val remove_pks_from_aggregate : pk list -> pk -> pk option end end @@ -390,5 +398,13 @@ module MinSig : sig https://datatracker.ietf.org/doc/html/draft-irtf-cfrg-bls-signature-04#section-3.3.4 } section 3.3.4 }*) val aggregate_verify : (pk * proof) list -> Bytes.t -> signature -> bool + + (** [aggregate_pks pks] only perform the aggregation of public key part of + [aggregate_verify] and return the aggregated public key. *) + val aggregate_pks : pk list -> pk option + + (** [remove_pks_from_aggregate pks aggregate] remove the list of public keys + [pks] from the [aggregate]. *) + val remove_pks_from_aggregate : pk list -> pk -> pk option end end -- GitLab From 2e66e63a99e61bae542d9470c2e894fb03e7976c Mon Sep 17 00:00:00 2001 From: Albin Coquereau Date: Fri, 14 Feb 2025 17:06:50 +0100 Subject: [PATCH 10/10] Lib_crypto/bls_pop: add public key aggregation function --- src/lib_crypto/bls_pop.ml | 5 +++++ src/lib_crypto/bls_pop.mli | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/src/lib_crypto/bls_pop.ml b/src/lib_crypto/bls_pop.ml index 9cd350772f91..89fdc398b7bc 100644 --- a/src/lib_crypto/bls_pop.ml +++ b/src/lib_crypto/bls_pop.ml @@ -363,6 +363,11 @@ let deterministic_nonce_hash sk msg = let aggregate_signature_opt = Bls12_381_signature.MinPk.aggregate_signature_opt +let aggregate_pks = Bls12_381_signature.MinPk.Pop.aggregate_pks + +let remove_pks_from_aggregate = + Bls12_381_signature.MinPk.Pop.remove_pks_from_aggregate + module Primitive = struct include Bls12_381 diff --git a/src/lib_crypto/bls_pop.mli b/src/lib_crypto/bls_pop.mli index 2b652d9e0c98..8caeb317582c 100644 --- a/src/lib_crypto/bls_pop.mli +++ b/src/lib_crypto/bls_pop.mli @@ -41,3 +41,8 @@ module Primitive : sig end val aggregate_signature_opt : t list -> t option + +val aggregate_pks : Public_key.t list -> Public_key.t option + +val remove_pks_from_aggregate : + Public_key.t list -> Public_key.t -> Public_key.t option -- GitLab