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

octez-19.0.tar.gz
sha256=c6df840ebbf115e454db949028c595bec558a59a66cade73b52a6d099d6fa4d4
sha512=d8aee903b9fe130d73176bc8ec38b78c9ff65317da3cb4f3415f09af0c625b4384e7498201fdb61aa39086a7d5d409d0ab3423f9bc3ab989a680cf444a79bc13

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.