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.plonk/input_commitment.ml.html

Source file input_commitment.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
open Kzg.Bls
open Identities
module SMap = Kzg.SMap

module type S = sig
  module Commitment :
    Kzg.Interfaces.Commitment with type secret = Poly.t Kzg.SMap.t

  type public_parameters = Commitment.public_parameters

  type prover_aux = {poly : Poly.t; pc_prover_aux : Commitment.prover_aux}
  [@@deriving repr]

  type public = Commitment.t [@@deriving repr]

  type t = {public : public; prover_aux : prover_aux} [@@deriving repr]

  (* size is the expected length of the commitment ; it must be at least bigger
     than the length of the secret if it’s given, the secret is padded with zero
     to reach this length *)
  val commit :
    ?size:int -> ?shift:int -> public_parameters -> int -> Scalar.t array -> t
end

module Make_impl (Commitment : Kzg.Interfaces.Commitment) = struct
  module Commitment = Commitment

  type public_parameters = Commitment.public_parameters

  type prover_aux = {poly : Poly.t; pc_prover_aux : Commitment.prover_aux}
  [@@deriving repr]

  type public = Commitment.t [@@deriving repr]

  type t = {public : public; prover_aux : prover_aux} [@@deriving repr]

  let commit ?size ?(shift = 0) pp n secret =
    let domain = Domain.build n in
    let l = Array.length secret in
    let size = Option.value ~default:l size in
    let secret =
      Array.(append secret (init (size - l) (Fun.const Scalar.zero)))
    in
    (* we add some randomness to hide the secret *)
    let secret =
      let random _ = Scalar.random () in
      let head = Array.init shift random in
      let tail = Array.init (n - size - shift) random in
      Array.concat [head; secret; tail]
    in
    let poly = Evaluations.interpolation_fft2 domain secret in
    let poly_map = SMap.singleton "com" poly in
    let public, pc_prover_aux = Commitment.commit pp poly_map in
    {public; prover_aux = {poly; pc_prover_aux}}
end

module Make : functor (Commitment : Kzg.Interfaces.Commitment) ->
  S with module Commitment = Commitment =
  Make_impl
OCaml

Innovation. Community. Security.