EIP-1702 General account versioning scheme (Generalized Account Versioning Scheme)

No call decision · EVM & execution · EIP status Stagnant · created 2017-12-30

An approach that adds a version field to account state so that a contract runs for its entire lifetime on the virtual machine version that was in effect when it was first deployed. Even if a hard fork changes the EVM rules, existing contracts are unaffected.

Why it is needed

Changing EVM functionality via a hard fork risks altering the execution results of contracts that are already deployed. In the current structure, contracts carry no version information, so a hard fork that changes the VM must either individually account for compatibility with existing contracts or accept that contract behavior will break. Furthermore, if a new VM such as on-chain WebAssembly is added alongside the EVM in the future, there is no way to distinguish and execute, within the same block, contracts built for different VMs. This EIP adds a version field to account state so that the VM rules under which a contract was deployed are permanently recorded alongside that contract, and the code is always executed under that recorded version. This allows hard forks that change the VM and the introduction of new VMs to proceed without breaking existing contracts.

What changes

Today

After EIP-1702

Who is affected

In depth

Redefinition of account state

Account state stored in the world state trie is redefined with five fields: nonce, balance, storageRoot, codeHash, version. version is a 256-bit scalar like nonce and balance (an RLP variable-length array of up to 32 bytes with no leading zero byte). If version is 0, it is RLP-encoded with only the original four fields, as before; if nonzero, it is encoded with five fields. Thanks to this branching, existing accounts with version 0 see no change at all in their RLP representation.

Code always runs under its own version

When code is fetched from an account, the version bound to it is fetched as well, referred to as the code's version. The code is always executed under this code's version. For DELEGATECALL and CALLCODE, the version of the executing call frame follows the version of the contract that delegates or receives the call, that is, whichever contract is actually executing the code.

A deployed contract inherits the same version as its parent (the family concept)

A contract creation transaction is treated as the root, and the contracts derived from it via CREATE/CREATE2 are treated as one family. Every contract within a family always has the same version. That is, CREATE/CREATE2 executes initcode under the code's version, and the contract deployed as a result is also stored with that same version. This rule applies the same way even when the code to be deployed is empty.

Introduction of a pre-deployment validation step

A new step called validation is added to the process of deploying via CREATE/CREATE2 or a contract creation transaction. If version is 0, validation does nothing and always succeeds. Later VM versions may define additional validation rules. If validation fails, deployment does not proceed and is treated as out-of-gas.

A contract creation transaction is always LATEST_VERSION

Each hard fork defines LATEST_VERSION as the most recent VM version that fork supports. A contract creation transaction is always executed under LATEST_VERSION (that is, its code's version is LATEST_VERSION), and the deployed contract also has LATEST_VERSION. Validation of the creation code is performed before execution, and if it fails, an out-of-gas result is returned.

Precompiles and EOAs have no version

Precompiled contracts and externally owned accounts (EOAs) do not have a version field. If a message-call transaction or a CALL/CALLCODE/STATICCALL/DELEGATECALL touches a new EOA or a precompile address that does not yet exist, that account is always created with version 0.

Parsing rule for when additional fields are added to account RLP

A parsing strategy for the case where a future EIP defines additional fields in the account state RLP. If the RLP list length is 4, version is treated as 0 and no additional fields are parsed. If the list length is greater than 4, the scalar at position 4 is treated as version, and the number of additional fields N defined by that version's specification is checked; if the list length is not 5+N, it is treated as a parsing error. If it matches, positions 5 through 4+N are parsed according to the meaning specified.

Current status, alternatives, and extensions

This EIP's status is Stagnant: there are no test cases or an implementation yet, and it is not a finalized standard, so it may still change or never be adopted. The body compares, as alternatives, the code-header-prefix-based 26-VER (and 40-UNUSED), and EIP-1891, which records the version in a separate contract, explaining that the EIP-1891 approach requires an extra trie lookup on every execution and so affects performance. It also mentions, for documentation purposes only, extensions that could be layered on top of this base, such as a contract-creation transaction extension (44-VERTXN) and a CREATE/CREATE2 extension (45-VEROP). No core dev call record of a fork-inclusion decision has been found.

Original EIP · ← EIPs