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

fix NoProof block signature #5219

Merged
merged 1 commit into from
Aug 31, 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
1 change: 0 additions & 1 deletion libethashseal/Ethash.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ class Ethash: public SealEngineBase

eth::GenericFarm<EthashProofOfWork>& farm() { return m_farm; }

enum { MixHashField = 0, NonceField = 1 };
static h256 seedHash(BlockHeader const& _bi);
static Nonce nonce(BlockHeader const& _bi) { return _bi.seal<Nonce>(NonceField); }
static h256 mixHash(BlockHeader const& _bi) { return _bi.seal<h256>(MixHashField); }
Expand Down
7 changes: 5 additions & 2 deletions libethcore/BasicAuthority.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,11 @@ void BasicAuthority::generateSeal(BlockHeader const& _bi)
BlockHeader bi = _bi;
h256 h = bi.hash(WithoutSeal);
Signature s = sign(m_secret, h);
setSig(bi, s);
SealEngineBase::generateSeal(bi);
setSig(bi, s);
RLPStream ret;
bi.streamRLP(ret);
if (m_onSealGenerated)
m_onSealGenerated(ret.out());
}

bool BasicAuthority::onOptionChanging(std::string const& _name, bytes const& _value)
Expand Down
11 changes: 11 additions & 0 deletions libethcore/SealEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@ void NoProof::init()
ETH_REGISTER_SEAL_ENGINE(NoProof);
}

void NoProof::generateSeal(BlockHeader const& _bi)
{
BlockHeader header(_bi);
header.setSeal(NonceField, h64{0});
header.setSeal(MixHashField, h256{0});
RLPStream ret;
header.streamRLP(ret);
if (m_onSealGenerated)
m_onSealGenerated(ret.out());
}

void SealEngineFace::verify(Strictness _s, BlockHeader const& _bi, BlockHeader const& _parent, bytesConstRef _block) const
{
_bi.verify(_s, _parent, _block);
Expand Down
15 changes: 7 additions & 8 deletions libethcore/SealEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,12 @@ class SealEngineFace
class SealEngineBase: public SealEngineFace
{
public:
void generateSeal(BlockHeader const& _bi) override
{
RLPStream ret;
_bi.streamRLP(ret);
if (m_onSealGenerated)
m_onSealGenerated(ret.out());
}
void onSealGenerated(std::function<void(bytes const&)> const& _f) override { m_onSealGenerated = _f; }
enum
{
MixHashField = 0,
NonceField = 1
};
void onSealGenerated(std::function<void(bytes const&)> const& _f) override { m_onSealGenerated = _f; }
EVMSchedule const& evmSchedule(u256 const& _blockNumber) const override;
u256 blockReward(u256 const& _blockNumber) const override;

Expand Down Expand Up @@ -139,6 +137,7 @@ class NoProof: public eth::SealEngineBase
public:
static std::string name() { return "NoProof"; }
static void init();
void generateSeal(BlockHeader const& _bi) override;
};

}
Expand Down
12 changes: 3 additions & 9 deletions test/tools/jsontests/BlockChainTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ json_spirit::mValue BlockchainTestSuite::doTests(json_spirit::mValue const& _inp
set<string> netlist;
json_spirit::mObject const& expectObj = expect.get_obj();
ImportTest::parseJsonStrValueIntoSet(expectObj.at("network"), netlist);

netlist = test::translateNetworks(netlist);
gumb0 marked this conversation as resolved.
Show resolved Hide resolved
if (netlist.count(test::netIdToString(network)) || netlist.count("ALL"))
{
jObjOutput["expect"] = expectObj.at("result");
Expand Down Expand Up @@ -440,10 +440,6 @@ void testBCTest(json_spirit::mObject const& _o)
TestBlock genesisBlock(_o.at("genesisBlockHeader").get_obj(), _o.at("pre").get_obj());

TestBlockChain::MiningType const miningType = getMiningType(_o);
eth::IncludeSeal includeSeal = (miningType == TestBlockChain::MiningType::ForceEthash ||
miningType == TestBlockChain::MiningType::Default) ?
WithSeal :
WithoutSeal;
TestBlockChain blockchain(genesisBlock, miningType);
TestBlockChain testChain(genesisBlock, miningType);
assert(testChain.getInterface().isKnown(genesisBlock.blockHeader().hash(WithSeal)));
Expand Down Expand Up @@ -539,8 +535,7 @@ void testBCTest(json_spirit::mObject const& _o)
}

//Check that imported block to the chain is equal to declared block from test
bytes importedblock =
testChain.getInterface().block(blockFromFields.blockHeader().hash(includeSeal));
bytes importedblock = testChain.getInterface().block(blockFromFields.blockHeader().hash());
TestBlock inchainBlock(toHex(importedblock));
checkBlocks(inchainBlock, blockFromFields, testName);

Expand Down Expand Up @@ -571,7 +566,7 @@ void testBCTest(json_spirit::mObject const& _o)

//Check lastblock hash
BOOST_REQUIRE((_o.count("lastblockhash") > 0));
string lastTrueBlockHash = toHexPrefixed(testChain.topBlock().blockHeader().hash(includeSeal));
string lastTrueBlockHash = toHexPrefixed(testChain.topBlock().blockHeader().hash());
BOOST_CHECK_MESSAGE(lastTrueBlockHash == _o.at("lastblockhash").get_str(),
testName + "Boost check: lastblockhash does not match " + lastTrueBlockHash + " expected: " + _o.at("lastblockhash").get_str());

Expand Down Expand Up @@ -1100,7 +1095,6 @@ BOOST_AUTO_TEST_CASE(stBugs){}
//Constantinople Tests
BOOST_AUTO_TEST_CASE(stShift){}


//Stress Tests
BOOST_AUTO_TEST_CASE(stAttackTest){}
BOOST_AUTO_TEST_CASE(stMemoryStressTest){}
Expand Down
8 changes: 6 additions & 2 deletions test/tools/jsontests/StateTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,12 @@ json_spirit::mValue StateTestSuite::doTests(json_spirit::mValue const& _input, b
if (!foundResults)
{
Options const& opt = Options::get();
BOOST_ERROR("Transaction not found! (Network: " + (opt.singleTestNet.empty() ? "Any" : opt.singleTestNet) + ", dataInd: " + toString(opt.trDataIndex) + ", gasInd: " + toString(opt.trGasIndex) + ", valInd: " + toString(opt.trValueIndex) + ")");
}
BOOST_ERROR("Transaction not found! (Test: '" + testname + "', Network: " +
(opt.singleTestNet.empty() ? "Any" : opt.singleTestNet) +
", dataInd: " + toString(opt.trDataIndex) +
", gasInd: " + toString(opt.trGasIndex) +
", valInd: " + toString(opt.trValueIndex) + ")");
}

if (Options::get().statediff)
importer.traceStateDiff();
Expand Down
2 changes: 0 additions & 2 deletions test/unittests/libethereum/BlockChainInsert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,6 @@ void syncStateTrie(bytesConstRef _block, OverlayDB const& _dbSource, OverlayDB&
BOOST_AUTO_TEST_CASE(bcBasicInsert)
{
BasicAuthority::init();
BasicAuthority::init();

KeyPair me = Secret(sha3("Gav Wood"));
KeyPair myMiner = Secret(sha3("Gav's Miner"));

Expand Down