ERC-2876 Deposit-only address / contract standard (Deposit contract and address standard)
Stagnant · Accounts & wallets · created 2020-08-13
A standard that lets exchanges or merchants distinguish incoming ETH deposits per depositor, without creating a new account for each one, using a new address format that appends an 8-byte identifier to a 20-byte address together with a deposit-only contract.
Why it is needed
Exchanges or merchants need to give each depositor or invoice a distinguishable address. Previously, this required creating a new externally owned account or contract address each time; using an externally owned account means keeping the signing key in a hot wallet exposed to the network, raising security risk, while operating with a cold wallet requires manual labor to sweep funds one by one from thousands of accounts. Conversely, deploying a new contract for every deposit costs at least 60,000 gas, which is too expensive. The higher network gas fees rise, the more services are pushed to give up security and choose hot wallets. This standard aims to eliminate the dilemma between security, cost, and manual labor by distinguishing depositors using just a single contract and address format.
What to implement
function deposit(bytes8 id) external payable returns (bool);: Takes the ETH sent by the depositor and the 8-byte identifier (id), and returns true if payment is complete, false if it is still incomplete as with a partial payment, and reverts if the deposit itself fails.
In depth
Generating the deposit address format
The 28-byte deposit address is made by appending a 5-byte nonce to the 20-byte contract address, then appending as a checksum the first 3 bytes of the keccak256 hash of the 25 bytes (address+nonce). That is, the structure is baseAddress + nonce + keccak256(baseAddress+nonce)[:3].
Checksum verification
Inside the contract, a function like checksumMatch(bytes8 id) can verify by concatenating its own address (address(this)) with the first 5 bytes (nonce) of the id, taking the first 3 bytes of the keccak256 of that, and comparing it with the last 3 bytes of the id. deposit(bytes8) SHOULD check this checksum.
Rules the contract must follow
The contract MUST revert if it receives a pure value transaction with empty msg.data. deposit(bytes8) must hold the value and return false if payment is not yet complete, revert if the deposit itself fails such that the value should not be held, and return true if the value is held and payment is complete.
Rules the wallet must follow
Wallets must accept the deposit address format anywhere they accept a 20-byte address, and must fail if the 3-byte checksum does not match. If the destination is a deposit address format but the data field already contains a different value, the wallet must fail. The transaction's to must be set to the first 20 bytes of the deposit address, and data must be set to the 4-byte function selector 0x3ef8e69a followed by the last 8 bytes (id) of the deposit address, with the remainder zero-padded.
Rationale for the 8-byte id structure
The id is split into a 5-byte nonce and a 3-byte checksum. The 24-bit checksum is safer than the average 15-bit checksum of EIP-55 addresses, and the 40-bit nonce supports more than one trillion deposit addresses. The total length was set to 64 bits to provide sufficient checksum and nonce space while staying under 256 bits, keeping the gas cost of hash operations low.
ETH only, ERC-20 out of scope
This standard covers only native ETH transfers and does not support other token protocols such as ERC-20. Since exchanges and merchants separating wallets logically or by key per currency is accounting and security best practice, using a separate approach for ERC-20 is acceptable. Applying the same approach to ERC-20 would require modifying the transfer function itself, which would make the scope too large.
Overpayment and backward compatibility
If a deposit id is a one-time invoice for a fixed amount and the amount received is greater, the app should not immediately return the excess to msg.sender, but should record it internally and contact the depositor separately to resolve it. Also, because existing wallets that do not support this address format will not recognize it as a valid address, technically savvy users must verify the checksum themselves and manually enter the data field.
Proposal status
This proposal is in Stagnant status, meaning discussion is no longer progressing and has stalled.
Things to watch out for
- Fixed cold wallet address: The contract must hold the cold wallet address to which received funds are forwarded as a hardcoded constant, or use the immutable keyword from Solidity 0.6.5 or later so it cannot be changed after deployment.
- Using a kill switch instead of selfdestruct: Since deposits can still arrive after a service is shut down, the contract should use a kill switch that reverts all deposit(bytes8) calls rather than using selfdestruct(address). If selfdestruct is used, value sent by an external account is accepted regardless of calldata, turning the contract into a black hole that swallows new deposits.