diff --git a/commands/constants.py b/commands/constants.py index a6e9abb..a48fb46 100644 --- a/commands/constants.py +++ b/commands/constants.py @@ -7,12 +7,13 @@ Constants and defaults specific to the CLI interface. """ -ETH_RPC_ENDPOINT_DEFAULT = "http://localhost:8545" -PROVER_SERVER_ENDPOINT_DEFAULT = "localhost:50051" +FISCO_RPC_ENDPOINT_DEFAULT = "http://119.23.46.126:8545" +PROVER_SERVER_ENDPOINT_DEFAULT = "119.23.46.126:50051" +FISCO_ADDRESS_FILE = "keystore" ADDRESS_FILE_DEFAULT = "zeth-address.json" -INSTANCE_FILE_DEFAULT = "zeth-instance.json" -ETH_ADDRESS_DEFAULT = "eth-address" +#INSTANCE_FILE_DEFAULT = "zeth-instance.json" +#ETH_ADDRESS_DEFAULT = "eth-address" WALLET_DIR_DEFAULT = "./wallet" -WALLET_USERNAME = "zeth" +WALLET_USERNAME = "zbac" diff --git a/commands/utils.py b/commands/utils.py index 61c7655..43d48dd 100644 --- a/commands/utils.py +++ b/commands/utils.py @@ -9,13 +9,16 @@ InstanceDescription, get_block_number, get_mix_results, compile_files from zeth.mixer_client import MixerClient from zeth.utils import \ - open_web3, short_commitment, EtherValue, get_zeth_dir, from_zeth_units + short_commitment, EtherValue, get_zeth_dir, from_zeth_units from zeth.wallet import ZethNoteDescription, Wallet from click import ClickException import json from os.path import exists, join from typing import Dict, Tuple, Optional, Callable, Any -from web3 import Web3 # type: ignore +#from web3 import Web3 # type: ignore +from Groth16Mixer import Groth16Mixer +from bac import bac +from python_web3.client.bcoskeypair import BcosKeyPair #todo class ClientConfig: @@ -26,20 +29,20 @@ def __init__( self, eth_rpc_endpoint: str, prover_server_endpoint: str, - instance_file: str, + #instance_file: str, address_file: str, wallet_dir: str): self.eth_rpc_endpoint = eth_rpc_endpoint self.prover_server_endpoint = prover_server_endpoint - self.instance_file = instance_file + #self.instance_file = instance_file self.address_file = address_file self.wallet_dir = wallet_dir - +''' def open_web3_from_ctx(ctx: ClientConfig) -> Any: return open_web3(ctx.eth_rpc_endpoint) - - +''' +''' class MixerDescription: """ Holds an InstanceDescription for the mixer contract, and optionally an @@ -105,7 +108,7 @@ def load_mixer_description(mixer_description_file: str) -> MixerDescription: def load_mixer_description_from_ctx(ctx: ClientConfig) -> MixerDescription: return load_mixer_description(ctx.instance_file) - +''' def get_zeth_address_file(ctx: ClientConfig) -> str: return ctx.address_file @@ -170,25 +173,26 @@ def open_wallet( def do_sync( - web3: Any, + #web3: Any, wallet: Wallet, - wait_tx: Optional[str], + receipt: Any, + #wait_tx: Optional[str], callback: Optional[Callable[[ZethNoteDescription], None]] = None) -> int: """ Implementation of sync, reused by several commands. Returns the block_number synced to. Also updates and saves the MerkleTree. """ def _do_sync() -> int: - wallet_next_block = wallet.get_next_block() - chain_block_number: int = get_block_number(web3) + #wallet_next_block = wallet.get_next_block() + #chain_block_number: int = get_block_number(web3) - if chain_block_number >= wallet_next_block: - new_merkle_root: Optional[bytes] = None + #if chain_block_number >= wallet_next_block: + #new_merkle_root: Optional[bytes] = None - print(f"SYNCHING blocks ({wallet_next_block} - {chain_block_number})") + #print(f"SYNCHING blocks ({wallet_next_block} - {chain_block_number})") mixer_instance = wallet.mixer_instance for mix_result in get_mix_results( - web3, mixer_instance, wallet_next_block, chain_block_number): + mixer_instance, receipt): new_merkle_root = mix_result.new_merkle_root for note_desc in wallet.receive_notes(mix_result.output_events): if callback: @@ -198,26 +202,26 @@ def _do_sync() -> int: for commit in spent_commits: print(f" SPENT: {commit}") - wallet.update_and_save_state(next_block=chain_block_number + 1) + wallet.update_and_save_state() # Check merkle root and save the updated tree if new_merkle_root: our_merkle_root = wallet.merkle_tree.get_root() assert new_merkle_root == our_merkle_root - return chain_block_number + return new_merkle_root # Do a sync upfront (it would be a waste of time to wait for a tx before # syncing, as it can take time to traverse all blocks). Then wait for a tx # if requested, and sync again. - + ''' if wait_tx: _do_sync() tx_receipt = web3.eth.waitForTransactionReceipt(wait_tx, 10000) gas_used = tx_receipt.gasUsed status = tx_receipt.status print(f"{wait_tx[0:8]}: gasUsed={gas_used}, status={status}") - + ''' return _do_sync() @@ -241,7 +245,7 @@ def find_pub_address_file(base_file: str) -> str: raise ClickException(f"No public key file {pub_addr_file} or {base_file}") - +''' def create_mixer_client(ctx: ClientConfig) -> MixerClient: """ Create a MixerClient for an existing deployment. @@ -250,19 +254,32 @@ def create_mixer_client(ctx: ClientConfig) -> MixerClient: mixer_desc = load_mixer_description_from_ctx(ctx) mixer_instance = mixer_desc.mixer.instantiate(web3) return MixerClient.open(web3, ctx.prover_server_endpoint, mixer_instance) - +''' def create_zeth_client_and_mixer_desc( - ctx: ClientConfig) -> Tuple[MixerClient, MixerDescription]: + ctx: ClientConfig, mixer_addr: str, password: str) -> Tuple[MixerClient, MixerDescription]: """ Create a MixerClient and MixerDescription object, for an existing deployment. """ - web3 = open_web3_from_ctx(ctx) - mixer_desc = load_mixer_description_from_ctx(ctx) - mixer_instance = mixer_desc.mixer.instantiate(web3) + #web3 = open_web3_from_ctx(ctx) + #mixer_desc = load_mixer_description_from_ctx(ctx) + mixer_instance = Groth16Mixer(mixer_addr) + keystore_file = "pyaccount.keystore" + mixer_instance.client.keystore_file = "pyaccount.keystore" + if os.path.exists(keystore_file) is False: + raise ClickException(f"invalid output spec: {keystore_file}") + with open(keystore_file, "r") as dump_f: + keytext = json.load(dump_f) + privkey = Account.decrypt(keytext, password) + mixer_instance.client.ecdsa_account = Account.from_key(privkey) + keypair = BcosKeyPair() + keypair.private_key = mixer_instance.client.ecdsa_account.privateKey + keypair.public_key = mixer_instance.client.ecdsa_account.publickey + keypair.address = mixer_instance.client.ecdsa_account.address + mixer_instance.client.keypair = keypair zeth_client = MixerClient.open( - web3, ctx.prover_server_endpoint, mixer_instance) - return (zeth_client, mixer_desc) + ctx.prover_server_endpoint, mixer_instance) + return (zeth_client) def zeth_note_short(note_desc: ZethNoteDescription) -> str: @@ -288,7 +305,7 @@ def parse_output(output_str: str) -> Tuple[ZethAddressPub, EtherValue]: raise ClickException(f"invalid output spec: {output_str}") return (ZethAddressPub.parse(parts[0]), EtherValue(parts[1])) - +''' def load_eth_address(eth_addr: Optional[str]) -> str: """ Given an --eth-addr command line param, either parse the address, load from @@ -301,3 +318,4 @@ def load_eth_address(eth_addr: Optional[str]) -> str: with open(eth_addr, "r") as eth_addr_f: return Web3.toChecksumAddress(eth_addr_f.read().rstrip()) raise ClickException(f"could find file or parse eth address: {eth_addr}") +''' \ No newline at end of file diff --git a/commands/zeth b/commands/zeth index b39fb00..8c72482 100644 --- a/commands/zeth +++ b/commands/zeth @@ -5,8 +5,8 @@ # SPDX-License-Identifier: LGPL-3.0+ from commands.constants import \ - PROVER_SERVER_ENDPOINT_DEFAULT, INSTANCE_FILE_DEFAULT, \ - ADDRESS_FILE_DEFAULT, WALLET_DIR_DEFAULT, ETH_RPC_ENDPOINT_DEFAULT + PROVER_SERVER_ENDPOINT_DEFAULT, \ + ADDRESS_FILE_DEFAULT, WALLET_DIR_DEFAULT, FISCO_RPC_ENDPOINT_DEFAULT from commands.utils import ClientConfig from commands.zeth_deploy import deploy from commands.zeth_gen_address import gen_address @@ -35,16 +35,12 @@ def help(ctx: Context) -> None: @group(cls=DefaultGroup, default_if_no_args=True, default="help") @option( "--eth-rpc", - default=ETH_RPC_ENDPOINT_DEFAULT, + default=FISCO_RPC_ENDPOINT_DEFAULT, help=f"Ethereum rpc end-point") @option( "--prover-server", default=PROVER_SERVER_ENDPOINT_DEFAULT, help=f"Prover server endpoint (default={PROVER_SERVER_ENDPOINT_DEFAULT})") -@option( - "--instance-file", - default=INSTANCE_FILE_DEFAULT, - help=f"Instance file (default={INSTANCE_FILE_DEFAULT})") @option( "--address-file", default=ADDRESS_FILE_DEFAULT, @@ -58,7 +54,6 @@ def zeth( ctx: Context, eth_rpc: Optional[str], prover_server: str, - instance_file: str, address_file: str, wallet_dir: str) -> None: if ctx.invoked_subcommand == "help": @@ -67,7 +62,6 @@ def zeth( ctx.obj = ClientConfig( eth_rpc_endpoint=eth_rpc, prover_server_endpoint=prover_server, - instance_file=instance_file, address_file=address_file, wallet_dir=wallet_dir) diff --git a/commands/zeth_deploy.py b/commands/zeth_deploy.py index 054d6cc..7882900 100644 --- a/commands/zeth_deploy.py +++ b/commands/zeth_deploy.py @@ -1,53 +1,44 @@ # Copyright (c) 2015-2020 Clearmatics Technologies Ltd # # SPDX-License-Identifier: LGPL-3.0+ - -from commands.constants import INSTANCE_FILE_DEFAULT +''' from commands.utils import \ open_web3_from_ctx, get_erc20_instance_description, load_eth_address, \ write_mixer_description, MixerDescription from zeth.mixer_client import MixerClient from zeth.utils import EtherValue +''' from click import Context, command, option, pass_context from typing import Optional +import sys +sys.path.append('../') +from contract.Groth16Mixer import Groth16Mixer @command() -@option("--eth-addr", help="Sender eth address or address filename") -@option( - "--instance-out", - default=INSTANCE_FILE_DEFAULT, - help=f"File to write deployment address to (default={INSTANCE_FILE_DEFAULT})") -@option("--token-address", help="Address of token contract (if used)") -@option("--deploy-gas", help="Maximum gas, in Wei") +#@option("--eth-addr", help="Sender eth address or address filename") +#@option("--token-address", help="Address of token contract (if used)") @pass_context def deploy( - ctx: Context, - eth_addr: Optional[str], - instance_out: str, - token_address: str, - deploy_gas: str) -> None: + ctx: Context + #eth_addr: Optional[str], + ) -> None: """ Deploy the zeth contracts and record the instantiation details. """ - eth_address = load_eth_address(eth_addr) - client_ctx = ctx.obj - web3 = open_web3_from_ctx(client_ctx) - deploy_gas_value = EtherValue(deploy_gas, 'wei') if deploy_gas else None - - print(f"deploy: eth_address={eth_address}") - print(f"deploy: instance_out={instance_out}") - print(f"deploy: token_address={token_address}") + #eth_address = load_eth_address(eth_addr) + #client_ctx = ctx.obj + #web3 = open_web3_from_ctx(client_ctx) + #deploy_gas_value = EtherValue(deploy_gas, 'wei') if deploy_gas else None - token_instance_desc = get_erc20_instance_description(token_address) \ - if token_address else None + #print(f"deploy: eth_address={eth_address}") + #print(f"deploy: token_address={token_address}") - _zeth_client, mixer_instance_desc = MixerClient.deploy( - web3, - client_ctx.prover_server_endpoint, - eth_address, - token_address, - deploy_gas_value) + #token_instance = bac(token_address) \ + # if token_address else None + si = Groth16Mixer("") + result = si.deploy("contract/Groth16Mixer.bin") + address = result['contractAddress'] + print(f"deploy: mixer_address={address}") + #mixer_instance = Groth16Mixer(address) - mixer_desc = MixerDescription(mixer_instance_desc, token_instance_desc) - write_mixer_description(instance_out, mixer_desc) diff --git a/commands/zeth_ls_commits.py b/commands/zeth_ls_commits.py index d906271..099240b 100644 --- a/commands/zeth_ls_commits.py +++ b/commands/zeth_ls_commits.py @@ -5,17 +5,19 @@ from commands.utils import \ create_zeth_client_and_mixer_desc, load_zeth_address, open_wallet from zeth.utils import short_commitment -from click import Context, command, pass_context +from click import Context, command, pass_context, option @command() +@option("--mixer-addr", help="The Groth16Mixer contract address you want to use") +@option("--password", help="the password of you keystore") @pass_context -def ls_commits(ctx: Context) -> None: +def ls_commits(ctx: Context, mixer_addr:str, password: str) -> None: """ List all commitments in the joinsplit contract """ client_ctx = ctx.obj - zeth_client, _mixer_desc = create_zeth_client_and_mixer_desc(client_ctx) + zeth_client = create_zeth_client_and_mixer_desc(client_ctx, mixer_addr, password) zeth_address = load_zeth_address(client_ctx) wallet = open_wallet( zeth_client.mixer_instance, zeth_address.addr_sk, client_ctx) diff --git a/commands/zeth_ls_notes.py b/commands/zeth_ls_notes.py index 1178669..c1fe37d 100644 --- a/commands/zeth_ls_notes.py +++ b/commands/zeth_ls_notes.py @@ -2,24 +2,27 @@ # # SPDX-License-Identifier: LGPL-3.0+ -from commands.utils import open_web3_from_ctx, load_zeth_address_secret, \ - open_wallet, load_mixer_description_from_ctx +from commands.utils import load_zeth_address_secret, open_wallet from zeth.utils import EtherValue from click import Context, command, option, pass_context - +import sys +sys.path.append('../') +from Groth16Mixer import Groth16Mixer @command() +@option("--mixer-addr", help="The Groth16Mixer contract address you want to use") @option("--balance", is_flag=True, help="Show total balance") @option("--spent", is_flag=True, help="Show spent notes") @pass_context -def ls_notes(ctx: Context, balance: bool, spent: bool) -> None: +def ls_notes(ctx: Context, mixer_addr: str, balance: bool, spent: bool) -> None: """ List the set of notes owned by this wallet """ client_ctx = ctx.obj - web3 = open_web3_from_ctx(client_ctx) - mixer_desc = load_mixer_description_from_ctx(client_ctx) - mixer_instance = mixer_desc.mixer.instantiate(web3) + #web3 = open_web3_from_ctx(client_ctx) + #mixer_desc = load_mixer_description_from_ctx(client_ctx) + #mixer_instance = mixer_desc.mixer.instantiate(web3) + mixer_instance = Groth16Mixer(mixer_addr) js_secret = load_zeth_address_secret(client_ctx) wallet = open_wallet(mixer_instance, js_secret, client_ctx) diff --git a/commands/zeth_mix.py b/commands/zeth_mix.py index 44ee6a7..f697abb 100644 --- a/commands/zeth_mix.py +++ b/commands/zeth_mix.py @@ -3,30 +3,37 @@ # SPDX-License-Identifier: LGPL-3.0+ from commands.utils import create_zeth_client_and_mixer_desc, \ - load_zeth_address, open_wallet, parse_output, do_sync, load_eth_address + load_zeth_address, open_wallet, parse_output, do_sync from zeth.constants import JS_INPUTS, JS_OUTPUTS from zeth.mixer_client import ZethAddressPub from zeth.utils import EtherValue, from_zeth_units from api.zeth_messages_pb2 import ZethNote from click import command, option, pass_context, ClickException, Context from typing import List, Tuple, Optional - +import sys +sys.path.append('../') +from contract.Groth16Mixer import Groth16Mixer +from python_web3.eth_account.account import Account @command() +@option("--mixer-addr", help="The Groth16Mixer contract address you want to use") +@option("--password", help="the password of you keystore") @option("--vin", default="0", help="public in value") @option("--vout", default="0", help="public out value") @option("--in", "input_notes", multiple=True) @option("--out", "output_specs", multiple=True, help=",") -@option("--eth-addr", help="Sender eth address or address filename") +#@option("--eth-addr", help="Sender eth address or address filename") @option("--wait", is_flag=True) @pass_context def mix( ctx: Context, + mixer_addr: str, + password: str, vin: str, vout: str, input_notes: List[str], output_specs: List[str], - eth_addr: Optional[str], + #eth_addr: Optional[str], wait: bool) -> None: """ Generic mix function @@ -43,7 +50,8 @@ def mix( vin_pub = EtherValue(vin) vout_pub = EtherValue(vout) client_ctx = ctx.obj - zeth_client, mixer_desc = create_zeth_client_and_mixer_desc(client_ctx) + zeth_client = create_zeth_client_and_mixer_desc(client_ctx, mixer_addr, password) + zeth_address = load_zeth_address(client_ctx) wallet = open_wallet( zeth_client.mixer_instance, zeth_address.addr_sk, client_ctx) @@ -60,24 +68,22 @@ def mix( if vin_pub + input_note_sum != vout_pub + output_note_sum: raise ClickException("input and output value mismatch") - eth_address = load_eth_address(eth_addr) - + #eth_address = load_eth_address(eth_addr) + fisco_bcos_address = mixer_instance.client.ecdsa_account.address # If instance uses an ERC20 token, tx_value can be 0 not default vin_pub. - tx_value: Optional[EtherValue] = None - if mixer_desc.token: - tx_value = EtherValue(0) + tx_value: Optional[EtherValue] = EtherValue(0) + #if mixer_desc.token: + # tx_value = EtherValue(0) - tx_hash = zeth_client.joinsplit( + (outputresult, receipt) = zeth_client.joinsplit( wallet.merkle_tree, zeth_address.ownership_keypair(), - eth_address, + fisco_bcos_address, inputs, outputs, vin_pub, vout_pub, tx_value) - if wait: - do_sync(zeth_client.web3, wallet, tx_hash) - else: - print(tx_hash) + print("receipt output :", outputresult) + do_sync(wallet, receipt) \ No newline at end of file diff --git a/commands/zeth_token_approve.py b/commands/zeth_token_approve.py index 6954960..f228ae8 100644 --- a/commands/zeth_token_approve.py +++ b/commands/zeth_token_approve.py @@ -2,34 +2,50 @@ # # SPDX-License-Identifier: LGPL-3.0+ -from commands.utils import load_eth_address, open_web3_from_ctx, \ - load_mixer_description_from_ctx, EtherValue +from commands.utils import EtherValue from click import command, argument, option, pass_context, ClickException, Context - +import sys +sys.path.append('../') +from contract.Groth16Mixer import Groth16Mixer +from contract.ERC20Mintable import ERC20Mintable +from python_web3.eth_account.account import Account @command() @argument("tokens") -@option("--eth-addr", help="Sender eth address or address filename") +#@option("--eth-addr", help="Sender eth address or address filename") @option("--wait", is_flag=True, help="Wait for transaction to complete") +@option("--mixer-addr", help="The Groth16Mixer contract address you want to use") +@option("--ERC20Mintable-addr", help="The Groth16Mixer contract address you want to use") +@option("--password", help="the password of you keystore") @pass_context -def token_approve(ctx: Context, tokens: str, eth_addr: str, wait: bool) -> None: +def token_approve(ctx: Context, tokens: str, mixer_addr: str, ERC20Mintable_addr: str, password: str, wait: bool) -> None: """ Approve the mixer to spend some amount of tokens """ approve_value = EtherValue(tokens) - eth_addr = load_eth_address(eth_addr) - client_ctx = ctx.obj - web3 = open_web3_from_ctx(client_ctx) - mixer_desc = load_mixer_description_from_ctx(client_ctx) - if not mixer_desc.token: - raise ClickException("no token for mixer {mixer_desc.mixer.address}") + #eth_addr = load_eth_address(eth_addr) + #client_ctx = ctx.obj + #web3 = open_web3_from_ctx(client_ctx) + #mixer_desc = load_mixer_description_from_ctx(client_ctx) + #if not mixer_desc.token: + # raise ClickException("no token for mixer {mixer_desc.mixer.address}") - token_instance = mixer_desc.token.instantiate(web3) - tx_hash = token_instance.functions.approve( - mixer_desc.mixer.address, - approve_value.wei).transact({'from': eth_addr}) + token_instance = ERC20Mintable(ERC20Mintable_addr) + keystore_file = "pyaccount.keystore" + token_instance.client.keystore_file = "pyaccount.keystore" + if os.path.exists(keystore_file) is False: + raise ClickException(f"invalid output spec: {keystore_file}") + with open(keystore_file, "r") as dump_f: + keytext = json.load(dump_f) + privkey = Account.decrypt(keytext, password) + token_instance.client.ecdsa_account = Account.from_key(privkey) + keypair = BcosKeyPair() + keypair.private_key = token_instance.client.ecdsa_account.privateKey + keypair.public_key = token_instance.client.ecdsa_account.publickey + keypair.address = token_instance.client.ecdsa_account.address + token_instance.client.keypair = keypair + (outputresult, receipt) = token_instance.approve( + mixer_addr, + approve_value.wei) - if wait: - web3.eth.waitForTransactionReceipt(tx_hash) # pylint: disable=no-member - else: - print(tx_hash.hex()) + print("receipt output :", outputresult) \ No newline at end of file diff --git a/contract/ERC20Mintable.abi b/contract/ERC20Mintable.abi new file mode 100644 index 0000000..1ddb114 --- /dev/null +++ b/contract/ERC20Mintable.abi @@ -0,0 +1 @@ +[{"anonymous": false, "inputs": [{"indexed": true, "internalType": "address", "name": "owner", "type": "address"}, {"indexed": true, "internalType": "address", "name": "spender", "type": "address"}, {"indexed": false, "internalType": "uint256", "name": "value", "type": "uint256"}], "name": "Approval", "type": "event"}, {"anonymous": false, "inputs": [{"indexed": true, "internalType": "address", "name": "account", "type": "address"}], "name": "MinterAdded", "type": "event"}, {"anonymous": false, "inputs": [{"indexed": true, "internalType": "address", "name": "account", "type": "address"}], "name": "MinterRemoved", "type": "event"}, {"anonymous": false, "inputs": [{"indexed": true, "internalType": "address", "name": "from", "type": "address"}, {"indexed": true, "internalType": "address", "name": "to", "type": "address"}, {"indexed": false, "internalType": "uint256", "name": "value", "type": "uint256"}], "name": "Transfer", "type": "event"}, {"constant": false, "inputs": [{"internalType": "address", "name": "account", "type": "address"}], "name": "addMinter", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function"}, {"constant": true, "inputs": [{"internalType": "address", "name": "owner", "type": "address"}, {"internalType": "address", "name": "spender", "type": "address"}], "name": "allowance", "outputs": [{"internalType": "uint256", "name": "", "type": "uint256"}], "payable": false, "stateMutability": "view", "type": "function"}, {"constant": false, "inputs": [{"internalType": "address", "name": "spender", "type": "address"}, {"internalType": "uint256", "name": "amount", "type": "uint256"}], "name": "approve", "outputs": [{"internalType": "bool", "name": "", "type": "bool"}], "payable": false, "stateMutability": "nonpayable", "type": "function"}, {"constant": true, "inputs": [{"internalType": "address", "name": "account", "type": "address"}], "name": "balanceOf", "outputs": [{"internalType": "uint256", "name": "", "type": "uint256"}], "payable": false, "stateMutability": "view", "type": "function"}, {"constant": false, "inputs": [{"internalType": "address", "name": "spender", "type": "address"}, {"internalType": "uint256", "name": "subtractedValue", "type": "uint256"}], "name": "decreaseAllowance", "outputs": [{"internalType": "bool", "name": "", "type": "bool"}], "payable": false, "stateMutability": "nonpayable", "type": "function"}, {"constant": false, "inputs": [{"internalType": "address", "name": "spender", "type": "address"}, {"internalType": "uint256", "name": "addedValue", "type": "uint256"}], "name": "increaseAllowance", "outputs": [{"internalType": "bool", "name": "", "type": "bool"}], "payable": false, "stateMutability": "nonpayable", "type": "function"}, {"constant": true, "inputs": [{"internalType": "address", "name": "account", "type": "address"}], "name": "isMinter", "outputs": [{"internalType": "bool", "name": "", "type": "bool"}], "payable": false, "stateMutability": "view", "type": "function"}, {"constant": false, "inputs": [{"internalType": "address", "name": "account", "type": "address"}, {"internalType": "uint256", "name": "amount", "type": "uint256"}], "name": "mint", "outputs": [{"internalType": "bool", "name": "", "type": "bool"}], "payable": false, "stateMutability": "nonpayable", "type": "function"}, {"constant": false, "inputs": [], "name": "renounceMinter", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function"}, {"constant": true, "inputs": [], "name": "totalSupply", "outputs": [{"internalType": "uint256", "name": "", "type": "uint256"}], "payable": false, "stateMutability": "view", "type": "function"}, {"constant": false, "inputs": [{"internalType": "address", "name": "recipient", "type": "address"}, {"internalType": "uint256", "name": "amount", "type": "uint256"}], "name": "transfer", "outputs": [{"internalType": "bool", "name": "", "type": "bool"}], "payable": false, "stateMutability": "nonpayable", "type": "function"}, {"constant": false, "inputs": [{"internalType": "address", "name": "sender", "type": "address"}, {"internalType": "address", "name": "recipient", "type": "address"}, {"internalType": "uint256", "name": "amount", "type": "uint256"}], "name": "transferFrom", "outputs": [{"internalType": "bool", "name": "", "type": "bool"}], "payable": false, "stateMutability": "nonpayable", "type": "function"}] \ No newline at end of file diff --git a/contract/ERC20Mintable.bin b/contract/ERC20Mintable.bin new file mode 100644 index 0000000..46bc80d --- /dev/null +++ b/contract/ERC20Mintable.bin @@ -0,0 +1 @@ +608060405262000024620000186200002a60201b60201c565b6200003260201b60201c565b62000257565b600033905090565b6200004d8160036200009360201b620012a81790919060201c565b8073ffffffffffffffffffffffffffffffffffffffff167f6ae172837ea30b801fbfcdd4108aa1d5bf8ff775444fd70256b44e6bf3dfc3f660405160405180910390a250565b620000a582826200017760201b60201c565b1562000119576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601f8152602001807f526f6c65733a206163636f756e7420616c72656164792068617320726f6c650081525060200191505060405180910390fd5b60018260000160008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055505050565b60008073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff16141562000200576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526022815260200180620018506022913960400191505060405180910390fd5b8260000160008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16905092915050565b6115e980620002676000396000f3fe608060405234801561001057600080fd5b50600436106100b45760003560e01c8063983b2d5611610071578063983b2d56146102e7578063986502751461032b578063a457c2d714610335578063a9059cbb1461039b578063aa271e1a14610401578063dd62ed3e1461045d576100b4565b8063095ea7b3146100b957806318160ddd1461011f57806323b872dd1461013d57806339509351146101c357806340c10f191461022957806370a082311461028f575b600080fd5b610105600480360360408110156100cf57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506104d5565b604051808215151515815260200191505060405180910390f35b6101276104f3565b6040518082815260200191505060405180910390f35b6101a96004803603606081101561015357600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506104fd565b604051808215151515815260200191505060405180910390f35b61020f600480360360408110156101d957600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506105d6565b604051808215151515815260200191505060405180910390f35b6102756004803603604081101561023f57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610689565b604051808215151515815260200191505060405180910390f35b6102d1600480360360208110156102a557600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610704565b6040518082815260200191505060405180910390f35b610329600480360360208110156102fd57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919050505061074c565b005b6103336107bd565b005b6103816004803603604081101561034b57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506107cf565b604051808215151515815260200191505060405180910390f35b6103e7600480360360408110156103b157600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291908035906020019092919050505061089c565b604051808215151515815260200191505060405180910390f35b6104436004803603602081101561041757600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506108ba565b604051808215151515815260200191505060405180910390f35b6104bf6004803603604081101561047357600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506108d7565b6040518082815260200191505060405180910390f35b60006104e96104e261095e565b8484610966565b6001905092915050565b6000600254905090565b600061050a848484610b5d565b6105cb8461051661095e565b6105c6856040518060600160405280602881526020016114fd60289139600160008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600061057c61095e565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054610e139092919063ffffffff16565b610966565b600190509392505050565b600061067f6105e361095e565b8461067a85600160006105f461095e565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008973ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054610ed390919063ffffffff16565b610966565b6001905092915050565b600061069b61069661095e565b6108ba565b6106f0576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260308152602001806114ac6030913960400191505060405180910390fd5b6106fa8383610f5b565b6001905092915050565b60008060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b61075c61075761095e565b6108ba565b6107b1576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260308152602001806114ac6030913960400191505060405180910390fd5b6107ba81611116565b50565b6107cd6107c861095e565b611170565b565b60006108926107dc61095e565b8461088d85604051806060016040528060258152602001611590602591396001600061080661095e565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008a73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054610e139092919063ffffffff16565b610966565b6001905092915050565b60006108b06108a961095e565b8484610b5d565b6001905092915050565b60006108d08260036111ca90919063ffffffff16565b9050919050565b6000600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b600033905090565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1614156109ec576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602481526020018061156c6024913960400191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415610a72576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260228152602001806114646022913960400191505060405180910390fd5b80600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925836040518082815260200191505060405180910390a3505050565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415610be3576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260258152602001806115476025913960400191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415610c69576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260238152602001806114416023913960400191505060405180910390fd5b610cd481604051806060016040528060268152602001611486602691396000808773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054610e139092919063ffffffff16565b6000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550610d67816000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054610ed390919063ffffffff16565b6000808473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef836040518082815260200191505060405180910390a3505050565b6000838311158290610ec0576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825283818151815260200191508051906020019080838360005b83811015610e85578082015181840152602081019050610e6a565b50505050905090810190601f168015610eb25780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b5060008385039050809150509392505050565b600080828401905083811015610f51576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601b8152602001807f536166654d6174683a206164646974696f6e206f766572666c6f77000000000081525060200191505060405180910390fd5b8091505092915050565b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415610ffe576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601f8152602001807f45524332303a206d696e7420746f20746865207a65726f20616464726573730081525060200191505060405180910390fd5b61101381600254610ed390919063ffffffff16565b60028190555061106a816000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054610ed390919063ffffffff16565b6000808473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff16600073ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef836040518082815260200191505060405180910390a35050565b61112a8160036112a890919063ffffffff16565b8073ffffffffffffffffffffffffffffffffffffffff167f6ae172837ea30b801fbfcdd4108aa1d5bf8ff775444fd70256b44e6bf3dfc3f660405160405180910390a250565b61118481600361138390919063ffffffff16565b8073ffffffffffffffffffffffffffffffffffffffff167fe94479a9f7e1952cc78f2d6baab678adc1b772d936c6583def489e524cb6669260405160405180910390a250565b60008073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415611251576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260228152602001806115256022913960400191505060405180910390fd5b8260000160008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16905092915050565b6112b282826111ca565b15611325576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601f8152602001807f526f6c65733a206163636f756e7420616c72656164792068617320726f6c650081525060200191505060405180910390fd5b60018260000160008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055505050565b61138d82826111ca565b6113e2576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260218152602001806114dc6021913960400191505060405180910390fd5b60008260000160008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff021916908315150217905550505056fe45524332303a207472616e7366657220746f20746865207a65726f206164647265737345524332303a20617070726f766520746f20746865207a65726f206164647265737345524332303a207472616e7366657220616d6f756e7420657863656564732062616c616e63654d696e746572526f6c653a2063616c6c657220646f6573206e6f74206861766520746865204d696e74657220726f6c65526f6c65733a206163636f756e7420646f6573206e6f74206861766520726f6c6545524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e6365526f6c65733a206163636f756e7420697320746865207a65726f206164647265737345524332303a207472616e736665722066726f6d20746865207a65726f206164647265737345524332303a20617070726f76652066726f6d20746865207a65726f206164647265737345524332303a2064656372656173656420616c6c6f77616e63652062656c6f77207a65726fa265627a7a723158200bc878b43475e3971e822ce426de56a885c06df5280a7bfeed7fcc76dc165bef64736f6c63430005110032526f6c65733a206163636f756e7420697320746865207a65726f2061646472657373 \ No newline at end of file diff --git a/contract/ERC20Mintable.py b/contract/ERC20Mintable.py new file mode 100644 index 0000000..3daf82a --- /dev/null +++ b/contract/ERC20Mintable.py @@ -0,0 +1,121 @@ +# template for codegen +import sys +sys.path.append('../') +from python_web3.client.bcosclient import ( + BcosClient +) +from python_web3.client.datatype_parser import DatatypeParser +import json + +from python_web3.eth_utils import to_checksum_address + + +class ERC20Mintable: # name of abi + address = None + contract_abi_string = '''[{"anonymous": false, "inputs": [{"indexed": true, "internalType": "address", "name": "owner", "type": "address"}, {"indexed": true, "internalType": "address", "name": "spender", "type": "address"}, {"indexed": false, "internalType": "uint256", "name": "value", "type": "uint256"}], "name": "Approval", "type": "event", "topic": "0x8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925"}, {"anonymous": false, "inputs": [{"indexed": true, "internalType": "address", "name": "account", "type": "address"}], "name": "MinterAdded", "type": "event", "topic": "0x6ae172837ea30b801fbfcdd4108aa1d5bf8ff775444fd70256b44e6bf3dfc3f6"}, {"anonymous": false, "inputs": [{"indexed": true, "internalType": "address", "name": "account", "type": "address"}], "name": "MinterRemoved", "type": "event", "topic": "0xe94479a9f7e1952cc78f2d6baab678adc1b772d936c6583def489e524cb66692"}, {"anonymous": false, "inputs": [{"indexed": true, "internalType": "address", "name": "from", "type": "address"}, {"indexed": true, "internalType": "address", "name": "to", "type": "address"}, {"indexed": false, "internalType": "uint256", "name": "value", "type": "uint256"}], "name": "Transfer", "type": "event", "topic": "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"}, {"constant": false, "inputs": [{"internalType": "address", "name": "account", "type": "address"}], "name": "addMinter", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function"}, {"constant": true, "inputs": [{"internalType": "address", "name": "owner", "type": "address"}, {"internalType": "address", "name": "spender", "type": "address"}], "name": "allowance", "outputs": [{"internalType": "uint256", "name": "", "type": "uint256"}], "payable": false, "stateMutability": "view", "type": "function"}, {"constant": false, "inputs": [{"internalType": "address", "name": "spender", "type": "address"}, {"internalType": "uint256", "name": "amount", "type": "uint256"}], "name": "approve", "outputs": [{"internalType": "bool", "name": "", "type": "bool"}], "payable": false, "stateMutability": "nonpayable", "type": "function"}, {"constant": true, "inputs": [{"internalType": "address", "name": "account", "type": "address"}], "name": "balanceOf", "outputs": [{"internalType": "uint256", "name": "", "type": "uint256"}], "payable": false, "stateMutability": "view", "type": "function"}, {"constant": false, "inputs": [{"internalType": "address", "name": "spender", "type": "address"}, {"internalType": "uint256", "name": "subtractedValue", "type": "uint256"}], "name": "decreaseAllowance", "outputs": [{"internalType": "bool", "name": "", "type": "bool"}], "payable": false, "stateMutability": "nonpayable", "type": "function"}, {"constant": false, "inputs": [{"internalType": "address", "name": "spender", "type": "address"}, {"internalType": "uint256", "name": "addedValue", "type": "uint256"}], "name": "increaseAllowance", "outputs": [{"internalType": "bool", "name": "", "type": "bool"}], "payable": false, "stateMutability": "nonpayable", "type": "function"}, {"constant": true, "inputs": [{"internalType": "address", "name": "account", "type": "address"}], "name": "isMinter", "outputs": [{"internalType": "bool", "name": "", "type": "bool"}], "payable": false, "stateMutability": "view", "type": "function"}, {"constant": false, "inputs": [{"internalType": "address", "name": "account", "type": "address"}, {"internalType": "uint256", "name": "amount", "type": "uint256"}], "name": "mint", "outputs": [{"internalType": "bool", "name": "", "type": "bool"}], "payable": false, "stateMutability": "nonpayable", "type": "function"}, {"constant": false, "inputs": [], "name": "renounceMinter", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function"}, {"constant": true, "inputs": [], "name": "totalSupply", "outputs": [{"internalType": "uint256", "name": "", "type": "uint256"}], "payable": false, "stateMutability": "view", "type": "function"}, {"constant": false, "inputs": [{"internalType": "address", "name": "recipient", "type": "address"}, {"internalType": "uint256", "name": "amount", "type": "uint256"}], "name": "transfer", "outputs": [{"internalType": "bool", "name": "", "type": "bool"}], "payable": false, "stateMutability": "nonpayable", "type": "function"}, {"constant": false, "inputs": [{"internalType": "address", "name": "sender", "type": "address"}, {"internalType": "address", "name": "recipient", "type": "address"}, {"internalType": "uint256", "name": "amount", "type": "uint256"}], "name": "transferFrom", "outputs": [{"internalType": "bool", "name": "", "type": "bool"}], "payable": false, "stateMutability": "nonpayable", "type": "function"}]''' + contract_abi = None + data_parser = DatatypeParser() + client = None + + def __init__(self, address): + self.client = BcosClient() + self.address = address + self.contract_abi = json.loads(self.contract_abi_string) + self.data_parser.set_abi(self.contract_abi) + + def deploy(self, contract_bin_file): + result = self.client.deployFromFile(contract_bin_file) + self.address = result["contractAddress"] + return result + + # ------------------------------------------ + def addMinter(self, account): + func_name = 'addMinter' + args = [to_checksum_address(account)] + receipt = self.client.sendRawTransactionGetReceipt(self.address, self.contract_abi, func_name, args) + outputresult = self.data_parser.parse_receipt_output(func_name, receipt['output']) + return outputresult, receipt + + # ------------------------------------------ + def allowance(self, owner, spender): + func_name = 'allowance' + args = [to_checksum_address(owner), to_checksum_address(spender)] + result = self.client.call(self.address, self.contract_abi, func_name, args) + return result + + # ------------------------------------------ + def approve(self, spender, amount): + func_name = 'approve' + args = [to_checksum_address(spender), amount] + receipt = self.client.sendRawTransactionGetReceipt(self.address, self.contract_abi, func_name, args) + outputresult = self.data_parser.parse_receipt_output(func_name, receipt['output']) + return outputresult, receipt + + # ------------------------------------------ + def balanceOf(self, account): + func_name = 'balanceOf' + args = [to_checksum_address(account)] + result = self.client.call(self.address, self.contract_abi, func_name, args) + return result + + # ------------------------------------------ + def decreaseAllowance(self, spender, subtractedValue): + func_name = 'decreaseAllowance' + args = [to_checksum_address(spender), subtractedValue] + receipt = self.client.sendRawTransactionGetReceipt(self.address, self.contract_abi, func_name, args) + outputresult = self.data_parser.parse_receipt_output(func_name, receipt['output']) + return outputresult, receipt + + # ------------------------------------------ + def increaseAllowance(self, spender, addedValue): + func_name = 'increaseAllowance' + args = [to_checksum_address(spender), addedValue] + receipt = self.client.sendRawTransactionGetReceipt(self.address, self.contract_abi, func_name, args) + outputresult = self.data_parser.parse_receipt_output(func_name, receipt['output']) + return outputresult, receipt + + # ------------------------------------------ + def isMinter(self, account): + func_name = 'isMinter' + args = [to_checksum_address(account)] + result = self.client.call(self.address, self.contract_abi, func_name, args) + return result + + # ------------------------------------------ + def mint(self, account, amount): + func_name = 'mint' + args = [to_checksum_address(account), amount] + receipt = self.client.sendRawTransactionGetReceipt(self.address, self.contract_abi, func_name, args) + outputresult = self.data_parser.parse_receipt_output(func_name, receipt['output']) + return outputresult, receipt + + # ------------------------------------------ + def renounceMinter(self): + func_name = 'renounceMinter' + args = [] + receipt = self.client.sendRawTransactionGetReceipt(self.address, self.contract_abi, func_name, args) + outputresult = self.data_parser.parse_receipt_output(func_name, receipt['output']) + return outputresult, receipt + + # ------------------------------------------ + def totalSupply(self): + func_name = 'totalSupply' + args = [] + result = self.client.call(self.address, self.contract_abi, func_name, args) + return result + + # ------------------------------------------ + def transfer(self, recipient, amount): + func_name = 'transfer' + args = [to_checksum_address(recipient), amount] + receipt = self.client.sendRawTransactionGetReceipt(self.address, self.contract_abi, func_name, args) + outputresult = self.data_parser.parse_receipt_output(func_name, receipt['output']) + return outputresult, receipt + + # ------------------------------------------ + def transferFrom(self, sender, recipient, amount): + func_name = 'transferFrom' + args = [to_checksum_address(sender), to_checksum_address(recipient), amount] + receipt = self.client.sendRawTransactionGetReceipt(self.address, self.contract_abi, func_name, args) + outputresult = self.data_parser.parse_receipt_output(func_name, receipt['output']) + return outputresult, receipt diff --git a/contract/Groth16Mixer.abi b/contract/Groth16Mixer.abi new file mode 100644 index 0000000..0eec46b --- /dev/null +++ b/contract/Groth16Mixer.abi @@ -0,0 +1,18 @@ +[ +{"inputs": [{"internalType": "uint256", "name": "mk_depth", "type": "uint256"}, +{"internalType": "address", "name": "token", "type": "address"}, + {"internalType": "uint256[2]", "name": "Alpha", "type": "uint256[2]"}, + {"internalType": "uint256[2]", "name": "Beta1", "type": "uint256[2]"}, + {"internalType": "uint256[2]", "name": "Beta2", "type": "uint256[2]"}, + {"internalType": "uint256[2]", "name": "Delta1", "type": "uint256[2]"}, + {"internalType": "uint256[2]", "name": "Delta2", "type": "uint256[2]"}, + {"internalType": "uint256[]", "name": "ABC_coords", "type": "uint256[]"}], + "payable": false, "stateMutability": "nonpayable", "type": "constructor"}, + {"anonymous": false, "inputs": [{"indexed": false, "internalType": "string", "name": "message", "type": "string"}], "name": "LogDebug", "type": "event"}, + {"anonymous": false, "inputs": [{"indexed": false, "internalType": "bytes32", "name": "message", "type": "bytes32"}], "name": "LogDebug", "type": "event"}, + {"anonymous": false, "inputs": [{"indexed": false, "internalType": "bytes32", "name": "root", "type": "bytes32"}, + {"indexed": false, "internalType": "bytes32[2]", "name": "nullifiers", "type": "bytes32[2]"}, + {"indexed": false, "internalType": "bytes32[2]", "name": "commitments", "type": "bytes32[2]"}, + {"indexed": false, "internalType": "bytes[2]", "name": "ciphertexts", "type": "bytes[2]"}], + "name": "LogMix", "type": "event"}, {"constant": true, "inputs": [{"internalType": "uint256[9]", "name": "primary_inputs", "type": "uint256[9]"}], "name": "assemble_hsig", "outputs": [{"internalType": "bytes32", "name": "hsig", "type": "bytes32"}], "payable": false, "stateMutability": "pure", "type": "function"}, + {"constant": true, "inputs": [{"internalType": "uint256", "name": "index", "type": "uint256"}, {"internalType": "uint256[9]", "name": "primary_inputs", "type": "uint256[9]"}], "name": "assemble_nullifier", "outputs": [{"internalType": "bytes32", "name": "nf", "type": "bytes32"}], "payable": false, "stateMutability": "pure", "type": "function"}, {"constant": true, "inputs": [{"internalType": "uint256[9]", "name": "primary_inputs", "type": "uint256[9]"}], "name": "assemble_public_values", "outputs": [{"internalType": "uint256", "name": "vpub_in", "type": "uint256"}, {"internalType": "uint256", "name": "vpub_out", "type": "uint256"}], "payable": false, "stateMutability": "pure", "type": "function"}, {"constant": true, "inputs": [], "name": "get_constants", "outputs": [{"internalType": "uint256", "name": "js_in", "type": "uint256"}, {"internalType": "uint256", "name": "js_out", "type": "uint256"}, {"internalType": "uint256", "name": "num_inputs", "type": "uint256"}], "payable": false, "stateMutability": "pure", "type": "function"}, {"constant": false, "inputs": [{"internalType": "bytes32", "name": "commitment", "type": "bytes32"}], "name": "insert", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function"}, {"constant": false, "inputs": [{"internalType": "uint256[2]", "name": "a", "type": "uint256[2]"}, {"internalType": "uint256[4]", "name": "b", "type": "uint256[4]"}, {"internalType": "uint256[2]", "name": "c", "type": "uint256[2]"}, {"internalType": "uint256[4]", "name": "vk", "type": "uint256[4]"}, {"internalType": "uint256", "name": "sigma", "type": "uint256"}, {"internalType": "uint256[9]", "name": "input", "type": "uint256[9]"}, {"internalType": "bytes[2]", "name": "ciphertexts", "type": "bytes[2]"}], "name": "mix", "outputs": [], "payable": true, "stateMutability": "payable", "type": "function"}, {"constant": true, "inputs": [], "name": "token", "outputs": [{"internalType": "address", "name": "", "type": "address"}], "payable": false, "stateMutability": "view", "type": "function"}, {"constant": true, "inputs": [{"internalType": "address", "name": "from", "type": "address"}, {"internalType": "uint256", "name": "value", "type": "uint256"}, {"internalType": "bytes", "name": "data", "type": "bytes"}], "name": "tokenFallback", "outputs": [], "payable": false, "stateMutability": "pure", "type": "function"}] diff --git a/contract/Groth16Mixer.bin b/contract/Groth16Mixer.bin new file mode 100644 index 0000000..1b18255 --- /dev/null +++ b/contract/Groth16Mixer.bin @@ -0,0 +1 @@ +60806040523480156200001157600080fd5b50604051620025a4380380620025a4833981016040819052620000349162000479565b8787818060208114620000645760405162461bcd60e51b81526004016200005b9062000590565b60405180910390fd5b50620000786001600160e01b036200025a16565b50600080800154600081815264020000000060205260409020805460ff1916600117905564020000000280546001600160a01b0385166001600160a01b03199091161790559050505050604051806040016040528087600060028110620000db57fe5b6020020151815260200187600160028110620000f357fe5b602090810291909101519091528151640200000003559081015164020000000455604080516080808201835288518083528985015183860181905289518486018190528a87015160609586018190526402000000059390935564020000000691909155640200000007556402000000085582519081018352865180825287850151828601819052875194830185905294870151919092018190526402000000099190915564020000000a9290925564020000000b5564020000000c5560005b6002825181620001be57fe5b64020000000d54919004146200024b57640200000003600a016040518060400160405280848481518110620001ef57fe5b602002602001015181526020018484600101815181106200020c57fe5b602090810291909101810151909152825460018181018555600094855293829020835160029283029091019081559290910151919092015501620001b2565b5050505050505050506200064b565b60006401fffffffe81905563800000005b8015620002b357620002898283620002b760201b62000ef41760201c565b91506001196002820201826000826401ffffffff8110620002a657fe5b015550600290046200026b565b5050565b60007fdec937b7fa8db3de380427a8cc947bfab68514522c3439cfa2e99655098368146000527f30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f00000018284828282088381820984858383098683840909925060005b605a8112156200034f57602060002080600052868688838808089350868485099250868488858a878809090994505060010162000317565b508484868a88888808080898975050505050505050565b8051620003738162000626565b92915050565b600082601f8301126200038b57600080fd5b6002620003a26200039c82620005c9565b620005a2565b91508183856020840282011115620003b957600080fd5b60005b83811015620003e95781620003d288826200046c565b8452506020928301929190910190600101620003bc565b5050505092915050565b600082601f8301126200040557600080fd5b8151620004166200039c82620005e7565b915081818352602084019350602081019050838560208402820111156200043c57600080fd5b60005b83811015620003e957816200045588826200046c565b84525060209283019291909101906001016200043f565b8051620003738162000640565b6000806000806000806000806101a0898b0312156200049757600080fd5b6000620004a58b8b6200046c565b9850506020620004b88b828c0162000366565b9750506040620004cb8b828c0162000379565b9650506080620004de8b828c0162000379565b95505060c0620004f18b828c0162000379565b945050610100620005058b828c0162000379565b935050610140620005198b828c0162000379565b9250506101808901516001600160401b038111156200053757600080fd5b620005458b828c01620003f3565b9150509295985092959890939650565b600062000564601f8362000608565b7f496e76616c696420646570746820696e20426173654d65726b6c655472656500815260200192915050565b60208082528101620003738162000555565b6040518181016001600160401b0381118282101715620005c157600080fd5b604052919050565b60006001600160401b03821115620005e057600080fd5b5060200290565b60006001600160401b03821115620005fe57600080fd5b5060209081020190565b90815260200190565b60006001600160a01b03821662000373565b90565b620006318162000611565b81146200063d57600080fd5b50565b620006318162000623565b611f49806200065b6000396000f3fe60806040526004361061007b5760003560e01c806397e004891161004e57806397e0048914610126578063c0ee0b8a14610139578063f9eb943f14610159578063fc0c546a1461017d5761007b565b806305ceb93c146100805780631f40927c146100b65780632d287e43146100e4578063354d06fd14610106575b600080fd5b34801561008c57600080fd5b506100a061009b3660046113e9565b61019f565b6040516100ad9190611c7d565b60405180910390f35b3480156100c257600080fd5b506100d66100d136600461138e565b61022d565b6040516100ad929190611dbf565b3480156100f057600080fd5b506101046100ff3660046113ad565b610256565b005b34801561011257600080fd5b506100a061012136600461138e565b6102ad565b6101046101343660046112d5565b6102cc565b34801561014557600080fd5b50610104610154366004611270565b61043f565b34801561016557600080fd5b5061016e610526565b6040516100ad93929190611dcd565b34801561018957600080fd5b50610192610530565b6040516100ad9190611c2c565b6000600283106101ca5760405162461bcd60e51b81526004016101c190611ccf565b60405180910390fd5b60036001840102608081019060830160fd10156101f95760405162461bcd60e51b81526004016101c190611d1f565b610100830151607182011b60fd1c60006003858782016009811061021957fe5b6020020151901b9190910195945050505050565b610100015164e8d4a5100067ffffffffffffffff604f83901c8116820293600f9390931c160290565b6401ffffffff54640100000000116102805760405162461bcd60e51b81526004016101c190611d0f565b6401ffffffff80546001810182559063ffffffff8201908390600090839081106102a657fe5b0155505050565b61010081015160a09091015160031b6007600c9290921c919091160190565b6102d4610fa1565b6102df858483610543565b815160208084015160405160009360029361030693339390918f918f918f918d9101611bb8565b60408051601f198184030181529082905261032091611ba1565b602060405180830381855afa15801561033d573d6000803e3d6000fd5b5050506040513d601f19601f8201168201806040525061036091908101906113cb565b86516020880151604089015160608a015193945061037f9389866106a4565b61039b5760405162461bcd60e51b81526004016101c190611d8f565b6103a789898987610743565b6103c35760405162461bcd60e51b81526004016101c190611d5f565b6103cb610fa1565b6103d58582610860565b60006103e160026108ad565b90506103ec816108ee565b7f36ed7c3f2ecfb5a5226c478b034d33144c060afe361be291e948f861dcddc618818584886040516104219493929190611c8b565b60405180910390a16104328661090d565b5050505050505050505050565b610447610fbf565b6001600160a01b0384168152602081018390526040810182905281516000906018908490600390811061047657fe5b016020015184516001600160f81b031990911690911c60e01c90601090859060029081106104a057fe5b016020015185516001600160f81b031990911690911c60e01c90600890869060019081106104ca57fe5b016020015186516001600160f81b031990911690911c60e01c9086906000906104ef57fe5b01602001516001600160e01b031963ff00000060e092831c16929092019290920192909201901b1660609092019190915250505050565b6002908190600990565b640200000002546001600160a01b031681565b81516000908152640200000000602052604090205460ff166105775760405162461bcd60e51b81526004016101c190611d2f565b60005b60028110156105fd57600061058f828561019f565b6000818152640200000001602052604090205490915060ff16156105c55760405162461bcd60e51b81526004016101c190611cdf565b600081815264020000000160205260409020805460ff19166001179055808383600281106105ef57fe5b60200201525060010161057a565b50600060028285604051602001610615929190611b7b565b60408051601f198184030181529082905261062f91611ba1565b602060405180830381855afa15801561064c573d6000803e3d6000fd5b5050506040513d601f19601f8201168201806040525061066f91908101906113cb565b9050600061067c846102ad565b905080821461069d5760405162461bcd60e51b81526004016101c190611d3f565b5050505050565b60006106ae610ffa565b6107d05a038682528560208301528360408301526020608083016060846000600286f150604082018981528860208201526040816060836000600787f1506040836080856000600687f15060016040840152600260608401528560808401526040816060836000600787f150505060408101518151148015610737575060608101516020820151145b98975050505050505050565b60007f30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f000000161076e611018565b86518152602080880151828201528651604080840191909152878201516060808501919091528189015160808501528089015160a0850152875160c08501528783015160e0850152815160098082526101408201909352909290919082016101208038833901905050905060005b600981101561084457838682600981106107f257fe5b6020020151106108145760405162461bcd60e51b81526004016101c190611d7f565b85816009811061082057fe5b602002015182828151811061083157fe5b60209081029190910101526001016107dc565b5061084f8183610b60565b60011493505050505b949350505050565b60005b60028110156108a857600083826001016009811061087d57fe5b602002015190508083836002811061089157fe5b602002015261089f81610256565b50600101610863565b505050565b6401ffffffff546000908281036401000000005b60018111156108e2576108d5818385610e2b565b93509150600290046108c1565b50506000549392505050565b600090815264020000000060205260409020805460ff19166001179055565b6000806109198361022d565b909250905081156109cf57640200000002546001600160a01b0316156109ab57640200000002546040516323b872dd60e01b81526001600160a01b039091169081906323b872dd9061097390339030908890600401611c3a565b600060405180830381600087803b15801561098d57600080fd5b505af11580156109a1573d6000803e3d6000fd5b50505050506109ca565b8134146109ca5760405162461bcd60e51b81526004016101c190611d6f565b610a53565b3415610a53576000336001600160a01b0316346040516109ee90611bad565b60006040518083038185875af1925050503d8060008114610a2b576040519150601f19603f3d011682016040523d82523d6000602084013e610a30565b606091505b5050905080610a515760405162461bcd60e51b81526004016101c190611cef565b505b80156108a857640200000002546001600160a01b031615610ade576402000000025460405163a9059cbb60e01b81526001600160a01b0390911690819063a9059cbb90610aa69033908690600401611c62565b600060405180830381600087803b158015610ac057600080fd5b505af1158015610ad4573d6000803e3d6000fd5b50505050506108a8565b6000336001600160a01b031682604051610af790611bad565b60006040518083038185875af1925050503d8060008114610b34576040519150601f19603f3d011682016040523d82523d6000602084013e610b39565b606091505b5050905080610b5a5760405162461bcd60e51b81526004016101c190611cff565b50505050565b64020000000d548251600091600190910114610b8e5760405162461bcd60e51b81526004016101c190611d4f565b610b9661105d565b60016107d05a03600a6402000000030183526020832060208701875160200281018254865260018301546020870152600283019250604086015b81831015610c1e57835481526001840154602082015282516040820152604081606083600060078af160408860808a600060068bf11695909516946002939093019260209290920191610bd0565b505050505080610c405760405162461bcd60e51b81526004016101c190611daf565b7f198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c260408301527f1800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed60608301527f090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b60808301527f12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa60a08301526402000000035460c08301526001640200000003015460e08301526002640200000003015461010083015260036402000000030154610120830152600464020000000301546101408301526005640200000003015461016083015283516101808301527f30644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd47602085015181810682036101a085015260408601516101c085015260608601516101e0850152608086015161020085015260a086015161022085015260c086015161024085015260e086015161026085015260066402000000030154610280850152600764020000000301546102a0850152600864020000000301546102c0850152600964020000000301546102e085015260208461030086600060086107d05a03f19250505080610e205760405162461bcd60e51b81526004016101c190611d9f565b505190505b92915050565b600080600019808601906001198616870101826001861615610e9f575060001982860101610e806000826401ffffffff8110610e6357fe5b01546000856002026401ffffffff8110610e7957fe5b0154610ef4565b600060026000198401046401ffffffff8110610e9857fe5b0155610ea4565b508185015b81811115610eda5760011901610e806000826401ffffffff8110610ec457fe5b01546000836001016401ffffffff8110610e7957fe5b600287046002600188010494509450505050935093915050565b60007fdec937b7fa8db3de380427a8cc947bfab68514522c3439cfa2e99655098368146000527f30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f00000018284828282088381820984858383098683840909925060005b605a811215610f8a57602060002080600052868688838808089350868485099250868488858a8788090909945050600101610f54565b508484868a88888808080898975050505050505050565b60405180604001604052806002906020820280388339509192915050565b604051806080016040528060006001600160a01b03168152602001600081526020016060815260200160006001600160e01b03191681525090565b6040518060a001604052806005906020820280388339509192915050565b60405180610100016040528060008152602001600081526020016000815260200160008152602001600081526020016000815260200160008152602001600081525090565b6040518061030001604052806018906020820280388339509192915050565b8035610e2581611ee6565b600082601f83011261109857600080fd5b60026110ab6110a682611e0f565b611de8565b9150818360005b838110156110de57813586016110c88882611221565b84525060209283019291909101906001016110b2565b5050505092915050565b600082601f8301126110f957600080fd5b60026111076110a682611e0f565b9150818385602084028201111561111d57600080fd5b60005b838110156110de5781611133888261120b565b8452506020928301929190910190600101611120565b600082601f83011261115a57600080fd5b60046111686110a682611e0f565b9150818385602084028201111561117e57600080fd5b60005b838110156110de5781611194888261120b565b8452506020928301929190910190600101611181565b600082601f8301126111bb57600080fd5b60096111c96110a682611e0f565b915081838560208402820111156111df57600080fd5b60005b838110156110de57816111f5888261120b565b84525060209283019291909101906001016111e2565b8035610e2581611efd565b8051610e2581611efd565b600082601f83011261123257600080fd5b81356112406110a682611e2d565b9150808252602083016020830185838301111561125c57600080fd5b611267838284611ea4565b50505092915050565b60008060006060848603121561128557600080fd5b6000611291868661107c565b93505060206112a28682870161120b565b925050604084013567ffffffffffffffff8111156112bf57600080fd5b6112cb86828701611221565b9150509250925092565b60008060008060008060006102e0888a0312156112f157600080fd5b60006112fd8a8a6110e8565b975050604061130e8a828b01611149565b96505060c061131f8a828b016110e8565b9550506101006113318a828b01611149565b9450506101806113438a828b0161120b565b9350506101a06113558a828b016111aa565b9250506102c088013567ffffffffffffffff81111561137357600080fd5b61137f8a828b01611087565b91505092959891949750929550565b600061012082840312156113a157600080fd5b600061085884846111aa565b6000602082840312156113bf57600080fd5b6000610858848461120b565b6000602082840312156113dd57600080fd5b60006108588484611216565b60008061014083850312156113fd57600080fd5b6000611409858561120b565b925050602061141a858286016111aa565b9150509250929050565b60006114308383611655565b505060200190565b6000611444838361168d565b9392505050565b61145481611e93565b82525050565b61145481611e82565b61146c81611e58565b6114768184611e74565b925061148182611e55565b8060005b838110156114af5781516114998782611424565b96506114a483611e6e565b925050600101611485565b505050505050565b6114c081611e58565b6114ca8184611e74565b92506114d582611e55565b8060005b838110156114af5781516114ed8782611424565b96506114f883611e6e565b9250506001016114d9565b600061150e82611e58565b6115188185611e74565b93508360208202850161152a85611e55565b8060005b8581101561156457848403895281516115478582611438565b945061155283611e6e565b60209a909a019992505060010161152e565b5091979650505050505050565b61157a81611e58565b6115848184611e74565b925061158f82611e55565b8060005b838110156114af5781516115a78782611424565b96506115b283611e6e565b925050600101611593565b6115c681611e5e565b6115d08184611e74565b92506115db82611e55565b8060005b838110156114af5781516115f38782611424565b96506115fe83611e6e565b9250506001016115df565b61161281611e64565b61161c8184611e74565b925061162782611e55565b8060005b838110156114af57815161163f8782611424565b965061164a83611e6e565b92505060010161162b565b61145481611e55565b600061166982611e6a565b6116738185611e74565b9350611683818560208601611eb0565b9290920192915050565b600061169882611e6a565b6116a28185611e79565b93506116b2818560208601611eb0565b6116bb81611edc565b9093019392505050565b60006116d2601883611e79565b7f6e756c6c696669657220696e646578206f766572666c6f770000000000000000815260200192915050565b600061170b603783611e79565b7f496e76616c6964206e756c6c69666965723a2054686973206e756c6c6966696581527f722068617320616c7265616479206265656e2075736564000000000000000000602082015260400192915050565b600061176a601e83611e79565b7f767075625f696e2072657475726e207472616e73666572206661696c65640000815260200192915050565b60006117a3601883611e79565b7f767075625f6f7574207472616e73666572206661696c65640000000000000000815260200192915050565b60006117dc602783611e79565b7f4d65726b6c6520747265652066756c6c3a2043616e6e6f7420617070656e6420815266616e796d6f726560c81b602082015260400192915050565b6000611825603083611e79565b7f6e756c6c6966696572207772697474656e20696e20646966666572656e74207281526f32b9b4b23ab0b6103134ba103317329760811b602082015260400192915050565b6000611877602583611e79565b7f496e76616c696420726f6f743a205468697320726f6f7420646f65736e277420815264195e1a5cdd60da1b602082015260400192915050565b60006118be604983611e79565b7f496e76616c696420687369673a2054686973206873696720646f6573206e6f7481527f20636f72726573706f6e6420746f207468652068617368206f6620766b20616e6020820152686420746865206e667360b81b604082015260600192915050565b600061192f602283611e79565b7f496e707574206c656e67746820646966666572732066726f6d20657870656374815261195960f21b602082015260400192915050565b6000611973603383611e79565b7f496e76616c69642070726f6f663a20556e61626c6520746f20766572696679208152727468652070726f6f6620636f72726563746c7960681b602082015260400192915050565b60006119c8602a83611e79565b7f57726f6e67206d73672e76616c75653a2056616c75652070616964206973206e8152691bdd0818dbdc9c9958dd60b21b602082015260400192915050565b6000611a14601c83611e79565b7f496e707574206973206e6f7420696e207363616c6172206669656c6400000000815260200192915050565b6000611a4d603b83611e79565b7f496e76616c6964207369676e61747572653a20556e61626c6520746f2076657281527f69667920746865207369676e617475726520636f72726563746c790000000000602082015260400192915050565b6000610e25600083611e74565b6000611ab9603783611e79565b7f43616c6c20746f20626e3235364164642c20626e3235365363616c61724d756c81527f206f7220626e32353650616972696e67206661696c6564000000000000000000602082015260400192915050565b6000611b18603983611e79565b7f43616c6c20746f2074686520626e323536416464206f7220626e32353653636181527f6c61724d756c20707265636f6d70696c6564206661696c656400000000000000602082015260400192915050565b611454611b7682611e55565b611e55565b6000611b8782856114b7565b604082019150611b9782846115bd565b5060800192915050565b6000611444828461165e565b6000610e2582611a9f565b6000611bc4828a611b6a565b602082019150611bd4828961165e565b9150611be0828861165e565b9150611bec8287611571565b604082019150611bfc82866115bd565b608082019150611c0c8285611571565b604082019150611c1c8284611609565b5061012001979650505050505050565b60208101610e25828461145a565b60608101611c48828661144b565b611c55602083018561145a565b6108586040830184611655565b60408101611c70828561144b565b6114446020830184611655565b60208101610e258284611655565b60c08101611c998287611655565b611ca66020830186611463565b611cb36060830185611463565b81810360a0830152611cc58184611503565b9695505050505050565b60208082528101610e25816116c5565b60208082528101610e25816116fe565b60208082528101610e258161175d565b60208082528101610e2581611796565b60208082528101610e25816117cf565b60208082528101610e2581611818565b60208082528101610e258161186a565b60208082528101610e25816118b1565b60208082528101610e2581611922565b60208082528101610e2581611966565b60208082528101610e25816119bb565b60208082528101610e2581611a07565b60208082528101610e2581611a40565b60208082528101610e2581611aac565b60208082528101610e2581611b0b565b60408101611c708285611655565b60608101611ddb8286611655565b611c556020830185611655565b60405181810167ffffffffffffffff81118282101715611e0757600080fd5b604052919050565b600067ffffffffffffffff821115611e2657600080fd5b5060200290565b600067ffffffffffffffff821115611e4457600080fd5b506020601f91909101601f19160190565b90565b50600290565b50600490565b50600990565b5190565b60200190565b919050565b90815260200190565b60006001600160a01b038216610e25565b6000610e25826000610e2582611e82565b82818337506000910152565b60005b83811015611ecb578181015183820152602001611eb3565b83811115610b5a5750506000910152565b601f01601f191690565b611eef81611e82565b8114611efa57600080fd5b50565b611eef81611e5556fea365627a7a72315820e42326a4694c17436c7722fd4a82ac810b74162de26e7fd1035ac3ef5d5a29d16c6578706572696d656e74616cf564736f6c63430005110040 \ No newline at end of file diff --git a/contract/Groth16Mixer.py b/contract/Groth16Mixer.py new file mode 100644 index 0000000..d66d676 --- /dev/null +++ b/contract/Groth16Mixer.py @@ -0,0 +1,86 @@ +# template for codegen + +from python_web3.client.bcosclient import ( + BcosClient +) +from python_web3.client.datatype_parser import DatatypeParser +import json + +from python_web3.eth_utils import to_checksum_address + + +class Groth16Mixer: # name of abi + address = None + contract_abi_string = '''[{"inputs": [{"internalType": "uint256", "name": "mk_depth", "type": "uint256"}, {"internalType": "address", "name": "token", "type": "address"}, {"internalType": "uint256[2]", "name": "Alpha", "type": "uint256[2]"}, {"internalType": "uint256[2]", "name": "Beta1", "type": "uint256[2]"}, {"internalType": "uint256[2]", "name": "Beta2", "type": "uint256[2]"}, {"internalType": "uint256[2]", "name": "Delta1", "type": "uint256[2]"}, {"internalType": "uint256[2]", "name": "Delta2", "type": "uint256[2]"}, {"internalType": "uint256[]", "name": "ABC_coords", "type": "uint256[]"}], "payable": false, "stateMutability": "nonpayable", "type": "constructor"}, {"anonymous": false, "inputs": [{"indexed": false, "internalType": "string", "name": "message", "type": "string"}], "name": "LogDebug", "type": "event", "topic": "0xd44da6836c8376d1693e8b9cacf1c39b9bed3599164ad6d8e60902515f83938e"}, {"anonymous": false, "inputs": [{"indexed": false, "internalType": "bytes32", "name": "message", "type": "bytes32"}], "name": "LogDebug", "type": "event", "topic": "0x05e46912c9be87d8a6830598db8544b61884d9d22f3921597a9a6e8a340914b3"}, {"anonymous": false, "inputs": [{"indexed": false, "internalType": "bytes32", "name": "root", "type": "bytes32"}, {"indexed": false, "internalType": "bytes32[2]", "name": "nullifiers", "type": "bytes32[2]"}, {"indexed": false, "internalType": "bytes32[2]", "name": "commitments", "type": "bytes32[2]"}, {"indexed": false, "internalType": "bytes[2]", "name": "ciphertexts", "type": "bytes[2]"}], "name": "LogMix", "type": "event", "topic": "0x36ed7c3f2ecfb5a5226c478b034d33144c060afe361be291e948f861dcddc618"}, {"constant": true, "inputs": [{"internalType": "uint256[9]", "name": "primary_inputs", "type": "uint256[9]"}], "name": "assemble_hsig", "outputs": [{"internalType": "bytes32", "name": "hsig", "type": "bytes32"}], "payable": false, "stateMutability": "pure", "type": "function"}, {"constant": true, "inputs": [{"internalType": "uint256", "name": "index", "type": "uint256"}, {"internalType": "uint256[9]", "name": "primary_inputs", "type": "uint256[9]"}], "name": "assemble_nullifier", "outputs": [{"internalType": "bytes32", "name": "nf", "type": "bytes32"}], "payable": false, "stateMutability": "pure", "type": "function"}, {"constant": true, "inputs": [{"internalType": "uint256[9]", "name": "primary_inputs", "type": "uint256[9]"}], "name": "assemble_public_values", "outputs": [{"internalType": "uint256", "name": "vpub_in", "type": "uint256"}, {"internalType": "uint256", "name": "vpub_out", "type": "uint256"}], "payable": false, "stateMutability": "pure", "type": "function"}, {"constant": true, "inputs": [], "name": "get_constants", "outputs": [{"internalType": "uint256", "name": "js_in", "type": "uint256"}, {"internalType": "uint256", "name": "js_out", "type": "uint256"}, {"internalType": "uint256", "name": "num_inputs", "type": "uint256"}], "payable": false, "stateMutability": "pure", "type": "function"}, {"constant": false, "inputs": [{"internalType": "bytes32", "name": "commitment", "type": "bytes32"}], "name": "insert", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function"}, {"constant": false, "inputs": [{"internalType": "uint256[2]", "name": "a", "type": "uint256[2]"}, {"internalType": "uint256[4]", "name": "b", "type": "uint256[4]"}, {"internalType": "uint256[2]", "name": "c", "type": "uint256[2]"}, {"internalType": "uint256[4]", "name": "vk", "type": "uint256[4]"}, {"internalType": "uint256", "name": "sigma", "type": "uint256"}, {"internalType": "uint256[9]", "name": "input", "type": "uint256[9]"}, {"internalType": "bytes[2]", "name": "ciphertexts", "type": "bytes[2]"}], "name": "mix", "outputs": [], "payable": true, "stateMutability": "payable", "type": "function"}, {"constant": true, "inputs": [], "name": "token", "outputs": [{"internalType": "address", "name": "", "type": "address"}], "payable": false, "stateMutability": "view", "type": "function"}, {"constant": true, "inputs": [{"internalType": "address", "name": "from", "type": "address"}, {"internalType": "uint256", "name": "value", "type": "uint256"}, {"internalType": "bytes", "name": "data", "type": "bytes"}], "name": "tokenFallback", "outputs": [], "payable": false, "stateMutability": "pure", "type": "function"}]''' + contract_abi = None + data_parser = DatatypeParser() + client = None + + def __init__(self, address): + self.client = BcosClient() + self.address = address + self.contract_abi = json.loads(self.contract_abi_string) + self.data_parser.set_abi(self.contract_abi) + + def deploy(self, contract_bin_file): + result = self.client.deployFromFile(contract_bin_file) + self.address = result["contractAddress"] + return result + + # ------------------------------------------ + def assemble_hsig(self, primary_inputs): + func_name = 'assemble_hsig' + args = [primary_inputs] + result = self.client.call(self.address, self.contract_abi, func_name, args) + return result + + # ------------------------------------------ + def assemble_nullifier(self, index, primary_inputs): + func_name = 'assemble_nullifier' + args = [index, primary_inputs] + result = self.client.call(self.address, self.contract_abi, func_name, args) + return result + + # ------------------------------------------ + def assemble_public_values(self, primary_inputs): + func_name = 'assemble_public_values' + args = [primary_inputs] + result = self.client.call(self.address, self.contract_abi, func_name, args) + return result + + # ------------------------------------------ + def get_constants(self): + func_name = 'get_constants' + args = [] + result = self.client.call(self.address, self.contract_abi, func_name, args) + return result + + # ------------------------------------------ + def insert(self, commitment): + func_name = 'insert' + args = [commitment] + receipt = self.client.sendRawTransactionGetReceipt(self.address, self.contract_abi, func_name, args) + outputresult = self.data_parser.parse_receipt_output(func_name, receipt['output']) + return outputresult, receipt + + # ------------------------------------------ + def mix(self, a, b, c, vk, sigma, input, ciphertexts): + func_name = 'mix' + args = [a, b, c, vk, sigma, input, ciphertexts] + receipt = self.client.sendRawTransactionGetReceipt(self.address, self.contract_abi, func_name, args) + outputresult = self.data_parser.parse_receipt_output(func_name, receipt['output']) + return outputresult, receipt + + # ------------------------------------------ + def token(self): + func_name = 'token' + args = [] + result = self.client.call(self.address, self.contract_abi, func_name, args) + return result + + # ------------------------------------------ + def tokenFallback(self, from1, value, data): + func_name = 'tokenFallback' + args = [to_checksum_address(from1), value, data] + result = self.client.call(self.address, self.contract_abi, func_name, args) + return result diff --git a/contract/__init__.py b/contract/__init__.py new file mode 100644 index 0000000..b6e016d --- /dev/null +++ b/contract/__init__.py @@ -0,0 +1,3 @@ +# Copyright (c) 2015-2020 Clearmatics Technologies Ltd +# +# SPDX-License-Identifier: LGPL-3.0+ diff --git a/python_web3 b/python_web3 new file mode 160000 index 0000000..7841309 --- /dev/null +++ b/python_web3 @@ -0,0 +1 @@ +Subproject commit 78413090e8b825b8b38fc27a9e775e6dc1028dd8 diff --git a/test_commands/deploy_test_token.py b/test_commands/deploy_test_token.py index 141c53b..18058f7 100644 --- a/test_commands/deploy_test_token.py +++ b/test_commands/deploy_test_token.py @@ -5,14 +5,14 @@ from zeth.contracts import Interface from zeth.utils import get_zeth_dir from zeth.constants import SOL_COMPILER_VERSION -from test_commands.mock import open_test_web3 +#from test_commands.mock import open_test_web3 from click import command, argument from os.path import join from solcx import compile_files, set_solc_version from typing import Any from web3 import Web3 # type: ignore - +''' @command() @argument("deployer_address") @argument("mint_amount", type=int) @@ -31,8 +31,8 @@ def deploy_test_token( token_instance, recipient_address, deployer_address, mint_amount) eth.waitForTransactionReceipt(mint_tx_hash) print(token_instance.address) - - +''' +''' def compile_token() -> Interface: """ Compile the testing ERC20 token contract @@ -51,8 +51,8 @@ def compile_token() -> Interface: compiled_sol = compile_files([path_to_token], allow_paths=allowed_path) token_interface = compiled_sol[path_to_token + ":ERC20Mintable"] return token_interface - - +''' +''' def deploy_token( eth: Any, deployer_address: str, @@ -72,16 +72,16 @@ def deploy_token( abi=token_interface['abi'], ) return token - +''' def mint_token( token_instance: Any, spender_address: str, deployer_address: str, token_amount: int) -> bytes: - return token_instance.functions.mint( + return token_instance.mint( spender_address, - Web3.toWei(token_amount, 'ether')).transact({'from': deployer_address}) + Web3.toWei(token_amount, 'ether')) if __name__ == "__main__": diff --git a/test_commands/mock.py b/test_commands/mock.py index 08c2c3b..8a17e08 100644 --- a/test_commands/mock.py +++ b/test_commands/mock.py @@ -8,23 +8,23 @@ from zeth.encryption import EncryptionKeyPair, decode_encryption_secret_key, \ decode_encryption_public_key from zeth.ownership import gen_ownership_keypair -from zeth.utils import get_contracts_dir, open_web3 +from zeth.utils import get_contracts_dir from os.path import join from solcx import compile_files # type: ignore from typing import Dict, List, Tuple, Optional, Any # Web3 HTTP provider -TEST_PROVER_SERVER_ENDPOINT: str = "localhost:50051" -TEST_WEB3_PROVIDER_ENDPOINT: str = "http://localhost:8545" +TEST_PROVER_SERVER_ENDPOINT: str = "119.23.46.126:50051" +#TEST_WEB3_PROVIDER_ENDPOINT: str = "http://localhost:8545" TEST_NOTE_DIR: str = "_test_notes" KeyStore = Dict[str, ZethAddress] - +''' def open_test_web3() -> Tuple[Any, Any]: web3 = open_web3(TEST_WEB3_PROVIDER_ENDPOINT) return web3, web3.eth # pylint: disable=no-member # type: ignore - +''' def init_test_keystore() -> KeyStore: """ diff --git a/test_commands/scenario.py b/test_commands/scenario.py index e0ab942..46a81f7 100644 --- a/test_commands/scenario.py +++ b/test_commands/scenario.py @@ -17,7 +17,7 @@ from os import urandom from web3 import Web3 # type: ignore -from typing import List, Tuple, Optional +from typing import List, Tuple, Optional, Any ZERO_UNITS_HEX = "0000000000000000" BOB_DEPOSIT_ETH = 200 @@ -36,16 +36,26 @@ def dump_merkle_tree(mk_tree: List[bytes]) -> None: for node in mk_tree: print("Node: " + Web3.toHex(node)[2:]) +def _event_args_to_mix_result(event_args: Any) -> contracts.MixResult: + mix_out_args = zip(event_args.commitments, event_args.ciphertexts) + out_events = [contracts.MixOutputEvents(c, ciph) for (c, ciph) in mix_out_args] + return contracts.MixResult( + new_merkle_root=event_args.root, + nullifiers=event_args.nullifiers, + output_events=out_events) def wait_for_tx_update_mk_tree( zeth_client: MixerClient, mk_tree: MerkleTree, - tx_hash: str) -> contracts.MixResult: - tx_receipt = zeth_client.web3.eth.waitForTransactionReceipt(tx_hash, 10000) - result = contracts.parse_mix_call(zeth_client.mixer_instance, tx_receipt) + receipt: Any) -> contracts.MixResult: + #tx_receipt = zeth_client.web3.eth.waitForTransactionReceipt(tx_hash, 10000) + #result = contracts.parse_mix_call(zeth_client.mixer_instance, tx_receipt) + logresult = zeth_client.mixer_instance.data_parser.parse_event_logs(receipt["logs"]) + print(logresult) + log = logresult[0] + result = _event_args_to_mix_result(log['eventdata']) for out_ev in result.output_events: mk_tree.insert(out_ev.commitment) - if mk_tree.recompute_root() != result.new_merkle_root: raise Exception("Merkle root mismatch between log and local tree") return result @@ -69,16 +79,16 @@ def bob_deposit( (bob_addr, EtherValue(BOB_SPLIT_2_ETH)), ] - tx_hash = zeth_client.deposit( + (outputresult, receipt) = zeth_client.deposit( mk_tree, bob_js_keypair, bob_eth_address, EtherValue(BOB_DEPOSIT_ETH), outputs, tx_value) - return wait_for_tx_update_mk_tree(zeth_client, mk_tree, tx_hash) - + return wait_for_tx_update_mk_tree(zeth_client, mk_tree, receipt) +''' def bob_to_charlie( zeth_client: MixerClient, mk_tree: MerkleTree, @@ -459,3 +469,4 @@ def charlie_corrupt_bob_deposit( Web3.toWei(BOB_DEPOSIT_ETH, 'ether'), DEFAULT_MIX_GAS_WEI) return wait_for_tx_update_mk_tree(zeth_client, mk_tree, tx_hash) +''' \ No newline at end of file diff --git a/test_commands/test_erc_token_mixing.py b/test_commands/test_erc_token_mixing.py index 2c8d739..4c23ab7 100644 --- a/test_commands/test_erc_token_mixing.py +++ b/test_commands/test_erc_token_mixing.py @@ -13,12 +13,17 @@ from zeth.wallet import Wallet, ZethNoteDescription import test_commands.mock as mock import test_commands.scenario as scenario -from test_commands.deploy_test_token import deploy_token, mint_token +from test_commands.deploy_test_token import mint_token from os.path import join, exists import shutil from web3 import Web3 # type: ignore from typing import Dict, List, Any - +from contract.Groth16Mixer import Groth16Mixer +from contract.ERC20Mintable import ERC20Mintable +from python_web3.eth_account.account import Account +from python_web3.client.bcoskeypair import BcosKeyPair +from python_web3.client.bcosclient import BcosClient +from python_web3.eth_utils import to_checksum_address def print_token_balances( token_instance: Any, @@ -27,10 +32,14 @@ def print_token_balances( charlie: str, mixer: str) -> None: print("BALANCES:") - print(f" Alice : {token_instance.functions.balanceOf(alice).call()}") - print(f" Bob : {token_instance.functions.balanceOf(bob).call()}") - print(f" Charlie : {token_instance.functions.balanceOf(charlie).call()}") - print(f" Mixer : {token_instance.functions.balanceOf(mixer).call()}") + outputresult = token_instance.balanceOf(alice) + print(f" Alice : {outputresult}") + outputresult = token_instance.balanceOf(bob) + print(f" Bob : {outputresult}") + outputresult = token_instance.balanceOf(charlie) + print(f" Charlie : {outputresult}") + outputresult = token_instance.balanceOf(mixer) + print(f" Mixer : {outputresult}") def approve( @@ -38,37 +47,105 @@ def approve( owner_address: str, spender_address: str, token_amount: int) -> str: - return token_instance.functions.approve( + return token_instance.approve( spender_address, - Web3.toWei(token_amount, 'ether')).transact({'from': owner_address}) + Web3.toWei(token_amount, 'ether')) def allowance( token_instance: Any, owner_address: str, spender_address: str) -> str: - return token_instance.functions.allowance(owner_address, spender_address) \ - .call() - + return token_instance.allowance(owner_address, spender_address) + +si1 = Groth16Mixer("") +t1 = [16483624808830139117766005204006999845999393770666960505987166774116637665999, 15253936697195453458829704583528307376312090566175390614587367387882742888799] +t2 = [44284375965535255079801546243344002941596092908842750679505529109882140766, 11233183866282701416902842220398187526010682123304678142269318052114672666546] +t3 = [9975131970349417387454290174223382296463371611384079201194338159523411969581, 2836898428783494084355965442200696991005913320682471111065246558592301381311] +t4 = [9012277824718376381708077833555069935024430531058406360274230750681719039405, 18190687865858218001240874594336155036798710042113506844146290795387291588304] +t5 = [17798233959403027396420681547231945946145872783571600213811511589402431785080, 11217575595290996252585082378889649247766308217470417842352099180694760290188] +t6 = [13127546870442545011329176149454856901858462444541631023772933727095126529058, 19404375304354975644607334439648861444889263700940827808535214165647741300489, 7343011947856741308665292820167543015926418084154235912896839265227063475033, 9453663051630548672460758115379738986086323263715023634810574618860824165649, 10496397454998568476919935796689319286841216134974193457788117232365204626258, 11284352140683880343219250416670805942308406063791636940567376665512284052292, 17017594587165963191916060512316029390223787071785433187962067889654085091307, 19758759260873392541342276698014494472625895047987621107563834072318625381206, 8406307591444443375641072935994568035140518660841560151667202202813333885586, 5410830339934220399520427973486934263275622363479939517966013346779825897558, 16445114304315291249248248939147540565726925385944823187367299037813648954755, 3221459929655206232033643211703182348049561169738000403197310192344333897587, 20646682408467610111202194704403498169538806050581274032158885964904048419809, 11513380394743681123603185762855885450188409910128452969151184039101786105503, 16997502938391560880601578169553651092656671673592231136010407878532484008107, 13341125156553104272973835991394926394157444151712334543687551476437070936247, 7657410784579699053919494258956230966569350740250871130025214375144683745585, 15505388359419626992414275582583840166300945266511135060834671458795528295132, 6052746551364842597375684973752628633468284022556264989735303124812075848535, 12662727174561814448494408062186338092403379116204770936971191877512919408352] + +abi = [ + {"inputs": + [ + {"internalType": "uint256", "name": "mk_depth", "type": "uint256"}, + {"internalType": "address", "name": "token", "type": "address"}, + {"internalType": "uint256[2]", "name": "Alpha", "type": "uint256[2]"}, + {"internalType": "uint256[2]", "name": "Beta1", "type": "uint256[2]"}, + {"internalType": "uint256[2]", "name": "Beta2", "type": "uint256[2]"}, + {"internalType": "uint256[2]", "name": "Delta1", "type": "uint256[2]"}, + {"internalType": "uint256[2]", "name": "Delta2", "type": "uint256[2]"}, + {"internalType": "uint256[]", "name": "ABC_coords", "type": "uint256[]"}], + "payable": False, "stateMutability": "nonpayable", "type": "constructor"}, + {"anonymous": False, "inputs": [{"indexed": False, "internalType": "string", "name": "message", "type": "string"}], "name": "LogDebug", "type": "event"}, + {"anonymous": False, "inputs": [{"indexed": False, "internalType": "bytes32", "name": "message", "type": "bytes32"}], "name": "LogDebug", "type": "event"}, + {"anonymous": False, "inputs": [{"indexed": False, "internalType": "bytes32", "name": "root", "type": "bytes32"}, + {"indexed": False, "internalType": "bytes32[2]", "name": "nullifiers", "type": "bytes32[2]"}, + {"indexed": False, "internalType": "bytes32[2]", "name": "commitments", "type": "bytes32[2]"}, + {"indexed": False, "internalType": "bytes[2]", "name": "ciphertexts", "type": "bytes[2]"}], "name": "LogMix", "type": "event"}, + {"constant": True, "inputs": [{"internalType": "uint256[9]", "name": "primary_inputs", "type": "uint256[9]"}], "name": "assemble_hsig", "outputs": [{"internalType": "bytes32", "name": "hsig", "type": "bytes32"}], "payable": False, "stateMutability": "pure", "type": "function"}, + {"constant": True, "inputs": [{"internalType": "uint256", "name": "index", "type": "uint256"}, {"internalType": "uint256[9]", "name": "primary_inputs", "type": "uint256[9]"}], "name": "assemble_nullifier", "outputs": [{"internalType": "bytes32", "name": "nf", "type": "bytes32"}], "payable": False, "stateMutability": "pure", "type": "function"}, + {"constant": True, "inputs": [{"internalType": "uint256[9]", "name": "primary_inputs", "type": "uint256[9]"}], "name": "assemble_public_values", "outputs": [{"internalType": "uint256", "name": "vpub_in", "type": "uint256"}, + {"internalType": "uint256", "name": "vpub_out", "type": "uint256"}], "payable": False, "stateMutability": "pure", "type": "function"}, {"constant": True, "inputs": [], "name": "get_constants", "outputs": [{"internalType": "uint256", "name": "js_in", "type": "uint256"}, {"internalType": "uint256", "name": "js_out", "type": "uint256"}, {"internalType": "uint256", "name": "num_inputs", "type": "uint256"}], "payable": False, "stateMutability": "pure", "type": "function"}, {"constant": False, "inputs": [{"internalType": "bytes32", "name": "commitment", "type": "bytes32"}], "name": "insert", "outputs": [], "payable": False, "stateMutability": "nonpayable", "type": "function"}, {"constant": False, "inputs": [{"internalType": "uint256[2]", "name": "a", "type": "uint256[2]"}, {"internalType": "uint256[4]", "name": "b", "type": "uint256[4]"}, {"internalType": "uint256[2]", "name": "c", "type": "uint256[2]"}, {"internalType": "uint256[4]", "name": "vk", "type": "uint256[4]"}, {"internalType": "uint256", "name": "sigma", "type": "uint256"}, {"internalType": "uint256[9]", "name": "input", "type": "uint256[9]"}, {"internalType": "bytes[2]", "name": "ciphertexts", "type": "bytes[2]"}], "name": "mix", "outputs": [], "payable": True, "stateMutability": "payable", "type": "function"}, {"constant": True, "inputs": [], "name": "token", "outputs": [{"internalType": "address", "name": "", "type": "address"}], "payable": False, "stateMutability": "view", "type": "function"}, {"constant": True, "inputs": [{"internalType": "address", "name": "from", "type": "address"}, {"internalType": "uint256", "name": "value", "type": "uint256"}, {"internalType": "bytes", "name": "data", "type": "bytes"}], "name": "tokenFallback", "outputs": [], "payable": False, "stateMutability": "pure", "type": "function"}] +#argbin = TransactionCommon.format_args_by_abi(fn_args, abi[0]['inputs'] ) +#argbin = encode_transaction_data(None, abi, None, fn_args) +bin = '0x60806040523480156200001157600080fd5b50604051620025a4380380620025a4833981016040819052620000349162000479565b8787818060208114620000645760405162461bcd60e51b81526004016200005b9062000590565b60405180910390fd5b50620000786001600160e01b036200025a16565b50600080800154600081815264020000000060205260409020805460ff1916600117905564020000000280546001600160a01b0385166001600160a01b03199091161790559050505050604051806040016040528087600060028110620000db57fe5b6020020151815260200187600160028110620000f357fe5b602090810291909101519091528151640200000003559081015164020000000455604080516080808201835288518083528985015183860181905289518486018190528a87015160609586018190526402000000059390935564020000000691909155640200000007556402000000085582519081018352865180825287850151828601819052875194830185905294870151919092018190526402000000099190915564020000000a9290925564020000000b5564020000000c5560005b6002825181620001be57fe5b64020000000d54919004146200024b57640200000003600a016040518060400160405280848481518110620001ef57fe5b602002602001015181526020018484600101815181106200020c57fe5b602090810291909101810151909152825460018181018555600094855293829020835160029283029091019081559290910151919092015501620001b2565b5050505050505050506200064b565b60006401fffffffe81905563800000005b8015620002b357620002898283620002b760201b62000ef41760201c565b91506001196002820201826000826401ffffffff8110620002a657fe5b015550600290046200026b565b5050565b60007fdec937b7fa8db3de380427a8cc947bfab68514522c3439cfa2e99655098368146000527f30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f00000018284828282088381820984858383098683840909925060005b605a8112156200034f57602060002080600052868688838808089350868485099250868488858a878809090994505060010162000317565b508484868a88888808080898975050505050505050565b8051620003738162000626565b92915050565b600082601f8301126200038b57600080fd5b6002620003a26200039c82620005c9565b620005a2565b91508183856020840282011115620003b957600080fd5b60005b83811015620003e95781620003d288826200046c565b8452506020928301929190910190600101620003bc565b5050505092915050565b600082601f8301126200040557600080fd5b8151620004166200039c82620005e7565b915081818352602084019350602081019050838560208402820111156200043c57600080fd5b60005b83811015620003e957816200045588826200046c565b84525060209283019291909101906001016200043f565b8051620003738162000640565b6000806000806000806000806101a0898b0312156200049757600080fd5b6000620004a58b8b6200046c565b9850506020620004b88b828c0162000366565b9750506040620004cb8b828c0162000379565b9650506080620004de8b828c0162000379565b95505060c0620004f18b828c0162000379565b945050610100620005058b828c0162000379565b935050610140620005198b828c0162000379565b9250506101808901516001600160401b038111156200053757600080fd5b620005458b828c01620003f3565b9150509295985092959890939650565b600062000564601f8362000608565b7f496e76616c696420646570746820696e20426173654d65726b6c655472656500815260200192915050565b60208082528101620003738162000555565b6040518181016001600160401b0381118282101715620005c157600080fd5b604052919050565b60006001600160401b03821115620005e057600080fd5b5060200290565b60006001600160401b03821115620005fe57600080fd5b5060209081020190565b90815260200190565b60006001600160a01b03821662000373565b90565b620006318162000611565b81146200063d57600080fd5b50565b620006318162000623565b611f49806200065b6000396000f3fe60806040526004361061007b5760003560e01c806397e004891161004e57806397e0048914610126578063c0ee0b8a14610139578063f9eb943f14610159578063fc0c546a1461017d5761007b565b806305ceb93c146100805780631f40927c146100b65780632d287e43146100e4578063354d06fd14610106575b600080fd5b34801561008c57600080fd5b506100a061009b3660046113e9565b61019f565b6040516100ad9190611c7d565b60405180910390f35b3480156100c257600080fd5b506100d66100d136600461138e565b61022d565b6040516100ad929190611dbf565b3480156100f057600080fd5b506101046100ff3660046113ad565b610256565b005b34801561011257600080fd5b506100a061012136600461138e565b6102ad565b6101046101343660046112d5565b6102cc565b34801561014557600080fd5b50610104610154366004611270565b61043f565b34801561016557600080fd5b5061016e610526565b6040516100ad93929190611dcd565b34801561018957600080fd5b50610192610530565b6040516100ad9190611c2c565b6000600283106101ca5760405162461bcd60e51b81526004016101c190611ccf565b60405180910390fd5b60036001840102608081019060830160fd10156101f95760405162461bcd60e51b81526004016101c190611d1f565b610100830151607182011b60fd1c60006003858782016009811061021957fe5b6020020151901b9190910195945050505050565b610100015164e8d4a5100067ffffffffffffffff604f83901c8116820293600f9390931c160290565b6401ffffffff54640100000000116102805760405162461bcd60e51b81526004016101c190611d0f565b6401ffffffff80546001810182559063ffffffff8201908390600090839081106102a657fe5b0155505050565b61010081015160a09091015160031b6007600c9290921c919091160190565b6102d4610fa1565b6102df858483610543565b815160208084015160405160009360029361030693339390918f918f918f918d9101611bb8565b60408051601f198184030181529082905261032091611ba1565b602060405180830381855afa15801561033d573d6000803e3d6000fd5b5050506040513d601f19601f8201168201806040525061036091908101906113cb565b86516020880151604089015160608a015193945061037f9389866106a4565b61039b5760405162461bcd60e51b81526004016101c190611d8f565b6103a789898987610743565b6103c35760405162461bcd60e51b81526004016101c190611d5f565b6103cb610fa1565b6103d58582610860565b60006103e160026108ad565b90506103ec816108ee565b7f36ed7c3f2ecfb5a5226c478b034d33144c060afe361be291e948f861dcddc618818584886040516104219493929190611c8b565b60405180910390a16104328661090d565b5050505050505050505050565b610447610fbf565b6001600160a01b0384168152602081018390526040810182905281516000906018908490600390811061047657fe5b016020015184516001600160f81b031990911690911c60e01c90601090859060029081106104a057fe5b016020015185516001600160f81b031990911690911c60e01c90600890869060019081106104ca57fe5b016020015186516001600160f81b031990911690911c60e01c9086906000906104ef57fe5b01602001516001600160e01b031963ff00000060e092831c16929092019290920192909201901b1660609092019190915250505050565b6002908190600990565b640200000002546001600160a01b031681565b81516000908152640200000000602052604090205460ff166105775760405162461bcd60e51b81526004016101c190611d2f565b60005b60028110156105fd57600061058f828561019f565b6000818152640200000001602052604090205490915060ff16156105c55760405162461bcd60e51b81526004016101c190611cdf565b600081815264020000000160205260409020805460ff19166001179055808383600281106105ef57fe5b60200201525060010161057a565b50600060028285604051602001610615929190611b7b565b60408051601f198184030181529082905261062f91611ba1565b602060405180830381855afa15801561064c573d6000803e3d6000fd5b5050506040513d601f19601f8201168201806040525061066f91908101906113cb565b9050600061067c846102ad565b905080821461069d5760405162461bcd60e51b81526004016101c190611d3f565b5050505050565b60006106ae610ffa565b6107d05a038682528560208301528360408301526020608083016060846000600286f150604082018981528860208201526040816060836000600787f1506040836080856000600687f15060016040840152600260608401528560808401526040816060836000600787f150505060408101518151148015610737575060608101516020820151145b98975050505050505050565b60007f30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f000000161076e611018565b86518152602080880151828201528651604080840191909152878201516060808501919091528189015160808501528089015160a0850152875160c08501528783015160e0850152815160098082526101408201909352909290919082016101208038833901905050905060005b600981101561084457838682600981106107f257fe5b6020020151106108145760405162461bcd60e51b81526004016101c190611d7f565b85816009811061082057fe5b602002015182828151811061083157fe5b60209081029190910101526001016107dc565b5061084f8183610b60565b60011493505050505b949350505050565b60005b60028110156108a857600083826001016009811061087d57fe5b602002015190508083836002811061089157fe5b602002015261089f81610256565b50600101610863565b505050565b6401ffffffff546000908281036401000000005b60018111156108e2576108d5818385610e2b565b93509150600290046108c1565b50506000549392505050565b600090815264020000000060205260409020805460ff19166001179055565b6000806109198361022d565b909250905081156109cf57640200000002546001600160a01b0316156109ab57640200000002546040516323b872dd60e01b81526001600160a01b039091169081906323b872dd9061097390339030908890600401611c3a565b600060405180830381600087803b15801561098d57600080fd5b505af11580156109a1573d6000803e3d6000fd5b50505050506109ca565b8134146109ca5760405162461bcd60e51b81526004016101c190611d6f565b610a53565b3415610a53576000336001600160a01b0316346040516109ee90611bad565b60006040518083038185875af1925050503d8060008114610a2b576040519150601f19603f3d011682016040523d82523d6000602084013e610a30565b606091505b5050905080610a515760405162461bcd60e51b81526004016101c190611cef565b505b80156108a857640200000002546001600160a01b031615610ade576402000000025460405163a9059cbb60e01b81526001600160a01b0390911690819063a9059cbb90610aa69033908690600401611c62565b600060405180830381600087803b158015610ac057600080fd5b505af1158015610ad4573d6000803e3d6000fd5b50505050506108a8565b6000336001600160a01b031682604051610af790611bad565b60006040518083038185875af1925050503d8060008114610b34576040519150601f19603f3d011682016040523d82523d6000602084013e610b39565b606091505b5050905080610b5a5760405162461bcd60e51b81526004016101c190611cff565b50505050565b64020000000d548251600091600190910114610b8e5760405162461bcd60e51b81526004016101c190611d4f565b610b9661105d565b60016107d05a03600a6402000000030183526020832060208701875160200281018254865260018301546020870152600283019250604086015b81831015610c1e57835481526001840154602082015282516040820152604081606083600060078af160408860808a600060068bf11695909516946002939093019260209290920191610bd0565b505050505080610c405760405162461bcd60e51b81526004016101c190611daf565b7f198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c260408301527f1800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed60608301527f090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b60808301527f12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa60a08301526402000000035460c08301526001640200000003015460e08301526002640200000003015461010083015260036402000000030154610120830152600464020000000301546101408301526005640200000003015461016083015283516101808301527f30644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd47602085015181810682036101a085015260408601516101c085015260608601516101e0850152608086015161020085015260a086015161022085015260c086015161024085015260e086015161026085015260066402000000030154610280850152600764020000000301546102a0850152600864020000000301546102c0850152600964020000000301546102e085015260208461030086600060086107d05a03f19250505080610e205760405162461bcd60e51b81526004016101c190611d9f565b505190505b92915050565b600080600019808601906001198616870101826001861615610e9f575060001982860101610e806000826401ffffffff8110610e6357fe5b01546000856002026401ffffffff8110610e7957fe5b0154610ef4565b600060026000198401046401ffffffff8110610e9857fe5b0155610ea4565b508185015b81811115610eda5760011901610e806000826401ffffffff8110610ec457fe5b01546000836001016401ffffffff8110610e7957fe5b600287046002600188010494509450505050935093915050565b60007fdec937b7fa8db3de380427a8cc947bfab68514522c3439cfa2e99655098368146000527f30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f00000018284828282088381820984858383098683840909925060005b605a811215610f8a57602060002080600052868688838808089350868485099250868488858a8788090909945050600101610f54565b508484868a88888808080898975050505050505050565b60405180604001604052806002906020820280388339509192915050565b604051806080016040528060006001600160a01b03168152602001600081526020016060815260200160006001600160e01b03191681525090565b6040518060a001604052806005906020820280388339509192915050565b60405180610100016040528060008152602001600081526020016000815260200160008152602001600081526020016000815260200160008152602001600081525090565b6040518061030001604052806018906020820280388339509192915050565b8035610e2581611ee6565b600082601f83011261109857600080fd5b60026110ab6110a682611e0f565b611de8565b9150818360005b838110156110de57813586016110c88882611221565b84525060209283019291909101906001016110b2565b5050505092915050565b600082601f8301126110f957600080fd5b60026111076110a682611e0f565b9150818385602084028201111561111d57600080fd5b60005b838110156110de5781611133888261120b565b8452506020928301929190910190600101611120565b600082601f83011261115a57600080fd5b60046111686110a682611e0f565b9150818385602084028201111561117e57600080fd5b60005b838110156110de5781611194888261120b565b8452506020928301929190910190600101611181565b600082601f8301126111bb57600080fd5b60096111c96110a682611e0f565b915081838560208402820111156111df57600080fd5b60005b838110156110de57816111f5888261120b565b84525060209283019291909101906001016111e2565b8035610e2581611efd565b8051610e2581611efd565b600082601f83011261123257600080fd5b81356112406110a682611e2d565b9150808252602083016020830185838301111561125c57600080fd5b611267838284611ea4565b50505092915050565b60008060006060848603121561128557600080fd5b6000611291868661107c565b93505060206112a28682870161120b565b925050604084013567ffffffffffffffff8111156112bf57600080fd5b6112cb86828701611221565b9150509250925092565b60008060008060008060006102e0888a0312156112f157600080fd5b60006112fd8a8a6110e8565b975050604061130e8a828b01611149565b96505060c061131f8a828b016110e8565b9550506101006113318a828b01611149565b9450506101806113438a828b0161120b565b9350506101a06113558a828b016111aa565b9250506102c088013567ffffffffffffffff81111561137357600080fd5b61137f8a828b01611087565b91505092959891949750929550565b600061012082840312156113a157600080fd5b600061085884846111aa565b6000602082840312156113bf57600080fd5b6000610858848461120b565b6000602082840312156113dd57600080fd5b60006108588484611216565b60008061014083850312156113fd57600080fd5b6000611409858561120b565b925050602061141a858286016111aa565b9150509250929050565b60006114308383611655565b505060200190565b6000611444838361168d565b9392505050565b61145481611e93565b82525050565b61145481611e82565b61146c81611e58565b6114768184611e74565b925061148182611e55565b8060005b838110156114af5781516114998782611424565b96506114a483611e6e565b925050600101611485565b505050505050565b6114c081611e58565b6114ca8184611e74565b92506114d582611e55565b8060005b838110156114af5781516114ed8782611424565b96506114f883611e6e565b9250506001016114d9565b600061150e82611e58565b6115188185611e74565b93508360208202850161152a85611e55565b8060005b8581101561156457848403895281516115478582611438565b945061155283611e6e565b60209a909a019992505060010161152e565b5091979650505050505050565b61157a81611e58565b6115848184611e74565b925061158f82611e55565b8060005b838110156114af5781516115a78782611424565b96506115b283611e6e565b925050600101611593565b6115c681611e5e565b6115d08184611e74565b92506115db82611e55565b8060005b838110156114af5781516115f38782611424565b96506115fe83611e6e565b9250506001016115df565b61161281611e64565b61161c8184611e74565b925061162782611e55565b8060005b838110156114af57815161163f8782611424565b965061164a83611e6e565b92505060010161162b565b61145481611e55565b600061166982611e6a565b6116738185611e74565b9350611683818560208601611eb0565b9290920192915050565b600061169882611e6a565b6116a28185611e79565b93506116b2818560208601611eb0565b6116bb81611edc565b9093019392505050565b60006116d2601883611e79565b7f6e756c6c696669657220696e646578206f766572666c6f770000000000000000815260200192915050565b600061170b603783611e79565b7f496e76616c6964206e756c6c69666965723a2054686973206e756c6c6966696581527f722068617320616c7265616479206265656e2075736564000000000000000000602082015260400192915050565b600061176a601e83611e79565b7f767075625f696e2072657475726e207472616e73666572206661696c65640000815260200192915050565b60006117a3601883611e79565b7f767075625f6f7574207472616e73666572206661696c65640000000000000000815260200192915050565b60006117dc602783611e79565b7f4d65726b6c6520747265652066756c6c3a2043616e6e6f7420617070656e6420815266616e796d6f726560c81b602082015260400192915050565b6000611825603083611e79565b7f6e756c6c6966696572207772697474656e20696e20646966666572656e74207281526f32b9b4b23ab0b6103134ba103317329760811b602082015260400192915050565b6000611877602583611e79565b7f496e76616c696420726f6f743a205468697320726f6f7420646f65736e277420815264195e1a5cdd60da1b602082015260400192915050565b60006118be604983611e79565b7f496e76616c696420687369673a2054686973206873696720646f6573206e6f7481527f20636f72726573706f6e6420746f207468652068617368206f6620766b20616e6020820152686420746865206e667360b81b604082015260600192915050565b600061192f602283611e79565b7f496e707574206c656e67746820646966666572732066726f6d20657870656374815261195960f21b602082015260400192915050565b6000611973603383611e79565b7f496e76616c69642070726f6f663a20556e61626c6520746f20766572696679208152727468652070726f6f6620636f72726563746c7960681b602082015260400192915050565b60006119c8602a83611e79565b7f57726f6e67206d73672e76616c75653a2056616c75652070616964206973206e8152691bdd0818dbdc9c9958dd60b21b602082015260400192915050565b6000611a14601c83611e79565b7f496e707574206973206e6f7420696e207363616c6172206669656c6400000000815260200192915050565b6000611a4d603b83611e79565b7f496e76616c6964207369676e61747572653a20556e61626c6520746f2076657281527f69667920746865207369676e617475726520636f72726563746c790000000000602082015260400192915050565b6000610e25600083611e74565b6000611ab9603783611e79565b7f43616c6c20746f20626e3235364164642c20626e3235365363616c61724d756c81527f206f7220626e32353650616972696e67206661696c6564000000000000000000602082015260400192915050565b6000611b18603983611e79565b7f43616c6c20746f2074686520626e323536416464206f7220626e32353653636181527f6c61724d756c20707265636f6d70696c6564206661696c656400000000000000602082015260400192915050565b611454611b7682611e55565b611e55565b6000611b8782856114b7565b604082019150611b9782846115bd565b5060800192915050565b6000611444828461165e565b6000610e2582611a9f565b6000611bc4828a611b6a565b602082019150611bd4828961165e565b9150611be0828861165e565b9150611bec8287611571565b604082019150611bfc82866115bd565b608082019150611c0c8285611571565b604082019150611c1c8284611609565b5061012001979650505050505050565b60208101610e25828461145a565b60608101611c48828661144b565b611c55602083018561145a565b6108586040830184611655565b60408101611c70828561144b565b6114446020830184611655565b60208101610e258284611655565b60c08101611c998287611655565b611ca66020830186611463565b611cb36060830185611463565b81810360a0830152611cc58184611503565b9695505050505050565b60208082528101610e25816116c5565b60208082528101610e25816116fe565b60208082528101610e258161175d565b60208082528101610e2581611796565b60208082528101610e25816117cf565b60208082528101610e2581611818565b60208082528101610e258161186a565b60208082528101610e25816118b1565b60208082528101610e2581611922565b60208082528101610e2581611966565b60208082528101610e25816119bb565b60208082528101610e2581611a07565b60208082528101610e2581611a40565b60208082528101610e2581611aac565b60208082528101610e2581611b0b565b60408101611c708285611655565b60608101611ddb8286611655565b611c556020830185611655565b60405181810167ffffffffffffffff81118282101715611e0757600080fd5b604052919050565b600067ffffffffffffffff821115611e2657600080fd5b5060200290565b600067ffffffffffffffff821115611e4457600080fd5b506020601f91909101601f19160190565b90565b50600290565b50600490565b50600990565b5190565b60200190565b919050565b90815260200190565b60006001600160a01b038216610e25565b6000610e25826000610e2582611e82565b82818337506000910152565b60005b83811015611ecb578181015183820152602001611eb3565b83811115610b5a5750506000910152565b601f01601f191690565b611eef81611e82565b8114611efa57600080fd5b50565b611eef81611e5556fea365627a7a72315820e42326a4694c17436c7722fd4a82ac810b74162de26e7fd1035ac3ef5d5a29d16c6578706572696d656e74616cf564736f6c63430005110040' def main() -> None: zksnark = zeth.zksnark.get_zksnark_provider(zeth.utils.parse_zksnark_arg()) - web3, eth = mock.open_test_web3() - + #web3, eth = mock.open_test_web3() + ''' # Ethereum addresses deployer_eth_address = eth.accounts[0] bob_eth_address = eth.accounts[1] alice_eth_address = eth.accounts[2] charlie_eth_address = eth.accounts[3] + ''' + # Fisco-bcos addresses + deployer_password = "123456" + bob_password = "234567" + alice_password = "345678" + charlie_password = "456789" + deployer_ac = Account.create(deployer_password) + bob_ac = Account.create(bob_password) + alice_ac = Account.create(alice_password) + charlie_ac = Account.create(charlie_password) + #keypair + deployer_keypair = BcosKeyPair() + deployer_keypair.private_key = deployer_ac.privateKey + deployer_keypair.public_key = deployer_ac.publickey + deployer_keypair.address = deployer_ac.address + bob_keypair = BcosKeyPair() + bob_keypair.private_key = bob_ac.privateKey + bob_keypair.public_key = bob_ac.publickey + bob_keypair.address = bob_ac.address + alice_keypair = BcosKeyPair() + alice_keypair.private_key = alice_ac.privateKey + alice_keypair.public_key = alice_ac.publickey + alice_keypair.address = alice_ac.address + charlie_keypair = BcosKeyPair() + charlie_keypair.private_key = charlie_ac.privateKey + charlie_keypair.public_key = charlie_ac.publickey + charlie_keypair.address = charlie_ac.address + # Zeth addresses keystore = mock.init_test_keystore() # Deploy the token contract - token_instance = deploy_token(eth, deployer_eth_address, 4000000) - + #token_instance = deploy_token(eth, deployer_eth_address, 4000000) + token_si = ERC20Mintable("") + token_si.client.ecdsa_account = deployer_ac + token_si.client.keypair = deployer_keypair + token_result = token_si.deploy("contract/ERC20Mintable.bin") + token_address = token_result['contractAddress'] + token_instance = ERC20Mintable(token_address) + token_instance.client.ecdsa_account = deployer_ac + token_instance.client.keypair = deployer_keypair # Deploy Zeth contracts tree_depth = constants.ZETH_MERKLE_TREE_DEPTH + ''' zeth_client, _contract_desc = MixerClient.deploy( web3, mock.TEST_PROVER_SERVER_ENDPOINT, @@ -76,8 +153,25 @@ def main() -> None: token_instance.address, None, zksnark) + ''' + #mixer_si = Groth16Mixer("") + #mixer_si.client.ecdsa_account = deployer_ac + #mixer_si.client.keypair = deployer_keypair + #mixer_result = mixer_si.deploy("contract/Groth16Mixer.bin") + fn_args = [32, to_checksum_address(token_address), t1, t2, t3, t4, t5, t6] + client = BcosClient() + client.ecdsa_account = deployer_ac + client.keypair = deployer_keypair + mixer_result = client.sendRawTransactionGetReceipt("", abi, None, fn_args, bin, 30000000, 15) + mixer_address = mixer_result['contractAddress'] + mixer_instance = Groth16Mixer(mixer_address) + mixer_instance.client.ecdsa_account = deployer_ac + mixer_instance.client.keypair = deployer_keypair + print(token_address) + print("token address: ", mixer_instance.token()) + zeth_client = MixerClient.open(mock.TEST_PROVER_SERVER_ENDPOINT, mixer_instance) mk_tree = zeth.merkle_tree.MerkleTree.empty_with_depth(tree_depth) - mixer_instance = zeth_client.mixer_instance + #mixer_instance = zeth_client.mixer_instance # Keys and wallets def _mk_wallet(name: str, sk: ZethAddressPriv) -> Wallet: @@ -93,80 +187,84 @@ def _mk_wallet(name: str, sk: ZethAddressPriv) -> Wallet: alice_wallet = _mk_wallet('alice', sk_alice) bob_wallet = _mk_wallet('bob', sk_bob) charlie_wallet = _mk_wallet('charlie', sk_charlie) - block_num = 1 + #block_num = 1 # Universal update function def _receive_notes( out_ev: List[MixOutputEvents]) \ -> Dict[str, List[ZethNoteDescription]]: - nonlocal block_num + #nonlocal block_num notes = { 'alice': alice_wallet.receive_notes(out_ev), 'bob': bob_wallet.receive_notes(out_ev), 'charlie': charlie_wallet.receive_notes(out_ev), } - alice_wallet.update_and_save_state(block_num) - bob_wallet.update_and_save_state(block_num) - charlie_wallet.update_and_save_state(block_num) - block_num = block_num + 1 + alice_wallet.update_and_save_state() + bob_wallet.update_and_save_state() + charlie_wallet.update_and_save_state() + #block_num = block_num + 1 return notes print("[INFO] 4. Running tests (asset mixed: ERC20 token)...") # We assign ETHToken to Bob mint_token( token_instance, - bob_eth_address, - deployer_eth_address, + bob_ac.address, + deployer_ac.address, 2*scenario.BOB_DEPOSIT_ETH) print("- Initial balances: ") print_token_balances( token_instance, - bob_eth_address, - alice_eth_address, - charlie_eth_address, - zeth_client.mixer_instance.address) + bob_ac.address, + alice_ac.address, + charlie_ac.address, + mixer_address) # Bob tries to deposit ETHToken, split in 2 notes on the mixer (without # approving) + token_si.client.ecdsa_account = bob_ac + token_si.client.keypair = bob_keypair + zeth_client.mixer_instance.client.ecdsa_account = bob_ac + zeth_client.mixer_instance.client.keypair = bob_keypair try: result_deposit_bob_to_bob = scenario.bob_deposit( zeth_client, mk_tree, - bob_eth_address, + bob_ac.address, keystore, zeth.utils.EtherValue(0)) except Exception as e: - allowance_mixer = allowance( + outputresult = allowance( token_instance, - bob_eth_address, - zeth_client.mixer_instance.address) + bob_ac.address, + mixer_address) print(f"[ERROR] Bob deposit failed! (msg: {e})") - print("The allowance for Mixer from Bob is: ", allowance_mixer) + print("The allowance for Mixer from Bob is: ", outputresult) # Bob approves the transfer print("- Bob approves the transfer of ETHToken to the Mixer") - tx_hash = approve( + (outputresult, receipt) = approve( token_instance, - bob_eth_address, - zeth_client.mixer_instance.address, + bob_ac.address, + mixer_address, scenario.BOB_DEPOSIT_ETH) - eth.waitForTransactionReceipt(tx_hash) - allowance_mixer = allowance( + #eth.waitForTransactionReceipt(tx_hash) + outputresult = allowance( token_instance, - bob_eth_address, - zeth_client.mixer_instance.address) - print("- The allowance for the Mixer from Bob is:", allowance_mixer) + bob_ac.address, + mixer_address) + print("- The allowance for the Mixer from Bob is:", outputresult) # Bob deposits ETHToken, split in 2 notes on the mixer result_deposit_bob_to_bob = scenario.bob_deposit( - zeth_client, mk_tree, bob_eth_address, keystore) + zeth_client, mk_tree, bob_ac.address, keystore) print("- Balances after Bob's deposit: ") print_token_balances( token_instance, - bob_eth_address, - alice_eth_address, - charlie_eth_address, - zeth_client.mixer_instance.address + bob_ac.address, + alice_ac.address, + charlie_ac.address, + mixer_address ) # Alice sees a deposit and tries to decrypt the ciphertexts to see if she @@ -185,7 +283,7 @@ def _receive_notes( assert(len(recovered_notes_bob) == 2), \ f"Bob recovered {len(recovered_notes_bob)} notes from deposit, expected 2" input_bob_to_charlie = recovered_notes_bob[0].as_input() - + ''' # Execution of the transfer result_transfer_bob_to_charlie = scenario.bob_to_charlie( zeth_client, @@ -302,7 +400,7 @@ def _receive_notes( alice_eth_address, charlie_eth_address, zeth_client.mixer_instance.address) - + ''' print( "========================================\n" + " TESTS PASSED\n" + diff --git a/zeth/contracts.py b/zeth/contracts.py index 4cb4676..75f41ce 100644 --- a/zeth/contracts.py +++ b/zeth/contracts.py @@ -10,7 +10,7 @@ signature_as_mix_parameter, signature_from_mix_parameter from zeth.zksnark import IZKSnarkProvider, GenericProof from zeth.utils import EtherValue, hex_to_int -from zeth.constants import SOL_COMPILER_VERSION +#from zeth.constants import SOL_COMPILER_VERSION import json import solcx import traceback @@ -100,7 +100,7 @@ def _event_args_to_mix_result(event_args: Any) -> MixResult: nullifiers=event_args.nullifiers, output_events=out_events) - +''' class InstanceDescription: """ Minimal data required to instantiate the in-memory interface to a contract. @@ -180,12 +180,12 @@ def instantiate(self, web3: Any) -> Any: Return the instantiated contract """ return web3.eth.contract(address=self.address, abi=self.abi) - +''' def get_block_number(web3: Any) -> int: return web3.eth.blockNumber - +''' def install_sol() -> None: solcx.install_solc(SOL_COMPILER_VERSION) @@ -197,7 +197,7 @@ def compile_files(files: List[str], **kwargs: Any) -> Any: """ solcx.set_solc_version(SOL_COMPILER_VERSION) return solcx.compile_files(files, optimize=True, **kwargs) - +''' def mix_parameters_as_contract_arguments( zksnark: IZKSnarkProvider, @@ -222,9 +222,9 @@ def _create_web3_mixer_call( mixer_instance: Any, mix_parameters: MixParameters) -> Any: mix_params_eth = mix_parameters_as_contract_arguments(zksnark, mix_parameters) - return mixer_instance.functions.mix(*mix_params_eth) - + return mixer_instance.mix(*mix_params_eth) +''' def mix_call( zksnark: IZKSnarkProvider, mixer_instance: Any, @@ -250,27 +250,29 @@ def mix_call( traceback.print_exc() return False - +''' def mix( zksnark: IZKSnarkProvider, mixer_instance: Any, mix_parameters: MixParameters, - sender_address: str, + #sender_address: str, wei_pub_value: int, call_gas: int) -> str: """ Create and broadcast a transaction that calls the mix method of the Mixer """ + ''' mixer_call = _create_web3_mixer_call(zksnark, mixer_instance, mix_parameters) tx_hash = mixer_call.transact({ 'from': sender_address, 'value': wei_pub_value, 'gas': call_gas }) - return tx_hash.hex() - + ''' + return _create_web3_mixer_call(zksnark, mixer_instance, mix_parameters) +''' def parse_mix_call( mixer_instance: Any, _tx_receipt: str) -> MixResult: @@ -281,7 +283,7 @@ def parse_mix_call( log_mix_events = log_mix_filter.get_all_entries() mix_results = [_event_args_to_mix_result(ev.args) for ev in log_mix_events] return mix_results[0] - +''' def _next_nullifier_or_none(nullifier_iter: Iterator[bytes]) -> Optional[Any]: try: @@ -291,15 +293,18 @@ def _next_nullifier_or_none(nullifier_iter: Iterator[bytes]) -> Optional[Any]: def get_mix_results( - web3: Any, + #web3: Any, mixer_instance: Any, - start_block: int, - end_block: int) -> Iterator[MixResult]: + receipt: Any + #start_block: int, + #end_block: int + ) -> Iterator[MixResult]: """ Iterator for all events generated by 'mix' executions, over some block range. Batches eth RPC calls to avoid holding huge numbers of events in memory. """ + ''' for batch_start in range(start_block, end_block + 1, SYNC_BLOCKS_PER_BATCH): # Get mk_root, address and ciphertext filters for try: @@ -313,3 +318,9 @@ def get_mix_results( finally: web3.eth.uninstallFilter(log_mix_filter.filter_id) + ''' + logresult = mixer_instance.data_parser.parse_event_logs(receipt["logs"]) + for log in logresult: + if log['eventname'] == 'LogMix': + yield _event_args_to_mix_result(log['eventdata']) + diff --git a/zeth/mixer_client.py b/zeth/mixer_client.py index f1f02e3..b421f4a 100644 --- a/zeth/mixer_client.py +++ b/zeth/mixer_client.py @@ -288,29 +288,30 @@ class MixerClient: """ def __init__( self, - web3: Any, + #web3: Any, prover_client: ProverClient, mixer_instance: Any, zksnark: IZKSnarkProvider): self._prover_client = prover_client - self.web3 = web3 + #self.web3 = web3 self._zksnark = zksnark self.mixer_instance = mixer_instance @staticmethod def open( - web3: Any, + #web3: Any, prover_server_endpoint: str, mixer_instance: Any) -> MixerClient: """ Create a client for an existing Zeth deployment. """ return MixerClient( - web3, + #web3, ProverClient(prover_server_endpoint), mixer_instance, get_zksnark_provider(constants.ZKSNARK_DEFAULT)) + ''' @staticmethod def deploy( web3: Any, @@ -324,8 +325,8 @@ def deploy( 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) + zksnark = zksnark or get_zksnark_provider(constants.ZKSNARK_DEFAULT) #Groth16SnarkProvider + prover_client = ProverClient(prover_server_endpoint) #gRPC客户端实例 vk_obj = prover_client.get_verification_key() vk_json = zksnark.parse_verification_key(vk_obj) deploy_gas = deploy_gas or \ @@ -335,8 +336,8 @@ def deploy( write_verification_key(vk_json) print("[INFO] 3. VK written, deploying smart contracts...") - contracts_dir = get_contracts_dir() - mixer_name = zksnark.get_contract_name() + contracts_dir = get_contracts_dir() #../../zeth_contract + mixer_name = zksnark.get_contract_name() #Groth16Mixer mixer_src = os.path.join(contracts_dir, mixer_name + ".sol") verification_key_params = zksnark.verification_key_parameters(vk_json) @@ -353,7 +354,7 @@ def deploy( mixer_instance = mixer_description.instantiate(web3) client = MixerClient(web3, prover_client, mixer_instance, zksnark) return client, mixer_description - + ''' def deposit( self, mk_tree: MerkleTree, @@ -398,7 +399,7 @@ def joinsplit( # By default transfer exactly v_in, otherwise allow caller to manually # specify. - tx_value = tx_value or v_in + tx_value = tx_value or v_in #如果是deposit eth,则tx_value等于v_in,如果是deposit erc20,则tx_value等于EtherValue(0) return self.mix( mix_params, sender_eth_address, @@ -436,7 +437,7 @@ def create_mix_parameters_keep_signing_key( outputs = \ outputs + \ [(dummy_addr_pk, EtherValue(0)) - for _ in range(constants.JS_OUTPUTS - len(outputs))] + for _ in range(constants.JS_OUTPUTS - len(outputs))] #根据需要构造dummy output,缺多少个构造多少个 outputs_with_a_pk = \ [(zeth_addr.a_pk, to_zeth_units(value)) for (zeth_addr, value) in outputs] @@ -514,10 +515,10 @@ def mix( self._zksnark, self.mixer_instance, mix_params, - sender_eth_address, + #sender_eth_address, wei_pub_value, call_gas) - + ''' def mix_call( self, mix_params: contracts.MixParameters, @@ -531,7 +532,7 @@ def mix_call( sender_eth_address, wei_pub_value, call_gas) - + ''' def get_proof_joinsplit_2_by_2( self, mk_root: bytes, diff --git a/zeth/utils.py b/zeth/utils.py index c96078f..9d33068 100644 --- a/zeth/utils.py +++ b/zeth/utils.py @@ -15,7 +15,7 @@ import os from os.path import join, dirname, normpath import eth_abi -from web3 import Web3, HTTPProvider # type: ignore +from web3 import Web3 # type: ignore from py_ecc import bn128 as ec from typing import List, Tuple, Union, Any, cast @@ -24,7 +24,7 @@ # most machines, but allow 1 min. WEB3_HTTP_PROVIDER_TIMEOUT_SEC = 60 - +''' def open_web3(url: str) -> Any: """ Create a Web3 context from an http URL. @@ -32,7 +32,7 @@ def open_web3(url: str) -> Any: return Web3(HTTPProvider( url, request_kwargs={'timeout': WEB3_HTTP_PROVIDER_TIMEOUT_SEC})) - +''' FQ = ec.FQ G1 = Tuple[ec.FQ, ec.FQ] diff --git a/zeth/wallet.py b/zeth/wallet.py index e954f31..6f68ed2 100644 --- a/zeth/wallet.py +++ b/zeth/wallet.py @@ -73,14 +73,14 @@ class WalletState: transaction. """ def __init__( - self, next_block: int, num_notes: int, nullifier_map: NullifierMap): - self.next_block = next_block + self, num_notes: int, nullifier_map: NullifierMap): + #self.next_block = next_block self.num_notes = num_notes self.nullifier_map = nullifier_map def to_json(self) -> str: json_dict = { - "next_block": self.next_block, + #"next_block": self.next_block, "num_notes": self.num_notes, "nullifier_map": self.nullifier_map, } @@ -90,14 +90,14 @@ def to_json(self) -> str: def from_json(json_str: str) -> WalletState: json_dict = json.loads(json_str) return WalletState( - next_block=int(json_dict["next_block"]), + #next_block=int(json_dict["next_block"]), num_notes=int(json_dict["num_notes"]), nullifier_map=cast(NullifierMap, json_dict["nullifier_map"])) def _load_state_or_default(state_file: str) -> WalletState: if not exists(state_file): - return WalletState(1, 0, {}) + return WalletState(0, {}) with open(state_file, "r") as state_f: return WalletState.from_json(state_f.read()) @@ -221,8 +221,8 @@ def spent_note_summaries(self) -> Iterator[Tuple[int, str, EtherValue]]: def get_next_block(self) -> int: return self.state.next_block - def update_and_save_state(self, next_block: int) -> None: - self.state.next_block = next_block + def update_and_save_state(self) -> None: + #self.state.next_block = next_block _save_state(self.state_file, self.state) self._save_merkle_tree_if_changed()