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 examines ERC5630, a proposal for a common interface for securely encrypting and decrypting messages using Ethereum wallet keys.
This article translates, summarizes, and expands on the following proposal.
I've also written about other EIPs, BIPs, SLIPs, CAIPs, ENSIPs, RFCs, and ACPs.
Overview
ERC5630 proposes a new way to perform encryption and decryption using Ethereum keys (the private and public key pair associated with an account). It uses only secp256k1, the elliptic curve (the mathematical foundation of public-key cryptography) already used for Ethereum signatures. The proposal centers on two new RPC methods. RPC stands for remote procedure call, a standard interface for invoking predefined functions on wallets or nodes.
eth_getEncryptionPublicKeyRetrieves the public key used for encryption. This lets the sender encrypt data for the recipient's key.eth_performECDHThe wallet performs only ECDH (elliptic-curve Diffie–Hellman, a procedure for securely establishing a shared secret between two parties). The resulting shared secret can then be used for decryption.
Together, these methods allow users to receive encrypted data and use their wallets to decrypt it. A central design decision is that the wallet performs only the core ECDH computation, while implementers handle the subsequent ECIES (Elliptic Curve Integrated Encryption Scheme, the sequence of operations that produces or decrypts ciphertext from a shared secret). A recommended configuration is provided, but it is not mandatory.
Some earlier EIPs used the same private key for signing and encryption across two different curves (secp256k1 and ec25519) and also prescribed a specific ECIES scheme. ERC5630 separates these responsibilities by using secp256k1 throughout and limiting the wallet's role to the minimal ECDH computation.
Motivation
One motivation is encryption directly to an Ethereum address. With ERC5630, a sender can deliver an encrypted message onchain to a particular recipient without having established a dedicated communication channel beforehand. The proposal standardizes only how ciphertext is produced, not how it is transmitted onchain. Ideally, a smart contract infrastructure would exist for this purpose. In its absence, ciphertext can also be placed in the raw data field of a transaction.
Another common design pattern arises when a dApp generates a new secret for a user, such as a new key or shared secret. Asking the user to store and back up that secret separately creates extra work and introduces the risk of losing it. With ERC5630, the new secret can instead be encrypted to a public key controlled by the user, whose corresponding private key belongs to the user's HD wallet hierarchy. An HD (hierarchical deterministic) wallet systematically derives many keys from a single seed phrase. The resulting ciphertext can be stored somewhere safe, such as onchain. The security of the new secret then rests on the security of the seed phrase the user already protects. Users do not have to manage additional key material separately, substantially reducing friction in the user experience (UX). This design pattern is already used by several dApps, including Tornado Cash.
Specification
Choice of elliptic curve and encryption scheme
ERC5630 uses the same elliptic curve for encryption as Ethereum uses for signatures: secp256k1.
secp256k1 is a familiar elliptic curve used in elliptic-curve cryptography (ECC) by Ethereum and Bitcoin.
The encryption scheme is ECIES. ECIES is a hybrid encryption scheme based on elliptic-curve cryptography, broadly consisting of the following operations.
- Establish a shared secret using elliptic-curve Diffie–Hellman (ECDH).
- Derive symmetric keys from that shared secret using a key derivation function (KDF).
- Encrypt the actual data with a symmetric cipher such as AES.
- Where appropriate, use a message authentication mechanism such as HMAC to detect tampering.
A key principle of ERC5630 is to give wallets only the simplest security-critical responsibilities. Specifically, wallets handle only the core ECDH computation. ECDH computes a shared secret known to the two parties from one's own private key and the other party's public key.
The wallet performs only the computation of the ECDH secret. The surrounding operations are left to implementers of dApps and libraries, including the following.
- The ECIES configuration (the choice of KDF, HMAC, and AES mode).
- The ciphertext structure.
- The assembly of the decryption procedure.
This keeps wallet implementations lightweight while allowing applications to choose an ECIES variant appropriate to their requirements.
Data representation and serialization
ERC5630 specifies the data formats used for communication and RPC parameters precisely.
All binary data is exchanged as hexadecimal strings prefixed with 0x.
Examples include the following.
- Binary data in general Hexadecimal strings with a 0x prefix.
- Private and public keys Also represented as hexadecimal strings with a 0x prefix.
- Public key format Represented in compressed form.
- Ethereum accounts
Standard 20-byte hexadecimal strings (addresses) beginning with
0x.
A compressed public key encodes the x-coordinate of an elliptic-curve point (x, y) together with the parity of its y-coordinate (even or odd). This reduces the public key to approximately 33 bytes.
Serialization (converting a point to bytes) and deserialization (recovering a point from bytes) must follow Section 2.3.3 of the standard SEC 1: Elliptic Curve Cryptography, by Daniel R. L. Brown.
Deserialization must satisfy the following conditions.
- The input byte string must have a length of ⌈log₂q / 8⌉ + 1 = 33 bytes. Here q is the elliptic-curve order; for secp256k1, this expression gives 33 bytes.
- The first byte must be
0x02or0x03. These prefixes identify compressed public keys: 0x02 indicates an even y-coordinate and 0x03 an odd one. - The remaining 32 bytes are interpreted as an integer that must fall between
0andp−1, inclusive.pis the prime used by secp256k1; values outside this range are invalid. - Furthermore, the expression for that x-coordinate must be a quadratic residue. A quadratic residue is a value that can be obtained by squaring another value. Checking this establishes that the point actually exists on the curve.
Wallets and libraries are therefore required to verify that compressed public keys are correctly formatted.
Recommended ECIES variant
ECIES defines a general framework, and individual variants differ in their choice of KDF, HMAC, and cipher. ERC5630 recommends a particular combination unless there is a reason to choose another.
The recommended configuration is as follows.
-
KDF (key derivation function): ANSI-X9.63-KDF + SHA-512
- ANSI-X9.63-KDF is a standardized key derivation function designed for use with elliptic-curve cryptography.
- SHA-512 is a member of the SHA-2 hash function family with a 512-bit output.
-
HMAC: HMAC–SHA-256–256, with a key length of 32 octets (256 bits)
- HMAC is a type of message authentication code used to detect tampering.
- This configuration uses SHA-256 internally, with a 256-bit output and a 256-bit key.
-
Symmetric cipher: AES–256 in CBC mode
- AES–256 is a symmetric block cipher with a 256-bit key.
- CBC is a block cipher mode that chains blocks during encryption and uses an initialization vector (IV) to improve security.
The proposal also specifies the following representation for ciphertext.
- ECIES ciphertext uses concatenated binary data.
- Elliptic-curve points included in ciphertext, such as the sender's ephemeral public key, are represented in compressed form.
In other words, the compressed public key, encrypted data, and authentication tag (such as an HMAC) are concatenated as binary data, and the result is represented as a 0x-prefixed hexadecimal string.
eth_getEncryptionPublicKey
This RPC method retrieves the encryption public key corresponding to the private key of a particular Ethereum address. It is the same key used for signing, but is explicitly retrieved for use in encryption as well.
Here is an example call.
request({
method: 'eth_getEncryptionPublicKey',
params: [account]
})Here, account is a 20-byte hexadecimal string beginning with 0x (a standard Ethereum address).
The client (wallet) handles the request as follows.
- For
account, look up the corresponding private keysk. If the wallet does not hold the private key for that account, return an error. - Compute the public key on the secp256k1 curve from the private key
sk. This is the same computation used for ordinary Ethereum signing keys. - Serialize the resulting public key as a compressed elliptic-curve point according to Section 2.3.3 of SEC 1. Return it as a 0x-prefixed hexadecimal string.
The method returns a public key suitable for encryption, enabling a dApp or another user to construct ECIES ciphertext for that address.
eth_performECDH
The other method, eth_performECDH, is an RPC method that asks the wallet to compute only the ECDH secret.
ECDH calculates a shared secret (a value known only to the two parties) from one's own private key and the other party's public key.
Here is an example call.
request({
method: 'eth_performECDH',
params: [account, ephemeralKey]
})Here, account is the Ethereum address described earlier, and ephemeralKey is an elliptic-curve point representing an ephemeral public key.
As specified above, ephemeralKey is a compressed elliptic-curve point represented as a 0x-prefixed hexadecimal string.
The client (wallet) processes the request as follows.
- For
account, look up the corresponding private keysk. If the corresponding private key does not exist, return an error. - Deserialize
ephemeralKeyas an elliptic-curve point according to Section 2.3.3 of SEC 1. Compressed form is mandatory; an invalid format results in an error. The length, first byte, coordinate range, and quadratic residue checks described earlier are performed. - Compute the ECDH shared secret according to Section 3.3.1 of SEC 1.
This involves scalar multiplication of the private key
skand the public keyephemeralKey, followed by extraction of the field element that constitutes the shared secret. - Serialize the resulting shared secret as a field element according to Section 2.3.5 of SEC 1. Return it as a 0x-prefixed hexadecimal string. Its length is fixed at 32 bytes.
The method returns a 32-byte value representing the shared secret obtained through ECDH. The application can pass this value to a KDF (such as ANSI-X9.63-KDF + SHA-512, described earlier) to derive symmetric keys for encryption and decryption.
The wallet's role is limited to keeping the private key internal and performing ECDH securely. All remaining ECIES logic is handled by the application.
Encryption to smart contracts
So far, we have considered encryption to EOAs, or wallet addresses controlled by users. However, with account abstraction proposals such as EIP4337 and the adoption of smart contract wallets, addresses increasingly correspond to smart contracts.
See the following article for more on ERC4337.
[ERC4337] Implementing Account Abstraction Without Protocol Changes
ERC5630 therefore also proposes a mechanism for smart contracts to advertise how data should be encrypted to them. It can be viewed as the encryption counterpart to EIP1271, the standard interface for signature verification. EIP-1271 allows a contract to decide whether a signature is valid for it; the proposed encryption interface expresses how ciphertext addressed to the contract should be constructed.
See the following article for more on EIP1271.
[ERC1271] Verifying Signatures in Smart Contracts
The proposed interface takes the following form in Solidity.
pragma solidity ^0.8.0;
contract ERC5630 {
/**
* @dev Should return an encryption of the provided plaintext, using the provided randomness.
* @param plaintext Plaintext to be encrypted
* @param randomness Entropy to be used during encryption
*/
function encryptTo(bytes memory plaintext, bytes32 randomness)
public
view
returns (bytes memory ciphertext);
}- A contract can implement a function called
encryptTo. This function encrypts the supplied plaintextplaintextusing the supplied randomnessrandomnessand returns the resultingciphertext. plaintextcontains the original data to be encrypted, supplied as an arbitrary byte string.randomnessis random data or additional entropy (an unpredictable value) used to strengthen encryption. For example, it can be used to generate an ECIES ephemeral key or an IV.- Each contract may implement
encryptTousing a scheme of its choice. Unless there is a reason to choose another, the recommended ERC5630 ECIES variant is preferred (ANSI-X9.63-KDF + SHA-512, HMAC–SHA-256–256, AES-256-CBC, compressed public keys and concatenated serialization).
This mechanism lets a smart contract define its own rules for constructing ciphertext addressed to it and expose them through encryptTo.
A sending application can call the contract's encryptTo function to obtain ciphertext in the format the contract expects, avoiding mismatches between encryption schemes.
Additional notes
Security of curve and key reuse
ERC5630 uses secp256k1 for both signing and encryption and reuses the same private key for both operations.
By contrast, some earlier EIPs adopted the following configuration.
- Signing:
secp256k1 - Encryption:
ec25519 - The same private key for both operations.
This raises a substantial concern. There is no security proof for a scheme that reuses the same private key across different elliptic curves, making its risk difficult to assess even if no attacks are known.
ERC5630 adopts a different configuration: signing (ECDSA) and encryption (ECIES) use the same private key on the same curve (secp256k1). This construction has been studied previously, including the following research, which established security under specific assumptions.
- Degabriele, Lehmann, Paterson, Smart, Strefler (2011) This study analyzes the security of using the same key for signing and encryption in the EMV cryptographic scheme. It assesses the combination of ECDSA and ECIES on the same curve as secure in the generic group model.
Furthermore, this construction is used in the EMV payment system. Reusing the same curve and key for signing and encryption thus has precedent in both theory and practical deployment.
Retrieving public keys from onchain data
A major advantage of ERC5630 is that if an account has signed a transaction at least once, its public key can be recovered from onchain data.
Ethereum signatures (ECDSA) support public key recovery from signature values. This is a property of the signing algorithm: the information in a signature can be used to recover the public key.
Encryption is therefore possible when the following conditions hold.
- The account has sent at least one transaction in the past.
- Its signature can be read from the blockchain.
- The
secp256k1public key can be recovered from the signature.
The sender does not need a dedicated channel for obtaining the recipient's public key.
Why wallets perform only ECDH
ERC5630 restricts wallet operations to computing the ECDH secret. There are two reasons for this.
Flexibility
ECIES specifies only a structural framework, with multiple choices for the internal KDF, HMAC, and cipher. If the entire ECIES scheme were fixed in the wallet, implementers could not choose other variants, and upgrades would be difficult. By delegating only ECDH to wallets, implementers can choose ECIES variants on the application side.
Lightweight communication
The data handled by a wallet stays on the order of 32 bytes, which is particularly useful in the following circumstances.
- The plaintext or ciphertext is large.
- The client and wallet communicate over a network and need to minimize traffic.
Mobile wallets and browser extensions, for example, benefit from smaller data transfers.
Twist attacks on secp256k1
In a GitHub post, Christian Lundkvist raised concerns about twist attacks when using secp256k1.
A twist attack exploits a different curve called a twist to extract information about another party's secret.
ERC5630 explains why it considers this attack inapplicable as follows.
Twist attacks target classical ECDH rather than ECIES
A twist attack requires the following conditions.
- The attacker supplies a specially crafted point to the victim.
- The victim performs scalar multiplication of that point using their private key.
- The victim returns the resulting point to the attacker.
The proposal describes this sequence as applying only to classical Diffie–Hellman.
ECIES, by contrast, operates differently.
- Encryption side The private key used is an ephemeral key, and the proposal argues that disclosure of this key does not create the same concern.
- Decryption side The victim does not return the ECDH result to the attacker. It is used internally for AES decryption.
In other words, the condition necessary for a twist attack, returning the computation result to the attacker, is not met.
ERC5630 uses compressed public keys and can reject invalid points
A twist attack requires the attacker to supply a point that is not on the curve. However, ERC5630 restricts public key representations to compressed points.
Compressed representations have the following properties, which make it possible to reject points outside the curve.
- The first byte is 0x02 or 0x03.
- The remaining 32 bytes contain the coordinate.
- The coordinate is uniquely determined during decoding.
- A point cannot be reconstructed if it does not satisfy the curve equation.
The premise of the twist attack is therefore removed.
Mandatory validation that points lie on the curve
ERC5630 requires public key deserialization to verify that the point lies on the curve according to SEC 1.
- Format validation.
- Range validation of .
- A quadratic residue check against the curve equation.
These checks reject points that are not on the curve.
In addition to requiring compressed representations, which do not represent valid off-curve points, the proposal mandates strict validation to reject malicious inputs.
Compatibility
First, consider RPC method compatibility.
ERC5630 introduces eth_performECDH as a new RPC method.
Because eth_performECDH did not previously exist, it does not introduce the kind of compatibility problem in which a change to an existing specification alters the behavior of older wallets or dApps.
The situation is different for eth_getEncryptionPublicKey.
An earlier proposal introduced eth_getEncryptionPublicKey together with another method, eth_decrypt, which is unrelated to this proposal.
ERC5630 overrides the behavior of eth_getEncryptionPublicKey.
The following points are important.
- The encryption public key can be retrieved again at the time encryption is performed.
- Data encrypted with a public key retrieved under the new specification (new ciphertext) is decrypted using the ERC5630 ECIES scheme.
- Ciphertext produced under the earlier proposal can still be decrypted by an implementation of
eth_decryptthat supports that proposal.
Although the ciphertext construction rules change between the old and new schemes, previously generated ciphertext does not become unreadable. Furthermore, the earlier proposal never became a formal standard, and to the authors' knowledge, no non-deprecated implementations of it were in production.
For this reason, ERC5630 considers significant practical backward compatibility problems unlikely even if it overrides the behavior of eth_getEncryptionPublicKey.
Test cases
The following concrete example illustrates the sequence of operations envisioned by ERC5630.
It derives a public key from a private key, retrieves the encryption public key through eth_getEncryptionPublicKey, and demonstrates ECIES encryption and decryption.
Private key, address, and public key
First, the following secret signing key is supplied.
0x439047a312c8502d7dd276540e89fe6639d39da1d8466f79be390579d7eaa3b2The Ethereum address corresponding to this private key is as follows.
0x72682F2A3c160947696ac3c9CC48d290aa89549cComputing the public key on secp256k1 from this private key gives the following compressed representation.
0x03ff5763a2d3113229f2eda8305fae5cc1729e89037532a42df357437532770010We now have the complete set of an account's private key, address, and compressed public key.
Behavior of eth_getEncryptionPublicKey
The following example shows a client using eth_getEncryptionPublicKey to retrieve the encryption public key corresponding to this address.
request({
method: 'eth_getEncryptionPublicKey',
params: ["0x72682F2A3c160947696ac3c9CC48d290aa89549c"]
})A wallet conforming to ERC5630 behaves as follows.
- Look up the private key corresponding to the address supplied as a parameter.
- Compute the
secp256k1public key from the private key. - Serialize the public key in compressed form and return it as a hexadecimal string with a
0xprefix.
The response to the preceding request is as follows.
"0x03ff5763a2d3113229f2eda8305fae5cc1729e89037532a42df357437532770010"This matches the public key calculated earlier, demonstrating the expected behavior of eth_getEncryptionPublicKey.
Encryption with the public key (ECIES)
The next example uses this public key to encrypt a message. The plaintext is the following English sentence.
I use Firn Protocol to gain privacy on Ethereum.The encryptor uses the ECIES variant recommended by ERC5630 (ANSI-X9.63-KDF + SHA-512, HMAC–SHA-256–256, AES-256-CBC, compressed public keys and concatenated serialization). One possible resulting ciphertext is shown below.
"0x036f06f9355b0e3f7d2971da61834513d5870413d28a16d7d68ce05dc78744daf850e6c2af8fb38e3e31d679deac82bd12148332fa0e34aecb31981bd4fe8f7ac1b74866ce65cbe848ee7a9d39093e0de0bd8523a615af8d6a83bbd8541bf174f47b1ea2bd57396b4a950a0a2eb77af09e36bd5832b8841848a8b302bd816c41ce"This ciphertext begins with the compressed ephemeral public key used by ECIES, followed by the concatenated encrypted payload and authentication data.
Extracting the ephemeral public key during decryption
The decryptor first extracts the ephemeral public key from the ciphertext. In the preceding example, the first 33 bytes (66 hexadecimal characters plus the two-character 0x prefix, for a total of 68 characters) constitute the ephemeral public key.
The extracted ephemeral public key is as follows.
"0x036f06f9355b0e3f7d2971da61834513d5870413d28a16d7d68ce05dc78744daf8"This value is the public key of the ephemeral key pair generated by the sender for ECIES. The decryptor combines it with their own private key to perform ECDH and compute the shared secret.
Calling eth_performECDH
The decryptor calls eth_performECDH to delegate the ECDH computation to the wallet.
The request is as follows.
request({
method: 'eth_performECDH',
params: [
"0x72682F2A3c160947696ac3c9CC48d290aa89549c",
"0x036f06f9355b0e3f7d2971da61834513d5870413d28a16d7d68ce05dc78744daf8"
]
})- The first parameter is the address of the account holding the private key.
- The second parameter is the ephemeral public key extracted from the ciphertext.
The wallet performs the following operations according to the eth_performECDH specification.
- Look up the private key corresponding to the address.
- Deserialize the ephemeral public key as a compressed elliptic-curve point.
- Perform ECDH and calculate the shared secret (Diffie–Hellman secret).
- Serialize the result as a 32-byte field element and return it as a 0x-prefixed hexadecimal string.
In this example, the return value is as follows.
"0x4ad782e7409702101abe6d0279f242a2c545c46dd50a6704a4b9e3ae2730522e"This is the shared secret obtained through ECDH.
ECIES decryption and plaintext recovery
The decryptor uses this shared secret as input to a KDF to derive symmetric keys for AES-256-CBC and related operations. The remaining ciphertext (the encrypted data and authentication tag) is then used to perform decryption according to the ECIES variant recommended by ERC5630.
As a result, the original plaintext
I use Firn Protocol to gain privacy on Ethereum.is recovered.
This sequence of test cases illustrates how eth_getEncryptionPublicKey and eth_performECDH work together as specified to support ECIES encryption and decryption.
Security
ERC5630 relies on widely standardized cryptographic algorithms that have been studied and tested in practical deployments, rather than introducing proprietary schemes or experimental algorithms.
Specifically, these include the following.
- Elliptic curve: secp256k1 (a curve already used in Bitcoin and Ethereum).
- Signatures: ECDSA.
- Key agreement: ECDH.
- Hashing, KDF, and HMAC: SHA-2 family, ANSI-X9.63-KDF, and HMAC-SHA-256.
- Symmetric encryption: AES-256-CBC.
These are standard algorithms widely used in the cryptographic community and combined according to established practices.
Another important design decision is to limit wallet responsibilities to the core ECDH computation, reducing implementation complexity while keeping sensitive information (private keys) inside the wallet. The specification explicitly defines the inputs that must be validated, including the compressed public key format and whether the point lies on the curve, to reduce the scope for attacks arising from common implementation mistakes.
By combining existing standards and established algorithms and defining a minimal security-focused interface, ERC5630 aims to provide a robust cryptographic foundation.
Reference
Firn Protocol (@firnprotocol), Fried L. Trout, Weiji Guo (@weijiguo), "ERC-5630: New approach for encryption / decryption [DRAFT]," Ethereum Improvement Proposals, no. 5630, September 2022. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-5630.
Conclusion
This article has covered the proposal. I hope you found it useful.
If you have questions, feel free to contact me via Twitter DM.
I also publish on other platforms, so feel free to explore them.



