Skip to content

Commit d6e164f

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

15 files changed

+184
-56
lines changed

libyul/backends/evm/EVMDialect.cpp

+1-1
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,
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
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

+1-1
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

+2-4
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.
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.
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
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.
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)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
contract B {}
2+
3+
contract C {
4+
function f() public view {
5+
B b;
6+
assembly {
7+
b := eofcreate(B.objectName, 0, 0, 0, 0)
8+
}
9+
}
10+
11+
function g() public pure {
12+
B b;
13+
assembly {
14+
b := eofcreate(B.objectName, 0, 0, 0, 0)
15+
}
16+
}
17+
18+
}
19+
// ====
20+
// bytecodeFormat: >=EOFv1
21+
// ----
22+
// TypeError 8961: (108-143): Function cannot be declared as view because this expression (potentially) modifies the state.
23+
// TypeError 8961: (241-276): Function cannot be declared as pure because this expression (potentially) modifies the state.

test/libsolidity/syntaxTests/inlineAssembly/storage_reference_on_function.sol

+2
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,7 @@ contract C {
55
}
66
}
77
}
8+
// ====
9+
// bytecodeFormat: legacy
810
// ----
911
// TypeError 7944: (84-90): The suffixes ".offset", ".slot" and ".length" can only be used with variables.

test/libsolidity/syntaxTests/viewPureChecker/eof/inline_assembly_instructions_allowed.sol

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
contract B {}
2+
13
contract C {
24
function f() public {
35
assembly {
@@ -71,6 +73,8 @@ contract C {
7173
pop(tload(0))
7274
tstore(0, 0)
7375

76+
pop(eofcreate(B.objectName, 0, 0, 0, 0))
77+
7478
// NOTE: msize() is allowed only with optimizer disabled
7579
//pop(msize())
7680
}
@@ -79,8 +83,8 @@ contract C {
7983
// ====
8084
// bytecodeFormat: >=EOFv1
8185
// ----
82-
// Warning 2394: (1970-1976): Transient storage as defined by EIP-1153 can break the composability of smart contracts: Since transient storage is cleared only at the end of the transaction and not at the end of the outermost call frame to the contract within a transaction, your contract may unintentionally misbehave when invoked multiple times in a complex transaction. To avoid this, be sure to clear all transient storage at the end of any call to your contract. The use of transient storage for reentrancy guards that are cleared at the end of the call is safe.
83-
// Warning 5740: (89-1400): Unreachable code.
84-
// Warning 5740: (1413-1425): Unreachable code.
85-
// Warning 5740: (1438-1447): Unreachable code.
86-
// Warning 5740: (1460-1982): Unreachable code.
86+
// Warning 2394: (1985-1991): Transient storage as defined by EIP-1153 can break the composability of smart contracts: Since transient storage is cleared only at the end of the transaction and not at the end of the outermost call frame to the contract within a transaction, your contract may unintentionally misbehave when invoked multiple times in a complex transaction. To avoid this, be sure to clear all transient storage at the end of any call to your contract. The use of transient storage for reentrancy guards that are cleared at the end of the call is safe.
87+
// Warning 5740: (104-1415): Unreachable code.
88+
// Warning 5740: (1428-1440): Unreachable code.
89+
// Warning 5740: (1453-1462): Unreachable code.
90+
// Warning 5740: (1475-2051): Unreachable code.

test/libsolidity/syntaxTests/viewPureChecker/eof/inline_assembly_instructions_disallowed.sol

+4-7
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ contract C {
66
memoryguard(0)
77
verbatim_1i_1o(hex"600202", 0)
88

9-
pop(eofcreate("a", 0, 0, 0, 0))
109
returncontract("a", 0, 0, 0)
1110
pop(auxdataloadn(0))
1211

@@ -17,12 +16,10 @@ contract C {
1716
// ====
1817
// bytecodeFormat: >=EOFv1
1918
// ----
20-
// SyntaxError 6553: (184-449): The msize instruction cannot be used when the Yul optimizer is activated because it can change its semantics. Either disable the Yul optimizer or do not use the instruction.
19+
// SyntaxError 6553: (184-405): The msize instruction cannot be used when the Yul optimizer is activated because it can change its semantics. Either disable the Yul optimizer or do not use the instruction.
2120
// DeclarationError 4619: (207-219): Function "linkersymbol" not found.
2221
// DeclarationError 4619: (237-248): Function "memoryguard" not found.
2322
// DeclarationError 4619: (264-278): Function "verbatim_1i_1o" not found.
24-
// DeclarationError 4619: (312-321): Function "eofcreate" not found.
25-
// TypeError 3950: (312-338): Expected expression to evaluate to one value, but got 0 values instead.
26-
// DeclarationError 4619: (352-366): Function "returncontract" not found.
27-
// DeclarationError 4619: (397-409): Function "auxdataloadn" not found.
28-
// TypeError 3950: (397-412): Expected expression to evaluate to one value, but got 0 values instead.
23+
// DeclarationError 4619: (308-322): Function "returncontract" not found.
24+
// DeclarationError 4619: (353-365): Function "auxdataloadn" not found.
25+
// TypeError 3950: (353-368): Expected expression to evaluate to one value, but got 0 values instead.
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
contract B {}
2+
13
contract C {
24
function f() public pure {
35
assembly {
@@ -30,6 +32,7 @@ contract C {
3032
pop(chainid())
3133
pop(basefee())
3234
pop(prevrandao())
35+
pop(eofcreate(B.objectName, 0, 0, 0, 0))
3336

3437
// This one is disallowed too but the error suppresses other errors.
3538
//pop(msize())
@@ -39,33 +42,34 @@ contract C {
3942
// ====
4043
// bytecodeFormat: >=EOFv1
4144
// ----
42-
// Warning 2394: (781-787): Transient storage as defined by EIP-1153 can break the composability of smart contracts: Since transient storage is cleared only at the end of the transaction and not at the end of the outermost call frame to the contract within a transaction, your contract may unintentionally misbehave when invoked multiple times in a complex transaction. To avoid this, be sure to clear all transient storage at the end of any call to your contract. The use of transient storage for reentrancy guards that are cleared at the end of the call is safe.
43-
// TypeError 2527: (79-87): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view".
44-
// TypeError 8961: (101-113): Function cannot be declared as pure because this expression (potentially) modifies the state.
45-
// TypeError 2527: (130-139): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view".
46-
// TypeError 2527: (157-167): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view".
47-
// TypeError 2527: (185-193): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view".
48-
// TypeError 2527: (211-222): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view".
49-
// TypeError 8961: (240-259): Function cannot be declared as pure because this expression (potentially) modifies the state.
50-
// TypeError 2527: (277-299): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view".
51-
// TypeError 8961: (317-341): Function cannot be declared as pure because this expression (potentially) modifies the state.
52-
// TypeError 8961: (355-365): Function cannot be declared as pure because this expression (potentially) modifies the state.
53-
// TypeError 8961: (378-391): Function cannot be declared as pure because this expression (potentially) modifies the state.
54-
// TypeError 8961: (404-420): Function cannot be declared as pure because this expression (potentially) modifies the state.
55-
// TypeError 8961: (433-452): Function cannot be declared as pure because this expression (potentially) modifies the state.
56-
// TypeError 8961: (465-487): Function cannot be declared as pure because this expression (potentially) modifies the state.
57-
// TypeError 2527: (504-512): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view".
58-
// TypeError 2527: (530-540): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view".
59-
// TypeError 2527: (558-570): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view".
60-
// TypeError 2527: (588-598): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view".
61-
// TypeError 2527: (616-627): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view".
62-
// TypeError 2527: (645-653): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view".
63-
// TypeError 2527: (671-681): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view".
64-
// TypeError 2527: (699-710): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view".
65-
// TypeError 2527: (728-741): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view".
66-
// TypeError 2527: (759-767): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view".
67-
// TypeError 8961: (781-793): Function cannot be declared as pure because this expression (potentially) modifies the state.
68-
// TypeError 2527: (810-823): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view".
69-
// TypeError 2527: (841-850): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view".
70-
// TypeError 2527: (868-877): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view".
71-
// TypeError 2527: (895-907): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view".
45+
// Warning 2394: (796-802): Transient storage as defined by EIP-1153 can break the composability of smart contracts: Since transient storage is cleared only at the end of the transaction and not at the end of the outermost call frame to the contract within a transaction, your contract may unintentionally misbehave when invoked multiple times in a complex transaction. To avoid this, be sure to clear all transient storage at the end of any call to your contract. The use of transient storage for reentrancy guards that are cleared at the end of the call is safe.
46+
// TypeError 2527: (94-102): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view".
47+
// TypeError 8961: (116-128): Function cannot be declared as pure because this expression (potentially) modifies the state.
48+
// TypeError 2527: (145-154): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view".
49+
// TypeError 2527: (172-182): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view".
50+
// TypeError 2527: (200-208): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view".
51+
// TypeError 2527: (226-237): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view".
52+
// TypeError 8961: (255-274): Function cannot be declared as pure because this expression (potentially) modifies the state.
53+
// TypeError 2527: (292-314): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view".
54+
// TypeError 8961: (332-356): Function cannot be declared as pure because this expression (potentially) modifies the state.
55+
// TypeError 8961: (370-380): Function cannot be declared as pure because this expression (potentially) modifies the state.
56+
// TypeError 8961: (393-406): Function cannot be declared as pure because this expression (potentially) modifies the state.
57+
// TypeError 8961: (419-435): Function cannot be declared as pure because this expression (potentially) modifies the state.
58+
// TypeError 8961: (448-467): Function cannot be declared as pure because this expression (potentially) modifies the state.
59+
// TypeError 8961: (480-502): Function cannot be declared as pure because this expression (potentially) modifies the state.
60+
// TypeError 2527: (519-527): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view".
61+
// TypeError 2527: (545-555): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view".
62+
// TypeError 2527: (573-585): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view".
63+
// TypeError 2527: (603-613): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view".
64+
// TypeError 2527: (631-642): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view".
65+
// TypeError 2527: (660-668): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view".
66+
// TypeError 2527: (686-696): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view".
67+
// TypeError 2527: (714-725): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view".
68+
// TypeError 2527: (743-756): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view".
69+
// TypeError 2527: (774-782): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view".
70+
// TypeError 8961: (796-808): Function cannot be declared as pure because this expression (potentially) modifies the state.
71+
// TypeError 2527: (825-838): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view".
72+
// TypeError 2527: (856-865): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view".
73+
// TypeError 2527: (883-892): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view".
74+
// TypeError 2527: (910-922): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view".
75+
// TypeError 8961: (940-975): Function cannot be declared as pure because this expression (potentially) modifies the state.

0 commit comments

Comments
 (0)