Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat: allow signerless account registration #16

Merged
merged 1 commit into from
Aug 29, 2024

Conversation

johnletey
Copy link
Member

@johnletey johnletey commented Aug 6, 2024

Summary by CodeRabbit

  • New Features

    • Users can now register accounts with a balance without needing a signer, streamlining the registration process.
    • A new CLI command allows for signerless registration of forwarding accounts, enhancing usability.
  • Enhancements

    • Improved transaction validation ensures only accounts with sufficient balances can proceed.
    • A new public key type, ForwardingPubKey, has been introduced for better cryptographic operations and identity verification.
  • Bug Fixes

    • The account registration logic now allows accounts with matching public keys to be registered, preventing unnecessary errors.

@johnletey johnletey added this to the v1.2.0 milestone Aug 6, 2024
@johnletey johnletey self-assigned this Aug 6, 2024
Copy link

coderabbitai bot commented Aug 6, 2024

Walkthrough

The changes introduce a new feature allowing accounts with a balance to be registered without requiring a signer. This includes the addition of a ForwardingPubKey message to the protocol, enhancements in signature verification logic, a new CLI command for signerless account registration, and modifications to account registration logic to accommodate existing accounts with matching public keys. These updates enhance transaction processing and account management capabilities.

Changes

Files Change Summary
.changelog/unreleased/features/17-signerless-registration.md New feature enabling accounts with a balance to be registered without a signer.
proto/noble/forwarding/v1/account.proto Introduced ForwardingPubKey message with a bytes field for structured public key representation.
x/forwarding/ante.go Added SigVerificationGasConsumer for new public key type and SigVerificationDecorator for enhanced transaction validation.
x/forwarding/client/cli/tx.go Added TxRegisterAccountSignerlessly command for registering accounts without a signer.
x/forwarding/keeper/msg_server.go Modified RegisterAccount logic to allow registration of existing accounts with matching public keys.
x/forwarding/types/account.go Introduced ForwardingPubKey type implementing cryptotypes.PubKey interface with several methods.
x/forwarding/types/codec.go Registered ForwardingPubKey implementation within the interface registry.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CLI
    participant Keeper
    participant BankKeeper

    User->>CLI: Register Account Signerlessly
    CLI->>Keeper: Create MsgRegisterAccount
    Keeper->>BankKeeper: Check Account Balance
    BankKeeper-->>Keeper: Return Balance
    Keeper-->>CLI: Account Registered Successfully
Loading

🐇 In a world of code, I hop with glee,
New accounts can join, oh so freely!
No signer needed, just balance in hand,
A leap towards ease, oh isn’t it grand?
With keys that forward, we dance and play,
In the land of transactions, hip-hip-hooray! 🥕✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • 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 generate unit testing code for this file.
    • @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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @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.

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

@johnletey johnletey marked this pull request as ready for review August 29, 2024 09:00
@johnletey johnletey requested a review from g-luca August 29, 2024 09:00
@johnletey
Copy link
Member Author

@coderabbitai review

Copy link

coderabbitai bot commented Aug 29, 2024

Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

@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: 0

Outside diff range, codebase verification and nitpick comments (4)
x/forwarding/ante.go (4)

130-139: Add documentation for the function.

The function is correctly implemented, but it lacks documentation. Consider adding a docstring to explain the purpose and behavior of the function.

+// SigVerificationGasConsumer handles signature verification for ForwardingPubKey and delegates to the default gas consumer for other types.
 func SigVerificationGasConsumer(
 	meter storetypes.GasMeter, sig signing.SignatureV2, params authtypes.Params,
 ) error {
 	switch sig.PubKey.(type) {
 	case *types.ForwardingPubKey:
 		return nil
 	default:
 		return ante.DefaultSigVerificationGasConsumer(meter, sig, params)
 	}
 }

143-146: Add documentation for the struct.

The struct is correctly implemented, but it lacks documentation. Consider adding a docstring to explain the purpose and behavior of the struct.

+// SigVerificationDecorator wraps an existing signature verification decorator and incorporates a bank keeper.
 type SigVerificationDecorator struct {
 	underlying ante.SigVerificationDecorator
 	bank       types.BankKeeper
 }

150-155: Add documentation for the function.

The function is correctly implemented, but it lacks documentation. Consider adding a docstring to explain the purpose and behavior of the function.

+// NewSigVerificationDecorator instantiates the SigVerificationDecorator.
 func NewSigVerificationDecorator(ak ante.AccountKeeper, bk types.BankKeeper, signModeHandler authsigning.SignModeHandler) SigVerificationDecorator {
 	return SigVerificationDecorator{
 		underlying: ante.NewSigVerificationDecorator(ak, signModeHandler),
 		bank:       bk,
 	}
 }

157-175: Add documentation and improve error handling.

The function is correctly implemented, but it lacks documentation. Additionally, the logic for handling MsgRegisterAccount could benefit from improved error handling. Consider adding a docstring to explain the purpose and behavior of the function and improving error handling for MsgRegisterAccount.

+// AnteHandle handles the transaction validation process for SigVerificationDecorator.
 func (d SigVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) {
 	if msgs := tx.GetMsgs(); len(msgs) == 1 {
 		msg, ok := msgs[0].(*types.MsgRegisterAccount)
 		if !ok {
 			return d.underlying.AnteHandle(ctx, tx, simulate, next)
 		}

 		address := types.GenerateAddress(msg.Channel, msg.Recipient)
 		balance := d.bank.GetAllBalances(ctx, address)

 		if balance.IsZero() || msg.Signer != address.String() {
-			return d.underlying.AnteHandle(ctx, tx, simulate, next)
+			return ctx, fmt.Errorf("invalid MsgRegisterAccount message: insufficient balance or incorrect signer")
 		}

 		return next(ctx, tx, simulate)
 	}

 	return d.underlying.AnteHandle(ctx, tx, simulate, next)
 }
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between dd5f499 and 56acfa2.

Files ignored due to path filters (1)
  • x/forwarding/types/account.pb.go is excluded by !**/*.pb.go
Files selected for processing (7)
  • .changelog/unreleased/features/17-signerless-registration.md (1 hunks)
  • proto/noble/forwarding/v1/account.proto (1 hunks)
  • x/forwarding/ante.go (2 hunks)
  • x/forwarding/client/cli/tx.go (3 hunks)
  • x/forwarding/keeper/msg_server.go (1 hunks)
  • x/forwarding/types/account.go (2 hunks)
  • x/forwarding/types/codec.go (2 hunks)
Additional comments not posted (13)
.changelog/unreleased/features/17-signerless-registration.md (1)

1-1: LGTM!

The changelog entry is concise and correctly formatted.

proto/noble/forwarding/v1/account.proto (1)

17-22: LGTM!

The ForwardingPubKey message is well-defined and the gogoproto_stringer option is correctly set to false.

x/forwarding/types/codec.go (1)

31-31: LGTM!

The ForwardingPubKey type is correctly registered as an implementation of the cryptotypes.PubKey interface.

x/forwarding/types/account.go (7)

38-38: LGTM!

The variable assertion correctly ensures that ForwardingPubKey satisfies the cryptotypes.PubKey interface.


40-42: LGTM!

The String method is correctly implemented and follows best practices.


44-44: LGTM!

The Address method is correctly implemented and follows best practices.


46-46: LGTM!

The Bytes method is correctly implemented and follows best practices.


48-50: LGTM!

The VerifySignature method is correctly implemented to indicate that signature verification is not applicable for this type.


52-58: LGTM!

The Equals method is correctly implemented and follows best practices.


60-60: LGTM!

The Type method is correctly implemented and follows best practices.

x/forwarding/keeper/msg_server.go (1)

32-34: LGTM!

The modified logic is correctly implemented and enhances the functionality of the account registration process.

x/forwarding/client/cli/tx.go (1)

53-116: LGTM!

The new command TxRegisterAccountSignerlessly is correctly implemented and follows best practices.

x/forwarding/ante.go (1)

6-11: LGTM!

The import statements are necessary for the new functionality.

@johnletey johnletey merged commit 6bfe328 into v1.x Aug 29, 2024
1 check passed
@johnletey johnletey deleted the signerless-registration branch August 29, 2024 17:42
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants