crypto: ed25519 & sr25519 batch verification#6120
Conversation
Codecov Report
@@ Coverage Diff @@
## master #6120 +/- ##
==========================================
- Coverage 60.82% 60.66% -0.17%
==========================================
Files 276 277 +1
Lines 25788 25913 +125
==========================================
+ Hits 15686 15719 +33
- Misses 8488 8555 +67
- Partials 1614 1639 +25
|
|
This pr focuses on previous commit verification. I think current vote verification in a batch form should be done in a separate PR because it puts a greater focus on consensus. |
alexanderbez
left a comment
There was a problem hiding this comment.
Great work @marbar3778. I left some questions and comments 👍
author Marko Baricevic <marbar3778@yahoo.com> 1614262850 +0100 committer Marko Baricevic <marbar3778@yahoo.com> 1614692925 +0100 gpgsig -----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEEFE0lS6lW436ohG3eHBpbRKDkZ00FAmA+Qj0ACgkQHBpbRKDk Z01x5Q/7B9W9kvHie8GNI9nLU7/BBiJo1tvfIA9bUbS0mpEvm25Bp9CndLg7jmWt tKEZmu+diANZVKSdtrPWUhiD6hg980BBZqrMjXnedxpQGAoDwQxFwrRbMhkU7TJC InoMsGkMKAiJ2oKDWQNH+5iGiJqsgO9oXXgzWXZdE9usfcuikoJyYOOx8T/Pnyed aCdEpCRKklAzSawT2gBOoCpTzOohZ/Jr2NGgBj93PUem1cAQBqhcvHm4lxVCT+E8 vHobXxErTFf+22o4Pj2HjDjqihfuhOT4+mAb9Bz53FtWyq5uHrtnhITABCF2fHFd Mk68y3pAzM9hBjiyb2FIYQ4HHMaC841qamlTRUb8RdgxGYpV0TZ39A3F92gkYgad fOr8jBrGtZDXnqEeGdEcZYqeYVOP/YvAy4jvgE3RPbaaGc1nXgR6J54/dxpEqEek KOMtWVaR2xLVg1D9/EZlzH2qX4Vy2ybIWlLZApHXIPN6KLwkkB1OV3LfUGdTAcT5 ag9eOSU41KLp4c1QUwTBbwBAqZ7b1f/790jvIIrUwXDl66Llj7VP9WxhzrlnX2k0 03YcJbFkGw57jAm7UwfH0Y+F0wHLWuPtUt0TDwTxMlaYYTyjT2kpBwsevBCxUWTv YiBNeOzajD5UiKc7JE7yKZUPthstyvOrPHgi1AxgLXxsI0cq6GQ= =Vik0 -----END PGP SIGNATURE----- add verifycommit batch and bench specify keytype for benchmark remove new.txt goimport add changelog entry address comments Update crypto/sr25519/sr25519_test.go Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com> Update crypto/sr25519/batch.go Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com> Update crypto/ed25519/ed25519.go Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com> Update crypto/ed25519/ed25519_test.go Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com> Update crypto/ed25519/ed25519_test.go Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com> add more context add comment for signature check Update crypto/ed25519/bench_test.go Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com>
844d9e0 to
79b54ba
Compare
Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com>
79b54ba to
7a7a4db
Compare
types/validator_set.go
Outdated
| for idx, commitSig := range commit.Signatures { | ||
| if commitSig.Absent() { | ||
| continue // OK, some signatures can be absent. | ||
| } | ||
|
|
||
| // The vals and commit have a 1-to-1 correspondance. | ||
| // This means we don't need the validator address or to do any lookup. | ||
| val := vals.Validators[idx] | ||
|
|
||
| // Validate signature. | ||
| voteSignBytes := commit.VoteSignBytes(chainID, int32(idx)) | ||
| if !val.PubKey.VerifySignature(voteSignBytes, commitSig.Signature) { | ||
| return fmt.Errorf("wrong signature (#%d): %X", idx, commitSig.Signature) | ||
| } | ||
|
|
||
| // Good! | ||
| if commitSig.ForBlock() { | ||
| talliedVotingPower += val.VotingPower | ||
| } |
There was a problem hiding this comment.
So this block and the block under the case of when !bv.Verify() evaluates true are identical. We should keep this code DRY. Perhaps move this logic to an inline function in this function.
e.g.
verifySigsDefault := func(...) {
// ...
}
// ...
if !bv.Verify() {
verifySigsDefault(...)
}Also, if !bv.Verify() evaluates to true, we recompute the voteSignBytes all over again. Maybe this isn't much overhead, but perhaps we can compute and store these once. Thoughts @melekes?
There was a problem hiding this comment.
I can look at inlining, I tested it and ran into some issues but cant recall why I reverted.
We can try caching it. If verification fails we will need to single verify whats in the cache and potentially more. Its possible to do this, I can do some benchmarking to test this.
There was a problem hiding this comment.
It should 100% be possible. The code is identical unless I'm missing something obscure.
CHANGELOG_PENDING.md
Outdated
| - [rpc/client/http] \#6163 Do not drop events even if the `out` channel is full (@melekes) | ||
| - [node] \#6059 Validate and complete genesis doc before saving to state store (@silasdavis) | ||
| - [state] \#6067 Batch save state data (@githubsands & @cmwaters) | ||
| - [libs/log] \#6174 Include timestamp (`ts` field; `time.RFC3339Nano` format) in JSON logger output (@melekes) |
There was a problem hiding this comment.
Where did this entry come from?
There was a problem hiding this comment.
no idea, merged in master and it appeared. Will remove
alexanderbez
left a comment
There was a problem hiding this comment.
Looks good @marbar3778. Could use use linting/style cleanup, but the logic seems good.
Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com>
Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com>
…ermint into marko/batch-impl
|
yay! Very excited that this got in =))) |
Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com> Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com>
Description
Add batch verification
closes #1809
all done on a macbook pro m1 8gb