summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Nordberg <linus@nordberg.se>2014-09-14 18:03:18 +0200
committerLinus Nordberg <linus@nordberg.se>2014-09-14 18:03:18 +0200
commit7d14830a1c800279d03f0ae6946ba69449238978 (patch)
treed440cfe2d6fd1f3063db535137305cafa922a5bf
parente41ef099a6dcf2947b759f6a8fff260d581723c6 (diff)
Add three more test vectors for consistency proofs.
Also add print_tree/1.
-rw-r--r--src/ht.erl45
1 files changed, 33 insertions, 12 deletions
diff --git a/src/ht.erl b/src/ht.erl
index 7d0a75a..93a765e 100644
--- a/src/ht.erl
+++ b/src/ht.erl
@@ -27,7 +27,7 @@
-export([start_link/0, start_link/1, stop/0]).
-export([init/1, handle_call/3, terminate/2, handle_cast/2, handle_info/2,
code_change/3]).
--export([testing_get_state/0, print_tree/0]).
+-export([testing_get_state/0, print_tree/0, print_tree/1]).
-include("$CTROOT/plop/include/plop.hrl").
-include_lib("eunit/include/eunit.hrl").
@@ -63,6 +63,8 @@ testing_get_state() ->
gen_server:call(?MODULE, testing_get_state).
print_tree() ->
gen_server:call(?MODULE, print_tree).
+print_tree(HashOutputLen) ->
+ gen_server:call(?MODULE, {print_tree, HashOutputLen}).
%% gen_server callbacks
init([]) ->
@@ -98,7 +100,9 @@ handle_call({consistency, Version1, Version2}, _From, State) ->
handle_call(testing_get_state, _From, State) ->
{reply, State, State};
handle_call(print_tree, _From, State) ->
- {reply, print_tree(State), State}.
+ {reply, print_tree(State, 4), State};
+handle_call({print_tree, HashOutputLen}, _From, State) ->
+ {reply, print_tree(State, HashOutputLen), State}.
%%%%%%%%%%%%%%%%%%%%
%% Private.
@@ -368,21 +372,21 @@ hash(Data) ->
%%%%%%%%%%%%%%%%%%%%
%% Debugging helpers.
-print_tree(Tree) ->
- print_tree(update(Tree), 0, Tree#tree.version, depth(Tree)).
+print_tree(Tree, HashOutputLen) ->
+ print_tree(update(Tree), HashOutputLen, 0, Tree#tree.version, depth(Tree)).
-print_tree(_, _, _, 0) ->
+print_tree(_, _, _, _, 0) ->
ok;
-print_tree(Tree, Layer, ILast, LayersLeft) ->
- print_layer(Tree, Layer, ILast),
- print_tree(Tree, Layer + 1, ILast bsr 1, LayersLeft - 1).
+print_tree(Tree, HashOutputLen, Layer, ILast, LayersLeft) ->
+ print_layer(Tree, HashOutputLen, Layer, ILast),
+ print_tree(Tree, HashOutputLen, Layer + 1, ILast bsr 1, LayersLeft - 1).
-print_layer(Tree, Layer, ILast) ->
+print_layer(Tree, HashOutputLen, Layer, ILast) ->
foreach(
fun(I) -> io:format("~s ",
[string:substr(
hex:bin_to_hexstr(
- get_hash(Tree, {I, Layer})), 1, 4)])
+ get_hash(Tree, {I, Layer})), 1, HashOutputLen)])
end,
lists:seq(0, ILast)),
io:format("~n").
@@ -473,7 +477,10 @@ path_inc_test() ->
lists:seq(1, length(?TEST_VECTOR_PATHS))).
-define(TEST_VECTOR_PROOFS,
- [{1, 1, []},
+ [
+ %% Test vectors from Googles C++ implementation, "Generated
+ %% from ReferenceSnapshotConsistency."
+ {1, 1, []},
{1, 8,
["96a296d224f285c67bee93c30f8a309157f0daa35dc5b87e410b78630a09cfc7",
"5f083f0a1a33ca076a95279832580db3e0ef4584bdff1f54c8a360f50de3031e",
@@ -484,7 +491,21 @@ path_inc_test() ->
"d37ee418976dd95753c1c73862b9398fa2a2cf9b4ff0fdfe8b30cd95209614b7"]},
{2, 5,
["5f083f0a1a33ca076a95279832580db3e0ef4584bdff1f54c8a360f50de3031e",
- "bc1a0643b12e4d2d7c77918f44e0f4f79a838b6cf9ec5b5c283e1f4d88599e6b"]}]).
+ "bc1a0643b12e4d2d7c77918f44e0f4f79a838b6cf9ec5b5c283e1f4d88599e6b"]},
+ %% RFC6962 section 2.1.3.
+ {3, 7,
+ ["0298D122906DCFC10892CB53A73992FC5B9F493EA4C9BADB27B791B4127A7FE7",
+ "07506A85FD9DD2F120EB694F86011E5BB4662E5C415A62917033D4A9624487E7",
+ "FAC54203E7CC696CF0DFCB42C92A1D9DBAF70AD9E621F4BD8D98662F00E3C125",
+ "837DBB152E9B079010717E84E865DA4EBC0FA198A806D59D31BF15ACCEF22D0E"]},
+ {4, 7,
+ ["837DBB152E9B079010717E84E865DA4EBC0FA198A806D59D31BF15ACCEF22D0E"]},
+ {6, 7,
+ ["0EBC5D3437FBE2DB158B9F126A1D118E308181031D0A949F8DEDEDEBC558EF6A",
+ "B08693EC2E721597130641E8211E7EEDCCB4C26413963EEE6C1E2ED16FFB1A5F",
+ "D37EE418976DD95753C1C73862B9398FA2A2CF9B4FF0FDFE8B30CD95209614B7"]}
+ ]).
+
%% @doc Test proofs on a single version 7 tree.
consistency_test() ->
test_init(?TEST_VECTOR_LEAVES),