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 12 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
9 changes: 6 additions & 3 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("frontierCompatibilityModeLimit"))
return HomesteadSchedule;
else
return FrontierSchedule;
}

void Ethash::verify(Strictness _s, BlockHeader const& _bi, BlockHeader const& _parent, bytesConstRef _block) const
Expand Down
4 changes: 4 additions & 0 deletions libethashseal/GenesisInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ R"E(
"accountStartNonce": "0x00",
"frontierCompatibilityModeLimit": "0xffffffffffffffff",
"daoHardforkBlock": "0xfffffffffffffff",
"EIP150ForkBlock": "0xfffffffffffffff",
"maximumExtraDataSize": "0x20",
"tieBreakingGas": false,
"minGasLimit": "0x1388",
Expand Down Expand Up @@ -159,6 +160,7 @@ R"E(
"accountStartNonce": "0x00",
"frontierCompatibilityModeLimit": "0x05",
"daoHardforkBlock": "0x08",
"EIP150ForkBlock": "0x0a",
"maximumExtraDataSize": "0x20",
"tieBreakingGas": false,
"minGasLimit": "0x1388",
Expand Down Expand Up @@ -199,6 +201,7 @@ R"E(
"accountStartNonce": "0x00",
"maximumExtraDataSize": "0x20",
"daoHardforkBlock": "0x1d4c00",
"EIP150ForkBlock": "0xfffffffffffffff",
"minGasLimit": "0x1388",
"maxGasLimit": "7fffffffffffffff",
"tieBreakingGas": false,
Expand Down Expand Up @@ -238,6 +241,7 @@ R"E(
"accountStartNonce": "0x00",
"frontierCompatibilityModeLimit": "0x118c30",
"daoHardforkBlock": "0x1d4c00",
"EIP150ForkBlock": "0xfffffffffffffff",
"maximumExtraDataSize": "0x20",
"tieBreakingGas": false,
"minGasLimit": "0x1388",
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
36 changes: 29 additions & 7 deletions libevm/VMCalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,21 @@ 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);

bool depthOk = m_schedule->staticCallDepthLimit() ? m_ext->depth < 1024 : true;
if (m_ext->balance(m_ext->myAddress) >= endowment && depthOk)
{
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 +136,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 +150,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 All @@ -169,7 +190,8 @@ bool VM::caseCallSetup(CallParameters *callParams)
uint64_t outOff = (uint64_t)*m_sp--;
uint64_t outSize = (uint64_t)*m_sp--;

if (m_ext->balance(m_ext->myAddress) >= callParams->valueTransfer && m_ext->depth < 1024)
bool depthOk = m_schedule->staticCallDepthLimit() ? m_ext->depth < 1024 : true;
if (m_ext->balance(m_ext->myAddress) >= callParams->valueTransfer && depthOk)
{
callParams->onOp = *m_onOp;
callParams->senderAddress = m_op == Instruction::DELEGATECALL ? m_ext->caller : m_ext->myAddress;
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
12 changes: 12 additions & 0 deletions test/libethereum/BlockChainTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,12 @@ BOOST_AUTO_TEST_CASE(bcTheDaoTest)
dev::test::executeTests("bcTheDaoTest", "/BlockchainTests/TestNetwork",dev::test::getFolder(__FILE__) + "/BlockchainTestsFiller/TestNetwork", dev::test::doBlockchainTests);
}

BOOST_AUTO_TEST_CASE(bcEIP150Test)
{
dev::test::TestBlockChain::s_sealEngineNetwork = eth::Network::Test;
dev::test::executeTests("bcEIP150Test", "/BlockchainTests/TestNetwork",dev::test::getFolder(__FILE__) + "/BlockchainTestsFiller/TestNetwork", dev::test::doBlockchainTests);
}

BOOST_AUTO_TEST_SUITE_END()

///
Expand All @@ -780,6 +786,12 @@ BOOST_AUTO_TEST_CASE(bcForkStressTestHomestead)
dev::test::executeTests("bcForkStressTest", "/BlockchainTests/Homestead",dev::test::getFolder(__FILE__) + "/BlockchainTestsFiller/Homestead", dev::test::doBlockchainTests);
}

BOOST_AUTO_TEST_CASE(bcSuicideIssueHomestead)
{
dev::test::TestBlockChain::s_sealEngineNetwork = eth::Network::HomesteadTest;
dev::test::executeTests("bcSuicideIssue", "/BlockchainTests/Homestead",dev::test::getFolder(__FILE__) + "/BlockchainTestsFiller/Homestead", dev::test::doBlockchainTests);
}

BOOST_AUTO_TEST_CASE(bcTotalDifficultyTestHomestead)
{
dev::test::TestBlockChain::s_sealEngineNetwork = eth::Network::HomesteadTest;
Expand Down
Loading