8000 Fixed inconsistencies between CamelCase and snake_case in python client by AntoineRondelet · Pull Request #107 · clearmatics/zeth · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fixed inconsistencies between CamelCase and snake_case in python client #107

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 1 commit into from
Nov 6, 2019
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
64 changes: 32 additions & 32 deletions pyClient/test_commands/mock.py
Original file line number Diff line number Diff line change
@@ -1,73 +1,73 @@
import zeth.grpc


def initTestKeystore():
def init_test_keystore():
"""
Keystore for the tests
"""

# Alice credentials in the zeth abstraction
AliceOwnershipKeys = zeth.grpc.generateApkAskKeypair()
Alice25519EncPublicKey = \
alice_ownership_keys = zeth.grpc.gen_apk_ask_keypair()
alice_25519_enc_public_key = \
b'\x1eO"\n\xdaWnU+\xf5\xaa\x8a#\xd2*\xd3\x11\x9fc\xe52 \xd8^\xbc-' + \
b'\xb6\xf1\xeej\xf41'
Alice25519EncPrivateKey = \
alice_25519_enc_private_key = \
b'\xde\xa2\xc1\x0b\xd1\xf7\x13\xf8J\xa4:\xa4\xb6\xfa\xbd\xd5\xc9' + \
b'\x8a\xd9\xb6\xb4\xc4\xc4I\x88\xa4\xd9\xe2\xee\x9e\x9a\xff'

# Bob credentials in the zeth abstraction
BobOwnershipKeys = zeth.grpc.generateApkAskKeypair()
Bob25519EncPublicKey = \
bob_ownership_keys = zeth.grpc.gen_apk_ask_keypair()
bob_25519_enc_public_key = \
b't\xc5{5j\xb5\x8a\xd3n\xb3\xab9\xe8s^13\xba\xa2\x91x\xb01(\xf9' + \
b'\xbb\xf9@r_\x91}'
Bob25519EncPrivateKey = \
bob_25519_enc_private_key = \
b'\xd3\xf0\x8f ,\x1d#\xdc\xac,\x93\xbd\xd0\xd9\xed\x8c\x92\x822' + \
b'\xef\xd6\x97^\x86\xf7\xe4/\x85\xb6\x10\xe6o'

# Charlie credentials in the zeth abstraction
CharlieOwnershipKeys = zeth.grpc.generateApkAskKeypair()
Charlie25519EncPublicKey = \
charlie_ownership_keys = zeth.grpc.gen_apk_ask_keypair()
charlie_25519_enc_public_key = \
b'u\xe7\x88\x9c\xbfE(\xf8\x99\xca<\xa8[<\xa2\x88m\xad\rN"\xf0}' + \
b'\xec\xfcB\x89\xe6\x96\xcf\x19U'
Charlie25519EncPrivateKey = b'zH\xb66q\x97\x0bO\xcb\xb9q\x9b\xbd-1`I' + \
charlie_25519_enc_private_key = b'zH\xb66q\x97\x0bO\xcb\xb9q\x9b\xbd-1`I' + \
b'\xae\x00-\x11\xb9\xed}\x18\x9f\xf6\x8dr\xaa\xd4R'

keystore = {
"Alice": {
"AddrPk": {
"encPK": Alice25519EncPublicKey,
"aPK": AliceOwnershipKeys["aPK"]
"addr_pk": {
"enc_pk": alice_25519_enc_public_key,
"apk": alice_ownership_keys["apk"]
},
"AddrSk": {
"encSK": Alice25519EncPrivateKey,
"aSK": AliceOwnershipKeys["aSK"]
"addr_sk": {
"enc_sk": alice_25519_enc_private_key,
"ask": alice_ownership_keys["ask"]
}
},
"Bob": {
"AddrPk": {
"encPK": Bob25519EncPublicKey,
"aPK": BobOwnershipKeys["aPK"]
"addr_pk": {
"enc_pk": bob_25519_enc_public_key,
"apk": bob_ownership_keys["apk"]
},
"AddrSk": {
"encSK": Bob25519EncPrivateKey,
"aSK": BobOwnershipKeys["aSK"]
"addr_sk": {
"enc_sk": bob_25519_enc_private_key,
"ask": bob_ownership_keys["ask"]
}
},
"Charlie": {
"AddrPk": {
"encPK": Charlie25519EncPublicKey,
"aPK": CharlieOwnershipKeys["aPK"]
"addr_pk": {
"enc_pk": charlie_25519_enc_public_key,
"apk": charlie_ownership_keys["apk"]
},
"AddrSk": {
"encSK": Charlie25519EncPrivateKey,
"aSK": CharlieOwnershipKeys["aSK"]
"addr_sk": {
"enc_sk": charlie_25519_enc_private_key,
"ask": charlie_ownership_keys["ask"]
}
}
}
return keystore


def getDummyMerklePath(length):
def get_dummy_merkle_path(length):
mkPath = []
# Arbitrary sha256 digest used to build the dummy merkle path
dummyNode = "6461f753bfe21ba2219ced74875b8dbd8c114c3c79d7e41306dd82118de1895b"
Expand All @@ -76,9 +76,9 @@ def getDummyMerklePath(length):
return mkPath


def getDummyInput(recipient_apk, recipient_ask):
def get_dummy_input(recipient_apk, recipient_ask):
zero_wei_hex = "0000000000000000"
dummy_note = zeth.grpc.createZethNote(zeth.grpc.noteRandomness(), recipient_apk, zero_wei_hex)
dummy_note_nullifier = zeth.grpc.computeNullifier(dummy_note, recipient_ask)
dummy_note = zeth.grpc.create_zeth_note(zeth.grpc.gen_note_randomness(), recipient_apk, zero_wei_hex)
dummy_note_nullifier = zeth.grpc.compute_nullifier(dummy_note, recipient_ask)
dummy_note_address = 7
return (dummy_note, dummy_note_nullifier, dummy_note_address)
78 changes: 39 additions & 39 deletions pyClient/test_commands/scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,19 @@ def bob_deposit(
print(
f"=== Bob deposits {BOB_DEPOSIT_ETH} ETH for himself and splits into " +
f"note1: {BOB_SPLIT_1_ETH}ETH, note2: {BOB_SPLIT_2_ETH}ETH ===")
bob_apk = keystore["Bob"]["AddrPk"]["aPK"]
bob_ask = keystore["Bob"]["AddrSk"]["aSK"]
bob_apk = keystore["Bob"]["addr_pk"]["apk"]
bob_ask = keystore["Bob"]["addr_sk"]["ask"]
# Create the JoinSplit dummy inputs for the deposit
(input_note1, input_nullifier1, input_address1) = mock.getDummyInput(bob_apk, bob_ask)
(input_note2, input_nullifier2, input_address2) = mock.getDummyInput(bob_apk, bob_ask)
dummy_mk_path = mock.getDummyMerklePath(mk_tree_depth)
(input_note1, input_nullifier1, input_address1) = mock.get_dummy_input(bob_apk, bob_ask)
(input_note2, input_nullifier2, input_address2) = mock.get_dummy_input(bob_apk, bob_ask)
dummy_mk_path = mock.get_dummy_merkle_path(mk_tree_depth)

note1_value = zeth.utils.to_zeth_units(str(BOB_SPLIT_1_ETH), 'ether')
note2_value = zeth.utils.to_zeth_units(str(BOB_SPLIT_2_ETH), 'ether')
v_in = zeth.utils.to_zeth_units(str(BOB_DEPOSIT_ETH), 'ether')

(output_note1, output_note2, proof_json, joinsplit_keypair) = \
zeth.grpc.getProofJoinsplit2By2(
zeth.grpc.get_proof_joinsplit_2_by_2(
test_grpc_endpoint,
mk_root,
input_note1,
Expand All @@ -65,14 +65,14 @@ def bob_deposit(
zksnark
)

output_note1_str = json.dumps(zeth.grpc.parseZethNote(output_note1))
output_note2_str = json.dumps(zeth.grpc.parseZethNote(output_note2))
output_note1_str = json.dumps(zeth.grpc.parse_zeth_note(output_note1))
output_note2_str = json.dumps(zeth.grpc.parse_zeth_note(output_note2))

# generate ephemeral ec25519 key
eph_sk_bob = PrivateKey.generate()

# construct pk object from bytes
pk_bob = zeth.utils.get_public_key_from_bytes(keystore["Bob"]["AddrPk"]["encPK"])
pk_bob = zeth.utils.get_public_key_from_bytes(keystore["Bob"]["addr_pk"]["enc_pk"])

# encrypt the coins
ciphertext1 = zeth.utils.encrypt(output_note1_str, pk_bob, eph_sk_bob)
Expand All @@ -93,7 +93,7 @@ def bob_deposit(
hash_proof = sha256(zeth.utils.encode_to_hash(proof)).hexdigest()

# Encode and hash the primary inputs
encoded_inputs = zeth.grpc.encodeInputToHash(proof_json["inputs"])
encoded_inputs = zeth.grpc.encode_pub_input_to_hash(proof_json["inputs"])
hash_inputs = sha256(encoded_inputs).hexdigest()

# Compute the joinSplit signature
Expand Down Expand Up @@ -128,22 +128,22 @@ def bob_to_charlie(
print(f"=== Bob transfers {BOB_TO_CHARLIE_ETH}ETH to Charlie from his funds on the mixer ===")

# We generate a coin for Charlie (recipient1)
charlie_apk = keystore["Charlie"]["AddrPk"]["aPK"]
charlie_apk = keystore["Charlie"]["addr_pk"]["apk"]
# We generate a coin for Bob: the change (recipient2)
bob_apk = keystore["Bob"]["AddrPk"]["aPK"]
bob_apk = keystore["Bob"]["addr_pk"]["apk"]
# Bob is the sender
bob_ask = keystore["Bob"]["AddrSk"]["aSK"]
bob_ask = keystore["Bob"]["addr_sk"]["ask"]

# Create the an additional dummy input for the JoinSplit
(input_note2, input_nullifier2, input_address2) = mock.getDummyInput(
8000 (input_note2, input_nullifier2, input_address2) = mock.get_dummy_input(
bob_apk, bob_ask)
dummy_mk_path = mock.getDummyMerklePath(mk_tree_depth)
dummy_mk_path = mock.get_dummy_merkle_path(mk_tree_depth)

note1_value = zeth.utils.to_zeth_units(str(BOB_TO_CHARLIE_ETH), 'ether')
note2_value = zeth.utils.to_zeth_units(str(BOB_TO_CHARLIE_CHANGE_ETH), 'ether')

(output_note1, output_note2, proof_json, joinsplit_keypair) = \
zeth.grpc.getProofJoinsplit2By2(
zeth.grpc.get_proof_joinsplit_2_by_2(
test_grpc_endpoint,
mk_root,
input_note1,
Expand All @@ -162,15 +162,15 @@ def bob_to_charlie(
zksnark
)

output_note1_str = json.dumps(zeth.grpc.parseZethNote(output_note1))
output_note2_str = json.dumps(zeth.grpc.parseZethNote(output_note2))
output_note1_str = json.dumps(zeth.grpc.parse_zeth_note(output_note1))
output_note2_str = json.dumps(zeth.grpc.parse_zeth_note(output_note2))

# generate ephemeral ec25519 key
eph_sk_bob = PrivateKey.generate()

# construct pk objects from bytes
pk_bob = zeth.utils.get_public_key_from_bytes(keystore["Bob"]["AddrPk"]["encPK"])
pk_charlie = zeth.utils.get_public_key_from_bytes(keystore["Charlie"]["AddrPk"]["encPK"])
pk_bob = zeth.utils.get_public_key_from_bytes(keystore["Bob"]["addr_pk"]["enc_pk"])
pk_charlie = zeth.utils.get_public_key_from_bytes(keystore["Charlie"]["addr_pk"]["enc_pk"])

# encrypt the coins
# Bob is the recipient
Expand All @@ -191,7 +191,7 @@ def bob_to_charlie(
hash_proof = sha256(zeth.utils.encode_to_hash(proof)).hexdigest()

# Encode and hash the primary inputs
encoded_inputs = zeth.grpc.encodeInputToHash(proof_json["inputs"])
encoded_inputs = zeth.grpc.encode_pub_input_to_hash(proof_json["inputs"])
hash_inputs = sha256(encoded_inputs).hexdigest()

# Compute the joinSplit signature
Expand Down Expand Up @@ -227,19 +227,19 @@ def charlie_withdraw(
zksnark):
print(f" === Charlie withdraws {CHARLIE_WITHDRAW_ETH}ETH from his funds on the Mixer ===")

charlie_apk = keystore["Charlie"]["AddrPk"]["aPK"]
charlie_ask = keystore["Charlie"]["AddrSk"]["aSK"]
charlie_apk = keystore["Charlie"]["addr_pk"]["apk"]
charlie_ask = keystore["Charlie"]["addr_sk"]["ask"]

# Create the an additional dummy input for the JoinSplit
(input_note2, input_nullifier2, input_address2) = mock.getDummyInput(
(input_note2, input_nullifier2, input_address2) = mock.get_dummy_input(
charlie_apk, charlie_ask)
dummy_mk_path = mock.getDummyMerklePath(mk_tree_depth)
dummy_mk_path = mock.get_dummy_merkle_path(mk_tree_depth)

note1_value = zeth.utils.to_zeth_units(str(CHARLIE_WITHDRAW_CHANGE_ETH), 'ether')
v_out = zeth.utils.to_zeth_units(str(CHARLIE_WITHDRAW_ETH), 'ether')

(output_note1, output_note2, proof_json, joinsplit_keypair) = \
zeth.grpc.getProofJoinsplit2By2(
zeth.grpc.get_proof_joinsplit_2_by_2(
test_grpc_endpoint,
mk_root,
input_note1,
Expand All @@ -258,15 +258,15 @@ def charlie_withdraw(
zksnark
)

output_note1_str = json.dumps(zeth.grpc.parseZethNote(output_note1))
output_note2_str = json.dumps(zeth.grpc.parseZethNote(output_note2))
output_note1_str = json.dumps(zeth.grpc.parse_zeth_note(output_note1))
output_note2_str = json.dumps(zeth.grpc.parse_zeth_note(output_note2))

# generate ephemeral ec25519 key
eph_sk_charlie = PrivateKey.generate()

# construct pk object from bytes
pk_charlie = zeth.utils.get_public_key_from_bytes(
keystore["Charlie"]["AddrPk"]["encPK"])
keystore["Charlie"]["addr_pk"]["enc_pk"])

# encrypt the coins
# Charlie is the recipient
Expand All @@ -287,7 +287,7 @@ def charlie_withdraw(
hash_proof = sha256(zeth.utils.encode_to_hash(proof)).hexdigest()

# Encode and hash the primary inputs
encoded_inputs = zeth.grpc.encodeInputToHash(proof_json["inputs"])
encoded_inputs = zeth.grpc.encode_pub_input_to_hash(proof_json["inputs"])
hash_inputs = sha256(encoded_inputs).hexdigest()

# Compute the joinSplit signature
Expand Down Expand Up @@ -329,19 +329,19 @@ def charlie_double_withdraw(
f" === Charlie attempts to withdraw {CHARLIE_WITHDRAW_ETH}ETH once more " +
"(double spend) one of his note on the Mixer ===")

charlie_apk = keystore["Charlie"]["AddrPk"]["aPK"]
charlie_ask = keystore["Charlie"]["AddrSk"]["aSK"]
charlie_apk = keystore["Charlie"]["addr_pk"]["apk"]
charlie_ask = keystore["Charlie"]["addr_sk"]["ask"]

# Create the an additional dummy input for the JoinSplit
(input_note2, input_nullifier2, input_address2) = \
mock.getDummyInput(charlie_apk, charlie_ask)
dummy_mk_path = mock.getDummyMerklePath(mk_tree_depth)
mock.get_dummy_input(charlie_apk, charlie_ask)
dummy_mk_path = mock.get_dummy_merkle_path(mk_tree_depth)

note1_value = zeth.utils.to_zeth_units(str(CHARLIE_WITHDRAW_CHANGE_ETH), 'ether')
v_out = zeth.utils.to_zeth_units(str(CHARLIE_WITHDRAW_ETH), 'ether')

(output_note1, output_note2, proof_json, joinsplit_keypair) = \
zeth.grpc.getProofJoinsplit2By2(
zeth.grpc.get_proof_joinsplit_2_by_2(
test_grpc_endpoint,
mk_root,
input_note1,
Expand Down Expand Up @@ -371,14 +371,14 @@ def charlie_double_withdraw(
proof_json["inputs"][4] = hex(int(proof_json["inputs"][4], 16) + r)
# ### ATTACK BLOCK

output_note1_str = json.dumps(zeth.grpc.parseZethNote(output_note1))
output_note2_str = json.dumps(zeth.grpc.parseZethNote(output_note2))
output_note1_str = json.dumps(zeth.grpc.parse_zeth_note(output_note1))
output_note2_str = json.dumps(zeth.grpc.parse_zeth_note(output_note2))

# generate ephemeral ec25519 key
eph_sk_charlie = PrivateKey.generate()

# construct pk object from bytes
pk_charlie = zeth.utils.get_public_key_from_bytes(keystore["Charlie"]["AddrPk"]["encPK"])
pk_charlie = zeth.utils.get_public_key_from_bytes(keystore["Charlie"]["addr_pk"]["enc_pk"])

# encrypt the coins
# Charlie is the recipient
Expand All @@ -399,7 +399,7 @@ def charlie_double_withdraw(
hash_proof = sha256(zeth.utils.encode_to_hash(proof)).hexdigest()

# Encode and hash the primary inputs
encoded_inputs = zeth.grpc.encodeInputToHash(proof_json["inputs"])
encoded_inputs = zeth.grpc.encode_pub_input_to_hash(proof_json["inputs"])
hash_inputs = sha256(encoded_inputs).hexdigest()

# Compute the joinSplit signature
Expand Down
16 changes: 8 additions & 8 deletions pyClient/test_commands/test_erc_token_mixing.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,15 @@ def mint_token(token_instance, spender_address, deployer_address, token_amount):
alice_eth_address = w3.eth.accounts[2]
charlie_eth_address = w3.eth.accounts[3]
# Zeth addresses
keystore = mock.initTestKeystore()
keystore = mock.init_test_keystore()
# Depth of the merkle tree (need to match the one used in the cpp prover)
mk_tree_depth = constants.ZETH_MERKLE_TREE_DEPTH

print("[INFO] 1. Fetching the verification key from the proving server")
vk = zeth.grpc.getVerificationKey(test_grpc_endpoint)
vk = zeth.grpc.get_verification_key(test_grpc_endpoint)

print("[INFO] 2. Received VK, writing the key...")
zeth.grpc.writeVerificationKey(vk, zksnark)
zeth.grpc.write_verification_key(vk, zksnark)

print("[INFO] 3. VK written, deploying the smart contracts...")
token_interface = compile_token()
Expand Down Expand Up @@ -185,7 +185,7 @@ def mint_token(token_instance, spender_address, deployer_address, token_amount):

# Construct sk and pk objects from bytes
alice_sk = zeth.utils.get_private_key_from_bytes(
keystore["Alice"]["AddrSk"]["encSK"])
keystore["Alice"]["addr_sk"]["enc_sk"])
pk_sender = zeth.utils.get_public_key_from_bytes(pk_sender_bob_to_bob)

# Alice sees a deposit and tries to decrypt the ciphertexts to see if she was the recipient
Expand All @@ -209,11 +209,11 @@ def mint_token(token_instance, spender_address, deployer_address, token_amount):
# Bob decrypts one of the note he previously received (useless here but
# useful if the payment came from someone else)
bob_sk = zeth.utils.get_private_key_from_bytes(
keystore["Bob"]["AddrSk"]["encSK"])
keystore["Bob"]["addr_sk"]["enc_sk"])
input_note_json = json.loads(
zeth.utils.decrypt(ciphertext_bob_to_bob1, pk_sender, bob_sk))
input_note_bob_to_charlie = \
zeth.grpc.zethNoteObjFromParsed(input_note_json)
zeth.grpc.zeth_note_obj_from_parsed(input_note_json)
# Execution of the transfer
result_transfer_bob_to_charlie = scenario.bob_to_charlie(
test_grpc_endpoint,
Expand Down Expand Up @@ -266,7 +266,7 @@ def mint_token(token_instance, spender_address, deployer_address, token_amount):

# Construct sk and pk objects from bytes
charlie_sk = zeth.utils.get_private_key_from_bytes(
keystore["Charlie"]["AddrSk"]["encSK"])
keystore["Charlie"]["addr_sk"]["enc_sk"])
pk_sender = zeth.utils.get_public_key_from_bytes(pk_sender_bob_to_charlie)

# Charlie tries to decrypt the ciphertexts from Bob's previous transaction
Expand All @@ -283,7 +283,7 @@ def mint_token(token_instance, spender_address, deployer_address, token_amount):
mk_byte_tree = get_merkle_tree(mixer_instance)
mk_path = zeth.utils.compute_merkle_path(
cm_address_bob_to_charlie2, mk_tree_depth, mk_byte_tree)
input_note_charlie_withdraw = zeth.grpc.zethNoteObjFromParsed(
input_note_charlie_withdraw = zeth.grpc.zeth_note_obj_from_parsed(
json.loads(recovered_plaintext2))
result_charlie_withdrawal = scenario.charlie_withdraw(
test_grpc_endpoint,
Expand Down
Loading
0