Browse Source

PoC-7 JUMPDEST done the intended way.

Windows pedantic build fix.
cl-refactor
Gav Wood 10 years ago
parent
commit
e491090e7c
  1. 2
      libethereum/DownloadMan.cpp
  2. 2
      libevm/VM.cpp
  3. 18
      libevm/VM.h
  4. 31
      liblll/Assembly.cpp

2
libethereum/DownloadMan.cpp

@ -71,7 +71,7 @@ bool DownloadSub::noteBlock(h256 _hash)
Guard l(m_fetch); Guard l(m_fetch);
if (m_man && m_indices.count(_hash)) if (m_man && m_indices.count(_hash))
m_man->m_blocksGot += m_indices[_hash]; m_man->m_blocksGot += m_indices[_hash];
bool ret = m_remaining.count(_hash); bool ret = !!m_remaining.count(_hash);
m_remaining.erase(_hash); m_remaining.erase(_hash);
return ret; return ret;
} }

2
libevm/VM.cpp

@ -29,6 +29,4 @@ void VM::reset(u256 _gas)
{ {
m_gas = _gas; m_gas = _gas;
m_curPC = 0; m_curPC = 0;
m_jumpLatch = false;
m_destinations.clear();
} }

18
libevm/VM.h

@ -84,8 +84,6 @@ private:
u256 m_curPC = 0; u256 m_curPC = 0;
bytes m_temp; bytes m_temp;
u256s m_stack; u256s m_stack;
bool m_jumpLatch = false;
u256Set m_destinations;
}; };
} }
@ -568,19 +566,19 @@ template <class Ext> dev::bytesConstRef dev::eth::VM::go(Ext& _ext, OnOpFunc con
break; break;
case Instruction::JUMP: case Instruction::JUMP:
require(1); require(1);
m_jumpLatch = true;
if (!m_destinations.count(m_stack.back()))
BOOST_THROW_EXCEPTION(BadJumpDestination());
nextPC = m_stack.back(); nextPC = m_stack.back();
if ((Instruction)_ext.getCode(nextPC) != Instruction::JUMPDEST)
BOOST_THROW_EXCEPTION(BadJumpDestination());
m_stack.pop_back(); m_stack.pop_back();
break; break;
case Instruction::JUMPI: case Instruction::JUMPI:
require(2); require(2);
m_jumpLatch = true;
if (!m_destinations.count(m_stack.back()))
BOOST_THROW_EXCEPTION(BadJumpDestination());
if (m_stack[m_stack.size() - 2]) if (m_stack[m_stack.size() - 2])
{
nextPC = m_stack.back(); nextPC = m_stack.back();
if ((Instruction)_ext.getCode(nextPC) != Instruction::JUMPDEST)
BOOST_THROW_EXCEPTION(BadJumpDestination());
}
m_stack.pop_back(); m_stack.pop_back();
m_stack.pop_back(); m_stack.pop_back();
break; break;
@ -594,10 +592,6 @@ template <class Ext> dev::bytesConstRef dev::eth::VM::go(Ext& _ext, OnOpFunc con
m_stack.push_back(m_gas); m_stack.push_back(m_gas);
break; break;
case Instruction::JUMPDEST: case Instruction::JUMPDEST:
require(1);
if (!m_jumpLatch)
m_destinations.insert(m_stack.back());
m_stack.pop_back();
break; break;
case Instruction::CREATE: case Instruction::CREATE:
{ {

31
liblll/Assembly.cpp

@ -129,7 +129,7 @@ ostream& dev::eth::operator<<(ostream& _out, AssemblyItemsConstRef _i)
_out << " PUSH[tag" << i.data() << "]"; _out << " PUSH[tag" << i.data() << "]";
break; break;
case Tag: case Tag:
_out << " tag" << i.data() << ":"; _out << " tag" << i.data() << ": JUMPDEST";
break; break;
case PushData: case PushData:
_out << " PUSH*[" << hex << (unsigned)i.data() << "]"; _out << " PUSH*[" << hex << (unsigned)i.data() << "]";
@ -149,17 +149,6 @@ ostream& dev::eth::operator<<(ostream& _out, AssemblyItemsConstRef _i)
ostream& Assembly::streamOut(ostream& _out, string const& _prefix) const ostream& Assembly::streamOut(ostream& _out, string const& _prefix) const
{ {
_out << _prefix << ".pre:" << endl;
for (AssemblyItem const& i: m_items)
switch (i.m_type)
{
case PushTag:
_out << _prefix << " PUSH [tag" << i.m_data << "]" << endl;
_out << _prefix << " JUMPDEST" << endl;
break;
default:;
}
_out << _prefix << ".code:" << endl; _out << _prefix << ".code:" << endl;
for (AssemblyItem const& i: m_items) for (AssemblyItem const& i: m_items)
switch (i.m_type) switch (i.m_type)
@ -183,7 +172,7 @@ ostream& Assembly::streamOut(ostream& _out, string const& _prefix) const
_out << _prefix << " PUSH #[$" << h256(i.m_data).abridged() << "]" << endl; _out << _prefix << " PUSH #[$" << h256(i.m_data).abridged() << "]" << endl;
break; break;
case Tag: case Tag:
_out << _prefix << "tag" << i.m_data << ": " << endl; _out << _prefix << "tag" << i.m_data << ": " << endl << _prefix << " JUMPDEST" << endl;
break; break;
case PushData: case PushData:
_out << _prefix << " PUSH [" << hex << (unsigned)i.m_data << "]" << endl; _out << _prefix << " PUSH [" << hex << (unsigned)i.m_data << "]" << endl;
@ -364,11 +353,9 @@ bytes Assembly::assemble() const
ret.reserve(totalBytes); ret.reserve(totalBytes);
vector<unsigned> tagPos(m_usedTags); vector<unsigned> tagPos(m_usedTags);
map<unsigned, unsigned> tagRef; map<unsigned, unsigned> tagRef;
map<unsigned, unsigned> pretagRef;
multimap<h256, unsigned> dataRef; multimap<h256, unsigned> dataRef;
unsigned bytesPerTag = dev::bytesRequired(totalBytes); unsigned bytesPerTag = dev::bytesRequired(totalBytes);
byte tagPush = (byte)Instruction::PUSH1 - 1 + bytesPerTag; byte tagPush = (byte)Instruction::PUSH1 - 1 + bytesPerTag;
bytes preret;
for (auto const& i: m_subs) for (auto const& i: m_subs)
m_data[i.first] = i.second.assemble(); m_data[i.first] = i.second.assemble();
@ -406,11 +393,6 @@ bytes Assembly::assemble() const
ret.push_back(tagPush); ret.push_back(tagPush);
tagRef[ret.size()] = (unsigned)i.m_data; tagRef[ret.size()] = (unsigned)i.m_data;
ret.resize(ret.size() + bytesPerTag); ret.resize(ret.size() + bytesPerTag);
preret.push_back(tagPush);
pretagRef[preret.size()] = (unsigned)i.m_data;
preret.resize(preret.size() + bytesPerTag);
preret.push_back((byte)Instruction::JUMPDEST);
break; break;
} }
case PushData: case PushSub: case PushData: case PushSub:
@ -432,6 +414,7 @@ bytes Assembly::assemble() const
} }
case Tag: case Tag:
tagPos[(unsigned)i.m_data] = ret.size(); tagPos[(unsigned)i.m_data] = ret.size();
ret.push_back((byte)Instruction::JUMPDEST);
break; break;
default:; default:;
} }
@ -442,12 +425,6 @@ bytes Assembly::assemble() const
toBigEndian(tagPos[i.second], r); toBigEndian(tagPos[i.second], r);
} }
for (auto const& i: pretagRef)
{
bytesRef r(preret.data() + i.first, bytesPerTag);
toBigEndian(tagPos[i.second], r);
}
if (m_data.size()) if (m_data.size())
{ {
ret.push_back(0); ret.push_back(0);
@ -466,5 +443,5 @@ bytes Assembly::assemble() const
} }
} }
} }
return preret + ret; return ret;
} }

Loading…
Cancel
Save