Rationale (Full Text)
Rationale (Full Text)
This file accompanies the draft ERC “Serial-Numbered ERC-20 Tokens”. It is the full text of the draft’s “Rationale” section, of which the draft itself keeps a summary. Its subsections are the 37 that existed before the summary was written, and they do not map one to one onto the draft’s current subsections. A section name in quotation marks refers to a section of this file if there is one. Otherwise, the subsections of “Security Considerations” are given in full in security-considerations.md, and every other name refers to the section of that name in the draft. ERC and EIP numbers are not linked in this file.
Applicability
This proposal suits assets in which every unit represents the same right, with the same face value and the same terms, while some units need to be treated individually. Units differ only in whether they can be transferred out, to whom they can be transferred, and where they came from. The ERC-20 interface reports a balance as a single number, and wallets and exchanges that know only ERC-20 treat any two units as the same thing; serials give the question “which units are these?” an answer, but they do not change that.
The following scenarios meet this condition.
- Money for which action can be taken against specific funds, for example stablecoins and deposit receipts. Funds that were stolen or are involved in a case are frozen by slice, and the freeze remains in effect after they are split and change hands; a judicial freeze, a stop on payment and a pledge can coexist under different reasons. A freeze affects whoever holds those units at the time, not necessarily the party originally responsible (see “Freezing follows units, not people”).
- A single bond issue, or a single type of share. One contract corresponds to one issue. A pledge can be represented by a freeze, and the disposal of the collateral by a forced transfer; after the transfer the units are still frozen and have to be unfrozen by a party entitled to do so. The portion subject to a lock-up period can be represented by a class that the implementation defines itself and whose flow rule depends on time. Interest payments and redemption at maturity are outside the scope of this proposal.
- Funds that can only be paid to designated addresses, for example subsidies and consumption vouchers. These use a class that restricts destinations by payee address (see “Examples of classes”). When the constraint is set by a party other than the token’s issuer, and the token’s implementation offers that party no entry point for setting classes and rules, a wrapper contract is used instead (see “Classes and wrapper contracts”).
- A single asset whose batches or origins need to be told apart. These use classes without a flow rule.
- In-game currency. Currency produced by exploiting a bug or moved out of stolen accounts can be traced by serial, and only those units are frozen and destroyed, without rolling back the state of the whole game. The part of the currency that cannot be traded between players and can only be paid to the game’s own contracts can be represented by a class that restricts destinations by payee address.
- Points. Points of different origin or with different validity periods are distinguished by class; points that cannot be transferred between users and can only be used with the issuer and with merchants use a class that restricts destinations by payee address.
The following scenarios do not meet this condition, or meet it poorly.
- Measures against accounts. This proposal freezes specific units, not accounts. Blocking an address, or freezing a given amount in an account without saying which units, needs a separate account-based mechanism, such as those defined by ERC-3643 and ERC-7943. These can be used on the same token as this proposal (see “Freezing by serial rather than by account”).
- Assets with different rights in one contract, for example several bonds with different maturity dates or coupons, positions that each carry their own parameters, or the various items of a game together with gameplay that combines several items into another. Classes can only distinguish where units can go and where they come from (see “Classes do not represent different rights”). Such assets should use one contract each, or a standard that keeps separate accounts for each asset, for example ERC-3525, ERC-1155 and ERC-7518 (see “Classes are not partitions”).
- Tokens that charge a fee on transfer, or that change balances without issuance or destruction, for example tokens that scale all balances proportionally. They cannot conform to this proposal (see “Tightening the choices ERC-20 leaves open”).
- Assets that need privacy. The complete history of every unit is public (see “Reduced fungibility and privacy”).
Assets that suit this proposal also enter contracts with frequent transfers, such as market-making pools and lending pools; stablecoins are an example. A token that conforms to this proposal is an ERC-20 token, and these contracts interact with it as with any ERC-20 token (see “Backwards Compatibility”). Integrators need to consider three things in particular: the cost of a transfer grows with the number of slices (see “Fragmentation and gas”); units in a pool might later be frozen, and integrators should treat such a token as they would any token whose issuer can freeze funds (see “Freezing follows units, not people”); and units subject to a flow rule might be impossible to pay out (see “Destination-dependent flow rules and contracts”).
Serials and holders rather than note objects
The specification describes state as a mapping from serials to holders and says nothing about notes, outputs or how holdings are stored. Slices appear only as an encoding for events and views. This keeps the normative rules few and testable, and leaves implementations free to store holdings as stacks, linked lists or trees, to split and coalesce slices as they see fit, and to change those choices without affecting indexers.
Consecutive issuance and no renumbering on transfer
Because a transfer does not change the serials of the units it moves, the units descended from a holding are exactly the serials that holding consisted of. Transfers create no ancestry graph that has to be recorded or traversed: a holding that was the slice (start, amount) at some point in time is, at every later point, the same set of serials, however it is distributed among holders. This is the property that makes freezing by slice complete and free of races. In ledgers based on unspent outputs an output gets a new identity on every spend, so the same question needs a walk through the transaction graph.
Issuing serials consecutively from 0 makes serialsIssued() a complete description of which serials exist, so validity checks are a single comparison.
The only operation that renumbers units is a defragmentation. Exchanging several scattered slices for one new slice of consecutive serials gives units a new identity: to keep tracing them, the correspondence between old and new serials has to be recorded, which is exactly the ancestry graph described above. It also brings the race back: whoever holds stolen units could exchange them for new serials ahead of the freeze, and the freeze could then only land on old serials that are no longer in use. Defragmentation answers both points with rules: the correspondence is recorded in the contract, and freezes propagate along it, from the serials of every generation (see “Design of defragmentation”).
On a token that does not open defragmentation, where a holding really does need to be defragmented, the issuer can do it, much as small banknotes are taken to a bank and exchanged for large ones: the holder transfers the units to the issuer, the issuer burns them after confirming that they are not involved in anything that calls for a freeze, and then issues the same number of new units to the holder. Tracing is broken at this step, but the gatekeeper is the party entitled to freeze: the issuer can turn down suspicious units and can keep its own record of the correspondence between old and new serials. This uses only existing operations and needs no new interface.
Slices rather than individual serials
A token with 18 decimals has 10^18 serials per whole token. Events and views therefore describe slices. Reporting a sequence of consecutive identifiers in one event has a precedent in ERC-2309, which does so for ERC-721 token ids. Unlike that event, which is emitted instead of the ERC-721 Transfer event, the SliceTransferred event accompanies the ERC-20 Transfer event and never replaces it, so indexers that know only ERC-20 still see every movement. Non-adjacent slices cannot be combined without discarding the identity of the units between them, so an account that receives many separate payments holds many slices. This fragmentation is inherent to tracking unit identity and is discussed in “Security Considerations”.
The core sets no minimum transfer amount
The core interface sets no minimum transfer amount that applies to all accounts, even though dust imposes a cost on recipients (see “Dust attacks”). There are two reasons. First, payers and contracts that know only ERC-20 expect a transfer to succeed when the balance is sufficient; a token that rejects incoming transfers by amount would expose these callers to failure when paying any account at all. Second, a minimum amount does not stop fragmentation; it only makes each slice of dust cost a little more value, and that value goes to the recipient. The right threshold depends on what a unit is worth, which differs from token to token and changes over time; it also differs from account to account: a merchant that takes small payments wants to turn nothing away, while a vault or a pool would rather refuse small, scattered incoming transfers.
The core therefore does not make this choice for all tokens and leaves it to implementers and recipients. On a token that supports the acceptance check, a receiving contract can refuse by its own rules (see “Acceptance is decided by the receiving contract”); an implementation can also let an account set a limit for itself on the token (see “The acceptance check and failed payments”).
The cost of dust comes from the identity that this proposal preserves for every unit: every non-adjacent slice a recipient holds is a piece of history that has to be kept. This proposal chooses to keep it, and leaves the work of reducing the cost to the implementation’s storage layout and selection rule, to refusal by recipients, to the issuer’s policy, and to defragmentation by holders (see “Design of defragmentation”).
Acceptance is decided by the receiving contract
The cost of dust is introduced by the core interface. Receiving costs nothing in a plain ERC-20 token, whereas here every additional slice has a cost; for a contract that cannot split its own outgoing transfers, this cost can grow until a withdrawal no longer fits in one transaction (see “Fragmentation and gas”). This proposal therefore defines the acceptance check: a receiving contract can refuse incoming transfers, and the token asks it at transfer time.
The acceptance check is optional, and whether to support it is decided by the token’s implementer. What this proposal sets out to solve is the identity of units (see “Motivation”), so the core only adds serials to ERC-20 and does not change whether any transfer succeeds or fails; the rules that can make a transfer fail, namely freezing, classification and the acceptance check, are all optional. On a token that only registered accounts can hold, anonymous dust cannot get in, so the acceptance check has no use there. The price is that a receiving contract cannot count on every token that conforms to this proposal asking it: it has to use ERC-165 to find out whether a token supports the acceptance check, and on a token that does not, it has to rely on other means, for example paying out only units of its own choosing with transferSlices (see “Dust attacks”). Although the acceptance check is optional, there is only one way of asking: every token that supports the acceptance check behaves as “Acceptance check” specifies, so a receiving contract implements the interface once and it works on all such tokens.
Support for the acceptance check is declared with an agreed identifier, not one computed in the way ERC-165 defines, because the acceptance check has no function on the token side. ERC-4906 does the same: its interface has only events, and it specifies that supportsInterface returns true for a fixed value. This proposal takes the selector of the error ERC8527TransferRefused as that value.
To let a recipient decide whether to take a transfer, existing standards mostly use callbacks: ERC-721 and ERC-1155 call the receiving contract in safe transfers, ERC-777 calls a hook that the recipient has registered, and ERC-3525 calls a receiving contract that implements its receiver function when value is transferred. This proposal is closest to ERC-3525 and differs from these standards in several places.
- The check is attached to every form of transfer. ERC-721 checks the recipient only in
safeTransferFrom;transferFromdoes not check. Which path is taken is the sender’s choice, so such a check cannot stop anything that is sent on purpose. Like ERC-3525, this proposal has no separate safe transfer: every form of transfer initiated by a holder or by a spender is checked. - Only contracts that implement the acceptance interface are asked. If every receiving contract were required to implement a receiver function, as in ERC-1155, existing contracts that know only ERC-20 could not receive payments. Like ERC-3525, this proposal calls only recipients that implement the corresponding interface. The price is that every transfer to an address with code first has to query whether that address implements the acceptance interface, including transfers to contracts that do not implement it.
- ERC-165 determines whether the interface is implemented. If the way of determining this were not specified, “does not implement the receiver function” and “reverts to refuse” could not be told apart. Under ERC-165, only a contract that explicitly answers that it supports the interface counts as implementing it.
- It is a query, not a notification. The callbacks of ERC-721, ERC-1155, ERC-777 and ERC-3525 can all change state. Recipients often use them to do processing on receipt, for example bookkeeping, and refusing is only one of their uses; because they can change state, they can also call the token again during the transfer. The function in this proposal only answers whether the transfer is accepted. The token calls it with
STATICCALL: the called contract cannot emit an event or complete another transfer, so it does not disturb the attribution of events (see “External calls and event attribution”); wallets and payers can also call it in advance and get the same answer as at transfer time. The interface and the function therefore do not follow theReceiverandon...Receivedfamily of names and are calledIERC8527AcceptanceandacceptsERC8527Transferinstead. The price is that a receiving contract cannot record anything in the call; a contract that needs to act when it receives units can use the notification of ERC-1363, which a token can implement as well. Why this proposal defines no notification of its own is explained in “No receipt notification is defined”. - An agreed return value signals acceptance. This follows the practice of ERC-721, ERC-1155 and ERC-3525.
- Incoming transfers that the recipient pulls itself are not checked. A recipient that calls
transferFromitself has thereby consented. A contract can use this to require that all deposits go through its own entry point: it refuses every incoming transfer initiated by others and takes only those it pulls itself. - The receiving contract sees the number of slices. A recipient’s cost is counted per slice, not per amount (see “Dust attacks”). Given the amount and the number of slices, a receiving contract can refuse incoming transfers with too many slices, or require an average slice length of at least some value. The number of slices passed to it is the number of
SliceTransferredevents, not the number of non-adjacent slices. The former is a number the implementation already knows at transfer time; the latter can only be obtained by first sorting the selected slices and then merging adjacent ones. The number of events is at least the number of non-adjacent slices, so what the receiving contract sees is an upper bound.
A payer who wants to know in advance whether an incoming transfer would be refused can query to in the same way as the token does, setting the caller to the token contract’s address in the simulation, or can simulate the transfer. A receiving contract that refuses can revert with a custom error carrying parameters to say why, instead of returning another value; a party that queries it directly then sees why, and the token does not forward this error. In a transfer by amount the payer does not know in advance how many slices the contract will select and can only simulate. When naming serials with transferSlices, the payer knows how many non-adjacent slices it gave, but the contract can emit more events than that, because one slice can be stored in separate pieces in the sender’s holding. A receiving contract can change its answer at any time, so a query made in advance does not guarantee that the transfer that follows succeeds (see “The acceptance check and failed payments”).
How a receiving contract reaches its decision is not specified by this proposal. It can look only at the arguments of the call and its own state, or it can query other contracts read-only, oracles included. One possible scenario is the settlement of real-world assets: a settlement contract or an escrow contract accepts an incoming transfer only when an oracle confirms that the off-chain steps are complete, for example delivery, payment or a change of registration; when they are not, it refuses, and the whole transfer reverts. Such an answer changes with the state of the oracle, and a query made in advance likewise does not guarantee that the transfer that follows succeeds. The acceptance check expresses the recipient’s own conditions; an issuer’s conditions on the outgoing transfer itself, whoever it is paid to, have to be expressed with the flow rules of the classification extension or with the implementation’s own transfer restrictions. Under clause 6 of “Acceptance check”, the query can take place before the changes of holder or after them, so a receiving contract that reads token state can answer differently on different implementations.
Addresses without code and contracts that do not implement the acceptance interface receive payments as usual. The native currency behaves the same way: a transfer of native currency to an address without code always succeeds, whereas a contract can refuse it. A payer that knows only ERC-20 therefore fails only when, on a token that supports the acceptance check, it pays a contract that has chosen to refuse. Such a failure is still a cost, and it is discussed in “The acceptance check and failed payments”.
Restricted issuance and forced operations are not subject to the acceptance check. An issuer issuing units and an authorized party disposing of units act on their respective authority, not on the recipient’s wishes; sometimes the very purpose of a forced transfer is to hand units to an address that is unwilling to receive them. Issuance that anyone can trigger is different, for example a token that wraps another asset and mints to an arbitrary address against a deposit of that asset: if it were not constrained, dust could take this route instead.
ERC-3643 and ERC-7943 also restrict who can receive: the former requires the recipient to pass verification by an identity registry, and the latter uses canReceive to query whether an account can receive. Their rules are set by the issuer and apply to all accounts, and anonymous dust cannot get into such tokens. In this proposal, whether to accept is decided by each recipient for itself. The two can be used on the same token.
No registered checker is defined
An alternative is to let every account register a checker contract with the token, which the token calls on an incoming transfer. This is how ERC-777 finds the hook of each address, through a registry. With this approach, addresses without code can use arbitrary rules too. This proposal does not adopt it, for three reasons.
First, it requires every token to store every account’s registration and to provide a setter function, a query function and an event for it. The acceptance interface does not need the token to store anything, and it adds no function to the token.
Second, a shared checker contract raises a new question of trust. The party that controls it can prevent all of its registrants from receiving payments; and registering its address on a chain where it has not been deployed amounts to refusing everything.
Third, it is contracts that need rules of their own the most, and a contract can implement the acceptance interface itself. Addresses with code are not only contract accounts: an address that has set a delegation under EIP-7702 has code too, and when its delegation target implements the acceptance interface, it is a receiving contract as well.
Registration can be standardized later by another proposal without affecting this one: an implementation can already reject transfers on account-specific grounds (see clause 6 of “Transferable balance”). Conversely, a mechanism written into this proposal cannot be removed later.
No receipt notification is defined
The acceptance check is read-only, and the recipient cannot record anything in it. This proposal does not additionally define a notification that calls the recipient during a transfer and lets it change state. Such a notification comes in two forms, and this proposal considered both.
The first is chosen by the payer, payment by payment: the payer calls a dedicated function, and the token notifies the recipient after the transfer. This is the form that ERC-1363 defines, and a token can implement it as well: when a payer pays with its transferAndCall or transferFromAndCall, the token calls onTransferReceived on the recipient after the transfer, in which the recipient can change state; a plain transfer does not trigger this notification. ERC-1363 and the acceptance check do not replace each other: on a token that supports both, such a payment to a receiving contract has to be accepted by it, and it is also notified (for the timing of the notification, see “External calls and event attribution”). The ERC-1363 notification carries only the amount, not the serials. This proposal does not define a version of that notification that carries serials: such a notification happens only when the payer calls that dedicated function, whereas the transfer feature of a wallet usually calls transfer, so it does not help users who pay with nothing but a wallet.
The second is attached to the transfer itself: whichever function the payer calls, as long as the recipient has registered or implements the notification function, the token calls it, and the recipient can change state in the call. The hooks of ERC-777 and the receiver function of ERC-3525 are of this form. Users can thus interact with a contract using nothing but the transfer feature of a wallet. This proposal does not adopt it, for two reasons.
First, the risk falls on a party that did not choose it. When a transfer fails because of a freeze, a class or a refusal, what the caller sees is a revert, which every caller of ERC-20 has to handle anyway. A notification is different: any contract that holds such a token and pays it out runs the payee’s code when it pays, and in that code the payee can change state and can also call the paying contract again. A contract written to ERC-20 is not necessarily guarded against this, and it is the token and the payee that choose the notification, not that contract. The acceptance check is called with STATICCALL precisely so as not to bring in this risk (see “Acceptance is decided by the receiving contract”).
Second, the read-only acceptance check would no longer be the whole answer. If the notification can make a transfer fail, it is one more gate besides the acceptance check, and one that can change state: neither a wallet querying the recipient directly nor a paying contract querying it on-chain beforehand can then tell whether a transfer will succeed; only simulating the whole transfer can. If the notification cannot make a transfer fail, the token has to ignore the recipient’s failure: the transfer completes, yet the recipient has not completed its processing. The notification of ERC-1363 can also make a payment fail, but taking that path is the payer’s own choice.
Among the problems a notification is meant to solve, one is introduced by serials: a contract does not know which serials an incoming transfer brings. transfer and transferFrom return only a boolean, and the notification of ERC-1363 carries only the amount. sliceAt can list the slices the contract holds now, but the order of the slices is not specified (see “Enumeration”), and it does not say who sent each slice. This proposal provides no function by which a spender transfers by serial (see “Transfers by serial are part of the core”), so a contract cannot name the serials it wants to pull either. Having the payer transfer first and then declare the serials to the contract does not work reliably either: the contract can verify that it holds those serials (see “No on-chain lookup of the holder of a serial”) but cannot verify who sent them, and someone else can declare them first. Contracts that mix units together, for example pools, do not need to know any of this; custody contracts and contracts that have to return the original units do.
These contracts can do this without a notification. For example, the contract gives every payer a dedicated deposit address, to which the payer makes a plain transfer with a wallet; at this address there is a small contract deployed by the contract, which reads the slices it holds with sliceAt and transfers them to the main contract with transferSlices. All units held by this address are credited to that one payer, so there is no need to know who sent each slice. The complexity of this arrangement and the risk of its external calls stay with the contract that needs the feature; they are imposed neither on the token nor on the other contracts that use the token.
One event per slice rather than a batch event
When a transfer moves several slices, all of them could be reported in one event carrying two arrays, as TransferBatch does in ERC-1155, with the sender and the recipient recorded only once. This proposal does not do so. A transfer by amount usually moves a single slice, and an event with arrays has to encode, in addition, the offsets and lengths of the two arrays: at Ethereum’s current pricing of logs, it costs about 1,000 gas more when it reports a single slice. When many slices are moved, a batch event saves the repeated topics, but by then the bulk of the cost is the storage writes to holdings and the events are only a small part. If both encodings were allowed, every indexer would have to support both, and rules would be needed for attributing them to the same Transfer event and for deduplicating them. With a single encoding, indexers are simpler and the most common transfer is also the cheapest.
Relation to ERC-8047
ERC-8047, a draft at the time of writing, has the same aim as this proposal, on-chain traceability with enforcement against specific funds, and takes a graph approach. Every transfer creates a new token id that records its parent and its depth below a root. Its interface does not define freezing; the enforcement contract it gives as a reference freezes by root together with a depth or a bound on depths, or by individual id. This proposal differs in four respects.
- The token remains an ERC-20 token, so existing wallets, exchanges and contracts work with it unchanged.
- Transfers do not renumber units, so transfers create no graph that has to be maintained. The descendants of a holding are the serials it originally contained. Freezing each of its originally consecutive slices once names exactly those units and no others, however many people they have since been divided among. With the reference enforcement contract of ERC-8047, freezing funds that have already dispersed means either listing every one of their descendant ids, to which every transfer adds new ones, or freezing by root and depth, which also freezes funds on other branches under the same root. Only a defragmentation renumbers units: it is initiated by the holder or by a party the implementation permits, and an implementation can also perform it in the course of a transfer; it records a one-to-one correspondence from old serials to new ones, and the contract propagates freezes along that record, so the freezing party does not have to list descendants.
- Balances are on-chain. ERC-8047 records balances per id, an account holds as many ids as the payments it has received, and how much it can spend in total is expected to be computed off-chain by services that subscribe to events. This proposal provides
balanceOfon-chain, as well astransferableBalanceOf, which already takes freezes and flow rules into account. - Merging creates no new identity. ERC-8047 lets a holder merge several ids under the same root into one, and the merged id records only the deepest of its inputs as its parent. All inputs are recorded in events: the
TransferBatchthat destroys them and theTokenMergedthat associates them with the new id; whether merging across roots is allowed, and how it is recorded, is up to the implementation. After a merge, therefore, walking back along the parents finds only one origin, and the other origins have to be found in events. An implementation of this proposal can store adjacent serials as one slice, but the serials themselves do not change: units of different origin held by one account do not get a new identity by being put together, and a payment assembled from several sources does not join their histories. Without defragmentation, whether a unit comes from a given holding can be told from its serial alone (see “Consecutive issuance and no renumbering on transfer”); when a defragmentation renumbers units, it records the correspondence of every old serial to its new one, and there is no case in which only one origin is recorded.
The price is the same in both designs: holdings fragment, and the cost of a transfer depends on how many pieces it moves. In its security considerations, ERC-8047 suggests a minimum transfer threshold or a limit on the number of decimals to counter dust. It is not an ERC-20 token, so setting a threshold does not make existing ERC-20 callers fail. The core of this proposal sets no threshold (see “The core sets no minimum transfer amount”) and leaves the choice to implementers and recipients (see “Acceptance is decided by the receiving contract”); the choice of the number of decimals is discussed in “Dust attacks”.
Tightening the choices ERC-20 leaves open
ERC-20 is loosely worded in several places, and integrators have paid for that over the years. A new standard has no reason to carry these uncertainties over, so this proposal settles them without changing any function or event of ERC-20.
- Return values. ERC-20 allows failure to be signaled by returning
false, and some deployed tokens return no value at all. Callers therefore have to use dedicated wrapper code to handle every case. This proposal requires returningtrueon success and reverting on failure, so callers need to handle only one behavior. - Name, symbol and decimals. They are optional in ERC-20, but a wallet cannot display amounts without
decimals. In this proposal one serial corresponds to one smallest unit, and once the number of decimals changes, the quantity that a given serial represents changes with it, so the number of decimals must not change. - The zero address. In the model of this proposal the holder of a serial cannot be the zero address, so a transfer to the zero address can only mean destruction. Letting a plain transfer silently turn into destruction invites accidents, so it is forbidden, and destruction has to go through an explicit operation.
- Errors. ERC-6093 defines uniform errors for the common failures of ERC-20, from which wallets and tools can explain to users why an operation failed. This proposal recommends using them.
- Burning. ERC-20 defines no burn function, and later standards each defined a different signature, for example
burn(uint256,bytes)in ERC-777 andburn(address,uint256,bytes)in ERC-5679. For burning by amount, this proposal does not add yet another signature and instead recommends the widely deployedburn(uint256)andburnFrom(address,uint256). For burning by serial there is no existing signature to use, so this proposal provides one,burnSlices. It is toburnwhattransferSlicesis totransfer: without it, a holder can name the units to transfer out but not the units to burn. All three functions are recommendations only and are not counted in the interface identifier, because not every token allows holders to burn; wallets therefore cannot detect them with ERC-165.
Two well-known problems are not addressed by this proposal, because they are unrelated to the identity of units and separate proposals already exist that can be used together with this one: the approve race and approval by signature (for example ERC-2612). Notifying the recipient on transfer is not addressed by this proposal either, and ERC-1363 can be used together with it; what serials change for it is described in “No receipt notification is defined”. Tokens that charge a fee on transfer cannot conform to this proposal, because a transfer must move exactly value serials and must not change the holder of any other serial. Tokens that scale balances proportionally cannot conform either, because balances change only with Transfer events; tokens that adjust balances by issuing or destroying serials account by account, and emitting the corresponding events, can conform.
Selection of serials is left to the implementation
transfer(address,uint256) carries no parameter to say which units to send, so the contract has to choose. Last-in-first-out, first-in-first-out and other rules trade gas cost against how units circulate, and each implies a different storage layout. Fixing one rule would fix the data structure. The specification instead requires that every movement is reported, so the rule in use is observable.
This section is about transfers by amount. Holders who need to decide for themselves which units to send use transferSlices.
Transfers by serial are part of the core
transferSlices gives holders control over selection, as the party spending an output has in ledgers based on unspent outputs. The difference is that it is only an additional path: callers that do not care about serials keep using transfer.
There are two reasons for putting it in the core rather than in an extension. First, it is a function called by wallets. For “choosing which units to send” to be a feature that wallets can rely on, every token that conforms to this proposal has to provide it in the same way. Second, on a token whose holders can freely use several accounts, it gives holders no new capability. Without it, a holder can still pick out particular units, by transferring by amount back and forth between several accounts under its control; the function merely spares the detour. On a token that only registered accounts can hold, holders cannot do this, and the function gives them a choice they did not have before.
Its price is that an implementation has to be able to locate a named slice of serials in the caller’s holding and cut it out of the slice that contains it, a requirement that transfers by amount do not have. The specification does not prescribe how serials are located; the cost is discussed in “Security Considerations”.
transferSlices takes a list of slices rather than a single one. Once a holding is fragmented, a payment often has to be assembled from several slices; if a call could transfer only one slice, the payment would have to be split into several transactions, the payee would see several Transfer events, and they would not be atomic. With a list of slices, a payment is one call and one Transfer event. A caller that transfers a single slice passes an array of length 1, so there is no separate single-slice function.
Slices have to be given in ascending order of start and must not overlap. The contract can then detect an overlap in a single pass, and sorting beforehand costs a wallet nothing. Without this rule, when to is the caller itself, the same serial could be listed twice without being noticed.
If even one of the named serials does not belong to the caller, the whole call reverts; there is no “transfer as much as possible” behavior: the caller names specific units, and completing only part of the transfer would not be the result it wants. A slice with an amount of zero likewise makes the call revert, because it names no serial.
A serial not being held by the caller, and a serial not being transferable because of state attached to it, such as a freeze or a class, are the two most common failures of operations by serial. This proposal defines one error for each, ERC8527NotHeld and ERC8527NotTransferable, which report the offending slice, so that a wallet can tell the user which units cannot be transferred out. Which one is used when both conditions occur together is not specified: determining the state of a serial is often cheaper than locating the serial in a holding, and prescribing an order would force some implementations to perform the more expensive check first. These two errors are not counted in the interface identifier.
This proposal defines no function by which a spender transfers by serial. Which units a transferFrom by amount draws on is decided by the contract’s selection rule; a version by serial would hand that choice to the spender, a power that approve did not originally grant. In this proposal an allowance keeps its ERC-20 meaning and is only a cap on an amount (see “Allowances do not reflect transferability”).
Event ordering
Requiring SliceTransferred events to be emitted between the preceding Transfer event and the Transfer event they belong to lets an indexer attribute them without heuristics, including in transactions that contain several transfers between the same pair of addresses.
Freeze events and class events have to be emitted after the Transfer event that issues the serials concerned. This way, an indexer that replays events in log order never meets a state event that refers to serials that have not yet appeared. An operation that sets state at issuance reports the issuance first and the state afterwards. SliceForciblyTransferred following the Transfer event it belongs to is the same arrangement: events that describe units come after the events that make the units appear or move.
No on-chain lookup of the holder of a serial
A function returning the holder of an arbitrary serial would need an ordered index that is updated on every transfer. The holder of a serial can be derived from SliceTransferred events, and sliceAt allows a claimed holding to be verified on-chain. The functions that operate by serial on another party’s holding, namely forcedTransferSlice and destroySlice, therefore have the caller supply the holder.
Freezing is an optional extension
A token that implements only the core already has three things that an ordinary ERC-20 token lacks: every unit has a traceable identity on-chain, holders can name which units to send, and units have a place to which a class can be attached. An issuer that only wants to sort units into a few classes needs only the core and the classification extension and has no use for freezing.
Freezing is not cheap to implement either. Freezing with reasons has to record a set of slices for every reason, and a transfer by amount has to skip frozen serials. Placing it in an optional extension spares the tokens that do not need it these costs. The price is that wallets and integrators have to make one more ERC-165 check.
Freezes carry a reason
A state with only the two values “frozen” and “not frozen” goes wrong when several parties have the right to freeze at the same time. The same units can first be pledged and later be put under a judicial freeze. When the pledge is released, if unfreezing means “these serials are no longer frozen”, the judicial freeze is lifted along with it. In traditional finance such coexistence is the norm. Freezes are therefore recorded by reason: unfreezing lifts only one reason, and a serial stays frozen until its last reason is lifted.
A stop on payment, a pledge and a judicial freeze have the same effect on transfers; they differ only in the reason, in who can set it and in who can lift it. The specification therefore does not define a state for each of them; it makes the reason an opaque bytes32 and leaves permissions to the implementation. A token that needs only one form of freeze uses a single reason and behaves the same as freezing without reasons.
The reason is part of the function signatures and of the events. If freezing without reasons were standardized first, reasons could not be added later without changing the interface.
The freeze functions are part of the interface
With reasons, freezing is no longer only the issuer’s own administrative operation. A pledge contract, a custodian and an agency carrying out a court order can each be the party that sets some reason, and they deal with many different tokens. With uniform signatures for freezeSlice and unfreezeSlice, these callers do not have to adapt to each token separately.
The interface does not specify who can call them for which reason. Issuers differ widely in what they require of permissions, delays and approvals; these remain up to the implementation and are described in the token’s own documentation. The interface provides only two queries, which answer whether an address can freeze for a given reason and whether it can unfreeze for a given reason (see the next section).
Events record the caller, and the interface can be asked who has the right
The events for freezing, unfreezing and forced operations all carry operator, the address that initiated the call. The party with the right to freeze is often a multisig, a timelock or a pledge contract, while the sender of the transaction is only an address that submits transactions for it; without operator in the event, one has to trace the call to learn which address froze or disposed. The AccountFrozen event of ERC-1450 has such a field as well (frozenBy).
canFreeze(reason, account) and canUnfreeze(reason, account) answer “can this address freeze for this reason” and “can this address unfreeze for this reason”, and do not list all the addresses that can. Such a query can be implemented on any permission mechanism: a single owner, role-based permissions and a multisig can all answer whether an address has the right, whereas a list requires the implementation to keep an enumerable set. A holder gets addresses from authority in the description document and from the operator of the events, and checks them with these two queries; a pledge contract can confirm that it has the right to freeze before it accepts a pledge. Freezing and unfreezing have separate queries because the two powers are often not in the same hands; for example, an address responsible for emergencies can freeze at once, while unfreezing has to go through a multisig. With a query for freezing only, a holder would have no way to check who can lift the freeze on its own units.
The two queries report exactly the restriction on callers that the specification requires an implementation to set (clauses 10 and 11 of “Freezing and unfreezing”), so both directions are requirements: an address that is not permitted gets false, and one that is permitted gets true. The former direction can be checked only by reading the code, but the same is true of the restriction on callers itself; if it were only recommended, a token that returns true for every address would also conform, and the query would be of no use. What is judged is the address that calls the token contract directly: a single signer of a multisig gets false, and the multisig contract gets true. A call can still fail when the query returns true, because a delay, approval by several parties, and being able to do so only for some of the serials are not part of the restriction on callers.
The two queries cover every function that freezes or unfreezes issued serials, not only freezeSlice and unfreezeSlice. An implementation can provide other functions that change the frozen state (clause 11 of “Freezing and unfreezing”); if the queries bound only those two functions, false would say only that the address cannot call them, it could still freeze through another function, and a holder or a pledge contract could not rely on false. The cost is this: when one of an implementation’s freezing functions restricts its callers only loosely, every address it permits gets true for that reason, and the query says little about who has the right. The answer is truthful, because what is judged is the caller.
This proposal defines no roles, and does not specify how permissions are granted or changed. Different reasons on the same token can belong to the issuer, a pledge contract and an agency carrying out a court order, each with its own mechanism; specifying roles would conflict with the permission mechanism a token already has. Other proposals fall into two groups. ERC-3643 defines one Agent role, which performs operations such as freezing, and provides the query isAgent; it has only this one role, which is not divided by reason. ERC-7943 requires that freezing and forced transfer be restricted, but leaves the mechanism entirely to the implementation and provides no query. This proposal lies between the two: it provides the query and does not specify the mechanism.
No event is required when permissions change. One role can cover any number of reasons, and a contract cannot report the change reason by reason; holders can discover a change only by querying, which is discussed in “Security Considerations”.
The queries cover freezing and unfreezing only, which is the first thing a holder asks when its units are frozen: whether the address that initiated the freeze has that right, and who can lift it. For destruction and forced transfer the interface has no corresponding query; who can perform them is stated in the reason’s description document (in properties, under disposal).
Freeze events report the resulting state
SliceFrozen and SliceUnfrozen say “these serials are now frozen for this reason” or “are not”, rather than “the state has just changed”. Freezing the same slice again is therefore idempotent, an implementation does not have to work out which serials actually changed state in order to emit events, and an indexer can rebuild the state of any serial by overwriting it reason by reason. The same holds for the operator in an event: it records who initiated this call, which is not necessarily the party that first froze these serials.
Freezing by serial rather than by account
Freezing an account or an amount within an account, as ERC-3643 and ERC-7943 do, restricts a person. Freezing serials targets specific units wherever they are. The two are complementary, and a token can use both at once; transferableBalanceOf describes only the latter, so the fact that it is at least the amount of a transfer does not guarantee that the transfer succeeds. This proposal does not reuse their freeze functions: those take an account and an amount, carry no reason, and cannot name specific serials. ERC-3643 also requires a whole set of components, such as an identity registry and a compliance contract, whereas the core of this proposal is an unrestricted ERC-20.
Frozen units remain in the balance
balanceOf changes only together with a Transfer event. Reducing it when units are frozen would break this invariant, which indexers rely on, so frozen units remain counted and the transferable balance is exposed separately by transferableBalanceOf.
The alternative is to have balanceOf report only unfrozen units. Its advantage is that contracts that know only ERC-20 would not overestimate the amount that can be used. This proposal does not adopt it, on four grounds. First, indexers that compute balances by summing Transfer events would get wrong results; the Transfer event emitted when frozen units are destroyed would also make them deduct those units a second time. Second, totalSupply would either no longer equal the sum of the account balances or would have to exclude frozen units as well, which would turn freezing into a reduction of supply. Third, the core specifies that the balance equals the number of serials the account holds, and a frozen serial is still held by that account. Fourth, when the classification extension is implemented the transferable balance depends on the destination, and balanceOf has no such parameter, so it would still not equal the amount that can be transferred to a given address. In ERC-3643 and ERC-7943, balanceOf includes the frozen part as well.
The transferable balance is in the core and takes a destination
On a token that implements only the core and places no restriction whatsoever on serials, transferableBalanceOf equals the balance. A token that implements the freezing extension has to exclude frozen units, and the result is still independent of the destination. It takes the destination as a parameter because the flow rules of the classification extension can depend on the destination. Restrictions that an implementation defines itself and attaches to serials are reflected in this amount too, so a wallet can know how much can be transferred without knowing those restrictions.
The query is placed in the core rather than in the individual extensions. Wallets and contracts then need to ask only one question, “how much can be transferred from here to there now”, whichever extensions the token implements.
Allowances do not reflect transferability
An ERC-20 allowance can already exceed the balance of the holder who granted it. It is an upper limit, not a guarantee. This proposal keeps that: neither freezing nor the rules of classes change an allowance, and approve does not check how many transferable units the holder has. How much a spender can use is decided only at the time of the transfer; a caller that needs to know in advance queries transferableBalanceOf.
If a freeze reduced the allowance, an unfreeze would have to decide whether to restore it; and an allowance is recorded as an amount, which does not correspond to particular serials. With the two kept independent, existing contracts that rely on approve and transferFrom do not need to know about freezing either.
Classification is a dimension separate from freezing
A class answers “where does this unit come from and where can it go”; freezing answers “can this unit move now”. A class is a long-term attribute of a unit, usually determined at issuance; a freeze is a temporary measure against specific units. Because the two are recorded separately, when a unit that can only be paid to designated addresses is frozen, its class does not change, and nothing needs to be restored after it is unfrozen.
A class can carry flow rules, because a common purpose of classifying units is precisely to give units of different classes different destinations. Flow rules are reported by classAllows; the specification does not say which rules exist. A token that does not need classification does not implement this extension.
Examples of classes
This proposal does not specify which classes exist. The examples below, arranged by asset, show how classes can be used. The “Flow rules” column gives the value that classAllows(classId, from, to) returns when to is not the zero address.
| Asset | Class | Flow rules |
|---|---|---|
| Stablecoin | Purpose bound funds, for example subsidies and consumption vouchers | Returns true only when to is a permitted recipient (for example a participating merchant) |
| Stablecoin | Purpose bound funds with a validity period | Same as above during the validity period; after expiry, returns false for any to |
| Stablecoin | Issuance batch or issuance channel | No flow rule; always returns true |
| Securities (for example company shares or fund shares) | Securities subject to a lock-up period | Returns false until the lock-up is lifted, and always returns true afterwards |
| Securities (for example company shares or fund shares) | Offering round | No flow rule |
| Bonds | The part of an issuance that is placed privately | Returns true only when to is a qualified investor registered by the issuer |
| Bonds | Subscription batch | No flow rule |
| Real-world assets (for example shares in land-use rights or in real estate) | The part subject to restrictions on foreign holding | Returns true only when to is a domestic entity registered by the issuer |
| Real-world assets (for example shares in land-use rights or in real estate) | The part offered to qualified investors | Returns true only when to is a qualified investor registered by the issuer |
| Real-world assets (for example shares in land-use rights or in real estate) | Shares within a lock-up period | Returns false during the lock-up period, and always returns true afterwards |
| Real-world assets (for example precious metals or minerals backed by physical reserves) | Units from a particular mine or a particular batch of certified reserves | No flow rule; the class only records the origin |
| Points | Points from different sources, for example points earned by spending and points given away in promotions | No flow rule |
| Points | Points that cannot be transferred between users | Returns true only when to is the issuer or a merchant |
| Points | Points that expire by the year in which they were earned | Follows its original rule until expiry; after expiry, returns false for any to |
These examples have several things in common.
- Rules apply to units, not to holders. None of the rules above depends on who holds the unit. A class follows its serial (see clause 6 of “Classes”): after a unit changes hands it still belongs to its original class, unless the same operation changes its class. Measures aimed at accounts, such as blocking an address, are not part of the classification extension (see “Applicability”).
- All classes carry the same rights. Parts with different rights, such as bonds with different maturities or coupons, or different classes of shares, are not classes and are each expected to use a contract of their own (see “Applicability”). The same holds for real-world assets: different plots of land, different properties or different minerals are different assets and are each expected to use a contract of their own, and the examples above are all divisions within one asset. Classifying by origin presupposes that units of every origin carry the same rights; if redemption can only return the physical goods of the corresponding batch, the rights differ, and the batches have to be issued separately as well.
- Rules can be combined, and parameters can be encoded in the class. Purpose bound funds with a validity period depend on both the payee’s address and the time. The time at which a lock-up is lifted, a validity period and a batch number can be encoded in
classId, or written into thepropertiesof the description document (see “Description document”). - How classes are set is up to the implementation. A class can be set at issuance, and an implementation can also provide functions that change it, for example to let holders change the class of their own units. Whether a class can be changed back, and whether restricted units can be burned, is also up to the implementation.
Permitted recipients. When a flow rule restricts the destination by the payee’s address, units of the class can only be transferred to its permitted recipients (see “Flow rules”) and cannot reach any other address. When a holder pays a permitted recipient, both units of such a class and units of the default class can be used; when the holder pays any other address, only units of the default class can be used. In a payment by amount to a permitted recipient, the selection rule might draw on units of the default class first and use up units that could be paid to anyone; an implementation can make its selection rule use the restricted units first in such payments, and a holder can also name them with transferSlices. Which class a unit belongs to once it is in the hands of a permitted recipient is up to the implementation. It can still belong to its original class, in which case the permitted recipient, too, can only transfer it to other permitted recipients. An implementation can also change it to the default class in that transfer and emit a SliceClassified event (see clause 6 of “Classes”), so that the merchant receives unrestricted units. The constraint then falls only on the payer, and the payee is not constrained (see “Destination-dependent flow rules and contracts”). classAllows reports only whether a unit can be transferred out, not its class after it arrives; a wallet that needs to explain this to holders can rely on the description document of the class.
Lock-up and expiry. A lock-up is lifted automatically when its period ends, without anyone having to unfreeze anything, so it is suitably represented by a class; pledges and judicial freezes have to be released by a party with the authority to do so, and are represented by freezes. Expired units are not transferable to any destination but still count toward balanceOf (see “Balance includes units that cannot be transferred”); what happens to them afterwards, for example destruction by an authorized party, is up to the implementation.
Classes are not partitions
ERC-7518 treats each token id of an ERC-1155 token as a partition. Each partition has its own balance, rights, compliance rules and transfer restrictions, and payouts are distributed per partition; when two partitions are to be merged, holders hand the tokens of the old partitions to a merger contract in exchange for tokens of the new partition. Classes are not partitions: units of all classes are counted in the same ERC-20 balance, a class is only an attribute of a unit, and when the class of a unit changes, its serial and its holder stay the same, no exchange is needed, and its frozen state is not affected. Classes are therefore used to distinguish where units can go and where they come from, not to distinguish rights (see “Classes do not represent different rights”).
Classes and wrapper contracts
There are two ways to put a constraint on what funds can be used for. One places the constraint outside the funds: the purpose bound money defined by ERC-7291 is a wrapper contract in which the underlying ERC-20 tokens are locked; holders receive the wrapper contract’s tokens, which are unwrapped only when they are transferred to an eligible payee. The other places the constraint on the units of the funds themselves, and the classes of this proposal are of this second sort.
A wrapper token is a different asset. Anyone can build a wrapper on top of an ERC-20 token, so who sets the constraint is independent of who issues the money; the wrapper token is not accepted elsewhere as the underlying token, so it can be transferred freely among holders without the constraint being defeated. The price is that the funds cannot be used as the underlying token until they are unwrapped, and both distribution and redemption have to go through deposit and unwrapping. A class can only be provided by the token’s own implementation, but the constrained units remain the same token: they still have serials and can be traced and frozen like other units, and redemption is just a transfer. They are, however, counted in the same balance as other units, and a contract that knows only ERC-20 cannot tell them apart (see “Classes do not represent different rights”). The constraint must therefore be written into the flow rule: if a class allows its units to be transferred to any address, they can be transferred into an exchange or a pool and be used as ordinary units. Constrained units can therefore be transferred only among the addresses the flow rule allows; they cannot be transferred freely as wrapper tokens can.
The two therefore serve different cases. When the constraint is set by the token’s issuer, classes can be used. When it is set by someone else on top of a token, for example when the agency distributing subsidies is not the issuer of the stablecoin it uses, classes can be used only if the token’s implementation provides an entry point that lets that party set classes and rules; otherwise a wrapper contract should be used. A party able to set rules has a power close to that of freezing (see “Powers of the authorized party”). The two can also be stacked: a token that conforms to this proposal can serve as the underlying token of a wrapper contract. The wrapper token changing hands then no longer moves the underlying serials, and tracing can go no further than the wrapper contract; the wrapper contract also holds the units of many holders together, as a pool does, and when units among them are later frozen, there is no telling which holder they belong to unless the wrapper contract itself records the serials of every deposit (for how a contract learns which serials an incoming transfer brought, see “No receipt notification is defined”).
An opaque class
A class is a bytes32; zero is the default class, and the meaning of every other value is up to the implementation. An implementation can treat it as an enumeration, or encode parameters in it, for example an unlock time or a batch number. However many classes there are, the interface stays the same.
The flow rule query takes a class
classAllows answers “can units of this class go from here to there”, not “can this serial be transferred”. A caller can therefore use it without understanding what the class means, and the result can change with time or with a list, for example when a lock expires or an address is added to a list, without state having to be updated for every affected serial. It does not take freezing into account, so a wallet can say separately whether part of a balance cannot be sent because of a freeze or because of the rules of a class.
Class events report the class only
The SliceClassified event reports the class of serials, and the class of any serial can be rebuilt from events. Which flows a class allows at a given moment is part of its rules and can change without any event. An indexer that needs to track transferability either knows the token’s rules or calls classAllows directly.
Describable reasons and classes
Once the meaning of reasons and classes is left to the implementation, a wallet faces a bytes32 it does not recognize. If they could not describe themselves, a wallet could only display a number or adapt to each token separately, and either outcome would cost this proposal the support of wallets. The specification therefore requires every reason in use and every non-zero class in use to have an on-chain name.
The name is on-chain rather than in an off-chain document because a wallet needs it to display a balance, and a wallet should be able to obtain it with read-only calls alone, without depending on the availability of an external service. Longer descriptions, images and properties go in the description document given by uri, which is optional.
No machine-readable identifier
classInfo returns only a name and a uri; there is no identifier field for programs to recognize. The on-chain name is in one language only; if a class could declare an identifier common to all tokens, a wallet that recognized it could present the class with its own language, icons and hints. Such a field was considered and not adopted, for three reasons.
First, an identifier is meaningful only if it constrains behavior, so defining a value also means specifying how a class that declares it must behave. The rules of real-world classes, however, are often a combination of several conditions. The purpose bound money defined by ERC-7291 is like this: it checks a merchant allowlist at redemption and suggests a validity period. A single string cannot declare a combination; predefining values for single rules would not cover these classes.
Second, the one rule that was considered is too broad to tell classes apart. Predefining an allowlist value was considered, with the requirement that the return value of classAllows not depend on the payer. Purpose bound funds, shares with a lock-up period and classes that serve only as labels all satisfy this, and so do all the classes given in “Examples of classes”; yet the name “allowlist” fits only the purpose bound funds among them.
Third, a field with no agreed values is of use to no one. A program that knows a token can recognize its classes by classId; a program that does not know the token needs values common to all tokens, and this proposal defines none. Keeping only the field and a naming rule for its values would add a concept to the specification and leave a wallet with nothing it can do.
This proposal therefore has no such field. A proposal for a specific scenario can define such identifiers, specify the behavior that goes with them, and declare them through an interface of its own; parameters meant for programs can already go in the properties of the description document (see “Structure of the description document”). Until then, a wallet displays the name the token provides and uses transferableBalanceOf and classAllows to determine whether units can be sent, so no functionality is lost; all that is missing is the wallet’s own text and icons.
Structure of the description document
The description document has three fields, name, description and image, the same as ERC-721 metadata. It also has an optional properties, the same as in ERC-1155 metadata, which is an object; apart from the five keys defined below for reasons, its internal structure is not specified.
properties gives implementations a fixed place for the parameters encoded in a class, for example an unlock time or a batch number. Without it, each implementation would pick its own name, and a reader of the document would have no way of knowing where to look. Its internal structure is not specified: a wallet does not know what a property means, and specifying its format would not make the wallet understand it. A later proposal can agree on more keys in properties.
The slot of ERC-3525 represents a category of assets and is the closest thing to this proposal’s class; its metadata defines properties as an array whose entries carry a display type. This proposal does not adopt that form, because it would also have to specify the values of the display type.
Reasons use the same document, so a wallet needs only one parser.
The description document of a reason has five more optional keys in properties: who can freeze and release (authority), the conditions of release (release), whether frozen units can be disposed of and how long one has to wait at the least (disposal), how to contest a freeze (contest), and the law or contract term it rests on (reference). These are what a holder most needs to know once its units are frozen, and they depend on the issuer and the jurisdiction, so a standard cannot specify their content. What it can do is give them a fixed place: a holder can find the document starting from the reasons for which its own units are frozen (freezeReasonsOf), and a wallet can display these keys under fixed headings. The specification recommends that a reason in use state at least authority and contest; this is only a recommendation, because they are expressive text whose content a contract has no means of checking. They are placed in properties, and no separate top-level fields are defined: five fields that are meaningful only for reasons, placed alongside name and description, would break the document’s correspondence with ERC-721 and ERC-1155 metadata; placed in properties, they leave the top level of the document unchanged, and a wallet that only knows that metadata usually displays the keys and values of properties one by one, so a holder can see them even in a wallet that does not know this proposal. The price is that the description document of a reason cannot use these five key names with any other meaning. They are text and not a structure for programs, because a contested freeze is handled off-chain; the addresses given in authority can be checked with canFreeze and canUnfreeze.
Matters that concern a single freeze are not among these five keys, for example a particular court order or its review date. A reason usually stands for a kind of freeze; using a separate reason for every freeze would increase the number of reasons in use, and the cost of determining whether a serial is frozen can grow with that number (see “Number of reasons” in “Security Considerations”).
The specification recommends putting the document in a data URI, as ERC-3525 does for its metadata. A wallet can then obtain the description with read-only calls alone, and the document cannot become unavailable or be replaced outside the contract. The price is more gas to deploy and to update the document, which is why it is only a recommendation.
Breakdowns are returned in one call
freezeReasonsOf and classesOf each return the complete breakdown in one call, rather than in the “count plus index” form the core interface uses to enumerate slices. What a wallet needs when it displays a balance is exactly the whole breakdown, and a single call saves round trips. The price is that the length of the return value has no upper bound, which is discussed in “Security Considerations”.
Queries by serial return a span
A token with 18 decimals has 10^18 serials per whole token, so querying state serial by serial is pointless. frozenSpanAt and classSpanAt therefore, while answering “what is the state of this serial”, also report how many consecutive serials starting from it have the same state. By calling repeatedly along a slice of a holding, a wallet can divide it into frozen and unfrozen slices, or into slices by class. When the implementation returns the longest span, the number of calls grows with the number of boundaries, not with the number of units.
Spans are not bounded by holder. Freezes and classes are both recorded on serials, regardless of who holds them, so querying them needs no additional index by holder; this differs from looking up the holder of a serial. The caller already knows the slices of the holding from sliceAt and can truncate the span itself.
The specification only recommends returning the longest span and does not require it, because an implementation that stores frozen slices separately for each reason has to merge several reasons to obtain the longest span. For an issued serial the length is at least 1, so the caller’s loop terminates on any implementation that conforms to this proposal; but the number of calls grows with the number of boundaries only when the implementation returns the longest span.
Destroyed serials are also counted in spans according to their state. Their frozen state and class are determined by events in the same way as those of other serials, so an indexer can compute from events alone the state of every serial, and the span that a contract returning the longest span would return. If destroyed serials were skipped in the determination, the longest span would have to extend across them, which an implementation could do only by building a separate index of destroyed serials.
This proposal does not add queries that return an account’s frozen slices or class slices. They can be obtained from sliceAt together with frozenSpanAt or classSpanAt: for each slice of the holding, call repeatedly from its start and truncate the returned span to the slice of the holding. A wallet can batch these read-only calls into one request, and has to read them at the same block, otherwise the assembled result might be inconsistent. A dedicated function could only save these round trips, yet would have to return an array of unbounded length.
What a wallet needs to support this proposal
A wallet that does not know this proposal can use a token that conforms to this proposal as an ERC-20 token as usual. Its shortcoming is that the balance it displays can include units that cannot be sent, which the user discovers only when a send fails.
To support this proposal fully, a wallet does the following, and all of the queries involved can be made with read-only calls and need no indexer: detect the core interface, the two extensions and the acceptance check with ERC-165; break the balance down and display it with frozenBalanceOf, freezeReasonsOf and classesOf, together with freezeReasonInfo and classInfo; when sending, take transferableBalanceOf(from, to) as the upper limit of the amount that can be sent; and estimate gas for every transaction individually. A wallet can also display the slices of serials in a holding with sliceAt, frozenSpanAt and classSpanAt, and let the user choose which units to send with transferSlices. The steps in detail, and how to explain to the user why part of a balance cannot be sent, are in wallet-support.md.
Destruction and forced transfer belong to the freezing extension
An issuer that has the right to freeze units usually also needs to dispose of them after freezing, for example to destroy stolen funds or to hand collateral over to the pledgee. The two sorts of operation usually have the same callers, and both name units by slice. They are therefore placed in the same extension as freezing, and no further extension is split off. A token that freezes but does not dispose of units makes these two functions revert for any caller. The limitation of this is that the interface does not show whether a token will dispose of units, which is discussed in “Security Considerations”.
Their functions are part of the interface on the same grounds as the freeze functions: a contract that enforces a pledge and an agency that carries out a court order deal with many different tokens.
This proposal recommends that forced operations act only on frozen serials, but does not make it a requirement. Freezing first, disposing afterwards and leaving an interval between the two steps lets holders and third parties see the freeze before the units are taken away, and lets the issuer arrange a delay and a review in between. But the specification cannot require this interval: even if “freeze first” were made a requirement, a contract could freeze and dispose in the same transaction, and advance visibility would still not be guaranteed. Such a requirement would also add a pro forma freeze to a disposal that is completed in one step, for example when funds are recovered for a holder who lost a key, where the units would arrive at the new address still frozen and would have to be unfrozen again; forced transfers by amount in the same contract, such as the forcedTransfer of ERC-3643 and ERC-7943, would be bound by it too. Whether freezing first is required is therefore the implementation’s choice, to be stated in its documentation. The price is that this guarantee cannot be obtained from the interface, which is discussed in “Security Considerations”.
Nor does this proposal specify a minimum delay between a freeze and a disposal. The right length differs from reason to reason: pledged units can be taken at once on default, while a disposal after a judicial freeze has to wait for a judgment to take effect. A standard cannot fix a number, and a requirement that a deployment can set to zero guarantees nothing. Enforcing it in the contract would also mean recording a time for every frozen slice and specifying how it is counted when there are several reasons, after a repeated freeze and after a defragmentation, and the freezing extension is already the heaviest part of an implementation. A deployment that needs a delay can have one without a change to the interface: it gives the right of disposal to a contract with a timelock and states the length in the reason’s description document (in properties, under disposal). Frozen units in shared contracts are an exception: there the delay is a window for leaving first (see “Powers of the authorized party”).
A forced transfer does not change frozen state. “Freezing follows units” has no exception here: frozen units are still frozen in the recipient’s hands and are unfrozen in the original way by the party entitled to lift each reason. If a forced transfer unfroze units along the way, the party executing it could lift reasons set by others, which is exactly what freezing with reasons is meant to prevent. This is the opposite of ERC-7943, which requires a forced transfer that bypasses a freeze to unfreeze first; the difference is that there the freeze belongs to the account, and here it belongs to the units.
A forced transfer cannot be replaced by destruction followed by a new issuance. The newly issued units have new serials, and neither the history, nor the class, nor the freeze reasons of the original units would be kept; units frozen for two reasons at once could thus shed the other reason through one disposal. Doing so would also require the party that carries out the disposal to have the power to issue, and in the events it would be a burn and an issuance, which does not show who the units came from or went to. ERC-3643 and ERC-7943 also both make forced transfer a separate function.
The SliceForciblyTransferred event distinguishes forced operations from the holder’s own transfers. Without it, a forced transfer would be indistinguishable in the events from an ordinary transfer, and wallets, audits and bookkeeping would all take it for an act of the holder. It carries operator as well: disposal is a graver power than freezing, and it matters even more which address initiated it.
Each of these two functions takes a single slice, like freezeSlice, because what is disposed of is usually the very slice of consecutive serials that was frozen earlier. An implementation that needs to handle several slices at once, or needs position hints, can provide additional functions.
Design of defragmentation
Every time an account receives units whose serials are not adjacent to those it already has, it holds one more slice. A selection rule can change which accounts accumulate scattered slices, but it cannot eliminate them: an account that collects payments over a long time and then pays out in bulk, such as a merchant, an exchange or a pool, sees its number of slices keep growing until a transfer no longer fits in one transaction. Defragmentation lets such an account renumber its scattered units into one slice. It concentrates the cost in the defragmentation, paid by the defragmenting account at a time of its choosing; without defragmentation, the cost of these scattered slices is paid again every time they change hands, and it is passed on to the next holder with each payment.
The operation and the state have two different names. The operation is named after its purpose, defragmentation, and the function is defragmentSlices: it does what defragmenting a disk does, replacing several scattered pieces with one consecutive piece, and the name itself says why it is done. The state of the old serials that were replaced is called consolidated: their units have been merged into one new slice of consecutive serials. The event SliceConsolidated, the query consolidatedSpanAt and the error ERC8527NotConsolidatable all speak of this state of a serial, so they are named after it. Unlike on a disk, the old positions that were vacated are not used again and remember where their contents went: old serials are never reused, and the successor can be looked up from an old serial.
Renumbering units would break tracing by serial, and this proposal preserves it with three rules. First, the correspondence between old and new serials is recorded in the contract, and freezes and unfreezes propagate along it, so freezing any serial a unit has had freezes the serial it has now. Second, propagation holds from the serials of every generation, so defragmenting ahead of a freeze does not make the freeze miss. Third, frozen units cannot be consolidated, so a defragmentation never has to move any frozen state. Transfers do not consult the record, and their cost is not affected; the cost falls on defragmentations and on the freezes that pass through defragmentation records, and both operations are far less frequent than transfers. On a token whose implementation defragments in the course of a transfer, defragmentations are as frequent as transfers, and the records a freeze has to pass through grow accordingly (see “Costs of defragmentation”).
New serials are assigned in ascending order of the old serials, so the units of one defragmentation that come from the same old slice receive new serials that are still adjacent. A holder therefore cannot use the order of the list to interleave a slice that might later be frozen with other units, which would multiply the slices a freeze has to pass through.
A defragmentation emits no Transfer, because no balance changes; reporting it as a burn followed by an issuance would make a party that looks only at ERC-20 events believe that the supply had changed. The units of one defragmentation have to belong to the same class, because classes are recorded by serial and the new serials need one definite class.
Defragmentation is in the core for two reasons. Fragmentation comes from keeping accounts by serial itself, and every account that collects payments over a long time runs into it, so the remedy should not depend on which extensions a token chose. And defragmentSlices is a function called by wallets, so every token has to offer it in the same way, and indexers need only one way of handling it.
Who can defragment is left to the implementation. When it is open to all holders, the issuer does not need to know in advance which accounts will use it, and does not need to vet and authorize them one by one; the price is that the number of records a freeze passes through is decided by holders, and so is the consumption of the serial space. When only listed accounts can defragment, both are under control, and the price is maintaining the list. Both approaches use the same interface. An implementation can also require a defragmentation to include at least a certain number of slices, so that creating a record costs no less than a freeze passing through it (see “Costs of defragmentation”). When defragmentation is open, it should also limit the consumption of serials by means that do not depend on gas (see “Finite serial space”). A token that does not want units to be renumbered can make defragmentSlices revert for every caller and perform no defragmentation in any other way; on such a token a unit keeps its serial for its entire life.
A holder’s defragmentation of its own units stays in the core, because holders need it whether or not the token lets others defragment for them. Defragmenting for other accounts is in the optional “On-behalf defragmentation extension”, because pools that are already deployed can neither initiate a call themselves nor authorize anyone else; the parties that can defragment for them, for example an address designated by the issuer or a service that defragments for the pools of many tokens, deal with many different tokens and need a uniform function signature, and holders need to be able to find out who can renumber their units. Without this extension, clause 8 of “Defragmentation” already lets an implementation provide such a function, but every token could give it a different signature. The extension is not part of the core because a token on which only the issuer itself defragments, or which does not let anyone defragment for others, has no use for it; putting it in the core would also change the identifier of the core interface. Like canFreeze, it only answers “can this address defragment for this account”; it defines no roles and lists no addresses, so an issuer’s list, a holder’s authorization and opening by number of slices can all be expressed with it. It cannot be used for the caller’s own units, so canDefragmentFor answers only for the permission to defragment for others, and the conditions for defragmenting one’s own units are still decided by the defragmentSlices of the core. SliceConsolidated carries operator, for the same reason as the freeze events: the party that defragments for others is often a contract or a designated address, and without it in the event one would have to trace the call to learn who renumbered these units. The same event reports three kinds of defragmentation: when a holder defragments its own units, operator equals account; in an on-behalf defragmentation it is the caller; and in a defragmentation performed in the course of a transfer it is the caller that initiated the transfer.
This proposal lets an implementation defragment for from or for to in the course of a transfer, because the reason for forbidding renumbering in transfers is to preserve tracing by serial, and the defragmentation records already preserve it; on-behalf defragmentation also already lets someone else renumber an account’s units in the preceding transaction, and putting it into the same call adds no case that a reader of the chain does not already face. This keeps accounts such as pools usable even when nobody defragments for them, at a cost borne by whoever happens to deposit, withdraw or swap. On the reference implementation, a defragmentation costs more per slice it handles than a transfer does per slice it moves, so a transfer that already does not fit in one transaction cannot be rescued, and defragmenting in the course of a transfer can only be preventive, handling a small batch each time. The units being moved are not themselves renumbered, so SliceTransferred reports exactly the serials the recipient receives. When it defragments for someone else, it is subject to the same restriction as on-behalf defragmentation; otherwise anyone could renumber a payee’s units by sending it one unit. This proposal defines no query for this, because no party needs to know before every transfer whether it will renumber: calls that name units by their old serials and are not yet included fail, but do not move the wrong units, and the same situation exists with on-behalf defragmentation; a party that needs serials to stay unchanged can freeze the units; the simulation a wallet runs to estimate gas already includes the cost of the defragmentation; and indexers and parties that keep serials off-chain only have to catch up afterwards from SliceConsolidated (see “Costs of defragmentation”).
Three other approaches were considered. First, the contract could keep only a commitment for each defragmentation, for example a hash of the list of old slices, with the list itself in events. A defragmentation would be much cheaper, but the contract could not translate old serials into new ones by itself, and the translation would have to be done off-chain by the freezing party; a holder could defragment once more before the freeze is included and make it miss, and closing that gap would require a waiting period for defragmentations. Second, a defragmentation could carry the frozen state of the old serials over to the new ones, and so allow frozen units to be consolidated. The cost of a defragmentation would then depend on the number of reasons, and a pledgee could no longer rely on a freeze to keep the serials of its collateral unchanged. Third, a defragmentation could be reported as a burn followed by an issuance. No new event would be needed, but supply statistics would be distorted and a defragmentation could not be told apart from real destruction and issuance.