Skip to content

Commit

Permalink
Merge branch 'main' into fix/issue-5738/engine-api-v3-validation-orde…
Browse files Browse the repository at this point in the history
…ring
  • Loading branch information
macfarla authored Aug 17, 2023
2 parents c7d8b6a + 5a766b4 commit 01b7e7d
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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);
}
}
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -33,6 +35,8 @@
import java.util.function.Supplier;
import javax.inject.Named;

import picocli.CommandLine;

class MainnetGenesisFileModule extends GenesisFileModule {

MainnetGenesisFileModule(final String genesisConfig) {
Expand All @@ -49,6 +53,19 @@ ProtocolSchedule provideProtocolSchedule(
final GenesisConfigOptions configOptions,
@Named("Fork") final Optional<String> fork,
@Named("RevertReasonEnabled") final boolean revertReasonEnabled) {

final Optional<String> 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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion evm/src/main/java/org/hyperledger/besu/evm/MainnetEVMs.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}

Expand Down

0 comments on commit 01b7e7d

Please sign in to comment.