From 14d9b10dde683301050310bd420a5f8639f5d669 Mon Sep 17 00:00:00 2001 From: Danno Ferrin Date: Fri, 24 Jan 2025 12:25:11 -0700 Subject: [PATCH 1/2] Improve BLOCKHASH Short Circuit Improve efficiency of the blockhash range checking by only testing the soughtBlock. Signed-off-by: Danno Ferrin --- .../org/hyperledger/besu/evm/operation/BlockHashOperation.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 60a16229e35..6c2ae606091 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 @@ -59,7 +59,7 @@ public OperationResult execute(final MessageFrame frame, final EVM evm) { // If the current block is the genesis block or the sought block is // not within the lookback window, zero is returned. - if (currentBlockNumber == 0 + if (soughtBlock < 0 || soughtBlock >= currentBlockNumber || soughtBlock < (currentBlockNumber - blockHashLookup.getLookback())) { frame.pushStackItem(Bytes32.ZERO); From 72e85786753c5acc1114de0625ace55613e0fe8b Mon Sep 17 00:00:00 2001 From: Danno Ferrin Date: Fri, 24 Jan 2025 13:05:41 -0700 Subject: [PATCH 2/2] docs Signed-off-by: Danno Ferrin --- .../hyperledger/besu/evm/operation/BlockHashOperation.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 6c2ae606091..332e7140509 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 @@ -57,8 +57,8 @@ public OperationResult execute(final MessageFrame frame, final EVM evm) { final long currentBlockNumber = blockValues.getNumber(); final BlockHashLookup blockHashLookup = frame.getBlockHashLookup(); - // If the current block is the genesis block or the sought block is - // not within the lookback window, zero is returned. + // If the sought block is negative, a future block, the current block, or not in the + // lookback window, zero is returned. if (soughtBlock < 0 || soughtBlock >= currentBlockNumber || soughtBlock < (currentBlockNumber - blockHashLookup.getLookback())) {