Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EIP7516 - Add BlobBaseFee opcode to Cancun EVM #5884

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ public TransactionProcessingResult processTransaction(
.initialGas(gasAvailable)
.originator(senderAddress)
.gasPrice(transactionGasPrice)
.blobGasPrice(blobGasPrice)
.sender(senderAddress)
.value(transaction.getValue())
.apparentValue(transaction.getValue())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ public TransactionProcessingResult processTransaction(
.initialGas(Long.MAX_VALUE)
.originator(senderAddress)
.gasPrice(transaction.getGasPrice())
.blobGasPrice(Wei.ZERO)
.sender(senderAddress)
.value(transaction.getValue())
.apparentValue(transaction.getValue())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -117,6 +118,11 @@ public MessageFrameTestFixture gasPrice(final Wei gasPrice) {
return this;
}

public MessageFrameTestFixture blobGasPrice(final Wei blobGasPrice) {
this.blobGasPrice = blobGasPrice;
return this;
}

public MessageFrameTestFixture value(final Wei value) {
this.value = value;
return this;
Expand Down Expand Up @@ -160,6 +166,7 @@ public MessageFrame build() {
.address(address)
.originator(originator)
.gasPrice(gasPrice)
.blobGasPrice(blobGasPrice)
.inputData(inputData)
.sender(sender)
.value(value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,12 @@ void setBytes(final String optionValue) {
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>",
Expand Down Expand Up @@ -376,6 +382,7 @@ public void run() {
.originator(sender)
.sender(sender)
.gasPrice(gasPriceGWei)
.blobGasPrice(blobGasPrice)
.inputData(callData)
.value(ethValue)
.apparentValue(ethValue)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public abstract class BenchmarkExecutor {
.blockHashLookup(n -> null)
.blockValues(new SimpleBlockValues())
.gasPrice(Wei.ZERO)
.blobGasPrice(Wei.ZERO)
Gabriel-Trintinalia marked this conversation as resolved.
Show resolved Hide resolved
.miningBeneficiary(Address.ZERO)
.originator(Address.ZERO)
.initialGas(100_000L)
Expand Down
4 changes: 4 additions & 0 deletions evm/src/main/java/org/hyperledger/besu/evm/MainnetEVMs.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
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;
Expand Down Expand Up @@ -856,6 +857,9 @@ public static void registerCancunOperations(

// EIP-6780 nerf self destruct
registry.put(new SelfDestructOperation(gasCalculator, true));

// EIP-7516 BLOBBASEFEE
registry.put(new BlobBaseFeeOperation(gasCalculator));
}

/**
Expand Down
13 changes: 13 additions & 0 deletions evm/src/main/java/org/hyperledger/besu/evm/fluent/EVMExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -354,6 +355,7 @@ public Bytes execute() {
.originator(sender)
.sender(sender)
.gasPrice(gasPriceGWei)
.blobGasPrice(blobGasPrice)
.inputData(callData)
.value(ethValue)
.apparentValue(ethValue)
Expand Down Expand Up @@ -457,6 +459,17 @@ public EVMExecutor gasPriceGWei(final Wei gasPriceGWei) {
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.
*
Expand Down
23 changes: 23 additions & 0 deletions evm/src/main/java/org/hyperledger/besu/evm/frame/MessageFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -1134,6 +1134,15 @@ public Wei getGasPrice() {
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.
*
Expand Down Expand Up @@ -1365,6 +1374,7 @@ public static class Builder {
private Address originator;
private Address contract;
private Wei gasPrice;
private Wei blobGasPrice;
private Bytes inputData;
private Address sender;
private Wei value;
Expand Down Expand Up @@ -1472,6 +1482,17 @@ public Builder gasPrice(final Wei gasPrice) {
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.
*
Expand Down Expand Up @@ -1653,6 +1674,7 @@ private void validate() {
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");
Gabriel-Trintinalia marked this conversation as resolved.
Show resolved Hide resolved
checkState(blockValues != null, "Missing message frame block header");
checkState(miningBeneficiary != null, "Missing mining beneficiary");
checkState(blockHashLookup != null, "Missing block hash lookup");
Expand Down Expand Up @@ -1689,6 +1711,7 @@ public MessageFrame build() {
UndoTable.of(HashBasedTable.create()),
originator,
gasPrice,
blobGasPrice,
blockValues,
new ArrayDeque<>(),
miningBeneficiary,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ private MessageFrame createJumpFrame(final CodeV0 getsCached) {
.originator(Address.ZERO)
.contract(Address.ZERO)
.gasPrice(Wei.ZERO)
.blobGasPrice(Wei.ZERO)
.inputData(Bytes.EMPTY)
.sender(Address.ZERO)
.value(Wei.ZERO)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ private void executeOperation(final Bytes contract, final EVM evm) {
.blockHashLookup(n -> Hash.hash(Words.longBytes(n)))
.blockValues(mock(BlockValues.class))
.gasPrice(Wei.ZERO)
.blobGasPrice(Wei.ZERO)
.miningBeneficiary(Address.ZERO)
.originator(Address.ZERO)
.initialGas(100000L)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ public void setUp(final String sender, final String salt, final String code) {
.blockHashLookup(n -> Hash.hash(Words.longBytes(n)))
.blockValues(mock(BlockValues.class))
.gasPrice(Wei.ZERO)
.blobGasPrice(Wei.ZERO)
.miningBeneficiary(Address.ZERO)
.originator(Address.ZERO)
.initialGas(100_000L)
Expand Down Expand Up @@ -272,6 +273,7 @@ private MessageFrame testMemoryFrame(
.blockHashLookup(n -> Hash.hash(Words.longBytes(n)))
.blockValues(mock(BlockValues.class))
.gasPrice(Wei.ZERO)
.blobGasPrice(Wei.ZERO)
.miningBeneficiary(Address.ZERO)
.originator(Address.ZERO)
.initialGas(100000L)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ private MessageFrame testMemoryFrame(
.blockHashLookup(n -> Hash.hash(Words.longBytes(n)))
.blockValues(mock(BlockValues.class))
.gasPrice(Wei.ZERO)
.blobGasPrice(Wei.ZERO)
.miningBeneficiary(Address.ZERO)
.originator(Address.ZERO)
.initialGas(100000L)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ void checkContractDeletionCommon(
.blockHashLookup(n -> Hash.hash(Words.longBytes(n)))
.blockValues(mock(BlockValues.class))
.gasPrice(Wei.ZERO)
.blobGasPrice(Wei.ZERO)
.miningBeneficiary(Address.ZERO)
.originator(Address.ZERO)
.initialGas(100_000L)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -91,6 +92,11 @@ public TestMessageFrameBuilder gasPrice(final Wei gasPrice) {
return this;
}

public TestMessageFrameBuilder blobGasPrice(final Wei blobGasPrice) {
this.blobGasPrice = blobGasPrice;
return this;
}

public TestMessageFrameBuilder value(final Wei value) {
this.value = value;
return this;
Expand Down Expand Up @@ -145,6 +151,7 @@ public MessageFrame build() {
.address(address)
.originator(originator)
.gasPrice(gasPrice)
.blobGasPrice(blobGasPrice)
.inputData(inputData)
.sender(sender)
.value(value)
Expand Down