From 5e4f3b67464dbf60da749f97fe8319b2db41180b Mon Sep 17 00:00:00 2001 From: Dimitry Date: Sun, 20 Jan 2019 04:01:33 +0300 Subject: [PATCH 1/6] add ConstantinopleFix --- libethashseal/GenesisInfo.cpp | 9 ++- libethashseal/GenesisInfo.h | 4 +- .../test/ByzantiumToConstantinopleAt5Test.cpp | 4 +- .../genesis/test/constantinopleTestFix.cpp | 65 +++++++++++++++++++ libethcore/ChainOperationParams.cpp | 2 + libethcore/ChainOperationParams.h | 1 + libethcore/EVMSchedule.h | 6 ++ libethereum/ChainParams.cpp | 1 + libethereum/ValidationSchemes.cpp | 1 + libethereum/ValidationSchemes.h | 1 + test/tools/libtesteth/TestHelper.cpp | 19 ++++-- test/unittests/libtesteth/testHelperTest.cpp | 8 +++ 12 files changed, 109 insertions(+), 12 deletions(-) create mode 100644 libethashseal/genesis/test/constantinopleTestFix.cpp diff --git a/libethashseal/GenesisInfo.cpp b/libethashseal/GenesisInfo.cpp index e43b14b59d8..6a280c2b5c9 100644 --- a/libethashseal/GenesisInfo.cpp +++ b/libethashseal/GenesisInfo.cpp @@ -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/constantinopleTestFix.cpp" #include "genesis/test/eip150Test.cpp" #include "genesis/test/eip158Test.cpp" #include "genesis/test/experimentalTransitionTest.cpp" @@ -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_genesisInfoConstantinopleTestFix; + //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: @@ -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: diff --git a/libethashseal/GenesisInfo.h b/libethashseal/GenesisInfo.h index dee55d1b0cb..405763b60a4 100644 --- a/libethashseal/GenesisInfo.h +++ b/libethashseal/GenesisInfo.h @@ -65,13 +65,15 @@ enum class Network ByzantiumNoProofTest = 81, /// Constantinople rules + NoProof seal engine ConstantinopleNoProofTest = 82, + /// Byzantium + Constantinople + Constantinople FIx acrive from block 0 + ConstantinopleFixTest = 83, // TransitionTest networks FrontierToHomesteadAt5 = 100, HomesteadToDaoAt5 = 101, HomesteadToEIP150At5 = 102, EIP158ToByzantiumAt5 = 103, - ByzantiumToConstantinopleAt5 = 104, + ByzantiumToConstantinopleFixAt5 = 104, Special = 0xff ///< Something else. }; diff --git a/libethashseal/genesis/test/ByzantiumToConstantinopleAt5Test.cpp b/libethashseal/genesis/test/ByzantiumToConstantinopleAt5Test.cpp index 5b0b9c90338..7c8d8250bf4 100644 --- a/libethashseal/genesis/test/ByzantiumToConstantinopleAt5Test.cpp +++ b/libethashseal/genesis/test/ByzantiumToConstantinopleAt5Test.cpp @@ -16,8 +16,8 @@ along with cpp-ethereum. If not, see . */ #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": { diff --git a/libethashseal/genesis/test/constantinopleTestFix.cpp b/libethashseal/genesis/test/constantinopleTestFix.cpp new file mode 100644 index 00000000000..041498f1cba --- /dev/null +++ b/libethashseal/genesis/test/constantinopleTestFix.cpp @@ -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 . +*/ +#include "../../GenesisInfo.h" + +static std::string const c_genesisInfoConstantinopleTestFix = 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"; diff --git a/libethcore/ChainOperationParams.cpp b/libethcore/ChainOperationParams.cpp index 9fea6c2a727..bffa6cffca5 100644 --- a/libethcore/ChainOperationParams.cpp +++ b/libethcore/ChainOperationParams.cpp @@ -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) diff --git a/libethcore/ChainOperationParams.h b/libethcore/ChainOperationParams.h index 4e1095e43cd..a3f9baff290 100644 --- a/libethcore/ChainOperationParams.h +++ b/libethcore/ChainOperationParams.h @@ -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). diff --git a/libethcore/EVMSchedule.h b/libethcore/EVMSchedule.h index ba6215d4753..6fe8a1395c4 100644 --- a/libethcore/EVMSchedule.h +++ b/libethcore/EVMSchedule.h @@ -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; diff --git a/libethereum/ChainParams.cpp b/libethereum/ChainParams.cpp index eab9d6c6765..1b20ded188e 100644 --- a/libethereum/ChainParams.cpp +++ b/libethereum/ChainParams.cpp @@ -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); diff --git a/libethereum/ValidationSchemes.cpp b/libethereum/ValidationSchemes.cpp index 0588b4043b0..ed9dcaa27f4 100644 --- a/libethereum/ValidationSchemes.cpp +++ b/libethereum/ValidationSchemes.cpp @@ -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"; diff --git a/libethereum/ValidationSchemes.h b/libethereum/ValidationSchemes.h index 9a4b958d6ef..c80ddfe6e51 100644 --- a/libethereum/ValidationSchemes.h +++ b/libethereum/ValidationSchemes.h @@ -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; diff --git a/test/tools/libtesteth/TestHelper.cpp b/test/tools/libtesteth/TestHelper.cpp index ddd26bb33b4..1750d50d714 100644 --- a/test/tools/libtesteth/TestHelper.cpp +++ b/test/tools/libtesteth/TestHelper.cpp @@ -112,6 +112,8 @@ string netIdToString(eth::Network _netId) return "Byzantium"; case eth::Network::ConstantinopleTest: return "Constantinople"; + case eth::Network::ConstantinopleFixTest: + return "ConstantinopleFix"; case eth::Network::FrontierToHomesteadAt5: return "FrontierToHomesteadAt5"; case eth::Network::HomesteadToDaoAt5: @@ -120,7 +122,7 @@ string netIdToString(eth::Network _netId) return "HomesteadToEIP150At5"; case eth::Network::EIP158ToByzantiumAt5: return "EIP158ToByzantiumAt5"; - case eth::Network::ByzantiumToConstantinopleAt5: + case eth::Network::ByzantiumToConstantinopleFixAt5: return "ByzantiumToConstantinopleAt5"; case eth::Network::TransitionnetTest: return "TransitionNet"; @@ -136,9 +138,10 @@ eth::Network stringToNetId(string const& _netname) static vector const networks{ {eth::Network::FrontierTest, eth::Network::HomesteadTest, eth::Network::EIP150Test, eth::Network::EIP158Test, eth::Network::ByzantiumTest, eth::Network::ConstantinopleTest, - eth::Network::FrontierToHomesteadAt5, eth::Network::HomesteadToDaoAt5, - eth::Network::HomesteadToEIP150At5, eth::Network::EIP158ToByzantiumAt5, - eth::Network::ByzantiumToConstantinopleAt5, eth::Network::TransitionnetTest}}; + eth::Network::ConstantinopleFixTest, eth::Network::FrontierToHomesteadAt5, + eth::Network::HomesteadToDaoAt5, eth::Network::HomesteadToEIP150At5, + eth::Network::EIP158ToByzantiumAt5, eth::Network::ByzantiumToConstantinopleFixAt5, + eth::Network::TransitionnetTest}}; for (auto const& net : networks) if (netIdToString(net) == _netname) @@ -162,6 +165,7 @@ bool isDisabledNetwork(eth::Network _net) case eth::Network::FrontierToHomesteadAt5: case eth::Network::HomesteadToDaoAt5: case eth::Network::HomesteadToEIP150At5: + case eth::Network::ConstantinopleTest: // Disable initial constantinople version return true; default: break; @@ -172,9 +176,10 @@ bool isDisabledNetwork(eth::Network _net) set const& getNetworks() { // Networks for the test case execution when filling the tests - static set const networks{{eth::Network::FrontierTest, - eth::Network::HomesteadTest, eth::Network::EIP150Test, eth::Network::EIP158Test, - eth::Network::ByzantiumTest, eth::Network::ConstantinopleTest}}; + static set const networks{ + {eth::Network::FrontierTest, eth::Network::HomesteadTest, eth::Network::EIP150Test, + eth::Network::EIP158Test, eth::Network::ByzantiumTest, eth::Network::ConstantinopleTest, + eth::Network::ConstantinopleFixTest}}; return networks; } diff --git a/test/unittests/libtesteth/testHelperTest.cpp b/test/unittests/libtesteth/testHelperTest.cpp index dbc2036373a..67c64c7530d 100644 --- a/test/unittests/libtesteth/testHelperTest.cpp +++ b/test/unittests/libtesteth/testHelperTest.cpp @@ -28,6 +28,14 @@ using namespace dev::test; BOOST_FIXTURE_TEST_SUITE(TestHelperSuite, TestOutputHelperFixture) +BOOST_AUTO_TEST_CASE(translateNetworks_gtConstantinople) +{ + set networks = {">Constantinople"}; + networks = test::translateNetworks(networks); + BOOST_REQUIRE(networks.count("Constantinople") == 0); + BOOST_REQUIRE(networks.count("ConstantinopleFix") == 1); +} + BOOST_AUTO_TEST_CASE(translateNetworks_gtHomestead) { set networks = {"Frontier", ">Homestead"}; From ac02067eb9042b4a545af560e1ad09254d2f6b6d Mon Sep 17 00:00:00 2001 From: Dimitry Date: Tue, 22 Jan 2019 18:56:37 +0300 Subject: [PATCH 2/6] rename networks constantinopleFixTest --- aleth-vm/main.cpp | 2 ++ libethashseal/GenesisInfo.cpp | 6 +++--- libethashseal/GenesisInfo.h | 2 +- ...eAt5Test.cpp => ByzantiumToConstantinopleFixAt5Test.cpp} | 0 ...{constantinopleTestFix.cpp => constantinopleFixTest.cpp} | 2 +- test/tools/libtesteth/TestHelper.cpp | 2 +- 6 files changed, 8 insertions(+), 6 deletions(-) rename libethashseal/genesis/test/{ByzantiumToConstantinopleAt5Test.cpp => ByzantiumToConstantinopleFixAt5Test.cpp} (100%) rename libethashseal/genesis/test/{constantinopleTestFix.cpp => constantinopleFixTest.cpp} (97%) diff --git a/aleth-vm/main.cpp b/aleth-vm/main.cpp index 283f7001b89..a6c53c1f17e 100644 --- a/aleth-vm/main.cpp +++ b/aleth-vm/main.cpp @@ -226,6 +226,8 @@ int main(int argc, char** argv) if (vm.count("network")) { string network = vm["network"].as(); + if (network == "ConstantinopleFix") + networkName = Network::ConstantinopleFixTest; if (network == "Constantinople") networkName = Network::ConstantinopleTest; else if (network == "Byzantium") diff --git a/libethashseal/GenesisInfo.cpp b/libethashseal/GenesisInfo.cpp index 6a280c2b5c9..6e3a2ace283 100644 --- a/libethashseal/GenesisInfo.cpp +++ b/libethashseal/GenesisInfo.cpp @@ -29,7 +29,7 @@ using namespace dev; #include "genesis/test/byzantiumTransitionTest.cpp" #include "genesis/test/constantinopleNoProofTest.cpp" #include "genesis/test/constantinopleTest.cpp" -#include "genesis/test/constantinopleTestFix.cpp" +#include "genesis/test/constantinopleFixTest.cpp" #include "genesis/test/eip150Test.cpp" #include "genesis/test/eip158Test.cpp" #include "genesis/test/experimentalTransitionTest.cpp" @@ -40,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" @@ -76,7 +76,7 @@ std::string const& dev::eth::genesisInfo(Network _n) case Network::ExperimentalTransitionTest: return c_genesisInfoExperimentalTransitionTest; case Network::ConstantinopleFixTest: - return c_genesisInfoConstantinopleTestFix; + return c_genesisInfoConstantinopleFixTest; //Transition test genesis diff --git a/libethashseal/GenesisInfo.h b/libethashseal/GenesisInfo.h index 405763b60a4..ac74544b72c 100644 --- a/libethashseal/GenesisInfo.h +++ b/libethashseal/GenesisInfo.h @@ -65,7 +65,7 @@ enum class Network ByzantiumNoProofTest = 81, /// Constantinople rules + NoProof seal engine ConstantinopleNoProofTest = 82, - /// Byzantium + Constantinople + Constantinople FIx acrive from block 0 + /// Byzantium + Constantinople + ConstantinopleFix acrive from block 0 ConstantinopleFixTest = 83, // TransitionTest networks diff --git a/libethashseal/genesis/test/ByzantiumToConstantinopleAt5Test.cpp b/libethashseal/genesis/test/ByzantiumToConstantinopleFixAt5Test.cpp similarity index 100% rename from libethashseal/genesis/test/ByzantiumToConstantinopleAt5Test.cpp rename to libethashseal/genesis/test/ByzantiumToConstantinopleFixAt5Test.cpp diff --git a/libethashseal/genesis/test/constantinopleTestFix.cpp b/libethashseal/genesis/test/constantinopleFixTest.cpp similarity index 97% rename from libethashseal/genesis/test/constantinopleTestFix.cpp rename to libethashseal/genesis/test/constantinopleFixTest.cpp index 041498f1cba..0ba50c210e1 100644 --- a/libethashseal/genesis/test/constantinopleTestFix.cpp +++ b/libethashseal/genesis/test/constantinopleFixTest.cpp @@ -16,7 +16,7 @@ */ #include "../../GenesisInfo.h" -static std::string const c_genesisInfoConstantinopleTestFix = std::string() + +static std::string const c_genesisInfoConstantinopleFixTest = std::string() + R"E( { "sealEngine": "Ethash", diff --git a/test/tools/libtesteth/TestHelper.cpp b/test/tools/libtesteth/TestHelper.cpp index 1750d50d714..dce06d4f3f2 100644 --- a/test/tools/libtesteth/TestHelper.cpp +++ b/test/tools/libtesteth/TestHelper.cpp @@ -123,7 +123,7 @@ string netIdToString(eth::Network _netId) case eth::Network::EIP158ToByzantiumAt5: return "EIP158ToByzantiumAt5"; case eth::Network::ByzantiumToConstantinopleFixAt5: - return "ByzantiumToConstantinopleAt5"; + return "ByzantiumToConstantinopleFixAt5"; case eth::Network::TransitionnetTest: return "TransitionNet"; default: From 22a42cb88f236d3f3cfe09f709c9e7364f8a56f4 Mon Sep 17 00:00:00 2001 From: Dimitry Date: Wed, 23 Jan 2019 03:41:35 +0300 Subject: [PATCH 3/6] bcUncleSpecialTests --- test/tools/jsontests/BlockChainTests.cpp | 62 +++++++++++++----------- 1 file changed, 33 insertions(+), 29 deletions(-) diff --git a/test/tools/jsontests/BlockChainTests.cpp b/test/tools/jsontests/BlockChainTests.cpp index d9ff381f3dc..cbee50117a8 100644 --- a/test/tools/jsontests/BlockChainTests.cpp +++ b/test/tools/jsontests/BlockChainTests.cpp @@ -763,10 +763,10 @@ void overwriteUncleHeaderForTest(mObject& uncleHeaderObj, TestBlock& uncle, std: return; } - string overwrite = "false"; + set overwrite; if (uncleHeaderObj.count("overwriteAndRedoPoW")) { - overwrite = uncleHeaderObj.at("overwriteAndRedoPoW").get_str(); + ImportTest::parseJsonStrValueIntoSet(uncleHeaderObj.at("overwriteAndRedoPoW"), overwrite); uncleHeaderObj.erase("overwriteAndRedoPoW"); } @@ -809,42 +809,45 @@ void overwriteUncleHeaderForTest(mObject& uncleHeaderObj, TestBlock& uncle, std: uncleHeader = uncle.blockHeader(); } - if (overwrite != "false") + if (overwrite.size()) { - uncleHeader = constructHeader(overwrite == "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(), - uncleHeader.transactionsRoot(), uncleHeader.receiptsRoot(), uncleHeader.logBloom(), - overwrite == "difficulty" ? - toU256(uncleHeaderObj.at("difficulty")) : - overwrite == "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()); + for (auto const& rewrite : overwrite) + { + uncleHeader = constructHeader(rewrite == "parentHash" ? + h256(uncleHeaderObj.at("parentHash").get_str()) : + uncleHeader.parentHash(), + uncleHeader.sha3Uncles(), + 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(), + rewrite == "difficulty" ? + toU256(uncleHeaderObj.at("difficulty")) : + rewrite == "timestamp" ? + calculateEthashDifficulty(sealEngine->chainParams(), uncleHeader, + importedBlocks.at((size_t)uncleHeader.number() - 1).blockHeader()) : + uncleHeader.difficulty(), + 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); @@ -1065,6 +1068,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() From 6739ab44a3290bf87abf65119fa3b9efe365892d Mon Sep 17 00:00:00 2001 From: Dimitry Date: Wed, 23 Jan 2019 04:43:09 +0300 Subject: [PATCH 4/6] update tests --- aleth-vm/main.cpp | 2 +- libethashseal/GenesisInfo.h | 2 +- .../ByzantiumToConstantinopleFixAt5Test.cpp | 3 +- .../genesis/test/constantinopleFixTest.cpp | 84 +++++++++---------- test/jsontests | 2 +- test/tools/jsontests/BlockChainTests.cpp | 52 ++++++------ test/tools/jsontests/TransactionTests.cpp | 5 +- 7 files changed, 74 insertions(+), 76 deletions(-) diff --git a/aleth-vm/main.cpp b/aleth-vm/main.cpp index a6c53c1f17e..872e0a4ab4f 100644 --- a/aleth-vm/main.cpp +++ b/aleth-vm/main.cpp @@ -128,7 +128,7 @@ int main(int argc, char** argv) po::options_description networkOptions("Network options", c_lineWidth); networkOptions.add_options()("network", po::value(), - "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(); diff --git a/libethashseal/GenesisInfo.h b/libethashseal/GenesisInfo.h index ac74544b72c..641b84190e2 100644 --- a/libethashseal/GenesisInfo.h +++ b/libethashseal/GenesisInfo.h @@ -65,7 +65,7 @@ enum class Network ByzantiumNoProofTest = 81, /// Constantinople rules + NoProof seal engine ConstantinopleNoProofTest = 82, - /// Byzantium + Constantinople + ConstantinopleFix acrive from block 0 + /// Byzantium + Constantinople + ConstantinopleFix active from block 0 ConstantinopleFixTest = 83, // TransitionTest networks diff --git a/libethashseal/genesis/test/ByzantiumToConstantinopleFixAt5Test.cpp b/libethashseal/genesis/test/ByzantiumToConstantinopleFixAt5Test.cpp index 7c8d8250bf4..122a28249f1 100644 --- a/libethashseal/genesis/test/ByzantiumToConstantinopleFixAt5Test.cpp +++ b/libethashseal/genesis/test/ByzantiumToConstantinopleFixAt5Test.cpp @@ -26,7 +26,8 @@ static std::string const c_genesisInfoByzantiumToConstantinopleFixAt5Test = std: "EIP150ForkBlock": "0x00", "EIP158ForkBlock": "0x00", "byzantiumForkBlock": "0x00", - "constantinopleForkBlock": "0x05", + "constantinopleForkBlock": "0x00", + "constantinopleFixForkBlock": "0x05", "networkID" : "0x1", "chainID": "0x01", "maximumExtraDataSize": "0x20", diff --git a/libethashseal/genesis/test/constantinopleFixTest.cpp b/libethashseal/genesis/test/constantinopleFixTest.cpp index 0ba50c210e1..75e8f182b63 100644 --- a/libethashseal/genesis/test/constantinopleFixTest.cpp +++ b/libethashseal/genesis/test/constantinopleFixTest.cpp @@ -19,47 +19,47 @@ 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" } } - } + "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"; diff --git a/test/jsontests b/test/jsontests index 4cfaa3e600f..c5318ce8d71 160000 --- a/test/jsontests +++ b/test/jsontests @@ -1 +1 @@ -Subproject commit 4cfaa3e600f45d34bc00d88a4b142d2f27762912 +Subproject commit c5318ce8d71bba2c2f9c2ffccc199d02168aa1d2 diff --git a/test/tools/jsontests/BlockChainTests.cpp b/test/tools/jsontests/BlockChainTests.cpp index cbee50117a8..ec8b819f36f 100644 --- a/test/tools/jsontests/BlockChainTests.cpp +++ b/test/tools/jsontests/BlockChainTests.cpp @@ -809,34 +809,30 @@ void overwriteUncleHeaderForTest(mObject& uncleHeaderObj, TestBlock& uncle, std: uncleHeader = uncle.blockHeader(); } - if (overwrite.size()) + for (auto const& rewrite : overwrite) { - for (auto const& rewrite : overwrite) - { - uncleHeader = constructHeader(rewrite == "parentHash" ? - h256(uncleHeaderObj.at("parentHash").get_str()) : - uncleHeader.parentHash(), - uncleHeader.sha3Uncles(), - 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(), - rewrite == "difficulty" ? - toU256(uncleHeaderObj.at("difficulty")) : - rewrite == "timestamp" ? - calculateEthashDifficulty(sealEngine->chainParams(), uncleHeader, - importedBlocks.at((size_t)uncleHeader.number() - 1).blockHeader()) : - uncleHeader.difficulty(), - 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()); - } + uncleHeader = constructHeader(rewrite == "parentHash" ? + h256(uncleHeaderObj.at("parentHash").get_str()) : + uncleHeader.parentHash(), + uncleHeader.sha3Uncles(), + 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(), + rewrite == "difficulty" ? + toU256(uncleHeaderObj.at("difficulty")) : + rewrite == "timestamp" ? + calculateEthashDifficulty(sealEngine->chainParams(), uncleHeader, + importedBlocks.at((size_t)uncleHeader.number() - 1).blockHeader()) : + uncleHeader.difficulty(), + 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); @@ -1079,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() diff --git a/test/tools/jsontests/TransactionTests.cpp b/test/tools/jsontests/TransactionTests.cpp index 94c25dfa357..37e52fd0d33 100644 --- a/test/tools/jsontests/TransactionTests.cpp +++ b/test/tools/jsontests/TransactionTests.cpp @@ -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 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); } From 2df73ac5791439946b1bf06d302d9f76d4af707f Mon Sep 17 00:00:00 2001 From: Andrei Maiboroda Date: Mon, 28 Jan 2019 17:31:16 +0100 Subject: [PATCH 5/6] Support ConstantinopleFix in aleth-interpreter --- libaleth-interpreter/VM.cpp | 5 +++-- libevm/EVMC.cpp | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/libaleth-interpreter/VM.cpp b/libaleth-interpreter/VM.cpp index 727773c3783..955aa05c800 100644 --- a/libaleth-interpreter/VM.cpp +++ b/libaleth-interpreter/VM.cpp @@ -1360,12 +1360,13 @@ 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_rev >= EVMC_CONSTANTINOPLE2)) 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_rev < EVMC_CONSTANTINOPLE2); m_runGas = VMSchedule::sstoreUnchangedGas; } diff --git a/libevm/EVMC.cpp b/libevm/EVMC.cpp index 982dfc815ff..9dc548dbb95 100644 --- a/libevm/EVMC.cpp +++ b/libevm/EVMC.cpp @@ -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; From 8b3cfa0e2e1196dda0f46f1fb1a4b4730ef895e7 Mon Sep 17 00:00:00 2001 From: Andrei Maiboroda Date: Wed, 30 Jan 2019 15:58:51 +0100 Subject: [PATCH 6/6] Address minor review issues --- libaleth-interpreter/VM.cpp | 5 ++--- test/unittests/libtesteth/testHelperTest.cpp | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/libaleth-interpreter/VM.cpp b/libaleth-interpreter/VM.cpp index 955aa05c800..9d761333b4b 100644 --- a/libaleth-interpreter/VM.cpp +++ b/libaleth-interpreter/VM.cpp @@ -1360,13 +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 || m_rev >= EVMC_CONSTANTINOPLE2)) + 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 && m_rev < EVMC_CONSTANTINOPLE2); + assert(m_rev == EVMC_CONSTANTINOPLE); m_runGas = VMSchedule::sstoreUnchangedGas; } diff --git a/test/unittests/libtesteth/testHelperTest.cpp b/test/unittests/libtesteth/testHelperTest.cpp index 67c64c7530d..114f194f23e 100644 --- a/test/unittests/libtesteth/testHelperTest.cpp +++ b/test/unittests/libtesteth/testHelperTest.cpp @@ -32,8 +32,8 @@ BOOST_AUTO_TEST_CASE(translateNetworks_gtConstantinople) { set networks = {">Constantinople"}; networks = test::translateNetworks(networks); - BOOST_REQUIRE(networks.count("Constantinople") == 0); - BOOST_REQUIRE(networks.count("ConstantinopleFix") == 1); + BOOST_CHECK(!contains(networks, "Constantinople")); + BOOST_CHECK(contains(networks, "ConstantinopleFix")); } BOOST_AUTO_TEST_CASE(translateNetworks_gtHomestead)