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: renaming origin and sender in MessageContext #474

Merged
merged 5 commits into from
Mar 18, 2025

Conversation

lumtis
Copy link
Member

@lumtis lumtis commented Mar 12, 2025

Changes in smart contract discussed from zeta-chain/node#3689

These changes are aimed to be backward compatible, keep same signature, but rename the field for refactoring in the chain.

origin was initially intended to be set from tx.origin and represent the signer address on each non-EVM chains but the field has never been used.

Summary by CodeRabbit

  • New Features
    • Enhanced cross-chain transaction support with dual sender identification, providing better interoperability between varied network types.
    • Expanded list of accepted symbols and updated supported chain names, improving flexibility in parameter usage.
  • Refactor
    • Updated event logging to clearly capture sender information, improving transparency during cross-chain interactions.

Copy link
Contributor

coderabbitai bot commented Mar 12, 2025

📝 Walkthrough

Walkthrough

The changes update the cross-chain interaction interface by replacing the old zContext struct with a new MessageContext struct. The new struct now includes a chain-agnostic bytes sender and an additional address senderEVM field specifically for EVM chains. The UniversalContract interface has been modified to use the updated onCall method with the new context parameter. Additionally, tests and event logs have been updated to reflect these changes by removing deprecated parameters and properly initializing the new fields.

Changes

File(s) Change Summary
contracts/zevm/interfaces/UniversalContract.sol Replaced zContext with MessageContext including new bytes sender and address senderEVM fields; updated onCrossChainCall to onCall using the new struct; enhanced comments.
test/GatewayZEVM.t.sol Updated test initializations by removing the origin field and adding senderEVM when initializing MessageContext across multiple test functions.
test/utils/TestUniversalContract.sol Modified the ContextData event: removed the origin parameter and added senderEVM, updating the event log to incorporate the new MessageContext data.
lib/types.ts Updated ParamSymbol to include "SUI.SUI" and "USDC.ARBSEP"; changed ParamChainName to replace "solana_devnet" with "sui_testnet".

Possibly related issues

Possibly related PRs

  • refactor: move v1 contracts still used to v2 directory #447: The changes in the main PR are related to the modifications of the MessageContext struct and the UniversalContract interface, which are also reflected in the test functions of the retrieved PR.
  • refactor: port ZRC20 contract to v2 #281: The changes in the main PR, which involve the introduction and modification of the MessageContext struct and the UniversalContract interface, are related to the updates in the retrieved PR that also modify the contract's context handling.
  • test: connector and revert unit tests #244: The changes in the main PR, which involve modifications to the MessageContext struct and the UniversalContract interface, are directly related to the updates made in the GatewayZEVMOutboundTest contract in the retrieved PR.

Suggested reviewers

  • fadeev
  • CharlieMc0
  • andresaiello
  • brewmaster012
  • skosito

Tip

⚡🧪 Multi-step agentic review comment chat (experimental)
  • We're introducing multi-step agentic chat in review comments. This experimental feature enhances review discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments.
    - To enable this feature, set early_access to true under in the settings.

📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between eee8553 and ddd74ab.

⛔ Files ignored due to path filters (13)
  • data/addresses.testnet.json is excluded by !data/**
  • pkg/gatewayevmzevm.t.sol/gatewayevmzevmtest.go is excluded by !pkg/**
  • pkg/gatewayzevm.sol/gatewayzevm.go is excluded by !pkg/**
  • pkg/gatewayzevm.t.sol/gatewayzevminboundtest.go is excluded by !pkg/**
  • pkg/gatewayzevm.t.sol/gatewayzevmoutboundtest.go is excluded by !pkg/**
  • pkg/gatewayzevmupgradetest.sol/gatewayzevmupgradetest.go is excluded by !pkg/**
  • pkg/igatewayzevm.sol/igatewayzevm.go is excluded by !pkg/**
  • pkg/senderzevm.sol/senderzevm.go is excluded by !pkg/**
  • pkg/zrc20.t.sol/zrc20test.go is excluded by !pkg/**
  • types/factories/GatewayZEVMUpgradeTest__factory.ts is excluded by !types/**
  • types/factories/GatewayZEVM__factory.ts is excluded by !types/**
  • types/factories/IGatewayZEVM.sol/IGatewayZEVM__factory.ts is excluded by !types/**
  • types/factories/SenderZEVM__factory.ts is excluded by !types/**
📒 Files selected for processing (2)
  • lib/types.ts (1 hunks)
  • test/GatewayZEVM.t.sol (20 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`test/**`: Review the test files for proper coverage, edge cases, and best practices.

test/**: Review the test files for proper coverage, edge cases, and best practices.

  • test/GatewayZEVM.t.sol
🔇 Additional comments (4)
lib/types.ts (2)

1-1: Addition of new token symbols enhances cross-chain capabilities.

The addition of "SUI.SUI" and "USDC.ARBSEP" to the ParamSymbol type expands token support, aligning with the cross-chain interaction improvements in the PR.


2-2: Chain support update accommodates new integration.

The inclusion of "sui_testnet" in the ParamChainName type reflects the integration with the SUI blockchain, which is consistent with the addition of the SUI token support.

test/GatewayZEVM.t.sol (2)

825-826: Tests updated correctly with the new MessageContext structure.

All test instances have been consistently updated to use the new MessageContext structure with sender and senderEVM fields, properly removing the unused origin field as specified in the PR objectives. The initialization is consistent across all test cases, maintaining proper test coverage.

Also applies to: 835-836, 845-846, 855-856, 866-867, 895-896, 905-906, 915-916, 928-929, 942-943, 952-953, 962-963, 1021-1022, 1031-1032, 1041-1042, 1051-1052, 1065-1066, 1086-1087, 1097-1098, 1108-1109


858-858: Verify test assertions match the updated MessageContext structure.

The event assertions in these tests correctly use the packed address and the protocol address, matching the new structure of the MessageContext. This maintains consistency between the implementation changes and test expectations.

Also applies to: 931-931, 1068-1068

✨ Finishing Touches
  • 📝 Generate Docstrings

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

@lumtis lumtis marked this pull request as ready for review March 12, 2025 15:26
@lumtis lumtis requested review from a team as code owners March 12, 2025 15:26
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 (1)
test/utils/TestUniversalContract.sol (1)

48-48: Rename event parameter and doc references.

You're now passing context.sender as the first event argument, yet the event parameter remains named origin, and the documentation refers to it as "The origin address on the external chain." This may cause confusion since it's now a chain-agnostic bytes sender. Consider renaming the parameter and updating the related doc comments for clarity.

Here is a possible diff to illustrate the rename:

- event ContextData(bytes origin, address sender, uint256 chainID, address msgSender, string message);
+ event ContextData(bytes sender, address senderEVM, uint256 chainID, address msgSender, string message);
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c151ad8 and eee8553.

⛔ Files ignored due to path filters (27)
  • docs/src/contracts/zevm/interfaces/UniversalContract.sol/interface.UniversalContract.md is excluded by !docs/**
  • docs/src/contracts/zevm/interfaces/UniversalContract.sol/struct.MessageContext.md is excluded by !docs/**
  • pkg/gatewayevmzevm.t.sol/gatewayevmzevmtest.go is excluded by !pkg/**
  • pkg/gatewayzevm.sol/gatewayzevm.go is excluded by !pkg/**
  • pkg/gatewayzevm.t.sol/gatewayzevminboundtest.go is excluded by !pkg/**
  • pkg/gatewayzevm.t.sol/gatewayzevmoutboundtest.go is excluded by !pkg/**
  • pkg/gatewayzevmupgradetest.sol/gatewayzevmupgradetest.go is excluded by !pkg/**
  • pkg/igatewayzevm.sol/igatewayzevm.go is excluded by !pkg/**
  • pkg/senderzevm.sol/senderzevm.go is excluded by !pkg/**
  • pkg/systemcontract.sol/systemcontract.go is excluded by !pkg/**
  • pkg/systemcontractmock.sol/systemcontractmock.go is excluded by !pkg/**
  • pkg/testuniversalcontract.sol/testuniversalcontract.go is excluded by !pkg/**
  • pkg/universalcontract.sol/universalcontract.go is excluded by !pkg/**
  • pkg/zrc20.t.sol/zrc20test.go is excluded by !pkg/**
  • types/GatewayZEVM.ts is excluded by !types/**
  • types/GatewayZEVMUpgradeTest.ts is excluded by !types/**
  • types/IGatewayZEVM.sol/IGatewayZEVM.ts is excluded by !types/**
  • types/TestUniversalContract.ts is excluded by !types/**
  • types/UniversalContract.sol/UniversalContract.ts is excluded by !types/**
  • types/factories/GatewayZEVMUpgradeTest__factory.ts is excluded by !types/**
  • types/factories/GatewayZEVM__factory.ts is excluded by !types/**
  • types/factories/IGatewayZEVM.sol/IGatewayZEVM__factory.ts is excluded by !types/**
  • types/factories/SenderZEVM__factory.ts is excluded by !types/**
  • types/factories/SystemContract.sol/SystemContract__factory.ts is excluded by !types/**
  • types/factories/SystemContractMock.sol/SystemContractMock__factory.ts is excluded by !types/**
  • types/factories/TestUniversalContract__factory.ts is excluded by !types/**
  • types/factories/UniversalContract.sol/UniversalContract__factory.ts is excluded by !types/**
📒 Files selected for processing (3)
  • contracts/zevm/interfaces/UniversalContract.sol (1 hunks)
  • test/GatewayZEVM.t.sol (20 hunks)
  • test/utils/TestUniversalContract.sol (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
`test/**`: Review the test files for proper coverage, edge c...

test/**: Review the test files for proper coverage, edge cases, and best practices.

  • test/utils/TestUniversalContract.sol
  • test/GatewayZEVM.t.sol
`contracts/**`: Review the Solidity contracts for security v...

contracts/**: Review the Solidity contracts for security vulnerabilities and best practices.

  • contracts/zevm/interfaces/UniversalContract.sol
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: generate
  • GitHub Check: slither
  • GitHub Check: test
🔇 Additional comments (22)
contracts/zevm/interfaces/UniversalContract.sol (2)

26-27: Documentation looks clear.

These docstrings accurately convey the purpose of the struct and highlight its chain-agnostic design.


40-46: New interface and doc block are well-structured.

The reworked onCall method with the revised MessageContext parameter is consistent with the described functionality and documentation. No immediate concerns.

test/GatewayZEVM.t.sol (20)

799-800: Same concern as above.


809-810: Same concern as above.


819-820: Same concern as above.


829-830: Same concern as above.


859-860: Same concern as above.


869-870: Same concern as above.


879-880: Same concern as above.


892-893: Same concern as above.


906-907: Same concern as above.


916-917: Same concern as above.


926-927: Same concern as above.


985-986: Same concern as above.


995-996: Same concern as above.


1005-1006: Same concern as above.


1015-1016: Same concern as above.


1029-1030: Same concern as above.


1050-1051: Same concern as above.


1061-1062: Same concern as above.


1072-1073: Same concern as above.


789-790:

✅ Verification successful

Potential mismatch in sender vs. senderEVM.

Here, MessageContext.sender is set to abi.encodePacked(address(gateway)), while MessageContext.senderEVM is set to protocolAddress. Verify that this difference is intentional. If this chain is EVM-based, you might want both to represent the same address or document the reason for using distinct addresses.


🏁 Script executed:

#!/bin/bash
# Searching the codebase for all test context initializations to ensure consistency
rg -A 5 "MessageContext({ sender:"

Length of output: 151


Below is a revised next step to verify the intended behavior:

It appears the first run failed due to unescaped curly braces in the regex. To continue gathering context on the initialization pattern for MessageContext—especially the assignments for sender and senderEVM—please run the following script using a fixed-string search so that the curly braces are treated literally:

The output from this search should help confirm whether:

  • The use of abi.encodePacked(address(gateway)) for sender and protocolAddress for senderEVM is unique to this test case.
  • There exists a consistent pattern elsewhere in the codebase that supports using different addresses.

Once you have validated that the discrepancy is intentional (or identified a mistake if similar initializations are meant to use the same value), please update the test code accordingly or add documentation that clarifies the difference.


🏁 Script executed:

#!/bin/bash
# Search for the MessageContext initialization in the specific file with correct escaping
rg --fixed-strings -A 5 "MessageContext({ sender:" test/GatewayZEVM.t.sol

Length of output: 6331


Attention: Confirm Intentional Use of Distinct Values for sender and senderEVM

We verified that every instantiation of MessageContext in test/GatewayZEVM.t.sol consistently assigns:

  • sender as abi.encodePacked(address(gateway))
  • senderEVM as protocolAddress

Since the same pattern is used throughout the test cases, it appears the distinction is intentional. However, to avoid any future confusion, please confirm that this design choice is deliberate. If so, consider adding a brief comment/documentation that explains why the gateway’s address is encoded for sender while a different address (i.e. protocolAddress) is used for senderEVM.

@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 86.22%. Comparing base (95f9ecc) to head (ddd74ab).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #474   +/-   ##
=======================================
  Coverage   86.22%   86.22%           
=======================================
  Files           9        9           
  Lines         559      559           
  Branches      129      129           
=======================================
  Hits          482      482           
  Misses         77       77           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@lumtis lumtis merged commit 429d839 into main Mar 18, 2025
10 of 11 checks passed
@lumtis lumtis deleted the refactor/rename-origin branch March 18, 2025 09:48
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.

4 participants