Skip to content

Add support of additional crypto types and hashing algorithms for Beefy#8707

Closed
Klapeyron wants to merge 28 commits intoparitytech:masterfrom
input-output-hk:hasher_trait_for_pallet_beefy
Closed

Add support of additional crypto types and hashing algorithms for Beefy#8707
Klapeyron wants to merge 28 commits intoparitytech:masterfrom
input-output-hk:hasher_trait_for_pallet_beefy

Conversation

@Klapeyron
Copy link
Copy Markdown
Contributor

@Klapeyron Klapeyron commented May 30, 2025

We would like to use BEEFY with our custom crypto type, in this PR we would like to extend BeefyKeystore with additional code, that makes an execution to underlying keystore.

Also we added a testcases for additional crypto type that is already supported.

This PR also adds support for custom hashing.

@cla-bot-2021
Copy link
Copy Markdown

cla-bot-2021 bot commented May 30, 2025

User @Klapeyron, please sign the CLA here.

@Klapeyron Klapeyron force-pushed the hasher_trait_for_pallet_beefy branch from f2c5ac1 to 22103b7 Compare June 3, 2025 10:12
@Klapeyron Klapeyron changed the title Extended pallet_beefy Config with Hashing trait Add support of additional crypto types for BeefyKeeystore Jun 3, 2025
@Klapeyron Klapeyron force-pushed the hasher_trait_for_pallet_beefy branch from 8a29ef3 to 5f4738d Compare June 3, 2025 10:41
.keys(BEEFY_KEY_TYPE)
.map_err(|e| error::Error::Keystore(e.to_string()))?
.into_iter()
.filter_map(|pk| AuthorityId::try_from(pk.as_ref()).ok())
Copy link
Copy Markdown
Contributor Author

@Klapeyron Klapeyron Jun 3, 2025

Choose a reason for hiding this comment

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

I changed the behavior here, so in case in keystore were multiple keys for beefy with different schemes, then:
Before:
it was failing on first non-compatible key
After:
it is taking keys that can be converted to AuthorityId, ignoring non-compatible ones

Copy link
Copy Markdown
Contributor

@acatangiu acatangiu Jan 5, 2026

Choose a reason for hiding this comment

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

this doesn't look sound, it will result in duplicate authorities list if we have authorities registered with multiple types of crypto keys -- we would get an authority instance for each compatible crypto key -- which is breaking the old behavior and potentially breaking downstream assumptions

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Opened a PR that should make some things more generic and should address this also: #10763

},

_ => Err(error::Error::Keystore("key type is not supported by BEEFY Keystore".into()))?,
_ => store
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I am not replacing previous 2 cases with this generic call, due they perform some additional hashing, which will be not done in case I will remove them

sig_ref.to_vec()
},

_ => Err(error::Error::Keystore("key type is not supported by BEEFY Keystore".into()))?,
Copy link
Copy Markdown
Contributor Author

@Klapeyron Klapeyron Jun 3, 2025

Choose a reason for hiding this comment

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

I am not adding a case for bls381::CRYPTO_ID, due it does not need additional hashing as I understand, please correct me if I am wrong :). So it should fall in generic call.

@Klapeyron Klapeyron force-pushed the hasher_trait_for_pallet_beefy branch from aed7013 to 26e99a8 Compare June 3, 2025 18:45
@Klapeyron Klapeyron marked this pull request as ready for review June 3, 2025 18:45
@burdges
Copy link
Copy Markdown
Contributor

burdges commented Jun 4, 2025

Any thoughts on this @drskalman ?

@Klapeyron Klapeyron force-pushed the hasher_trait_for_pallet_beefy branch from 0f3d74e to 56dac31 Compare June 4, 2025 19:47
@bkchr bkchr requested a review from serban300 June 5, 2025 09:36
@serban300 serban300 requested a review from acatangiu June 16, 2025 12:38
@serban300
Copy link
Copy Markdown
Contributor

Not sure if it would make sense to allow Beefy to work with custom crypto types. @acatangiu @drskalman WDYT ?

Also @Klapeyron could you give us more details about your use case please ?

@Klapeyron
Copy link
Copy Markdown
Contributor Author

Klapeyron commented Jun 16, 2025

Also @Klapeyron could you give us more details about your use case please ?

Sure. So we have more zero knowledge related scenario, we would like to use schnorr jubjub for that. So far we implemented the cryptography traits so we can use it among substrate code, but without changes in this PR, BEEFY will not make a call to a keystore for necessary keys, due custom cryptography is not on the list of supported types.

Draft of the changes is here: input-output-hk/partner-chains#813

Also cryptography is not the only thing we would like to adjust, probably replacement of hardocded Keccak256 will require to add additional code (maybe as separate PR to not complicate).

@Klapeyron Klapeyron force-pushed the hasher_trait_for_pallet_beefy branch from 5577411 to 9719b43 Compare June 16, 2025 18:34
@Klapeyron Klapeyron requested a review from a team as a code owner June 16, 2025 18:34
@acatangiu
Copy link
Copy Markdown
Contributor

I haven't the time now to review the code in detail. The reasoning behind this PR is good to me, maybe @drskalman and @serban300 can help with the code review.

One high-level comment I have is that this is making breaking changes to BEEFY primitives, and BEEFY and MMR runtime pallets. It means that it needs major bumps across the board and can only go in a major release.

@Klapeyron Klapeyron changed the title Add support of additional crypto types for BeefyKeeystore Add support of additional crypto types and hashing algorithms for BeefyKeeystore Jun 30, 2025
@nkpar nkpar enabled auto-merge November 28, 2025 03:31
@nkpar nkpar disabled auto-merge November 28, 2025 03:31
@Klapeyron
Copy link
Copy Markdown
Contributor Author

@serban300 @acatangiu may as ask for your review of this changes?

@Klapeyron Klapeyron force-pushed the hasher_trait_for_pallet_beefy branch from b69e08a to 579c7de Compare January 5, 2026 11:43
@Klapeyron Klapeyron requested review from a team, cheme and koute as code owners January 5, 2026 11:43
@paritytech-review-bot paritytech-review-bot bot requested a review from a team January 5, 2026 11:44
@Klapeyron Klapeyron force-pushed the hasher_trait_for_pallet_beefy branch from 579c7de to b69e08a Compare January 5, 2026 12:08
@acatangiu
Copy link
Copy Markdown
Contributor

@serban300 @skunert please review

@acatangiu acatangiu added the T0-node This PR/Issue is related to the topic “node”. label Jan 5, 2026
github-merge-queue bot pushed a commit that referenced this pull request Jan 13, 2026
As a follow-up of the discussion
#8707 (comment),
I am extracting a missing forward call to a separate PR so we can
deliver it independently.

Context:
When keystore is used by some component (like BEEFY) via Arc, then calls
of `sign_with` function are forwarded to default trait implementation.
It is not working, when custom keystore with custom `sign_with`
implementation is used.
acatangiu pushed a commit to acatangiu/polkadot-sdk that referenced this pull request Jan 14, 2026
As a follow-up of the discussion
paritytech#8707 (comment),
I am extracting a missing forward call to a separate PR so we can
deliver it independently.

Context:
When keystore is used by some component (like BEEFY) via Arc, then calls
of `sign_with` function are forwarded to default trait implementation.
It is not working, when custom keystore with custom `sign_with`
implementation is used.
@serban300
Copy link
Copy Markdown
Contributor

#10763 was merged in master. Please update this PR

pull bot pushed a commit to AKJUS/polkadot-sdk that referenced this pull request Jan 29, 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`.
2. 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
paritytech#8707 (comment)

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@Klapeyron
Copy link
Copy Markdown
Contributor Author

Thank you @serban300, we are now happy with current state of master with your recent changes, I will close this PR. If you will be interested in this remaining part of the PR (MMR hasher adjustment), I can rebase and narrow it to this scope of changes

@Klapeyron Klapeyron closed this Feb 13, 2026
@serban300
Copy link
Copy Markdown
Contributor

Thank you @serban300, we are now happy with current state of master with your recent changes, I will close this PR. If you will be interested in this remaining part of the PR (MMR hasher adjustment), I can rebase and narrow it to this scope of changes

Nice, glad to hear that ! I'm good. Feel free to close.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T0-node This PR/Issue is related to the topic “node”.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants