Skip to content

Serialization for uncompressed srs

Guillaume B requested to merge nomadic-labs/tezos:baugr@srs-serialization into master

What

This MR adds a new serialization and deserialization functions for SRS.

Why

Loading uncompressed SRS is faster than calculating exponents at runtime, so the impact will be to speedup SRS loading time when it will be used.

How

Adds 2 functions in lib_crypto_dal/srs.ml:

  • read_uncompressed_srs, similar in usage to the existing read_srs, but reading a serialized uncompressed SRS
  • _write_uncompressed_srs
  • _generate_srsu_uncompressed_serialized_from_zcash_file

These functions define a format in order to recognize the uncompressed SRS: They begin with the magic string TZ_SRS_U01, the 'U' means uncompressed and the 01 (in ascii) serving as a rude versioning number:

❯ head -c 100 srsu_g1 | hd
00000000  54 5a 5f 53 52 53 5f 55  30 31 16 0c 53 fd 90 87  |TZ_SRS_U01..S...|
00000010  b3 5c f5 ff 76 99 67 fc  17 78 c1 a1 3b 14 c7 95  |.\..v.g..x..;...|
  • The read_uncompressed_srs is the one we expect to use in order to replace current SRS initialization. It loads a uncompressed SRS file given the paths in argument.
  • The write_uncompressed_srs is the corresponding writing function, that, given the SRS_g1 and SRS_g2 in argument, will dump with the serialization format described above, into two files, whose names are also given in argument.
  • Also, for internal use, the _generate_srsu_uncompressed_serialized_from_zcash_file allows, given the old format of SRS files, to write (using the write_uncompressed_srs the uncompressed and serialized SRS into specified files. Additionnaly, this function reads back the written compare and compares the result with the given input, in order to verify the serialization correct for the given files.
Edited by Guillaume B

Merge request reports