Browse Source

Merge branch 'develop' of github.com:ethereum/cpp-ethereum into develop

cl-refactor
Vitalik Buterin 10 years ago
parent
commit
aa733fbfaa
  1. 3
      alethzero/Main.ui
  2. 4
      alethzero/MainWin.cpp
  3. 12
      libethcore/All.h
  4. 4
      libethcore/TrieDB.h
  5. 8
      libethential/All.h
  6. 2
      libethential/CMakeLists.txt
  7. 14
      libethereum/All.h
  8. 30
      libethereum/Client.h
  9. 39
      libethereum/ExtVM.h
  10. 5
      libevm/All.h
  11. 10
      libevm/ExtVMFace.h
  12. 7
      liblll/All.h
  13. 5
      liblll/Assembly.cpp
  14. 2
      liblll/Assembly.h
  15. 39
      liblll/CodeFragment.cpp
  16. 7
      liblll/CodeFragment.h
  17. 4
      liblll/Compiler.cpp
  18. 3
      liblll/CompilerState.cpp
  19. 1
      liblll/CompilerState.h
  20. 4
      libpyserpent/pyserpent.cpp
  21. 9
      libserpent/All.h
  22. 2
      sc/cmdline.cpp

3
alethzero/Main.ui

@ -1288,7 +1288,8 @@ font-size: 14pt</string>
<property name="styleSheet">
<string notr="true">background: white;
border: 0;
font-family: Monospace, Ubuntu Mono, Lucida Console, Courier New</string>
font-family: Monospace, Ubuntu Mono, Lucida Console, Courier New;
font-size: 12pt</string>
</property>
<property name="inputMask">
<string/>

4
alethzero/MainWin.cpp

@ -118,7 +118,7 @@ Main::Main(QWidget *parent) :
connect(ui->ourAccounts->model(), SIGNAL(rowsMoved(const QModelIndex &, int, int, const QModelIndex &, int)), SLOT(ourAccountsRowsMoved()));
#if ETH_DEBUG
#if 0&&ETH_DEBUG
m_servers.append("192.168.0.10:30301");
#else
int pocnumber = QString(eth::EthVersion).section('.', 1, 1).toInt();
@ -985,7 +985,7 @@ void Main::on_data_textChanged()
{
try
{
m_data = eth::asBytes(compile(src));
m_data = compile(src);
for (auto& i: errors)
i = "(LLL " + i + ")";
}

12
libethcore/All.h

@ -0,0 +1,12 @@
#pragma once
#include "BlockInfo.h"
#include "CommonEth.h"
#include "Dagger.h"
#include "FileSystem.h"
#include "MemoryDB.h"
#include "OverlayDB.h"
#include "SHA3.h"
#include "TrieCommon.h"
#include "TrieDB.h"
#include "UPnP.h"

4
libethcore/TrieDB.h

@ -42,7 +42,7 @@ extern const h256 c_shaNull;
/**
* @brief Merkle Patricia Tree "Trie": a modifed base-16 Radix tree.
* This version uses an LDB backend
* This version uses an database backend.
* Usage:
* @code
* GenericTrieDB<MyDB> t(&myDB);
@ -153,6 +153,7 @@ public:
std::string at(bytesConstRef _key) const;
void insert(bytesConstRef _key, bytesConstRef _value);
void remove(bytesConstRef _key);
void contains(bytesConstRef _key) { return !at(_key).empty(); }
class iterator
{
@ -274,6 +275,7 @@ public:
std::string operator[](KeyType _k) const { return at(_k); }
bool contains(KeyType _k) const { return GenericTrieDB<DB>::contains(bytesConstRef((byte const*)&_k, sizeof(KeyType))); }
std::string at(KeyType _k) const { return GenericTrieDB<DB>::at(bytesConstRef((byte const*)&_k, sizeof(KeyType))); }
void insert(KeyType _k, bytesConstRef _value) { GenericTrieDB<DB>::insert(bytesConstRef((byte const*)&_k, sizeof(KeyType)), _value); }
void insert(KeyType _k, bytes const& _value) { insert(_k, bytesConstRef(&_value)); }

8
libethential/All.h

@ -0,0 +1,8 @@
#pragma once
#include "Common.h"
#include "CommonData.h"
#include "CommonIO.h"
#include "FixedHash.h"
#include "Log.h"
#include "RLP.h"

2
libethential/CMakeLists.txt

@ -1,4 +1,5 @@
cmake_policy(SET CMP0015 NEW)
cmake_policy(SET CMP0022 NEW)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DSTATICLIB")
@ -16,7 +17,6 @@ include_directories(..)
target_link_libraries(${EXECUTABLE} ethential)
target_link_libraries(${EXECUTABLE} gmp)
if(${TARGET_PLATFORM} STREQUAL "w64")
include_directories(/usr/x86_64-w64-mingw32/include/cryptopp)
target_link_libraries(${EXECUTABLE} boost_thread_win32-mt-s)

14
libethereum/All.h

@ -0,0 +1,14 @@
#pragma once
#include "AddressState.h"
#include "BlockChain.h"
#include "Client.h"
#include "Defaults.h"
#include "Executive.h"
#include "ExtVM.h"
#include "PeerNetwork.h"
#include "PeerServer.h"
#include "PeerSession.h"
#include "State.h"
#include "Transaction.h"
#include "TransactionQueue.h"

30
libethereum/Client.h

@ -77,6 +77,9 @@ private:
unsigned m_protocolVersion;
};
/**
* @brief Main API hub for interfacing with Ethereum.
*/
class Client
{
public:
@ -114,24 +117,37 @@ public:
/// Calls @a _f when a transaction is mined that involves @a _dest and once per change.
// void onConfirmed(Address _dest, function<void(Transaction, AddressState)> const& _f);
// Informational stuff:
/// Locks/unlocks the state/blockChain/transactionQueue for access.
void lock();
void unlock();
// Informational stuff
/// Determines whether at least one of the state/blockChain/transactionQueue has changed since the last call to changed().
bool changed() const { auto ret = m_changed; m_changed = false; return ret; }
bool peekChanged() const { return m_changed; }
/// Get a map containing each of the pending transactions.
Transactions pending() const { return m_postMine.pending(); }
// [OLD API]:
/// Locks/unlocks the state/blockChain/transactionQueue for access.
void lock();
void unlock();
/// Get the object representing the current state of Ethereum.
State const& state() const { return m_preMine; }
/// Get the object representing the current state of Ethereum.
State const& postState() const { return m_postMine; }
/// Get the object representing the current canonical blockchain.
BlockChain const& blockChain() const { return m_bc; }
/// Get a map containing each of the pending transactions.
Transactions pending() const { return m_postMine.pending(); }
// [NEW API]
u256 balanceAt(Address _a, int _block = -1) const;
u256 countAt(Address _a, int _block = -1) const;
u256 stateAt(Address _a, u256 _l, int _block = -1) const;
bytes codeAt(Address _a, int _block = -1) const;
Transactions transactions(Addresses const& _from, Addresses const& _to, std::vector<std::pair<u256, u256>> const& _stateAlterations, Addresses const& _altered, int _blockFrom = 0, int _blockTo = -1, unsigned _max = 10) const;
// Misc stuff:
void setClientVersion(std::string const& _name) { m_clientVersion = _name; }

39
libethereum/ExtVM.h

@ -29,56 +29,61 @@
namespace eth
{
// TODO: Document
/**
* @brief Externalality interface for the Virtual Machine providing access to world state.
*/
class ExtVM: public ExtVMFace
{
public:
/// Full constructor.
ExtVM(State& _s, Address _myAddress, Address _caller, Address _origin, u256 _value, u256 _gasPrice, bytesConstRef _data, bytesConstRef _code):
ExtVMFace(_myAddress, _caller, _origin, _value, _gasPrice, _data, _code, _s.m_previousBlock, _s.m_currentBlock), m_s(_s), m_origCache(_s.m_cache)
{
m_s.ensureCached(_myAddress, true, true);
}
u256 store(u256 _n)
{
return m_s.storage(myAddress, _n);
}
void setStore(u256 _n, u256 _v)
{
m_s.setStorage(myAddress, _n, _v);
}
/// Read storage location.
u256 store(u256 _n) { return m_s.storage(myAddress, _n); }
/// Write a value in storage.
void setStore(u256 _n, u256 _v) { m_s.setStorage(myAddress, _n, _v); }
/// Create a new contract.
h160 create(u256 _endowment, u256* _gas, bytesConstRef _code)
{
// Increment associated nonce for sender.
m_s.noteSending(myAddress);
return m_s.create(myAddress, _endowment, gasPrice, _gas, _code, origin);
}
/// Create a new message call.
bool call(Address _receiveAddress, u256 _txValue, bytesConstRef _txData, u256* _gas, bytesRef _out)
{
return m_s.call(_receiveAddress, myAddress, _txValue, gasPrice, _txData, _gas, _out, origin);
}
/// Read address's balance.
u256 balance(Address _a) { return m_s.balance(_a); }
/// Subtract amount from account's balance.
void subBalance(u256 _a) { m_s.subBalance(myAddress, _a); }
/// Determine account's TX count.
u256 txCount(Address _a) { return m_s.transactionsFrom(_a); }
/// Suicide the associated contract to the given address.
void suicide(Address _a)
{
m_s.addBalance(_a, m_s.balance(myAddress));
m_s.m_cache[myAddress].kill();
}
void revert()
{
m_s.m_cache = m_origCache;
}
/// Revert any changes made (by any of the other calls).
void revert() { m_s.m_cache = m_origCache; }
private:
State& m_s;
std::map<Address, AddressState> m_origCache;
std::map<u256, u256>* m_store;
State& m_s; ///< A reference to the base state.
std::map<Address, AddressState> m_origCache; ///< The cache of the address states (i.e. the externalities) as-was prior to the execution.
};
}

5
libevm/All.h

@ -0,0 +1,5 @@
#pragma once
#include "ExtVMFace.h"
#include "FeeStructure.h"
#include "VM.h"

10
libevm/ExtVMFace.h

@ -40,7 +40,6 @@ public:
/// Full constructor.
ExtVMFace(Address _myAddress, Address _caller, Address _origin, u256 _value, u256 _gasPrice, bytesConstRef _data, bytesConstRef _code, BlockInfo const& _previousBlock, BlockInfo const& _currentBlock);
/// Get the code at the given location in code ROM.
byte getCode(u256 _n) const { return _n < code.size() ? code[(unsigned)_n] : 0; }
@ -53,21 +52,24 @@ public:
/// Read address's balance.
u256 balance(Address) { return 0; }
/// Subtract amount from address's balance.
/// Subtract amount from account's balance.
void subBalance(u256) {}
/// Determine address's TX count.
/// Determine account's TX count.
u256 txCount(Address) { return 0; }
/// Suicide the associated contract to the given address.
void suicide(Address) {}
/// Create a new contract.
/// Create a new (contract) account.
h160 create(u256, u256*, bytesConstRef, bytesConstRef) { return h160(); }
/// Make a new message call.
bool call(Address, u256, bytesConstRef, u256*, bytesRef) { return false; }
/// Revert any changes made (by any of the other calls).
void revert() {}
Address myAddress; ///< Address associated with executing code (a contract, or contract-to-be).
Address caller; ///< Address which sent the message (either equal to origin or a contract).
Address origin; ///< Original transactor.

7
liblll/All.h

@ -0,0 +1,7 @@
#pragma once
#include "Assembly.h"
#include "CodeFragment.h"
#include "Compiler.h"
#include "CompilerState.h"
#include "Parser.h"

5
liblll/Assembly.cpp

@ -176,6 +176,11 @@ AssemblyItem const& Assembly::append(AssemblyItem const& _i)
return back();
}
void Assembly::injectStart(AssemblyItem const& _i)
{
m_items.insert(m_items.begin(), _i);
}
inline bool matches(AssemblyItemsConstRef _a, AssemblyItemsConstRef _b)
{
if (_a.size() != _b.size())

2
liblll/Assembly.h

@ -98,6 +98,8 @@ public:
void popTo(int _deposit) { while (m_deposit > _deposit) append(Instruction::POP); }
void injectStart(AssemblyItem const& _i);
std::string out() const { std::stringstream ret; streamOut(ret); return ret.str(); }
int deposit() const { return m_deposit; }
bytes assemble() const;

39
liblll/CodeFragment.cpp

@ -19,7 +19,6 @@
* @date 2014
*/
#include "Parser.h"
#include "CodeFragment.h"
#include <boost/algorithm/string.hpp>
@ -27,12 +26,30 @@
#include <libethential/Log.h>
#include <libevmface/Instruction.h>
#include "CompilerState.h"
#include "Parser.h"
using namespace std;
using namespace eth;
namespace qi = boost::spirit::qi;
namespace px = boost::phoenix;
namespace sp = boost::spirit;
void CodeFragment::finalise(CompilerState const& _cs)
{
if (_cs.usedAlloc && _cs.vars.size() && !m_finalised)
{
m_finalised = true;
m_asm.injectStart(Instruction::MSTORE8);
m_asm.injectStart((u256)((_cs.vars.size() + 2) * 32) - 1);
m_asm.injectStart((u256)1);
}
}
bytes CodeFragment::code(CompilerState const& _cs)
{
finalise(_cs);
return m_asm.assemble();
}
CodeFragment::CodeFragment(sp::utree const& _t, CompilerState& _s, bool _allowASM)
{
/* cdebug << "CodeFragment. Locals:";
@ -317,6 +334,7 @@ void CodeFragment::constructOperation(sp::utree const& _t, CompilerState& _s)
vector<CodeFragment> code;
CompilerState ns = _s;
ns.vars.clear();
ns.usedAlloc = false;
int c = _t.tag() ? 1 : 0;
for (auto const& i: _t)
if (c++)
@ -456,13 +474,30 @@ void CodeFragment::constructOperation(sp::utree const& _t, CompilerState& _s)
m_asm.appendJump(begin);
m_asm << end.tag();
}
else if (us == "ALLOC")
{
requireSize(1);
requireDeposit(0, 1);
m_asm.append(Instruction::MEMSIZE);
m_asm.append(u256(0));
m_asm.append(u256(1));
m_asm.append(code[0].m_asm, 1);
m_asm.append(Instruction::MEMSIZE);
m_asm.append(Instruction::ADD);
m_asm.append(Instruction::SUB);
m_asm.append(Instruction::MSTORE8);
_s.usedAlloc = true;
}
else if (us == "LLL")
{
requireMinSize(2);
requireMaxSize(3);
requireDeposit(1, 1);
bytes const& subcode = code[0].code();
code[0].optimise();
bytes subcode = code[0].code(ns);
m_asm.append((u256)subcode.size());
m_asm.append(Instruction::DUP);

7
liblll/CodeFragment.h

@ -43,18 +43,21 @@ public:
static CodeFragment compile(std::string const& _src, CompilerState& _s);
/// Consolidates data and compiles code.
bytes code() const { return m_asm.assemble(); }
bytes code(CompilerState const& _cs);
/// Consolidates data and compiles code.
std::string assembly() const { return m_asm.out(); }
std::string assembly(CompilerState const& _cs) { finalise(_cs); return m_asm.out(); }
/// Optimise the code. Best do this just before calling code() or assembly().
void optimise() { m_asm.optimise(); }
private:
void finalise(CompilerState const& _cs);
template <class T> void error() const { throw T(); }
void constructOperation(sp::utree const& _t, CompilerState& _s);
bool m_finalised = false;
Assembly m_asm;
};

4
liblll/Compiler.cpp

@ -36,7 +36,7 @@ bytes eth::compileLLL(string const& _src, bool _opt, vector<string>* _errors)
auto f = CodeFragment::compile(_src, cs);
if (_opt)
f.optimise();
bytes ret = f.code();
bytes ret = f.code(cs);
for (auto i: cs.treesToKill)
killBigints(i);
return ret;
@ -63,7 +63,7 @@ std::string eth::compileLLLToAsm(std::string const& _src, bool _opt, std::vector
auto f = CodeFragment::compile(_src, cs);
if (_opt)
f.optimise();
string ret = f.assembly();
string ret = f.assembly(cs);
for (auto i: cs.treesToKill)
killBigints(i);
return ret;

3
liblll/CompilerState.cpp

@ -52,8 +52,7 @@ void CompilerState::populateStandard()
"(def 'regname (name) { [0]:name (call (- (gas) 21) namereg 0 0 32 0 0) })"
"(def 'send (to value) (call (- (gas) 21) to value 0 0 0 0))"
"(def 'send (gaslimit to value) (call gaslimit to value 0 0 0 0))"
"(def 'alloc (len) (asm msize 0 1 len msize add sub mstore8))"
"(def 'msg (gaslimit to value data datasize outsize) { [32]:outsize [0]:(alloc @32) (call gaslimit to value data datasize @0 @32) @0 })"
"(def 'msg (gaslimit to value data datasize outsize) { (set x outsize) (set y (alloc @32)) (call gaslimit to value data datasize @0 @32) @0 })"
"(def 'msg (gaslimit to value data datasize) { (call gaslimit to value data datasize 0 32) @0 })"
"(def 'msg (gaslimit to value data) { [0]:data (msg gaslimit to value 0 32) })"
"(def 'msg (to value data) { [0]:data (msg 0 to value 0 32) })"

1
liblll/CompilerState.h

@ -48,6 +48,7 @@ struct CompilerState
std::map<std::string, CodeFragment> outers;
std::map<std::pair<std::string, unsigned>, Macro> macros;
std::vector<boost::spirit::utree> treesToKill;
bool usedAlloc = false;
};
}

4
libpyserpent/pyserpent.cpp

@ -18,8 +18,8 @@ struct VecToList
for(size_t i = 0; i < vec.size(); i++)
(*l).append(vec[i]);
return l->ptr();
}
return l->ptr();
}
};
// python list to std::vector converter

9
libserpent/All.h

@ -0,0 +1,9 @@
#pragma once
#include "compiler.h"
#include "funcs.h"
#include "lllparser.h"
#include "parser.h"
#include "rewriter.h"
#include "tokenize.h"
#include "util.h"

2
sc/cmdline.cpp

@ -10,7 +10,7 @@ int main(int argv, char** argc) {
if (argv == 1) {
std::cerr << "Must provide a command and arguments! Try parse, rewrite, compile, assemble\n";
return 0;
}
}
std::string flag = "";
std::string command = argc[1];
std::string input;

Loading…
Cancel
Save