From cd7cd964d48174da2468e8a5133966c9828fec77 Mon Sep 17 00:00:00 2001 From: Victor Allombert Date: Thu, 7 Nov 2024 14:32:05 +0100 Subject: [PATCH 1/3] 021_PsQuebec/Baker: rework delegate's consensus key event --- src/proto_021_PsQuebec/lib_delegate/baking_events.ml | 4 +++- src/proto_021_PsQuebec/lib_delegate/baking_state.ml | 12 ++++++++++++ src/proto_021_PsQuebec/lib_delegate/baking_state.mli | 6 ++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/proto_021_PsQuebec/lib_delegate/baking_events.ml b/src/proto_021_PsQuebec/lib_delegate/baking_events.ml index adbccc199f06..1c23c031239b 100644 --- a/src/proto_021_PsQuebec/lib_delegate/baking_events.ml +++ b/src/proto_021_PsQuebec/lib_delegate/baking_events.ml @@ -613,7 +613,9 @@ module Delegates = struct Format.( pp_print_list ~pp_sep:pp_print_cut Baking_state.pp_consensus_key) delegates) - ("delegates", Data_encoding.list Baking_state.consensus_key_encoding) + ( "delegates", + Data_encoding.list + Baking_state.consensus_key_without_sk_encoding__cannot_decode ) end module Scheduling = struct diff --git a/src/proto_021_PsQuebec/lib_delegate/baking_state.ml b/src/proto_021_PsQuebec/lib_delegate/baking_state.ml index 8f3e9e823153..6c6a12dd621f 100644 --- a/src/proto_021_PsQuebec/lib_delegate/baking_state.ml +++ b/src/proto_021_PsQuebec/lib_delegate/baking_state.ml @@ -62,6 +62,18 @@ let consensus_key_encoding = (req "public_key_hash" Signature.Public_key_hash.encoding) (req "secret_key_uri" string)) +let consensus_key_without_sk_encoding__cannot_decode = + let open Data_encoding in + conv + (fun {alias; public_key; public_key_hash; _} -> + (alias, public_key, public_key_hash)) + (fun (_alias, _public_key, _public_key_hash) -> + Stdlib.failwith "Unexpected secret key") + (obj3 + (req "alias" (option string)) + (req "public_key" Signature.Public_key.encoding) + (req "public_key_hash" Signature.Public_key_hash.encoding)) + let pp_consensus_key fmt {alias; public_key_hash; _} = match alias with | None -> Format.fprintf fmt "%a" Signature.Public_key_hash.pp public_key_hash diff --git a/src/proto_021_PsQuebec/lib_delegate/baking_state.mli b/src/proto_021_PsQuebec/lib_delegate/baking_state.mli index 0244ed7342b7..6ba1c4857e43 100644 --- a/src/proto_021_PsQuebec/lib_delegate/baking_state.mli +++ b/src/proto_021_PsQuebec/lib_delegate/baking_state.mli @@ -35,6 +35,12 @@ type consensus_key = { val consensus_key_encoding : consensus_key Data_encoding.t +(* Encodes the consensus_key but removes the [secret_key_uri] to avoid + leaking information. + Warning: this encoding was designed to encode, decoding will fail. *) +val consensus_key_without_sk_encoding__cannot_decode : + consensus_key Data_encoding.t + val pp_consensus_key : Format.formatter -> consensus_key -> unit type consensus_key_and_delegate = consensus_key * Signature.Public_key_hash.t -- GitLab From 7801cea6d84e687404349ac12f56612635a08e74 Mon Sep 17 00:00:00 2001 From: Victor Allombert Date: Thu, 20 Mar 2025 09:50:15 +0100 Subject: [PATCH 2/3] 022_PsRiotum/Baker: rework delegate's consensus key event --- src/proto_022_PsRiotum/lib_delegate/baking_events.ml | 5 ++++- src/proto_022_PsRiotum/lib_delegate/baking_state.ml | 11 +++++++++++ src/proto_022_PsRiotum/lib_delegate/baking_state.mli | 5 +++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/proto_022_PsRiotum/lib_delegate/baking_events.ml b/src/proto_022_PsRiotum/lib_delegate/baking_events.ml index 3365dbeaf8e0..eef4f1f65efd 100644 --- a/src/proto_022_PsRiotum/lib_delegate/baking_events.ml +++ b/src/proto_022_PsRiotum/lib_delegate/baking_events.ml @@ -600,7 +600,10 @@ module Delegates = struct Format.( pp_print_list ~pp_sep:pp_print_cut Baking_state.Consensus_key.pp) delegates) - ("delegates", Data_encoding.list Baking_state.Consensus_key.encoding) + ( "delegates", + Data_encoding.list + Baking_state.Consensus_key + .consensus_key_without_sk_encoding__cannot_decode ) end module Scheduling = struct diff --git a/src/proto_022_PsRiotum/lib_delegate/baking_state.ml b/src/proto_022_PsRiotum/lib_delegate/baking_state.ml index 01dfd7829c40..e6728319de67 100644 --- a/src/proto_022_PsRiotum/lib_delegate/baking_state.ml +++ b/src/proto_022_PsRiotum/lib_delegate/baking_state.ml @@ -77,6 +77,17 @@ module Consensus_key = struct (req "public_key_hash" Signature.Public_key_hash.encoding) (req "secret_key_uri" string)) + let consensus_key_without_sk_encoding__cannot_decode = + let open Data_encoding in + conv + (fun {alias; public_key; id; _} -> (alias, public_key, id)) + (fun (_alias, _public_key, _id) -> + Stdlib.failwith "Unexpected secret key") + (obj3 + (req "alias" (option string)) + (req "public_key" Signature.Public_key.encoding) + (req "public_key_hash" Signature.Public_key_hash.encoding)) + let pp fmt {alias; id; _} = match alias with | None -> Format.fprintf fmt "%a" Signature.Public_key_hash.pp id diff --git a/src/proto_022_PsRiotum/lib_delegate/baking_state.mli b/src/proto_022_PsRiotum/lib_delegate/baking_state.mli index 69c475605825..ee6b1ba11d87 100644 --- a/src/proto_022_PsRiotum/lib_delegate/baking_state.mli +++ b/src/proto_022_PsRiotum/lib_delegate/baking_state.mli @@ -63,6 +63,11 @@ module Consensus_key : sig val encoding : t Data_encoding.t + (* Encodes the consensus_key but removes the [secret_key_uri] to avoid + leaking information. + Warning: this encoding was designed to encode, decoding will fail. *) + val consensus_key_without_sk_encoding__cannot_decode : t Data_encoding.t + val pp : Format.formatter -> t -> unit end -- GitLab From e4d73c319e276c5f4facfad5ee714475ff03e8f3 Mon Sep 17 00:00:00 2001 From: Victor Allombert Date: Thu, 20 Mar 2025 09:50:48 +0100 Subject: [PATCH 3/3] alpha/Baker: rework delegate's consensus key event Porting to proto alpha 8c6b2522d49e23d4925f4555bd65a188968cac30 - 022_PsRiotum/Baker: rework delegate's consensus key event --- src/proto_alpha/lib_delegate/baking_events.ml | 5 ++++- src/proto_alpha/lib_delegate/baking_state.ml | 11 +++++++++++ src/proto_alpha/lib_delegate/baking_state.mli | 5 +++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/proto_alpha/lib_delegate/baking_events.ml b/src/proto_alpha/lib_delegate/baking_events.ml index 93641c311045..b96204b7fbff 100644 --- a/src/proto_alpha/lib_delegate/baking_events.ml +++ b/src/proto_alpha/lib_delegate/baking_events.ml @@ -607,7 +607,10 @@ module Delegates = struct Format.( pp_print_list ~pp_sep:pp_print_cut Baking_state.Consensus_key.pp) delegates) - ("delegates", Data_encoding.list Baking_state.Consensus_key.encoding) + ( "delegates", + Data_encoding.list + Baking_state.Consensus_key + .consensus_key_without_sk_encoding__cannot_decode ) end module Scheduling = struct diff --git a/src/proto_alpha/lib_delegate/baking_state.ml b/src/proto_alpha/lib_delegate/baking_state.ml index daf2cdf5f059..ffb4130dfa6d 100644 --- a/src/proto_alpha/lib_delegate/baking_state.ml +++ b/src/proto_alpha/lib_delegate/baking_state.ml @@ -77,6 +77,17 @@ module Consensus_key = struct (req "public_key_hash" Signature.Public_key_hash.encoding) (req "secret_key_uri" string)) + let consensus_key_without_sk_encoding__cannot_decode = + let open Data_encoding in + conv + (fun {alias; public_key; id; _} -> (alias, public_key, id)) + (fun (_alias, _public_key, _id) -> + Stdlib.failwith "Unexpected secret key") + (obj3 + (req "alias" (option string)) + (req "public_key" Signature.Public_key.encoding) + (req "public_key_hash" Signature.Public_key_hash.encoding)) + let pp fmt {alias; id; _} = match alias with | None -> Format.fprintf fmt "%a" Signature.Public_key_hash.pp id diff --git a/src/proto_alpha/lib_delegate/baking_state.mli b/src/proto_alpha/lib_delegate/baking_state.mli index 94d2ece13d1c..6ce42effd2a7 100644 --- a/src/proto_alpha/lib_delegate/baking_state.mli +++ b/src/proto_alpha/lib_delegate/baking_state.mli @@ -63,6 +63,11 @@ module Consensus_key : sig val encoding : t Data_encoding.t + (* Encodes the consensus_key but removes the [secret_key_uri] to avoid + leaking information. + Warning: this encoding was designed to encode, decoding will fail. *) + val consensus_key_without_sk_encoding__cannot_decode : t Data_encoding.t + val pp : Format.formatter -> t -> unit end -- GitLab