Skip to content

Conversation

@aljo242
Copy link
Contributor

@aljo242 aljo242 commented Jun 10, 2025

need to add changelog

Summary by CodeRabbit

  • New Features
    • Added support for reconstructing public keys from key type and byte data for Ed25519 and Secp256k1.
  • Tests
    • Introduced comprehensive tests to verify public key reconstruction, error handling for invalid key types and lengths, and compatibility checks for supported key types.

@ironbird-prod
Copy link

ironbird-prod bot commented Jun 10, 2025

Ironbird - launch a network To use Ironbird, you can use the following commands:
  • /ironbird start OR /ironbird start --load-test-config= - Launch a testnet with the specified chain and load test configuration.
  • /ironbird chains - List of chain images that ironbird can use to spin-up testnet
  • /ironbird loadtests - List of load test modes that ironbird can run against testnet
Custom Load Test Configuration You can provide a custom load test configuration using the `--load-test-config=` flag:
/ironbird start cosmos --load-test-config={
  "block_gas_limit_target": 0.75,
  "num_of_blocks": 50,
  "msgs": [
    {"weight": 0.3, "type": "MsgSend"},
    {"weight": 0.3, "type": "MsgMultiSend"},
	{"weight": 0.4, "type": "MsgArr", "ContainedType": "MsgSend", "NumMsgs": 3300}
  ]
}

Use /ironbird loadtests to see more examples.

@github-actions

This comment has been minimized.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 10, 2025

📝 Walkthrough

Walkthrough

A new function, PubKeyFromTypeAndBytes, is added to the keys package to construct a public key from a key type string and byte slice, supporting Ed25519 and Secp256k1 types with validation. Comprehensive tests for this function are also introduced, covering valid, invalid, and unsupported key scenarios.

Changes

File(s) Change Summary
crypto/keys/convert.go Added PubKeyFromTypeAndBytes function to construct and validate public keys from type and bytes.
crypto/keys/convert_test.go Added tests for PubKeyFromTypeAndBytes, covering multiple key types, error cases, and validation.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant keys.PubKeyFromTypeAndBytes
    participant types.PubKey

    Caller->>keys.PubKeyFromTypeAndBytes: Call with pkType, bytes
    alt pkType is "ed25519" or "secp256k1"
        keys.PubKeyFromTypeAndBytes->>keys.PubKeyFromTypeAndBytes: Validate byte length
        alt Valid length
            keys.PubKeyFromTypeAndBytes->>types.PubKey: Construct PubKey object
            keys.PubKeyFromTypeAndBytes-->>Caller: Return PubKey
        else Invalid length
            keys.PubKeyFromTypeAndBytes-->>Caller: Return ErrInvalidKeyLen
        end
    else pkType unsupported
        keys.PubKeyFromTypeAndBytes-->>Caller: Return ErrUnsupportedKey
    end
Loading
✨ Finishing Touches
  • 📝 Generate Docstrings

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 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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Knowledge Base: Disabled due to Reviews > Disable Knowledge Base setting

📥 Commits

Reviewing files that changed from the base of the PR and between 1521447 and e5c72bb.

📒 Files selected for processing (2)
  • crypto/keys/convert.go (1 hunks)
  • crypto/keys/convert_test.go (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
crypto/keys/convert.go (2)
crypto/types/types.go (1)
  • PubKey (9-17)
crypto/keys/ed25519/ed25519.go (2)
  • KeyType (36-36)
  • PubKeySize (26-26)
⏰ Context from checks skipped due to timeout of 90000ms (17)
  • GitHub Check: test-system-legacy
  • GitHub Check: test-system
  • GitHub Check: tests (00)
  • GitHub Check: tests (01)
  • GitHub Check: tests (03)
  • GitHub Check: tests (02)
  • GitHub Check: test-e2e
  • GitHub Check: Check up to date mocks
  • GitHub Check: test-sim-nondeterminism
  • GitHub Check: Analyze
  • GitHub Check: test-integration
  • GitHub Check: build (arm64)
  • GitHub Check: golangci-lint
  • GitHub Check: build (amd64)
  • GitHub Check: dependency-review
  • GitHub Check: Gosec
  • GitHub Check: Summary
🔇 Additional comments (8)
crypto/keys/convert.go (3)

1-11: LGTM: Clean package structure and imports.

The package declaration and imports are well-organized and include all necessary dependencies for the conversion functionality.


13-16: LGTM: Clear function documentation and signature.

The function documentation clearly describes the purpose and error conditions. The signature appropriately takes a type string and byte slice, returning the interface type and error.


28-30: LGTM: Secure byte handling.

The implementation correctly creates new byte slices and copies the input data, preventing shared references that could lead to security issues.

Also applies to: 41-43

crypto/keys/convert_test.go (5)

1-14: LGTM: Comprehensive test imports and package structure.

The test package structure follows Go conventions, and imports include all necessary crypto types for thorough testing.


17-33: LGTM: Thorough ed25519 testing.

The test properly validates key reconstruction, equivalence checks, and error handling for invalid key lengths with appropriate error type assertions.


35-48: LGTM: Consistent secp256k1 testing pattern.

The secp256k1 testing follows the same comprehensive pattern as ed25519, ensuring consistency in validation.


71-73: LGTM: BLS limitation testing.

The test correctly verifies that BLS key generation fails as expected in the current configuration.


75-79: LGTM: Proper unsupported key type testing.

The test correctly validates error handling for unsupported key types with proper error type assertion.

Comment on lines +18 to +46
switch pkType {
case ed25519.KeyType:
if len(bytes) != ed25519.PubKeySize {
return nil, encoding.ErrInvalidKeyLen{
Key: pkType,
Got: len(bytes),
Want: ed25519.PubKeySize,
}
}

pk := make([]byte, ed25519.PubKeySize)
copy(pk, bytes)
pubKey = &cosmosed25519.PubKey{Key: pk}

case secp256k1.KeyType:
if len(bytes) != secp256k1.PubKeySize {
return nil, encoding.ErrInvalidKeyLen{
Key: pkType,
Got: len(bytes),
Want: secp256k1.PubKeySize,
}
}

pk := make([]byte, secp256k1.PubKeySize)
copy(pk, bytes)
pubKey = &cosmossecp256k1.PubKey{Key: pk}
default:
return nil, encoding.ErrUnsupportedKey{KeyType: pkType}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Critical Issue: Missing secp256k1eth support despite test expectations.

The function only handles ed25519 and secp256k1 key types, but the test file (convert_test.go lines 50-69) expects secp256k1eth support when enabled. This will cause test failures when secp256k1eth.Enabled is true.

Add support for secp256k1eth when enabled:

 	case secp256k1.KeyType:
 		if len(bytes) != secp256k1.PubKeySize {
 			return nil, encoding.ErrInvalidKeyLen{
 				Key:  pkType,
 				Got:  len(bytes),
 				Want: secp256k1.PubKeySize,
 			}
 		}

 		pk := make([]byte, secp256k1.PubKeySize)
 		copy(pk, bytes)
 		pubKey = &cosmossecp256k1.PubKey{Key: pk}
+	case secp256k1eth.KeyType:
+		if !secp256k1eth.Enabled {
+			return nil, encoding.ErrUnsupportedKey{KeyType: pkType}
+		}
+		if len(bytes) != secp256k1eth.PubKeySize {
+			return nil, encoding.ErrInvalidKeyLen{
+				Key:  pkType,
+				Got:  len(bytes),
+				Want: secp256k1eth.PubKeySize,
+			}
+		}
+
+		pk := make([]byte, secp256k1eth.PubKeySize)
+		copy(pk, bytes)
+		pubKey = &cosmossecp256k1.PubKey{Key: pk}
 	default:
 		return nil, encoding.ErrUnsupportedKey{KeyType: pkType}

You'll also need to add the import:

 import (
 	"github.com/cometbft/cometbft/v2/crypto/ed25519"
 	"github.com/cometbft/cometbft/v2/crypto/encoding"
 	"github.com/cometbft/cometbft/v2/crypto/secp256k1"
+	"github.com/cometbft/cometbft/v2/crypto/secp256k1eth"

 	cosmosed25519 "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
 	cosmossecp256k1 "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
 	"github.com/cosmos/cosmos-sdk/crypto/types"
 )

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In crypto/keys/convert.go lines 18 to 46, the switch statement handles only
ed25519 and secp256k1 key types but lacks support for secp256k1eth, which causes
test failures when secp256k1eth.Enabled is true. To fix this, add a case for
secp256k1eth.KeyType that checks the byte length against
secp256k1eth.PubKeySize, copies the bytes into a new slice, and assigns pubKey
to a new cosmossecp256k1eth.PubKey with the copied key. Also, add the necessary
import for the secp256k1eth package to enable this support.

Comment on lines 50 to 69
// --- secp256k1eth (optional) ---
if secp256k1eth.Enabled {
ethPriv := secp256k1eth.GenPrivKey()
ethPub := ethPriv.PubKey()

pk, err = keys.PubKeyFromTypeAndBytes(ethPub.Type(), ethPub.Bytes())
require.NoError(t, err)
require.Equal(t, ethPub.Type(), pk.Type())
require.Equal(t, ethPub.Bytes(), pk.Bytes())
require.Equal(t, ethPub.Address(), pk.Address())
require.Equal(t, ethPub.VerifySignature([]byte("msg"), []byte("sig")), pk.VerifySignature([]byte("msg"), []byte("sig")))

_, err = keys.PubKeyFromTypeAndBytes(ethPub.Type(), ethPub.Bytes()[:5])
require.Error(t, err)
require.ErrorAs(t, err, &invLen)
} else {
// should error if type known but not enabled
_, err := keys.PubKeyFromTypeAndBytes(secp256k1eth.KeyType, []byte{})
require.Error(t, err)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Test will fail: secp256k1eth not implemented in convert.go.

This test expects secp256k1eth support when enabled, but the PubKeyFromTypeAndBytes function in convert.go doesn't handle this key type, causing test failures.

This test segment will pass only after implementing secp256k1eth support in the conversion function as noted in the previous review comment.

🤖 Prompt for AI Agents
In crypto/keys/convert.go around the implementation of PubKeyFromTypeAndBytes,
the function currently lacks support for the secp256k1eth key type, causing the
test in convert_test.go lines 50 to 69 to fail when secp256k1eth is enabled. To
fix this, add handling logic for the secp256k1eth key type in
PubKeyFromTypeAndBytes so it correctly recognizes and processes keys of this
type, ensuring the test passes when secp256k1eth.Enabled is true.

@aljo242 aljo242 added this pull request to the merge queue Jun 10, 2025
@aljo242 aljo242 removed this pull request from the merge queue due to a manual request Jun 10, 2025
@aljo242 aljo242 enabled auto-merge June 10, 2025 17:10
@aljo242 aljo242 added this pull request to the merge queue Jun 10, 2025
Merged via the queue into main with commit b482ce4 Jun 10, 2025
40 checks passed
@aljo242 aljo242 deleted the feat/conv-function branch June 10, 2025 17:22
warpbuild-benchmark-bot bot added a commit to WarpBuilds/cosmos-sdk that referenced this pull request Jun 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants