This proposal defines a fungible token, compatible with ERC-20, in which every smallest unit carries a unique serial number, in the way a banknote does. An account’s balance is the number of serials it holds, and a transfer changes only the holder of the serials it moves and never renumbers them, so however many times an amount is split or forwarded, its units stay inside the slice of serials they came from. Holdings and movements are exposed as slices of consecutive serials, and a holder can also name which serials are sent; the contract remains a plain ERC-20 token for wallets, exchanges and other contracts. A holder that has received many scattered units can defragment them, which moves them onto one new slice of consecutive serials so that later transfers no longer cost more because the holding is scattered; a token can also implement the optional on-behalf defragmentation extension, which lets a permitted party defragment for other accounts, and an implementation can also defragment in the course of a transfer. The correspondence between old and new serials is always recorded in the contract. Two further optional extensions attach state to serials by slice: the freezing extension, in which every freeze carries a reason and follows the units themselves however they are later divided or consolidated, and which lets an authorized party destroy or forcibly transfer units; and the classification extension, which gives every serial a class that can restrict to whom its units can be transferred. Reasons and classes can both describe themselves through the contract, so a wallet can break down and display a balance without prior knowledge of a particular token’s rules. A token can also choose to support the acceptance check, which lets a receiving contract refuse incoming transfers.
Motivation
An ERC-20 balance is a single number. Units have no identity, so the question “which tokens are these?” has no on-chain answer. This becomes a practical problem when an issuer has to act on specific funds, for example after a theft.
Existing mechanisms act on accounts. An issuer can block an address outright, or freeze a given amount inside an address as ERC-3643 and ERC-7943 allow. Neither follows the funds. Once stolen tokens are split across fresh addresses, forwarded, or mixed with other balances, nothing on-chain says which units are the stolen ones. Tracing then depends on off-chain conventions (first-in-first-out, pro-rata, or treating everything touched as tainted) that different parties apply differently, and enforcement becomes a race in which each new address has to be found and frozen while the funds keep moving.
Physical cash addresses identification with serial numbers. Ledgers built on unspent outputs, such as Bitcoin or the cell model of Nervos CKB, give every output an identity, but that identity changes each time the output is spent, and for every spend, whoever spends the output has to choose the inputs off-chain. Neither property fits transfer(address,uint256), which names an amount and nothing else. Token designs that attach identity to positions, such as ERC-3525, build on ERC-721, whose balanceOf, approve and transferFrom share selectors with ERC-20 while meaning something different, so one contract cannot serve both.
ERC-8047 gives funds an on-chain lineage for the same purpose, but it is an ERC-1155 token in which every transfer creates a new token id, so it cannot be used where ERC-20 is expected.
State that needs to rest on specific units comes in more than one form. The first is freezing: stolen funds have to be frozen however many addresses they have since been split across; the same units might also first be pledged and later be put under a judicial freeze, it has to be possible to lift each of the two on its own, and a holder has to be able to find out why its units are frozen. The freezing extension therefore freezes serials by slice, and every freeze carries a reason. The second is classification: an issuer might want some units to be freely transferable and others to be payable only to designated addresses, or not transferable before a certain date, for example purpose bound funds and securities subject to a lock-up period. Today such restrictions are usually implemented by issuing a separate token or with a wrapper contract, which splits one asset into several balances. The classification extension gives every serial a class, and a class can restrict to whom its units can be transferred, while the units of all classes still count in one balance. What the two kinds of state have in common is that they are attached to units and have to remain in effect after the units are split and forwarded. Once units have a stable identity, both have something to attach to.
A stable identity is useful even when no state is attached to it. Which serials every movement transferred is recorded on-chain, and so is the correspondence between old and new serials when a defragmentation gives units new serials, so where a given set of units went is a fact that can be read directly and no longer has to be inferred with the conventions above. An exchange can check, before it credits an incoming transfer, whether the transfer contains serials taken in a theft, and investigators and courts rely on the same record. A token that provides no freezing offers all of this as well. What it establishes is where the units are, not who is responsible (see “Selection order can be influenced”, “Holders can choose which units to send” and “Reduced fungibility and privacy”).
What is missing is a token whose units keep a stable identity across splits and transfers, with that identity recorded on-chain, so that state such as freezes and classes can attach to it, while the token still behaves as ERC-20 everywhere ERC-20 is expected.
Specification
The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “NOT RECOMMENDED”, “MAY”, and “OPTIONAL” in this document are to be interpreted as described in RFC 2119 and RFC 8174.
Definitions
Unit: the smallest indivisible amount of the token, that is, 1 in the uint256 values used by ERC-20.
Serial: a non-negative integer that identifies exactly one unit.
Slice(start, amount): the amount consecutive serials start, start + 1, …, start + amount - 1, where amount > 0.
Holder: the address that currently owns a serial.
Issued: a serial that has been assigned to a unit by a mint.
Destroyed: an issued serial whose unit no longer exists. Both a burn by the holder and destruction by an authorized party make a serial destroyed. A destroyed serial has no holder.
Defragmentation: an operation that moves units held by one account onto a newly issued slice of consecutive serials. It turns scattered slices into one consecutive slice, so that the account’s later transfers no longer cost more because its holding is scattered, in the way defragmenting a disk does. It changes neither balances nor holders, only the serials of these units, and the correspondence between old and new serials is recorded in the contract.
Consolidated: an issued serial whose unit has been given a new serial by a defragmentation. A consolidated serial has no holder, but its unit still exists.
Successor: the new serial that the unit of a consolidated serial received in that defragmentation.
Reason: a bytes32 value that identifies the cause of a freeze.
Frozen: a serial is frozen when it is frozen for at least one reason.
Span: the sequence of consecutive serials that frozenSpanAt, classSpanAt and consolidatedSpanAt return: it starts at the serial queried, and every serial in it has the same state as that serial. The state is whether a serial is frozen, its class, or whether it is consolidated. A span is thus a slice whose serials share one state, given by the serial queried and the length returned. It starts at the serial queried, which need not be where that state begins, and it need not reach where that state ends, because these queries are not required to return the longest one. In a span returned by consolidatedSpanAt, the successors of the serials are consecutive as well. A span is independent of holders: it can contain the serials of several holders, and it can include destroyed or consolidated serials. It is up to a caller that is interested in only one holding to truncate the span to the slices of that holding.
Core interface
Every contract that conforms to this proposal MUST implement ERC-20, ERC-165 and the IERC8527 interface.
interfaceIERC8527/* is IERC20, IERC165 */{/// @notice Emitted when the `amount` consecutive serials starting at `start` change holder.
/// @dev `from` is the zero address when the serials are issued, and `to` is the zero address
/// when they are destroyed.
eventSliceTransferred(addressindexedfrom,addressindexedto,uint256start,uint256amount);/// @notice Emitted when the units with the `amount` consecutive serials starting at `start`,
/// held by `account`, are given the `amount` consecutive serials starting at
/// `newStart`.
/// @dev The unit with the serial `start + i` receives the serial `newStart + i`. `operator` is
/// the caller of the call in which the defragmentation took place.
eventSliceConsolidated(addressindexedaccount,addressindexedoperator,uint256start,uint256newStart,uint256amount);/// @notice `from` holds at least `amount` units, but only `transferable` of them may currently
/// be moved to `to`.
errorERC8527InsufficientTransferableBalance(addressfrom,addressto,uint256amount,uint256transferable);/// @notice Some of the `amount` consecutive serials starting at `start` are not held by `from`.
errorERC8527NotHeld(addressfrom,uint256start,uint256amount);/// @notice Some of the `amount` consecutive serials starting at `start` may not currently be
/// moved from `from` to `to` because of state attached to them, such as a freeze.
errorERC8527NotTransferable(addressfrom,addressto,uint256start,uint256amount);/// @notice `to` refuses a transfer of `value` units from `from`.
errorERC8527TransferRefused(addressfrom,addressto,uint256value);/// @notice Some of the `amount` consecutive serials starting at `start`, held by `account`,
/// may not currently be consolidated because of state attached to them, such as a
/// freeze.
errorERC8527NotConsolidatable(addressaccount,uint256start,uint256amount);/// @notice The number of serials issued so far, including serials that were later destroyed
/// or consolidated.
/// @dev The next unit to be issued receives the serial `serialsIssued()`.
functionserialsIssued()externalviewreturns(uint256);/// @notice The number of slices that `sliceAt` exposes for `account`.
functionsliceCount(addressaccount)externalviewreturns(uint256);/// @notice One of the slices of serials held by `account`.
/// @dev The slice covers the serials `start`, `start + 1`, ..., `start + amount - 1`.
/// MUST revert if `index >= sliceCount(account)`.
functionsliceAt(addressaccount,uint256index)externalviewreturns(uint256start,uint256amount);/// @notice Moves the serials in the slices `(starts[i], amounts[i])` from the caller to `to`.
/// @dev MUST revert if the arrays are empty or differ in length, if any amount is zero, if the
/// slices are not in ascending order of `start` or overlap, if `to` is the zero address,
/// or if any of these serials is not held by the caller or may not currently be moved
/// to `to`.
functiontransferSlices(addressto,uint256[]calldatastarts,uint256[]calldataamounts)externalreturns(bool);/// @notice The number of serials held by `from` that may currently be moved to `to`.
/// @dev `to` is the zero address for a burn.
functiontransferableBalanceOf(addressfrom,addressto)externalviewreturns(uint256);/// @notice Gives the units with the serials in the slices `(starts[i], amounts[i])`, held by
/// the caller, new consecutive serials starting at `newStart`.
/// @dev The units receive the new serials in ascending order of their old serials. MUST revert
/// if the arrays are empty or differ in length, if any amount is zero, if the slices are
/// not in ascending order of `start` or overlap, or if any of these serials is not held
/// by the caller.
functiondefragmentSlices(uint256[]calldatastarts,uint256[]calldataamounts)externalreturns(uint256newStart);/// @notice Whether `serial` has been consolidated, the serial its unit received, and a span of
/// serials that were consolidated together with it.
/// @dev If `consolidated` is true, the unit that had the serial `serial + i` received the
/// serial `successor + i`, for every `i < length`. If it is false, none of the `length`
/// consecutive serials starting at `serial` has been consolidated and `successor` is
/// zero. `length` is zero if `serial` has not been issued.
functionconsolidatedSpanAt(uint256serial)externalviewreturns(boolconsolidated,uint256successor,uint256length);}
supportsInterface MUST return true for 0x8fbd0cc8, the ERC-165 identifier of IERC8527.
Serial model
Serials MUST be issued consecutively starting from 0. An operation that assigns new serials to v units, that is, an operation that creates these units or a defragmentation as defined in “Defragmentation”, MUST assign them the serials serialsIssued() through serialsIssued() + v - 1, as read before the operation, and MUST then increase serialsIssued() by v. serialsIssued() MUST NOT change in any other way.
Every issued serial MUST, at all times, be in exactly one of the following states: it has exactly one holder, which is not the zero address; it is destroyed; it is consolidated.
A destroyed or consolidated serial MUST NOT have a holder again. Serials are never reused.
balanceOf(account) MUST equal the number of serials held by account.
totalSupply() MUST equal the number of serials that have a holder, that is, the issued serials that are neither destroyed nor consolidated.
Apart from a defragmentation, no operation changes the serial of a unit: operations change the holder of a serial. In a contract that does not open defragmentation (see clause 7 of “Defragmentation”), a unit therefore keeps its serial for its entire life.
Requirements on ERC-20 behavior
ERC-20 leaves a choice open in several places, or only makes a recommendation. A contract that conforms to this proposal MUST behave as this section specifies. Every clause of this section is behavior that ERC-20 permits, so a contract that conforms to this proposal also conforms to ERC-20.
transfer, transferFrom and approve MUST return true on success and MUST revert on failure. They MUST NOT signal failure by returning false.
The contract MUST implement name, symbol and decimals. The value returned by decimals MUST NOT change.
transfer and transferFrom MUST revert when to is the zero address. Units are destroyed only through an explicit burn or destruction operation.
When a failure is a case described by one of the errors that ERC-6093 defines for ERC-20, the contract SHOULD revert with that error: for example ERC20InsufficientBalance when the balance is insufficient, ERC20InsufficientAllowance when the allowance is insufficient, and ERC20InvalidReceiver when to is the zero address. When a failure matches several of the errors that ERC-6093 or this proposal recommends, which one is used is not specified.
The contract MAY let holders burn their own units. A contract that provides this SHOULD use the signatures burn(uint256 value) and burnFrom(address account, uint256 value): the former burns value units of the caller; the latter burns value units of account and consumes the caller’s allowance from account in the same way as transferFrom. Which serials these two functions burn is determined by the implementation’s selection rule.
The contract MAY let holders name the serials to burn. A contract that provides this SHOULD use the signature burnSlices(uint256[] calldata starts, uint256[] calldata amounts), which returns no value. It burns all serials in the slices (starts[i], amounts[i]), all of which have to be held by the caller. Its requirements on the arguments are the same as those of transferSlices: the call MUST revert in the cases listed in clauses 2 to 4 of “Transfers by serial”, and when serials are not held by the caller it likewise SHOULD revert with ERC8527NotHeld(msg.sender, starts[i], amounts[i]). A successful call MUST emit exactly one Transfer(msg.sender, address(0), value), where value is the sum of the entries of amounts, and emit SliceTransferred events as specified in “Events”. It MUST NOT change any allowance. This proposal defines no function by which a spender burns by serial.
burn, burnFrom and burnSlices are not part of IERC8527 and do not count toward its ERC-165 identifier.
ERC-20 only recommends emitting a Transfer event when units are issued, and does not specify whether one is emitted when they are destroyed; this proposal makes both a requirement in “Events”.
Transfers
transfer and transferFrom MUST behave as specified by ERC-20, with the following additions.
A successful transfer of value units from from to to, where from != to, MUST change the holder of exactly value serials held by from to to, and, apart from a defragmentation permitted by clause 4, MUST NOT change the holder of any other serial.
Which of the sender’s serials are moved is chosen by the implementation. Implementations SHOULD document their selection rule.
A transfer where from == to or value == 0 MUST NOT change the holder of any serial.
In a successful call to transfer, transferFrom or transferSlices with from != to and value > 0, an implementation MAY also defragment for from or for to. Every such defragmentation MUST follow clause 8 of “Defragmentation”; the units moved by the call MUST NOT be consolidated in that call, whether before or after they are moved. When the units being consolidated are not held by the msg.sender of the call, for example the units of to, or the units of from in a transferFrom, this is a defragmentation on behalf of another account: the implementation MUST restrict who can trigger it, or do so only for accounts that hold more than a certain number of slices (see “Costs of defragmentation”). Implementations SHOULD document the conditions under which they do this.
Transfers by serial
transferSlices(to, starts, amounts) lets a holder name the serials to transfer. It names all serials in the slices (starts[i], amounts[i]). In this section, the caller is msg.sender, and value is the sum of the entries of amounts.
A successful call MUST change the holder of every named serial from the caller to to, MUST NOT change the holder of any other serial apart from a defragmentation permitted by clause 4 of “Transfers”, and MUST return true.
The call MUST revert if the two arrays differ in length, if their length is zero, or if any amounts[i] is zero.
The slices have to be given in ascending order of start and without overlap: the call MUST revert if, for some i > 0, starts[i] is less than starts[i - 1] + amounts[i - 1]. Adjacent slices MAY be given separately.
The call MUST revert if any of the named serials is not held by the caller, including a serial that has not been issued, has been destroyed or is consolidated. The contract SHOULD revert with ERC8527NotHeld(msg.sender, starts[i], amounts[i]), where (starts[i], amounts[i]) is a slice that contains such a serial.
A successful call MUST emit exactly one Transfer(msg.sender, to, value), and emit SliceTransferred events according to the rules of “Events”.
If to is the caller, clauses 2 to 4 still apply; a successful call changes the holder of no serial.
The call MUST revert if to is the zero address.
transferSlices MUST NOT change any allowance.
Events
Every operation that changes the holder of serials MUST emit the ERC-20 Transfer(from, to, value) event, where value is the number of serials whose holder changes from from to to as reported by that event. from is the zero address when serials are issued, and to is the zero address when serials are destroyed. This includes destruction that is not initiated by the holder. The holder of a serial MUST NOT change in any way that is not reported by a Transfer event. A defragmentation is the only exception: it changes no account’s balance, emits neither Transfer nor SliceTransferred, and is reported by SliceConsolidated events (see “Defragmentation”).
For every ERC-20 Transfer(from, to, value) event with from != to and value > 0, including mints (from is the zero address) and burns (to is the zero address), the contract MUST emit one or more SliceTransferred events such that:
each has the same from and to as the Transfer event;
each has amount > 0;
their slices are pairwise disjoint and together are exactly the serials whose holder changes from from to to as reported by that Transfer event;
their amount values sum to value;
they are emitted before that Transfer event and after any earlier Transfer event emitted by the same contract in the same transaction.
The contract MUST NOT emit SliceTransferred in any other circumstance. In particular, a Transfer event with from == to or value == 0 has no SliceTransferred events.
Under clause 5, the SliceTransferred events belonging to a Transfer event are exactly those emitted by the contract between the previous Transfer event of the same transaction (or the start of the transaction) and that Transfer event.
Enumeration
For any account, the slices returned by sliceAt(account, i) for 0 <= i < sliceCount(account) MUST be pairwise disjoint, MUST each have amount > 0, and together MUST be exactly the set of serials held by account. sliceAt(account, index) MUST revert when index >= sliceCount(account).
The order of the slices is not specified and MAY change with any state-changing operation. Two slices that are adjacent MAY be reported separately. Callers MUST NOT assume that an index still refers to the same slice after any state-changing operation.
Transferable balance
The extensions of this proposal, and restrictions attached to serials that an implementation defines itself, can leave some units temporarily unable to be transferred out, or transferable only to some addresses. The core interface reports the result through one query, so that wallets and contracts obtain the amount that can be transferred out in the same way whichever extensions a token implements.
For a pair of addresses (from, to), a serial is transferable if and only if it is held by from and the contract does not prohibit its transfer from from to to because of state attached to that serial. The freezes and flow rules defined by the extensions of this proposal are such state, and so are restrictions attached to serials that an implementation defines itself. For a burn, to is the zero address. In a contract that places no restriction on serials, every serial held by from is transferable.
transferableBalanceOf(from, to) MUST equal the number of serials that are transferable for (from, to). It never exceeds balanceOf(from).
Clauses 2 to 5 apply to every operation that transfers or burns units and is initiated by the holder or by a spender, whatever function provides it. This includes transfer, transferFrom, transferSlices, burn, burnFrom and burnSlices, and any other such function an implementation provides, for example a function that notifies the recipient on a transfer. In these operations, from is the holder of the units that are transferred or burned.
These operations MUST NOT change the holder of a serial that is not transferable for (from, to).
A transfer or burn of value units from from to to with value greater than transferableBalanceOf(from, to) MUST revert. If value <= balanceOf(from), the contract SHOULD revert with ERC8527InsufficientTransferableBalance(from, to, value, transferable), where transferable is transferableBalanceOf(from, to). If value > balanceOf(from), the contract SHOULD revert with the ERC20InsufficientBalance error of ERC-6093.
If value is not greater than transferableBalanceOf(from, to), these operations MUST NOT revert because from holds serials that are not transferable. The implementation’s selection rule therefore has to be able to skip serials that are not transferable. Which of the transferable serials are selected is still chosen by the implementation. This clause does not require an operation to still succeed when gas runs out; an implementation SHOULD avoid letting the cost of skipping serials that are not transferable grow with the number of slices they form, for example by storing slices separately by frozen state and class (see “Fragmentation and gas”).
Clauses 3 and 4 do not apply to operations in which the initiator names the serials, such as transferSlices and burnSlices; in these two functions, from is the caller. When any of the serials such an operation names is not transferable for (from, to), the call MUST revert; for a burn, to is the zero address. If one of the named serials is prohibited from being transferred from from to to because of state attached to it, whether or not it is held by from, the contract SHOULD revert with ERC8527NotTransferable(from, to, starts[i], amounts[i]), where (starts[i], amounts[i]) is a slice that contains such a serial. When the named serials include both one that is not held by from and one that is prohibited in this way, both errors match, and which one is used is not specified (see clause 4 of “Requirements on ERC-20 behavior”).
transferableBalanceOf reflects only state attached to serials. An implementation MAY reject any operation, including transfers, burns, approve and issuance, on other grounds, for example restrictions on accounts or a global pause; transferableBalanceOf does not reflect these grounds. The section “Acceptance check”, which a contract can choose whether to support, defines one of them: refusal by the recipient.
Allowances are independent of whether serials are transferable. approve MUST NOT revert because serials held by the caller are not transferable. The value returned by allowance MUST NOT change because serials become transferable or not transferable, so freezing, unfreezing and setting a class change no allowance. Whether serials are transferable is checked only when units are transferred or burned: transferFrom and burnFrom behave according to clauses 2 to 4, and the amount they can move is limited by both the allowance and transferableBalanceOf(from, to).
Defragmentation
When an account receives units whose serials are not adjacent, the number of slices it holds grows, and so does the cost of its later transfers (see “Fragmentation and gas”). This section specifies how units held by one account are given one new slice of consecutive serials, and how the correspondence between old and new serials is recorded and queried. It does not specify who can defragment, nor how many slices a defragmentation has to include at least; these are left to the implementation.
In this section, a defragmentation is an operation that assigns new serials to units held by one account. defragmentSlices(starts, amounts) acts on all the serials in the slices (starts[i], amounts[i]), which are held by the caller. In this section v is the sum of the elements of amounts, n is serialsIssued() before the call, and p_i is the sum of amounts[0] through amounts[i - 1], with p_0 being zero.
A successful call to defragmentSlices MUST assign the serials n through n + v - 1 to the named units, and MUST return n. New serials are assigned in ascending order of the old serials: the unit whose serial was starts[i] + k receives the serial n + p_i + k, where 0 <= k < amounts[i].
After the call, the new serials MUST all be held by the caller, and the named old serials MUST all be consolidated, their successors being the new serials assigned under clause 1. Under clause 1 of “Serial model”, serialsIssued() increases by v.
A defragmentation MUST NOT change the holder of any other serial, MUST NOT change the balanceOf of any account, and MUST NOT change totalSupply() or any allowance.
defragmentSlices has the same requirements on its arguments as transferSlices: the call MUST revert in the cases listed in clauses 2 to 4 of “Transfers by serial”, and when serials are not held by the caller it likewise SHOULD revert with ERC8527NotHeld(msg.sender, starts[i], amounts[i]).
Every defragmentation MUST emit one or more SliceConsolidated(account, operator, start, newStart, amount) events, where account is the holder of these units and operator is the msg.sender of the call in which the defragmentation took place, including a defragmentation performed in the course of a transfer (see clause 4 of “Transfers”). Each event has amount > 0; their slices (start, amount) are pairwise disjoint and together are exactly the old serials of this defragmentation; and for every 0 <= k < amount, the successor of the serial start + k is newStart + k. defragmentSlices MUST emit exactly one SliceConsolidated(msg.sender, msg.sender, starts[i], n + p_i, amounts[i]) for each i, in ascending order of i.
A defragmentation MUST NOT emit Transfer or SliceTransferred events. The serials a defragmentation assigns are reported as issued by the SliceConsolidated events: for these serials, “the Transfer event that issues the serials it covers” in clause 4 of “Freezing and unfreezing” and in clause 5 of “Classes” means the SliceConsolidated event that reports them.
defragmentSlices acts on the caller’s own units. An implementation MAY restrict who can call it, and MAY refuse a call for other reasons, for example by requiring a defragmentation to include at least a certain number of slices, by allowing only accounts that hold more than a certain number of slices to defragment, or by limiting the rate at which defragmentation consumes serials (see “Costs of defragmentation” and “Finite serial space”). Implementations SHOULD document these conditions. A contract MAY make defragmentSlices revert for every caller. A contract that performs no defragmentation in any way is called, in this proposal, a contract that does not open defragmentation; it has no consolidated serials.
An implementation MAY perform a defragmentation in other ways, for example with the defragmentSlicesFor defined by the optional “On-behalf defragmentation extension”, or in the course of a transfer (see clause 4 of “Transfers”). Every such defragmentation MUST involve only serials held by one account, MUST assign them consecutive serials starting at serialsIssued() in ascending order of the old serials, and MUST follow clauses 2, 3, 5 and 6, with that account in place of the caller in clause 2.
A defragmentation does not transfer units. It is not among the operations that “Transferable balance” addresses, it is not subject to flow rules, and it does not go through the acceptance check. When the contract implements the freezing extension or the classification extension, a defragmentation is also subject to “Freezing and defragmentation” or “Classes and defragmentation”; the rules of these two subsections apply to every kind of defragmentation an implementation provides. When a failed defragmentation fits several of the errors this proposal recommends, for example when the serials named include some that are not held by the caller and some that are frozen, which one is used is not specified (see clause 4 of “Requirements on ERC-20 behavior”).
Clauses 9 to 11 specify the queries on defragmentation records.
consolidatedSpanAt(serial) reports whether serial is consolidated, its successor, and a span starting at it (see “Definitions”). For an issued serial, it MUST return a (consolidated, successor, length) that satisfies the following conditions: length is at least 1; serial + length is not greater than serialsIssued(); if consolidated is true, the serials serial through serial + length - 1 are all consolidated and, for every 0 <= k < length, the successor of the serial serial + k is successor + k; if consolidated is false, none of these serials is consolidated and successor is zero. For a serial that has not been issued, it MUST return (false, 0, 0).
consolidatedSpanAt SHOULD return the largest length that satisfies clause 9. Callers MUST NOT assume that the returned span is the longest.
A successor can itself be consolidated by a later defragmentation. To obtain the serial a unit has now, a caller starts from any serial the unit has had and queries repeatedly until consolidated is false. This proposal defines no function that looks up the old serial from the new one; the correspondence in that direction is given by the SliceConsolidated events.
Operations outside the core interface
The core interface contains no function that issues units, and none that freezes units or that destroys or transfers units without the holder’s consent; the latter are defined by the freezing extension, which a contract can choose whether to implement. These operations, whatever function provides them, MUST follow the rules of “Serial model” and “Events”. Transfer and burn functions that an implementation provides outside the core interface and that are initiated by the holder or by a spender MUST likewise follow these two sections, and are subject to clauses 2 to 5 of “Transferable balance”; on a contract that supports the acceptance check, those of them that transfer units are also subject to “Acceptance check”.
Acceptance check
The acceptance check is OPTIONAL. A token contract that supports the acceptance check asks the recipient, when units are transferred, whether it accepts them, so that a recipient can refuse units that others transfer to it. A recipient answers by implementing the IERC8527Acceptance interface. The interface is only a query: the token calls it read-only, it is not a receipt notification, and the recipient cannot change state in it.
interfaceIERC8527Acceptance/* is IERC165 */{/// @notice Whether this contract accepts a transfer of `value` units from `from` that is
/// initiated by `operator` and delivered in `slices` slices. The caller is the token
/// contract.
/// @dev Returns `IERC8527Acceptance.acceptsERC8527Transfer.selector` to accept.
functionacceptsERC8527Transfer(addressoperator,addressfrom,uint256value,uint256slices)externalviewreturns(bytes4);}
This interface is implemented by the recipient, not by the token. A contract that implements it MUST implement ERC-165, and its supportsInterface MUST return true for 0x3fbf9755, the ERC-165 identifier of IERC8527Acceptance.
A token contract supports the acceptance check if it follows clauses 1 to 10 of this section. The acceptance check has no function on the token side, so a token declares it with an agreed identifier: a contract that supports the acceptance check MUST return true from supportsInterface for 0xde7278e5, the ERC-165 identifier of the acceptance check, and a contract that does not support it MUST return false. This value is the selector of the error ERC8527TransferRefused(address,address,uint256); it is not computed from function selectors in the way ERC-165 defines. It is a different identifier from 0x3fbf9755: a token contract MUST NOT return true for 0x3fbf9755 because it supports the acceptance check, otherwise other tokens would treat it as a receiving contract and query it. In the rest of this section, “the contract” means a token contract that supports the acceptance check.
In this section, an incoming transfer is the movement of value units from from to to by an operation, reported by one Transfer(from, to, value) event; to is not the zero address. operator is the msg.sender that initiated the operation. slices is the number of SliceTransferred events the contract emits for that Transfer event (see “Events”). When an operation contains several incoming transfers, each is judged separately.
An incoming transfer is exempt if and only if at least one of the following holds:
value is zero;
from equals to;
operator equals to.
to is a receiving contract if and only if to has code and, by the detection procedure that ERC-165 specifies, to implements ERC-165 and its supportsInterface(0x3fbf9755) returns true.
Clauses 2 to 8 apply to every operation that transfers units and is initiated by the holder or by a spender, whatever function provides it. This includes transfer, transferFrom and transferSlices, and any other such function an implementation provides.
For every incoming transfer that is not exempt, the contract MUST determine whether to is a receiving contract. If to is a receiving contract, the contract MUST call acceptsERC8527Transfer(operator, from, value, slices) on to with STATICCALL. If the call succeeds and returns the bytes4 value 0x3fbf9755, the selector of this function, to accepts the incoming transfer. In every other case torefuses the incoming transfer, including when the call reverts and when it returns other data.
When an incoming transfer is refused, the operation MUST revert. The contract SHOULD revert with ERC8527TransferRefused(from, to, value).
If to is not a receiving contract, the contract MUST NOT call acceptsERC8527Transfer and MUST NOT reject the incoming transfer because to is not a receiving contract. Incoming transfers to an address without code, or to a contract that does not implement this interface, are therefore never refused under this section. For an exempt incoming transfer, the contract MUST NOT call acceptsERC8527Transfer.
The contract MUST NOT treat a receiving contract as not being one because too little gas was available. ERC-165 requires supportsInterface to use at most 30,000 gas. When the contract could not forward 30,000 gas to a supportsInterface query, it MUST NOT conclude from that query that to is not a receiving contract; the operation MUST revert.
The queries and the call to to MUST take place either before the operation has made any of its changes to the holders of serials or after it has made all of them; which of the two is not specified.
An implementation MAY limit the gas forwarded to acceptsERC8527Transfer. An implementation that does so SHOULD document the limit. When this call fails for lack of gas, the incoming transfer is refused.
In a transfer by amount, slices depends on the implementation’s selection rule. This proposal does not require an implementation to look for a selection that would be accepted: when an incoming transfer by amount is refused, the operation reverts even if other serials held by the sender would have made it acceptable. Clause 4 of “Transferable balance” concerns only serials that are not transferable and does not apply here.
An issuance operation that an implementation provides, if any caller can execute it and name the receiving address, for example minting to an arbitrary address against a deposit of another asset, MUST treat its incoming transfers according to clauses 2 to 8, with from being the zero address. Issuance that only restricted callers can execute, and forced operations, which do not need the holder’s consent, are not subject to this section; whether they query receiving contracts is up to the implementation, which SHOULD document it. Burning and destruction have no recipient and are not subject to this section.
approve MUST NOT revert because spender or the caller would refuse incoming transfers. A refusal MUST NOT change any allowance.
The rest of this section is informative.
A contract that needs to act when it receives units can use ERC-1363, which a token can implement as well. How a receiving contract decides is not specified: it can look only at the arguments of the call and its own state, or it can query other contracts, for example accepting an incoming transfer only when an oracle confirms that an off-chain settlement is complete (see “Acceptance is decided by the receiving contract” in rationale.md). Under clause 6 the call 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. Why this proposal defines no notification of its own, the considerations behind the design of the acceptance check, and how a payer can find out in advance whether an incoming transfer would be refused are explained in “Dust, the acceptance check and receipt notification”.
Freezing extension
The freezing extension is OPTIONAL. A contract that implements it MUST implement the core interface and the IERC8527Freezable interface.
interfaceIERC8527Freezable/* is IERC8527 */{/// @notice Emitted to report that the `amount` consecutive serials starting at `start` are
/// frozen for `reason`.
/// @dev `operator` is the caller of the operation that emits the event.
eventSliceFrozen(bytes32indexedreason,addressindexedoperator,uint256start,uint256amount);/// @notice Emitted to report that the `amount` consecutive serials starting at `start` are
/// not frozen for `reason`.
/// @dev `operator` is the caller of the operation that emits the event.
eventSliceUnfrozen(bytes32indexedreason,addressindexedoperator,uint256start,uint256amount);/// @notice Emitted when the `amount` consecutive serials starting at `start` are moved from
/// `from` to `to`, or destroyed, without the consent of `from`.
/// @dev `to` is the zero address when the serials are destroyed. `operator` is the caller of
/// the operation that emits the event.
eventSliceForciblyTransferred(addressindexedfrom,addressindexedto,addressindexedoperator,uint256start,uint256amount);/// @notice Freezes the `amount` consecutive serials starting at `start` for `reason`.
/// @dev Serials that are already frozen for `reason` remain so. The successors of consolidated
/// serials among them are frozen as well.
functionfreezeSlice(uint256start,uint256amount,bytes32reason)external;/// @notice Releases the `amount` consecutive serials starting at `start` from `reason`.
/// @dev A serial stays frozen for as long as it is frozen for any other reason. The successors
/// of consolidated serials among them are released as well.
functionunfreezeSlice(uint256start,uint256amount,bytes32reason)external;/// @notice Moves the `amount` consecutive serials starting at `start` from `from` to `to`
/// without the consent of `from`.
/// @dev Does not change whether the serials are frozen.
functionforcedTransferSlice(addressfrom,addressto,uint256start,uint256amount)external;/// @notice Destroys the `amount` consecutive serials starting at `start`, which are held by
/// `from`, without the consent of `from`.
functiondestroySlice(addressfrom,uint256start,uint256amount)external;/// @notice Whether `serial` is frozen for at least one reason, and a span of serials sharing
/// that status.
/// @dev The `length` consecutive serials starting at `serial` are all frozen or all not
/// frozen. `length` is zero if `serial` has not been issued.
functionfrozenSpanAt(uint256serial)externalviewreturns(boolfrozen,uint256length);/// @notice The number of serials held by `account` that are frozen for at least one reason.
functionfrozenBalanceOf(addressaccount)externalviewreturns(uint256);/// @notice The reasons for which serials held by `account` are frozen.
/// @dev `amounts[i]` is the number of serials held by `account` that are frozen for
/// `reasons[i]`. A serial frozen for several reasons is counted under each of them, so
/// the amounts can add up to more than `frozenBalanceOf(account)`.
functionfreezeReasonsOf(addressaccount)externalviewreturns(bytes32[]memoryreasons,uint256[]memoryamounts);/// @notice A description of the freeze reason `reason`.
/// @dev `name` is a short human-readable name, and `uri` points to a JSON document or is an
/// empty string.
functionfreezeReasonInfo(bytes32reason)externalviewreturns(stringmemoryname,stringmemoryuri);/// @notice Whether `account` is among the callers permitted to freeze serials for `reason`.
/// @dev When this returns `false`, every call by `account` that would freeze issued serials for
/// `reason` reverts.
functioncanFreeze(bytes32reason,addressaccount)externalviewreturns(bool);/// @notice Whether `account` is among the callers permitted to release serials from `reason`.
/// @dev When this returns `false`, every call by `account` that would release serials from
/// `reason` reverts.
functioncanUnfreeze(bytes32reason,addressaccount)externalviewreturns(bool);}
supportsInterface MUST return true for 0xe3076627, the ERC-165 identifier of IERC8527Freezable.
This extension specifies how serials are frozen and unfrozen, and how an authorized party makes forced transfers of serials or destroys them. It does not specify which reasons exist or who can perform these operations; these are up to the implementation. Whether an address can freeze or unfreeze for a given reason is reported by the implementation through canFreeze and canUnfreeze (see clause 8 of “Freeze queries”).
In a contract that implements this extension, a frozen serial is not transferable for any (from, to). The frozen state is one of the states attached to a serial that “Transferable balance” refers to.
Freezing and unfreezing
Freezes are recorded per reason. For every reason, each issued serial either is frozen for that reason or is not. A reason can be any bytes32 value, including zero; its meaning is defined by the implementation.
A serial is frozen if and only if it is frozen for at least one reason.
After every state-changing call has completed, whether a serial is frozen for the reason reason MUST be determined by the most recent event so far among the SliceFrozen and SliceUnfrozen events that have the same reason and cover the serial: if it is SliceFrozen, the serial is frozen for reason; if it is SliceUnfrozen, or if there is no such event, the serial is not frozen for reason. Any operation that changes the frozen state, including one that freezes serials at issuance, therefore has to emit the corresponding events. An event can cover serials whose state does not change.
Every SliceFrozen and SliceUnfrozen event MUST have amount > 0 and start + amount <= serialsIssued(), and MUST be emitted after the Transfer event that issues the serials it covers. An operation that freezes serials at issuance therefore has to emit the Transfer event of the issuance first and SliceFrozen after it.
Freezing follows the serial. Under clause 3, a change of a serial’s holder does not change the reasons for which it is frozen, unless the same operation emits the corresponding events for it.
After a successful call to freezeSlice(start, amount, reason) completes, the serials start through start + amount - 1 MUST all be frozen for reason.
After a successful call to unfreezeSlice(start, amount, reason) completes, the serials start through start + amount - 1 MUST all be not frozen for reason.
freezeSlice and unfreezeSlice MUST NOT change the frozen state of any other serial, and MUST NOT change whether any serial is frozen for any other reason. The propagation required by “Freezing and defragmentation” is not limited by the preceding sentence.
freezeSlice and unfreezeSlice MUST revert if amount is zero or if start + amount is greater than serialsIssued().
An implementation MUST restrict who can call freezeSlice and unfreezeSlice. Who can call them for which reason is up to the implementation, which SHOULD document it; for the same reason, the addresses that can call freezeSlice can differ from the addresses that can call unfreezeSlice. An implementation MAY reject a call on other grounds, for example by requiring a delay or approval by several parties. Whether an address can freeze or unfreeze issued serials for a given reason is reported by canFreeze and canUnfreeze respectively (see clause 8 of “Freeze queries”).
An implementation MAY provide other functions that change the frozen state. These functions MUST follow clauses 3 to 5 and clause 12 and, as in clause 10, MUST restrict who can call them. Those among them that freeze or unfreeze issued serials are also subject to clause 8 of “Freeze queries”.
The operator of every SliceFrozen and SliceUnfrozen event MUST be the msg.sender that initiated the operation, that is, the address whose call to the contract made it emit the event. This applies to every such event the contract emits: those emitted by freezeSlice and unfreezeSlice, by the other functions of clause 11, by an operation that freezes serials at issuance, and by the propagation required by “Freezing and defragmentation”. operator plays no part in clause 3. An event can cover serials that are already frozen for the reason, so operator only says who initiated the call that emitted this event.
Freeze queries
A reason is in use if and only if some serial that is issued and not destroyed is currently frozen for it.
frozenSpanAt(serial) reports whether serial is frozen, together with a sequence of consecutive serials starting at it that share the same frozen state, that is, a span (see “Definitions”). For an issued serial, it MUST return a (frozen, length) that satisfies the following conditions: length is at least 1; serial + length is not greater than serialsIssued(); the serials serial through serial + length - 1 are all frozen if frozen is true and are all not frozen if frozen is false. The state here is only whether a serial is frozen; the reasons for which these serials are frozen can differ from one serial to another. Destroyed and consolidated serials have a frozen state too (see clauses 1 and 3 of “Freezing and unfreezing”), and this clause applies to them as well. For a serial that has not been issued, it MUST return (false, 0).
frozenSpanAt SHOULD return the largest length that satisfies clause 1. Callers MUST NOT assume that the returned span is the longest.
frozenBalanceOf(account) MUST equal the number of frozen serials held by account.
freezeReasonsOf(account) MUST return two arrays of the same length. The values in reasons MUST be pairwise distinct; every amounts[i] MUST be greater than zero and MUST equal the number of serials held by account that are frozen for reasons[i]. Every reason for which some serial held by account is frozen MUST appear in reasons. The order of the entries in the arrays is not specified.
A serial that is frozen for several reasons is counted once under each of them, so the sum of amounts can be greater than frozenBalanceOf(account).
freezeReasonInfo(reason) MUST NOT revert. For every reason in use, the returned name MUST be non-empty. name SHOULD be short enough to be displayed on one line.
For every reason in use, uri SHOULD be non-empty; for other reasons it MAY be the empty string. When it is not empty, it SHOULD give the description document of this reason (see “Description document”). The description document of a reason in use SHOULD contain authority and contest in properties (see clause 5 of “Description document”). When the name in the document differs from the name returned by freezeReasonInfo, the latter prevails.
canFreeze(reason, account) and canUnfreeze(reason, account) report the restriction on callers required by clauses 10 and 11 of “Freezing and unfreezing”, and they MUST NOT revert. In this clause, a freezing function is freezeSlice or any function that an implementation provides under clause 11 of “Freezing and unfreezing” and that can make issued serials frozen for a reason; an unfreezing function is unfreezeSlice or any function that an implementation provides and that can make serials no longer frozen for a reason. When the restriction on callers permits account, as msg.sender, to call at least one freezing function so that serials become frozen for reason, canFreeze MUST return true; otherwise it MUST return false. The same holds for canUnfreeze and the unfreezing functions. Therefore, when canFreeze(reason, account) returns false, every call by account to a freezing function that would make serials frozen for reason MUST revert; and when canUnfreeze(reason, account) returns false, every call by account to an unfreezing function that would make serials no longer frozen for reason MUST revert. That it returns true does not guarantee that a call succeeds: when the restriction on callers permits account to call but the call would be rejected on other grounds (see clause 10 of “Freezing and unfreezing”), for example because a delay has not yet passed, approvals are still missing, or account can do so only for some of the serials, it MUST still return true. The return value MAY depend on time and on other state of the contract, and no event has to be emitted when it changes.
canFreeze and canUnfreeze do not say who can perform forced operations. Nor do they address operations that freeze serials at issuance, so the operator of a SliceFrozen event is not necessarily an address for which canFreeze returns true.
Forced transfer and destruction
In this subsection, a forced operation is an operation that is initiated by an authorized party, does not need the holder’s consent, and either transfers serials from their holder to another address or destroys them.
A forced operation SHOULD act only on frozen serials: when any of the serials that a forced operation names is not frozen, the contract SHOULD revert. This applies to every forced operation the contract provides, not only to the two functions of this interface. An implementation SHOULD document whether it requires the serials to be frozen first.
A successful call to forcedTransferSlice(from, to, start, amount) MUST change the holder of the serials start through start + amount - 1 from from to to, and MUST NOT change the holder of any other serial.
A successful call to destroySlice(from, start, amount) MUST destroy the serials start through start + amount - 1, and MUST NOT change the holder of any other serial.
These two functions MUST revert in any of the following cases: amount is zero; any of these serials is not held by from, including serials that have not been issued and serials that are destroyed or consolidated. forcedTransferSlice MUST revert when to is the zero address or equals from. When serials are not held by from, the contract SHOULD revert with ERC8527NotHeld(from, start, amount).
These two functions MUST NOT change the frozen state of any serial and MUST NOT change any allowance. If the serials moved by a forced transfer are frozen, they are still frozen for the same reasons once to holds them; unfreezing them is still done through unfreezeSlice.
Forced operations are not among the operations that “Transferable balance” addresses. They are not subject to clauses 2 to 5 of that section, nor to the flow rules of the classification extension.
A forced operation emits SliceTransferred and Transfer events as specified in “Events”; in a destruction, to is the zero address. In addition, for every Transfer(from, to, value) event emitted by a forced operation, the contract MUST emit, after that event and before it emits the next Transfer event, one or more SliceForciblyTransferred(from, to, operator, start, amount) events: each has the same from and to as that Transfer event, its operator is the msg.sender that initiated the forced operation, and their slices are pairwise disjoint and together are exactly the serials reported by the SliceTransferred events that belong to that Transfer event. forcedTransferSlice and destroySlice MUST emit exactly one such event, whose start and amount are the same as the arguments of the call.
An implementation MUST restrict who can call forcedTransferSlice and destroySlice. Who can call them is up to the implementation, which SHOULD document it. An implementation MAY reject a call on other grounds, for example by requiring a delay or approval by several parties. A contract that does not provide forced transfer or destruction MAY make the corresponding function revert for any caller.
An implementation MAY provide other functions that perform forced operations, for example functions that take a position hint or that handle several slices in one call. They MUST follow clauses 5 and 7 and, as in clause 8, MUST restrict who can call them; the recommendation in clause 1 applies to them as well.
Freezing and defragmentation
Frozen serials cannot be consolidated: a defragmentation MUST revert if any of the named serials is frozen. The contract SHOULD revert with ERC8527NotConsolidatable(account, starts[i], amounts[i]), where account is the holder of these serials and (starts[i], amounts[i]) is a slice that contains a frozen serial. The new serials are therefore not frozen for any reason when the defragmentation completes, which is the state their old serials had at the time of the defragmentation.
A freeze propagates to successors. After a successful call to freezeSlice(start, amount, reason), the successor of every consolidated serial among the serials start through start + amount - 1 MUST also be frozen for reason; when that successor is itself consolidated, the same holds for its successor, and so on up to a serial that is not consolidated.
An unfreeze propagates in the same way. After a successful call to unfreezeSlice(start, amount, reason), the successors described in clause 2 MUST all be not frozen for reason.
Under clause 3 of “Freezing and unfreezing”, every change that propagation makes to the state of a successor has to be reported by the corresponding SliceFrozen or SliceUnfrozen event.
Other functions that change the frozen state, which an implementation provides under clause 11 of “Freezing and unfreezing”, MUST propagate in the same way.
Propagation makes the cost of a freeze or an unfreeze grow with the number of defragmentation records it passes through. When a call does not fit in one transaction, the caller can split the slice into several calls, or freeze later serials of these units instead: a freeze of a serial passes only through the defragmentation records from that serial onward. Clause 2 holds for consolidated serials of every generation, so freezing any serial a unit has had has the same effect; if these serials are consolidated again after the call is sent and before it executes, the freeze still propagates to the new successors. Propagation goes only toward successors and happens only at the time of a call: unfreezing a successor directly does not change the state of its earlier serials, which stay frozen for the reason while the successor no longer is; a later freeze of an earlier serial propagates to this successor again. Forced transfer and destruction act on the serial a unit has now: a consolidated serial has no holder (see clause 4 of “Forced transfer and destruction”). A contract that does not open defragmentation has no consolidated serials, and the rules of this subsection hold trivially.
Classification extension
The classification extension is OPTIONAL. A contract that implements it MUST implement the core interface and the IERC8527Classified interface.
interfaceIERC8527Classified/* is IERC8527 */{/// @notice Emitted when the class of the `amount` consecutive serials starting at `start` is
/// set to `classId`.
eventSliceClassified(uint256start,uint256amount,bytes32classId);/// @notice The class of `serial`, and a span of serials of that class. Zero is the default
/// class.
/// @dev The `length` consecutive serials starting at `serial` all have the class `classId`.
/// `length` is zero if `serial` has not been issued.
functionclassSpanAt(uint256serial)externalviewreturns(bytes32classId,uint256length);/// @notice Whether the class `classId` allows a serial of that class held by `from` to be
/// moved to `to` at present.
/// @dev `to` is the zero address for a burn. Freezing is not taken into account.
functionclassAllows(bytes32classId,addressfrom,addressto)externalviewreturns(bool);/// @notice The balance of `account` broken down by class.
/// @dev `amounts[i]` is the number of serials held by `account` whose class is `classIds[i]`.
/// Frozen serials are included.
functionclassesOf(addressaccount)externalviewreturns(bytes32[]memoryclassIds,uint256[]memoryamounts);/// @notice A description of the class `classId`.
/// @dev `name` is a short human-readable name, and `uri` points to a JSON document or is an
/// empty string.
functionclassInfo(bytes32classId)externalviewreturns(stringmemoryname,stringmemoryuri);}
supportsInterface MUST return true for 0xb62c1e43, the ERC-165 identifier of IERC8527Classified.
This extension specifies how classes are attached to serials, how they are reported, and how transfers obey the flow rules of classes. It does not specify which classes exist, or who can set or change them; these are up to the implementation. It does, however, require that every class an implementation uses can describe itself through the contract. How classes can be used is shown in “Examples of classes”.
Classes
Every issued serial has a class, which is a bytes32 value, written classId in the interface. Zero is the default class.
The meaning of a non-zero class is defined by the implementation and described through classInfo (see “Description”). An implementation SHOULD also document who can set and change classes.
classSpanAt(serial) reports the class of serial together with a sequence of consecutive serials starting at it that have the same class, that is, a span (see “Definitions”). For an issued serial, it MUST return a (classId, length) that satisfies the following conditions: classId is the current class of serial; length is at least 1; serial + length is not greater than serialsIssued(); and the serials serial through serial + length - 1 all have the class classId. For a serial that has not been issued, it MUST return (bytes32(0), 0). It SHOULD return the largest length that satisfies these conditions, and callers MUST NOT assume that the returned span is the longest.
After every state-changing call has completed, the class of a serial MUST equal the classId of the most recent SliceClassified event so far that covers it; if there is no such event, it MUST be zero. Any operation that changes a class, including one that issues serials with a non-zero class, therefore has to emit the corresponding event. An event can cover serials whose class does not change.
Every SliceClassified(start, amount, classId) event MUST satisfy amount > 0 and start + amount <= serialsIssued(), and MUST be emitted after the Transfer event that issues the serials it covers. An operation that issues serials with a non-zero class therefore has to emit the Transfer event of the issuance first and SliceClassified after it.
A class follows its serial. Under clause 4, neither a change of the holder of a serial nor the destruction or consolidation of the serial changes its class, unless the same operation emits a SliceClassified event for it.
In a contract that also implements the freezing extension, classes and freezes are recorded separately. Under clause 4 of this section and clause 3 of “Freezing and unfreezing”, freezing or unfreezing a serial does not change its class, and setting the class of a serial does not change its frozen state.
Flow rules
A class can carry a flow rule, which restricts from whom and to whom units of that class can be transferred. When a flow rule restricts the destination by the payee’s address, an address it allows transfers to is called a permitted recipient of the class.
classAllows(classId, from, to) reports whether a serial of class classId held by from is currently allowed by its class to be transferred to to. to being the zero address denotes a burn. The function does not take into account whether the serial is frozen.
classAllows(bytes32(0), from, to) MUST return true for all from and to.
classAllows MUST NOT revert. For a non-zero class that is not in use (see “Description”), the return value is not specified.
The return value MAY depend on time and on other state of the contract, for example a list of addresses. No event has to be emitted when the return value changes.
In a contract that implements this extension, let c be the class of a serial serial: when classAllows(c, from, to) returns false, serial is not transferable for (from, to). The flow rule of a class is one of the states attached to a serial that “Transferable balance” refers to. Therefore, in a contract that implements this extension and has no other restrictions attached to serials, transferableBalanceOf(from, to) equals the number of serials held by from whose class c makes classAllows(c, from, to) return true; when the freezing extension is implemented as well, frozen serials have to be excluded too.
Classes and defragmentation
The serials of one defragmentation have to belong to the same class: a defragmentation MUST revert if the named serials do not all have the same class. The contract SHOULD revert with ERC8527NotConsolidatable(account, starts[i], amounts[i]), where account is the holder of these serials and (starts[i], amounts[i]) is a slice that contains a serial whose class differs from that of the serial starts[0].
After the defragmentation, the class of the new serials MUST be the class the old serials had at the time of the defragmentation. When this class is not zero, under clause 4 of “Classes” the contract has to emit a SliceClassified event for the new serials after the SliceConsolidated events.
This proposal does not require a change of class to propagate to successors: setting the class of a consolidated serial after the defragmentation need not change the class of its successor. When an implementation makes such an operation act on successors as well, it likewise has to emit events for the successors under clause 4 of “Classes”.
Description
A class is in use if and only if some serial that is issued and not destroyed currently belongs to it.
classesOf(account) MUST return two arrays of the same length. The values in classIds MUST be pairwise distinct; every amounts[i] MUST be greater than zero and MUST equal the number of serials held by account whose class is classIds[i]. Every serial held by account MUST be counted, including frozen serials; serials of the default class are counted under zero. The order of the entries in the arrays is not specified.
The sum of amounts therefore equals balanceOf(account).
classInfo(classId) MUST NOT revert. For every non-zero class that is in use, the returned name MUST be non-empty. name SHOULD be short enough to be displayed on one line.
uri MAY be the empty string. When it is not empty, it SHOULD give the description document of the class (see “Description document”). When the name in the document differs from the name returned by classInfo, the latter prevails.
On-behalf defragmentation extension
The on-behalf defragmentation extension is OPTIONAL. A contract that implements it MUST implement the core interface and the IERC8527DefragmentationFor interface.
interfaceIERC8527DefragmentationFor/* is IERC8527 */{/// @notice Gives the units with the serials in the slices `(starts[i], amounts[i])`, held by
/// `account`, new consecutive serials starting at `newStart`.
/// @dev MUST revert if `account` is the caller, or if the caller may not defragment for
/// `account`. Otherwise the requirements of `defragmentSlices` apply, with `account` in
/// place of the caller as the holder.
functiondefragmentSlicesFor(addressaccount,uint256[]calldatastarts,uint256[]calldataamounts)externalreturns(uint256newStart);/// @notice Whether `operator` may call `defragmentSlicesFor` for `account`.
/// @dev MUST return false if `operator == account`.
functioncanDefragmentFor(addressoperator,addressaccount)externalviewreturns(bool);}
supportsInterface MUST return true for 0xfddc4edb, the ERC-165 identifier of IERC8527DefragmentationFor.
This extension lets a party other than the holder defragment for an account, for example for a pool that cannot initiate calls itself. It does not specify who can defragment for whom; that is decided by the implementation, for example an address designated by the issuer, an address the holder itself has authorized, or any caller once the account holds more than a certain number of slices. A holder still defragments its own units with the defragmentSlices of the core.
A successful call to defragmentSlicesFor(account, starts, amounts) acts on all the serials in the slices (starts[i], amounts[i]), which are held by account. It MUST satisfy the requirements that clauses 1 to 6 of “Defragmentation” place on defragmentSlices, with account in place of the caller that holds the units; under clause 5 it emits exactly one SliceConsolidated(account, msg.sender, starts[i], n + p_i, amounts[i]) for each i.
A call in which account equals msg.sender MUST revert.
canDefragmentFor(operator, account) answers whether operator can call defragmentSlicesFor for account. It MUST return false when operator == account. For an operator that the implementation does not allow to call defragmentSlicesFor for account, it MUST return false, and a call by that operator for account MUST revert; for an operator that is allowed, it MUST return true. A call can still fail for other reasons when it returns true, for example because some of the named serials are frozen, or because the call does not reach the minimum number of slices the implementation requires of a defragmentation.
Implementations SHOULD document who can defragment for whom. No event is required when the value returned by canDefragmentFor changes.
“Freezing and defragmentation” and “Classes and defragmentation” apply to defragmentSlicesFor as well (see “Defragmentation”).
Description document
When the uri returned by freezeReasonInfo or classInfo is not empty, it gives a description document that explains the reason or class. The freezing extension and the classification extension use the same document format.
uri SHOULD be a data URI that begins with data:application/json and contains the document directly. It MAY be another URI that points to the document.
The document SHOULD be a JSON object that conforms to the structure below. name and description have to be present: name is the name of the reason or class, and description is an explanation intended for holders. The other fields can be omitted.
properties is an object that holds properties of the reason or class, for example parameters encoded in the class. Apart from the five keys that clause 5 defines for reasons, its internal structure is not specified, and its values can be strings, numbers, objects or arrays.
The document MAY contain fields that are not defined here. A party that reads the document SHOULD ignore fields it does not recognize.
In the description document of a reason, the five keys authority, release, disposal, contest and reference in properties have the meanings below. All of them are optional, and their values are text (strings) intended for holders. authority says who can freeze for this reason and who can release it. Where these parties are specific addresses, it SHOULD give the addresses; a holder can check them with canFreeze and canUnfreeze. release gives the conditions under which the reason is released, including any time limit or review date. disposal says whether units frozen for this reason can be destroyed or forcibly transferred, by whom, and how long after the freeze at the least. contest says to whom and in what way a holder can contest a freeze. reference gives the law, contract term or other basis for this reason.
{"title":"Description Document","type":"object","required":["name","description"],"properties":{"name":{"type":"string","description":"The name of the freeze reason or class."},"description":{"type":"string","description":"An explanation of the freeze reason or class, intended for holders."},"image":{"type":"string","description":"Optional. A URI pointing to a resource with mime type image/*, or a data URI containing the image."},"properties":{"type":"object","description":"Optional. Arbitrary properties. Values may be strings, numbers, objects or arrays. In the document of a freeze reason, the keys below have the meaning given here.","properties":{"authority":{"type":"string","description":"Optional. For a freeze reason: who can freeze for it and who can release it, with their addresses where they are specific addresses."},"release":{"type":"string","description":"Optional. For a freeze reason: the conditions under which it is released, including any time limit or review date."},"disposal":{"type":"string","description":"Optional. For a freeze reason: whether units frozen for it can be destroyed or forcibly transferred, by whom, and how long after the freeze at the least."},"contest":{"type":"string","description":"Optional. For a freeze reason: to whom and in what way a holder can contest a freeze."},"reference":{"type":"string","description":"Optional. For a freeze reason: the law, contract term or other basis for it."}}}}}
The following is an example of a description document for a reason.
{"name":"Court order","description":"Units frozen under a court order served on the issuer.","properties":{"authority":"The issuer's compliance multisig (0x1111111111111111111111111111111111111111) freezes and releases for this reason, each time on a written order of a court.","release":"Released when the court lifts the order. The issuer reviews every freeze 90 days after it was made.","disposal":"Units can be forcibly transferred or destroyed only under a final judgment, and no earlier than 30 days after the freeze.","contest":"Write to the issuer's compliance office at the address given in the token's terms of issue, quoting the transaction of the freeze.","reference":"Section 9 of the token's terms of issue."}}
The following is an example of a description document for a class.
{"name":"Locked until 2030","description":"Units of this class cannot be transferred before 1 January 2030 (UTC).","image":"data:image/svg+xml;base64,PHN2Zy8+","properties":{"unlock_time":1893456000}}
name, description and image are the same as in the metadata of ERC-721, and properties is the same as in the metadata of ERC-1155. The five keys of clause 5 are defined by this proposal for the description document of a reason; they are placed in properties, so a wallet that only knows ERC-1155 metadata can still display them one by one.
Rationale
This section summarizes the design decisions and the main reasons for them. The full discussion, including the alternatives that were considered and the point-by-point comparisons with other standards, is in rationale.md.
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. Examples are stablecoins and deposit receipts for which action can be taken against specific funds, a single bond issue, subsidies and consumption vouchers that can only be paid to designated addresses, in-game currency, and points. Units differ only in whether they can be transferred out, to whom they can be transferred, and where they came from.
The following cases do not suit this proposal, or cannot conform to it.
Measures against accounts, for example blocking an address. These need a separate account-based mechanism, such as those defined by ERC-3643 and ERC-7943; such a mechanism can be used on the same token as this proposal.
Assets with different rights in one contract. 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 do not represent different rights”).
Tokens that charge a fee on transfer, or that change balances without issuance or destruction, for example tokens that scale balances proportionally. They cannot conform to this proposal: a transfer has to move exactly value serials, and a balance changes only together with a Transfer event.
Assets that need privacy (see “Reduced fungibility and privacy”).
Assets that suit this proposal also enter contracts with frequent transfers, such as market-making pools and lending pools, and these contracts interact with such a token 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”).
Design of serials
The specification describes state as a mapping from serials to holders, and slices are only the encoding used by events and views. How holdings are stored, and which units a transfer by amount draws on, are up to the implementation; the specification instead requires every movement to be reported, so the rule actually in use is observable.
Serials are issued consecutively from 0, and a transfer does not change the serials of the units it moves. The units descended from a holding are therefore exactly the serials that holding consisted of, transfers create no ancestry graph that has to be recorded or traversed, and freezing by slice is complete and free of races. The only operation that renumbers units is a defragmentation, which records the correspondence between old and new serials in the contract, and freezes propagate along that record (see “Design of defragmentation”). On a token that does not open defragmentation, the issuer can exchange a scattered holding: 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.
transferSlices lets a holder name the units it sends. It is part of the core because it is a function called by wallets, which every token that conforms to this proposal has to provide in the same way. On a token whose holders can freely use several accounts, it gives holders no new capability: transferring by amount back and forth between accounts the holder controls can single out particular units just as well; on a token that only registered accounts can hold, it gives holders a choice they did not have before. This proposal defines no function for a spender to transfer by serial, because approve did not originally grant the power to choose which units are drawn on.
Relation to ERC-20
This proposal changes none of the functions or events of ERC-20 and only settles a few points that ERC-20 leaves open or merely recommends, for example that a failure reverts instead of returning false, that the number of decimals must not change, and that a transfer to the zero address cannot be used to destroy units; it also recommends the errors of ERC-6093 and the signatures of the burn functions burn, burnFrom and burnSlices (see “Requirements on ERC-20 behavior”). The approve race and approval by signature (for example ERC-2612) are unrelated to the identity of units and are left to existing proposals.
balanceOf changes only together with a Transfer event, so frozen units remain counted in the balance, and the transferable balance is given separately by transferableBalanceOf. Otherwise indexers that compute balances by summing Transfer events would get wrong results, and totalSupply would either no longer equal the sum of the account balances or turn freezing into a reduction of supply. An allowance keeps its ERC-20 meaning and is only an upper limit on an amount; neither freezing nor the rules of classes change it.
Form of the queries and events
transferableBalanceOf is part of the core and takes the destination as a parameter. Wallets and contracts then need to ask only one question, namely how much can be transferred from here to there now, whichever extensions the token implements. frozenSpanAt and classSpanAt return, together with the state of a serial, the length of the span of serials in the same state that starts at it, because a token with 18 decimals has 10^18 serials per whole token and querying serial by serial would be pointless. This proposal provides no on-chain lookup of the holder of a serial, because that would need an ordered index that is updated on every transfer; the holder of a serial can be derived from the events.
The slices a transfer moves are reported slice by slice in SliceTransferred events, one slice per event, and a batch event carrying arrays is not used: the most common transfer moves a single slice, for which a single event is cheaper, and indexers need to support only one encoding. The SliceTransferred event accompanies the ERC-20 Transfer event and never replaces it, which differs from ERC-2309. The order of the events is specified, so an indexer can attribute every SliceTransferred event to the Transfer it belongs to without heuristics.
Dust, the acceptance check and receipt notification
Every non-adjacent slice a recipient holds has a cost (see “Dust attacks”). This cost comes from the identity this proposal keeps for every unit. This proposal chooses to keep that identity, and makes the following choices among the ways of dealing with dust.
No minimum transfer amount is set. Rejecting incoming transfers by amount would expose payers that know only ERC-20 to failure when paying any account. A minimum amount also does not stop fragmentation; it only makes each slice of dust cost a little more value. The right threshold differs from token to token and from account to account.
The acceptance check is optional and read-only. A receiving contract can refuse an incoming transfer, and the token asks it at the time of the transfer. The check is optional because the core only adds serials and does not change whether any transfer succeeds or fails. It applies to every form of transfer initiated by a holder or by a spender, with no separate safe transfer, because the sender chooses which path to take and a check on a separate path cannot stop something that is sent on purpose. It asks only contracts that declare through ERC-165 that they implement the acceptance interface, so existing contracts that know only ERC-20 are paid as usual. Unlike the callbacks of ERC-721, ERC-1155, ERC-777 and ERC-3525, it is a query made with STATICCALL, not a notification: the called contract cannot emit an event or complete another transfer. A payer can simulate the transfer in advance, or query the receiving contract as the token would (with the caller set to the token contract’s address); for a transfer by amount the number of slices is not known in advance, so only a simulation works. The receiving contract sees the number of slices, because its cost is counted per slice.
No registered checker is defined. If every account could register a checker contract with the token, addresses without code could use arbitrary rules as well. This proposal does not adopt that approach: the token would have to store a registration for every account, a shared checker contract raises a new question of trust, and the contracts that most need rules of their own can implement the acceptance interface themselves; an address that has set a delegation under EIP-7702 has code as well, and it is likewise a receiving contract when its delegation target implements the interface. An implementation can still provide, on its own, limits set by accounts, for example a receive limit for accounts (see “The acceptance check and failed payments”).
No receipt notification is defined. A contract that needs to act when it receives units can use ERC-1363, which a token can implement as well. This proposal defines no notification attached to every transfer: with such a notification, any contract that pays out would run the payee’s code when it pays, although the paying contract is not the party that chose the notification; and if the notification could make a transfer fail, the read-only acceptance check could no longer tell whether a transfer would succeed. A contract that needs to know which serials an incoming transfer brought, for example a custody contract, can give every payer a dedicated deposit address, where a small contract moves the units it receives to the main contract with transferSlices.
Design of the freezing extension
Freezing is an optional extension, because freezing with reasons is not cheap to implement and an issuer that only wants to sort units into a few classes has no use for it. It is aimed at specific units, wherever they are. ERC-3643 and ERC-7943 freeze an account or a given amount within an account; their freeze functions carry no reason and cannot name specific serials, so this proposal does not reuse them. The two kinds of freeze complement each other, and a token can use both.
Freezes carry a reason, because several parties can have the right to freeze the same units at the same time, for example when units are first pledged and later put under a judicial freeze; unfreezing lifts only one reason. The freeze functions are part of the interface, because a pledge contract, a custodian and an agency carrying out a court order deal with many different tokens; who can call them for which reason is up to the implementation.
The events for freezing, unfreezing and forced operations all carry operator, the address that initiated the call, because the party with the right is often a multisig, a timelock or a pledge contract, which the sender of the transaction does not reveal. canFreeze and canUnfreeze answer whether an address can freeze for a reason and whether it can unfreeze for it, and do not list the addresses that can, so they can be implemented on any permission mechanism; a holder gets addresses from authority in the description document and from the operator of the events, and checks them with these two queries. That an address that is not permitted gets false is a requirement and not a recommendation, and the queries cover every function that freezes or unfreezes issued serials, not only freezeSlice and unfreezeSlice; otherwise false would not show that the address cannot freeze. A call can still fail when the query returns true, because conditions such as a delay or approval by several parties are not part of the restriction on callers. 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.
Destruction and forced transfer are in the same extension as freezing, because an issuer that has the right to freeze units usually also needs to dispose of them after freezing. A forced transfer does not change frozen state, since otherwise the party executing it could lift reasons set by others; nor can it be replaced by destruction followed by a new issuance, because the newly issued units have new serials. The SliceForciblyTransferred event distinguishes forced operations from the holder’s own transfers. This proposal recommends that forced operations act only on frozen serials, but does not make it a requirement, because a contract could freeze and dispose in the same transaction. Nor does it specify a minimum delay between a freeze and a disposal: the right length differs from reason to reason, and a requirement that can be set to zero guarantees nothing. A deployment that needs a delay can give the right of disposal to a contract with a timelock and state the length in the reason’s description document (in properties, under disposal); the side effect of a delay in shared contracts is described in “Powers of the authorized party”.
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, at a cost that it pays once, at a time of its choosing; without defragmentation, the cost of these scattered slices is paid again every time they change hands, and is passed on to the next holder with each payment. The operation is named after its purpose, defragmentation; the state of the old serials that were replaced is called consolidated, and the event SliceConsolidated and the query consolidatedSpanAt report that state, so they are named after it.
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; the cost falls on defragmentations and on the freezes that pass through the records (see “Costs of defragmentation”).
New serials are assigned in ascending order of the old serials, so units that come from the same old slice receive new serials that are still adjacent, and a holder 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 the new serials need one definite class.
Defragmentation is in the core because fragmentation comes from keeping accounts by serial itself, so the remedy should not depend on which extensions a token chose; and defragmentSlices is a function called by wallets, which every token has to offer in the same way. Who can defragment is left to the implementation, and both approaches use the same interface: when it is open to all holders, the issuer does not have to authorize accounts one by one, and 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. An implementation can also require a defragmentation to include at least a certain number of slices (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.
Defragmenting for other accounts is in the optional “On-behalf defragmentation extension”. It is needed 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. canDefragmentFor, like canFreeze, only answers whether an address can defragment for an 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. The extension cannot be used for the caller’s own units; 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.
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. 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. The units being moved are not themselves renumbered, so SliceTransferred reports exactly the serials the recipient receives. This proposal defines no query for this, because the only calls affected are those that name units by their old serials and are not yet included, and they fail rather than move the wrong units (see “Costs of defragmentation”).
Design of the classification extension
A class answers “where does this unit come from and where can it go”; freezing answers “can this unit move now”; the two are recorded separately. A class is an opaque bytes32 whose meaning is up to the implementation. classAllows takes a class rather than a serial as its parameter, so a rule can change with time or with a list without state having to be updated for every affected serial.
Units of all classes are counted in the same ERC-20 balance. Classes are therefore not partitions in the sense of ERC-7518; they distinguish only where units can go and where they come from, not rights (see “Classes do not represent different rights”).
Classes also differ from wrapper contracts, such as the purpose bound money defined by ERC-7291. A wrapper token is a different asset and can be transferred freely among holders without the constraint being defeated. Units constrained by a class remain the same token, and the constraint must be written into the flow rule: if a class allows its units to be transferred to any address, they can be used as ordinary units. When the constraint is set by the token’s issuer, classes can be used; when it is set by someone else, and the token’s implementation provides that party no entry point for setting classes and rules, a wrapper contract should be used.
Examples of classes
This proposal does not specify which classes exist. The following examples are arranged by asset. The “Flow rules” column gives the value that classAllows(classId, from, to) returns when to is not the zero address. More examples are in “Examples of classes” in rationale.md.
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 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
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”). 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, or it can be changed to the default class in that transfer, in which case the constraint falls only on the payer (see “Destination-dependent flow rules and contracts”). In a payment by amount to a permitted recipient, the selection rule might use up units of the default class first; an implementation can make its selection rule use the restricted units first in such payments, and a holder can also name them with transferSlices.
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”).
Describing reasons and classes
Once the meaning of reasons and classes is left to the implementation, a wallet faces a bytes32 it does not recognize. The specification therefore requires every reason in use and every non-zero class in use to have an on-chain name, which a wallet can obtain with read-only calls alone; longer descriptions go into an optional description document.
classInfo returns only a name and a uri; there is no identifier field for programs to recognize. Such an identifier is useful only when its values are agreed on and constrain how a class behaves, and the rules of real-world classes are often a combination of several conditions, for example a restriction on payees together with a validity period, which a single value cannot declare. A program that knows a token can recognize its classes by classId, and parameters meant for programs can go in the properties of the description document. A later proposal that defines identifiers common to all tokens can declare them through an interface of its own.
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, where a holder can find them starting from the reasons for which its own units are frozen, and a wallet can display them under fixed headings. They are placed in properties, and no separate top-level fields are defined: the top level of the document stays the same as the metadata of ERC-721 and ERC-1155, and a wallet that only knows that metadata can display them as well. They are text and not a structure for programs, because a contested freeze is handled off-chain. Matters that concern a single freeze, for example a particular court order or its review date, are not among them: a reason usually stands for a kind of freeze, and using a separate reason for every freeze would increase the number of reasons in use (see “Number of reasons”).
Relation to ERC-8047
ERC-8047 is a draft at the time of writing. It has the same goal as this proposal and takes a graph approach: every transfer creates a new token id that records its parent. This proposal differs in four respects.
The token remains an ERC-20 token, so existing wallets, exchanges and contracts can use it without modification.
Transfers do not renumber units, so transfers create no graph that has to be maintained. If each slice of consecutive serials that a holding originally contained is frozen once, the freezes name exactly all of the units descended from that holding, however many holders they have since been divided among. Only a defragmentation renumbers units; it records a one-to-one correspondence from old serials to new ones, and the contract propagates freezes along that record (see “Design of defragmentation”).
The balance and the transferable balance are given on-chain and do not have to be computed by off-chain services.
Putting together units received in several payments creates no new identity. An implementation can store adjacent serials as one slice, but the serials themselves do not change.
The two designs pay the same price: holdings fragment, and the cost of a transfer depends on how many pieces it moves.
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, except that the balance it displays can include units that cannot be sent. All of the queries needed to support this proposal fully can be made with read-only calls and need no indexer. The steps in detail, and how to explain to the user why part of a balance cannot be sent, are in wallet-support.md.
Backwards Compatibility
This proposal adds to ERC-20 and changes none of its functions or events, so existing wallets, exchanges and contracts interact with a token that conforms to this proposal as with any ERC-20 token. In several places where ERC-20 leaves a choice, this proposal specifies the behavior (see “Requirements on ERC-20 behavior”), and everything it specifies there is within what ERC-20 allows. Several behaviors differ from a minimal ERC-20 implementation and can matter to integrators:
The gas cost of a transfer is not constant. It grows with the number of slices the transfer has to move.
A transfer to the zero address reverts. A contract that relies on “transferring to the zero address” to destroy tokens needs to use a burn function instead.
When the freezing extension or the classification extension is implemented, a transfer can revert although balanceOf is sufficient, and balanceOf can exceed the amount an account is actually able to transfer. When the classification extension is implemented, the amount that can be transferred can also depend on the destination.
When the freezing extension is implemented, an account’s balance can decrease without the holder initiating it, as with other tokens that give an issuer confiscation powers.
On a token that supports the acceptance check, a transfer to a contract that implements the acceptance interface can revert even though the sender’s balance and transferable balance are both sufficient (see “Acceptance check”); a transfer to an address with code also pays the extra gas of querying it. Addresses without code and contracts that do not implement this interface are not affected. Tokens that do not support the acceptance check have none of these differences.
The serial of a unit can change through a defragmentation, including one that another party performs on the holder’s behalf and one performed in the course of a transfer. A defragmentation changes no balance and emits no Transfer, so integrators that use only ERC-20 functions and events are not affected. An indexer that reconstructs holdings from SliceTransferred events also has to process SliceConsolidated events.
Test Cases
The test cases are in test-cases.md. They are sequences of operations, which check, in order, issuance and transfers by amount, freezing and unfreezing, transferSlices and burnSlices, the classification extension, forced transfer and destruction, defragmentation, and the acceptance check. Each sequence lists, step by step, the calls, the events that are to be emitted and the values that the queries return. Under the assumptions stated in that file, the sequences hold for every implementation that conforms to this proposal, whatever its selection rule.
Reference Implementation
A reference implementation accompanies this proposal. Its code and tests are placed with the other assets of this proposal, and README.md describes the layout of the directory and how to run the tests. It implements the core interface, the freezing extension and the classification extension, supports the acceptance check, and in addition provides burn, burnFrom and burnSlices, as well as two groups of functions that this proposal does not define: forced transfer and destruction that take a position hint, provided under clause 9 of “Forced transfer and destruction”, and tidySlices, which only adjusts where holdings are stored and neither transfers nor renumbers anything. It does not implement ERC-1363.
The core contract ERC8527 implements ERC-20 and the core interface, and keeps defragmentation closed by default. The freezing extension, the classification extension, an example class that restricts destinations by payee address, the acceptance check, burning, tidySlices and the module that opens defragmentation are each a separate contract, which a token inherits as needed. Who can freeze, force transfers, and define and set classes is decided by authorization functions that the token implements itself. The storage of holdings sits behind an abstraction layer and has two interchangeable implementations: a slice stack (last-in-first-out) and a sorted array in ascending order of start. Both use one storage slot per slice; they serve to compare the gas of different data structures.
The reference implementation falls short of this proposal’s recommendations in several places: the cost of skipping serials that are not transferable is bounded only in the amortized sense; the cost of locating by serial is bounded only for the functions that take a position hint, and only on the slice stack; the default selection rule pays out first the units received most recently or the units with the largest serials; the defragmentation module does not by default limit how many slices a defragmentation includes, nor the rate at which defragmentation consumes serials (see “Finite serial space”); the on-behalf defragmentation extension is not implemented, and transfers do not defragment; and no receive limit for accounts is provided. To keep tokens within the contract code size limit, the parts of the freezing extension, the classification extension and defragmentation that transfers do not use are in separately deployed libraries, which a token links when it is deployed; with them, every combination of modules on the slice stack is within that limit as long as the deployment parameters of defragmentation keep their defaults, and the sizes of the combinations are listed in README.md. These places are described in reference-implementation.md, together with the storage of holdings, the libraries, the two selection rules, the storage of defragmentation records, and what the reference implementation does in the places that “Acceptance check” leaves up to the implementation.
Security Considerations
This section states, item by item, the risks that implementers, integrators and wallets need to know about, and the recommended practice. The three subsections “Fragmentation and gas”, “Dust attacks” and “The acceptance check and failed payments” are summaries; the full analysis is in security-considerations.md.
Freezing follows units, not people
Freezing a slice affects whoever holds those units when the freeze takes effect. If a thief sells stolen units before they are frozen, the units that end up frozen or destroyed belong to the buyer or to the liquidity pool that took them, while the thief keeps the proceeds. A recipient cannot know in advance that the units it accepts will later be frozen. A thief who observes a pending freeze can also try to sell ahead of it. Issuers need a clear policy on how quickly and under which conditions slices are frozen and on how innocent recipients are treated, and integrators have to treat a token that implements the freezing extension as they would any token whose issuer can freeze funds.
Descriptions are the token’s own claims
The names and documents returned by freezeReasonInfo and classInfo are all supplied by the token contract itself, and no third party verifies them. How a token actually behaves is determined by the values that transferableBalanceOf and classAllows return and by the outcome of the transfers themselves; when what a name says disagrees with that, a wallet cannot detect it from the interface alone. As for powers, the interface answers only whether an address can freeze or unfreeze for a given reason (canFreeze and canUnfreeze), and that answer too is given by the token contract itself; it does not say who can destroy or forcibly transfer, or who can set classes. Two tokens that both conform to this proposal can give holders entirely different guarantees, and integrators must read a token’s own documentation and code before integrating it.
Wallets must treat these strings as untrusted input: limit their length, filter out control characters and easily confused characters, and not parse them as markup. When uri is a data URI, the description document is in the return value of the call itself, and wallets should limit its length. When uri points to an external resource, fetching it reveals the user’s network address to an external server, and the document can also become unavailable or be replaced. Even when the document is on-chain, the image in it can still point to an external resource, with the same problems; the image itself is untrusted content too, for example an SVG can contain scripts. Wallets should therefore not depend on the description document to complete their display. The properties in the document are likewise only the token’s own claims, and a wallet cannot use them to decide whether a unit can be transferred out. The result of classAllows can change over time or as a list changes, and callers should not cache it.
The arrays returned by freezeReasonsOf and classesOf have no upper bound on their length. An implementation that encodes parameters into the class, for example by using a different unlock time for every lock, can leave one account holding a great many different classes, and a third party can also increase that number by transferring in units of different classes. Contracts that call these functions on-chain must take this into account.
Number of reasons
A serial can be frozen for several reasons at the same time. The cost of determining whether a serial is frozen can grow with the number of reasons in use, and every transfer has to make that determination. Implementations should limit the number of reasons that can be in use at the same time, or use a storage layout whose cost does not grow with the number of reasons. “In use” counts only serials that are not destroyed, while destroyed serials still keep their frozen state: issuing, freezing and then destroying, over and over, can leave behind many reasons that are no longer in use but still have records. Limiting only the number of reasons in use does not limit the growth of these records; implementations should make sure that transfers and account-level queries do not need to scan them.
The interface separates the power to freeze by reason, but it does not by itself guarantee that one party cannot lift another party’s reason: who can unfreeze for which reason is up to the implementation. A party that relies on a reason, for example a pledgee, must confirm that the token’s implementation does not allow anyone else to lift it. A reason only prevents the holder from transferring the units out, so that party also needs to confirm who can destroy or forcibly transfer frozen units.
Selection order can be influenced
Units held by a shared contract, such as a pool or vault, are paid out according to the implementation’s selection rule. Under last-in-first-out, the most recently deposited units are the next to leave, so a depositor can make it likely that particular units are passed on to the next withdrawer; under first-in-first-out they would instead sit behind earlier deposits. Whoever designs a token on this proposal has to consider how the rule distributes units that may later be frozen.
Holders can choose which units to send
A holder can use transferSlices to name the units it sends, for example to pay others first with the units it believes might later be frozen. How far this is a new capability depends on whether holders can freely use several accounts (see “Design of serials”). A recipient that cares which units it receives must check the serials reported by the SliceTransferred events and cannot look at the amount alone. This check can only be made off-chain: a contract cannot read events during execution, and this proposal has no function that makes a transfer by amount return the serials selected. A contract that needs to confirm on-chain which units it received needs to agree on a separate way of interacting with the payer, for example having the payer transfer in specified serials with transferSlices, and to bear the cost of checking its holding with queries such as sliceAt.
Fragmentation and gas
The cost of a transfer grows with the number of slices it moves: when the serials a transfer moves together form k non-adjacent slices, the contract has to emit at least k SliceTransferred events. Two accounts with the same balance and the same transferable balance can therefore pay very different costs for paying out the same amount, and in the extreme a single transfer can exceed the gas available to a transaction. The number of slices in an account can be inflated by others (see “Dust attacks”), which is most damaging for contracts that cannot split their outgoing transfers. Contracts that forward a fixed amount of gas with token transfers are not safe to use with these tokens. For accounts that receive payments over a long period, such as merchants, pools and vaults, integrators should evaluate on the target chain how much one transaction can actually transfer out of the account.
An implementation can reduce this cost in the following three areas.
The selection rule. An implementation’s selection rule should not pay out recently received small slices first; it can, for example, prefer a single slice that is enough to pay the whole amount. Such a rule likewise affects which units are paid to whom (see “Selection order can be influenced”). A selection rule changes which accounts accumulate scattered slices; it cannot eliminate fragmentation (see “Design of defragmentation”).
Slices that are not transferable. A transfer by amount has to skip serials that are not transferable (see clause 4 of “Transferable balance”). If an implementation leaves these slices on the selection path, every transfer pays for every slice it skips. This cost can be driven up by others, for example by transferring to a permitted recipient many small scattered slices of units that are subject to a flow rule: when the units still belong to their original class after they arrive, every later transfer by that recipient to an address the class does not allow has to skip them. Small scattered units that are frozen after they are transferred in give rise to the same situation. When enough slices are skipped, a transfer that does not exceed the transferable balance might not fit in one transaction. Implementations should take slices that are not transferable off the selection path.
Locating by serial.transferSlices, forcedTransferSlice and destroySlice have to locate the named serials in the account’s holding. In an implementation that locates them by scanning, the cost grows with the number of slices the account holds, and that number can be inflated deliberately: a holder can split its own holding into many slices beforehand, and after a freeze others can still transfer small scattered amounts of units to the account. In the extreme, a forced operation no longer fits in one transaction. Implementations should use a storage layout in which the cost of locating serials is bounded, or, as the freezing extension allows, provide additional functions that take the position of the slice as a hint and verify it.
A holder can use transferSlices to transfer the units out of a fragmented account over several transactions, but this does not help contracts that can only call transfer. A holder can use defragmentation to replace scattered slices with one consecutive slice (see “Defragmentation”). On a token that does not open defragmentation, non-adjacent slices cannot become one slice, and a scattered holding can only be exchanged by the issuer (see “Design of serials”).
Dust attacks
A dust attack is the sending of very small amounts of units to someone else’s account. In an ordinary ERC-20 token, the recipient bears no cost for a received amount. This proposal changes that: a received amount that is not adjacent to the serials the recipient already holds adds a slice to its holding, and that slice stays in the holding until it is transferred out, burned or destroyed; received units might also be frozen later. By the attacker’s aim, the following cases can be distinguished.
Raising costs. The attacker sends many very small non-adjacent slices into an account, raising the cost of its later transfers, operations by serial and account-level queries (see “Fragmentation and gas” and “Balance includes units that cannot be transferred”). If the selection rule pays out the most recently received units first, or the units with the highest serials first, the victim’s later payments also draw on the dust first and pass it on to the payees. The less a unit is worth, the cheaper dust is for the attacker; this should be considered when choosing the number of decimals, and “Finite serial space” needs to be considered as well.
Passing on history. Someone who holds stolen units, or units involved in a case, can split them into very small amounts before they are frozen and scatter them across a large number of unrelated addresses. The number of freezes needed does not change, because the scattered units are still within the few slices of consecutive serials they were in originally. The recipient’s other units are not affected either, because history follows units, not accounts. What increases is the work of disposal: an issuer’s policy should state how very small amounts scattered to unrelated accounts are treated. Once units scattered into a shared contract such as a pool or a vault are frozen, who bears the loss depends on whether the contract pays out by shares of balanceOf or by its own accounts, and on whether these units are in the end unfrozen or disposed of; while the freeze lasts, those who leave a contract that pays out by shares first bear no loss. Exchanges and compliance screening should assess an account’s exposure by serial, rather than treating the whole account as suspect because it once received units from a certain address.
Tracking markers. The attacker knows the serials it sent, and after these units enter a contract that mixes many people’s funds, such as a pool or an exchange, it can still tell from the serials paid out where they went (see also “Reduced fungibility and privacy”).
Zero-value transfers. This proposal emits no SliceTransferred event for a zero-value Transfer (see “Events”), so a wallet that displays history by SliceTransferred events does not show the zero-value entries that address poisoning forges. A very small real transfer sent from a look-alike address still has a SliceTransferred event, so wallets should not let users copy a payee address from the transaction history.
Dust can be dealt with in the following ways. On a token that supports the acceptance check, a receiving contract can refuse incoming transfers (see “Acceptance check”). An implementation can let accounts set a receive limit for themselves (see “The acceptance check and failed payments”), and can reduce the cost of dust through its selection rule and storage layout (see “Fragmentation and gas”). A holder can avoid the dust by using transferSlices to pay only units of its own choosing; on a token that provides burning by holders, it can also burn the dust, but frozen dust and dust whose class does not allow burning cannot be cleaned up this way.
The acceptance check is optional, and only contracts that implement the acceptance interface can refuse: on a token that does not support it, dust can be sent to any address; on a token that supports it, dust can still be sent to addresses without code and to contracts that do not implement the interface. A token that circulates publicly and will be held by contracts needs the acceptance check and a receive limit for accounts all the more. On a token that does not support the acceptance check, a contract that receives payments over a long period and cannot split its outgoing transfers can use transferSlices to pay only units of its own choosing, or can decline to integrate the token.
The acceptance check and failed payments
On a token that supports the acceptance check, a receiving contract can make transfers paid to it fail. This is what the acceptance check is for, and it also has the following consequences.
A payer can be blocked. A contract that pushes payments to addresses named by others, for example an auction that refunds the previous bidder when it receives a new bid, can have a whole operation fail because one payee refuses. Such contracts should let payees withdraw for themselves, or record a payment when it fails. A receiving contract can change its answer at any time, and the result of a query or a simulation made in advance does not guarantee that the transfer that follows succeeds. When a recipient refuses by number of slices, a normal payment from a payer with a fragmented holding can be refused as well, and that holding might have been fragmented precisely by dust that others scattered on it; the payer can name longer slices with transferSlices.
A receiving contract is arbitrary code of the payee. The gas it consumes is borne by the payer, and wallets should estimate gas for every transaction individually; an implementation can limit the gas forwarded to it and read only the first 32 bytes of the return data. The read-only call prevents reentrancy and misplaced events; it does not prevent a receiving contract from depending on external state that the payer can manipulate.
Lowering the gas could bypass the query. The query that determines whether the payee is a receiving contract is taken as “not a receiving contract” when it fails or answers “no”. A payer that can, by lowering the gas, make this query fail or answer “no” while the rest of the transfer succeeds has bypassed the acceptance check. That is why clause 5 of “Acceptance check” requires the contract to revert when it could not forward 30,000 gas to a query; an implementation needs to check the available gas before every query and cannot look only at whether the call succeeded.
What the acceptance check does not stop. Addresses without code cannot implement the acceptance interface, and a contract that is already deployed and cannot be upgraded cannot implement it after the fact. Incoming transfers that the recipient pulls itself, restricted issuance and forced operations are not subject to the acceptance check; a contract that lets anyone trigger it to pull needs to set limits in its own entry points.
Limits set by accounts themselves. This proposal specifies no way for addresses without code to refuse; an implementation can provide one itself (see clause 6 of “Transferable balance”). One suggested approach is a receive limit for accounts: every account sets a number for itself on the token, namely how many units, at least, an incoming transfer has to contain per slice on average, and the token rejects an incoming transfer that falls short of it; the number of slices is the number of SliceTransferred events of that incoming transfer. The threshold is counted per slice because the recipient’s cost is counted per slice; a limit of this kind raises the price and does not block. The threshold of accounts that have never set one can be decided by the issuer. When it is not zero, small transfers paid to those accounts fail, and payers that know only ERC-20 do not expect such failures. A party that can change the threshold of accounts that have never set one can make all of those accounts refuse small amounts together; deployments should put this power under the same controls as the right to freeze (see “Powers of the authorized party”). An implementation can also provide other limits set by accounts, for example a list of trusted senders.
Costs of defragmentation
This subsection applies to tokens that open defragmentation.
The cost of a freeze grows with defragmentation records. Without defragmentation, the cost of freezing a slice does not depend on how many holders the units have since been divided among. With defragmentation, a freeze propagates once more for every defragmentation record it passes through, and the number of records depends on how many times the holders of these units have defragmented. Whoever holds stolen units can divide them among many accounts and defragment once in each, or defragment the same units again and again, so that one freeze has to pass through many records. Each of these defragmentations costs its caller gas as well. An implementation should make creating a record cost no less than a freeze passing through it, for example by requiring a defragmentation to include at least a certain number of slices (clause 7 of “Defragmentation”). A defragmentation whose serials all lie inside one slice that sliceAt reports removes no slice and only leaves a record; an implementation can refuse it. An implementation in which only listed accounts can defragment is not affected.
A freeze might take several transactions. A freeze of any serial a unit has had propagates to the serial it has now, so defragmenting ahead of a freeze does not make the freeze miss. But when a freeze passes through too many records, it does not fit in one transaction. The authorized party can split the slice into several calls; when a unit has been consolidated many times, it can also freeze the serial the unit has now, and such a freeze passes only through the records created after that serial was looked up. The serial a unit has now can be found by calling consolidatedSpanAt step by step, or computed from the SliceConsolidated events. Between these calls, units that are not yet frozen can still be transferred away; a transfer does not change the serials of the units it moves, and a defragmentation performed in the course of a transfer leaves a record as well, so the later calls still freeze them. The authorized party should first estimate the cost of a freeze with a read-only call.
Cost and limit of a defragmentation. A defragmentation pays the storage cost of the record it leaves, and the number of slices one defragmentation can handle is limited by the gas available to a transaction. An account with very many slices has to defragment over several transactions, each of which yields one new slice.
Defragmenting on behalf of another account. After serials change, calls that name units by their old serials fail, for example a transferSlices or burnSlices that has been signed and is not yet included. An implementation that provides a function for defragmenting on behalf of another account therefore must restrict who can call it, or open it only for accounts that hold more than a certain number of slices; otherwise anyone can make other holders’ transfers by serial fail. The defragmentSlicesFor of the “On-behalf defragmentation extension” and a defragmentation performed for someone else in the course of a transfer (clause 4 of “Transfers”) are both defragmentations of this kind; the restriction on the former can be queried with canDefragmentFor. A party that needs certain units to keep their serials, for example a contract that registers collateral by serial, can freeze these units: frozen units cannot be consolidated. An ordinary holder usually cannot freeze its own units, and on a token that lets others defragment for it, it cannot assume that only it will renumber its own units.
Defragmenting in the course of a transfer. On a token that does this, defragmentations are as frequent as transfers, and the records a freeze has to pass through grow accordingly (see the first item of this subsection); the cost falls on 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 it cannot rescue a transfer that already does not fit in one transaction, and can only keep the number of slices down in advance. A caller does not know beforehand whether a transfer will also defragment, but this affects only calls that name units by their old serials and are not yet included, which fail rather than move the wrong units; the simulation a wallet runs to estimate gas already includes the cost of the defragmentation, and the state can be different at inclusion, as it can for any transfer. Implementations should document the conditions under which they defragment in the course of a transfer (clause 4 of “Transfers”).
Serials kept off-chain. After a defragmentation, a list of serials kept off-chain is not updated automatically. A party that screens the units it receives by serial (see “Holders can choose which units to send”) has to follow the SliceConsolidated events, or use consolidatedSpanAt, to translate the serials on its list into the serials the units have now; the new serials alone do not show where the units come from.
Serial space. Each defragmentation consumes as many new serials as the number of units consolidated, whatever the number of slices, so any holder can use it to exhaust the serial space and bring issuance to a stop. Limits that do not depend on gas are described in “Finite serial space”.
Balance includes units that cannot be transferred
When the freezing extension is implemented, balanceOf includes frozen units; when the classification extension is implemented, it also includes units that can only be transferred to some addresses. Contracts that derive reserves, collateral value or withdrawable amounts from balanceOf can overestimate what is available and have to use transferableBalanceOf instead. Computing transferableBalanceOf can require iterating over an account’s slices and may be expensive to call on-chain; the same can be true of frozenBalanceOf, freezeReasonsOf and classesOf. The number of slices of an account can be raised by a third party that transfers in small scattered amounts of units (see “Dust attacks”), so the cost of these queries is not entirely under the account’s own control.
Classes do not represent different rights
balanceOf and totalSupply add up the units of all classes, and integrators that know only ERC-20 will price, collateralize and exchange them as one and the same asset. Classes should therefore only be used to distinguish where units can go and where they come from. Making assets with different rights, for example several bonds with different maturity dates or yields, into several classes of one token does not violate the interface, but integrators will treat them at the same price, and holders of the worse class can profit from that. Such assets should each use a contract of their own.
Even when all classes carry the same rights, units that are subject to a flow rule are of less use to their holder than units of the default class, and the same is true of frozen units (see “Balance includes units that cannot be transferred” and “Destination-dependent flow rules and contracts”).
Destination-dependent flow rules and contracts
Under a flow rule that restricts destinations by payee address (see “Examples of classes”), whether a unit can be transferred out depends on the destination. A liquidity pool, a vault or any other contract that needs to pay arbitrary addresses, if it takes in such units, can end up holding balance it cannot pay out, and withdrawals can fail as a result.
An issuer has two ways to avoid this. One is to list only terminal accounts as permitted recipients, that is, accounts that do not need to transfer units onward to arbitrary addresses after receiving them. The other is to have units change to the default class when they arrive at a permitted recipient (see “Permitted recipients” in “Examples of classes”). A permitted recipient then receives unrestricted units that it can pay on to anyone, and so does not have to be a terminal account; the practice described in “Fragmentation and gas”, of transferring small scattered amounts of restricted units to a permitted recipient to raise the cost of its transfers, no longer works either; the scattered units themselves are still dust (see “Dust attacks”). The price is that once units have changed to the default class, the issuer can no longer constrain where they go. When units still belong to their original class once they are in a permitted recipient’s hands, the issuer should use the first way.
Powers of the authorized party
A party that can freeze units holds substantial power over holders, and a party that can destroy or forcibly transfer units holds even more; a compromise of their keys allows arbitrary units to be frozen and then destroyed or transferred away. The freezing extension involves four powers, and their abuse harms different parties and to different degrees. A freeze stops a holder from transferring its units out, but it can be lifted. Unfreezing harms the party that the freeze protects: stolen units, pledged units or the units named in a court order can be transferred away again. A forced transfer hands units to someone else. A destruction cannot be undone, because issuing again produces new serials. On a token where others can defragment for an account, this is a fifth power: it changes neither balances nor holders and is weaker than the other four, but whoever holds it can make the target account’s calls by serial fail, add defragmentation records and so raise the cost of freezes, and consume serials (see “Costs of defragmentation”).
Deployments are advised to place these functions behind multi-party control and to grant the four powers separately, so that one of them falling into the wrong hands does not hand over the others as well, for example by letting an address responsible for emergencies only freeze, while unfreezing and disposal go through a multisig; and to leave a delay between freezing and disposal so that mistaken freezes can be contested. This proposal does not require such an assignment: how the powers are granted is up to the implementation, and a small issuer might have only one multisig.
Every change of frozen state and every forced operation has an event (SliceFrozen, SliceUnfrozen and SliceForciblyTransferred), and the events all carry the address that initiated the call (operator). The operator of a freeze event is the address that initiated that call, which is not necessarily the party that first froze the units: freezing serials again that are already frozen emits an event with another operator.
The delay between freezing and disposal protects holders whose own units were frozen by mistake. When the frozen units are in a shared contract that pays out by shares of balanceOf, the delay has a side effect: those who leave first during the delay take their full amount, and if the outcome is disposal, the whole loss falls on those who stay, so the delay is a window for leaving first (see “Dust attacks”). A deployment can, in the same transaction that freezes these units, forcibly transfer them to a dedicated escrow address. A forced transfer does not change frozen state (clause 5 of “Forced transfer and destruction”), so the units remain frozen for the original reasons at the escrow address, and the delay and any contest take place there. Doing so has the following costs and limits.
The contract’s balanceOf drops at the moment of the transfer out, and the loss is at once shared pro rata by those who are in the contract at that time, and not by those who have already left. The delay protects the units, not the depositors’ positions: when a contest succeeds, the units should not simply be transferred back to the contract, for example back to a Uniswap v2 pool, where anyone can take the amount above the reserves with skim; making the depositors whole according to their shares at the moment of the transfer out has to be handled outside this proposal.
The transfer to the escrow address uses the power of forced transfer without a delay. A deployment that needs a delay therefore has to divide forced transfers into two tiers: a transfer to the escrow address can be executed at once, while a transfer from the escrow address to any other address, or a destruction, has to go through the delay.
It is of use only for contracts that pay out by balanceOf. A contract that pays out by its own accounts, for example a Uniswap v3 pool or the PoolManager of v4, does not read its balance when it pays, and transferring the units out spreads no loss.
It removes only the window after the freeze. Before the freezing transaction is included, whoever observes it can still leave first (see “Freezing follows units, not people”).
Who can freeze and unfreeze, and how a holder contests a freeze, is the policy of the deployment and depends on the issuer and the jurisdiction; this proposal does not specify it (see “Design of the freezing extension”). A holder can obtain four things from the interface: the reasons for which its units are frozen (freezeReasonsOf); the name and description document of each of these reasons (freezeReasonInfo); the address that initiated a freeze (the operator of the SliceFrozen event); and whether a given address can freeze or unfreeze for a given reason (canFreeze and canUnfreeze). What these two queries provide is limited: they do not list the addresses that have the right, and do not say who can destroy or forcibly transfer; their return values can change without an event; and an address for which they return true can be a contract, in which case who can freeze or unfreeze through that contract depends on that contract. The rest has to come from the reason’s description document: the specification recommends that every reason in use have a description document that states who can freeze for it and who can release it (authority), and to whom and in what way a holder can contest a freeze (contest), see clause 7 of “Freeze queries”; a deployment should also state there the conditions of release (release) and how long after a freeze, at the least, units can be destroyed or forcibly transferred (disposal). The innocent recipients described in “Freezing follows units, not people” are the ones who need this route most. This information is likewise the token’s own claim (see “Descriptions are the token’s own claims”); the addresses given in authority can be checked with canFreeze and canUnfreeze.
A party that can set classes or change flow rules holds a power close to that of freezing: changing units to a class that does not allow transfer to anyone, or emptying a class’s list of permitted recipients, has the same effect as a freeze. Unlike a freeze, a change to a flow rule emits no event (see clause 4 of “Flow rules”). The name and uri of a reason or a class, and the return values of canFreeze and canUnfreeze, can also change without an event. Holders can discover these changes only by querying. Deployments should put these powers under the same controls as the right to freeze.
The declaration of an interface does not say which powers a token actually has. On a token that declares the freezing extension, the destruction and forced transfer functions might revert for every caller, or might be usable at any time. A token that does not declare the freezing extension can still freeze, destroy or transfer units with functions outside this proposal, and an upgradeable contract can also add them later. “Freeze first, then dispose” is only a recommendation in this proposal: a token that declares the freezing extension might also destroy or transfer away units without freezing them, and unless the token’s own documentation and code guarantee it, holders and integrators cannot assume that a visible freeze comes before disposal. Integrators must read the token’s own code.
External calls and event attribution
Indexers attribute SliceTransferred and SliceForciblyTransferred events by the order of events (see “Events” and clause 7 of “Forced transfer and destruction”). An implementation that calls an external contract between the events of one operation, for example notifying the recipient after emitting SliceTransferred and before emitting the corresponding Transfer, or making a callback between Transfer and SliceForciblyTransferred, gives the called contract the opportunity to reenter and complete another transfer. Once the events of that other transfer are interleaved, events are attributed wrongly, and the contract also violates the ordering requirements stated in those two places. Implementations should complete their state updates and emit all events of the operation before calling any external contract, or prevent reentrancy. Functions that notify the recipient on transfer, such as those defined by ERC-1363, should call the recipient only after all of these events have been emitted. The queries and the call to the recipient under “Acceptance check” are not such a case: they are read-only, and the called contract can neither emit events nor complete another transfer, so they can take place before the events are emitted; for their timing relative to the changes of holder, see clause 6 of “Acceptance check”.
Reduced fungibility and privacy
Units are distinguishable by design. The complete history of every unit is public, and markets can price units differently according to that history, for instance by avoiding units that passed through a particular address. Issuers and users have to accept this as an inherent property of the token.
Finite serial space
Serials are never reused, so the total number of units ever issued, including those later destroyed, is limited by the integer width the implementation uses for serials. Tokens with frequent mint-and-burn cycles consume this space continuously and have to size it, or choose their number of decimals, accordingly.
Consolidated serials are likewise never used again: each defragmentation consumes as many new serials as the number of units consolidated, whatever the number of slices. On a token that opens defragmentation, any holder can defragment the same units again and again, and the units needed can even be borrowed; once the serials run out, issuance and defragmentation both fail permanently. Neither conditions such as a minimum number of slices per defragmentation nor the cost of gas can limit this consumption, least of all on chains where gas is cheap. A token that opens defragmentation needs a limit that does not depend on gas; how to do it is left to the implementation. One possible way is to reserve part of the serial space for issuance, which defragmentation cannot use, and to provide that a unit is consolidated at most once in a fixed period, so that the serials consumed in each period do not exceed the circulating supply. The latter makes units that have just been consolidated temporarily unavailable for another defragmentation, and the length of the period has to be weighed against that.