diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/blockhash/Eip7709BlockHashProcessor.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/blockhash/Eip7709BlockHashProcessor.java index 903efb5d3be..146300a5bb1 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/blockhash/Eip7709BlockHashProcessor.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/blockhash/Eip7709BlockHashProcessor.java @@ -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"); diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/vm/Eip7709BlockHashLookup.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/vm/Eip7709BlockHashLookup.java index fab1fb512b6..dad5454142c 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/vm/Eip7709BlockHashLookup.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/vm/Eip7709BlockHashLookup.java @@ -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) { @@ -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(); diff --git a/ethereum/referencetests/src/main/java/org/hyperledger/besu/ethereum/referencetests/ReferenceTestEnv.java b/ethereum/referencetests/src/main/java/org/hyperledger/besu/ethereum/referencetests/ReferenceTestEnv.java index a4e907dbfb5..3585ac0ce37 100644 --- a/ethereum/referencetests/src/main/java/org/hyperledger/besu/ethereum/referencetests/ReferenceTestEnv.java +++ b/ethereum/referencetests/src/main/java/org/hyperledger/besu/ethereum/referencetests/ReferenceTestEnv.java @@ -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; diff --git a/evm/src/main/java/org/hyperledger/besu/evm/operation/BlockHashOperation.java b/evm/src/main/java/org/hyperledger/besu/evm/operation/BlockHashOperation.java index 1f1c5bbc2ae..a85ce1dc775 100644 --- a/evm/src/main/java/org/hyperledger/besu/evm/operation/BlockHashOperation.java +++ b/evm/src/main/java/org/hyperledger/besu/evm/operation/BlockHashOperation.java @@ -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); } /**