Browse Source

Merge pull request #1249 from chriseth/sol_fix_randomness

Make subroutine id non-random.
cl-refactor
chriseth 10 years ago
parent
commit
6f302ee74b
  1. 20
      libevmcore/Assembly.cpp
  2. 6
      libevmcore/Assembly.h

20
libevmcore/Assembly.cpp

@ -99,6 +99,8 @@ void Assembly::append(Assembly const& _a)
{
if (i.type() == Tag || i.type() == PushTag)
i.m_data += m_usedTags;
else if (i.type() == PushSub || i.type() == PushSubSize)
i.m_data += m_subs.size();
append(i);
}
m_deposit = newDeposit;
@ -108,7 +110,7 @@ void Assembly::append(Assembly const& _a)
for (auto const& i: _a.m_strings)
m_strings.insert(i);
for (auto const& i: _a.m_subs)
m_subs.insert(i);
m_subs.push_back(i);
assert(!_a.m_baseDeposit);
assert(!_a.m_totalDeposit);
@ -245,12 +247,12 @@ ostream& Assembly::streamRLP(ostream& _out, string const& _prefix, StringMap con
{
_out << _prefix << ".data:" << endl;
for (auto const& i: m_data)
if (!m_subs.count(i.first))
if (u256(i.first) >= m_subs.size())
_out << _prefix << " " << hex << (unsigned)(u256)i.first << ": " << toHex(i.second) << endl;
for (auto const& i: m_subs)
for (size_t i = 0; i < m_subs.size(); ++i)
{
_out << _prefix << " " << hex << (unsigned)(u256)i.first << ": " << endl;
i.second.streamRLP(_out, _prefix + " ", _sourceCodes);
_out << _prefix << " " << hex << i << ": " << endl;
m_subs[i].streamRLP(_out, _prefix + " ", _sourceCodes);
}
}
return _out;
@ -493,8 +495,8 @@ Assembly& Assembly::optimise(bool _enable)
copt << total << " optimisations done.";
for (auto& i: m_subs)
i.second.optimise(true);
for (auto& sub: m_subs)
sub.optimise(true);
return *this;
}
@ -511,8 +513,8 @@ bytes Assembly::assemble() const
unsigned bytesPerTag = dev::bytesRequired(totalBytes);
byte tagPush = (byte)Instruction::PUSH1 - 1 + bytesPerTag;
for (auto const& i: m_subs)
m_data[i.first] = i.second.assemble();
for (size_t i = 0; i < m_subs.size(); ++i)
m_data[u256(i)] = m_subs[i].assemble();
unsigned bytesRequiredIncludingData = bytesRequired();
unsigned bytesPerDataRef = dev::bytesRequired(bytesRequiredIncludingData);

6
libevmcore/Assembly.h

@ -81,9 +81,9 @@ public:
AssemblyItem newTag() { return AssemblyItem(Tag, m_usedTags++); }
AssemblyItem newPushTag() { return AssemblyItem(PushTag, m_usedTags++); }
AssemblyItem newData(bytes const& _data) { h256 h = (u256)std::hash<std::string>()(asString(_data)); m_data[h] = _data; return AssemblyItem(PushData, h); }
AssemblyItem newSub(Assembly const& _sub) { h256 h = h256::random(s_fixedHashEngine); m_subs[h] = _sub; return AssemblyItem(PushSub, h); }
AssemblyItem newSub(Assembly const& _sub) { m_subs.push_back(_sub); return AssemblyItem(PushSub, m_subs.size() - 1); }
AssemblyItem newPushString(std::string const& _data) { h256 h = (u256)std::hash<std::string>()(_data); m_strings[h] = _data; return AssemblyItem(PushString, h); }
AssemblyItem newPushSubSize(h256 const& _subId) { return AssemblyItem(PushSubSize, _subId); }
AssemblyItem newPushSubSize(u256 const& _subId) { return AssemblyItem(PushSubSize, _subId); }
AssemblyItem append() { return append(newTag()); }
void append(Assembly const& _a);
@ -134,7 +134,7 @@ protected:
unsigned m_usedTags = 0;
AssemblyItems m_items;
mutable std::map<h256, bytes> m_data;
std::map<h256, Assembly> m_subs;
std::vector<Assembly> m_subs;
std::map<h256, std::string> m_strings;
int m_deposit = 0;

Loading…
Cancel
Save