EIPs Explained

EIP-2 · Final · Core · 2015-11-15

EIP-2: Homestead Hard-fork Changes

The Homestead hard fork's core rule changes: pricier contract-creation transactions, no high-s signatures, all-or-nothing contract deployment, and a fairer difficulty formula.

What problem does it solve?

Ethereum launched in July 2015 (Frontier) with a few rough edges that were fine for a beta but not for a stable network. EIP-2 bundles four fixes that went live with the Homestead hard fork at block 1,150,000 on mainnet:

  • Creating a contract by sending a transaction cost only 21,000 gas, while creating one from another contract cost 32,000. That made a cheap trick possible: deploy a contract that immediately self-destructs to move ETH for less than a normal transfer.
  • Any ECDSA signature could be "flipped" into a second valid signature, so a third party could change a transaction's hash before it was mined (transaction malleability). Users and apps that tracked transactions by hash could get confused.
  • A contract creation that ran short of gas for storing its code would still succeed, leaving an empty contract behind. That was a confusing third outcome besides "success" and "failure".
  • The difficulty formula targeted a median block time. Miners who stamped blocks one second after their parent could push the average block time up without limit.

How it works

From the fork block onward:

  1. Contract-creation transactions (the to field is empty) start at 53,000 gas instead of 21,000, plus the usual data cost. Creation through the CREATE opcode is unchanged.
  2. Signatures with s > secp256k1n / 2 are invalid for transactions. Each signature now has exactly one accepted form. The ecrecover precompile still accepts high-s values, so contracts can verify old signatures from other systems.
  3. Out of gas while storing code means failure. If the creation cannot pay the final code-deposit cost, the whole creation reverts. No empty account is left behind, and any ETH sent is returned.
  4. New difficulty adjustment. The timestamp gap is divided into 10-second buckets. That way the formula targets the mean block time, and miners gain nothing by setting a gap of exactly one second.

Sample code

The difficulty change, in the spec's own Python-style notation (// is integer division):

# Frontier
block_diff = parent_diff + parent_diff // 2048 * (1 if timestamp - parent_timestamp < 13 else -1) \
             + int(2 ** ((block.number // 100000) - 2))

# Homestead (EIP-2)
block_diff = parent_diff + parent_diff // 2048 * max(1 - (timestamp - parent_timestamp) // 10, -99) \
             + int(2 ** ((block.number // 100000) - 2))

Checking the low-s rule on a signature:

const SECP256K1_N = 0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141n;

function isCanonical(s: bigint): boolean {
  return s > 0n && s <= SECP256K1_N / 2n; // high-s values are rejected for transactions
}

Things to know

  • EIP-2 is the technical core of Homestead. The full list of changes in that fork is in the meta EIP EIP-606, which also includes EIP-7 (DELEGATECALL) and EIP-8 (devp2p forward compatibility).
  • The low-s rule is why signing libraries normalize s today. If you build raw signatures yourself, make sure s is in the lower half of the curve order.
  • The rule removed signature malleability but not cross-chain replay. That came later with chain IDs in EIP-155.
  • The exponential "difficulty bomb" term 2 ** (block.number // 100000 - 2) is unchanged here. It was delayed by later forks and no longer matters now that Ethereum uses proof of stake.

#hardfork #homestead #core #signatures #gas

Details

Authors
Vitalik Buterin (@vbuterin)
Status
Final
Type
Standards Track / Core
Created
2015-11-15
Required by

Machine-readable: Markdown · JSON