Skip to content

Commit 5865e14

Browse files
committed
eof: Disallow EOF builtins in inline assembly.
1 parent 69058b3 commit 5865e14

File tree

3 files changed

+75
-42
lines changed

3 files changed

+75
-42
lines changed

libyul/backends/evm/EVMDialect.cpp

Lines changed: 44 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -381,50 +381,51 @@ std::vector<std::optional<BuiltinFunctionForEVM>> createBuiltins(langutil::EVMVe
381381
}
382382
else // EOF context
383383
{
384-
builtins.emplace_back(createFunction(
385-
"auxdataloadn",
386-
1,
387-
1,
388-
EVMDialect::sideEffectsOfInstruction(evmasm::Instruction::DATALOADN),
389-
ControlFlowSideEffects::fromInstruction(evmasm::Instruction::DATALOADN),
390-
{LiteralKind::Number},
391-
[](
392-
FunctionCall const& _call,
393-
AbstractAssembly& _assembly,
394-
BuiltinContext&
395-
) {
396-
yulAssert(_call.arguments.size() == 1);
397-
Literal const* literal = std::get_if<Literal>(&_call.arguments.front());
398-
yulAssert(literal, "");
399-
yulAssert(literal->value.value() <= std::numeric_limits<uint16_t>::max());
400-
_assembly.appendAuxDataLoadN(static_cast<uint16_t>(literal->value.value()));
401-
}
402-
));
403-
404-
builtins.emplace_back(createFunction(
405-
"eofcreate",
406-
5,
407-
1,
408-
EVMDialect::sideEffectsOfInstruction(evmasm::Instruction::EOFCREATE),
409-
ControlFlowSideEffects::fromInstruction(evmasm::Instruction::EOFCREATE),
410-
{LiteralKind::String, std::nullopt, std::nullopt, std::nullopt, std::nullopt},
411-
[](
412-
FunctionCall const& _call,
413-
AbstractAssembly& _assembly,
414-
BuiltinContext& context
415-
) {
416-
yulAssert(_call.arguments.size() == 5);
417-
Literal const* literal = std::get_if<Literal>(&_call.arguments.front());
418-
auto const formattedLiteral = formatLiteral(*literal);
419-
yulAssert(!util::contains(formattedLiteral, '.'));
420-
auto const* containerID = valueOrNullptr(context.subIDs, formattedLiteral);
421-
yulAssert(containerID != nullptr);
422-
yulAssert(*containerID <= std::numeric_limits<AbstractAssembly::ContainerID>::max());
423-
_assembly.appendEOFCreate(static_cast<AbstractAssembly::ContainerID>(*containerID));
424-
}
384+
if (_objectAccess)
385+
{
386+
builtins.emplace_back(createFunction(
387+
"auxdataloadn",
388+
1,
389+
1,
390+
EVMDialect::sideEffectsOfInstruction(evmasm::Instruction::DATALOADN),
391+
ControlFlowSideEffects::fromInstruction(evmasm::Instruction::DATALOADN),
392+
{LiteralKind::Number},
393+
[](
394+
FunctionCall const& _call,
395+
AbstractAssembly& _assembly,
396+
BuiltinContext&
397+
) {
398+
yulAssert(_call.arguments.size() == 1);
399+
Literal const* literal = std::get_if<Literal>(&_call.arguments.front());
400+
yulAssert(literal, "");
401+
yulAssert(literal->value.value() <= std::numeric_limits<uint16_t>::max());
402+
_assembly.appendAuxDataLoadN(static_cast<uint16_t>(literal->value.value()));
403+
}
425404
));
426405

427-
if (_objectAccess)
406+
builtins.emplace_back(createFunction(
407+
"eofcreate",
408+
5,
409+
1,
410+
EVMDialect::sideEffectsOfInstruction(evmasm::Instruction::EOFCREATE),
411+
ControlFlowSideEffects::fromInstruction(evmasm::Instruction::EOFCREATE),
412+
{LiteralKind::String, std::nullopt, std::nullopt, std::nullopt, std::nullopt},
413+
[](
414+
FunctionCall const& _call,
415+
AbstractAssembly& _assembly,
416+
BuiltinContext& context
417+
) {
418+
yulAssert(_call.arguments.size() == 5);
419+
Literal const* literal = std::get_if<Literal>(&_call.arguments.front());
420+
auto const formattedLiteral = formatLiteral(*literal);
421+
yulAssert(!util::contains(formattedLiteral, '.'));
422+
auto const* containerID = valueOrNullptr(context.subIDs, formattedLiteral);
423+
yulAssert(containerID != nullptr);
424+
yulAssert(*containerID <= std::numeric_limits<AbstractAssembly::ContainerID>::max());
425+
_assembly.appendEOFCreate(static_cast<AbstractAssembly::ContainerID>(*containerID));
426+
}
427+
));
428+
428429
builtins.emplace_back(createFunction(
429430
"returncontract",
430431
3,
@@ -448,6 +449,7 @@ std::vector<std::optional<BuiltinFunctionForEVM>> createBuiltins(langutil::EVMVe
448449
_assembly.appendReturnContract(static_cast<AbstractAssembly::ContainerID>(*containerID));
449450
}
450451
));
452+
}
451453
}
452454
yulAssert(
453455
ranges::all_of(builtins, [](std::optional<BuiltinFunctionForEVM> const& _builtinFunction){
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
contract C {
2+
function f() view public {
3+
assembly {
4+
eofcreate("a", 0, 0, 0, 0)
5+
returncontract("a", 0)
6+
auxdataloadn(0)
7+
}
8+
}
9+
}
10+
// ====
11+
// bytecodeFormat: legacy
12+
// ----
13+
// DeclarationError 7223: (75-84): Builtin function "eofcreate" is only available in EOF.
14+
// DeclarationError 7223: (114-128): Builtin function "returncontract" is only available in EOF.
15+
// DeclarationError 7223: (149-161): Builtin function "auxdataloadn" is only available in EOF.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// TODO: They should be available in some way in the context of inline assembly. For now it's disallowed them.
2+
contract C {
3+
function f() view public {
4+
assembly {
5+
eofcreate("a", 0, 0, 0, 0)
6+
returncontract("a", 0)
7+
auxdataloadn(0)
8+
}
9+
}
10+
}
11+
// ====
12+
// bytecodeFormat: >=EOFv1
13+
// ----
14+
// DeclarationError 4619: (186-195): Function "eofcreate" not found.
15+
// DeclarationError 4619: (225-239): Function "returncontract" not found.
16+
// DeclarationError 4619: (260-272): Function "auxdataloadn" not found.

0 commit comments

Comments
 (0)