Browse Source

New PoC-5 stuff for zero hashes.

cl-refactor
Gav Wood 11 years ago
parent
commit
8dd065bb45
  1. 4
      alethzero/MainWin.cpp
  2. 2
      libethcore/RLP.h
  3. 7
      libethereum/BlockInfo.cpp
  4. 20
      libethereum/State.cpp
  5. 6
      libethereum/State.h
  6. 3
      libethereum/Transaction.h

4
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();

2
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 <unsigned N> RLPStream& append(FixedHash<N> _s, bool _compact = false) { return append(_s.ref(), _compact); }
template <unsigned N> RLPStream& append(FixedHash<N> _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); }

7
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;
}

20
libethereum/State.cpp

@ -43,12 +43,18 @@ std::map<Address, AddressState> 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<string>({
"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<u256>() != m_state.root())
if (tr[1].toHash<h256>() != m_state.root())
{
// Invalid state root
cnote << m_state.root() << "\n" << m_state;

6
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<Address, AddressState> const& _cache, DB& _db, TrieDB<Addre
s << i.second.balance() << i.second.nonce();
if (i.second.storage().empty())
s << i.second.oldRoot();
s.append(i.second.oldRoot(), false, true);
else
{
TrieDB<h256, DB> storageDB(&_db, i.second.oldRoot());
@ -350,7 +350,7 @@ void commit(std::map<Address, AddressState> const& _cache, DB& _db, TrieDB<Addre
storageDB.insert(j.first, rlp(j.second));
else
storageDB.remove(j.first);
s << storageDB.root();
s.append(storageDB.root(), false, true);
}
if (i.second.isFreshCode())

3
libethereum/Transaction.h

@ -34,9 +34,6 @@ struct Signature
u256 s;
};
// [ nonce, value, receiveAddress, gasPrice, gasDeposit, data, v, r, s ]
// or
// [ nonce, endowment, 0, gasPrice, gasDeposit (for init), body, init, v, r, s ]
struct Transaction
{
Transaction() {}

Loading…
Cancel
Save