cosmos-sdk icon indicating copy to clipboard operation
cosmos-sdk copied to clipboard

feat: port bls12381 from v0.52.rc2

Open simonzg opened this issue 5 months ago • 8 comments

Port the support for BLS 12381 key in cli init, gentx, collect-gentx

Summary by CodeRabbit

  • New Features
    • Added support for BLS12-381 cryptographic keys, enabling their use for validator consensus keys.
    • Users can now specify the consensus key algorithm (e.g., Ed25519 or BLS12-381) during node initialization and testnet setup via command-line flags.
  • Bug Fixes
    • Improved error handling when specifying unsupported key types or using mnemonics with BLS12-381 keys.
  • Documentation
    • Updated documentation and flag descriptions to reflect new consensus key algorithm options.
  • Tests
    • Updated tests to accommodate the new consensus key algorithm parameter.

simonzg avatar Jun 12 '25 23:06 simonzg

📝 Walkthrough

Walkthrough

The changes introduce support for BLS12-381 cryptographic keys throughout the codebase. This includes adding BLS12-381 key types to key generation, encoding/decoding, interface registration, and multisig handling. The node validator initialization functions and related CLI commands are updated to accept a key type parameter, enabling explicit selection of consensus key algorithms during initialization and testing.

Changes

Files/Paths Change Summary
crypto/codec/amino.go, crypto/codec/proto.go Registered BLS12-381 public/private keys with Amino and protobuf interface registries.
crypto/codec/cmt.go Added BLS12-381 public key support in Tendermint protobuf <-> SDK conversion functions.
crypto/hd/algo.go Added Bls12_381Type constant for the BLS12-381 key type.
crypto/keys/bls12_381/key.go, key_cgo.go Introduced BLS12-381 key wrappers implementing Cosmos SDK cryptographic interfaces; provided both stub and CGO-enabled versions.
crypto/keys/multisig/codec.go Registered BLS12-381 public key type with multisig Amino codec.
simapp/simd/cmd/testnet.go Passed key algorithm argument to node validator file initialization.
testutil/network/network.go Explicitly specified ed25519 key type in node validator file initialization.
x/genutil/client/cli/collect.go, gentx.go, init.go CLI commands now retrieve and pass consensus key algorithm to initialization functions.
x/genutil/client/cli/init_test.go Updated test to provide explicit key type argument ("ed25519") to initialization function.
x/genutil/utils.go Updated initialization functions to accept key type parameter and support BLS12-381 key generation and handling.

Sequence Diagram(s)

sequenceDiagram
    participant CLI/User
    participant CLI_Command
    participant GenUtil
    participant CryptoKeys

    CLI/User->>CLI_Command: Run collect/gentx/init command (with --consensus-key-algo)
    CLI_Command->>GenUtil: InitializeNodeValidatorFiles(config, keyType)
    alt keyType == "ed25519"
        GenUtil->>CryptoKeys: Generate Ed25519 key
    else keyType == "bls12_381"
        GenUtil->>CryptoKeys: Generate BLS12-381 key
    end
    CryptoKeys-->>GenUtil: Return PrivKey, PubKey
    GenUtil-->>CLI_Command: Return nodeID, PubKey
    CLI_Command-->>CLI/User: Output result
sequenceDiagram
    participant Codec
    participant Registry
    participant BLS12_381Key

    Codec->>Registry: Register BLS12-381 PubKey/PrivKey types
    Registry->>BLS12_381Key: Recognize BLS12-381 key types for encoding/decoding
    BLS12_381Key-->>Registry: Provide implementation for cryptotypes interfaces
✨ Finishing Touches
  • [ ] 📝 Generate Docstrings
🧪 Generate Unit Tests
  • [ ] Create PR with Unit Tests
  • [ ] Commit Unit Tests in branch main
  • [ ] Post Copyable Unit Tests in Comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

‼️ IMPORTANT Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai auto-generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

coderabbitai[bot] avatar Jun 12 '25 23:06 coderabbitai[bot]

@simonzg could we get a CHANGELOG entry for this too?

aljo242 avatar Jun 13 '25 13:06 aljo242

where should I put the CHANGELOG entry ? Most of my modifications are in x/genutil, maybe I should create a CHANGELOG.md there?

simonzg avatar Jun 13 '25 17:06 simonzg

where should I put the CHANGELOG entry ? Most of my modifications are in x/genutil, maybe I should create a CHANGELOG.md there?

where should I put the CHANGELOG entry ? Most of my modifications are in x/genutil, maybe I should create a CHANGELOG.md there?

Its good to just have it in the root ./CHANGELOG file

aljo242 avatar Jun 13 '25 19:06 aljo242

One more nit:

InitializeNodeValidatorFilesFromMnemonic should call InitializeNodeValidatorFilesFromMnemonicWithKeyType with the keytype arg as ed25519

aljo242 avatar Jun 13 '25 19:06 aljo242

This is good stuff! Nice work.

faddat avatar Jun 14 '25 21:06 faddat

@simozg

need to run make lint-fix and there is a failing test

aljo242 avatar Jun 16 '25 16:06 aljo242

lint-fix is done. The failed test case was TestInitializeNodeValidatorFilesFromMnemonicWithBLS, this test case only works when bls12381 tag exists. I've commented out this test case for now. Let me know if there's a better way of doing this. @aljo242

simonzg avatar Jun 16 '25 22:06 simonzg

could we also get support for this key type with the sdk.AccAddress Interface?

This would enable aggregated key authorization for a single account on-chain, ~~and with ADR-032, would allow for key rotation.~~

I have a proof of concept implemented in a sdk fork here: https://github.com/permissionlessweb/cosmos-sdk/tree/v0.0.70

hard-nett avatar Jun 25 '25 01:06 hard-nett

@simonzg what do you think about adding what @hard-nett suggested?

aljo242 avatar Jul 01 '25 16:07 aljo242

@simonzg what do you think about adding what @hard-nett suggested?

To be honest, I'm not sure how I should merge that specifically.

simonzg avatar Jul 09 '25 20:07 simonzg