From 03db6dd4534217122db4652514c7b26b1aaa1fa2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Mon, 25 Nov 2024 21:01:09 +0700 Subject: [PATCH 1/6] fix: partialCopyOfReturnDataForIdentity correction of 'size' parameter --- .../zktracer/module/hub/fragment/imc/mmu/MmuCall.java | 8 +++++--- .../call/precompileSubsection/IdentitySubsection.java | 8 ++++---- .../call/precompileSubsection/PrecompileSubsection.java | 8 ++++++++ 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/MmuCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/MmuCall.java index 1761231c0d..97d55fff7f 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/MmuCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/MmuCall.java @@ -417,7 +417,7 @@ public static MmuCall partialReturnDataCopyForShaTwoAndRipemd( .referenceSize(subsection.returnAtCapacity()); } - public static MmuCall forIdentityExtractCallData(final Hub hub, PrecompileSubsection subsection) { + public static MmuCall callDataExtractionForIdentity(final Hub hub, PrecompileSubsection subsection) { return new MmuCall(hub, MMU_INST_RAM_TO_RAM_SANS_PADDING) .sourceId(hub.currentFrame().contextNumber()) // called at ContextReEntry @@ -429,17 +429,19 @@ public static MmuCall forIdentityExtractCallData(final Hub hub, PrecompileSubsec .referenceSize(subsection.callDataSize()); } - public static MmuCall forIdentityReturnData( + public static MmuCall partialCopyOfReturnDataForIdentity( final Hub hub, final PrecompileSubsection subsection) { + checkState(subsection.callDataSize() == subsection.returnDataSize()); + checkState(subsection.returnDataOffset() == 0); return new MmuCall(hub, MMU_INST_RAM_TO_RAM_SANS_PADDING) .sourceId(subsection.exoModuleOperationId()) .sourceRamBytes(Optional.of(subsection.returnDataRange.extract())) .targetId(hub.currentFrame().contextNumber()) .targetRamBytes(Optional.of(subsection.rawCallerMemory())) .sourceOffset(EWord.ZERO) + .size(subsection.returnDataSize()) .referenceOffset(subsection.returnAtOffset()) - .size(subsection.returnAtCapacity()) .referenceSize(subsection.returnAtCapacity()); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/IdentitySubsection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/IdentitySubsection.java index 08ad7cdc42..504f543bad 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/IdentitySubsection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/IdentitySubsection.java @@ -16,8 +16,8 @@ package net.consensys.linea.zktracer.module.hub.section.call.precompileSubsection; import static com.google.common.base.Preconditions.*; -import static net.consensys.linea.zktracer.module.hub.fragment.imc.mmu.MmuCall.forIdentityExtractCallData; -import static net.consensys.linea.zktracer.module.hub.fragment.imc.mmu.MmuCall.forIdentityReturnData; +import static net.consensys.linea.zktracer.module.hub.fragment.imc.mmu.MmuCall.callDataExtractionForIdentity; +import static net.consensys.linea.zktracer.module.hub.fragment.imc.mmu.MmuCall.partialCopyOfReturnDataForIdentity; import static net.consensys.linea.zktracer.module.hub.fragment.imc.oob.OobInstruction.OOB_INST_IDENTITY; import static net.consensys.linea.zktracer.module.hub.fragment.scenario.PrecompileScenarioFragment.PrecompileScenario.PRC_FAILURE_KNOWN_TO_HUB; @@ -57,14 +57,14 @@ public void resolveAtContextReEntry(Hub hub, CallFrame callFrame) { final boolean extractCallData = callSuccess && !getCallDataRange().isEmpty(); if (extractCallData) { - final MmuCall mmuCall = forIdentityExtractCallData(hub, this); + final MmuCall mmuCall = callDataExtractionForIdentity(hub, this); firstImcFragment.callMmu(mmuCall); } final ImcFragment secondImcFragment = ImcFragment.empty(hub); fragments().add(secondImcFragment); if (extractCallData && !getReturnAtRange().isEmpty()) { - final MmuCall mmuCall = forIdentityReturnData(hub, this); + final MmuCall mmuCall = partialCopyOfReturnDataForIdentity(hub, this); secondImcFragment.callMmu(mmuCall); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileSubsection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileSubsection.java index 07f1fe18b9..9cb6438f67 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileSubsection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileSubsection.java @@ -200,6 +200,14 @@ public long returnAtCapacity() { return getReturnAtRange().size(); } + public long returnDataOffset() { + return returnDataRange().offset(); + } + + public long returnDataSize() { + return returnDataRange().size(); + } + public Bytes rawCallerMemory() { return callSection.getCallDataRange().getRawData(); } From 6b43a485a5d0fd1e29f0300bff49b14d7a8d4d31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Mon, 25 Nov 2024 21:01:17 +0700 Subject: [PATCH 2/6] ras --- .../linea/zktracer/module/hub/fragment/imc/mmu/MmuCall.java | 5 +++-- .../EllipticCurvePrecompileSubsection.java | 2 +- .../call/precompileSubsection/ShaTwoOrRipemdSubSection.java | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/MmuCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/MmuCall.java index 97d55fff7f..cd644208dc 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/MmuCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/MmuCall.java @@ -397,7 +397,7 @@ public static MmuCall fullResultTransferForShaTwoAndRipemd( } } - public static MmuCall partialReturnDataCopyForShaTwoAndRipemd( + public static MmuCall partialCopyOfReturnDataForShaTwoAndRipemd( final Hub hub, PrecompileSubsection subsection) { final PrecompileScenarioFragment.PrecompileFlag flag = @@ -434,6 +434,7 @@ public static MmuCall partialCopyOfReturnDataForIdentity( checkState(subsection.callDataSize() == subsection.returnDataSize()); checkState(subsection.returnDataOffset() == 0); + return new MmuCall(hub, MMU_INST_RAM_TO_RAM_SANS_PADDING) .sourceId(subsection.exoModuleOperationId()) .sourceRamBytes(Optional.of(subsection.returnDataRange.extract())) @@ -460,7 +461,7 @@ public static MmuCall callDataExtractionForEcadd( .phase(PHASE_ECADD_DATA); } - public static MmuCall fullReturnDataTransferForEcadd( + public static MmuCall fullTransferOfReturnDataForEcadd( final Hub hub, PrecompileSubsection subsection, boolean successBit) { return new MmuCall(hub, MMU_INST_EXO_TO_RAM_TRANSPLANTS) .sourceId(subsection.exoModuleOperationId()) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/EllipticCurvePrecompileSubsection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/EllipticCurvePrecompileSubsection.java index 8a588e2db2..36315187b8 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/EllipticCurvePrecompileSubsection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/EllipticCurvePrecompileSubsection.java @@ -138,7 +138,7 @@ public void resolveAtContextReEntry(Hub hub, CallFrame callFrame) { } case PRC_ECADD -> { if (nonemptyCallData) { - secondMmuCall = MmuCall.fullReturnDataTransferForEcadd(hub, this, successBitMmuCall); + secondMmuCall = MmuCall.fullTransferOfReturnDataForEcadd(hub, this, successBitMmuCall); } if (callerMayReceiveReturnData) { thirdMmuCall = MmuCall.partialCopyOfReturnDataForEcadd(hub, this); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/ShaTwoOrRipemdSubSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/ShaTwoOrRipemdSubSection.java index c5f4ea3187..5f8a9695fd 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/ShaTwoOrRipemdSubSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/ShaTwoOrRipemdSubSection.java @@ -92,7 +92,7 @@ public void resolveAtContextReEntry(Hub hub, CallFrame callFrame) { // provided a nonempty return data target if (!getReturnAtRange().isEmpty()) { final MmuCall partialReturnDataCopy = - MmuCall.partialReturnDataCopyForShaTwoAndRipemd(hub, this); + MmuCall.partialCopyOfReturnDataForShaTwoAndRipemd(hub, this); thirdImcFragment.callMmu(partialReturnDataCopy); } } From e5ee9afd91a6c6152466b895a2b0223d7175454e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Mon, 25 Nov 2024 21:12:55 +0700 Subject: [PATCH 3/6] spotless --- .../linea/zktracer/module/hub/fragment/imc/mmu/MmuCall.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/MmuCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/MmuCall.java index cd644208dc..b4e8938299 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/MmuCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/MmuCall.java @@ -417,7 +417,8 @@ public static MmuCall partialCopyOfReturnDataForShaTwoAndRipemd( .referenceSize(subsection.returnAtCapacity()); } - public static MmuCall callDataExtractionForIdentity(final Hub hub, PrecompileSubsection subsection) { + public static MmuCall callDataExtractionForIdentity( + final Hub hub, PrecompileSubsection subsection) { return new MmuCall(hub, MMU_INST_RAM_TO_RAM_SANS_PADDING) .sourceId(hub.currentFrame().contextNumber()) // called at ContextReEntry From f9ccfd7494a23797174c0369430114a4999ae38f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Tue, 26 Nov 2024 11:42:38 +0700 Subject: [PATCH 4/6] fix: make JUnit run tests in parallel --- arithmetization/src/test/resources/junit-platform.properties | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 arithmetization/src/test/resources/junit-platform.properties diff --git a/arithmetization/src/test/resources/junit-platform.properties b/arithmetization/src/test/resources/junit-platform.properties new file mode 100644 index 0000000000..5302706516 --- /dev/null +++ b/arithmetization/src/test/resources/junit-platform.properties @@ -0,0 +1,3 @@ +junit.jupiter.execution.parallel.enabled = true +junit.jupiter.execution.parallel.mode.default = concurrent +junit.jupiter.execution.parallel.config.strategy = dynamic \ No newline at end of file From 8d95e8d4ba70c3e7d853a585f623defc6f273489 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Tue, 26 Nov 2024 11:42:57 +0700 Subject: [PATCH 5/6] feat: parallelized IDENTITY tests (wip) --- .../callTests/prc/identity/Tests.java | 62 +++++++++++++++++++ .../utilities/Calls.java | 43 +++++++++++++ .../utilities/enums/GasParam.java | 24 +++++++ .../utilities/enums/OfstParam.java | 36 +++++++++++ .../utilities/enums/SizeParam.java | 37 +++++++++++ .../utilities/enums/ValueParameter.java | 24 +++++++ 6 files changed, 226 insertions(+) create mode 100644 arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/utilities/enums/GasParam.java create mode 100644 arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/utilities/enums/OfstParam.java create mode 100644 arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/utilities/enums/SizeParam.java create mode 100644 arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/utilities/enums/ValueParameter.java diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/callTests/prc/identity/Tests.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/callTests/prc/identity/Tests.java index 264b254ce6..05907ca11b 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/callTests/prc/identity/Tests.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/callTests/prc/identity/Tests.java @@ -15,23 +15,37 @@ package net.consensys.linea.zktracer.instructionprocessing.callTests.prc.identity; import static net.consensys.linea.zktracer.instructionprocessing.utilities.Calls.appendCall; +import static net.consensys.linea.zktracer.instructionprocessing.utilities.Calls.appendGenericCall; import static net.consensys.linea.zktracer.instructionprocessing.utilities.MonoOpCodeSmcs.keyPair; import static net.consensys.linea.zktracer.instructionprocessing.utilities.MonoOpCodeSmcs.userAccount; +import static net.consensys.linea.zktracer.instructionprocessing.utilities.enums.GasParam.*; +import static net.consensys.linea.zktracer.instructionprocessing.utilities.enums.GasParam.GAS; +import static net.consensys.linea.zktracer.instructionprocessing.utilities.enums.GasParam.GAS_PLUS_ONE; import static net.consensys.linea.zktracer.opcode.OpCode.*; +import java.util.ArrayList; import java.util.List; +import java.util.stream.Stream; import net.consensys.linea.testing.BytecodeCompiler; import net.consensys.linea.testing.ToyAccount; import net.consensys.linea.testing.ToyExecutionEnvironmentV2; import net.consensys.linea.testing.ToyTransaction; +import net.consensys.linea.zktracer.instructionprocessing.utilities.enums.GasParam; +import net.consensys.linea.zktracer.instructionprocessing.utilities.enums.OfstParam; +import net.consensys.linea.zktracer.instructionprocessing.utilities.enums.SizeParam; +import net.consensys.linea.zktracer.instructionprocessing.utilities.enums.ValueParameter; import net.consensys.linea.zktracer.opcode.OpCode; import org.apache.tuweni.bytes.Bytes; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.core.Transaction; +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.EnumSource; +import org.junit.jupiter.params.provider.MethodSource; public class Tests { @@ -92,6 +106,31 @@ void nontrivialCallDataIdentityTest(OpCode callOpCode) { .run(); } + @ParameterizedTest + @MethodSource("callParameterIDENTITY") + void genericIdentityTests( + OpCode callOpCode, GasParam gasParam, OfstParam cdo, SizeParam cds, OfstParam rao, SizeParam rac) { + + BytecodeCompiler program = BytecodeCompiler.newProgram(); + fullCodeCopyOf(program, byteSource); + appendGenericCall(program, callOpCode, gasParam, Address.ID, ValueParameter.ONE, cdo, cds, rao, rac, 0, 0); + identityCaller.setCode(program.compile()); + + Transaction transaction = + ToyTransaction.builder() + .sender(userAccount) + .keyPair(keyPair) + .to(identityCaller) + .value(Wei.of(7_000_000_000L)) + .build(); + + ToyExecutionEnvironmentV2.builder() + .accounts(List.of(byteSource, userAccount, identityCaller)) + .transaction(transaction) + .build() + .run(); + } + /** * The following copies the entirety of the account code to RAM. * @@ -108,4 +147,27 @@ public void fullCodeCopyOf(BytecodeCompiler program, ToyAccount account) { .push(address) .op(EXTCODECOPY); // copies the entire code to RAM } + + static Stream callParameterIDENTITY() { + + + List callOpCodes = List.of(CALL, CALLCODE, DELEGATECALL, STATICCALL); + List gasParams = List.of(GAS, GAS_PLUS_ONE); + List arguments = new ArrayList<>(); + + for (OpCode callOpCode : callOpCodes) { + for (GasParam gasParam : gasParams) { + for (OfstParam cdo : OfstParam.values()) { + for (SizeParam cds : SizeParam.values()) { + for (OfstParam rao : OfstParam.values()) { + for (SizeParam rac : SizeParam.values()) { + arguments.add(Arguments.of(callOpCode, gasParam, cdo, cds, rao, rac)); + } + } + } + } + } + } + return arguments.stream(); + } } diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/utilities/Calls.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/utilities/Calls.java index aad30723b1..69c24a349d 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/utilities/Calls.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/utilities/Calls.java @@ -19,6 +19,10 @@ import net.consensys.linea.testing.BytecodeCompiler; import net.consensys.linea.testing.ToyAccount; +import net.consensys.linea.zktracer.instructionprocessing.utilities.enums.GasParam; +import net.consensys.linea.zktracer.instructionprocessing.utilities.enums.OfstParam; +import net.consensys.linea.zktracer.instructionprocessing.utilities.enums.SizeParam; +import net.consensys.linea.zktracer.instructionprocessing.utilities.enums.ValueParameter; import net.consensys.linea.zktracer.opcode.OpCode; import org.apache.tuweni.bytes.Bytes32; import org.hyperledger.besu.datatypes.Address; @@ -36,6 +40,45 @@ public class Calls { public static Bytes32 randCdo = Bytes32.fromHexString("1a3b88fc78471a5d0ce2df8a5799299b7eefd8e6bfd6d6afb0e437e0a6311878"); + public enum Revert { + WILL_REVERT, + WONT_REVERT + } + + public static void appendGenericCall( + BytecodeCompiler program, + OpCode callOpcode, + GasParam gasParam, + Address to, + ValueParameter valueParameter, + OfstParam cdo, + SizeParam cds, + OfstParam rao, + SizeParam rac, + int userDefinedGas, + int userDefinedValue) { + program.push(rac.value()).push(rao.value()).push(cds.value()).push(cdo.value()); + if (callOpcode.callHasValueArgument()) { + switch (valueParameter) { + case ZERO -> program.push(0); + case ONE -> program.push(1); + case BALANCE -> program.op(BALANCE); + case BALANCE_PLUS_ONE -> program.op(BALANCE).push(1).op(ADD); + case MAX_UINT_256 -> program.push("ff".repeat(32)); + case USER_DEFINED -> program.push(userDefinedValue); + } + } + program.push(to); + switch (gasParam) { + case ZERO -> program.push(0); + case GAS -> program.op(GAS); + case GAS_PLUS_ONE -> program.op(GAS).push(1).op(ADD); + case MAX_UINT_256 -> program.push("ff".repeat(32)); + case USER_DEFINED -> program.push(userDefinedGas); + } + program.op(callOpcode); + } + public static void appendFullGasCall( BytecodeCompiler program, OpCode callOpcode, diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/utilities/enums/GasParam.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/utilities/enums/GasParam.java new file mode 100644 index 0000000000..8c92803cb8 --- /dev/null +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/utilities/enums/GasParam.java @@ -0,0 +1,24 @@ +/* + * Copyright Consensys Software 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.instructionprocessing.utilities.enums; + +public enum GasParam { + ZERO, + GAS, + GAS_PLUS_ONE, + MAX_UINT_256, + USER_DEFINED; +} + diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/utilities/enums/OfstParam.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/utilities/enums/OfstParam.java new file mode 100644 index 0000000000..0cfe8aad9e --- /dev/null +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/utilities/enums/OfstParam.java @@ -0,0 +1,36 @@ +/* + * Copyright Consensys Software 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.instructionprocessing.utilities.enums; + +public enum OfstParam { + // aligned + ZERO("00"), + SIXTEEN("10"), + THIRTY_TWO("20"), + // unaligned + THIRTEEN("0d"), // -3 + THIRTY_SIX("24"), // + 4 + FIFTY_FIVE("37"), // + 7 + HUGE("124ab874bbaa123456098f861235567bbbbacde765213"), + MAX("ff".repeat(32)); + + private final String value; + OfstParam(String s) { + this.value = s; + } + public String value() { + return value; + } +} diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/utilities/enums/SizeParam.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/utilities/enums/SizeParam.java new file mode 100644 index 0000000000..69fc9ac40e --- /dev/null +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/utilities/enums/SizeParam.java @@ -0,0 +1,37 @@ +/* + * Copyright Consensys Software 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.instructionprocessing.utilities.enums; + +public enum SizeParam { + // aligned + ZERO("00"), + SIXTEEN("10"), + EVM_WORD("20"), + // unaligned + THREE("03"), // + 3 + SIXTY("3c"), // - 4 + FIFTY_FIVE("37"), // + 7 + HUGE("43565efefffeeabc54213576345234"), + MAX("ff".repeat(32)) + ; + + private final String value; + SizeParam(String s) { + this.value = s; + } + public String value() { + return value; + } +} diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/utilities/enums/ValueParameter.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/utilities/enums/ValueParameter.java new file mode 100644 index 0000000000..c13b51526e --- /dev/null +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/utilities/enums/ValueParameter.java @@ -0,0 +1,24 @@ +/* + * Copyright Consensys Software 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.instructionprocessing.utilities.enums; + +public enum ValueParameter { + ZERO, + ONE, + BALANCE, + BALANCE_PLUS_ONE, + MAX_UINT_256, + USER_DEFINED; +} From bb8c70ace2d55076f853668c4047b29fc159dc14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Tue, 26 Nov 2024 14:58:44 +0700 Subject: [PATCH 6/6] ras: IDENTITY test stuff --- .../callTests/prc/identity/Tests.java | 78 ++++++++++++------- 1 file changed, 51 insertions(+), 27 deletions(-) diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/callTests/prc/identity/Tests.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/callTests/prc/identity/Tests.java index 05907ca11b..360d53949d 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/callTests/prc/identity/Tests.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/callTests/prc/identity/Tests.java @@ -40,6 +40,8 @@ import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.core.Transaction; +import org.junit.jupiter.api.Tag; +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; @@ -89,23 +91,30 @@ void nontrivialCallDataIdentityTest(OpCode callOpCode) { 7, 51); program.op(RETURNDATASIZE); // should return 512 + run(program); + } - identityCaller.setCode(program.compile()); + @Test + void callCodeTransfersValueToIdentityTest() { + BytecodeCompiler program = BytecodeCompiler.newProgram(); + fullCodeCopyOf(program, byteSource); + appendGenericCall(program, CALLCODE, GAS, Address.ID, ValueParameter.ONE, OfstParam.ZERO, SizeParam.ZERO, OfstParam.ZERO, SizeParam.ZERO, 0, 0); + program.op(RETURNDATASIZE); - Transaction transaction = - ToyTransaction.builder() - .sender(userAccount) - .keyPair(keyPair) - .to(identityCaller) - .value(Wei.of(7_000_000_000L)) - .build(); - ToyExecutionEnvironmentV2.builder() - .accounts(List.of(byteSource, userAccount, identityCaller)) - .transaction(transaction) - .build() - .run(); + run(program); } + @Test + void callCodeNoValueValueTransferToIdentityTest() { + BytecodeCompiler program = BytecodeCompiler.newProgram(); + fullCodeCopyOf(program, byteSource); + appendGenericCall(program, CALLCODE, GAS, Address.ID, ValueParameter.ZERO, OfstParam.ZERO, SizeParam.ZERO, OfstParam.ZERO, SizeParam.ZERO, 0, 0); + program.op(RETURNDATASIZE); + + run(program); + } + + // @Tag("nightly") @ParameterizedTest @MethodSource("callParameterIDENTITY") void genericIdentityTests( @@ -114,21 +123,9 @@ void genericIdentityTests( BytecodeCompiler program = BytecodeCompiler.newProgram(); fullCodeCopyOf(program, byteSource); appendGenericCall(program, callOpCode, gasParam, Address.ID, ValueParameter.ONE, cdo, cds, rao, rac, 0, 0); - identityCaller.setCode(program.compile()); + program.op(RETURNDATASIZE); - Transaction transaction = - ToyTransaction.builder() - .sender(userAccount) - .keyPair(keyPair) - .to(identityCaller) - .value(Wei.of(7_000_000_000L)) - .build(); - - ToyExecutionEnvironmentV2.builder() - .accounts(List.of(byteSource, userAccount, identityCaller)) - .transaction(transaction) - .build() - .run(); + run(program); } /** @@ -159,8 +156,16 @@ static Stream callParameterIDENTITY() { for (GasParam gasParam : gasParams) { for (OfstParam cdo : OfstParam.values()) { for (SizeParam cds : SizeParam.values()) { + if ((cds == SizeParam.ZERO) && !(cdo == OfstParam.ZERO || cdo == OfstParam.SIXTEEN)) { + continue; + } for (OfstParam rao : OfstParam.values()) { for (SizeParam rac : SizeParam.values()) { + + if ((rac == SizeParam.ZERO) && !(rao == OfstParam.ZERO || rao == OfstParam.SIXTEEN)) { + continue; + } + arguments.add(Arguments.of(callOpCode, gasParam, cdo, cds, rao, rac)); } } @@ -170,4 +175,23 @@ static Stream callParameterIDENTITY() { } return arguments.stream(); } + + void run(BytecodeCompiler program) { + + identityCaller.setCode(program.compile()); + + Transaction transaction = + ToyTransaction.builder() + .sender(userAccount) + .keyPair(keyPair) + .to(identityCaller) + .value(Wei.of(7_000_000_000L)) + .build(); + ToyExecutionEnvironmentV2.builder() + .accounts(List.of(byteSource, userAccount, identityCaller)) + .transaction(transaction) + .build() + .run(); + } + }