@Override
  public OperationResult execute(final MessageFrame frame, final EVM evm) {
    final long cost = gasCalculator().getBlockHashOperationGasCost();
    if (frame.getRemainingGas() < cost) {
      return new OperationResult(cost, ExceptionalHaltReason.INSUFFICIENT_GAS);
    }

    // Make sure we can convert to long
    final Bytes blockArg = frame.popStackItem().trimLeadingZeros();
    if (blockArg.size() > MAX_BLOCK_ARG_SIZE) {
      frame.pushStackItem(Hash.ZERO);
      return new OperationResult(cost, null);
    }

    final long soughtBlock = blockArg.toLong();
    final BlockValues blockValues = frame.getBlockValues();
    final long currentBlockNumber = blockValues.getNumber();
    final BlockHashLookup blockHashLookup = frame.getBlockHashLookup();

    // 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())) {
      frame.pushStackItem(Bytes32.ZERO);
    } else {
      final Hash blockHash = blockHashLookup.apply(frame, soughtBlock);
      frame.pushStackItem(blockHash);
    }

    return new OperationResult(cost, null);
  }
Instantiates a new Block hash operation.

@param gasCalculator the gas calculator
evm/src/main/java/org/hyperledger/besu/evm/operation/BlockHashOperation.java