Skip to content

Commit

Permalink
fix: remove non-determinism from tests (#1537)
Browse files Browse the repository at this point in the history
* Remove non-determinism from tests

This removes non-determinism from the tests caused by a shared RNG
across tests.

* Disable tests with `RETURN_DATA_OFFSET` overflow

This disables three tests which lead to an overflow of the
`hub/RETURN_DATA_OFFSET` column during trace generation.  See #1538.
  • Loading branch information
DavePearce authored Nov 22, 2024
1 parent 892534c commit 8353d02
Show file tree
Hide file tree
Showing 10 changed files with 131 additions and 86 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import static net.consensys.linea.zktracer.module.mxp.MxpTestUtils.opCodesType3;
import static net.consensys.linea.zktracer.module.mxp.MxpTestUtils.opCodesType4;
import static net.consensys.linea.zktracer.module.mxp.MxpTestUtils.opCodesType5;
import static net.consensys.linea.zktracer.module.mxp.MxpTestUtils.triggerNonTrivialButMxpxOrRoobForOpCode;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

Expand All @@ -30,6 +29,7 @@

import net.consensys.linea.testing.BytecodeCompiler;
import net.consensys.linea.testing.BytecodeRunner;
import net.consensys.linea.zktracer.module.mxp.MxpTestUtils;
import net.consensys.linea.zktracer.opcode.OpCode;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
Expand All @@ -41,7 +41,7 @@ public class MemoryExpansionExceptionTest {
@MethodSource("memoryExpansionExceptionTestSource")
public void memoryExpansionExceptionTest(boolean triggerRoob, OpCode opCode) {
BytecodeCompiler program = BytecodeCompiler.newProgram();
triggerNonTrivialButMxpxOrRoobForOpCode(program, triggerRoob, opCode);
new MxpTestUtils().triggerNonTrivialButMxpxOrRoobForOpCode(program, triggerRoob, opCode);
BytecodeRunner bytecodeRunner = BytecodeRunner.of(program.compile());
bytecodeRunner.run();
assertEquals(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package net.consensys.linea.zktracer.instructionprocessing;

import static com.google.common.base.Preconditions.*;
import static net.consensys.linea.zktracer.module.rlpcommon.RlpRandEdgeCase.randData;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -24,6 +23,7 @@
import net.consensys.linea.testing.ToyAccount;
import net.consensys.linea.testing.ToyExecutionEnvironmentV2;
import net.consensys.linea.testing.ToyTransaction;
import net.consensys.linea.zktracer.module.rlpcommon.RlpRandEdgeCase;
import net.consensys.linea.zktracer.types.AddressUtils;
import org.apache.tuweni.bytes.Bytes;
import org.hyperledger.besu.crypto.KeyPair;
Expand Down Expand Up @@ -160,7 +160,7 @@ void temporaryTest() {
SECPPublicKey pk5 = keyPair5.getPublicKey();
ToyAccount account5 = buildAnAccount(Address.extract(Hash.hash(pk5.getEncodedBytes())), 7);

Bytes initCode = randData(true);
Bytes initCode = new RlpRandEdgeCase().randData(true);

// TODO: deployment transaction fails in our ToyWorld
/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@
public class EcPairingTestSupport {
private static final String DELIMITER_CSV = ",";
static final String DELIMITER_PAIRINGS = "_";
private static final Random random = new Random(1);
private final Random random = new Random(1);

static String info(int totalPairings, int r) {
// r represents the number of the repetition of a scenario
return "TotalPairings" + totalPairings + "(" + r + ")";
}

static Arguments generatePairings(
Arguments generatePairings(
final String description,
final int totalPairings,
List<Arguments> smallPointsType,
Expand All @@ -48,7 +48,7 @@ static Arguments generatePairings(
return Arguments.of(description, argumentsListToPairingsAsString(pairings));
}

static Arguments generatePairingsSmallPointsMixed(
Arguments generatePairingsSmallPointsMixed(
final String description,
final int totalPairings,
List<Arguments> smallPointsType1,
Expand All @@ -65,7 +65,7 @@ static Arguments generatePairingsSmallPointsMixed(
return Arguments.of(description, argumentsListToPairingsAsString(pairings));
}

static Arguments generatePairingsLargePointsMixed(
Arguments generatePairingsLargePointsMixed(
final String description,
final int totalPairings,
List<Arguments> smallPointsType,
Expand All @@ -82,7 +82,7 @@ static Arguments generatePairingsLargePointsMixed(
return Arguments.of(description, argumentsListToPairingsAsString(pairings));
}

static Arguments generatePairingsMixed(
Arguments generatePairingsMixed(
final String description,
final int totalPairings,
List<Arguments> smallPointsType1,
Expand Down Expand Up @@ -167,7 +167,7 @@ public static List<Arguments> csvToArgumentsList(String filePath) throws IOExcep
return argumentsList;
}

private static Arguments rnd(List<Arguments> points) {
private Arguments rnd(List<Arguments> points) {
// If there is only one point, return it
if (points.size() == 1) {
return points.getFirst();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@

import static net.consensys.linea.zktracer.module.ecdata.ecpairing.EcPairingTestSupport.argumentsListToPairingsAsString;
import static net.consensys.linea.zktracer.module.ecdata.ecpairing.EcPairingTestSupport.csvToArgumentsList;
import static net.consensys.linea.zktracer.module.ecdata.ecpairing.EcPairingTestSupport.generatePairings;
import static net.consensys.linea.zktracer.module.ecdata.ecpairing.EcPairingTestSupport.generatePairingsLargePointsMixed;
import static net.consensys.linea.zktracer.module.ecdata.ecpairing.EcPairingTestSupport.generatePairingsMixed;
import static net.consensys.linea.zktracer.module.ecdata.ecpairing.EcPairingTestSupport.generatePairingsSmallPointsMixed;
import static net.consensys.linea.zktracer.module.ecdata.ecpairing.EcPairingTestSupport.info;
import static net.consensys.linea.zktracer.module.ecdata.ecpairing.EcPairingTestSupport.pair;
import static net.consensys.linea.zktracer.module.ecdata.ecpairing.EcPairingTestSupport.pairingsAsStringToArgumentsList;
Expand Down Expand Up @@ -328,70 +324,72 @@ private void testEcPairingGenericForScenario(String description, String pairings
// Method source of testEcPairingGenericForScenarioUsingMethodSource
private static Stream<Arguments> ecPairingGenericSource() {
List<Arguments> allPairings = new ArrayList<>();
EcPairingTestSupport util = new EcPairingTestSupport();

final int REPETITIONS = 3;
for (int r = 1; r <= REPETITIONS; r++) {
for (Integer totalPairings : List.of(3, 4, 5)) {
// PRECOMPILE_ECPAIRING_MILLER_LOOPS = 64
// This test has totalPairings fixed to 64
allPairings.add(
generatePairings("maxGenericPairings" + info(64, r), 64, smallPoints, largePoints));
util.generatePairings(
"maxGenericPairings" + info(64, r), 64, smallPoints, largePoints));

// Focus on small points scenarios
allPairings.add(
generatePairings(
util.generatePairings(
"smallPointsOutOfRange" + info(totalPairings, r),
totalPairings,
smallPointsOutOfRange,
largePoints));

allPairings.add(
generatePairingsSmallPointsMixed(
util.generatePairingsSmallPointsMixed(
"smallPointsOutOfRangeMixed" + info(totalPairings, r),
totalPairings,
smallPointsOutOfRange,
smallPoints,
largePoints));

allPairings.add(
generatePairings(
util.generatePairings(
"smallPointsNotOnC1" + info(totalPairings, r),
totalPairings,
smallPointsNotOnC1,
largePoints));

allPairings.add(
generatePairingsSmallPointsMixed(
util.generatePairingsSmallPointsMixed(
"smallPointsNotOnC1Mixed" + info(totalPairings, r),
totalPairings,
smallPointsNotOnC1,
smallPoints,
largePoints));

allPairings.add(
generatePairings(
util.generatePairings(
"smallPointsOnC1" + info(totalPairings, r),
totalPairings,
smallPointsOnC1,
largePoints));

allPairings.add(
generatePairingsSmallPointsMixed(
util.generatePairingsSmallPointsMixed(
"smallPointsOnC1Mixed" + info(totalPairings, r),
totalPairings,
smallPointsOnC1,
smallPoints,
largePoints));

allPairings.add(
generatePairings(
util.generatePairings(
"smallPointInfinity" + info(totalPairings, r),
totalPairings,
List.of(smallPointInfinity),
largePoints));

allPairings.add(
generatePairingsSmallPointsMixed(
util.generatePairingsSmallPointsMixed(
"smallPointInfinityMixed" + info(totalPairings, r),
totalPairings,
List.of(smallPointInfinity),
Expand All @@ -400,74 +398,74 @@ private static Stream<Arguments> ecPairingGenericSource() {

// Focus on large points scenarios
allPairings.add(
generatePairings(
util.generatePairings(
"largePointsOutOfRange" + info(totalPairings, r),
totalPairings,
smallPoints,
largePointsOutOfRange));

allPairings.add(
generatePairingsLargePointsMixed(
util.generatePairingsLargePointsMixed(
"largePointsOutOfRangeMixed" + info(totalPairings, r),
totalPairings,
smallPoints,
largePointsOutOfRange,
largePoints));

allPairings.add(
generatePairings(
util.generatePairings(
"largePointsNotOnC2" + info(totalPairings, r),
totalPairings,
smallPoints,
largePointsNotOnC2));

allPairings.add(
generatePairingsLargePointsMixed(
util.generatePairingsLargePointsMixed(
"largePointsNotOnC2Mixed" + info(totalPairings, r),
totalPairings,
smallPoints,
largePointsNotOnC2,
largePoints));

allPairings.add(
generatePairings(
util.generatePairings(
"largePointsNotOnG2" + info(totalPairings, r),
totalPairings,
smallPoints,
largePointsNotOnG2));

allPairings.add(
generatePairingsLargePointsMixed(
util.generatePairingsLargePointsMixed(
"largePointsNotOnG2Mixed" + info(totalPairings, r),
totalPairings,
smallPoints,
largePointsNotOnG2,
largePoints));

allPairings.add(
generatePairings(
util.generatePairings(
"largePointsOnG2" + info(totalPairings, r),
totalPairings,
smallPoints,
largePointsOnG2));

allPairings.add(
generatePairingsLargePointsMixed(
util.generatePairingsLargePointsMixed(
"largePointsOnG2Mixed" + info(totalPairings, r),
totalPairings,
smallPoints,
largePointsOnG2,
largePoints));

allPairings.add(
generatePairings(
util.generatePairings(
"largePointInfinity" + info(totalPairings, r),
totalPairings,
smallPoints,
List.of(largePointInfinity)));

allPairings.add(
generatePairingsLargePointsMixed(
util.generatePairingsLargePointsMixed(
"largePointInfinityMixed" + info(totalPairings, r),
totalPairings,
smallPoints,
Expand All @@ -476,37 +474,37 @@ private static Stream<Arguments> ecPairingGenericSource() {

// Focus on combinations of small and large points scenarios
allPairings.add(
generatePairingsLargePointsMixed(
util.generatePairingsLargePointsMixed(
"largePointNotOnG2Exists" + info(totalPairings, r),
totalPairings,
smallPointsOnC1,
largePointsNotOnG2,
largePoints));

allPairings.add(
generatePairings(
util.generatePairings(
"trivialPairingAllSmallPointsOnC1" + info(totalPairings, r),
totalPairings,
smallPointsOnC1,
List.of(largePointInfinity)));

allPairings.add(
generatePairingsSmallPointsMixed(
util.generatePairingsSmallPointsMixed(
"trivialPairingSmallPointsOnC1AndInfinity" + info(totalPairings, r),
totalPairings,
smallPointsOnC1,
List.of(smallPointInfinity),
List.of(largePointInfinity)));

allPairings.add(
generatePairings(
util.generatePairings(
"nonTrivialPairingExcludingInfinity" + info(totalPairings, r),
totalPairings,
smallPointsOnC1,
largePointsOnG2));

allPairings.add(
generatePairingsMixed(
util.generatePairingsMixed(
"nonTrivialPairingIncludingInfinity" + info(totalPairings, r),
totalPairings,
smallPointsOnC1,
Expand Down
Loading

0 comments on commit 8353d02

Please sign in to comment.