Skip to content

feat: eip712 type hash #10483

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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

0xrusowsky
Copy link

Adds a new cheatcode to safely generate hashes following the EIP-712 spec.

implementation details

As highlighted on:

due to the lack of polymorphism, it is not possible for the cheatcode to accept a struct. Because of that, users must provide a string.

This initial impl requires users to input the full string representation of the type (later on we can iterate and attempt to figure the type from the artifact).

Users are not required to pass sorted types, and can also add spaces after commas. See the test cases for a better understanding:

// CANONICAL TYPE
bytes32 constant _PERMIT_SINGLE_TYPEHASH = keccak256(
    "PermitSingle(PermitDetails details,address spender,uint256 sigDeadline)PermitDetails(address token,uint160 amount,uint48 expiration,uint48 nonce)"
);

function test_canHashCanonicalTypes() public {
    typeHash = vm.eip712HashType(
        "PermitSingle(PermitDetails details,address spender,uint256 sigDeadline)PermitDetails(address token,uint160 amount,uint48 expiration,uint48 nonce)"
    );
    assertEq(typeHash, _PERMIT_SINGLE_TYPEHASH);
}

function test_canHashMessyTypes() public {
    typeHash = vm.eip712HashType(
        "PermitDetails(address token, uint160 amount, uint48 expiration, uint48 nonce) PermitSingle(PermitDetails details, address spender, uint256 sigDeadline)"
    );
    assertEq(typeHash, _PERMIT_SINGLE_TYPEHASH);
}

@0xrusowsky 0xrusowsky self-assigned this May 9, 2025
@0xrusowsky 0xrusowsky added the A-cheatcodes Area: cheatcodes label May 9, 2025
@0xrusowsky 0xrusowsky requested a review from zerosnacks as a code owner May 9, 2025 16:16
@0xrusowsky 0xrusowsky linked an issue May 9, 2025 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-cheatcodes Area: cheatcodes
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

Cheatcode: EIP712 canonical hashing
2 participants