Skip to content

Incorrect getUserOperationHash calculation causes signature errors. #4197

@drortirosh

Description

@drortirosh

Check existing issues

Viem Version

2.43.1

Current Behavior

getUserOperationHash() doesn't handle properly different EIP-7702 "factory" settings.
It returns different values than the EntryPoint.getUserOperationHash(), and thus cause validation to fail.

The toPackedUserOperation should behave differently when "just packing" (for the purpose of making an ABI call) and "for signing".

  • When packing it should pack the factory as-is, even if it is only 2 bytes (0x7702), not padding it to 20 bytes
  • When signing it should replace factory (which is a 0x7702 with possible trailing zeros) with the current delegate (this is a mechanism that ensures a UserOp is never executed against a delegate that it wasn't explicitly signed for)

Expected Behavior

No response

Steps To Reproduce

I suggest testing the implementation of getUserOperationHash() against the values of the on-chain EntryPoint.getUserOperationHash(), to make sure they are aligned.
Unfortunately, I couldn't find a test against a contract.
e.g the tests here

Link to Minimal Reproducible Example

No response

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions