def test_mix_parameters(self) -> None: zksnark = Groth16() ext_proof = ExtendedProof(proof=Groth16.proof_from_json_dict({ "a": ["1234", "2345"], "b": [["3456", "4567"], ["5678", "6789"]], "c": ["789a", "89ab"], }), inputs=[ "9abc", "abcd", "bcde", "cdef", ]) sig_keypair = gen_signing_keypair() sig_vk = sig_keypair.vk sig = sign(sig_keypair.sk, bytes.fromhex("00112233")) receiver_enc_keypair = generate_encryption_keypair() ciphertexts = [ encrypt(token_bytes(NOTE_LENGTH_BYTES), receiver_enc_keypair.k_pk), encrypt(token_bytes(NOTE_LENGTH_BYTES), receiver_enc_keypair.k_pk), ] mix_params = MixParameters(ext_proof, sig_vk, sig, ciphertexts) mix_params_json = mix_params.to_json() mix_params_2 = MixParameters.from_json(zksnark, mix_params_json) self.assertEqual(mix_params.extended_proof.to_json_dict(), mix_params_2.extended_proof.to_json_dict()) self.assertEqual(encode_vk_to_bytes(mix_params.signature_vk), encode_vk_to_bytes(mix_params_2.signature_vk)) self.assertEqual(mix_params.signature, mix_params_2.signature) self.assertEqual(mix_params.ciphertexts, mix_params_2.ciphertexts)
def _invoke_groth16_bls12_377_verify(vk: Groth16.VerificationKey, proof: Groth16.Proof, inputs: List[str]) -> bool: vk_evm = Groth16.verification_key_to_contract_parameters( vk, BLS12_377_PAIRING) proof_evm = Groth16.proof_to_contract_parameters( proof, BLS12_377_PAIRING) inputs_evm = hex_list_to_uint256_list(inputs) return CONTRACT_INSTANCE.functions.testVerify(vk_evm, proof_evm, inputs_evm).call()
def test_proof_proto_encode_decode(self) -> None: extproof_1 = EXTPROOF_BLS12_377_GROTH16 self._do_test_ext_proof_proto_encode_decode(extproof_1, Groth16())
def test_verification_key_proto_encode_decode(self) -> None: vk_1 = VERIFICATION_KEY_BLS12_377_GROTH16 self._do_test_verification_key_proto_encode_decode(vk_1, Groth16())
def test_alt_bn128_groth16_proof_parameters(self) -> None: extproof = EXTPROOF_ALT_BN128_GROTH16 proof_parameters = Groth16.proof_to_contract_parameters( extproof.proof, ALT_BN128_PAIRING) self.assertEqual(PROOF_ALT_BN128_GROTH16_PARAMETERS, proof_parameters)
def test_alt_bn128_groth16_verification_key_parameters(self) -> None: vk = VERIFICATION_KEY_ALT_BN128_GROTH16 vk_parameters_expect = VERIFICATION_KEY_ALT_BN128_GROTH16_PARAMETERS vk_parameters = Groth16.verification_key_to_contract_parameters( vk, ALT_BN128_PAIRING) self.assertEqual(vk_parameters_expect, vk_parameters)
def test_bw6_761_groth16_proof_parameters(self) -> None: extproof = EXTPROOF_BW6_761_GROTH16 proof_parameters = Groth16.proof_to_contract_parameters( extproof.proof, BW6_761_PAIRING) self.assertEqual(PROOF_BW6_761_GROTH16_PARAMETERS, proof_parameters)
def test_bls12_377_groth16_verification_key_parameters(self) -> None: vk = VERIFICATION_KEY_BLS12_377_GROTH16 vk_parameters_expect = VERIFICATION_KEY_BLS12_377_GROTH16_PARAMETERS vk_parameters = Groth16.verification_key_to_contract_parameters( vk, BLS12_377_PAIRING) self.assertEqual(vk_parameters_expect, vk_parameters)