コード例 #1
0
ファイル: utils.py プロジェクト: hyunokoh/zeth
 def from_json(json_str: str) -> MixerDescription:
     json_dict = json.loads(json_str)
     mixer = InstanceDescription.from_json_dict(json_dict["mixer"])
     token_dict = json_dict.get("token", None)
     token = InstanceDescription.from_json_dict(token_dict) \
         if token_dict else None
     return MixerDescription(mixer, token)
コード例 #2
0
ファイル: utils.py プロジェクト: clearmatics/zeth
    def from_json_dict(json_dict: Dict[str, Any]) -> MixerDescription:
        zeth_mixer = json_dict["zeth_mixer"]

        mixer = InstanceDescription.from_json_dict(json_dict)
        token_dict = cast(Optional[Dict[str, Any]],
                          zeth_mixer.get("token", None))
        token = InstanceDescription.from_json_dict(token_dict) \
            if token_dict else None
        permitted_dispatcher = \
            cast(Optional[str], zeth_mixer.get("permitted_dispatcher", None))
        vk_hash = cast(Optional[str], zeth_mixer.get("vk_hash", None))
        return MixerDescription(mixer, token, permitted_dispatcher, vk_hash)
コード例 #3
0
def deploy(ctx: Context, verification_key_hash: str,
           dispatcher_instance_file: str, instance_file: str) -> None:
    """
    Deploy the contract for a dummy application.
    """

    eth_network = ctx.obj["eth_network"]

    # Load the dispatcher instance
    with open(dispatcher_instance_file, "r") as dispatcher_instance_f:
        dispatcher_desc = InstanceDescription.from_json_dict(
            json.load(dispatcher_instance_f))

    # Verification key hash as an array of evm words.
    verification_key_hash_evm = list(
        hex_to_uint256_list(verification_key_hash))
    print(f"verification_key_hash_evm = {verification_key_hash_evm}")

    web3 = open_web3_from_network(eth_network)
    eth_address = load_eth_address(ctx.obj["eth_addr"])
    eth_private_key_data = load_eth_private_key(ctx.obj["eth_private_key"])
    instance_desc = InstanceDescription.deploy(
        web3, DUMMY_APP_CONTRACT_FILE, "DummyApplication", eth_address,
        eth_private_key_data, DUMMY_APP_CONTRACT_DEPLOY_GAS,
        {"allow_paths": CONTRACTS_DIR},
        [dispatcher_desc.address, verification_key_hash_evm])

    with open(instance_file, "w") as instance_file_f:
        json.dump(instance_desc.to_json_dict(), instance_file_f)

    print(f"Instance file written to '{instance_file}'")
コード例 #4
0
ファイル: command_context.py プロジェクト: clearmatics/zecale
 def get_dispatcher_contract(self) -> Any:
     """
     Load (and cache) the dispatcher contract instance.
     """
     if not self._dispatcher_contract:
         with open(self.instance_file, "r") as instance_f:
             instance_dict = json.load(instance_f)
             instance = InstanceDescription.from_json_dict(instance_dict)
         self._dispatcher_contract = DispatcherContract(
             self.get_web3(), instance, self.get_wrapper_snark())
     return self._dispatcher_contract
コード例 #5
0
ファイル: utils.py プロジェクト: clearmatics/zeth
def load_contract_address(contract_addr: str) -> str:
    """
    Parse a string as either an eth address, or a contract instance file.
    """
    if contract_addr.startswith("0x"):
        return Web3.toChecksumAddress(contract_addr)
    if exists(contract_addr):
        with open(contract_addr, "r") as instance_f:
            instance = InstanceDescription.from_json_dict(
                json.load(instance_f))
        return Web3.toChecksumAddress(instance.address)
    raise ClickException(
        f"failed to parse as address or instance file: {contract_addr}")
コード例 #6
0
def submit_batch(
        ctx: Context,
        batch_file: str,
        application_instance_file: str,
        wait: bool) -> None:
    """
    Submit an aggregated transaction ("batch") to a zecale dispatcher contract
    instance.
    """

    cmd_ctx: CommandContext = ctx.obj
    aggregator_config = cmd_ctx.get_aggregator_configuration()
    wrapper_snark = aggregator_config.wrapper_snark
    pp = aggregator_config.wrapper_pairing_parameters

    # Load the batch
    aggregated_tx = load_aggregated_transaction(wrapper_snark, batch_file)

    # Load the application instance address
    with open(application_instance_file, "r") as app_instance_f:
        app_instance = InstanceDescription.from_json_dict(
            json.load(app_instance_f))

    # Open the dispatcher client and submit the batch to it
    eth_addr, eth_private_key = cmd_ctx.get_eth_key_and_address()
    dispatcher_contract = cmd_ctx.get_dispatcher_contract()
    tx_id = dispatcher_contract.process_batch(
        pp, aggregated_tx, app_instance.address, eth_addr, eth_private_key)
    print(tx_id.hex())

    if wait:
        tx_receipt = cmd_ctx.get_web3().eth.waitForTransactionReceipt(
            tx_id, 10000)
        gas_used = tx_receipt.gasUsed
        status = tx_receipt.status
        print(f"(gasUsed={gas_used}, status={status})")
        if status != 1:
            raise ClickException("transaction failed")

        # This is kept for convenience during contract development. Can be
        # removed once the contract code is stable.
        dispatcher_contract.dump_logs(tx_receipt)
コード例 #7
0
ファイル: get.py プロジェクト: clearmatics/zecale
def get(ctx: Context, scalar: int, instance_file: str,
        check: Optional[int]) -> None:
    """
    Query the deployed contract to find the value stored for a given scalar.
    (These values are the parameters submitted along side the proof for the
    given scalar.)
    """

    eth_network = ctx.obj["eth_network"]

    # Load the contract instance
    with open(instance_file, "r") as instance_f:
        instance_desc = InstanceDescription.from_json_dict(
            json.load(instance_f))

    # Instantiate
    web3 = open_web3_from_network(eth_network)
    app_contract = instance_desc.instantiate(web3)
    result: int = app_contract.functions.get(scalar).call()
    print(f"{scalar}: {result}")

    if (check is not None) and (result != check):
        raise ClickException("state check failed")