Skip to content

Commit

Permalink
fix: CREATE2 gas pricing (similar error to CREATE pricing error)
Browse files Browse the repository at this point in the history
  • Loading branch information
OlivierBBB committed Dec 2, 2024
1 parent 0611e0e commit 59c91cd
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,17 @@ public class StpCall implements TraceSubFragment {
@EqualsAndHashCode.Include long gasPaidOutOfPocket;
@EqualsAndHashCode.Include long stipend;

public StpCall(Hub hub, long memoryExpansionGas) {
this.memoryExpansionGas = memoryExpansionGas;
public StpCall(Hub hub, MessageFrame frame, long memoryExpansionGas) {
this.opCode = hub.opCode();
this.gasActual = hub.messageFrame().getRemainingGas();
checkArgument(this.opCode.isCall() || this.opCode.isCreate());

this.memoryExpansionGas = memoryExpansionGas;
this.gasActual = frame.getRemainingGas();

if (this.opCode.isCall()) {
this.stpCallForCalls(hub);
} else {
this.stpCallForCreates(hub);
this.stpCallForCreates(frame);
}
}

Expand Down Expand Up @@ -114,8 +115,7 @@ private long gasPaidOutOfPocketForCalls() {
}
}

private void stpCallForCreates(Hub hub) {
MessageFrame frame = hub.messageFrame();
private void stpCallForCreates(MessageFrame frame) {

this.gas = ZERO; // irrelevant
this.value = EWord.of(frame.getStackItem(0));
Expand All @@ -132,7 +132,7 @@ private long computeGasPaidOutOfPocketForCreates() {
return 0;
} else {
long gasMinusUpfrontCost = gasActual - upfrontGasCost;
return gasMinusUpfrontCost - (gasMinusUpfrontCost >> 6);
return gasMinusUpfrontCost - gasMinusUpfrontCost / 64;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public CreateSection(Hub hub, MessageFrame frame) {
return;
}

final StpCall stpCall = new StpCall(hub, mxpCall.getGasMxp());
final StpCall stpCall = new StpCall(hub, frame, mxpCall.getGasMxp());
imcFragment.callStp(stpCall);

checkArgument(stpCall.outOfGasException() == Exceptions.outOfGasException(exceptions));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public CallSection(Hub hub, MessageFrame frame) {
return;
}

stpCall = new StpCall(hub, mxpCall.gasMxp);
stpCall = new StpCall(hub, frame, mxpCall.gasMxp);
firstImcFragment.callStp(stpCall);
checkArgument(
stpCall.outOfGasException() == Exceptions.outOfGasException(exceptions),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

package net.consensys.linea.zktracer.opcode.gas.projector;

import static com.google.common.base.Preconditions.checkState;
import static org.hyperledger.besu.evm.internal.Words.clampedToLong;

import net.consensys.linea.zktracer.module.constants.GlobalConstants;
Expand Down Expand Up @@ -57,13 +58,15 @@ public long linearPerWord() {
@Override
public long gasPaidOutOfPocket() {
long currentGas = frame.getRemainingGas();
long gasCost = this.staticGas() + this.memoryExpansion() + this.linearPerWord();
long upfrontGasCost = this.upfrontGasCost();

if (gasCost > currentGas) {
if (upfrontGasCost > currentGas) {
return 0;
} else {
return currentGas - currentGas / 64;
}

final long gasMinusUpfrontGasCost = currentGas - upfrontGasCost;

return gasMinusUpfrontGasCost - gasMinusUpfrontGasCost / 64;
}

@Override
Expand Down

0 comments on commit 59c91cd

Please sign in to comment.