Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to get bridged eth and ERC20 tokens on child chain #210

Closed
leovct opened this issue Nov 13, 2023 · 5 comments
Closed

Unable to get bridged eth and ERC20 tokens on child chain #210

leovct opened this issue Nov 13, 2023 · 5 comments

Comments

@leovct
Copy link
Contributor

leovct commented Nov 13, 2023

Description

Hi, I'm currently playing with the docker PoS setup and I'm trying to bridge ERC20 tokens but I'm running into an issue that I have no idea how to solve.

Here are the steps to reproduce my problem. Hopefully, you'll see the thing that's missing! 🙏

  • Set up the devnet config.
  • Spin up the different container.
  • Approve the DepositManagerProxy to use TestToken on behalf of node0.
  • Bridge TestToken from root chain to child chain using node0 private key.
  • Get number of state syncs. It is incrementing, everything looks good!
  • But I don't have any ERC20 token on L2...
  • I can see that's there are failures in Bor logs so it must be related to that.
INFO [11-13|15:43:43.010] "→ committing new state"                 eventRecord=2
ERROR[11-13|15:43:43.010] message execution failed on contract     msgData=0xf28a80

Commands

Get contract addresses.

$ cat matic-cli/devnet/code/contracts/contractAddresses.json  | jq
{
  "root": {
    "Registry": "0xB39aA4E9646Fd9C50ee8C871Fe345569C4D5D04A",
    "RootChain": "0x67D07acbA0389ECF514eF8B43dFE4D8f6dDBB5d2",
    "GovernanceProxy": "0x0e63099e1420C7a3BF8C226730eEDc6C2d1A1704",
    "RootChainProxy": "0xBa1F4D93D62c24dAE67c33F9Cd1bECaa2d46dD5B",
    "DepositManager": "0x5Bc2B859D594e136A0552e7BDF2dF3867424Cce7",
    "DepositManagerProxy": "0x4A356C9CAeDfefE43c144419487e06c04296bf69",
    "WithdrawManager": "0x765fd35DBbDff1dd36e422C76Fa37a6F55A4687d",
    "WithdrawManagerProxy": "0x50415F3215599Bd6B92bA68cea61b46A15022F59",
    "StakeManager": "0x09F8d80E3d162CD8CBbD494633b9D3eD75bDF36e",
    "StakeManagerProxy": "0x9Db18c0C0384c2986F70e8B109a564129599Ce23",
    "SlashingManager": "0xF67b5A1A85b4e50F594d450dB2a2f2FCfD24DEF0",
    "StakingInfo": "0xcC589091De6aE35b53dF660A347c3887E6C94461",
    "ExitNFT": "0x29A4a587c0642B1234b2918Fb37Ca06270D1a1CF",
    "StateSender": "0xF88d3899fD32f0531E100d258160738145379E14",
    "predicates": {
      "ERC20Predicate": "0x25405947a3bD2BD7767C2Cf8124F315883fD7111",
      "ERC721Predicate": "0xBe710e1C3F7F4c7E295A4686d1d6478512238EA4",
      "MarketplacePredicate": "0xe3c38Ab717c4e489C602196Cc2902F7AfeD3765D",
      "TransferWithSigPredicate": "0x497506B0Be50dcD034b03D6565fc0A39EC513092"
    },
    "tokens": {
      "MaticToken": "0x4b7FF52bbe91CF6A743D428D84F38162ea3a1310",
      "MaticWeth": "0xc888E865D9067E2c44672Fa50bE2B77a781528EC",
      "TestToken": "0x2DDAB92De80d1D9D7e89fA49429F88d47d7222Bc",
      "RootERC721": "0xe80F298C455A5aD3EbB8B6ab602A336a43C958A7"
    }
  },
  "child": {
    "ChildChain": "0x680C2C3f42213FA92868b80E0aCb6430850186CE",
    "tokens": {
      "MaticWeth": "0xd30123F2B51a9C043755cAF07a833124933B1edb",
      "MaticToken": "0x0000000000000000000000000000000000001010",
      "TestToken": "0xe249c8135a138fF48C8b79Ef7ABe8c0C902cC298",
      "RootERC721": "0x43e5D5380B8D5FA8aA1fe67D0C3F33D5B0FcE26b"
    }
  }
}

Get node0 address and private key.

$ cat matic-cli/devnet/devnet/node0/bor/address.txt
0x2Bd3C50030325a0587f6c9AE3d3Aa5C2b14b72E6

$ cat matic-cli/devnet/devnet/node0/bor/privatekey.txt
0x2bf046c818b06eca93f25dcb08ff89658bd1acd54c43d6e1fffe78c9332fd50a

Get node0 balance of TestToken.

# on root chain
$ cast call --rpc-url http://localhost:9545 0x2DDAB92De80d1D9D7e89fA49429F88d47d7222Bc "balanceOf(address)(uint256)" 0x2Bd3C50030325a0587f6c9AE3d3Aa5C2b14b72E6
10000000000000000000000000000 [1e28]

# on child chain
$ cast call --rpc-url http://localhost:8545 0xe249c8135a138fF48C8b79Ef7ABe8c0C902cC298 "balanceOf(address)(uint256)" 0x2Bd3C50030325a0587f6c9AE3d3Aa5C2b14b72E6
0

Approve the DepositManagerProxy to use TestToken on behalf of node0.

$ cast send --legacy --rpc-url http://localhost:9545 --private-key "2bf046c818b06eca93f25dcb08ff89658bd1acd54c43d6e1fffe78c9332fd50a" \
    0x2DDAB92De80d1D9D7e89fA49429F88d47d7222Bc "approve(address,uint256)(bool)" 0x4A356C9CAeDfefE43c144419487e06c04296bf69 1000

Bridge TestToken from root chain to child chain using node0 private key.

$ cast send --legacy --rpc-url http://localhost:9545 --private-key "2bf046c818b06eca93f25dcb08ff89658bd1acd54c43d6e1fffe78c9332fd50a" \
    0x4A356C9CAeDfefE43c144419487e06c04296bf69 "depositERC20(address,uint256)" 0x2DDAB92De80d1D9D7e89fA49429F88d47d7222Bc 10

Same thing when trying to bridge native eth.

$ cast send --legacy --rpc-url http://localhost:9545 --private-key "2bf046c818b06eca93f25dcb08ff89658bd1acd54c43d6e1fffe78c9332fd50a" \
  --value "2ether" 0x4A356C9CAeDfefE43c144419487e06c04296bf69
...

Get number of state syncs.

$ cast call --rpc-url http://localhost:9545 0xF88d3899fD32f0531E100d258160738145379E14 "counter()(uint256)"
2

Extract of bor logs.

INFO [11-13|15:43:43.003] Fetching state updates from Heimdall     fromID=1 to=2023-11-13T15:41:35Z
INFO [11-13|15:43:43.004] Fetching state sync events               queryParams="from-id=1&to-time=1699890095&limit=50"
INFO [11-13|15:43:43.008] "→ committing new state"                 eventRecord=1
INFO [11-13|15:43:43.009] "→ committing new state"                 eventRecord=1
ERROR[11-13|15:43:43.009] message execution failed on contract     msgData=0xf28a80
INFO [11-13|15:43:43.009] "→ committed new state"                  eventRecord="id 1, contract 0x680C2C3f42213FA92868b80E0aCb6430850186CE, data: 0x0000000000000000000000002bd3c50030325a0587f6c9ae3d3aa5c2b14b72e60000000000000000000000002ddab92de80d1d9d7e89fa49429f88d47d7222bc000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000013881, txHash: 0x959afcc05f1365ee0fd347e4650986368f2d4f37fd03c2f97d233966926cd059, logIndex: 2, chainId: 15005, time 2023-11-13T15:39:54Z, gasUsed 71304"
INFO [11-13|15:43:43.009] "→ committing new state"                 eventRecord=2
ERROR[11-13|15:43:43.010] message execution failed on contract     msgData=0xf28a80
INFO [11-13|15:43:43.010] "→ committed new state"                  eventRecord="id 1, contract 0x680C2C3f42213FA92868b80E0aCb6430850186CE, data: 0x0000000000000000000000002bd3c50030325a0587f6c9ae3d3aa5c2b14b72e60000000000000000000000002ddab92de80d1d9d7e89fa49429f88d47d7222bc000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000013881, txHash: 0x959afcc05f1365ee0fd347e4650986368f2d4f37fd03c2f97d233966926cd059, logIndex: 2, chainId: 15005, time 2023-11-13T15:39:54Z, gasUsed 71304"
INFO [11-13|15:43:43.010] "→ committing new state"                 eventRecord=2
ERROR[11-13|15:43:43.010] message execution failed on contract     msgData=0xf28a80
INFO [11-13|15:43:43.010] "→ committed new state"                  eventRecord="id 2, contract 0x680C2C3f42213FA92868b80E0aCb6430850186CE, data: 0x0000000000000000000000002bd3c50030325a0587f6c9ae3d3aa5c2b14b72e60000000000000000000000002ddab92de80d1d9d7e89fa49429f88d47d7222bc000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000015f91, txHash: 0x9a48ad6edaff441dc0c1e5c6070f874dac15e1011a4f86d1de876e668f41847a, logIndex: 2, chainId: 15005, time 2023-11-13T15:40:54Z, gasUsed 46904"
INFO [11-13|15:43:43.010] StateSyncData                            gas=118,208 number=2304 lastStateID=2 "total records"=2 "fetch time"=5  "process time"=1
ERROR[11-13|15:43:43.010] message execution failed on contract     msgData=0xf28a80
INFO [11-13|15:43:43.010] "→ committed new state"                  eventRecord="id 2, contract 0x680C2C3f42213FA92868b80E0aCb6430850186CE, data: 0x0000000000000000000000002bd3c50030325a0587f6c9ae3d3aa5c2b14b72e60000000000000000000000002ddab92de80d1d9d7e89fa49429f88d47d7222bc000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000015f91, txHash: 0x9a48ad6edaff441dc0c1e5c6070f874dac15e1011a4f86d1de876e668f41847a, logIndex: 2, chainId: 15005, time 2023-11-13T15:40:54Z, gasUsed 46904"
INFO [11-13|15:43:43.010] StateSyncData                            gas=118,208 number=2304 lastStateID=2 "total records"=2 "fetch time"=4  "process time"=2
@marcello33
Copy link
Contributor

Hey @leovct

I think this is related to smart contract methods reverting
You can have a look on how the contracts team achieved something similar in their on scripts here
When you deploy the devnet, those scripts are available on node0/matic-cli/devnet/code/contracts/scripts (iirc) so you can try to use those.

On a side note you can get the state-sync data with the --monitor command

@leovct
Copy link
Contributor Author

leovct commented Nov 14, 2023

Thanks for the pointers. Unfortunately, I'm also able to reproduce the issue using the contracts team script. I'll check with them then.

Bridge ERC20 tokens using scripts/deposit.js.

$ npm run truffle exec scripts/deposit.js -- network development 0x2DDAB92De80d1D9D7e89fA49429F88d47d7222Bc 10

> [email protected] truffle
> truffle

Using network 'development'.

Contract addresses:  {
  root: {
    Registry: '0xB39aA4E9646Fd9C50ee8C871Fe345569C4D5D04A',
    RootChain: '0x67D07acbA0389ECF514eF8B43dFE4D8f6dDBB5d2',
    GovernanceProxy: '0x0e63099e1420C7a3BF8C226730eEDc6C2d1A1704',
    RootChainProxy: '0xBa1F4D93D62c24dAE67c33F9Cd1bECaa2d46dD5B',
    DepositManager: '0x5Bc2B859D594e136A0552e7BDF2dF3867424Cce7',
    DepositManagerProxy: '0x4A356C9CAeDfefE43c144419487e06c04296bf69',
    WithdrawManager: '0x765fd35DBbDff1dd36e422C76Fa37a6F55A4687d',
    WithdrawManagerProxy: '0x50415F3215599Bd6B92bA68cea61b46A15022F59',
    StakeManager: '0x09F8d80E3d162CD8CBbD494633b9D3eD75bDF36e',
    StakeManagerProxy: '0x9Db18c0C0384c2986F70e8B109a564129599Ce23',
    SlashingManager: '0xF67b5A1A85b4e50F594d450dB2a2f2FCfD24DEF0',
    StakingInfo: '0xcC589091De6aE35b53dF660A347c3887E6C94461',
    ExitNFT: '0x29A4a587c0642B1234b2918Fb37Ca06270D1a1CF',
    StateSender: '0xF88d3899fD32f0531E100d258160738145379E14',
    predicates: {
      ERC20Predicate: '0x25405947a3bD2BD7767C2Cf8124F315883fD7111',
      ERC721Predicate: '0xBe710e1C3F7F4c7E295A4686d1d6478512238EA4',
      MarketplacePredicate: '0xe3c38Ab717c4e489C602196Cc2902F7AfeD3765D',
      TransferWithSigPredicate: '0x497506B0Be50dcD034b03D6565fc0A39EC513092'
    },
    tokens: {
      MaticToken: '0x4b7FF52bbe91CF6A743D428D84F38162ea3a1310',
      MaticWeth: '0xc888E865D9067E2c44672Fa50bE2B77a781528EC',
      TestToken: '0x2DDAB92De80d1D9D7e89fA49429F88d47d7222Bc',
      RootERC721: '0xe80F298C455A5aD3EbB8B6ab602A336a43C958A7'
    }
  },
  child: {
    ChildChain: '0x680C2C3f42213FA92868b80E0aCb6430850186CE',
    tokens: {
      MaticWeth: '0xd30123F2B51a9C043755cAF07a833124933B1edb',
      MaticToken: '0x0000000000000000000000000000000000001010',
      TestToken: '0xe249c8135a138fF48C8b79Ef7ABe8c0C902cC298',
      RootERC721: '0x43e5D5380B8D5FA8aA1fe67D0C3F33D5B0FcE26b'
    }
  }
}
[
  '/home/ubuntu/.nvm/versions/node/v16.17.1/bin/node',
  '/home/ubuntu/matic-cli/devnet/code/contracts/node_modules/.bin/truffle',
  'exec',
  'scripts/deposit.js',
  'network',
  'development',
  '0x2DDAB92De80d1D9D7e89fA49429F88d47d7222Bc',
  '10'
]
Current configured address to make transactions: 0x2Bd3C50030325a0587f6c9AE3d3Aa5C2b14b72E6
Deposit ERC20:
   Token:   0x2DDAB92De80d1D9D7e89fA49429F88d47d7222Bc
   Amount:  10
Balance for current address: 9999999999999999999999999960
Approved tokens transfer with tx: 0x2454c25c8abc24ae99fd40517488e4f4dad65690019121db9c51cdd69152e614
Deposit tokens with tx: 0x7f27f24e60f04bb5cf34bcff40dd98526f1a24c68edd16c6187ba3c0e65f1724

State sync event happening

$ cast call --rpc-url http://localhost:9545 0xF88d3899fD32f0531E100d258160738145379E14 "counter()(uint256)"
5

Extract of bor logs failing when processing state sync data.

INFO [11-14|10:13:03.003] Fetching state sync events               queryParams="from-id=5&to-time=1699956655&limit=50"
INFO [11-14|10:13:03.012] "→ committing new state"                 eventRecord=5
ERROR[11-14|10:13:03.013] message execution failed on contract     msgData=0xf28a80
INFO [11-14|10:13:03.013] "→ committed new state"                  eventRecord="id 5, contract 0x680C2C3f42213FA92868b80E0aCb6430850186CE, data: 0x0000000000000000000000002bd3c50030325a0587f6c9ae3d3aa5c2b14b72e60000000000000000000000002ddab92de80d1d9d7e89fa49429f88d47d7222bc000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000001535b1, txHash: 0x7f27f24e60f04bb5cf34bcff40dd98526f1a24c68edd16c6187ba3c0e65f1724, logIndex: 2, chainId: 15005, time 2023-11-14T10:10:52Z, gasUsed 54204"
INFO [11-14|10:13:03.013] StateSyncData                            gas=54204   number=35584 lastStateID=5 "total records"=1 "fetch time"=8  "process time"=1
INFO [11-14|10:13:03.015] "→ committing new state"                 eventRecord=5
INFO [11-14|10:13:03.016] Imported new chain segment               number=35584 hash=03d89f..00cf92 blocks=1  txs=0 mgas=0.000 elapsed=13.457ms    mgasps=0.000   dirty=34.55KiB
ERROR[11-14|10:13:03.020] message execution failed on contract     msgData=0xf28a80
INFO [11-14|10:13:03.020] "→ committed new state"                  eventRecord="id 5, contract 0x680C2C3f42213FA92868b80E0aCb6430850186CE, data: 0x0000000000000000000000002bd3c50030325a0587f6c9ae3d3aa5c2b14b72e60000000000000000000000002ddab92de80d1d9d7e89fa49429f88d47d7222bc000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000001535b1, txHash: 0x7f27f24e60f04bb5cf34bcff40dd98526f1a24c68edd16c6187ba3c0e65f1724, logIndex: 2, chainId: 15005, time 2023-11-14T10:10:52Z, gasUsed 54204"
INFO [11-14|10:13:03.020] StateSyncData                            gas=54204   number=35584 lastStateID=5 "total records"=1 "fetch time"=12 "process time"=5

@marcello33
Copy link
Contributor

Ok thanks @leovct and please keep me posted on the outcome.
If there's any change needed in matic-cli, I'd like to keep it updated.

@leovct leovct changed the title Unable to get bridged ERC20 tokens on child chain Unable to get bridged eth and ERC20 tokens on child chain Nov 16, 2023
@leovct
Copy link
Contributor Author

leovct commented Nov 27, 2023

@marcello33 I sent a PR to update the deploy_child_contract migration script in maticnetwork/contracts. It fixes the issue when bridging eth/ERC20/ERC721 tokens and not receiving anything on L2 because of a revert. I tested it against my setup and also matic-cli setup and it works fine.

@marcello33
Copy link
Contributor

That's great, thanks @leovct for taking this up.
Would you please assign the contracts PR to someone in the smart-contracts team? So that we can merge and get matic-cli fixed out of the box :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants