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

Commit

Permalink
Merge pull request #5443 from ethereum/const
Browse files Browse the repository at this point in the history
add ConstantinopleFix
  • Loading branch information
gumb0 authored Jan 30, 2019
2 parents f9b2b4b + 8b3cfa0 commit c901c8a
Show file tree
Hide file tree
Showing 18 changed files with 147 additions and 44 deletions.
4 changes: 3 additions & 1 deletion aleth-vm/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ int main(int argc, char** argv)

po::options_description networkOptions("Network options", c_lineWidth);
networkOptions.add_options()("network", po::value<string>(),
"Main|Ropsten|Homestead|Frontier|Byzantium|Constantinople\n");
"Main|Ropsten|Homestead|Frontier|Byzantium|Constantinople|ConstantinopleFix\n");

po::options_description optionsForTrace("Options for trace", c_lineWidth);
auto addTraceOption = optionsForTrace.add_options();
Expand Down Expand Up @@ -226,6 +226,8 @@ int main(int argc, char** argv)
if (vm.count("network"))
{
string network = vm["network"].as<string>();
if (network == "ConstantinopleFix")
networkName = Network::ConstantinopleFixTest;
if (network == "Constantinople")
networkName = Network::ConstantinopleTest;
else if (network == "Byzantium")
Expand Down
4 changes: 2 additions & 2 deletions libaleth-interpreter/VM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1360,12 +1360,12 @@ void VM::interpretCases()
m_runGas = VMSchedule::sstoreSetGas;
else if (status == EVMC_STORAGE_MODIFIED || status == EVMC_STORAGE_DELETED)
m_runGas = VMSchedule::sstoreResetGas;
else if (status == EVMC_STORAGE_UNCHANGED && m_rev < EVMC_CONSTANTINOPLE)
else if (status == EVMC_STORAGE_UNCHANGED && m_rev != EVMC_CONSTANTINOPLE)
m_runGas = VMSchedule::sstoreResetGas;
else
{
assert(status == EVMC_STORAGE_UNCHANGED || status == EVMC_STORAGE_MODIFIED_AGAIN);
assert(m_rev >= EVMC_CONSTANTINOPLE);
assert(m_rev == EVMC_CONSTANTINOPLE);
m_runGas = VMSchedule::sstoreUnchangedGas;
}

Expand Down
11 changes: 8 additions & 3 deletions libethashseal/GenesisInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ using namespace dev;
#include "genesis/test/byzantiumTransitionTest.cpp"
#include "genesis/test/constantinopleNoProofTest.cpp"
#include "genesis/test/constantinopleTest.cpp"
#include "genesis/test/constantinopleFixTest.cpp"
#include "genesis/test/eip150Test.cpp"
#include "genesis/test/eip158Test.cpp"
#include "genesis/test/experimentalTransitionTest.cpp"
Expand All @@ -39,7 +40,7 @@ using namespace dev;
#include "genesis/test/mainNetworkTest.cpp"

//Transition configurations
#include "genesis/test/ByzantiumToConstantinopleAt5Test.cpp"
#include "genesis/test/ByzantiumToConstantinopleFixAt5Test.cpp"
#include "genesis/test/EIP158ToByzantiumAt5Test.cpp"
#include "genesis/test/frontierToHomesteadAt5Test.cpp"
#include "genesis/test/homesteadToDaoAt5Test.cpp"
Expand Down Expand Up @@ -74,14 +75,17 @@ std::string const& dev::eth::genesisInfo(Network _n)
return c_genesisInfoConstantinopleNoProofTest;
case Network::ExperimentalTransitionTest:
return c_genesisInfoExperimentalTransitionTest;
case Network::ConstantinopleFixTest:
return c_genesisInfoConstantinopleFixTest;


//Transition test genesis
case Network::FrontierToHomesteadAt5: return c_genesisInfoFrontierToHomesteadAt5Test;
case Network::HomesteadToDaoAt5: return c_genesisInfoHomesteadToDaoAt5Test;
case Network::HomesteadToEIP150At5: return c_genesisInfoHomesteadToEIP150At5Test;
case Network::EIP158ToByzantiumAt5: return c_genesisInfoEIP158ToByzantiumAt5Test;
case Network::ByzantiumToConstantinopleAt5:
return c_genesisInfoByzantiumToConstantinopleAt5Test;
case Network::ByzantiumToConstantinopleFixAt5:
return c_genesisInfoByzantiumToConstantinopleFixAt5Test;
case Network::TransitionnetTest: return c_genesisInfoTest;

default:
Expand All @@ -103,6 +107,7 @@ h256 const& dev::eth::genesisStateRoot(Network _n)
case Network::EIP158Test:
case Network::ByzantiumTest:
case Network::ConstantinopleTest:
case Network::ConstantinopleFixTest:
case Network::ExperimentalTransitionTest:
return c_genesisDefaultStateRoot;
default:
Expand Down
4 changes: 3 additions & 1 deletion libethashseal/GenesisInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,15 @@ enum class Network
ByzantiumNoProofTest = 81,
/// Constantinople rules + NoProof seal engine
ConstantinopleNoProofTest = 82,
/// Byzantium + Constantinople + ConstantinopleFix active from block 0
ConstantinopleFixTest = 83,

// TransitionTest networks
FrontierToHomesteadAt5 = 100,
HomesteadToDaoAt5 = 101,
HomesteadToEIP150At5 = 102,
EIP158ToByzantiumAt5 = 103,
ByzantiumToConstantinopleAt5 = 104,
ByzantiumToConstantinopleFixAt5 = 104,

Special = 0xff ///< Something else.
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
*/
#include "../../GenesisInfo.h"

static std::string const c_genesisInfoByzantiumToConstantinopleAt5Test = std::string() +
R"E(
static std::string const c_genesisInfoByzantiumToConstantinopleFixAt5Test = std::string() +
R"E(
{
"sealEngine": "Ethash",
"params": {
Expand All @@ -26,7 +26,8 @@ static std::string const c_genesisInfoByzantiumToConstantinopleAt5Test = std::st
"EIP150ForkBlock": "0x00",
"EIP158ForkBlock": "0x00",
"byzantiumForkBlock": "0x00",
"constantinopleForkBlock": "0x05",
"constantinopleForkBlock": "0x00",
"constantinopleFixForkBlock": "0x05",
"networkID" : "0x1",
"chainID": "0x01",
"maximumExtraDataSize": "0x20",
Expand Down
65 changes: 65 additions & 0 deletions libethashseal/genesis/test/constantinopleFixTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
This file is part of cpp-ethereum.
cpp-ethereum is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
cpp-ethereum is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
*/
#include "../../GenesisInfo.h"

static std::string const c_genesisInfoConstantinopleFixTest = std::string() +
R"E(
{
"sealEngine": "Ethash",
"params": {
"accountStartNonce": "0x00",
"maximumExtraDataSize": "0x20",
"homesteadForkBlock": "0x00",
"EIP150ForkBlock": "0x00",
"EIP158ForkBlock": "0x00",
"byzantiumForkBlock": "0x00",
"constantinopleForkBlock": "0x00",
"constantinopleFixForkBlock": "0x00",
"minGasLimit": "0x1388",
"maxGasLimit": "7fffffffffffffff",
"tieBreakingGas": false,
"gasLimitBoundDivisor": "0x0400",
"minimumDifficulty": "0x020000",
"difficultyBoundDivisor": "0x0800",
"durationLimit": "0x0d",
"blockReward": "0x4563918244F40000",
"networkID" : "0x1",
"chainID": "0x01",
"allowFutureBlocks" : true
},
"genesis": {
"nonce": "0x0000000000000042",
"difficulty": "0x020000",
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"author": "0x0000000000000000000000000000000000000000",
"timestamp": "0x00",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"extraData": "0x11bbe8db4e347b4e8c937c1c8370e4b5ed33adb3db69cbdb7a38e1e50b1b82fa",
"gasLimit": "0x1388"
},
"accounts": {
"0000000000000000000000000000000000000001": { "precompiled": { "name": "ecrecover", "linear": { "base": 3000, "word": 0 } } },
"0000000000000000000000000000000000000002": { "precompiled": { "name": "sha256", "linear": { "base": 60, "word": 12 } } },
"0000000000000000000000000000000000000003": { "precompiled": { "name": "ripemd160", "linear": { "base": 600, "word": 120 } } },
"0000000000000000000000000000000000000004": { "precompiled": { "name": "identity", "linear": { "base": 15, "word": 3 } } },
"0000000000000000000000000000000000000005": { "precompiled": { "name": "modexp" } },
"0000000000000000000000000000000000000006": { "precompiled": { "name": "alt_bn128_G1_add", "linear": { "base": 500, "word": 0 } } },
"0000000000000000000000000000000000000007": { "precompiled": { "name": "alt_bn128_G1_mul", "linear": { "base": 40000, "word": 0 } } },
"0000000000000000000000000000000000000008": { "precompiled": { "name": "alt_bn128_pairing_product" } }
}
}
)E";
2 changes: 2 additions & 0 deletions libethcore/ChainOperationParams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ EVMSchedule const& ChainOperationParams::scheduleForBlockNumber(u256 const& _blo
{
if (_blockNumber >= experimentalForkBlock)
return ExperimentalSchedule;
else if (_blockNumber >= constantinopleFixForkBlock)
return ConstantinopleFixSchedule;
else if (_blockNumber >= constantinopleForkBlock)
return ConstantinopleSchedule;
else if (_blockNumber >= eWASMForkBlock)
Expand Down
1 change: 1 addition & 0 deletions libethcore/ChainOperationParams.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ struct ChainOperationParams
u256 byzantiumForkBlock = c_infiniteBlockNumer;
u256 eWASMForkBlock = c_infiniteBlockNumer;
u256 constantinopleForkBlock = c_infiniteBlockNumer;
u256 constantinopleFixForkBlock = c_infiniteBlockNumer;
u256 daoHardforkBlock = c_infiniteBlockNumer;
u256 experimentalForkBlock = c_infiniteBlockNumer;
int chainID = 0; // Distinguishes different chains (mainnet, Ropsten, etc).
Expand Down
6 changes: 6 additions & 0 deletions libethcore/EVMSchedule.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,12 @@ static const EVMSchedule ConstantinopleSchedule = []
return schedule;
}();

static const EVMSchedule ConstantinopleFixSchedule = [] {
EVMSchedule schedule = ConstantinopleSchedule;
schedule.eip1283Mode = false;
return schedule;
}();

static const EVMSchedule ExperimentalSchedule = [] {
EVMSchedule schedule = ConstantinopleSchedule;
schedule.blockhashGas = 800;
Expand Down
1 change: 1 addition & 0 deletions libethereum/ChainParams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ ChainParams ChainParams::loadConfig(
setOptionalU256Parameter(cp.byzantiumForkBlock, c_byzantiumForkBlock);
setOptionalU256Parameter(cp.eWASMForkBlock, c_eWASMForkBlock);
setOptionalU256Parameter(cp.constantinopleForkBlock, c_constantinopleForkBlock);
setOptionalU256Parameter(cp.constantinopleFixForkBlock, c_constantinopleFixForkBlock);
setOptionalU256Parameter(cp.daoHardforkBlock, c_daoHardforkBlock);
setOptionalU256Parameter(cp.experimentalForkBlock, c_experimentalForkBlock);
setOptionalU256Parameter(cp.minimumDifficulty, c_minimumDifficulty);
Expand Down
1 change: 1 addition & 0 deletions libethereum/ValidationSchemes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ string const c_EIP158ForkBlock = "EIP158ForkBlock";
string const c_byzantiumForkBlock = "byzantiumForkBlock";
string const c_eWASMForkBlock = "eWASMForkBlock";
string const c_constantinopleForkBlock = "constantinopleForkBlock";
string const c_constantinopleFixForkBlock = "constantinopleFixForkBlock";
string const c_experimentalForkBlock = "experimentalForkBlock";
string const c_accountStartNonce = "accountStartNonce";
string const c_maximumExtraDataSize = "maximumExtraDataSize";
Expand Down
1 change: 1 addition & 0 deletions libethereum/ValidationSchemes.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ extern std::string const c_EIP158ForkBlock;
extern std::string const c_byzantiumForkBlock;
extern std::string const c_eWASMForkBlock;
extern std::string const c_constantinopleForkBlock;
extern std::string const c_constantinopleFixForkBlock;
extern std::string const c_experimentalForkBlock;
extern std::string const c_accountStartNonce;
extern std::string const c_maximumExtraDataSize;
Expand Down
4 changes: 3 additions & 1 deletion libevm/EVMC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ namespace
{
evmc_revision toRevision(EVMSchedule const& _schedule) noexcept
{
if (_schedule.haveCreate2)
if (_schedule.haveCreate2 && !_schedule.eip1283Mode)
return EVMC_CONSTANTINOPLE2;
if (_schedule.haveCreate2 && _schedule.eip1283Mode)
return EVMC_CONSTANTINOPLE;
if (_schedule.haveRevert)
return EVMC_BYZANTIUM;
Expand Down
2 changes: 1 addition & 1 deletion test/jsontests
Submodule jsontests updated 24286 files
44 changes: 22 additions & 22 deletions test/tools/jsontests/BlockChainTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -763,10 +763,10 @@ void overwriteUncleHeaderForTest(mObject& uncleHeaderObj, TestBlock& uncle, std:
return;
}

string overwrite = "false";
set<string> overwrite;
if (uncleHeaderObj.count("overwriteAndRedoPoW"))
{
overwrite = uncleHeaderObj.at("overwriteAndRedoPoW").get_str();
ImportTest::parseJsonStrValueIntoSet(uncleHeaderObj.at("overwriteAndRedoPoW"), overwrite);
uncleHeaderObj.erase("overwriteAndRedoPoW");
}

Expand Down Expand Up @@ -809,42 +809,41 @@ void overwriteUncleHeaderForTest(mObject& uncleHeaderObj, TestBlock& uncle, std:
uncleHeader = uncle.blockHeader();
}

if (overwrite != "false")
for (auto const& rewrite : overwrite)
{
uncleHeader = constructHeader(overwrite == "parentHash" ?
uncleHeader = constructHeader(rewrite == "parentHash" ?
h256(uncleHeaderObj.at("parentHash").get_str()) :
uncleHeader.parentHash(),
uncleHeader.sha3Uncles(),
overwrite == "coinbase" ? Address(uncleHeaderObj.at("coinbase").get_str()) :
uncleHeader.author(),
overwrite == "stateRoot" ? h256(uncleHeaderObj.at("stateRoot").get_str()) :
uncleHeader.stateRoot(),
rewrite == "coinbase" ? Address(uncleHeaderObj.at("coinbase").get_str()) :
uncleHeader.author(),
rewrite == "stateRoot" ? h256(uncleHeaderObj.at("stateRoot").get_str()) :
uncleHeader.stateRoot(),
uncleHeader.transactionsRoot(), uncleHeader.receiptsRoot(), uncleHeader.logBloom(),
overwrite == "difficulty" ?
rewrite == "difficulty" ?
toU256(uncleHeaderObj.at("difficulty")) :
overwrite == "timestamp" ?
rewrite == "timestamp" ?
calculateEthashDifficulty(sealEngine->chainParams(), uncleHeader,
importedBlocks.at((size_t)uncleHeader.number() - 1).blockHeader()) :
uncleHeader.difficulty(),
overwrite == "number" ? toU256(uncleHeaderObj.at("number")) : uncleHeader.number(),
overwrite == "gasLimit" ? toU256(uncleHeaderObj.at("gasLimit")) :
uncleHeader.gasLimit(),
overwrite == "gasUsed" ? toU256(uncleHeaderObj.at("gasUsed")) : uncleHeader.gasUsed(),
overwrite == "timestamp" ? toU256(uncleHeaderObj.at("timestamp")) :
uncleHeader.timestamp(),
overwrite == "extraData" ? fromHex(uncleHeaderObj.at("extraData").get_str()) :
uncleHeader.extraData());
rewrite == "number" ? toU256(uncleHeaderObj.at("number")) : uncleHeader.number(),
rewrite == "gasLimit" ? toU256(uncleHeaderObj.at("gasLimit")) : uncleHeader.gasLimit(),
rewrite == "gasUsed" ? toU256(uncleHeaderObj.at("gasUsed")) : uncleHeader.gasUsed(),
rewrite == "timestamp" ? toU256(uncleHeaderObj.at("timestamp")) :
uncleHeader.timestamp(),
rewrite == "extraData" ? fromHex(uncleHeaderObj.at("extraData").get_str()) :
uncleHeader.extraData());
}

uncle.setBlockHeader(uncleHeader);
cnote << "Updating block nonce. Difficulty of: " << uncle.blockHeader().difficulty();
uncle.updateNonce(_chainBranch.blockchain);

if (overwrite == "nonce" || overwrite == "mixHash")
if (overwrite.count("nonce") || overwrite.count("mixHash"))
{
if (overwrite == "nonce")
if (overwrite.count("nonce"))
Ethash::setNonce(uncleHeader, eth::Nonce(uncleHeaderObj["nonce"].get_str()));
if (overwrite == "mixHash")
if (overwrite.count("mixHash"))
Ethash::setMixHash(uncleHeader, h256(uncleHeaderObj["mixHash"].get_str()));

uncle.setBlockHeader(uncleHeader);
Expand Down Expand Up @@ -1065,6 +1064,7 @@ BOOST_AUTO_TEST_CASE(bcForkStressTest){}
BOOST_AUTO_TEST_CASE(bcForgedTest){}
BOOST_AUTO_TEST_CASE(bcRandomBlockhashTest){}
BOOST_AUTO_TEST_CASE(bcExploitTest){}
BOOST_AUTO_TEST_CASE(bcUncleSpecialTests){}

BOOST_AUTO_TEST_SUITE_END()

Expand All @@ -1075,7 +1075,7 @@ BOOST_AUTO_TEST_CASE(bcFrontierToHomestead){}
BOOST_AUTO_TEST_CASE(bcHomesteadToDao){}
BOOST_AUTO_TEST_CASE(bcHomesteadToEIP150){}
BOOST_AUTO_TEST_CASE(bcEIP158ToByzantium){}
BOOST_AUTO_TEST_CASE(bcByzantiumToConstantinople) {}
BOOST_AUTO_TEST_CASE(bcByzantiumToConstantinopleFix) {}

BOOST_AUTO_TEST_SUITE_END()

Expand Down
5 changes: 3 additions & 2 deletions test/tools/jsontests/TransactionTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,14 @@ mObject getExpectSection(mValue const& _expect, eth::Network _network)
BOOST_REQUIRE_MESSAGE(obj.count("network"), "network section not set in expect section!");
set<string> networks;
ImportTest::parseJsonStrValueIntoSet(obj["network"], networks);
networks = translateNetworks(networks);
BOOST_CHECK_MESSAGE(networks.size() > 0, TestOutputHelper::get().testName() + " Network array not set!");
ImportTest::checkAllowedNetwork(networks);

if (networks.count(test::netIdToString(_network)) || networks.count(string("ALL")))
if (networks.count(test::netIdToString(_network)))
objVector.push_back(obj);
}
BOOST_REQUIRE_MESSAGE(objVector.size() == 1, "Expect network should occur once in expect section of transaction test filler! (" + test::netIdToString(_network) + ")");
BOOST_REQUIRE_MESSAGE(objVector.size() == 1, "Expect network should occur once in expect section of transaction test filler! (" + test::netIdToString(_network) + ") " + TestOutputHelper::get().testName());
return objVector.at(0);
}

Expand Down
Loading

0 comments on commit c901c8a

Please sign in to comment.