Browse Source

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

cl-refactor
arkpar 10 years ago
parent
commit
33d45574ff
  1. 2
      evmjit
  2. 2
      libethcore/CommonEth.cpp
  3. 11
      libethcore/Exceptions.cpp
  4. 2
      libethereum/BlockChain.cpp
  5. 4
      libethereum/BlockChain.h
  6. 8
      libethereum/Precompiled.cpp
  7. 2
      libethereum/TransactionReceipt.cpp
  8. 3
      libethereum/TransactionReceipt.h
  9. 12
      libevm/VM.h
  10. 4
      libevmcore/Instruction.cpp
  11. 2
      libevmcore/Instruction.h
  12. 2
      libserpent/opcodes.cpp
  13. 6
      libsolidity/ExpressionCompiler.cpp
  14. 2
      libsolidity/SourceReferenceFormatter.h
  15. 4
      test/stSystemOperationsTestFiller.json
  16. 65
      test/trie.cpp
  17. 2392
      test/vmArithmeticTestFiller.json

2
evmjit

@ -1 +1 @@
Subproject commit 66d5a2b5cdf1361dcf0205b191dd12be090ed224
Subproject commit 3df5a125fa0baa579528abce80402118cad803fd

2
libethcore/CommonEth.cpp

@ -32,7 +32,7 @@ namespace dev
namespace eth
{
const unsigned c_protocolVersion = 49;
const unsigned c_protocolVersion = 51;
const unsigned c_databaseVersion = 5;
static const vector<pair<u256, string>> g_units =

11
libethcore/Exceptions.cpp

@ -20,13 +20,22 @@
*/
#include "Exceptions.h"
#include <boost/thread.hpp>
#include <libdevcore/CommonIO.h>
using namespace std;
using namespace dev;
using namespace dev::eth;
#define ETH_RETURN_STRING(S) static string s_what; s_what = S; return s_what.c_str();
#if ALL_COMPILERS_ARE_CPP11_COMPLIANT
#define ETH_RETURN_STRING(S) thread_local static string s_what; s_what = S; return s_what.c_str();
#else
#define ETH_RETURN_STRING(S) \
static boost::thread_specific_ptr<string> s_what; \
if (!s_what.get()) \
s_what.reset(new string); \
*s_what = S; return s_what->c_str();
#endif
const char* InvalidBlockFormat::what() const noexcept { ETH_RETURN_STRING("Invalid block format: Bad field " + toString(m_f) + " (" + toHex(m_d) + ")"); }
const char* UncleInChain::what() const noexcept { ETH_RETURN_STRING("Uncle in block already mentioned: Uncles " + toString(m_uncles) + " (" + m_block.abridged() + ")"); }

2
libethereum/BlockChain.cpp

@ -71,7 +71,7 @@ std::map<Address, Account> const& dev::eth::genesisState()
return s_ret;
}
BlockInfo* BlockChain::s_genesis = nullptr;
std::unique_ptr<BlockInfo> BlockChain::s_genesis;
boost::shared_mutex BlockChain::x_genesis;
ldb::Slice dev::eth::toSlice(h256 _h, unsigned _sub)

4
libethereum/BlockChain.h

@ -132,7 +132,7 @@ public:
h256Set allUnclesFrom(h256 _parent) const;
/// @returns the genesis block header.
static BlockInfo const& genesis() { UpgradableGuard l(x_genesis); if (!s_genesis) { auto gb = createGenesisBlock(); UpgradeGuard ul(l); (s_genesis = new BlockInfo)->populate(&gb); } return *s_genesis; }
static BlockInfo const& genesis() { UpgradableGuard l(x_genesis); if (!s_genesis) { auto gb = createGenesisBlock(); UpgradeGuard ul(l); s_genesis.reset(new BlockInfo); s_genesis->populate(&gb); } return *s_genesis; }
/// @returns the genesis block as its RLP-encoded byte array.
/// @note This is slow as it's constructed anew each call. Consider genesis() instead.
@ -211,7 +211,7 @@ private:
/// Static genesis info and its lock.
static boost::shared_mutex x_genesis;
static BlockInfo* s_genesis;
static std::unique_ptr<BlockInfo> s_genesis;
};
std::ostream& operator<<(std::ostream& _out, BlockChain const& _bc);

8
libethereum/Precompiled.cpp

@ -75,11 +75,17 @@ static bytes ripemd160Code(bytesConstRef _in)
return ret;
}
static bytes identityCode(bytesConstRef _in)
{
return _in.toBytes();
}
static const std::map<unsigned, PrecompiledAddress> c_precompiled =
{
{ 1, { [](bytesConstRef) -> bigint { return (bigint)500; }, ecrecoverCode }},
{ 2, { [](bytesConstRef i) -> bigint { return (bigint)50 + (i.size() + 31) / 32 * 50; }, sha256Code }},
{ 3, { [](bytesConstRef i) -> bigint { return (bigint)50 + (i.size() + 31) / 32 * 50; }, ripemd160Code }}
{ 3, { [](bytesConstRef i) -> bigint { return (bigint)50 + (i.size() + 31) / 32 * 50; }, ripemd160Code }},
{ 4, { [](bytesConstRef i) -> bigint { return (bigint)1 + (i.size() + 31) / 32 * 1; }, identityCode }}
};
std::map<unsigned, PrecompiledAddress> const& dev::eth::precompiled()

2
libethereum/TransactionReceipt.cpp

@ -50,7 +50,7 @@ void TransactionReceipt::streamRLP(RLPStream& _s) const
l.streamRLP(_s);
}
std::ostream& dev::operator<<(std::ostream& _out, TransactionReceipt const& _r)
std::ostream& dev::eth::operator<<(std::ostream& _out, TransactionReceipt const& _r)
{
_out << "Root: " << _r.stateRoot() << std::endl;
_out << "Gas used: " << _r.gasUsed() << std::endl;

3
libethereum/TransactionReceipt.h

@ -57,8 +57,7 @@ private:
using TransactionReceipts = std::vector<TransactionReceipt>;
}
std::ostream& operator<<(std::ostream& _out, eth::TransactionReceipt const& _r);
}
}

12
libevm/VM.h

@ -219,9 +219,8 @@ inline bytesConstRef VM::go(ExtVMFace& _ext, OnOpFunc const& _onOp, uint64_t _st
break;
}
case Instruction::PREVHASH:
if (c_protocolVersion > 49)
require(1);
case Instruction::BLOCKHASH:
require(1);
break;
case Instruction::PC:
@ -563,11 +562,8 @@ inline bytesConstRef VM::go(ExtVMFace& _ext, OnOpFunc const& _onOp, uint64_t _st
case Instruction::GASPRICE:
m_stack.push_back(_ext.gasPrice);
break;
case Instruction::PREVHASH:
if (c_protocolVersion > 49)
m_stack.back() = (u256)_ext.prevhash(m_stack.back());
else
m_stack.push_back(_ext.previousBlock.hash);
case Instruction::BLOCKHASH:
m_stack.back() = (u256)_ext.prevhash(m_stack.back());
break;
case Instruction::COINBASE:
m_stack.push_back((u160)_ext.currentBlock.coinbaseAddress);

4
libevmcore/Instruction.cpp

@ -67,7 +67,7 @@ const std::map<std::string, Instruction> dev::eth::c_instructions =
{ "GASPRICE", Instruction::GASPRICE },
{ "EXTCODESIZE", Instruction::EXTCODESIZE },
{ "EXTCODECOPY", Instruction::EXTCODECOPY },
{ "PREVHASH", Instruction::PREVHASH },
{ "BLOCKHASH", Instruction::BLOCKHASH },
{ "COINBASE", Instruction::COINBASE },
{ "TIMESTAMP", Instruction::TIMESTAMP },
{ "NUMBER", Instruction::NUMBER },
@ -200,7 +200,7 @@ static const std::map<Instruction, InstructionInfo> c_instructionInfo =
{ Instruction::GASPRICE, { "GASPRICE", 0, 0, 1, false } },
{ Instruction::EXTCODESIZE, { "EXTCODESIZE", 0, 1, 1, false } },
{ Instruction::EXTCODECOPY, { "EXTCODECOPY", 0, 4, 0, true } },
{ Instruction::PREVHASH, { "PREVHASH", 0, 0, 1, false } },
{ Instruction::BLOCKHASH, { "BLOCKHASH", 0, 1, 1, false } },
{ Instruction::COINBASE, { "COINBASE", 0, 0, 1, false } },
{ Instruction::TIMESTAMP, { "TIMESTAMP", 0, 0, 1, false } },
{ Instruction::NUMBER, { "NUMBER", 0, 0, 1, false } },

2
libevmcore/Instruction.h

@ -73,7 +73,7 @@ enum class Instruction: uint8_t
EXTCODESIZE, ///< get external code size (from another contract)
EXTCODECOPY, ///< copy external code (from another contract)
PREVHASH = 0x40, ///< get hash of most recent complete block
BLOCKHASH = 0x40, ///< get hash of most recent complete block
COINBASE, ///< get the block's coinbase address
TIMESTAMP, ///< get the block's timestamp
NUMBER, ///< get the block's number

2
libserpent/opcodes.cpp

@ -44,7 +44,7 @@ Mapping mapping[] = {
Mapping("GASPRICE", 0x3a, 0, 1),
Mapping("EXTCODESIZE", 0x3b, 1, 1),
Mapping("EXTCODECOPY", 0x3c, 4, 0),
Mapping("PREVHASH", 0x40, 0, 1),
Mapping("BLOCKHASH", 0x40, 1, 1),
Mapping("COINBASE", 0x41, 0, 1),
Mapping("TIMESTAMP", 0x42, 0, 1),
Mapping("NUMBER", 0x43, 0, 1),

6
libsolidity/ExpressionCompiler.cpp

@ -344,9 +344,9 @@ void ExpressionCompiler::endVisit(MemberAccess const& _memberAccess)
m_context << eth::Instruction::COINBASE;
else if (member == "timestamp")
m_context << eth::Instruction::TIMESTAMP;
else if (member == "prevhash")
m_context << eth::Instruction::PREVHASH;
else if (member == "difficulty")
/* else if (member == "blockhash")
m_context << eth::Instruction::BLOCKHASH;
*/ else if (member == "difficulty")
m_context << eth::Instruction::DIFFICULTY;
else if (member == "number")
m_context << eth::Instruction::NUMBER;

2
libsolidity/SourceReferenceFormatter.h

@ -28,7 +28,7 @@
namespace dev
{
class Exception; // forward
struct Exception; // forward
namespace solidity
{

4
test/stSystemOperationsTestFiller.json

@ -740,7 +740,7 @@
"transaction" : {
"nonce" : "0",
"gasPrice" : "1",
"gasLimit" : "365223",
"gasLimit" : "365243",
"to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87",
"value" : "100000",
"secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8",
@ -774,7 +774,7 @@
"transaction" : {
"nonce" : "0",
"gasPrice" : "1",
"gasLimit" : "365224",
"gasLimit" : "365244",
"to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87",
"value" : "100000",
"secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8",

65
test/trie.cpp

@ -50,7 +50,7 @@ static unsigned fac(unsigned _i)
BOOST_AUTO_TEST_SUITE(TrieTests)
BOOST_AUTO_TEST_CASE(trie_tests)
BOOST_AUTO_TEST_CASE(trie_test_anyorder)
{
string testPath = test::getTestPath();
@ -92,6 +92,69 @@ BOOST_AUTO_TEST_CASE(trie_tests)
}
}
BOOST_AUTO_TEST_CASE(trie_tests_ordered)
{
string testPath = test::getTestPath();
testPath += "/TrieTests";
cnote << "Testing Trie...";
js::mValue v;
string s = asString(contents(testPath + "/trietest.json"));
BOOST_REQUIRE_MESSAGE(s.length() > 0, "Contents of 'trietest.json' is empty. Have you cloned the 'tests' repo branch develop?");
js::read_string(s, v);
for (auto& i: v.get_obj())
{
cnote << i.first;
js::mObject& o = i.second.get_obj();
vector<pair<string, string>> ss;
vector<string> keysToBeDeleted;
for (auto& i: o["in"].get_array())
{
vector<string> values;
for (auto& s: i.get_array())
{
if (s.type() == json_spirit::str_type)
values.push_back(s.get_str());
else if (s.type() == json_spirit::null_type)
{
// mark entry for deletion
values.push_back("");
if (!values[0].find("0x"))
values[0] = asString(fromHex(values[0].substr(2)));
keysToBeDeleted.push_back(values[0]);
}
else
BOOST_FAIL("Bad type (expected string)");
}
BOOST_REQUIRE(values.size() == 2);
ss.push_back(make_pair(values[0], values[1]));
if (!ss.back().first.find("0x"))
ss.back().first = asString(fromHex(ss.back().first.substr(2)));
if (!ss.back().second.find("0x"))
ss.back().second = asString(fromHex(ss.back().second.substr(2)));
}
MemoryDB m;
GenericTrieDB<MemoryDB> t(&m);
t.init();
BOOST_REQUIRE(t.check(true));
for (auto const& k: ss)
{
if (find(keysToBeDeleted.begin(), keysToBeDeleted.end(), k.first) != keysToBeDeleted.end() && k.second.empty())
t.remove(k.first);
else
t.insert(k.first, k.second);
BOOST_REQUIRE(t.check(true));
}
BOOST_REQUIRE(!o["root"].is_null());
BOOST_CHECK_EQUAL(o["root"].get_str(), "0x" + toHex(t.root().asArray()));
}
}
inline h256 stringMapHash256(StringMap const& _s)
{
return hash256(_s);

2392
test/vmArithmeticTestFiller.json

File diff suppressed because it is too large
Loading…
Cancel
Save