mantlenetworkio / mantle

Mantle | Mass adoption of decentralized & token-governed technologies. With Mantle Network, Mantle Treasury, and token holder-governed products initiatives.
https://www.mantle.xyz
MIT License
229 stars 101 forks source link

[sdk]: After obtaining proof using the Mantle SDK, it is necessary to wait for a period of time before successfully submitting the finalizeMessage transaction. #1076

Open agnarsong opened 1 year ago

agnarsong commented 1 year ago

Describe the bug A clear and concise description of what the bug is.

To Reproduce Steps to reproduce the behavior:

  1. had run Mantle localNetwork
  2. add log into Mantle'sdk cross-chain-messenger.ts
      console.log("======================")
      console.log("resolved.target: ", resolved.target)
      console.log("resolved.target: ", resolved.sender)
      console.log("resolved.target: ", resolved.message)
      console.log("resolved.target: ", resolved.messageNonce)
      console.log("prooft: ", proof)
      console.log("======================")
  3. add try&catch into finalize.ts

    let finalizeMessageResponse:any
    
    while (true) {
    try {
      finalizeMessageResponse = await crossChainMessenger.finalizeMessage(
        withdrawETHtx
      )
    
      if (finalizeMessageResponse.hash.length > 10){
        console.log("finalizeMessageResponse txHash: ", finalizeMessageResponse.hash)
        break;
      }
    } catch (error) {
      // const err1s = error.toString().split('error={"reason":"');
      // const err2s = err1s[1].split('"')
    
      // console.error('请求 finalizeMessage 异常:', err2s[0]);
      console.log(error)
      console.log("等待 10 秒后, 再次请求...");
      await wait(10);
      continue
    }
    }
  4. make test0_withdraw
  5. check log

Expected behavior

finalizeMessage is success

Screenshots It can be seen that the contents of the three newly added log outputs are consistent, although errors were encountered in the first two times: "Provided message could not be verified". However, the third time was able to successfully finalize the message.

Account test0 withdraw 0.01 mnt: 0x4c93c858bbd8d37896b68d13e9d4b6e70058742d7044d0e16512c51f2fa6e67b
====== finished withdraw ======
will finalizeMessage withdraw txHash: 0x9b9a266d25de81edc22618deef0687942cda8287b3d5c13d559fb6f7c58aa88a
等待通过 FRAUD_PROOF_WINDOW:  60 秒!
已等待 10 秒.
已等待 10 秒.
已等待 10 秒.
已等待 10 秒.
已等待 10 秒.
已等待 10 秒.
已等待 10 秒.
proof.stateRoot:   0xde4c0ea22f7c572124e82af8bf4fff0ce99c904d1ae9a8a356022b1fcfe43587
======================
resolved.target:  0x36fCf02Fc651c0b7ef2ECA446Dd2405364F85337
resolved.target:  0x4200000000000000000000000000000000000010
resolved.target:  0x1532ec3400000000000000000000000000000500e87ee83a1bfa233512af25a4003836c800000000000000000000000000000500e87ee83a1bfa233512af25a4003836c8000000000000000000000000000000000000000000000000002386f26fc1000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000000
resolved.target:  BigNumber { _hex: '0x0186b4', _isBigNumber: true }
prooft:  {
  stateRoot: '0xde4c0ea22f7c572124e82af8bf4fff0ce99c904d1ae9a8a356022b1fcfe43587',
  stateRootBatchHeader: {
    batchIndex: BigNumber { _hex: '0x2e', _isBigNumber: true },
    batchRoot: '0xb9b419da17ed8c946b58b403a7aa56dfed7f0fbfb87aee88e3e87490d706782c',
    batchSize: BigNumber { _hex: '0x03', _isBigNumber: true },
    prevTotalElements: BigNumber { _hex: '0x0f44', _isBigNumber: true },
    signature: '0xc01406422531924f079d2feeccf02d81feea144bc746d8dff3c1e47f21d07705724d805aa00ae5cb350e162f5405cbb37406ec4c5d5513c93f5dd0e5eed5d35a01',
    extraData: '0x00000000000000000000000000000000000000000000000000000000649322aa00000000000000000000000073b9f10e505c47aa99cdc90f28e0c0b7dda3bae6'
  },
  stateRootProof: {
    index: 2,
    siblings: [
      '0x290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e563',
      '0x9234733e2185e2172eb6387a896e80e77380b8180539270721fe72b07b872b42'
    ]
  },
  stateTrieWitness: '0xf90299b90174f9017180a0122383ce8e6ac6f06b585bf8f18ede3f450bd67e5ac868dd75010825e73b887ba042a5870394429bb448e10782b26902c392ba1eef4a8c6e74ac3ed68d1d244bd4a04dcaf9f2cc3919f604a0e356a944883f53b73f866455b5c865aefa5a91ef51d58080a03448e0dddf231ffe3398ccab073dbd57b10833b239b954fe4c0fea93ec8b080380a0551196e6b0d06141c7886e45f7f8e8b847a33bcf5628e1f3d95a2e43039f688ea03cfffaeaf1dbd43dac97801eeb70efa5741418f41957561e40e5a82c946006b9a0bada4ad7ec61ea9a89ed2aedee91596fece4d88c81335dc8dc679b9bad7433b6a0a11a77985883459544f1d4148499c48e8c3de24e8ef816beef42150743968cbd80a0da1ef8739c1f22e2146fabe7bba46385bc534ae5a9a5a7a2f66b23fc5ab0ce9aa00d7f720520fe51b119753304fe3a61ebb969345b65b4608b5242caa7177df4b2a0c60e32f6fabba6287fb161d58d20f41101c89bc9762f1b24f851f3b87a018ecf80b8b3f8b1a095f0713f64dd25ae223558ccf22f720bbf1c64908cb662e56e22c86c0d8490fe8080a09d912ffcc5b29ca9e8bd84964570ecf0355d8d9eb09fc86d635a80a6ef80697a8080a0dbe071016dcb971ff859fcba12703d3441713c2332117f9471cf47bf7ca24b2880a0ab41c6467d2ea19b9b24305436f18d2c48ac0711d6fdc47b9a674a9f3d825180a008def728e01f97127a2979c2e2757b960a446f96c443fa713a546562ce2ddae180808080808080b86bf869a020bd311b46a2440f3eaf346b6c1ce588ed08712591822a258c5a1c4cf44cd0c9b846f8448080a0bdfb3030b5bb35d7b73484de9749d6b7d7657a240cc1ea5ccd76f6fdc26835efa0b139321113538ffa52ef410f27f0b2bfabf1f2a467e066d5277df8dbc10769d9',
  storageTrieWitness: '0xf901dbb901b4f901b1a032462ae76c81f29a5ae42aaa61d128605e5050869f91e1b483154b69d58814f5a0131d0d5cc144daea3cbe58a82a0e56f16cabfd1c9e2073372b8b20a1afe68a84a01dcb46abf83478eb61768db45266cba54d8b21a36c34dd2effb8a50364481929a09d0f34287c600e38376f0474fde0c1674b7203ad7daae78cdaca98f30090177580a076b6b34f03c1b7b07c9edebf286a62f24111698a32db6288c629a50f356f4ab1a0719f668c9306121430750da7da8e3ee08c2ce3b170a36633f23230db9e171f1ea0bfcfb6815dc5b1f04fda9a6737ea8c6cf6f912faca5d3bcedf7b920355aa0a76a06935e8d949f0e8933875d3907ecda7e19afbc4d406e96c713fa3ef7dcbb6da54a0bae203969be29bbf8743b6e1b204c7c7bce7a81ea4f5d0033faa9b224befc366a0fc6364ea86a7bc858f20d1bb2e7be0423365cd2cc5e901ddb59b1db9421b300da055d2fd3d0290cf31aa04bbb5922d8e8320b3c38a586cbd0a911be1badcd172d8a0282f26df1ff51897ee2dacb1519e583bd8d180bb1e6d56081f603eaf575371b080a0c865d99c441080ab61cf6235255c40b29b1719b702b9a0a000ced623afc89e658080a3e2a0344a417741e2e94717669b013d7c0976a3e36c3b1ce19779d95ceddb7c45628601'
}
======================
<ref *1> Error: cannot estimate gas; transaction may fail or may require manual gas limit [ See: https://links.ethers.org/v5-errors-UNPREDICTABLE_GAS_LIMIT ] (error={"reason":"execution reverted: Provided message could not be verified.","code":"UNPREDICTABLE_GAS_LIMIT","method":"estimateGas","transaction":
.
.
.

等待 10 秒后, 再次请求...
======================
resolved.target:  0x36fCf02Fc651c0b7ef2ECA446Dd2405364F85337
resolved.target:  0x4200000000000000000000000000000000000010
resolved.target:  0x1532ec3400000000000000000000000000000500e87ee83a1bfa233512af25a4003836c800000000000000000000000000000500e87ee83a1bfa233512af25a4003836c8000000000000000000000000000000000000000000000000002386f26fc1000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000000
resolved.target:  BigNumber { _hex: '0x0186b4', _isBigNumber: true }
prooft:  {
  stateRoot: '0xde4c0ea22f7c572124e82af8bf4fff0ce99c904d1ae9a8a356022b1fcfe43587',
  stateRootBatchHeader: {
    batchIndex: BigNumber { _hex: '0x2e', _isBigNumber: true },
    batchRoot: '0xb9b419da17ed8c946b58b403a7aa56dfed7f0fbfb87aee88e3e87490d706782c',
    batchSize: BigNumber { _hex: '0x03', _isBigNumber: true },
    prevTotalElements: BigNumber { _hex: '0x0f44', _isBigNumber: true },
    signature: '0xc01406422531924f079d2feeccf02d81feea144bc746d8dff3c1e47f21d07705724d805aa00ae5cb350e162f5405cbb37406ec4c5d5513c93f5dd0e5eed5d35a01',
    extraData: '0x00000000000000000000000000000000000000000000000000000000649322aa00000000000000000000000073b9f10e505c47aa99cdc90f28e0c0b7dda3bae6'
  },
  stateRootProof: {
    index: 2,
    siblings: [
      '0x290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e563',
      '0x9234733e2185e2172eb6387a896e80e77380b8180539270721fe72b07b872b42'
    ]
  },
  stateTrieWitness: '0xf90299b90174f9017180a0122383ce8e6ac6f06b585bf8f18ede3f450bd67e5ac868dd75010825e73b887ba042a5870394429bb448e10782b26902c392ba1eef4a8c6e74ac3ed68d1d244bd4a04dcaf9f2cc3919f604a0e356a944883f53b73f866455b5c865aefa5a91ef51d58080a03448e0dddf231ffe3398ccab073dbd57b10833b239b954fe4c0fea93ec8b080380a0551196e6b0d06141c7886e45f7f8e8b847a33bcf5628e1f3d95a2e43039f688ea03cfffaeaf1dbd43dac97801eeb70efa5741418f41957561e40e5a82c946006b9a0bada4ad7ec61ea9a89ed2aedee91596fece4d88c81335dc8dc679b9bad7433b6a0a11a77985883459544f1d4148499c48e8c3de24e8ef816beef42150743968cbd80a0da1ef8739c1f22e2146fabe7bba46385bc534ae5a9a5a7a2f66b23fc5ab0ce9aa00d7f720520fe51b119753304fe3a61ebb969345b65b4608b5242caa7177df4b2a0c60e32f6fabba6287fb161d58d20f41101c89bc9762f1b24f851f3b87a018ecf80b8b3f8b1a095f0713f64dd25ae223558ccf22f720bbf1c64908cb662e56e22c86c0d8490fe8080a09d912ffcc5b29ca9e8bd84964570ecf0355d8d9eb09fc86d635a80a6ef80697a8080a0dbe071016dcb971ff859fcba12703d3441713c2332117f9471cf47bf7ca24b2880a0ab41c6467d2ea19b9b24305436f18d2c48ac0711d6fdc47b9a674a9f3d825180a008def728e01f97127a2979c2e2757b960a446f96c443fa713a546562ce2ddae180808080808080b86bf869a020bd311b46a2440f3eaf346b6c1ce588ed08712591822a258c5a1c4cf44cd0c9b846f8448080a0bdfb3030b5bb35d7b73484de9749d6b7d7657a240cc1ea5ccd76f6fdc26835efa0b139321113538ffa52ef410f27f0b2bfabf1f2a467e066d5277df8dbc10769d9',
  storageTrieWitness: '0xf901dbb901b4f901b1a032462ae76c81f29a5ae42aaa61d128605e5050869f91e1b483154b69d58814f5a0131d0d5cc144daea3cbe58a82a0e56f16cabfd1c9e2073372b8b20a1afe68a84a01dcb46abf83478eb61768db45266cba54d8b21a36c34dd2effb8a50364481929a09d0f34287c600e38376f0474fde0c1674b7203ad7daae78cdaca98f30090177580a076b6b34f03c1b7b07c9edebf286a62f24111698a32db6288c629a50f356f4ab1a0719f668c9306121430750da7da8e3ee08c2ce3b170a36633f23230db9e171f1ea0bfcfb6815dc5b1f04fda9a6737ea8c6cf6f912faca5d3bcedf7b920355aa0a76a06935e8d949f0e8933875d3907ecda7e19afbc4d406e96c713fa3ef7dcbb6da54a0bae203969be29bbf8743b6e1b204c7c7bce7a81ea4f5d0033faa9b224befc366a0fc6364ea86a7bc858f20d1bb2e7be0423365cd2cc5e901ddb59b1db9421b300da055d2fd3d0290cf31aa04bbb5922d8e8320b3c38a586cbd0a911be1badcd172d8a0282f26df1ff51897ee2dacb1519e583bd8d180bb1e6d56081f603eaf575371b080a0c865d99c441080ab61cf6235255c40b29b1719b702b9a0a000ced623afc89e658080a3e2a0344a417741e2e94717669b013d7c0976a3e36c3b1ce19779d95ceddb7c45628601'
}
======================
<ref *1> Error: cannot estimate gas; transaction may fail or may require manual gas limit [ See: https://links.ethers.org/v5-errors-UNPREDICTABLE_GAS_LIMIT ] (error={"reason":"execution reverted: Provided message could not be 
.
.
.

等待 10 秒后, 再次请求...
======================
resolved.target:  0x36fCf02Fc651c0b7ef2ECA446Dd2405364F85337
resolved.target:  0x4200000000000000000000000000000000000010
resolved.target:  0x1532ec3400000000000000000000000000000500e87ee83a1bfa233512af25a4003836c800000000000000000000000000000500e87ee83a1bfa233512af25a4003836c8000000000000000000000000000000000000000000000000002386f26fc1000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000000
resolved.target:  BigNumber { _hex: '0x0186b4', _isBigNumber: true }
prooft:  {
  stateRoot: '0xde4c0ea22f7c572124e82af8bf4fff0ce99c904d1ae9a8a356022b1fcfe43587',
  stateRootBatchHeader: {
    batchIndex: BigNumber { _hex: '0x2e', _isBigNumber: true },
    batchRoot: '0xb9b419da17ed8c946b58b403a7aa56dfed7f0fbfb87aee88e3e87490d706782c',
    batchSize: BigNumber { _hex: '0x03', _isBigNumber: true },
    prevTotalElements: BigNumber { _hex: '0x0f44', _isBigNumber: true },
    signature: '0xc01406422531924f079d2feeccf02d81feea144bc746d8dff3c1e47f21d07705724d805aa00ae5cb350e162f5405cbb37406ec4c5d5513c93f5dd0e5eed5d35a01',
    extraData: '0x00000000000000000000000000000000000000000000000000000000649322aa00000000000000000000000073b9f10e505c47aa99cdc90f28e0c0b7dda3bae6'
  },
  stateRootProof: {
    index: 2,
    siblings: [
      '0x290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e563',
      '0x9234733e2185e2172eb6387a896e80e77380b8180539270721fe72b07b872b42'
    ]
  },
  stateTrieWitness: '0xf90299b90174f9017180a0122383ce8e6ac6f06b585bf8f18ede3f450bd67e5ac868dd75010825e73b887ba042a5870394429bb448e10782b26902c392ba1eef4a8c6e74ac3ed68d1d244bd4a04dcaf9f2cc3919f604a0e356a944883f53b73f866455b5c865aefa5a91ef51d58080a03448e0dddf231ffe3398ccab073dbd57b10833b239b954fe4c0fea93ec8b080380a0551196e6b0d06141c7886e45f7f8e8b847a33bcf5628e1f3d95a2e43039f688ea03cfffaeaf1dbd43dac97801eeb70efa5741418f41957561e40e5a82c946006b9a0bada4ad7ec61ea9a89ed2aedee91596fece4d88c81335dc8dc679b9bad7433b6a0a11a77985883459544f1d4148499c48e8c3de24e8ef816beef42150743968cbd80a0da1ef8739c1f22e2146fabe7bba46385bc534ae5a9a5a7a2f66b23fc5ab0ce9aa00d7f720520fe51b119753304fe3a61ebb969345b65b4608b5242caa7177df4b2a0c60e32f6fabba6287fb161d58d20f41101c89bc9762f1b24f851f3b87a018ecf80b8b3f8b1a095f0713f64dd25ae223558ccf22f720bbf1c64908cb662e56e22c86c0d8490fe8080a09d912ffcc5b29ca9e8bd84964570ecf0355d8d9eb09fc86d635a80a6ef80697a8080a0dbe071016dcb971ff859fcba12703d3441713c2332117f9471cf47bf7ca24b2880a0ab41c6467d2ea19b9b24305436f18d2c48ac0711d6fdc47b9a674a9f3d825180a008def728e01f97127a2979c2e2757b960a446f96c443fa713a546562ce2ddae180808080808080b86bf869a020bd311b46a2440f3eaf346b6c1ce588ed08712591822a258c5a1c4cf44cd0c9b846f8448080a0bdfb3030b5bb35d7b73484de9749d6b7d7657a240cc1ea5ccd76f6fdc26835efa0b139321113538ffa52ef410f27f0b2bfabf1f2a467e066d5277df8dbc10769d9',
  storageTrieWitness: '0xf901dbb901b4f901b1a032462ae76c81f29a5ae42aaa61d128605e5050869f91e1b483154b69d58814f5a0131d0d5cc144daea3cbe58a82a0e56f16cabfd1c9e2073372b8b20a1afe68a84a01dcb46abf83478eb61768db45266cba54d8b21a36c34dd2effb8a50364481929a09d0f34287c600e38376f0474fde0c1674b7203ad7daae78cdaca98f30090177580a076b6b34f03c1b7b07c9edebf286a62f24111698a32db6288c629a50f356f4ab1a0719f668c9306121430750da7da8e3ee08c2ce3b170a36633f23230db9e171f1ea0bfcfb6815dc5b1f04fda9a6737ea8c6cf6f912faca5d3bcedf7b920355aa0a76a06935e8d949f0e8933875d3907ecda7e19afbc4d406e96c713fa3ef7dcbb6da54a0bae203969be29bbf8743b6e1b204c7c7bce7a81ea4f5d0033faa9b224befc366a0fc6364ea86a7bc858f20d1bb2e7be0423365cd2cc5e901ddb59b1db9421b300da055d2fd3d0290cf31aa04bbb5922d8e8320b3c38a586cbd0a911be1badcd172d8a0282f26df1ff51897ee2dacb1519e583bd8d180bb1e6d56081f603eaf575371b080a0c865d99c441080ab61cf6235255c40b29b1719b702b9a0a000ced623afc89e658080a3e2a0344a417741e2e94717669b013d7c0976a3e36c3b1ce19779d95ceddb7c45628601'
}
======================
finalizeMessageResponse txHash:  0x71c6d741b1e53f7a9a83c833d0fb65fa2f734fc571733c85a50085d783529e19
agnarsong commented 1 year ago

get proof function:

  let proof:any

  while (true) {
    try {
      proof = await crossChainMessenger.getMessageProof(withdrawETHtx)

      if (proof.stateRoot.length == 66){
        console.log("proof.stateRoot:  ", proof.stateRoot)
        break;
      }
    } catch (error) {
      console.error('请求 proof 异常:', error.message);
      console.log("等待 10 秒后, 再次请求...");
      await wait(10);
      continue
    }
  }