Skip to content

refactor: set sender and senderEVM in Message context#3700

Merged
lumtis merged 9 commits intodevelopfrom
refactor-origin-address
Mar 18, 2025
Merged

refactor: set sender and senderEVM in Message context#3700
lumtis merged 9 commits intodevelopfrom
refactor-origin-address

Conversation

@lumtis
Copy link
Contributor

@lumtis lumtis commented Mar 12, 2025

Description

Closes #3689

Uses https://github.com/zeta-chain/protocol-contracts/pull/474

Modify tests to check the sender address in the message context

Summary by CodeRabbit

  • New Features
    • Added functionality to retrieve sender details alongside transaction messages.
  • Refactor
    • Improved consistency in how sender information is stored and displayed across cross-chain interactions.
  • Tests
    • Enhanced end-to-end testing with stricter version requirements and additional validation of sender data.
  • Chores
    • Upgraded protocol dependencies to ensure improved stability and performance.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 12, 2025

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

📝 Walkthrough

Walkthrough

This update introduces several changes to improve the clarity and functionality of cross-chain call message handling. The changelog now includes a refactor section, and multiple smart contracts (Example, TestDAppV2, and others) have been updated to rename parameters (e.g., origin to sender and sender to senderEVM), add new functions (e.g., lastSender, getSenderWithMessage, senderWithMessageZEVM), and adjust struct definitions. Additionally, numerous test cases and utility functions have been modified to include sender verification by passing extra parameters. Dependency versions and context types have also been updated accordingly.

Changes

File(s) Change Summary
changelog.md Added a new "Refactor" section with entry for PR [3700] for sender context refactoring.
e2e/contracts/example/Example.{abi,go,json,sol} Added lastSender method; renamed parameters (originsender; sendersenderEVM); updated struct definitions and state variables.
e2e/contracts/testdappv2/TestDAppV2.{abi,go,json,sol} Added getSenderWithMessage and senderWithMessageZEVM methods; renamed struct fields (originsender, sendersenderEVM, _contextcontext).
e2e/e2etests/**/* Updated calls to MustHaveCalledExampleContract and MustHaveCalledExampleContractWithMsg by adding a sender address parameter; modified tests to use the new parameters and return values.
e2e/runner/bitcoin.go and e2e/utils/contracts.go Updated function signatures to return/accept additional sender-related information (e.g., commit address and sender as byte slice).
go.mod Updated dependency version for github.com/zeta-chain/protocol-contracts.
x/fungible/keeper/{deposits.go,evm_gateway.go} Updated context type from systemcontract.ZContext to gatewayzevm.MessageContext and adjusted corresponding field values.

Sequence Diagram(s)

sequenceDiagram
    participant T as Test
    participant U as Utils (Validation)
    participant C as Smart Contract
    T->>U: Call MustHaveCalledExampleContract(..., sender)
    U->>C: Invoke contract.LastSender(&bind.CallOpts{})
    C-->>U: Return actual sender (bytes)
    U->>T: Validate expected sender matches actual sender
Loading

Suggested labels

breaking:cli, chain:bitcoin

Suggested reviewers

  • fbac
  • skosito
  • kingpinXD
  • gartnera
  • ws4charlie

🪧 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 generate docstrings to generate docstrings 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.

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.

@codecov
Copy link

codecov bot commented Mar 12, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 64.46%. Comparing base (4081338) to head (77cce0e).
Report is 2 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff            @@
##           develop    #3700   +/-   ##
========================================
  Coverage    64.46%   64.46%           
========================================
  Files          462      462           
  Lines        32699    32699           
========================================
  Hits         21080    21080           
  Misses       10657    10657           
  Partials       962      962           
Files with missing lines Coverage Δ
x/fungible/keeper/deposits.go 51.72% <100.00%> (ø)
x/fungible/keeper/evm_gateway.go 19.76% <ø> (ø)
🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@lumtis lumtis added UPGRADE_TESTS Run make start-upgrade-tests SOLANA_TESTS Run make start-solana-test TON_TESTS Runs TON E2E tests SUI_TESTS Run make start-sui-tests labels Mar 13, 2025
@lumtis lumtis marked this pull request as ready for review March 13, 2025 16:01
@lumtis lumtis requested a review from a team as a code owner March 13, 2025 16:01
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: 1

🧹 Nitpick comments (5)
e2e/contracts/testdappv2/TestDAppV2.sol (3)

89-90: Use cautious naming for two sender mappings.
Having two mappings (senderWithMessageZEVM and senderWithMessage) could introduce confusion. Consider clarifying naming or documenting the distinction to future maintainers.


113-115: Check internal write operations for error conditions.
setSenderWithMessage updates storage but does not revert on failure. Ensure that potential input issues (e.g., empty messages) are not inadvertently masked.


125-128: Validate payload usage in 'getSenderWithMessage'.
Ensure downstream code interprets the returned bytes correctly. If a known format (e.g., compressed addresses) is expected, add clear documentation to avoid confusion.

e2e/contracts/testdappv2/TestDAppV2.go (2)

442-458: Validate 'GetSenderWithMessage' output correctness.
Exposing the raw []byte can be beneficial for flexible usage. Consider clarifying usage of this data in docstrings if it expects an address, public key, or other format.


535-564: Enhance usage of 'SenderWithMessageZEVM'.
This function provides cross-chain metadata. Consider adding revert checks or data validation if any assumptions about the []byte format are crucial.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5bac6f9 and 21949f4.

⛔ Files ignored due to path filters (3)
  • e2e/contracts/example/Example.bin is excluded by !**/*.bin
  • e2e/contracts/testdappv2/TestDAppV2.bin is excluded by !**/*.bin
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (23)
  • changelog.md (1 hunks)
  • e2e/contracts/example/Example.abi (2 hunks)
  • e2e/contracts/example/Example.go (2 hunks)
  • e2e/contracts/example/Example.json (3 hunks)
  • e2e/contracts/example/Example.sol (2 hunks)
  • e2e/contracts/testdappv2/TestDAppV2.abi (4 hunks)
  • e2e/contracts/testdappv2/TestDAppV2.go (4 hunks)
  • e2e/contracts/testdappv2/TestDAppV2.json (5 hunks)
  • e2e/contracts/testdappv2/TestDAppV2.sol (5 hunks)
  • e2e/e2etests/e2etests.go (8 hunks)
  • e2e/e2etests/legacy/test_eth_deposit_call.go (1 hunks)
  • e2e/e2etests/test_bitcoin_deposit_call.go (1 hunks)
  • e2e/e2etests/test_bitcoin_std_deposit_and_call.go (1 hunks)
  • e2e/e2etests/test_bitcoin_std_memo_inscribed_deposit_and_call.go (2 hunks)
  • e2e/e2etests/test_solana_deposit_call.go (1 hunks)
  • e2e/e2etests/test_spl_deposit_and_call.go (1 hunks)
  • e2e/e2etests/test_sui_deposit_and_call.go (1 hunks)
  • e2e/e2etests/test_ton_deposit_and_call.go (1 hunks)
  • e2e/runner/bitcoin.go (2 hunks)
  • e2e/utils/contracts.go (4 hunks)
  • go.mod (1 hunks)
  • x/fungible/keeper/deposits.go (2 hunks)
  • x/fungible/keeper/evm_gateway.go (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.go`: Review the Go code, point out issues relative to ...

**/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

  • e2e/e2etests/test_bitcoin_deposit_call.go
  • e2e/e2etests/legacy/test_eth_deposit_call.go
  • e2e/e2etests/test_sui_deposit_and_call.go
  • e2e/e2etests/test_ton_deposit_and_call.go
  • e2e/e2etests/test_spl_deposit_and_call.go
  • x/fungible/keeper/deposits.go
  • e2e/e2etests/test_bitcoin_std_memo_inscribed_deposit_and_call.go
  • e2e/e2etests/test_solana_deposit_call.go
  • e2e/utils/contracts.go
  • e2e/e2etests/test_bitcoin_std_deposit_and_call.go
  • e2e/runner/bitcoin.go
  • x/fungible/keeper/evm_gateway.go
  • e2e/e2etests/e2etests.go
  • e2e/contracts/example/Example.go
  • e2e/contracts/testdappv2/TestDAppV2.go
🔇 Additional comments (46)
go.mod (1)

53-53: Dependency version updated correctly

The update to the github.com/zeta-chain/protocol-contracts dependency is correctly implemented, moving from the February version to a newer March release. This update aligns with the refactoring of the Message context to include both sender and senderEVM fields.

e2e/e2etests/test_bitcoin_deposit_call.go (1)

44-49: Function signature update correctly implemented

The function call to MustHaveCalledExampleContract has been properly updated to include the Bitcoin deployer address as an additional parameter. This change is consistent with the refactoring effort to provide sender information in the Message context for verification.

e2e/e2etests/legacy/test_eth_deposit_call.go (1)

58-58: Updated function call with appropriate EVM address parameter

The addition of r.EVMAddress().Bytes() as the fourth parameter to MustHaveCalledExampleContract is consistent with the refactoring efforts to include sender information in cross-chain call contexts. This ensures that the Ethereum address of the sender is properly passed for verification.

x/fungible/keeper/deposits.go (2)

11-12: Import correctly added for the new context

The addition of the gatewayzevm.sol package import is appropriate for the context structure changes being implemented.


105-109: Refactored Message context structure

The context structure has been properly updated from systemcontract.ZContext to gatewayzevm.MessageContext with appropriate field modifications:

  1. Removed the Origin field
  2. Changed Sender to use the raw bytes
  3. Added a new SenderEVM field that contains the bytes converted to an Ethereum address

This refactoring provides more clarity about the sender's identity across different blockchain environments, separating the raw bytes representation from the EVM-specific address format.

changelog.md (1)

15-17: Clear and well-formatted changelog entry

The new entry is properly formatted and provides a concise description of the changes made in PR #3700, following the established pattern in the changelog.

e2e/e2etests/test_ton_deposit_and_call.go (1)

49-49: Updated function call to include sender information

The function call has been properly updated to include the sender's address as a byte array parameter, aligning with the refactoring of sender context in cross-chain calls.

e2e/e2etests/test_bitcoin_std_deposit_and_call.go (1)

49-54: Improved function call with sender information

The function call has been updated to include the Bitcoin deployer address, and the formatting has been improved by breaking the call into multiple lines. This enhances both functionality and readability.

e2e/e2etests/test_sui_deposit_and_call.go (1)

41-49: Added sender verification for cross-chain calls

This code addition properly verifies that the sender address is correctly propagated through the cross-chain call mechanism. The implementation is clear with appropriate error handling and assertions.

e2e/contracts/example/Example.sol (3)

8-12: Good refactoring of the zContext struct.

The renaming from origin/sender to sender/senderEVM provides much clearer semantics about what these fields represent. This change makes the code more intuitive by correctly identifying the sender's address in bytes format and its EVM-compatible representation.


16-16: Good addition of lastSender field.

Adding this public variable complements the existing lastMessage field and allows tracking of the message sender, which is useful for verification purposes and improves the contract's observability.


55-55: Implementation correctly uses the renamed field.

The function now assigns context.sender to lastSender, which is consistent with the struct field renaming. This change properly maintains the contract's functionality while improving field naming clarity.

e2e/runner/bitcoin.go (2)

324-324: Enhanced function return signature.

Adding the receiver's encoded address to the return values improves function usability by providing critical information about the transaction destination without requiring callers to compute it separately.


365-365: Properly implemented the updated return signature.

The implementation now correctly returns the additional information (receiver's encoded address) as promised in the function signature. This maintains the contract with callers of this function.

e2e/contracts/example/Example.abi (2)

66-78: Good ABI update for the new lastSender function.

The ABI has been properly updated to include the new lastSender function, matching the contract implementation. The function signature is correctly defined with no inputs and a bytes output with view mutability.


85-86: Consistent parameter naming across ABI.

The parameter names have been updated from origin to sender and from sender to senderEVM in both function definitions, maintaining consistency with the contract implementation. This renaming provides better semantic clarity about the role of each parameter.

Also applies to: 90-91, 130-131, 135-136

e2e/e2etests/test_spl_deposit_and_call.go (1)

55-61: Updated test to include sender information.

The function call now includes the sender's public key as an additional parameter, which aligns with the contract changes where sender information is explicitly tracked. The multi-line format also improves readability.

e2e/e2etests/test_solana_deposit_call.go (1)

34-41: Updated function call to include sender verification.

The function call has been updated to include the Solana public key as a sender parameter, which aligns with the contract's new sender verification mechanism. This ensures that the example contract correctly records and verifies the origin of cross-chain calls.

e2e/contracts/example/Example.json (4)

67-79: New function added for sender verification.

The addition of the lastSender function provides a necessary mechanism to retrieve and verify the sender of cross-chain messages, enhancing security and traceability.


86-86: Renamed context fields for improved clarity.

The renaming of origin to sender and sender to senderEVM provides more precise terminology for cross-chain interactions, making the code more self-documenting and consistent with industry standards.

Also applies to: 91-91


131-131: Consistent renaming in all struct instances.

The consistent application of the field renaming across all struct instances ensures that the contract maintains a uniform interface, which is crucial for preventing confusion during development and maintenance.

Also applies to: 136-136


171-171: Updated binary representation reflects contract changes.

The binary has been regenerated to incorporate all the interface changes, which is necessary for proper contract deployment and interaction.

e2e/contracts/testdappv2/TestDAppV2.abi (3)

224-242: Added getSenderWithMessage function.

The new function allows retrieval of sender information with a string message parameter, enhancing the contract's ability to track and verify message origins in a user-friendly format.


262-262: Standardized naming convention in zContext struct.

The field name changes align with the same pattern applied to the Example contract, maintaining consistency across different contracts in the codebase.

Also applies to: 267-267, 277-277


386-404: Added senderWithMessageZEVM function.

This function provides a specialized method for working with sender information in the ZEVM context using bytes32 parameters, offering more flexibility for cross-chain interactions.

e2e/utils/contracts.go (2)

22-22: Added sender verification to MustHaveCalledExampleContract.

The function now accepts a sender parameter and verifies that the contract recorded the correct sender. This additional check strengthens the testing framework by ensuring that cross-chain messages are properly attributed to their originators.

Also applies to: 32-34


43-43: Added sender verification to MustHaveCalledExampleContractWithMsg.

Similar to the changes in MustHaveCalledExampleContract, this function now also verifies sender information, ensuring consistent verification behavior across different test scenarios.

Also applies to: 57-59

e2e/e2etests/test_bitcoin_std_memo_inscribed_deposit_and_call.go (2)

43-43: Function return value updated correctly.

The InscribeToTSSFromDeployerWithMemo now returns an additional commitAddress parameter, which is properly captured here. This aligns with the PR's purpose of including sender information in message contexts.


55-60: Sender verification added appropriately.

The MustHaveCalledExampleContract function now receives the commitAddress as an additional parameter, ensuring proper sender verification in cross-chain calls. This implementation correctly passes the commit address as a byte slice to validate that the example contract was called with the expected sender.

e2e/contracts/testdappv2/TestDAppV2.json (3)

225-243: New getSenderWithMessage function added correctly.

This new view function allows retrieving the sender associated with a given message. It returns a bytes value, providing a consistent way to verify sender information in cross-chain calls.


263-264: Improved naming convention for context fields.

The renaming of fields improves clarity:

  • originsender: More accurately reflects that this is the original sender
  • sendersenderEVM: Provides clarity that this is the EVM-formatted sender
  • _contextcontext: Removes unnecessary underscore prefix

These changes make the code more intuitive and align with standard naming conventions.

Also applies to: 268-269, 278-279


387-405: New senderWithMessageZEVM function added.

This view function provides a way to look up sender information by a bytes32 key in the ZEVM context. The byte return type allows for flexibility in encoding different address formats from various chains.

x/fungible/keeper/evm_gateway.go (2)

59-59: Updated context type to match protocol changes.

Changed parameter type from systemcontract.ZContext to gatewayzevm.MessageContext for the CallDepositAndCallZRC20 function. This aligns with the contract changes and maintains consistency throughout the codebase for handling message context.


112-112: Updated context type to match protocol changes.

Changed parameter type from systemcontract.ZContext to gatewayzevm.MessageContext for the CallExecute function. This matches the changes in the gateway contract and ensures consistency across the codebase.

e2e/e2etests/e2etests.go (1)

601-601: Version requirements updated for deposit-and-call tests.

All deposit-and-call tests now require runner version v30.0.0 or later. This is necessary because these tests now include sender verification functionality, which depends on the updated contract interfaces and test utilities.

The consistent version requirement across all chain implementations (Solana, SPL, TON, Sui, Bitcoin, and Ether) ensures compatibility with the refactored message context handling.

Also applies to: 678-678, 698-698, 741-741, 829-829, 866-866, 899-899, 1444-1444

e2e/contracts/example/Example.go (3)

34-36: Ensure consistent handling of changed sender type.
Renaming Sender to []byte and adding SenderEVM require all consumers and upstream code to handle the new sender representation consistently. Verify that calls to this struct in other files align with these changes.


41-42: Confirm ABI and Binary updates.
These updates to the ABI and Bin reflect the changes in the contract. Double-check that this metadata is correct by verifying with the compiled artifacts to prevent deployment or runtime mismatches.


274-304: Reviewed new 'LastSender' functionality.
The implementation to retrieve the last sender as []byte seems correct. It follows the standard pattern for a getter method, and the usage of abi.ConvertType is appropriately handled.

e2e/contracts/testdappv2/TestDAppV2.sol (4)

63-64: Revisit the struct to confirm cross-chain usage.
Switching sender from address to bytes and adding senderEVM is a sound approach for more flexible representation. Ensure that external calls or libraries expecting an address type do not break.


131-131: Reviewed parameter rename.
Renaming _context to context is straightforward and improves consistency. No concerns here.


140-140: Check fallback for empty messages.
When message.length == 0, the code uses context.senderEVM. Confirm that senderEVM is always valid in these scenarios to avoid potential default-zero addresses.


144-144: Inspirational approach to unify EVM and cross-chain sender.
Storing the custom sender bytes in senderWithMessageZEVM can facilitate advanced cross-chain logic. Just ensure no stale data accumulates to avoid storage bloat.

e2e/contracts/testdappv2/TestDAppV2.go (4)

47-49: Confirm contract struct alignment.
Changing Sender to []byte and adding SenderEVM must match the on-chain struct formation. Confirm any older code references are updated to avoid potential panics or type mismatches.


54-55: Cross-check updated ABI and Bin.
These updates must reflect the final compiled contract. Verify using a local build to ensure no drift in your build artifacts.


673-674: Ensure consistent usage of 'TestDAppV2zContext'.
When passing the context struct, confirm all fields are populated in a valid manner (basic or advanced cross-chain scenarios).


680-681: Confirm _zrc20 references.
As _zrc20 is mandatory in some cross-chain workflows, verify that blank or zero addresses do not lead to unexpected behaviors.

@lumtis lumtis added the CONSENSUS_BREAKING_ACK Acknowledge a consensus breaking change label Mar 18, 2025
@lumtis lumtis enabled auto-merge March 18, 2025 09:56
@lumtis lumtis added this pull request to the merge queue Mar 18, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Mar 18, 2025
@lumtis lumtis added this pull request to the merge queue Mar 18, 2025
Merged via the queue into develop with commit 2077c63 Mar 18, 2025
49 of 54 checks passed
@lumtis lumtis deleted the refactor-origin-address branch March 18, 2025 11:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CONSENSUS_BREAKING_ACK Acknowledge a consensus breaking change SOLANA_TESTS Run make start-solana-test SUI_TESTS Run make start-sui-tests TON_TESTS Runs TON E2E tests UPGRADE_TESTS Run make start-upgrade-tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Calls from Solana have incorrect sender address in message context

4 participants