Module SMap.Aggregation

This module is used to handle proof aggregation in Plonk The format of keys for aggregation is <circuit~proof~key>

val sep : string

The separator that distinguish the different parts of the key, currently '~'

val update_key_name : (string -> string) -> string -> string

applies the input function on the last part of the input string (parts are delimited by sep). update_key_name f ("hello" ^ sep ^ "world" ^ sep ^ "!!") returns "hello" ^ sep ^ "world" ^ sep ^ (f "!!")

val add_prefix : ?no_sep:bool -> ?n:int -> ?i:int -> ?shift:int -> string -> string -> string

add_prefix ~n ~i ~shift prefix str return idx^prefix^sep^str idx = i + shift as a string, eventually padded with '0' before to allow a numbering until n with the same number of caracters for instance, prefix ~n:11 ~i:5 ~shift:1 "hello" "world" will return "06~hello~world" n is zero by default, this means if no n is specified, no idx will be added no_sep is false by default ; if set to true, the separator before the string to prefix will be ommitted : prefix ~no_sep:true ~n:11 ~i:5 ~shift:1 "hello" "world" will return "06~helloworld"

val build_all_names : string -> int -> string -> string list

build_all_names prefix n k build the list of all prefixed k with n proofs : build_all_names "hello" 11 "world" will return "hello~00~world" ; "hello~01~world" ; … ; "hello~10~world"

val prefix_map : ?n:int -> ?i:int -> ?shift:int -> string -> 'a t -> 'a t

adds prefix to each key of str_map ; i will be added as a string before the prefix For instance prefix_map ~n:3000 ~i:5 ~shift:1 "hello" map will prefix all the keys of map with "0006~hello~"

val of_list : ?n:int -> ?shift:int -> string -> string -> 'a list -> 'a t

Aggregation.of_list ~n ~shift s name l is the same as of_list @@ List.mapi (fun i x -> Aggregation.add_prefix ~n ~i ~shift s name, x) l

val smap_of_smap_smap : 'a t t -> 'a t

"c1" -> {"a" ; "b"} ; "c2" -> {"a" ; "c"} becomes {"c1~a" ; "c1~b" ; "c2~a" ; "c2~c"} with the same values

val gather_maps : ?shifts_map:(int * int) t -> 'a t list t -> 'a t

Converts a map of list of map in a map, by merging each list of map in one map, prefixing all keys with their proof index, and then merging all the new maps into one prefixing the keys with the outside map’s keys. shifts_maps map outside key to pairs of integers. 'key1' -> (7, 20) means that 20 proofs will be produced for key1 in total and we should start from the 8th one, assuming 7 of them were done independently. (Note that we may not even finish the whole 20, this depends on the map_list length). For example, on input:

'circuit_foo' -> [ {'a' -> fa0; 'b' -> fb0; 'c' -> fc0};
                  {'a' -> fa1; 'b' -> fb1; 'c' -> fc1} ];
'circuit_bar' -> [ {'a' -> ga0; 'b' -> gb0; 'c' -> gc0} ]; 

outputs

'circuit_foo~0~a' -> fa0
'circuit_foo~0~b' -> fb0
'circuit_foo~0~c' -> fc0
'circuit_foo~1~a' -> fa1
'circuit_foo~1~b' -> fb1
'circuit_foo~1~c' -> fc1
'circuit_bar~0~a' -> ga0
'circuit_bar~0~b' -> gb0
'circuit_bar~0~c' -> gc0
val filter_by_circuit_name : string -> 'a t -> 'a t

Filter a map keeping the elements whose key corresponds to the given circuit name

val select_answers_by_circuit : string -> 'a t t -> 'a t t

select_answers_by_circuit circuit_name s_map_map takes a circuit_name and a map with the structure:

'x' -> { 'circuit_foo~0~a' -> [scalar] ;
         'circuit_foo~0~b' -> [scalar] ;
         ...
      }

and filters the keys of the inner map, keeping the elements whose key corresponds to the given circuit name.

val add_map_list_map : 'a t list t -> 'a t list t -> 'a t list t

add_map_list_map m1 m2 will merge m1 & m2 ; the resulting map will contain the same keys as m1 ; m1 & m2 can be disjoint, if a key is not found in m2, the resulting map contains the same binding as m1 for this key