Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eof: Syntax tests update #15661

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion libevmasm/Assembly.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1660,7 +1660,14 @@ LinkerObject const& Assembly::assembleEOF() const

ptrdiff_t const relativeJumpOffset = static_cast<ptrdiff_t>(tagPos) - (static_cast<ptrdiff_t>(refPos) + 2);
// This cannot happen in practice because we'll run into section size limit first.
solAssert(-0x8000 <= relativeJumpOffset && relativeJumpOffset <= 0x7FFF, "Relative jump too far");
if (!(-0x8000 <= relativeJumpOffset && relativeJumpOffset <= 0x7FFF))
// TODO: Include source location. Note that origin locations we have in debug data are
// not usable for error reporting when compiling pure Yul because they point at the optimized source.
throw Error(
2703_error,
Error::Type::CodeGenerationError,
"Relative jump too far"
);
solAssert(relativeJumpOffset < -2 || 0 <= relativeJumpOffset, "Relative jump offset into immediate argument.");
setBigEndianUint16(ret.bytecode, refPos, static_cast<size_t>(static_cast<uint16_t>(relativeJumpOffset)));
}
Expand Down
14 changes: 14 additions & 0 deletions libsolidity/codegen/ir/IRGeneratorForStatements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1529,6 +1529,15 @@ void IRGeneratorForStatements::endVisit(FunctionCall const& _functionCall)
case FunctionType::Kind::BlockHash:
case FunctionType::Kind::BlobHash:
{
solAssert(
!m_context.eofVersion().has_value() || functionType->kind() != FunctionType::Kind::GasLeft,
"EOF does not support gasleft."
);
solAssert(
!m_context.eofVersion().has_value() || functionType->kind() != FunctionType::Kind::Selfdestruct,
"EOF does not support selfdestruct."
);

static std::map<FunctionType::Kind, std::string> functions = {
{FunctionType::Kind::GasLeft, "gas"},
{FunctionType::Kind::Selfdestruct, "selfdestruct"},
Expand Down Expand Up @@ -1845,6 +1854,7 @@ void IRGeneratorForStatements::endVisit(MemberAccess const& _memberAccess)
")\n";
else if (member == "code")
{
solAssert(!m_context.eofVersion().has_value(), "EOF does not support address.code.");
std::string externalCodeFunction = m_utils.externalCodeFunction();
define(_memberAccess) <<
externalCodeFunction <<
Expand All @@ -1853,10 +1863,13 @@ void IRGeneratorForStatements::endVisit(MemberAccess const& _memberAccess)
")\n";
}
else if (member == "codehash")
{
solAssert(!m_context.eofVersion().has_value(), "EOF does not support address.codehash.");
define(_memberAccess) <<
"extcodehash(" <<
expressionAsType(_memberAccess.expression(), *TypeProvider::address()) <<
")\n";
}
else if (std::set<std::string>{"send", "transfer"}.count(member))
{
solAssert(dynamic_cast<AddressType const&>(*_memberAccess.expression().annotation().type).stateMutability() == StateMutability::Payable);
Expand Down Expand Up @@ -1973,6 +1986,7 @@ void IRGeneratorForStatements::endVisit(MemberAccess const& _memberAccess)
solAssert(false, "Blockhash has been removed.");
else if (member == "creationCode" || member == "runtimeCode")
{
solAssert(!m_context.eofVersion().has_value(), "EOF does not support \"" + member + "\".");
Type const* arg = dynamic_cast<MagicType const&>(*_memberAccess.expression().annotation().type).typeArgument();
auto const& contractType = dynamic_cast<ContractType const&>(*arg);
solAssert(!contractType.isSuper());
Expand Down
7 changes: 4 additions & 3 deletions libyul/AsmAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -690,21 +690,22 @@ void AsmAnalyzer::expectValidIdentifier(YulName _identifier, SourceLocation cons
bool AsmAnalyzer::validateInstructions(std::string_view _instructionIdentifier, langutil::SourceLocation const& _location)
{
// NOTE: This function uses the default EVM version instead of the currently selected one.
auto const& defaultEVMDialect = EVMDialect::strictAssemblyForEVM(EVMVersion{}, std::nullopt);
auto const& defaultEVMDialect = EVMDialect::strictAssemblyForEVMObjects(EVMVersion{}, std::nullopt);
auto const builtinHandle = defaultEVMDialect.findBuiltin(_instructionIdentifier);
if (builtinHandle && defaultEVMDialect.builtin(*builtinHandle).instruction.has_value())
return validateInstructions(*defaultEVMDialect.builtin(*builtinHandle).instruction, _location);

solAssert(!m_eofVersion.has_value() || (*m_eofVersion == 1 && m_evmVersion == langutil::EVMVersion::prague()));
// TODO: Change `prague()` to `EVMVersion{}` once EOF gets deployed
auto const& eofDialect = EVMDialect::strictAssemblyForEVM(EVMVersion::prague(), 1);
auto const& eofDialect = EVMDialect::strictAssemblyForEVMObjects(EVMVersion::prague(), 1);
auto const eofBuiltinHandle = eofDialect.findBuiltin(_instructionIdentifier);
if (eofBuiltinHandle)
{
auto const builtin = eofDialect.builtin(*eofBuiltinHandle);
if (builtin.instruction.has_value())
return validateInstructions(*builtin.instruction, _location);
else if (!m_eofVersion.has_value())
// If builtin is avavailable in EOF but not available in legacy (and we build to legacy) generate custom error.
else if (!m_eofVersion.has_value() && !builtinHandle)
{
m_errorReporter.declarationError(
7223_error,
Expand Down
86 changes: 44 additions & 42 deletions libyul/backends/evm/EVMDialect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,50 +381,51 @@ std::vector<std::optional<BuiltinFunctionForEVM>> createBuiltins(langutil::EVMVe
}
else // EOF context
{
builtins.emplace_back(createFunction(
"auxdataloadn",
1,
1,
EVMDialect::sideEffectsOfInstruction(evmasm::Instruction::DATALOADN),
ControlFlowSideEffects::fromInstruction(evmasm::Instruction::DATALOADN),
{LiteralKind::Number},
[](
FunctionCall const& _call,
AbstractAssembly& _assembly,
BuiltinContext&
) {
yulAssert(_call.arguments.size() == 1);
Literal const* literal = std::get_if<Literal>(&_call.arguments.front());
yulAssert(literal, "");
yulAssert(literal->value.value() <= std::numeric_limits<uint16_t>::max());
_assembly.appendAuxDataLoadN(static_cast<uint16_t>(literal->value.value()));
}
));

builtins.emplace_back(createFunction(
"eofcreate",
5,
1,
EVMDialect::sideEffectsOfInstruction(evmasm::Instruction::EOFCREATE),
ControlFlowSideEffects::fromInstruction(evmasm::Instruction::EOFCREATE),
{LiteralKind::String, std::nullopt, std::nullopt, std::nullopt, std::nullopt},
[](
FunctionCall const& _call,
AbstractAssembly& _assembly,
BuiltinContext& context
) {
yulAssert(_call.arguments.size() == 5);
Literal const* literal = std::get_if<Literal>(&_call.arguments.front());
auto const formattedLiteral = formatLiteral(*literal);
yulAssert(!util::contains(formattedLiteral, '.'));
auto const* containerID = valueOrNullptr(context.subIDs, formattedLiteral);
yulAssert(containerID != nullptr);
yulAssert(*containerID <= std::numeric_limits<AbstractAssembly::ContainerID>::max());
_assembly.appendEOFCreate(static_cast<AbstractAssembly::ContainerID>(*containerID));
}
if (_objectAccess)
{
builtins.emplace_back(createFunction(
"auxdataloadn",
1,
1,
EVMDialect::sideEffectsOfInstruction(evmasm::Instruction::DATALOADN),
ControlFlowSideEffects::fromInstruction(evmasm::Instruction::DATALOADN),
{LiteralKind::Number},
[](
FunctionCall const& _call,
AbstractAssembly& _assembly,
BuiltinContext&
) {
yulAssert(_call.arguments.size() == 1);
Literal const* literal = std::get_if<Literal>(&_call.arguments.front());
yulAssert(literal, "");
yulAssert(literal->value.value() <= std::numeric_limits<uint16_t>::max());
_assembly.appendAuxDataLoadN(static_cast<uint16_t>(literal->value.value()));
}
));

if (_objectAccess)
builtins.emplace_back(createFunction(
"eofcreate",
5,
1,
EVMDialect::sideEffectsOfInstruction(evmasm::Instruction::EOFCREATE),
ControlFlowSideEffects::fromInstruction(evmasm::Instruction::EOFCREATE),
{LiteralKind::String, std::nullopt, std::nullopt, std::nullopt, std::nullopt},
[](
FunctionCall const& _call,
AbstractAssembly& _assembly,
BuiltinContext& context
) {
yulAssert(_call.arguments.size() == 5);
Literal const* literal = std::get_if<Literal>(&_call.arguments.front());
auto const formattedLiteral = formatLiteral(*literal);
yulAssert(!util::contains(formattedLiteral, '.'));
auto const* containerID = valueOrNullptr(context.subIDs, formattedLiteral);
yulAssert(containerID != nullptr);
yulAssert(*containerID <= std::numeric_limits<AbstractAssembly::ContainerID>::max());
_assembly.appendEOFCreate(static_cast<AbstractAssembly::ContainerID>(*containerID));
}
));

builtins.emplace_back(createFunction(
"returncontract",
3,
Expand All @@ -448,6 +449,7 @@ std::vector<std::optional<BuiltinFunctionForEVM>> createBuiltins(langutil::EVMVe
_assembly.appendReturnContract(static_cast<AbstractAssembly::ContainerID>(*containerID));
}
));
}
}
yulAssert(
ranges::all_of(builtins, [](std::optional<BuiltinFunctionForEVM> const& _builtinFunction){
Expand Down
4 changes: 3 additions & 1 deletion test/libsolidity/SyntaxTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ SyntaxTest::SyntaxTest(
{
static std::set<std::string> const compileViaYulAllowedValues{"true", "false"};

m_compileViaYul = m_reader.stringSetting("compileViaYul", "false");
auto const eofEnabled = solidity::test::CommonOptions::get().eofVersion().has_value();

m_compileViaYul = m_reader.stringSetting("compileViaYul", eofEnabled ? "true" : "false");
if (!util::contains(compileViaYulAllowedValues, m_compileViaYul))
BOOST_THROW_EXCEPTION(std::runtime_error("Invalid compileViaYul value: " + m_compileViaYul + "."));
m_optimiseYul = m_reader.boolSetting("optimize-yul", true);
Expand Down
13 changes: 13 additions & 0 deletions test/libsolidity/semanticTests/array/nested_calldata_storage.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
pragma abicoder v2;

contract C {
uint[][2] public tmp_i;
function i(uint[][2] calldata s) external { tmp_i = s; }
}
// ====
// compileViaYul: true
// ----
// i(uint256[][2]): 0x20, 0x40, 0xC0, 3, 0x0A01, 0x0A02, 0x0A03, 4, 0x0B01, 0x0B02, 0x0B03, 0x0B04
// gas irOptimized: 223100
// tmp_i(uint256,uint256): 0, 0 -> 0x0A01
// tmp_i(uint256,uint256): 1, 0 -> 0x0B01
13 changes: 13 additions & 0 deletions test/libsolidity/semanticTests/array/nested_calldata_storage2.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
pragma abicoder v2;

contract C {
uint[][] public tmp_i;
function i(uint[][] calldata s) external { tmp_i = s; }
}
// ====
// compileViaYul: true
// ----
// i(uint256[][]): 0x20, 2, 0x40, 0xC0, 3, 0x0A01, 0x0A02, 0x0A03, 4, 0x0B01, 0x0B02, 0x0B03, 0x0B04
// gas irOptimized: 245506
// tmp_i(uint256,uint256): 0, 0 -> 0x0A01
// tmp_i(uint256,uint256): 1, 0 -> 0x0B01
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ contract D {
return a + b;
}
}
// ====
// bytecodeFormat: legacy
// ----
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@ contract Test {
L.set(item);
}
}
// ====
// bytecodeFormat: legacy
// ----
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@ contract Test {
L.get(item);
}
}
// ====
// bytecodeFormat: legacy
// ----
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@ contract C is B {
validate()
{}
}
// ====
// bytecodeFormat: legacy
// ----
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,6 @@ import "B";
contract D is C {
constructor() validate B() validate C() validate {}
}
// ====
// bytecodeFormat: legacy
// ----
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ pragma abicoder v1;
import "A";

contract C is B {}
// ====
// bytecodeFormat: legacy
// ----
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ pragma abicoder v1;
import "A";

contract D is C {}
// ====
// bytecodeFormat: legacy
// ----
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@ pragma abicoder v1;
import "A";

contract D is C {}
// ====
// bytecodeFormat: legacy
// ----
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,6 @@ contract C is B {
_;
}
}
// ====
// bytecodeFormat: legacy
// ----
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,6 @@ struct Data {
contract X {
function get() public view returns (Data memory) {}
}
// ====
// bytecodeFormat: legacy
// ----
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ contract C {
function i(uint[][2] calldata s) external { tmp_i = s; }
}

// ====
// compileViaYul: false
// ----
// UnimplementedFeatureError 1834: (35-127): Copying nested calldata dynamic arrays to storage is not implemented in the old code generator.
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ contract C {
function i(uint[][] calldata s) external { tmp_i = s; }
}

// ====
// compileViaYul: false
// ----
// UnimplementedFeatureError 1834: (35-125): Copying nested calldata dynamic arrays to storage is not implemented in the old code generator.
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@ library L2 {
contract A {
function f() public pure { type(L2).creationCode; }
cameel marked this conversation as resolved.
Show resolved Hide resolved
}
// ====
// bytecodeFormat: legacy
// ----
// Warning 6133: (157-178): Statement has no effect.
4 changes: 3 additions & 1 deletion test/libsolidity/syntaxTests/constants/mod_div_rational.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ contract C {
fixed a3 = 0 / 0.123;
fixed a4 = 0 / -0.123;
}
// ====
// compileViaYul: true
// ----
// UnimplementedFeatureError 1834: (0-150): Not yet implemented - FixedPointType.
// UnimplementedFeatureError 1834: (28-53): Fixed point types not implemented.
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ pragma abicoder v1;
abstract contract C {
constructor(uint[][][] memory t) {}
}
// ====
// bytecodeFormat: legacy
// ----
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ contract C {
// ====
// EVMVersion: >=constantinople
// compileViaYul: true
// bytecodeFormat: legacy
// ----
// Warning 2264: (0-29): Experimental features are turned on. Do not use experimental features on live deployments.
// Info 4164: (31-61): Inferred type: void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ contract C
// ====
// EVMVersion: >=constantinople
// compileViaYul: true
// bytecodeFormat: legacy
// ----
// Warning 2264: (std.stub:63-92): Experimental features are turned on. Do not use experimental features on live deployments.
// Warning 2264: (0-29): Experimental features are turned on. Do not use experimental features on live deployments.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ contract C {
}
}
// ====
// bytecodeFormat: legacy
// ====
// EVMVersion: >=constantinople
// ----
// TypeError 9886: (78-101): Duplicate option "gas".
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ contract C {
address(10).delegatecall{value: 7, gas: 3}("");
}
}
// ====
// bytecodeFormat: legacy
// ----
// TypeError 6189: (56-98): Cannot set option "value" for delegatecall.
// Warning 9302: (56-102): Return value of low-level calls not used.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ contract C {
}
// ====
// EVMVersion: >=byzantium
// bytecodeFormat: legacy
// ----
// TypeError 2842: (56-96): Cannot set option "value" for staticcall.
// Warning 9302: (56-100): Return value of low-level calls not used.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ contract C {
}
// ====
// EVMVersion: >=constantinople
// bytecodeFormat: legacy
// ----
// TypeError 1645: (78-110): Function call options have already been set, you have to combine them into a single {...}-option.
// TypeError 1645: (120-154): Function call options have already been set, you have to combine them into a single {...}-option.
Expand Down
Loading