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

Support for multiple signature scheme for BEEFY primitves #14373

Conversation

drskalman
Copy link
Contributor

@drskalman drskalman commented Jun 14, 2023

This is a subset of the changes introduced by Pull request #13311 which tends to enable BEEFY to support more than one signature scheme at the time in order to accommodate various bridged chains. This is only the changes needed in primitives/consensus/beefy while keeping the current client backward compatible in order to facilitate reviewing and merging.

polkadot companion: paritytech/polkadot#7572

cumulus companion: paritytech/cumulus#2962

…ives

- Fix remaining crypto -> ecdsa_crypto
- code build but not tests
…ent`.

- Remove apk proof keyset_commitment from `BeefyAuthoritySet`.
- Fix failing signed commitment and signature to witness test.
- Make client compatible with BeefyAPI generic on AuthorityId.
- `crypto` → `ecdsa_crypto` in BEEFY client and frame.
Copy link
Contributor

@acatangiu acatangiu left a comment

Choose a reason for hiding this comment

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

Everything looks good, except single question below.

primitives/consensus/beefy/src/lib.rs Outdated Show resolved Hide resolved
primitives/consensus/beefy/src/lib.rs Outdated Show resolved Hide resolved
primitives/consensus/beefy/Cargo.toml Outdated Show resolved Hide resolved
primitives/consensus/beefy/src/lib.rs Outdated Show resolved Hide resolved
primitives/consensus/beefy/src/witness.rs Outdated Show resolved Hide resolved
@davxy
Copy link
Member

davxy commented Jun 19, 2023

Probably at some point you'll need to embed this key type in the keys used by some node (in SessionKeys here).

This is used to generate new keys "on demand" via the sp_session::SessionKeys interface or in the genesis build for the testnet node.

BTW, to add a key type there you need to implement the RuntimePublic trait for your application specific public key.
Is not required to implement the full set of functions (as you don't need all of them) you can implement only the generate_key.

As a reference see the bandersnatch-vrf PR here:

impl RuntimePublic for Public {
type Signature = Signature;
/// Dummy implementation. Returns an empty vector.
fn all(_key_type: KeyTypeId) -> Vec<Self> {
Vec::new()
}
fn generate_pair(key_type: KeyTypeId, seed: Option<Vec<u8>>) -> Self {
sp_io::crypto::bandersnatch_generate(key_type, seed)
}
/// Dummy implementation. Returns `None`.
fn sign<M: AsRef<[u8]>>(&self, _key_type: KeyTypeId, _msg: &M) -> Option<Self::Signature> {
None
}
/// Dummy implementation. Returns `false`.
fn verify<M: AsRef<[u8]>>(&self, _msg: &M, _signature: &Self::Signature) -> bool {
false
}
fn to_raw_vec(&self) -> Vec<u8> {
sp_core::crypto::ByteArray::to_raw_vec(self)
}
}

drskalman and others added 3 commits June 20, 2023 04:24
…c/lib.rs

Co-authored-by: Davide Galassi <davxy@datawok.net>
- Make new `BeeyApi` functinos also generic over AuthorityId and Signature
@andresilva andresilva added A0-please_review Pull request needs code review. B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders. D2-notlive 💤 PR contains changes in a runtime directory that is not deployed to a chain that requires an audit. labels Jun 20, 2023
@drskalman
Copy link
Contributor Author

BTW, to add a key type there you need to implement the RuntimePublic trait for your application specific public key.

Hmm, I did but you removed them for some reason. I can bring them back if you think they are OK.

@davxy
Copy link
Member

davxy commented Jun 22, 2023

BTW, to add a key type there you need to implement the RuntimePublic trait for your application specific public key.

Hmm, I did but you removed them for some reason. I can bring them back if you think they are OK.

@drskalman we don't require to implement the full set of methods because most of them require host functions support (sp_io::...). Is preferable to add new host functions only if are really - really- required.

Unfortunately, working on analoguous code for introducing bandersnatch-vrf, I noticed that if you want to use the key as part of the session keys set then you require to implement at least the generate_pair because it is used to do a couple of things.

Now, as you can see from the snip I've shared, I just implemented the generate_pair and provided a dummy implementation for the others (makes no sense to introduce a HF that is never used).

Before adding it, just let me check a couple of things to see if we can instead fix this requirement in other way
@drskalman looks like -as is - there is no workaround. Explicit session keys set generation pass thorough the runtime and then access the keystore via externalities to save the key there.
In short, I think you need to add a "partially dummy" implementation to at least provide the ability to generate the key via host func as in the bandersnatch-vrf snip I shared

@Lederstrumpf Lederstrumpf self-requested a review June 22, 2023 08:30
- Add `bls-experimental` to `sp-io`

Does not compile because PassByCodec can not derive PassBy using customly implemented PassByIner.
@drskalman
Copy link
Contributor Author

@davxy : It seems that runtime_interface is failing to derive PassBy using your custom implementation of PassByInner:

    |   the trait `PassBy` is not implemented for `sp_core::bls::Public<w3f_bls::engine::TinyBLS<ark_ec::models::bls12::Bls12<ark_bls12_377::curves::Config>,
 ark_bls12_377::curves::Config>>`                                                                                                                     

Should we also manually implement PassBy for Public And Signature in core/src/bls.rs?

… skalman-multiple-signature-scheme-beefy-primitves
@drskalman
Copy link
Contributor Author

@drskalman I added a suggestion that allows to remove direct dep from w3f-bls.

Some more nits

I think I addressed all the new ones.

@davxy davxy requested review from andresilva and a team August 1, 2023 06:57
Copy link
Contributor

@andresilva andresilva left a comment

Choose a reason for hiding this comment

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

lgtm. just minor nits

primitives/consensus/beefy/src/lib.rs Outdated Show resolved Hide resolved
primitives/consensus/beefy/src/lib.rs Outdated Show resolved Hide resolved
primitives/consensus/beefy/src/lib.rs Show resolved Hide resolved
primitives/consensus/beefy/src/witness.rs Outdated Show resolved Hide resolved
Co-authored-by: André Silva <123550+andresilva@users.noreply.github.com>
Copy link
Contributor

@Lederstrumpf Lederstrumpf left a comment

Choose a reason for hiding this comment

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

lgtm - one comment re. consistency on path forward wrt. host functions.

primitives/application-crypto/src/bls377.rs Show resolved Hide resolved
@davxy
Copy link
Member

davxy commented Aug 2, 2023

bot merge

@paritytech-processbot
Copy link

Error: Github API says "Allow edits from maintainers" is not enabled for paritytech/polkadot#7562. The bot would use that permission to push the lockfile update after merging this PR. Please check https://docs.github.com/en/github/collaborating-with-pull-requests/working-with-forks/allowing-changes-to-a-pull-request-branch-created-from-a-fork.

@davxy
Copy link
Member

davxy commented Aug 2, 2023

@drskalman apparently you have to enable "allow edits from maintainers" in your polkadot PR

@ironoa
Copy link

ironoa commented Aug 2, 2023

@drskalman apparently you have to enable "allow edits from maintainers" in your polkadot PR

there seems to be a known GH issue that still hasn't been solved, which prevents "allow edits from maintainers" to be engaged on our end: https://github.com/orgs/community/discussions/5634

Have you ever managed to bypass this problem ?

@davxy
Copy link
Member

davxy commented Aug 2, 2023

@drskalman apparently you have to enable "allow edits from maintainers" in your polkadot PR

there seems to be a known GH issue that still hasn't been solved, which prevents "allow edits from maintainers" to be engaged on our end: https://github.com/orgs/community/discussions/5634

Have you ever managed to bypass this problem ?

cc @paritytech/ci

@davxy
Copy link
Member

davxy commented Aug 2, 2023

bot merge

@paritytech-processbot
Copy link

Error: "Check reviews" status is not passing for paritytech/polkadot#7572

@davxy
Copy link
Member

davxy commented Aug 2, 2023

bot merge

@paritytech-processbot paritytech-processbot bot merged commit e966352 into paritytech:master Aug 2, 2023
48 of 49 checks passed
Lederstrumpf added a commit to Lederstrumpf/substrate that referenced this pull request Aug 7, 2023
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. B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders. D2-notlive 💤 PR contains changes in a runtime directory that is not deployed to a chain that requires an audit.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants