EIP7516 - Add BlobBaseFee opcode to Cancun EVM (#5884)

Signed-off-by: Gabriel-Trintinalia <gabriel.trintinalia@consensys.net>
pull/5893/head
Gabriel-Trintinalia 1 year ago committed by GitHub
parent 80d9adaea5
commit c4f73aa643
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionProcessor.java
  2. 7
      ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/MessageFrameTestFixture.java
  3. 7
      ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/EvmToolCommand.java
  4. 4
      evm/src/main/java/org/hyperledger/besu/evm/MainnetEVMs.java
  5. 13
      evm/src/main/java/org/hyperledger/besu/evm/fluent/EVMExecutor.java
  6. 23
      evm/src/main/java/org/hyperledger/besu/evm/frame/MessageFrame.java
  7. 1
      evm/src/main/java/org/hyperledger/besu/evm/frame/TxValues.java
  8. 41
      evm/src/main/java/org/hyperledger/besu/evm/operation/BlobBaseFeeOperation.java
  9. 7
      evm/src/test/java/org/hyperledger/besu/evm/testutils/TestMessageFrameBuilder.java

@ -363,6 +363,7 @@ public class MainnetTransactionProcessor {
.initialGas(gasAvailable)
.originator(senderAddress)
.gasPrice(transactionGasPrice)
.blobGasPrice(blobGasPrice)
.sender(senderAddress)
.value(transaction.getValue())
.apparentValue(transaction.getValue())

@ -48,6 +48,7 @@ public class MessageFrameTestFixture {
private Address originator = DEFAUT_ADDRESS;
private Address contract = DEFAUT_ADDRESS;
private Wei gasPrice = Wei.ZERO;
private Wei blobGasPrice = Wei.ZERO;
private Wei value = Wei.ZERO;
private Bytes inputData = Bytes.EMPTY;
private Code code = CodeV0.EMPTY_CODE;
@ -117,6 +118,11 @@ public class MessageFrameTestFixture {
return this;
}
public MessageFrameTestFixture blobGasPrice(final Wei blobGasPrice) {
this.blobGasPrice = blobGasPrice;
return this;
}
public MessageFrameTestFixture value(final Wei value) {
this.value = value;
return this;
@ -160,6 +166,7 @@ public class MessageFrameTestFixture {
.address(address)
.originator(originator)
.gasPrice(gasPrice)
.blobGasPrice(blobGasPrice)
.inputData(inputData)
.sender(sender)
.value(value)

@ -116,6 +116,12 @@ public class EvmToolCommand implements Runnable {
paramLabel = "<int>")
private final Wei gasPriceGWei = Wei.ZERO;
@Option(
names = {"--blob-price"},
description = "Price of blob gas for this invocation",
paramLabel = "<int>")
private final Wei blobGasPrice = Wei.ZERO;
@Option(
names = {"--sender"},
paramLabel = "<address>",
@ -376,6 +382,7 @@ public class EvmToolCommand implements Runnable {
.originator(sender)
.sender(sender)
.gasPrice(gasPriceGWei)
.blobGasPrice(blobGasPrice)
.inputData(callData)
.value(ethValue)
.apparentValue(ethValue)

@ -33,6 +33,7 @@ import org.hyperledger.besu.evm.operation.AddressOperation;
import org.hyperledger.besu.evm.operation.AndOperation;
import org.hyperledger.besu.evm.operation.BalanceOperation;
import org.hyperledger.besu.evm.operation.BaseFeeOperation;
import org.hyperledger.besu.evm.operation.BlobBaseFeeOperation;
import org.hyperledger.besu.evm.operation.BlobHashOperation;
import org.hyperledger.besu.evm.operation.BlockHashOperation;
import org.hyperledger.besu.evm.operation.ByteOperation;
@ -856,6 +857,9 @@ public class MainnetEVMs {
// EIP-6780 nerf self destruct
registry.put(new SelfDestructOperation(gasCalculator, true));
// EIP-7516 BLOBBASEFEE
registry.put(new BlobBaseFeeOperation(gasCalculator));
}
/**

@ -58,6 +58,7 @@ public class EVMExecutor {
private Address receiver = Address.ZERO;
private Address sender = Address.ZERO;
private Wei gasPriceGWei = Wei.ZERO;
private Wei blobGasPrice = Wei.ZERO;
private Bytes callData = Bytes.EMPTY;
private Wei ethValue = Wei.ZERO;
private Code code = CodeV0.EMPTY_CODE;
@ -354,6 +355,7 @@ public class EVMExecutor {
.originator(sender)
.sender(sender)
.gasPrice(gasPriceGWei)
.blobGasPrice(blobGasPrice)
.inputData(callData)
.value(ethValue)
.apparentValue(ethValue)
@ -457,6 +459,17 @@ public class EVMExecutor {
return this;
}
/**
* Sets Blob Gas price.
*
* @param blobGasPrice the blob gas price g wei
* @return the evm executor
*/
public EVMExecutor blobGasPrice(final Wei blobGasPrice) {
this.blobGasPrice = blobGasPrice;
return this;
}
/**
* Sets Call data.
*

@ -1134,6 +1134,15 @@ public class MessageFrame {
return txValues.gasPrice();
}
/**
* Returns the current blob gas price.
*
* @return the current blob gas price
*/
public Wei getBlobGasPrice() {
return txValues.blobGasPrice();
}
/**
* Returns the recipient of the sender.
*
@ -1365,6 +1374,7 @@ public class MessageFrame {
private Address originator;
private Address contract;
private Wei gasPrice;
private Wei blobGasPrice = Wei.ZERO;
private Bytes inputData;
private Address sender;
private Wei value;
@ -1472,6 +1482,17 @@ public class MessageFrame {
return this;
}
/**
* Sets Blob Gas price.
*
* @param blobGasPrice the blob gas price
* @return the builder
*/
public Builder blobGasPrice(final Wei blobGasPrice) {
this.blobGasPrice = blobGasPrice;
return this;
}
/**
* Sets Input data.
*
@ -1653,6 +1674,7 @@ public class MessageFrame {
checkState(worldUpdater != null, "Missing message frame world updater");
checkState(originator != null, "Missing message frame originator");
checkState(gasPrice != null, "Missing message frame getGasRemaining price");
checkState(blobGasPrice != null, "Missing message frame blob gas price");
checkState(blockValues != null, "Missing message frame block header");
checkState(miningBeneficiary != null, "Missing mining beneficiary");
checkState(blockHashLookup != null, "Missing block hash lookup");
@ -1689,6 +1711,7 @@ public class MessageFrame {
UndoTable.of(HashBasedTable.create()),
originator,
gasPrice,
blobGasPrice,
blockValues,
new ArrayDeque<>(),
miningBeneficiary,

@ -40,6 +40,7 @@ public record TxValues(
UndoTable<Address, Bytes32, Boolean> warmedUpStorage,
Address originator,
Wei gasPrice,
Wei blobGasPrice,
BlockValues blockValues,
Deque<MessageFrame> messageFrameStack,
Address miningBeneficiary,

@ -0,0 +1,41 @@
/*
* Copyright contributors to Hyperledger Besu
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/
package org.hyperledger.besu.evm.operation;
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.evm.EVM;
import org.hyperledger.besu.evm.frame.MessageFrame;
import org.hyperledger.besu.evm.gascalculator.GasCalculator;
/** The Blob Base fee operation. */
public class BlobBaseFeeOperation extends AbstractFixedCostOperation {
/**
* Instantiates a new Blob Base fee operation.
*
* @param gasCalculator the gas calculator
*/
public BlobBaseFeeOperation(final GasCalculator gasCalculator) {
super(0x4a, "BLOBBASEFEE", 0, 1, gasCalculator, gasCalculator.getBaseTierGasCost());
}
@Override
public OperationResult executeFixedCostOperation(final MessageFrame frame, final EVM evm) {
final Wei blobGasPrice = frame.getBlobGasPrice();
frame.pushStackItem(blobGasPrice.toBytes());
return successResponse;
}
}

@ -47,6 +47,7 @@ public class TestMessageFrameBuilder {
private Address originator = DEFAUT_ADDRESS;
private Address contract = DEFAUT_ADDRESS;
private Wei gasPrice = Wei.ZERO;
private Wei blobGasPrice = Wei.ZERO;
private Wei value = Wei.ZERO;
private Bytes inputData = Bytes.EMPTY;
private Code code = CodeV0.EMPTY_CODE;
@ -91,6 +92,11 @@ public class TestMessageFrameBuilder {
return this;
}
public TestMessageFrameBuilder blobGasPrice(final Wei blobGasPrice) {
this.blobGasPrice = blobGasPrice;
return this;
}
public TestMessageFrameBuilder value(final Wei value) {
this.value = value;
return this;
@ -145,6 +151,7 @@ public class TestMessageFrameBuilder {
.address(address)
.originator(originator)
.gasPrice(gasPrice)
.blobGasPrice(blobGasPrice)
.inputData(inputData)
.sender(sender)
.value(value)

Loading…
Cancel
Save