Upgrade to Apache Tuweni 2.0 (#2376)

* Upgrade to Apache Tuweni 2.0

Signed-off-by: Antoine Toulme <antoine@lunar-ocean.com>

* Remove intermediate repository

Signed-off-by: Antoine Toulme <antoine@lunar-ocean.com>

* Remove all occurrences of toBytes

Signed-off-by: Antoine Toulme <antoine@lunar-ocean.com>

* Migrate to tuweni-bytes

Signed-off-by: Antoine Toulme <antoine@lunar-ocean.com>

* add changelog

Signed-off-by: Antoine Toulme <antoine@lunar-ocean.com>

* correct reference tests

Signed-off-by: Antoine Toulme <antoine@lunar-ocean.com>

* Initial API changes

Signed-off-by: Antoine Toulme <antoine@lunar-ocean.com>

* more changes

Signed-off-by: Antoine Toulme <antoine@lunar-ocean.com>

* Change APIs for VM ops

Signed-off-by: Antoine Toulme <antoine@lunar-ocean.com>

* Use constant UInt256.ONE

Signed-off-by: Antoine Toulme <antoine@lunar-ocean.com>

* Optimize a bit address <> word transformation

Signed-off-by: Antoine Toulme <antoine@lunar-ocean.com>

* spotless

Signed-off-by: Antoine Toulme <antoine@lunar-ocean.com>
pull/2549/head
Antoine Toulme 3 years ago committed by GitHub
parent ff67cc6962
commit 11f5cfb022
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      CHANGELOG.md
  2. 6
      acceptance-tests/dsl/build.gradle
  3. 2
      acceptance-tests/tests/build.gradle
  4. 12
      besu/build.gradle
  5. 2
      besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java
  6. 2
      config/build.gradle
  7. 4
      consensus/clique/build.gradle
  8. 2
      consensus/common/build.gradle
  9. 4
      consensus/ibft/build.gradle
  10. 2
      consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/BftBlockHashingTest.java
  11. 4
      consensus/ibftlegacy/build.gradle
  12. 6
      consensus/qbft/build.gradle
  13. 4
      crypto/build.gradle
  14. 2
      crypto/src/main/java/org/hyperledger/besu/crypto/AbstractSECP256.java
  15. 2
      crypto/src/main/java/org/hyperledger/besu/crypto/SECPPrivateKey.java
  16. 4
      crypto/src/main/java/org/hyperledger/besu/crypto/SECPSignature.java
  17. 2
      enclave/build.gradle
  18. 2
      enclave/src/integration-test/java/org/hyperledger/besu/enclave/TlsEnabledHttpServerFactory.java
  19. 2
      enclave/src/main/java/org/hyperledger/besu/enclave/EnclaveFactory.java
  20. 8
      ethereum/api/build.gradle
  21. 2
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/graphql/internal/pojoadapter/AccountAdapter.java
  22. 4
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpService.java
  23. 3
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/StructLog.java
  24. 2
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/proof/StorageEntryProof.java
  25. 2
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/tracing/vm/VmTraceGenerator.java
  26. 4
      ethereum/blockcreation/build.gradle
  27. 10
      ethereum/core/build.gradle
  28. 2
      ethereum/core/src/integration-test/java/org/hyperledger/besu/ethereum/vm/EntriesFromIntegrationTest.java
  29. 4
      ethereum/core/src/jmh/java/org/hyperledger/besu/ethereum/vm/operations/BlockHashOperationBenchmark.java
  30. 6
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/BonsaiLayeredWorldState.java
  31. 8
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/BonsaiPersistedWorldState.java
  32. 10
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/BonsaiWorldStateUpdater.java
  33. 2
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/AccountStorageEntry.java
  34. 12
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/encoding/TransactionDecoder.java
  35. 2
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/BodyValidation.java
  36. 2
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ConstantinopleGasCalculator.java
  37. 4
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/FrontierGasCalculator.java
  38. 3
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/headervalidationrules/CalculatedDifficultyValidationRule.java
  39. 2
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/headervalidationrules/ProofOfWorkValidationRule.java
  40. 4
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/privacy/PrivateTransaction.java
  41. 2
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/proof/WorldStateProofProvider.java
  42. 8
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/storage/keyvalue/KeyValueStoragePrefixedKeyBlockchainStorage.java
  43. 2
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/storage/keyvalue/WorldStatePreimageKeyValueStorage.java
  44. 7
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/vm/AbstractCallOperation.java
  45. 2
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/vm/Memory.java
  46. 8
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/vm/MessageFrame.java
  47. 6
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/vm/OperandStack.java
  48. 10
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/vm/Words.java
  49. 13
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/vm/operations/AbstractCreateOperation.java
  50. 11
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/vm/operations/AddModOperation.java
  51. 6
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/vm/operations/AddOperation.java
  52. 6
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/vm/operations/AndOperation.java
  53. 4
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/vm/operations/BalanceOperation.java
  54. 2
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/vm/operations/BaseFeeOperation.java
  55. 9
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/vm/operations/BlockHashOperation.java
  56. 8
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/vm/operations/ByteOperation.java
  57. 8
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/vm/operations/CallCodeOperation.java
  58. 6
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/vm/operations/CallDataCopyOperation.java
  59. 6
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/vm/operations/CallDataLoadOperation.java
  60. 2
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/vm/operations/CallDataSizeOperation.java
  61. 8
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/vm/operations/CallOperation.java
  62. 2
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/vm/operations/CallValueOperation.java
  63. 5
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/vm/operations/ChainIdOperation.java
  64. 6
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/vm/operations/CodeCopyOperation.java
  65. 2
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/vm/operations/CodeSizeOperation.java
  66. 4
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/vm/operations/Create2Operation.java
  67. 8
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/vm/operations/DelegateCallOperation.java
  68. 2
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/vm/operations/DifficultyOperation.java
  69. 9
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/vm/operations/DivOperation.java
  70. 7
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/vm/operations/EqOperation.java
  71. 6
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/vm/operations/ExpOperation.java
  72. 6
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/vm/operations/ExtCodeCopyOperation.java
  73. 6
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/vm/operations/ExtCodeHashOperation.java
  74. 3
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/vm/operations/ExtCodeSizeOperation.java
  75. 3
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/vm/operations/GasLimitOperation.java
  76. 3
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/vm/operations/GasOperation.java
  77. 2
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/vm/operations/GasPriceOperation.java
  78. 8
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/vm/operations/GtOperation.java
  79. 4
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/vm/operations/IsZeroOperation.java
  80. 2
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/vm/operations/JumpOperation.java
  81. 2
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/vm/operations/JumpiOperation.java
  82. 4
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/vm/operations/LogOperation.java
  83. 8
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/vm/operations/LtOperation.java
  84. 5
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/vm/operations/MLoadOperation.java
  85. 2
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/vm/operations/MSizeOperation.java
  86. 2
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/vm/operations/MStore8Operation.java
  87. 2
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/vm/operations/MStoreOperation.java
  88. 6
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/vm/operations/ModOperation.java
  89. 11
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/vm/operations/MulModOperation.java
  90. 6
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/vm/operations/MulOperation.java
  91. 4
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/vm/operations/NotOperation.java
  92. 2
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/vm/operations/NumberOperation.java
  93. 6
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/vm/operations/OrOperation.java
  94. 2
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/vm/operations/PCOperation.java
  95. 3
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/vm/operations/PushOperation.java
  96. 6
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/vm/operations/ReturnDataCopyOperation.java
  97. 2
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/vm/operations/ReturnDataSizeOperation.java
  98. 4
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/vm/operations/ReturnOperation.java
  99. 4
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/vm/operations/RevertOperation.java
  100. 12
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/vm/operations/SDivOperation.java
  101. Some files were not shown because too many files have changed in this diff Show More

@ -2,6 +2,7 @@
## 21.7.2
### Additions and Improvements
- Migration to Apache Tuweni 2.0 [\#2376](https://github.com/hyperledger/besu/pull/2376)
### Bug Fixes

@ -33,9 +33,9 @@ dependencies {
implementation 'org.apache.logging.log4j:log4j-api'
implementation 'org.apache.logging.log4j:log4j-core'
implementation 'org.apache.logging.log4j:log4j-slf4j-impl'
implementation 'org.apache.tuweni:bytes'
implementation 'org.apache.tuweni:io'
implementation 'org.apache.tuweni:units'
implementation 'org.apache.tuweni:tuweni-bytes'
implementation 'org.apache.tuweni:tuweni-io'
implementation 'org.apache.tuweni:tuweni-units'
implementation 'org.assertj:assertj-core'
implementation 'org.awaitility:awaitility'
implementation 'org.java-websocket:Java-WebSocket'

@ -49,7 +49,7 @@ dependencies {
testImplementation 'junit:junit'
testImplementation 'net.consensys:orion'
testImplementation 'org.apache.commons:commons-compress'
testImplementation 'org.apache.tuweni:crypto'
testImplementation 'org.apache.tuweni:tuweni-crypto'
testImplementation 'org.assertj:assertj-core'
testImplementation 'org.awaitility:awaitility'
testImplementation 'org.web3j:abi'

@ -63,10 +63,10 @@ dependencies {
implementation 'io.vertx:vertx-web'
implementation 'org.apache.logging.log4j:log4j-api'
implementation 'org.apache.logging.log4j:log4j-core'
implementation 'org.apache.tuweni:bytes'
implementation 'org.apache.tuweni:config'
implementation 'org.apache.tuweni:toml'
implementation 'org.apache.tuweni:units'
implementation 'org.apache.tuweni:tuweni-bytes'
implementation 'org.apache.tuweni:tuweni-config'
implementation 'org.apache.tuweni:tuweni-toml'
implementation 'org.apache.tuweni:tuweni-units'
implementation 'org.springframework.security:spring-security-crypto'
implementation 'org.xerial.snappy:snappy-java'
implementation 'net.consensys.services:quorum-mainnet-launcher'
@ -85,8 +85,8 @@ dependencies {
testImplementation 'com.squareup.okhttp3:okhttp'
testImplementation 'junit:junit'
testImplementation 'org.apache.commons:commons-text'
testImplementation 'org.apache.tuweni:bytes'
testImplementation 'org.apache.tuweni:units'
testImplementation 'org.apache.tuweni:tuweni-bytes'
testImplementation 'org.apache.tuweni:tuweni-units'
testImplementation 'org.assertj:assertj-core'
testImplementation 'org.awaitility:awaitility'
testImplementation 'org.mockito:mockito-core'

@ -3660,7 +3660,7 @@ public class BesuCommandTest extends CommandTestAbstract {
@Test
public void transactionPoolTxFeeCap() {
final Wei txFeeCap = Wei.fromEth(2);
parseCommand("--rpc-tx-feecap", txFeeCap.toString());
parseCommand("--rpc-tx-feecap", txFeeCap.toDecimalString());
verify(mockControllerBuilder)
.transactionPoolConfiguration(transactionPoolConfigCaptor.capture());
assertThat(transactionPoolConfigCaptor.getValue().getTxFeeCap()).isEqualTo(txFeeCap);

@ -32,7 +32,7 @@ dependencies {
implementation 'com.google.guava:guava'
implementation 'org.apache.logging.log4j:log4j-api'
implementation 'info.picocli:picocli'
implementation 'org.apache.tuweni:bytes'
implementation 'org.apache.tuweni:tuweni-bytes'
runtimeOnly 'org.apache.logging.log4j:log4j-core'
testImplementation project(':testutil')

@ -44,8 +44,8 @@ dependencies {
implementation 'com.google.guava:guava'
implementation 'io.vertx:vertx-core'
implementation 'org.apache.tuweni:bytes'
implementation 'org.apache.tuweni:units'
implementation 'org.apache.tuweni:tuweni-bytes'
implementation 'org.apache.tuweni:tuweni-units'
testImplementation project(path: ':consensus:common', configuration: 'testArtifacts')
testImplementation project(path: ':crypto', configuration: 'testSupportArtifacts')

@ -42,7 +42,7 @@ dependencies {
implementation 'com.fasterxml.jackson.core:jackson-databind'
implementation 'com.google.guava:guava'
implementation 'org.apache.tuweni:bytes'
implementation 'org.apache.tuweni:tuweni-bytes'
testImplementation project(':config')
testImplementation project(':crypto')

@ -41,8 +41,8 @@ dependencies {
implementation 'com.google.guava:guava'
implementation 'io.vertx:vertx-core'
implementation 'org.apache.tuweni:bytes'
implementation 'org.apache.tuweni:units'
implementation 'org.apache.tuweni:tuweni-bytes'
implementation 'org.apache.tuweni:tuweni-units'
integrationTestImplementation project(path: ':config', configuration: 'testSupportArtifacts')
integrationTestImplementation project(path: ':ethereum:core', configuration: 'testSupportArtifacts')

@ -108,7 +108,7 @@ public class BftBlockHashingTest {
i ->
NodeKeyUtils.createFrom(
(signatureAlgorithm.createKeyPair(
signatureAlgorithm.createPrivateKey(UInt256.valueOf(i).toBytes())))))
signatureAlgorithm.createPrivateKey(UInt256.valueOf(i))))))
.collect(Collectors.toList());
}

@ -28,8 +28,8 @@ dependencies {
implementation 'com.google.guava:guava'
implementation 'io.vertx:vertx-core'
implementation 'org.apache.tuweni:bytes'
implementation 'org.apache.tuweni:units'
implementation 'org.apache.tuweni:tuweni-bytes'
implementation 'org.apache.tuweni:tuweni-units'
testImplementation project(path: ':consensus:common', configuration: 'testSupportArtifacts')
testImplementation project(path: ':consensus:ibft', configuration: 'testSupportArtifacts')

@ -69,8 +69,8 @@ dependencies {
implementation 'com.google.guava:guava'
implementation 'io.vertx:vertx-core'
implementation 'org.apache.tuweni:bytes'
implementation 'org.apache.tuweni:units'
implementation 'org.apache.tuweni:tuweni-bytes'
implementation 'org.apache.tuweni:tuweni-units'
integrationTestImplementation project(path: ':config', configuration: 'testSupportArtifacts')
integrationTestImplementation project(path: ':ethereum:core', configuration: 'testSupportArtifacts')
@ -103,7 +103,7 @@ dependencies {
referenceTestImplementation 'org.mockito:mockito-core'
referenceTestImplementation 'com.fasterxml.jackson.core:jackson-databind'
referenceTestImplementation 'com.fasterxml.jackson.datatype:jackson-datatype-jdk8'
referenceTestImplementation 'org.apache.tuweni:bytes'
referenceTestImplementation 'org.apache.tuweni:tuweni-bytes'
referenceTestImplementation project(':crypto')
referenceTestImplementation project(path: ':crypto', configuration: 'testSupportArtifacts')
referenceTestImplementation project(':consensus:common')

@ -36,8 +36,8 @@ dependencies {
implementation 'com.google.guava:guava'
implementation 'net.java.dev.jna:jna'
implementation 'org.apache.logging.log4j:log4j-api'
implementation 'org.apache.tuweni:bytes'
implementation 'org.apache.tuweni:units'
implementation 'org.apache.tuweni:tuweni-bytes'
implementation 'org.apache.tuweni:tuweni-units'
implementation 'org.hyperledger.besu:secp256k1'
runtimeOnly 'org.apache.logging.log4j:log4j-core'

@ -141,7 +141,7 @@ public abstract class AbstractSECP256 implements SignatureAlgorithm {
agreement.init(privKeyP);
final BigInteger agreed = agreement.calculateAgreement(pubKeyP);
return UInt256.valueOf(agreed).toBytes();
return UInt256.valueOf(agreed);
}
@Override

@ -35,7 +35,7 @@ public class SECPPrivateKey implements java.security.PrivateKey {
public static SECPPrivateKey create(final BigInteger key, final String algorithm) {
checkNotNull(key);
return create(UInt256.valueOf(key).toBytes(), algorithm);
return create(UInt256.valueOf(key), algorithm);
}
public static SECPPrivateKey create(final Bytes32 key, final String algorithm) {

@ -104,8 +104,8 @@ public class SECPSignature {
private Bytes _encodedBytes() {
final MutableBytes bytes = MutableBytes.create(BYTES_REQUIRED);
UInt256.valueOf(r).toBytes().copyTo(bytes, 0);
UInt256.valueOf(s).toBytes().copyTo(bytes, 32);
UInt256.valueOf(r).copyTo(bytes, 0);
UInt256.valueOf(s).copyTo(bytes, 32);
bytes.set(64, recId);
return bytes;
}

@ -5,7 +5,7 @@ dependencies {
implementation 'com.fasterxml.jackson.core:jackson-databind'
implementation 'com.google.guava:guava'
implementation 'io.vertx:vertx-core'
implementation 'org.apache.tuweni:net'
implementation 'org.apache.tuweni:tuweni-net'
implementation 'org.apache.logging.log4j:log4j-api'
runtimeOnly('org.bouncycastle:bcpkix-jdk15on')

@ -70,7 +70,7 @@ class TlsEnabledHttpServerFactory {
web3HttpServerOptions.setSsl(true);
web3HttpServerOptions.setClientAuth(ClientAuth.REQUIRED);
web3HttpServerOptions.setTrustOptions(
VertxTrustOptions.whitelistClients(serverFingerprintFile));
VertxTrustOptions.allowlistClients(serverFingerprintFile));
web3HttpServerOptions.setPfxKeyCertOptions(
new PfxOptions()
.setPath(serverCert.getPkcs12File().toString())

@ -116,7 +116,7 @@ public class EnclaveFactory {
convertFrom(privacyKeyStoreFile, privacyKeyStorePasswordFile));
}
clientOptions.setTrustOptions(
VertxTrustOptions.whitelistServers(privacyAllowlistFile, TRUST_CA));
VertxTrustOptions.allowlistServers(privacyAllowlistFile, TRUST_CA));
} catch (final NoSuchFileException e) {
throw new InvalidConfigurationException(
"Requested file " + e.getMessage() + " does not exist at specified location.");

@ -56,10 +56,10 @@ dependencies {
implementation 'io.vertx:vertx-unit'
implementation 'io.vertx:vertx-web'
implementation 'org.apache.logging.log4j:log4j-core'
implementation 'org.apache.tuweni:bytes'
implementation 'org.apache.tuweni:net'
implementation 'org.apache.tuweni:toml'
implementation 'org.apache.tuweni:units'
implementation 'org.apache.tuweni:tuweni-bytes'
implementation 'org.apache.tuweni:tuweni-net'
implementation 'org.apache.tuweni:tuweni-toml'
implementation 'org.apache.tuweni:tuweni-units'
implementation 'org.bouncycastle:bcprov-jdk15on'
implementation 'org.springframework.security:spring-security-crypto'
implementation 'org.xerial.snappy:snappy-java'

@ -51,6 +51,6 @@ public class AccountAdapter extends AdapterBase {
public Optional<Bytes32> getStorage(final DataFetchingEnvironment environment) {
final Bytes32 slot = environment.getArgument("slot");
return Optional.of(account.getStorageValue(UInt256.fromBytes(slot)).toBytes());
return Optional.of(account.getStorageValue(UInt256.fromBytes(slot)));
}
}

@ -17,7 +17,7 @@ package org.hyperledger.besu.ethereum.api.jsonrpc;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.collect.Streams.stream;
import static java.util.stream.Collectors.toList;
import static org.apache.tuweni.net.tls.VertxTrustOptions.whitelistClients;
import static org.apache.tuweni.net.tls.VertxTrustOptions.allowlistClients;
import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcError.INVALID_REQUEST;
import org.hyperledger.besu.ethereum.api.handlers.HandlerFactory;
@ -430,7 +430,7 @@ public class JsonRpcHttpService {
.ifPresent(
knownClientsFile ->
httpServerOptions.setTrustOptions(
whitelistClients(
allowlistClients(
knownClientsFile, clientAuthConfiguration.isCaClientsEnabled())));
}

@ -64,8 +64,7 @@ public class StructLog {
final Map<String, String> formattedStorage = new TreeMap<>();
storage.forEach(
(key, value) ->
formattedStorage.put(
key.toBytes().toUnprefixedHexString(), value.toBytes().toUnprefixedHexString()));
formattedStorage.put(key.toUnprefixedHexString(), value.toUnprefixedHexString()));
return formattedStorage;
}

@ -39,7 +39,7 @@ public class StorageEntryProof {
@JsonGetter(value = "key")
public String getKey() {
return key.toString();
return key.toDecimalString();
}
@JsonGetter(value = "value")

@ -264,7 +264,7 @@ public class VmTraceGenerator {
entry ->
report.setStore(
new Store(
entry.getOffset().toBytes().toQuantityHexString(),
entry.getOffset().toQuantityHexString(),
entry.getValue().toQuantityHexString())));
}

@ -22,8 +22,8 @@ dependencies {
implementation 'com.google.guava:guava'
implementation 'io.vertx:vertx-core'
implementation 'org.apache.tuweni:bytes'
implementation 'org.apache.tuweni:units'
implementation 'org.apache.tuweni:tuweni-bytes'
implementation 'org.apache.tuweni:tuweni-units'
testImplementation project(path: ':config', configuration: 'testSupportArtifacts')
testImplementation project(path: ':ethereum:core', configuration: 'testArtifacts')

@ -45,8 +45,8 @@ dependencies {
implementation 'io.vertx:vertx-core'
implementation 'net.java.dev.jna:jna'
implementation 'org.apache.logging.log4j:log4j-api'
implementation 'org.apache.tuweni:bytes'
implementation 'org.apache.tuweni:units'
implementation 'org.apache.tuweni:tuweni-bytes'
implementation 'org.apache.tuweni:tuweni-units'
implementation 'org.hyperledger.besu:bls12-381'
implementation 'org.immutables:value-annotations'
@ -63,9 +63,9 @@ dependencies {
testImplementation 'junit:junit'
testImplementation 'org.apache.logging.log4j:log4j-core'
testImplementation 'org.apache.tuweni:bytes'
testImplementation 'org.apache.tuweni:io'
testImplementation 'org.apache.tuweni:units'
testImplementation 'org.apache.tuweni:tuweni-bytes'
testImplementation 'org.apache.tuweni:tuweni-io'
testImplementation 'org.apache.tuweni:tuweni-units'
testImplementation 'org.assertj:assertj-core'
testImplementation 'org.mockito:mockito-core'

@ -75,6 +75,6 @@ public class EntriesFromIntegrationTest {
final UInt256 key,
final UInt256 value) {
account.setStorageValue(key, value);
expectedValues.put(Hash.hash(key.toBytes()), AccountStorageEntry.forKeyAndValue(key, value));
expectedValues.put(Hash.hash(key), AccountStorageEntry.forKeyAndValue(key, value));
}
}

@ -55,7 +55,7 @@ public class BlockHashOperationBenchmark {
@Benchmark
public Bytes32 executeOperation() {
frame.pushStackItem(UInt256.valueOf(blockNumber).toBytes());
frame.pushStackItem(UInt256.valueOf(blockNumber));
operation.execute(frame, null);
return frame.popStackItem();
}
@ -67,7 +67,7 @@ public class BlockHashOperationBenchmark {
.createMessageFrameBuilder()
.blockHashLookup(new BlockHashLookup(frame.getBlockHeader(), frame.getBlockchain()))
.build();
cleanFrame.pushStackItem(UInt256.valueOf(blockNumber).toBytes());
cleanFrame.pushStackItem(UInt256.valueOf(blockNumber));
operation.execute(cleanFrame, null);
return cleanFrame.popStackItem();
}

@ -127,7 +127,7 @@ public class BonsaiLayeredWorldState implements MutableWorldState, BonsaiWorldVi
@Override
public UInt256 getStorageValue(final Address address, final UInt256 key) {
return getStorageValueBySlotHash(address, Hash.hash(key.toBytes())).orElse(UInt256.ZERO);
return getStorageValueBySlotHash(address, Hash.hash(key)).orElse(UInt256.ZERO);
}
@Override
@ -180,7 +180,7 @@ public class BonsaiLayeredWorldState implements MutableWorldState, BonsaiWorldVi
if (!results.containsKey(entry.getKey())) {
final UInt256 value = entry.getValue().getUpdated();
// yes, store the nulls. If it was deleted it should stay deleted
results.put(entry.getKey(), value == null ? null : value.toBytes());
results.put(entry.getKey(), value == null ? null : value);
}
});
}
@ -196,7 +196,7 @@ public class BonsaiLayeredWorldState implements MutableWorldState, BonsaiWorldVi
.forEach(
(k, v) -> {
if (!results.containsKey(k)) {
results.put(k, v.getValue().toBytes());
results.put(k, v.getValue());
}
});
}

@ -170,10 +170,8 @@ public class BonsaiPersistedWorldState implements MutableWorldState, BonsaiWorld
stateUpdater.removeStorageValueBySlotHash(updatedAddressHash, keyHash);
storageTrie.remove(keyHash);
} else {
final Bytes32 updatedStorageBytes = updatedStorage.toBytes();
stateUpdater.putStorageValueBySlotHash(
updatedAddressHash, keyHash, updatedStorageBytes);
storageTrie.put(keyHash, BonsaiWorldView.encodeTrieValue(updatedStorageBytes));
stateUpdater.putStorageValueBySlotHash(updatedAddressHash, keyHash, updatedStorage);
storageTrie.put(keyHash, BonsaiWorldView.encodeTrieValue(updatedStorage));
}
}
@ -391,7 +389,7 @@ public class BonsaiPersistedWorldState implements MutableWorldState, BonsaiWorld
@Override
public UInt256 getStorageValue(final Address address, final UInt256 storageKey) {
return getStorageValueBySlotHash(address, Hash.hash(storageKey.toBytes())).orElse(UInt256.ZERO);
return getStorageValueBySlotHash(address, Hash.hash(storageKey)).orElse(UInt256.ZERO);
}
@Override

@ -261,7 +261,7 @@ public class BonsaiWorldStateUpdater extends AbstractWorldUpdater<BonsaiWorldVie
for (final Map.Entry<UInt256, UInt256> storageUpdate : entries) {
final UInt256 keyUInt = storageUpdate.getKey();
final Hash slotHash = Hash.hash(keyUInt.toBytes());
final Hash slotHash = Hash.hash(keyUInt);
final UInt256 value = storageUpdate.getValue();
final BonsaiValue<UInt256> pendingValue = pendingStorageUpdates.get(slotHash);
if (pendingValue == null) {
@ -304,7 +304,7 @@ public class BonsaiWorldStateUpdater extends AbstractWorldUpdater<BonsaiWorldVie
@Override
public UInt256 getStorageValue(final Address address, final UInt256 storageKey) {
// TODO maybe log the read into the trie layer?
final Hash slotHashBytes = Hash.hash(storageKey.toBytes());
final Hash slotHashBytes = Hash.hash(storageKey);
return getStorageValueBySlotHash(address, slotHashBytes).orElse(UInt256.ZERO);
}
@ -328,7 +328,7 @@ public class BonsaiWorldStateUpdater extends AbstractWorldUpdater<BonsaiWorldVie
public UInt256 getPriorStorageValue(final Address address, final UInt256 storageKey) {
// TODO maybe log the read into the trie layer?
final Map<Hash, BonsaiValue<UInt256>> localAccountStorage = storageToUpdate.get(address);
final Hash slotHash = Hash.hash(storageKey.toBytes());
final Hash slotHash = Hash.hash(storageKey);
if (localAccountStorage != null && localAccountStorage.containsKey(slotHash)) {
final BonsaiValue<UInt256> value = localAccountStorage.get(slotHash);
if (value.isCleared()) {
@ -352,9 +352,7 @@ public class BonsaiWorldStateUpdater extends AbstractWorldUpdater<BonsaiWorldVie
@Override
public Map<Bytes32, Bytes> getAllAccountStorage(final Address address, final Hash rootHash) {
final Map<Bytes32, Bytes> results = wrappedWorldView().getAllAccountStorage(address, rootHash);
storageToUpdate
.get(address)
.forEach((key, value) -> results.put(key, value.getUpdated().toBytes()));
storageToUpdate.get(address).forEach((key, value) -> results.put(key, value.getUpdated()));
return results;
}

@ -44,7 +44,7 @@ public class AccountStorageEntry {
}
public static AccountStorageEntry forKeyAndValue(final UInt256 key, final UInt256 value) {
return create(value, Hash.hash(key.toBytes()), key);
return create(value, Hash.hash(key), key);
}
/**

@ -116,8 +116,8 @@ public class TransactionDecoder {
throw new RuntimeException(
String.format("An unsupported encoded `v` value of %s was found", v));
}
final BigInteger r = input.readUInt256Scalar().toBytes().toUnsignedBigInteger();
final BigInteger s = input.readUInt256Scalar().toBytes().toUnsignedBigInteger();
final BigInteger r = input.readUInt256Scalar().toUnsignedBigInteger();
final BigInteger s = input.readUInt256Scalar().toUnsignedBigInteger();
final SECPSignature signature = SIGNATURE_ALGORITHM.get().createSignature(r, s, recId);
input.leaveList();
@ -158,8 +158,8 @@ public class TransactionDecoder {
SIGNATURE_ALGORITHM
.get()
.createSignature(
rlpInput.readUInt256Scalar().toBytes().toUnsignedBigInteger(),
rlpInput.readUInt256Scalar().toBytes().toUnsignedBigInteger(),
rlpInput.readUInt256Scalar().toUnsignedBigInteger(),
rlpInput.readUInt256Scalar().toUnsignedBigInteger(),
recId))
.build();
rlpInput.leaveList();
@ -198,8 +198,8 @@ public class TransactionDecoder {
SIGNATURE_ALGORITHM
.get()
.createSignature(
input.readUInt256Scalar().toBytes().toUnsignedBigInteger(),
input.readUInt256Scalar().toBytes().toUnsignedBigInteger(),
input.readUInt256Scalar().toUnsignedBigInteger(),
input.readUInt256Scalar().toUnsignedBigInteger(),
recId))
.build();
input.leaveList();

@ -40,7 +40,7 @@ public final class BodyValidation {
}
private static Bytes indexKey(final int i) {
return RLP.encodeOne(UInt256.valueOf(i).toBytes().trimLeadingZeros());
return RLP.encodeOne(UInt256.valueOf(i).trimLeadingZeros());
}
private static MerklePatriciaTrie<Bytes, Bytes> trie() {

@ -36,7 +36,7 @@ public class ConstantinopleGasCalculator extends ByzantiumGasCalculator {
@Override
public Gas create2OperationGasCost(final MessageFrame frame) {
final UInt256 initCodeLength = UInt256.fromBytes(frame.getStackItem(2));
final UInt256 initCodeLength = frame.getStackItem(2);
final UInt256 numWords = initCodeLength.divideCeil(Bytes32.SIZE);
final Gas initCodeHashCost = SHA3_OPERATION_WORD_GAS_COST.times(Gas.of(numWords));
return createOperationGasCost(frame).plus(initCodeHashCost);

@ -287,8 +287,8 @@ public class FrontierGasCalculator implements GasCalculator {
@Override
public Gas createOperationGasCost(final MessageFrame frame) {
final UInt256 initCodeOffset = UInt256.fromBytes(frame.getStackItem(1));
final UInt256 initCodeLength = UInt256.fromBytes(frame.getStackItem(2));
final UInt256 initCodeOffset = frame.getStackItem(1);
final UInt256 initCodeLength = frame.getStackItem(2);
final Gas memoryGasCost = memoryExpansionGasCost(frame, initCodeOffset, initCodeLength);
return CREATE_OPERATION_GAS_COST.plus(memoryGasCost);

@ -35,8 +35,7 @@ public class CalculatedDifficultyValidationRule implements AttachedBlockHeaderVa
@Override
public boolean validate(
final BlockHeader header, final BlockHeader parent, final ProtocolContext context) {
final BigInteger actualDifficulty =
new BigInteger(1, header.getDifficulty().toBytes().toArray());
final BigInteger actualDifficulty = new BigInteger(1, header.getDifficulty().toArray());
final BigInteger expectedDifficulty =
difficultyCalculator.nextDifficulty(header.getTimestamp(), parent, context);

@ -81,7 +81,7 @@ public final class ProofOfWorkValidationRule implements DetachedBlockHeaderValid
LOG.info("Invalid block header: difficulty is 0");
return false;
}
final BigInteger difficulty = header.getDifficulty().toBytes().toUnsignedBigInteger();
final BigInteger difficulty = header.getDifficulty().toUnsignedBigInteger();
final UInt256 target =
difficulty.equals(BigInteger.ONE)
? UInt256.MAX_VALUE

@ -177,8 +177,8 @@ public class PrivateTransaction implements org.hyperledger.besu.plugin.data.Priv
throw new RuntimeException(
String.format("An unsupported encoded `v` value of %s was found", v));
}
final BigInteger r = input.readUInt256Scalar().toBytes().toUnsignedBigInteger();
final BigInteger s = input.readUInt256Scalar().toBytes().toUnsignedBigInteger();
final BigInteger r = input.readUInt256Scalar().toUnsignedBigInteger();
final BigInteger s = input.readUInt256Scalar().toUnsignedBigInteger();
final SECPSignature signature = SIGNATURE_ALGORITHM.get().createSignature(r, s, recId);
final Bytes privateFrom = input.readBytes();

@ -74,7 +74,7 @@ public class WorldStateProofProvider {
newAccountStorageTrie(accountHash, account.getStorageRoot());
final NavigableMap<UInt256, Proof<Bytes>> storageProofs = new TreeMap<>();
accountStorageKeys.forEach(
key -> storageProofs.put(key, storageTrie.getValueWithProof(Hash.hash(key.toBytes()))));
key -> storageProofs.put(key, storageTrie.getValueWithProof(Hash.hash(key))));
return storageProofs;
}

@ -91,7 +91,7 @@ public class KeyValueStoragePrefixedKeyBlockchainStorage implements BlockchainSt
@Override
public Optional<Hash> getBlockHash(final long blockNumber) {
return get(BLOCK_HASH_PREFIX, UInt256.valueOf(blockNumber).toBytes()).map(this::bytesToHash);
return get(BLOCK_HASH_PREFIX, UInt256.valueOf(blockNumber)).map(this::bytesToHash);
}
@Override
@ -154,12 +154,12 @@ public class KeyValueStoragePrefixedKeyBlockchainStorage implements BlockchainSt
@Override
public void putBlockHash(final long blockNumber, final Hash blockHash) {
set(BLOCK_HASH_PREFIX, UInt256.valueOf(blockNumber).toBytes(), blockHash);
set(BLOCK_HASH_PREFIX, UInt256.valueOf(blockNumber), blockHash);
}
@Override
public void putTotalDifficulty(final Hash blockHash, final Difficulty totalDifficulty) {
set(TOTAL_DIFFICULTY_PREFIX, blockHash, totalDifficulty.toBytes());
set(TOTAL_DIFFICULTY_PREFIX, blockHash, totalDifficulty);
}
@Override
@ -176,7 +176,7 @@ public class KeyValueStoragePrefixedKeyBlockchainStorage implements BlockchainSt
@Override
public void removeBlockHash(final long blockNumber) {
remove(BLOCK_HASH_PREFIX, UInt256.valueOf(blockNumber).toBytes());
remove(BLOCK_HASH_PREFIX, UInt256.valueOf(blockNumber));
}
@Override

@ -64,7 +64,7 @@ public class WorldStatePreimageKeyValueStorage implements WorldStatePreimageStor
@Override
public WorldStatePreimageStorage.Updater putStorageTrieKeyPreimage(
final Bytes32 trieKey, final UInt256 preimage) {
transaction.put(trieKey.toArrayUnsafe(), preimage.toBytes().toArrayUnsafe());
transaction.put(trieKey.toArrayUnsafe(), preimage.toArrayUnsafe());
return this;
}

@ -22,7 +22,6 @@ import org.hyperledger.besu.ethereum.core.Wei;
import java.util.Optional;
import org.apache.tuweni.bytes.Bytes;
import org.apache.tuweni.bytes.Bytes32;
import org.apache.tuweni.units.bigints.UInt256;
/**
@ -179,7 +178,7 @@ public abstract class AbstractCallOperation extends AbstractOperation {
frame.expandMemory(outputDataOffset(frame), outputDataLength(frame));
frame.incrementRemainingGas(gasAvailableForChildCall(frame).plus(cost));
frame.popStackItems(getStackItemsConsumed());
frame.pushStackItem(Bytes32.ZERO);
frame.pushStackItem(UInt256.ZERO);
return new OperationResult(optionalCost, Optional.empty());
}
@ -248,9 +247,9 @@ public abstract class AbstractCallOperation extends AbstractOperation {
frame.popStackItems(getStackItemsConsumed());
if (childFrame.getState() == MessageFrame.State.COMPLETED_SUCCESS) {
frame.mergeWarmedUpFields(childFrame);
frame.pushStackItem(UInt256.ONE.toBytes());
frame.pushStackItem(UInt256.ONE);
} else {
frame.pushStackItem(Bytes32.ZERO);
frame.pushStackItem(UInt256.ZERO);
}
final int currentPC = frame.getPC();

@ -122,7 +122,7 @@ public class Memory {
// Note that this is one place where, while the result will fit UInt256, we should compute
// without modulo for extreme cases.
final BigInteger byteSize =
location.toBytes().toUnsignedBigInteger().add(numBytes.toBytes().toUnsignedBigInteger());
location.toUnsignedBigInteger().add(numBytes.toUnsignedBigInteger());
final BigInteger[] result = byteSize.divideAndRemainder(BigInteger.valueOf(Bytes32.SIZE));
BigInteger wordSize = result[0];
if (!result[1].equals(BigInteger.ZERO)) {

@ -456,7 +456,7 @@ public class MessageFrame {
* @return The item at the specified offset in the stack
* @throws UnderflowException if the offset is out of range
*/
public Bytes32 getStackItem(final int offset) {
public UInt256 getStackItem(final int offset) {
return stack.get(offset);
}
@ -466,7 +466,7 @@ public class MessageFrame {
* @return the item at the top of the stack
* @throws UnderflowException if the stack is empty
*/
public Bytes32 popStackItem() {
public UInt256 popStackItem() {
return stack.pop();
}
@ -484,7 +484,7 @@ public class MessageFrame {
*
* @param value The value to push onto the stack.
*/
public void pushStackItem(final Bytes32 value) {
public void pushStackItem(final UInt256 value) {
stack.push(value);
}
@ -495,7 +495,7 @@ public class MessageFrame {
* @param value The value to set the stack item to
* @throws IllegalStateException if the stack is too small
*/
public void setStackItem(final int offset, final Bytes32 value) {
public void setStackItem(final int offset, final UInt256 value) {
stack.set(offset, value);
}

@ -16,11 +16,11 @@
package org.hyperledger.besu.ethereum.vm;
import org.apache.tuweni.bytes.Bytes32;
import org.apache.tuweni.units.bigints.UInt256;
public class OperandStack extends FixedStack<Bytes32> {
public class OperandStack extends FixedStack<UInt256> {
public OperandStack(final int maxSize) {
super(maxSize, Bytes32.class);
super(maxSize, UInt256.class);
}
}

@ -18,7 +18,7 @@ import org.hyperledger.besu.ethereum.core.Address;
import org.apache.tuweni.bytes.Bytes;
import org.apache.tuweni.bytes.Bytes32;
import org.apache.tuweni.bytes.MutableBytes32;
import org.apache.tuweni.units.bigints.UInt256;
/** Static utility methods to work with VM words (that is, {@link Bytes32} values). */
public abstract class Words {
@ -31,10 +31,8 @@ public abstract class Words {
* @return A VM word containing {@code address} (left-padded as according to the VM specification
* (Appendix H. of the Yellow paper)).
*/
public static Bytes32 fromAddress(final Address address) {
final MutableBytes32 bytes = MutableBytes32.create();
address.copyTo(bytes, Bytes32.SIZE - Address.SIZE);
return bytes;
public static UInt256 fromAddress(final Address address) {
return UInt256.fromBytes(Bytes32.leftPad(address));
}
/**
@ -45,7 +43,7 @@ public abstract class Words {
* VM specification (Appendix H. of the Yellow paper)).
*/
public static Address toAddress(final Bytes32 bytes) {
return Address.wrap(bytes.slice(bytes.size() - Address.SIZE, Address.SIZE).copy());
return Address.wrap(bytes.slice(bytes.size() - Address.SIZE, Address.SIZE));
}
/**

@ -29,7 +29,6 @@ import org.hyperledger.besu.ethereum.vm.Words;
import java.util.Optional;
import org.apache.tuweni.bytes.Bytes;
import org.apache.tuweni.bytes.Bytes32;
import org.apache.tuweni.units.bigints.UInt256;
public abstract class AbstractCreateOperation extends AbstractOperation {
@ -95,11 +94,11 @@ public abstract class AbstractCreateOperation extends AbstractOperation {
protected abstract Address targetContractAddress(MessageFrame frame);
private void fail(final MessageFrame frame) {
final UInt256 inputOffset = UInt256.fromBytes(frame.getStackItem(1));
final UInt256 inputSize = UInt256.fromBytes(frame.getStackItem(2));
final UInt256 inputOffset = frame.getStackItem(1);
final UInt256 inputSize = frame.getStackItem(2);
frame.readMemory(inputOffset, inputSize);
frame.popStackItems(getStackItemsConsumed());
frame.pushStackItem(Bytes32.ZERO);
frame.pushStackItem(UInt256.ZERO);
}
private void spawnChildMessage(final MessageFrame frame) {
@ -113,8 +112,8 @@ public abstract class AbstractCreateOperation extends AbstractOperation {
account.incrementNonce();
final Wei value = Wei.wrap(frame.getStackItem(0));
final UInt256 inputOffset = UInt256.fromBytes(frame.getStackItem(1));
final UInt256 inputSize = UInt256.fromBytes(frame.getStackItem(2));
final UInt256 inputOffset = frame.getStackItem(1);
final UInt256 inputSize = frame.getStackItem(2);
final Bytes inputData = frame.readMemory(inputOffset, inputSize);
final Address contractAddress = targetContractAddress(frame);
@ -168,7 +167,7 @@ public abstract class AbstractCreateOperation extends AbstractOperation {
frame.pushStackItem(Words.fromAddress(childFrame.getContractAddress()));
} else {
frame.setReturnData(childFrame.getOutputData());
frame.pushStackItem(Bytes32.ZERO);
frame.pushStackItem(UInt256.ZERO);
}
final int currentPC = frame.getPC();

@ -18,7 +18,6 @@ import org.hyperledger.besu.ethereum.vm.EVM;
import org.hyperledger.besu.ethereum.vm.GasCalculator;
import org.hyperledger.besu.ethereum.vm.MessageFrame;
import org.apache.tuweni.bytes.Bytes32;
import org.apache.tuweni.units.bigints.UInt256;
public class AddModOperation extends AbstractFixedCostOperation {
@ -29,15 +28,15 @@ public class AddModOperation extends AbstractFixedCostOperation {
@Override
public OperationResult executeFixedCostOperation(final MessageFrame frame, final EVM evm) {
final UInt256 value0 = UInt256.fromBytes(frame.popStackItem());
final UInt256 value1 = UInt256.fromBytes(frame.popStackItem());
final UInt256 value2 = UInt256.fromBytes(frame.popStackItem());
final UInt256 value0 = frame.popStackItem();
final UInt256 value1 = frame.popStackItem();
final UInt256 value2 = frame.popStackItem();
if (value2.isZero()) {
frame.pushStackItem(Bytes32.ZERO);
frame.pushStackItem(UInt256.ZERO);
} else {
final UInt256 result = value0.addMod(value1, value2);
frame.pushStackItem(result.toBytes());
frame.pushStackItem(result);
}
return successResponse;
}

@ -28,12 +28,12 @@ public class AddOperation extends AbstractFixedCostOperation {
@Override
public OperationResult executeFixedCostOperation(final MessageFrame frame, final EVM evm) {
final UInt256 value0 = UInt256.fromBytes(frame.popStackItem());
final UInt256 value1 = UInt256.fromBytes(frame.popStackItem());
final UInt256 value0 = frame.popStackItem();
final UInt256 value1 = frame.popStackItem();
final UInt256 result = value0.add(value1);
frame.pushStackItem(result.toBytes());
frame.pushStackItem(result);
return successResponse;
}
}

@ -28,11 +28,11 @@ public class AndOperation extends AbstractFixedCostOperation {
@Override
public OperationResult executeFixedCostOperation(final MessageFrame frame, final EVM evm) {
final UInt256 value0 = UInt256.fromBytes(frame.popStackItem());
final UInt256 value1 = UInt256.fromBytes(frame.popStackItem());
final UInt256 value0 = frame.popStackItem();
final UInt256 value1 = frame.popStackItem();
final UInt256 result = value0.and(value1);
frame.pushStackItem(result.toBytes());
frame.pushStackItem(result);
return successResponse;
}

@ -28,7 +28,7 @@ import org.hyperledger.besu.ethereum.vm.Words;
import java.util.Optional;
import org.apache.tuweni.bytes.Bytes32;
import org.apache.tuweni.units.bigints.UInt256;
public class BalanceOperation extends AbstractOperation {
@ -54,7 +54,7 @@ public class BalanceOperation extends AbstractOperation {
optionalCost, Optional.of(ExceptionalHaltReason.INSUFFICIENT_GAS));
} else {
final Account account = frame.getWorldState().get(address);
frame.pushStackItem(account == null ? Bytes32.ZERO : account.getBalance().toBytes());
frame.pushStackItem(account == null ? UInt256.ZERO : account.getBalance().toUInt256());
return new OperationResult(optionalCost, Optional.empty());
}
} catch (final UnderflowException ufe) {

@ -23,6 +23,7 @@ import java.util.Optional;
import org.apache.tuweni.bytes.Bytes;
import org.apache.tuweni.bytes.Bytes32;
import org.apache.tuweni.units.bigints.UInt256;
public class BaseFeeOperation extends AbstractFixedCostOperation {
@ -42,6 +43,7 @@ public class BaseFeeOperation extends AbstractFixedCostOperation {
.getBaseFee()
.map(Bytes::ofUnsignedLong)
.map(Bytes32::leftPad)
.map(UInt256::fromBytes)
.orElseThrow());
return successResponse;
}

@ -22,7 +22,6 @@ import org.hyperledger.besu.ethereum.vm.EVM;
import org.hyperledger.besu.ethereum.vm.GasCalculator;
import org.hyperledger.besu.ethereum.vm.MessageFrame;
import org.apache.tuweni.bytes.Bytes32;
import org.apache.tuweni.units.bigints.UInt256;
public class BlockHashOperation extends AbstractFixedCostOperation {
@ -43,11 +42,11 @@ public class BlockHashOperation extends AbstractFixedCostOperation {
@Override
public OperationResult executeFixedCostOperation(final MessageFrame frame, final EVM evm) {
final UInt256 blockArg = UInt256.fromBytes(frame.popStackItem());
final UInt256 blockArg = frame.popStackItem();
// Short-circuit if value is unreasonably large
if (!blockArg.fitsLong()) {
frame.pushStackItem(Bytes32.ZERO);
frame.pushStackItem(UInt256.ZERO);
return successResponse;
}
@ -61,11 +60,11 @@ public class BlockHashOperation extends AbstractFixedCostOperation {
if (currentBlockNumber == BlockHeader.GENESIS_BLOCK_NUMBER
|| soughtBlock < (mostRecentBlockNumber - MAX_RELATIVE_BLOCK)
|| soughtBlock > mostRecentBlockNumber) {
frame.pushStackItem(Bytes32.ZERO);
frame.pushStackItem(UInt256.ZERO);
} else {
final BlockHashLookup blockHashLookup = frame.getBlockHashLookup();
final Hash blockHash = blockHashLookup.getBlockHash(soughtBlock);
frame.pushStackItem(blockHash);
frame.pushStackItem(UInt256.fromBytes(blockHash));
}
return successResponse;

@ -37,7 +37,7 @@ public class ByteOperation extends AbstractFixedCostOperation {
return UInt256.ZERO;
}
final byte b = seq.toBytes().get(index);
final byte b = seq.get(index);
final MutableBytes32 res = MutableBytes32.create();
res.set(31, b);
return UInt256.fromBytes(res);
@ -45,13 +45,13 @@ public class ByteOperation extends AbstractFixedCostOperation {
@Override
public OperationResult executeFixedCostOperation(final MessageFrame frame, final EVM evm) {
final UInt256 value0 = UInt256.fromBytes(frame.popStackItem());
final UInt256 value1 = UInt256.fromBytes(frame.popStackItem());
final UInt256 value0 = frame.popStackItem();
final UInt256 value1 = frame.popStackItem();
// Stack items are reversed for the BYTE operation.
final UInt256 result = getByte(value1, value0);
frame.pushStackItem(result.toBytes());
frame.pushStackItem(result);
return successResponse;
}

@ -53,22 +53,22 @@ public class CallCodeOperation extends AbstractCallOperation {
@Override
protected UInt256 inputDataOffset(final MessageFrame frame) {
return UInt256.fromBytes(frame.getStackItem(3));
return frame.getStackItem(3);
}
@Override
protected UInt256 inputDataLength(final MessageFrame frame) {
return UInt256.fromBytes(frame.getStackItem(4));
return frame.getStackItem(4);
}
@Override
protected UInt256 outputDataOffset(final MessageFrame frame) {
return UInt256.fromBytes(frame.getStackItem(5));
return frame.getStackItem(5);
}
@Override
protected UInt256 outputDataLength(final MessageFrame frame) {
return UInt256.fromBytes(frame.getStackItem(6));
return frame.getStackItem(6);
}
@Override

@ -34,9 +34,9 @@ public class CallDataCopyOperation extends AbstractOperation {
@Override
public OperationResult execute(final MessageFrame frame, final EVM evm) {
final UInt256 memOffset = UInt256.fromBytes(frame.popStackItem());
final UInt256 sourceOffset = UInt256.fromBytes(frame.popStackItem());
final UInt256 numBytes = UInt256.fromBytes(frame.popStackItem());
final UInt256 memOffset = frame.popStackItem();
final UInt256 sourceOffset = frame.popStackItem();
final UInt256 numBytes = frame.popStackItem();
final Gas cost = gasCalculator().dataCopyOperationGasCost(frame, memOffset, numBytes);
final Optional<Gas> optionalCost = Optional.of(cost);

@ -32,12 +32,12 @@ public class CallDataLoadOperation extends AbstractFixedCostOperation {
@Override
public OperationResult executeFixedCostOperation(final MessageFrame frame, final EVM evm) {
final UInt256 startWord = UInt256.fromBytes(frame.popStackItem());
final UInt256 startWord = frame.popStackItem();
// If the start index doesn't fit a int, it comes after anything in data, and so the returned
// word should be zero.
if (!startWord.fitsInt()) {
frame.pushStackItem(Bytes32.ZERO);
frame.pushStackItem(UInt256.ZERO);
return successResponse;
}
@ -48,7 +48,7 @@ public class CallDataLoadOperation extends AbstractFixedCostOperation {
final Bytes toCopy = data.slice(offset, Math.min(Bytes32.SIZE, data.size() - offset));
toCopy.copyTo(res, 0);
}
frame.pushStackItem(res);
frame.pushStackItem(UInt256.fromBytes(res));
return successResponse;
}

@ -30,7 +30,7 @@ public class CallDataSizeOperation extends AbstractFixedCostOperation {
@Override
public OperationResult executeFixedCostOperation(final MessageFrame frame, final EVM evm) {
final Bytes callData = frame.getInputData();
frame.pushStackItem(UInt256.valueOf(callData.size()).toBytes());
frame.pushStackItem(UInt256.valueOf(callData.size()));
return successResponse;
}

@ -57,22 +57,22 @@ public class CallOperation extends AbstractCallOperation {
@Override
protected UInt256 inputDataOffset(final MessageFrame frame) {
return UInt256.fromBytes(frame.getStackItem(3));
return frame.getStackItem(3);
}
@Override
protected UInt256 inputDataLength(final MessageFrame frame) {
return UInt256.fromBytes(frame.getStackItem(4));
return frame.getStackItem(4);
}
@Override
protected UInt256 outputDataOffset(final MessageFrame frame) {
return UInt256.fromBytes(frame.getStackItem(5));
return frame.getStackItem(5);
}
@Override
protected UInt256 outputDataLength(final MessageFrame frame) {
return UInt256.fromBytes(frame.getStackItem(6));
return frame.getStackItem(6);
}
@Override

@ -28,7 +28,7 @@ public class CallValueOperation extends AbstractFixedCostOperation {
@Override
public OperationResult executeFixedCostOperation(final MessageFrame frame, final EVM evm) {
final Wei value = frame.getApparentValue();
frame.pushStackItem(value.toBytes());
frame.pushStackItem(value.toUInt256());
return successResponse;
}

@ -19,14 +19,15 @@ import org.hyperledger.besu.ethereum.vm.GasCalculator;
import org.hyperledger.besu.ethereum.vm.MessageFrame;
import org.apache.tuweni.bytes.Bytes32;
import org.apache.tuweni.units.bigints.UInt256;
public class ChainIdOperation extends AbstractFixedCostOperation {
private final Bytes32 chainId;
private final UInt256 chainId;
public ChainIdOperation(final GasCalculator gasCalculator, final Bytes32 chainId) {
super(0x46, "CHAINID", 0, 1, false, 1, gasCalculator, gasCalculator.getBaseTierGasCost());
this.chainId = chainId;
this.chainId = UInt256.fromBytes(chainId);
}
@Override

@ -34,9 +34,9 @@ public class CodeCopyOperation extends AbstractOperation {
@Override
public OperationResult execute(final MessageFrame frame, final EVM evm) {
final UInt256 memOffset = UInt256.fromBytes(frame.popStackItem());
final UInt256 sourceOffset = UInt256.fromBytes(frame.popStackItem());
final UInt256 numBytes = UInt256.fromBytes(frame.popStackItem());
final UInt256 memOffset = frame.popStackItem();
final UInt256 sourceOffset = frame.popStackItem();
final UInt256 numBytes = frame.popStackItem();
final Gas cost = gasCalculator().dataCopyOperationGasCost(frame, memOffset, numBytes);
final Optional<Gas> optionalCost = Optional.of(cost);

@ -30,7 +30,7 @@ public class CodeSizeOperation extends AbstractFixedCostOperation {
@Override
public OperationResult executeFixedCostOperation(final MessageFrame frame, final EVM evm) {
final Code code = frame.getCode();
frame.pushStackItem(UInt256.valueOf(code.getSize()).toBytes());
frame.pushStackItem(UInt256.valueOf(code.getSize()));
return successResponse;
}

@ -35,8 +35,8 @@ public class Create2Operation extends AbstractCreateOperation {
@Override
protected Address targetContractAddress(final MessageFrame frame) {
final Address sender = frame.getRecipientAddress();
final UInt256 offset = UInt256.fromBytes(frame.getStackItem(1));
final UInt256 length = UInt256.fromBytes(frame.getStackItem(2));
final UInt256 offset = frame.getStackItem(1);
final UInt256 length = frame.getStackItem(2);
final Bytes32 salt = frame.getStackItem(3);
final Bytes initCode = frame.readMemory(offset, length);
final Hash hash = Hash.hash(Bytes.concatenate(PREFIX, sender, salt, Hash.hash(initCode)));

@ -53,22 +53,22 @@ public class DelegateCallOperation extends AbstractCallOperation {
@Override
protected UInt256 inputDataOffset(final MessageFrame frame) {
return UInt256.fromBytes(frame.getStackItem(2));
return frame.getStackItem(2);
}
@Override
protected UInt256 inputDataLength(final MessageFrame frame) {
return UInt256.fromBytes(frame.getStackItem(3));
return frame.getStackItem(3);
}
@Override
protected UInt256 outputDataOffset(final MessageFrame frame) {
return UInt256.fromBytes(frame.getStackItem(4));
return frame.getStackItem(4);
}
@Override
protected UInt256 outputDataLength(final MessageFrame frame) {
return UInt256.fromBytes(frame.getStackItem(5));
return frame.getStackItem(5);
}
@Override

@ -28,7 +28,7 @@ public class DifficultyOperation extends AbstractFixedCostOperation {
@Override
public OperationResult executeFixedCostOperation(final MessageFrame frame, final EVM evm) {
final Difficulty difficulty = frame.getBlockHeader().getDifficulty();
frame.pushStackItem(difficulty.toBytes());
frame.pushStackItem(difficulty.toUInt256());
return successResponse;
}

@ -18,7 +18,6 @@ import org.hyperledger.besu.ethereum.vm.EVM;
import org.hyperledger.besu.ethereum.vm.GasCalculator;
import org.hyperledger.besu.ethereum.vm.MessageFrame;
import org.apache.tuweni.bytes.Bytes32;
import org.apache.tuweni.units.bigints.UInt256;
public class DivOperation extends AbstractFixedCostOperation {
@ -29,14 +28,14 @@ public class DivOperation extends AbstractFixedCostOperation {
@Override
public OperationResult executeFixedCostOperation(final MessageFrame frame, final EVM evm) {
final UInt256 value0 = UInt256.fromBytes(frame.popStackItem());
final UInt256 value1 = UInt256.fromBytes(frame.popStackItem());
final UInt256 value0 = frame.popStackItem();
final UInt256 value1 = frame.popStackItem();
if (value1.isZero()) {
frame.pushStackItem(Bytes32.ZERO);
frame.pushStackItem(UInt256.ZERO);
} else {
final UInt256 result = value0.divide(value1);
frame.pushStackItem(result.toBytes());
frame.pushStackItem(result);
}
return successResponse;

@ -18,7 +18,6 @@ import org.hyperledger.besu.ethereum.vm.EVM;
import org.hyperledger.besu.ethereum.vm.GasCalculator;
import org.hyperledger.besu.ethereum.vm.MessageFrame;
import org.apache.tuweni.bytes.Bytes32;
import org.apache.tuweni.units.bigints.UInt256;
public class EqOperation extends AbstractFixedCostOperation {
@ -29,10 +28,10 @@ public class EqOperation extends AbstractFixedCostOperation {
@Override
public OperationResult executeFixedCostOperation(final MessageFrame frame, final EVM evm) {
final UInt256 value0 = UInt256.fromBytes(frame.popStackItem());
final UInt256 value1 = UInt256.fromBytes(frame.popStackItem());
final UInt256 value0 = frame.popStackItem();
final UInt256 value1 = frame.popStackItem();
final Bytes32 result = (value0.equals(value1) ? UInt256.valueOf(1) : UInt256.ZERO).toBytes();
final UInt256 result = (value0.equals(value1) ? UInt256.ONE : UInt256.ZERO);
frame.pushStackItem(result);

@ -33,8 +33,8 @@ public class ExpOperation extends AbstractOperation {
@Override
public OperationResult execute(final MessageFrame frame, final EVM evm) {
final UInt256 number = UInt256.fromBytes(frame.popStackItem());
final UInt256 power = UInt256.fromBytes(frame.popStackItem());
final UInt256 number = frame.popStackItem();
final UInt256 power = frame.popStackItem();
final int numBytes = (power.bitLength() + 7) / 8;
@ -46,7 +46,7 @@ public class ExpOperation extends AbstractOperation {
final UInt256 result = number.pow(power);
frame.pushStackItem(result.toBytes());
frame.pushStackItem(result);
return new OperationResult(optionalCost, Optional.empty());
}
}

@ -38,9 +38,9 @@ public class ExtCodeCopyOperation extends AbstractOperation {
@Override
public OperationResult execute(final MessageFrame frame, final EVM evm) {
final Address address = Words.toAddress(frame.popStackItem());
final UInt256 memOffset = UInt256.fromBytes(frame.popStackItem());
final UInt256 sourceOffset = UInt256.fromBytes(frame.popStackItem());
final UInt256 numBytes = UInt256.fromBytes(frame.popStackItem());
final UInt256 memOffset = frame.popStackItem();
final UInt256 sourceOffset = frame.popStackItem();
final UInt256 numBytes = frame.popStackItem();
final boolean accountIsWarm =
frame.warmUpAddress(address) || gasCalculator().isPrecompile(address);

@ -28,7 +28,7 @@ import org.hyperledger.besu.ethereum.vm.Words;
import java.util.Optional;
import org.apache.tuweni.bytes.Bytes32;
import org.apache.tuweni.units.bigints.UInt256;
public class ExtCodeHashOperation extends AbstractOperation {
@ -55,9 +55,9 @@ public class ExtCodeHashOperation extends AbstractOperation {
} else {
final Account account = frame.getWorldState().get(address);
if (account == null || account.isEmpty()) {
frame.pushStackItem(Bytes32.ZERO);
frame.pushStackItem(UInt256.ZERO);
} else {
frame.pushStackItem(account.getCodeHash());
frame.pushStackItem(UInt256.fromBytes(account.getCodeHash()));
}
return new OperationResult(optionalCost, Optional.empty());
}

@ -28,7 +28,6 @@ import org.hyperledger.besu.ethereum.vm.Words;
import java.util.Optional;
import org.apache.tuweni.bytes.Bytes32;
import org.apache.tuweni.units.bigints.UInt256;
public class ExtCodeSizeOperation extends AbstractOperation {
@ -56,7 +55,7 @@ public class ExtCodeSizeOperation extends AbstractOperation {
} else {
final Account account = frame.getWorldState().get(address);
frame.pushStackItem(
account == null ? Bytes32.ZERO : UInt256.valueOf(account.getCode().size()).toBytes());
account == null ? UInt256.ZERO : UInt256.valueOf(account.getCode().size()));
return new OperationResult(optionalCost, Optional.empty());
}
} catch (final UnderflowException ufe) {

@ -21,6 +21,7 @@ import org.hyperledger.besu.ethereum.vm.MessageFrame;
import org.apache.tuweni.bytes.Bytes;
import org.apache.tuweni.bytes.Bytes32;
import org.apache.tuweni.units.bigints.UInt256;
public class GasLimitOperation extends AbstractFixedCostOperation {
@ -31,7 +32,7 @@ public class GasLimitOperation extends AbstractFixedCostOperation {
@Override
public OperationResult executeFixedCostOperation(final MessageFrame frame, final EVM evm) {
final Gas gasLimit = Gas.of(frame.getBlockHeader().getGasLimit());
final Bytes32 value = Bytes32.leftPad(Bytes.of(gasLimit.getBytes()));
final UInt256 value = UInt256.fromBytes(Bytes32.leftPad(Bytes.of(gasLimit.getBytes())));
frame.pushStackItem(value);
return successResponse;

@ -21,6 +21,7 @@ import org.hyperledger.besu.ethereum.vm.MessageFrame;
import org.apache.tuweni.bytes.Bytes;
import org.apache.tuweni.bytes.Bytes32;
import org.apache.tuweni.units.bigints.UInt256;
public class GasOperation extends AbstractFixedCostOperation {
@ -31,7 +32,7 @@ public class GasOperation extends AbstractFixedCostOperation {
@Override
public OperationResult executeFixedCostOperation(final MessageFrame frame, final EVM evm) {
final Gas gasRemaining = frame.getRemainingGas().minus(gasCost);
final Bytes32 value = Bytes32.leftPad(Bytes.of(gasRemaining.getBytes()));
final UInt256 value = UInt256.fromBytes(Bytes32.leftPad(Bytes.of(gasRemaining.getBytes())));
frame.pushStackItem(value);
return successResponse;

@ -28,7 +28,7 @@ public class GasPriceOperation extends AbstractFixedCostOperation {
@Override
public OperationResult executeFixedCostOperation(final MessageFrame frame, final EVM evm) {
final Wei gasPrice = frame.getGasPrice();
frame.pushStackItem(gasPrice.toBytes());
frame.pushStackItem(gasPrice.toUInt256());
return successResponse;
}

@ -18,7 +18,6 @@ import org.hyperledger.besu.ethereum.vm.EVM;
import org.hyperledger.besu.ethereum.vm.GasCalculator;
import org.hyperledger.besu.ethereum.vm.MessageFrame;
import org.apache.tuweni.bytes.Bytes32;
import org.apache.tuweni.units.bigints.UInt256;
public class GtOperation extends AbstractFixedCostOperation {
@ -29,11 +28,10 @@ public class GtOperation extends AbstractFixedCostOperation {
@Override
public OperationResult executeFixedCostOperation(final MessageFrame frame, final EVM evm) {
final UInt256 value0 = UInt256.fromBytes(frame.popStackItem());
final UInt256 value1 = UInt256.fromBytes(frame.popStackItem());
final UInt256 value0 = frame.popStackItem();
final UInt256 value1 = frame.popStackItem();
final Bytes32 result =
(value0.compareTo(value1) > 0 ? UInt256.valueOf(1) : UInt256.ZERO).toBytes();
final UInt256 result = (value0.compareTo(value1) > 0 ? UInt256.ONE : UInt256.ZERO);
frame.pushStackItem(result);

@ -28,9 +28,9 @@ public class IsZeroOperation extends AbstractFixedCostOperation {
@Override
public OperationResult executeFixedCostOperation(final MessageFrame frame, final EVM evm) {
final UInt256 value = UInt256.fromBytes(frame.popStackItem());
final UInt256 value = frame.popStackItem();
frame.pushStackItem(value.isZero() ? UInt256.ONE.toBytes() : UInt256.ZERO.toBytes());
frame.pushStackItem(value.isZero() ? UInt256.ONE : UInt256.ZERO);
return successResponse;
}

@ -37,7 +37,7 @@ public class JumpOperation extends AbstractFixedCostOperation {
@Override
public OperationResult executeFixedCostOperation(final MessageFrame frame, final EVM evm) {
final UInt256 jumpDestination = UInt256.fromBytes(frame.popStackItem());
final UInt256 jumpDestination = frame.popStackItem();
final Code code = frame.getCode();
if (!code.isValidJumpDestination(evm, frame, jumpDestination)) {
return invalidJumpResponse;

@ -38,7 +38,7 @@ public class JumpiOperation extends AbstractFixedCostOperation {
@Override
public OperationResult executeFixedCostOperation(final MessageFrame frame, final EVM evm) {
final UInt256 jumpDestination = UInt256.fromBytes(frame.popStackItem());
final UInt256 jumpDestination = frame.popStackItem();
final Bytes32 condition = frame.popStackItem();
// If condition is zero (false), no jump is will be performed. Therefore skip the test.

@ -41,8 +41,8 @@ public class LogOperation extends AbstractOperation {
@Override
public OperationResult execute(final MessageFrame frame, final EVM evm) {
final UInt256 dataLocation = UInt256.fromBytes(frame.popStackItem());
final UInt256 numBytes = UInt256.fromBytes(frame.popStackItem());
final UInt256 dataLocation = frame.popStackItem();
final UInt256 numBytes = frame.popStackItem();
final Gas cost = gasCalculator().logOperationGasCost(frame, dataLocation, numBytes, numTopics);
final Optional<Gas> optionalCost = Optional.of(cost);

@ -18,7 +18,6 @@ import org.hyperledger.besu.ethereum.vm.EVM;
import org.hyperledger.besu.ethereum.vm.GasCalculator;
import org.hyperledger.besu.ethereum.vm.MessageFrame;
import org.apache.tuweni.bytes.Bytes32;
import org.apache.tuweni.units.bigints.UInt256;
public class LtOperation extends AbstractFixedCostOperation {
@ -29,11 +28,10 @@ public class LtOperation extends AbstractFixedCostOperation {
@Override
public OperationResult executeFixedCostOperation(final MessageFrame frame, final EVM evm) {
final UInt256 value0 = UInt256.fromBytes(frame.popStackItem());
final UInt256 value1 = UInt256.fromBytes(frame.popStackItem());
final UInt256 value0 = frame.popStackItem();
final UInt256 value1 = frame.popStackItem();
final Bytes32 result =
value0.compareTo(value1) < 0 ? UInt256.ONE.toBytes() : UInt256.ZERO.toBytes();
final UInt256 result = value0.compareTo(value1) < 0 ? UInt256.ONE : UInt256.ZERO;
frame.pushStackItem(result);

@ -34,7 +34,7 @@ public class MLoadOperation extends AbstractOperation {
@Override
public OperationResult execute(final MessageFrame frame, final EVM evm) {
final UInt256 location = UInt256.fromBytes(frame.popStackItem());
final UInt256 location = frame.popStackItem();
final Gas cost = gasCalculator().mLoadOperationGasCost(frame, location);
final Optional<Gas> optionalCost = Optional.of(cost);
@ -42,7 +42,8 @@ public class MLoadOperation extends AbstractOperation {
return new OperationResult(optionalCost, Optional.of(ExceptionalHaltReason.INSUFFICIENT_GAS));
}
final Bytes32 value = Bytes32.leftPad(frame.readMemory(location, UInt256.valueOf(32), true));
final UInt256 value =
UInt256.fromBytes(Bytes32.leftPad(frame.readMemory(location, UInt256.valueOf(32), true)));
frame.pushStackItem(value);
return new OperationResult(optionalCost, Optional.empty());

@ -28,7 +28,7 @@ public class MSizeOperation extends AbstractFixedCostOperation {
@Override
public OperationResult executeFixedCostOperation(final MessageFrame frame, final EVM evm) {
frame.pushStackItem(UInt256.valueOf(frame.memoryByteSize()).toBytes());
frame.pushStackItem(UInt256.valueOf(frame.memoryByteSize()));
return successResponse;
}

@ -34,7 +34,7 @@ public class MStore8Operation extends AbstractOperation {
@Override
public OperationResult execute(final MessageFrame frame, final EVM evm) {
final UInt256 location = UInt256.fromBytes(frame.popStackItem());
final UInt256 location = frame.popStackItem();
final Bytes32 value = frame.popStackItem();
final Gas cost = gasCalculator().mStore8OperationGasCost(frame, location);

@ -34,7 +34,7 @@ public class MStoreOperation extends AbstractOperation {
@Override
public OperationResult execute(final MessageFrame frame, final EVM evm) {
final UInt256 location = UInt256.fromBytes(frame.popStackItem());
final UInt256 location = frame.popStackItem();
final Bytes32 value = frame.popStackItem();
final Gas cost = gasCalculator().mStoreOperationGasCost(frame, location);

@ -28,11 +28,11 @@ public class ModOperation extends AbstractFixedCostOperation {
@Override
public OperationResult executeFixedCostOperation(final MessageFrame frame, final EVM evm) {
final UInt256 value0 = UInt256.fromBytes(frame.popStackItem());
final UInt256 value1 = UInt256.fromBytes(frame.popStackItem());
final UInt256 value0 = frame.popStackItem();
final UInt256 value1 = frame.popStackItem();
final UInt256 result = value0.mod0(value1);
frame.pushStackItem(result.toBytes());
frame.pushStackItem(result);
return successResponse;
}

@ -18,7 +18,6 @@ import org.hyperledger.besu.ethereum.vm.EVM;
import org.hyperledger.besu.ethereum.vm.GasCalculator;
import org.hyperledger.besu.ethereum.vm.MessageFrame;
import org.apache.tuweni.bytes.Bytes32;
import org.apache.tuweni.units.bigints.UInt256;
public class MulModOperation extends AbstractFixedCostOperation {
@ -29,15 +28,15 @@ public class MulModOperation extends AbstractFixedCostOperation {
@Override
public OperationResult executeFixedCostOperation(final MessageFrame frame, final EVM evm) {
final UInt256 value0 = UInt256.fromBytes(frame.popStackItem());
final UInt256 value1 = UInt256.fromBytes(frame.popStackItem());
final UInt256 value2 = UInt256.fromBytes(frame.popStackItem());
final UInt256 value0 = frame.popStackItem();
final UInt256 value1 = frame.popStackItem();
final UInt256 value2 = frame.popStackItem();
if (value2.isZero()) {
frame.pushStackItem(Bytes32.ZERO);
frame.pushStackItem(UInt256.ZERO);
} else {
final UInt256 result = value0.multiplyMod(value1, value2);
frame.pushStackItem(result.toBytes());
frame.pushStackItem(result);
}
return successResponse;

@ -28,12 +28,12 @@ public class MulOperation extends AbstractFixedCostOperation {
@Override
public OperationResult executeFixedCostOperation(final MessageFrame frame, final EVM evm) {
final UInt256 value0 = UInt256.fromBytes(frame.popStackItem());
final UInt256 value1 = UInt256.fromBytes(frame.popStackItem());
final UInt256 value0 = frame.popStackItem();
final UInt256 value1 = frame.popStackItem();
final UInt256 result = value0.multiply(value1);
frame.pushStackItem(result.toBytes());
frame.pushStackItem(result);
return successResponse;
}

@ -28,11 +28,11 @@ public class NotOperation extends AbstractFixedCostOperation {
@Override
public OperationResult executeFixedCostOperation(final MessageFrame frame, final EVM evm) {
final UInt256 value = UInt256.fromBytes(frame.popStackItem());
final UInt256 value = frame.popStackItem();
final UInt256 result = value.not();
frame.pushStackItem(result.toBytes());
frame.pushStackItem(result);
return successResponse;
}

@ -29,7 +29,7 @@ public class NumberOperation extends AbstractFixedCostOperation {
@Override
public OperationResult executeFixedCostOperation(final MessageFrame frame, final EVM evm) {
final long number = frame.getBlockHeader().getNumber();
frame.pushStackItem(UInt256.valueOf(number).toBytes());
frame.pushStackItem(UInt256.valueOf(number));
return successResponse;
}

@ -28,12 +28,12 @@ public class OrOperation extends AbstractFixedCostOperation {
@Override
public OperationResult executeFixedCostOperation(final MessageFrame frame, final EVM evm) {
final UInt256 value0 = UInt256.fromBytes(frame.popStackItem());
final UInt256 value1 = UInt256.fromBytes(frame.popStackItem());
final UInt256 value0 = frame.popStackItem();
final UInt256 value1 = frame.popStackItem();
final UInt256 result = value0.or(value1);
frame.pushStackItem(result.toBytes());
frame.pushStackItem(result);
return successResponse;
}

@ -28,7 +28,7 @@ public class PCOperation extends AbstractFixedCostOperation {
@Override
public OperationResult executeFixedCostOperation(final MessageFrame frame, final EVM evm) {
frame.pushStackItem(UInt256.valueOf(frame.getPC()).toBytes());
frame.pushStackItem(UInt256.valueOf(frame.getPC()));
return successResponse;
}

@ -22,6 +22,7 @@ import org.hyperledger.besu.ethereum.vm.MessageFrame;
import org.apache.tuweni.bytes.Bytes;
import org.apache.tuweni.bytes.MutableBytes32;
import org.apache.tuweni.units.bigints.UInt256;
public class PushOperation extends AbstractFixedCostOperation {
@ -48,7 +49,7 @@ public class PushOperation extends AbstractFixedCostOperation {
final int copyLength = min(length, code.size() - pc - 1);
final MutableBytes32 bytes = MutableBytes32.create();
code.slice(pc + 1, copyLength).copyTo(bytes, bytes.size() - length);
frame.pushStackItem(bytes);
frame.pushStackItem(UInt256.fromBytes(bytes));
return successResponse;
}

@ -38,9 +38,9 @@ public class ReturnDataCopyOperation extends AbstractOperation {
@Override
public OperationResult execute(final MessageFrame frame, final EVM evm) {
final UInt256 memOffset = UInt256.fromBytes(frame.popStackItem());
final UInt256 sourceOffset = UInt256.fromBytes(frame.popStackItem());
final UInt256 numBytes = UInt256.fromBytes(frame.popStackItem());
final UInt256 memOffset = frame.popStackItem();
final UInt256 sourceOffset = frame.popStackItem();
final UInt256 numBytes = frame.popStackItem();
final Bytes returnData = frame.getReturnData();
final UInt256 returnDataLength = UInt256.valueOf(returnData.size());

@ -31,7 +31,7 @@ public class ReturnDataSizeOperation extends AbstractFixedCostOperation {
@Override
public OperationResult executeFixedCostOperation(final MessageFrame frame, final EVM evm) {
final Bytes returnData = frame.getReturnData();
frame.pushStackItem(UInt256.valueOf(returnData.size()).toBytes());
frame.pushStackItem(UInt256.valueOf(returnData.size()));
return successResponse;
}

@ -33,8 +33,8 @@ public class ReturnOperation extends AbstractOperation {
@Override
public OperationResult execute(final MessageFrame frame, final EVM evm) {
final UInt256 from = UInt256.fromBytes(frame.popStackItem());
final UInt256 length = UInt256.fromBytes(frame.popStackItem());
final UInt256 from = frame.popStackItem();
final UInt256 length = frame.popStackItem();
final Gas cost = gasCalculator().memoryExpansionGasCost(frame, from, length);
final Optional<Gas> optionalCost = Optional.of(cost);

@ -34,8 +34,8 @@ public class RevertOperation extends AbstractOperation {
@Override
public OperationResult execute(final MessageFrame frame, final EVM evm) {
final UInt256 from = UInt256.fromBytes(frame.popStackItem());
final UInt256 length = UInt256.fromBytes(frame.popStackItem());
final UInt256 from = frame.popStackItem();
final UInt256 length = frame.popStackItem();
final Gas cost = gasCalculator().memoryExpansionGasCost(frame, from, length);
final Optional<Gas> optionalCost = Optional.of(cost);

@ -22,7 +22,7 @@ import java.math.BigInteger;
import java.util.Arrays;
import org.apache.tuweni.bytes.Bytes;
import org.apache.tuweni.bytes.Bytes32;
import org.apache.tuweni.units.bigints.UInt256;
public class SDivOperation extends AbstractFixedCostOperation {
@ -32,12 +32,12 @@ public class SDivOperation extends AbstractFixedCostOperation {
@Override
public OperationResult executeFixedCostOperation(final MessageFrame frame, final EVM evm) {
final Bytes32 value0 = frame.popStackItem();
final Bytes32 value1 = frame.popStackItem();
final UInt256 value0 = frame.popStackItem();
final UInt256 value1 = frame.popStackItem();
if (value1.isZero()) {
frame.pushStackItem(Bytes32.ZERO);
frame.pushStackItem(UInt256.ZERO);
} else {
final BigInteger result = value0.toBigInteger().divide(value1.toBigInteger());
final BigInteger result = value0.toSignedBigInteger().divide(value1.toSignedBigInteger());
Bytes resultBytes = Bytes.wrap(result.toByteArray());
if (resultBytes.size() > 32) {
resultBytes = resultBytes.slice(resultBytes.size() - 32, 32);
@ -46,7 +46,7 @@ public class SDivOperation extends AbstractFixedCostOperation {
final byte[] padding = new byte[32 - resultBytes.size()];
Arrays.fill(padding, result.signum() < 0 ? (byte) 0xFF : 0x00);
frame.pushStackItem(Bytes32.wrap(Bytes.concatenate(Bytes.wrap(padding), resultBytes)));
frame.pushStackItem(UInt256.fromBytes(Bytes.concatenate(Bytes.wrap(padding), resultBytes)));
}
return successResponse;

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save