package tezos-plonk
Plonk zero-knowledge proving system
Install
Dune Dependency
Authors
Maintainers
Sources
privacy-team-v1.0.0.tar.gz
md5=c9007a234fbacaddbc652c139cac56db
sha512=b67825a9259c27ccba51a4cb98056985c93f74f5211d422ce8ee8c35cda748c22bd1e59b3a584a79f96c1be21a409a12ee4b705346e1319c6d8bf45e81029f93
doc/src/tezos-plonk/fr_generation.ml.html
Source file fr_generation.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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
(*****************************************************************************) (* *) (* MIT License *) (* Copyright (c) 2022 Nomadic Labs <contact@nomadic-labs.com> *) (* *) (* Permission is hereby granted, free of charge, to any person obtaining a *) (* copy of this software and associated documentation files (the "Software"),*) (* to deal in the Software without restriction, including without limitation *) (* the rights to use, copy, modify, merge, publish, distribute, sublicense, *) (* and/or sell copies of the Software, and to permit persons to whom the *) (* Software is furnished to do so, subject to the following conditions: *) (* *) (* The above copyright notice and this permission notice shall be included *) (* in all copies or substantial portions of the Software. *) (* *) (* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*) (* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *) (* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *) (* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*) (* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *) (* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *) (* DEALINGS IN THE SOFTWARE. *) (* *) (*****************************************************************************) module type S = sig type scalar val powers : int -> scalar -> scalar array val batch : scalar -> scalar list -> scalar val build_quadratic_non_residues : int -> scalar array val random_fr_list : Bytes.t -> int -> scalar list * Bytes.t val random_fr : Bytes.t -> scalar * Bytes.t end module Make (Scalar : Bls.Scalar_sig) : S with type scalar = Scalar.t = struct (* convert int to Fr scalar (algo based on fast exponentiation model) *) type scalar = Scalar.t let succ = Scalar.(add one) (* computes [| 1; x; x²; x³; ...; xᵈ⁻¹ |] *) let powers d x = Utils.build_array Scalar.one Scalar.(mul x) d (* [batch x l] adds the elements of l scaled by ascending powers of x *) let batch x l = List.fold_left (fun acc y -> Scalar.((x * acc) + y)) Scalar.zero (List.rev l) (* quadratic non-residues for Sid *) let build_quadratic_non_residues len = let is_nonresidue n = Z.(equal (Scalar.legendre_symbol n) Z.(-one)) in let rec next n = succ n |> fun n -> if is_nonresidue n then n else next n in Utils.build_array Scalar.one next len let z_to_bytes n = Z.to_bits n |> Bytes.of_string (* * a is the element to hash * to_bytes_func, add, one is the function of conversion to_bytes, the function of addition, the one compatible with a type * returns x ∈ F built from the hash of a * if hash a not in F, returns hash (a+1) until its value belongs to F *) let rec hash_to_Fr a = let b = z_to_bytes a in let hashed_b = Utils.Hash.hash_bytes [ b ] in assert (Bytes.length hashed_b = 32); let x_fr = Scalar.of_bytes_opt hashed_b in match x_fr with | Some a -> a (* x_fr can be converted *) | None -> hash_to_Fr (Z.succ a) let generate_random_fr ?state () = (match state with None -> () | Some s -> Random.set_state s); let n0 = Z.of_int64 @@ Random.int64 Int64.max_int in let n1 = Z.of_int64 @@ Random.int64 Int64.max_int in let n2 = Z.of_int64 @@ Random.int64 Int64.max_int in let n3 = Z.of_int64 @@ Random.int64 Int64.max_int in let n1_64 = Z.(n1 lsl 64) in let n2_128 = Z.(n2 lsl 128) in let n3_192 = Z.(n3 lsl 192) in let gamma_z = Z.(n0 + n1_64 + n2_128 + n3_192) in let gamma_fr = hash_to_Fr gamma_z in gamma_fr (* generate nb_values scalar of Fr based on seed transcript *) let random_fr_list transcript nb_values = let transcript_array, hashed_transcript = Utils.Hash.bytes_to_seed transcript in Random.full_init transcript_array; (List.init nb_values (fun _ -> generate_random_fr ()), hashed_transcript) let random_fr transcript = let l, hashed_transcript = random_fr_list transcript 1 in (List.hd l, hashed_transcript) end
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>