Skip to content

Commit

Permalink
Merge branch 'main' into zkbesu
Browse files Browse the repository at this point in the history
# Conflicts:
#	.github/pull_request_template.md
#	.github/workflows/sonarcloud.yml
  • Loading branch information
fab-10 committed Feb 3, 2025
2 parents 921c726 + 24e2895 commit 1d875cf
Show file tree
Hide file tree
Showing 105 changed files with 2,156 additions and 602 deletions.
10 changes: 8 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@
### Breaking Changes
### Upcoming Breaking Changes
### Additions and Improvements
- Adds timestamps to enable Prague hardfork on Sepolia and Holesky test networks. [#8163](https://github.com/hyperledger/besu/pull/8163)
- Add a tx selector to skip txs from the same sender after the first not selected [#8216](https://github.com/hyperledger/besu/pull/8216)

#### Prague
- Add timestamps to enable Prague hardfork on Sepolia and Holesky test networks [#8163](https://github.com/hyperledger/besu/pull/8163)
- Update system call addresses to match [devnet-6](https://github.com/ethereum/execution-spec-tests/releases/) values [#8209](https://github.com/hyperledger/besu/issues/8209)

#### Plugins
- Extend simulate transaction on pending block plugin API [#8174](https://github.com/hyperledger/besu/pull/8174)

### Bug fixes

- Fix the simulation of txs with a future nonce [#8215](https://github.com/hyperledger/besu/pull/8215)

## 25.1.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,7 @@ public BesuNode createExecutionEngineGenesisNode(final String name, final String
.jsonRpcTxPool()
.engineRpcEnabled(true)
.jsonRpcDebug()
.dataStorageConfiguration(DataStorageConfiguration.DEFAULT_BONSAI_CONFIG)
.build());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* 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.tests.acceptance.dsl.transaction.eth;

import static org.assertj.core.api.Assertions.assertThat;
import static org.web3j.protocol.core.DefaultBlockParameterName.LATEST;

import org.hyperledger.besu.tests.acceptance.dsl.account.Account;
import org.hyperledger.besu.tests.acceptance.dsl.transaction.NodeRequests;
import org.hyperledger.besu.tests.acceptance.dsl.transaction.Transaction;

import java.io.IOException;

import org.apache.tuweni.bytes.Bytes;
import org.web3j.protocol.core.methods.response.EthGetCode;

public class EthGetCodeTransaction implements Transaction<Bytes> {

private final Account account;

public EthGetCodeTransaction(final Account account) {
this.account = account;
}

@Override
public Bytes execute(final NodeRequests node) {
try {
final EthGetCode result = node.eth().ethGetCode(account.getAddress(), LATEST).send();
assertThat(result).isNotNull();
assertThat(result.hasError()).isFalse();

return Bytes.fromHexString(result.getCode());

} catch (final IOException e) {
throw new RuntimeException(e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ public EthGetBalanceTransaction getBalance(final Account account) {
return new EthGetBalanceTransaction(account);
}

public EthGetCodeTransaction getCode(final Account account) {
return new EthGetCodeTransaction(account);
}

public EthGetBalanceAtBlockTransaction getBalanceAtBlock(
final Account account, final BigInteger block) {
return new EthGetBalanceAtBlockTransaction(account, block);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ public class CodeDelegationTransactionAcceptanceTest extends AcceptanceTestBase
public static final Address SEND_ALL_ETH_CONTRACT_ADDRESS =
Address.fromHexStringStrict("0000000000000000000000000000000000009999");

public static final Address ALWAYS_REVERT_CONTRACT_ADDRESS =
Address.fromHexStringStrict("0000000000000000000000000000000000000666");

private final Account authorizer =
accounts.createAccount(
Address.fromHexStringStrict("8da48afC965480220a3dB9244771bd3afcB5d895"));
Expand Down Expand Up @@ -232,4 +235,124 @@ public void shouldCheckNonceAfterNonceIncreaseOfSender() throws IOException {
assertThat(otherAccountBalanceAfterFirstTx.add(BigInteger.ONE))
.isEqualTo(otherAccountBalanceAfterSecondTx);
}

/**
* EIP-7702 code delegation should be persisted even if the transaction that contains the
* authorization is reverted.
*/
@Test
public void shouldPersistCodeDelegationAfterRevert() throws IOException {
final long GAS_LIMIT = 1_000_000L;

// check the authorizer has no code before the transaction
final Bytes authorizerCodeBeforeCodeDelegation =
besuNode.execute(ethTransactions.getCode(authorizer));
assertThat(authorizerCodeBeforeCodeDelegation).isEqualTo(Bytes.EMPTY);

// valid 7702 code delegation to SEND_ALL_ETH_CONTRACT_ADDRESS
final CodeDelegation codeDelegation =
org.hyperledger.besu.ethereum.core.CodeDelegation.builder()
.chainId(BigInteger.valueOf(20211))
.nonce(0L)
.address(SEND_ALL_ETH_CONTRACT_ADDRESS)
.signAndBuild(
secp256k1.createKeyPair(
secp256k1.createPrivateKey(AUTHORIZER_PRIVATE_KEY.toUnsignedBigInteger())));

// the transaction will revert, because the to address is a contract that always reverts
final Transaction tx =
Transaction.builder()
.type(TransactionType.DELEGATE_CODE)
.chainId(BigInteger.valueOf(20211))
.nonce(0)
.maxPriorityFeePerGas(Wei.of(1_000_000_000))
.maxFeePerGas(Wei.fromHexString("0x02540BE400"))
.gasLimit(GAS_LIMIT)
.to(ALWAYS_REVERT_CONTRACT_ADDRESS)
.value(Wei.ZERO)
.payload(Bytes.EMPTY)
.codeDelegations(List.of(codeDelegation))
.signAndBuild(
secp256k1.createKeyPair(
secp256k1.createPrivateKey(
TRANSACTION_SPONSOR_PRIVATE_KEY.toUnsignedBigInteger())));

// include the tx in the next block
final String txHash =
besuNode.execute(ethTransactions.sendRawTransaction(tx.encoded().toHexString()));
testHelper.buildNewBlock();

// check that the transaction was included and has indeed reverted
Optional<TransactionReceipt> maybeTransactionReceipt =
besuNode.execute(ethTransactions.getTransactionReceipt(txHash));
assertThat(maybeTransactionReceipt).isPresent();
assertThat(maybeTransactionReceipt.get().getStatus()).isEqualTo("0x0");

// check the authorizer has the code delegation after the transaction even though it has
// reverted
final Bytes expectedCode =
Bytes.concatenate(Bytes.fromHexString("ef0100"), SEND_ALL_ETH_CONTRACT_ADDRESS);
final Bytes authorizerCode = besuNode.execute(ethTransactions.getCode(authorizer));
assertThat(authorizerCode).isEqualTo(expectedCode);
}

/**
* EIP-7702 code delegation should be persisted even if the transaction that contains the
* authorization is reverted and the transaction sender is the same as the code delegation
* authorizer.
*/
@Test
public void shouldPersistCodeDelegationAfterRevertWhenSelfSponsored() throws IOException {
final long GAS_LIMIT = 1_000_000L;

// check the authorizer has no code before the transaction
final Bytes authorizerCodeBeforeCodeDelegation =
besuNode.execute(ethTransactions.getCode(authorizer));
assertThat(authorizerCodeBeforeCodeDelegation).isEqualTo(Bytes.EMPTY);

// valid 7702 code delegation to SEND_ALL_ETH_CONTRACT_ADDRESS
final CodeDelegation codeDelegation =
org.hyperledger.besu.ethereum.core.CodeDelegation.builder()
.chainId(BigInteger.valueOf(20211))
.nonce(1L)
.address(SEND_ALL_ETH_CONTRACT_ADDRESS)
.signAndBuild(
secp256k1.createKeyPair(
secp256k1.createPrivateKey(AUTHORIZER_PRIVATE_KEY.toUnsignedBigInteger())));

// the transaction will revert, because the to address is a contract that always reverts
final Transaction tx =
Transaction.builder()
.type(TransactionType.DELEGATE_CODE)
.chainId(BigInteger.valueOf(20211))
.nonce(0)
.maxPriorityFeePerGas(Wei.of(1_000_000_000))
.maxFeePerGas(Wei.fromHexString("0x02540BE400"))
.gasLimit(GAS_LIMIT)
.to(ALWAYS_REVERT_CONTRACT_ADDRESS)
.value(Wei.ZERO)
.payload(Bytes.EMPTY)
.codeDelegations(List.of(codeDelegation))
.signAndBuild(
secp256k1.createKeyPair(
secp256k1.createPrivateKey(AUTHORIZER_PRIVATE_KEY.toUnsignedBigInteger())));

// include the tx in the next block
final String txHash =
besuNode.execute(ethTransactions.sendRawTransaction(tx.encoded().toHexString()));
testHelper.buildNewBlock();

// check that the transaction was included and has indeed reverted
Optional<TransactionReceipt> maybeTransactionReceipt =
besuNode.execute(ethTransactions.getTransactionReceipt(txHash));
assertThat(maybeTransactionReceipt).isPresent();
assertThat(maybeTransactionReceipt.get().getStatus()).isEqualTo("0x0");

// check the authorizer has the code delegation after the transaction even though it has
// reverted
final Bytes expectedCode =
Bytes.concatenate(Bytes.fromHexString("ef0100"), SEND_ALL_ETH_CONTRACT_ADDRESS);
final Bytes authorizerCode = besuNode.execute(ethTransactions.getCode(authorizer));
assertThat(authorizerCode).isEqualTo(expectedCode);
}
}
7 changes: 7 additions & 0 deletions acceptance-tests/tests/src/test/resources/dev/dev_prague.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@
"privateKey": "11f2e7b6a734ab03fa682450e0d4681d18a944f8b83c99bf7b9b4de6c0f35ea1",
"balance": "90000000000000000000000"
},
"0x0000000000000000000000000000000000000666": {
"comment": "Contract reverts immediately when called",
"balance": "0",
"code": "5F5FFD",
"codeDecompiled": "PUSH0 PUSH0 REVERT",
"storage": {}
},
"0x0000000000000000000000000000000000009999": {
"comment": "Contract sends all its Ether to the address provided as a call data.",
"balance": "0",
Expand Down

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
import org.hyperledger.besu.cli.options.TransactionPoolOptions;
import org.hyperledger.besu.cli.options.storage.DataStorageOptions;
import org.hyperledger.besu.cli.options.storage.DiffBasedSubStorageOptions;
import org.hyperledger.besu.cli.options.unstable.QBFTOptions;
import org.hyperledger.besu.cli.presynctasks.PreSynchronizationTaskRunner;
import org.hyperledger.besu.cli.presynctasks.PrivateDatabaseMigrationPreSyncTask;
import org.hyperledger.besu.cli.subcommands.PasswordSubCommand;
Expand Down Expand Up @@ -301,6 +302,7 @@ public class BesuCommand implements DefaultCommandValues, Runnable {
private final EvmOptions unstableEvmOptions = EvmOptions.create();
private final IpcOptions unstableIpcOptions = IpcOptions.create();
private final ChainPruningOptions unstableChainPruningOptions = ChainPruningOptions.create();
private final QBFTOptions unstableQbftOptions = QBFTOptions.create();

// stable CLI options
final DataStorageOptions dataStorageOptions = DataStorageOptions.create();
Expand Down Expand Up @@ -1162,6 +1164,7 @@ private void handleUnstableOptions() {
.put("EVM Options", unstableEvmOptions)
.put("IPC Options", unstableIpcOptions)
.put("Chain Data Pruning Options", unstableChainPruningOptions)
.put("QBFT Options", unstableQbftOptions)
.build();

UnstableOptionsSubCommand.createUnstableOptions(commandLine, unstableOptions);
Expand Down Expand Up @@ -1794,6 +1797,7 @@ public BesuControllerBuilder setupControllerBuilder() {
.clock(Clock.systemUTC())
.isRevertReasonEnabled(isRevertReasonEnabled)
.storageProvider(storageProvider)
.isEarlyRoundChangeEnabled(unstableQbftOptions.isEarlyRoundChangeEnabled())
.gasLimitCalculator(
miningParametersSupplier.get().getTargetGasLimit().isPresent()
? new FrontierTargetingGasLimitCalculator()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright contributors to 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.cli.options.unstable;

import picocli.CommandLine;

/** Handles configuration options for QBFT consensus */
public class QBFTOptions {

/** Default constructor */
private QBFTOptions() {}

/**
* Create a new instance of QBFTOptions
*
* @return a new instance of QBFTOptions
*/
public static QBFTOptions create() {
return new QBFTOptions();
}

@CommandLine.Option(
names = {"--Xqbft-enable-early-round-change"},
description =
"Enable early round change upon receiving f+1 valid future Round Change messages from different validators (experimental)",
hidden = true)
private boolean enableEarlyRoundChange = false;

/**
* Is early round change enabled boolean.
*
* @return true if early round change is enabled
*/
public boolean isEarlyRoundChangeEnabled() {
return enableEarlyRoundChange;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration;
import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration.MutableInitValues;
import org.hyperledger.besu.ethereum.core.MiningConfiguration;
import org.hyperledger.besu.evm.precompile.KZGPointEvalPrecompiledContract;
import org.hyperledger.besu.metrics.MetricsService;
import org.hyperledger.besu.metrics.prometheus.MetricsConfiguration;

Expand Down Expand Up @@ -206,6 +207,7 @@ public void run() {
}
LOG.info("Import {} block data from {} files", format, blockImportFiles.size());
final Optional<MetricsService> metricsService = initMetrics(parentCommand);
KZGPointEvalPrecompiledContract.init();

try (final BesuController controller = createController()) {
for (final Path path : blockImportFiles) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,9 @@ public abstract class BesuControllerBuilder implements MiningParameterOverrides
/** The transaction simulator */
protected TransactionSimulator transactionSimulator;

/** When enabled, round changes on f+1 RC messages from higher rounds */
protected boolean isEarlyRoundChangeEnabled = false;

/** Instantiates a new Besu controller builder. */
protected BesuControllerBuilder() {}

Expand Down Expand Up @@ -553,6 +556,17 @@ public BesuControllerBuilder isParallelTxProcessingEnabled(
return this;
}

/**
* check if early round change is enabled when f+1 RC messages from higher rounds are received
*
* @param isEarlyRoundChangeEnabled whether to enable early round change
* @return the besu controller
*/
public BesuControllerBuilder isEarlyRoundChangeEnabled(final boolean isEarlyRoundChangeEnabled) {
this.isEarlyRoundChangeEnabled = isEarlyRoundChangeEnabled;
return this;
}

/**
* Build besu controller.
*
Expand Down
Loading

0 comments on commit 1d875cf

Please sign in to comment.