Repository navigation
fix(erc7739): order the wrapped contents type like the TypedDataSign type - #5487
erkancamli wants to merge 1 commit into
Conversation
|
@erkancamli is attempting to deploy a commit to the Wevm Team on Vercel. A member of the Team first needs to authorize it. |
🦋 Changeset detectedLatest commit: 2fa23e9 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
…type wrapTypedDataSignature put the contents struct first in contentsDescription, but the signed TypedDataSign type sorts it with its dependencies. An ERC-7739 verifier rebuilds the type from contentsDescription, so a typed data signature whose nested type sorts before the primary type (for example Permit2 PermitDetails and PermitSingle) did not verify. Send the contents type in the sorted order and use explicit mode when the primary type is not first.
5297606 to
2fa23e9
Compare
|
Rebased onto main to clear the |
|
Thanks @erkancamli, the fix is spot on! I carried your commit over to #5583 with a few small review fixes (one-sentence changeset, snapshot-based tests, and an on-chain PermitSingle check), so I'm closing this in favour of it. |
|
Thanks @jxom, the review fixes look good to me. Appreciate you carrying it over! |
wrapTypedDataSignatureappendscontentsTypebuilt withencodeType({ primaryType, types }), so the contents struct comes first and its dependencies follow. The owner signs theTypedDataSigntyped data fromerc7739/hashTypedData, and in that encoding the contents struct is a dependency ofTypedDataSign, so it is sorted by name together with its own dependencies. An ERC-7739 verifier rebuilds the typehash as"TypedDataSign(" ‖ contentsName ‖ " contents,...)" ‖ contentsTypefrom what was appended, so the two only match when the primary type also sorts first.When a nested type sorts before the primary type, the verifier hashes something else and
isValidSignaturefails. Permit2PermitSingleis an example:PermitDetailssorts first, so the signed type ends inPermitDetails(...)PermitSingle(...)while the appended one isPermitSingle(...)PermitDetails(...). The ERC covers this case: "When the contents structure contains nested types, EIP-712 lexicographical sorting can result in the contentsName not being positioned exactly at the start of the contentsType. As such, we need the explicit mode." Solady'sERC1271reads both modes.This reaches
toSoladySmartAccount().signTypedData, the ERC-7739signTypedDataaction anderc7739Actions.The change builds
contentsTypein the order of theTypedDataSignencoding and uses explicit mode (contentsType ‖ contentsName) only when the primary type is not first. When it is first (theMailfixtures, for example) the output is byte for byte the same as before.Tests
In
wrapTypedDataSignature.test.ts, a helper rebuilds the hash a verifier checks from the wrapped signature (implicit and explicit modes, per the ERC and Solady's parsing) and compares it witherc7739/hashTypedData:default(Mail): unchanged snapshot, and the hashes match before and afterbehavior: nested type sorts before the contents type(PermitSingle): fails onmain(417f2eb) and passes with the changeThe erc7739, signature and typed data suites give the same results before and after apart from the new test (the anvil tests could not run in my environment, and fail the same way on both).
tscand biome are clean. A changeset is included. I did not run an on-chainisValidSignaturecheck against a deployed account.The
v3branch copy insrc/erc4337/internal/erc7739.tsbuildscontentsTypethe same way.