Browse Source

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

cl-refactor
Gav Wood 10 years ago
parent
commit
1fc3520559
  1. 16
      libevm/VM.h
  2. 2
      liblll/Assembly.cpp
  3. 2
      libsolidity/Parser.cpp
  4. 2
      test/solidityParser.cpp
  5. 37
      test/vm.cpp
  6. 29
      test/vm.h

16
libevm/VM.h

@ -448,16 +448,18 @@ template <class Ext> dev::bytesConstRef dev::eth::VM::go(Ext& _ext, OnOpFunc con
m_stack.pop_back();
break;
case Instruction::SIGNEXTEND:
if (m_stack.back() < 31)
{
unsigned k = m_stack.back();
unsigned const testBit(m_stack.back() * 8 + 7);
u256& number = m_stack[m_stack.size() - 2];
u256 mask = ((u256(1) << testBit) - 1);
if (boost::multiprecision::bit_test(number, testBit))
number |= ~mask;
else
number &= mask;
}
m_stack.pop_back();
auto& b = m_stack.back();
if (k <= 31)
if ((b >> (k * 8)) & 0x80)
for (int i = 31; i > k; --i)
b |= (u256(0xff) << i);
break;
}
case Instruction::SHA3:
{
unsigned inOff = (unsigned)m_stack.back();

2
liblll/Assembly.cpp

@ -54,6 +54,7 @@ unsigned Assembly::bytesRequired() const
switch (i.m_type)
{
case Operation:
case Tag: // 1 byte for the JUMPDEST
ret++;
break;
case PushString:
@ -69,7 +70,6 @@ unsigned Assembly::bytesRequired() const
case PushData:
case PushSub:
ret += 1 + br;
case Tag:;
default:;
}
if (dev::bytesRequired(ret) <= br)

2
libsolidity/Parser.cpp

@ -266,9 +266,11 @@ ASTPointer<Statement> Parser::parseStatement()
// starting from here, all statements must be terminated by a semicolon
case Token::CONTINUE:
statement = ASTNodeFactory(*this).createNode<Continue>();
m_scanner->next();
break;
case Token::BREAK:
statement = ASTNodeFactory(*this).createNode<Break>();
m_scanner->next();
break;
case Token::RETURN:
{

2
test/solidityParser.cpp

@ -185,7 +185,7 @@ BOOST_AUTO_TEST_CASE(while_loop)
{
char const* text = "contract test {\n"
" function fun(uint256 a) {\n"
" uint256 x = (1 + 4).member(++67) || true;\n"
" while (true) { uint256 x = 1; break; continue; } x = 9;\n"
" }\n"
"}\n";
BOOST_CHECK_NO_THROW(parseText(text));

37
test/vm.cpp

@ -130,7 +130,7 @@ bool FakeExtVM::call(Address _receiveAddress, u256 _value, bytesConstRef _data,
m_ms.internal.resize(m_ms.internal.size() + 1);
auto ret = m_s.call(_receiveAddress,_codeAddressOverride ? _codeAddressOverride : _receiveAddress, _myAddressOverride ? _myAddressOverride : myAddress, _value, gasPrice, _data, _gas, _out, origin, &sub, &(m_ms.internal.back()), simpleTrace<ExtVM>(), 1);
auto ret = m_s.call(_receiveAddress,_codeAddressOverride ? _codeAddressOverride : _receiveAddress, _myAddressOverride ? _myAddressOverride : myAddress, _value, gasPrice, _data, _gas, _out, origin, &sub, &(m_ms.internal.back()), Executive::simpleTrace(), 1);
if (!m_ms.internal.back().from)
m_ms.internal.pop_back();
@ -421,6 +421,39 @@ void FakeExtVM::importCallCreates(mArray& _callcreates)
}
}
eth::OnOpFunc FakeExtVM::simpleTrace()
{
return [](uint64_t steps, eth::Instruction inst, bigint newMemSize, bigint gasCost, void* voidVM, void const* voidExt)
{
FakeExtVM const& ext = *(FakeExtVM const*)voidExt;
eth::VM& vm = *(eth::VM*)voidVM;
std::ostringstream o;
o << std::endl << " STACK" << std::endl;
for (auto i: vm.stack())
o << (h256)i << std::endl;
o << " MEMORY" << std::endl << memDump(vm.memory());
o << " STORAGE" << std::endl;
for (auto const& i: ext.state().storage(ext.myAddress))
o << std::showbase << std::hex << i.first << ": " << i.second << std::endl;
for (auto const& i: std::get<2>(ext.addresses.find(ext.myAddress)->second))
o << std::showbase << std::hex << i.first << ": " << i.second << std::endl;
dev::LogOutputStream<eth::VMTraceChannel, false>(true) << o.str();
dev::LogOutputStream<eth::VMTraceChannel, false>(false) << " | " << std::dec << ext.depth << " | " << ext.myAddress << " | #" << steps << " | " << std::hex << std::setw(4) << std::setfill('0') << vm.curPC() << " : " << instructionInfo(inst).name << " | " << std::dec << vm.gas() << " | -" << std::dec << gasCost << " | " << newMemSize << "x32" << " ]";
if (eth::VMTraceChannel::verbosity <= g_logVerbosity)
{
std::ofstream f;
f.open("./vmtrace.log", std::ofstream::app);
f << o.str();
f << " | " << std::dec << ext.depth << " | " << ext.myAddress << " | #" << steps << " | " << std::hex << std::setw(4) << std::setfill('0') << vm.curPC() << " : " << instructionInfo(inst).name << " | " << std::dec << vm.gas() << " | -" << std::dec << gasCost << " | " << newMemSize << "x32";
}
};
}
// THIS IS BROKEN AND NEEDS TO BE REMOVED.
h160 FakeState::createNewAddress(Address _newAddress, Address _sender, u256 _endowment, u256 _gasPrice, u256* _gas, bytesConstRef _code, Address _origin, SubState* o_sub, Manifest* o_ms, OnOpFunc const& _onOp, unsigned _level)
{
@ -517,7 +550,7 @@ void doTests(json_spirit::mValue& v, bool _fillin)
VM vm(fev.gas);
try
{
output = vm.go(fev, fev.simpleTrace<FakeExtVM>()).toVector();
output = vm.go(fev, fev.simpleTrace()).toVector();
}
catch (Exception const& _e)
{

29
test/vm.h

@ -81,9 +81,7 @@ public:
json_spirit::mArray exportCallCreates();
void importCallCreates(json_spirit::mArray& _callcreates);
template<typename ExtVMType>
eth::OnOpFunc simpleTrace();
FakeState state() const { return m_s; }
std::map<Address, std::tuple<u256, u256, std::map<u256, u256>, bytes>> addresses;
@ -97,32 +95,5 @@ private:
eth::Manifest m_ms;
};
template<typename ExtVMType>
eth::OnOpFunc FakeExtVM::simpleTrace()
{
return [](uint64_t steps, eth::Instruction inst, bigint newMemSize, bigint gasCost, void* voidVM, void const* voidExt)
{
ExtVMType const& ext = *(ExtVMType const*)voidExt;
eth::VM& vm = *(eth::VM*)voidVM;
std::ostringstream o;
o << std::endl << " STACK" << std::endl;
for (auto i: vm.stack())
o << (h256)i << std::endl;
o << " MEMORY" << std::endl << memDump(vm.memory());
o << " STORAGE" << std::endl;
for (auto const& i: ext.state().storage(ext.myAddress))
o << std::showbase << std::hex << i.first << ": " << i.second << std::endl;
dev::LogOutputStream<eth::VMTraceChannel, false>(true) << o.str();
dev::LogOutputStream<eth::VMTraceChannel, false>(false) << " | " << std::dec << ext.depth << " | " << ext.myAddress << " | #" << steps << " | " << std::hex << std::setw(4) << std::setfill('0') << vm.curPC() << " : " << instructionInfo(inst).name << " | " << std::dec << vm.gas() << " | -" << std::dec << gasCost << " | " << newMemSize << "x32" << " ]";
if (eth::VMTraceChannel::verbosity <= g_logVerbosity)
{
std::ofstream f;
f.open("./vmtrace.log", std::ofstream::app);
f << o.str();
f << " | " << std::dec << ext.depth << " | " << ext.myAddress << " | #" << steps << " | " << std::hex << std::setw(4) << std::setfill('0') << vm.curPC() << " : " << instructionInfo(inst).name << " | " << std::dec << vm.gas() << " | -" << std::dec << gasCost << " | " << newMemSize << "x32";
}
};
}
} } // Namespace Close

Loading…
Cancel
Save