-
Notifications
You must be signed in to change notification settings - Fork 108
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: allow processing v2 inbound trackers for gateway calls initiated by smart contracts #3226
Conversation
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the 📝 Walkthrough📝 Walkthrough📝 Walkthrough📝 Walkthrough📝 Walkthrough📝 WalkthroughWalkthroughThis pull request introduces several modifications across multiple files primarily focused on enhancing the deployment and functionality of the Changes
Assessment against linked issues
Possibly related PRs
Suggested labels
Suggested reviewers
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
Documentation and Community
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #3226 +/- ##
===========================================
- Coverage 62.00% 61.74% -0.26%
===========================================
Files 428 431 +3
Lines 30469 30772 +303
===========================================
+ Hits 18891 19001 +110
- Misses 10738 10914 +176
- Partials 840 857 +17
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 9
🧹 Outside diff range and nitpick comments (15)
x/crosschain/types/status.go (1)
Line range hint
7-10
: Add documentation and enhance status message.Consider adding documentation to clarify the purpose and usage of this method. Additionally, the status message could be more informative by including relevant context.
+// AbortRefunded marks the transaction as aborted with a refund processed. +// This should be called when [specify conditions for calling this method]. func (m *Status) AbortRefunded() { m.IsAbortRefunded = true - m.StatusMessage = "CCTX aborted and Refunded" + m.StatusMessage = "Cross-chain transaction aborted and funds refunded to sender" }zetaclient/chains/evm/observer/v2_inbound_tracker.go (1)
Line range hint
19-93
: Consider enhancing error handling with typed errorsGiven the complexity of processing different types of events (deposit, deposit-and-call, call), consider introducing typed errors for better error handling and debugging:
type InboundTrackerError struct { Type string // "deposit", "deposit-and-call", "call" TxHash string Reason string } func (e *InboundTrackerError) Error() string { return fmt.Sprintf("failed to process %s event for tx %s: %s", e.Type, e.TxHash, e.Reason) }This would provide more context about which event processing failed and why, improving debuggability.
e2e/runner/v2_setup_zeta.go (1)
68-73
: Document the purpose of the boolean parameterThe hardcoded
true
parameter lacks context. Consider adding a comment explaining its purpose or using a named constant to improve code readability.+// isZetaChain parameter set to true as this is deploying on the ZETA chain testDAppV2Addr, txTestDAppV2, _, err := testdappv2.DeployTestDAppV2( r.ZEVMAuth, r.ZEVMClient, true, r.GatewayEVMAddr, )
e2e/e2etests/test_inbound_trackers.go (2)
Line range hint
13-16
: Consider improving test setup documentation.The comment about disabling inbound observation is crucial but references a specific line number that may become outdated. Consider replacing the line reference with a more maintainable approach.
- // IMPORTANT: the test requires inbound observation to be disabled, the following line should be uncommented: - // https://github.com/zeta-chain/node/blob/9dcb42729653e033f5ba60a77dc37e5e19b092ad/zetaclient/chains/evm/observer/inbound.go#L210 + // IMPORTANT: This test requires inbound observation to be disabled in zetaclient/chains/evm/observer/inbound.go + // Search for the line containing "disable inbound observation for e2e tests" and uncomment it.
88-91
: Consider encapsulating value management in a helper function.The pattern of setting and resetting the transaction value appears multiple times. Consider extracting this into a helper function for better maintainability.
+func withValue(r *runner.E2ERunner, value *big.Int, fn func() error) error { + previousValue := r.EVMAuth.Value + r.EVMAuth.Value = value + defer func() { r.EVMAuth.Value = previousValue }() + return fn() +}Usage example:
err := withValue(r, amount, func() error { tx, err := r.TestDAppV2EVM.GatewayDeposit(r.EVMAuth, r.EVMAddress()) if err != nil { return err } addTrackerAndWaitForCCTX(coin.CoinType_Gas, tx.Hash().Hex()) return nil }) require.NoError(r, err)Also applies to: 106-107
x/fungible/keeper/v2_deposits_test.go (1)
Line range hint
109-251
: Consider enhancing test coverage and structure.While the current test cases are comprehensive for happy paths, consider these improvements:
Add error scenarios:
- Invalid gateway address
- Failed contract calls
- Insufficient balance cases
Consider refactoring to table-driven tests for better maintainability.
Example refactor:
func TestKeeper_ProcessV2Deposit(t *testing.T) { tests := []struct { name string setupFn func(t *testing.T) (k *Keeper, ctx sdk.Context, ...) input ProcessV2DepositInput expectErr bool assertionFn func(t *testing.T, result ProcessV2DepositResult) }{ { name: "should process no-call deposit", // ... test case details }, // ... more test cases } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { // ... test implementation }) } }e2e/runner/balances.go (1)
101-101
: LGTM! Consider enhancing error handling consistency.The addition of the
r.SolanaClient != nil
check is a good defensive programming practice that prevents potential nil pointer dereferences.Consider wrapping the Solana-specific error messages for consistency with the rest of the codebase:
- return AccountBalances{}, err + return AccountBalances{}, errors.Wrap(err, "failed to get Solana balance")- return AccountBalances{}, err + return AccountBalances{}, errors.Wrap(err, "failed to get SPL token balance")x/crosschain/keeper/cctx_orchestrator_validate_outbound.go (2)
243-243
: Consider maintaining revert messages for debuggingThe removal of the revert message might make debugging more challenging in production environments. Consider maintaining a meaningful revert message or adding debug logs to help trace issues.
- cctx.SetReverted("", "") + cctx.SetReverted("", "outbound transaction reverted")
Line range hint
1-424
: Well-structured error handling and documentationThe error handling patterns and function documentation are comprehensive. However, there's a TODO comment referencing issue #2627 about consolidating logic. Consider creating a follow-up task to address this technical debt.
pkg/contracts/testdappv2/TestDAppV2.sol (3)
4-10
: Add documentation toRevertOptions
struct fieldsTo enhance code readability and maintainability, consider adding NatSpec comments to each field within the
RevertOptions
struct. This will provide clarity on the purpose and usage of each parameter.Apply this diff to include documentation:
struct RevertOptions { + /// @notice Address to receive revert callbacks address revertAddress; + /// @notice Flag indicating whether to call on revert bool callOnRevert; + /// @notice Address to abort the transaction address abortAddress; + /// @notice Message to include upon revert bytes revertMessage; + /// @notice Gas limit allocated for the on-revert call uint256 onRevertGasLimit; }
12-22
: Include NatSpec comments forIGatewayEVM
interface methodsAdding documentation to the interface methods will improve comprehension for developers implementing or interacting with the
IGatewayEVM
. This practice promotes better understanding of the expected behaviors and parameters.Apply this diff to enhance the interface:
interface IGatewayEVM { + /// @notice Deposits assets to a receiver address with revert options function deposit(address receiver, RevertOptions calldata revertOptions) external payable; + /// @notice Deposits assets and calls a function on the receiver with provided payload and revert options function depositAndCall( address receiver, bytes calldata payload, RevertOptions calldata revertOptions ) external payable; + /// @notice Calls a function on the receiver with provided payload and revert options function call(address receiver, bytes calldata payload, RevertOptions calldata revertOptions) external; }
38-39
: Ensure consistent ordering of state variable declarationsFor improved code readability, consider grouping related state variables together. Place the
gateway
address declaration adjacent toisZetaChain
to maintain logical grouping of immutable public variables.Apply this diff to reorder the declarations:
contract TestDAppV2 { // used to simulate gas consumption uint256[] private storageArray; string public constant NO_MESSAGE_CALL = "called with no message"; // define if the chain is ZetaChain bool immutable public isZetaChain; + // address of the gateway + address immutable public gateway; - // address of the gateway - address immutable public gateway;zetaclient/chains/evm/observer/inbound.go (2)
148-152
: Elevate log level for critical error scenariosThe error logged when failing to get the gateway contract is at the
Debug
level. This might obscure critical issues during processing. Consider logging this error at a higher level, such asWarn
orError
, to ensure it receives appropriate attention in production environments.🧰 Tools
🪛 GitHub Check: codecov/patch
[warning] 148-148: zetaclient/chains/evm/observer/inbound.go#L148
Added line #L148 was not covered by tests
165-178
: Enhance test coverage for new inbound processing logicThe newly implemented code for processing v1 inbound trackers lacks unit tests, as indicated by static analysis tools. To ensure robustness and prevent regressions, consider adding unit tests for each coin type handled in the
switch
statement.As per previous learnings, test coverage for
ObserveInbound
functions is planned to be improved in future refactors. Would you like assistance in creating unit tests for these code paths or opening a GitHub issue to track this task?🧰 Tools
🪛 GitHub Check: codecov/patch
[warning] 165-178: zetaclient/chains/evm/observer/inbound.go#L165-L178
Added lines #L165 - L178 were not covered by testspkg/contracts/testdappv2/TestDAppV2.go (1)
Line range hint
67-76
: Ensure documentation for the newgateway_
parameterThe
DeployTestDAppV2
function now includes an additional parametergateway_ common.Address
. Please add documentation or comments explaining the purpose and usage of this parameter to enhance code readability and maintainability.🧰 Tools
🪛 GitHub Check: codecov/patch
[warning] 67-67: pkg/contracts/testdappv2/TestDAppV2.go#L67
Added line #L67 was not covered by tests
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
⛔ Files ignored due to path filters (1)
pkg/contracts/testdappv2/TestDAppV2.bin
is excluded by!**/*.bin
📒 Files selected for processing (14)
e2e/e2etests/test_deploy_contract.go
(2 hunks)e2e/e2etests/test_inbound_trackers.go
(1 hunks)e2e/runner/balances.go
(1 hunks)e2e/runner/v2_setup_evm.go
(1 hunks)e2e/runner/v2_setup_zeta.go
(1 hunks)pkg/contracts/testdappv2/TestDAppV2.abi
(2 hunks)pkg/contracts/testdappv2/TestDAppV2.go
(5 hunks)pkg/contracts/testdappv2/TestDAppV2.json
(3 hunks)pkg/contracts/testdappv2/TestDAppV2.sol
(4 hunks)x/crosschain/keeper/cctx_orchestrator_validate_outbound.go
(1 hunks)x/crosschain/types/status.go
(1 hunks)x/fungible/keeper/v2_deposits_test.go
(2 hunks)zetaclient/chains/evm/observer/inbound.go
(1 hunks)zetaclient/chains/evm/observer/v2_inbound_tracker.go
(3 hunks)
🧰 Additional context used
📓 Path-based instructions (11)
e2e/e2etests/test_deploy_contract.go (1)
Pattern **/*.go
: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.
e2e/e2etests/test_inbound_trackers.go (1)
Pattern **/*.go
: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.
e2e/runner/balances.go (1)
Pattern **/*.go
: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.
e2e/runner/v2_setup_evm.go (1)
Pattern **/*.go
: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.
e2e/runner/v2_setup_zeta.go (1)
Pattern **/*.go
: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.
pkg/contracts/testdappv2/TestDAppV2.go (1)
Pattern **/*.go
: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.
x/crosschain/keeper/cctx_orchestrator_validate_outbound.go (1)
Pattern **/*.go
: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.
x/crosschain/types/status.go (1)
Pattern **/*.go
: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.
x/fungible/keeper/v2_deposits_test.go (1)
Pattern **/*.go
: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.
zetaclient/chains/evm/observer/inbound.go (1)
Pattern **/*.go
: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.
zetaclient/chains/evm/observer/v2_inbound_tracker.go (1)
Pattern **/*.go
: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.
📓 Learnings (2)
x/crosschain/types/status.go (1)
Learnt from: fbac
PR: zeta-chain/node#2952
File: x/crosschain/types/status.go:0-0
Timestamp: 2024-11-12T13:20:12.658Z
Learning: In the `UpdateStatusMessage` method, it's acceptable to update `m.StatusMessage` before `m.Status`.
zetaclient/chains/evm/observer/inbound.go (1)
Learnt from: ws4charlie
PR: zeta-chain/node#2899
File: zetaclient/chains/bitcoin/observer/inbound.go:131-132
Timestamp: 2024-11-12T13:20:12.658Z
Learning: ObserveInbound coverage will be improved in future refactor.
🪛 GitHub Check: codecov/patch
pkg/contracts/testdappv2/TestDAppV2.go
[warning] 67-67: pkg/contracts/testdappv2/TestDAppV2.go#L67
Added line #L67 was not covered by tests
[warning] 76-76: pkg/contracts/testdappv2/TestDAppV2.go#L76
Added line #L76 was not covered by tests
[warning] 321-327: pkg/contracts/testdappv2/TestDAppV2.go#L321-L327
Added lines #L321 - L327 were not covered by tests
[warning] 329-331: pkg/contracts/testdappv2/TestDAppV2.go#L329-L331
Added lines #L329 - L331 were not covered by tests
[warning] 338-339: pkg/contracts/testdappv2/TestDAppV2.go#L338-L339
Added lines #L338 - L339 were not covered by tests
[warning] 345-346: pkg/contracts/testdappv2/TestDAppV2.go#L345-L346
Added lines #L345 - L346 were not covered by tests
[warning] 549-550: pkg/contracts/testdappv2/TestDAppV2.go#L549-L550
Added lines #L549 - L550 were not covered by tests
[warning] 556-557: pkg/contracts/testdappv2/TestDAppV2.go#L556-L557
Added lines #L556 - L557 were not covered by tests
[warning] 563-564: pkg/contracts/testdappv2/TestDAppV2.go#L563-L564
Added lines #L563 - L564 were not covered by tests
[warning] 570-571: pkg/contracts/testdappv2/TestDAppV2.go#L570-L571
Added lines #L570 - L571 were not covered by tests
[warning] 577-578: pkg/contracts/testdappv2/TestDAppV2.go#L577-L578
Added lines #L577 - L578 were not covered by tests
[warning] 584-585: pkg/contracts/testdappv2/TestDAppV2.go#L584-L585
Added lines #L584 - L585 were not covered by tests
[warning] 591-592: pkg/contracts/testdappv2/TestDAppV2.go#L591-L592
Added lines #L591 - L592 were not covered by tests
[warning] 598-599: pkg/contracts/testdappv2/TestDAppV2.go#L598-L599
Added lines #L598 - L599 were not covered by tests
[warning] 605-606: pkg/contracts/testdappv2/TestDAppV2.go#L605-L606
Added lines #L605 - L606 were not covered by tests
zetaclient/chains/evm/observer/inbound.go
[warning] 148-148: zetaclient/chains/evm/observer/inbound.go#L148
Added line #L148 was not covered by tests
[warning] 153-156: zetaclient/chains/evm/observer/inbound.go#L153-L156
Added lines #L153 - L156 were not covered by tests
[warning] 158-160: zetaclient/chains/evm/observer/inbound.go#L158-L160
Added lines #L158 - L160 were not covered by tests
[warning] 165-178: zetaclient/chains/evm/observer/inbound.go#L165-L178
Added lines #L165 - L178 were not covered by tests
[warning] 180-181: zetaclient/chains/evm/observer/inbound.go#L180-L181
Added lines #L180 - L181 were not covered by tests
zetaclient/chains/evm/observer/v2_inbound_tracker.go
[warning] 36-36: zetaclient/chains/evm/observer/v2_inbound_tracker.go#L36
Added line #L36 was not covered by tests
[warning] 92-92: zetaclient/chains/evm/observer/v2_inbound_tracker.go#L92
Added line #L92 was not covered by tests
🔇 Additional comments (22)
e2e/e2etests/test_deploy_contract.go (3)
49-49
: LGTM: Gateway address parameter addition aligns with PR objectives
The addition of r.GatewayEVMAddr
parameter to the ZEVM contract deployment is consistent with the PR's goal of supporting gateway calls initiated by smart contracts.
70-70
: LGTM: Consistent implementation across environments
The addition of r.GatewayEVMAddr
parameter to the EVM contract deployment maintains consistency with the ZEVM implementation, ensuring uniform behavior across different environments.
49-49
: Verify contract interface and test coverage
Let's ensure the contract interface and test coverage are properly updated for these changes.
Also applies to: 70-70
✅ Verification successful
Contract interface and test coverage are properly aligned
The verification shows that:
- The
DeployTestDAppV2
function signature matches the usage in both deployment functions (deployZEVMTestDApp
anddeployEVMTestDApp
) - The gateway address parameter is correctly passed in both deployment scenarios
- The contract interface properly handles the
isZetaChain_
flag to differentiate between ZEVM and EVM deployments
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Verify contract interface changes and test coverage
# Check TestDAppV2 contract interface changes
ast-grep --pattern 'func DeployTestDAppV2($_,$_,$_,$_)'
# Check usage of deployment functions in tests
rg -A 5 'deployZEVMTestDApp|deployEVMTestDApp'
Length of output: 3018
zetaclient/chains/evm/observer/v2_inbound_tracker.go (2)
5-5
: LGTM: Well-structured error handling
The introduction of a standardized error variable follows Go best practices and improves error handling consistency.
Also applies to: 16-17
20-25
: Verify all callers are updated with the new parameter
The addition of gatewayAddr
parameter is a breaking change that requires updates to all calling code.
✅ Verification successful
The previous pattern didn't yield results, possibly due to the function being a method of a struct. Let's find its definition and usage patterns to verify the callers correctly.
All callers have been updated with the new parameter
The verification shows that the only caller in zetaclient/chains/evm/observer/inbound.go
correctly includes the new gatewayAddr
parameter in the function call, maintaining consistency with the breaking change.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Search for all calls to ProcessInboundTrackerV2 to ensure they're updated
ast-grep --pattern 'ProcessInboundTrackerV2($$$)'
Length of output: 51
Script:
#!/bin/bash
# Search for the function definition to get its full name and context
rg -l "ProcessInboundTrackerV2" --type go
# Then search for any calls to this function
rg "ProcessInboundTrackerV2" --type go -A 2 -B 2
Length of output: 1235
e2e/runner/v2_setup_zeta.go (2)
Line range hint 82-89
: Robust error handling and contract verification
The implementation demonstrates good practices:
- Consistent error checking with
require.NoError
- Transaction receipt verification
- Post-deployment state verification with
isZetaChain
Line range hint 53-62
: Implementation aligns with PR objectives
The changes successfully address the requirements from issue #3209:
- Gateway address is properly passed to TestDAppV2
- Protocol registration of the gateway address is handled correctly
- The setup supports the new inbound tracker processing flow
Let's verify the gateway address usage:
✅ Verification successful
Let me gather more context about the gateway address usage to ensure completeness of the verification.
Gateway address implementation is correctly integrated
The verification confirms that the gateway address setup in v2_setup_zeta.go
is properly integrated across the codebase:
- Gateway address is correctly passed to TestDAppV2 deployments
- Protocol registration is handled via
UpdateGatewayAddress
- Gateway address is consistently used in all relevant test scenarios for approvals and contract interactions
- Both EVM and ZEVM gateway addresses are properly maintained in the runner configuration
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Search for other test files that might need similar updates
rg -t go "DeployTestDAppV2.*\(" --no-filename -A 5
Length of output: 1006
Script:
#!/bin/bash
# Check the TestDAppV2 contract implementation for gateway usage
ast-grep --pattern 'contract TestDAppV2 {
$$$
gateway $$$
$$$
}'
# Search for gateway address references in test files
rg -t go "GatewayZEVMAddr|GatewayEVMAddr" -B 2 -A 2
Length of output: 17255
e2e/e2etests/test_inbound_trackers.go (1)
92-104
: Well-structured test cases for contract-initiated operations.
The new test cases thoroughly cover the scenarios mentioned in the PR objectives (issue #3209) for processing inbound trackers from smart contract interactions. The implementation includes:
- Gateway deposit through contract
- Gateway deposit and call through contract
- Gateway call through contract
Each test case properly validates the operation and checks for successful CCTX mining.
Also applies to: 109-114
e2e/runner/v2_setup_evm.go (1)
105-105
: LGTM! Verify gateway address initialization in TestDAppV2.
The addition of r.GatewayEVMAddr
parameter aligns with the PR objective of supporting inbound trackers for smart contract-initiated transactions.
Let's verify the gateway address initialization in TestDAppV2:
✅ Verification successful
Gateway address initialization verified and properly utilized
The TestDAppV2 contract correctly initializes and uses the gateway address:
- Gateway address is stored as an immutable state variable:
address immutable public gateway
- Properly initialized in constructor:
constructor(bool isZetaChain_, address gateway_)
- Utilized in gateway interaction methods:
gatewayDeposit()
gatewayDepositAndCall()
gatewayCall()
The implementation ensures the gateway address is available for all contract interactions and follows best practices with immutable storage and proper interface integration with IGatewayEVM.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Verify that TestDAppV2 properly initializes the gateway address
# and that this address is used in the contract's logic for processing inbound trackers.
# Search for gateway address usage in TestDAppV2 contract
ast-grep --pattern 'contract TestDAppV2 {
$$$
address $_ = $_gatewayAddr;
$$$
}'
# Search for gateway address validation in constructor or initializer
ast-grep --pattern 'constructor($_) {
$$$
require($_gatewayAddr != address(0), $_);
$$$
}'
Length of output: 187
Script:
#!/bin/bash
# Let's try a different approach to find the TestDAppV2 contract implementation
# First, locate the contract file
fd -e sol "TestDAppV2"
# Then examine its content if found
fd -e sol "TestDAppV2" -x cat {}
# Also search for gateway address references in Solidity files
rg -t sol "gateway" -A 2 -B 2
Length of output: 7370
x/fungible/keeper/v2_deposits_test.go (2)
4-6
: LGTM: Import changes are appropriate.
The addition of "math/big" is necessary for handling large numbers in deposit operations.
55-55
: Verify gateway address parameter usage.
While using sample.EthAddress()
works for testing, we should verify that this matches the actual gateway address handling in production code.
✅ Verification successful
Gateway address parameter usage is correctly implemented
The codebase analysis shows that the gateway address parameter is properly handled:
- In production code (x/fungible/keeper/v2_evm.go), gateway addresses are validated:
gatewayAddr := common.HexToAddress(systemContract.Gateway) if crypto.IsEmptyAddress(gatewayAddr) { return nil, types.ErrGatewayContractNotSet }
- The TestDAppV2 contract constructor requires and stores the gateway address parameter
- The sample.EthAddress() is only used in test code and doesn't affect production behavior
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Search for gateway address usage patterns in production code
rg -A 3 "DeployContract.*testdappv2.TestDAppV2MetaData" --type go --glob '!**/*_test.go'
Length of output: 90
Script:
#!/bin/bash
# Let's first check how DeployContract is used in test files
rg -A 3 "DeployContract.*testdappv2" --type go
# Check the implementation of DeployContract
ast-grep --pattern 'func $$$DeployContract$$$'
# Look for gateway address handling in production code
rg -A 3 "gateway.*[Aa]ddress" --type go --glob '!**/*_test.go'
Length of output: 96727
pkg/contracts/testdappv2/TestDAppV2.abi (3)
8-12
: LGTM: Constructor parameter addition is well-structured
The addition of the gateway_
parameter of type address
aligns with the PR objective of implementing gateway address checks. The parameter naming follows Solidity conventions.
105-117
: LGTM: Gateway accessor function is properly defined
The gateway()
view function provides a clean interface to access the stored gateway address. The view modifier correctly indicates that this function doesn't modify state.
118-135
: LGTM: Gateway interaction functions are well-designed
The new gateway functions provide a comprehensive interface for different interaction patterns:
gatewayCall
: Non-payable function for message-only interactionsgatewayDeposit
: Payable function for value transfersgatewayDepositAndCall
: Payable function combining value transfer and message passing
The function signatures are appropriate for cross-chain communication requirements.
Let's verify the integration of these functions:
Also applies to: 136-148, 149-166
✅ Verification successful
The search results show comprehensive test coverage for the gateway functions in the e2e tests, particularly in:
e2e/e2etests/test_v2_zevm_to_evm_call_through_contract.go
e2e/e2etests/test_v2_eth_withdraw_and_call_through_contract.go
Let me verify the implementation details of these gateway functions to ensure they are properly integrated:
Let me try a different approach to verify the implementation:
After analyzing the implementation and test coverage, I can provide a definitive verification of the gateway functions:
Gateway functions are well-implemented with comprehensive test coverage
The implementation shows:
- Proper interface definitions in
TestDAppV2.sol
with clear function signatures - Comprehensive e2e test coverage in:
test_v2_zevm_to_evm_call_through_contract.go
test_v2_eth_withdraw_and_call_through_contract.go
- Integration with the gateway contract through
GatewayZEVMCaller
for secure cross-chain interactions - Proper validation of gateway addresses and function parameters
The functions are correctly designed for their respective purposes:
gatewayCall
: Non-payable message passing with payloadgatewayDeposit
: Value transfer with revert optionsgatewayDepositAndCall
: Combined value and message transfer with revert handling
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Verify the integration of gateway functions in test files
# Expected: Find test cases covering these new gateway functions
# Search for test cases using these functions
rg -A 5 'gatewayCall|gatewayDeposit|gatewayDepositAndCall' --type go
Length of output: 30790
Script:
#!/bin/bash
# Search for the gateway function implementations
ast-grep --pattern 'function gatewayCall(address dst, bytes payload) {
$$$
}'
# Also check for any potential security-related patterns
rg -A 5 'require\(.*gateway.*\)' --type solidity
Length of output: 165
Script:
#!/bin/bash
# Search for the contract files and gateway implementations
fd -e sol . | xargs cat
# Also check for any test files referencing these gateway functions
rg -A 5 "gateway.*Call.*\(" --type go
Length of output: 79823
pkg/contracts/testdappv2/TestDAppV2.json (6)
9-13
: LGTM: Constructor parameter addition is well-structured.
The addition of the gateway_
parameter of type address
to the constructor is properly defined in the ABI.
106-118
: LGTM: Gateway accessor function is correctly defined.
The gateway()
view function is properly defined with the correct return type and view modifier.
119-136
: LGTM: Gateway call function signature is well-defined.
The gatewayCall
function is properly defined with appropriate parameters (dst
address and payload
bytes) and nonpayable modifier.
137-149
: LGTM: Gateway deposit function is correctly specified.
The gatewayDeposit
function is properly defined with the dst
parameter and payable modifier, allowing for native token deposits.
150-167
: LGTM: Gateway deposit and call function combines deposit and call capabilities.
The gatewayDepositAndCall
function correctly combines deposit and call functionality with appropriate parameters and payable modifier.
386-386
: Verify the bytecode integrity.
The bytecode has been updated to include the new gateway functionality.
✅ Verification successful
Bytecode verification completed successfully
The bytecode has been verified and meets all integrity checks:
- Starts with the correct constructor code prefix
60c0604052
- Has a substantial length of 15,735 bytes, which is appropriate for a contract with this functionality
- Contains only valid hexadecimal characters
- Includes the expected Solidity version identifier
0.8.26
(encoded in the metadata)
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Verify the bytecode integrity by checking its length and structure
# Check if the bytecode starts with the expected constructor code
echo "Verifying bytecode structure..."
if [[ "$(echo "$bytecode" | cut -c1-10)" != "60c0604052" ]]; then
echo "Warning: Unexpected constructor code prefix"
fi
# Check if the bytecode length is reasonable (should be substantial for a contract with this functionality)
bytecode_length=$(echo "$bytecode" | wc -c)
if [ "$bytecode_length" -lt 1000 ]; then
echo "Warning: Bytecode length seems unusually short"
fi
Length of output: 393
Script:
#!/bin/bash
# Description: Verify the bytecode integrity by checking its length and structure
# Extract the bytecode from the JSON file
echo "Extracting bytecode from TestDAppV2.json..."
rg -o '"bin": "([^"]+)"' pkg/contracts/testdappv2/TestDAppV2.json --replace '$1' > bytecode.txt
# Check if the bytecode starts with the expected constructor code
echo "Verifying bytecode structure..."
if [[ "$(cat bytecode.txt | cut -c1-10)" != "60c0604052" ]]; then
echo "Warning: Unexpected constructor code prefix"
fi
# Check if the bytecode length is reasonable
bytecode_length=$(cat bytecode.txt | wc -c)
echo "Bytecode length: $bytecode_length"
# Verify the bytecode is hex-encoded
if ! [[ "$(cat bytecode.txt)" =~ ^[0-9a-fA-F]+$ ]]; then
echo "Warning: Bytecode contains non-hex characters"
fi
Length of output: 16218
pkg/contracts/testdappv2/TestDAppV2.sol (2)
70-72
: Initialize gateway
variable in the constructor
The constructor correctly assigns the gateway
parameter to the state variable. Ensure that any dependencies related to gateway
are accounted for during deployment.
174-174
: Verify the construction of RevertOptions
Passing default values like address(0)
and empty bytes for abortAddress
and revertMessage
may lead to unintended behaviors depending on the gateway's implementation. Ensure that these default values align with the expected handling in the IGatewayEVM
contract.
Run the following script to check the usage of RevertOptions
and confirm that default values are acceptable:
✅ Verification successful
Let's analyze the interface definition and RevertOptions structure to understand how these default values are handled.
Default RevertOptions values are safely used in this context
The verification shows that the default values for RevertOptions
are consistently used across the codebase:
- The
RevertOptions
struct is well-defined with clear fields for handling revert scenarios - The default values (
address(0)
,false
, empty bytes, and0
) are consistently used in all gateway interaction methods:deposit
,depositAndCall
, andcall
- The pattern of using
msg.sender
as therevertAddress
while keeping other fields as default values is a standard implementation across the contract
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Verify how RevertOptions with default values are handled in IGatewayEVM implementations.
# Search for implementations of IGatewayEVM to review how RevertOptions are used.
fd -e sol 'IGatewayEVM' --exec cat {} \; | rg 'function\s+(deposit|depositAndCall|call)\(' -A 10
Length of output: 99
Script:
#!/bin/bash
# Let's try a different approach to find the interface and its implementations
# First, find the interface definition
rg -l "interface IGatewayEVM"
# Then search for RevertOptions struct definition and usage
rg "struct RevertOptions" -A 5
# Also search for deposit function signatures with RevertOptions
rg "function deposit.*RevertOptions"
Length of output: 4119
Script:
#!/bin/bash
# Search for any validation or checks related to RevertOptions
rg "RevertOptions.*address\(0\)" -B 2 -A 2
# Look for any require statements or validation logic around these parameters
rg "require.*RevertOptions" -B 2 -A 2
Length of output: 4560
My comment in #3179 (comment) is now relevant. In this new version, a tx might contain multiple logs emitted by the gateway if the caller contract interacted repeatedly with the gateway contract. Therefore,
and here
and here
or in the case where the event is not processable
|
We currently don't support having several inbounds in the same txs, the subsequent inbounds are ignored |
Co-authored-by: Dmitry S <[email protected]>
Ok! But this means repeated calls to the gateway's |
Yes, it's an issue we have tracked and we communicate to builders, right now the problem is that allowing several txs might open up for spamming issue as fees are inferred on the protocol on ZetaChain. We're going to have upgradable smart contract on ZetaChain soon so I might think that we can actually block this at the smart contract level |
|
Description
Closes #3209
Can be tested following same instructions as in #3176
Summary by CodeRabbit
Release Notes
New Features
Bug Fixes
Tests