Skip to content

Commit cab035d

Browse files
test(mxp): add failing tests for debugging purposes
1 parent 1f3d4ca commit cab035d

File tree

2 files changed

+110
-1
lines changed

2 files changed

+110
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/*
2+
* Copyright ConsenSys Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
5+
* the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
10+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11+
* specific language governing permissions and limitations under the License.
12+
*
13+
* SPDX-License-Identifier: Apache-2.0
14+
*/
15+
16+
package net.consensys.linea.zktracer.module.hub;
17+
18+
import java.util.List;
19+
20+
import net.consensys.linea.testing.BytecodeCompiler;
21+
import net.consensys.linea.testing.BytecodeRunner;
22+
import net.consensys.linea.testing.ToyAccount;
23+
import net.consensys.linea.zktracer.opcode.OpCode;
24+
import org.hyperledger.besu.datatypes.Address;
25+
import org.hyperledger.besu.datatypes.Wei;
26+
import org.junit.jupiter.api.Test;
27+
28+
public class ZeroSizeCallDataOrReturnDataTest {
29+
30+
@Test
31+
void zeroSizeHugeReturnAtOffsetTest() {
32+
BytecodeCompiler program = BytecodeCompiler.newProgram();
33+
program
34+
.push(0)
35+
.push("ff".repeat(32)) // return data offset
36+
.push(0)
37+
.push(0)
38+
.push("ca11ee") // address
39+
.push(1000) // gas
40+
.op(OpCode.STATICCALL);
41+
42+
BytecodeCompiler calleeProgram = BytecodeCompiler.newProgram();
43+
calleeProgram.op(OpCode.CALLDATASIZE);
44+
45+
final ToyAccount calleeAccount =
46+
ToyAccount.builder()
47+
.balance(Wei.fromEth(1))
48+
.nonce(10)
49+
.address(Address.fromHexString("ca11ee"))
50+
.code(calleeProgram.compile())
51+
.build();
52+
53+
BytecodeRunner.of(program.compile()).run(Wei.fromEth(1), 30000L, List.of(calleeAccount));
54+
// TODO: this test is supposed to fail as the ones below, but it does not. Understand why
55+
}
56+
57+
@Test
58+
void zeroSizeHugeCallDataOffsetTest() {
59+
BytecodeCompiler program = BytecodeCompiler.newProgram();
60+
program
61+
.push(0)
62+
.push(0)
63+
.push(0)
64+
.push("ff".repeat(32)) // call data offset
65+
.push("ca11ee") // address
66+
.push(1000) // gas
67+
.op(OpCode.STATICCALL);
68+
69+
BytecodeCompiler calleeProgram = BytecodeCompiler.newProgram();
70+
calleeProgram.op(OpCode.CALLDATASIZE);
71+
72+
final ToyAccount calleeAccount =
73+
ToyAccount.builder()
74+
.balance(Wei.fromEth(1))
75+
.nonce(10)
76+
.address(Address.fromHexString("ca11ee"))
77+
.code(calleeProgram.compile())
78+
.build();
79+
80+
BytecodeRunner.of(program.compile()).run(Wei.fromEth(1), 30000L, List.of(calleeAccount));
81+
}
82+
83+
@Test
84+
void zeroSizeHugeReturnDataOffsetTest() {
85+
BytecodeCompiler program = BytecodeCompiler.newProgram();
86+
program
87+
.push(0)
88+
.push(0)
89+
.push(0)
90+
.push(0)
91+
.push("ca11ee") // address
92+
.push(1000) // gas
93+
.op(OpCode.STATICCALL);
94+
95+
BytecodeCompiler calleeProgram = BytecodeCompiler.newProgram();
96+
calleeProgram.push(0).push("ff".repeat(32)).op(OpCode.RETURN);
97+
98+
final ToyAccount calleeAccount =
99+
ToyAccount.builder()
100+
.balance(Wei.fromEth(1))
101+
.nonce(10)
102+
.address(Address.fromHexString("ca11ee"))
103+
.code(calleeProgram.compile())
104+
.build();
105+
106+
BytecodeRunner.of(program.compile()).run(Wei.fromEth(1), 30000L, List.of(calleeAccount));
107+
}
108+
}

arithmetization/src/test/java/net/consensys/linea/zktracer/module/mxp/MxpTest.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,8 @@ private void triggerNonTrivialOrNoop(BytecodeCompiler program, boolean isHalting
419419
appendOpCodeCall(List.of(value, offset1), opCode, program);
420420
break;
421421
case LOG0, SHA3, RETURN, REVERT: // RETURN and REVERT are selected only when isHalting is true
422-
System.out.println(opCode + " size: " + size1.toBigInteger() + " offset: " + offset1.toBigInteger());
422+
System.out.println(
423+
opCode + " size: " + size1.toBigInteger() + " offset: " + offset1.toBigInteger());
423424
appendOpCodeCall(List.of(size1, offset1), opCode, program);
424425
if (opCode == OpCode.SHA3) {
425426
program.op(OpCode.POP);

0 commit comments

Comments
 (0)