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

refactor: SetCctxAndNonceToCctxAndInboundHashToCctx receive tsspubkey as an argument #2725

Closed
wants to merge 8 commits into from

Conversation

kingpinXD
Copy link
Contributor

@kingpinXD kingpinXD commented Aug 15, 2024

Description

  • This pr refactors the SetCctxAndNonceToCctxAndInboundHashToCctx to accept a tssPubkey instead of trying to fetch it.
    It does not modify any logic.

Closes #2719

How Has This Been Tested?

  • Tested CCTX in localnet
  • Tested in development environment
  • Go unit tests
  • Go integration tests
  • Tested via GitHub Actions

Summary by CodeRabbit

  • New Features

    • Enhanced handling of TSS (Threshold Signature Scheme) public keys for cross-chain operations, improving security and functionality in multiple methods.
  • Bug Fixes

    • Streamlined validation checks for TSS keys, ensuring more robust error handling when keys are absent during outbound transaction processing.
  • Tests

    • Added tests for scenarios involving missing TSS keys and updated existing tests to align with new method signatures that include the TSS public key.
  • Chores

    • Removed unnecessary mock setups to improve test clarity and maintainability.

Copy link
Contributor

coderabbitai bot commented Aug 15, 2024

Caution

Review failed

The pull request is closed.

Walkthrough

Walkthrough

This update introduces a significant refactor to enhance the handling of TSS (Threshold Signature Scheme) public keys within various functions. Key changes include the addition of new parameters to several methods, allowing for dynamic retrieval of public keys during cross-chain transaction processing. The refactor aims to improve security and functionality in how transactions are managed, while also refining testing strategies to align with the updated logic.

Changes

Files Changed Summary
changelog.md Added entry for refactor involving SetCctxAndNonceToCctxAndInboundHashToCctx, requiring tsspubkey.
testutil/keeper/crosschain.go Removed MockGetOutbound and altered mock setup for GetTSS in MockSaveOutbound.
x/crosschain/genesis.go Modified InitGenesis to incorporate TSS public key retrieval for transaction context management.
x/crosschain/keeper/cctx.go Updated SetCctxAndNonceToCctxAndInboundHashToCctx to include a tssFunc parameter for TSS key access.
x/crosschain/keeper/cctx_orchestrator_validate_inbound.go Enhanced ValidateInbound to pass TSS public key during context setup.
x/crosschain/keeper/cctx_orchestrator_validate_inbound_test.go Removed a test case covering validation errors for inbound transactions.
x/crosschain/keeper/cctx_test.go Added tssPubkey parameter to createNCctxWithStatus and createNCctx for TSS integration in tests.
x/crosschain/keeper/grpc_query_inbound_hash_to_cctx_test.go Changed signature of createInTxHashToCctxWithCctxs to include tssPubkey for enhanced transaction handling.
x/crosschain/keeper/msg_server_migrate_erc20_custody_funds.go Included TSS public key retrieval in MigrateERC20CustodyFunds.
x/crosschain/keeper/msg_server_migrate_tss_funds.go Enhanced initiateMigrateTSSFundsCCTX with inline TSS public key function parameter.
x/crosschain/keeper/msg_server_update_erc20_custody_pause_status.go Updated UpdateERC20CustodyPauseStatus to use TSS public key function parameter.
x/crosschain/keeper/msg_server_vote_outbound_tx.go Integrated TSS public key handling in VoteOutbound and related methods.
x/crosschain/keeper/msg_server_vote_outbound_tx_test.go Added test cases for TSS key absence and updated existing tests for new method signatures.
x/crosschain/keeper/msg_server_whitelist_erc20.go Modified WhitelistERC20 to retrieve TSS public key dynamically during execution.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant MsgServer
    participant Keeper
    participant TSS

    User->>MsgServer: Initiate transaction
    MsgServer->>Keeper: Validate transaction with TSS key
    Keeper->>TSS: Retrieve TSS public key
    TSS-->>Keeper: Return TSS public key
    Keeper-->>MsgServer: Process transaction with TSS key
    MsgServer-->>User: Confirm transaction
Loading

Assessment against linked issues

Objective Addressed Explanation
Unhandled error may result in incorrect query results for rate limiting (2719)
Improve handling of TSS keys in outbound transactions (2719)
Ensure error handling for missing TSS keys (2719)
Streamline mock setups for tests related to TSS (2719) Some redundant mock setups remain.
Validate that cross-chain transactions properly utilize TSS keys (2719)

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

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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.

Comment on lines +45 to +52
tss, found := k.GetObserverKeeper().GetTSS(ctx)
if found {
for _, elem := range genState.CrossChainTxs {
if elem != nil {
k.SetCctxAndNonceToCctxAndInboundHashToCctx(ctx, *elem, func(ctx sdk.Context) string {
return tss.TssPubkey
})
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Trying to retain older behaviour , but I feel we should use
elem.GetCurrentOutboundParam().TssPubkey instead of trying to fetch the current tss.

the cctxs in the genstate would already have been created using the existing tss

Copy link

gitguardian bot commented Aug 16, 2024

⚠️ GitGuardian has uncovered 3 secrets following the scan of your pull request.

Please consider investigating the findings and remediating the incidents. Failure to do so may lead to compromising the associated services or software components.

🔎 Detected hardcoded secrets in your pull request
GitGuardian id GitGuardian status Secret Commit Filename
13340122 Triggered Generic High Entropy Secret d6ea2df zetaclient/chains/solana/signer/signer_test.go View secret
13340122 Triggered Generic High Entropy Secret d6ea2df zetaclient/chains/solana/signer/signer_test.go View secret
13392123 Triggered Generic High Entropy Secret d6ea2df zetaclient/chains/solana/signer/signer_test.go View secret
🛠 Guidelines to remediate hardcoded secrets
  1. Understand the implications of revoking this secret by investigating where it is used in your code.
  2. Replace and store your secret safely. Learn here the best practices.
  3. Revoke and rotate this secret.
  4. If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.

To avoid such incidents in the future consider


🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

Copy link

codecov bot commented Aug 16, 2024

Codecov Report

Attention: Patch coverage is 84.61538% with 6 lines in your changes missing coverage. Please review.

Project coverage is 71.23%. Comparing base (a4c1b18) to head (a35599c).
Report is 4 commits behind head on develop.

Files Patch % Lines
x/crosschain/genesis.go 14.28% 5 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #2725      +/-   ##
===========================================
- Coverage    71.25%   71.23%   -0.03%     
===========================================
  Files          351      351              
  Lines        18982    18996      +14     
===========================================
+ Hits         13525    13531       +6     
- Misses        4853     4859       +6     
- Partials       604      606       +2     
Files Coverage Δ
x/crosschain/keeper/cctx.go 94.23% <100.00%> (-0.22%) ⬇️
...chain/keeper/cctx_orchestrator_validate_inbound.go 92.30% <100.00%> (+0.30%) ⬆️
...n/keeper/msg_server_migrate_erc20_custody_funds.go 96.77% <100.00%> (+0.10%) ⬆️
.../crosschain/keeper/msg_server_migrate_tss_funds.go 87.67% <100.00%> (+0.34%) ⬆️
...er/msg_server_update_erc20_custody_pause_status.go 96.61% <100.00%> (+0.11%) ⬆️
x/crosschain/keeper/msg_server_vote_outbound_tx.go 90.32% <100.00%> (-1.99%) ⬇️
x/crosschain/keeper/msg_server_whitelist_erc20.go 70.27% <100.00%> (+0.54%) ⬆️
x/crosschain/genesis.go 81.63% <14.28%> (-11.71%) ⬇️

@kingpinXD kingpinXD marked this pull request as ready for review August 19, 2024 19:21
@kingpinXD kingpinXD closed this Aug 19, 2024
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.

zetacore : Unhandled error may result in incorrect query results for rate limiting and queries
1 participant