From 18975c73a086da884c2b80d50ba100121b24d5fa Mon Sep 17 00:00:00 2001 From: Sally MacFarlane Date: Thu, 17 Aug 2023 10:00:27 +1000 Subject: [PATCH 1/3] fix: Move maintainers to emeritus (#5743) * moved to emeritus Signed-off-by: Sally MacFarlane --------- Signed-off-by: Sally MacFarlane --- MAINTAINERS.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MAINTAINERS.md b/MAINTAINERS.md index 94f3ff3da0d..e5bd1814983 100644 --- a/MAINTAINERS.md +++ b/MAINTAINERS.md @@ -24,14 +24,12 @@ | Joshua Fernandes | joshuafernandes | joshuafernandes | | Lucas Saldanha | lucassaldanha | lucassaldanha | | Sally MacFarlane | macfarla | macfarla | -| Mark Terry | mark-terry | m.terry | | Karim Taam | matkt | matkt | | Meredith Baxter | mbaxter | mbaxter | | Stefan Pingel | pinges | pinges | | Danno Ferrin | shemnon | shemnon | | Simon Dudley | siladu | siladu | | Usman Saleem | usmansaleem | usmansaleem | -| Zhenyang Shi | wcgcyx | wcgcyx | ## Emeritus Maintainers @@ -47,6 +45,7 @@ | Frank Li | frankisawesome | frankliawesome | | Ivaylo Kirilov | iikirilov | iikirilov | | Madeline Murray | MadelineMurray | madelinemurray | +| Mark Terry | mark-terry | m.terry | | Nicolas Massart | NicolasMassart | NicolasMassart | | Trent Mohay | rain-on | trent.mohay | | Rai Sur | RatanRSur | ratanraisur | @@ -55,6 +54,7 @@ | Taccat Isid | taccatisid | taccatisid | | Tim Beiko | timbeiko | timbeiko | | Vijay Michalik | vmichalik | VijayMichalik | +| Zhenyang Shi | wcgcyx | wcgcyx | ## Becoming a Maintainer From 5a766b4696abca108b357621acc08dfeb340d7c8 Mon Sep 17 00:00:00 2001 From: Danno Ferrin Date: Wed, 16 Aug 2023 22:21:01 -0500 Subject: [PATCH 2/3] EvmTool fixes (#5763) * EvmTool fixes A mixed collection of EVMTool fixes * Ensure ECDSA algo is pre-configured * used clamped math in an old gas calculator * use correct gas calculator in fluent APIs Signed-off-by: Danno Ferrin * spotless Signed-off-by: Danno Ferrin --------- Signed-off-by: Danno Ferrin --- .../besu/evmtool/B11rSubCommand.java | 7 +++++-- .../besu/evmtool/MainnetGenesisFileModule.java | 17 +++++++++++++++++ .../besu/evmtool/StateTestSubCommand.java | 3 +++ .../besu/evmtool/T8nServerSubCommand.java | 3 +++ .../hyperledger/besu/evmtool/T8nSubCommand.java | 5 ++++- .../org/hyperledger/besu/evm/MainnetEVMs.java | 3 ++- ...odularExponentiationPrecompiledContract.java | 5 +++-- 7 files changed, 37 insertions(+), 6 deletions(-) diff --git a/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/B11rSubCommand.java b/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/B11rSubCommand.java index edd274088b7..6c65fc2804e 100644 --- a/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/B11rSubCommand.java +++ b/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/B11rSubCommand.java @@ -19,6 +19,7 @@ import static org.hyperledger.besu.evmtool.B11rSubCommand.COMMAND_ALIAS; import static org.hyperledger.besu.evmtool.B11rSubCommand.COMMAND_NAME; +import org.hyperledger.besu.crypto.SignatureAlgorithmFactory; import org.hyperledger.besu.ethereum.core.BlockHeaderBuilder; import org.hyperledger.besu.ethereum.mainnet.MainnetBlockHeaderFunctions; import org.hyperledger.besu.ethereum.referencetests.BlockchainReferenceTestCaseSpec.ReferenceTestBlockHeader; @@ -154,6 +155,8 @@ public B11rSubCommand(final EvmToolCommand parentCommand) { @Override public void run() { LogConfigurator.setLevel("", "OFF"); + // presume ethereum mainnet for reference and state tests + SignatureAlgorithmFactory.setDefaultInstance(); ObjectMapper objectMapper = JsonUtils.createObjectMapper(); final ObjectReader b11rReader = objectMapper.reader(); @@ -212,7 +215,7 @@ public void run() { if (config.has("txs")) { String txsString = config.get("txs").textValue(); - if (txsString.length() > 0) { + if (!txsString.isEmpty()) { txsBytes = Bytes.fromHexString(txsString); } } @@ -224,7 +227,7 @@ public void run() { BytesValueRLPOutput rlpOut = new BytesValueRLPOutput(); rlpOut.startList(); newHeader.writeTo(rlpOut); - if (txsBytes != null && txsBytes.size() > 0) { + if (txsBytes != null && !txsBytes.isEmpty()) { rlpOut.writeRaw(txsBytes); } else { rlpOut.startList(); diff --git a/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/MainnetGenesisFileModule.java b/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/MainnetGenesisFileModule.java index 89c361b7d42..5445fe2b43d 100644 --- a/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/MainnetGenesisFileModule.java +++ b/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/MainnetGenesisFileModule.java @@ -17,6 +17,8 @@ import org.hyperledger.besu.config.GenesisConfigOptions; import org.hyperledger.besu.config.StubGenesisConfigOptions; +import org.hyperledger.besu.crypto.SignatureAlgorithmFactory; +import org.hyperledger.besu.crypto.SignatureAlgorithmType; import org.hyperledger.besu.ethereum.core.BlockHeaderFunctions; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.mainnet.MainnetBlockHeaderFunctions; @@ -33,6 +35,8 @@ import java.util.function.Supplier; import javax.inject.Named; +import picocli.CommandLine; + class MainnetGenesisFileModule extends GenesisFileModule { MainnetGenesisFileModule(final String genesisConfig) { @@ -49,6 +53,19 @@ ProtocolSchedule provideProtocolSchedule( final GenesisConfigOptions configOptions, @Named("Fork") final Optional fork, @Named("RevertReasonEnabled") final boolean revertReasonEnabled) { + + final Optional ecCurve = configOptions.getEcCurve(); + if (ecCurve.isEmpty()) { + SignatureAlgorithmFactory.setDefaultInstance(); + } else { + try { + SignatureAlgorithmFactory.setInstance(SignatureAlgorithmType.create(ecCurve.get())); + } catch (final IllegalArgumentException e) { + throw new CommandLine.InitializationException( + "Invalid genesis file configuration for ecCurve. " + e.getMessage()); + } + } + if (fork.isPresent()) { var schedules = createSchedules(); var schedule = schedules.get(fork.map(String::toLowerCase).get()); diff --git a/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/StateTestSubCommand.java b/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/StateTestSubCommand.java index 33aad83a22d..f31afc52053 100644 --- a/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/StateTestSubCommand.java +++ b/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/StateTestSubCommand.java @@ -20,6 +20,7 @@ import static org.hyperledger.besu.ethereum.referencetests.ReferenceTestProtocolSchedules.shouldClearEmptyAccounts; import static org.hyperledger.besu.evmtool.StateTestSubCommand.COMMAND_NAME; +import org.hyperledger.besu.crypto.SignatureAlgorithmFactory; import org.hyperledger.besu.datatypes.DataGas; import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.datatypes.Wei; @@ -115,6 +116,8 @@ public StateTestSubCommand() { @Override public void run() { LogConfigurator.setLevel("", "OFF"); + // presume ethereum mainnet for reference and state tests + SignatureAlgorithmFactory.setDefaultInstance(); final ObjectMapper stateTestMapper = JsonUtils.createObjectMapper(); final JavaType javaType = diff --git a/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/T8nServerSubCommand.java b/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/T8nServerSubCommand.java index 73e20be247e..eec78ee50d1 100644 --- a/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/T8nServerSubCommand.java +++ b/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/T8nServerSubCommand.java @@ -17,6 +17,7 @@ import static org.hyperledger.besu.evmtool.T8nExecutor.extractTransactions; +import org.hyperledger.besu.crypto.SignatureAlgorithmFactory; import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.referencetests.ReferenceTestEnv; @@ -65,6 +66,8 @@ public class T8nServerSubCommand implements Runnable { @Override public void run() { LogConfigurator.setLevel("", "OFF"); + // presume ethereum mainnet for reference and state tests + SignatureAlgorithmFactory.setDefaultInstance(); Vertx.vertx() .createHttpServer( new HttpServerOptions() diff --git a/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/T8nSubCommand.java b/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/T8nSubCommand.java index efcb3b71043..1571dc3551e 100644 --- a/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/T8nSubCommand.java +++ b/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/T8nSubCommand.java @@ -19,6 +19,7 @@ import static org.hyperledger.besu.evmtool.T8nSubCommand.COMMAND_ALIAS; import static org.hyperledger.besu.evmtool.T8nSubCommand.COMMAND_NAME; +import org.hyperledger.besu.crypto.SignatureAlgorithmFactory; import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.ethereum.core.MutableWorldState; import org.hyperledger.besu.ethereum.core.Transaction; @@ -169,6 +170,8 @@ public T8nSubCommand(final EvmToolCommand parentCommand) { @Override public void run() { LogConfigurator.setLevel("", "OFF"); + // presume ethereum mainnet for reference and state tests + SignatureAlgorithmFactory.setDefaultInstance(); final ObjectMapper objectMapper = JsonUtils.createObjectMapper(); final ObjectReader t8nReader = objectMapper.reader(); @@ -321,7 +324,7 @@ public void disposeTracer(final OperationTracer tracer) { } } - if (outputObject.size() > 0) { + if (!outputObject.isEmpty()) { parentCommand.out.println(writer.writeValueAsString(outputObject)); } } catch (IOException ioe) { diff --git a/evm/src/main/java/org/hyperledger/besu/evm/MainnetEVMs.java b/evm/src/main/java/org/hyperledger/besu/evm/MainnetEVMs.java index 6398f23a507..3aad40735d8 100644 --- a/evm/src/main/java/org/hyperledger/besu/evm/MainnetEVMs.java +++ b/evm/src/main/java/org/hyperledger/besu/evm/MainnetEVMs.java @@ -14,6 +14,7 @@ */ package org.hyperledger.besu.evm; +import org.hyperledger.besu.evm.gascalculator.BerlinGasCalculator; import org.hyperledger.besu.evm.gascalculator.ByzantiumGasCalculator; import org.hyperledger.besu.evm.gascalculator.CancunGasCalculator; import org.hyperledger.besu.evm.gascalculator.ConstantinopleGasCalculator; @@ -546,7 +547,7 @@ public static EVM berlin(final EvmConfiguration evmConfiguration) { * @return the evm */ public static EVM berlin(final BigInteger chainId, final EvmConfiguration evmConfiguration) { - return berlin(new IstanbulGasCalculator(), chainId, evmConfiguration); + return berlin(new BerlinGasCalculator(), chainId, evmConfiguration); } /** diff --git a/evm/src/main/java/org/hyperledger/besu/evm/precompile/BigIntegerModularExponentiationPrecompiledContract.java b/evm/src/main/java/org/hyperledger/besu/evm/precompile/BigIntegerModularExponentiationPrecompiledContract.java index 712b0fcc69d..669edc78103 100644 --- a/evm/src/main/java/org/hyperledger/besu/evm/precompile/BigIntegerModularExponentiationPrecompiledContract.java +++ b/evm/src/main/java/org/hyperledger/besu/evm/precompile/BigIntegerModularExponentiationPrecompiledContract.java @@ -14,6 +14,7 @@ */ package org.hyperledger.besu.evm.precompile; +import static org.hyperledger.besu.evm.internal.Words.clampedAdd; import static org.hyperledger.besu.evm.internal.Words.clampedMultiply; import static org.hyperledger.besu.evm.internal.Words.clampedToInt; import static org.hyperledger.besu.evm.internal.Words.clampedToLong; @@ -154,9 +155,9 @@ public static long multiplicationComplexity(final long x) { if (x <= 64) { return square(x); } else if (x <= 1024) { - return (square(x) / 4) + (x * 96) - 3072; + return clampedAdd((square(x) / 4), clampedMultiply(x, 96)) - 3072; } else { - return (square(x) / 16) + (480 * x) - 199680; + return clampedAdd((square(x) / 16), clampedMultiply(480, x)) - 199680; } } From 210927ed082d338692501f029814e1840109ebe6 Mon Sep 17 00:00:00 2001 From: Sally MacFarlane Date: Fri, 18 Aug 2023 00:18:30 +1000 Subject: [PATCH 3/3] fix: prioritize fork error over missing payload fields (#5765) additional rpc error code for unsupported fork fixes #5738 Signed-off-by: Sally MacFarlane --- .../engine/AbstractEngineNewPayload.java | 18 ++++++++++-------- .../methods/engine/EngineNewPayloadV3.java | 4 ++-- .../internal/response/RpcErrorType.java | 1 + .../methods/engine/EngineNewPayloadV3Test.java | 5 +++++ 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineNewPayload.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineNewPayload.java index 59fd54f7d99..3f574a47b82 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineNewPayload.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineNewPayload.java @@ -105,11 +105,18 @@ public JsonRpcResponse syncResponse(final JsonRpcRequestContext requestContext) final EnginePayloadParameter blockParam = requestContext.getRequiredParameter(0, EnginePayloadParameter.class); - Optional> maybeVersionedHashParam = + final Optional> maybeVersionedHashParam = requestContext.getOptionalList(1, String.class); - Object reqId = requestContext.getRequest().getId(); - Optional> maybeVersionedHashes; + final Object reqId = requestContext.getRequest().getId(); + + final ValidationResult forkValidationResult = + validateForkSupported(reqId, blockParam); + if (!forkValidationResult.isValid()) { + return new JsonRpcErrorResponse(reqId, forkValidationResult); + } + + final Optional> maybeVersionedHashes; try { maybeVersionedHashes = extractVersionedHashes(maybeVersionedHashParam); } catch (RuntimeException ex) { @@ -124,11 +131,6 @@ public JsonRpcResponse syncResponse(final JsonRpcRequestContext requestContext) .addArgument(() -> Json.encodePrettily(blockParam)) .log(); - ValidationResult forkValidationResult = validateForkSupported(reqId, blockParam); - if (!forkValidationResult.isValid()) { - return new JsonRpcErrorResponse(reqId, forkValidationResult); - } - final Optional> maybeWithdrawals = Optional.ofNullable(blockParam.getWithdrawals()) .map(ws -> ws.stream().map(WithdrawalParameter::toWithdrawal).collect(toList())); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadV3.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadV3.java index 6454c22fdb6..1bbf81a86be 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadV3.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadV3.java @@ -54,12 +54,12 @@ protected ValidationResult validateForkSupported( if (cancun.isPresent() && payloadParameter.getTimestamp() >= cancun.get().milestone()) { if (payloadParameter.getDataGasUsed() == null || payloadParameter.getExcessDataGas() == null) { - return ValidationResult.invalid(RpcErrorType.INVALID_PARAMS, "Missing data gas fields"); + return ValidationResult.invalid(RpcErrorType.INVALID_PARAMS, "Missing blob gas fields"); } else { return ValidationResult.valid(); } } else { - return ValidationResult.invalid(RpcErrorType.INVALID_PARAMS, "Fork not supported"); + return ValidationResult.invalid(RpcErrorType.UNSUPPORTED_FORK, "Fork not supported"); } } } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/response/RpcErrorType.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/response/RpcErrorType.java index 78017deca09..2b7096ceb42 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/response/RpcErrorType.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/response/RpcErrorType.java @@ -81,6 +81,7 @@ public enum RpcErrorType { INVALID_FORKCHOICE_STATE(-38002, "Invalid forkchoice state"), INVALID_PAYLOAD_ATTRIBUTES(-38003, "Invalid payload attributes"), INVALID_RANGE_REQUEST_TOO_LARGE(-38004, "Too large request"), + UNSUPPORTED_FORK(-38005, "Unsupported fork"), // Miner failures COINBASE_NOT_SET(-32010, "Coinbase not set. Unable to start mining without a coinbase"), NO_HASHES_PER_SECOND(-32011, "No hashes being generated by the current node"), diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadV3Test.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadV3Test.java index e98be62b2c2..c4abbfee9d6 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadV3Test.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadV3Test.java @@ -73,7 +73,12 @@ public void before() { @Test public void shouldInvalidPayloadOnShortVersionedHash() { Bytes shortHash = Bytes.fromHexString("0x" + "69".repeat(31)); + EnginePayloadParameter payload = mock(EnginePayloadParameter.class); + when(payload.getTimestamp()).thenReturn(30l); + when(payload.getExcessDataGas()).thenReturn("99"); + when(payload.getDataGasUsed()).thenReturn(9l); + JsonRpcResponse badParam = method.response( new JsonRpcRequestContext(