Introduction
Hi, I'm cardene, a software engineer and technical writer focused on blockchain and AI.
I've also authored Japanese technical books on specification-driven development with LLMs and decentralized application (DApp) development.
I also build and publish a variety of tools, libraries, and open-source projects.
This article explains ERC7739, which standardizes a way to prevent signature replay when a single EOA manages multiple smart accounts by combining defensive rehashing with EIP-712 typed data.
This article translates, summarizes, and expands on the specification below.
I also cover other EIPs:
Overview
ERC7739 defines a standard for preventing signature replay attacks when one externally owned account (EOA) owns multiple smart accounts. A replay attack occurs when a previously used signature is reused to authorize an unintended transaction. As a defense, it introduces defensive rehashing into ERC1271 signature verification using nested EIP712 typed structures. This preserves a human-readable representation of the data in wallet signing requests.
Motivation
Smart accounts verify signatures using the isValidSignature function defined by ERC1271.
A naive implementation is vulnerable when a single EOA manages multiple smart accounts: if the signed data does not include the smart account address, the same signature may be valid for another account and can therefore be replayed.
For more on ERC1271, see the following article.
[ERC1271] How Contracts Verify Signatures
This issue can arise in widely used applications such as Permit2. Many smart account implementations therefore use defensive rehashing to incorporate additional information into the hash:
- The original hash
- The smart account's own address
- The chain ID
This prevents a signature from being accepted by a different account or on a different chain. However, a naive implementation using EIP712 can obscure the data being signed, leaving the user unable to read it in the wallet client.
For more on EIP712, see the following article.
[EIP712] Hashing and Signing Typed Structured Data
With the ERC7739 approach, wallets supporting EIP712 can display the signing payload without changes to existing wallet clients or application front ends. When necessary, users can also enable defensive rehashing by adding client-side JavaScript.
Specification
ERC7739 specifies how to introduce defensive rehashing into signature verification in the ERC1271 isValidSignature function.
The goal is to prevent signature replay attacks when one EOA owns multiple smart accounts while allowing the wallet to display the data being signed.
The mechanism defines two workflows:
- TypedDataSign workflow (EIP712 signatures)
- PersonalSign workflow (EIP191 signatures)
Each workflow has a different final hash calculation and signature format.
For more on EIP191, see the following article.
[ERC191] Using Signed Data Safely
Required specifications
Implementing this standard requires the following:
- EIP712
- Defines hashing and signing of typed structured data.
- Provides the logic for constructing the final hash.
- ERC1271
- Defines the standard method for verifying contract signatures, including the
isValidSignature(bytes32 hash, bytes calldata signature)function.
- Defines the standard method for verifying contract signatures, including the
- ERC5267
- Specifies how to retrieve EIP712 domain information.
- The
eip712Domain()function retrieves domain information for use in the final hash calculation.
For more on ERC5267, see the following article.
[ERC5267] Providing the Information Needed to Construct an EIP712 Domain
TypedDataSign workflow
This workflow rehashes the original EIP712 hash with information specific to the smart account. The result is a different signature for each account and chain, preventing replay attacks.
Final hash calculation
keccak256(
\x19\x01 ‖ APP_DOMAIN_SEPARATOR ‖
hashStruct(TypedDataSign({
contents: hashStruct(originalStruct),
name: eip712Domain().name,
version: eip712Domain().version,
chainId: eip712Domain().chainId,
verifyingContract: eip712Domain().verifyingContract,
salt: eip712Domain().salt
}))
)This expression shows how to construct the final hash to be signed.
The new hash includes both the original data (originalStruct) and information specific to the smart account (domain information and account-specific constants). This prevents signature replay while retaining the readable EIP712 signing format.
The calculation concatenates the EIP712 \x19\x01 prefix, the application's domain separator (APP_DOMAIN_SEPARATOR), and the hash of the TypedDataSign structure, then hashes the result with keccak256.
Calculation steps
- Fixed prefix
\x19\x01
This identifier is defined by EIP712 and indicates that the data is intended for typed structured data signing.
APP_DOMAIN_SEPARATOR
This is the application-specific domain identifier. Including it prevents the same structured data from being reused in another application or for another purpose.
hashStruct(TypedDataSign({...}))
Hash the newly defined TypedDataSign structure, which contains the following fields:
contents- Hash of the original data structure (
originalStruct).
- Hash of the original data structure (
name- Hash of the
eip712Domain().namestring.
- Hash of the
version- Hash of the domain version string.
chainId- Chain ID.
verifyingContract- Address of the contract performing verification.
salt- A domain-specific 32-byte identifier.
The resulting hash thus incorporates the original data, account-specific information, and chain-specific information.
Solidity implementation example
finalTypedDataSignHash =
keccak256(
abi.encodePacked(
hex"1901", // (1) 固定プレフィックス
bytes32(APP_DOMAIN_SEPARATOR), // (2) アプリ固有ドメイン
keccak256( // (3) TypedDataSign構造体のハッシュ
abi.encode(
typedDataSignTypehash, // 型情報のハッシュ
bytes32(hashStruct(originalStruct)), // 元構造体のハッシュ
keccak256(bytes(eip712Domain().name)),
keccak256(bytes(eip712Domain().version)),
uint256(eip712Domain().chainId),
uint256(uint160(eip712Domain().verifyingContract)),
bytes32(eip712Domain().salt)
)
)
)
);Calculating typedDataSignTypehash
typedDataSignTypehash is the hash of the type definition of the TypedDataSign structure.
It enables the wallet client to understand the type structure of the data being signed.
The calculation is as follows:
typedDataSignTypehash =
keccak256(
abi.encodePacked(
"TypedDataSign(",
contentsName, " contents,", // ユーザー定義型のフィールド
"string name,",
"string version,",
"uint256 chainId,",
"address verifyingContract,",
"bytes32 salt"
")",
contentsType // contentsNameの完全な型定義
)
);contentsName is the substring of contentsType (for example, "Mail(address from,address to,string message)") before the first "(".
For example:
contentsType→"Mail(address from,address to,string message)"contentsName→"Mail"
The code extracts it using the LibString library's slice and indexOf functions.
contentsName =
LibString.slice(
contentsType, // 対象文字列
0, // 開始位置(先頭)
LibString.indexOf(contentsType, "(") // "(" の位置まで
);For security, signatures should be rejected when contentsName is empty or contains certain invalid characters.
Signature format
The signature passed to isValidSignature is extended as follows:
originalSignature ‖ APP_DOMAIN_SEPARATOR ‖ contents ‖ contentsDescription ‖ uint16(contentsDescription.length)Solidity implementation example:
signature =
abi.encodePacked(
bytes(originalSignature),
bytes32(APP_DOMAIN_SEPARATOR),
bytes32(contents),
bytes(contentsDescription),
uint16(contentsDescription.length)
);Using APP_DOMAIN_SEPARATOR and contents, verify that the hash is correct with the following expression:
hash == keccak256(
abi.encodePacked(
hex"1901",
bytes32(APP_DOMAIN_SEPARATOR),
bytes32(contents)
)
)If the hashes do not match, the signature and hash are invalid.
PersonalSign workflow
This workflow handles EIP191 signatures and generates a hash that includes the Ethereum message signing prefix.
The PersonalSign workflow wraps the EIP191 format, commonly used for plain message signing (personal_sign/eth_sign), in an EIP712-style structure to bind it to the smart account's own domain.
This prevents the same message from being replayed in a different smart account or chain context while maintaining compatibility: the application can still pass just the EIP191 hash (hash) as before.
Final hash calculation
keccak256(
\x19\x01 ‖ ACCOUNT_DOMAIN_SEPARATOR ‖
hashStruct(PersonalSign({
prefixed: keccak256(bytes(
\x19Ethereum Signed Message:\n ‖
base10(len) ‖
someString
))
}))
)\x19\x01is the EIP712 identifier prefix.ACCOUNT_DOMAIN_SEPARATORis the smart account's own EIP712 domain identifier (derived from ERC5267'seip712Domain()).- It binds the signature to the account and chain.
- The simple, single-field type
PersonalSign(bytes prefixed)wraps the EIP191 prefixed message hash.- This is the
hashStruct(PersonalSign({...}))portion.
- This is the
Solidity implementation example
finalPersonalSignHash =
keccak256(
abi.encodePacked(
hex"1901", // 1) EIP-712識別プレフィックス
bytes32(ACCOUNT_DOMAIN_SEPARATOR), // 2) スマートアカウント固有のドメイン
keccak256(
abi.encode(
keccak256("PersonalSign(bytes prefixed)"), // 3) 型定義のtypehash
hash // 4) EIP-191のメッセージハッシュ
)
)
)
);Here, hash is calculated by the application contract.
For example:
hash = keccak256(
abi.encodePacked(
"\x19Ethereum Signed Message:\n",
LibString.toString(someString.length), // 10進ASCIIで長さ
someString // 元メッセージの生バイト列
)
);hashis the keccak256 hash of the manually concatenated EIP191 prefix ("\x19Ethereum Signed Message:\n" + decimal length + message). The length is represented as decimal ASCII rather than hexadecimal (for example,"5"or"32").someStringis treated as its raw byte sequence.- For a string, these are the raw UTF-8 bytes; arbitrary binary data is also supported.
- The smart account does not need to know how
hashwas generated.- It simply receives the
hashcalculated by the application and wraps it again.
- It simply receives the
PersonalSign does not require the additional data used by TypedDataSign.
Why wrap the hash using EIP712?
PersonalSign does not include metadata about who signed the message or in what context.
Using EIP712 allows domain information, such as the account address, chain ID, and version, to be incorporated into the final hash through ACCOUNT_DOMAIN_SEPARATOR.
As a result, even the same hash fails verification on another account or chain, preventing replay attacks.
Implementation steps
- The application calculates
hashaccording to EIP191 (see the example above). - The smart account prepares
ACCOUNT_DOMAIN_SEPARATOR(which can be calculated fromeip712Domain()information). - Use
keccak256("PersonalSign(bytes prefixed)")as the typehash and hashabi.encode(typehash, hash)with keccak256. - Concatenate
hex"1901" || ACCOUNT_DOMAIN_SEPARATOR || (result of step 3)usingabi.encodePackedand hash the result with keccak256.- This is
finalPersonalSignHash.
- This is
- Verify the signature against
finalPersonalSignHashusingecrecoveror another method according to the internal ERC-1271 verification policy.
Support detection
A smart account implementing this standard indicates support by returning a specific value for the following call:
isValidSignature(
0x7739773977397739773977397739773977397739773977397739773977397739,
""
)
// => bytes4(0x77390001)This value is incremented for future updates.
Workflow detection logic
Because the function signature of isValidSignature remains unchanged, the signature data determines which workflow to use.
if (
hash == keccak256(
abi.encodePacked(
hex"1901",
bytes32(APP_DOMAIN_SEPARATOR),
bytes32(contents)
)
)
) {
// TypedDataSign ワークフロー
} else {
// PersonalSign ワークフロー
}When defensive rehashing can be skipped
Defensive rehashing can be skipped in the following cases:
isValidSignatureis called off-chain.- The supplied
hashalready includes the smart account address.
This allows existing applications that do not support the new specification to continue using conventional verification when it is safe to do so.
Additional details
Design rationale for the TypedDataSign structure
typedDataSignTypehash must be generated dynamically on-chain.
This allows users to inspect the data in their wallet during a signing request and ensures that contents is a user-defined type.
The fields of eip712Domain are also expanded directly within the TypedDataSign structure.
This avoids type collisions when the domain type on the verifyingContract side differs.
Furthermore, the bytes1 bitmap field and uint256[] extensions array found in ERC5267 are omitted.
Although these distinguish missing fields from zero values, they do not improve the security of defensive rehashing.
extensions is used to communicate EIP numbers off-chain.
Implicit and explicit modes for contentsDescription
When the contents structure includes nested types, EIP712 lexicographic sorting can result in contentsName not appearing at the start of contentsType.
An explicit mode is required to handle such cases.
The implicit mode is used when contentsType begins with contentsName.
Support detection through isValidSignature
To simplify implementation in modular smart accounts, the standard uses a particular magic value returned by isValidSignature rather than defining a new function.
This makes it possible to detect support without an additional interface definition.
Restrictions on the first character of contentsName
Signatures should be rejected if contentsName begins with a lowercase 7-bit ASCII character.
This is intended to preserve compatibility across languages and allow future extensions.
For example, a type written as uint256 in Solidity may have a different name, such as u256, in another language.
Compatibility
Differences from earlier drafts
An earlier draft defined a supportsNestedTypedDataSign() function for support detection that returned bytes4(0xd620c85a).
The specification described here replaces that approach with a magic value returned by isValidSignature.
This minimizes changes to existing ERC1271-compatible code and makes migration easier.
Security
Rejecting invalid contentsName values
Major implementations using eth_signTypedData do not always strictly validate custom type names (contentsName).
A malicious website could therefore supply a contentsName containing control characters or special symbols to deliberately corrupt the type definition in the EIP712 signing data.
This may prevent the wallet client from displaying the correct type structure, leaving the user with only an opaque hash to sign.
This is a form of phishing in which users are induced to sign without understanding what they are signing.
Smart contracts should therefore validate contentsName and reject invalid strings.
Doing so closes this attack vector.
Inability to chain multiple signers using the same scheme
An account adopting this mechanism as an ERC1271 signature replay defense cannot compose it with another signer using the same mechanism.
This is because the TypedDataSign structure contains the type of the message being signed.
If that message were another TypedDataSign structure, the EIP712 message would contain two distinct types named TypedDataSign.
The EIP712 specification does not allow both type definitions to be represented in a single signing request.
Consequently, the same defensive rehashing scheme cannot be composed hierarchically across multiple signers.
References
vectorized (@vectorized), Sihoon Lee (@push0ebp), Francisco Giordano (@frangio), Hadrien Croubois (@Amxx), Ernesto García (@ernestognw), Im Juno (@junomonster), howydev (@howydev), Atarpara (@Atarpara), 0xcuriousapple (@0xcuriousapple), "ERC-7739: Readable Typed Signatures for Smart Accounts [DRAFT]," Ethereum Improvement Proposals, no. 7739, May 2024. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-7739.
Conclusion
ERC7739 standardizes a way to prevent signature replay across multiple smart accounts managed by a single EOA by combining defensive rehashing with nested EIP-712 typed data.
If you have questions, feel free to reach out by direct message on Twitter.
I also publish on the following platforms:



