ERC-3135 Dedicated claimable token (Exclusive Claimable Token)
Stagnant · Tokens · created 2020-08-10
A micropayment standard that adds signature based claiming to ERC-20 tokens, letting an issuer claim a user's spend on chain using only the user's off chain signature.
Why it is needed
A small business building a blockchain payment system has only two options. Paying directly with tokens means paying gas and waiting for transaction confirmation every single time. A micropayment channel approach, where tokens are locked in a payment contract and spend amounts are released via off chain signatures, reduces blockchain interaction but places a heavy burden on resource constrained small businesses, since the issuer must build their own dApp. These payment contracts also vary by provider and are not standardized, and users must learn to use a wallet with a dApp browser. ERC-3135 proposes building this micropayment interaction directly into the token standard itself, so wallets can build a generic UI for it.
What to implement
function iconUrl() external view returns (string memory);: Returns this token's image URL or descriptive materials.function issuer() external view returns (address);: Returns the issuer address for this token. Only the issuer can execute claim.function claim(address from, uint256 consumption, uint256 epoch, bytes calldata signature) external;: The issuer deducts and takes the spend amount, confirmed by signature, from the payer's deposit balance.function transferIssuer(address newIssuer) external;: Transfers issuer privileges to a new address.function deposit(uint256 amount) external;: Moves an amount from the token balance into the deposit balance to fund payments.function withdraw(address to, uint256 amount) external;: Returns the remaining deposit balance to a specified account (acts as a refund).function depositBalanceOf(address user) external view returns(uint256 depositBalance, uint256 epoch);: Returns a specific user's deposit balance and current epoch number.
In depth
The claim function and epoch structure
claim(from, consumption, epoch, signature) executes only after confirming that msg.sender is the issuer. consumption is the amount spent in that epoch, and epoch increments by 1 each time claim or withdraw is executed, with the consumption amount reset to 0 at the start of each epoch. The example implementation checks that the epoch matches with require(_depositBalance[from].epoch + 1 == epoch), then deducts the credit from the deposit balance and adds it to the issuer's balance.
Structure of the signed message
ECDSA signatures are created over keccak256(abi_encode(token_address, payer_address, token_issuer, token_consumption, epoch)), rehashed together with the Ethereum signed message prefix ("\x19Ethereum Signed Message:\n32"). At claim time, the issuer reconstructs the message the same way and checks that the address recovered via recoverSigner matches from.
The verification server's serving/verification loop
The serving_loop requires the user to top up and halts service if unpaid_consumption exceeds the signature-confirmed signed_consumption by more than the tolerance. The verification_loop recovers the signer address for each incoming message, checks that it matches payer_address and that the epoch and deposit balance are valid, and then stores the message.
deposit and withdraw
deposit moves part of a token balance into the deposit balance to fund payments (example implementation: require(value <= _balances[msg.sender])). withdraw is a refund function that returns the remaining deposit balance to the "to" account; who can call it depends on the business model.
The prepayment model and the lock-release model
The prepayment model works like a gift card: the user tops up in advance and signs cumulative consumption with each payment, and when the card is returned the issuer (merchant) calls withdraw to return the balance. The lock-release model is used for usage-based services such as sending email. When the client does not trust the server's billing it can stop signing, in which case the design has the user call withdraw directly to reclaim the deposit if there is no epoch change for a set period (e.g. one month).
Why this is implemented directly in the token contract
This EIP puts deposit/claim/withdraw directly into the token contract itself instead of a separate payment-record contract. The original text gives as reasons that token transfers are more universal than dapp interaction, have better UI support, and that making the token itself the service can energize the token economy and eliminate the approve step. It targets ERC-20 but is designed to be compatible with other token standards as well.
Current status
Since being written in August 2020, this proposal has remained in Stagnant status: it is not a finalized or actively adopted standard but a stalled proposal.
Things to watch out for
- Double payment across multiple verification servers: Restricting claim to the issuer removes any on-chain race condition, but if the issuer runs multiple verification servers and a payer signs several payment messages at the same time, more than one message could be validated as valid simultaneously. However, only the single message with the largest consumption amount can actually be claimed, and the original text proposes guarding against this by having the verification servers exchange messages through an echo server that always synchronizes to the message with the largest consumption and epoch.