# Genesis Upgrade Specification
Version: 2020-01-09
Authors: nChain Ltd
* Introduction
* Definitions
* Upgrade Activation Mechanism
* UTXO Height Rule Determination
* Changes to the Bitcoin Specification
* Block Consensus Rules
* Block Size Consensus Rule
* Number of CheckSig Operations per MB of Block Space
* Transaction Consensus Rules
* Maximum Transaction Size
* Maximum Number of CheckSig Operations per Transaction
* nLockTime & nSequence
* Script Language Rules
* Data Types
* Formal Grammar for Bitcoin Script
* Validity of Script Consensus Rule
* PUSHDATA Only in Unlocking Script Consensus Rule
* Disabled Operations Consensus Rule
* Script Element Size Consensus Rule
* Stack Size Consensus Rule
* Script Size Consensus Rule
* Numeric Value Size Consensus Rule
* Number of Public Keys per Multisig Consensus Rule
* Number of Non-Push Operations Per Script Consensus Rule
* Stack Memory Usage Consensus Rule
* Sunset P2SH
* OP_RETURN Functionality
* Sunset OP_CHECKLOCKTIMEVERIFY & OP_CHECKSEQUENCEVERIFY
* Standard Local Policies
* Standard Local Transaction Policies
* Maximum Acceptable Transaction Size Policy
* Transaction Evaluation Timeout
* Standard Local Script Language Policies
* Numeric Value Length
* Stack Memory Usage Policy
* Standard Local P2P Network Policies
* Propagation of non-Standard Transactions
* Notes
## Introduction
This is the specification of the Genesis Upgrade. It defines the upgrade activation mechanism, the changes to the
Bitcoin Specification and the Consensus Rules, as well as the Standard Local Policies that are recommended for client
implementations.
This document is a specification. It is not a guide and it does not describe implementation specifics or emergent
behaviour of the system.
## Definitions
The **Bitcoin Rules** are the precise rules which define Bitcoin. These include rules such as: the sum of the value of
the inputs of a transaction must be greater than or equal to the sum of the values of the outputs, and the block subsidy
schedule. These are the foundational rules of Bitcoin, irrespective of implementation.
The **Consensus Rules** are additional rules that have been reached by general agreement and are necessary to implement
the Bitcoin Specification in software. They are needed because software has limitations and agreements are needed in
order to facilitate integration of the software. Some Consensus Rules are configurable in the software, some are not.
An example of a non-configurable Consensus Rule is that the version of a transaction must fit in a signed 32-bit integer.
An example of a configurable Consensus Rule, after Genesis activation, is the maximum accepted block size.
**Local Policies** are additional controls that are implemented in software and may place additional restrictions on the
transactions and blocks that the software will propagate to other systems and, for transactions, confirm in blocks.
Policies are “local”, they apply to the instance of software that is running, they do not apply to the validation of
blocks, or the transactions within a block. A block accepted from another miner may contain transactions that do not
conform to local policy.
**Standard Policies** are common local policies that are used by client software. They are defined as a Standard to
facilitate common application across independent software implementations but it is important to note that it is not
required that software implement or adhere to these policies.
Throughout this specification the following words are used with specific meanings:
* **valid** - a transaction or block is valid if it follows the Bitcoin and Consensus rules.
* **invalid** - a transaction or block is invalid if it does not follow either the Bitcoin or Consensus rules.
* **rejected** - a transaction or block may be rejected by an implementation due to a Policy. The implementation may not have determined whether the transaction or block was valid or invalid.
Throughout this specification the metric system is used. One KB is one kilobyte which is 1,000 bytes.
## Upgrade Activation Mechanism
The Genesis Upgrade will activate at the block heights defined in the table below.
| Mainnet
|
620,538
|
| Testnet
|
1,344,302
|
| Scaling Test Network
|
14,896
|
| Regtest
|
10,000
|
The upgraded Bitcoin Rules, Consensus Rules, and Policies become active in the block that is mined at this height.
## UTXO Height Rule Determination
The Genesis Upgrade introduces the “UTXO Height” mechanism for determining the Bitcoin Rules, Consensus Rules, and
Policies that are to be applied to a transaction. The purpose of this mechanism is to maintain compatibility for UTXO’s
that were created under the previous version of the Bitcoin Rules and Consensus Rules.
Every output of a transaction is evaluated under the rules that are in effect for the block in which the transaction is
being confirmed. If a transaction is confirmed in a block that has a height which is greater or equal to the Genesis
activation height, then the outputs of that transaction must comply with the Genesis Upgrade. If a transaction is
confirmed in a block that has a height which is less than the Genesis activation height, then the outputs of that
transaction must comply with the rules prior to the Genesis Upgrade.
Every input of a transaction is evaluated under either the rules prior to the Genesis Upgrade, or the Genesis Upgrade
rules, depending on whether the UTXO that is being spent by the input was, or will be, confirmed prior to the Genesis
activation height or after the Genesis activation height. If the transaction which contains the UTXO that is being spent
was, or will be, confirmed in a block before the Genesis activation height then the input script and the output script
for the UTXO being spent by that input are evaluated according to rules prior to the Genesis Upgrade. If the transaction
which contains the UTXO that is being spent was, or will be, confirmed in a block with a height greater than or equal to
the Genesis activation height, then the input script and the output script for the UTXO being spent by that input are
evaluated according to the Genesis Upgrade.
Other characteristics of the transaction, such as the maximum number of sigops, are evaluated according to the rules
that are in effect for the block in which the transaction is being confirmed.
It is worth noting that, after Genesis activation, a single transaction may spend inputs from before Genesis activation
and after Genesis activation, in which case each input is evaluated under the rules that are applicable to that input
based upon the block height that the transaction referenced by that input was confirmed.
## Changes to the Bitcoin Specification
### Block Consensus Rules
These consensus rules apply to blocks that are produced after Genesis activation.
#### Block Size Consensus Rule
The size of a block is the size in bytes of the serialized form of the block, including the block header and all of the
transactions confirmed by the block[^1].
The consensus rule that restricts the maximum size of a block to a specific number of bytes has been converted into a
configurable consensus rule. The default value of the maximum acceptable size of a block is unlimited.
**Miners are expected to reach consensus on this value and configure it manually.**
#### Number of CheckSig Operations per MB of Block Space
The consensus rule that limits the number of checksig operations per megabyte of block space has been removed.
### Transaction Consensus Rules
These consensus rules apply to transactions that are confirmed in blocks after Genesis activation.
#### Maximum Transaction Size
The size of a transaction is the size in bytes of the serialized form of the transaction[^2].
The maximum size of a transaction is 1GB (1,000,000,000 bytes). This limitation is expected to be lifted in the future.
#### Maximum Number of CheckSig Operations per Transaction
The consensus rule that limits the number of checksig operations per transaction has been removed.
#### nLockTime & nSequence
After Genesis activation, the functionality of the nLockTime field of a transaction and the nSequence fields of
transaction inputs revert to their original purpose. The rules defined here only apply to transactions that are
confirmed after Genesis activation.
The nSequence fields of every transaction input and the nLockTime field of the transaction collectively determine the
“finality” of a transaction. If a transaction is “non-final” then it can not be valid but it can become “final” at a
later time. If a transaction is “final” then it can be valid.
* If the value of nSequence of a transaction input is 0xFFFFFFFF then that input is a “final input”.
* If the value of nSequence of a transaction input is not 0xFFFFFFFF then that input is a “non-final input”.
* If all of the inputs of a transaction are “final inputs” then the transaction is “final”, irrespective of the value of the nLockTime field.
* If one or more of the inputs of a transaction are “non-final inputs” then:
* If the value of the transactions nLockTime field is less than 500,000,000 then the field represents a block height.
* If the height of the block in which the transaction is being confirmed is greater or equal to the value of this field, then the transaction is “final”.
* Otherwise the transaction is “non-final”
* If the value of the transactions nLockTime field is greater or equal to 500,000,000 then the field represents a UNIX epoch timestamp.
* If the MTP of the last 11 blocks is greater or equal to the value of this field, then the transaction is “final”.
* Otherwise, the transaction is “non-final”.
A “final” transaction may be confirmed in a block following the “first-seen” rule.
A new transaction must replace a prior “non-final” transaction if it has the same inputs in the same order and every
sequence number for every input in the new transaction is not less than the sequence number for the corresponding input
in the prior transaction and the sequence number of at least one input in the new transaction is greater than the
sequence number for the corresponding input in the prior transaction.
If a new transaction is detected which does not fulfill all of these requirements then it must be rejected.
If a new transaction is detected which has inputs that conflict with the inputs of a “non-final” transaction, but which
are not identical to the inputs of the “non-final” transaction, then the “non-final” transaction is the “first seen”
transaction and takes priority over the new transaction.
### Script Language Rules
Bitcoin Script is the programming language that is used to lock and unlock transaction outputs. This section contains
changes to the Script Language Rules.
The rules defined here apply to locking and unlocking scripts for transactions outputs that are created after the
Genesis activation. The previous rules apply to transaction outputs created prior to Genesis activation.
#### Data Types
All data items in Bitcoin Script are a byte sequence. Some operations interpret their parameters as numeric or boolean
values and require the item to fulfill the requirements of those types. Some operations produce items on the stack which
are valid numeric or boolean values.
A byte sequence has a length and a value. The length of the byte sequence must be an integer greater or equal to zero
and less than or equal to 2^32-1 (UINT32_MAX).
The byte sequence of length zero is called the “null value”.
Any data item can be interpreted as a boolean value. If the data item consists entirely of bytes with value zero, or the
data item is the null value, then the boolean value of the item is **false**. Otherwise, the boolean value of the item
is **true**.
A data item can be interpreted as a numeric value. The numeric value is encoded in a byte sequence using little-endian
notation. The byte sequence of length zero (the null value) is the standard representation for the numeric value zero.
There is a Consensus Rule on the maximum size of a numeric value that is defined below.
#### Formal Grammar for Bitcoin Script
A formal grammar has been defined for Bitcoin Script. This section of the document defines that grammar but it does not
describe how this definition is applied. The application of the grammar definition is described in further parts of this
document.
This grammar is fully described by the following BNF grammar:
```