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

Implement Ice Age delay and issuance reduction #5247

Merged
merged 3 commits into from
Sep 6, 2018
Merged
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
12 changes: 10 additions & 2 deletions libethashseal/Ethash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,16 @@ u256 Ethash::calculateDifficulty(BlockHeader const& _bi, BlockHeader const& _par
bigint o = target;
unsigned exponentialIceAgeBlockNumber = unsigned(_parent.number() + 1);

// EIP-649 modifies exponentialIceAgeBlockNumber
if (_bi.number() >= chainParams().byzantiumForkBlock)
// EIP-1234 Constantinople Ice Age delay
if (_bi.number() >= chainParams().constantinopleForkBlock)
{
if (exponentialIceAgeBlockNumber >= 5000000)
exponentialIceAgeBlockNumber -= 5000000;
else
exponentialIceAgeBlockNumber = 0;
}
// EIP-649 Byzantium Ice Age delay
else if (_bi.number() >= chainParams().byzantiumForkBlock)
{
if (exponentialIceAgeBlockNumber >= 3000000)
exponentialIceAgeBlockNumber -= 3000000;
Expand Down
9 changes: 8 additions & 1 deletion libethashseal/GenesisInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ using namespace dev;
#include "genesis/ropsten.cpp"

//Test configurations
#include "genesis/test/byzantiumNoProofTest.cpp"
#include "genesis/test/byzantiumTest.cpp"
#include "genesis/test/byzantiumTransitionTest.cpp"
#include "genesis/test/constantinopleNoProofTest.cpp"
#include "genesis/test/constantinopleTest.cpp"
#include "genesis/test/eip150Test.cpp"
#include "genesis/test/eip158Test.cpp"
Expand Down Expand Up @@ -62,8 +64,13 @@ std::string const& dev::eth::genesisInfo(Network _n)
case Network::EIP150Test: return c_genesisInfoEIP150Test;
case Network::EIP158Test: return c_genesisInfoEIP158Test;
case Network::ByzantiumTest: return c_genesisInfoByzantiumTest;
case Network::ByzantiumNoProofTest:
return c_genesisInfoByzantiumNoProofTest;
case Network::ByzantiumTransitionTest: return c_genesisInfoByzantiumTransitionTest;
case Network::ConstantinopleTest: return c_genesisInfoConstantinopleTest;
case Network::ConstantinopleTest:
return c_genesisInfoConstantinopleTest;
case Network::ConstantinopleNoProofTest:
return c_genesisInfoConstantinopleNoProofTest;
case Network::ExperimentalTransitionTest:
return c_genesisInfoExperimentalTransitionTest;

Expand Down
4 changes: 4 additions & 0 deletions libethashseal/GenesisInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ enum class Network
ExperimentalTransitionTest = 79,
/// MainNetwork rules without genesis accounts + NoProof seal engine
MainNetworkNoProofTest = 80,
/// Byzantium rules + NoProof seal engine
ByzantiumNoProofTest = 81,
/// Constantinople rules + NoProof seal engine
ConstantinopleNoProofTest = 82,

// TransitionTest networks
FrontierToHomesteadAt5 = 100,
Expand Down
62 changes: 62 additions & 0 deletions libethashseal/genesis/test/byzantiumNoProofTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
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_genesisInfoByzantiumNoProofTest = R"E(
{
"sealEngine": "NoProof",
"params": {
"accountStartNonce": "0x00",
"maximumExtraDataSize": "0x20",
"homesteadForkBlock": "0x00",
"EIP150ForkBlock": "0x00",
"EIP158ForkBlock": "0x00",
"byzantiumForkBlock": "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";
63 changes: 63 additions & 0 deletions libethashseal/genesis/test/constantinopleNoProofTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
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_genesisInfoConstantinopleNoProofTest = R"E(
{
"sealEngine": "NoProof",
"params": {
"accountStartNonce": "0x00",
"maximumExtraDataSize": "0x20",
"homesteadForkBlock": "0x00",
"EIP150ForkBlock": "0x00",
"EIP158ForkBlock": "0x00",
"byzantiumForkBlock": "0x00",
"constantinopleForkBlock": "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";
1 change: 1 addition & 0 deletions libethcore/EVMSchedule.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ static const EVMSchedule ConstantinopleSchedule = []
schedule.haveBitwiseShifting = true;
schedule.haveExtcodehash = true;
schedule.eip1283Mode = true;
schedule.blockRewardOverwrite = {2 * ether};
return schedule;
}();

Expand Down
16 changes: 16 additions & 0 deletions test/tools/libtesteth/BlockChainHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,5 +195,21 @@ class MainNetworkNoProofTestFixture : public TestOutputHelperFixture

NetworkSelector networkSelector;
};

class ByzantiumTestFixture : public TestOutputHelperFixture
{
public:
ByzantiumTestFixture() : networkSelector(Network::ByzantiumNoProofTest) {}

NetworkSelector networkSelector;
};

class ConstantinopleTestFixture : public TestOutputHelperFixture
{
public:
ConstantinopleTestFixture() : networkSelector(Network::ConstantinopleNoProofTest) {}

NetworkSelector networkSelector;
};
}
}
46 changes: 46 additions & 0 deletions test/unittests/libethashseal/EthashTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,52 @@ BOOST_AUTO_TEST_CASE(calculateDifficultyByzantiumMaxAdjustment)
BOOST_CHECK_EQUAL(ethash.calculateDifficulty(header, parentHeader), 951688);
}

class IceAgeDelayFixture: public TestOutputHelperFixture
{
public:
IceAgeDelayFixture()
{
params.homesteadForkBlock = 0;
params.byzantiumForkBlock = 4000000;
params.constantinopleForkBlock = 6000000;

ethash.setChainParams(params);
}

u256 calculateDifficulty(int64_t _blockNumber)
{
BlockHeader parentHeader;
parentHeader.clear();
parentHeader.setNumber(_blockNumber - 1);
parentHeader.setTimestamp(100);
parentHeader.setDifficulty(1000000);

BlockHeader header;
header.clear();
header.setNumber(_blockNumber);
header.setTimestamp(1100);

return ethash.calculateDifficulty(header, parentHeader);
}

ChainOperationParams params;
Ethash ethash;
};

BOOST_FIXTURE_TEST_SUITE(IceAgeDelayTests, IceAgeDelayFixture)

BOOST_AUTO_TEST_CASE(ByzantiumIceAgeDelay)
{
BOOST_CHECK_EQUAL(calculateDifficulty(4500000), calculateDifficulty(1500000));
}

BOOST_AUTO_TEST_CASE(ConstantinopleIceAgeDelay)
{
BOOST_CHECK_EQUAL(calculateDifficulty(6500000), calculateDifficulty(1500000));
}

BOOST_AUTO_TEST_SUITE_END()

BOOST_AUTO_TEST_CASE(epochSeed)
{
BlockHeader header;
Expand Down
31 changes: 31 additions & 0 deletions test/unittests/libethereum/Block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,37 @@ BOOST_AUTO_TEST_CASE(bGetReceiptOverflow)
BOOST_CHECK_THROW(block.receipt(123), std::out_of_range);
}


BOOST_FIXTURE_TEST_SUITE(ByzantiumBlockSuite, ByzantiumTestFixture)

BOOST_AUTO_TEST_CASE(bByzantiumBlockReward)
{
TestBlockChain testBlockchain;
TestBlock testBlock;
testBlock.mine(testBlockchain);
testBlockchain.addBlock(testBlock);

TestBlock const& topBlock = testBlockchain.topBlock();
BOOST_REQUIRE_EQUAL(topBlock.state().balance(topBlock.beneficiary()), 3 * ether);
}

BOOST_AUTO_TEST_SUITE_END()

BOOST_FIXTURE_TEST_SUITE(ConstantinopleBlockSuite, ConstantinopleTestFixture)

BOOST_AUTO_TEST_CASE(bConstantinopleBlockReward)
{
TestBlockChain testBlockchain;
TestBlock testBlock;
testBlock.mine(testBlockchain);
testBlockchain.addBlock(testBlock);

TestBlock const& topBlock = testBlockchain.topBlock();
BOOST_REQUIRE_EQUAL(topBlock.state().balance(topBlock.beneficiary()), 2 * ether);
}

BOOST_AUTO_TEST_SUITE_END()

class ExperimentalTransitionTestFixture : public TestOutputHelperFixture
{
public:
Expand Down