EIPs Explained

EIP-1702 · Stagnant · Core · 2017-12-30

EIP-1702: Generalized Account Versioning Scheme

A proposal to add a version field to every account so contracts keep running under the VM rules they were deployed with, letting hard forks introduce breaking EVM changes or a new VM without breaking old code.

What problem does it solve?

Every hard fork changes the rules for all contracts at once. That makes some improvements impossible: changing an opcode's behaviour, removing a feature or adding a new VM (eWASM was the candidate in 2017–2019) could break contracts that were deployed years ago and cannot be upgraded.

EIP-1702 proposes account versioning: each contract remembers which VM version it was created under and is always executed with that version's rules. New forks can then define a new version with breaking changes, while existing contracts continue to behave exactly as before.

How it works

  • Account state. Accounts gain a fifth field, version, next to nonce, balance, storageRoot and codeHash. If version is 0 the account is still RLP-encoded with four items, so existing state does not change.
  • Execution. Code always runs under its own version. For DELEGATECALL and CALLCODE the frame uses the version of the contract whose code is executing.
  • Deployment. A contract creation transaction runs and deploys at the fork's LATEST_VERSION. CREATE and CREATE2 deploy children with the same version as the creating code, so a "family" of contracts shares one version.
  • Validation. Deployment gains a validation step. Version 0 always passes; future versions can reject code that does not meet their rules (deployment then fails as out-of-gas).
  • EOAs and precompiles have no meaningful version; newly touched accounts get version 0.
  • Extra fields. Future versions may append additional RLP fields to the account; the version tells parsers how many to expect.

Hard-fork meta EIPs would then declare, per VM, a version number, its parent version and the features enabled.

Sample code

How a client would decode an account under this scheme (pseudocode):

def decode_account(rlp_items):
    if len(rlp_items) == 4:
        nonce, balance, storage_root, code_hash = rlp_items
        return Account(nonce, balance, storage_root, code_hash, version=0)

    nonce, balance, storage_root, code_hash, version = rlp_items[:5]
    n_extra = extra_field_count(version)          # defined by that version's spec
    if len(rlp_items) != 5 + n_extra:
        raise ParseError("bad account RLP length")
    return Account(nonce, balance, storage_root, code_hash, version, extra=rlp_items[5:])

def evm_for(account):
    return VM_RULES[account.version]             # e.g. 0 -> legacy EVM

Things to know

  • Status is Stagnant. Ethereum never added an account version field.
  • The idea of versioned code lives on in a different form: the EVM Object Format work (EIP-3540, EIP-3670) puts a version in a code header and validates code at deploy time, rather than storing the version in account state.
  • Once any non-zero version exists, the legacy (version 0) feature set must be frozen; long-term, clients would have to maintain every VM version ever shipped.

#evm #account #versioning #core #hard-fork

Details

Authors
Wei Tang (@sorpaas)
Status
Stagnant
Type
Standards Track / Core
Created
2017-12-30

Machine-readable: Markdown · JSON