Skip to content

Commit

Permalink
rollback lookupcost modification during oog and fix after review
Browse files Browse the repository at this point in the history
Signed-off-by: Karim Taam <karim.t2am@gmail.com>
  • Loading branch information
matkt committed Feb 21, 2025
1 parent 34b96e9 commit bbaebfc
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
*/
public class Eip7709BlockHashProcessor extends PragueBlockHashProcessor {

// TODO we will have to use HISTORY_STORAGE_ADDRESS from PragueBlockHashProcessor in the future
public static final Address EIP_7709_HISTORY_STORAGE_ADDRESS =
Address.fromHexString("0xfffffffffffffffffffffffffffffffffffffffe");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ public Hash apply(final MessageFrame frame, final Long blockNumber) {
final UInt256 slot = UInt256.valueOf(blockNumber % historyServeWindow);

final long lookupCost = lookupCost(frame, slot);
if (frame.getRemainingGas() < lookupCost) {
frame.decrementRemainingGas(lookupCost);
if (frame.getRemainingGas() < 0) {
return null;
}
frame.decrementRemainingGas(lookupCost);

final Hash cachedHash = hashByNumber.get(blockNumber);
if (cachedHash != null) {
Expand All @@ -108,17 +108,13 @@ public Hash apply(final MessageFrame frame, final Long blockNumber) {
return blockHash;
}

public Address getContractAddress() {
return contractAddress;
}

@Override
public long getLookback() {
return blockHashServeWindow;
}

private long lookupCost(final MessageFrame frame, final UInt256 slotKey) {
long gas = frame.getAccessWitness().touchAndChargeStorageLoad(getContractAddress(), slotKey);
long gas = frame.getAccessWitness().touchAndChargeStorageLoad(contractAddress, slotKey);

if (gas == 0) {
return getWarmStorageReadCost();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,7 @@ public ReferenceTestEnv(
beaconRoot == null ? null : Bytes32.fromHexString(beaconRoot),
null, // requestsHash
new MainnetBlockHeaderFunctions(),
null // execution witnesses
);
null); // execution witnesses
this.parentDifficulty = parentDifficulty;
this.parentBaseFee = parentBaseFee;
this.parentGasUsed = parentGasUsed;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,20 @@ public OperationResult execute(final MessageFrame frame, final EVM evm) {
|| soughtBlock < (currentBlockNumber - blockHashLookup.getLookback())) {
frame.pushStackItem(Bytes32.ZERO);
return new OperationResult(cost, null);
} else {
final long remainingGas = frame.getRemainingGas();
final Hash blockHash = blockHashLookup.apply(frame, soughtBlock);
if (blockHash == null) { // when blockHashLookup return null we have INSUFFICIENT_GAS issue
return new OperationResult(cost, ExceptionalHaltReason.INSUFFICIENT_GAS);
}
final long lookupCost = remainingGas - frame.getRemainingGas();
// give lookupCost back as it will be taken after
frame.incrementRemainingGas(lookupCost);
}

final long remainingGas = frame.getRemainingGas();
final Hash blockHash = blockHashLookup.apply(frame, soughtBlock);
final long lookupCost = remainingGas - frame.getRemainingGas();
// give lookupCost back as it will be taken after
frame.incrementRemainingGas(lookupCost);

frame.pushStackItem(blockHash);
return new OperationResult(cost + lookupCost, null);
if (blockHash == null) { // when blockHashLookup return null we have INSUFFICIENT_GAS issue
return new OperationResult(cost + lookupCost, ExceptionalHaltReason.INSUFFICIENT_GAS);
}

frame.pushStackItem(blockHash);
return new OperationResult(cost + lookupCost, null);
}

/**
Expand Down

0 comments on commit bbaebfc

Please sign in to comment.