Skip to content

Commit

Permalink
add 'typed' variant of Witness file data
Browse files Browse the repository at this point in the history
  • Loading branch information
Vindaar committed Aug 13, 2024
1 parent e3f0c06 commit f648d56
Showing 1 changed file with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
#
import
../../serialization/[io_limbs, parsing],
constantine/platforms/[fileio, abstractions]
constantine/platforms/[fileio, abstractions],
../../named/algebras, # Fr
./groth16_utils

#[
1. File Header:
Expand Down Expand Up @@ -79,6 +81,11 @@ type
# of each different section in the file and then parse them in increasing
# order of the section types

Wtns*[Name: static Algebra] = object
version*: uint32
header*: WitnessHeader
witnesses*: seq[Fr[Name]]

## XXX: Add `Wtns[T]` type, which takes care of converting field elements and
## does not contain `seq[Section]` anymore

Expand All @@ -88,6 +95,18 @@ func header*(wtns: WtnsBin): WitnessHeader =
func witnesses*(wtns: WtnsBin): seq[Witness] =
result = wtns.sections.filterIt(it.sectionType == kData)[0].wtns

proc getWitnesses[Name: static Algebra](witnesses: seq[Witness]): seq[Fr[Name]] =
result = newSeq[Fr[Name]](witnesses.len)
for i, w in witnesses:
result[i] = toFr[Name](w.data, isMont = false) ## Improtant: Witness does *not* store numbers in Montgomery rep

proc toWtns*[Name: static Algebra](wtns: WtnsBin): Wtns[Name] =
result = Wtns[Name](
version: wtns.version,
header: wtns.header(),
witnesses: wtns.witnesses().getWitnesses[:Name]()
)

proc initSection(kind: WtnsSectionKind, size: uint64): Section =
result = Section(sectionType: kind, size: size)

Expand Down

0 comments on commit f648d56

Please sign in to comment.