Browse Source

Merge pull request #344 from arkpar/develop

Fixed RLPs being constructed for deallocated memory
cl-refactor
Gav Wood 10 years ago
parent
commit
aa75354c31
  1. 11
      alethzero/MainWin.cpp
  2. 3
      libdevcore/RLP.h
  3. 20
      libdevcrypto/TrieDB.h
  4. 9
      libethereum/BlockChain.cpp
  5. 4
      libethereum/Client.cpp
  6. 20
      test/crypto.cpp

11
alethzero/MainWin.cpp

@ -107,10 +107,11 @@ Main::Main(QWidget *parent) :
#endif
m_servers.append(QString::fromStdString(Host::pocHost() + ":30303"));
cerr << "State root: " << BlockChain::genesis().stateRoot << endl;
cerr << "Block Hash: " << sha3(BlockChain::createGenesisBlock()) << endl;
cerr << "Block RLP: " << RLP(BlockChain::createGenesisBlock()) << endl;
cerr << "Block Hex: " << toHex(BlockChain::createGenesisBlock()) << endl;
cerr << "State root: " << BlockChain::genesis().stateRoot << endl;
cerr << "Block Hash: " << sha3(BlockChain::createGenesisBlock()) << endl;
auto block = BlockChain::createGenesisBlock();
cerr << "Block RLP: " << RLP(block) << endl;
cerr << "Block Hex: " << toHex(BlockChain::createGenesisBlock()) << endl;
cerr << "Network protocol version: " << dev::eth::c_protocolVersion << endl;
cerr << "Client database version: " << dev::eth::c_databaseVersion << endl;
@ -462,7 +463,7 @@ QString Main::lookup(QString const& _a) const
void Main::on_about_triggered()
{
QMessageBox::about(this, "About AlethZero PoC-" + QString(dev::Version).section('.', 1, 1), QString("AlethZero/v") + dev::Version + "/" DEV_QUOTED(ETH_BUILD_TYPE) "/" DEV_QUOTED(ETH_BUILD_PLATFORM) "\n" DEV_QUOTED(ETH_COMMIT_HASH) + (ETH_CLEAN_REPO ? "\nCLEAN" : "\n+ LOCAL CHANGES") + "\n\nBy Gav Wood, 2014.\nThis software wouldn't be where it is today without the many leaders & contributors including:\n\nVitalik Buterin, Tim Hughes, caktux, Nick Savers, Eric Lombrozo, Marko Simovic, the many testers and the Berlin \304\220\316\236V team.");
QMessageBox::about(this, "About AlethZero PoC-" + QString(dev::Version).section('.', 1, 1), QString("AlethZero/v") + dev::Version + "/" DEV_QUOTED(ETH_BUILD_TYPE) "/" DEV_QUOTED(ETH_BUILD_PLATFORM) "\n" DEV_QUOTED(ETH_COMMIT_HASH) + (ETH_CLEAN_REPO ? "\nCLEAN" : "\n+ LOCAL CHANGES") + "\n\nBy Gav Wood, 2014.\nBased on a design by Vitalik Buterin.\n\nThanks to the various contributors including: Alex Leverington, Tim Hughes, caktux, Eric Lombrozo, Marko Simovic.");
}
void Main::on_paranoia_triggered()

3
libdevcore/RLP.h

@ -288,6 +288,9 @@ public:
unsigned actualSize() const;
private:
/// Disable construction from rvalue
explicit RLP(bytes const&& _d) {}
/// Single-byte data payload.
bool isSingleByte() const { return !isNull() && m_data[0] < c_rlpDataImmLenStart; }

20
libdevcrypto/TrieDB.h

@ -553,11 +553,17 @@ template <class DB> bytes GenericTrieDB<DB>::mergeAt(RLP const& _orig, NibbleSli
auto sh = _k.shared(k);
// std::cout << _k << " sh " << k << " = " << sh << std::endl;
if (sh)
{
// shared stuff - cleve at disagreement.
return mergeAt(RLP(cleve(_orig, sh)), _k, _v, true);
auto cleved = cleve(_orig, sh);
return mergeAt(RLP(cleved), _k, _v, true);
}
else
{
// nothing shared - branch
return mergeAt(RLP(branch(_orig)), _k, _v, true);
auto branched = branch(_orig);
return mergeAt(RLP(branched), _k, _v, true);
}
}
else
{
@ -686,7 +692,10 @@ template <class DB> bytes GenericTrieDB<DB>::deleteAt(RLP const& _orig, NibbleSl
byte used = uniqueInUse(_orig, 16);
if (used != 255)
if (isTwoItemNode(_orig[used]))
return graft(RLP(merge(_orig, used)));
{
auto merged = merge(_orig, used);
return graft(RLP(merged));
}
else
return merge(_orig, used);
else
@ -722,7 +731,10 @@ template <class DB> bytes GenericTrieDB<DB>::deleteAt(RLP const& _orig, NibbleSl
// yes; merge
if (isTwoItemNode(rlp[used]))
return graft(RLP(merge(rlp, used)));
{
auto merged = merge(rlp, used);
return graft(RLP(merged));
}
else
return merge(rlp, used);
}

9
libethereum/BlockChain.cpp

@ -277,8 +277,10 @@ h256s BlockChain::import(bytes const& _block, OverlayDB const& _db)
auto pd = details(bi.parentHash);
if (!pd)
{
cwarn << "Odd: details is returning false despite block known:" << RLP(pd.rlp());
cwarn << "Block:" << RLP(block(bi.parentHash));
auto pdata = pd.rlp();
cwarn << "Odd: details is returning false despite block known:" << RLP(pdata);
auto parentBlock = block(bi.parentHash);
cwarn << "Block:" << RLP(parentBlock);
}
// Check it's not crazy
@ -447,7 +449,8 @@ h256Set BlockChain::allUnclesFrom(h256 _parent) const
for (unsigned i = 0; i < 6 && p != m_genesisHash; ++i, p = details(p).parent)
{
ret.insert(p); // TODO: check: should this be details(p).parent?
for (auto i: RLP(block(p))[2])
auto b = block(p);
for (auto i: RLP(b)[2])
ret.insert(sha3(i.data()));
}
return ret;

4
libethereum/Client.cpp

@ -36,7 +36,9 @@ using namespace p2p;
VersionChecker::VersionChecker(string const& _dbPath):
m_path(_dbPath.size() ? _dbPath : Defaults::dbPath())
{
m_ok = RLP(contents(m_path + "/protocol")).toInt<unsigned>(RLP::LaisezFaire) == c_protocolVersion && RLP(contents(m_path + "/database")).toInt<unsigned>(RLP::LaisezFaire) == c_databaseVersion;
auto protocolContents = contents(m_path + "/protocol");
auto databaseContents = contents(m_path + "/database");
m_ok = RLP(protocolContents).toInt<unsigned>(RLP::LaisezFaire) == c_protocolVersion && RLP(databaseContents).toInt<unsigned>(RLP::LaisezFaire) == c_databaseVersion;
}
void VersionChecker::setOk()

20
test/crypto.cpp

@ -46,12 +46,14 @@ BOOST_AUTO_TEST_CASE(crypto_tests)
t.nonce = 0;
t.receiveAddress = h160(fromHex("944400f4b88ac9589a0f17ed4671da26bddb668b"));
t.value = 1000;
cnote << RLP(t.rlp(false));
cnote << toHex(t.rlp(false));
auto rlp = t.rlp(false);
cnote << RLP(rlp);
cnote << toHex(rlp);
cnote << t.sha3(false);
t.sign(p.secret());
cnote << RLP(t.rlp(true));
cnote << toHex(t.rlp(true));
rlp = t.rlp(true);
cnote << RLP(rlp);
cnote << toHex(rlp);
cnote << t.sha3(true);
BOOST_REQUIRE(t.sender() == p.address());
}
@ -72,12 +74,14 @@ int cryptoTest()
t.nonce = 0;
t.receiveAddress = h160(fromHex("944400f4b88ac9589a0f17ed4671da26bddb668b"));
t.value = 1000;
cnote << RLP(t.rlp(false));
cnote << toHex(t.rlp(false));
auto rlp = t.rlp(false);
cnote << RLP(rlp);
cnote << toHex(rlp);
cnote << t.sha3(false);
t.sign(p.secret());
cnote << RLP(t.rlp(true));
cnote << toHex(t.rlp(true));
rlp = t.rlp(true);
cnote << RLP(rlp);
cnote << toHex(rlp);
cnote << t.sha3(true);
assert(t.sender() == p.address());
}

Loading…
Cancel
Save