Browse Source

Various fixes.

Initial portion of NatSpec integration.
cl-refactor
Gav Wood 10 years ago
parent
commit
8491e5f2f7
  1. 2
      alethzero/MainWin.cpp
  2. 2
      alethzero/MainWin.h
  3. 40
      alethzero/OurWebThreeStubServer.cpp
  4. 4
      alethzero/OurWebThreeStubServer.h
  5. 2
      eth/main.cpp
  6. 4
      libdevcrypto/CryptoPP.cpp
  7. 8
      libethereum/EthereumPeer.cpp
  8. 2
      libethereum/Executive.cpp
  9. 2
      libethereum/Executive.h
  10. 7
      libethereum/State.cpp
  11. 4
      libethereum/State.h
  12. 22
      libweb3jsonrpc/WebThreeStubServer.cpp
  13. 6
      libweb3jsonrpc/WebThreeStubServer.h
  14. 2
      mix/AssemblyDebuggerModel.cpp

2
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();
}

2
alethzero/MainWin.h

@ -78,6 +78,8 @@ public:
dev::eth::Client* ethereum() const { return m_webThree->ethereum(); }
std::shared_ptr<dev::shh::WhisperHost> 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<dev::KeyPair> owned() const { return m_myIdentities + m_myKeys; }
public slots:

40
alethzero/OurWebThreeStubServer.cpp

@ -20,12 +20,16 @@
*/
#include "OurWebThreeStubServer.h"
#include <QMessageBox>
#include <libwebthree/WebThree.h>
#include "MainWin.h"
using namespace std;
using namespace dev;
using namespace dev::eth;
OurWebThreeStubServer::OurWebThreeStubServer(jsonrpc::AbstractServerConnector& _conn, dev::WebThreeDirect& _web3, std::vector<dev::KeyPair> 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;
}

4
alethzero/OurWebThreeStubServer.h

@ -32,7 +32,11 @@ public:
OurWebThreeStubServer(jsonrpc::AbstractServerConnector& _conn, dev::WebThreeDirect& _web3, std::vector<dev::KeyPair> 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;
};

2
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)
{

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

8
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.

2
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.

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

7
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)

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

22
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<u256>(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())

6
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<dev::KeyPair> const& _ids);
std::map<dev::Public, dev::Secret> const& ids() const { return m_ids; }
protected:
virtual bool authenticate(dev::TransactionSkeleton const& _t) const;
private:
dev::eth::Interface* client() const;
std::shared_ptr<dev::shh::Interface> face() const;
dev::WebThreeDirect& m_web3;
std::map<dev::Address, dev::KeyPair> m_accounts;
ldb::ReadOptions m_readOptions;
ldb::WriteOptions m_writeOptions;
ldb::DB* m_db;

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

Loading…
Cancel
Save