Skip to content

Conversation

@srivtx
Copy link

@srivtx srivtx commented Dec 29, 2025

fixes #4197

Description

This PR fixes the getUserOperationHash calculation for EIP-7702 UserOperations.

Previously, viem was substituting the factory address with the delegate address (authorization.address) during both packing (bundling) and hashing (signing).

This caused a mismatch because:

  1. Bundling: Requires the raw factory address 0x7702 (2 bytes) to be present in initCode so the chain recognizes it as an EIP-7702 transaction.
  2. Signing/Hashing: Requires the specific delegate address to be hashed in initCode for security.

Changes

  • Modified getInitCode to accept an options.forHash parameter.
  • Updated toPackedUserOperation to pass this option through.
  • Updated getUserOperationHash (v0.6, v0.7) and getUserOperationTypedData (v0.8, v0.9) to pass { forHash: true }.

Verification

  • Ran existing tests successfully:
    pnpm test src/account-abstraction/utils/userOperation/getUserOperationHash.test.ts
  • Verified that v0.6, v0.7, v0.8, and v0.9 EntryPoints all calculate the correct hash while enabling correct packing for Bundlers.

@changeset-bot
Copy link

changeset-bot bot commented Dec 29, 2025

🦋 Changeset detected

Latest commit: e368bc5

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
viem Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@jxom
Copy link
Member

jxom commented Dec 29, 2025

Superseded by 892ebea (your commit is still preserved).

@jxom jxom closed this Dec 29, 2025
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.

Incorrect getUserOperationHash calculation causes signature errors.

2 participants