Skip to content

Commit

Permalink
fix verify_chain to use verify_block_fit
Browse files Browse the repository at this point in the history
  • Loading branch information
Rahul Garg committed May 2, 2018
1 parent 5e5ac01 commit 69fd63b
Showing 1 changed file with 4 additions and 15 deletions.
19 changes: 4 additions & 15 deletions test/hbbft_worker.erl
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,12 @@ verify_chain([G], PubKey) ->
io:format("no genesis block~n"),
false
end;
verify_chain([A, B|_]=Chain, PubKey) ->
verify_chain(Chain, PubKey) ->
io:format("Chain verification depth ~p~n", [length(Chain)]),
%% A should have the the prev_hash of B
case A#block.prev_hash == hash_block(B) of
true ->
%% A should have a valid signature
HM = tpke_pubkey:hash_message(PubKey, term_to_binary(A#block{signature= <<>>})),
Signature = tpke_pubkey:deserialize_element(PubKey, A#block.signature),
case tpke_pubkey:verify_signature(PubKey, Signature, HM) of
true ->
verify_chain(tl(Chain), PubKey);
false ->
io:format("bad signature~n"),
false
end;
case verify_block_fit(Chain, PubKey) of
true -> verify_chain(tl(Chain), PubKey);
false ->
io:format("parent hash mismatch ~p ~p~n", [A#block.prev_hash, hash_block(B)]),
io:format("bad signature~n"),
false
end.

Expand Down

0 comments on commit 69fd63b

Please sign in to comment.