Skip to content

safe mode self-transfer handling in Wallet #369

Description

@Dargon789

Reviewer's Guide

Adjusts safe mode restrictions to allow native token transfers to the wallet’s own address (self-transfers with no calldata) and adds tests to validate both the allowed and disallowed behaviors.

Sequence diagram for safe mode self-transfer handling in Wallet

sequenceDiagram
  actor User
  participant Wallet
  participant Blockchain

  User->>Wallet: submitTransaction(call)
  activate Wallet
  alt safeMode_enabled
    alt call_to_wallet_address_and_empty_data
      Wallet->>Blockchain: sendNativeTransfer(to_wallet_address, value, data_0x)
      Blockchain-->>Wallet: transferSuccess
      Wallet-->>User: return success
    else call_to_wallet_address_and_non_empty_data_or_delegateCall
      Wallet-->>User: throw Error
    end
  else safeMode_disabled
    Wallet->>Blockchain: sendTransaction(call)
    Blockchain-->>Wallet: txResult
    Wallet-->>User: return txResult
  end
  deactivate Wallet
Loading

Flow diagram for safe mode call validation logic in Wallet

flowchart TD
  A[Start safe mode call validation] --> B{safeMode_enabled?}
  B -- No --> H[Allow call]
  B -- Yes --> C{delegateCall?}
  C -- Yes --> D[Throw error: delegate calls are not allowed in safe mode]
  C -- No --> E{call.to equals wallet.address?}
  E -- No --> H
  E -- Yes --> F{call.data equals 0x?}
  F -- Yes --> H
  F -- No --> G[Throw error: calls to the wallet contract itself are not allowed in safe mode]
  H --> I[End call validation]
Loading

File-Level Changes

Change Details Files
Relax safe mode self-call restriction to allow native-token self-transfers without calldata while still blocking contract calls to self.
  • Update safe-mode validation to only reject self-calls when there is non-empty calldata, preserving the delegateCall restriction.
  • Apply the same conditional self-call check in both transaction validation paths to keep behavior consistent.
packages/wallet/core/src/wallet.ts
Extend transaction tests to cover safe-mode self-transfer behavior and ensure non-value self-calls with data remain disallowed.
  • Modify the existing test to include non-empty calldata when sending a transaction to self, so it continues to be rejected in safe mode.
  • Add a new test that performs a native token transfer to the wallet’s own address in safe mode and asserts that it is allowed.
packages/wallet/wdk/test/transactions.test.ts

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Originally posted by @sourcery-ai[bot] in #367 (comment)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions