Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

More secure Signed implementation #2963

Merged
merged 27 commits into from
May 3, 2021
Merged

More secure Signed implementation #2963

merged 27 commits into from
May 3, 2021

Conversation

eskimor
Copy link
Member

@eskimor eskimor commented Apr 30, 2021

Fixes #2944

Also:

  • A bunch of cleanup
  • Check signature on collator side on seconded notifications
  • Couple of convenience functions
  • Get rid of redundant signature checks (in backing for example) - we now have type level guarantee that signature has been already checked.
  • Collator protocol: Better connection management - only drop connections we really no longer need.
  • CollatorProtocol has changed as we now also transmit the relay parent for the signing context in order to actually check the signature.

Important: This PR changes the wire protocol for collations.

@eskimor eskimor added A0-please_review Pull request needs code review. B1-releasenotes C1-low PR touches the given topic and has a low impact on builders. D3-trivial 🧸 PR contains trivial changes in a runtime directory that do not require an audit. labels Apr 30, 2021
primitives/src/v0.rs Outdated Show resolved Hide resolved
primitives/src/v0.rs Outdated Show resolved Hide resolved
@eskimor eskimor requested a review from drahnr May 3, 2021 15:59
Copy link
Contributor

@drahnr drahnr left a comment

Choose a reason for hiding this comment

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

Generally this LGTM besides a few nits.

Iiuc this unifies the signature check into a type, and uses that to only verify it once and hence reduce the load.

The open question that is left is, if the path from the point of checking where it was to where it is now, if that opens up any issues. TBD

node/network/collator-protocol/src/error.rs Show resolved Hide resolved
@@ -72,7 +75,7 @@ pub struct ValidatorInfo {

impl RuntimeInfo {
/// Create a new `RuntimeInfo` for convenient runtime fetches.
pub fn new(keystore: SyncCryptoStorePtr) -> Self {
pub fn new(keystore: Option<SyncCryptoStorePtr>) -> Self {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't quite see where the keystore is ever None 🙈

Copy link
Member Author

Choose a reason for hiding this comment

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

In the collator protocol (collator side) we don't need it, because we are not a validator.

signature: ValidatorSignature,
context: &SigningContext<H>,
key: &ValidatorId,
) -> Option<Self> {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Isn't this rather a Result with a unit struct SignatureVerificationError?

Copy link
Member Author

Choose a reason for hiding this comment

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

It was this way before and I also think it is pretty obvious what None means in this case. To be honest you have a point, but if you do not object, I am going to be lazy and just merge if this is the only nit 😬

statement: &SignedFullStatement,
) -> std::result::Result<(), ()> {
statement: UncheckedSignedFullStatement,
) -> std::result::Result<SignedFullStatement, UncheckedSignedFullStatement> {
Copy link
Contributor

Choose a reason for hiding this comment

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

❤️ this is nice!

Copy link
Contributor

@drahnr drahnr left a comment

Choose a reason for hiding this comment

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

Second sweep, LGTM (besides the previous mentioned nits)

@eskimor eskimor merged commit e9a29ec into master May 3, 2021
@eskimor eskimor deleted the rk-secure-signed branch May 3, 2021 19:41
andresilva pushed a commit that referenced this pull request May 4, 2021
* Remove signature verification in backing.

`SignedFullStatement` now signals that the signature has already been
checked.

* Remove unused check_payload function.

* Introduced unchecked signed variants.

* Fix inclusion to use unchecked variant.

* More unchecked variants.

* Use unchecked variants in protocols.

* Start fixing statement-distribution.

* Fixup statement distribution.

* Fix inclusion.

* Fix warning.

* Fix backing properly.

* Fix bitfield distribution.

* Make crypto store optional for `RuntimeInfo`.

* Factor out utility functions.

* get_group_rotation_info

* WIP: Collator cleanup + check signatures.

* Convenience signature checking functions.

* Check signature on collator-side.

* Fix warnings.

* Fix collator side tests.

* Get rid of warnings.

* Better Signed/UncheckedSigned implementation.

Also get rid of Encode/Decode for Signed! *party*

* Get rid of dead code.

* Move Signed in its own module.

* into_checked -> try_into_checked

* Fix merge.
ordian added a commit that referenced this pull request May 6, 2021
* master:
  Squashed 'bridges/' changes from 89a76998..b2099c5c
  Enable Pallet XCM for Kusama & Westend (#2970)
  kusama, westend: use proper parachain session keys (#2975)
  change statemint id (not system para) (#2974)
  runtime: remove random_seed from BlockBuilder API (#2968)
  runtime: remove beefy and mmr from westend (again) (#2972)
  Do peer connect later (as it happens in reality). (#2971)
  More secure `Signed` implementation (#2963)
  runtime: remove BabePalletPrefix impls for old migration (#2967)
  Companion for Substrate#8526 (#2845)
  Companion for Multi-phase elections solution resubmission (#2648)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A0-please_review Pull request needs code review. C1-low PR touches the given topic and has a low impact on builders. D3-trivial 🧸 PR contains trivial changes in a runtime directory that do not require an audit.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Signed struct should not have Encode and Decode instances.
3 participants