diff --git a/src/lib_client_base/client_keys.mli b/src/lib_client_base/client_keys.mli index 72211eb8306980518c6da866607f2eceff8a1a52..e6e6b96826dc99702ce741f3a2a6c7506ca14942 100644 --- a/src/lib_client_base/client_keys.mli +++ b/src/lib_client_base/client_keys.mli @@ -101,10 +101,6 @@ module PVSS_secret_key : Client_aliases.Alias with type t = pvss_sk_uri See [Client_aliases] for more information about Aliases.*) module Aggregate_alias : sig - type pk_uri = private Uri.t - - type sk_uri = private Uri.t - module Public_key_hash : Client_aliases.Alias with type t = Aggregate_signature.Public_key_hash.t diff --git a/src/lib_crypto/bls.ml b/src/lib_crypto/bls.ml index 78211ff6c903dac2f7a798d8e8e237846161fbe9..efe345b27e4f1d300cd380eb9aceb9d51c6cb7b6 100644 --- a/src/lib_crypto/bls.ml +++ b/src/lib_crypto/bls.ml @@ -143,7 +143,10 @@ module Secret_key = struct include Compare.Make (struct type nonrec t = t - let compare a b = Stdlib.compare a b + 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 diff --git a/src/lib_crypto/bls.mli b/src/lib_crypto/bls.mli index 530df18ef647c4a37d8660df2eb193b20549aea6..3be4352c4b408de569abf41374d18611bdf5ed81 100644 --- a/src/lib_crypto/bls.mli +++ b/src/lib_crypto/bls.mli @@ -23,6 +23,10 @@ (* *) (*****************************************************************************) -include S.AGGREGATE_SIGNATURE +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 include S.RAW_DATA with type t := t diff --git a/src/proto_alpha/bin_tx_rollup_client/commands.ml b/src/proto_alpha/bin_tx_rollup_client/commands.ml index ab167477b21524ba1c182b22ce625e1723acb8fd..6c5b9b67a2a5214af2a306970f6a4a0a14db2421 100644 --- a/src/proto_alpha/bin_tx_rollup_client/commands.ml +++ b/src/proto_alpha/bin_tx_rollup_client/commands.ml @@ -104,7 +104,7 @@ let sign_transaction sks txs = Tx_rollup_l2_batch.V1.transaction_encoding txs in - List.map (fun sk -> Bls12_381.Signature.MinPk.Aug.sign sk buf) sks + List.map (fun sk -> Bls.sign sk buf) sks let craft_tx ~counter ~signer ~destination ~ticket_hash ~qty = let content = @@ -120,7 +120,7 @@ let craft_tx ~counter ~signer ~destination ~ticket_hash ~qty = Tx_rollup_l2_batch.V1.{signer; counter; contents = [content]} let aggregate_signature_exn signatures = - match Bls12_381.Signature.MinPk.aggregate_signature_opt signatures with + match Bls.aggregate_signature_opt signatures with | Some res -> res | None -> invalid_arg "aggregate_signature_exn" @@ -149,13 +149,7 @@ let craft_batch let conv_pk = Clic.parameter (fun _ pk_str -> - let bls_pk = - Tezos_crypto.Bls.Public_key.of_b58check_exn pk_str - |> Data_encoding.Binary.to_bytes_exn - Tezos_crypto.Bls.Public_key.encoding - |> Bls12_381.Signature.MinPk.pk_of_bytes_exn - in - return bls_pk) + return (Bls.Public_key.of_b58check_exn pk_str)) let conv_qty = Clic.parameter (fun _ qty -> @@ -218,18 +212,10 @@ let batch_of_json ~txs:tx_json ~sks:sks_json = Data_encoding.( Json.destruct (list Tx_rollup_l2_batch.V1.transaction_encoding) tx_json) in - let signatures = - Data_encoding.( - Json.destruct (list (list Tezos_crypto.Bls.Secret_key.encoding)) sks_json) - in - let signatures = - List.map - (List.map (fun v -> - Data_encoding.Binary.to_bytes_exn Bls.Secret_key.encoding v - |> Bls12_381.Signature.sk_of_bytes_exn)) - signatures + let sks = + Data_encoding.(Json.destruct (list (list Bls.Secret_key.encoding)) sks_json) in - craft_batch transactions signatures + craft_batch transactions sks let craft_tx_batch () = command diff --git a/src/proto_alpha/lib_benchmark/michelson_samplers.ml b/src/proto_alpha/lib_benchmark/michelson_samplers.ml index 0ced7ddd8a71ee272f37f15f625b2afcac46fc6f..a480cc3b989467734e88bd30e07ce9e144adad75 100644 --- a/src/proto_alpha/lib_benchmark/michelson_samplers.ml +++ b/src/proto_alpha/lib_benchmark/michelson_samplers.ml @@ -521,10 +521,9 @@ end) let seed = Bytes.init 32 (fun _ -> char_of_int @@ Random.State.int rng_state 255) in - let secret_key = Bls12_381.Signature.generate_sk seed in + let (_pkh, public_key, _secret_key) = Bls.generate_key ~seed () in Tx_rollup_l2_address.Indexable.value - (Tx_rollup_l2_address.of_bls_pk - @@ Bls12_381.Signature.MinPk.derive_pk secret_key) + (Tx_rollup_l2_address.of_bls_pk public_key) let chain_id rng_state = let string = Base_samplers.uniform_string ~nbytes:4 rng_state in diff --git a/src/proto_alpha/lib_protocol/test/helpers/tx_rollup_l2_helpers.ml b/src/proto_alpha/lib_protocol/test/helpers/tx_rollup_l2_helpers.ml index 496f781594cb5281b3513e8e1895781ed5465295..f254a406668f715089dfb3290b767da229a43639 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/tx_rollup_l2_helpers.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/tx_rollup_l2_helpers.ml @@ -99,11 +99,7 @@ let rng_state = Random.State.make_self_init () let gen_l1_address ?seed () = Signature.generate_key ~algo:Ed25519 ?seed () let gen_l2_address () = - let seed = - Bytes.init 32 (fun _ -> char_of_int @@ Random.State.int rng_state 255) - in - let secret_key = Bls12_381.Signature.generate_sk seed in - let public_key = Bls12_381.Signature.MinPk.derive_pk secret_key in + let (_pkh, public_key, secret_key) = Bls.generate_key () in (secret_key, public_key, Tx_rollup_l2_address.of_bls_pk public_key) (** [make_unit_ticket_key ctxt ticketer l2_address] computes the key hash of @@ -157,7 +153,7 @@ let gen_n_ticket_hash n = | Error _ -> raise (Invalid_argument "Failed to forge tickets") let sign_transaction : - Bls12_381.Signature.sk list -> + Bls.Secret_key.t list -> ('signer, 'content) Tx_rollup_l2_batch.V1.transaction -> Tx_rollup_l2_batch.V1.signature list = fun sks transaction -> @@ -169,8 +165,7 @@ let sign_transaction : Tx_rollup_l2_batch.V1.transaction_encoding transaction in - - List.map (fun sk -> Bls12_381.Signature.MinPk.Aug.sign sk buf) sks + List.map (fun sk -> Bls.sign sk buf) sks type Environment.Error_monad.error += Test_error of string diff --git a/src/proto_alpha/lib_protocol/test/integration/operations/test_tx_rollup.ml b/src/proto_alpha/lib_protocol/test/integration/operations/test_tx_rollup.ml index e6a69322c4d7f181def03feafee8ad386ee4dba8..94b403ed8dadbdf1cbbcce10588bdea6d0d2c955 100644 --- a/src/proto_alpha/lib_protocol/test/integration/operations/test_tx_rollup.ml +++ b/src/proto_alpha/lib_protocol/test/integration/operations/test_tx_rollup.ml @@ -293,12 +293,9 @@ let inbox_testable = Alcotest.testable Tx_rollup_inbox.pp Tx_rollup_inbox.( = ) let rng_state = Random.State.make_self_init () -let gen_l2_account ?(rng_state = rng_state) () = - let seed = - Bytes.init 32 (fun _ -> char_of_int @@ Random.State.int rng_state 255) - in - let secret_key = Bls12_381.Signature.generate_sk seed in - let public_key = Bls12_381.Signature.MinPk.derive_pk secret_key in +let gen_l2_account () = + (* TODO: when add bls into env6 we could use directly the pkh *) + let (_pkh, public_key, secret_key) = Bls.generate_key () in (secret_key, public_key, Tx_rollup_l2_address.of_bls_pk public_key) (** [make_ticket_key ty contents ticketer tx_rollup] computes the ticket hash @@ -329,8 +326,6 @@ let make_unit_ticket_key ctxt ~ticketer tx_rollup = let contents = Prim (0, D_Unit, [], []) in make_ticket_key ctxt ~ty ~contents ~ticketer tx_rollup -let rng_state = Random.State.make_self_init () - let print_deposit_arg tx_rollup account = let open Alpha_context.Script in Format.sprintf @@ -3417,7 +3412,6 @@ module Rejection = struct Tezos operation even in the worst cases. *) let test_rejection_size_limit () = - let rng_state = Random.State.make [|42|] in context_init1 () >>=? fun (b, account) -> originate b account >>=? fun (b, tx_rollup) -> Context.get_constants (B b) >>=? fun constant -> @@ -3430,8 +3424,7 @@ module Rejection = struct we add in the context, bigger the proofs becomes. It needs to be adjusted so the following [message2] in this context produces a proof that is larger to 30Kb. *) - List.init ~when_negative_length:[] 200 (fun _ -> - gen_l2_account ~rng_state ()) + List.init ~when_negative_length:[] 200 (fun _ -> gen_l2_account ()) >>?= fun l2_accounts -> (* The context is filled with the generated l2 accounts. *) fill_store store l2_accounts >>= fun store -> @@ -3447,7 +3440,7 @@ module Rejection = struct in (* Then, we build a real message which is close to the maximum message size limit and produces a proof also close to the maximum proof size limit. *) - let (_sk, _pk, addr) = gen_l2_account ~rng_state () in + let (_sk, _pk, addr) = gen_l2_account () in let (signers, transfers) = List.map (fun (sk, pk, _) -> diff --git a/src/proto_alpha/lib_protocol/test/pbt/test_tx_rollup_l2_encoding.ml b/src/proto_alpha/lib_protocol/test/pbt/test_tx_rollup_l2_encoding.ml index 7d40ce4da5626c6205480bffac7ef4c2f8746048..02cd7382a32530fbee918d1f317083af80eb05d4 100644 --- a/src/proto_alpha/lib_protocol/test/pbt/test_tx_rollup_l2_encoding.ml +++ b/src/proto_alpha/lib_protocol/test/pbt/test_tx_rollup_l2_encoding.ml @@ -48,8 +48,8 @@ let bls_pk = `Hex "8fee216367c463821f82c942a1cee3a01469b1da782736ca269a2accea6e0cc4" |> Hex.to_bytes_exn in - let secret_key = Bls12_381.Signature.generate_sk ikm in - Bls12_381.Signature.MinPk.derive_pk secret_key + let (_pkh, public_key, _secret_key) = Bls.generate_key ~seed:ikm () in + public_key let l2_address = Protocol.Tx_rollup_l2_address.of_bls_pk bls_pk diff --git a/src/proto_alpha/lib_protocol/test/unit/test_tx_rollup_l2_apply.ml b/src/proto_alpha/lib_protocol/test/unit/test_tx_rollup_l2_apply.ml index 8b704e6dcd617e3c4501ba80bcf28d2f15ed057b..a65d58cc46dfde8fd6d6fd22d98c7e93fda91e4a 100644 --- a/src/proto_alpha/lib_protocol/test/unit/test_tx_rollup_l2_apply.ml +++ b/src/proto_alpha/lib_protocol/test/unit/test_tx_rollup_l2_apply.ml @@ -84,7 +84,7 @@ let expect_error_status ~msg error status cont = let aggregate_signature_exn : signature list -> signature = fun signatures -> - match Bls12_381.Signature.MinPk.aggregate_signature_opt signatures with + match Bls.aggregate_signature_opt signatures with | Some res -> res | None -> raise (Invalid_argument "aggregate_signature_exn") @@ -125,9 +125,10 @@ let pp_metadata fmt Tx_rollup_l2_context_sig.{counter; public_key} = let counter = Int64.to_int counter in Format.fprintf fmt - "{counter=%d; public_key=%s}" + "{counter=%d; public_key=%a}" counter - (Environment.Bls_signature.pk_to_bytes public_key |> Bytes.to_string) + Bls.Public_key.pp + public_key let eq_metadata = Alcotest.of_pp pp_metadata @@ -282,12 +283,8 @@ let batch_from_transfers inputs = (fun all_sks input -> List.fold_left (fun acc (sk, _, _, _, _, _) -> - let equal x y = - Bytes.equal - (Bls12_381.Signature.sk_to_bytes x) - (Bls12_381.Signature.sk_to_bytes y) - in - if List.mem ~equal sk acc then acc else sk :: acc) + if List.mem ~equal:Bls.Secret_key.equal sk acc then acc + else sk :: acc) [] input :: all_sks) diff --git a/tezt/tests/tx_rollup_node.ml b/tezt/tests/tx_rollup_node.ml index 4ca0a5830e5a5801ee17e2babf2489e2eab80592..288a8ef9e1df9055877ede500befd5b4d3a1193c 100644 --- a/tezt/tests/tx_rollup_node.ml +++ b/tezt/tests/tx_rollup_node.ml @@ -638,7 +638,7 @@ let sign_one_transaction key txs_string = Tx_rollup_l2_batch.V1.transaction_encoding (List.hd txs) in - Bls12_381.Signature.MinPk.Aug.sign (bls_sk_of_key key) buf + Tezos_crypto.Bls.sign (bls_sk_of_key key) buf let craft_tx ?counter tx_client ~qty ~signer ~dest ~ticket = let* json_str =