From f82f2dc2639f166f622d757e35508120180b4633 Mon Sep 17 00:00:00 2001 From: Lucas Randazzo Date: Thu, 27 Mar 2025 14:52:29 +0100 Subject: [PATCH 01/13] Proto: expose kind consensus_key also update one error to add the kind --- .../lib_protocol/delegate_consensus_key.ml | 32 +++++++++++-------- .../lib_protocol/delegate_consensus_key.mli | 9 ++++-- .../lib_protocol/operation_repr.ml | 16 ++++++++++ .../lib_protocol/operation_repr.mli | 6 ++++ .../test/unit/test_consensus_key.ml | 6 ++-- 5 files changed, 50 insertions(+), 19 deletions(-) diff --git a/src/proto_alpha/lib_protocol/delegate_consensus_key.ml b/src/proto_alpha/lib_protocol/delegate_consensus_key.ml index 5d9bd8fb6dcc..bd00ebeff1b2 100644 --- a/src/proto_alpha/lib_protocol/delegate_consensus_key.ml +++ b/src/proto_alpha/lib_protocol/delegate_consensus_key.ml @@ -24,7 +24,8 @@ (*****************************************************************************) type error += - | Invalid_consensus_key_update_noop of Cycle_repr.t + | Invalid_consensus_key_update_noop of + (Cycle_repr.t * Operation_repr.consensus_key_kind) | Invalid_consensus_key_update_active | Invalid_consensus_key_update_tz4 of Bls.Public_key.t @@ -34,13 +35,18 @@ let () = ~id:"delegate.consensus_key.invalid_noop" ~title:"Invalid key for consensus key update" ~description:"Tried to update the consensus key with the active key" - ~pp:(fun ppf cycle -> + ~pp:(fun ppf (cycle, kind) -> Format.fprintf ppf - "Invalid key while updating a consensus key (already active since %a)." + "Invalid key while updating a %a key (already active since %a)." + Operation_repr.pp_consensus_key_kind + kind Cycle_repr.pp cycle) - Data_encoding.(obj1 (req "cycle" Cycle_repr.encoding)) + Data_encoding.( + obj2 + (req "cycle" Cycle_repr.encoding) + (req "kind" Operation_repr.consensus_key_kind_encoding)) (function Invalid_consensus_key_update_noop c -> Some c | _ -> None) (fun c -> Invalid_consensus_key_update_noop c) ; register_error_kind @@ -71,9 +77,9 @@ let () = (function Invalid_consensus_key_update_tz4 pk -> Some pk | _ -> None) (fun pk -> Invalid_consensus_key_update_tz4 pk) -type 'a kind = - | Consensus : Signature.public_key kind - | Companion : Bls.Public_key.t option kind +type 'a typed_kind = + | Consensus : Signature.public_key typed_kind + | Companion : Bls.Public_key.t option typed_kind type pk = Raw_context.consensus_pk = { delegate : Signature.Public_key_hash.t; @@ -155,7 +161,7 @@ let init ctxt delegate pk = let*! ctxt = set_used ctxt pkh in Storage.Contract.Consensus_key.init ctxt (Contract_repr.Implicit delegate) pk -let active_pubkey_kind (type a) ctxt ~(kind : a kind) delegate : +let active_pubkey_kind (type a) ctxt ~(kind : a typed_kind) delegate : a tzresult Lwt.t = match kind with | Consensus -> @@ -176,8 +182,8 @@ let active_key ctxt delegate = let* pk = active_pubkey ctxt delegate in return (pkh pk) -let raw_pending_updates (type a) ctxt ?up_to_cycle ~(kind : a kind) delegate : - (Cycle_repr.t * a) list tzresult Lwt.t = +let raw_pending_updates (type a) ctxt ?up_to_cycle ~(kind : a typed_kind) + delegate : (Cycle_repr.t * a) list tzresult Lwt.t = let open Lwt_result_syntax in let relevant_cycles = let level = Raw_context.current_level ctxt in @@ -194,7 +200,7 @@ let raw_pending_updates (type a) ctxt ?up_to_cycle ~(kind : a kind) delegate : Cycle_repr.(first_cycle ---> last_cycle) in let delegate = Contract_repr.Implicit delegate in - let find (type a) (ctxt, cycle) delegate (kind : a kind) : + let find (type a) (ctxt, cycle) delegate (kind : a typed_kind) : a option tzresult Lwt.t = match kind with | Consensus -> Storage.Pending_consensus_keys.find (ctxt, cycle) delegate @@ -262,7 +268,7 @@ let register_update ctxt delegate pk = in fail_when Signature.Public_key.(pk = active_pubkey) - (Invalid_consensus_key_update_noop first_active_cycle) + (Invalid_consensus_key_update_noop (first_active_cycle, Consensus)) in let pkh = Signature.Public_key.hash pk in let* () = check_unused ctxt pkh in @@ -295,7 +301,7 @@ let register_update_companion ctxt delegate pk = | Some active_pubkey -> fail_when Bls.Public_key.(pk = active_pubkey) - (Invalid_consensus_key_update_noop first_active_cycle) + (Invalid_consensus_key_update_noop (first_active_cycle, Companion)) in let pkh : Signature.public_key_hash = Signature.Bls (Bls.Public_key.hash pk) diff --git a/src/proto_alpha/lib_protocol/delegate_consensus_key.mli b/src/proto_alpha/lib_protocol/delegate_consensus_key.mli index 41348c23c75a..d0d5f12f26e2 100644 --- a/src/proto_alpha/lib_protocol/delegate_consensus_key.mli +++ b/src/proto_alpha/lib_protocol/delegate_consensus_key.mli @@ -26,11 +26,14 @@ (** Management of a delegate's consensus key, the one used to sign blocks and consensus operations. It is responsible for maintaining the tables {!Storage.Consensus_keys}, - {!Storage.Contract.Consensus_key}, and - {!Storage.Contract.Pending_consensus_keys}. *) + {!Storage.Contract.Consensus_key}, + {!Storage.Contract.Pending_consensus_keys}, + {!Storage.Contract.Companion_key}, and + {!Storage.Contract.Pending_companion_keys}. *) type error += - | Invalid_consensus_key_update_noop of Cycle_repr.t + | Invalid_consensus_key_update_noop of + (Cycle_repr.t * Operation_repr.consensus_key_kind) | Invalid_consensus_key_update_active | Invalid_consensus_key_update_tz4 of Bls.Public_key.t diff --git a/src/proto_alpha/lib_protocol/operation_repr.ml b/src/proto_alpha/lib_protocol/operation_repr.ml index c41297db04bd..527698eb582e 100644 --- a/src/proto_alpha/lib_protocol/operation_repr.ml +++ b/src/proto_alpha/lib_protocol/operation_repr.ml @@ -236,6 +236,22 @@ let of_watermark = function else None | _ -> None +type consensus_key_kind = Consensus | Companion + +let consensus_key_kind_encoding = + let open Data_encoding in + conv + (function Consensus -> true | Companion -> false) + (fun x -> if x then Consensus else Companion) + bool + +let consensus_key_kind_to_string = function + | Consensus -> "consensus" + | Companion -> "companion" + +let pp_consensus_key_kind ppf kind = + Format.fprintf ppf "%s" (consensus_key_kind_to_string kind) + type raw = Operation.t = {shell : Operation.shell_header; proto : bytes} let raw_encoding = Operation.encoding diff --git a/src/proto_alpha/lib_protocol/operation_repr.mli b/src/proto_alpha/lib_protocol/operation_repr.mli index fea379d15cb9..061c2bf7b155 100644 --- a/src/proto_alpha/lib_protocol/operation_repr.mli +++ b/src/proto_alpha/lib_protocol/operation_repr.mli @@ -225,6 +225,12 @@ val to_watermark : consensus_watermark -> Signature.watermark val of_watermark : Signature.watermark -> consensus_watermark option +type consensus_key_kind = Consensus | Companion + +val consensus_key_kind_encoding : consensus_key_kind Data_encoding.t + +val pp_consensus_key_kind : Format.formatter -> consensus_key_kind -> unit + type raw = Operation.t = {shell : Operation.shell_header; proto : bytes} val raw_encoding : raw Data_encoding.t diff --git a/src/proto_alpha/lib_protocol/test/unit/test_consensus_key.ml b/src/proto_alpha/lib_protocol/test/unit/test_consensus_key.ml index 42acc80e0013..714890f646fd 100644 --- a/src/proto_alpha/lib_protocol/test/unit/test_consensus_key.ml +++ b/src/proto_alpha/lib_protocol/test/unit/test_consensus_key.ml @@ -155,7 +155,7 @@ let test_consensus_key_storage () = let*! err = Consensus_key.register_update ctxt del1.pkh a1.pk in Assert.proto_error ~loc:__LOC__ err (function | Delegate_consensus_key.Invalid_consensus_key_update_noop c -> - c = Cycle_repr.of_int32_exn 4l + c = (Cycle_repr.of_int32_exn 4l, Consensus) | _ -> false) in let* () = @@ -189,7 +189,7 @@ let test_consensus_key_storage () = let*! err = Consensus_key.register_update ctxt del1.pkh a1.pk in Assert.proto_error ~loc:__LOC__ err (function | Delegate_consensus_key.Invalid_consensus_key_update_noop c -> - c = Cycle_repr.of_int32_exn 4l + c = (Cycle_repr.of_int32_exn 4l, Consensus) | _ -> false) in let* ctxt = Consensus_key.register_update ctxt del1.pkh a2.pk in @@ -219,7 +219,7 @@ let test_consensus_key_storage () = let*! err = Consensus_key.register_update ctxt del1.pkh a2.pk in Assert.proto_error ~loc:__LOC__ err (function | Delegate_consensus_key.Invalid_consensus_key_update_noop c -> - c = Cycle_repr.of_int32_exn 5l + c = (Cycle_repr.of_int32_exn 5l, Consensus) | _ -> false) in let* ctxt = Consensus_key.register_update ctxt del1.pkh a1.pk in -- GitLab From 9ef77b82217e93c8eab47576b045e8176ca50369 Mon Sep 17 00:00:00 2001 From: Lucas Randazzo Date: Thu, 27 Mar 2025 17:08:34 +0100 Subject: [PATCH 02/13] Proto: update_consensus_key: add kind to handle companion --- src/proto_alpha/lib_client/client_proto_context.ml | 6 +++++- src/proto_alpha/lib_client/operation_result.ml | 3 ++- src/proto_alpha/lib_protocol/alpha_context.mli | 1 + src/proto_alpha/lib_protocol/apply.ml | 3 ++- src/proto_alpha/lib_protocol/operation_repr.ml | 14 ++++++++------ src/proto_alpha/lib_protocol/operation_repr.mli | 1 + src/proto_alpha/lib_protocol/test/helpers/op.ml | 4 +++- src/proto_alpha/lib_protocol/validate.ml | 3 ++- 8 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src/proto_alpha/lib_client/client_proto_context.ml b/src/proto_alpha/lib_client/client_proto_context.ml index 6b502162b3da..fedbed8e1da2 100644 --- a/src/proto_alpha/lib_client/client_proto_context.ml +++ b/src/proto_alpha/lib_client/client_proto_context.ml @@ -371,7 +371,11 @@ let build_update_consensus_key cctxt ?fee ?gas_limit ?storage_limit | _ -> tzfail (Unexpected_proof_of_possession_format proof)) | _ -> return_none in - let operation = Update_consensus_key {public_key; proof} in + let operation = + Update_consensus_key + {public_key; proof; kind = Delegate_consensus_key.Consensus} + in + (* TODO: handle companion *) return @@ Injection.prepare_manager_operation ~fee:(Limit.of_option fee) diff --git a/src/proto_alpha/lib_client/operation_result.ml b/src/proto_alpha/lib_client/operation_result.ml index a441c881b90f..b1dd87a90120 100644 --- a/src/proto_alpha/lib_client/operation_result.ml +++ b/src/proto_alpha/lib_client/operation_result.ml @@ -234,7 +234,8 @@ let pp_manager_operation_content (type kind) source ppf source Contract_hash.pp destination - | Update_consensus_key {public_key = pk; proof} -> + | Update_consensus_key {public_key = pk; proof; kind = _} -> + (* TODO: handle companion *) Format.fprintf ppf "Update_consensus_key:@,Public key hash: %a%a" diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index 69ba51ebc533..53e220b71c2c 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -4803,6 +4803,7 @@ and _ manager_operation = | Update_consensus_key : { public_key : Signature.Public_key.t; proof : Bls.t option; + kind : Operation_repr.consensus_key_kind; } -> Kind.update_consensus_key manager_operation | Transfer_ticket : { diff --git a/src/proto_alpha/lib_protocol/apply.ml b/src/proto_alpha/lib_protocol/apply.ml index 8ff6b432bc25..9631e639cffe 100644 --- a/src/proto_alpha/lib_protocol/apply.ml +++ b/src/proto_alpha/lib_protocol/apply.ml @@ -1424,7 +1424,8 @@ let apply_manager_operation : } in (ctxt, result, []) - | Update_consensus_key {public_key; proof} -> + | Update_consensus_key {public_key; proof; kind = _} -> + (* TODO: handle companion *) let*! is_registered = Delegate.registered ctxt source in let*? () = error_unless diff --git a/src/proto_alpha/lib_protocol/operation_repr.ml b/src/proto_alpha/lib_protocol/operation_repr.ml index 527698eb582e..60b50da6aad2 100644 --- a/src/proto_alpha/lib_protocol/operation_repr.ml +++ b/src/proto_alpha/lib_protocol/operation_repr.ml @@ -382,6 +382,7 @@ and _ manager_operation = | Update_consensus_key : { public_key : Signature.Public_key.t; proof : Bls.t option; + kind : consensus_key_kind; } -> Kind.update_consensus_key manager_operation | Transfer_ticket : { @@ -774,18 +775,19 @@ module Encoding = struct tag = update_consensus_key_tag; name = "update_consensus_key"; encoding = - obj2 + obj3 (req "pk" Signature.Public_key.encoding) + (req "kind" Delegate_consensus_key.kind_encoding) (opt "proof" (dynamic_size Bls.encoding)); select = (function | Manager (Update_consensus_key _ as op) -> Some op | _ -> None); proj = - (fun (Update_consensus_key {public_key; proof}) -> - (public_key, proof)); + (fun (Update_consensus_key {public_key; proof; kind}) -> + (public_key, kind, proof)); inj = - (fun (public_key, proof) -> - Update_consensus_key {public_key; proof}); + (fun (public_key, kind, proof) -> + Update_consensus_key {public_key; proof; kind}); } let transfer_ticket_case = @@ -2255,7 +2257,7 @@ let attestation_infos_from_content (c : consensus_content) d; } -(** Compute an {!aggregate_info} value from {!consensus_aggregate_content} +(** Compute an {!aggregate_info} value from {!consensus_aggregate_content} and {!Slot_repr.t list} values. It is used to compute the weight of an {!Aggregate_attestation}. diff --git a/src/proto_alpha/lib_protocol/operation_repr.mli b/src/proto_alpha/lib_protocol/operation_repr.mli index 061c2bf7b155..17363118f90b 100644 --- a/src/proto_alpha/lib_protocol/operation_repr.mli +++ b/src/proto_alpha/lib_protocol/operation_repr.mli @@ -434,6 +434,7 @@ and _ manager_operation = | Update_consensus_key : { public_key : Signature.Public_key.t; proof : Bls.t option; + kind : consensus_key_kind; } -> Kind.update_consensus_key manager_operation (** [Transfer_ticket] allows an implicit account (the "claimer") to receive diff --git a/src/proto_alpha/lib_protocol/test/helpers/op.ml b/src/proto_alpha/lib_protocol/test/helpers/op.ml index f345bea9a821..a50834903bd4 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/op.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/op.ml @@ -1144,6 +1144,8 @@ let update_consensus_key ?force_reveal ?counter ?fee ?gas_limit ?storage_limit "Can't forge an Update_consensus_key with a non-BLS proof of \ possession.") in + (* TODO: handle companion *) + let kind = Delegate_consensus_key.Consensus in let* to_sign_op = manager_operation ?force_reveal @@ -1153,7 +1155,7 @@ let update_consensus_key ?force_reveal ?counter ?fee ?gas_limit ?storage_limit ?storage_limit ~source:src ctxt - (Update_consensus_key {public_key; proof}) + (Update_consensus_key {public_key; proof; kind}) in let* account = Context.Contract.manager ctxt src in sign ctxt account.sk (Context.branch ctxt) to_sign_op diff --git a/src/proto_alpha/lib_protocol/validate.ml b/src/proto_alpha/lib_protocol/validate.ml index 955ce00febf8..74f9e858df63 100644 --- a/src/proto_alpha/lib_protocol/validate.ml +++ b/src/proto_alpha/lib_protocol/validate.ml @@ -2622,7 +2622,8 @@ module Manager = struct | Delegation (Some pkh) -> if Constants.allow_tz4_delegate_enable vi.ctxt then return_unit else Delegate.check_not_tz4 pkh - | Update_consensus_key {public_key; proof} -> + | Update_consensus_key {public_key; proof; kind = _} -> + (* TODO: handle companion *) check_update_consensus_key vi remaining_gas source public_key proof | Delegation None | Set_deposits_limit _ | Increase_paid_storage _ -> return_unit -- GitLab From 94ec2c07052c1c2f318fd8068d80480ee09ddf35 Mon Sep 17 00:00:00 2001 From: Lucas Randazzo Date: Thu, 27 Mar 2025 17:11:06 +0100 Subject: [PATCH 03/13] Proto: add new validate errors --- src/proto_alpha/lib_protocol/apply.ml | 2 +- .../consensus/test_consensus_key.ml | 4 +- src/proto_alpha/lib_protocol/validate.ml | 6 +- .../lib_protocol/validate_errors.ml | 82 ++++++++++++++----- .../lib_protocol/validate_errors.mli | 7 ++ 5 files changed, 74 insertions(+), 27 deletions(-) diff --git a/src/proto_alpha/lib_protocol/apply.ml b/src/proto_alpha/lib_protocol/apply.ml index 9631e639cffe..b1f2be4515b1 100644 --- a/src/proto_alpha/lib_protocol/apply.ml +++ b/src/proto_alpha/lib_protocol/apply.ml @@ -1460,7 +1460,7 @@ let apply_manager_operation : (Signature.check public_key (Bls proof) bytes) (Validate_errors.Manager .Update_consensus_key_with_incorrect_proof - {public_key; proof}) + {kind = Consensus; public_key; proof}) in return ctxt | _, _ -> return ctxt 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 12ad2d2f0133..e7401d26766f 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 @@ -231,7 +231,7 @@ let test_tz4_consensus_key ~allow_tz4_delegate_enable () = | [ Environment.Ecoproto_error (Validate_errors.Manager.Update_consensus_key_with_tz4_without_proof - {source; public_key}); + {kind = Consensus; source; public_key}); ] when Signature.Public_key.(public_key = consensus_pk) && source = delegate -> @@ -260,7 +260,7 @@ let test_tz4_consensus_key ~allow_tz4_delegate_enable () = | [ Environment.Ecoproto_error (Validate_errors.Manager.Update_consensus_key_with_incorrect_proof - {public_key; proof = _}); + {kind = Consensus; public_key; proof = _}); ] when Signature.Public_key.(public_key = consensus_pk) -> return_unit diff --git a/src/proto_alpha/lib_protocol/validate.ml b/src/proto_alpha/lib_protocol/validate.ml index 74f9e858df63..1255ab4efaee 100644 --- a/src/proto_alpha/lib_protocol/validate.ml +++ b/src/proto_alpha/lib_protocol/validate.ml @@ -2556,7 +2556,7 @@ module Manager = struct | Bls _bls_public_key, None -> result_error (Validate_errors.Manager.Update_consensus_key_with_tz4_without_proof - {source; public_key}) + {kind = Consensus; source; public_key}) | Bls bls_public_key, Some _ -> (* Compute the gas cost to encode the consensus public key and check the proof. *) @@ -2579,14 +2579,14 @@ module Manager = struct | (Ed25519 _ | Secp256k1 _ | P256 _), Some _proof -> result_error (Validate_errors.Manager.Update_consensus_key_with_unused_proof - {source; public_key}) + {kind = Consensus; source; public_key}) | (Ed25519 _ | Secp256k1 _ | P256 _), None -> return_unit else let* () = Delegate.Consensus_key.check_not_tz4 public_key in if Option.is_some proof then result_error (Validate_errors.Manager.Update_consensus_key_with_unused_proof - {source; public_key}) + {kind = Consensus; source; public_key}) else return_unit let check_kind_specific_content (type kind) diff --git a/src/proto_alpha/lib_protocol/validate_errors.ml b/src/proto_alpha/lib_protocol/validate_errors.ml index 6483adbcbc7f..bbbdad971dfa 100644 --- a/src/proto_alpha/lib_protocol/validate_errors.ml +++ b/src/proto_alpha/lib_protocol/validate_errors.ml @@ -1592,14 +1592,21 @@ module Manager = struct } | Incorrect_reveal_position | Update_consensus_key_with_tz4_without_proof of { + kind : Operation_repr.consensus_key_kind; source : public_key_hash; public_key : public_key; } | Update_consensus_key_with_incorrect_proof of { + kind : Operation_repr.consensus_key_kind; public_key : public_key; proof : Bls.t; } | Update_consensus_key_with_unused_proof of { + kind : Operation_repr.consensus_key_kind; + source : public_key_hash; + public_key : public_key; + } + | Update_companion_key_not_tz4 of { source : public_key_hash; public_key : public_key; } @@ -1696,74 +1703,107 @@ module Manager = struct ~id:"validate.operation.update_consensus_key_with_tz4_without_proof" ~title:"update consensus key with tz4 without proof" ~description:"Update to a tz4 consensus key without proof of possession" - ~pp:(fun ppf (pk, source) -> + ~pp:(fun ppf (kind, pk, source) -> Format.fprintf ppf - "Update to a BLS consensus key %a from %a should contain a proof of \ + "Update to a BLS %a key %a from %a should contain a proof of \ possession." + Operation_repr.pp_consensus_key_kind + kind Signature.Public_key_hash.pp pk Signature.Public_key.pp source) Data_encoding.( - obj2 + obj3 + (req "kind" Operation_repr.consensus_key_kind_encoding) (req "source" Signature.Public_key_hash.encoding) (req "public_key" Signature.Public_key.encoding)) (function - | Update_consensus_key_with_tz4_without_proof {source; public_key} -> - Some (source, public_key) + | Update_consensus_key_with_tz4_without_proof {kind; source; public_key} + -> + Some (kind, source, public_key) | _ -> None) - (fun (source, public_key) -> - Update_consensus_key_with_tz4_without_proof {source; public_key}) ; + (fun (kind, source, public_key) -> + Update_consensus_key_with_tz4_without_proof {kind; source; public_key}) ; register_error_kind `Permanent - ~id:"validate.operation.update_consensus_key_with_with_incorrect_proof" + ~id:"validate.operation.update_consensus_key_with_incorrect_proof" ~title:"update consensus key with tz4 with incorrect proof" ~description: "Update to a tz4 consensus key with an incorrect proof of possession" - ~pp:(fun ppf (pk, proof) -> + ~pp:(fun ppf (kind, pk, proof) -> Format.fprintf ppf - "Update to a BLS consensus key %a contains an incorrect proof of \ - possession %a." + "Update to a BLS %a key %a contains an incorrect proof of possession \ + %a." + Operation_repr.pp_consensus_key_kind + kind Signature.Public_key.pp pk Bls.pp proof) Data_encoding.( - obj2 + obj3 + (req "kind" Operation_repr.consensus_key_kind_encoding) (req "public_key" Signature.Public_key.encoding) (req "proof" Bls.encoding)) (function - | Update_consensus_key_with_incorrect_proof {public_key; proof} -> - Some (public_key, proof) + | Update_consensus_key_with_incorrect_proof {kind; public_key; proof} -> + Some (kind, public_key, proof) | _ -> None) - (fun (public_key, proof) -> - Update_consensus_key_with_incorrect_proof {public_key; proof}) ; + (fun (kind, public_key, proof) -> + Update_consensus_key_with_incorrect_proof {kind; public_key; proof}) ; register_error_kind `Permanent ~id:"validate.operation.update_consensus_key_with_unused_proof" ~title:"update consensus key with unused proof" ~description:"Update consensus key with unused proof of possession" - ~pp:(fun ppf (pk, source) -> + ~pp:(fun ppf (kind, pk, source) -> Format.fprintf ppf - "Consensus key update to %a from %a contains an unused proof of \ - possession." + "Update %a key of %a from %a contains an unused proof of possession." + Operation_repr.pp_consensus_key_kind + kind Signature.Public_key_hash.pp pk Signature.Public_key.pp source) + Data_encoding.( + obj3 + (req "kind" Operation_repr.consensus_key_kind_encoding) + (req "source" Signature.Public_key_hash.encoding) + (req "public_key" Signature.Public_key.encoding)) + (function + | Update_consensus_key_with_unused_proof {kind; source; public_key} -> + Some (kind, source, public_key) + | _ -> None) + (fun (kind, source, public_key) -> + Update_consensus_key_with_unused_proof {kind; source; public_key}) ; + register_error_kind + `Permanent + ~id:"validate.operation.update_companion_key_not_tz4" + ~title:"update companion key without a tz4 key" + ~description:"Update to a tz4 companion key without providing a tz4 key" + ~pp:(fun ppf (source, pk) -> + Format.fprintf + ppf + "Update to the BLS companion key of %a with key %a that should be a \ + tz4." + Signature.Public_key_hash.pp + source + Signature.Public_key.pp + pk) Data_encoding.( obj2 (req "source" Signature.Public_key_hash.encoding) (req "public_key" Signature.Public_key.encoding)) (function - | Update_consensus_key_with_unused_proof {source; public_key} -> + | Update_companion_key_not_tz4 {source; public_key} -> Some (source, public_key) | _ -> None) (fun (source, public_key) -> - Update_consensus_key_with_unused_proof {source; public_key}) ; + Update_companion_key_not_tz4 {source; public_key}) ; register_error_kind `Permanent ~id:"validate.operation.insufficient_gas_for_manager" diff --git a/src/proto_alpha/lib_protocol/validate_errors.mli b/src/proto_alpha/lib_protocol/validate_errors.mli index 480c26cc20e7..671e936b94d3 100644 --- a/src/proto_alpha/lib_protocol/validate_errors.mli +++ b/src/proto_alpha/lib_protocol/validate_errors.mli @@ -252,14 +252,21 @@ module Manager : sig } | Incorrect_reveal_position | Update_consensus_key_with_tz4_without_proof of { + kind : Operation_repr.consensus_key_kind; source : public_key_hash; public_key : public_key; } | Update_consensus_key_with_incorrect_proof of { + kind : Operation_repr.consensus_key_kind; public_key : public_key; proof : Bls.t; } | Update_consensus_key_with_unused_proof of { + kind : Operation_repr.consensus_key_kind; + source : public_key_hash; + public_key : public_key; + } + | Update_companion_key_not_tz4 of { source : public_key_hash; public_key : public_key; } -- GitLab From 4588b25b16aab70c174ae16f14bb80b7ca0665ff Mon Sep 17 00:00:00 2001 From: Lucas Randazzo Date: Thu, 27 Mar 2025 15:26:20 +0100 Subject: [PATCH 04/13] Proto: validate update_companion_key --- src/proto_alpha/lib_protocol/validate.ml | 39 +++++++++++++++--------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/src/proto_alpha/lib_protocol/validate.ml b/src/proto_alpha/lib_protocol/validate.ml index 1255ab4efaee..71c2651884b3 100644 --- a/src/proto_alpha/lib_protocol/validate.ml +++ b/src/proto_alpha/lib_protocol/validate.ml @@ -2549,15 +2549,15 @@ module Manager = struct record_trace Gas.Gas_limit_too_high let check_update_consensus_key vi remaining_gas source - (public_key : Signature.Public_key.t) proof = + (public_key : Signature.Public_key.t) proof kind = let open Result_syntax in if Constants.allow_tz4_delegate_enable vi.ctxt then - match (public_key, proof) with - | Bls _bls_public_key, None -> + match (public_key, proof, kind) with + | Bls _bls_public_key, None, kind -> result_error (Validate_errors.Manager.Update_consensus_key_with_tz4_without_proof - {kind = Consensus; source; public_key}) - | Bls bls_public_key, Some _ -> + {kind; source; public_key}) + | Bls bls_public_key, Some _, _kind -> (* Compute the gas cost to encode the consensus public key and check the proof. *) let gas_cost_for_sig_check = @@ -2576,18 +2576,28 @@ module Manager = struct gas_cost_for_sig_check) in return_unit - | (Ed25519 _ | Secp256k1 _ | P256 _), Some _proof -> + | (Ed25519 _ | Secp256k1 _ | P256 _), _, Operation_repr.Companion -> + result_error + (Validate_errors.Manager.Update_companion_key_not_tz4 + {source; public_key}) + | (Ed25519 _ | Secp256k1 _ | P256 _), Some _proof, Consensus -> result_error (Validate_errors.Manager.Update_consensus_key_with_unused_proof {kind = Consensus; source; public_key}) - | (Ed25519 _ | Secp256k1 _ | P256 _), None -> return_unit + | (Ed25519 _ | Secp256k1 _ | P256 _), None, Consensus -> return_unit else let* () = Delegate.Consensus_key.check_not_tz4 public_key in - if Option.is_some proof then - result_error - (Validate_errors.Manager.Update_consensus_key_with_unused_proof - {kind = Consensus; source; public_key}) - else return_unit + match kind with + | Companion -> + result_error + (Validate_errors.Manager.Update_companion_key_not_tz4 + {source; public_key}) + | Consensus -> + if Option.is_some proof then + result_error + (Validate_errors.Manager.Update_consensus_key_with_unused_proof + {kind; source; public_key}) + else return_unit let check_kind_specific_content (type kind) (contents : kind Kind.manager contents) remaining_gas vi = @@ -2622,9 +2632,8 @@ module Manager = struct | Delegation (Some pkh) -> if Constants.allow_tz4_delegate_enable vi.ctxt then return_unit else Delegate.check_not_tz4 pkh - | Update_consensus_key {public_key; proof; kind = _} -> - (* TODO: handle companion *) - check_update_consensus_key vi remaining_gas source public_key proof + | Update_consensus_key {public_key; proof; kind} -> + check_update_consensus_key vi remaining_gas source public_key proof kind | Delegation None | Set_deposits_limit _ | Increase_paid_storage _ -> return_unit | Transfer_ticket {contents; ty; _} -> -- GitLab From 5628bc65e40c9ec9cf861ee6d915beae68715888 Mon Sep 17 00:00:00 2001 From: Lucas Randazzo Date: Thu, 27 Mar 2025 15:43:59 +0100 Subject: [PATCH 05/13] Proto: update_companion_key apply errors --- src/proto_alpha/lib_protocol/apply.ml | 22 ++++++++++++++-------- src/proto_alpha/lib_protocol/apply.mli | 3 ++- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/proto_alpha/lib_protocol/apply.ml b/src/proto_alpha/lib_protocol/apply.ml index b1f2be4515b1..b37332fd88ba 100644 --- a/src/proto_alpha/lib_protocol/apply.ml +++ b/src/proto_alpha/lib_protocol/apply.ml @@ -35,7 +35,8 @@ type error += | Set_deposits_limit_on_unregistered_delegate of Signature.Public_key_hash.t | Set_deposits_limit_when_automated_staking_off | Error_while_taking_fees - | Update_consensus_key_on_unregistered_delegate of Signature.Public_key_hash.t + | Update_consensus_key_on_unregistered_delegate of + (Signature.Public_key_hash.t * Operation_repr.consensus_key_kind) | Empty_transaction of Contract.t | Non_empty_transaction_from of Destination.t | Internal_operation_replay of @@ -115,14 +116,19 @@ let () = `Temporary ~id:"operation.update_consensus_key_on_unregistered_delegate" ~title:"Update consensus key on an unregistered delegate" - ~description:"Cannot update consensus key an unregistered delegate." - ~pp:(fun ppf c -> + ~description:"Cannot update consensus key for an unregistered delegate." + ~pp:(fun ppf (delegate, kind) -> Format.fprintf ppf - "Cannot update the consensus key on the unregistered delegate %a." + "Cannot update the %a key on the unregistered delegate %a." + Operation_repr.pp_consensus_key_kind + kind Signature.Public_key_hash.pp - c) - Data_encoding.(obj1 (req "delegate" Signature.Public_key_hash.encoding)) + delegate) + Data_encoding.( + obj2 + (req "delegate" Signature.Public_key_hash.encoding) + (req "kind" Operation_repr.consensus_key_kind_encoding)) (function | Update_consensus_key_on_unregistered_delegate c -> Some c | _ -> None) (fun c -> Update_consensus_key_on_unregistered_delegate c) ; @@ -1424,13 +1430,13 @@ let apply_manager_operation : } in (ctxt, result, []) - | Update_consensus_key {public_key; proof; kind = _} -> + | Update_consensus_key {public_key; proof; kind} -> (* TODO: handle companion *) let*! is_registered = Delegate.registered ctxt source in let*? () = error_unless is_registered - (Update_consensus_key_on_unregistered_delegate source) + (Update_consensus_key_on_unregistered_delegate (source, kind)) in let* ctxt = match (public_key, proof) with diff --git a/src/proto_alpha/lib_protocol/apply.mli b/src/proto_alpha/lib_protocol/apply.mli index 3c0c5198b471..444bd81de59a 100644 --- a/src/proto_alpha/lib_protocol/apply.mli +++ b/src/proto_alpha/lib_protocol/apply.mli @@ -40,7 +40,8 @@ type error += | Set_deposits_limit_on_unregistered_delegate of Signature.Public_key_hash.t | Set_deposits_limit_when_automated_staking_off | Error_while_taking_fees - | Update_consensus_key_on_unregistered_delegate of Signature.Public_key_hash.t + | Update_consensus_key_on_unregistered_delegate of + (Signature.Public_key_hash.t * Operation_repr.consensus_key_kind) | Empty_transaction of Contract.t | Non_empty_transaction_from of Destination.t | Internal_operation_replay of -- GitLab From 8928cb5d0057a4fb2f669c8f051cf8cbc42fb896 Mon Sep 17 00:00:00 2001 From: Lucas Randazzo Date: Wed, 19 Mar 2025 13:57:20 +0100 Subject: [PATCH 06/13] Proto: apply update companion key --- .../lib_protocol/alpha_context.mli | 3 +++ src/proto_alpha/lib_protocol/apply.ml | 19 ++++++++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index 53e220b71c2c..f878cd61c270 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -2389,6 +2389,9 @@ module Delegate : sig val register_update : context -> public_key_hash -> public_key -> context tzresult Lwt.t + + val register_update_companion : + context -> public_key_hash -> Bls.Public_key.t -> context tzresult Lwt.t end (** See {!Stake_storage.prepare_stake_distribution}. *) diff --git a/src/proto_alpha/lib_protocol/apply.ml b/src/proto_alpha/lib_protocol/apply.ml index b37332fd88ba..fce347a7ecc8 100644 --- a/src/proto_alpha/lib_protocol/apply.ml +++ b/src/proto_alpha/lib_protocol/apply.ml @@ -1431,13 +1431,13 @@ let apply_manager_operation : in (ctxt, result, []) | Update_consensus_key {public_key; proof; kind} -> - (* TODO: handle companion *) let*! is_registered = Delegate.registered ctxt source in let*? () = error_unless is_registered (Update_consensus_key_on_unregistered_delegate (source, kind)) in + (* Check proof *) let* ctxt = match (public_key, proof) with | Bls bls_public_key, Some proof -> @@ -1466,13 +1466,26 @@ let apply_manager_operation : (Signature.check public_key (Bls proof) bytes) (Validate_errors.Manager .Update_consensus_key_with_incorrect_proof - {kind = Consensus; public_key; proof}) + {kind; public_key; proof}) in return ctxt | _, _ -> return ctxt in + (* Register key *) let* ctxt = - Delegate.Consensus_key.register_update ctxt source public_key + match (public_key, kind) with + | _, Consensus -> + Delegate.Consensus_key.register_update ctxt source public_key + | Bls bls_pk, Companion -> + Delegate.Consensus_key.register_update_companion + ctxt + source + bls_pk + | (Ed25519 _ | Secp256k1 _ | P256 _), Companion -> + (* Should not happen if operation has been validated *) + tzfail + (Validate_errors.Manager.Update_companion_key_not_tz4 + {source; public_key}) in return ( ctxt, -- GitLab From 82ca0f6a4081e429b3e07ad756da797015cf37ea Mon Sep 17 00:00:00 2001 From: Lucas Randazzo Date: Wed, 19 Mar 2025 14:37:44 +0100 Subject: [PATCH 07/13] Proto: update operation encoding to discriminate companion update --- .../lib_protocol/alpha_context.mli | 4 ++ src/proto_alpha/lib_protocol/apply_results.ml | 18 +++++++- .../lib_protocol/operation_repr.ml | 45 ++++++++++++++++--- .../lib_protocol/operation_repr.mli | 4 ++ 4 files changed, 63 insertions(+), 8 deletions(-) diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index f878cd61c270..23c066b2adff 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -5032,6 +5032,8 @@ module Operation : sig val update_consensus_key_case : Kind.update_consensus_key Kind.manager case + val update_companion_key_case : Kind.update_consensus_key Kind.manager case + val transfer_ticket_case : Kind.transfer_ticket Kind.manager case val dal_publish_commitment_case : @@ -5095,6 +5097,8 @@ module Operation : sig val update_consensus_key_case : Kind.update_consensus_key case + val update_companion_key_case : Kind.update_consensus_key case + val register_global_constant_case : Kind.register_global_constant case val set_deposits_limit_case : Kind.set_deposits_limit case diff --git a/src/proto_alpha/lib_protocol/apply_results.ml b/src/proto_alpha/lib_protocol/apply_results.ml index 5a961b2c5abb..ea59262997a4 100644 --- a/src/proto_alpha/lib_protocol/apply_results.ml +++ b/src/proto_alpha/lib_protocol/apply_results.ml @@ -1511,7 +1511,22 @@ module Encoding = struct Manager_result.update_consensus_key_case (function | Contents_and_result - ( (Manager_operation {operation = Update_consensus_key _; _} as op), + ( (Manager_operation + {operation = Update_consensus_key {kind = Consensus; _}; _} as + op), + res ) -> + Some (op, res) + | _ -> None) + + let update_companion_key_case = + make_manager_case + Operation.Encoding.update_companion_key_case + Manager_result.update_consensus_key_case + (function + | Contents_and_result + ( (Manager_operation + {operation = Update_consensus_key {kind = Companion; _}; _} as + op), res ) -> Some (op, res) | _ -> None) @@ -1713,6 +1728,7 @@ let common_cases = set_deposits_limit_case; increase_paid_storage_case; update_consensus_key_case; + update_companion_key_case; transfer_ticket_case; dal_publish_commitment_case; sc_rollup_originate_case; diff --git a/src/proto_alpha/lib_protocol/operation_repr.ml b/src/proto_alpha/lib_protocol/operation_repr.ml index 60b50da6aad2..afffce57b7df 100644 --- a/src/proto_alpha/lib_protocol/operation_repr.ml +++ b/src/proto_alpha/lib_protocol/operation_repr.ml @@ -775,19 +775,46 @@ module Encoding = struct tag = update_consensus_key_tag; name = "update_consensus_key"; encoding = - obj3 + obj2 (req "pk" Signature.Public_key.encoding) - (req "kind" Delegate_consensus_key.kind_encoding) (opt "proof" (dynamic_size Bls.encoding)); select = (function - | Manager (Update_consensus_key _ as op) -> Some op | _ -> None); + | Manager + (Update_consensus_key + {public_key = _; proof = _; kind = Consensus} as op) -> + Some op + | _ -> None); proj = - (fun (Update_consensus_key {public_key; proof; kind}) -> - (public_key, kind, proof)); + (fun (Update_consensus_key {public_key; proof; kind = _}) -> + (public_key, proof)); inj = - (fun (public_key, kind, proof) -> - Update_consensus_key {public_key; proof; kind}); + (fun (public_key, proof) -> + Update_consensus_key {public_key; proof; kind = Consensus}); + } + + let update_companion_key_case = + MCase + { + tag = 32; + name = "update_companion_key"; + encoding = + obj2 + (req "pk" Signature.Public_key.encoding) + (opt "proof" (dynamic_size Bls.encoding)); + select = + (function + | Manager + (Update_consensus_key + {public_key = _; proof = _; kind = Companion} as op) -> + Some op + | _ -> None); + proj = + (fun (Update_consensus_key {public_key; proof; kind = _}) -> + (public_key, proof)); + inj = + (fun (public_key, proof) -> + Update_consensus_key {public_key; proof; kind = Companion}); } let transfer_ticket_case = @@ -1479,6 +1506,9 @@ module Encoding = struct let update_consensus_key_case = make_manager_case 114 Manager_operations.update_consensus_key_case + let update_companion_key_case = + make_manager_case 115 Manager_operations.update_companion_key_case + let transfer_ticket_case = make_manager_case transfer_ticket_tag @@ -1565,6 +1595,7 @@ module Encoding = struct PCase set_deposits_limit_case; PCase increase_paid_storage_case; PCase update_consensus_key_case; + PCase update_companion_key_case; PCase drain_delegate_case; PCase failing_noop_case; PCase register_global_constant_case; diff --git a/src/proto_alpha/lib_protocol/operation_repr.mli b/src/proto_alpha/lib_protocol/operation_repr.mli index 17363118f90b..8e02274bb133 100644 --- a/src/proto_alpha/lib_protocol/operation_repr.mli +++ b/src/proto_alpha/lib_protocol/operation_repr.mli @@ -772,6 +772,8 @@ module Encoding : sig val update_consensus_key_case : Kind.update_consensus_key Kind.manager case + val update_companion_key_case : Kind.update_consensus_key Kind.manager case + val register_global_constant_case : Kind.register_global_constant Kind.manager case @@ -833,6 +835,8 @@ module Encoding : sig val update_consensus_key_case : Kind.update_consensus_key case + val update_companion_key_case : Kind.update_consensus_key case + val register_global_constant_case : Kind.register_global_constant case val set_deposits_limit_case : Kind.set_deposits_limit case -- GitLab From 01f104fe3010d3c536238dd0c6a0d058123bf681 Mon Sep 17 00:00:00 2001 From: Lucas Randazzo Date: Wed, 19 Mar 2025 14:50:02 +0100 Subject: [PATCH 08/13] Tezt/encoding: add encoding test for update companion key --- ....unsigned-update-companion-key.sample.json | 13 ++++++++ ...operation-update-companion-key.sample.json | 14 ++++++++ ...ol encoding regression test- operation.out | 32 +++++++++++++++++++ ...ng regression test- operation.unsigned.out | 29 +++++++++++++++++ 4 files changed, 88 insertions(+) create mode 100644 tezt/tests/encoding_samples/alpha/operation.unsigned/operation.unsigned-update-companion-key.sample.json create mode 100644 tezt/tests/encoding_samples/alpha/operation/operation-update-companion-key.sample.json diff --git a/tezt/tests/encoding_samples/alpha/operation.unsigned/operation.unsigned-update-companion-key.sample.json b/tezt/tests/encoding_samples/alpha/operation.unsigned/operation.unsigned-update-companion-key.sample.json new file mode 100644 index 000000000000..2b3b5f717b25 --- /dev/null +++ b/tezt/tests/encoding_samples/alpha/operation.unsigned/operation.unsigned-update-companion-key.sample.json @@ -0,0 +1,13 @@ +{ + "branch": "BKpbfCvh777DQHnXjU2sqHvVUNZ7dBAdqEfKkdw8EGSkD9LSYXb", + "contents": [{ + "kind": "update_companion_key", + "source": "tz4XsUYECWrJ5c4gktAnr1nkFC9mjDEVn3qh", + "fee": "33", + "counter": "732", + "gas_limit": "9451117", + "storage_limit": "57024931117", + "pk": "BLpk1xXdveUYh7YFsyf6LwGWfv5zAfLvnMG71byiMFDZc4CkXzZPVko3Dz4sD43Ln5uFNvdjiQJY", + "proof": "BLsigA5hv9bjFDmrbvVfam6CaXM87xZv1GYhFmn3uaR4LTXahHpADaNk9LcEcQb2EF1w9b72AutNqPxzVT5EhRFQN1Ue43XA3HkMfmCYTCHa3WiLsJYLmuQvchTwoMy8zx8EibsZAJ3Dug" + }] +} diff --git a/tezt/tests/encoding_samples/alpha/operation/operation-update-companion-key.sample.json b/tezt/tests/encoding_samples/alpha/operation/operation-update-companion-key.sample.json new file mode 100644 index 000000000000..6a3ff5e22536 --- /dev/null +++ b/tezt/tests/encoding_samples/alpha/operation/operation-update-companion-key.sample.json @@ -0,0 +1,14 @@ +{ + "branch": "BKpbfCvh777DQHnXjU2sqHvVUNZ7dBAdqEfKkdw8EGSkD9LSYXb", + "contents": [{ + "kind": "update_companion_key", + "source": "tz4XsUYECWrJ5c4gktAnr1nkFC9mjDEVn3qh", + "fee": "33", + "counter": "732", + "gas_limit": "9451117", + "storage_limit": "57024931117", + "pk": "BLpk1xXdveUYh7YFsyf6LwGWfv5zAfLvnMG71byiMFDZc4CkXzZPVko3Dz4sD43Ln5uFNvdjiQJY", + "proof": "BLsigA5hv9bjFDmrbvVfam6CaXM87xZv1GYhFmn3uaR4LTXahHpADaNk9LcEcQb2EF1w9b72AutNqPxzVT5EhRFQN1Ue43XA3HkMfmCYTCHa3WiLsJYLmuQvchTwoMy8zx8EibsZAJ3Dug" + }], + "signature": "BLsigAV587qg1S78p9hRyfmcqM6cVxsafJ9MVRWLLxfykmdB7LcpMWgLZjSQfhbuffvJovUsS9vJpesiwJm9xEhZPjW93DB5tjSUkUrXcQpTVGoJe4KsGR16BUdVEZQuXeW2XjUk9BqYSP" +} diff --git a/tezt/tests/expected/encoding.ml/Alpha- protocol encoding regression test- operation.out b/tezt/tests/expected/encoding.ml/Alpha- protocol encoding regression test- operation.out index 885b089efe7f..8eff237d57a6 100644 --- a/tezt/tests/expected/encoding.ml/Alpha- protocol encoding regression test- operation.out +++ b/tezt/tests/expected/encoding.ml/Alpha- protocol encoding regression test- operation.out @@ -620,6 +620,38 @@ "signature": "sigbQ5ZNvkjvGssJgoAnUAfY4Wvvg3QZqawBYB1j1VDBNTMBAALnCzRHWzer34bnfmzgHg3EvwdzQKdxgSghB897cono6gbQ" } +./octez-codec encode alpha.operation from '{ + "branch": "BKpbfCvh777DQHnXjU2sqHvVUNZ7dBAdqEfKkdw8EGSkD9LSYXb", + "contents": [ + { + "kind": "update_companion_key", + "source": "tz4XsUYECWrJ5c4gktAnr1nkFC9mjDEVn3qh", + "fee": "33", + "counter": "732", + "gas_limit": "9451117", + "storage_limit": "57024931117", + "pk": "BLpk1xXdveUYh7YFsyf6LwGWfv5zAfLvnMG71byiMFDZc4CkXzZPVko3Dz4sD43Ln5uFNvdjiQJY", + "proof": "BLsigA5hv9bjFDmrbvVfam6CaXM87xZv1GYhFmn3uaR4LTXahHpADaNk9LcEcQb2EF1w9b72AutNqPxzVT5EhRFQN1Ue43XA3HkMfmCYTCHa3WiLsJYLmuQvchTwoMy8zx8EibsZAJ3Dug" + } + ], + "signature": "BLsigAV587qg1S78p9hRyfmcqM6cVxsafJ9MVRWLLxfykmdB7LcpMWgLZjSQfhbuffvJovUsS9vJpesiwJm9xEhZPjW93DB5tjSUkUrXcQpTVGoJe4KsGR16BUdVEZQuXeW2XjUk9BqYSP" +}' +0e5751c026e543b2e8ab2eb06099daa1d1e5df47778f7787faab45cdf12fe3a87303fad261084d3e363c48b61d2ad617de8b798841ff21dc05edecc004adcacdb7d40103b1835898e501798f26d7ee20cb772fedc4e4e0e963f6ef47a7925ac9cfb61d5100bde3ee7f1e9e37175842b3d378776dff000000608ed0b1d82e17ce7e927ffd9470f8208ec5d8d32556135c2c670000815f20a81b9de3f2ac50919751b4872644be2f75cb041108a9fbf9b550b6c5f90b5626d5a99f7784b11194561768220cff18e9a142a4246d279311f46de4ba9727740c6438ff03992e5281475b5634a6d9f0637d2da0e7d75a2b49d43893c68dcffdfa4d2e45c8d119d7a253e2e981ed1c788d3854d0020ffc9091e355c3287eda37d2163d0a56f3ef36268fcc176f063715a1fe97c746cbedf1f8cd76ee73e1e48c0d9c23ea0c + +./octez-codec decode alpha.operation from 0e5751c026e543b2e8ab2eb06099daa1d1e5df47778f7787faab45cdf12fe3a87303fad261084d3e363c48b61d2ad617de8b798841ff21dc05edecc004adcacdb7d40103b1835898e501798f26d7ee20cb772fedc4e4e0e963f6ef47a7925ac9cfb61d5100bde3ee7f1e9e37175842b3d378776dff000000608ed0b1d82e17ce7e927ffd9470f8208ec5d8d32556135c2c670000815f20a81b9de3f2ac50919751b4872644be2f75cb041108a9fbf9b550b6c5f90b5626d5a99f7784b11194561768220cff18e9a142a4246d279311f46de4ba9727740c6438ff03992e5281475b5634a6d9f0637d2da0e7d75a2b49d43893c68dcffdfa4d2e45c8d119d7a253e2e981ed1c788d3854d0020ffc9091e355c3287eda37d2163d0a56f3ef36268fcc176f063715a1fe97c746cbedf1f8cd76ee73e1e48c0d9c23ea0c +{ "branch": "BKpbfCvh777DQHnXjU2sqHvVUNZ7dBAdqEfKkdw8EGSkD9LSYXb", + "contents": + [ { "kind": "update_companion_key", + "source": "tz4XsUYECWrJ5c4gktAnr1nkFC9mjDEVn3qh", "fee": "33", + "counter": "732", "gas_limit": "9451117", + "storage_limit": "57024931117", + "pk": + "BLpk1xXdveUYh7YFsyf6LwGWfv5zAfLvnMG71byiMFDZc4CkXzZPVko3Dz4sD43Ln5uFNvdjiQJY", + "proof": + "BLsigA5hv9bjFDmrbvVfam6CaXM87xZv1GYhFmn3uaR4LTXahHpADaNk9LcEcQb2EF1w9b72AutNqPxzVT5EhRFQN1Ue43XA3HkMfmCYTCHa3WiLsJYLmuQvchTwoMy8zx8EibsZAJ3Dug" } ], + "signature": + "BLsigAV587qg1S78p9hRyfmcqM6cVxsafJ9MVRWLLxfykmdB7LcpMWgLZjSQfhbuffvJovUsS9vJpesiwJm9xEhZPjW93DB5tjSUkUrXcQpTVGoJe4KsGR16BUdVEZQuXeW2XjUk9BqYSP" } + ./octez-codec encode alpha.operation from '{ "branch": "BKpbfCvh777DQHnXjU2sqHvVUNZ7dBAdqEfKkdw8EGSkD9LSYXb", "contents": [ diff --git a/tezt/tests/expected/encoding.ml/Alpha- protocol encoding regression test- operation.unsigned.out b/tezt/tests/expected/encoding.ml/Alpha- protocol encoding regression test- operation.unsigned.out index f65bdbb5ac4e..416b19714b55 100644 --- a/tezt/tests/expected/encoding.ml/Alpha- protocol encoding regression test- operation.unsigned.out +++ b/tezt/tests/expected/encoding.ml/Alpha- protocol encoding regression test- operation.unsigned.out @@ -601,6 +601,35 @@ "parameters": { "entrypoint": "action", "value": [ { "prim": "UNIT" } ] } } ] } +./octez-codec encode alpha.operation.unsigned from '{ + "branch": "BKpbfCvh777DQHnXjU2sqHvVUNZ7dBAdqEfKkdw8EGSkD9LSYXb", + "contents": [ + { + "kind": "update_companion_key", + "source": "tz4XsUYECWrJ5c4gktAnr1nkFC9mjDEVn3qh", + "fee": "33", + "counter": "732", + "gas_limit": "9451117", + "storage_limit": "57024931117", + "pk": "BLpk1xXdveUYh7YFsyf6LwGWfv5zAfLvnMG71byiMFDZc4CkXzZPVko3Dz4sD43Ln5uFNvdjiQJY", + "proof": "BLsigA5hv9bjFDmrbvVfam6CaXM87xZv1GYhFmn3uaR4LTXahHpADaNk9LcEcQb2EF1w9b72AutNqPxzVT5EhRFQN1Ue43XA3HkMfmCYTCHa3WiLsJYLmuQvchTwoMy8zx8EibsZAJ3Dug" + } + ] +}' +0e5751c026e543b2e8ab2eb06099daa1d1e5df47778f7787faab45cdf12fe3a87303fad261084d3e363c48b61d2ad617de8b798841ff21dc05edecc004adcacdb7d40103b1835898e501798f26d7ee20cb772fedc4e4e0e963f6ef47a7925ac9cfb61d5100bde3ee7f1e9e37175842b3d378776dff000000608ed0b1d82e17ce7e927ffd9470f8208ec5d8d32556135c2c670000815f20a81b9de3f2ac50919751b4872644be2f75cb041108a9fbf9b550b6c5f90b5626d5a99f7784b11194561768220cff18e9a142a4246d279311f46de4ba9727740c6438 + +./octez-codec decode alpha.operation.unsigned from 0e5751c026e543b2e8ab2eb06099daa1d1e5df47778f7787faab45cdf12fe3a87303fad261084d3e363c48b61d2ad617de8b798841ff21dc05edecc004adcacdb7d40103b1835898e501798f26d7ee20cb772fedc4e4e0e963f6ef47a7925ac9cfb61d5100bde3ee7f1e9e37175842b3d378776dff000000608ed0b1d82e17ce7e927ffd9470f8208ec5d8d32556135c2c670000815f20a81b9de3f2ac50919751b4872644be2f75cb041108a9fbf9b550b6c5f90b5626d5a99f7784b11194561768220cff18e9a142a4246d279311f46de4ba9727740c6438 +{ "branch": "BKpbfCvh777DQHnXjU2sqHvVUNZ7dBAdqEfKkdw8EGSkD9LSYXb", + "contents": + [ { "kind": "update_companion_key", + "source": "tz4XsUYECWrJ5c4gktAnr1nkFC9mjDEVn3qh", "fee": "33", + "counter": "732", "gas_limit": "9451117", + "storage_limit": "57024931117", + "pk": + "BLpk1xXdveUYh7YFsyf6LwGWfv5zAfLvnMG71byiMFDZc4CkXzZPVko3Dz4sD43Ln5uFNvdjiQJY", + "proof": + "BLsigA5hv9bjFDmrbvVfam6CaXM87xZv1GYhFmn3uaR4LTXahHpADaNk9LcEcQb2EF1w9b72AutNqPxzVT5EhRFQN1Ue43XA3HkMfmCYTCHa3WiLsJYLmuQvchTwoMy8zx8EibsZAJ3Dug" } ] } + ./octez-codec encode alpha.operation.unsigned from '{ "branch": "BKpbfCvh777DQHnXjU2sqHvVUNZ7dBAdqEfKkdw8EGSkD9LSYXb", "contents": [ -- GitLab From 6ed12eaf2b0b98d70bb2418f3945a1b3090d7567 Mon Sep 17 00:00:00 2001 From: Lucas Randazzo Date: Wed, 19 Mar 2025 15:16:00 +0100 Subject: [PATCH 09/13] Proto/client: add update companion key commands --- .../lib_client/client_proto_context.ml | 29 +++++++----- .../lib_client/client_proto_context.mli | 16 +++++++ .../client_proto_context_commands.ml | 46 +++++++++++++++++++ 3 files changed, 80 insertions(+), 11 deletions(-) diff --git a/src/proto_alpha/lib_client/client_proto_context.ml b/src/proto_alpha/lib_client/client_proto_context.ml index fedbed8e1da2..5b682f90559d 100644 --- a/src/proto_alpha/lib_client/client_proto_context.ml +++ b/src/proto_alpha/lib_client/client_proto_context.ml @@ -355,7 +355,7 @@ let set_delegate cctxt ~chain ~block ?confirmations ?dry_run ?verbose_signing opt_delegate let build_update_consensus_key cctxt ?fee ?gas_limit ?storage_limit - ?secret_key_uri public_key = + ?secret_key_uri ~kind public_key = let open Lwt_result_syntax in let* proof = match ((public_key : Signature.public_key), secret_key_uri) with @@ -371,11 +371,7 @@ let build_update_consensus_key cctxt ?fee ?gas_limit ?storage_limit | _ -> tzfail (Unexpected_proof_of_possession_format proof)) | _ -> return_none in - let operation = - Update_consensus_key - {public_key; proof; kind = Delegate_consensus_key.Consensus} - in - (* TODO: handle companion *) + let operation = Update_consensus_key {public_key; proof; kind} in return @@ Injection.prepare_manager_operation ~fee:(Limit.of_option fee) @@ -414,7 +410,12 @@ let register_as_delegate cctxt ~chain ~block ?confirmations ?dry_run | Some (public_key, secret_key_uri) -> ( let* operation = let+ operation_content = - build_update_consensus_key cctxt ?fee ?secret_key_uri public_key + build_update_consensus_key + cctxt + ~kind:Consensus + ?fee + ?secret_key_uri + public_key in Annotated_manager_operation.Cons_manager ( delegate_op, @@ -448,13 +449,13 @@ let register_as_delegate cctxt ~chain ~block ?confirmations ?dry_run Single_and_result ((Manager_operation _ as op2), res2) ) -> return ((oph, op1, res1), Some (op2, res2))) -let update_consensus_key cctxt ~chain ~block ?confirmations ?dry_run - ?verbose_signing ?simulation ?fee ?secret_key_uri ~public_key ~manager_sk - ~fee_parameter src_pk = +let update_consensus_or_companion_key ~kind cctxt ~chain ~block ?confirmations + ?dry_run ?verbose_signing ?simulation ?fee ?secret_key_uri ~public_key + ~manager_sk ~fee_parameter src_pk = let open Lwt_result_syntax in let source = Signature.Public_key.hash src_pk in let* operation = - build_update_consensus_key cctxt ?fee ?secret_key_uri public_key + build_update_consensus_key cctxt ?fee ?secret_key_uri ~kind public_key in let operation = Annotated_manager_operation.Single_manager operation in let* oph, _, op, result = @@ -480,6 +481,12 @@ let update_consensus_key cctxt ~chain ~block ?confirmations ?dry_run | Apply_results.Single_and_result ((Manager_operation _ as op), result) -> return (oph, op, result) +let update_consensus_key cctxt = + update_consensus_or_companion_key ~kind:Consensus cctxt + +let update_companion_key cctxt = + update_consensus_or_companion_key ~kind:Companion cctxt + let drain_delegate cctxt ~chain ~block ?confirmations ?dry_run ?verbose_signing ?simulation ~consensus_sk ~consensus_pkh ?(destination = consensus_pkh) ~delegate () = diff --git a/src/proto_alpha/lib_client/client_proto_context.mli b/src/proto_alpha/lib_client/client_proto_context.mli index c33a513fe4fd..37aaf126b72c 100644 --- a/src/proto_alpha/lib_client/client_proto_context.mli +++ b/src/proto_alpha/lib_client/client_proto_context.mli @@ -216,6 +216,22 @@ val update_consensus_key : Signature.public_key -> Kind.update_consensus_key Kind.manager Injection.result tzresult Lwt.t +val update_companion_key : + #Protocol_client_context.full -> + chain:Shell_services.chain -> + block:Shell_services.block -> + ?confirmations:int -> + ?dry_run:bool -> + ?verbose_signing:bool -> + ?simulation:bool -> + ?fee:Tez.t -> + ?secret_key_uri:Client_keys.sk_uri -> + public_key:Signature.public_key -> + manager_sk:Client_keys.sk_uri -> + fee_parameter:Injection.fee_parameter -> + Signature.public_key -> + Kind.update_consensus_key Kind.manager Injection.result tzresult Lwt.t + val drain_delegate : #Protocol_client_context.full -> chain:Shell_services.chain -> 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..d39934e44203 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 @@ -2423,6 +2423,52 @@ let commands_rw () = delegate_pk in match r with Ok _ -> return_unit | Error el -> Lwt.return_error el); + command + ~group + ~desc:"Update the companion key of a delegate." + (args4 fee_arg dry_run_switch verbose_signing_switch fee_parameter_args) + (prefixes ["set"; "companion"; "key"; "for"] + @@ Public_key_hash.source_param ~name:"mgr" ~desc:"the delegate key" + @@ prefixes ["to"] + @@ Public_key.source_param ~name:"key" ~desc:"the companion key" + @@ stop) + (fun (fee, dry_run, verbose_signing, fee_parameter) + delegate_pkh + (name_pk, public_key) + cctxt -> + let open Lwt_result_syntax in + let* _, delegate_pk, delegate_sk = + Client_keys.get_key cctxt delegate_pkh + in + let* public_key = + match public_key with + | Some pk -> return pk + | None -> Client_keys.public_key name_pk + in + let* secret_key_uri = + match public_key with + | Bls _ -> + 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 + | _ -> return_none + in + let*! r = + update_companion_key + cctxt + ~chain:cctxt#chain + ~block:cctxt#block + ?confirmations:cctxt#confirmations + ~dry_run + ~fee_parameter + ~verbose_signing + ?fee + ?secret_key_uri + ~public_key + ~manager_sk:delegate_sk + delegate_pk + in + match r with Ok _ -> return_unit | Error el -> Lwt.return_error el); command ~group ~desc:"Drain all funds from a delegate." -- GitLab From c98d57cd599e799dd50a6f13c3105fcd07356c68 Mon Sep 17 00:00:00 2001 From: Lucas Randazzo Date: Wed, 19 Mar 2025 15:17:29 +0100 Subject: [PATCH 10/13] Proto/client: operation result handling when updating companion --- src/proto_alpha/lib_client/operation_result.ml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/proto_alpha/lib_client/operation_result.ml b/src/proto_alpha/lib_client/operation_result.ml index b1dd87a90120..e1d4ffac56c7 100644 --- a/src/proto_alpha/lib_client/operation_result.ml +++ b/src/proto_alpha/lib_client/operation_result.ml @@ -234,11 +234,12 @@ let pp_manager_operation_content (type kind) source ppf source Contract_hash.pp destination - | Update_consensus_key {public_key = pk; proof; kind = _} -> - (* TODO: handle companion *) + | Update_consensus_key {public_key = pk; proof; kind} -> Format.fprintf ppf - "Update_consensus_key:@,Public key hash: %a%a" + "Update_%a_key:@,Public key hash: %a%a" + Operation_repr.pp_consensus_key_kind + kind Signature.Public_key_hash.pp (Signature.Public_key.hash pk) (fun ppf proof -> -- GitLab From 12829c184613a4ceea7cc18a39bd144837baa2ba Mon Sep 17 00:00:00 2001 From: Lucas Randazzo Date: Wed, 19 Mar 2025 15:20:16 +0100 Subject: [PATCH 11/13] Proto/tests: add update_companion in tests --- src/proto_alpha/lib_protocol/test/helpers/op.ml | 10 ++++++---- src/proto_alpha/lib_protocol/test/helpers/op.mli | 12 ++++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/proto_alpha/lib_protocol/test/helpers/op.ml b/src/proto_alpha/lib_protocol/test/helpers/op.ml index a50834903bd4..71bac6bd8874 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/op.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/op.ml @@ -1124,8 +1124,8 @@ let zk_rollup_origination ?force_reveal ?counter ?fee ?gas_limit ?storage_limit let addr = originated_zk_rollup op in return (op, addr) -let update_consensus_key ?force_reveal ?counter ?fee ?gas_limit ?storage_limit - ?proof_signer ctxt (src : Contract.t) public_key = +let update_consensus_or_companion ~kind ?force_reveal ?counter ?fee ?gas_limit + ?storage_limit ?proof_signer ctxt (src : Contract.t) public_key = let open Lwt_result_syntax in let* proof = match proof_signer with @@ -1144,8 +1144,6 @@ let update_consensus_key ?force_reveal ?counter ?fee ?gas_limit ?storage_limit "Can't forge an Update_consensus_key with a non-BLS proof of \ possession.") in - (* TODO: handle companion *) - let kind = Delegate_consensus_key.Consensus in let* to_sign_op = manager_operation ?force_reveal @@ -1160,6 +1158,10 @@ let update_consensus_key ?force_reveal ?counter ?fee ?gas_limit ?storage_limit let* account = Context.Contract.manager ctxt src in sign ctxt account.sk (Context.branch ctxt) to_sign_op +let update_consensus_key = update_consensus_or_companion ~kind:Consensus + +let update_companion_key = update_consensus_or_companion ~kind:Companion + let drain_delegate ctxt ~consensus_key ~delegate ~destination = let open Lwt_result_syntax in let contents = diff --git a/src/proto_alpha/lib_protocol/test/helpers/op.mli b/src/proto_alpha/lib_protocol/test/helpers/op.mli index 8e8335dc74b9..7c5779656dff 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/op.mli +++ b/src/proto_alpha/lib_protocol/test/helpers/op.mli @@ -669,6 +669,18 @@ val update_consensus_key : public_key -> (packed_operation, tztrace) result Lwt.t +val update_companion_key : + ?force_reveal:bool -> + ?counter:Manager_counter.t -> + ?fee:Tez.t -> + ?gas_limit:gas_limit -> + ?storage_limit:Z.t -> + ?proof_signer:Contract.t -> + Context.t -> + Contract.t -> + public_key -> + (packed_operation, tztrace) result Lwt.t + val drain_delegate : Context.t -> consensus_key:Signature.Public_key_hash.t -> -- GitLab From 1ee1baec95f9de6484b922e6f857b216fdeec4d9 Mon Sep 17 00:00:00 2001 From: Lucas Randazzo Date: Wed, 19 Mar 2025 16:47:16 +0100 Subject: [PATCH 12/13] Kaitai: update --- .../files/alpha__operation.ksy | 26 +++++++++++++++++++ .../alpha__operation__bls_mode_unsigned.ksy | 26 +++++++++++++++++++ .../files/alpha__operation__contents.ksy | 26 +++++++++++++++++++ .../files/alpha__operation__contents_list.ksy | 26 +++++++++++++++++++ .../files/alpha__operation__protocol_data.ksy | 26 +++++++++++++++++++ .../files/alpha__operation__unsigned.ksy | 26 +++++++++++++++++++ 6 files changed, 156 insertions(+) diff --git a/client-libs/kaitai-struct-files/files/alpha__operation.ksy b/client-libs/kaitai-struct-files/files/alpha__operation.ksy index 59f53a51eb1c..8e1576737d42 100644 --- a/client-libs/kaitai-struct-files/files/alpha__operation.ksy +++ b/client-libs/kaitai-struct-files/files/alpha__operation.ksy @@ -196,6 +196,9 @@ types: - id: update_consensus_key type: update_consensus_key if: (alpha__operation__alpha__contents_or_signature_prefix_tag == alpha__operation__alpha__contents_or_signature_prefix_tag::update_consensus_key) + - id: update_companion_key + type: update_companion_key + if: (alpha__operation__alpha__contents_or_signature_prefix_tag == alpha__operation__alpha__contents_or_signature_prefix_tag::update_companion_key) - id: drain_delegate type: drain_delegate if: (alpha__operation__alpha__contents_or_signature_prefix_tag == alpha__operation__alpha__contents_or_signature_prefix_tag::drain_delegate) @@ -1461,6 +1464,28 @@ types: type: new_state_0 - id: proof type: bytes_dyn_uint30 + update_companion_key: + seq: + - id: source + type: public_key_hash + doc: A Ed25519, Secp256k1, P256, or BLS public key hash + - id: fee + type: alpha__mutez + - id: counter + type: n + - id: gas_limit + type: n + - id: storage_limit + type: n + - id: pk + type: public_key + doc: A Ed25519, Secp256k1, or P256 public key + - id: proof_tag + type: u1 + enum: bool + - id: proof + type: proof_0 + if: (proof_tag == bool::true) update_consensus_key: seq: - id: source @@ -2014,6 +2039,7 @@ enums: 112: set_deposits_limit 113: increase_paid_storage 114: update_consensus_key + 115: update_companion_key 158: transfer_ticket 200: smart_rollup_originate 201: smart_rollup_add_messages diff --git a/client-libs/kaitai-struct-files/files/alpha__operation__bls_mode_unsigned.ksy b/client-libs/kaitai-struct-files/files/alpha__operation__bls_mode_unsigned.ksy index 1d8071a35038..47e569bfda19 100644 --- a/client-libs/kaitai-struct-files/files/alpha__operation__bls_mode_unsigned.ksy +++ b/client-libs/kaitai-struct-files/files/alpha__operation__bls_mode_unsigned.ksy @@ -182,6 +182,9 @@ types: - id: update_consensus_key type: update_consensus_key if: (alpha__operation__alpha__bls_mode_contents_tag == alpha__operation__alpha__bls_mode_contents_tag::update_consensus_key) + - id: update_companion_key + type: update_companion_key + if: (alpha__operation__alpha__bls_mode_contents_tag == alpha__operation__alpha__bls_mode_contents_tag::update_companion_key) - id: drain_delegate type: drain_delegate if: (alpha__operation__alpha__bls_mode_contents_tag == alpha__operation__alpha__bls_mode_contents_tag::drain_delegate) @@ -1468,6 +1471,28 @@ types: type: new_state_0 - id: proof type: bytes_dyn_uint30 + update_companion_key: + seq: + - id: source + type: public_key_hash + doc: A Ed25519, Secp256k1, P256, or BLS public key hash + - id: fee + type: alpha__mutez + - id: counter + type: n + - id: gas_limit + type: n + - id: storage_limit + type: n + - id: pk + type: public_key + doc: A Ed25519, Secp256k1, or P256 public key + - id: proof_tag + type: u1 + enum: bool + - id: proof + type: proof_0 + if: (proof_tag == bool::true) update_consensus_key: seq: - id: source @@ -2020,6 +2045,7 @@ enums: 112: set_deposits_limit 113: increase_paid_storage 114: update_consensus_key + 115: update_companion_key 158: transfer_ticket 200: smart_rollup_originate 201: smart_rollup_add_messages diff --git a/client-libs/kaitai-struct-files/files/alpha__operation__contents.ksy b/client-libs/kaitai-struct-files/files/alpha__operation__contents.ksy index 8b65070b8e68..533fd67c91a2 100644 --- a/client-libs/kaitai-struct-files/files/alpha__operation__contents.ksy +++ b/client-libs/kaitai-struct-files/files/alpha__operation__contents.ksy @@ -185,6 +185,9 @@ types: - id: update_consensus_key type: update_consensus_key if: (alpha__operation__alpha__contents_tag == alpha__operation__alpha__contents_tag::update_consensus_key) + - id: update_companion_key + type: update_companion_key + if: (alpha__operation__alpha__contents_tag == alpha__operation__alpha__contents_tag::update_companion_key) - id: drain_delegate type: drain_delegate if: (alpha__operation__alpha__contents_tag == alpha__operation__alpha__contents_tag::drain_delegate) @@ -1438,6 +1441,28 @@ types: type: new_state_0 - id: proof type: bytes_dyn_uint30 + update_companion_key: + seq: + - id: source + type: public_key_hash + doc: A Ed25519, Secp256k1, P256, or BLS public key hash + - id: fee + type: alpha__mutez + - id: counter + type: n + - id: gas_limit + type: n + - id: storage_limit + type: n + - id: pk + type: public_key + doc: A Ed25519, Secp256k1, or P256 public key + - id: proof_tag + type: u1 + enum: bool + - id: proof + type: proof_0 + if: (proof_tag == bool::true) update_consensus_key: seq: - id: source @@ -1991,6 +2016,7 @@ enums: 112: set_deposits_limit 113: increase_paid_storage 114: update_consensus_key + 115: update_companion_key 158: transfer_ticket 200: smart_rollup_originate 201: smart_rollup_add_messages diff --git a/client-libs/kaitai-struct-files/files/alpha__operation__contents_list.ksy b/client-libs/kaitai-struct-files/files/alpha__operation__contents_list.ksy index fe57635c705d..476a78d54d70 100644 --- a/client-libs/kaitai-struct-files/files/alpha__operation__contents_list.ksy +++ b/client-libs/kaitai-struct-files/files/alpha__operation__contents_list.ksy @@ -185,6 +185,9 @@ types: - id: update_consensus_key type: update_consensus_key if: (alpha__operation__alpha__contents_tag == alpha__operation__alpha__contents_tag::update_consensus_key) + - id: update_companion_key + type: update_companion_key + if: (alpha__operation__alpha__contents_tag == alpha__operation__alpha__contents_tag::update_companion_key) - id: drain_delegate type: drain_delegate if: (alpha__operation__alpha__contents_tag == alpha__operation__alpha__contents_tag::drain_delegate) @@ -1442,6 +1445,28 @@ types: type: new_state_0 - id: proof type: bytes_dyn_uint30 + update_companion_key: + seq: + - id: source + type: public_key_hash + doc: A Ed25519, Secp256k1, P256, or BLS public key hash + - id: fee + type: alpha__mutez + - id: counter + type: n + - id: gas_limit + type: n + - id: storage_limit + type: n + - id: pk + type: public_key + doc: A Ed25519, Secp256k1, or P256 public key + - id: proof_tag + type: u1 + enum: bool + - id: proof + type: proof_0 + if: (proof_tag == bool::true) update_consensus_key: seq: - id: source @@ -1995,6 +2020,7 @@ enums: 112: set_deposits_limit 113: increase_paid_storage 114: update_consensus_key + 115: update_companion_key 158: transfer_ticket 200: smart_rollup_originate 201: smart_rollup_add_messages diff --git a/client-libs/kaitai-struct-files/files/alpha__operation__protocol_data.ksy b/client-libs/kaitai-struct-files/files/alpha__operation__protocol_data.ksy index 644e75aea000..41fdb4524195 100644 --- a/client-libs/kaitai-struct-files/files/alpha__operation__protocol_data.ksy +++ b/client-libs/kaitai-struct-files/files/alpha__operation__protocol_data.ksy @@ -196,6 +196,9 @@ types: - id: update_consensus_key type: update_consensus_key if: (alpha__operation__alpha__contents_or_signature_prefix_tag == alpha__operation__alpha__contents_or_signature_prefix_tag::update_consensus_key) + - id: update_companion_key + type: update_companion_key + if: (alpha__operation__alpha__contents_or_signature_prefix_tag == alpha__operation__alpha__contents_or_signature_prefix_tag::update_companion_key) - id: drain_delegate type: drain_delegate if: (alpha__operation__alpha__contents_or_signature_prefix_tag == alpha__operation__alpha__contents_or_signature_prefix_tag::drain_delegate) @@ -1461,6 +1464,28 @@ types: type: new_state_0 - id: proof type: bytes_dyn_uint30 + update_companion_key: + seq: + - id: source + type: public_key_hash + doc: A Ed25519, Secp256k1, P256, or BLS public key hash + - id: fee + type: alpha__mutez + - id: counter + type: n + - id: gas_limit + type: n + - id: storage_limit + type: n + - id: pk + type: public_key + doc: A Ed25519, Secp256k1, or P256 public key + - id: proof_tag + type: u1 + enum: bool + - id: proof + type: proof_0 + if: (proof_tag == bool::true) update_consensus_key: seq: - id: source @@ -2014,6 +2039,7 @@ enums: 112: set_deposits_limit 113: increase_paid_storage 114: update_consensus_key + 115: update_companion_key 158: transfer_ticket 200: smart_rollup_originate 201: smart_rollup_add_messages diff --git a/client-libs/kaitai-struct-files/files/alpha__operation__unsigned.ksy b/client-libs/kaitai-struct-files/files/alpha__operation__unsigned.ksy index 6c901e36e8ba..803251b21c2f 100644 --- a/client-libs/kaitai-struct-files/files/alpha__operation__unsigned.ksy +++ b/client-libs/kaitai-struct-files/files/alpha__operation__unsigned.ksy @@ -185,6 +185,9 @@ types: - id: update_consensus_key type: update_consensus_key if: (alpha__operation__alpha__contents_tag == alpha__operation__alpha__contents_tag::update_consensus_key) + - id: update_companion_key + type: update_companion_key + if: (alpha__operation__alpha__contents_tag == alpha__operation__alpha__contents_tag::update_companion_key) - id: drain_delegate type: drain_delegate if: (alpha__operation__alpha__contents_tag == alpha__operation__alpha__contents_tag::drain_delegate) @@ -1449,6 +1452,28 @@ types: type: new_state_0 - id: proof type: bytes_dyn_uint30 + update_companion_key: + seq: + - id: source + type: public_key_hash + doc: A Ed25519, Secp256k1, P256, or BLS public key hash + - id: fee + type: alpha__mutez + - id: counter + type: n + - id: gas_limit + type: n + - id: storage_limit + type: n + - id: pk + type: public_key + doc: A Ed25519, Secp256k1, or P256 public key + - id: proof_tag + type: u1 + enum: bool + - id: proof + type: proof_0 + if: (proof_tag == bool::true) update_consensus_key: seq: - id: source @@ -2002,6 +2027,7 @@ enums: 112: set_deposits_limit 113: increase_paid_storage 114: update_consensus_key + 115: update_companion_key 158: transfer_ticket 200: smart_rollup_originate 201: smart_rollup_add_messages -- GitLab From 3f22ea2a484abb5fc4d82566c21315e2a0e24beb Mon Sep 17 00:00:00 2001 From: Lucas Randazzo Date: Thu, 27 Mar 2025 12:07:06 +0100 Subject: [PATCH 13/13] Doc: update changelog --- docs/protocols/alpha.rst | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/docs/protocols/alpha.rst b/docs/protocols/alpha.rst index 42af03252fa6..55f046c12f2d 100644 --- a/docs/protocols/alpha.rst +++ b/docs/protocols/alpha.rst @@ -5,7 +5,7 @@ This page lists the changes brought by protocol Alpha with respect to Rio (see :ref:`naming_convention`). For the list of changes brought by Rio with respect to Quebec, see :doc:`../protocols/022_rio`. -For a higher-level overview of the most salient new features see the +For a higher-level overview of the most salient new features see the `announcement blog `__. The code can be found in directory :src:`src/proto_alpha` of the ``master`` @@ -22,6 +22,12 @@ This protocol requires an updated protocol environment version (V15) from R vers scheme. Starting from V15, they are expected to be produced with the ``Proof of possession`` cryptographic scheme. (MR :gl:`!17036`) +Client +------ + +- Added ``octez-client set companion key for to ``, setting a + companion key for the given delegate. (MR :gl:`!17320`) + Smart Rollups ------------- @@ -54,6 +60,10 @@ RPC Changes Operation receipts ------------------ +- Adds receipt for ``companion_key`` update. The receipt is similar to a consensus + key update, with the ``kind`` field used to differientiate between both. + (MR :gl:`!17320`) + Errors ------ -- GitLab