implement EIP-3607 (#2676)

* implement EIP-3607

Signed-off-by: Gary Schulte <gary.schulte@consensys.net>
pull/2686/head
garyschulte 3 years ago committed by Lucas Saldanha
parent 9b3c734c6a
commit b5113e715f
  1. 2
      .circleci/config.yml
  2. 6
      ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/fork/frontier/EthEstimateGasIntegrationTest.java
  3. 2
      ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/graphql/eth_estimateGas_contractDeploy.json
  4. 2
      ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/graphql/eth_estimateGas_transfer.json
  5. 2
      ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_estimateGas_contractDeploy.json
  6. 2
      ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_estimateGas_invalid.json
  7. 2
      ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_estimateGas_transfer.json
  8. 11
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionValidator.java
  9. 17
      ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionValidatorTest.java
  10. 2
      ethereum/referencetests/build.gradle
  11. 2
      ethereum/referencetests/src/test/resources

@ -163,7 +163,7 @@ jobs:
at: ~/project
- run:
name: ReferenceTests
no_output_timeout: 20m
no_output_timeout: 30m
command: |
git submodule update --init --recursive
./gradlew --no-daemon referenceTest

@ -78,7 +78,7 @@ public class EthEstimateGasIntegrationTest {
public void shouldReturnExpectedValueForTransfer() {
final JsonCallParameter callParameter =
new JsonCallParameter(
Address.fromHexString("0x6295ee1b4f6dd65047762f924ecd367c17eabf8f"),
Address.fromHexString("0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b"),
Address.fromHexString("0x8888f1f195afa192cfee860698584c030f4c9db1"),
null,
null,
@ -99,7 +99,7 @@ public class EthEstimateGasIntegrationTest {
public void shouldReturnExpectedValueForContractDeploy() {
final JsonCallParameter callParameter =
new JsonCallParameter(
Address.fromHexString("0x6295ee1b4f6dd65047762f924ecd367c17eabf8f"),
Address.fromHexString("0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b"),
null,
null,
null,
@ -121,7 +121,7 @@ public class EthEstimateGasIntegrationTest {
public void shouldIgnoreSenderBalanceAccountWhenStrictModeDisabledAndReturnExpectedValue() {
final JsonCallParameter callParameter =
new JsonCallParameter(
Address.fromHexString("0x6295ee1b4f6dd65047762f924ecd367c17eabf8f"),
Address.fromHexString("0x0000000000000000000000000000000000000000"),
null,
Gas.of(1),
Wei.fromHexString("0x9999999999"),

@ -1,6 +1,6 @@
{
"request" :"{block{estimateGas (data: {from :\"0x6295ee1b4f6dd65047762f924ecd367c17eabf8f\", data :\"0x608060405234801561001057600080fd5b50610157806100206000396000f30060806040526004361061004c576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680633bdab8bf146100515780639ae97baa14610068575b600080fd5b34801561005d57600080fd5b5061006661007f565b005b34801561007457600080fd5b5061007d6100b9565b005b7fa53887c1eed04528e23301f55ad49a91634ef5021aa83a97d07fd16ed71c039a60016040518082815260200191505060405180910390a1565b7fa53887c1eed04528e23301f55ad49a91634ef5021aa83a97d07fd16ed71c039a60026040518082815260200191505060405180910390a17fa53887c1eed04528e23301f55ad49a91634ef5021aa83a97d07fd16ed71c039a60036040518082815260200191505060405180910390a15600a165627a7a7230582010ddaa52e73a98c06dbcd22b234b97206c1d7ed64a7c048e10c2043a3d2309cb0029\"})}}",
"request" :"{block{estimateGas (data: {from :\"0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b\", data :\"0x608060405234801561001057600080fd5b50610157806100206000396000f30060806040526004361061004c576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680633bdab8bf146100515780639ae97baa14610068575b600080fd5b34801561005d57600080fd5b5061006661007f565b005b34801561007457600080fd5b5061007d6100b9565b005b7fa53887c1eed04528e23301f55ad49a91634ef5021aa83a97d07fd16ed71c039a60016040518082815260200191505060405180910390a1565b7fa53887c1eed04528e23301f55ad49a91634ef5021aa83a97d07fd16ed71c039a60026040518082815260200191505060405180910390a17fa53887c1eed04528e23301f55ad49a91634ef5021aa83a97d07fd16ed71c039a60036040518082815260200191505060405180910390a15600a165627a7a7230582010ddaa52e73a98c06dbcd22b234b97206c1d7ed64a7c048e10c2043a3d2309cb0029\"})}}",
"response":{
"data" : {
"block" : {

@ -1,5 +1,5 @@
{
"request" :"{block{estimateGas (data: {from :\"0x6295ee1b4f6dd65047762f924ecd367c17eabf8f\", to :\"0x8888f1f195afa192cfee860698584c030f4c9db1\"})}}",
"request" :"{block{estimateGas (data: {from :\"0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b\", to :\"0x8888f1f195afa192cfee860698584c030f4c9db1\"})}}",
"response":{
"data" : {
"block" : {

@ -5,7 +5,7 @@
"method": "eth_estimateGas",
"params": [
{
"from": "0x6295ee1b4f6dd65047762f924ecd367c17eabf8f",
"from": "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b",
"data": "0x608060405234801561001057600080fd5b50610157806100206000396000f30060806040526004361061004c576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680633bdab8bf146100515780639ae97baa14610068575b600080fd5b34801561005d57600080fd5b5061006661007f565b005b34801561007457600080fd5b5061007d6100b9565b005b7fa53887c1eed04528e23301f55ad49a91634ef5021aa83a97d07fd16ed71c039a60016040518082815260200191505060405180910390a1565b7fa53887c1eed04528e23301f55ad49a91634ef5021aa83a97d07fd16ed71c039a60026040518082815260200191505060405180910390a17fa53887c1eed04528e23301f55ad49a91634ef5021aa83a97d07fd16ed71c039a60036040518082815260200191505060405180910390a15600a165627a7a7230582010ddaa52e73a98c06dbcd22b234b97206c1d7ed64a7c048e10c2043a3d2309cb0029"
}
]

@ -5,7 +5,7 @@
"method": "eth_estimateGas",
"params": [
{
"from": "0x6295ee1b4f6dd65047762f924ecd367c17eabf8f",
"from": "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b",
"data": "0x600160005560016000fe6011600155"
}
]

@ -5,7 +5,7 @@
"method": "eth_estimateGas",
"params": [
{
"from": "0x6295ee1b4f6dd65047762f924ecd367c17eabf8f",
"from": "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b",
"to": "0x8888f1f195afa192cfee860698584c030f4c9db1",
"value": "0x1"
}

@ -18,6 +18,7 @@ import org.hyperledger.besu.crypto.SECPSignature;
import org.hyperledger.besu.crypto.SignatureAlgorithmFactory;
import org.hyperledger.besu.ethereum.core.Account;
import org.hyperledger.besu.ethereum.core.Gas;
import org.hyperledger.besu.ethereum.core.Hash;
import org.hyperledger.besu.ethereum.core.Transaction;
import org.hyperledger.besu.ethereum.core.TransactionFilter;
import org.hyperledger.besu.ethereum.core.Wei;
@ -168,10 +169,12 @@ public class MainnetTransactionValidator {
final TransactionValidationParams validationParams) {
Wei senderBalance = Account.DEFAULT_BALANCE;
long senderNonce = Account.DEFAULT_NONCE;
Hash codeHash = Hash.EMPTY;
if (sender != null) {
senderBalance = sender.getBalance();
senderNonce = sender.getNonce();
if (sender.getCodeHash() != null) codeHash = sender.getCodeHash();
}
if (transaction.getUpfrontCost().compareTo(senderBalance) > 0) {
@ -198,6 +201,14 @@ public class MainnetTransactionValidator {
transaction.getNonce(), senderNonce));
}
if (!codeHash.equals(Hash.EMPTY)) {
return ValidationResult.invalid(
TransactionInvalidReason.TX_SENDER_NOT_AUTHORIZED,
String.format(
"Sender %s has deployed code and so is not authorized to send transactions",
transaction.getSender()));
}
if (!isSenderAllowed(transaction, validationParams)) {
return ValidationResult.invalid(
TransactionInvalidReason.TX_SENDER_NOT_AUTHORIZED,

@ -32,6 +32,7 @@ import org.hyperledger.besu.ethereum.core.Account;
import org.hyperledger.besu.ethereum.core.Address;
import org.hyperledger.besu.ethereum.core.Gas;
import org.hyperledger.besu.ethereum.core.GasAndAccessedState;
import org.hyperledger.besu.ethereum.core.Hash;
import org.hyperledger.besu.ethereum.core.Transaction;
import org.hyperledger.besu.ethereum.core.TransactionFilter;
import org.hyperledger.besu.ethereum.core.TransactionTestFixture;
@ -204,6 +205,22 @@ public class MainnetTransactionValidatorTest {
.isEqualTo(ValidationResult.valid());
}
@Test
public void shouldRejectTransactionIfAccountIsNotEOA() {
final MainnetTransactionValidator validator =
new MainnetTransactionValidator(
transactionGasCalculator, false, Optional.empty(), defaultGoQuorumCompatibilityMode);
validator.setTransactionFilter(transactionFilter(false));
Account invalidEOA =
when(account(basicTransaction.getUpfrontCost(), basicTransaction.getNonce()).getCodeHash())
.thenReturn(Hash.fromHexStringLenient("0xdeadbeef"))
.getMock();
assertThat(validator.validateForSender(basicTransaction, invalidEOA, true))
.isEqualTo(ValidationResult.invalid(TransactionInvalidReason.TX_SENDER_NOT_AUTHORIZED));
}
@Test
public void shouldRejectTransactionIfAccountIsNotPermitted() {
final MainnetTransactionValidator validator =

@ -41,7 +41,7 @@ task ('validateReferenceTestSubmodule') {
description = "Checks that the reference tests submodule is not accidentally changed"
doLast {
def result = new ByteArrayOutputStream()
def expectedHash = 'e0a8b2f9292fbaeb6ca2d69d461794e587aa123b'
def expectedHash = '1587f40e7f606140822307d47e88c8d09acc907a'
def submodulePath = java.nio.file.Path.of("${rootProject.projectDir}", "ethereum/referencetests/src/test/resources").toAbsolutePath()
try {
exec {

@ -1 +1 @@
Subproject commit e0a8b2f9292fbaeb6ca2d69d461794e587aa123b
Subproject commit 1587f40e7f606140822307d47e88c8d09acc907a
Loading…
Cancel
Save