Exemple #1
0
 def mixer_proof_parameters(parsed_proof: GenericProof) -> List[List[Any]]:
     return [
         hex_to_int(parsed_proof["a"]),
         [
             hex_to_int(parsed_proof["b"][0]),
             hex_to_int(parsed_proof["b"][1])
         ],
         hex_to_int(parsed_proof["c"])
     ]
Exemple #2
0
def mix(mixer_instance: Any, pk_sender: EncryptionPublicKey,
        ciphertext1: bytes, ciphertext2: bytes, parsed_proof: GenericProof,
        vk: SigningVerificationKey, sigma: int, sender_address: str,
        wei_pub_value: int, call_gas: int,
        zksnark: IZKSnarkProvider) -> MixResult:
    """
    Run the mixer
    """
    pk_sender_encoded = encode_encryption_public_key(pk_sender)
    proof_params = zksnark.mixer_proof_parameters(parsed_proof)
    tx_hash = mixer_instance.functions.mix(
        *proof_params,
        [[int(vk.ppk[0]), int(vk.ppk[1])], [int(vk.spk[0]),
                                            int(vk.spk[1])]],
        sigma,
        hex_to_int(parsed_proof["inputs"]),
        pk_sender_encoded,
        ciphertext1,
        ciphertext2,
    ).transact({
        'from': sender_address,
        'value': wei_pub_value,
        'gas': call_gas
    })
    tx_receipt = eth.waitForTransactionReceipt(tx_hash, 10000)
    return parse_mix_call(mixer_instance, tx_receipt)
Exemple #3
0
 def verifier_constructor_parameters(
         vk: GenericVerificationKey) -> Dict[str, List[int]]:
     return {
         "Alpha": hex_to_int(vk["alpha_g1"]),
         "Beta1": hex_to_int(vk["beta_g2"][0]),
         "Beta2": hex_to_int(vk["beta_g2"][1]),
         "Delta1": hex_to_int(vk["delta_g2"][0]),
         "Delta2": hex_to_int(vk["delta_g2"][1]),
         "ABC_coords": hex_to_int(sum(vk["abc_g1"], [])),
     }
Exemple #4
0
def mix_parameters_as_contract_arguments(
        zksnark: IZKSnarkProvider,
        mix_parameters: MixParameters) -> List[Any]:
    """
    Convert MixParameters to a list of eth ABI objects which can be passed to
    the contract's mix method.
    """
    proof_params: List[Any] = zksnark.mixer_proof_parameters(
        mix_parameters.extended_proof)
    proof_params.extend([
        verification_key_as_mix_parameter(mix_parameters.signature_vk),
        signature_as_mix_parameter(mix_parameters.signature),
        hex_to_int(mix_parameters.extended_proof["inputs"]),
        mix_parameters.ciphertexts
    ])
    return proof_params
Exemple #5
0
 def verifier_constructor_parameters(
         vk: GenericVerificationKey) -> Dict[str, List[int]]:
     return {
         "A1": hex_to_int(vk["a"][0]),
         "A2": hex_to_int(vk["a"][1]),
         "B": hex_to_int(vk["b"]),
         "C1": hex_to_int(vk["c"][0]),
         "C2": hex_to_int(vk["c"][1]),
         "gamma1": hex_to_int(vk["g"][0]),
         "gamma2": hex_to_int(vk["g"][1]),
         "gammaBeta1": hex_to_int(vk["gb1"]),
         "gammaBeta2_1": hex_to_int(vk["gb2"][0]),
         "gammaBeta2_2": hex_to_int(vk["gb2"][1]),
         "Z1": hex_to_int(vk["z"][0]),
         "Z2": hex_to_int(vk["z"][1]),
         "IC_coefficients": hex_to_int(sum(vk["IC"], [])),
     }