Skip to content

Conversation

@serban300
Copy link
Contributor

@serban300 serban300 commented Jan 9, 2026

This PR:

  1. makes some BEEFY keystore methods more generic:
  • sign()
  • public_keys()
    This is done by implementing the specific logic in the BeefyAuthorityId.
  1. Removes the BeefyAuthorityId::SignatureHasher since for some algorithms it doesn't make sense to have a hasher.

Also since now the BeefyAuthorityId implements both the signing and the verification logic, we should have better consistency.

Related to #8707 (comment)

@serban300 serban300 self-assigned this Jan 9, 2026
@serban300 serban300 added the T15-bridges This PR/Issue is related to bridges. label Jan 9, 2026
@serban300 serban300 changed the title Make BEEFY keystore more generic Make some BEEFY keystore logic more generic Jan 9, 2026
@serban300 serban300 force-pushed the small_fixes_beefy branch 2 times, most recently from d74c2d6 to ca1d586 Compare January 9, 2026 18:17
let msg_hash = keccak_256(msg);
let public = ecdsa::Public::try_from(self.as_slice()).unwrap();

let maybe_sig = store.ecdsa_sign_prehashed(BEEFY_KEY_TYPE, &public, &msg_hash)?;
Copy link
Contributor

Choose a reason for hiding this comment

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

I assume that you can do this in no_std and when it gets called actually in no_std it panics? Is it acceptable behavoir?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a #[cfg(feature = "std")] guard for try_sign().

));
let blake2_256_signature: ecdsa_crypto::Signature =
pair.as_inner_ref().sign_prehashed(&blake2_256(msg)).into();
assert!(!BeefyAuthorityId::verify(&pair.public(), &blake2_256_signature, msg));
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the point of keeping this? The test was showing that signing with different hash works, now it doesn't, do we need it to demonestrate that something doesn't work?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed


#[test]
#[cfg(feature = "bls-experimental")]
fn bls_beefy_verify_works() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we removing bls tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added back the support for bls_crypto

{
fn sign_with_hasher(&self, message: &[u8]) -> <Self as AppCrypto>::Signature {
let hashed_message = <MsgHash as Hash>::hash(message).into();
impl BeefySignerAuthority for <ecdsa_crypto::AuthorityId as AppCrypto>::Pair {
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't need to define BeefySignerAuthority because apparently BeefyAuthority can sign itself. Right?

Copy link
Contributor Author

@serban300 serban300 Jan 15, 2026

Choose a reason for hiding this comment

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

I think we still need it because these are different use cases. BeefySignerAuthority signs using the private key. BeefyAuthorityId signs using a keystore. Also renamed BeefyAuthority::try_sign() to try_sign_with_store()

I see that BeefySignerAuthority is used in the tests and we don't always have the store in those scenarios. Maybe we could try to modify the tests to always use a key store, but sounds like some work and I don't know if it's worth it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok let makes that explicit in the comment so it is less confusing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

let raw_signature = BeefyAuthorityId::try_sign(public, store, message)
.map_err(|e| error::Error::Keystore(e.to_string()))?
.ok_or_else(|| {
error::Error::Signature("BeefyAuthorityId::try_sign() returned None".to_string())
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems to me that error messages were more expressive before. Now we only getting "returned None" with no further clarification.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

pub trait BeefyAuthorityId<MsgHash: Hash>: RuntimeAppPublic {
pub trait BeefyAuthorityId: RuntimeAppPublic {
/// Get all the public keys of the current type from a provided `Keystore`.
fn get_all_from_store(store: KeystorePtr) -> Vec<impl AsRef<[u8]>>;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
fn get_all_from_store(store: KeystorePtr) -> Vec<impl AsRef<[u8]>>;
fn get_all_public_keys_from_store(store: KeystorePtr) -> Vec<impl AsRef<[u8]>>;

I could not figure out the puprose of the function from "get_all_from_store"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@serban300
Copy link
Contributor Author

@drskalman thank you for the review ! I think I addressed all your comments. Can you PTAL when you have time ?

Copy link
Contributor

@drskalman drskalman left a comment

Choose a reason for hiding this comment

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

I actually liked your using of BEEFY_KEY_TYPE it was more expressive but I'm on going to dwell on that :-)

{
fn sign_with_hasher(&self, message: &[u8]) -> <Self as AppCrypto>::Signature {
let hashed_message = <MsgHash as Hash>::hash(message).into();
impl BeefySignerAuthority for <ecdsa_crypto::AuthorityId as AppCrypto>::Pair {
Copy link
Contributor

Choose a reason for hiding this comment

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

Ok let makes that explicit in the comment so it is less confusing.

@serban300
Copy link
Contributor Author

serban300 commented Jan 26, 2026

I actually liked your using of BEEFY_KEY_TYPE it was more expressive but I'm on going to dwell on that :-)

Renamed it back to BEEFY_KEY_TYPE

@serban300
Copy link
Contributor Author

/cmd prdoc --audience node_dev --bump patch

@drskalman drskalman self-requested a review January 29, 2026 17:01
Copy link
Contributor

@drskalman drskalman left a comment

Choose a reason for hiding this comment

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

Thank you very much! LGTM 👍

@serban300 serban300 added this pull request to the merge queue Jan 29, 2026
Merged via the queue into paritytech:master with commit a6082b3 Jan 29, 2026
237 of 241 checks passed
@serban300 serban300 deleted the small_fixes_beefy branch January 29, 2026 17:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T15-bridges This PR/Issue is related to bridges.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants