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

Addition of test vectors to test-crypto test suite for ecdsa and schnorr #320

Merged
merged 1 commit into from
Nov 7, 2022

Conversation

nabinpkl
Copy link
Contributor

@nabinpkl nabinpkl commented Oct 18, 2022

An initial pull request that contains test vectors for secp256k1. which includes following :

ECDSA
- Signing and verification successful
- Invalid length for required parameters check
- Signing and verification of pre-image message by hashing it
- Invalid message hash length check for ecdsa
- Invalid verification key check
- Invalid message hash check
- Invalid signature check

Schnorr
- Signing and verification successful
- Invalid length for required parameters check
- Invalid verification key check
- Invalid message check
- Invalid signature check

@nabinpkl nabinpkl marked this pull request as draft October 18, 2022 14:53
@nabinpkl nabinpkl marked this pull request as ready for review October 18, 2022 19:09
Copy link
Collaborator

@lehins lehins left a comment

Choose a reason for hiding this comment

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

Thank you for submitting this PR. I'll do a proper review tomorrow, but for now there is one comment

cardano-crypto-tests/cardano-crypto-tests.cabal Outdated Show resolved Hide resolved
Copy link
Collaborator

@iquerejeta iquerejeta left a comment

Choose a reason for hiding this comment

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

A few comments on the PR:

  • Unit tests should not be here. They should live in the DSIGN testing framework. Tests in the Test folder are duplicates, and those who are not should be included here.
  • I don't understand what is the purpose of writing the result to the csv-outputs, nor why they are included in the repo.

The way tests should be organised with test-vectors is that given some hardcoded values (the test-vectors), functions should behave in certain ways. e.g. "running verify function on test-vector#1 should output true". I can't find that in this PR, and it seems to me that the test vectors are simply used to create the csv-outputs.

Please let me know if I'm missing something.

cardano-crypto-tests/vector-tests/README.md Outdated Show resolved Hide resolved
cardano-crypto-tests/vector-tests/Main.hs Outdated Show resolved Hide resolved
@nabinpkl nabinpkl marked this pull request as draft October 20, 2022 14:53
@nabinpkl
Copy link
Contributor Author

nabinpkl commented Oct 20, 2022

@iquerejeta I was also in confusion about where should the vector tests live, is it okay to create a separate folder as done here for vector tests only or should it be integrated into src/Vector and include it in test/Main.hs?

@iquerejeta
Copy link
Collaborator

I don't have a strong opinion on where the vector test live. Given that this folder is dedicated only for test over hardcoded test-vectors, it might make sense to put them in Main.hs, but I don't know what are the standard practices in Haskell.

@nabinpkl nabinpkl marked this pull request as ready for review October 22, 2022 06:47
@nabinpkl nabinpkl requested review from iquerejeta and lehins and removed request for iquerejeta and lehins October 22, 2022 06:48
Copy link
Contributor

@tdammers tdammers left a comment

Choose a reason for hiding this comment

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

Looks mostly OK, but the stringly-typed fixtures are a show stopper IMO.

@nabinpkl nabinpkl marked this pull request as draft October 26, 2022 05:12
@nabinpkl nabinpkl changed the title Addition of test vectors and simple unit tests for secp256k1 - ECDSA and Schnorr Addition of test vectors to test-crypto test suite - ECDSA and Schnorr Oct 26, 2022
@nabinpkl nabinpkl requested review from tdammers and removed request for iquerejeta October 26, 2022 17:19
@nabinpkl nabinpkl marked this pull request as ready for review October 26, 2022 17:20
@nabinpkl nabinpkl changed the title Addition of test vectors to test-crypto test suite - ECDSA and Schnorr Addition of test vectors to test-crypto test suite for ecdsa and schnorr Oct 26, 2022
Copy link
Contributor

@tdammers tdammers left a comment

Choose a reason for hiding this comment

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

This is going in the right direction, but could use some cleaning up.

I'd suggest the following:

  • Change the HexString type to be a newtype wrapper over ByteString
  • Write appropriate IsString and Show instances for it (you can actually do the hex conversions in those, such that the wrapped ByteString is just the raw bytes, and conversion to and from hex happens when reading / printing them)
  • Use OverloadedStrings to write HexStrings as string literals directly
  • Write a set of conversion functions from HexString to your keys, sigs and messages (4 of them should be all you need: sign key, ver key, sig, message), and use these when defining your fixtures.

See further minor suggestions inline.

Copy link
Contributor

@tdammers tdammers left a comment

Choose a reason for hiding this comment

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

Some minor remarks, but no show stoppers as far as I'm concerned.

@nabinpkl nabinpkl requested a review from catch-21 November 1, 2022 16:58
@nabinpkl
Copy link
Contributor Author

nabinpkl commented Nov 2, 2022

Another interesting test to have with ECDSA is testing signAndVerify with all hash functions we have available in cardano-base that output 32bytes (Blake2b, SHA-256, SHA3-256, and Keccak probably? thinking ). Could you add that as a unit test? Note that this does not need to be a test-vector, but rather some randomly generated unit tests that can go in Test/Crypto.

Another pr is created for these tests which are added in quick check tests testGroup Crypto.DSIGN. Review is required.
#332

@iquerejeta iquerejeta requested review from lehins and removed request for catch-21 November 2, 2022 11:52
@nabinpkl nabinpkl requested review from catch-21 and lehins and removed request for lehins and catch-21 November 2, 2022 14:50
Copy link
Collaborator

@lehins lehins left a comment

Choose a reason for hiding this comment

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

Looks good. I have no idea why all those tests are called Vector, it doesn't look like it has to do with any vectors that I know of, but I don't particularly care about test names.

Mostly comments are about formatting and usage of utf8

cardano-crypto-tests/cardano-crypto-tests.cabal Outdated Show resolved Hide resolved
cardano-crypto-tests/src/Test/Crypto/Vector/Vectors.hs Outdated Show resolved Hide resolved
cardano-crypto-tests/src/Test/Crypto/Vector/Vectors.hs Outdated Show resolved Hide resolved
cardano-crypto-tests/src/Test/Crypto/Vector/Vectors.hs Outdated Show resolved Hide resolved
cardano-crypto-tests/src/Test/Crypto/Vector/Vectors.hs Outdated Show resolved Hide resolved
cardano-crypto-tests/src/Test/Crypto/Vector/Vectors.hs Outdated Show resolved Hide resolved
cardano-crypto-tests/src/Test/Crypto/Vector/Vectors.hs Outdated Show resolved Hide resolved
cardano-crypto-tests/src/Test/Crypto/Vector/Vectors.hs Outdated Show resolved Hide resolved
cardano-crypto-tests/src/Test/Crypto/Vector/Vectors.hs Outdated Show resolved Hide resolved
@nabinpkl
Copy link
Contributor Author

nabinpkl commented Nov 4, 2022

Looks good. I have no idea why all those tests are called Vector, it doesn't look like it has to do with any vectors that I know of, but I don't particularly care about test names.

Mostly comments are about formatting and usage of utf8

Sorry, I don't quite get the question. Are you referring to module Vector? I thought it indicated that it contains tests for hardcoded vectors. Test names are named using Test only at suffix.

@nabinpkl nabinpkl force-pushed the master branch 2 times, most recently from 05c46a8 to 8723981 Compare November 4, 2022 07:28
@nabinpkl nabinpkl requested a review from lehins November 4, 2022 07:45
@lehins
Copy link
Collaborator

lehins commented Nov 4, 2022

I thought it indicated that it contains tests for hardcoded vectors.

@nabinpkl That's my point, there are no vectors in any of the tests. There are some lists, but no vectors.

Could you also please rebase it on master. I'll take a second look in just a little bit

Copy link
Collaborator

@lehins lehins left a comment

Choose a reason for hiding this comment

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

Awesome work. Thank you!

@lehins
Copy link
Collaborator

lehins commented Nov 4, 2022

Before merging we also need to squash all commits. Other than that I think this PR is ready to be merged

@nabinpkl
Copy link
Contributor Author

nabinpkl commented Nov 4, 2022

I thought it indicated that it contains tests for hardcoded vectors.

@nabinpkl That's my point, there are no vectors in any of the tests. There are some lists, but no vectors.

@lehins Are you referring to Vector as in Data.Vector? But i was referring to Test vector as in set of inputs to be used to test the system. But yeah it could be ambiguous. Not sure about living area for hardcoded test values to be sit here on parent module mostly with quick check tests tho.

In addition, to some serialization utils, error messages constants, and input vectors contained in Vectors.hs
@nabinpkl nabinpkl requested a review from catch-21 November 4, 2022 17:12
@iquerejeta iquerejeta merged commit b403b76 into IntersectMBO:master Nov 7, 2022
iquerejeta pushed a commit that referenced this pull request Nov 21, 2022
Addition of test vectors to test-crypto test suite for ecdsa and schnorr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants