Zeth - Zerocash on Ethereum
0.8
Reference implementation of the Zeth protocol by Clearmatics
|
|
List[Any] | mix_parameters_to_contract_arguments (IZKSnarkProvider zksnark, PairingParameters pp, MixParameters mix_parameters) |
|
bytes | mix_parameters_to_dispatch_parameters (MixParameters mix_parameters) |
|
MixResult | event_args_to_mix_result (Any event_args) |
|
api.JoinsplitInput | create_api_joinsplit_input (List[str] merkle_path, int address, api.ZethNote note, OwnershipSecretKey a_sk, bytes nullifier) |
|
Tuple[int, api.ZethNote] | get_dummy_input_and_address (OwnershipPublicKey a_pk) |
|
List[bytes] | encrypt_notes (List[Tuple[api.ZethNote, EncryptionPublicKey]] notes) |
|
Optional[Tuple[bytes, api.ZethNote]] | receive_note (MixOutputEvents out_ev, EncryptionSecretKey receiver_k_sk) |
|
Iterator[MixResult] | get_mix_results (Any web3, Any mixer_instance, int start_block, int end_block, Optional[int] batch_size=None) |
|
int | joinsplit_sign (IZKSnarkProvider zksnark, PairingParameters pp, JoinsplitSigKeyPair signing_keypair, str sender_eth_address, List[bytes] ciphertexts, ExtendedProof extproof, List[int] public_data, bool for_dispatch_call=False) |
|
bytes | compute_commitment (api.ZethNote zeth_note, PairingParameters pp) |
|
bytes | compute_nullifier (api.ZethNote zeth_note, OwnershipSecretKey spending_authority_ask) |
|
bytes | compute_h_sig (List[bytes] nullifiers, JoinsplitSigVerificationKey sign_vk) |
|
◆ compute_commitment()
bytes zeth.core.mixer_client.compute_commitment |
( |
api.ZethNote |
zeth_note, |
|
|
PairingParameters |
pp |
|
) |
| |
Used by the recipient of a payment to recompute the commitment and check
the membership in the tree to confirm the validity of a payment
Definition at line 701 of file mixer_client.py.
703 Used by the recipient of a payment to recompute the commitment and check
704 the membership in the tree to confirm the validity of a payment
708 blake.update(bytes.fromhex(zeth_note.trap_r))
709 blake.update(bytes.fromhex(zeth_note.apk))
710 blake.update(bytes.fromhex(zeth_note.rho))
711 blake.update(bytes.fromhex(zeth_note.value))
714 cm_field = int.from_bytes(cm, byteorder=
"big") % pp.scalar_field_mod()
715 return cm_field.to_bytes(
int(constants.DIGEST_LENGTH/8), byteorder=
"big")
◆ compute_h_sig()
Compute h_sig = sha256(nf_1 || ... || nf_{JS_INPUTS} || sign_vk)
Definition at line 734 of file mixer_client.py.
735 nullifiers: List[bytes],
736 sign_vk: JoinsplitSigVerificationKey) -> bytes:
738 Compute h_sig = sha256(nf_1 || ... || nf_{JS_INPUTS} || sign_vk)
741 for nf
in nullifiers:
743 h.update(sign_vk.to_bytes())
◆ compute_nullifier()
bytes zeth.core.mixer_client.compute_nullifier |
( |
api.ZethNote |
zeth_note, |
|
|
OwnershipSecretKey |
spending_authority_ask |
|
) |
| |
Returns nf = blake2s(1110 || [a_sk]_252 || rho)
Definition at line 718 of file mixer_client.py.
719 zeth_note: api.ZethNote,
720 spending_authority_ask: OwnershipSecretKey) -> bytes:
722 Returns nf = blake2s(1110 || [a_sk]_252 || rho)
725 first_252bits_ask = binary_ask[:252]
726 left_leg_bin =
"1110" + first_252bits_ask
727 left_leg =
int(left_leg_bin, 2).to_bytes(32, byteorder=
'big')
728 blake_hash = blake2s()
729 blake_hash.update(left_leg)
730 blake_hash.update(bytes.fromhex(zeth_note.rho))
731 return blake_hash.digest()
◆ create_api_joinsplit_input()
api.JoinsplitInput zeth.core.mixer_client.create_api_joinsplit_input |
( |
List[str] |
merkle_path, |
|
|
int |
address, |
|
|
api.ZethNote |
note, |
|
|
OwnershipSecretKey |
a_sk, |
|
|
bytes |
nullifier |
|
) |
| |
Definition at line 227 of file mixer_client.py.
228 merkle_path: List[str],
231 a_sk: OwnershipSecretKey,
232 nullifier: bytes) -> api.JoinsplitInput:
233 return api.JoinsplitInput(
234 merkle_path=merkle_path,
238 nullifier=nullifier.hex())
◆ encrypt_notes()
List[bytes] zeth.core.mixer_client.encrypt_notes |
( |
List[Tuple[api.ZethNote, EncryptionPublicKey]] |
notes | ) |
|
Encrypts a set of output notes to be decrypted by the respective receivers.
Returns the ciphertexts corresponding to each note.
Definition at line 601 of file mixer_client.py.
602 notes: List[Tuple[api.ZethNote, EncryptionPublicKey]]) -> List[bytes]:
604 Encrypts a set of output notes to be decrypted by the respective receivers.
605 Returns the ciphertexts corresponding to each note.
609 out_note: api.ZethNote, pub_key: EncryptionPublicKey) -> bytes:
610 out_note_bytes = proto_utils.zeth_note_to_bytes(out_note)
612 return encrypt(out_note_bytes, pub_key)
614 ciphertexts = [_encrypt_note(note, pk)
for (note, pk)
in notes]
◆ event_args_to_mix_result()
MixResult zeth.core.mixer_client.event_args_to_mix_result |
( |
Any |
event_args | ) |
|
Definition at line 218 of file mixer_client.py.
219 mix_out_args = zip(event_args.commitments, event_args.ciphertexts)
220 out_events = [MixOutputEvents(c, ciph)
for (c, ciph)
in mix_out_args]
222 new_merkle_root=event_args.root,
223 nullifiers=event_args.nullifiers,
224 output_events=out_events)
◆ get_dummy_input_and_address()
Tuple[int, api.ZethNote] zeth.core.mixer_client.get_dummy_input_and_address |
( |
OwnershipPublicKey |
a_pk | ) |
|
Create a zeth note and address, for use as circuit inputs where there is no
real input.
Definition at line 241 of file mixer_client.py.
242 a_pk: OwnershipPublicKey) -> Tuple[int, api.ZethNote]:
244 Create a zeth note and address, for use as circuit inputs where there is no
247 dummy_note = api.ZethNote(
249 value=ZERO_UNITS_HEX,
250 rho=_get_dummy_rho(),
251 trap_r=_trap_r_randomness())
255 dummy_note_address = 0
256 return (dummy_note_address, dummy_note)
◆ get_mix_results()
Iterator[MixResult] zeth.core.mixer_client.get_mix_results |
( |
Any |
web3, |
|
|
Any |
mixer_instance, |
|
|
int |
start_block, |
|
|
int |
end_block, |
|
|
Optional[int] |
batch_size = None |
|
) |
| |
Iterator for all events generated by 'mix' executions, over some block
range (inclusive of `end_block`). Batch eth RPC calls to avoid too many
calls, and holding huge lists of events in memory.
Definition at line 640 of file mixer_client.py.
645 batch_size: Optional[int] =
None) -> Iterator[MixResult]:
647 Iterator for all events generated by 'mix' executions, over some block
648 range (inclusive of `end_block`). Batch eth RPC calls to avoid too many
649 calls, and holding huge lists of events in memory.
651 logs = contracts.get_event_logs(
652 web3, mixer_instance,
"LogMix", start_block, end_block, batch_size)
653 for event_data
in logs:
◆ joinsplit_sign()
Generate a signature on the hash of the ciphertexts, proofs and primary
inputs. This is used to solve transaction malleability. We chose to sign
the hash and not the values themselves for modularity (to use the same code
regardless of whether GROTH16 or PGHR13 proof system is chosen), and sign
the hash of the ciphers and inputs for consistency. If for_dispatch_call is
set, the parameters are to be passed to the Mixer's `dispatch` call in a
later operation (in which proof data is not available), hence proof is
omitted from the signature.
Definition at line 657 of file mixer_client.py.
658 zksnark: IZKSnarkProvider,
659 pp: PairingParameters,
660 signing_keypair: JoinsplitSigKeyPair,
661 sender_eth_address: str,
662 ciphertexts: List[bytes],
663 extproof: ExtendedProof,
664 public_data: List[int],
665 for_dispatch_call: bool =
False) -> int:
667 Generate a signature on the hash of the ciphertexts, proofs and primary
668 inputs. This is used to solve transaction malleability. We chose to sign
669 the hash and not the values themselves for modularity (to use the same code
670 regardless of whether GROTH16 or PGHR13 proof system is chosen), and sign
671 the hash of the ciphers and inputs for consistency. If for_dispatch_call is
672 set, the parameters are to be passed to the Mixer's `dispatch` call in a
673 later operation (in which proof data is not available), hence proof is
674 omitted from the signature.
676 assert len(ciphertexts) == constants.JS_INPUTS
685 for ciphertext
in ciphertexts:
688 proof_bytes, pub_inputs_bytes = _proof_and_inputs_to_bytes(
689 zksnark, pp, extproof, public_data)
693 if not for_dispatch_call:
694 h.update(proof_bytes)
696 h.update(pub_inputs_bytes)
697 message_digest = h.digest()
698 return signing.sign(signing_keypair.sk, message_digest)
◆ mix_parameters_to_contract_arguments()
Convert MixParameters to a list of eth ABI objects which can be passed to
the contract's mix method.
Definition at line 157 of file mixer_client.py.
158 zksnark: IZKSnarkProvider,
159 pp: PairingParameters,
160 mix_parameters: MixParameters) -> List[Any]:
162 Convert MixParameters to a list of eth ABI objects which can be passed to
163 the contract's mix method.
165 proof_contract_params = zksnark.proof_to_contract_parameters(
166 mix_parameters.extended_proof.proof, pp)
168 proof_contract_params,
169 signing.verification_key_as_mix_parameter(mix_parameters.signature_vk),
170 signing.signature_as_mix_parameter(mix_parameters.signature),
171 mix_parameters.public_data,
172 mix_parameters.ciphertexts,
◆ mix_parameters_to_dispatch_parameters()
bytes zeth.core.mixer_client.mix_parameters_to_dispatch_parameters |
( |
MixParameters |
mix_parameters | ) |
|
Encode parameters from mix_parameters into an array of uint256 values,
compatible with the `dispatch` method on Mixer. This conforms to the
`IZecaleApplication` solidity interface of Zecale
(https://github.com/clearmatics/zecale)
Definition at line 176 of file mixer_client.py.
178 Encode parameters from mix_parameters into an array of uint256 values,
179 compatible with the `dispatch` method on Mixer. This conforms to the
180 `IZecaleApplication` solidity interface of Zecale
181 (https://github.com/clearmatics/zecale)
183 vk_param = signing.verification_key_as_mix_parameter(
184 mix_parameters.signature_vk)
185 sigma_param = signing.signature_as_mix_parameter(mix_parameters.signature)
186 public_data = mix_parameters.public_data
187 ciphertexts = mix_parameters.ciphertexts
188 return eth_abi.encode_abi(
189 [
'uint256[4]',
'uint256',
'uint256[]',
'bytes[]'],
190 [vk_param, sigma_param, public_data, ciphertexts])
◆ receive_note()
Optional[Tuple[bytes, api.ZethNote]] zeth.core.mixer_client.receive_note |
( |
MixOutputEvents |
out_ev, |
|
|
EncryptionSecretKey
|
receiver_k_sk |
|
) |
| |
Given the receivers secret key, and the event data from a transaction
(encrypted notes), decrypt any that are intended for the receiver. Return
tuples `(<address-in-merkle-tree>, ZethNote)`. Callers should record the
address-in-merkle-tree along with ZethNote information, for convenience
when spending the notes.
Definition at line 618 of file mixer_client.py.
619 out_ev: MixOutputEvents,
620 receiver_k_sk: EncryptionSecretKey
621 ) -> Optional[Tuple[bytes, api.ZethNote]]:
623 Given the receivers secret key, and the event data from a transaction
624 (encrypted notes), decrypt any that are intended for the receiver. Return
625 tuples `(<address-in-merkle-tree>, ZethNote)`. Callers should record the
626 address-in-merkle-tree along with ZethNote information, for convenience
627 when spending the notes.
630 plaintext =
decrypt(out_ev.ciphertext, receiver_k_sk)
633 proto_utils.zeth_note_from_bytes(plaintext))
634 except InvalidSignature:
◆ ComputeHSigCB
◆ JoinsplitSigKeyPair
◆ JoinsplitSigSecretKey
◆ JoinsplitSigVerificationKey
◆ ZERO_ADDRESS
string zeth.core.mixer_client.ZERO_ADDRESS = "0x0000000000000000000000000000000000000000" |
◆ ZERO_UNITS_HEX
string zeth.core.mixer_client.ZERO_UNITS_HEX = "0000000000000000" |
List[Any] mix_parameters_to_contract_arguments(IZKSnarkProvider zksnark, PairingParameters pp, MixParameters mix_parameters)
api.JoinsplitInput create_api_joinsplit_input(List[str] merkle_path, int address, api.ZethNote note, OwnershipSecretKey a_sk, bytes nullifier)
str ownership_key_as_hex(bytes a_sk)
Optional[Tuple[bytes, api.ZethNote]] receive_note(MixOutputEvents out_ev, EncryptionSecretKey receiver_k_sk)
List[bytes] encrypt_notes(List[Tuple[api.ZethNote, EncryptionPublicKey]] notes)
Tuple[int, api.ZethNote] get_dummy_input_and_address(OwnershipPublicKey a_pk)
bytes encrypt(bytes message, EncryptionPublicKey pk_receiver)
bytes mix_parameters_to_dispatch_parameters(MixParameters mix_parameters)
bytes eth_address_to_bytes32(str eth_addr)
str digest_to_binary_string(bytes digest)
int joinsplit_sign(IZKSnarkProvider zksnark, PairingParameters pp, JoinsplitSigKeyPair signing_keypair, str sender_eth_address, List[bytes] ciphertexts, ExtendedProof extproof, List[int] public_data, bool for_dispatch_call=False)
bytes compute_h_sig(List[bytes] nullifiers, JoinsplitSigVerificationKey sign_vk)
bytes compute_nullifier(api.ZethNote zeth_note, OwnershipSecretKey spending_authority_ask)
bytes decrypt(bytes encrypted_message, EncryptionSecretKey sk_receiver)
MixResult event_args_to_mix_result(Any event_args)
bytes compute_commitment(api.ZethNote zeth_note, PairingParameters pp)
Iterator[MixResult] get_mix_results(Any web3, Any mixer_instance, int start_block, int end_block, Optional[int] batch_size=None)