package octez-libs

  1. Overview
  2. Docs
A package that contains multiple base libraries used by the Octez suite

Install

Dune Dependency

Authors

Maintainers

Sources

tezos-18.1.tar.gz
sha256=aa2f5bc99cc4ca2217c52a1af2a2cdfd3b383208cb859ca2e79ca0903396ca1d
sha512=d68bb3eb615e3dcccc845fddfc9901c95b3c6dc8e105e39522ce97637b1308a7fa7aa1d271351d5933febd7476b2819e1694f31198f1f0919681f1f9cc97cb3a

doc/src/octez-libs.mec/sinsemilla.ml.html

Source file sinsemilla.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
open Pallas

exception Bottom

(* incomplete addition for Pallas *)
let ( ++ ) p1 p2 =
  if Affine.is_zero p1 then raise Bottom
  else if Affine.is_zero p2 then raise Bottom
  else
    let x1 = Affine.get_x_coordinate p1 in
    let x2 = Affine.get_x_coordinate p2 in
    if Affine.Base.eq x1 x2 then raise Bottom else Affine.add p1 p2

module MakeSinsemilla (Params : sig
  val iv : Affine.t

  val generators : Affine.t array

  val chunk_size : int
end) =
struct
  let hash_exn iterator =
    let rec aux acc =
      if Iterator.Bit.is_processed iterator then acc
      else
        let m_j_bits = Iterator.Bit.get_chunk iterator Params.chunk_size in
        let m_j, _ =
          List.fold_left
            (fun (acc, i) b -> (acc + ((1 lsl i) * b), i + 1))
            (0, 0)
            m_j_bits
        in
        let gen_j = Params.generators.(m_j) in
        aux (acc ++ (acc ++ gen_j))
    in
    let v = aux Params.iv in
    Affine.get_x_coordinate v

  let hash_opt iterator =
    try Some (hash_exn iterator) with Bottom -> None | e -> raise e
end

module Zcash = struct
  let hash_exn iv iterator =
    let module Sinsemilla = MakeSinsemilla (struct
      let iv = iv

      let generators = Sinsemilla_zcash_generators.generators_zcash

      let chunk_size = 10
    end) in
    Sinsemilla.hash_exn iterator

  let hash_opt iv iterator =
    let module Sinsemilla = MakeSinsemilla (struct
      let iv = iv

      let generators = Sinsemilla_zcash_generators.generators_zcash

      let chunk_size = 10
    end) in
    Sinsemilla.hash_opt iterator
end
OCaml

Innovation. Community. Security.