From 607e380a4b4241ef283a1f9f0b8f59567a81a852 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Tue, 11 Feb 2014 17:43:37 +0000 Subject: [PATCH] Fixes for Go interop. --- CMakeLists.txt | 2 +- alethzero/MainWin.cpp | 2 +- libethereum/BlockChain.cpp | 10 +++++++++- libethereum/BlockInfo.cpp | 2 +- libethereum/Common.cpp | 2 ++ libethereum/Common.h | 2 +- libethereum/Exceptions.h | 2 +- libethereum/PeerNetwork.cpp | 4 ++-- libethereum/State.cpp | 2 +- libethereum/Transaction.cpp | 2 ++ test/crypto.cpp | 24 ++++++++++++++++++++++++ test/main.cpp | 8 ++++---- 12 files changed, 49 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a6514301d..a999f25e8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,7 @@ set(CMAKE_AUTOMOC ON) cmake_policy(SET CMP0015 NEW) -set(ETH_VERSION 0.2.2) +set(ETH_VERSION 0.2.3) set(ETH_BUILD_TYPE ${CMAKE_BUILD_TYPE}) set(TARGET_PLATFORM CACHE STRING "linux") diff --git a/alethzero/MainWin.cpp b/alethzero/MainWin.cpp index af5cf1bc7..c99acebba 100644 --- a/alethzero/MainWin.cpp +++ b/alethzero/MainWin.cpp @@ -64,7 +64,7 @@ Main::~Main() void Main::on_about_triggered() { - QMessageBox::about(this, "About AlethZero PoC-2", "AlethZero/v" ADD_QUOTES(ETH_VERSION) "/" ADD_QUOTES(ETH_BUILD_TYPE) "/" ADD_QUOTES(ETH_BUILD_PLATFORM) "\nBy Gav Wood, 2014.\nBased on a design by Vitalik Buterin.\n\nTeam Ethereum++ includes: Eric Lombrozo, Marko Simovic, Subtly and several others."); + QMessageBox::about(this, "About AlethZero PoC-2", "AlethZero/v" ADD_QUOTES(ETH_VERSION) "/" ADD_QUOTES(ETH_BUILD_TYPE) "/" ADD_QUOTES(ETH_BUILD_PLATFORM) "\nBy Gav Wood, 2014.\nBased on a design by Vitalik Buterin.\n\nTeam Ethereum++ includes: Eric Lombrozo, Marko Simovic, Alex Leverington and several others."); } void Main::writeSettings() diff --git a/libethereum/BlockChain.cpp b/libethereum/BlockChain.cpp index 00ebf0697..6b9e0715c 100644 --- a/libethereum/BlockChain.cpp +++ b/libethereum/BlockChain.cpp @@ -120,7 +120,15 @@ void BlockChain::import(bytes const& _block, Overlay const& _db) { // VERIFY: populates from the block and checks the block is internally coherent. BlockInfo bi(&_block); - bi.verifyInternals(&_block); + try + { + bi.verifyInternals(&_block); + } + catch (Exception const& _e) + { + clog(BlockChainNote) << " Malformed block (" << _e.description() << ")."; + throw; + } auto newHash = eth::sha3(_block); diff --git a/libethereum/BlockInfo.cpp b/libethereum/BlockInfo.cpp index 520b2c202..9b97f250e 100644 --- a/libethereum/BlockInfo.cpp +++ b/libethereum/BlockInfo.cpp @@ -131,7 +131,7 @@ void BlockInfo::verifyInternals(bytesConstRef _block) const RLP root(_block); if (sha3Transactions != sha3(root[1].data())) - throw InvalidTransactionsHash(); + throw InvalidTransactionsHash(sha3Transactions, sha3(root[1].data())); if (sha3Uncles != sha3(root[2].data())) throw InvalidUnclesHash(); diff --git a/libethereum/Common.cpp b/libethereum/Common.cpp index 2041b25bd..ad5d491f4 100644 --- a/libethereum/Common.cpp +++ b/libethereum/Common.cpp @@ -38,6 +38,8 @@ using namespace std; using namespace eth; +#define ETH_ADDRESS_DEBUG 1 + // Logging int eth::g_logVerbosity = 8; map eth::g_logOverride; diff --git a/libethereum/Common.h b/libethereum/Common.h index d066dc193..90d920ddb 100644 --- a/libethereum/Common.h +++ b/libethereum/Common.h @@ -366,7 +366,7 @@ uint commonPrefix(_T const& _t, _U const& _u) inline h160 right160(h256 const& _t) { h160 ret; - memcpy(ret.data(), _t.data() + 10, 20); + memcpy(ret.data(), _t.data() + 12, 20); return ret; } diff --git a/libethereum/Exceptions.h b/libethereum/Exceptions.h index d777386b6..023362554 100644 --- a/libethereum/Exceptions.h +++ b/libethereum/Exceptions.h @@ -29,7 +29,7 @@ class InvalidBlockHeaderFormat: public Exception { public: InvalidBlockHeaderFor class InvalidUnclesHash: public Exception {}; class InvalidUncle: public Exception {}; class InvalidStateRoot: public Exception {}; -class InvalidTransactionsHash: public Exception {}; +class InvalidTransactionsHash: public Exception { public: InvalidTransactionsHash(h256 _head, h256 _real): m_head(_head), m_real(_real) {} h256 m_head; h256 m_real; virtual std::string description() const { return "Invalid transactions hash: header says: " + asHex(m_head.ref()) + " block is:" + asHex(m_real.ref()); } }; class InvalidTransaction: public Exception {}; class InvalidDifficulty: public Exception {}; class InvalidTimestamp: public Exception {}; diff --git a/libethereum/PeerNetwork.cpp b/libethereum/PeerNetwork.cpp index f7d12bf68..66d74a8df 100644 --- a/libethereum/PeerNetwork.cpp +++ b/libethereum/PeerNetwork.cpp @@ -43,7 +43,7 @@ using namespace eth; #define clogS(X) eth::LogOutputStream(false) << "| " << std::setw(2) << m_socket.native_handle() << "] " -static const int c_protocolVersion = 3; +static const int c_protocolVersion = 4; static const eth::uint c_maxHashes = 256; ///< Maximum number of hashes GetChain will ever send. static const eth::uint c_maxBlocks = 128; ///< Maximum number of blocks Blocks will ever send. BUG: if this gets too big (e.g. 2048) stuff starts going wrong. @@ -304,13 +304,13 @@ bool PeerSession::interpret(RLP const& _r) { if (m_server->m_mode == NodeMode::PeerServer) break; + clogS(NetMessageSummary) << "GetChain (" << (_r.itemCount() - 2) << " hashes, " << (_r[_r.itemCount() - 1].toInt()) << ")"; // ******************************************************************** // NEEDS FULL REWRITE! h256s parents; parents.reserve(_r.itemCount() - 2); for (unsigned i = 1; i < _r.itemCount() - 1; ++i) parents.push_back(_r[i].toHash()); - clogS(NetMessageSummary) << "GetChain (" << (_r.itemCount() - 2) << " hashes, " << (_r[_r.itemCount() - 1].toInt()) << ")"; if (_r.itemCount() == 2) break; // return 2048 block max. diff --git a/libethereum/State.cpp b/libethereum/State.cpp index 0c27baca1..44b51ed15 100644 --- a/libethereum/State.cpp +++ b/libethereum/State.cpp @@ -62,7 +62,7 @@ std::map const& eth::genesisState() if (s_ret.empty()) { // Initialise. - s_ret[Address(fromUserHex("07598a40bfaa73256b60764c1bf40675a99083ef"))] = AddressState(u256(1) << 200, 0); + s_ret[Address(fromUserHex("8a40bfaa73256b60764c1bf40675a99083efb075"))] = AddressState(u256(1) << 200, 0); s_ret[Address(fromUserHex("93658b04240e4bd4046fd2d6d417d20f146f4b43"))] = AddressState(u256(1) << 200, 0); s_ret[Address(fromUserHex("1e12515ce3e0f817a4ddef9ca55788a1d66bd2df"))] = AddressState(u256(1) << 200, 0); s_ret[Address(fromUserHex("80c01a26338f0d905e295fccb71fa9ea849ffa12"))] = AddressState(u256(1) << 200, 0); diff --git a/libethereum/Transaction.cpp b/libethereum/Transaction.cpp index 4044eccf2..9e0ecd976 100644 --- a/libethereum/Transaction.cpp +++ b/libethereum/Transaction.cpp @@ -26,6 +26,8 @@ using namespace std; using namespace eth; +#define ETH_ADDRESS_DEBUG 0 + Transaction::Transaction(bytesConstRef _rlpData) { RLP rlp(_rlpData); diff --git a/test/crypto.cpp b/test/crypto.cpp index 215d772ee..83a735c70 100644 --- a/test/crypto.cpp +++ b/test/crypto.cpp @@ -30,6 +30,29 @@ using namespace eth; int cryptoTest() { + secp256k1_start(); + + KeyPair p(Secret(fromUserHex("3ecb44df2159c26e0f995712d4f39b6f6e499b40749b1cf1246c37f9516cb6a4"))); + assert(p.pub() == Public(fromUserHex("97466f2b32bc3bb76d4741ae51cd1d8578b48d3f1e68da206d47321aec267ce78549b514e4453d74ef11b0cd5e4e4c364effddac8b51bcfc8de80682f952896f"))); + assert(p.address() == Address(fromUserHex("8a40bfaa73256b60764c1bf40675a99083efb075"))); + { + Transaction t; + t.nonce = 0; + t.receiveAddress = h160(fromUserHex("944400f4b88ac9589a0f17ed4671da26bddb668b")); + t.value = 1000; + t.data = u256s(); + cnote << RLP(t.rlp(false)); + cnote << asHex(t.rlp(false)); + cnote << t.sha3(false); + t.sign(p.secret()); + cnote << RLP(t.rlp(true)); + cnote << asHex(t.rlp(true)); + cnote << t.sha3(true); + assert(t.sender() == p.address()); + } + + +#if 0 // Test transaction. bytes tx = fromUserHex("88005401010101010101010101010101010101010101011f0de0b6b3a76400001ce8d4a5100080181c373130a009ba1f10285d4e659568bfcfec85067855c5a3c150100815dad4ef98fd37cf0593828c89db94bd6c64e210a32ef8956eaa81ea9307194996a3b879441f5d"); cout << "TX: " << RLP(tx) << endl; @@ -94,6 +117,7 @@ int cryptoTest() cout << "RECPUB: " << dec << ret << " " << pubkeylen << " " << asHex(pubkey) << endl; cout << "SENDER: " << hex << low160(eth::sha3(bytesConstRef(&pubkey).cropped(1))) << dec << endl; } +#endif return 0; } diff --git a/test/main.cpp b/test/main.cpp index 14af62b8f..9caaaa14c 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -41,11 +41,11 @@ int main(int argc, char** argv) std::cout << asHex(s.out()) << std::endl; std::cout << sha3(s.out()) << std::endl;*/ - hexPrefixTest(); - rlpTest(); - trieTest(); +// hexPrefixTest(); +// rlpTest(); +// trieTest(); // daggerTest(); -// cryptoTest(); + cryptoTest(); // stateTest(); // peerTest(argc, argv); return 0;