diff --git a/src/proto/alpha/TEZOS_PROTOCOL b/src/proto/alpha/TEZOS_PROTOCOL index b011da7eb..ed12b35cc 100644 --- a/src/proto/alpha/TEZOS_PROTOCOL +++ b/src/proto/alpha/TEZOS_PROTOCOL @@ -38,6 +38,7 @@ "Fitness_storage", "Vote_storage", "Init_storage", + "Public_key_storage", "Tezos_context", diff --git a/src/proto/alpha/apply.ml b/src/proto/alpha/apply.ml index 6f1dbf15a..0dfdbcee3 100644 --- a/src/proto/alpha/apply.ml +++ b/src/proto/alpha/apply.ml @@ -109,7 +109,7 @@ let check_signature_and_update_public_key ctxt id public_key op = match public_key with | None -> return ctxt | Some public_key -> - Public_key.set ctxt id public_key + Public_key.reveal ctxt id public_key end >>=? fun ctxt -> Public_key.get ctxt id >>=? fun public_key -> Operation.check_signature public_key op >>=? fun () -> diff --git a/src/proto/alpha/public_key_storage.ml b/src/proto/alpha/public_key_storage.ml new file mode 100644 index 000000000..8f23e67b0 --- /dev/null +++ b/src/proto/alpha/public_key_storage.ml @@ -0,0 +1,48 @@ +(**************************************************************************) +(* *) +(* Copyright (c) 2014 - 2016. *) +(* Dynamic Ledger Solutions, Inc. *) +(* *) +(* All rights reserved. No warranty, explicit or implicit, provided. *) +(* *) +(**************************************************************************) + +open Ed25519 + +type error += Inconsistent_hash of Public_key.t * Public_key_hash.t * Public_key_hash.t + +let () = + register_error_kind + `Permanent + ~id:"public_key.inconsistent_hash" + ~title:"Inconsistent public key hash" + ~description:"A revealed public key is inconsistent with the announced hash" + ~pp:(fun ppf (k, eh, ph) -> + Format.fprintf ppf "Hash of public key %s is not %a as announced but %a" + (Public_key.to_b58check k) + Public_key_hash.pp ph + Public_key_hash.pp eh) + Data_encoding.(obj3 + (req "public_key" Public_key.encoding) + (req "expected_hash" Public_key_hash.encoding) + (req "provided_hash" Public_key_hash.encoding)) + (function Inconsistent_hash (k, eh, ph) -> Some (k, eh, ph) | _ -> None) + (fun (k, eh, ph) -> Inconsistent_hash (k, eh, ph)) + +let get = Storage.Public_key.get + +let get_option = Storage.Public_key.get_option + +let reveal c hash key = + let actual_hash = Ed25519.Public_key.hash key in + if Ed25519.Public_key_hash.equal hash actual_hash then + Storage.Public_key.init_set c hash key + else + fail (Inconsistent_hash (key, actual_hash, hash)) + +let remove = Storage.Public_key.remove + +let list ctxt = + Storage.Public_key.fold ctxt [] ~f:(fun pk_h pk acc -> + Lwt.return @@ (pk_h, pk) :: acc) >>= fun res -> + return res diff --git a/src/proto/alpha/public_key_storage.mli b/src/proto/alpha/public_key_storage.mli new file mode 100644 index 000000000..6a9fa3902 --- /dev/null +++ b/src/proto/alpha/public_key_storage.mli @@ -0,0 +1,24 @@ +(**************************************************************************) +(* *) +(* Copyright (c) 2014 - 2016. *) +(* Dynamic Ledger Solutions, Inc. *) +(* *) +(* All rights reserved. No warranty, explicit or implicit, provided. *) +(* *) +(**************************************************************************) + +open Ed25519 + +type error += Inconsistent_hash of Public_key.t * Public_key_hash.t * Public_key_hash.t + +val get: + Storage.t -> Public_key_hash.t -> Public_key.t tzresult Lwt.t +val get_option: + Storage.t -> Public_key_hash.t -> Public_key.t option tzresult Lwt.t +val reveal: + Storage.t -> Public_key_hash.t -> Public_key.t -> Storage.t tzresult Lwt.t +val remove: + Storage.t -> Public_key_hash.t -> Storage.t Lwt.t + +val list: + Storage.t -> (Public_key_hash.t * Public_key.t) list tzresult Lwt.t diff --git a/src/proto/alpha/tezos_context.ml b/src/proto/alpha/tezos_context.ml index a4a92deb2..41577693b 100644 --- a/src/proto/alpha/tezos_context.ml +++ b/src/proto/alpha/tezos_context.ml @@ -75,19 +75,7 @@ module Constants = struct constants.dictator_pubkey end -module Public_key = struct - - let get = Storage.Public_key.get - let get_option = Storage.Public_key.get_option - let set = Storage.Public_key.init_set - let remove = Storage.Public_key.remove - - let list ctxt = - Storage.Public_key.fold ctxt [] ~f:(fun pk_h pk acc -> - Lwt.return @@ (pk_h, pk) :: acc) >>= fun res -> - return res - -end +module Public_key = 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 79cf2ab0f..3ffbbd560 100644 --- a/src/proto/alpha/tezos_context.mli +++ b/src/proto/alpha/tezos_context.mli @@ -197,7 +197,7 @@ module Public_key : sig context -> public_key_hash -> public_key tzresult Lwt.t val get_option: context -> public_key_hash -> public_key option tzresult Lwt.t - val set: + val reveal: context -> public_key_hash -> public_key -> context tzresult Lwt.t val remove: context -> public_key_hash -> context Lwt.t