Fix #2890: Allow eth_call and eth_estimateGas to accept contract address as sender (#2891)

Signed-off-by: Vladyslav Lupashevskyi <vlad@lupashevskyi.com>
pull/2909/head
Vladyslav Lupashevskyi 3 years ago committed by GitHub
parent dba5ce55a4
commit 7d8464caa5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      CHANGELOG.md
  2. 2
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/graphql/EthGraphQLHttpBySpecTest.java
  3. 16
      ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/graphql/eth_call_from_contract.json
  4. 11
      ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/graphql/eth_estimateGas_from_contract.json
  5. 21
      ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_call_from_contract.json
  6. 20
      ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_estimateGas_from_contract.json
  7. 2
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionValidator.java
  8. 15
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/TransactionValidationParams.java

@ -8,6 +8,7 @@
### Bug Fixes
- Regression in RC1 involving LogOperation and frame memory overwrites [#2908](https://github.com/hyperledger/besu/pull/2908)
- Allow `eth_call` and `eth_estimateGas` to accept contract address as sender. [#2891](https://github.com/hyperledger/besu/pull/2891)
### Early Access Features
- Enable plugins to expose custom JSON-RPC / WebSocket methods [#1317](https://github.com/hyperledger/besu/issues/1317)

@ -49,10 +49,12 @@ public class EthGraphQLHttpBySpecTest extends AbstractEthGraphQLHttpServiceTest
specs.add("eth_call_Block8");
specs.add("eth_call_Block8_invalidHexBytesData");
specs.add("eth_call_BlockLatest");
specs.add("eth_call_from_contract");
specs.add("eth_estimateGas_transfer");
specs.add("eth_estimateGas_noParams");
specs.add("eth_estimateGas_contractDeploy");
specs.add("eth_estimateGas_from_contract");
specs.add("eth_gasPrice");

@ -0,0 +1,16 @@
{
"request": "{block {number call (data : {from : \"0x6295ee1b4f6dd65047762f924ecd367c17eabf8f\", to: \"0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b\", data :\"0x123456\"}){data status}}}"
,
"response":{
"data" : {
"block" : {
"number" : 32,
"call" : {
"data" : "0x",
"status" : 1
}
}
}
},
"statusCode": 200
}

@ -0,0 +1,11 @@
{
"request" :"{block{estimateGas (data : {from : \"0x6295ee1b4f6dd65047762f924ecd367c17eabf8f\", to: \"0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b\", data :\"0x123456\"})}}",
"response":{
"data" : {
"block" : {
"estimateGas" : 21204
}
}
},
"statusCode": 200
}

@ -0,0 +1,21 @@
{
"request": {
"id": 3,
"jsonrpc": "2.0",
"method": "eth_call",
"params": [
{
"to": "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b",
"from": "0x6295ee1b4f6dd65047762f924ecd367c17eabf8f",
"data": "0x123456"
},
"latest"
]
},
"response": {
"jsonrpc": "2.0",
"id": 3,
"result": "0x"
},
"statusCode": 200
}

@ -0,0 +1,20 @@
{
"request": {
"id": 3,
"jsonrpc": "2.0",
"method": "eth_estimateGas",
"params": [
{
"to": "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b",
"from": "0x6295ee1b4f6dd65047762f924ecd367c17eabf8f",
"data": "0x123456"
}
]
},
"response": {
"jsonrpc": "2.0",
"id": 3,
"result": "0x52d4"
},
"statusCode": 200
}

@ -205,7 +205,7 @@ public class MainnetTransactionValidator {
transaction.getNonce(), senderNonce));
}
if (!codeHash.equals(Hash.EMPTY)) {
if (!validationParams.isAllowContractAddressAsSender() && !codeHash.equals(Hash.EMPTY)) {
return ValidationResult.invalid(
TransactionInvalidReason.TX_SENDER_NOT_AUTHORIZED,
String.format(

@ -21,19 +21,19 @@ import org.immutables.value.Value;
public interface TransactionValidationParams {
TransactionValidationParams processingBlockParams =
ImmutableTransactionValidationParams.of(false, false, false, true, false);
ImmutableTransactionValidationParams.of(false, false, false, true, false, false);
TransactionValidationParams transactionPoolParams =
ImmutableTransactionValidationParams.of(true, false, true, true, true);
ImmutableTransactionValidationParams.of(true, false, true, true, true, false);
TransactionValidationParams miningParams =
ImmutableTransactionValidationParams.of(false, false, false, true, true);
ImmutableTransactionValidationParams.of(false, false, false, true, true, false);
TransactionValidationParams blockReplayParams =
ImmutableTransactionValidationParams.of(false, false, false, false, false);
ImmutableTransactionValidationParams.of(false, false, false, false, false, false);
TransactionValidationParams transactionSimulatorParams =
ImmutableTransactionValidationParams.of(false, false, false, false, false);
ImmutableTransactionValidationParams.of(false, false, false, false, false, true);
@Value.Default
default boolean isAllowFutureNonce() {
@ -60,6 +60,11 @@ public interface TransactionValidationParams {
return true;
}
@Value.Default
default boolean isAllowContractAddressAsSender() {
return false;
}
static TransactionValidationParams transactionSimulator() {
return transactionSimulatorParams;
}

Loading…
Cancel
Save