Skip to content
This repository has been archived by the owner on Oct 28, 2021. It is now read-only.

Commit

Permalink
EIP96 - 1. Creation of blockhash contract at Metropolis fork block. 2…
Browse files Browse the repository at this point in the history
…. Updating block hashes at each block starting form Metropolis
  • Loading branch information
gumb0 committed May 4, 2017
1 parent 0725111 commit f5f802a
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 0 deletions.
2 changes: 2 additions & 0 deletions libdevcrypto/Common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ const Address dev::ZeroAddress = Address();

const Address dev::MaxAddress = Address("0xffffffffffffffffffffffffffffffffffffffff");

const Address dev::SuperuserAddress = Address("0xfffffffffffffffffffffffffffffffffffffffe");

Public dev::toPublic(Secret const& _secret)
{
auto* ctx = getCtx();
Expand Down
3 changes: 3 additions & 0 deletions libdevcrypto/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ extern const Address ZeroAddress;
/// The last address.
extern const Address MaxAddress;

/// The SUPER_USER address.
extern const Address SuperuserAddress;

/// A vector of Ethereum addresses.
using Addresses = h160s;

Expand Down
3 changes: 3 additions & 0 deletions libethcore/Common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ const unsigned c_databaseVersionModifier = 0;

const unsigned c_databaseVersion = c_databaseBaseVersion + (c_databaseVersionModifier << 8) + (23 << 9);

const Address c_blockhashContractAddress(0xf0);
const bytes c_blockhashContractCode(fromHex("0x73fffffffffffffffffffffffffffffffffffffffe33141561006a5760014303600035610100820755610100810715156100455760003561010061010083050761010001555b6201000081071515610064576000356101006201000083050761020001555b5061013e565b4360003512151561008457600060405260206040f361013d565b61010060003543031315156100a857610100600035075460605260206060f361013c565b6101006000350715156100c55762010000600035430313156100c8565b60005b156100ea576101006101006000350507610100015460805260206080f361013b565b620100006000350715156101095763010000006000354303131561010c565b60005b1561012f57610100620100006000350507610200015460a052602060a0f361013a565b600060c052602060c0f35b5b5b5b5b"));

Address toAddress(std::string const& _s)
{
try
Expand Down
5 changes: 5 additions & 0 deletions libethcore/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ extern const unsigned c_minorProtocolVersion;
/// Current database version.
extern const unsigned c_databaseVersion;

/// Address of the special contract for block hash storage defined in EIP96
extern const Address c_blockhashContractAddress;
/// Code of the special contract for block hash storage defined in EIP96
extern const bytes c_blockhashContractCode;

/// User-friendly string representation of the amount _b in wei.
std::string formatBalance(bigint const& _b);

Expand Down
24 changes: 24 additions & 0 deletions libethereum/Block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ void Block::resetCurrent(u256 const& _timestamp)
m_committedToSeal = false;

performIrregularModifications();
updateBlockhashContract();
}

SealEngineFace* Block::sealEngine() const
Expand Down Expand Up @@ -692,6 +693,29 @@ void Block::performIrregularModifications()
}
}

void Block::updateBlockhashContract()
{
u256 const blockNumber = info().number();

u256 const metropolisForkBlock = m_sealEngine->chainParams().u256Param("metropolisForkBlock");
if (blockNumber == metropolisForkBlock)
{
m_state.createContract(c_blockhashContractAddress);
m_state.setNewCode(c_blockhashContractAddress, bytes(c_blockhashContractCode));
m_state.commit(State::CommitBehaviour::KeepEmptyAccounts);
}

if (blockNumber >= metropolisForkBlock)
{
u256 const nonce = transactionsFrom(SuperuserAddress);
u256 const gas = 1000000;
Transaction tx(0, 0, gas, c_blockhashContractAddress, m_previousBlock.hash().asBytes(), nonce);
tx.forceSender(SuperuserAddress);
// passing empty lastHashes - assuming the contract doesn't use BLOCKHASH
m_state.execute(EnvInfo(info(), {}, 0), *m_sealEngine, tx, Permanence::Committed);
}
}

void Block::commitToSeal(BlockChain const& _bc, bytes const& _extraData)
{
if (isSealed())
Expand Down
3 changes: 3 additions & 0 deletions libethereum/Block.h
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,9 @@ class Block
/// Performs irregular modifications right after initialization, e.g. to implement a hard fork.
void performIrregularModifications();

/// Creates and updates the special contract for storing block hashes according to EIP96
void updateBlockhashContract();

/// Provide a standard VM trace for debugging purposes.
std::string vmTrace(bytesConstRef _block, BlockChain const& _bc, ImportRequirements::value _ir);

Expand Down

0 comments on commit f5f802a

Please sign in to comment.