Zeth - Zerocash on Ethereum  0.8
Reference implementation of the Zeth protocol by Clearmatics
input_hasher.py
Go to the documentation of this file.
1 # Copyright (c) 2015-2022 Clearmatics Technologies Ltd
2 #
3 # SPDX-License-Identifier: LGPL-3.0+
4 
5 from zeth.core.mimc import MiMCBase
6 from typing import List
7 
8 
9 # Default seed, generated as:
10 # zeth.core.mimc._keccak_256(
11 # zeth.core.mimc._str_to_bytes("clearmatics_hash_seed"))
12 DEFAULT_IV_UINT256 = \
13  13196537064117388418196223856311987714388543839552400408340921397545324034315
14 
15 
17  """
18  Note that this is currently experimental code. Hash a series of field
19  elements via the Merkle-Damgard construction on a MiMC compression
20  function. Note that since this function only accepts whole numbers of
21  scalar field elements, there is no ambiguity w.r.t to padding and we could
22  technically omit the finalization step. It has been kept for now, to allow
23  time for further consideration, and in case the form of the hasher changes
24  (e.g. in case we want to be able to hash arbitrary bit strings in the
25  future).
26  """
27  def __init__(self, compression_fn: MiMCBase, iv: int = DEFAULT_IV_UINT256):
28  assert compression_fn.prime < (2 << 256)
29  self._compression_fn = compression_fn
30  self._iv = iv % compression_fn.prime
31 
32  def hash(self, values: List[int]) -> int:
33  current = self._iv
34  for m in values:
35  current = self._compression_fn.hash_int(current, m)
36  return self._compression_fn.hash_int(current, len(values))
zeth.core.input_hasher.InputHasher.hash
int hash(self, List[int] values)
Definition: input_hasher.py:32
zeth.core.input_hasher.InputHasher._iv
_iv
Definition: input_hasher.py:30
zeth.core.input_hasher.InputHasher._compression_fn
_compression_fn
Definition: input_hasher.py:29
zeth.core.input_hasher.InputHasher.__init__
def __init__(self, MiMCBase compression_fn, int iv=DEFAULT_IV_UINT256)
Definition: input_hasher.py:27
zeth.core.mimc
Definition: mimc.py:1
zeth.core.input_hasher.InputHasher
Definition: input_hasher.py:16