Skip to content

feat: use gas budget argument to refund TSS for sui withdraw cost #3671

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

Merged
merged 7 commits into from
Mar 10, 2025

Conversation

lumtis
Copy link
Member

@lumtis lumtis commented Mar 7, 2025

Description

Closes #3583

Use changes from zeta-chain/protocol-contracts-sui#40

Summary by CodeRabbit

  • New Features

    • Sui withdrawal transactions now include a dedicated gas budget parameter to ensure improved refund handling.
  • Documentation

    • The release notes have been updated to showcase upcoming improvements, providing enhanced visibility into future features.

@lumtis lumtis added the SUI_TESTS Run make start-sui-tests label Mar 7, 2025
Copy link
Contributor

coderabbitai bot commented Mar 7, 2025

📝 Walkthrough

Walkthrough

This pull request introduces a new feature documented in the changelog that refunds TSS for Sui withdrawal costs via a gas budget argument. Additionally, multiple end-to-end tests for Sui deposit, token deposit, token withdrawal, and withdrawal have been updated to record and assert TSS balance changes. The observer and signer components have been modified to expect an extra argument (gasBudget) in move call requests and update related constants and struct fields accordingly.

Changes

File(s) Change Summary
changelog.md New "Unreleased" section with a "Features" subsection documenting the use of a gas budget argument to refund TSS for Sui withdraw costs (linked to PR 3671).
e2e/e2etests/test_sui_deposit_and_call_revert.go,
e2e/e2etests/test_sui_token_deposit_and_call_revert.go,
e2e/e2etests/test_sui_token_withdraw.go,
e2e/e2etests/test_sui_withdraw.go
Added variables tssBalanceBefore and tssBalanceAfter with assertions to check that the TSS balance is not reduced after transaction execution.
zetaclient/chains/sui/observer/observer_test.go Added an extra argument (someArgStub) into the inputs of SuiTransactionBlockKind within the ProcessOutboundTrackers test.
zetaclient/chains/sui/observer/outbound.go Updated constant expectedWithdrawArgs from 5 to 6 for validating the number of input arguments in withdrawal transactions.
zetaclient/chains/sui/signer/signer_test.go Introduced a new CallOptions field in the OutboundParams structure and updated expected arguments for MoveCallRequest by adding a new string argument "42000".
zetaclient/chains/sui/signer/signer_tx.go Modified the buildWithdrawal method to include an additional gasBudget parameter in the MoveCallRequest arguments list.

Sequence Diagram(s)

sequenceDiagram
    participant Test as TestFunction
    participant TSS as TSS Account
    participant Tx as Transaction
    Test->>TSS: Query initial balance (tssBalanceBefore)
    Test->>Tx: Execute deposit/withdraw operation
    Test->>TSS: Query post-transaction balance (tssBalanceAfter)
    Test->>Test: Assert tssBalanceAfter ≥ tssBalanceBefore
Loading
sequenceDiagram
    participant Client
    participant Signer
    participant Observer
    Client->>Signer: Request withdrawal transaction
    Signer->>Signer: Build MoveCallRequest (include gasBudget via CallOptions)
    Signer->>Observer: Submit transaction
    Observer->>Observer: Validate input count (expected 6 arguments)
    Observer->>Client: Confirm transaction execution
Loading

Possibly related PRs

  • test(e2e): sui withdraws #3595: Introduces E2E tests for Sui withdrawals and modifies TSS address handling; closely related due to similar modifications for TSS functionality in Sui transactions.

Suggested labels

breaking:cli, UPGRADE_TESTS, no-changelog

Suggested reviewers

  • skosito
  • swift1337
  • brewmaster012
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai 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 changed the title feat: use gas budget argument to refund TSS for wthdraw cost feat: use gas budget argument to refund TSS for withdraw cost Mar 7, 2025
@lumtis lumtis changed the title feat: use gas budget argument to refund TSS for withdraw cost feat: use gas budget argument to refund TSS for sui withdraw cost Mar 7, 2025
Copy link

codecov bot commented Mar 7, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 64.57%. Comparing base (af5b542) to head (185e316).
Report is 5 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #3671      +/-   ##
===========================================
- Coverage    64.61%   64.57%   -0.05%     
===========================================
  Files          470      470              
  Lines        32857    32907      +50     
===========================================
+ Hits         21232    21249      +17     
- Misses       10659    10690      +31     
- Partials       966      968       +2     
Files with missing lines Coverage Δ
zetaclient/chains/sui/observer/outbound.go 56.44% <ø> (ø)
zetaclient/chains/sui/signer/signer_tx.go 60.93% <100.00%> (-0.61%) ⬇️

... and 2 files with indirect coverage changes

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@lumtis lumtis marked this pull request as ready for review March 7, 2025 13:49
@lumtis lumtis requested a review from a team as a code owner March 7, 2025 13:49
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
zetaclient/chains/sui/observer/outbound.go (2)

22-22: Consider enhancing documentation for the expectedWithdrawArgs constant

The constant has been updated from 5 to 6 to accommodate the new gas budget argument for TSS refund functionality. For better maintainability, consider expanding the comments to document all expected arguments (including their types and positions), particularly highlighting the newly added gas budget argument and its purpose.

// https://github.com/zeta-chain/protocol-contracts-sui/blob/9d08a70817d8cc7cf799b9ae12c59b6e0b8aaab9/sources/gateway.move#L125
// (excluding last arg of `ctx`)
-const expectedWithdrawArgs = 6
+// Expected arguments for withdrawal:
+// 1. recipient: address
+// 2. amount: u64
+// 3. nonce: u64
+// 4. message: vector<u8>
+// 5. gasAssetId: ID
+// 6. gasBudget: u64 - Used to refund TSS for Sui withdrawal costs
+const expectedWithdrawArgs = 6

277-296: Consider extracting constants for argument indices

For better code maintainability, consider extracting constants for all argument indices, not just the nonce index. This would make the code more readable and less prone to errors when the order of arguments changes.

+// Argument indices for withdraw inputs
+const (
+    recipientIdx = 0
+    amountIdx = 1
+    nonceIdx = 2
+    messageIdx = 3
+    gasAssetIdIdx = 4
+    gasBudgetIdx = 5
+)

-const nonceIdx = 2
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between af5b542 and 185e316.

📒 Files selected for processing (9)
  • changelog.md (1 hunks)
  • e2e/e2etests/test_sui_deposit_and_call_revert.go (2 hunks)
  • e2e/e2etests/test_sui_token_deposit_and_call_revert.go (2 hunks)
  • e2e/e2etests/test_sui_token_withdraw.go (2 hunks)
  • e2e/e2etests/test_sui_withdraw.go (2 hunks)
  • zetaclient/chains/sui/observer/observer_test.go (1 hunks)
  • zetaclient/chains/sui/observer/outbound.go (1 hunks)
  • zetaclient/chains/sui/signer/signer_test.go (2 hunks)
  • zetaclient/chains/sui/signer/signer_tx.go (1 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_sui_token_withdraw.go
  • zetaclient/chains/sui/signer/signer_test.go
  • zetaclient/chains/sui/observer/observer_test.go
  • e2e/e2etests/test_sui_token_deposit_and_call_revert.go
  • zetaclient/chains/sui/signer/signer_tx.go
  • zetaclient/chains/sui/observer/outbound.go
  • e2e/e2etests/test_sui_withdraw.go
  • e2e/e2etests/test_sui_deposit_and_call_revert.go
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: start-e2e-test / e2e
🔇 Additional comments (16)
zetaclient/chains/sui/signer/signer_test.go (2)

46-48: Good addition of CallOptions for gas budget testing.

The test now correctly includes CallOptions with a GasLimit value to test the new gas budget functionality for TSS refunds.


68-68: Expected arguments updated to include gas budget value.

The expected arguments now properly include "42000" (42 * 1000) as the gas budget value passed to the MoveCallRequest, correctly reflecting the implementation change.

changelog.md (1)

3-7: Well-structured changelog entry for the new feature.

The changelog entry clearly documents the new feature for using a gas budget argument to refund TSS for Sui withdraw costs. The PR reference provides good traceability.

zetaclient/chains/sui/observer/observer_test.go (1)

259-259: Test updated to match new withdrawal argument count.

The test case for ProcessOutboundTrackers has been correctly updated to include an additional argument stub, ensuring that withdrawal transaction validation will pass with the new gas budget parameter.

zetaclient/chains/sui/signer/signer_tx.go (2)

48-54: Good implementation of gas budget calculation.

The code correctly calculates the gas budget by multiplying gas price by gas limit from call options, implementing the core functionality for refunding TSS for Sui withdrawal costs.


66-66: Updated withdrawal function arguments to include gas budget.

The Arguments field now correctly includes the gas budget parameter in the transaction arguments list, enabling the Sui contract to refund the TSS for withdrawal costs.

e2e/e2etests/test_sui_withdraw.go (2)

18-18: Appropriate addition of TSS balance check

This addition correctly captures the TSS balance before the withdrawal operation, establishing a baseline for comparison.


37-40: Well-implemented TSS refund verification

The added verification logic correctly ensures that the TSS receives its gas budget refund after the transaction completes. The comments clearly explain the rationale, and the use of GreaterOrEqual correctly handles potential edge cases where the refund might exactly match the initial cost.

e2e/e2etests/test_sui_token_withdraw.go (2)

18-18: Appropriate addition of TSS balance check

This addition correctly captures the TSS balance before the token withdrawal operation, establishing a baseline for comparison.


37-40: Well-implemented TSS refund verification

The added verification logic correctly ensures that the TSS receives its gas budget refund after the token withdrawal transaction completes. The implementation maintains consistency with the other test files and properly validates the gas refund behavior.

e2e/e2etests/test_sui_deposit_and_call_revert.go (2)

21-21: Appropriate addition of TSS balance check

This addition correctly captures the TSS balance before the deposit operation that will revert, establishing a baseline for comparison.


40-43: Well-implemented TSS refund verification for revert scenario

The added verification logic ensures that the TSS receives its gas budget refund even in the case of reverted transactions. This is particularly important for validating that the gas refund mechanism works correctly in failure scenarios.

e2e/e2etests/test_sui_token_deposit_and_call_revert.go (2)

23-23: Appropriate addition of TSS balance check

This addition correctly captures the TSS balance before the token deposit operation that will revert, establishing a baseline for comparison.


48-51: Well-implemented TSS refund verification for token revert scenario

The added verification logic ensures that the TSS receives its gas budget refund even when token deposit transactions revert. The implementation is consistent with the other test files and properly validates the complex interaction between token operations and gas refunds.

zetaclient/chains/sui/observer/outbound.go (2)

203-205: The validation logic correctly uses the updated constant

The validation logic in validateOutbound properly uses the expectedWithdrawArgs constant to check the correct number of arguments, ensuring compatibility with the new gas budget parameter.


277-280:

❓ Verification inconclusive

Validate parseNonceFromWithdrawInputs function for gasBudget compatibility

This function correctly validates that the inputs match the updated expectedWithdrawArgs constant. However, it doesn't parse or use the new gas budget argument. If the position of the nonce has changed due to the additional argument, or if the gas budget needs to be processed here, this function would need further updates.


🏁 Script executed:

#!/bin/bash
# Check if the nonce position remains consistent and if there's any usage of the gas budget argument

# Search for the declaration and usage of the gas budget argument in the signer implementation
rg -A 10 "buildWithdrawal" --glob "*.go" | grep -A 20 "Arguments"

# Verify if there's any processing of gas budget in the codebase
rg -A 5 "gasBudget" --glob "*.go"

Length of output: 1031


Action: Confirm Nonce Extraction Consistency Amidst Withdraw Argument Updates

The function parseNonceFromWithdrawInputs correctly checks that the number of inputs equals expectedWithdrawArgs. However, with the new gas budget argument now computed and injected (as seen in sui/signer/signer_tx.go), please verify that the nonce remains in its expected position. Specifically:

  • Ensure that the constant expectedWithdrawArgs and the index used to extract the nonce are still valid after adding the gas budget.
  • If the argument order has shifted (e.g., nonce moved to a different index), update this function to correctly parse the nonce.
  • Confirm that gas budget processing is intentionally handled elsewhere and does not require additional action in this function.

@lumtis lumtis added this pull request to the merge queue Mar 10, 2025
Merged via the queue into develop with commit e501f5d Mar 10, 2025
47 checks passed
@lumtis lumtis deleted the sui-tss-fee-payment branch March 10, 2025 08:47
lumtis added a commit that referenced this pull request Mar 14, 2025
)

* build new gateway binary

* gas budget params

* fix order

* changelog

* add accounting checks

* fix tests

* fix unit test observer
gartnera pushed a commit that referenced this pull request Mar 14, 2025
)

* build new gateway binary

* gas budget params

* fix order

* changelog

* add accounting checks

* fix tests

* fix unit test observer
gartnera added a commit that referenced this pull request Mar 14, 2025
* feat(sui): custom sui_executeTransactionBlock (#3662)

* Fix sui_executeTransactionBlock

* rename

* fix unit test observer

* feat: use gas budget argument to refund TSS for sui withdraw cost (#3671)

* build new gateway binary

* gas budget params

* fix order

* changelog

* add accounting checks

* fix tests

* fix unit test observer

* fix changeogs

* changelog

---------

Co-authored-by: Dmitry S <11892559+swift1337@users.noreply.github.com>
Co-authored-by: Alex Gartner <git@agartner.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
SUI_TESTS Run make start-sui-tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement solution to handle Sui withdraw cost
3 participants