Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

fix tsnonce preventing multisignature bug #2453

Merged
merged 1 commit into from
Oct 3, 2024
Merged

Conversation

jerryfan01234
Copy link
Contributor

@jerryfan01234 jerryfan01234 commented Oct 3, 2024

Changelist

in AnteHandle seq number is checked if it is a ts nonce via

	if isTimestampNonce, err = accountplusante.IsTimestampNonceTx(ctx, tx); err != nil {
		return ctx, err
	}

However, IsTimestampNonce would return an error if len(signatures) != 1, causing AnteHandle to early return. Hence, multisignature would not be possible. This PR fixes the bug.

Test Plan

[Describe how this PR was tested (if applicable)]

Author/Reviewer Checklist

  • If this PR has changes that result in a different app state given the same prior state and transaction list, manually add the state-breaking label.
  • If the PR has breaking postgres changes to the indexer add the indexer-postgres-breaking label.
  • If this PR isn't state-breaking but has changes that modify behavior in PrepareProposal or ProcessProposal, manually add the label proposal-breaking.
  • If this PR is one of many that implement a specific feature, manually label them all feature:[feature-name].
  • If you wish to for mergify-bot to automatically create a PR to backport your change to a release branch, manually add the label backport/[branch-name].
  • Manually add any of the following labels: refactor, chore, bug.

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced logic for timestamp nonce transactions, allowing multiple signatures while preventing timestamp nonces.
    • Updated test cases to align with new expectations for multisignature scenarios, ensuring accurate validation outcomes.

@jerryfan01234 jerryfan01234 requested a review from a team as a code owner October 3, 2024 16:31
Copy link
Contributor

coderabbitai bot commented Oct 3, 2024

Walkthrough

The changes involve a modification to the IsTimestampNonceTx function in the ante package of the protocol. The function's logic has been updated to allow multiple signatures while ensuring that none can be timestamp nonces. It checks for more than one signature, iterating through them to verify compliance, and returns true only if there is exactly one timestamp nonce. The test cases for this function have also been updated to reflect the new expected behavior.

Changes

File Path Change Summary
protocol/x/accountplus/ante/timestampnonce.go Updated IsTimestampNonceTx to allow multiple signatures and validate against timestamp nonces.
protocol/x/accountplus/ante/timestampnonce_test.go Modified TestIsTimestampNonceTx to update expected outcomes for test cases regarding multiple signatures.

Possibly related PRs

Suggested labels

feature:timestamp_nonce

Suggested reviewers

  • roy-dydx
  • teddyding

🐰 In the code where logic flows,
A single check for nonce now glows.
With signatures counted, clear and bright,
The function hops with pure delight!
Streamlined paths, no more confusion,
Just one return, a swift conclusion! 🌟


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 4eee507 and c8bd668.

📒 Files selected for processing (2)
  • protocol/x/accountplus/ante/timestampnonce.go (1 hunks)
  • protocol/x/accountplus/ante/timestampnonce_test.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • protocol/x/accountplus/ante/timestampnonce.go
  • protocol/x/accountplus/ante/timestampnonce_test.go

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>, please review it.
    • 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 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 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.

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

🧹 Outside diff range and nitpick comments (1)
protocol/x/accountplus/ante/timestampnonce.go (1)

22-22: LGTM! Bug fix for multisignature transactions.

This change successfully addresses the issue of multisignature transactions being blocked. The new implementation correctly identifies single-signature timestamp nonce transactions while allowing other types (including multisig) to proceed.

Consider renaming the function for clarity.

The current function name IsTimestampNonceTx might be slightly misleading, as it now returns false for multisig timestamp nonce transactions. Consider renaming it to IsSingleSignatureTimestampNonceTx or similar to more accurately reflect its behavior.

Suggestion: Add debug logging for multisignature cases.

For improved observability, consider adding debug logging when encountering multisignature transactions. This could help with monitoring and debugging in production environments.

Here's a suggested implementation:

 func IsTimestampNonceTx(ctx sdk.Context, tx sdk.Tx) (bool, error) {
 	sigTx, ok := tx.(authsigning.SigVerifiableTx)
 	if !ok {
 		return false, errorsmod.Wrap(sdkerrors.ErrTxDecode, "invalid transaction type")
 	}
 	signatures, err := sigTx.GetSignaturesV2()
 	if err != nil {
 		return false, err
 	}
-	return len(signatures) == 1 && accountpluskeeper.IsTimestampNonce(signatures[0].Sequence), nil
+	if len(signatures) > 1 {
+		ctx.Logger().Debug("Multisignature transaction detected", "num_signatures", len(signatures))
+		return false, nil
+	}
+	return len(signatures) == 1 && accountpluskeeper.IsTimestampNonce(signatures[0].Sequence), nil
 }

This change adds logging for multisignature transactions without altering the function's behavior.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 8fdf8c5 and e48ba7f.

📒 Files selected for processing (1)
  • protocol/x/accountplus/ante/timestampnonce.go (1 hunks)

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

🧹 Outside diff range and nitpick comments (2)
protocol/x/accountplus/ante/timestampnonce_test.go (2)

35-38: Approved: Test case updated to reflect new behavior for multisignature transactions.

The changes in this test case align with the PR objectives of fixing the bug that prevented processing of multisignature transactions. The test now expects IsTimestampNonceTx to return false without an error for transactions with more than one signature, allowing them to be processed further in the AnteHandle function.

Consider adding the following test cases to ensure comprehensive coverage:

  1. A test case with exactly two signatures, both being timestamp nonces.
  2. A test case with multiple signatures, where only some are timestamp nonces.
  3. A test case with the maximum allowed number of signatures in a transaction.

These additional test cases will help verify the function's behavior across various multisignature scenarios.


Line range hint 1-90: Overall impact: Test function updated correctly, minor improvement suggested.

The changes to the TestIsTimestampNonceTx function effectively address the multisignature transaction issue while maintaining coverage for other scenarios. This approach ensures that the IsTimestampNonceTx function now correctly handles all types of transactions as per the PR objectives.

Consider updating the error handling in the test function to provide more specific assertions:

 if tc.expectedErr {
-    require.NotNil(t, err)
+    require.Error(t, err)
+} else {
+    require.NoError(t, err)
 }

This change will make the test more explicit about the expected error behavior and will catch any unexpected errors in the non-error cases.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between e48ba7f and 4eee507.

📒 Files selected for processing (2)
  • protocol/x/accountplus/ante/timestampnonce.go (1 hunks)
  • protocol/x/accountplus/ante/timestampnonce_test.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • protocol/x/accountplus/ante/timestampnonce.go
🔇 Additional comments (1)
protocol/x/accountplus/ante/timestampnonce_test.go (1)

Line range hint 1-90: Summary: Changes address the multisignature issue effectively.

The modifications to the TestIsTimestampNonceTx function successfully update the test expectations to align with the new behavior of allowing multisignature transactions. The changes are focused, maintain existing test coverage, and correctly implement the fix described in the PR objectives.

To ensure that these changes are consistent with the implementation, please run the following script to verify the IsTimestampNonceTx function:

This script will help confirm that the implementation matches the updated test expectations and that there are no remaining error returns related to multiple signatures.

✅ Verification successful

Verification Successful: IsTimestampNonceTx handles multiple signatures correctly.

The IsTimestampNonceTx function correctly returns false when multiple signatures are present, aligning with the test cases. The implementation ensures that only transactions with a single timestamp nonce signature are considered valid, and additional signatures result in the expected false outcome without errors.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation of IsTimestampNonceTx function

# Test: Search for the IsTimestampNonceTx function implementation
ast-grep --lang go --pattern $'func IsTimestampNonceTx($_, $_) (bool, error) {
  $$$
}'

# Test: Check for any remaining error returns related to multiple signatures
rg --type go 'return false, .*more than one signature' -A 5 -B 5

Length of output: 1086


Script:

#!/bin/bash
# Description: Inspect handling of multiple signatures in IsTimestampNonceTx function

# Search for logic that handles cases with more than one signature
ast-grep --lang go --pattern $'func IsTimestampNonceTx($_, $_) (bool, error) {
  $$$
  if len(signatures) > 1 {
    $$$
  }
  $$$
}'

# Additionally, check for any conditional statements that might bypass the len(signatures) == 1 check
rg --type go 'if .*len\(signatures\) > 1' -A 5 -B 5

Length of output: 187

@jerryfan01234 jerryfan01234 merged commit 77cef30 into main Oct 3, 2024
22 checks passed
@jerryfan01234 jerryfan01234 deleted the tsnonce_audit branch October 3, 2024 20:28
@jerryfan01234
Copy link
Contributor Author

@Mergifyio backport release/protocol/v7.x

Copy link
Contributor

mergify bot commented Oct 3, 2024

backport release/protocol/v7.x

✅ Backports have been created

mergify bot pushed a commit that referenced this pull request Oct 3, 2024
jerryfan01234 added a commit that referenced this pull request Oct 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

2 participants