Beispiel #1
0
    def deploy(
        web3: Any,
        prover_client: ProverClient,
        deployer_eth_address: str,
        deployer_eth_private_key: Optional[bytes],
        token_address: Optional[str] = None,
        permitted_dispatcher: Optional[str] = None,
        vk_hash: Optional[str] = None,
        deploy_gas: Optional[int] = None
    ) -> Tuple[MixerClient, contracts.InstanceDescription]:
        """
        Deploy Zeth contracts.
        """
        prover_config = prover_client.get_configuration()
        vk = prover_client.get_verification_key()

        contracts_dir = get_contracts_dir()
        zksnark = get_zksnark_provider(prover_config.zksnark_name)
        pp = prover_config.pairing_parameters
        mixer_name = zksnark.get_contract_name(pp)
        mixer_src = os.path.join(contracts_dir, mixer_name + ".sol")
        vk_hash_evm = list(hex_to_uint256_list(vk_hash)) if vk_hash else [0, 0]
        assert len(vk_hash_evm) == 2

        # Constructor parameters have the form:
        #   uint256 mk_depth
        #   address token
        #   ... snark-specific key data ...
        constructor_parameters: List[Any] = [
            constants.ZETH_MERKLE_TREE_DEPTH,  # mk_depth
            token_address or ZERO_ADDRESS,  # token
            zksnark.verification_key_to_contract_parameters(vk, pp),  # vk
            permitted_dispatcher or ZERO_ADDRESS,  # permitted_dispatcher
            vk_hash_evm  # vk_hash
        ]
        mixer_description = contracts.InstanceDescription.deploy(
            web3,
            mixer_src,
            mixer_name,
            deployer_eth_address,
            deployer_eth_private_key,
            deploy_gas,
            compiler_flags={},
            args=constructor_parameters)
        mixer_instance = mixer_description.instantiate(web3)
        client = MixerClient(web3, prover_config, mixer_instance)
        return client, mixer_description
Beispiel #2
0
    def deploy(
        web3: Any,
        prover_client: ProverClient,
        deployer_eth_address: str,
        deployer_eth_private_key: Optional[bytes],
        token_address: Optional[str] = None,
        deploy_gas: Optional[int] = None
    ) -> Tuple[MixerClient, contracts.InstanceDescription]:
        """
        Deploy Zeth contracts.
        """
        prover_config = prover_client.get_configuration()
        zksnark = get_zksnark_provider(prover_config.zksnark_name)
        vk_proto = prover_client.get_verification_key()
        pp = prover_config.pairing_parameters
        vk = zksnark.verification_key_from_proto(vk_proto)
        deploy_gas = deploy_gas or constants.DEPLOYMENT_GAS_WEI

        contracts_dir = get_contracts_dir()
        mixer_name = zksnark.get_contract_name(pp)
        mixer_src = os.path.join(contracts_dir, mixer_name + ".sol")

        # Constructor parameters have the form:
        #   uint256 mk_depth
        #   address token
        #   ... snark-specific key data ...
        constructor_parameters: List[Any] = [
            constants.ZETH_MERKLE_TREE_DEPTH,  # mk_depth
            token_address or ZERO_ADDRESS,  # token
            zksnark.verification_key_to_contract_parameters(vk, pp),  # vk
        ]
        mixer_description = contracts.InstanceDescription.deploy(
            web3,
            mixer_src,
            mixer_name,
            deployer_eth_address,
            deployer_eth_private_key,
            deploy_gas,
            compiler_flags={},
            args=constructor_parameters)
        mixer_instance = mixer_description.instantiate(web3)
        client = MixerClient(web3, prover_config, mixer_instance)
        return client, mixer_description
Beispiel #3
0
    def deploy(
            web3: Any,
            prover_server_endpoint: str,
            deployer_eth_address: str,
            deployer_eth_private_key: Optional[bytes],
            token_address: Optional[str] = None,
            deploy_gas: Optional[int] = None,
            zksnark: Optional[IZKSnarkProvider] = None) \
            -> Tuple[MixerClient, contracts.InstanceDescription]:
        """
        Deploy Zeth contracts.
        """
        print("[INFO] 1. Fetching verification key from the proving server")
        zksnark = zksnark or get_zksnark_provider(constants.ZKSNARK_DEFAULT)
        prover_client = ProverClient(prover_server_endpoint)
        vk_proto = prover_client.get_verification_key()
        vk = zksnark.verification_key_from_proto(vk_proto)
        deploy_gas = deploy_gas or constants.DEPLOYMENT_GAS_WEI

        print("[INFO] 2. Received VK, writing verification key...")
        write_verification_key(vk, "vk.json")

        print("[INFO] 3. VK written, deploying smart contracts...")
        contracts_dir = get_contracts_dir()
        mixer_name = zksnark.get_contract_name()
        mixer_src = os.path.join(contracts_dir, mixer_name + ".sol")

        verification_key_params = zksnark.verification_key_parameters(vk)
        mixer_description = contracts.InstanceDescription.deploy(
            web3,
            mixer_src,
            mixer_name,
            deployer_eth_address,
            deployer_eth_private_key,
            deploy_gas, {},
            mk_depth=constants.ZETH_MERKLE_TREE_DEPTH,
            token=token_address
            or "0x0000000000000000000000000000000000000000",
            **verification_key_params)
        mixer_instance = mixer_description.instantiate(web3)
        client = MixerClient(web3, prover_client, mixer_instance, zksnark)
        return client, mixer_description