Skip to content

Commit

Permalink
feat: add PRECOMPILE_ECPAIRING_G2_MEMBERSHIP_CALLS in spillings.toml …
Browse files Browse the repository at this point in the history
…and did some renaming (#819)


Signed-off-by: Tsvetan Dimitrov <[email protected]>
  • Loading branch information
OlivierBBB authored Jul 17, 2024
1 parent 2f1ce19 commit 561e204
Show file tree
Hide file tree
Showing 10 changed files with 450 additions and 197 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class CurveOperations {

public static BigInteger extractParameter(final Bytes input) {
if (input.isEmpty()) {
throw new IllegalArgumentException("EC_DATA input can not be empty");
throw new IllegalArgumentException("EC_DATA input cannot be empty");
}
return new BigInteger(1, input.toArray());
}
Expand All @@ -70,14 +70,8 @@ public static boolean isOnG2(Bytes xBytes) {
final Fq2 pX = Fq2.create(pXRe, pXIm);
final Fq2 pY = Fq2.create(pYRe, pYIm);

if (!pX.isValid() || !pY.isValid()) {
return false;
}

final AltBn128Fq2Point p2 = new AltBn128Fq2Point(pX, pY);
final AltBn128Fq2Point pPowQ = p2.multiply(Q);

return pPowQ.isInfinity();
return p2.isOnCurve() && p2.isInGroup();
}

public static boolean ecRecoverSuccessful(final Bytes input) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@
import net.consensys.linea.zktracer.module.limits.precompiles.BlakeRounds;
import net.consensys.linea.zktracer.module.limits.precompiles.EcAddEffectiveCall;
import net.consensys.linea.zktracer.module.limits.precompiles.EcMulEffectiveCall;
import net.consensys.linea.zktracer.module.limits.precompiles.EcPairingEffectiveCall;
import net.consensys.linea.zktracer.module.limits.precompiles.EcPairingMillerLoop;
import net.consensys.linea.zktracer.module.limits.precompiles.EcPairingFinalExponentiations;
import net.consensys.linea.zktracer.module.limits.precompiles.EcPairingG2MembershipCalls;
import net.consensys.linea.zktracer.module.limits.precompiles.EcPairingMillerLoops;
import net.consensys.linea.zktracer.module.limits.precompiles.EcRecoverEffectiveCall;
import net.consensys.linea.zktracer.module.limits.precompiles.ModexpEffectiveCall;
import net.consensys.linea.zktracer.module.limits.precompiles.RipemdBlocks;
Expand Down Expand Up @@ -285,7 +286,7 @@ public Hub(final Address l2l1ContractAddress, final Bytes l2l1Topic) {

final EcRecoverEffectiveCall ecRec = new EcRecoverEffectiveCall(this);
this.modexpEffectiveCall = new ModexpEffectiveCall(this, this.blakeModexpData);
final EcPairingEffectiveCall ecPairingCall = new EcPairingEffectiveCall(this);
final EcPairingFinalExponentiations ecPairingCall = new EcPairingFinalExponentiations(this);
final L2Block l2Block = new L2Block(l2l1ContractAddress, LogTopic.of(l2l1Topic));
final BlakeRounds blakeRounds = new BlakeRounds(this, this.blakeModexpData);

Expand All @@ -298,7 +299,8 @@ public Hub(final Address l2l1ContractAddress, final Bytes l2l1Topic) {
new EcAddEffectiveCall(this),
new EcMulEffectiveCall(this),
ecPairingCall,
new EcPairingMillerLoop(ecPairingCall),
new EcPairingG2MembershipCalls(ecPairingCall),
new EcPairingMillerLoops(ecPairingCall),
blakeRounds,
new BlakeEffectiveCall(blakeRounds),
// Block level limits
Expand Down Expand Up @@ -1082,9 +1084,9 @@ private boolean requiresEvmExecution(final WorldView worldView, final Transactio

public void traceContextReEnter(MessageFrame frame) {
this.defers.runReEntry(this, frame);
if (this.currentFrame().needsUnlatchingAtReEntry() != null) {
this.unlatchStack(frame, this.currentFrame().needsUnlatchingAtReEntry());
this.currentFrame().needsUnlatchingAtReEntry(null);
if (this.currentFrame().sectionToUnlatch() != null) {
this.unlatchStack(frame, this.currentFrame().sectionToUnlatch());
this.currentFrame().sectionToUnlatch(null);
}
}

Expand Down Expand Up @@ -1131,7 +1133,7 @@ public void tracePostExecution(MessageFrame frame, Operation.OperationResult ope
this.defers.runPostExec(this, frame, operationResult);
this.romLex.tracePostOpcode(frame);

if (this.currentFrame().needsUnlatchingAtReEntry() == null) {
if (this.currentFrame().sectionToUnlatch() == null) {
this.unlatchStack(frame);
}

Expand Down Expand Up @@ -1457,7 +1459,7 @@ void traceOperation(MessageFrame frame) {
CreateSection createSection =
new CreateSection(this, myAccountSnapshot, createdAccountSnapshot);
this.addTraceSection(createSection);
this.currentFrame().needsUnlatchingAtReEntry(createSection);
this.currentFrame().sectionToUnlatch(createSection);
}

case CALL -> {
Expand Down Expand Up @@ -1537,7 +1539,7 @@ void traceOperation(MessageFrame frame) {
new SmartContractCallSection(
this, myAccountSnapshot, calledAccountSnapshot, rawCalledAddress, imcFragment);
this.addTraceSection(section);
this.currentFrame().needsUnlatchingAtReEntry(section);
this.currentFrame().sectionToUnlatch(section);
} else {
//
// CALL EXECUTED
Expand Down Expand Up @@ -1566,7 +1568,7 @@ void traceOperation(MessageFrame frame) {
rawCalledAddress,
imcFragment);
this.addTraceSection(section);
this.currentFrame().needsUnlatchingAtReEntry(section);
this.currentFrame().sectionToUnlatch(section);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import net.consensys.linea.zktracer.module.limits.precompiles.BlakeRounds;
import net.consensys.linea.zktracer.module.limits.precompiles.EcAddEffectiveCall;
import net.consensys.linea.zktracer.module.limits.precompiles.EcMulEffectiveCall;
import net.consensys.linea.zktracer.module.limits.precompiles.EcPairingEffectiveCall;
import net.consensys.linea.zktracer.module.limits.precompiles.EcPairingFinalExponentiations;
import net.consensys.linea.zktracer.module.limits.precompiles.EcRecoverEffectiveCall;
import net.consensys.linea.zktracer.module.limits.precompiles.ModexpEffectiveCall;
import net.consensys.linea.zktracer.module.limits.precompiles.RipemdBlocks;
Expand Down Expand Up @@ -96,7 +96,7 @@ public static PrecompileInvocation of(final Hub hub, Precompile p) {
case MODEXP -> false;
case EC_ADD -> hub.transients().op().gasAllowanceForCall() < 150;
case EC_MUL -> hub.transients().op().gasAllowanceForCall() < 6000;
case EC_PAIRING -> EcPairingEffectiveCall.isHubFailure(hub);
case EC_PAIRING -> EcPairingFinalExponentiations.isHubFailure(hub);
case BLAKE2F -> BlakeRounds.isHubFailure(hub);
};

Expand All @@ -108,7 +108,7 @@ && switch (p) {
> hub.transients().op().gasAllowanceForCall();
case EC_ADD -> EcAddEffectiveCall.isRamFailure(hub);
case EC_MUL -> EcMulEffectiveCall.isRamFailure(hub);
case EC_PAIRING -> EcPairingEffectiveCall.isRamFailure(hub);
case EC_PAIRING -> EcPairingFinalExponentiations.isRamFailure(hub);
case BLAKE2F -> BlakeRounds.isRamFailure(hub);
};

Expand Down Expand Up @@ -137,7 +137,7 @@ && switch (p) {
case MODEXP -> ModexpEffectiveCall.gasCost(hub);
case EC_ADD -> EcAddEffectiveCall.gasCost();
case EC_MUL -> EcMulEffectiveCall.gasCost();
case EC_PAIRING -> EcPairingEffectiveCall.gasCost(hub);
case EC_PAIRING -> EcPairingFinalExponentiations.gasCost(hub);
case BLAKE2F -> BlakeRounds.gasCost(hub);
};

Expand Down

This file was deleted.

Loading

0 comments on commit 561e204

Please sign in to comment.