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 inline test for signature consistency #10650

Merged
merged 1 commit into from
Mar 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/lib/signature_lib/test/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
(library
(name signature_lib_tests)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why create a separate module for inline tests? Why not inline these in the library itself? (or the caller if we want to keep the library out of scope for this test)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inline tests get compiled into the Mina binary. We've been starting to move them out, to avoid executable bloat.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inline tests get compiled into the Mina binary

dang, that's a pretty good reason not to use inline tests at all :D

(libraries
random_oracle_input
signature_lib
snark_params)
(instrumentation (backend bisect_ppx))
(inline_tests)
(preprocess
(pps
ppx_inline_test
ppx_version)))
39 changes: 39 additions & 0 deletions src/lib/signature_lib/test/signature_lib_tests.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
open Signature_lib
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my understanding is that there is no global dune runtest running in CI, am I mistaken?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dune runtest src/lib/ is run, among others.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah I was wrong then


let%test_module "Signatures are unchanged test" =
Copy link
Contributor

@jspada jspada Mar 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a great test to add!

Would it be possible to quickly make it use our standard set of signature test vectors?

https://github.com/o1-labs/proof-systems/blob/bbc4c77382507c3a0c66f9fda1a7499a5d547b7a/signer/tests/signer.rs#L125

( module struct
let privkey =
Private_key.of_base58_check_exn
"EKE2M5q5afTtdzZTzyKu89Pzc7274BD6fm2fsDLgLt5zy34TAN5N"

let signature_expected =
( Snark_params.Tick.Field.of_string
"22392589120931543014785073787084416773963960016576902579504636013984435243005"
, Snark_params.Tock.Field.of_string
"21219227048859428590456415944357352158328885122224477074004768710152393114331"
)

let%test "signature of empty random oracle input matches" =
let signature_got =
Schnorr.sign privkey (Random_oracle_input.field_elements [||])
in
Snark_params.Tick.Field.equal (fst signature_expected) (fst signature_got)
&& Snark_params.Tock.Field.equal (snd signature_expected)
(snd signature_got)

let%test "signature of signature matches" =
let signature_got =
Schnorr.sign privkey
(Random_oracle_input.field_elements [| fst signature_expected |])
in
let signature_expected =
( Snark_params.Tick.Field.of_string
"7379148532947400206038414977119655575287747480082205647969258483647762101030"
, Snark_params.Tock.Field.of_string
"26901815964642131149392134713980873704065643302140817442239336405283236628658"
)
in
Snark_params.Tick.Field.equal (fst signature_expected) (fst signature_got)
&& Snark_params.Tock.Field.equal (snd signature_expected)
(snd signature_got)
end )