8000 Client proof types by dtebbs · Pull Request #289 · clearmatics/zeth · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Client proof types #289

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Oct 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion client/.pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ disable=
duplicate-code,
fixme

good-names=i,e,x,y,m,k,h,c,cm,rc,ek,ct,vk,sk,pk,X,Y,r,el,nf,g1,g2
good-names=a,b,c,e,g,h,i,k,m,x,y,z,cm,ic,rc,ek,ct,vk,sk,pk,X,Y,r,el,nf,g1,g2

max-attributes=10

[REPORTS]
output-format=text
42 changes: 25 additions & 17 deletions client/test_commands/scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from zeth.core.mixer_client import MixerClient, OwnershipKeyPair, \
joinsplit_sign, encrypt_notes, get_dummy_input_and_address, \
compute_h_sig, JoinsplitSigVerificationKey
from zeth.core.zksnark import IZKSnarkProvider
import zeth.core.contracts as contracts
from zeth.core.constants import ZETH_PRIME, FIELD_CAPACITY
import zeth.core.signing as signing
Expand Down Expand Up @@ -143,6 +144,7 @@ def charlie_withdraw(


def charlie_double_withdraw(
zksnark: IZKSnarkProvider,
zeth_client: MixerClient,
mk_tree: MerkleTree,
input1: Tuple[int, ZethNote],
Expand Down Expand Up @@ -214,7 +216,7 @@ def compute_h_sig_attack_nf(
return compute_h_sig(
bytes.fromhex(attack_nf0), bytes.fromhex(attack_nf1), sign_vk)

(output_note1, output_note2, proof_json, signing_keypair) = \
(output_note1, output_note2, proof, signing_keypair) = \
zeth_client.get_proof_joinsplit_2_by_2(
mk_root,
input1,
Expand All @@ -234,11 +236,11 @@ def compute_h_sig_attack_nf(
assert attack_primary_input3 != 0
assert attack_primary_input4 != 0

print("proof_json => ", proof_json)
print("proof_json[inputs][3] => ", proof_json["inputs"][3])
print("proof_json[inputs][4] => ", proof_json["inputs"][4])
proof_json["inputs"][3] = hex(attack_primary_input3)
proof_json["inputs"][4] = hex(attack_primary_input4)
print("proof = ", proof)
print("proof.inputs[3] = ", proof.inputs[3])
print("proof.inputs[4] = ", proof.inputs[4])
proof.inputs[3] = hex(attack_primary_input3)
proof.inputs[4] = hex(attack_primary_input4)
# ### ATTACK BLOCK

# construct pk object from bytes
Expand All @@ -251,13 +253,14 @@ def compute_h_sig_attack_nf(

# Compute the joinSplit signature
joinsplit_sig_charlie = joinsplit_sign(
zksnark,
signing_keypair,
charlie_eth_address,
ciphertexts,
proof_json)
proof)

mix_params = contracts.MixParameters(
proof_json,
proof,
signing_keypair.vk,
joinsplit_sig_charlie,
ciphertexts)
Expand All @@ -273,6 +276,7 @@ def compute_h_sig_attack_nf(


def charlie_corrupt_bob_deposit(
zksnark: IZKSnarkProvider,
zeth_client: MixerClient,
mk_tree: MerkleTree,
bob_eth_address: str,
Expand Down Expand Up @@ -320,7 +324,7 @@ def charlie_corrupt_bob_deposit(

v_in = to_zeth_units(EtherValue(BOB_DEPOSIT_ETH))

(output_note1, output_note2, proof_json, joinsplit_keypair) = \
(output_note1, output_note2, proof, joinsplit_keypair) = \
zeth_client.get_proof_joinsplit_2_by_2(
mk_root,
input1,
Expand Down Expand Up @@ -353,13 +357,14 @@ def charlie_corrupt_bob_deposit(
result_corrupt1 = None
try:
joinsplit_sig_charlie = joinsplit_sign(
zksnark,
joinsplit_keypair,
charlie_eth_address,
ciphertexts,
proof_json)
proof)

mix_params = contracts.MixParameters(
proof_json,
proof,
joinsplit_keypair.vk,
joinsplit_sig_charlie,
[fake_ciphertext0, fake_ciphertext1])
Expand Down Expand Up @@ -391,12 +396,13 @@ def charlie_corrupt_bob_deposit(
result_corrupt2 = None
try:
joinsplit_sig_charlie = joinsplit_sign(
zksnark,
new_joinsplit_keypair,
charlie_eth_address,
[fake_ciphertext0, fake_ciphertext1],
proof_json)
proof)
mix_params = contracts.MixParameters(
proof_json,
proof,
new_joinsplit_keypair.vk,
joinsplit_sig_charlie,
[fake_ciphertext0, fake_ciphertext1])
Expand All @@ -420,12 +426,13 @@ def charlie_corrupt_bob_deposit(
result_corrupt3 = None
try:
joinsplit_sig_bob = joinsplit_sign(
zksnark,
joinsplit_keypair,
bob_eth_address,
ciphertexts,
proof_json)
proof)
mix_params = contracts.MixParameters(
proof_json,
proof,
joinsplit_keypair.vk,
joinsplit_sig_bob,
ciphertexts)
Expand All @@ -448,12 +455,13 @@ def charlie_corrupt_bob_deposit(

# Bob transaction is finally mined
joinsplit_sig_bob = joinsplit_sign(
zksnark,
joinsplit_keypair,
bob_eth_address,
ciphertexts,
proof_json)
proof)
mix_params = contracts.MixParameters(
proof_json,
proof,
joinsplit_keypair.vk,
joinsplit_sig_bob,
ciphertexts)
Expand Down
2 changes: 2 additions & 0 deletions client/test_commands/test_erc_token_mixing.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ def _receive_notes(
# New commitments are added in the tree at each withdraw so we
# recompute the path to have the updated nodes
result_double_spending = scenario.charlie_double_withdraw(
zksnark,
zeth_client,
mk_tree,
note_descs_charlie[0].as_input(),
Expand Down Expand Up @@ -286,6 +287,7 @@ def _receive_notes(
print("- The allowance for the Mixer from Bob is:", allowance_mixer)

result_deposit_bob_to_bob = scenario.charlie_corrupt_bob_deposit(
zksnark,
zeth_client,
mk_tree,
bob_eth_address,
Expand Down
2 changes: 2 additions & 0 deletions client/test_commands/test_ether_mixing.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ def _receive_notes(
# New commitments are added in the tree at each withdraw so we
# recompiute the path to have the updated nodes
result_double_spending = scenario.charlie_double_withdraw(
zksnark,
zeth_client,
mk_tree,
input_charlie_withdraw.as_input(),
Expand All @@ -219,6 +220,7 @@ def _receive_notes(
# Bob deposits once again ETH, split in 2 notes on the mixer
# But Charlie attempts to corrupt the transaction (malleability attack)
result_deposit_bob_to_bob = scenario.charlie_corrupt_bob_deposit(
zksnark,
zeth_client,
mk_tree,
bob_eth_address,
Expand Down
25 changes: 15 additions & 10 deletions client/tests/test_contracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
Tests for zeth.core.contracts module
"""

from zeth.core.zksnark import ExtendedProof, Groth16
from zeth.core.contracts import MixParameters
from zeth.core.encryption import generate_encryption_keypair, encrypt
from zeth.core.signing import gen_signing_keypair, sign, encode_vk_to_bytes
Expand All @@ -17,18 +18,20 @@
class TestContracts(TestCase):

def test_mix_parameters(self) -> None:

ext_proof = {
"a": ["1234", "2345"],
"b": [["3456", "4567"], ["5678", "6789"]],
"c": ["789a", "89ab"],
"inputs": [
zksnark = Groth16()

ext_proof = ExtendedProof(
proof=Groth16.proof_from_json_dict({
"a": ["1234", "2345"],
"minus_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"))
Expand All @@ -41,9 +44,11 @@ def test_mix_parameters(self) -> None:
mix_params = MixParameters(ext_proof, sig_vk, sig, ciphertexts)

mix_params_json = mix_params.to_json()
mix_params_2 = MixParameters.from_json(mix_params_json)
mix_params_2 = MixParameters.from_json(zksnark, mix_params_json)

self.assertEqual(mix_params.extended_proof, mix_params_2.extended_proof)
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))
Expand Down
Loading
0