-
Notifications
You must be signed in to change notification settings - Fork 46
feat: forced transaction #2418
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: forced transaction #2418
Changes from all commits
d95c86d
4fdfc93
92d0001
d7ae571
8463dd5
69004d5
ef6efec
62a1b28
a90b9a4
da7858e
2c2dbcc
2c8fcd5
377541d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,12 +16,14 @@ | |
| package net.consensys.linea.zktracer; | ||
|
|
||
| import static net.consensys.linea.zktracer.Fork.*; | ||
| import static net.consensys.linea.zktracer.Trace.*; | ||
| import static net.consensys.linea.zktracer.Trace.Ecdata.TOTAL_SIZE_ECPAIRING_DATA_MIN; | ||
| import static net.consensys.linea.zktracer.TraceCancun.Oob.CT_MAX_CALL; | ||
| import static net.consensys.linea.zktracer.TraceCancun.Oob.CT_MAX_CREATE; | ||
| import static net.consensys.linea.zktracer.module.ModuleName.*; | ||
| import static net.consensys.linea.zktracer.module.ModuleName.GAS; | ||
| import static net.consensys.linea.zktracer.module.add.AddOperation.NB_ROWS_ADD; | ||
| import static net.consensys.linea.zktracer.module.blake2fmodexpdata.BlakeModexpDataOperation.NB_ROWS_BLAKEMODEPX_BLAKE; | ||
| import static net.consensys.linea.zktracer.module.blake2fmodexpdata.BlakeModexpDataOperation.NB_ROWS_BLAKEMODEXP_MODEXP; | ||
| import static net.consensys.linea.zktracer.module.blockdata.module.CancunBlockData.NB_ROWS_BLOCK_DATA; | ||
| import static net.consensys.linea.zktracer.module.blockhash.BlockhashOperation.NB_ROWS_BLOCKHASH; | ||
|
|
@@ -42,6 +44,7 @@ | |
| import static net.consensys.linea.zktracer.module.hub.section.StackOnlySection.NB_ROWS_HUB_SIMPLE_STACK_OP; | ||
| import static net.consensys.linea.zktracer.module.hub.section.StackRamSection.NB_ROWS_HUB_STACKRAM; | ||
| import static net.consensys.linea.zktracer.module.hub.section.call.CallSection.NB_ROWS_HUB_CALL; | ||
| import static net.consensys.linea.zktracer.module.hub.section.call.precompileSubsection.BlakeSubsection.NB_ROWS_HUB_PRC_BLAKE; | ||
| import static net.consensys.linea.zktracer.module.hub.section.call.precompileSubsection.EllipticCurvePrecompileSubsection.NB_ROWS_HUB_PRC_ELLIPTIC_CURVE; | ||
| import static net.consensys.linea.zktracer.module.hub.section.call.precompileSubsection.IdentitySubsection.NB_ROWS_HUB_PRC_IDENTITY; | ||
| import static net.consensys.linea.zktracer.module.hub.section.call.precompileSubsection.ModexpSubsection.NB_ROWS_HUB_PRC_MODEXP; | ||
|
|
@@ -65,7 +68,6 @@ | |
| import static net.consensys.linea.zktracer.module.hub.section.txInitializationSection.TxInitializationSection.NB_ROWS_HUB_INIT; | ||
| import static net.consensys.linea.zktracer.module.logdata.LogData.lineCountForLogData; | ||
| import static net.consensys.linea.zktracer.module.loginfo.LogInfo.lineCountForLogInfo; | ||
| import static net.consensys.linea.zktracer.module.mod.ModOperation.NB_ROWS_MOD; | ||
| import static net.consensys.linea.zktracer.module.mxp.moduleCall.CancunMSizeMxpCall.NB_ROWS_MXP_MSIZE; | ||
| import static net.consensys.linea.zktracer.module.mxp.moduleCall.CancunStateUpdateMxpCall.NB_ROWS_MXP_UPDT_B; | ||
| import static net.consensys.linea.zktracer.module.mxp.moduleCall.CancunStateUpdateWordPricingMxpCall.NB_ROWS_MXP_UPDT_W; | ||
|
|
@@ -88,7 +90,6 @@ | |
| import java.util.*; | ||
| import java.util.stream.Stream; | ||
|
|
||
| import lombok.Getter; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import net.consensys.linea.plugins.config.LineaL1L2BridgeSharedConfiguration; | ||
| import net.consensys.linea.zktracer.container.module.CountingOnlyModule; | ||
|
|
@@ -209,16 +210,9 @@ public class ZkCounter implements LineCountingTracer { | |
| // related to Shakira: | ||
| private final Keccak keccak; | ||
| private final Sha256Blocks sha256Blocks = new Sha256Blocks(); | ||
| private final IncrementAndDetectModule ripemdBlocks = | ||
| new IncrementAndDetectModule(PRECOMPILE_RIPEMD_BLOCKS); | ||
| private final CountingOnlyModule ripemdBlocks = new CountingOnlyModule(PRECOMPILE_RIPEMD_BLOCKS); | ||
|
|
||
| // Related to Bls | ||
| // remove me when Linea supports Cancun & Prague precompiles | ||
| @Getter | ||
| private final IncrementAndDetectModule pointEval = new IncrementAndDetectModule(POINT_EVAL) {}; | ||
|
|
||
| @Getter private final IncrementAndDetectModule bls = new IncrementAndDetectModule(BLS) {}; | ||
|
|
||
| final IncrementingModule pointEvaluationEffectiveCall = | ||
| new IncrementingModule(PRECOMPILE_BLS_POINT_EVALUATION_EFFECTIVE_CALLS); | ||
| final IncrementingModule pointEvaluationFailureCall = | ||
|
|
@@ -313,8 +307,6 @@ public List<Module> checkedModules() { | |
| modexpEffectiveCall, | ||
| modexpLargeCall, | ||
| blakeEffectiveCall, | ||
| bls, | ||
| pointEval, | ||
| pointEvaluationEffectiveCall, | ||
| pointEvaluationFailureCall, | ||
| blsG1AddEffectiveCall, | ||
|
|
@@ -694,7 +686,6 @@ public void tracePrecompileCall(MessageFrame frame, long gasRequirement, Bytes o | |
| final boolean prcSuccess = frame.getState() == COMPLETED_SUCCESS; | ||
| final Bytes returnData = output == null ? Bytes.EMPTY : output; | ||
|
|
||
| // MMU | ||
| switch (precompile) { | ||
| case PRC_ECRECOVER, PRC_ECADD, PRC_ECMUL -> { | ||
| // trigger EcData to count the underlying EC operations | ||
|
|
@@ -708,28 +699,25 @@ public void tracePrecompileCall(MessageFrame frame, long gasRequirement, Bytes o | |
| case PRC_SHA2_256 -> { | ||
| hub.updateTally(NB_ROWS_HUB_PRC_SHARIP); | ||
| oob.updateTally(oobLineCountForPrc(precompile)); | ||
| mod.updateTally(NB_ROWS_MOD); // coming from OOB call | ||
| mod.updateTally(modLinesComingFromOobCall(precompile)); | ||
| if (prcSuccess && callDataSize != 0) { | ||
| shakiradata.updateTally(fromDataSizeToLimbNbRows(callDataSize) + NB_ROWS_SHAKIRA_RESULT); | ||
| sha256Blocks.updateTally(callData.size()); | ||
| } | ||
| } | ||
| case PRC_RIPEMD_160 -> { | ||
| ripemdBlocks.detectEvent(); | ||
| // Reenable me when RIPEMD is supported by the prover | ||
| // hub.updateTally(NB_ROWS_HUB_PRC_SHARIP); | ||
| // oob.updateTally(oobLineCountforPrc(precompile)); | ||
| // mod.updateTally(NB_ROWS_MOD); // coming from OOB call | ||
| // if (prcSuccess && callDataSize != 0) { | ||
| // shakiradata.updateTally(fromDataSizeToLimbNbRows(callDataSize) + | ||
| // NB_ROWS_SHAKIRA_RESULT); | ||
| // ripemdBlocks.updateTally(callDataSize); | ||
| // } | ||
| hub.updateTally(NB_ROWS_HUB_PRC_SHARIP); | ||
| oob.updateTally(oobLineCountForPrc(precompile)); | ||
| mod.updateTally(modLinesComingFromOobCall(precompile)); | ||
| if (prcSuccess && callDataSize != 0) { | ||
| shakiradata.updateTally(fromDataSizeToLimbNbRows(callDataSize) + NB_ROWS_SHAKIRA_RESULT); | ||
| ripemdBlocks.updateTally(callDataSize); | ||
| } | ||
| } | ||
| case PRC_IDENTITY -> { | ||
| hub.updateTally(NB_ROWS_HUB_PRC_IDENTITY); | ||
| oob.updateTally(oobLineCountForPrc(precompile)); | ||
| mod.updateTally(NB_ROWS_MOD); // coming from OOB call | ||
| mod.updateTally(modLinesComingFromOobCall(precompile)); | ||
| } | ||
| case PRC_MODEXP -> { | ||
| hub.updateTally(NB_ROWS_HUB_PRC_MODEXP); | ||
|
|
@@ -747,7 +735,7 @@ public void tracePrecompileCall(MessageFrame frame, long gasRequirement, Bytes o | |
| exp.call(modexpLogCallToExp); | ||
| } | ||
| oob.updateTally(oobLineCountForPrc(precompile)); | ||
| mod.updateTally(2 * NB_ROWS_MOD); // 2 coming from OOB pricing call | ||
| mod.updateTally(modLinesComingFromOobCall(precompile)); | ||
| } | ||
| case PRC_ECPAIRING -> { | ||
| // trigger EcData to count the underlying EC operations | ||
|
|
@@ -757,9 +745,15 @@ public void tracePrecompileCall(MessageFrame frame, long gasRequirement, Bytes o | |
| } | ||
| hub.updateTally(NB_ROWS_HUB_PRC_ELLIPTIC_CURVE); | ||
| oob.updateTally(oobLineCountForPrc(precompile)); | ||
| mod.updateTally(NB_ROWS_MOD); // coming from OOB call | ||
| mod.updateTally(modLinesComingFromOobCall(precompile)); | ||
| } | ||
| case PRC_BLAKE2F -> { | ||
| blakeEffectiveCall.updateTally(true); | ||
| hub.updateTally(NB_ROWS_HUB_PRC_BLAKE); | ||
| oob.updateTally(oobLineCountForPrc(PRC_BLAKE2F)); | ||
| blakemodexp.updateTally(NB_ROWS_BLAKEMODEPX_BLAKE); | ||
| // TODO: still unchecked module for now: blakeRounds.updateTally(); | ||
| } | ||
| case PRC_BLAKE2F -> blakeEffectiveCall.detectEvent(); | ||
| case PRC_BLS_G1_ADD, | ||
| PRC_BLS_G1_MSM, | ||
| PRC_BLS_G2_ADD, | ||
|
|
@@ -768,18 +762,12 @@ public void tracePrecompileCall(MessageFrame frame, long gasRequirement, Bytes o | |
| PRC_BLS_MAP_FP_TO_G1, | ||
| PRC_BLS_MAP_FP2_TO_G2, | ||
| PRC_POINT_EVALUATION -> { | ||
| if (precompile == PRC_POINT_EVALUATION) { | ||
| pointEval.detectEvent(); | ||
| } else { | ||
| bls.detectEvent(); | ||
| } | ||
| if (callDataSize != 0) { | ||
| // TODO: temporary commented out | ||
| // blsdata.callBls(0, precompile, frame.getInputData(), returnData, prcSuccess); | ||
| if (validCallDataSize(precompile, callDataSize)) { | ||
| blsdata.callBls(0, precompile, frame.getInputData(), returnData, prcSuccess); | ||
| } | ||
| hub.updateTally(NB_ROWS_HUB_PRC_ELLIPTIC_CURVE); | ||
| oob.updateTally(oobLineCountForPrc(precompile)); | ||
| // TODO: check if we have some MOD coming from OOB call | ||
| mod.updateTally(modLinesComingFromOobCall(precompile)); | ||
| } | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. LGTM, maybe add here that a comment saying that for PAIRING_CHECK we have a calll to DIV, while for MSM a call to DIV and one to MSM.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
What do you mean @lorenzogentile404 ? Do you mean |
||
| default -> throw new IllegalStateException("Unsupported precompile: " + precompile); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,7 @@ | |
| package net.consensys.linea.zktracer.module.hub.fragment.scenario; | ||
|
|
||
| import static java.util.Map.entry; | ||
| import static net.consensys.linea.zktracer.Trace.*; | ||
| import static net.consensys.linea.zktracer.TraceCancun.Oob.CT_MAX_IDENTITY; | ||
| import static net.consensys.linea.zktracer.TraceCancun.Oob.CT_MAX_RIPEMD; | ||
| import static net.consensys.linea.zktracer.TracePrague.Blsdata.CT_MAX_POINT_EVALUATION; | ||
|
|
@@ -34,6 +35,7 @@ | |
| import static net.consensys.linea.zktracer.module.hub.fragment.imc.oob.precompiles.modexp.ModexpXbsOobCall.NB_ROWS_OOB_MODEXP_XBS; | ||
| import static net.consensys.linea.zktracer.module.hub.fragment.scenario.PrecompileScenarioFragment.PrecompileFlag.*; | ||
| import static net.consensys.linea.zktracer.module.hub.fragment.scenario.PrecompileScenarioFragment.PrecompileScenario.*; | ||
| import static net.consensys.linea.zktracer.module.mod.ModOperation.NB_ROWS_MOD; | ||
|
|
||
| import java.util.Map; | ||
|
|
||
|
|
@@ -228,6 +230,34 @@ public static short oobLineCountForPrc(PrecompileFlag prc) { | |
| default -> throw new IllegalArgumentException("Precompile not supported:" + prc); | ||
| }; | ||
| } | ||
|
|
||
| public static boolean validCallDataSize( | ||
| PrecompileScenarioFragment.PrecompileFlag prc, int cds) { | ||
| return switch (prc) { | ||
| case PRC_POINT_EVALUATION -> cds == PRECOMPILE_CALL_DATA_SIZE___POINT_EVALUATION; | ||
| case PRC_BLS_G1_ADD -> cds == PRECOMPILE_CALL_DATA_SIZE___G1_ADD; | ||
| case PRC_BLS_G1_MSM -> cds != 0 && cds % PRECOMPILE_CALL_DATA_UNIT_SIZE___BLS_G1_MSM == 0; | ||
| case PRC_BLS_G2_ADD -> cds == PRECOMPILE_CALL_DATA_SIZE___G2_ADD; | ||
| case PRC_BLS_G2_MSM -> cds != 0 && cds % PRECOMPILE_CALL_DATA_UNIT_SIZE___BLS_G2_MSM == 0; | ||
| case PRC_BLS_PAIRING_CHECK -> cds != 0 | ||
| && cds % PRECOMPILE_CALL_DATA_UNIT_SIZE___BLS_PAIRING_CHECK == 0; | ||
| case PRC_BLS_MAP_FP_TO_G1 -> cds == PRECOMPILE_CALL_DATA_SIZE___FP_TO_G1; | ||
| case PRC_BLS_MAP_FP2_TO_G2 -> cds == PRECOMPILE_CALL_DATA_SIZE___FP2_TO_G2; | ||
| default -> throw new IllegalArgumentException("not implemented for prc: " + prc); | ||
| }; | ||
| } | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe the cases could be ordered by increasing addresses.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes |
||
|
|
||
| public static short modLinesComingFromOobCall(PrecompileScenarioFragment.PrecompileFlag prc) { | ||
| return switch (prc) { | ||
| case PRC_SHA2_256, | ||
| PRC_RIPEMD_160, | ||
| PRC_IDENTITY, | ||
| PRC_BLS_PAIRING_CHECK, | ||
| PRC_ECPAIRING -> NB_ROWS_MOD; | ||
| case PRC_MODEXP, PRC_BLS_G1_MSM, PRC_BLS_G2_MSM -> (short) (NB_ROWS_MOD * 2); | ||
| default -> 0; | ||
| }; | ||
| } | ||
| } | ||
|
|
||
| final PrecompileSubsection precompileSubSection; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A
BLSprecompile call triggers aBLS_DATAcall as soon as the call data is of the right size and gas is sufficient. Why use a partial condition ?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because in ZkCounter, we're plugged at tracePrecompileCall which is trigger only if enough gas if I'm not mistaken whereas the hub is trigger by the call preOpcode