From 102ba49149d3904b804e0e5c6a3a1c7ae747092f Mon Sep 17 00:00:00 2001 From: Pietro Abate Date: Mon, 13 Nov 2017 12:32:05 +0100 Subject: [PATCH] Proto: Rename Public_key to Delegates_pubkey --- src/proto/alpha/apply.ml | 4 +-- src/proto/alpha/baking.ml | 2 +- src/proto/alpha/contract_storage.ml | 36 ++++++++++++------------ src/proto/alpha/contract_storage.mli | 2 +- src/proto/alpha/manager_repr.ml | 33 +++++++--------------- src/proto/alpha/services_registration.ml | 8 +++--- src/proto/alpha/tezos_context.ml | 2 +- src/proto/alpha/tezos_context.mli | 3 +- 8 files changed, 39 insertions(+), 51 deletions(-) diff --git a/src/proto/alpha/apply.ml b/src/proto/alpha/apply.ml index 9933e97da..65865b62b 100644 --- a/src/proto/alpha/apply.ml +++ b/src/proto/alpha/apply.ml @@ -174,10 +174,10 @@ let apply_sourced_operation (ctxt, origination_nonce, None) contents | Delegate_operations { source ; operations = contents } -> let delegate = Ed25519.Public_key.hash source in - Public_key.reveal ctxt delegate source >>=? fun ctxt -> + Delegates_pubkey.reveal ctxt delegate source >>=? fun ctxt -> Operation.check_signature source operation >>=? fun () -> (* TODO, see how to extract the public key hash after this operation to - pass it to apply_delegate_operation_content *) + pass it to apply_delegate_operation_content *) fold_left_s (fun ctxt content -> apply_delegate_operation_content ctxt delegate pred_block block_prio content) diff --git a/src/proto/alpha/baking.ml b/src/proto/alpha/baking.ml index 09b607d21..0edc2b21f 100644 --- a/src/proto/alpha/baking.ml +++ b/src/proto/alpha/baking.ml @@ -232,7 +232,7 @@ let check_proof_of_work_stamp ctxt block = fail Invalid_stamp let check_signature ctxt block id = - Public_key.get ctxt id >>=? fun key -> + Delegates_pubkey.get ctxt id >>=? fun key -> let check_signature key { Block_header.proto ; shell ; signature } = let unsigned_header = Block_header.forge_unsigned shell proto in Ed25519.Signature.check key signature unsigned_header in diff --git a/src/proto/alpha/contract_storage.ml b/src/proto/alpha/contract_storage.ml index f530826c7..c70dc60bf 100644 --- a/src/proto/alpha/contract_storage.ml +++ b/src/proto/alpha/contract_storage.ml @@ -182,7 +182,7 @@ let () = Data_encoding.(obj1 (req "message" string)) (function Failure s -> Some s | _ -> None) (fun s -> Failure s) - + let failwith msg = fail (Failure msg) let create_base c contract ~balance ~manager ~delegate ?script ~spendable ~delegatable = @@ -190,7 +190,7 @@ let create_base c contract ~balance ~manager ~delegate ?script ~spendable ~deleg | None -> return 0l | Some _ -> Storage.Contract.Global_counter.get c) >>=? fun counter -> Storage.Contract.Balance.init c contract balance >>=? fun c -> - Storage.Contract.Manager.init c contract (Manager_repr.hash manager) >>=? fun c -> + Storage.Contract.Manager.init c contract (Manager_repr.Hash manager) >>=? fun c -> begin match delegate with | None -> return c @@ -303,23 +303,23 @@ let get_manager c contract = let update_manager_key c contract = function | Some public_key -> - begin Storage.Contract.Manager.get c contract >>=? function - | (Manager_repr.Public_key v) -> (* key revealed for the second time *) - if Ed25519.Public_key.(v = public_key) then return (c,v) - else fail (Inconsistent_public_key (v,public_key)) - | (Manager_repr.Hash v) -> - let actual_hash = Ed25519.Public_key.hash public_key in - if (Ed25519.Public_key_hash.equal actual_hash v) then - let v = (Manager_repr.public_key public_key) in - Storage.Contract.Manager.set c contract v >>=? fun c -> - return (c,public_key) (* reveal and update key *) - else fail (Inconsistent_hash (public_key,v,actual_hash)) - end + begin Storage.Contract.Manager.get c contract >>=? function + | (Manager_repr.Public_key v) -> (* key revealed for the second time *) + if Ed25519.Public_key.(v = public_key) then return (c,v) + else fail (Inconsistent_public_key (v,public_key)) + | (Manager_repr.Hash v) -> + let actual_hash = Ed25519.Public_key.hash public_key in + if (Ed25519.Public_key_hash.equal actual_hash v) then + let v = (Manager_repr.Public_key public_key) in + Storage.Contract.Manager.set c contract v >>=? fun c -> + return (c,public_key) (* reveal and update key *) + else fail (Inconsistent_hash (public_key,v,actual_hash)) + end | None -> - begin Storage.Contract.Manager.get c contract >>=? function - | (Manager_repr.Public_key v) -> return (c,v) (* already revealed *) - | (Manager_repr.Hash v) -> fail (Missing_public_key (v)) - end + begin Storage.Contract.Manager.get c contract >>=? function + | (Manager_repr.Public_key v) -> return (c,v) (* already revealed *) + | (Manager_repr.Hash v) -> fail (Missing_public_key (v)) + end let get_delegate_opt = Roll_storage.get_contract_delegate diff --git a/src/proto/alpha/contract_storage.mli b/src/proto/alpha/contract_storage.mli index 465bc79e5..3e468df7e 100644 --- a/src/proto/alpha/contract_storage.mli +++ b/src/proto/alpha/contract_storage.mli @@ -37,7 +37,7 @@ val is_spendable : Storage.t -> Contract_repr.t -> bool tzresult Lwt.t val get_manager: Storage.t -> Contract_repr.t -> Ed25519.Public_key_hash.t tzresult Lwt.t val update_manager_key: Storage.t -> Contract_repr.t -> Ed25519.Public_key.t option -> - (Storage.t * Ed25519.Public_key.t) tzresult Lwt.t + (Storage.t * Ed25519.Public_key.t) tzresult Lwt.t val get_delegate_opt: Storage.t -> Contract_repr.t -> Ed25519.Public_key_hash.t option tzresult Lwt.t val get_balance: Storage.t -> Contract_repr.t -> Tez_repr.t tzresult Lwt.t diff --git a/src/proto/alpha/manager_repr.ml b/src/proto/alpha/manager_repr.ml index 8fe03f252..05c9b6d4f 100644 --- a/src/proto/alpha/manager_repr.ml +++ b/src/proto/alpha/manager_repr.ml @@ -15,34 +15,21 @@ type manager_key = type t = manager_key -let hash hash = Hash hash -let public_key hash = Public_key hash - open Data_encoding -let hash_encoding = - (obj1 - (req "hash" Ed25519.Public_key_hash.encoding) - ) - -let pubkey_encoding = - (obj1 - (req "public_key" Ed25519.Public_key.encoding) - ) - let hash_case tag = - case ~tag hash_encoding - (function - | Hash hash -> Some hash - | _ -> None) - (fun hash -> Hash hash) + case ~tag Ed25519.Public_key_hash.encoding + (function + | Hash hash -> Some hash + | _ -> None) + (fun hash -> Hash hash) let pubkey_case tag = - case ~tag pubkey_encoding - (function - | Public_key hash -> Some hash - | _ -> None) - (fun hash -> Public_key hash) + case ~tag Ed25519.Public_key.encoding + (function + | Public_key hash -> Some hash + | _ -> None) + (fun hash -> Public_key hash) let encoding = diff --git a/src/proto/alpha/services_registration.ml b/src/proto/alpha/services_registration.ml index 24129bc6c..11dda4eb1 100644 --- a/src/proto/alpha/services_registration.ml +++ b/src/proto/alpha/services_registration.ml @@ -185,11 +185,11 @@ let () = register0 Services.Context.Nonce.hash nonce_hash (*-- Context.Key -------------------------------------------------------------*) let get_key ctxt hash () = - Public_key.get ctxt hash >>=? fun pk -> + Delegates_pubkey.get ctxt hash >>=? fun pk -> return (hash, pk) let () = register2 Services.Context.Key.get get_key -let () = register0 Services.Context.Key.list Public_key.list +let () = register0 Services.Context.Key.list Delegates_pubkey.list (*-- Context.Contract --------------------------------------------------------*) @@ -469,7 +469,7 @@ let operation_public_key ctxt = function | None -> return None | Some public_key -> let hash = Ed25519.Public_key.hash public_key in - Public_key.get_option ctxt hash >>=? function + Delegates_pubkey.get_option ctxt hash >>=? function | None -> return (Some public_key) | Some _ -> return None @@ -499,7 +499,7 @@ let check_signature ctxt signature shell contents = | Some key -> return key | None -> Contract.get_manager ctxt op.source >>=? fun manager -> - Public_key.get ctxt manager + Delegates_pubkey.get ctxt manager end >>=? fun public_key -> Operation.check_signature public_key { signature ; shell ; contents ; hash = dummy_hash } diff --git a/src/proto/alpha/tezos_context.ml b/src/proto/alpha/tezos_context.ml index f5cadad59..24b605ef3 100644 --- a/src/proto/alpha/tezos_context.ml +++ b/src/proto/alpha/tezos_context.ml @@ -87,7 +87,7 @@ module Constants = struct constants.dictator_pubkey end -module Public_key = Public_key_storage +module Delegates_pubkey = Public_key_storage module Voting_period = Voting_period_repr diff --git a/src/proto/alpha/tezos_context.mli b/src/proto/alpha/tezos_context.mli index 71701c11f..42feff54d 100644 --- a/src/proto/alpha/tezos_context.mli +++ b/src/proto/alpha/tezos_context.mli @@ -282,7 +282,8 @@ module Constants : sig end -module Public_key : sig +(** Global storage for all delegates public keys *) +module Delegates_pubkey : sig val get: context -> public_key_hash -> public_key tzresult Lwt.t