From 4766f7ce2a7cc3d7c2b6c0e5dfc5792c9722b17c Mon Sep 17 00:00:00 2001 From: Albin Coquereau Date: Mon, 24 Jul 2023 10:02:35 +0200 Subject: [PATCH 1/3] lib_crypto: add attestation and preattestation watermark --- src/lib_crypto/signature_v0.ml | 9 +++++++++ src/lib_crypto/signature_v0.mli | 2 ++ src/lib_crypto/signature_v1.ml | 9 +++++++++ src/lib_crypto/signature_v1.mli | 2 ++ src/lib_protocol_environment/sigs/v0.ml | 2 ++ src/lib_protocol_environment/sigs/v0/signature.mli | 2 ++ src/lib_protocol_environment/sigs/v1.ml | 2 ++ src/lib_protocol_environment/sigs/v1/signature.mli | 2 ++ src/lib_protocol_environment/sigs/v10.ml | 2 ++ src/lib_protocol_environment/sigs/v10/signature.mli | 2 ++ src/lib_protocol_environment/sigs/v2.ml | 2 ++ src/lib_protocol_environment/sigs/v2/signature.mli | 2 ++ src/lib_protocol_environment/sigs/v3.ml | 2 ++ src/lib_protocol_environment/sigs/v3/signature.mli | 2 ++ src/lib_protocol_environment/sigs/v4.ml | 2 ++ src/lib_protocol_environment/sigs/v4/signature.mli | 2 ++ src/lib_protocol_environment/sigs/v5.ml | 2 ++ src/lib_protocol_environment/sigs/v5/signature.mli | 2 ++ src/lib_protocol_environment/sigs/v6.ml | 2 ++ src/lib_protocol_environment/sigs/v6/signature.mli | 2 ++ src/lib_protocol_environment/sigs/v7.ml | 2 ++ src/lib_protocol_environment/sigs/v7/signature.mli | 2 ++ src/lib_protocol_environment/sigs/v8.ml | 2 ++ src/lib_protocol_environment/sigs/v8/signature.mli | 2 ++ src/lib_protocol_environment/sigs/v9.ml | 2 ++ src/lib_protocol_environment/sigs/v9/signature.mli | 2 ++ 26 files changed, 66 insertions(+) diff --git a/src/lib_crypto/signature_v0.ml b/src/lib_crypto/signature_v0.ml index 1827f52ef661..dfacd2180060 100644 --- a/src/lib_crypto/signature_v0.ml +++ b/src/lib_crypto/signature_v0.ml @@ -45,6 +45,8 @@ type secret_key = type watermark = | Block_header of Chain_id.t | Endorsement of Chain_id.t + | Attestation of Chain_id.t + | Preattestation of Chain_id.t | Generic_operation | Custom of Bytes.t @@ -621,6 +623,10 @@ let bytes_of_watermark = function Bytes.cat (Bytes.of_string "\x01") (Chain_id.to_bytes chain_id) | Endorsement chain_id -> Bytes.cat (Bytes.of_string "\x02") (Chain_id.to_bytes chain_id) + | Attestation chain_id -> + Bytes.cat (Bytes.of_string "\x13") (Chain_id.to_bytes chain_id) + | Preattestation chain_id -> + Bytes.cat (Bytes.of_string "\x12") (Chain_id.to_bytes chain_id) | Generic_operation -> Bytes.of_string "\x03" | Custom bytes -> bytes @@ -629,6 +635,9 @@ let pp_watermark ppf = function | Block_header chain_id -> fprintf ppf "Block-header: %a" Chain_id.pp chain_id | Endorsement chain_id -> fprintf ppf "Endorsement: %a" Chain_id.pp chain_id + | Attestation chain_id -> fprintf ppf "Attestation: %a" Chain_id.pp chain_id + | Preattestation chain_id -> + fprintf ppf "Preattestation: %a" Chain_id.pp chain_id | Generic_operation -> pp_print_string ppf "Generic-operation" | Custom bytes -> let hexed = Hex.of_bytes bytes |> Hex.show in diff --git a/src/lib_crypto/signature_v0.mli b/src/lib_crypto/signature_v0.mli index 88769a465b61..355f4af9946f 100644 --- a/src/lib_crypto/signature_v0.mli +++ b/src/lib_crypto/signature_v0.mli @@ -42,6 +42,8 @@ type secret_key = type watermark = | Block_header of Chain_id.t | Endorsement of Chain_id.t + | Attestation of Chain_id.t + | Preattestation of Chain_id.t | Generic_operation | Custom of Bytes.t diff --git a/src/lib_crypto/signature_v1.ml b/src/lib_crypto/signature_v1.ml index 6f17d6c60202..e87f83fe0f42 100644 --- a/src/lib_crypto/signature_v1.ml +++ b/src/lib_crypto/signature_v1.ml @@ -48,6 +48,8 @@ type secret_key = type watermark = Signature_v0.watermark = | Block_header of Chain_id.t | Endorsement of Chain_id.t + | Attestation of Chain_id.t + | Preattestation of Chain_id.t | Generic_operation | Custom of Bytes.t @@ -764,6 +766,10 @@ let bytes_of_watermark = function Bytes.cat (Bytes.of_string "\x01") (Chain_id.to_bytes chain_id) | Endorsement chain_id -> Bytes.cat (Bytes.of_string "\x02") (Chain_id.to_bytes chain_id) + | Attestation chain_id -> + Bytes.cat (Bytes.of_string "\x13") (Chain_id.to_bytes chain_id) + | Preattestation chain_id -> + Bytes.cat (Bytes.of_string "\x12") (Chain_id.to_bytes chain_id) | Generic_operation -> Bytes.of_string "\x03" | Custom bytes -> bytes @@ -772,6 +778,9 @@ let pp_watermark ppf = function | Block_header chain_id -> fprintf ppf "Block-header: %a" Chain_id.pp chain_id | Endorsement chain_id -> fprintf ppf "Endorsement: %a" Chain_id.pp chain_id + | Attestation chain_id -> fprintf ppf "Attestation: %a" Chain_id.pp chain_id + | Preattestation chain_id -> + fprintf ppf "Preattestation: %a" Chain_id.pp chain_id | Generic_operation -> pp_print_string ppf "Generic-operation" | Custom bytes -> let hexed = Hex.of_bytes bytes |> Hex.show in diff --git a/src/lib_crypto/signature_v1.mli b/src/lib_crypto/signature_v1.mli index 22f1856bc0bc..f086c20234f1 100644 --- a/src/lib_crypto/signature_v1.mli +++ b/src/lib_crypto/signature_v1.mli @@ -45,6 +45,8 @@ type secret_key = type watermark = Signature_v0.watermark = | Block_header of Chain_id.t | Endorsement of Chain_id.t + | Attestation of Chain_id.t + | Preattestation of Chain_id.t | Generic_operation | Custom of Bytes.t diff --git a/src/lib_protocol_environment/sigs/v0.ml b/src/lib_protocol_environment/sigs/v0.ml index 068dd33080f2..24f099d139a2 100644 --- a/src/lib_protocol_environment/sigs/v0.ml +++ b/src/lib_protocol_environment/sigs/v0.ml @@ -5245,6 +5245,8 @@ type public_key = type watermark = | Block_header of Chain_id.t | Endorsement of Chain_id.t + | Attestation of Chain_id.t + | Preattestation of Chain_id.t | Generic_operation | Custom of MBytes.t diff --git a/src/lib_protocol_environment/sigs/v0/signature.mli b/src/lib_protocol_environment/sigs/v0/signature.mli index 21e6ae5e230c..95b253de0b9c 100644 --- a/src/lib_protocol_environment/sigs/v0/signature.mli +++ b/src/lib_protocol_environment/sigs/v0/signature.mli @@ -36,6 +36,8 @@ type public_key = type watermark = | Block_header of Chain_id.t | Endorsement of Chain_id.t + | Attestation of Chain_id.t + | Preattestation of Chain_id.t | Generic_operation | Custom of MBytes.t diff --git a/src/lib_protocol_environment/sigs/v1.ml b/src/lib_protocol_environment/sigs/v1.ml index 3d13f7ee82f2..ffb82123fa5e 100644 --- a/src/lib_protocol_environment/sigs/v1.ml +++ b/src/lib_protocol_environment/sigs/v1.ml @@ -6170,6 +6170,8 @@ type public_key = type watermark = | Block_header of Chain_id.t | Endorsement of Chain_id.t + | Attestation of Chain_id.t + | Preattestation of Chain_id.t | Generic_operation | Custom of bytes diff --git a/src/lib_protocol_environment/sigs/v1/signature.mli b/src/lib_protocol_environment/sigs/v1/signature.mli index 1a1d295d6025..75582016691c 100644 --- a/src/lib_protocol_environment/sigs/v1/signature.mli +++ b/src/lib_protocol_environment/sigs/v1/signature.mli @@ -36,6 +36,8 @@ type public_key = type watermark = | Block_header of Chain_id.t | Endorsement of Chain_id.t + | Attestation of Chain_id.t + | Preattestation of Chain_id.t | Generic_operation | Custom of bytes diff --git a/src/lib_protocol_environment/sigs/v10.ml b/src/lib_protocol_environment/sigs/v10.ml index 4462553c5345..5c23f92f5860 100644 --- a/src/lib_protocol_environment/sigs/v10.ml +++ b/src/lib_protocol_environment/sigs/v10.ml @@ -9793,6 +9793,8 @@ type public_key = type watermark = | Block_header of Chain_id.t | Endorsement of Chain_id.t + | Attestation of Chain_id.t + | Preattestation of Chain_id.t | Generic_operation | Custom of bytes diff --git a/src/lib_protocol_environment/sigs/v10/signature.mli b/src/lib_protocol_environment/sigs/v10/signature.mli index 67b9dd7aca16..38f4f83d9fd8 100644 --- a/src/lib_protocol_environment/sigs/v10/signature.mli +++ b/src/lib_protocol_environment/sigs/v10/signature.mli @@ -39,6 +39,8 @@ type public_key = type watermark = | Block_header of Chain_id.t | Endorsement of Chain_id.t + | Attestation of Chain_id.t + | Preattestation of Chain_id.t | Generic_operation | Custom of bytes diff --git a/src/lib_protocol_environment/sigs/v2.ml b/src/lib_protocol_environment/sigs/v2.ml index fb8b992a9ba4..846e5b3520f5 100644 --- a/src/lib_protocol_environment/sigs/v2.ml +++ b/src/lib_protocol_environment/sigs/v2.ml @@ -6235,6 +6235,8 @@ type public_key = type watermark = | Block_header of Chain_id.t | Endorsement of Chain_id.t + | Attestation of Chain_id.t + | Preattestation of Chain_id.t | Generic_operation | Custom of bytes diff --git a/src/lib_protocol_environment/sigs/v2/signature.mli b/src/lib_protocol_environment/sigs/v2/signature.mli index 1a1d295d6025..75582016691c 100644 --- a/src/lib_protocol_environment/sigs/v2/signature.mli +++ b/src/lib_protocol_environment/sigs/v2/signature.mli @@ -36,6 +36,8 @@ type public_key = type watermark = | Block_header of Chain_id.t | Endorsement of Chain_id.t + | Attestation of Chain_id.t + | Preattestation of Chain_id.t | Generic_operation | Custom of bytes diff --git a/src/lib_protocol_environment/sigs/v3.ml b/src/lib_protocol_environment/sigs/v3.ml index 564064b803b4..3a10e87e698a 100644 --- a/src/lib_protocol_environment/sigs/v3.ml +++ b/src/lib_protocol_environment/sigs/v3.ml @@ -7004,6 +7004,8 @@ type public_key = type watermark = | Block_header of Chain_id.t | Endorsement of Chain_id.t + | Attestation of Chain_id.t + | Preattestation of Chain_id.t | Generic_operation | Custom of bytes diff --git a/src/lib_protocol_environment/sigs/v3/signature.mli b/src/lib_protocol_environment/sigs/v3/signature.mli index 1a1d295d6025..75582016691c 100644 --- a/src/lib_protocol_environment/sigs/v3/signature.mli +++ b/src/lib_protocol_environment/sigs/v3/signature.mli @@ -36,6 +36,8 @@ type public_key = type watermark = | Block_header of Chain_id.t | Endorsement of Chain_id.t + | Attestation of Chain_id.t + | Preattestation of Chain_id.t | Generic_operation | Custom of bytes diff --git a/src/lib_protocol_environment/sigs/v4.ml b/src/lib_protocol_environment/sigs/v4.ml index 4f2e468ab803..0d38a78642ed 100644 --- a/src/lib_protocol_environment/sigs/v4.ml +++ b/src/lib_protocol_environment/sigs/v4.ml @@ -7173,6 +7173,8 @@ type public_key = type watermark = | Block_header of Chain_id.t | Endorsement of Chain_id.t + | Attestation of Chain_id.t + | Preattestation of Chain_id.t | Generic_operation | Custom of bytes diff --git a/src/lib_protocol_environment/sigs/v4/signature.mli b/src/lib_protocol_environment/sigs/v4/signature.mli index 1a1d295d6025..75582016691c 100644 --- a/src/lib_protocol_environment/sigs/v4/signature.mli +++ b/src/lib_protocol_environment/sigs/v4/signature.mli @@ -36,6 +36,8 @@ type public_key = type watermark = | Block_header of Chain_id.t | Endorsement of Chain_id.t + | Attestation of Chain_id.t + | Preattestation of Chain_id.t | Generic_operation | Custom of bytes diff --git a/src/lib_protocol_environment/sigs/v5.ml b/src/lib_protocol_environment/sigs/v5.ml index d43a15ccc721..b2efe29cfec1 100644 --- a/src/lib_protocol_environment/sigs/v5.ml +++ b/src/lib_protocol_environment/sigs/v5.ml @@ -9143,6 +9143,8 @@ type public_key = type watermark = | Block_header of Chain_id.t | Endorsement of Chain_id.t + | Attestation of Chain_id.t + | Preattestation of Chain_id.t | Generic_operation | Custom of bytes diff --git a/src/lib_protocol_environment/sigs/v5/signature.mli b/src/lib_protocol_environment/sigs/v5/signature.mli index 1a1d295d6025..75582016691c 100644 --- a/src/lib_protocol_environment/sigs/v5/signature.mli +++ b/src/lib_protocol_environment/sigs/v5/signature.mli @@ -36,6 +36,8 @@ type public_key = type watermark = | Block_header of Chain_id.t | Endorsement of Chain_id.t + | Attestation of Chain_id.t + | Preattestation of Chain_id.t | Generic_operation | Custom of bytes diff --git a/src/lib_protocol_environment/sigs/v6.ml b/src/lib_protocol_environment/sigs/v6.ml index 2056296fd2e0..46ec880a076a 100644 --- a/src/lib_protocol_environment/sigs/v6.ml +++ b/src/lib_protocol_environment/sigs/v6.ml @@ -9143,6 +9143,8 @@ type public_key = type watermark = | Block_header of Chain_id.t | Endorsement of Chain_id.t + | Attestation of Chain_id.t + | Preattestation of Chain_id.t | Generic_operation | Custom of bytes diff --git a/src/lib_protocol_environment/sigs/v6/signature.mli b/src/lib_protocol_environment/sigs/v6/signature.mli index 1a1d295d6025..75582016691c 100644 --- a/src/lib_protocol_environment/sigs/v6/signature.mli +++ b/src/lib_protocol_environment/sigs/v6/signature.mli @@ -36,6 +36,8 @@ type public_key = type watermark = | Block_header of Chain_id.t | Endorsement of Chain_id.t + | Attestation of Chain_id.t + | Preattestation of Chain_id.t | Generic_operation | Custom of bytes diff --git a/src/lib_protocol_environment/sigs/v7.ml b/src/lib_protocol_environment/sigs/v7.ml index db54ebbef4e4..40628f56906f 100644 --- a/src/lib_protocol_environment/sigs/v7.ml +++ b/src/lib_protocol_environment/sigs/v7.ml @@ -9548,6 +9548,8 @@ type public_key = type watermark = | Block_header of Chain_id.t | Endorsement of Chain_id.t + | Attestation of Chain_id.t + | Preattestation of Chain_id.t | Generic_operation | Custom of bytes diff --git a/src/lib_protocol_environment/sigs/v7/signature.mli b/src/lib_protocol_environment/sigs/v7/signature.mli index 1a1d295d6025..75582016691c 100644 --- a/src/lib_protocol_environment/sigs/v7/signature.mli +++ b/src/lib_protocol_environment/sigs/v7/signature.mli @@ -36,6 +36,8 @@ type public_key = type watermark = | Block_header of Chain_id.t | Endorsement of Chain_id.t + | Attestation of Chain_id.t + | Preattestation of Chain_id.t | Generic_operation | Custom of bytes diff --git a/src/lib_protocol_environment/sigs/v8.ml b/src/lib_protocol_environment/sigs/v8.ml index e10325fec779..efba429c91cb 100644 --- a/src/lib_protocol_environment/sigs/v8.ml +++ b/src/lib_protocol_environment/sigs/v8.ml @@ -9852,6 +9852,8 @@ type public_key = type watermark = | Block_header of Chain_id.t | Endorsement of Chain_id.t + | Attestation of Chain_id.t + | Preattestation of Chain_id.t | Generic_operation | Custom of bytes diff --git a/src/lib_protocol_environment/sigs/v8/signature.mli b/src/lib_protocol_environment/sigs/v8/signature.mli index 67b9dd7aca16..38f4f83d9fd8 100644 --- a/src/lib_protocol_environment/sigs/v8/signature.mli +++ b/src/lib_protocol_environment/sigs/v8/signature.mli @@ -39,6 +39,8 @@ type public_key = type watermark = | Block_header of Chain_id.t | Endorsement of Chain_id.t + | Attestation of Chain_id.t + | Preattestation of Chain_id.t | Generic_operation | Custom of bytes diff --git a/src/lib_protocol_environment/sigs/v9.ml b/src/lib_protocol_environment/sigs/v9.ml index 92d867725c6d..1a16c47c1aaf 100644 --- a/src/lib_protocol_environment/sigs/v9.ml +++ b/src/lib_protocol_environment/sigs/v9.ml @@ -9779,6 +9779,8 @@ type public_key = type watermark = | Block_header of Chain_id.t | Endorsement of Chain_id.t + | Attestation of Chain_id.t + | Preattestation of Chain_id.t | Generic_operation | Custom of bytes diff --git a/src/lib_protocol_environment/sigs/v9/signature.mli b/src/lib_protocol_environment/sigs/v9/signature.mli index 67b9dd7aca16..38f4f83d9fd8 100644 --- a/src/lib_protocol_environment/sigs/v9/signature.mli +++ b/src/lib_protocol_environment/sigs/v9/signature.mli @@ -39,6 +39,8 @@ type public_key = type watermark = | Block_header of Chain_id.t | Endorsement of Chain_id.t + | Attestation of Chain_id.t + | Preattestation of Chain_id.t | Generic_operation | Custom of bytes -- GitLab From b0f2cedba9db70e3b6f65caab8d206f47dcca5a3 Mon Sep 17 00:00:00 2001 From: Albin Coquereau Date: Mon, 24 Jul 2023 10:03:03 +0200 Subject: [PATCH 2/3] lib_delegate: use signature watermark --- src/proto_alpha/lib_delegate/baking_actions.ml | 4 ++-- .../lib_delegate/test/mockup_simulator/mockup_simulator.ml | 6 ++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/proto_alpha/lib_delegate/baking_actions.ml b/src/proto_alpha/lib_delegate/baking_actions.ml index ed949d4e6d20..65501d0b6308 100644 --- a/src/proto_alpha/lib_delegate/baking_actions.ml +++ b/src/proto_alpha/lib_delegate/baking_actions.ml @@ -426,7 +426,7 @@ let inject_preendorsements state ~preendorsements = >>=? fun may_sign -> (if may_sign then let unsigned_operation = (shell, Contents_list contents) in - let watermark = Operation.(to_watermark (Preattestation chain_id)) in + let watermark = Signature.Preattestation chain_id in let unsigned_operation_bytes = Data_encoding.Binary.to_bytes_exn Operation.unsigned_encoding_with_legacy_attestation_name @@ -506,7 +506,7 @@ let sign_endorsements state endorsements = | false -> return state.global_state.config.force) >>=? fun may_sign -> (if may_sign then - let watermark = Operation.(to_watermark (Attestation chain_id)) in + let watermark = Signature.Attestation chain_id in let unsigned_operation = (shell, Contents_list contents) in let unsigned_operation_bytes = Data_encoding.Binary.to_bytes_exn diff --git a/src/proto_alpha/lib_delegate/test/mockup_simulator/mockup_simulator.ml b/src/proto_alpha/lib_delegate/test/mockup_simulator/mockup_simulator.ml index 4d3cbfc8892f..cb4c855a9bfd 100644 --- a/src/proto_alpha/lib_delegate/test/mockup_simulator/mockup_simulator.ml +++ b/src/proto_alpha/lib_delegate/test/mockup_simulator/mockup_simulator.ml @@ -1342,10 +1342,8 @@ let op_is_signed_by ~public_key (op_hash : Operation_hash.t) | Single op_contents -> return (match op_contents with - | Attestation _ -> - Alpha_context.Operation.to_watermark (Attestation chain_id) - | Preattestation _ -> - Alpha_context.Operation.to_watermark (Preattestation chain_id) + | Attestation _ -> Signature.Attestation chain_id + | Preattestation _ -> Signature.Preattestation chain_id | _ -> Signature.Generic_operation) | _ -> failwith "unexpected contents in %a@." Operation_hash.pp op_hash) >>=? fun watermark -> -- GitLab From 0c0fd32047fb3507ae545e54bbfa889a733ff9b9 Mon Sep 17 00:00:00 2001 From: Albin Coquereau Date: Mon, 24 Jul 2023 10:06:13 +0200 Subject: [PATCH 3/3] alpha: use signature watermarks in operation repr --- .../lib_protocol/operation_repr.ml | 22 ++++--------------- 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/src/proto_alpha/lib_protocol/operation_repr.ml b/src/proto_alpha/lib_protocol/operation_repr.ml index 1fd6be0b4aa4..df4127a84350 100644 --- a/src/proto_alpha/lib_protocol/operation_repr.ml +++ b/src/proto_alpha/lib_protocol/operation_repr.ml @@ -183,9 +183,7 @@ type consensus_watermark = | Dal_attestation of Chain_id.t let to_watermark = function - | Preattestation chain_id -> - Signature.Custom - (Bytes.cat (Bytes.of_string "\x12") (Chain_id.to_bytes chain_id)) + | Preattestation chain_id -> Signature.Preattestation chain_id | Dal_attestation chain_id (* FIXME: https://gitlab.com/tezos/tezos/-/issues/4479 @@ -194,23 +192,11 @@ let to_watermark = function later on. Moreover, there is a leak of abstraction with the shell which makes adding a new watermark a bit awkward. *) | Attestation chain_id -> - Signature.Custom - (Bytes.cat (Bytes.of_string "\x13") (Chain_id.to_bytes chain_id)) + Signature.Attestation chain_id let of_watermark = function - | Signature.Custom b -> - if Compare.Int.(Bytes.length b > 0) then - match Bytes.get b 0 with - | '\x12' -> - Option.map - (fun chain_id -> Preattestation chain_id) - (Chain_id.of_bytes_opt (Bytes.sub b 1 (Bytes.length b - 1))) - | '\x13' -> - Option.map - (fun chain_id -> Attestation chain_id) - (Chain_id.of_bytes_opt (Bytes.sub b 1 (Bytes.length b - 1))) - | _ -> None - else None + | Signature.Attestation chain_id -> Some (Attestation chain_id) + | Signature.Preattestation chain_id -> Some (Preattestation chain_id) | _ -> None type raw = Operation.t = {shell : Operation.shell_header; proto : bytes} -- GitLab