Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add converted signature verification test #965

Open
wants to merge 2 commits into
base: crypto-test-hold-10
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions deku-p/src/core/crypto/tests/alg_intf_tests.ml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,22 @@ struct
List.map (fun hash -> (Signature.sign sk hash, hash)) to_sign)
secret_keys

let signatures_to_b58 =
List.map
(fun sig_list ->
List.map
(fun (signature, hash) -> (Signature.to_b58 signature, hash))
sig_list)
signatures

let b58_to_signatures =
List.map
(fun sig_list ->
List.map
(fun (b58, hash) -> (Option.get @@ Signature.of_b58 b58, hash))
sig_list)
signatures_to_b58

let verified_normal_signatures =
let check_sig pk signatures =
List.map
Expand All @@ -61,6 +77,16 @@ struct
List.map2
(fun key signatures -> check_sig key signatures)
public_keys signatures

let verified_after_conversion =
let check_sig pk signatures =
List.map
(fun (signature, hash) -> Signature.verify pk signature hash)
signatures
in
List.map2
(fun key signatures -> check_sig key signatures)
public_keys b58_to_signatures
end

module Test_secret_key_data = struct
Expand Down Expand Up @@ -161,5 +187,12 @@ struct
~msg:"verified normal signatures are equal"
~expected:Tezos_data.verified_normal_signatures
~actual:Signature_data.verified_normal_signatures

(* We convert the signatures to b58 and back to ensure no data is lost *)
let verified_after_conversion () =
Alcotest.(check' (list (list bool)))
~msg:"verified post conversion signatures are equal"
~expected:Tezos_data.verified_after_conversion
~actual:Signature_data.verified_after_conversion
end
end
32 changes: 32 additions & 0 deletions deku-p/src/core/crypto/tests/data_for_tests/data_gen.ml
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,35 @@ struct
(fun sk -> List.map (fun hash -> (sign sk hash, hash)) byte_data)
secret_keys

let signatures_to_b58 =
List.map
(fun sig_list ->
List.map
(fun (signature, hash) -> (to_b58check signature, hash))
sig_list)
signatures

let b58_to_signatures =
List.map
(fun sig_list ->
List.map (fun (b58, hash) -> (of_b58check_exn b58, hash)) sig_list)
signatures_to_b58

let verified_normal =
let check_sig pk signatures =
List.map (fun (signature, hash) -> check pk signature hash) signatures
in
List.map2
(fun key signatures -> check_sig key signatures)
public_keys signatures

let verified_after_conversion =
let check_sig pk signatures =
List.map (fun (signature, hash) -> check pk signature hash) signatures
in
List.map2
(fun key signatures -> check_sig key signatures)
public_keys b58_to_signatures
end

module Print_secret_key = struct
Expand Down Expand Up @@ -213,5 +235,15 @@ struct
Format.printf "];\n%!")
Sig.verified_normal;
Format.printf "]\n%!"

let print_verified_after_conversion () =
Format.printf "let verified_after_conversion = [\n%!";
List.iter
(fun sig_list ->
Format.printf "[\n%!";
List.iter (Format.printf "%b;\n%!") sig_list;
Format.printf "];\n%!")
Sig.verified_after_conversion;
Format.printf "]\n%!"
end
end
2 changes: 2 additions & 0 deletions deku-p/src/core/crypto/tests/test_ed25519.ml
Original file line number Diff line number Diff line change
Expand Up @@ -104,5 +104,7 @@ let run () =
test_case "signatures" `Quick Test_signature_data.signatures;
test_case "verified normal signatures" `Quick
Test_signature_data.verified_normal_signatures;
test_case "verified after conversion signatures" `Quick
Test_signature_data.verified_after_conversion;
] );
]
10 changes: 10 additions & 0 deletions deku-p/src/core/crypto/tests/tezos_test_data.ml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module type Tezos_data = sig
val to_sign : string
val signatures : string
val verified_normal_signatures : bool list list
val verified_after_conversion : bool list list
end

module Ed25519_data : Tezos_data = struct
Expand Down Expand Up @@ -68,4 +69,13 @@ module Ed25519_data : Tezos_data = struct
[ true; true; true; true; true ];
[ true; true; true; true; true ];
]

let verified_after_conversion =
[
[ true; true; true; true; true ];
[ true; true; true; true; true ];
[ true; true; true; true; true ];
[ true; true; true; true; true ];
[ true; true; true; true; true ];
]
end