diff --git a/alethzero/MainWin.cpp b/alethzero/MainWin.cpp index ff5208034..ff04428ae 100644 --- a/alethzero/MainWin.cpp +++ b/alethzero/MainWin.cpp @@ -199,9 +199,7 @@ Main::Main(QWidget *parent) : } #endif - cnote << "State root: " << BlockInfo::genesis().stateRoot; - cnote << "Genesis hash:" << sha3(BlockInfo::createGenesisBlock()); - cnote << "Genesis RLP:" << toHex(BlockInfo::createGenesisBlock()); + cerr << "State root: " << BlockInfo::genesis().stateRoot << endl << "Block Hash: " << sha3(BlockInfo::createGenesisBlock()) << endl << "Block RLP: " << RLP(BlockInfo::createGenesisBlock()) << endl << "Block Hex: " << toHex(BlockInfo::createGenesisBlock()) << endl; ui->configDock->close(); diff --git a/libethcore/RLP.h b/libethcore/RLP.h index e41ffd92a..769ef770c 100644 --- a/libethcore/RLP.h +++ b/libethcore/RLP.h @@ -278,7 +278,7 @@ public: RLPStream& append(bytes const& _s) { return append(bytesConstRef(&_s)); } RLPStream& append(std::string const& _s) { return append(bytesConstRef(_s)); } RLPStream& append(char const* _s) { return append(std::string(_s)); } - template RLPStream& append(FixedHash _s, bool _compact = false) { return append(_s.ref(), _compact); } + template RLPStream& append(FixedHash _s, bool _compact = false, bool _allOrNothing = false) { return _allOrNothing && !_s ? append(bytesConstRef()) : append(_s.ref(), _compact); } /// Appends an arbitrary RLP fragment - this *must* be a single item. RLPStream& append(RLP const& _rlp, uint _itemCount = 1) { return appendRaw(_rlp.data(), _itemCount); } diff --git a/libethereum/BlockInfo.cpp b/libethereum/BlockInfo.cpp index d3a369c67..2c3a28b8b 100644 --- a/libethereum/BlockInfo.cpp +++ b/libethereum/BlockInfo.cpp @@ -61,7 +61,8 @@ bytes BlockInfo::createGenesisBlock() stateRoot = state.root(); } - block.appendList(13) << h256() << sha3EmptyList << h160() << stateRoot << h256() << c_genesisDifficulty << 0 << 0 << 1000000 << 0 << (uint)0 << string() << sha3(bytes(1, 42)); + block.appendList(13) << h256() << sha3EmptyList << h160(); + block.append(stateRoot, false, true) << bytes() << c_genesisDifficulty << 0 << 0 << 1000000 << 0 << (uint)0 << string() << sha3(bytes(1, 42)); block.appendRaw(RLPEmptyList); block.appendRaw(RLPEmptyList); return block.out(); @@ -76,7 +77,9 @@ h256 BlockInfo::headerHashWithoutNonce() const void BlockInfo::fillStream(RLPStream& _s, bool _nonce) const { - _s.appendList(_nonce ? 13 : 12) << parentHash << sha3Uncles << coinbaseAddress << stateRoot << transactionsRoot << difficulty << number << minGasPrice << gasLimit << gasUsed << timestamp << extraData; + _s.appendList(_nonce ? 13 : 12) << parentHash << sha3Uncles << coinbaseAddress; + _s.append(stateRoot, false, true).append(transactionsRoot, false, true); + _s << difficulty << number << minGasPrice << gasLimit << gasUsed << timestamp << extraData; if (_nonce) _s << nonce; } diff --git a/libethereum/State.cpp b/libethereum/State.cpp index 12ad7b6e5..36a75064a 100644 --- a/libethereum/State.cpp +++ b/libethereum/State.cpp @@ -43,12 +43,18 @@ std::map const& eth::genesisState() if (s_ret.empty()) { // Initialise. - s_ret[Address(fromHex("8a40bfaa73256b60764c1bf40675a99083efb075"))] = AddressState(u256(1) << 200, 0, h256(), EmptySHA3); - s_ret[Address(fromHex("e6716f9544a56c530d868e4bfbacb172315bdead"))] = AddressState(u256(1) << 200, 0, h256(), EmptySHA3); - s_ret[Address(fromHex("1e12515ce3e0f817a4ddef9ca55788a1d66bd2df"))] = AddressState(u256(1) << 200, 0, h256(), EmptySHA3); - s_ret[Address(fromHex("1a26338f0d905e295fccb71fa9ea849ffa12aaf4"))] = AddressState(u256(1) << 200, 0, h256(), EmptySHA3); - s_ret[Address(fromHex("2ef47100e0787b915105fd5e3f4ff6752079d5cb"))] = AddressState(u256(1) << 200, 0, h256(), EmptySHA3); - s_ret[Address(fromHex("cd2a3d9f938e13cd947ec05abc7fe734df8dd826"))] = AddressState(u256(1) << 200, 0, h256(), EmptySHA3); + for (auto i: vector({ + "8a40bfaa73256b60764c1bf40675a99083efb075", + "e6716f9544a56c530d868e4bfbacb172315bdead", + "1e12515ce3e0f817a4ddef9ca55788a1d66bd2df", + "1a26338f0d905e295fccb71fa9ea849ffa12aaf4", + "2ef47100e0787b915105fd5e3f4ff6752079d5cb", + "cd2a3d9f938e13cd947ec05abc7fe734df8dd826", + "6c386a4b26f73c802f34673f7248bb118f97424a", + "e4157b34ea9615cfbde6b4fda419828124b70c78" + })) + s_ret[Address(fromHex(i))] = AddressState(u256(1) << 200, 0, h256(), EmptySHA3); + } return s_ret; } @@ -484,7 +490,7 @@ u256 State::playbackRaw(bytesConstRef _block, BlockInfo const& _grandParent, boo // cnote << m_state.root() << m_state; // cnote << *this; execute(tr[0].data()); - if (tr[1].toInt() != m_state.root()) + if (tr[1].toHash() != m_state.root()) { // Invalid state root cnote << m_state.root() << "\n" << m_state; diff --git a/libethereum/State.h b/libethereum/State.h index a2f12dc7f..59e2c1a74 100644 --- a/libethereum/State.h +++ b/libethereum/State.h @@ -55,7 +55,7 @@ struct TransactionReceipt { _s.appendList(3); transaction.fillStream(_s); - _s << stateRoot << gasUsed; + _s.append(stateRoot, false, true) << gasUsed; } Transaction transaction; @@ -341,7 +341,7 @@ void commit(std::map const& _cache, DB& _db, TrieDB storageDB(&_db, i.second.oldRoot()); @@ -350,7 +350,7 @@ void commit(std::map const& _cache, DB& _db, TrieDB