0

I am trying to make a multisig contract account on zksync. Here is my AAFactory.sol

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

import {DEPLOYER_SYSTEM_CONTRACT} from "@matterlabs/zksync-contracts/l2/system-contracts/Constants.sol";
import {SystemContractsCaller} from "@matterlabs/zksync-contracts/l2/system-contracts/libraries/SystemContractsCaller.sol";
import {IContractDeployer} from "@matterlabs/zksync-contracts/l2/system-contracts/interfaces/IContractDeployer.sol";

contract AAFactory {
    error AAFactory__AccountDeployerFailed();

    bytes32 public aaBytecodeHash;

    constructor(bytes32 _aaBytecodeHash) {
        aaBytecodeHash = _aaBytecodeHash;
    }

    function deployAccount(
        bytes32 _salt,
        address _owner1,
        address _owner2
    ) external returns (address accountAddress) {
        (bool success, bytes memory returnData) = SystemContractsCaller
            .systemCallWithReturndata(
                uint32(gasleft()),
                address(DEPLOYER_SYSTEM_CONTRACT),
                uint128(0),
                abi.encodeCall(
                    IContractDeployer.create2Account,
                    (
                        _salt,
                        aaBytecodeHash,
                        abi.encode(_owner1, _owner2),
                        IContractDeployer.AccountAbstractionVersion.Version1
                    )
                )
            );

        if (!success) {
            revert AAFactory__AccountDeployerFailed();
        }

        (accountAddress) = abi.decode(returnData, (address));
    }
}

aaBytecodeHash is the bytecode of MultisigAA.sol

I deployed the AAFactory successfully. But when I deploy the multisig , I get an error saying execution reverted (unknown custom error) Here is my multissig deployment script-

const hre = require("hardhat")
const { Wallet, utils, Provider } = require("zksync-ethers")
const addresses = require("../address.json")
const { Deployer } = require("@matterlabs/hardhat-zksync-deploy")

const AA_FACTORY_ADDRESS = addresses[hre.network.config.chainId]

module.exports = async () => {
    const provider = new Provider(hre.userConfig.networks.zkSyncTestnet.url)
    const wallet = new Wallet(process.env.RICH_ACCOUNTS_PRIVATE_KEY, provider)
    
    const factoryArtifact = await hre.artifacts.readArtifact("AAFactory")
    const aaFactory = new hre.ethers.Contract(
        AA_FACTORY_ADDRESS,
        factoryArtifact.abi,
        wallet
    )
    
    const owner1 = Wallet.createRandom()
    const owner2 = Wallet.createRandom()
    
    const salt = hre.ethers.ZeroHash;

    const tx = await aaFactory.deployAccount(
        salt,
        owner1.address,
        owner2.address,
    )
    await tx.wait()
    
    const abiCoder = new hre.ethers.AbiCoder()
    const multisigAddress = utils.create2Address(
        AA_FACTORY_ADDRESS,
        await aaFactory.aaBytecodeHash(),
        salt,
        abiCoder.encode(['address', 'address'], [owner1.address, owner2.address])
    )

    console.log(`Multisig account deployed on address ${multisigAddress}`)
}

The error comes from the aaFactory.deployAccount function. The error-

Error: execution reverted (unknown custom error) (action="estimateGas", data="0xb0591126", reason=null, transaction={ "data": "0x76fb8b65000000000000000000000000000000000000000000000000000000000000000000000000000000000000000087f2d1d29b19486b0ea15131f1a2be0755f402fc000000000000000000000000dc3c0ddd0c52857dc41b55072c1132f57712a7e5", "from": "0xBC989fDe9e54cAd2aB4392Af6dF60f04873A033A", "to": "0xa85a2DFAe6bead4f408Fcc6EB8a3ec6C7AaCE9Eb" }, invocation=null, revert=null, code=CALL_EXCEPTION, version=6.13.1)
    at makeError (/home/i-atiq/projects/blockchain/zksyncAccountAbstraction/node_modules/ethers/src.ts/utils/errors.ts:694:21)
    at getBuiltinCallException (/home/i-atiq/projects/blockchain/zksyncAccountAbstraction/node_modules/ethers/src.ts/abi/abi-coder.ts:118:21)
    at Function.getBuiltinCallException (/home/i-atiq/projects/blockchain/zksyncAccountAbstraction/node_modules/ethers/src.ts/abi/abi-coder.ts:235:16)
    at Provider.getRpcError (/home/i-atiq/projects/blockchain/zksyncAccountAbstraction/node_modules/ethers/src.ts/providers/provider-jsonrpc.ts:989:32)
    at /home/i-atiq/projects/blockchain/zksyncAccountAbstraction/node_modules/ethers/src.ts/providers/provider-jsonrpc.ts:563:45
    at processTicksAndRejections (node:internal/process/task_queues:95:5) {
  code: 'CALL_EXCEPTION',
  action: 'estimateGas',
  data: '0xb0591126',
  reason: null,
  transaction: {
    to: '0xa85a2DFAe6bead4f408Fcc6EB8a3ec6C7AaCE9Eb',
    data: '0x76fb8b65000000000000000000000000000000000000000000000000000000000000000000000000000000000000000087f2d1d29b19486b0ea15131f1a2be0755f402fc000000000000000000000000dc3c0ddd0c52857dc41b55072c1132f57712a7e5',
    from: '0xBC989fDe9e54cAd2aB4392Af6dF60f04873A033A'
  },
  invocation: null,
  revert: null,
  shortMessage: 'execution reverted (unknown custom error)',
  info: {
    error: {
      code: 3,
      message: 'execution reverted: Error function_selector = 0xb0591126, data = 0xb0591126',
      data: '0xb0591126'
    },
    payload: {
      method: 'eth_estimateGas',
      params: [Array],
      id: 4,
      jsonrpc: '2.0'
    }
  }
}

I tried with a override like this-

const salt = hre.ethers.ZeroHash;
    const override = {
        gasLimit: BigInt("20000000")
    }
    const tx = await aaFactory.deployAccount(
        salt,
        owner1.address,
        owner2.address,
        override
    )
    await tx.wait()

But I get this error after that-

code: 'CALL_EXCEPTION',
  action: 'sendTransaction',
  data: null,
  reason: null,
  invocation: null,
  revert: null,
  transaction: {
    to: '0x8df4285274DE8b19F4153f59f1881e29498F09E6',
    from: '0xBC989fDe9e54cAd2aB4392Af6dF60f04873A033A',
    data: ''
  },
  receipt: TransactionReceipt {
    provider: Provider { _contractAddresses: {} },
    to: '0x8df4285274DE8b19F4153f59f1881e29498F09E6',
    from: '0xBC989fDe9e54cAd2aB4392Af6dF60f04873A033A',
    contractAddress: null,
    hash: '0xb013cf63959841aff1bff832b902fafa08eb0b2004b58e6d7ebbdb5f26c901ae',
    index: 0,
    blockHash: '0x56c41a1c77b395ba4656d9ea865150086fb6c1a64dfd8af8feee49c6690621a1',
    blockNumber: 73,
    logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
    gasUsed: 1019975n,
    blobGasUsed: undefined,
    cumulativeGasUsed: 0n,
    gasPrice: 25000000n,
    blobGasPrice: undefined,
    type: 0,
    status: 0,
    root: '0x0000000000000000000000000000000000000000000000000000000000000000',
    l1BatchNumber: 37,
    l1BatchTxIndex: undefined,
    l2ToL1Logs: []
  },
  shortMessage: 'transaction execution reverted'
}

My hardhat.config.js-

require("@nomicfoundation/hardhat-toolbox");
require("@matterlabs/hardhat-zksync-deploy");
require("@matterlabs/hardhat-zksync-solc");
require("@matterlabs/hardhat-zksync-ethers");
require("@matterlabs/hardhat-zksync-node")
require("dotenv").config()

/** @type import('hardhat/config').HardhatUserConfig */
module.exports = {
  zksolc: {
    version: "latest",
    compilerSource: "binary",
    settings: {
      enableEraVMExtensions: false,
      forceEVMLA: false,
      optimizer: {
        enabled: true,
        mode: '3',
        fallback_to_optimizing_for_size: false,
      },
    },
  },
  solidity: {
    version: "0.8.20",
    eraVersion: "1.0.0",
    settings: {
      optimizer: {
        enabled: true,
        runs: 200,
      },
    }
  },
  deployerAccounts: {
    'zkTestnet': 0,
    dafault: 0,
  },
  defaultNetwork: "zkSyncTestnet",
  networks: {
    hardhat: {
      zksync: true,
    },
    zkSyncTestnet: {
      url: "http://localhost:8011",
      ethNetwork: "http://localhost:8545",
      zksync: true,
      chainId: 260
    },
    /* zkSyncTestnet: {
      url: "https://sepolia.era.zksync.dev",
      ethNetwork: "sepolia",
      zksync: true,
    }, */
    /* sepolia: {
      url: process.env.SEPOLIA_RPC_URl,
      accounts: [process.env.SEPOLIA_PRIVATE_KEY],
      chainId: 11155111,
      timeout: 30000,
      blockConfirmations: 6,
      zksync: false
    } */
  },
  gasReporter: {
    enabled: true,
    currency: 'USD',
    //outputFile: 'gas-reporter.txt',
    coinmarketcap: process.env.COINMARKETCAP_API_KEY
  },
};

I am using local zksync node

1 Answer 1

0

You should modify deploy AAfactory script to:

const factory = await deployer.deploy(
    factoryArtifact,
    [bytecodeHash],
    "create",
    undefined,
    [
      aaArtifact.bytecode,
    ],);
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.