Skip to content

Commit aeff1a6

Browse files
committed
Remove EOF from libevmasm
1 parent 0168407 commit aeff1a6

29 files changed

Lines changed: 54 additions & 1310 deletions

libevmasm/Assembly.cpp

Lines changed: 11 additions & 504 deletions
Large diffs are not rendered by default.

libevmasm/Assembly.h

Lines changed: 3 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -55,28 +55,18 @@ class Assembly
5555
using LinkRef = std::pair<size_t, std::string>;
5656

5757
public:
58-
Assembly(langutil::EVMVersion _evmVersion, bool _creation, std::optional<uint8_t> _eofVersion, std::string _name):
58+
Assembly(langutil::EVMVersion _evmVersion, bool _creation, std::string _name):
5959
m_evmVersion(_evmVersion),
6060
m_creation(_creation),
61-
m_eofVersion(_eofVersion),
6261
m_name(std::move(_name))
6362
{
6463
// Code section number 0 has to be non-returning.
6564
m_codeSections.emplace_back(CodeSection{0, 0, true, {}});
6665
}
6766

68-
std::optional<uint8_t> eofVersion() const { return m_eofVersion; }
69-
bool supportsFunctions() const { return m_eofVersion.has_value(); }
70-
bool supportsRelativeJumps() const { return m_eofVersion.has_value(); }
7167
AssemblyItem newTag() { assertThrow(m_usedTags < 0xffffffff, AssemblyException, ""); return AssemblyItem(Tag, m_usedTags++); }
7268
AssemblyItem newPushTag() { assertThrow(m_usedTags < 0xffffffff, AssemblyException, ""); return AssemblyItem(PushTag, m_usedTags++); }
7369

74-
AssemblyItem newFunctionCall(uint16_t _functionID) const;
75-
AssemblyItem newFunctionReturn() const;
76-
uint16_t createFunction(uint8_t _args, uint8_t _rets, bool _nonReturning);
77-
void beginFunction(uint16_t _functionID);
78-
void endFunction();
79-
8070
/// Returns a tag identified by the given name. Creates it if it does not yet exist.
8171
AssemblyItem namedTag(std::string const& _name, size_t _params, size_t _returns, std::optional<uint64_t> _sourceID);
8272
AssemblyItem newData(bytes const& _data) { util::h256 h(util::keccak256(util::asString(_data))); m_data[h] = _data; return AssemblyItem(PushData, h); }
@@ -89,9 +79,6 @@ class Assembly
8979
AssemblyItem newPushLibraryAddress(std::string const& _identifier);
9080
AssemblyItem newPushImmutable(std::string const& _identifier);
9181
AssemblyItem newImmutableAssignment(std::string const& _identifier);
92-
AssemblyItem newAuxDataLoadN(size_t offset) const;
93-
AssemblyItem newSwapN(size_t _depth) const;
94-
AssemblyItem newDupN(size_t _depth) const;
9582

9683
AssemblyItem const& append(AssemblyItem _i);
9784
AssemblyItem const& append(bytes const& _data) { return append(newData(_data)); }
@@ -104,37 +91,12 @@ class Assembly
10491
void appendLibraryAddress(std::string const& _identifier) { append(newPushLibraryAddress(_identifier)); }
10592
void appendImmutable(std::string const& _identifier) { append(newPushImmutable(_identifier)); }
10693
void appendImmutableAssignment(std::string const& _identifier) { append(newImmutableAssignment(_identifier)); }
107-
void appendAuxDataLoadN(uint16_t _offset) { append(newAuxDataLoadN(_offset));}
108-
void appendSwapN(size_t _depth) { append(newSwapN(_depth)); }
109-
void appendDupN(size_t _depth) { append(newDupN(_depth)); }
11094

11195
void appendVerbatim(bytes _data, size_t _arguments, size_t _returnVariables)
11296
{
11397
append(AssemblyItem(std::move(_data), _arguments, _returnVariables));
11498
}
11599

116-
AssemblyItem appendEOFCreate(ContainerID _containerId)
117-
{
118-
solAssert(_containerId < m_subs.size(), "EOF Create of undefined container.");
119-
return append(AssemblyItem::eofCreate(_containerId));
120-
}
121-
AssemblyItem appendReturnContract(ContainerID _containerId)
122-
{
123-
solAssert(_containerId < m_subs.size(), "Return undefined container ID.");
124-
return append(AssemblyItem::returnContract(_containerId));
125-
}
126-
127-
AssemblyItem appendFunctionCall(uint16_t _functionID)
128-
{
129-
return append(newFunctionCall(_functionID));
130-
}
131-
132-
AssemblyItem appendFunctionReturn()
133-
{
134-
solAssert(m_currentCodeSection != 0, "Appending function return without begin function.");
135-
return append(newFunctionReturn());
136-
}
137-
138100
AssemblyItem appendJump() { auto ret = append(newPushTag()); append(Instruction::JUMP); return ret; }
139101
AssemblyItem appendJumpI() { auto ret = append(newPushTag()); append(Instruction::JUMPI); return ret; }
140102
AssemblyItem appendJump(AssemblyItem const& _tag) { auto ret = append(_tag.pushTag()); append(Instruction::JUMP); return ret; }
@@ -210,8 +172,7 @@ class Assembly
210172
static std::pair<std::shared_ptr<Assembly>, std::vector<std::string>> fromJSON(
211173
Json const& _json,
212174
std::vector<std::string> const& _sourceList = {},
213-
size_t _level = 0,
214-
std::optional<uint8_t> _eofVersion = std::nullopt
175+
size_t _level = 0
215176
);
216177

217178
/// Mark this assembly as invalid. Calling ``assemble`` on it will throw.
@@ -248,7 +209,7 @@ class Assembly
248209
/// that are referenced in a super-assembly.
249210
std::map<u256, u256> const& optimiseInternal(OptimiserSettings const& _settings, std::set<size_t> _tagsReferencedFromOutside);
250211

251-
/// For EOF and legacy it calculates approximate size of "pure" code without data.
212+
/// Calculates approximate size of "pure" code without data.
252213
unsigned codeSize(unsigned subTagSize) const;
253214

254215
/// Add all assembly items from given JSON array. This function imports the items by iterating through
@@ -272,16 +233,7 @@ class Assembly
272233

273234
std::shared_ptr<std::string const> sharedSourceName(std::string const& _name) const;
274235

275-
/// Returns EOF header bytecode | code section sizes offsets | data section size offset
276-
std::tuple<bytes, std::vector<size_t>, size_t> createEOFHeader(std::set<ContainerID> const& _referencedSubIds) const;
277-
278236
LinkerObject const& assembleLegacy() const;
279-
LinkerObject const& assembleEOF() const;
280-
281-
/// Returns map from m_subs to an index of subcontainer in the final EOF bytecode
282-
std::map<ContainerID, ContainerID> findReferencedContainers() const;
283-
/// Returns max AuxDataLoadN offset for the assembly.
284-
std::optional<uint16_t> findMaxAuxDataLoadNOffset() const;
285237

286238
/// Assemble bytecode for AssemblyItem type.
287239
[[nodiscard]] bytes assembleOperation(AssemblyItem const& _item) const;
@@ -333,7 +285,6 @@ class Assembly
333285
int m_deposit = 0;
334286
/// True, if the assembly contains contract creation code.
335287
bool const m_creation = false;
336-
std::optional<uint8_t> m_eofVersion;
337288
/// Internal name of the assembly object, only used with the Yul backend
338289
/// currently
339290
std::string m_name;

libevmasm/AssemblyItem.cpp

Lines changed: 5 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -63,38 +63,20 @@ AssemblyItem AssemblyItem::toSubAssemblyTag(SubAssemblyID _subId) const
6363

6464
std::pair<SubAssemblyID, size_t> AssemblyItem::splitForeignPushTag() const
6565
{
66-
solAssert(m_type == PushTag || m_type == Tag || m_type == RelativeJump || m_type == ConditionalRelativeJump);
66+
solAssert(m_type == PushTag || m_type == Tag);
6767
u256 combined = u256(data());
6868
// the combined u256 is 'dirty', so we can't use the conversion constructor of SubAssemblyID here
6969
SubAssemblyID const subID{static_cast<SubAssemblyID::ValueType>((combined >> 64) - 1)};
7070
size_t tag = static_cast<size_t>(combined & 0xffffffffffffffffULL);
7171
return std::make_pair(subID, tag);
7272
}
7373

74-
size_t AssemblyItem::relativeJumpTagID() const
75-
{
76-
solAssert(m_type == RelativeJump || m_type == ConditionalRelativeJump);
77-
auto const [subId, tagId] = splitForeignPushTag();
78-
solAssert(subId.empty(), "Relative jump to sub");
79-
return tagId;
80-
}
81-
8274
std::pair<std::string, std::string> AssemblyItem::nameAndData(langutil::EVMVersion _evmVersion) const
8375
{
8476
switch (type())
8577
{
8678
case Operation:
87-
case EOFCreate:
88-
case ReturnContract:
89-
case RelativeJump:
90-
case ConditionalRelativeJump:
91-
case CallF:
92-
case JumpF:
93-
case RetF:
9479
return {instructionInfo(instruction(), _evmVersion).name, ""};
95-
case SwapN:
96-
case DupN:
97-
return {instructionInfo(instruction(), _evmVersion).name, util::toString(static_cast<size_t>(data())) };
9880
case Push:
9981
return {"PUSH", toStringInHex(data())};
10082
case PushTag:
@@ -122,8 +104,6 @@ std::pair<std::string, std::string> AssemblyItem::nameAndData(langutil::EVMVersi
122104
return {"PUSH data", toStringInHex(data())};
123105
case VerbatimBytecode:
124106
return {"VERBATIM", util::toHex(verbatimData())};
125-
case AuxDataLoadN:
126-
return {"AUXDATALOADN", util::toString(data())};
127107
case UndefinedItem:
128108
solAssert(false);
129109
}
@@ -133,8 +113,7 @@ std::pair<std::string, std::string> AssemblyItem::nameAndData(langutil::EVMVersi
133113

134114
void AssemblyItem::setPushTagSubIdAndTag(SubAssemblyID _subId, size_t _tag)
135115
{
136-
solAssert(m_type == PushTag || m_type == Tag || m_type == RelativeJump || m_type == ConditionalRelativeJump);
137-
solAssert(!(m_type == RelativeJump || m_type == ConditionalRelativeJump) || _subId.empty());
116+
solAssert(m_type == PushTag || m_type == Tag);
138117
u256 data = _tag;
139118
if (!_subId.empty())
140119
data |= (u256(_subId.value) + 1) << 64;
@@ -147,7 +126,6 @@ size_t AssemblyItem::bytesRequired(size_t _addressLength, langutil::EVMVersion _
147126
{
148127
case Operation:
149128
case Tag: // 1 byte for the JUMPDEST
150-
case RetF:
151129
return 1;
152130
case Push:
153131
return
@@ -187,20 +165,6 @@ size_t AssemblyItem::bytesRequired(size_t _addressLength, langutil::EVMVersion _
187165
}
188166
case VerbatimBytecode:
189167
return std::get<2>(*m_verbatimBytecode).size();
190-
case RelativeJump:
191-
case ConditionalRelativeJump:
192-
case AuxDataLoadN:
193-
case JumpF:
194-
case CallF:
195-
return 1 + 2;
196-
case EOFCreate:
197-
return 2;
198-
case ReturnContract:
199-
return 2;
200-
case SwapN:
201-
return 2;
202-
case DupN:
203-
return 2;
204168
case UndefinedItem:
205169
solAssert(false);
206170
}
@@ -210,15 +174,8 @@ size_t AssemblyItem::bytesRequired(size_t _addressLength, langutil::EVMVersion _
210174

211175
size_t AssemblyItem::arguments() const
212176
{
213-
if (type() == CallF || type() == JumpF)
214-
return functionSignature().argsNum;
215-
else if (type() == SwapN)
216-
return static_cast<size_t>(data()) + 1;
217-
else if (type() == DupN)
218-
return static_cast<size_t>(data());
219-
else if (hasInstruction())
177+
if (hasInstruction())
220178
{
221-
solAssert(instruction() != Instruction::CALLF && instruction() != Instruction::JUMPF);
222179
// The latest EVMVersion is used here, since the InstructionInfo is assumed to be
223180
// the same across all EVM versions except for the instruction name.
224181
return static_cast<size_t>(instructionInfo(instruction(), EVMVersion()).args);
@@ -236,17 +193,9 @@ size_t AssemblyItem::returnValues() const
236193
switch (m_type)
237194
{
238195
case Operation:
239-
case EOFCreate:
240-
case ReturnContract:
241-
case RelativeJump:
242-
case ConditionalRelativeJump:
243-
case RetF:
244196
// The latest EVMVersion is used here, since the InstructionInfo is assumed to be
245197
// the same across all EVM versions except for the instruction name.
246198
return static_cast<size_t>(instructionInfo(instruction(), EVMVersion()).ret);
247-
case SwapN:
248-
case DupN:
249-
return static_cast<size_t>(data()) + 1;
250199
case Push:
251200
case PushTag:
252201
case PushData:
@@ -261,11 +210,6 @@ size_t AssemblyItem::returnValues() const
261210
return 0;
262211
case VerbatimBytecode:
263212
return std::get<1>(*m_verbatimBytecode);
264-
case AuxDataLoadN:
265-
return 1;
266-
case JumpF:
267-
case CallF:
268-
return functionSignature().retsNum;
269213
case AssignImmutable:
270214
case UndefinedItem:
271215
break;
@@ -280,16 +224,6 @@ bool AssemblyItem::canBeFunctional() const
280224
switch (m_type)
281225
{
282226
case Operation:
283-
case EOFCreate:
284-
case ReturnContract:
285-
case RelativeJump:
286-
case ConditionalRelativeJump:
287-
case CallF:
288-
case JumpF:
289-
case SwapN:
290-
case DupN:
291-
case RetF:
292-
return !SemanticInformation::isDupInstruction(*this) && !SemanticInformation::isSwapInstruction(*this);
293227
case Push:
294228
case PushTag:
295229
case PushData:
@@ -299,7 +233,6 @@ bool AssemblyItem::canBeFunctional() const
299233
case PushLibraryAddress:
300234
case PushDeployTimeAddress:
301235
case PushImmutable:
302-
case AuxDataLoadN:
303236
return true;
304237
case Tag:
305238
return false;
@@ -401,37 +334,6 @@ std::string AssemblyItem::toAssemblyText(Assembly const& _assembly) const
401334
case VerbatimBytecode:
402335
text = std::string("verbatimbytecode_") + util::toHex(std::get<2>(*m_verbatimBytecode));
403336
break;
404-
case AuxDataLoadN:
405-
assertThrow(data() <= std::numeric_limits<size_t>::max(), AssemblyException, "Invalid auxdataloadn argument.");
406-
text = "auxdataloadn{" + std::to_string(static_cast<size_t>(data())) + "}";
407-
break;
408-
case EOFCreate:
409-
text = "eofcreate{" + std::to_string(static_cast<size_t>(data())) + "}";
410-
break;
411-
case ReturnContract:
412-
text = "returncontract{" + std::to_string(static_cast<size_t>(data())) + "}";
413-
break;
414-
case RelativeJump:
415-
text = "rjump{" + std::string("tag_") + std::to_string(relativeJumpTagID()) + "}";
416-
break;
417-
case ConditionalRelativeJump:
418-
text = "rjumpi{" + std::string("tag_") + std::to_string(relativeJumpTagID()) + "}";
419-
break;
420-
case CallF:
421-
text = "callf{" + std::string("code_section_") + std::to_string(static_cast<size_t>(data())) + "}";
422-
break;
423-
case JumpF:
424-
text = "jumpf{" + std::string("code_section_") + std::to_string(static_cast<size_t>(data())) + "}";
425-
break;
426-
case RetF:
427-
text = "retf";
428-
break;
429-
case SwapN:
430-
text = "swapn{" + std::to_string(static_cast<size_t>(data())) + "}";
431-
break;
432-
case DupN:
433-
text = "dupn{" + std::to_string(static_cast<size_t>(data())) + "}";
434-
break;
435337
}
436338
if (m_jumpType == JumpType::IntoFunction || m_jumpType == JumpType::OutOfFunction)
437339
{
@@ -450,15 +352,6 @@ std::ostream& solidity::evmasm::operator<<(std::ostream& _out, AssemblyItem cons
450352
switch (_item.type())
451353
{
452354
case Operation:
453-
case EOFCreate:
454-
case ReturnContract:
455-
case RelativeJump:
456-
case ConditionalRelativeJump:
457-
case CallF:
458-
case JumpF:
459-
case RetF:
460-
case SwapN:
461-
case DupN:
462355
_out << " " << instructionInfo(_item.instruction(), EVMVersion()).name;
463356
if (_item.instruction() == Instruction::JUMP || _item.instruction() == Instruction::JUMPI)
464357
_out << "\t" << _item.getJumpTypeAsString();
@@ -508,9 +401,6 @@ std::ostream& solidity::evmasm::operator<<(std::ostream& _out, AssemblyItem cons
508401
case VerbatimBytecode:
509402
_out << " Verbatim " << util::toHex(_item.verbatimData());
510403
break;
511-
case AuxDataLoadN:
512-
_out << " AuxDataLoadN " << util::toString(_item.data());
513-
break;
514404
case UndefinedItem:
515405
_out << " ???";
516406
break;
@@ -563,9 +453,9 @@ std::string AssemblyItem::computeSourceMapping(
563453
static_cast<int>(_sourceIndicesMap.at(*location.sourceName)) :
564454
-1;
565455
char jump = '-';
566-
if (item.getJumpType() == evmasm::AssemblyItem::JumpType::IntoFunction || item.type() == CallF || item.type() == JumpF)
456+
if (item.getJumpType() == evmasm::AssemblyItem::JumpType::IntoFunction)
567457
jump = 'i';
568-
else if (item.getJumpType() == evmasm::AssemblyItem::JumpType::OutOfFunction || item.type() == RetF)
458+
else if (item.getJumpType() == evmasm::AssemblyItem::JumpType::OutOfFunction)
569459
jump = 'o';
570460
int modifierDepth = static_cast<int>(item.m_modifierDepth);
571461

0 commit comments

Comments
 (0)