hashgraph / hedera-json-rpc-relay

Implementation of Ethereum JSON-RPC APIs for Hedera
Apache License 2.0
68 stars 72 forks source link

execution reverted: CONTRACT_REVERT_EXECUTED #1778

Closed max-chechel-vc closed 1 year ago

max-chechel-vc commented 1 year ago

Description

I took an example of the SC from here https://docs.hedera.com/hedera/tutorials/smart-contracts/deploy-your-first-smart-contract

  1. Compiled it using solc and generated a Go package to interact with the contract using abigen
  2. Deployed this SC using the go-ethereum/ethclient and the generated Go code (using JSON RPC relay)
  3. Executed set_message method of the SC using the generated code
  4. Tried to call get_message method of the SC and got the following error: execution reverted: CONTRACT_REVERT_EXECUTED

Expected result:

No error, generated code returns a message saved on (3)

Steps to reproduce

  1. solc --abi --bin HelloHedera.sol -o ./contracts/
  2. abigen --bin=./contracts/HelloHedera.bin --abi=./contracts/HelloHedera.abi --pkg=contracts --out=./contracts/hello_hedera.go
  3. Deploy contract using generated code in ./contracts package
  4. Execute SetMessage method of the SC
  5. Call GetMessage method of the SC

Additional context

JSON RPC log related to the request:

[2023-10-03 16:03:11.219 +0000] TRACE (relay-eth/85 on 83d3c95c4893): [Request ID: 248170d0-85c7-41d2-a0e0-3f3b64e693b9] call({to=0x8cf56172314f08f7d69f0ee527b5e0d1ce06dd59, from=0x775d10635b7d6c328b022cb3193bc7cddba91dd9, value=undefined, gas=undefined, ...}, blockParam=pending)
[2023-10-03 16:03:11.219 +0000] DEBUG (relay-eth/85 on 83d3c95c4893): [Request ID: 248170d0-85c7-41d2-a0e0-3f3b64e693b9] Making eth_call on contract 0x8cf56172314f08f7d69f0ee527b5e0d1ce06dd59 with gas 400000 and call data "undefined" from "0x775d10635b7d6c328b022cb3193bc7cddba91dd9" using mirror-node.
[2023-10-03 16:03:11.283 +0000] ERROR (mirror-node/85 on 83d3c95c4893): [Request ID: 248170d0-85c7-41d2-a0e0-3f3b64e693b9] [POST] contracts/call 400 status
    err: {
      "type": "Error",
      "message": "Request failed with status code 400",
      "stack":
          Error: Request failed with status code 400
              at MirrorNodeClient.handleError (/home/node/app/packages/relay/dist/lib/clients/mirrorNodeClient.js:229:27)
              at MirrorNodeClient.<anonymous> (/home/node/app/packages/relay/dist/lib/clients/mirrorNodeClient.js:202:22)
              at Generator.throw (<anonymous>)
              at rejected (/home/node/app/packages/relay/dist/lib/clients/mirrorNodeClient.js:25:65)
              at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    }
[2023-10-03 16:03:11.284 +0000] TRACE (relay-eth/85 on 83d3c95c4893): [Request ID: 248170d0-85c7-41d2-a0e0-3f3b64e693b9] mirror node eth_call request encoutered contract revert. message: CONTRACT_REVERT_EXECUTED, details: , data: 0x
[2023-10-03 16:03:11.284 +0000] ERROR (rpc-server/85 on 83d3c95c4893): [Request ID: 248170d0-85c7-41d2-a0e0-3f3b64e693b9] execution reverted: CONTRACT_REVERT_EXECUTED
[2023-10-03 16:03:11.284 +0000] INFO (rpc-server/85 on 83d3c95c4893): [Request ID: 248170d0-85c7-41d2-a0e0-3f3b64e693b9] [POST]: eth_call 400 (JSON RPC ERROR) 65 ms

Error from the go-ethereum client:

[Request ID: 248170d0-85c7-41d2-a0e0-3f3b64e693b9] execution reverted: CONTRACT_REVERT_EXECUTED

I'm able to successfully run all steps using native Hedera Go SDK but it's not the case with common go-ethereum client (and maybe others too).

Hedera network

testnet

Version

go-ethereum v1.13.2

Operating system

Linux

max-chechel-vc commented 1 year ago

There's no way to tell why mirror node rejects request with 400 status because these errors are not being logged by the mirror node. I think it's something that also needs to be fixed.

AlfredoG87 commented 1 year ago

Hello @max-chechel-vc

Thank you for reporting an issue.

I've reviewed the referenced tutorial and was able to successfully deploy it using remix and metmask using public hashio testnet relay. I was also able to successfully load the contract and interact with it, get the message and set a new message and then get the new message.

I also loaded your contract address 0x8cf56172314f08f7d69f0ee527b5e0d1ce06dd59 and was able to get the message, but not to set the message since I was not the owner, however the setMessage method is not reverting, since as you can see, if you are not the owner it does only a return and does not reverts.

function set_message(string memory message_) public {
        // only allow the owner to update the message
        if (msg.sender != owner) return;
        message = message_;
    }

Finally a proceeded to use the data provided on the logs so I could try that call directly against our hashio hosted testnet relay. and it works (with your deployed contract)

curl --location 'https://testnet.hashio.io/api' \
--header 'Content-Type: application/json' \
--data '{
  "id": 8151930679402,
  "jsonrpc": "2.0",
  "method": "eth_call",
  "params": [
    {
      "from": "0x775d10635b7d6c328b022cb3193bc7cddba91dd9",      
      "data": "0x32af2edb",
      "to": "0x8cf56172314f08F7d69f0eE527B5E0d1ce06Dd59"      
    },
    "latest"
  ]
}'

Based on those tests I can see that:

  1. you were able to sucessfully create the smart contract with the constructor (initial message) Hello World
  2. your deployed smart contract is able to return the message using get_message method.
  3. set_message method is working as expected when using remix and metamask
  4. taking a look at your logs, I see that the call data "undefined" when calling eth_call method. that is provoking the REVERT.

Without Data (REVERTS)

curl --location 'https://testnet.hashio.io/api' \
--header 'Content-Type: application/json' \
--data '{
  "id": 8151930679402,
  "jsonrpc": "2.0",
  "method": "eth_call",
  "params": [
    {
      "from": "0x775d10635b7d6c328b022cb3193bc7cddba91dd9",      
      "to": "0x8cf56172314f08F7d69f0eE527B5E0d1ce06Dd59"      
    },
    "latest"
  ]
}'

Hypothesis:

  1. your Go Json-RPC Client is not setting the method selector in the data field, I am not familiar with Go-Ethereum Client, but would like you to double-check the way you are setting the fields in order to get the message.

Let me know if we are good to close this ticket

hexdigest commented 1 year ago

Let me check what's the actual request body go-ethereum client sends to the JSON RPC relay.

hexdigest commented 1 year ago

Here is the body that go-ethereum client sends:

{
    "jsonrpc": "2.0",
    "id": 8,
    "method": "eth_call",
    "params": [
        {
            "from": "0x775d10635b7d6c328b022cb3193bc7cddba91dd9",
            "input": "0x32af2edb",
            "to": "0xaf220db900993d945aac371417d215783bfaf7d9"
        },
        "0x2b85ea"
    ]
}

I also tried to use pending and latest instead of the block number 0x2b85ea and also tried to remove the input field from request - same results.

hexdigest commented 1 year ago

Also it's not my client that makes this request it's the JSON RPC relay that makes request to the Hedera RPC mirror node. And the mirror node responds with 400 Bad Request error which results in CONTRACT_REVERT_EXECUTED error from the JSON RPC relay

hexdigest commented 1 year ago

So I think the undefined comes from the JSON RPC relay when the contract method doesn't have any parameters and this undefined comes from the JS code of the relay (no surprizes here).

AlfredoG87 commented 1 year ago

Here is the body that go-ethereum client sends:

{
    "jsonrpc": "2.0",
    "id": 8,
    "method": "eth_call",
    "params": [
        {
            "from": "0x775d10635b7d6c328b022cb3193bc7cddba91dd9",
            "input": "0x32af2edb",
            "to": "0xaf220db900993d945aac371417d215783bfaf7d9"
        },
        "0x2b85ea"
    ]
}

I also tried to use pending and latest instead of the block number 0x2b85ea and also tried to remove the input field from request - same results.

I've ran that same query against our hosted version of the relay hashio testnet and I don't get any 400 CONTRACT_REVERT (only changed to "latest" but it works also with the provided blockNumber.

curl --location 'https://testnet.hashio.io/api' \
--header 'Content-Type: application/json' \
--data '{
    "jsonrpc": "2.0",
    "id": 8,
    "method": "eth_call",
    "params": [
        {
            "from": "0x775d10635b7d6c328b022cb3193bc7cddba91dd9",
            "input": "0x32af2edb",
            "to": "0xaf220db900993d945aac371417d215783bfaf7d9"
        },
        "latest"
    ]
}'
AlfredoG87 commented 1 year ago

@hexdigest, maybe is something with your Relay Configuration, i see you are using your own instance.

could you share your .env properties without the secrets?

hexdigest commented 1 year ago

@hexdigest, maybe is something with your Relay Configuration, i see you are using your own instance.

could you share your .env properties without the secrets? Here is our .env:

HEDERA_NETWORK=TESTNET
CHAIN_ID=0x128
MIRROR_NODE_URL=http://rest:5551/
ETH_CALL_DEFAULT_TO_CONSENSUS_NODE=false

DEV_MODE=false
ETH_CALL_MAX_REQUEST_PER_SDK_INSTANCE=20
ETH_GET_TRANSACTION_COUNT_CACHE_TTL=200
ETH_POPULATE_SYNTHETIC_CONTRACT_RESULTS=true
INPUT_SIZE_LIMIT=1
MIRROR_NODE_HTTP_KEEP_ALIVE=true
MIRROR_NODE_HTTP_MAX_SOCKETS=200
MIRROR_NODE_HTTP_MAX_TOTAL_SOCKETS=200
MIRROR_NODE_RETRIES=1
MIRROR_NODE_RETRY_DELAY=3000
REQUEST_ID_IS_OPTIONAL=true
SDK_REQUEST_TIMEOUT=20000
SUBSCRIPTIONS_ENABLED=true
HBAR_RATE_LIMIT_TINYBAR=2200000000

Also can you please share what version of RPC relay and Mirror nodes you run? Maybe we use an outdated versions and this problem is no longer exists in the recent ones.

AlfredoG87 commented 1 year ago

Thanks, I don't see any potential issues with your env config.

Sharing used versions:

Relay version: 0.32.0 https://github.com/hashgraph/hedera-json-rpc-relay/releases/tag/v0.32.0

Mirror Node version: 0.89.0 https://github.com/hashgraph/hedera-mirror-node/releases/tag/v0.89.0

AlfredoG87 commented 1 year ago

@max-chechel-vc just asking if we are good to close this ticket?

hexdigest commented 1 year ago

@max-chechel-vc just asking if we are good to close this ticket?

Have you guys fixed anything? Should we update our mirrors/relays?

AlfredoG87 commented 1 year ago

Yes, the issue you described here is not happening on newer versions of the relay/mirror node.

hexdigest commented 1 year ago

Yes, the issue you described here is not happening on newer versions of the relay/mirror node.

I can confirm that the request above works with the latest versions of relay and mirror.

Nana-EC commented 1 year ago

@hexdigest thanks. In follow up you can always check https://status.swirldslabs.com/ and https://status.hedera.com/ to see what versions of the relay and mirror node are deployed in public environments. Mainnet also usually lines up with the latest GA version in the repos https://github.com/hashgraph/hedera-json-rpc-relay/releases and https://github.com/hashgraph/hedera-mirror-node/releases.

Appreciate the ticket, please feel free to open a ticket if you encounter any more issues or start discussion if you have questions we can help address in the future.