Zeth - Zerocash on Ethereum  0.8
Reference implementation of the Zeth protocol by Clearmatics
Public Member Functions | Public Attributes | List of all members
zeth.core.wallet.Wallet Class Reference

Public Member Functions

def __init__ (self, Any mixer_instance, str username, str wallet_dir, ZethAddressPriv secret_address, ITreeHash tree_hash)
 
Optional[ZethNoteDescriptionreceive_note (self, int comm_addr, MixOutputEvents out_ev, PairingParameters pp)
 
List[ZethNoteDescriptionreceive_notes (self, List[MixOutputEvents] output_events, PairingParameters pp)
 
List[strmark_nullifiers_used (self, List[bytes] nullifiers)
 
Iterator[Tuple[int, str, EtherValue]] note_summaries (self)
 
Iterator[Tuple[int, str, EtherValue]] spent_note_summaries (self)
 
int get_next_block (self)
 
None update_and_save_state (self, int next_block)
 
ZethNoteDescription find_note (self, str note_id)
 

Public Attributes

 mixer_instance
 
 username
 
 wallet_dir
 
 a_sk
 
 k_sk_receiver
 
 state_file
 
 state
 
 merkle_tree
 
 merkle_tree_changed
 
 next_addr
 

Detailed Description

Very simple class to track the list of notes owned by a Zeth user.

Note: this class does not store the notes in encrypted form, and encodes
some information (including value) in the filename. It is a proof of
concept implementation and NOT intended to be secure against intruders who
have access to the file system. However, we expect that a secure
implementation could expose similar interface and functionality.

Definition at line 111 of file wallet.py.

Constructor & Destructor Documentation

◆ __init__()

def zeth.core.wallet.Wallet.__init__ (   self,
Any  mixer_instance,
str  username,
str  wallet_dir,
ZethAddressPriv  secret_address,
ITreeHash  tree_hash 
)

Definition at line 121 of file wallet.py.

121  def __init__(
122  self,
123  mixer_instance: Any,
124  username: str,
125  wallet_dir: str,
126  secret_address: ZethAddressPriv,
127  tree_hash: ITreeHash):
128  # k_sk_receiver: EncryptionSecretKey):
129  assert "_" not in username
130  self.mixer_instance = mixer_instance
131  self.username = username
132  self.wallet_dir = wallet_dir
133  self.a_sk = secret_address.a_sk
134  self.k_sk_receiver = secret_address.k_sk
135  self.state_file = join(wallet_dir, f"state_{username}")
136  self.state = _load_state_or_default(self.state_file)
137  _ensure_dir(join(self.wallet_dir, SPENT_SUBDIRECTORY))
138  self.merkle_tree = PersistentMerkleTree.open(
139  join(wallet_dir, MERKLE_TREE_FILE),
140  int(math.pow(2, ZETH_MERKLE_TREE_DEPTH)),
141  tree_hash)
142  self.merkle_tree_changed = False
143  self.next_addr = self.merkle_tree.get_num_entries()
144 

Member Function Documentation

◆ find_note()

ZethNoteDescription zeth.core.wallet.Wallet.find_note (   self,
str  note_id 
)

Definition at line 234 of file wallet.py.

234  def find_note(self, note_id: str) -> ZethNoteDescription:
235  note_file = self._find_note_file(note_id)
236  if not note_file:
237  raise Exception(f"no note with id {note_id}")
238  with open(note_file, "r") as note_f:
239  return ZethNoteDescription.from_json(note_f.read())
240 
Here is the call graph for this function:

◆ get_next_block()

int zeth.core.wallet.Wallet.get_next_block (   self)

Definition at line 226 of file wallet.py.

226  def get_next_block(self) -> int:
227  return self.state.next_block
228 

◆ mark_nullifiers_used()

List[str] zeth.core.wallet.Wallet.mark_nullifiers_used (   self,
List[bytes]  nullifiers 
)
Process nullifiers, marking any of our notes that they spend.

Definition at line 198 of file wallet.py.

198  def mark_nullifiers_used(self, nullifiers: List[bytes]) -> List[str]:
199  """
200  Process nullifiers, marking any of our notes that they spend.
201  """
202  commits: List[str] = []
203  for nullifier in nullifiers:
204  nullifier_hex = nullifier.hex()
205  short_commit = self.state.nullifier_map.get(nullifier_hex, None)
206  if short_commit:
207  commits.append(short_commit)
208  self._mark_note_spent(nullifier_hex, short_commit)
209 
210  return commits
211 
Here is the call graph for this function:

◆ note_summaries()

Iterator[Tuple[int, str, EtherValue]] zeth.core.wallet.Wallet.note_summaries (   self)
Returns simple information that can be efficiently read from the notes
store.

Definition at line 212 of file wallet.py.

212  def note_summaries(self) -> Iterator[Tuple[int, str, EtherValue]]:
213  """
214  Returns simple information that can be efficiently read from the notes
215  store.
216  """
217  return self._decode_note_files_in_dir(self.wallet_dir)
218 
Here is the call graph for this function:

◆ receive_note()

Optional[ZethNoteDescription] zeth.core.wallet.Wallet.receive_note (   self,
int  comm_addr,
MixOutputEvents  out_ev,
PairingParameters  pp 
)

Definition at line 145 of file wallet.py.

145  def receive_note(
146  self,
147  comm_addr: int,
148  out_ev: MixOutputEvents,
149  pp: PairingParameters) -> Optional[ZethNoteDescription]:
150  # Check this output event to see if it belongs to this wallet.
151  our_note = receive_note(out_ev, self.k_sk_receiver)
152  if our_note is None:
153  return None
154 
155  (commit, note) = our_note
156  if not _check_note(commit, note, pp):
157  return None
158 
159  note_desc = ZethNoteDescription(note, comm_addr, commit)
160  self._write_note(note_desc)
161 
162  # Add the nullifier to the map in the state file
163  nullifier = compute_nullifier(note_desc.note, self.a_sk)
164  self.state.nullifier_map[nullifier.hex()] = \
165  short_commitment(commit)
166  return note_desc
167 
Here is the call graph for this function:
Here is the caller graph for this function:

◆ receive_notes()

List[ZethNoteDescription] zeth.core.wallet.Wallet.receive_notes (   self,
List[MixOutputEvents output_events,
PairingParameters  pp 
)
Decrypt any notes we can, verify them as being valid, and store them in
the database.

Definition at line 168 of file wallet.py.

168  def receive_notes(
169  self,
170  output_events: List[MixOutputEvents],
171  pp: PairingParameters) -> List[ZethNoteDescription]:
172  """
173  Decrypt any notes we can, verify them as being valid, and store them in
174  the database.
175  """
176  new_notes = []
177 
178  self.merkle_tree_changed = len(output_events) != 0
179  for out_ev in output_events:
180  print(
181  f"wallet.receive_notes: idx:{self.next_addr}, " +
182  f"comm:{out_ev.commitment[:8].hex()}")
183 
184  # All commitments must be added to the tree in order.
185  self.merkle_tree.insert(out_ev.commitment)
186  note_desc = self.receive_note(self.next_addr, out_ev, pp)
187  if note_desc is not None:
188  new_notes.append(note_desc)
189 
190  self.next_addr = self.next_addr + 1
191 
192  # Record full set of notes seen to keep an estimate of the total in the
193  # mixer.
194  self.state.num_notes = self.state.num_notes + len(output_events)
195 
196  return new_notes
197 
Here is the call graph for this function:

◆ spent_note_summaries()

Iterator[Tuple[int, str, EtherValue]] zeth.core.wallet.Wallet.spent_note_summaries (   self)
Returns simple info from note filenames in the spent directory.

Definition at line 219 of file wallet.py.

219  def spent_note_summaries(self) -> Iterator[Tuple[int, str, EtherValue]]:
220  """
221  Returns simple info from note filenames in the spent directory.
222  """
223  return self._decode_note_files_in_dir(
224  join(self.wallet_dir, SPENT_SUBDIRECTORY))
225 
Here is the call graph for this function:

◆ update_and_save_state()

None zeth.core.wallet.Wallet.update_and_save_state (   self,
int  next_block 
)

Definition at line 229 of file wallet.py.

229  def update_and_save_state(self, next_block: int) -> None:
230  self.state.next_block = next_block
231  _save_state(self.state_file, self.state)
232  self._save_merkle_tree_if_changed()
233 
Here is the call graph for this function:

Member Data Documentation

◆ a_sk

zeth.core.wallet.Wallet.a_sk

Definition at line 127 of file wallet.py.

◆ k_sk_receiver

zeth.core.wallet.Wallet.k_sk_receiver

Definition at line 128 of file wallet.py.

◆ merkle_tree

zeth.core.wallet.Wallet.merkle_tree

Definition at line 132 of file wallet.py.

◆ merkle_tree_changed

zeth.core.wallet.Wallet.merkle_tree_changed

Definition at line 136 of file wallet.py.

◆ mixer_instance

zeth.core.wallet.Wallet.mixer_instance

Definition at line 124 of file wallet.py.

◆ next_addr

zeth.core.wallet.Wallet.next_addr

Definition at line 137 of file wallet.py.

◆ state

zeth.core.wallet.Wallet.state

Definition at line 130 of file wallet.py.

◆ state_file

zeth.core.wallet.Wallet.state_file

Definition at line 129 of file wallet.py.

◆ username

zeth.core.wallet.Wallet.username

Definition at line 125 of file wallet.py.

◆ wallet_dir

zeth.core.wallet.Wallet.wallet_dir

Definition at line 126 of file wallet.py.


The documentation for this class was generated from the following file:
zeth.core.mixer_client.receive_note
Optional[Tuple[bytes, api.ZethNote]] receive_note(MixOutputEvents out_ev, EncryptionSecretKey receiver_k_sk)
Definition: mixer_client.py:618
zeth.cli.zeth_deploy.int
int
Definition: zeth_deploy.py:27
zeth.core.utils.short_commitment
str short_commitment(bytes cm)
Definition: utils.py:306
zeth.core.mixer_client.compute_nullifier
bytes compute_nullifier(api.ZethNote zeth_note, OwnershipSecretKey spending_authority_ask)
Definition: mixer_client.py:718