godwoken icon indicating copy to clipboard operation
godwoken copied to clipboard

Testnet. Contract is deployed, but can't interact with it. Getting error on every call

Open knerushkin-rumblefish opened this issue 1 year ago • 11 comments

Testnet Address: 0xc1fe7F78698BD9aA3802AEC6E43D8aAEa9d9Dbaf https://v1.testnet.gwscan.com/account/0xcf0a93789fe2740d6a6a28079719695eb8383792a53db177d94fac634ab85aa7?tab=events

This contract should be visible as Token, but in fact it's pool. Contract is quite big No problems with local ganache deployment and contract call's

knerushkin-rumblefish avatar Aug 26 '22 11:08 knerushkin-rumblefish

How can I debug it?

knerushkin-rumblefish avatar Aug 26 '22 11:08 knerushkin-rumblefish

Simiar contract, but different type of pool is operating OK, also visible as token on gwscan Testnet Address: 0xb79c38BbBeB57FC3f9b4Cb56c84fa9458f60B14b https://v1.testnet.gwscan.com/account/0x74f658e89a8c8af15e9202e7af3fb32c26b7888de6234fe9f5cc12bad2262c6a?tab=transactions

knerushkin-rumblefish avatar Aug 26 '22 11:08 knerushkin-rumblefish

For the failing cantract simple .symbol() call is already failing

knerushkin-rumblefish avatar Aug 26 '22 11:08 knerushkin-rumblefish

Looks like problem with library linking

knerushkin-rumblefish avatar Aug 26 '22 12:08 knerushkin-rumblefish

How can I debug it?

Godwoken-Kicker could help you to debug your contract on a local devnet. I think you may get more useful logs while debugging.

Flouse avatar Aug 27 '22 02:08 Flouse

web3_1                            | [1] 2022-08-29T09:09:09.430Z [debug]: [ethAddressToScriptHash] using cache: 0xabfb1a497faa51b667aa2baca2c768255cb1725c -> 0xfd9d52579b8cb89d899f6b310d6ecb9011d39d107f8ef81bd0340579568ae81c
web3_1                            | [1] 2022-08-29T09:09:09.431Z [debug]: fromId: 5
web3_1                            | [1] 2022-08-29T09:09:09.432Z [debug]: [ethAddressToScriptHash] using cache: 0x169260f3281b8987f51078fa10224d9f2e6c9dd2 -> 0x69b1a150fdd755b58f72bcd54ee83c0b35b28ce08b59a6b63abac88129470e30
web3_1                            | [1] 2022-08-29T09:09:09.433Z [debug]: rawL2Transaction: {
web3_1                            | [1]   "chain_id": "0x116e8",
web3_1                            | [1]   "from_id": "0x5",
web3_1                            | [1]   "to_id": "0x53",
web3_1                            | [1]   "nonce": "0x0",
web3_1                            | [1]   "args": "0xffffff504f4c5900983da800000000000000000000000000000000000000000000000000000000000000000000000000a4000000e098e844000000000000000000000000abfb1a497faa51b667aa2baca2c768255cb1725c0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000200000000000000000000000063c87d79978557f6412a73482375000898b0b339000000000000000000000000e212a507c1f1bf2edb2b8ec1c8c25112a2b4fc38"
web3_1                            | [1] }
web3_1                            | [1] 2022-08-29T09:09:09.443Z [debug]: RunResult: {
web3_1                            | [1]   return_data: '0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
web3_1                            | [1]   logs: [
web3_1                            | [1]     {
web3_1                            | [1]       account_id: '0x53',
web3_1                            | [1]       service_flag: '0x2',
web3_1                            | [1]       data: '0x591e000000000000591e000000000000000000000000000000000000000000000000000000000000'
web3_1                            | [1]     },
web3_1                            | [1]     {
web3_1                            | [1]       account_id: '0x1',
web3_1                            | [1]       service_flag: '0x1',
web3_1                            | [1]       data: '0x0200000014000000abfb1a497faa51b667aa2baca2c768255cb1725c02000000140000002e9df163055245bfadd35e3a1f05f06096447c850000000000000000000000000000000000000000000000000000000000000000'
web3_1                            | [1]     }
web3_1                            | [1]   ]
web3_1                            | [1] }
web3_1                            | [1] 2022-08-29T09:09:09.444Z [info]: POST / 200 15ms @eth_call
web3_1                            | [1] 2022-08-29T09:09:09.454Z [info]: POST / 200 0ms @eth_chainId
web3_1                            | [1] 2022-08-29T09:09:09.457Z [debug]: [ethAddressToScriptHash] using cache: 0xabfb1a497faa51b667aa2baca2c768255cb1725c -> 0xfd9d52579b8cb89d899f6b310d6ecb9011d39d107f8ef81bd0340579568ae81c
web3_1                            | [1] 2022-08-29T09:09:09.458Z [debug]: fromId: 5
web3_1                            | [1] 2022-08-29T09:09:09.458Z [debug]: [ethAddressToScriptHash] using cache: 0x20cc3934e63cff4d23ea5ce89914baf1784acca7 -> 0x82e64b5381b47ad1a7c8ddf1f6969ac87a5934cb87054ab1371082beee175416
web3_1                            | [1] 2022-08-29T09:09:09.459Z [debug]: rawL2Transaction: {
web3_1                            | [1]   "chain_id": "0x116e8",
web3_1                            | [1]   "from_id": "0x5",
web3_1                            | [1]   "to_id": "0x69",
web3_1                            | [1]   "nonce": "0x0",
web3_1                            | [1]   "args": "0xffffff504f4c5900d82ba8000000000000000000000000000000000000000000000000000000000000000000000000000400000095d89b41"
web3_1                            | [1] }

web3_1                            | [1] 2022-08-29T09:09:09.462Z [info]: Call gw rpc "gw_execute_raw_l2transaction" error: JSONRPCError: server error {"code":-32600,"message":"invalid exit code 50","data":{"tx_hash":"0x42e069878d72d8da77263c4a16fc822fd169da60d422e44a342a3e8241ed93d2","block_number":"0x8fb5","return_data":"0x","last_log":{"account_id":"0x69","service_flag":"0x2","data":"0xd82ba80000000000d82ba80000000000000000000000000000000000000000000000000001000000"},"exit_code":"0x32"}}

knerushkin-rumblefish avatar Aug 29 '22 09:08 knerushkin-rumblefish

Can you provide a binary format of transaction that send to the testnet? The exit code 50 means the transaction triggered some fatal error of the VM.

If you add an environment variableRUST_LOG=info, gw_generator=debug to godwoken, you can see some trace output of the execution.

jjyr avatar Aug 31 '22 03:08 jjyr

@knerushkin-rumblefish If you could create a private repo and share the Solidity code with us, we can debug it directly too.

Flouse avatar Aug 31 '22 10:08 Flouse

Can you provide the return data of the transaction(you can run it on ganache)? The returned data of transaction is stored in a buffer, I suspect the error is caused because the return data is larger than the buffer.

jjyr avatar Aug 31 '22 12:08 jjyr

Thanks guys, I'm already preparing reproduction

knerushkin-rumblefish avatar Aug 31 '22 13:08 knerushkin-rumblefish

@knerushkin-rumblefish When you debug with kicker, here is how to get debug logs:

./kicker start
./kicker logs -f godwoken ## you will find contract logs here
### you deploy your contract and then send a tx

Kicker prints out verbose logs of the contract in default. You will find something like below:

[2022-09-01T07:33:56Z DEBUG gw_generator::backend_manage] get_aot_code hash: c4ab3c7a1db04c20869eee3aa70e661f3e28132344baa9880a14bdb7b79c741f version: 0
[2022-09-01T07:33:56Z DEBUG gw_generator::generator] [contract debug]:
    v1.3.0
    BEGIN parse_message()
    args_len => 29486
    [call_kind] => 3
    [gas_limit] => 1000000
    [gas_price] => 1
    [input_size] => 29434
    END parse_message()
    load_account_script, account_id: => 3
    chain_id => 202204
    creator_account_id => 3
    g_rollup_script_hash 0xa9a9a9a9a9a9a9a9a9a9a9a9a9a9a9a9a9a9a9a9a9a9a9a9a9a9a9a9a9a9a9a9
    g_sudt_id => 1
    [run_polyjuice] initial gas limit => 1000000
    [create_new_account] msg->kind == EVMC_CREATE
    sender 0x0101010101010101010101010101010101010101
    from_id => 5
    nonce => 0
    script.hash_type => 1
    >> new to id => 6
    [handle_transfer] sender 0x0101010101010101010101010101010101010101
    [handle_transfer] destination 0x1c81a61a407017c58397a47d2ab28191b9b8ec9b
    [handle_transfer] msg->value 0x0000000000000000000000000000000000000000000000000000000000000000
    [handle_message] msg.kind => 3
    [execute_in_evmone] code size => 29434
    [execute_in_evmone] input_size => 0
    BEGIN store data key
    code_data_hash 0xdc23e094701f4a04ab16a782b472e078624233e21b21fa3ac89cf298f5c66628
    BEGIN store data
    contract_code_len => 29401
    END store data
    [run_polyjuice] gas left => 539114
    [run_polyjuice] gas_used => 460886
    set return data failed
[2022-09-01T07:33:56Z DEBUG gw_generator::generator] [execute tx] VM machine_run time: 7ms, exit code: 50 used_cycles: 3951992
[2022-09-01T07:33:56Z DEBUG gw_generator::traits] account: 0x0101010101010101010101010101010101010101 pay fee to block_producer: 0xa1ad227ad369f593b5f3d0cc934a681a50811cb2, sudt_id: 1, amount: 460886
code size: 29434, exit code: 50

Those logs help us understand what's going on in your case. If you are stuck in any place, feel free to tell us.

magicalne avatar Sep 01 '22 07:09 magicalne

Repro https://github.com/knerushkin-rumblefish/split-code-repro-error

Deployment: Hardhat vs Godwoken Testnet

knerushkin-rumblefish avatar Sep 06 '22 08:09 knerushkin-rumblefish

Well, there is a hard limit for the size of the smart contract, which is 24kb. See here. So no one can deploy a contract that is larger than 24kb. BTW, polyjuice is the EVM layer of godwoken. There's quite a lot to consume for your code repo. Can you try to make your contracts smaller than 24kb?

magicalne avatar Sep 06 '22 09:09 magicalne

@magicalne Ok, so that mean that this trick with deployment more than 24 from chain do not gonna work on godwoken-polyjuice So, it work's for smaller contracts because contract size was still less than 24 The only solution is to reduce size of contract

knerushkin-rumblefish avatar Sep 06 '22 12:09 knerushkin-rumblefish

Basically there is first case which is working with less than 24 kb of size

knerushkin-rumblefish avatar Sep 06 '22 12:09 knerushkin-rumblefish

Let me make some research first. Maybe we can increase the limit.

magicalne avatar Sep 06 '22 13:09 magicalne

I'm currently getting rid of on chain code splitting, and refactor it onto Minimal Proxy Contract deployer. And also moving some static features to external library. So also gonna keep you updated Thanks for help

knerushkin-rumblefish avatar Sep 06 '22 13:09 knerushkin-rumblefish

Related issue

  • https://github.com/nervosnetwork/godwoken-polyjuice/issues/108#issuecomment-989479759

Flouse avatar Sep 06 '22 15:09 Flouse

@knerushkin-rumblefish I just tried your repo on geth. (Gas limit and price should be updated accordingly.) It turns out godwoken and geth both failed when deploying MetaStablePool because the size of the contract is larger than 24kb. So the hard limit remains.

I just notice that you comment on strict mode in your hardhat config:

  contractSizer: {
    runOnCompile: true,
    alphaSort: true,
    disambiguatePaths: false,
    // strict: true,
  },

Maybe we should keep it strict so that we can expect consistency between different networks.

magicalne avatar Sep 07 '22 12:09 magicalne

I did more research. I think Godwoken works correctly.

Balancer contract used in reproduction repo resulted in too big deployed bytecode.

Using contracts from this commit point results in correctly sized contracts of MetaStablePool: https://github.com/balancer-labs/balancer-v2-monorepo/commit/a0f5ba919485c7d9f611a1868a279979742644e2

e00dan avatar Sep 09 '22 08:09 e00dan