Browse Source

Minor protocol changes.

cl-refactor
Gav Wood 11 years ago
parent
commit
0e401c0e35
  1. 18
      alethzero/MainWin.cpp
  2. 37
      libethereum/Instruction.cpp
  3. 2
      libethereum/State.cpp
  4. 8
      libethereum/VM.h

18
alethzero/MainWin.cpp

@ -437,23 +437,9 @@ void Main::on_contracts_currentItemChanged()
stringstream s;
auto mem = state().contractMemory(h);
u256 next = 0;
for (auto const& i: mem)
{
if (next < i.first)
{
unsigned j;
for (j = 0; next + j < i.first; ++j)
s << " 0";
if (next + j < i.first)
s << " ...<br/>@" << showbase << hex << i.first << "&nbsp;&nbsp;&nbsp;&nbsp;";
}
else if (!next)
s << "@" << showbase << hex << i.first << "&nbsp;&nbsp;&nbsp;&nbsp;";
s << " " << showbase << hex << i.second;
next = i.first + 1;
}
s << "<br/><br/>Code:";
s << "@" << showbase << hex << i.first << "&nbsp;&nbsp;&nbsp;&nbsp;" << showbase << hex << i.second << "<br/>";
s << "<br/>Code:";
s << "<br/>" << disassemble(state().contractCode(h));
ui->contractInfo->appendHtml(QString::fromStdString(s.str()));
}

37
libethereum/Instruction.cpp

@ -141,7 +141,7 @@ const std::map<Instruction, InstructionInfo> eth::c_instructionInfo =
{ Instruction::CALLER, { "CALLER", 0, 0, 1 } },
{ Instruction::CALLVALUE, { "CALLVALUE", 0, 0, 1 } },
{ Instruction::CALLDATALOAD, { "CALLDATALOAD", 0, 1, 1 } },
{ Instruction::CALLDATASIZE, { "CALLDATASIZE", 0, 1, 1 } },
{ Instruction::CALLDATASIZE, { "CALLDATASIZE", 0, 0, 1 } },
{ Instruction::GASPRICE, { "BASEFEE", 0, 0, 1 } },
{ Instruction::PREVHASH, { "PREVHASH", 0, 0, 1 } },
{ Instruction::COINBASE, { "COINBASE", 0, 0, 1 } },
@ -766,28 +766,25 @@ static int compileLispFragment(char const*& d, char const* e, bool _quiet, bytes
auto it = c_arith.find(t);
if (it != c_arith.end())
{
int i = 0;
vector<pair<bytes, vector<unsigned>>> codes(1);
int totalArgs = 0;
while (d != e)
{
bytes codes;
vector<unsigned> locs;
int o = compileLispFragment(d, e, _quiet, codes, locs);
if (o == -1)
{
if (!i)
cwarn << "Expected at least one argument to operation" << t;
break;
}
if (o == 0)
{
cwarn << "null operation given to " << t;
int o = compileLispFragment(d, e, _quiet, codes.back().first, codes.back().second);
if (o < 1)
break;
}
appendCode(o_code, o_locs, codes, locs);
i += o;
for (; i > 1; --i)
o_code.push_back((byte)it->second);
codes.push_back(pair<bytes, vector<unsigned>>());
totalArgs += o;
}
codes.pop_back();
if (!totalArgs)
{
cwarn << "Expected at least one argument to operation" << t;
break;
}
for (auto jt = codes.rbegin(); jt != codes.rend(); ++jt)
appendCode(o_code, o_locs, jt->first, jt->second);
o_code.push_back((byte)it->second);
}
else
{
@ -814,7 +811,7 @@ static int compileLispFragment(char const*& d, char const* e, bool _quiet, bytes
for (auto jt = codes.rbegin(); jt != codes.rend(); ++jt)
appendCode(o_code, o_locs, jt->first, jt->second);
if (it->second.second)
o_code.push_back((byte)Instruction::EQ);
o_code.push_back((byte)Instruction::NOT);
o_code.push_back((byte)it->second.first);
}
else

2
libethereum/State.cpp

@ -723,7 +723,7 @@ bool State::call(Address _receiveAddress, Address _sendAddress, u256 _value, u25
h160 State::create(Address _sender, u256 _endowment, u256 _gasPrice, u256* _gas, bytesConstRef _code, bytesConstRef _init)
{
Address newAddress = right160(sha3(rlpList(_sender, transactionsFrom(_sender))));
Address newAddress = left160(sha3(rlpList(_sender, transactionsFrom(_sender))));
while (isContractAddress(newAddress) || isNormalAddress(newAddress))
newAddress = (u160)newAddress + 1;

8
libethereum/VM.h

@ -36,12 +36,14 @@ namespace eth
// Currently we just pull out the right (low-order in BE) 160-bits.
inline Address asAddress(u256 _item)
{
return right160(h256(_item));
return left160(h256(_item));
}
inline u256 fromAddress(Address _a)
{
return (u160)_a;
u256 ret;
memcpy(&_a, &ret, sizeof(_a));
return ret;
}
/**
@ -311,7 +313,7 @@ template <class Ext> eth::bytesConstRef eth::VM::go(Ext& _ext, uint64_t _steps)
case Instruction::CALLDATALOAD:
{
require(1);
if ((unsigned)m_stack.back() < _ext.txData.size() + 32)
if ((unsigned)m_stack.back() + 32 < _ext.txData.size())
m_stack.back() = (u256)*(h256 const*)(_ext.txData.data() + (unsigned)m_stack.back());
else
{

Loading…
Cancel
Save