From d5a44f31f465397171465cdc7588f32b2fe7f300 Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Tue, 22 Oct 2024 16:52:25 +0200 Subject: [PATCH 01/11] test(mxp): add testMxpRandomAdvancedWithFixedSeed --- .../linea/zktracer/module/mxp/MxpTest.java | 52 +++++++++++++++---- 1 file changed, 42 insertions(+), 10 deletions(-) diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/mxp/MxpTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/mxp/MxpTest.java index ba70e798f0..812c297333 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/mxp/MxpTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/mxp/MxpTest.java @@ -40,15 +40,19 @@ import org.hyperledger.besu.datatypes.TransactionType; import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.core.Transaction; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.parallel.Execution; import org.junit.jupiter.api.parallel.ExecutionMode; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; // https://github.com/Consensys/linea-besu-plugin/issues/197 @Execution(ExecutionMode.SAME_THREAD) public class MxpTest { - private static final Random RAND = new Random(123456789123456L); + private Random RAND; public static final EWord TWO_POW_128 = EWord.of(EWord.ONE.shiftLeft(128)); public static final EWord TWO_POW_32 = EWord.of(EWord.ONE.shiftLeft(32)); @@ -74,6 +78,13 @@ public class MxpTest { final OpCode[] opCodesHalting = new OpCode[] {OpCode.RETURN, OpCode.REVERT}; + @BeforeEach + void init() { + // The random generator is re-initialized before each test so to do not make them + // order-dependent + RAND = new Random(123456789123456L); + } + @Test void testMxpMinimalNonEmptyReturn() { BytecodeRunner.of(Bytes.fromHexString("6101006000f3")).run(); @@ -181,18 +192,42 @@ void testMxpxOrRoob() { @Test void testMxpRandomAdvanced() { - // Testing a random program that contains creates with meaning random arguments - Bytes INIT = getRandomINITForCreate(); // This is the value given as an argument to CREATE + // Testing a random program that contains creates with meaningful random arguments + Bytes INIT = getRandomINITForCreate(256); // This is the value given as an argument to CREATE BytecodeCompiler program = BytecodeCompiler.newProgram(); - int instructionCount = 256; - for (int i = 0; i < instructionCount; i++) { - boolean isHalting = i == instructionCount - 1; + int INSTRUCTION_COUNT = 256; + for (int i = 0; i < INSTRUCTION_COUNT; i++) { + boolean isHalting = i == INSTRUCTION_COUNT - 1; triggerNonTrivialOrNoop(program, isHalting, INIT); } BytecodeRunner.of(program.compile()).run(); } + @ParameterizedTest + @MethodSource("testMxpRandomAdvancedSource") + void testMxpRandomAdvancedWithFixedSeed( + long SEED, int INSTRUCTION_COUNT_INIT, int INSTRUCTION_COUNT) { + // Overwrite the class-level random generator with a new one with a fixed seed + RAND = new Random(SEED); + // Testing a random program that contains creates with meaningful random arguments + Bytes INIT = + getRandomINITForCreate( + INSTRUCTION_COUNT_INIT); // This is the value given as an argument to CREATE + + BytecodeCompiler program = BytecodeCompiler.newProgram(); + for (int i = 0; i < INSTRUCTION_COUNT; i++) { + boolean isHalting = i == INSTRUCTION_COUNT - 1; + triggerNonTrivialOrNoop(program, isHalting, INIT); + } + BytecodeRunner.of(program.compile()).run(); + } + + private static Stream testMxpRandomAdvancedSource() { + // Failing test cases + return Stream.of(Arguments.of(166L, 3, 2), Arguments.of(44L, 3, 3), Arguments.of(244L, 5, 5)); + } + @Test void testCall() { /* NOTE: The contracts in this test are compiled by using @@ -302,8 +337,7 @@ void testCall() { } // Support methods - private Bytes getRandomINITForCreate() { - final int INSTRUCTION_COUNT_INIT = 256; + private Bytes getRandomINITForCreate(final int INSTRUCTION_COUNT_INIT) { BytecodeCompiler INIT = BytecodeCompiler.newProgram(); for (int i = 0; i < INSTRUCTION_COUNT_INIT; i++) { boolean isHalting = i == INSTRUCTION_COUNT_INIT - 1; @@ -548,9 +582,7 @@ private void triggerNonTrivialButMxpxOrRoob( } private boolean isRoob(MxpType randomMxpType, EWord size1, EWord offset1) { - final boolean condition4And5 = offset1.compareTo(TWO_POW_128) >= 0 && !size1.isZero(); - return switch (randomMxpType) { case TYPE_2, TYPE_3 -> offset1.compareTo(TWO_POW_128) >= 0; case TYPE_4 -> size1.compareTo(TWO_POW_128) >= 0 || condition4And5; From 6f4a136a49489e1593f7b607838fb8d98d103c86 Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Tue, 22 Oct 2024 21:21:03 +0200 Subject: [PATCH 02/11] fix(mxp): filter out RETURN and REVERT when testing against large offsets --- .../net/consensys/linea/zktracer/module/mxp/MxpTest.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/mxp/MxpTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/mxp/MxpTest.java index 812c297333..c35b7a12cb 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/mxp/MxpTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/mxp/MxpTest.java @@ -381,7 +381,10 @@ private void triggerNonTrivialOrNoop(BytecodeCompiler program, boolean isHalting offset2 = EWord.of(getRandomBigIntegerByBytesSize(0, MAX_BYTE_SIZE)); // NOOP case (except for Type2 and Type3 instructions) - if (mxpType != MxpType.TYPE_2 && mxpType != MxpType.TYPE_3) { + if (mxpType != MxpType.TYPE_2 + && mxpType != MxpType.TYPE_3 + && opCode != OpCode.RETURN + && opCode != OpCode.REVERT) { // TODO: double check filtering out RETURN and REVERT is correct if (RAND.nextFloat() < NOOP_PROB) { // One or both of the size parameters are equal to 0 (each scenario has the same // probability) From 0fd68d219b3edd41dd337216e13e70ec7c124fe0 Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Tue, 22 Oct 2024 21:44:46 +0200 Subject: [PATCH 03/11] fix(mxp): revert wrong fix --- .../net/consensys/linea/zktracer/module/mxp/MxpTest.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/mxp/MxpTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/mxp/MxpTest.java index c35b7a12cb..b29b7fe9a9 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/mxp/MxpTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/mxp/MxpTest.java @@ -381,10 +381,7 @@ private void triggerNonTrivialOrNoop(BytecodeCompiler program, boolean isHalting offset2 = EWord.of(getRandomBigIntegerByBytesSize(0, MAX_BYTE_SIZE)); // NOOP case (except for Type2 and Type3 instructions) - if (mxpType != MxpType.TYPE_2 - && mxpType != MxpType.TYPE_3 - && opCode != OpCode.RETURN - && opCode != OpCode.REVERT) { // TODO: double check filtering out RETURN and REVERT is correct + if (mxpType != MxpType.TYPE_2 && mxpType != MxpType.TYPE_3) { if (RAND.nextFloat() < NOOP_PROB) { // One or both of the size parameters are equal to 0 (each scenario has the same // probability) @@ -422,6 +419,7 @@ private void triggerNonTrivialOrNoop(BytecodeCompiler program, boolean isHalting appendOpCodeCall(List.of(value, offset1), opCode, program); break; case LOG0, SHA3, RETURN, REVERT: // RETURN and REVERT are selected only when isHalting is true + System.out.println("size: " + size1.toBigInteger() + " offset: " + offset1.toBigInteger()); appendOpCodeCall(List.of(size1, offset1), opCode, program); if (opCode == OpCode.SHA3) { program.op(OpCode.POP); From 1f3d4caba5ff44e70191ea15ecae0174f38be216 Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Tue, 22 Oct 2024 22:05:37 +0200 Subject: [PATCH 04/11] test(mxp): add print --- .../java/net/consensys/linea/zktracer/module/mxp/MxpTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/mxp/MxpTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/mxp/MxpTest.java index b29b7fe9a9..a86e2a63ed 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/mxp/MxpTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/mxp/MxpTest.java @@ -419,7 +419,7 @@ private void triggerNonTrivialOrNoop(BytecodeCompiler program, boolean isHalting appendOpCodeCall(List.of(value, offset1), opCode, program); break; case LOG0, SHA3, RETURN, REVERT: // RETURN and REVERT are selected only when isHalting is true - System.out.println("size: " + size1.toBigInteger() + " offset: " + offset1.toBigInteger()); + System.out.println(opCode + " size: " + size1.toBigInteger() + " offset: " + offset1.toBigInteger()); appendOpCodeCall(List.of(size1, offset1), opCode, program); if (opCode == OpCode.SHA3) { program.op(OpCode.POP); From cab035d5eef415af7cb0c007bdd569e92aa4ffc5 Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Tue, 22 Oct 2024 22:43:53 +0200 Subject: [PATCH 05/11] test(mxp): add failing tests for debugging purposes --- .../hub/ZeroSizeCallDataOrReturnDataTest.java | 108 ++++++++++++++++++ .../linea/zktracer/module/mxp/MxpTest.java | 3 +- 2 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/ZeroSizeCallDataOrReturnDataTest.java diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/ZeroSizeCallDataOrReturnDataTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/ZeroSizeCallDataOrReturnDataTest.java new file mode 100644 index 0000000000..87023b3d34 --- /dev/null +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/ZeroSizeCallDataOrReturnDataTest.java @@ -0,0 +1,108 @@ +/* + * Copyright ConsenSys Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +package net.consensys.linea.zktracer.module.hub; + +import java.util.List; + +import net.consensys.linea.testing.BytecodeCompiler; +import net.consensys.linea.testing.BytecodeRunner; +import net.consensys.linea.testing.ToyAccount; +import net.consensys.linea.zktracer.opcode.OpCode; +import org.hyperledger.besu.datatypes.Address; +import org.hyperledger.besu.datatypes.Wei; +import org.junit.jupiter.api.Test; + +public class ZeroSizeCallDataOrReturnDataTest { + + @Test + void zeroSizeHugeReturnAtOffsetTest() { + BytecodeCompiler program = BytecodeCompiler.newProgram(); + program + .push(0) + .push("ff".repeat(32)) // return data offset + .push(0) + .push(0) + .push("ca11ee") // address + .push(1000) // gas + .op(OpCode.STATICCALL); + + BytecodeCompiler calleeProgram = BytecodeCompiler.newProgram(); + calleeProgram.op(OpCode.CALLDATASIZE); + + final ToyAccount calleeAccount = + ToyAccount.builder() + .balance(Wei.fromEth(1)) + .nonce(10) + .address(Address.fromHexString("ca11ee")) + .code(calleeProgram.compile()) + .build(); + + BytecodeRunner.of(program.compile()).run(Wei.fromEth(1), 30000L, List.of(calleeAccount)); + // TODO: this test is supposed to fail as the ones below, but it does not. Understand why + } + + @Test + void zeroSizeHugeCallDataOffsetTest() { + BytecodeCompiler program = BytecodeCompiler.newProgram(); + program + .push(0) + .push(0) + .push(0) + .push("ff".repeat(32)) // call data offset + .push("ca11ee") // address + .push(1000) // gas + .op(OpCode.STATICCALL); + + BytecodeCompiler calleeProgram = BytecodeCompiler.newProgram(); + calleeProgram.op(OpCode.CALLDATASIZE); + + final ToyAccount calleeAccount = + ToyAccount.builder() + .balance(Wei.fromEth(1)) + .nonce(10) + .address(Address.fromHexString("ca11ee")) + .code(calleeProgram.compile()) + .build(); + + BytecodeRunner.of(program.compile()).run(Wei.fromEth(1), 30000L, List.of(calleeAccount)); + } + + @Test + void zeroSizeHugeReturnDataOffsetTest() { + BytecodeCompiler program = BytecodeCompiler.newProgram(); + program + .push(0) + .push(0) + .push(0) + .push(0) + .push("ca11ee") // address + .push(1000) // gas + .op(OpCode.STATICCALL); + + BytecodeCompiler calleeProgram = BytecodeCompiler.newProgram(); + calleeProgram.push(0).push("ff".repeat(32)).op(OpCode.RETURN); + + final ToyAccount calleeAccount = + ToyAccount.builder() + .balance(Wei.fromEth(1)) + .nonce(10) + .address(Address.fromHexString("ca11ee")) + .code(calleeProgram.compile()) + .build(); + + BytecodeRunner.of(program.compile()).run(Wei.fromEth(1), 30000L, List.of(calleeAccount)); + } +} diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/mxp/MxpTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/mxp/MxpTest.java index a86e2a63ed..f08cb20808 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/mxp/MxpTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/mxp/MxpTest.java @@ -419,7 +419,8 @@ private void triggerNonTrivialOrNoop(BytecodeCompiler program, boolean isHalting appendOpCodeCall(List.of(value, offset1), opCode, program); break; case LOG0, SHA3, RETURN, REVERT: // RETURN and REVERT are selected only when isHalting is true - System.out.println(opCode + " size: " + size1.toBigInteger() + " offset: " + offset1.toBigInteger()); + System.out.println( + opCode + " size: " + size1.toBigInteger() + " offset: " + offset1.toBigInteger()); appendOpCodeCall(List.of(size1, offset1), opCode, program); if (opCode == OpCode.SHA3) { program.op(OpCode.POP); From 8833f5ad8291978bcd9dd0cf74812b3372b58c7e Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Wed, 23 Oct 2024 13:35:34 +0200 Subject: [PATCH 06/11] fix: OperationAncillaries outputDataSpan --- .../zktracer/module/hub/transients/OperationAncillaries.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/OperationAncillaries.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/OperationAncillaries.java index 22de7df1ba..637e46df54 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/OperationAncillaries.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/OperationAncillaries.java @@ -221,7 +221,7 @@ public static MemorySpan outputDataSpan(final MessageFrame frame) { // We cannot use this method for that purpose. case CALL, CALLCODE, DELEGATECALL, STATICCALL -> { Address target = Words.toAddress(frame.getStackItem(1)); - if (isPrecompile(target)) { + if (!isPrecompile(target)) { return MemorySpan.fromStartLength(0, 0); } checkArgument(isPrecompile(target)); // useless (?) sanity check From bc80f9117cef108ea0b5b078e800507b435823e6 Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Wed, 23 Oct 2024 14:22:06 +0200 Subject: [PATCH 07/11] test: add docs --- .../hub/ZeroSizeCallDataOrReturnDataTest.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/ZeroSizeCallDataOrReturnDataTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/ZeroSizeCallDataOrReturnDataTest.java index 87023b3d34..9901a4ec18 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/ZeroSizeCallDataOrReturnDataTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/ZeroSizeCallDataOrReturnDataTest.java @@ -31,10 +31,10 @@ public class ZeroSizeCallDataOrReturnDataTest { void zeroSizeHugeReturnAtOffsetTest() { BytecodeCompiler program = BytecodeCompiler.newProgram(); program - .push(0) + .push(0) // return data size .push("ff".repeat(32)) // return data offset - .push(0) - .push(0) + .push(0) // call data size + .push(0) // call data offset .push("ca11ee") // address .push(1000) // gas .op(OpCode.STATICCALL); @@ -58,9 +58,9 @@ void zeroSizeHugeReturnAtOffsetTest() { void zeroSizeHugeCallDataOffsetTest() { BytecodeCompiler program = BytecodeCompiler.newProgram(); program - .push(0) - .push(0) - .push(0) + .push(0) // return data size + .push(0) // return data offset + .push(0) // call data size .push("ff".repeat(32)) // call data offset .push("ca11ee") // address .push(1000) // gas @@ -84,10 +84,10 @@ void zeroSizeHugeCallDataOffsetTest() { void zeroSizeHugeReturnDataOffsetTest() { BytecodeCompiler program = BytecodeCompiler.newProgram(); program - .push(0) - .push(0) - .push(0) - .push(0) + .push(0) // return data size + .push(0) // return data offset + .push(0) // call data size + .push(0) // call data offset .push("ca11ee") // address .push(1000) // gas .op(OpCode.STATICCALL); From f3a9d265b5ea74a76e6d41dbc861374b1e50c346 Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Wed, 23 Oct 2024 15:08:26 +0200 Subject: [PATCH 08/11] fix: returnDataRequestedSegment --- .../hub/transients/OperationAncillaries.java | 35 +++++++++++++++---- 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/OperationAncillaries.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/OperationAncillaries.java index 637e46df54..1315a76ff7 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/OperationAncillaries.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/OperationAncillaries.java @@ -19,6 +19,7 @@ import static net.consensys.linea.zktracer.module.UtilCalculator.allButOneSixtyFourth; import static net.consensys.linea.zktracer.types.AddressUtils.isPrecompile; +import com.google.common.base.Preconditions; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import net.consensys.linea.zktracer.module.constants.GlobalConstants; @@ -164,14 +165,36 @@ public static Bytes initCode(final MessageFrame frame) { public static MemorySpan returnDataRequestedSegment(final MessageFrame frame) { switch (OpCode.of(frame.getCurrentOperation().getOpcode())) { case CALL, CALLCODE -> { - long offset = Words.clampedToLong(frame.getStackItem(5)); - long length = Words.clampedToLong(frame.getStackItem(6)); - return MemorySpan.fromStartLength(offset, length); + long callDataOffset = Words.clampedToLong(frame.getStackItem(3)); + long callDataSize = Words.clampedToLong(frame.getStackItem(4)); + long returnDataOffset = Words.clampedToLong(frame.getStackItem(5)); + long returnDataSize = Words.clampedToLong(frame.getStackItem(6)); + + Preconditions.checkArgument(!(callDataOffset >= Math.pow(2, 32) && callDataSize == 0)); + Preconditions.checkArgument(!(returnDataOffset >= Math.pow(2, 32) && returnDataSize == 0)); + + System.out.println("callDataOffset: " + callDataOffset); + System.out.println("callDataSize: " + callDataSize); + System.out.println("returnDataOffset: " + returnDataOffset); + System.out.println("returnDataSize: " + returnDataSize); + + return MemorySpan.fromStartLength(returnDataOffset, returnDataSize); } case DELEGATECALL, STATICCALL -> { - long offset = Words.clampedToLong(frame.getStackItem(4)); - long length = Words.clampedToLong(frame.getStackItem(5)); - return MemorySpan.fromStartLength(offset, length); + long callDataOffset = Words.clampedToLong(frame.getStackItem(2)); + long callDataSize = Words.clampedToLong(frame.getStackItem(3)); + long returnDataOffset = Words.clampedToLong(frame.getStackItem(4)); + long returnDataSize = Words.clampedToLong(frame.getStackItem(5)); + + System.out.println("callDataOffset: " + callDataOffset); + System.out.println("callDataSize: " + callDataSize); + System.out.println("returnDataOffset: " + returnDataOffset); + System.out.println("returnDataSize: " + returnDataSize); + + Preconditions.checkArgument(!(callDataOffset >= Math.pow(2, 32) && callDataSize == 0)); + Preconditions.checkArgument(!(returnDataOffset >= Math.pow(2, 32) && returnDataSize == 0)); + + return MemorySpan.fromStartLength(returnDataOffset, returnDataSize); } default -> throw new IllegalArgumentException( "returnDataRequestedSegment called outside of a *CALL"); From 65b48a82a0f21cac13020af974e9672aa0840261 Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Fri, 25 Oct 2024 10:39:26 +0200 Subject: [PATCH 09/11] fix(operationAncillaries): return at offset and return at capacity --- .../hub/transients/OperationAncillaries.java | 24 +++++++++---------- .../hub/ZeroSizeCallDataOrReturnDataTest.java | 12 +++++----- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/OperationAncillaries.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/OperationAncillaries.java index 1315a76ff7..5b9e8d1410 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/OperationAncillaries.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/OperationAncillaries.java @@ -167,34 +167,34 @@ public static MemorySpan returnDataRequestedSegment(final MessageFrame frame) { case CALL, CALLCODE -> { long callDataOffset = Words.clampedToLong(frame.getStackItem(3)); long callDataSize = Words.clampedToLong(frame.getStackItem(4)); - long returnDataOffset = Words.clampedToLong(frame.getStackItem(5)); - long returnDataSize = Words.clampedToLong(frame.getStackItem(6)); + long returnAtOffset = Words.clampedToLong(frame.getStackItem(5)); + long returnAtCapacity = Words.clampedToLong(frame.getStackItem(6)); Preconditions.checkArgument(!(callDataOffset >= Math.pow(2, 32) && callDataSize == 0)); - Preconditions.checkArgument(!(returnDataOffset >= Math.pow(2, 32) && returnDataSize == 0)); + Preconditions.checkArgument(!(returnAtOffset >= Math.pow(2, 32) && returnAtCapacity == 0)); System.out.println("callDataOffset: " + callDataOffset); System.out.println("callDataSize: " + callDataSize); - System.out.println("returnDataOffset: " + returnDataOffset); - System.out.println("returnDataSize: " + returnDataSize); + System.out.println("returnAtOffset: " + returnAtOffset); + System.out.println("returnAtCapacity: " + returnAtCapacity); - return MemorySpan.fromStartLength(returnDataOffset, returnDataSize); + return MemorySpan.fromStartLength(returnAtOffset, returnAtCapacity); } case DELEGATECALL, STATICCALL -> { long callDataOffset = Words.clampedToLong(frame.getStackItem(2)); long callDataSize = Words.clampedToLong(frame.getStackItem(3)); - long returnDataOffset = Words.clampedToLong(frame.getStackItem(4)); - long returnDataSize = Words.clampedToLong(frame.getStackItem(5)); + long returnAtOffset = Words.clampedToLong(frame.getStackItem(4)); + long returnAtCapacity = Words.clampedToLong(frame.getStackItem(5)); System.out.println("callDataOffset: " + callDataOffset); System.out.println("callDataSize: " + callDataSize); - System.out.println("returnDataOffset: " + returnDataOffset); - System.out.println("returnDataSize: " + returnDataSize); + System.out.println("returnAtOffset: " + returnAtOffset); + System.out.println("returnDataSize: " + returnAtCapacity); Preconditions.checkArgument(!(callDataOffset >= Math.pow(2, 32) && callDataSize == 0)); - Preconditions.checkArgument(!(returnDataOffset >= Math.pow(2, 32) && returnDataSize == 0)); + Preconditions.checkArgument(!(returnAtOffset >= Math.pow(2, 32) && returnAtCapacity == 0)); - return MemorySpan.fromStartLength(returnDataOffset, returnDataSize); + return MemorySpan.fromStartLength(returnAtOffset, returnAtCapacity); } default -> throw new IllegalArgumentException( "returnDataRequestedSegment called outside of a *CALL"); diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/ZeroSizeCallDataOrReturnDataTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/ZeroSizeCallDataOrReturnDataTest.java index 9901a4ec18..1651939120 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/ZeroSizeCallDataOrReturnDataTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/ZeroSizeCallDataOrReturnDataTest.java @@ -31,8 +31,8 @@ public class ZeroSizeCallDataOrReturnDataTest { void zeroSizeHugeReturnAtOffsetTest() { BytecodeCompiler program = BytecodeCompiler.newProgram(); program - .push(0) // return data size - .push("ff".repeat(32)) // return data offset + .push(0) // return at capacity + .push("ff".repeat(32)) // return at offset .push(0) // call data size .push(0) // call data offset .push("ca11ee") // address @@ -58,8 +58,8 @@ void zeroSizeHugeReturnAtOffsetTest() { void zeroSizeHugeCallDataOffsetTest() { BytecodeCompiler program = BytecodeCompiler.newProgram(); program - .push(0) // return data size - .push(0) // return data offset + .push(0) // return at capacity + .push(0) // return at offset .push(0) // call data size .push("ff".repeat(32)) // call data offset .push("ca11ee") // address @@ -84,8 +84,8 @@ void zeroSizeHugeCallDataOffsetTest() { void zeroSizeHugeReturnDataOffsetTest() { BytecodeCompiler program = BytecodeCompiler.newProgram(); program - .push(0) // return data size - .push(0) // return data offset + .push(0) // return at capacity + .push(0) // return at offset .push(0) // call data size .push(0) // call data offset .push("ca11ee") // address From 1bc1a35db4c3fa1524b44f1f38c376ef98300c47 Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Mon, 4 Nov 2024 17:05:54 +0100 Subject: [PATCH 10/11] typo --- .../zktracer/module/hub/transients/OperationAncillaries.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/OperationAncillaries.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/OperationAncillaries.java index 5b9e8d1410..18c270253a 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/OperationAncillaries.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/OperationAncillaries.java @@ -189,7 +189,7 @@ public static MemorySpan returnDataRequestedSegment(final MessageFrame frame) { System.out.println("callDataOffset: " + callDataOffset); System.out.println("callDataSize: " + callDataSize); System.out.println("returnAtOffset: " + returnAtOffset); - System.out.println("returnDataSize: " + returnAtCapacity); + System.out.println("returnAtCapacity: " + returnAtCapacity); Preconditions.checkArgument(!(callDataOffset >= Math.pow(2, 32) && callDataSize == 0)); Preconditions.checkArgument(!(returnAtOffset >= Math.pow(2, 32) && returnAtCapacity == 0)); From 3a67df59fc12fc107e7c7cfdcabfc5566142fcbf Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Thu, 28 Nov 2024 16:02:35 +0100 Subject: [PATCH 11/11] docs: remove useless comment --- .../zktracer/module/hub/ZeroSizeCallDataOrReturnDataTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/ZeroSizeCallDataOrReturnDataTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/ZeroSizeCallDataOrReturnDataTest.java index 1651939120..1d103c4af0 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/ZeroSizeCallDataOrReturnDataTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/ZeroSizeCallDataOrReturnDataTest.java @@ -51,7 +51,6 @@ void zeroSizeHugeReturnAtOffsetTest() { .build(); BytecodeRunner.of(program.compile()).run(Wei.fromEth(1), 30000L, List.of(calleeAccount)); - // TODO: this test is supposed to fail as the ones below, but it does not. Understand why } @Test