Skip to content
This repository has been archived by the owner on Mar 24, 2023. It is now read-only.

[BUG] eth_getBlockByHash returns some fields equal to zero #564

Open
maciej-kozuszek opened this issue Oct 27, 2022 · 9 comments
Open

[BUG] eth_getBlockByHash returns some fields equal to zero #564

maciej-kozuszek opened this issue Oct 27, 2022 · 9 comments
Assignees
Labels
bug Something isn't working

Comments

@maciej-kozuszek
Copy link

maciej-kozuszek commented Oct 27, 2022

Performing RPC call eth_getBlockByHash to https://v1.mainnet.godwoken.io/rpc return some values equal to zero. For example Rpc call with body:

{
  "method": "eth_getBlockByHash",
  "jsonrpc": "2.0",
  "id": 1,
  "params": [
    "0x9207b685f981f6bdd1a191de60db31557bafc4774cb2093b395a6c4407b0e6f3",
    false
  ]
}

returns

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "number": "0x2d9e2",
    "hash": "0x9207b685f981f6bdd1a191de60db31557bafc4774cb2093b395a6c4407b0e6f3",
    ...
    "timestamp": "0x634f55fe",
    "mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
    "nonce": "0x0000000000000000",
    "stateRoot": "0x0000000000000000000000000000000000000000000000000000000000000000",
    "sha3Uncles": "0x0000000000000000000000000000000000000000000000000000000000000000",
    "receiptsRoot": "0x0000000000000000000000000000000000000000000000000000000000000000",
    "transactionsRoot": "0x0000000000000000000000000000000000000000000000000000000000000000",
    "uncles": [],
    "difficulty": "0x8e1bc9bf04000",
    "totalDifficulty": "0x8e1bc9bf04000",
    "extraData": "0x"
  }
}

Also visible on gwscan

mixHash, stateRoot, sha3Uncles, receiptsRoot and transactionsRoot are all equal to zero. Doing same call to ethereum mainnet for block 0xa9f6827e3a12cd76be9d2327c6545b57f947ba748ab5506a49b92728c71b16f7 we get response like this:

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "number": "0xf16d48",
    "hash": "0xa9f6827e3a12cd76be9d2327c6545b57f947ba748ab5506a49b92728c71b16f7",
    ...
    "mixHash": "0xf8d941477eeb485383d8e4a1fab83930bdddaf35fc1c1e62f196c8ad4099accd",
    "nonce": "0x0000000000000000",
    "parentHash": "0x78d724802d3fb66a7f1149d10f6eebdd122113803c37e3fd80eb3773da2753eb",
    "receiptsRoot": "0x5cf419c5ec3a2489858cfb91d3d50f5af1c11a22340bba442dfb4ddc3044282f",
    "sha3Uncles": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
    "size": "0x1dcb9",
    "stateRoot": "0x6f1280b9de56bf9b39649226d02f73644673cf7cbb07eaf029bad6ea5970b6a4",
    "timestamp": "0x63574bcb",
    "totalDifficulty": "0xc70d815d562d3cfa955",
    "transactionsRoot": "0x990e232c23c11f3e033717a3f7b53701685cc4204d8d1b09e2dc4d49f7c3bee1",
    "uncles": [],
    "baseFeePerGas": "0x2db9ff18d"
  }
}

Lack of those fields makes calculating block hash impossible for hardhat fork feature which make whole fork blockchain invalid. I have setup test with simple test that performs eth_getBlockByHash parse rpc call result with hardhat block object and calculates hash from call data.

@maciej-kozuszek maciej-kozuszek added the bug Something isn't working label Oct 27, 2022
@classicalliu
Copy link
Contributor

Why you need to perform hardhat fork on godwoken ?
We would like to learn more about the requirements of hardhat fork feature.

@maciej-kozuszek
Copy link
Author

Hardhat fork would be great debugging tool that could speed up our development and made it easier to detect potential bugs on chain. It should be working on every EVM compatible chain, but right now I am having issues with eth_getBlockByHash as describe. Right now I am working to make Godwoken fork and I am still finding some issues so I can't give you complete list of requirements.

@classicalliu
Copy link
Contributor

I have tried yarn hardhat node --fork https://v1.mainnet.godwoken.io/rpc and works well, so I'm not quite sure what the specific problem is. Can you tell me how to reproduce your problem?

@maciej-kozuszek
Copy link
Author

We should be able to send various eth methods eth_getBlockByHash eth_getTransactionByHash etc.
Sending POST at address http://localhost:8545 with body

{
  "method": "eth_getBlockByHash",
  "jsonrpc": "2.0",
  "id": 1,
  "params": [
    "0xf54a7d4c97ebdf4cb4409e962e0d9e8deeb625beb4ae5041ff10f46f0bc5accc",
    false
  ]
}

returns null which is incorrect and we can see this block and gw scan

This is happening because local fork doesn't have this block and and needs this make rpc call to https://v1.mainnet.godwoken.io/rpc it gets the block with hash 0xf54a7d4c97ebdf4cb4409e962e0d9e8deeb625beb4ae5041ff10f46f0bc5accc, recalculates hash (different as some parameters are equal to 0), add this new block with different hash to local chain and again tries to get block with hash 0xf54a7d4c97ebdf4cb4409e962e0d9e8deeb625beb4ae5041ff10f46f0bc5accc which returns undefined.
Hardhat assumes that hash from rpc call and locally recalculated will be the same and we should make sure that parameters from eth_getBlockByHash returns correct values required to calculate hash.

@jjyr
Copy link
Collaborator

jjyr commented Nov 4, 2022

The block hash is calculated from blake2b(gw_header). Which is different from Ethereum - sha3(eth_header).
To support the fork command, we must re-index l2 blocks and use sha3(eth_header) to re-calculate block_hash.


We can re-index l2 blocks with the ethereum compatible block hash and provide a new endpoint:/eth-rpc to return eth blocks. The old endpoint keeps the incompatible behavior, it still uses blake2b(gw_header) as its block hash.

Developers can use the new RPC to execute the fork command.

But we still had a little issue, the block-hash in the solidity will return blake2b(gw_header) instead of the sha3(eth_header), which may cause some unexpected behavior.

@maciej-kozuszek
Copy link
Author

I like the idea of another endpoint with sha3(eth_header) block hashing but it still requires to change some values returned by rpc like stateRoot so the new hash calculated correctly.

@jjyr
Copy link
Collaborator

jjyr commented Nov 8, 2022

I like the idea of another endpoint with sha3(eth_header) block hashing but it still requires to change some values returned by rpc like stateRoot so the new hash calculated correctly.

Unfortunately, Godwoken uses a sparse-merkle-tree to replace the MPT, which uses a different algorithm to calculate the state root, so stateRoot won't work.

Which feature do you expect from the hardhat fork command? maybe we can provide debugging API to simulate the process or use other tools to reach the goal?

@maciej-kozuszek
Copy link
Author

We still need stateRoot and other fields in the future and different data structure isn't much of problem.

I am using hardhat fork to query debug_traceTransaction on local fork for debugging purpose and verify changes on storage with eth_getStorageAt on https://v1.mainnet.godwoken.io/rpc RPC.

@jjyr
Copy link
Collaborator

jjyr commented Nov 11, 2022

Hi, a new debugging API has been implemented in Godwoken. It is like the debug_traceTransaction in the Geth. I think it can solve your question. The public endpoint may not support this RPC, but you can deploy one.

Don't worry about the output, the logs will be adjusted before release.

{
    "jsonrpc": "2.0",
    "result": {
        "return_data": "0x",
        "logs": [
            {
                "account_id": "0x26",
                "service_flag": "0x0",
                "data": "0x0200000014000000caebe8353b11b23546ad51ec7a51bf3f673e47dc0200000014000000f01d184fb606a51b82cb8f46bf9afb2a9c3d475900a0724e18090000000000000000000000000000000000000000000000000000"
            },
            {
                "account_id": "0x27",
                "service_flag": "0x3",
                "data": "0x9e858a7aaedf9fdb1026ab1f77f627be2791e98a20000000000000000000000000000000000000000000000000000000000009184e72a00003000000ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef000000000000000000000000caebe8353b11b23546ad51ec7a51bf3f673e47dc000000000000000000000000f01d184fb606a51b82cb8f46bf9afb2a9c3d4759"
            },
            {
                "account_id": "0x27",
                "service_flag": "0x3",
                "data": "0x9e858a7aaedf9fdb1026ab1f77f627be2791e98a20000000000000000000000000000000000000000000000000000000000384665653e000030000008c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925000000000000000000000000caebe8353b11b23546ad51ec7a51bf3f673e47dc000000000000000000000000f01d184fb606a51b82cb8f46bf9afb2a9c3d4759"
            },
            {
                "account_id": "0x27",
                "service_flag": "0x3",
                "data": "0x9e858a7aaedf9fdb1026ab1f77f627be2791e98a200000000000000000000000000000000000000000000000000000000000000000000000030000008c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925000000000000000000000000f01d184fb606a51b82cb8f46bf9afb2a9c3d47590000000000000000000000005302a41d95fc7b194c59154fd6ed8dde9e7c7430"
            },
            {
                "account_id": "0x27",
                "service_flag": "0x3",
                "data": "0x9e858a7aaedf9fdb1026ab1f77f627be2791e98a20000000000000000000000000000000000000000000000000000000000009184e72a000030000008c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925000000000000000000000000f01d184fb606a51b82cb8f46bf9afb2a9c3d47590000000000000000000000005302a41d95fc7b194c59154fd6ed8dde9e7c7430"
            },
            {
                "account_id": "0x16a6",
                "service_flag": "0x3",
                "data": "0x5302a41d95fc7b194c59154fd6ed8dde9e7c7430800000000000000000000000000000000000000000000000000000004181b643a9809bec0000000000000000000000000000000000000000000000000000002cffbe0a2d0000000000000000000000000000000000000000000000000de871bcda1bba2500000000000000000000000000000000000000000000000009a37600e1e24dd7010000004dec04e750ca11537cabcd8a9eab06494de08da3735bc8871cd41250e190bc04"
            },
            {
                "account_id": "0x16a5",
                "service_flag": "0x3",
                "data": "0x352d09567de5a02415670723d09e006f623fe62e80000000000000000000000000000000000000000000000000112ed5c58b1714d21a1277000000000000000000000000000000000000000000000006b7e5cade057d64570000000000000000000000000000000000000000000000000de7872bc44aa3d3000000000000000000000000000000000000000000018c808ffe9b91c25715d6010000004dec04e750ca11537cabcd8a9eab06494de08da3735bc8871cd41250e190bc04"
            },
            {
                "account_id": "0x169e",
                "service_flag": "0x3",
                "data": "0x5c68bdbba7151c486facb66dc39b891030e467254000000000000000000000000000000000000000000000000000000006481d9a62f1497a000000000000000000000000000000216a158fa3c031e12edc48a3da5a105b6603000000e4716eb795d885029cf31996b09df338107165091457dbfa921c5854162e316b0000000000000000000000005302a41d95fc7b194c59154fd6ed8dde9e7c743000000000000000000000000006e4cc6bf8096b78cdc1eafd7cef73e6ee58c09a"
            },
            {
                "account_id": "0x26",
                "service_flag": "0x0",
                "data": "0x0200000014000000f01d184fb606a51b82cb8f46bf9afb2a9c3d475902000000140000005302a41d95fc7b194c59154fd6ed8dde9e7c743000a0724e18090000000000000000000000000000000000000000000000000000"
            },
            {
                "account_id": "0x27",
                "service_flag": "0x3",
                "data": "0x9e858a7aaedf9fdb1026ab1f77f627be2791e98a20000000000000000000000000000000000000000000000000000000000009184e72a00003000000ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef000000000000000000000000f01d184fb606a51b82cb8f46bf9afb2a9c3d47590000000000000000000000005302a41d95fc7b194c59154fd6ed8dde9e7c7430"
            },
            {
                "account_id": "0x27",
                "service_flag": "0x3",
                "data": "0x9e858a7aaedf9fdb1026ab1f77f627be2791e98a200000000000000000000000000000000000000000000000000000000000000000000000030000008c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925000000000000000000000000f01d184fb606a51b82cb8f46bf9afb2a9c3d47590000000000000000000000005302a41d95fc7b194c59154fd6ed8dde9e7c7430"
            },
            {
                "account_id": "0x16a6",
                "service_flag": "0x3",
                "data": "0x5302a41d95fc7b194c59154fd6ed8dde9e7c7430a0000000000000000000000000000000f01d184fb606a51b82cb8f46bf9afb2a9c3d475900000000000000000000000006e4cc6bf8096b78cdc1eafd7cef73e6ee58c09a000000000000000000000000000000000000000000000000000009184e72a0000000000000000000000000000000000000000000000000000000ad6b51791dc100000000000000000000000000000000000000000000000009a36ce8936fadd7010000001a2a22cb034d26d1854bdc6666a5b91fe25efbbb5dcad3b0355478d6f5c362a1"
            },
            {
                "account_id": "0x169e",
                "service_flag": "0x3",
                "data": "0x5c68bdbba7151c486facb66dc39b891030e4672540000000000000000000000000000000000000000000000000000000006bcc2e86ef6121000000000000000000000000000000aaeba0ac2c5b43fbc365d8a0542e037a5903000000a5edc6018860a4e61a451543fc6d882fcfa5aed343e77f66841c8775671bb1d6000000000000000000000000352d09567de5a02415670723d09e006f623fe62e00000000000000000000000006e4cc6bf8096b78cdc1eafd7cef73e6ee58c09a"
            },
            {
                "account_id": "0x169e",
                "service_flag": "0x3",
                "data": "0x5c68bdbba7151c486facb66dc39b891030e46725400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000aaeba0ac2c5b43fbc365d8a0542e037a5903000000a5edc6018860a4e61a451543fc6d882fcfa5aed343e77f66841c8775671bb1d6000000000000000000000000352d09567de5a02415670723d09e006f623fe62e000000000000000000000000f01d184fb606a51b82cb8f46bf9afb2a9c3d4759"
            },
            {
                "account_id": "0x16a5",
                "service_flag": "0x3",
                "data": "0x352d09567de5a02415670723d09e006f623fe62e2000000000000000000000000000000000000000000000000000000000000005e6c2a72103000000ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef00000000000000000000000006e4cc6bf8096b78cdc1eafd7cef73e6ee58c09a000000000000000000000000f01d184fb606a51b82cb8f46bf9afb2a9c3d4759"
            },
            {
                "account_id": "0x16a6",
                "service_flag": "0x3",
                "data": "0x5302a41d95fc7b194c59154fd6ed8dde9e7c7430a0000000000000000000000000000000f01d184fb606a51b82cb8f46bf9afb2a9c3d475900000000000000000000000006e4cc6bf8096b78cdc1eafd7cef73e6ee58c09a000000000000000000000000000000000000000000000000000009184e72a000000000000000000000000000352d09567de5a02415670723d09e006f623fe62e00000000000000000000000000000000000000000000000000000005e6c2a72101000000298637f684da70674f26509b10f07ec2fbc77a335ab1e7d6215a4b2484d8bb52"
            },
            {
                "account_id": "0x169e",
                "service_flag": "0x3",
                "data": "0x5c68bdbba7151c486facb66dc39b891030e46725400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000aaeba0ac2c5b43fbc365d8a0542e037a5903000000a5edc6018860a4e61a451543fc6d882fcfa5aed343e77f66841c8775671bb1d6000000000000000000000000352d09567de5a02415670723d09e006f623fe62e000000000000000000000000f01d184fb606a51b82cb8f46bf9afb2a9c3d4759"
            },
            {
                "account_id": "0x169e",
                "service_flag": "0x3",
                "data": "0x5c68bdbba7151c486facb66dc39b891030e4672540000000000000000000000000000000000000000000000000000000000a54d1e69799ca000000000000000000000000000000aaeba0ac2c5b43fbc365d8a0542e037a5903000000a5edc6018860a4e61a451543fc6d882fcfa5aed343e77f66841c8775671bb1d6000000000000000000000000352d09567de5a02415670723d09e006f623fe62e000000000000000000000000caebe8353b11b23546ad51ec7a51bf3f673e47dc"
            },
            {
                "account_id": "0x16a5",
                "service_flag": "0x3",
                "data": "0x352d09567de5a02415670723d09e006f623fe62e2000000000000000000000000000000000000000000000000000000000000005a0d1584803000000ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef000000000000000000000000f01d184fb606a51b82cb8f46bf9afb2a9c3d4759000000000000000000000000caebe8353b11b23546ad51ec7a51bf3f673e47dc"
            },
            {
                "account_id": "0x169e",
                "service_flag": "0x3",
                "data": "0x5c68bdbba7151c486facb66dc39b891030e46725400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000aaeba0ac2c5b43fbc365d8a0542e037a5903000000a5edc6018860a4e61a451543fc6d882fcfa5aed343e77f66841c8775671bb1d6000000000000000000000000352d09567de5a02415670723d09e006f623fe62e000000000000000000000000f01d184fb606a51b82cb8f46bf9afb2a9c3d4759"
            },
            {
                "account_id": "0x169e",
                "service_flag": "0x3",
                "data": "0x5c68bdbba7151c486facb66dc39b891030e46725400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000aaeba0ac2c5b43fbc365d8a0542e037a5903000000a5edc6018860a4e61a451543fc6d882fcfa5aed343e77f66841c8775671bb1d6000000000000000000000000352d09567de5a02415670723d09e006f623fe62e000000000000000000000000350b2bec5872df6eca63fd8729d9a5885d192c52"
            },
            {
                "account_id": "0x16a5",
                "service_flag": "0x3",
                "data": "0x352d09567de5a02415670723d09e006f623fe62e200000000000000000000000000000000000000000000000000000000000000045f14ed903000000ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef000000000000000000000000f01d184fb606a51b82cb8f46bf9afb2a9c3d4759000000000000000000000000350b2bec5872df6eca63fd8729d9a5885d192c52"
            },
            {
                "account_id": "0x285a",
                "service_flag": "0x3",
                "data": "0xf01d184fb606a51b82cb8f46bf9afb2a9c3d4759c0000000000000000000000000000000caebe8353b11b23546ad51ec7a51bf3f673e47dc00000000000000000000000006e4cc6bf8096b78cdc1eafd7cef73e6ee58c09a000000000000000000000000000000000000000000000000000009184e72a000000000000000000000000000352d09567de5a02415670723d09e006f623fe62e0000000000000000000000000000000000000000000000000000000045f14ed900000000000000000000000000000000000000000000000000000005a0d1584801000000d71542567e4876e606f2a1dc04c1b26f3cf39cb975eb0a65aef3c98842410583"
            },
            {
                "account_id": "0x285a",
                "service_flag": "0x2",
                "data": "0xce1d1a0000000000ce1d1a0000000000000000000000000000000000000000000000000000000000"
            },
            {
                "account_id": "0x1",
                "service_flag": "0x1",
                "data": "0x0200000014000000caebe8353b11b23546ad51ec7a51bf3f673e47dc0200000014000000b8cde090e6a4741b6450308fad1dc338c53936a000802c2a863c2a91050000000000000000000000000000000000000000000000"
            }
        ],
        "exit_code": 0,
        "cycles": {
            "execution": "0xc432729",
            "virtual": "0x0",
            "total": "0xc432729"
        },
        "read_data_hashes": [
            "0x77f63503c40c2e45d9f71791dfab5b5c060a05c64873386156489443b5d02aa5",
            "0x7f35a5a94f2e153ad28ee8af49ad39bb13ab2e5d6814008782bcb509febad861",
            "0xde4542f5a5bd32c09cd98e9752281f88900a059aab7ac103edd9df214f136c52",
            "0x2591631201346ca259fdb1cac65d123fd8913982af9f2602d8a210ee06567efb",
            "0x6e08aed670359c43fb7ef3d8214955da04f3ee79ca61df0f09544be38e60fd0a",
            "0x9662e1ac327d5cfb4b34ccb2c35c30baeb6db99ead6ebb3a7429b33dbb067854",
            "0x656082f83e5d3d9f6c84a40e9b1b15f3ba24002e2f392cfef78f960dd88c6921",
            "0x8e0b4a159fa3821fd700245ce10316cf460721d937357fb5098c31dd4aebc580",
            "0x4ae6d28af9eb705ee8daf3c36d313d319d8d59fc4ba9d7a2c380221c4600751c",
            "0x32e0d592a4fff03b6890c8cafdb40d4aaa066c00929ffdbddf59f193e287a9ec",
            "0x0652fd54fc9e4174d119815fc5525ab755d631de0b05ee9eef11c3d9cf6dff64"
        ],
        "write_data_hashes": [],
        "debug_log": [
            "",
            "v1.4.5",
            "BEGIN parse_message()",
            "args_len => 184",
            "[call_kind] => 0",
            "[gas_limit] => 5739566",
            "[gas_price] => 60000000000000",
            "[input_size] => 132",
            "END parse_message()",
            "load_account_script, account_id: => 10330",
            "load_account_script, account_id: => 4",
            "chain_id => 71402",
            "creator_account_id => 4",
            "g_rollup_script_hash 0x1ca35cb5fda4bd542e71d94a6d5f4c0d255d6d6fba73c41cf45d2693e59b3072",
            "g_sudt_id => 1",
            "[run_polyjuice] initial gas limit => 5739566",
            "load_account_script, account_id: => 10330",
            "[load_account_code] account_id => 10330",
...
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants