b2network / b2-node

Ethermint is a Cosmos SDK library for running scalable and interoperable EVM chains
https://docs.evmos.org/
GNU Lesser General Public License v3.0
3 stars 7 forks source link

bridge contract call deposit method error #90

Closed robertcc0410 closed 2 months ago

robertcc0410 commented 6 months ago

error info: ProviderError: execution reverted

robertcc0410 commented 6 months ago

failed tx_hash: 0x3f72bbfe5ea2a167d73731bf30ce63fb568a7bd133f6f8b1a84211eb6609ffe4

robertcc0410 commented 6 months ago

2N9M1oLEWRKf3hqyQCiWGq28fVqCbtZbV4b --> 0x6AA5d8DA3b45d04b55F7C7bb5aD85C49174387b0 success tb1qzr648w8jsu35ym7y6d6ga2trra36fja8xc7urk --> 0x74e9b10998788f0eF94805225E076729b45472C7 fail different accounts have different execution results

0x677261706562616261 commented 6 months ago

still exist, may be zkevm issue.

oxf71 commented 5 months ago

tx hash: 0x6f1fadb1c6874bdaaeca13dedd10b23e4470e62e90d2ee9580dbcb2a149fc6bc

2024-01-24T12:46:04.386852786+08:00 stdout F Wed, 24 Jan 2024 12:46:04 CST  ERROR   [bridge-deposit]    bitcoin/bridge.go:256   wait mined status err   {"error": "tx wait mined status failed", "receipt": {"root":"0x8d25f85e5d3ae68152433b258219212bfa84375198b398d36cb18eea51a55ffd","status":"0x0","cumulativeGasUsed":"0xfa0e","logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","logs":[],"transactionHash":"0x6f1fadb1c6874bdaaeca13dedd10b23e4470e62e90d2ee9580dbcb2a149fc6bc","contractAddress":"0x0000000000000000000000000000000000000000","gasUsed":"0xfa0e","effectiveGasPrice":"0x989680","blockHash":"0x7dd5325aed243a4fb336ee90488f6152e437ffecaf402b111faede8f70ef2f95","blockNumber":"0x1da","transactionIndex":"0x0"}}
2024-01-24T12:46:03.381519834+08:00 stdout F Wed, 24 Jan 2024 12:46:03 CST  INFO    [bridge-deposit]    bitcoin/bridge_deposit_service.go:132   invoke deposit send tx success, wait mined  {"btcTxHash": "6678d827afc78971d2efbe83efbb5dc451f7b1ec3465cb534ff16d9645899e9b", "data": {"id":56,"created_at":"2024-01-24T12:45:53.318241+08:00","updated_at":"2024-01-24T12:45:53.318241+08:00","deleted_at":null,"btc_block_number":2575497,"btc_tx_index":291,"btc_tx_hash":"6678d827afc78971d2efbe83efbb5dc451f7b1ec3465cb534ff16d9645899e9b","btc_tx_type":0,"btc_froms":"[\"tb1qzr648w8jsu35ym7y6d6ga2trra36fja8xc7urk\"]","btc_from":"tb1qzr648w8jsu35ym7y6d6ga2trra36fja8xc7urk","btc_to":"tb1q8mxmujnzlhsdx4jkqdy0mx93t3ytt2sw4wselv","btc_from_aa_address":"0x74e9b10998788f0eF94805225E076729b45472C7","btc_value":10000,"b2_tx_hash":"0x6f1fadb1c6874bdaaeca13dedd10b23e4470e62e90d2ee9580dbcb2a149fc6bc","b2_tx_status":0,"b2_tx_retry":0,"b2_eoa_tx_hash":"","b2_eoa_tx_status":1,"btc_block_time":"2024-01-24T12:44:58+08:00"}}
2024-01-24T12:46:03.357846619+08:00 stdout F Wed, 24 Jan 2024 12:46:03 CST  ERROR   [bridge-deposit]    bitcoin/bridge.go:170   estimate gas err    {"error": "execution reverted"}
robertcc0410 commented 5 months ago

// SPDX-License-Identifier: MIT pragma solidity ^0.8.0;

import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; import "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol";

interface ISimpleBridge{ function deposit(address to_address, uint256 amount) external;

function withdraw(string calldata btc_address) external payable;

event DepositEvent(address indexed caller, address indexed to_address, uint256 amount);

event WithdrawEvent(address indexed from_address, string btc_address, uint256 amount);

}

contract SimpleBridge is ISimpleBridge, Initializable, AccessControlUpgradeable {

receive() external payable {}
bytes32 public constant ADMIN_ROLE = keccak256("admin_role");

mapping (bytes32 => bool) deposit_uuids;
mapping (bytes32 => bool) withdraw_uuids;

function initialize() public initializer {
    __AccessControl_init();
    _grantRole(DEFAULT_ADMIN_ROLE, msg.sender);
    _grantRole(ADMIN_ROLE, msg.sender);
}

function version() external pure returns (uint256) {
    return 2;
}

function deposit(address b2_to_address, uint256 btc_amount) external onlyRole(ADMIN_ROLE) {
    uint256 b2_amount = btc_amount * 10000000000;
     require(address(this).balance >= b2_amount, "insufficient balance");
    (bool success, bytes memory returndata) = address(b2_to_address).call{
        value: b2_amount
    }("");

    require(success, "ERC20: call failed");
    if (returndata.length > 0) {
        require(
            abi.decode(returndata, (bool)),
            "ERC20: operation did not succeed"
        );
    }
    emit DepositEvent(msg.sender, b2_to_address, b2_amount);
}

function withdraw(string calldata btc_address) external payable {
    uint256 b2_amount = msg.value;
    uint256 btc_amount = b2_amount/ 10000000000;
    emit WithdrawEvent(msg.sender, btc_address, btc_amount);
}

function depositV2(bytes32 deposit_uuid, address b2_to_address, uint256 btc_amount) external onlyRole(ADMIN_ROLE) {
    require(!deposit_uuids[deposit_uuid], "non-repeatable processing");
    deposit_uuids[deposit_uuid] = true;
    uint256 b2_amount = btc_amount * 10000000000;
    require(address(this).balance >= b2_amount, "insufficient balance");
    payable(b2_to_address).transfer(b2_amount);
    emit DepositEvent(msg.sender, b2_to_address, b2_amount);
}

function withdrawV2(bytes32 withdraw_uuid, string calldata btc_address) external payable {
    require(!withdraw_uuids[withdraw_uuid], "non-repeatable processing");
    withdraw_uuids[withdraw_uuid] = true;
    uint256 b2_amount = msg.value;
    uint256 btc_amount = b2_amount/ 10000000000;
    emit WithdrawEvent(msg.sender, btc_address, btc_amount);
}

}

robertcc0410 commented 5 months ago

// SPDX-License-Identifier: MIT pragma solidity ^0.8.0;

import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; import "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol";

interface ISimpleBridge{ function deposit(address to_address, uint256 amount) external;

function withdraw(string calldata btc_address) external payable;

event DepositEvent(address indexed caller, address indexed to_address, uint256 amount);

event WithdrawEvent(address indexed from_address, string btc_address, uint256 amount);

}

contract SimpleBridge is ISimpleBridge, Initializable, AccessControlUpgradeable {

receive() external payable {}
bytes32 public constant ADMIN_ROLE = keccak256("admin_role");

mapping (bytes32 => bool) deposit_uuids;
mapping (bytes32 => bool) withdraw_uuids;

function initialize() public initializer {
    __AccessControl_init();
    _grantRole(DEFAULT_ADMIN_ROLE, msg.sender);
    _grantRole(ADMIN_ROLE, msg.sender);
}

function version() external pure returns (uint256) {
    return 2;
}

function deposit(address b2_to_address, uint256 btc_amount) external onlyRole(ADMIN_ROLE) {
    uint256 b2_amount = btc_amount * 10000000000;
     require(address(this).balance >= b2_amount, "insufficient balance");
    (bool success, bytes memory returndata) = address(b2_to_address).call{
        value: b2_amount
    }("");

    require(success, "ERC20: call failed");
    if (returndata.length > 0) {
        require(
            abi.decode(returndata, (bool)),
            "ERC20: operation did not succeed"
        );
    }
    emit DepositEvent(msg.sender, b2_to_address, b2_amount);
}

function withdraw(string calldata btc_address) external payable {
    uint256 b2_amount = msg.value;
    uint256 btc_amount = b2_amount/ 10000000000;
    emit WithdrawEvent(msg.sender, btc_address, btc_amount);
}

function depositV2(bytes32 deposit_uuid, address b2_to_address, uint256 btc_amount) external onlyRole(ADMIN_ROLE) {
    require(!deposit_uuids[deposit_uuid], "non-repeatable processing");
    deposit_uuids[deposit_uuid] = true;
    uint256 b2_amount = btc_amount * 10000000000;
    require(address(this).balance >= b2_amount, "insufficient balance");
    payable(b2_to_address).transfer(b2_amount);
    emit DepositEvent(msg.sender, b2_to_address, b2_amount);
}

function withdrawV2(bytes32 withdraw_uuid, string calldata btc_address) external payable {
    require(!withdraw_uuids[withdraw_uuid], "non-repeatable processing");
    withdraw_uuids[withdraw_uuid] = true;
    uint256 b2_amount = msg.value;
    uint256 btc_amount = b2_amount/ 10000000000;
    emit WithdrawEvent(msg.sender, btc_address, btc_amount);
}

}

call depositV2 method

oxf71 commented 5 months ago

executor

2024-01-24T12:46:20.198603066+08:00 stdout F {"level":"info","ts":"1706071580.198508","msg":"ExecutorServiceImpl::ProcessBatch() returns result=1 old_state_root=b57cf2348d459d1003342cafa63041dd5b263ecf4ab213041bf4abfeb5ff0933 new_state_root=0x8d25f85e5d3ae68152433b258219212bfa84375198b398d36cb18eea51a55ffd new_acc_input_hash=0x037aaee6b0a23cbef3053cec4992bb7a33d7d759dfde22035ae82fb3b2451aee new_local_exit_root=0x0000000000000000000000000000000000000000000000000000000000000000 old_batch_num=436 steps=33302 gasUsed=64014 counters.keccakF=11 counters.poseidonG=981 counters.paddingPG=97 counters.memAlign=16 counters.arith=727 counters.binary=2069 flush_id=422 last_sent_flush_id=421 nTxs=1 tx[0].hash=0x6f1fadb1c6874bdaaeca13dedd10b23e4470e62e90d2ee9580dbcb2a149fc6bc stateRoot=0x8d25f85e5d3ae68152433b258219212bfa84375198b398d36cb18eea51a55ffd gasUsed=64014 gasLeft=2935986 gasUsed+gasLeft=3000000 gasRefunded=0 result=revert","pid":"60a7fb7","tid":"97fa640","version":"v3.0.2","context_id":"52d2bb32-cd30-4c66-b5f2-073d52f31085"}
oxf71 commented 5 months ago

Compare with zkevm testnet

failed https://haven-explorer.bsquared.network/tx/0x996dfb7b02ad423da73abee9d3915bee4e369b891944dda64e9cd02e5da84ca9 https://testnet-zkevm.polygonscan.com/tx/0xe6f430e3921af5dea8b39d9a89cd0bd59a3a1f9a126f98ce916852761fbe2ba2

success

https://haven-explorer.bsquared.network/tx/0xbc6d8a1c7d0af7da36deda1abd992ea35c53d7379a6951562ebf0f20aecba04c https://testnet-zkevm.polygonscan.com/tx/0x15a5be1e994c332a8d5772dc7ca893f1043919a1fe19e85de52feb6c463b3a4c

oxf71 commented 5 months ago

There's an error on another contract

https://haven-explorer.bsquared.network/address/0x6B7aB2622BfE00d62b4C787C2b3D29b021219b88

https://haven-explorer.bsquared.network/tx/0x3201706ac7fc6b75ad67914c02d39132de61677c98be933f6abfd1b3bde973f0

https://haven-explorer.bsquared.network/tx/0x87ce7b90b48c5d108a62a25bbdcbabf1f22ff4c3dcaf68e6b4a933d81d81369b

oxf71 commented 2 months ago
failed
curl https://habitat-public-rpc.bsquared.network/ \
  -X POST \
  -H "Content-Type: application/json" \
  --data '{"method":"eth_estimateGas","params":[{"from":"0x6e1805F9B1AA770417d346A913BCBd922067d27C","to":"0x9EdE875C2E22FFA159b23D16137b04eA04DDE771","value":"0x0","data":"0x314aba69bee471d044748a02b1440b19e0e1b4caaccb14d3c9f6f20ec6c02a90445b34c70000000000000000000000000b0c0149d5dbb9eec2c87cff703eadfe428df8910000000000000000000000000000000000000000000000000000000000000001"}],"id":1,"jsonrpc":"2.0"}'

success:
curl https://habitat-public-rpc.bsquared.network/ \
  -X POST \
  -H "Content-Type: application/json" \
  --data '{"method":"eth_estimateGas","params":[{"from":"0x6e1805F9B1AA770417d346A913BCBd922067d27C","to":"0x9EdE875C2E22FFA159b23D16137b04eA04DDE771","value":"0x0","data":"0x314aba69bee471d044748a02b1440b19e0e1b4caaccb14d3c9f6f20ec6c02a90445b34c7000000000000000000000000C54c9c8C3ad903b6EE9D8B4809492B347Ff4A5CE0000000000000000000000000000000000000000000000000000000000000001"}],"id":1,"jsonrpc":"2.0"}'
oxf71 commented 2 months ago
        2024-04-06 11:28:32 
2024-04-06T11:28:32.403820129+08:00 stdout F 20240406_032832_403769 5e695f7 57fa640 main_exec_generated_fast() done lastStep=28046 (0.334334%)
2024-04-06 11:28:32 
2024-04-06T11:28:32.40381498+08:00 stdout F 20240406_032832_403761 5e695f7 57fa640 Database map: dbMetrics MT.size=0 cached=1545times=1053us=0us/time db=0times=0us=0us/time cacheHitRatio=100% PROGRAM.size=0 cached=3times=10us=3us/time db=0times=0us=0us/time cacheHitRatio=100% GET_TREE 0times=0us=0us/time=0fields=0.000000fields/time=0us/field
2024-04-06 11:28:32 
2024-04-06T11:28:32.403801945+08:00 stdout F 20240406_032832_403741 5e695f7 ff14640 Database::sendData() dbMetrics multiWrite nodes=0 program=0 nodesStateRootCounter=1 query.size=313B=313B/field queries.size=1 total=1fields
2024-04-06 11:28:32 
2024-04-06T11:28:32.401663371+08:00 stdout F 20240406_032832_401598 5e695f7 57fa640 FullTracer::onError() error=revert zkPC=1292 rom= inFREE=1 inFREE0=0 freeInTag={} mOp=1 offset=36 offsetLabel=originCTX useCTX=1 setB=1 cmdAfter[0]={ op=functionCall funcName=eventLog params[0]={ op=getVar varName=onError } params[1]={ op=getVar varName=revert }} fileName=create-terminate-context.zkasm line=835 lineStr=    $ => B          :MLOAD(originCTX) block=173576 responses.size=1
2024-04-06 11:28:32 
2024-04-06T11:28:32.401495977+08:00 stdout F 20240406_032832_401441 5e695f7 57fa640 FullTracer::onError() error=revert zkPC=1292 rom= inFREE=1 inFREE0=0 freeInTag={} mOp=1 offset=36 offsetLabel=originCTX useCTX=1 setB=1 cmdAfter[0]={ op=functionCall funcName=eventLog params[0]={ op=getVar varName=onError } params[1]={ op=getVar varName=revert }} fileName=create-terminate-context.zkasm line=835 lineStr=    $ => B          :MLOAD(originCTX) block=173576 responses.size=1
2024-04-06 11:28:32 
2024-04-06T11:28:32.401336196+08:00 stdout F 20240406_032832_401249 5e695f7 57fa640 FullTracer::onError() error=OOG zkPC=12390 rom= jmpAddr=12399 JMP=1 useJmpAddr=1 cmdBefore[0]={ op=functionCall funcName=eventLog params[0]={ op=getVar varName=onError } params[1]={ op=getVar varName=OOG }} fileName=utils.zkasm line=849 lineStr=    $${eventLog(onError, OOG)}                      :JMP(handleError) block=173576 responses.size=1
2024-04-06 11:28:32 
2024-04-06T11:28:32.387873364+08:00 stdout F 20240406_032832_387764 5e695f7 57fa640 ExecutorServiceImpl::ProcessBatchV2() got sequencerAddr=35c9568c96900b7b9e68c1d435c783b76d122658 batchL2DataLength=213 batchL2Data=0x0b000531e000000000f8...84b80bf12f0d841e1cff oldStateRoot=6c0acf8f43d1d36a616c4317f780156550a3f6d8b212a8931c2b977f2ff2bb3f oldAccInputHash=b18f0ee0bf2e3360cf0995cbf7693ee77250fe422a82f0e20fad3416ed4f375a oldBatchNum=1701 chainId=1123 forkId=8 generated globalExitRoot=0 timestampLimit=1712374112 from=0x5C1c826354B53b7B66ec7A102ab6cB4488b0c774 bUpdateMerkleTree=0 bNoCounters=0 bGetKeys=0 bSkipVerifyL1InfoRoot=0 bSkipFirstChangeL2Block=1 bSkipWriteBlockInfoRoot=1 traceConfig=bEnabled=0,bDisableStorage=0,bDisableStack=0,bEnableMemory=0,bEnableReturnData=0,txHashToGenerateFullTrace= UUID=4dda9a77-1fe8-4952-b074-92491a4a5b9c gasLimit=0 l1InfoTreeData.size=0= stateOverride.size=0

2024-04-06 11:28:32 
2024-04-06T11:28:32.404464355+08:00 stderr F 2024-04-06T11:28:32.404+0800   DEBUG   jsonrpc/handler.go:129  failed call: [3]execution reverted. Params: [{"from":"0x5c1c826354b53b7b66ec7a102ab6cb4488b0c774","to":"0x9ede875c2e22ffa159b23d16137b04ea04dde771","data":"0x314aba6900000000000000000000000000000000000000000000000000000000000000020000000000000000000000000b0c0149d5dbb9eec2c87cff703eadfe428df8910000000000000000000000000000000000000000000000000000000000000001"},"pending"] {"pid": 1, "version": "v0.6.3", "method": "eth_estimateGas", "requestId": 2}
2024-04-06 11:28:32 
2024-04-06T11:28:32.404225188+08:00 stderr F 2024-04-06T11:28:32.404+0800   DEBUG   state/transaction.go:1037   executor time: 17ms {"pid": 1, "version": "v0.6.3"}
2024-04-06 11:28:32 
2024-04-06T11:28:32.386429968+08:00 stderr F 2024-04-06T11:28:32.386+0800   DEBUG   state/transaction.go:1033   EstimateGas[processBatchRequestV2.SkipWriteBlockInfoRoot]: 1    {"pid": 1, "version": "v0.6.3"}Show context
2024-04-06 11:28:32 
2024-04-06T11:28:32.386426052+08:00 stderr F 2024-04-06T11:28:32.386+0800   DEBUG   state/transaction.go:1032   EstimateGas[processBatchRequestV2.SkipFirstChangeL2Block]: 1    {"pid": 1, "version": "v0.6.3"}
2024-04-06 11:28:32 
2024-04-06T11:28:32.386406086+08:00 stderr F 2024-04-06T11:28:32.386+0800   DEBUG   state/transaction.go:1031   EstimateGas[processBatchRequestV2.TimestampLimit]: 1712374112   {"pid": 1, "version": "v0.6.3"}
2024-04-06 11:28:32 
2024-04-06T11:28:32.386389887+08:00 stderr F 2024-04-06T11:28:32.386+0800   DEBUG   state/transaction.go:1030   EstimateGas[processBatchRequestV2.L1InfoRoot]: 0x53f1fd2114d393b4f84c8dd36f2cc27f5c23b3eb6ae842393cd9ff2be02221e1   {"pid": 1, "version": "v0.6.3"}
2024-04-06 11:28:32 
2024-04-06T11:28:32.386380063+08:00 stderr F 2024-04-06T11:28:32.386+0800   DEBUG   state/transaction.go:1028   EstimateGas[processBatchRequestV2.ContextId]: 35ccd0dd-760f-4934-93c4-1a17b5573085  {"pid": 1, "version": "v0.6.3"}
2024-04-06 11:28:32 
2024-04-06T11:28:32.386349436+08:00 stderr F 2024-04-06T11:28:32.386+0800   DEBUG   state/transaction.go:1027   EstimateGas[processBatchRequestV2.UpdateMerkleTree]: 0  {"pid": 1, "version": "v0.6.3"}
2024-04-06 11:28:32 
2024-04-06T11:28:32.386346035+08:00 stderr F 2024-04-06T11:28:32.386+0800   DEBUG   state/transaction.go:1026   EstimateGas[processBatchRequestV2.ChainId]: 1123    {"pid": 1, "version": "v0.6.3"}
2024-04-06 11:28:32 
2024-04-06T11:28:32.386341778+08:00 stderr F 2024-04-06T11:28:32.386+0800   DEBUG   state/transaction.go:1025   EstimateGas[processBatchRequestV2.ForkId]: 8    {"pid": 1, "version": "v0.6.3"}
2024-04-06 11:28:32 
2024-04-06T11:28:32.386320998+08:00 stderr F 2024-04-06T11:28:32.386+0800   DEBUG   state/transaction.go:1024   EstimateGas[processBatchRequestV2.Coinbase]: 0x35C9568C96900b7b9E68c1D435C783B76D122658 {"pid": 1, "version": "v0.6.3"}
2024-04-06 11:28:32 
2024-04-06T11:28:32.386309458+08:00 stderr F 2024-04-06T11:28:32.386+0800   DEBUG   state/transaction.go:1023   EstimateGas[processBatchRequestV2.OldAccInputHash]: 0xb18f0ee0bf2e3360cf0995cbf7693ee77250fe422a82f0e20fad3416ed4f375a  {"pid": 1, "version": "v0.6.3"}
2024-04-06 11:28:32 
2024-04-06T11:28:32.386305947+08:00 stderr F 2024-04-06T11:28:32.386+0800   DEBUG   state/transaction.go:1022   EstimateGas[processBatchRequestV2.OldStateRoot]: 0x6c0acf8f43d1d36a616c4317f780156550a3f6d8b212a8931c2b977f2ff2bb3f {"pid": 1, "version": "v0.6.3"}
2024-04-06 11:28:32 
2024-04-06T11:28:32.38629087+08:00 stderr F 2024-04-06T11:28:32.386+0800    DEBUG   state/transaction.go:1021   EstimateGas[processBatchRequestV2.OldBatchNum]: 1701    {"pid": 1, "version": "v0.6.3"}
2024-04-06 11:28:32 
2024-04-06T11:28:32.386227902+08:00 stderr F 2024-04-06T11:28:32.386+0800   DEBUG   state/transaction.go:1020   EstimateGas[processBatchRequestV2.From]: 0x5C1c826354B53b7B66ec7A102ab6cB4488b0c774 {"pid": 1, "version": "v0.6.3"}
2024-04-06 11:28:32 
2024-04-06T11:28:32.38621462+08:00 stderr F 2024-04-06T11:28:32.386+0800    DEBUG   state/helper.go:135 Forced nonce: 10    {"pid": 1, "version": "v0.6.3"}
2024-04-06 11:28:32 
2024-04-06T11:28:32.386209705+08:00 stderr F 2024-04-06T11:28:32.386+0800   DEBUG   state/helper.go:131 10 0 30000000 0x9EdE875C2E22FFA159b23D16137b04eA04DDE771 0 100 1123 {"pid": 1, "version": "v0.6.3"}
2024-04-06 11:28:32 
2024-04-06T11:28:32.386185328+08:00 stderr F 2024-04-06T11:28:32.386+0800   DEBUG   state/transaction.go:807    Estimate gas. Trying to execute TX with 30000000 gas    {"pid": 1, "version": "v0.6.3"}
oxf71 commented 2 months ago

oog, Use call instead of transfer