matter-labs / zksync-v2-issues

Report issues encountered when using the zkSync 2.0 testnet.
9 stars 6 forks source link

L1 to L2 communication: Error: (Awaiting internal transactions for reason) #4

Closed rico-mercury closed 1 year ago

rico-mercury commented 2 years ago

Describe the issue I am trying to call a contract function on ZKSync 2 test net from Goerli network but I got following error

Error: (Awaiting internal transactions for reason)

https://zksync2-testnet.zkscan.io/tx/0x685c213917dcd5e25d846d6f882f595344b5391d2e84fb4b96c18f96660a848b/logs

Expected behavior The contract function should be invoked successfully

Minimal Reproducible Example Code

My contract code from L1 to call L2

contract MyBridge is IBridge {

  event Bridged(address indexed sender, uint256 indexed tokenId, bytes32 txHash);  
  mapping(uint256 => bool) private _bridgedTokens;
  mapping(uint256 => address) private _owners;

  address private _zkAddress;
  address private _zkContract;

  constructor(address zkAddress, address zkContract) {
    _zkAddress = zkAddress;
    _zkContract = zkContract;
  }

  // create a function to Fragmentize the NFT, only the owner can do this
  function bridgeNFT(uint256 tokenId, uint256 amount) external payable override {

  IZkSync zksync = IZkSync(_zkAddress);
  // // calling L2 smart contract from L1 Example contract

  bytes32 txHash = zksync.requestL2Transaction{ value: msg.value } (
          // The address of the L2 contract to call
          _zkContract,
          0,
          // Encoding the calldata for the execute
          abi.encodeWithSignature("mint(address,uint256, uint256, bytes)", msg.sender, tokenId, amount, new bytes(0)),
          // Ergs limit
          10000,
          // factory dependencies
          new bytes[](0)
      );
    emit Bridged(msg.sender, tokenId, txHash);
  }
}

To Reproduce Steps to reproduce the behavior: It can be re-produced with my Goerli contract as follows

Goerli Network: 0x2730297173C54c32e66D6E9826A476CB4596Bfd8

 const bridge = async data => {
        const { contractAddr } = data;
           // Ethereum L1 provider
        const l1Provider = ethers.providers.getDefaultProvider("goerli");
        const wallet = new Wallet("my private key", l1Provider);
        const contract = new ethers.Contract(
          contractAddr,
          BRIDGE_ABI,
          wallet,
        );
        const l2Provider = new Provider("https://zksync2-testnet.zksync.dev");
        const zkSyncAddress = await l2Provider.getMainContractAddress();
        // Getting the `Contract` object of the zkSync bridge
          // Governor wallet
        const zkSyncContract = new Contract(zkSyncAddress, utils.ZKSYNC_MAIN_ABI, wallet);
        // Encoding the tx data the same way it is done on Ethereum.
        const counterInterface = new ethers.utils.Interface(L2_ABI);
        const rawContract = counterInterface.encodeFunctionData("mint", [ethers.utils.getAddress('my address'), '8888', '1', []]);
        const lengthOfData = ethers.utils.hexlify(rawContract).length;
        // The price of the L1 transaction requests depends on the gas price used in the call
        console.log("length of contract", lengthOfData);
        const gasPrice = await l1Provider.getGasPrice();
        console.log("gas price is ", gasPrice.toString());
        // Here we define the constant for ergs limit.
        const ergsLimit = BigNumber.from(100000);
        // Getting the cost of the execution.
        // Getting the current address of the zkSync L1 bridge
        const baseCost = await zkSyncContract.l2TransactionBaseCost(gasPrice, ergsLimit, lengthOfData);
        console.log("base cost is " + baseCost);
        // call bridgeNFT from contract
        const tx = await contract.bridgeNFT(
          8888,1, {
            // Passing the necessary ETH `value` to cover the fee for the operation
            value: baseCost,
            gasPrice,
          }
        );
        await tx.wait();

        // Getting the TransactionResponse object for the L2 transaction corresponding to the
        // execution call
        const l2Response = await l2Provider.getL2TransactionFromPriorityOp(tx);

        // The receipt of the L2 transaction corresponding to the call to the Increment contract
        const l2Receipt = await l2Response.wait();
        console.log(l2Receipt);
        // } catch (error) {
        //   console.error("failed to mint NFT token "+ error);
        // } finally {
        //   console.log("processing minting function");
        // }
    };
bxpana commented 2 years ago

@rico-mercury can you share the contents of your package.json file to see what versions you have

rico-mercury commented 2 years ago

see below @bxpana

{
    "name": "stratum-ethereum-contracts",
    "version": "0.0.1",
    "repository": "git@gitlab.com:tcam-engineering/on-chain/stratum.git",
    "author": "Mercury Lab Dapp team",
    "license": "MIT",
    "files": [
        "/contracts/**/*.sol",
        "/build/contracts/*.json",
        "!/contracts/mocks/**/*"
    ],
    "engines": {
        "node": ">=12"
    },
    "scripts": {
        "clean": "hardhat clean && rimraf build contracts/build",
        "test": "hardhat test",
        "coverage": "env COVERAGE=true hardhat coverage",
        "lint": "yarn run lint:js && yarn run lint:sol",
        "lint:fix": "yarn run lint:js:fix && yarn run lint:sol:fix",
        "lint:js": "eslint --ignore-path .gitignore .",
        "lint:js:fix": "eslint --ignore-path .gitignore . --fix",
        "lint:sol": "solhint 'contracts/**/*.sol' && prettier -c 'contracts/**/*.sol'",
        "lint:sol:fix": "prettier --write \"contracts/**/*.sol\"",
        "gas-report": "env ENABLE_GAS_REPORT=true yarn run test",
        "slither": "yarn run clean && slither . --detect reentrancy-eth,reentrancy-no-eth,reentrancy-unlimited-gas",
        "compile": "hardhat compile",
        "deploy:goerli": "hardhat run deploy/deploy.js --network goerli",
        "deployGov:goerli": "hardhat run deploy/bridge.js --network goerli"
    },
    "devDependencies": {
        "@nomiclabs/hardhat-ethers": "^2.1.1",
        "@nomiclabs/hardhat-etherscan": "^3.1.0",
        "@nomiclabs/hardhat-truffle5": "^2.0.6",
        "@nomiclabs/hardhat-waffle": "^2.0.3",
        "@nomiclabs/hardhat-web3": "^2.0.0",
        "@openzeppelin/contracts": "^4.7.3",
        "@openzeppelin/test-helpers": "^0.5.15",
        "chai": "^4.3.6",
        "dotenv": "^16.0.1",
        "eslint": "^8.22.0",
        "eslint-config-prettier": "^8.5.0",
        "eslint-config-standard": "^17.0.0",
        "eslint-plugin-import": "^2.26.0",
        "eslint-plugin-mocha-no-only": "^1.1.1",
        "eslint-plugin-n": "^15.2.5",
        "eslint-plugin-node": "^11.1.0",
        "eslint-plugin-prettier": "^4.2.1",
        "eslint-plugin-promise": "^6.0.1",
        "ethereum-waffle": "^3.4.4",
        "ethers": "^5.7.0",
        "hardhat": "^2.10.2",
        "hardhat-deploy": "^0.11.12",
        "hardhat-gas-reporter": "^1.0.8",
        "husky": "^8.0.0",
        "prettier": "^2.7.1",
        "prettier-plugin-solidity": "^1.0.0-beta.24",
        "solc": "^0.8.17",
        "solhint": "^3.3.7",
        "solidity-coverage": "^0.7.21"
    },
    "dependencies": {
        "@matterlabs/zksync-contracts": "^0.3.3",
        "@openzeppelin/contracts": "^4.7.3",
        "dotenv": "^16.0.1",
        "zksync-web3": "^0.9.0"
    }
}
bxpana commented 2 years ago

@rico-mercury thank you! I'll let you know if we have any other questions and let you know when we have an update for you

rico-mercury commented 2 years ago

thanks @bxpana . and this is calling my L2 contract here:

https://zksync2-testnet.zkscan.io/address/0xAD32f5eDD744C2c376Be17006bFfae075191A9Bd/transactions

const {Provider} = require("zksync-web3");

const hre = require('hardhat');

async function main () {
  // Hardhat always runs the compile task when running scripts with its command
  // line interface.
  //
  // If this script is run directly using `node` you may want to call compile
  // manually to make sure everything is compiled
  // await hre.run('compile');
  // We get the contract to deploy
  // Getting the current address of the zkSync L1 bridge
  const l2Provider = new Provider("https://zksync2-testnet.zksync.dev");
  const zkSyncAddress = await l2Provider.getMainContractAddress();
  // Getting the `Contract` object of the zkSync bridge

  const bridgeContract = await hre.ethers.getContractFactory('VinoBridge');
  const bridge = await bridgeContract.deploy(zkSyncAddress, "0xAD32f5eDD744C2c376Be17006bFfae075191A9Bd");
  await bridge.deployed();
  console.log('Vino NFT bridge deployed to:', bridge.address);
}

main()
  .then(() => process.exit(0))
  .catch((error) => {
    console.error(error);
    process.exit(1);
  });
bxpana commented 1 year ago

@rico-mercury thanks for your patience! It's been a busy few months for us, but wanted to check on this with all the updates we've done in that time. Are you still running into the original issue here?