Skip to content
This repository was archived by the owner on Feb 2, 2019. It is now read-only.

Add a verify method which also takes in the uncompressed public key.#7

Closed
ValarDragon wants to merge 2 commits intotendermint:masterfrom
ValarDragon:dev/cache_pubkey
Closed

Add a verify method which also takes in the uncompressed public key.#7
ValarDragon wants to merge 2 commits intotendermint:masterfrom
ValarDragon:dev/cache_pubkey

Conversation

@ValarDragon
Copy link

@ValarDragon ValarDragon commented Jun 15, 2018

This is useful for the proof of stake use case, since we often validate multiple signatures from the same public key. Based off of the numbers in the official Ed25519 paper, the function with the uncompressed pubkey should save about 10% of the computation time.


// https://tools.ietf.org/html/rfc8032#section-5.1.7 requires that s be in
// the range [0, order) in order to prevent signature malleability.
if !edwards25519.ScMinimal(&s) {
Copy link

Choose a reason for hiding this comment

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

This also contains the diff for the upstream changes from x/crypto? I think we should merge this in a separate PR first and add the VerifyUncompressedKey here only (by rebasing / merging).

Copy link
Author

Choose a reason for hiding this comment

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

Okay!

Copy link

Choose a reason for hiding this comment

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

You can keep the PR open. I'll merge #6 after making sure the diff exactly matches the changes on x/crypto. Then, you can rebase on the branch that contains the merge.


// VerifyUncompressedKey returns true iff sig is a valid signature of message by publicKey.
// This takes in the uncompressed form of the public key (A) to avoid computing that internally.
func VerifyUncompressedKey(publicKey *[PublicKeySize]byte, A *edwards25519.ExtendedGroupElement, message []byte, sig *[SignatureSize]byte) bool {
Copy link

Choose a reason for hiding this comment

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

If we introduce a new public method, we should have a test for that.

Copy link
Author

@ValarDragon ValarDragon Jun 19, 2018

Choose a reason for hiding this comment

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

How would such a test differ from the normal verify though? I would basically be replicating the code inside of Verify, and I'm not sure how useful that is as a test. (Uncompress the pubkeys using the same decompression method, and then run the same test vectors, which is exactly whats done by testing Verify)

Copy link

Choose a reason for hiding this comment

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

Tests also serve as a form of documentation here. One can look into the test and see the exact behaviour you just described above. Does that make sense to you?

@liamsi
Copy link

liamsi commented Jun 19, 2018

Based off of the numbers in the official Ed25519 paper, the function with the uncompressed pubkey should save about 10% of the computation time.

That is pretty cool! 👍 We need to make sure that this 10% improvement, actually leads to a measurable improvement in a real deployment and hence is really worth exposing some edwards25519 compression interna (and later needing to change the keybase interface to provide the actual cached uncompressed public key.

Would you like to do some perf measurements to compare how much of an improvement this would actually bring in tendermint/cosmos deployment? I would suggest not to merge before that.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants