Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add header format for snark keys from RFC 0039 #6661

Merged
merged 7 commits into from
Nov 20, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/lib/snark_keys_header/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
(library
(name snark_keys_header)
(public_name snark_keys_header)
(libraries core_kernel runtime_config unsigned_extended)
(instrumentation (backend bisect_ppx))
(preprocess (pps ppx_version ppx_deriving_yojson)))
104 changes: 104 additions & 0 deletions src/lib/snark_keys_header/snark_keys_header.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
open Core_kernel

(** The string that preceeds the JSON header, to identify the file kind before
attempting to parse it.
*)
let header_string = "MINA_SNARK_KEYS\n"

module Kind = struct
(** The 'kind' of data in the file.
For example, a step proving key for the base transaction snark may have the
kind:
{[
{type_= "step_proving_key"; identifier= "transaction_snark_base"}
|}
*)
type t =
{ type_: string [@key "type"]
(** Identifies the type of data that the file contains *)
; identifier: string
(** Identifies the specific purpose of the file's data, in a
human-readable format
*)
}
[@@deriving yojson]
end

module Constraint_constants = struct
module Transaction_capacity = struct
(** Transaction pool capacity *)
type t = Log_2 of int | Txns_per_second_x10 of int

let to_yojson t : Yojson.Safe.t =
match t with
| Log_2 i ->
`Assoc [("two_to_the", `Int i)]
| Txns_per_second_x10 i ->
`Assoc [("txns_per_second_x10", `Int i)]

let of_yojson (json : Yojson.Safe.t) =
match json with
| `Assoc [("two_to_the", `Int i)] ->
Ok (Log_2 i)
| `Assoc [("txns_per_second_x10", `Int i)] ->
Ok (Txns_per_second_x10 i)
| `Assoc _ ->
Error
"Snark_keys_header.Constraint_constants.Transaction_capacity.of_yojson: \
Expected a JSON object containing the field 'two_to_the' or \
'txns_per_second_x10'"
| _ ->
Error
"Snark_keys_header.Constraint_constants.Transaction_capacity.of_yojson: \
Expected a JSON object"
end

module Fork_config = struct
(** Fork data *)
type t = Runtime_config.Fork_config.t =
{previous_state_hash: string; previous_length: int}
[@@deriving yojson]

let opt_to_yojson t : Yojson.Safe.t =
match t with Some t -> to_yojson t | None -> `Assoc []

let opt_of_yojson (json : Yojson.Safe.t) =
match json with
| `Assoc [] ->
Ok None
| _ ->
Result.map (of_yojson json) ~f:(fun t -> Some t)
end

(** The constants used in the constraint system. *)
type t =
{ sub_windows_per_window: int
; ledger_depth: int
; work_delay: int
; block_window_duration_ms: int
; transaction_capacity: Transaction_capacity.t
; coinbase_amount: Unsigned_extended.UInt64.t
; supercharged_coinbase_factor: int
; account_creation_fee: Unsigned_extended.UInt64.t
; fork:
(Fork_config.t option[@to_yojson Fork_config.opt_to_yojson]
[@of_yojson Fork_config.opt_of_yojson]) }
[@@deriving yojson]
end

module Commits = struct
(** Commit identifiers *)
type t = {mina: string; marlin: string} [@@deriving yojson]
end

(** Header contents *)
type t =
{ header_version: int
; kind: Kind.t
; constraint_constants: Constraint_constants.t
; commits: Commits.t
; length: int
; commit_date: string
; constraint_system_hash: string
; identifying_hash: string }
[@@deriving yojson]
24 changes: 24 additions & 0 deletions src/snark_keys_header.opam
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
opam-version: "2"
name: "snark_keys_header"
maintainer: "[email protected]"
authors: ["O(1) Labs, LLC <[email protected]>"]
homepage: "https://github.com/CodaProtocol/coda"
bug-reports: "https://github.com/CodaProtocol/coda/issues"
dev-repo: "https://github.com/CodaProtocol/coda.git"
license: "Apache"
build: [
["dune" "build" "-p" name "-j" jobs]
]
depends: [
"core_kernel"
"dune" {build & >= "2.0"}
"ppx_version"
"ppx_deriving_yojson"
"unsigned_extended"
]
synopsis: "Headers for mina snark keys"
description: "
Headers for mina snark key files and related files, exposing relevant data in a
JSON-formatted object
"