From e3bfe0d6516a042a03bc8fcf8b2a2a1b397d4cb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Henry?= Date: Wed, 18 Apr 2018 17:16:07 +0200 Subject: [PATCH] Alpha: exclude signature from the minimal stamp of PoW. We don't want the stamp to be cheaper for people with faster signing devices... --- scripts/protocol_parameters.json | 3 ++- .../lib_baking/client_baking_forge.ml | 16 +++++++++------- src/proto_alpha/lib_protocol/src/baking.ml | 8 +++++++- src/proto_alpha/lib_protocol/src/baking.mli | 2 +- 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/scripts/protocol_parameters.json b/scripts/protocol_parameters.json index 091a7efca..6a72296f4 100644 --- a/scripts/protocol_parameters.json +++ b/scripts/protocol_parameters.json @@ -11,5 +11,6 @@ "blocks_per_roll_snapshot" : 4, "blocks_per_cycle" : 8, "preserved_cycles" : 2, - "first_free_baking_slot" : 4 + "first_free_baking_slot" : 4, + "proof_of_work_threshold": -1 } diff --git a/src/proto_alpha/lib_baking/client_baking_forge.ml b/src/proto_alpha/lib_baking/client_baking_forge.ml index 1f8552bab..3fc8efc0b 100644 --- a/src/proto_alpha/lib_baking/client_baking_forge.ml +++ b/src/proto_alpha/lib_baking/client_baking_forge.ml @@ -22,17 +22,19 @@ let generate_seed_nonce () = | Ok nonce -> nonce let forge_block_header - cctxt block delegate_sk shell priority seed_nonce_hash = + (cctxt : #Proto_alpha.full) block delegate_sk shell priority seed_nonce_hash = Alpha_services.Constants.proof_of_work_threshold cctxt block >>=? fun stamp_threshold -> let rec loop () = let proof_of_work_nonce = generate_proof_of_work_nonce () in - let unsigned_header = - Alpha_context.Block_header.forge_unsigned - shell { priority ; seed_nonce_hash ; proof_of_work_nonce } in - Client_keys.append cctxt delegate_sk unsigned_header >>=? fun signed_header -> - let block_hash = Block_hash.hash_bytes [signed_header] in - if Baking.check_hash block_hash stamp_threshold then + let protocol_data : Block_header.protocol_data = + { priority ; seed_nonce_hash ; proof_of_work_nonce } in + let faked_header : Block_header.t = + { shell ; protocol_data ; signature = Signature.zero } in + if Baking.check_header_hash faked_header stamp_threshold then + let unsigned_header = + Alpha_context.Block_header.forge_unsigned shell protocol_data in + Client_keys.append cctxt delegate_sk unsigned_header >>=? fun signed_header -> return signed_header else loop () in diff --git a/src/proto_alpha/lib_protocol/src/baking.ml b/src/proto_alpha/lib_protocol/src/baking.ml index f4c6b7fba..f38b09570 100644 --- a/src/proto_alpha/lib_protocol/src/baking.ml +++ b/src/proto_alpha/lib_protocol/src/baking.ml @@ -252,7 +252,13 @@ let check_hash hash stamp_threshold = Compare.Uint64.(word <= stamp_threshold) let check_header_hash header stamp_threshold = - let hash = Block_header.hash header in + let hash = + Block_header.hash_raw + { shell = header.Block_header.shell ; + protocol_data = + Data_encoding.Binary.to_bytes + Block_header.protocol_data_encoding + header.protocol_data } in check_hash hash stamp_threshold let check_proof_of_work_stamp ctxt block = diff --git a/src/proto_alpha/lib_protocol/src/baking.mli b/src/proto_alpha/lib_protocol/src/baking.mli index c94dc64ab..c2162e398 100644 --- a/src/proto_alpha/lib_protocol/src/baking.mli +++ b/src/proto_alpha/lib_protocol/src/baking.mli @@ -103,7 +103,7 @@ val first_endorsement_slots: the given key *) val check_signature: Block_header.t -> public_key -> unit tzresult Lwt.t -val check_hash: Block_hash.t -> int64 -> bool +val check_header_hash: Block_header.t -> int64 -> bool (** verify if the proof of work stamp is valid *) val check_proof_of_work_stamp: