-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Use batching verification in the runtime #6643
Changes from all commits
f7c64a7
f455e39
c85a6f6
76b4dd8
4dd4efd
97bdf47
b880323
a955581
5f5e6e6
2519c54
a4764eb
fd2baf0
d8541f3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -84,10 +84,24 @@ pub trait Verify { | |
| type Signer: IdentifyAccount; | ||
| /// Verify a signature. | ||
| /// | ||
| /// Return `true` if signature is valid for the value. | ||
| /// Should return `true` if signature is valid for the value. | ||
| fn verify<L: Lazy<[u8]>>(&self, msg: L, signer: &<Self::Signer as IdentifyAccount>::AccountId) -> bool; | ||
| } | ||
|
|
||
| /// Means of signature batch verification. | ||
| /// | ||
| /// Should only be used when there is a batching context registered on the host (through instantiating | ||
| /// helper struct `SingatureBatching` or via 'crypto::start_batch_verify`). | ||
| /// | ||
| /// If there were at least one call to this function, `crypto::finish_batch_verify` (or `SingatureBatching::verify`) | ||
| /// then should be called and code must panic if either returns false. | ||
| pub trait BatchVerify: Verify { | ||
| /// Verify a signature using available batcher. | ||
| /// | ||
| /// Should return `false` if batching failed or a previous signature already evaluated as invalid. | ||
| fn batch_verify<L: Lazy<[u8]>>(&self, msg: L, signer: &<Self::Signer as IdentifyAccount>::AccountId) -> bool; | ||
| } | ||
|
|
||
| impl Verify for sp_core::ed25519::Signature { | ||
| type Signer = sp_core::ed25519::Public; | ||
|
|
||
|
|
@@ -96,6 +110,13 @@ impl Verify for sp_core::ed25519::Signature { | |
| } | ||
| } | ||
|
|
||
|
|
||
| impl BatchVerify for sp_core::ed25519::Signature { | ||
| fn batch_verify<L: Lazy<[u8]>>(&self, mut msg: L, signer: &sp_core::ed25519::Public) -> bool { | ||
| sp_io::crypto::ed25519_batch_verify(self, msg.get(), signer) | ||
| } | ||
| } | ||
|
|
||
| impl Verify for sp_core::sr25519::Signature { | ||
| type Signer = sp_core::sr25519::Public; | ||
|
|
||
|
|
@@ -104,6 +125,12 @@ impl Verify for sp_core::sr25519::Signature { | |
| } | ||
| } | ||
|
|
||
| impl BatchVerify for sp_core::sr25519::Signature { | ||
| fn batch_verify<L: Lazy<[u8]>>(&self, mut msg: L, signer: &sp_core::sr25519::Public) -> bool { | ||
| sp_io::crypto::sr25519_batch_verify(self, msg.get(), signer) | ||
| } | ||
| } | ||
|
|
||
| impl Verify for sp_core::ecdsa::Signature { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not for
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ecdsa is a bit tricky, since it dominates the verification (takes much more time compared to transaction execution) Node can be forced to do much more work before first ecdsa is resolved as invalid
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The other signatures probably also take more time to verify than a simple transfer. This feature is ridiculous if you draw the line here. Than we don't need async verification at all. If this would be a problem in the future, we could disable async signature verification when importing blocks on the tip of the chain. However, for syncing we want the best performance.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To me, you can trick node to verify 1000 or so heavy signatures for free until first one is resolved and possibly completely stop some validators, not going to add it here until some proof that this is safe provided.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can also force you to verify 3000 sr25519 signatures. Where it the difference?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, you basically just want early exit of the scheduled verifications? So that we abort all, if one fails? Should not be that hard to implement, just make the future select on an exit signal. And ECDSA is also not orders of magnitudes slower, on my machine it was factor 3 slower. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can support Ed25519 batch verification eventually I think, but not worth the time right now.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nevertheless, I like the idea of adding an early bail out for these verification tasks if one failed. This should prevent the problems you have described here.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added implementation for standalone ECDSA, but I think the way it works it can't be used in |
||
| type Signer = sp_core::ecdsa::Public; | ||
| fn verify<L: Lazy<[u8]>>(&self, mut msg: L, signer: &sp_core::ecdsa::Public) -> bool { | ||
|
|
@@ -117,6 +144,16 @@ impl Verify for sp_core::ecdsa::Signature { | |
| } | ||
| } | ||
|
|
||
| impl BatchVerify for sp_core::ecdsa::Signature { | ||
| fn batch_verify<L: Lazy<[u8]>>(&self, mut msg: L, signer: &sp_core::ecdsa::Public) -> bool { | ||
| sp_io::crypto::ecdsa_batch_verify( | ||
| self, | ||
| msg.get(), | ||
| signer, | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| /// Means of signature verification of an application key. | ||
| pub trait AppVerify { | ||
| /// Type of the signer. | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.