From a875a5f2e9b32acfeef5f38d12d0c0f9a7540be1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Henry?= Date: Thu, 22 Feb 2018 13:53:07 -0500 Subject: [PATCH] Alpha: ignore delegate with unrevealed keys when freezing rolls --- src/proto_alpha/lib_protocol/src/TEZOS_PROTOCOL | 2 +- src/proto_alpha/lib_protocol/src/alpha_context.mli | 4 ++-- src/proto_alpha/lib_protocol/src/baking.ml | 7 ++++--- src/proto_alpha/lib_protocol/src/baking.mli | 4 ++-- src/proto_alpha/lib_protocol/src/delegate_services.ml | 4 ++-- src/proto_alpha/lib_protocol/src/helpers_services.ml | 3 ++- src/proto_alpha/lib_protocol/src/roll_storage.ml | 4 +++- src/proto_alpha/lib_protocol/src/roll_storage.mli | 4 ++-- 8 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/proto_alpha/lib_protocol/src/TEZOS_PROTOCOL b/src/proto_alpha/lib_protocol/src/TEZOS_PROTOCOL index 1d7ca695c..411a342b0 100644 --- a/src/proto_alpha/lib_protocol/src/TEZOS_PROTOCOL +++ b/src/proto_alpha/lib_protocol/src/TEZOS_PROTOCOL @@ -37,6 +37,7 @@ "Level_storage", "Nonce_storage", "Seed_storage", + "Public_key_storage", "Roll_storage", "Contract_storage", "Reward_storage", @@ -44,7 +45,6 @@ "Fitness_storage", "Vote_storage", "Init_storage", - "Public_key_storage", "Alpha_context", diff --git a/src/proto_alpha/lib_protocol/src/alpha_context.mli b/src/proto_alpha/lib_protocol/src/alpha_context.mli index 9286da9f0..96544ad8b 100644 --- a/src/proto_alpha/lib_protocol/src/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/src/alpha_context.mli @@ -696,10 +696,10 @@ module Roll : sig val clear_cycle: context -> Cycle.t -> context tzresult Lwt.t val baking_rights_owner: - context -> Level.t -> priority:int -> public_key_hash tzresult Lwt.t + context -> Level.t -> priority:int -> public_key tzresult Lwt.t val endorsement_rights_owner: - context -> Level.t -> slot:int -> public_key_hash tzresult Lwt.t + context -> Level.t -> slot:int -> public_key tzresult Lwt.t end diff --git a/src/proto_alpha/lib_protocol/src/baking.ml b/src/proto_alpha/lib_protocol/src/baking.ml index 5089b4124..621accec2 100644 --- a/src/proto_alpha/lib_protocol/src/baking.ml +++ b/src/proto_alpha/lib_protocol/src/baking.ml @@ -123,7 +123,7 @@ let check_baking_rights c { Block_header.priority ; _ } let level = Level.current c in Roll.baking_rights_owner c level ~priority >>=? fun delegate -> check_timestamp c priority pred_timestamp >>=? fun () -> - return delegate + return (Ed25519.Public_key.hash delegate) let pay_baking_bond c { Block_header.priority ; _ } id = if Compare.Int.(priority >= Constants.first_free_baking_slot c) @@ -143,6 +143,7 @@ let check_signing_rights c slot delegate = (Invalid_endorsement_slot (Constants.max_signing_slot c, slot)) >>=? fun () -> let level = Level.current c in Roll.endorsement_rights_owner c level ~slot >>=? fun owning_delegate -> + let owning_delegate = Ed25519.Public_key.hash owning_delegate in fail_unless (Ed25519.Public_key_hash.equal owning_delegate delegate) (Wrong_delegate (owning_delegate, delegate)) @@ -187,9 +188,9 @@ let select_delegate delegate delegate_list max_priority = if Compare.Int.(n >= max_priority) then return (List.rev acc) else - let LCons (pkh, t) = l in + let LCons (pk, t) = l in let acc = - if Ed25519.Public_key_hash.equal delegate pkh + if Ed25519.Public_key_hash.equal delegate (Ed25519.Public_key.hash pk) then n :: acc else acc in t () >>=? fun t -> diff --git a/src/proto_alpha/lib_protocol/src/baking.mli b/src/proto_alpha/lib_protocol/src/baking.mli index 2d126e4f4..ff7493edc 100644 --- a/src/proto_alpha/lib_protocol/src/baking.mli +++ b/src/proto_alpha/lib_protocol/src/baking.mli @@ -75,12 +75,12 @@ val endorsement_reward: block_priority:int -> Tez.t tzresult Lwt.t (** [baking_priorities ctxt level] is the lazy list of contract's public key hashes that are allowed to bake for [level]. *) val baking_priorities: - context -> Level.t -> public_key_hash lazy_list + context -> Level.t -> public_key lazy_list (** [endorsement_priorities ctxt level] is the lazy list of contract's public key hashes that are allowed to endorse for [level]. *) val endorsement_priorities: - context -> Level.t -> public_key_hash lazy_list + context -> Level.t -> public_key lazy_list (** [first_baking_priorities ctxt ?max_priority contract_hash level] is a list of priorities of max [?max_priority] elements, where the diff --git a/src/proto_alpha/lib_protocol/src/delegate_services.ml b/src/proto_alpha/lib_protocol/src/delegate_services.ml index 3533c8e3d..e2db6a314 100644 --- a/src/proto_alpha/lib_protocol/src/delegate_services.ml +++ b/src/proto_alpha/lib_protocol/src/delegate_services.ml @@ -107,7 +107,7 @@ module Baker = struct let Misc.LCons (h, t) = l in t () >>=? fun t -> loop t (pred n) >>=? fun t -> - return (h :: t) + return (Ed25519.Public_key.hash h :: t) in loop contract_list max >>=? fun prio -> return (level.level, prio) @@ -266,7 +266,7 @@ module Endorser = struct let Misc.LCons (h, t) = l in t () >>=? fun t -> loop t (pred n) >>=? fun t -> - return (h :: t) + return (Ed25519.Public_key.hash h :: t) in loop contract_list max >>=? fun prio -> return (level.level, prio) diff --git a/src/proto_alpha/lib_protocol/src/helpers_services.ml b/src/proto_alpha/lib_protocol/src/helpers_services.ml index 59958f326..b013e15dd 100644 --- a/src/proto_alpha/lib_protocol/src/helpers_services.ml +++ b/src/proto_alpha/lib_protocol/src/helpers_services.ml @@ -134,7 +134,8 @@ module I = struct | Some (shell, contents) -> let operation = { hash ; shell ; contents ; signature } in let level = Alpha_context.Level.current ctxt in - Baking.baking_priorities ctxt level >>=? fun (Misc.LCons (baker_pkh, _)) -> + Baking.baking_priorities ctxt level >>=? fun (Misc.LCons (baker_pk, _)) -> + let baker_pkh = Ed25519.Public_key.hash baker_pk in let baker_contract = Contract.implicit_contract baker_pkh in let block_prio = 0 in Apply.apply_operation diff --git a/src/proto_alpha/lib_protocol/src/roll_storage.ml b/src/proto_alpha/lib_protocol/src/roll_storage.ml index 1d20c8ab3..dabf7fc9a 100644 --- a/src/proto_alpha/lib_protocol/src/roll_storage.ml +++ b/src/proto_alpha/lib_protocol/src/roll_storage.ml @@ -80,7 +80,9 @@ module Random = struct | None -> loop sequence | Some delegate -> - return delegate + Public_key_storage.get_option c delegate >>=? function + | None -> loop sequence + | Some delegate -> return delegate in Storage.Roll.Owner.snapshot_exists c cycle >>= fun snapshot_exists -> fail_unless snapshot_exists (No_roll_snapshot_for_cycle cycle) >>=? fun () -> diff --git a/src/proto_alpha/lib_protocol/src/roll_storage.mli b/src/proto_alpha/lib_protocol/src/roll_storage.mli index 95e284268..cc49770af 100644 --- a/src/proto_alpha/lib_protocol/src/roll_storage.mli +++ b/src/proto_alpha/lib_protocol/src/roll_storage.mli @@ -36,11 +36,11 @@ val clear_cycle : val baking_rights_owner : Raw_context.t -> Level_repr.t -> priority:int -> - Ed25519.Public_key_hash.t tzresult Lwt.t + Ed25519.Public_key.t tzresult Lwt.t val endorsement_rights_owner : Raw_context.t -> Level_repr.t -> slot:int -> - Ed25519.Public_key_hash.t tzresult Lwt.t + Ed25519.Public_key.t tzresult Lwt.t module Contract : sig