Skip to content

Commit a613c67

Browse files
committed
eof: Add and update tests.
1 parent d08567c commit a613c67

17 files changed

+229
-56
lines changed

libyul/backends/evm/EVMDialect.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ std::vector<std::optional<BuiltinFunctionForEVM>> createBuiltins(langutil::EVMVe
435435
1,
436436
EVMDialect::sideEffectsOfInstruction(evmasm::Instruction::EOFCREATE),
437437
ControlFlowSideEffects::fromInstruction(evmasm::Instruction::EOFCREATE),
438-
// TODO: Personaly I don't like this solution but cannot find any better way to prevent 9114 error in asm analysis.
438+
// TODO: Personally I don't like this solution but cannot find any better way to prevent 9114 error in asm analysis.
439439
{_objectAccess ? LiteralKind::String : std::optional<LiteralKind>{}, std::nullopt, std::nullopt, std::nullopt, std::nullopt},
440440
[](
441441
FunctionCall const& _call,
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
contract B
2+
{
3+
function f() public returns (uint ret){
4+
ret = 123;
5+
}
6+
}
7+
8+
contract C {
9+
B b;
10+
11+
function f() public {
12+
B t;
13+
assembly {
14+
t := eofcreate(B.objectName, 0, 0, 0, 0)
15+
}
16+
17+
b = t;
18+
}
19+
20+
function run_B_f() public returns (uint) {
21+
return b.f();
22+
}
23+
}
24+
// ====
25+
// bytecodeFormat: >=EOFv1
26+
// ----
27+
// f()
28+
// run_B_f() -> 123
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
library Lib {
2+
struct S {
3+
uint v;
4+
}
5+
function add(uint a, uint b) external pure returns(uint ret) {
6+
ret = a + b;
7+
}
8+
}
9+
10+
interface ILib {
11+
function add(uint a, uint b) external pure returns (uint);
12+
}
13+
14+
contract C {
15+
address addr;
16+
17+
function create_lib() public {
18+
address l;
19+
assembly {
20+
l := eofcreate(Lib.objectName, 0, 0, 0, 0)
21+
22+
}
23+
addr = l;
24+
}
25+
26+
function add() public returns(uint){
27+
return ILib(addr).add(5, 7);
28+
}
29+
}
30+
// ====
31+
// bytecodeFormat: >=EOFv1
32+
// ----
33+
// create_lib()
34+
// add() -> 12
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
contract C {
2+
function f() pure public {
3+
assembly {
4+
let x := f.slot
5+
}
6+
}
7+
}
8+
// ====
9+
// bytecodeFormat: >=EOFv1
10+
// ----
11+
// TypeError 9479: (84-90): The suffixes ".offset", ".slot" and ".length" can only be used with variables or the suffix "objectName" can be used with a contract name identifier.

test/libsolidity/syntaxTests/inlineAssembly/invalid/eof/eof_builtins_disallowed.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ contract C {
1010
// ====
1111
// bytecodeFormat: legacy
1212
// ----
13-
// DeclarationError 7223: (75-84): Builtin function "eofcreate" is only available in EOF.
13+
// TypeError 4328: (75-84): The "eofcreate" instruction is only available in EOF.
1414
// DeclarationError 7223: (114-128): Builtin function "returncontract" is only available in EOF.
1515
// DeclarationError 7223: (149-161): Builtin function "auxdataloadn" is only available in EOF.

test/libsolidity/syntaxTests/inlineAssembly/invalid/eof/eof_builtins_disallowed_in_inline_assembly.sol

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
contract C {
33
function f() view public {
44
assembly {
5-
eofcreate("a", 0, 0, 0, 0)
65
returncontract("a", 0)
76
auxdataloadn(0)
87
}
@@ -11,6 +10,5 @@ contract C {
1110
// ====
1211
// bytecodeFormat: >=EOFv1
1312
// ----
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.
13+
// DeclarationError 4619: (186-200): Function "returncontract" not found.
14+
// DeclarationError 4619: (221-233): Function "auxdataloadn" not found.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
contract B {}
2+
3+
contract C {
4+
function f() public {
5+
B b;
6+
assembly {
7+
b := eofcreate(B.objectId, 0, 0, 0, 0)
8+
}
9+
}
10+
}
11+
// ====
12+
// bytecodeFormat: >=EOFv1
13+
// ----
14+
// DeclarationError 8198: (113-123): Identifier "B.objectId" not found.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
contract B {}
2+
3+
contract C {
4+
function f() public {
5+
B b;
6+
assembly {
7+
b := eofcreate(B.objectName, 0, 0, 0, 0)
8+
}
9+
}
10+
}
11+
// ====
12+
// bytecodeFormat: >=EOFv1
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
contract C {
2+
uint s;
3+
function f() public {
4+
uint b;
5+
assembly {
6+
b := s.objectName
7+
b := b.objectName
8+
}
9+
}
10+
}
11+
// ====
12+
// bytecodeFormat: >=EOFv1
13+
// ----
14+
// TypeError 4656: (103-115): State variables only support ".slot" and ".offset".
15+
// TypeError 3622: (133-145): The suffix ".objectName" is not supported by this variable or type.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
contract B {}
2+
3+
contract C {
4+
function f() public {
5+
B b;
6+
assembly {
7+
b := eofcreate(B.objectName, 0, 0, 0, 0)
8+
}
9+
}
10+
}
11+
// ====
12+
// bytecodeFormat: legacy
13+
// ----
14+
// TypeError 4328: (103-112): The "eofcreate" instruction is only available in EOF.
15+
// TypeError 1342: (113-125): ".objectName" suffix is supported only for contract name identifier when compiling to EOF.
16+
// DeclarationError 8678: (98-138): Variable count for assignment to "b" does not match number of values (1 vs. 0)

0 commit comments

Comments
 (0)