diff --git a/reference/nim/proof_input/proof_input.nimble b/reference/nim/proof_input/proof_input.nimble index cf8ac91..d6a7d6b 100644 --- a/reference/nim/proof_input/proof_input.nimble +++ b/reference/nim/proof_input/proof_input.nimble @@ -10,5 +10,5 @@ bin = @["cli"] requires "nim >= 1.6.0" requires "https://github.com/mratsim/constantine#ab6fa6ae1bbbd1b10071a92ec209b381b5d82511" requires "https://github.com/codex-storage/nim-poseidon2#8a54c69032a741160bbc097d009e45a8b5e4d718" -requires "https://github.com/codex-storage/nim-goldilocks-hash#0d12b1429345c3f359df47171332e8966dc94ed3" -#requires "../../../../nim-goldilocks-hash/" +requires "https://github.com/codex-storage/nim-goldilocks-hash#bd5b805b80b6005a3e5de412dec15783284d205d" +#requires "goldilocks_hash == 0.0.1" diff --git a/reference/nim/proof_input/src/json/bn254.nim b/reference/nim/proof_input/src/json/bn254.nim index 997b7e8..34b7c35 100644 --- a/reference/nim/proof_input/src/json/bn254.nim +++ b/reference/nim/proof_input/src/json/bn254.nim @@ -17,7 +17,7 @@ import shared #------------------------------------------------------------------------------- proc writeFieldElems(h: Stream, prefix: string, xs: seq[F]) = - writeList[F]( h, prefix, xs, writeF ) + writeList[F]( h, prefix, xs, writeLnF ) #------------------------------------------------------------------------------- diff --git a/reference/nim/proof_input/src/json/goldilocks.nim b/reference/nim/proof_input/src/json/goldilocks.nim index b76749f..2784789 100644 --- a/reference/nim/proof_input/src/json/goldilocks.nim +++ b/reference/nim/proof_input/src/json/goldilocks.nim @@ -20,16 +20,23 @@ func bytesToFieldElements( bytes: openArray[byte] ): seq[F] = let digests = padAndDecodeBytesToDigest62(bytes) return digestSeqToFeltSeq(digests) +func bytesToFieldElementsMat( bytes: openArray[byte] ): seq[seq[F]] = + let digests = padAndDecodeBytesToDigest62(bytes) + return digestSeqToFeltSeqSeq(digests) + #------------------------------------------------------------------------------- proc writeFieldElems(h: Stream, prefix: string, xs: seq[F]) = - writeList[F]( h, prefix, xs, writeF ) + writeList[F]( h, prefix, xs, writeLnF ) + +proc writeFieldElemsMat(h: Stream, prefix: string, xs: seq[seq[F]]) = + writeListList[F]( h, prefix, xs, writeF ) #------------------------------------------------------------------------------- proc writeSingleCellData(h: Stream, prefix:string , cell: Cell) = - let flds : seq[F] = bytesToFieldElements(cell) # cell.elements(F).toSeq() - writeFieldElems(h, prefix, flds) + let flds : seq[seq[F]] = bytesToFieldElementsMat(cell) + writeFieldElemsMat(h, prefix, flds) proc writeAllCellData(h: Stream, cells: seq[Cell]) = writeList(h, " ", cells, writeSingleCellData ) @@ -37,8 +44,8 @@ proc writeAllCellData(h: Stream, cells: seq[Cell]) = #------------------------------------------------------------------------------- proc writeSingleMerklePath(h: Stream, prefix: string, path: MerkleProof[Digest]) = - let flds : seq[F] = digestSeqToFeltSeq( path.merklePath ) - writeFieldElems(h, prefix, flds) + let flds : seq[seq[F]] = digestSeqToFeltSeqSeq( path.merklePath ) + writeFieldElemsMat(h, prefix, flds) proc writeAllMerklePaths(h: Stream, paths: seq[MerkleProof[Digest]]) = writeList(h, " ", paths, writeSingleMerklePath ) diff --git a/reference/nim/proof_input/src/json/shared.nim b/reference/nim/proof_input/src/json/shared.nim index 1fb0217..dc72af6 100644 --- a/reference/nim/proof_input/src/json/shared.nim +++ b/reference/nim/proof_input/src/json/shared.nim @@ -24,4 +24,27 @@ proc writeList*[T](h: Stream, prefix: string, xs: seq[T], writeFun: WriteFun[T]) writeFun(h, indent & ", ", xs[i]) h.writeLine( indent & "]" ) +#--------------------------------------- + +proc writeListList*[T](h: Stream, prefix: string, xs: seq[seq[T]], writeFun: WriteFun[T]) = + let n = xs.len + let indent = mkIndent(prefix) + for i in 0..