Skip to content
This repository was archived by the owner on Oct 4, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions libethashseal/Ethash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,13 @@ StringHashMap Ethash::jsInfo(BlockHeader const& _bi) const

EVMSchedule const& Ethash::evmSchedule(EnvInfo const& _envInfo) const
{
if (_envInfo.number() >= chainParams().u256Param("frontierCompatibilityModeLimit"))
return HomesteadSchedule;
if (_envInfo.number() >= chainParams().u256Param("EIP150ForkBlock"))
return EIP150Schedule;
else
return FrontierSchedule;
if (_envInfo.number() >= chainParams().u256Param("homsteadForkBlock"))
return HomesteadSchedule;
else
return FrontierSchedule;
}

void Ethash::verify(Strictness _s, BlockHeader const& _bi, BlockHeader const& _parent, bytesConstRef _block) const
Expand Down Expand Up @@ -163,7 +166,7 @@ void Ethash::verify(Strictness _s, BlockHeader const& _bi, BlockHeader const& _p

void Ethash::verifyTransaction(ImportRequirements::value _ir, TransactionBase const& _t, BlockHeader const& _bi) const
{
if (_ir & ImportRequirements::TransactionSignatures && _bi.number() >= chainParams().u256Param("frontierCompatibilityModeLimit"))
if (_ir & ImportRequirements::TransactionSignatures && _bi.number() >= chainParams().u256Param("homsteadForkBlock"))
_t.checkLowS();
// Unneeded as it's checked again in Executive. Keep it here since tests assume it's checked.
if (_ir & ImportRequirements::TransactionBasic && _t.gasRequired(evmSchedule(EnvInfo(_bi))) > _t.gas())
Expand Down Expand Up @@ -197,7 +200,7 @@ u256 Ethash::calculateDifficulty(BlockHeader const& _bi, BlockHeader const& _par
auto durationLimit = chainParams().u256Param("durationLimit");

bigint target; // stick to a bigint for the target. Don't want to risk going negative.
if (_bi.number() < chainParams().u256Param("frontierCompatibilityModeLimit"))
if (_bi.number() < chainParams().u256Param("homsteadForkBlock"))
// Frontier-era difficulty adjustment
target = _bi.timestamp() >= _parent.timestamp() + durationLimit ? _parent.difficulty() - (_parent.difficulty() / difficultyBoundDivisor) : (_parent.difficulty() + (_parent.difficulty() / difficultyBoundDivisor));
else
Expand Down
56 changes: 51 additions & 5 deletions libethashseal/GenesisInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ R"ETHEREUM(
"sealEngine": "Ethash",
"params": {
"accountStartNonce": "0x00",
"frontierCompatibilityModeLimit": "0xffffffff",
"homsteadForkBlock": "0xffffffff",
"maximumExtraDataSize": "0x0400",
"tieBreakingGas": false,
"minGasLimit": "125000",
Expand Down Expand Up @@ -77,7 +77,7 @@ R"ETHEREUM(
"sealEngine": "Ethash",
"params": {
"accountStartNonce": "0x0100000",
"frontierCompatibilityModeLimit": "0x789b0",
"homsteadForkBlock": "0x789b0",
"maximumExtraDataSize": "0x20",
"tieBreakingGas": false,
"minGasLimit": "0x1388",
Expand Down Expand Up @@ -117,8 +117,9 @@ R"E(
"sealEngine": "Ethash",
"params": {
"accountStartNonce": "0x00",
"frontierCompatibilityModeLimit": "0xffffffffffffffff",
"homsteadForkBlock": "0xffffffffffffffff",
"daoHardforkBlock": "0xfffffffffffffff",
"EIP150ForkBlock": "0xfffffffffffffff",
"maximumExtraDataSize": "0x20",
"tieBreakingGas": false,
"minGasLimit": "0x1388",
Expand Down Expand Up @@ -157,8 +158,9 @@ R"E(
"sealEngine": "Ethash",
"params": {
"accountStartNonce": "0x00",
"frontierCompatibilityModeLimit": "0x05",
"homsteadForkBlock": "0x05",
"daoHardforkBlock": "0x08",
"EIP150ForkBlock": "0x0a",
"maximumExtraDataSize": "0x20",
"tieBreakingGas": false,
"minGasLimit": "0x1388",
Expand Down Expand Up @@ -199,6 +201,47 @@ R"E(
"accountStartNonce": "0x00",
"maximumExtraDataSize": "0x20",
"daoHardforkBlock": "0x1d4c00",
"EIP150ForkBlock": "0x2625A0",
"minGasLimit": "0x1388",
"maxGasLimit": "7fffffffffffffff",
"tieBreakingGas": false,
"gasLimitBoundDivisor": "0x0400",
"minimumDifficulty": "0x020000",
"difficultyBoundDivisor": "0x0800",
"durationLimit": "0x0d",
"blockReward": "0x4563918244F40000",
"registrar" : "0xc6d9d2cd449a754c494264e1809c50e34d64562b",
"networkID" : "0x1"
},
"genesis": {
"nonce": "0x0000000000000042",
"difficulty": "0x400000000",
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"author": "0x0000000000000000000000000000000000000000",
"timestamp": "0x00",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"extraData": "0x11bbe8db4e347b4e8c937c1c8370e4b5ed33adb3db69cbdb7a38e1e50b1b82fa",
"gasLimit": "0x1388"
},
"accounts": {
"0000000000000000000000000000000000000001": { "wei": "1", "precompiled": { "name": "ecrecover", "linear": { "base": 3000, "word": 0 } } },
"0000000000000000000000000000000000000002": { "wei": "1", "precompiled": { "name": "sha256", "linear": { "base": 60, "word": 12 } } },
"0000000000000000000000000000000000000003": { "wei": "1", "precompiled": { "name": "ripemd160", "linear": { "base": 600, "word": 120 } } },
"0000000000000000000000000000000000000004": { "wei": "1", "precompiled": { "name": "identity", "linear": { "base": 15, "word": 3 } } }
}
}
)E";

static h256 const c_genesisStateRootEIP150Test;
static std::string const c_genesisInfoEIP150Test = std::string() +
R"E(
{
"sealEngine": "Ethash",
"params": {
"accountStartNonce": "0x00",
"maximumExtraDataSize": "0x20",
"daoHardforkBlock": "0xfffffff",
"EIP150ForkBlock": "0x00",
"minGasLimit": "0x1388",
"maxGasLimit": "7fffffffffffffff",
"tieBreakingGas": false,
Expand Down Expand Up @@ -236,8 +279,9 @@ R"E(
"sealEngine": "Ethash",
"params": {
"accountStartNonce": "0x00",
"frontierCompatibilityModeLimit": "0x118c30",
"homsteadForkBlock": "0x118c30",
"daoHardforkBlock": "0x1d4c00",
"EIP150ForkBlock": "0xfffffffffffffff",
"maximumExtraDataSize": "0x20",
"tieBreakingGas": false,
"minGasLimit": "0x1388",
Expand Down Expand Up @@ -27224,6 +27268,7 @@ std::string const& dev::eth::genesisInfo(Network _n)
case Network::Test: return c_genesisInfoTest;
case Network::FrontierTest: return c_genesisInfoFrontierTest;
case Network::HomesteadTest: return c_genesisInfoHomesteadTest;
case Network::EIP150Test: return c_genesisInfoEIP150Test;
default:
throw std::invalid_argument("Invalid network value");
}
Expand All @@ -27239,6 +27284,7 @@ h256 const& dev::eth::genesisStateRoot(Network _n)
case Network::Test: return c_genesisStateRootTest;
case Network::FrontierTest: return c_genesisStateRootFrontierTest;
case Network::HomesteadTest: return c_genesisStateRootHomesteadTest;
case Network::EIP150Test: return c_genesisStateRootEIP150Test;
default:
throw std::invalid_argument("Invalid network value");
}
Expand Down
1 change: 1 addition & 0 deletions libethashseal/GenesisInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ enum class Network
Test = 70, ///< Normal Frontier/Homestead chain without all the premine.
FrontierTest = 71, ///< Just test the Frontier-era characteristics "forever" (no Homestead portion).
HomesteadTest = 72, ///< Just test the Homestead-era characteristics "forever" (no Frontier portion).
EIP150Test = 73, ///< EIP150 Rules For BlockchainTests
Special = 0xff ///< Something else.
};

Expand Down
1 change: 1 addition & 0 deletions libethereum/Block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ pair<TransactionReceipts, bool> Block::sync(BlockChain const& _bc, TransactionQu
else
{
clog(StateTrace) << t.sha3() << "Temporarily no gas left in current block (txs gas > block's gas limit)";
_tq.drop(t.sha3());
// Temporarily no gas left in current block.
// OPTIMISE: could note this and then we don't evaluate until a block that does have the gas left.
// for now, just leave alone.
Expand Down
13 changes: 11 additions & 2 deletions libevm/VM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,16 @@ void VM::interpretCases()

CASE_BEGIN(SUICIDE)
{
m_runGas = toUint64(m_schedule->suicideGas);
Address dest = asAddress(*m_sp);

// After EIP150 hard fork charge additional cost of sending
// ethers to non-existing account.
if (m_schedule->suicideChargesNewAccountGas() && !m_ext->exists(dest))
m_runGas += m_schedule->callNewAccountGas;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was this change spec'd in the yellow paper? i don't remember seeing it implemented in geth


onOperation();
updateIOGas();

Address dest = asAddress(*m_sp);
m_ext->suicide(dest);
m_bounce = 0;
}
Expand Down Expand Up @@ -543,6 +549,7 @@ void VM::interpretCases()

CASE_BEGIN(BALANCE)
{
m_runGas = toUint64(m_schedule->balanceGas);
onOperation();
updateIOGas();

Expand Down Expand Up @@ -607,6 +614,7 @@ void VM::interpretCases()
CASE_END

CASE_BEGIN(EXTCODESIZE)
m_runGas = toUint64(m_schedule->extcodesizeGas);
onOperation();
updateIOGas();

Expand Down Expand Up @@ -638,6 +646,7 @@ void VM::interpretCases()

CASE_BEGIN(EXTCODECOPY)
{
m_runGas = toUint64(m_schedule->extcodecopyGas);
m_copyMemSize = toUint64(*(m_sp - 3));
m_newMemSize = memNeed(*(m_sp - 1), *(m_sp - 3));
updateMem();
Expand Down
30 changes: 25 additions & 5 deletions libevm/VMCalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,20 @@ void VM::caseCreate()
updateMem();
onOperation();
updateIOGas();

auto const& endowment = *m_sp--;
uint64_t initOff = (uint64_t)*m_sp--;
uint64_t initSize = (uint64_t)*m_sp--;

if (m_ext->balance(m_ext->myAddress) >= endowment && m_ext->depth < 1024)
*++m_sp = (u160)m_ext->create(endowment, *m_io_gas, bytesConstRef(m_mem.data() + initOff, initSize), *m_onOp);
{
u256 createGas = *m_io_gas;
if (!m_schedule->staticCallDepthLimit())
createGas -= createGas / 64;
u256 gas = createGas;
*++m_sp = (u160)m_ext->create(endowment, gas, bytesConstRef(m_mem.data() + initOff, initSize), *m_onOp);
*m_io_gas -= (createGas - gas);
}
else
*++m_sp = 0;
}
Expand All @@ -128,7 +135,7 @@ void VM::caseCall()

bool VM::caseCallSetup(CallParameters *callParams)
{
m_runGas = toUint64(u512(*m_sp) + m_schedule->callGas);
m_runGas = toUint64(m_schedule->callGas);

if (m_op == Instruction::CALL && !m_ext->exists(asAddress(*(m_sp - 1))))
m_runGas += toUint64(m_schedule->callNewAccountGas);
Expand All @@ -142,10 +149,23 @@ bool VM::caseCallSetup(CallParameters *callParams)
memNeed(m_stack[(1 + m_sp - m_stack) - sizesOffset], m_stack[(1 + m_sp - m_stack) - sizesOffset - 1])
);
updateMem();
updateIOGas();

// "Static" costs already applied. Calculate call gas.
if (m_schedule->staticCallDepthLimit())
// With static call depth limit we just charge the provided gas amount.
callParams->gas = *m_sp;
else
{
// Apply "all but one 64th" rule.
u256 maxAllowedCallGas = *m_io_gas - *m_io_gas / 64;
callParams->gas = std::min(*m_sp, maxAllowedCallGas);
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the "all but one 64th" rule?

m_runGas = toUint64(callParams->gas);
onOperation();
updateIOGas();

callParams->gas = *m_sp;
if (m_op != Instruction::DELEGATECALL && *(m_sp - 2) > 0)
callParams->gas += m_schedule->callStipend;
--m_sp;
Expand Down
24 changes: 24 additions & 0 deletions libevmcore/EVMSchedule.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ struct EVMSchedule
EVMSchedule(bool _efcd, bool _hdc, unsigned const& _txCreateGas): exceptionalFailedCodeDeposit(_efcd), haveDelegateCall(_hdc), tierStepGas(std::array<unsigned, 8>{{0, 2, 3, 5, 8, 10, 20, 0}}), txCreateGas(_txCreateGas) {}
bool exceptionalFailedCodeDeposit = true;
bool haveDelegateCall = true;
bool eip150Mode = false;
unsigned stackLimit = 1024;
std::array<unsigned, 8> tierStepGas;
unsigned expGas = 10;
Expand Down Expand Up @@ -63,11 +64,34 @@ struct EVMSchedule
unsigned txDataZeroGas = 4;
unsigned txDataNonZeroGas = 68;
unsigned copyGas = 3;

//EIP150
unsigned extcodesizeGas = 20;
unsigned extcodecopyGas = 20;
unsigned balanceGas = 20;
unsigned suicideGas = 0;

bool staticCallDepthLimit() const { return !eip150Mode; }
bool suicideChargesNewAccountGas() const { return eip150Mode; }
};

static const EVMSchedule DefaultSchedule = EVMSchedule();
static const EVMSchedule FrontierSchedule = EVMSchedule(false, false, 21000);
static const EVMSchedule HomesteadSchedule = EVMSchedule(true, true, 53000);

static const EVMSchedule EIP150Schedule = []
{
//EIP150
EVMSchedule schedule = HomesteadSchedule;
schedule.eip150Mode = true;
schedule.extcodesizeGas = 700;
schedule.extcodecopyGas = 700;
schedule.balanceGas = 400;
schedule.sloadGas = 200;
schedule.callGas = 700;
schedule.suicideGas = 5000;
return schedule;
}();

}
}
8 changes: 4 additions & 4 deletions libevmcore/Instruction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ static const std::map<Instruction, InstructionInfo> c_instructionInfo =
{ Instruction::SIGNEXTEND, { "SIGNEXTEND", 0, 2, 1, false, LowTier } },
{ Instruction::SHA3, { "SHA3", 0, 2, 1, false, SpecialTier } },
{ Instruction::ADDRESS, { "ADDRESS", 0, 0, 1, false, BaseTier } },
{ Instruction::BALANCE, { "BALANCE", 0, 1, 1, false, ExtTier } },
{ Instruction::BALANCE, { "BALANCE", 0, 1, 1, false, SpecialTier } },
{ Instruction::ORIGIN, { "ORIGIN", 0, 0, 1, false, BaseTier } },
{ Instruction::CALLER, { "CALLER", 0, 0, 1, false, BaseTier } },
{ Instruction::CALLVALUE, { "CALLVALUE", 0, 0, 1, false, BaseTier } },
Expand All @@ -205,8 +205,8 @@ static const std::map<Instruction, InstructionInfo> c_instructionInfo =
{ Instruction::CODESIZE, { "CODESIZE", 0, 0, 1, false, BaseTier } },
{ Instruction::CODECOPY, { "CODECOPY", 0, 3, 0, true, VeryLowTier } },
{ Instruction::GASPRICE, { "GASPRICE", 0, 0, 1, false, BaseTier } },
{ Instruction::EXTCODESIZE, { "EXTCODESIZE", 0, 1, 1, false, ExtTier } },
{ Instruction::EXTCODECOPY, { "EXTCODECOPY", 0, 4, 0, true, ExtTier } },
{ Instruction::EXTCODESIZE, { "EXTCODESIZE", 0, 1, 1, false, SpecialTier } },
{ Instruction::EXTCODECOPY, { "EXTCODECOPY", 0, 4, 0, true, SpecialTier } },
{ Instruction::BLOCKHASH, { "BLOCKHASH", 0, 1, 1, false, ExtTier } },
{ Instruction::COINBASE, { "COINBASE", 0, 0, 1, false, BaseTier } },
{ Instruction::TIMESTAMP, { "TIMESTAMP", 0, 0, 1, false, BaseTier } },
Expand Down Expand Up @@ -299,7 +299,7 @@ static const std::map<Instruction, InstructionInfo> c_instructionInfo =
{ Instruction::CALLCODE, { "CALLCODE", 0, 7, 1, true, SpecialTier } },
{ Instruction::RETURN, { "RETURN", 0, 2, 0, true, ZeroTier } },
{ Instruction::DELEGATECALL,{ "DELEGATECALL", 0, 6, 1, true, SpecialTier } },
{ Instruction::SUICIDE, { "SUICIDE", 0, 1, 0, true, ZeroTier } },
{ Instruction::SUICIDE, { "SUICIDE", 0, 1, 0, true, SpecialTier } },

// these are generated by the interpreter - should never be in user code
{ Instruction::PUSHC, { "PUSHC", 2, 0, 1, false, VeryLowTier } },
Expand Down
2 changes: 1 addition & 1 deletion test/libethcore/difficulty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ std::string const c_testDifficulty = R"(
void checkCalculatedDifficulty(BlockHeader const& _bi, BlockHeader const& _parent, Network _n, ChainOperationParams const& _p, string const& _testName = "")
{
u256 difficulty = _bi.difficulty();
u256 frontierDiff = _p.u256Param("frontierCompatibilityModeLimit");
u256 frontierDiff = _p.u256Param("homsteadForkBlock");

//The ultimate formula (Homestead)
if (_bi.number() > frontierDiff)
Expand Down
Loading