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]
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
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