diff --git a/alethzero/MainWin.cpp b/alethzero/MainWin.cpp index dbcd0f493..b73a2cd0d 100644 --- a/alethzero/MainWin.cpp +++ b/alethzero/MainWin.cpp @@ -1475,7 +1475,7 @@ void Main::populateDebugger(dev::bytesConstRef _r) m_history.append(WorldState({steps, ext.myAddress, vm.curPC(), inst, newMemSize, vm.gas(), lastHash, lastDataHash, vm.stack(), vm.memory(), gasCost, ext.state().storage(ext.myAddress), levels})); }; m_currentExecution->go(onOp); - m_currentExecution->finalize(onOp); + m_currentExecution->finalize(); initDebugger(); updateDebugger(); } diff --git a/alethzero/MainWin.h b/alethzero/MainWin.h index 5c196792d..ed5d275eb 100644 --- a/alethzero/MainWin.h +++ b/alethzero/MainWin.h @@ -78,6 +78,8 @@ public: dev::eth::Client* ethereum() const { return m_webThree->ethereum(); } std::shared_ptr whisper() const { return m_webThree->whisper(); } + std::string lookupNatSpec(dev::h256 const& _contractCode) const { (void)_contractCode; return ""; } // TODO: actually implement with leveldb & a UI. + QList owned() const { return m_myIdentities + m_myKeys; } public slots: diff --git a/alethzero/OurWebThreeStubServer.cpp b/alethzero/OurWebThreeStubServer.cpp index 0c6f42b5a..0d840e8d4 100644 --- a/alethzero/OurWebThreeStubServer.cpp +++ b/alethzero/OurWebThreeStubServer.cpp @@ -20,12 +20,16 @@ */ #include "OurWebThreeStubServer.h" + +#include +#include +#include "MainWin.h" using namespace std; using namespace dev; using namespace dev::eth; OurWebThreeStubServer::OurWebThreeStubServer(jsonrpc::AbstractServerConnector& _conn, dev::WebThreeDirect& _web3, std::vector const& _accounts): - WebThreeStubServer(_conn, _web3, _accounts) + WebThreeStubServer(_conn, _web3, _accounts), m_web3(&_web3) {} std::string OurWebThreeStubServer::shh_newIdentity() @@ -34,3 +38,37 @@ std::string OurWebThreeStubServer::shh_newIdentity() emit onNewId(QString::fromStdString(toJS(kp.sec()))); return toJS(kp.pub()); } + +bool OurWebThreeStubServer::authenticate(dev::TransactionSkeleton const& _t) const +{ + return true; + + // To get the balance of the sender + cnote << "Sender has ETH: " << m_web3->ethereum()->postState().balance(_t.from); + + Main* main; // don't know this yet, should be a member and set at construction time by Main, who will construct us. + + h256 contractCodeHash = m_web3->ethereum()->postState().codeHash(_t.to); + + if (contractCodeHash == EmptySHA3) + { + // recipient has no code - nothing special about this transaction. + // TODO: show basic message for value transfer. + return true; // or whatever. + } + + std::string natspecJson = main->lookupNatSpec(contractCodeHash); + + if (natspecJson.empty()) + { + // TODO: HUGE warning - we don't know what this will do! + return false; // or whatever. + } + + // otherwise it's a transaction to contract for which we have the natspec: + // determine the actual message (embellish with real data) and ask user. + +// QMessageBox::question(); + + return true; +} diff --git a/alethzero/OurWebThreeStubServer.h b/alethzero/OurWebThreeStubServer.h index fb026d07e..9ff973371 100644 --- a/alethzero/OurWebThreeStubServer.h +++ b/alethzero/OurWebThreeStubServer.h @@ -32,7 +32,11 @@ public: OurWebThreeStubServer(jsonrpc::AbstractServerConnector& _conn, dev::WebThreeDirect& _web3, std::vector const& _accounts); virtual std::string shh_newIdentity() override; + virtual bool authenticate(dev::TransactionSkeleton const& _t) const; signals: void onNewId(QString _s); + +private: + dev::WebThreeDirect* m_web3; }; diff --git a/eth/main.cpp b/eth/main.cpp index d55766cfd..c6435235e 100644 --- a/eth/main.cpp +++ b/eth/main.cpp @@ -672,7 +672,7 @@ int main(int argc, char** argv) f << ext->myAddress << " " << hex << toHex(dev::toCompactBigEndian(vm->curPC(), 1)) << " " << hex << toHex(dev::toCompactBigEndian((int)(byte)instr, 1)) << " " << hex << toHex(dev::toCompactBigEndian((uint64_t)vm->gas(), 1)) << endl; }; e.go(oof); - e.finalize(oof); + e.finalize(); } catch(Exception const& _e) { diff --git a/libdevcrypto/CryptoPP.cpp b/libdevcrypto/CryptoPP.cpp index 766ca485d..d73e3fa43 100644 --- a/libdevcrypto/CryptoPP.cpp +++ b/libdevcrypto/CryptoPP.cpp @@ -108,7 +108,7 @@ Signature Secp256k1::sign(Secret const& _key, h256 const& _hash) Integer kInv = k.InverseMod(m_q); Integer z(_hash.asBytes().data(), 32); - Integer s = (kInv * (Integer(_key.asBytes().data(), 32)*r + z)) % m_q; + Integer s = (kInv * (Integer(_key.asBytes().data(), 32) * r + z)) % m_q; if (r == 0 || s == 0) BOOST_THROW_EXCEPTION(InvalidState()); @@ -144,7 +144,7 @@ Public Secp256k1::recover(Signature _signature, bytesConstRef _message) Integer s(_signature.data()+32, 32); // cryptopp encodes sign of y as 0x02/0x03 instead of 0/1 or 27/28 byte encodedpoint[33]; - encodedpoint[0] = _signature[64]|2; + encodedpoint[0] = _signature[64] | 2; memcpy(&encodedpoint[1], _signature.data(), 32); ECP::Element x; diff --git a/libethereum/EthereumPeer.cpp b/libethereum/EthereumPeer.cpp index b204546d4..0901766bf 100644 --- a/libethereum/EthereumPeer.cpp +++ b/libethereum/EthereumPeer.cpp @@ -317,14 +317,6 @@ bool EthereumPeer::interpret(unsigned _id, RLP const& _r) disable("Blacklisted client version."); else if (host()->isBanned(session()->id())) disable("Peer banned for previous bad behaviour."); - else - { - // Grab transactions off them. - RLPStream s; - prep(s, GetTransactionsPacket); - sealAndSend(s); - transition(Asking::Nothing); - } break; } case GetTransactionsPacket: break; // DEPRECATED. diff --git a/libethereum/Executive.cpp b/libethereum/Executive.cpp index 965d6f0af..f79bb4a3b 100644 --- a/libethereum/Executive.cpp +++ b/libethereum/Executive.cpp @@ -220,7 +220,7 @@ bool Executive::go(OnOpFunc const& _onOp) return true; } -void Executive::finalize(OnOpFunc const&) +void Executive::finalize() { // SSTORE refunds... // must be done before the miner gets the fees. diff --git a/libethereum/Executive.h b/libethereum/Executive.h index 5a97e5f87..d743e3746 100644 --- a/libethereum/Executive.h +++ b/libethereum/Executive.h @@ -64,7 +64,7 @@ public: bool setup(bytesConstRef _transaction); /// Finalise a transaction previously set up with setup(). /// @warning Only valid after setup(), and possibly go(). - void finalize(OnOpFunc const& _onOp = OnOpFunc()); + void finalize(); /// @returns the transaction from setup(). /// @warning Only valid after setup(). Transaction const& t() const { return m_t; } diff --git a/libethereum/State.cpp b/libethereum/State.cpp index dfd65c713..c6a6ce125 100644 --- a/libethereum/State.cpp +++ b/libethereum/State.cpp @@ -958,6 +958,13 @@ bytes const& State::code(Address _contract) const return m_cache[_contract].code(); } +h256 State::codeHash(Address _contract) const +{ + if (!addressHasCode(_contract)) + return EmptySHA3; + return m_cache[_contract].codeHash(); +} + bool State::isTrieGood(bool _enforceRefs, bool _requireNoLeftOvers) const { for (int e = 0; e < (_enforceRefs ? 2 : 1); ++e) diff --git a/libethereum/State.h b/libethereum/State.h index 0473893c4..921c82bb9 100644 --- a/libethereum/State.h +++ b/libethereum/State.h @@ -201,6 +201,10 @@ public: /// @returns bytes() if no account exists at that address. bytes const& code(Address _contract) const; + /// Get the code hash of an account. + /// @returns EmptySHA3 if no account exists at that address or if there is no code associated with the address. + h256 codeHash(Address _contract) const; + /// Note that the given address is sending a transaction and thus increment the associated ticker. void noteSending(Address _id); diff --git a/libweb3jsonrpc/WebThreeStubServer.cpp b/libweb3jsonrpc/WebThreeStubServer.cpp index d88aa0a5f..8dc95b8c2 100644 --- a/libweb3jsonrpc/WebThreeStubServer.cpp +++ b/libweb3jsonrpc/WebThreeStubServer.cpp @@ -677,16 +677,24 @@ std::string WebThreeStubServer::eth_transact(Json::Value const& _json) t.gasPrice = 10 * dev::eth::szabo; if (!t.gas) t.gas = min(client()->gasLimitRemaining(), client()->balanceAt(t.from) / t.gasPrice); - cwarn << "Silently signing transaction from address" << t.from.abridged() << ": User validation hook goes here."; - if (t.to) - // TODO: from qethereum, insert validification hook here. - client()->transact(m_accounts[t.from].secret(), t.value, t.to, t.data, t.gas, t.gasPrice); - else - ret = toJS(client()->transact(m_accounts[t.from].secret(), t.value, t.data, t.gas, t.gasPrice)); - client()->flushTransactions(); + if (authenticate(t)) + { + if (t.to) + // TODO: from qethereum, insert validification hook here. + client()->transact(m_accounts[t.from].secret(), t.value, t.to, t.data, t.gas, t.gasPrice); + else + ret = toJS(client()->transact(m_accounts[t.from].secret(), t.value, t.data, t.gas, t.gasPrice)); + client()->flushTransactions(); + } return ret; } +bool WebThreeStubServer::authenticate(TransactionSkeleton const& _t) const +{ + cwarn << "Silently signing transaction from address" << _t.from.abridged() << ": User validation hook goes here."; + return true; +} + Json::Value WebThreeStubServer::eth_transactionByHash(std::string const& _hash, int const& _i) { if (!client()) diff --git a/libweb3jsonrpc/WebThreeStubServer.h b/libweb3jsonrpc/WebThreeStubServer.h index 6d54c59ef..0f81fce9d 100644 --- a/libweb3jsonrpc/WebThreeStubServer.h +++ b/libweb3jsonrpc/WebThreeStubServer.h @@ -42,6 +42,7 @@ namespace dev { class WebThreeDirect; class KeyPair; +class TransactionSkeleton; namespace eth { class Interface; @@ -119,12 +120,15 @@ public: void setIdentities(std::vector const& _ids); std::map const& ids() const { return m_ids; } +protected: + virtual bool authenticate(dev::TransactionSkeleton const& _t) const; + private: dev::eth::Interface* client() const; std::shared_ptr face() const; dev::WebThreeDirect& m_web3; std::map m_accounts; - + ldb::ReadOptions m_readOptions; ldb::WriteOptions m_writeOptions; ldb::DB* m_db; diff --git a/mix/AssemblyDebuggerModel.cpp b/mix/AssemblyDebuggerModel.cpp index 354d0bd1e..3967b09af 100644 --- a/mix/AssemblyDebuggerModel.cpp +++ b/mix/AssemblyDebuggerModel.cpp @@ -73,7 +73,7 @@ DebuggingContent AssemblyDebuggerModel::executeTransaction(bytesConstRef const& }; m_currentExecution->go(onOp); - m_currentExecution->finalize(onOp); + m_currentExecution->finalize(); m_executiveState.completeMine(); DebuggingContent d;