Drop support for evm15 and eip-615.

This commit is contained in:
Daniel Kirchner
2021-03-09 15:56:03 +01:00
parent 5c2cd8d553
commit a75424eec4
18 changed files with 40 additions and 225 deletions
-9
View File
@@ -87,15 +87,6 @@ public:
virtual void appendJumpTo(LabelID _labelId, int _stackDiffAfter = 0, JumpType _jumpType = JumpType::Ordinary) = 0;
/// Append a jump-to-if-immediate operation.
virtual void appendJumpToIf(LabelID _labelId, JumpType _jumpType = JumpType::Ordinary) = 0;
/// Start a subroutine identified by @a _labelId that takes @a _arguments
/// stack slots as arguments.
virtual void appendBeginsub(LabelID _labelId, int _arguments) = 0;
/// Call a subroutine identified by @a _labelId, taking @a _arguments from the
/// stack upon call and putting @a _returns arguments onto the stack upon return.
virtual void appendJumpsub(LabelID _labelId, int _arguments, int _returns) = 0;
/// Return from a subroutine.
/// @param _stackDiffAfter the stack adjustment after this instruction.
virtual void appendReturnsub(int _returns, int _stackDiffAfter = 0) = 0;
/// Append the assembled size as a constant.
virtual void appendAssemblySize() = 0;
-19
View File
@@ -117,24 +117,6 @@ void EthAssemblyAdapter::appendJumpToIf(LabelID _labelId, JumpType _jumpType)
appendJumpInstruction(evmasm::Instruction::JUMPI, _jumpType);
}
void EthAssemblyAdapter::appendBeginsub(LabelID, int)
{
// TODO we could emulate that, though
yulAssert(false, "BEGINSUB not implemented for EVM 1.0");
}
void EthAssemblyAdapter::appendJumpsub(LabelID, int, int)
{
// TODO we could emulate that, though
yulAssert(false, "JUMPSUB not implemented for EVM 1.0");
}
void EthAssemblyAdapter::appendReturnsub(int, int)
{
// TODO we could emulate that, though
yulAssert(false, "RETURNSUB not implemented for EVM 1.0");
}
void EthAssemblyAdapter::appendAssemblySize()
{
m_assembly.appendProgramSize();
@@ -239,7 +221,6 @@ void CodeGenerator::assemble(
EVMDialect::strictAssemblyForEVM(_evmVersion),
builtinContext,
_optimizeStackAllocation,
false,
_identifierAccess,
_useNamedLabelsForFunctions
);
-3
View File
@@ -53,9 +53,6 @@ public:
void appendJump(int _stackDiffAfter, JumpType _jumpType) override;
void appendJumpTo(LabelID _labelId, int _stackDiffAfter, JumpType _jumpType) override;
void appendJumpToIf(LabelID _labelId, JumpType _jumpType) override;
void appendBeginsub(LabelID, int) override;
void appendJumpsub(LabelID, int, int) override;
void appendReturnsub(int, int) override;
void appendAssemblySize() override;
std::pair<std::shared_ptr<AbstractAssembly>, SubID> createSubAssembly(std::string _name = {}) override;
void appendDataOffset(std::vector<SubID> const& _subPath) override;
+4 -50
View File
@@ -65,7 +65,6 @@ void EVMAssembly::appendLabel(LabelID _labelId)
void EVMAssembly::appendLabelReference(LabelID _labelId)
{
yulAssert(!m_evm15, "Cannot use plain label references in EMV1.5 mode.");
// @TODO we now always use labelReferenceSize for all labels, it could be shortened
// for some of them.
appendInstruction(evmasm::pushInstruction(labelReferenceSize));
@@ -94,65 +93,20 @@ void EVMAssembly::appendLinkerSymbol(string const&)
void EVMAssembly::appendJump(int _stackDiffAfter, JumpType)
{
yulAssert(!m_evm15, "Plain JUMP used for EVM 1.5");
appendInstruction(evmasm::Instruction::JUMP);
m_stackHeight += _stackDiffAfter;
}
void EVMAssembly::appendJumpTo(LabelID _labelId, int _stackDiffAfter, JumpType _jumpType)
{
if (m_evm15)
{
m_bytecode.push_back(uint8_t(evmasm::Instruction::EIP615_JUMPTO));
appendLabelReferenceInternal(_labelId);
m_stackHeight += _stackDiffAfter;
}
else
{
appendLabelReference(_labelId);
appendJump(_stackDiffAfter, _jumpType);
}
appendLabelReference(_labelId);
appendJump(_stackDiffAfter, _jumpType);
}
void EVMAssembly::appendJumpToIf(LabelID _labelId, JumpType)
{
if (m_evm15)
{
m_bytecode.push_back(uint8_t(evmasm::Instruction::EIP615_JUMPIF));
appendLabelReferenceInternal(_labelId);
m_stackHeight--;
}
else
{
appendLabelReference(_labelId);
appendInstruction(evmasm::Instruction::JUMPI);
}
}
void EVMAssembly::appendBeginsub(LabelID _labelId, int _arguments)
{
yulAssert(m_evm15, "BEGINSUB used for EVM 1.0");
yulAssert(_arguments >= 0, "");
setLabelToCurrentPosition(_labelId);
m_bytecode.push_back(uint8_t(evmasm::Instruction::EIP615_BEGINSUB));
m_stackHeight += _arguments;
}
void EVMAssembly::appendJumpsub(LabelID _labelId, int _arguments, int _returns)
{
yulAssert(m_evm15, "JUMPSUB used for EVM 1.0");
yulAssert(_arguments >= 0 && _returns >= 0, "");
m_bytecode.push_back(uint8_t(evmasm::Instruction::EIP615_JUMPSUB));
appendLabelReferenceInternal(_labelId);
m_stackHeight += _returns - _arguments;
}
void EVMAssembly::appendReturnsub(int _returns, int _stackDiffAfter)
{
yulAssert(m_evm15, "RETURNSUB used for EVM 1.0");
yulAssert(_returns >= 0, "");
m_bytecode.push_back(uint8_t(evmasm::Instruction::EIP615_RETURNSUB));
m_stackHeight += _stackDiffAfter - _returns;
appendLabelReference(_labelId);
appendInstruction(evmasm::Instruction::JUMPI);
}
evmasm::LinkerObject EVMAssembly::finalize()
+1 -8
View File
@@ -38,7 +38,7 @@ namespace solidity::yul
class EVMAssembly: public AbstractAssembly
{
public:
explicit EVMAssembly(bool _evm15 = false): m_evm15(_evm15) { }
explicit EVMAssembly() { }
~EVMAssembly() override = default;
/// Set a new source location valid starting from the next instruction.
@@ -70,12 +70,6 @@ public:
void appendJumpTo(LabelID _labelId, int _stackDiffAfter, JumpType _jumpType) override;
/// Append a jump-to-if-immediate operation.
void appendJumpToIf(LabelID _labelId, JumpType _jumpType) override;
/// Start a subroutine.
void appendBeginsub(LabelID _labelId, int _arguments) override;
/// Call a subroutine.
void appendJumpsub(LabelID _labelId, int _arguments, int _returns) override;
/// Return from a subroutine.
void appendReturnsub(int _returns, int _stackDiffAfter) override;
/// Append the assembled size as a constant.
void appendAssemblySize() override;
@@ -97,7 +91,6 @@ private:
void appendLabelReferenceInternal(AbstractAssembly::LabelID _labelId);
void updateReference(size_t pos, size_t size, u256 value);
bool m_evm15 = false; ///< if true, switch to evm1.5 mode
LabelID m_nextLabelId = 0;
int m_stackHeight = 0;
bytes m_bytecode;
+16 -37
View File
@@ -101,7 +101,6 @@ CodeTransform::CodeTransform(
bool _allowStackOpt,
EVMDialect const& _dialect,
BuiltinContext& _builtinContext,
bool _evm15,
ExternalIdentifierAccess _identifierAccess,
bool _useNamedLabelsForFunctions,
shared_ptr<Context> _context
@@ -111,7 +110,6 @@ CodeTransform::CodeTransform(
m_dialect(_dialect),
m_builtinContext(_builtinContext),
m_allowStackOpt(_allowStackOpt),
m_evm15(_evm15),
m_useNamedLabelsForFunctions(_useNamedLabelsForFunctions),
m_identifierAccess(std::move(_identifierAccess)),
m_context(std::move(_context))
@@ -269,11 +267,9 @@ void CodeTransform::operator()(FunctionCall const& _call)
{
m_assembly.setSourceLocation(_call.location);
EVMAssembly::LabelID returnLabel(numeric_limits<EVMAssembly::LabelID>::max()); // only used for evm 1.0
if (!m_evm15)
{
returnLabel = m_assembly.newLabelId();
m_assembly.appendLabelReference(returnLabel);
}
returnLabel = m_assembly.newLabelId();
m_assembly.appendLabelReference(returnLabel);
Scope::Function* function = nullptr;
yulAssert(m_scope->lookup(_call.functionName.name, GenericVisitor{
@@ -285,21 +281,12 @@ void CodeTransform::operator()(FunctionCall const& _call)
for (auto const& arg: _call.arguments | boost::adaptors::reversed)
visitExpression(arg);
m_assembly.setSourceLocation(_call.location);
if (m_evm15)
m_assembly.appendJumpsub(
functionEntryID(_call.functionName.name, *function),
static_cast<int>(function->arguments.size()),
static_cast<int>(function->returns.size())
);
else
{
m_assembly.appendJumpTo(
functionEntryID(_call.functionName.name, *function),
static_cast<int>(function->returns.size() - function->arguments.size()) - 1,
AbstractAssembly::JumpType::IntoFunction
);
m_assembly.appendLabel(returnLabel);
}
m_assembly.appendJumpTo(
functionEntryID(_call.functionName.name, *function),
static_cast<int>(function->returns.size() - function->arguments.size()) - 1,
AbstractAssembly::JumpType::IntoFunction
);
m_assembly.appendLabel(returnLabel);
}
}
@@ -406,7 +393,7 @@ void CodeTransform::operator()(FunctionDefinition const& _function)
yulAssert(m_scope->identifiers.count(_function.name), "");
Scope::Function& function = std::get<Scope::Function>(m_scope->identifiers.at(_function.name));
size_t height = m_evm15 ? 0 : 1;
size_t height = 1;
yulAssert(m_info.scopes.at(&_function.body), "");
Scope* varScope = m_info.scopes.at(m_info.virtualBlocks.at(&_function).get()).get();
yulAssert(varScope, "");
@@ -419,10 +406,7 @@ void CodeTransform::operator()(FunctionDefinition const& _function)
m_assembly.setSourceLocation(_function.location);
int const stackHeightBefore = m_assembly.stackHeight();
if (m_evm15)
m_assembly.appendBeginsub(functionEntryID(_function.name, function), static_cast<int>(_function.parameters.size()));
else
m_assembly.appendLabel(functionEntryID(_function.name, function));
m_assembly.appendLabel(functionEntryID(_function.name, function));
m_assembly.setStackHeight(static_cast<int>(height));
@@ -444,7 +428,6 @@ void CodeTransform::operator()(FunctionDefinition const& _function)
m_allowStackOpt,
m_dialect,
m_builtinContext,
m_evm15,
m_identifierAccess,
m_useNamedLabelsForFunctions,
m_context
@@ -474,8 +457,7 @@ void CodeTransform::operator()(FunctionDefinition const& _function)
// This vector holds the desired target positions of all stack slots and is
// modified parallel to the actual stack.
vector<int> stackLayout;
if (!m_evm15)
stackLayout.push_back(static_cast<int>(_function.returnVariables.size())); // Move return label to the top
stackLayout.push_back(static_cast<int>(_function.returnVariables.size())); // Move return label to the top
stackLayout += vector<int>(_function.parameters.size(), -1); // discard all arguments
for (size_t i = 0; i < _function.returnVariables.size(); ++i)
@@ -512,13 +494,10 @@ void CodeTransform::operator()(FunctionDefinition const& _function)
yulAssert(i == static_cast<size_t>(stackLayout[i]), "Error reshuffling stack.");
}
}
if (m_evm15)
m_assembly.appendReturnsub(static_cast<int>(_function.returnVariables.size()), stackHeightBefore);
else
m_assembly.appendJump(
stackHeightBefore - static_cast<int>(_function.returnVariables.size()),
AbstractAssembly::JumpType::OutOfFunction
);
m_assembly.appendJump(
stackHeightBefore - static_cast<int>(_function.returnVariables.size()),
AbstractAssembly::JumpType::OutOfFunction
);
m_assembly.setStackHeight(stackHeightBefore);
}
-4
View File
@@ -128,7 +128,6 @@ public:
EVMDialect const& _dialect,
BuiltinContext& _builtinContext,
bool _allowStackOpt = false,
bool _evm15 = false,
ExternalIdentifierAccess const& _identifierAccess = ExternalIdentifierAccess(),
bool _useNamedLabelsForFunctions = false
): CodeTransform(
@@ -138,7 +137,6 @@ public:
_allowStackOpt,
_dialect,
_builtinContext,
_evm15,
_identifierAccess,
_useNamedLabelsForFunctions,
nullptr
@@ -158,7 +156,6 @@ protected:
bool _allowStackOpt,
EVMDialect const& _dialect,
BuiltinContext& _builtinContext,
bool _evm15,
ExternalIdentifierAccess _identifierAccess,
bool _useNamedLabelsForFunctions,
std::shared_ptr<Context> _context
@@ -228,7 +225,6 @@ private:
EVMDialect const& m_dialect;
BuiltinContext& m_builtinContext;
bool const m_allowStackOpt = true;
bool const m_evm15 = false;
bool const m_useNamedLabelsForFunctions = false;
ExternalIdentifierAccess m_identifierAccess;
std::shared_ptr<Context> m_context;
+4 -4
View File
@@ -31,9 +31,9 @@
using namespace solidity::yul;
using namespace std;
void EVMObjectCompiler::compile(Object& _object, AbstractAssembly& _assembly, EVMDialect const& _dialect, bool _evm15, bool _optimize)
void EVMObjectCompiler::compile(Object& _object, AbstractAssembly& _assembly, EVMDialect const& _dialect, bool _optimize)
{
EVMObjectCompiler compiler(_assembly, _dialect, _evm15);
EVMObjectCompiler compiler(_assembly, _dialect);
compiler.run(_object, _optimize);
}
@@ -49,7 +49,7 @@ void EVMObjectCompiler::run(Object& _object, bool _optimize)
auto subAssemblyAndID = m_assembly.createSubAssembly(subObject->name.str());
context.subIDs[subObject->name] = subAssemblyAndID.second;
subObject->subId = subAssemblyAndID.second;
compile(*subObject, *subAssemblyAndID.first, m_dialect, m_evm15, _optimize);
compile(*subObject, *subAssemblyAndID.first, m_dialect, _optimize);
}
else
{
@@ -61,7 +61,7 @@ void EVMObjectCompiler::run(Object& _object, bool _optimize)
yulAssert(_object.code, "No code.");
// We do not catch and re-throw the stack too deep exception here because it is a YulException,
// which should be native to this part of the code.
CodeTransform transform{m_assembly, *_object.analysisInfo, *_object.code, m_dialect, context, _optimize, m_evm15};
CodeTransform transform{m_assembly, *_object.analysisInfo, *_object.code, m_dialect, context, _optimize};
transform(*_object.code);
if (!transform.stackErrors().empty())
BOOST_THROW_EXCEPTION(transform.stackErrors().front());
+3 -4
View File
@@ -30,17 +30,16 @@ struct EVMDialect;
class EVMObjectCompiler
{
public:
static void compile(Object& _object, AbstractAssembly& _assembly, EVMDialect const& _dialect, bool _evm15, bool _optimize);
static void compile(Object& _object, AbstractAssembly& _assembly, EVMDialect const& _dialect, bool _optimize);
private:
EVMObjectCompiler(AbstractAssembly& _assembly, EVMDialect const& _dialect, bool _evm15):
m_assembly(_assembly), m_dialect(_dialect), m_evm15(_evm15)
EVMObjectCompiler(AbstractAssembly& _assembly, EVMDialect const& _dialect):
m_assembly(_assembly), m_dialect(_dialect)
{}
void run(Object& _object, bool _optimize);
AbstractAssembly& m_assembly;
EVMDialect const& m_dialect;
bool m_evm15 = false;
};
}
+4 -39
View File
@@ -26,8 +26,6 @@
#include <libevmasm/Instruction.h>
#include <boost/range/adaptor/reversed.hpp>
using namespace std;
using namespace solidity;
@@ -53,7 +51,6 @@ void NoOutputAssembly::appendLabel(LabelID)
void NoOutputAssembly::appendLabelReference(LabelID)
{
yulAssert(!m_evm15, "Cannot use plain label references in EMV1.5 mode.");
appendInstruction(evmasm::pushInstruction(1));
}
@@ -74,52 +71,20 @@ void NoOutputAssembly::appendLinkerSymbol(string const&)
void NoOutputAssembly::appendJump(int _stackDiffAfter, JumpType)
{
yulAssert(!m_evm15, "Plain JUMP used for EVM 1.5");
appendInstruction(evmasm::Instruction::JUMP);
m_stackHeight += _stackDiffAfter;
}
void NoOutputAssembly::appendJumpTo(LabelID _labelId, int _stackDiffAfter, JumpType _jumpType)
{
if (m_evm15)
m_stackHeight += _stackDiffAfter;
else
{
appendLabelReference(_labelId);
appendJump(_stackDiffAfter, _jumpType);
}
appendLabelReference(_labelId);
appendJump(_stackDiffAfter, _jumpType);
}
void NoOutputAssembly::appendJumpToIf(LabelID _labelId, JumpType)
{
if (m_evm15)
m_stackHeight--;
else
{
appendLabelReference(_labelId);
appendInstruction(evmasm::Instruction::JUMPI);
}
}
void NoOutputAssembly::appendBeginsub(LabelID, int _arguments)
{
yulAssert(m_evm15, "BEGINSUB used for EVM 1.0");
yulAssert(_arguments >= 0, "");
m_stackHeight += _arguments;
}
void NoOutputAssembly::appendJumpsub(LabelID, int _arguments, int _returns)
{
yulAssert(m_evm15, "JUMPSUB used for EVM 1.0");
yulAssert(_arguments >= 0 && _returns >= 0, "");
m_stackHeight += _returns - _arguments;
}
void NoOutputAssembly::appendReturnsub(int _returns, int _stackDiffAfter)
{
yulAssert(m_evm15, "RETURNSUB used for EVM 1.0");
yulAssert(_returns >= 0, "");
m_stackHeight += _stackDiffAfter - _returns;
appendLabelReference(_labelId);
appendInstruction(evmasm::Instruction::JUMPI);
}
void NoOutputAssembly::appendAssemblySize()
+1 -5
View File
@@ -45,7 +45,7 @@ namespace solidity::yul
class NoOutputAssembly: public AbstractAssembly
{
public:
explicit NoOutputAssembly(bool _evm15 = false): m_evm15(_evm15) { }
explicit NoOutputAssembly() { }
~NoOutputAssembly() override = default;
void setSourceLocation(langutil::SourceLocation const&) override {}
@@ -62,9 +62,6 @@ public:
void appendJump(int _stackDiffAfter, JumpType _jumpType) override;
void appendJumpTo(LabelID _labelId, int _stackDiffAfter, JumpType _jumpType) override;
void appendJumpToIf(LabelID _labelId, JumpType _jumpType) override;
void appendBeginsub(LabelID _labelId, int _arguments) override;
void appendJumpsub(LabelID _labelId, int _arguments, int _returns) override;
void appendReturnsub(int _returns, int _stackDiffAfter) override;
void appendAssemblySize() override;
std::pair<std::shared_ptr<AbstractAssembly>, SubID> createSubAssembly(std::string _name = "") override;
@@ -78,7 +75,6 @@ public:
void markAsInvalid() override {}
private:
bool m_evm15 = false; ///< if true, switch to evm1.5 mode
int m_stackHeight = 0;
};