From c257b1ad93d15ae400b8ac01a627aa06502e150b Mon Sep 17 00:00:00 2001 From: InfiniteSwerve Date: Mon, 31 Oct 2022 20:53:44 -0700 Subject: [PATCH 1/2] added signatures after b58 conversion and back to data_gen and tezos_test_data --- .../crypto/tests/data_for_tests/data_gen.ml | 32 +++++++++++++++++++ .../src/core/crypto/tests/tezos_test_data.ml | 10 ++++++ 2 files changed, 42 insertions(+) diff --git a/deku-p/src/core/crypto/tests/data_for_tests/data_gen.ml b/deku-p/src/core/crypto/tests/data_for_tests/data_gen.ml index 26f85b461b..d7d88e6aad 100644 --- a/deku-p/src/core/crypto/tests/data_for_tests/data_gen.ml +++ b/deku-p/src/core/crypto/tests/data_for_tests/data_gen.ml @@ -114,6 +114,20 @@ 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 @@ -121,6 +135,14 @@ 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) -> 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 @@ -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 diff --git a/deku-p/src/core/crypto/tests/tezos_test_data.ml b/deku-p/src/core/crypto/tests/tezos_test_data.ml index bc266b92e7..3dcf592d29 100644 --- a/deku-p/src/core/crypto/tests/tezos_test_data.ml +++ b/deku-p/src/core/crypto/tests/tezos_test_data.ml @@ -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 @@ -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 From 87e44143aefd57925ce20aef55bad5643b63bf7f Mon Sep 17 00:00:00 2001 From: InfiniteSwerve Date: Mon, 31 Oct 2022 20:54:38 -0700 Subject: [PATCH 2/2] added verification test for signatures after conversion to and from b58 --- .../src/core/crypto/tests/alg_intf_tests.ml | 33 +++++++++++++++++++ deku-p/src/core/crypto/tests/test_ed25519.ml | 2 ++ 2 files changed, 35 insertions(+) diff --git a/deku-p/src/core/crypto/tests/alg_intf_tests.ml b/deku-p/src/core/crypto/tests/alg_intf_tests.ml index 4c3e3ac03c..b6be9299ff 100644 --- a/deku-p/src/core/crypto/tests/alg_intf_tests.ml +++ b/deku-p/src/core/crypto/tests/alg_intf_tests.ml @@ -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 @@ -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 @@ -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 diff --git a/deku-p/src/core/crypto/tests/test_ed25519.ml b/deku-p/src/core/crypto/tests/test_ed25519.ml index b1841c3b98..5137b397c6 100644 --- a/deku-p/src/core/crypto/tests/test_ed25519.ml +++ b/deku-p/src/core/crypto/tests/test_ed25519.ml @@ -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; ] ); ]