mirror of
https://github.com/logos-storage/logos-storage-proofs-circuits.git
synced 2026-01-08 00:13:10 +00:00
add CLI and config for the new hash functions
This commit is contained in:
parent
95ccb2b7d8
commit
948f6c2c75
@ -29,6 +29,8 @@ use real data.
|
||||
-K, --ncells = <ncells> : number of cells inside this slot (eg. 1024; must be a power of two)
|
||||
-o, --output = <input.json> : the JSON file into which we write the proof input
|
||||
-C, --circom = <main.circom> : the circom main component to create with these parameters
|
||||
-F, --field = <field> : the underlying field: "bn254" or "goldilocks"
|
||||
-H, --hash = <hash> : the hash function to use: "poseidon2" or "monolith"
|
||||
|
||||
You can generate only the `.json` or only the `.circom` file, or both at the same
|
||||
time.
|
||||
|
||||
@ -9,3 +9,4 @@ bin = @["cli","testmain"]
|
||||
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"
|
||||
|
||||
@ -26,6 +26,7 @@ import misc
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
type FullConfig = object
|
||||
hashCfg: HashConfig
|
||||
globCfg: GlobalConfig
|
||||
dsetCfg: DataSetConfig
|
||||
slotIndex: int
|
||||
@ -34,6 +35,11 @@ type FullConfig = object
|
||||
circomFile: string
|
||||
verbose: bool
|
||||
|
||||
const defHashCfg =
|
||||
HashConfig( field: Goldilocks # BN254
|
||||
, hashFun: Poseidon2
|
||||
)
|
||||
|
||||
const defGlobCfg =
|
||||
GlobalConfig( maxDepth: 32
|
||||
, maxLog2NSlots: 8
|
||||
@ -49,7 +55,8 @@ const defDSetCfg =
|
||||
)
|
||||
|
||||
const defFullCfg =
|
||||
FullConfig( globCfg: defGlobCfg
|
||||
FullConfig( hashCfg: defHashCfg
|
||||
, globCfg: defGlobCfg
|
||||
, dsetCfg: defDSetCfg
|
||||
, slotIndex: 0
|
||||
, outFile: ""
|
||||
@ -81,6 +88,8 @@ proc printHelp() =
|
||||
echo " -K, --ncells = <ncells> : number of cells inside this slot (eg. 1024; must be a power of two)"
|
||||
echo " -o, --output = <input.json> : the JSON file into which we write the proof input"
|
||||
echo " -C, --circom = <main.circom> : the circom main component to create with these parameters"
|
||||
echo " -F, --field = <field> : the underlying field: \"bn254\" or \"goldilocks\""
|
||||
echo " -H, --hash = <hash> : the hash function to use: \"poseidon2\" or \"monolith\""
|
||||
echo ""
|
||||
|
||||
quit()
|
||||
@ -91,6 +100,7 @@ proc parseCliOptions(): FullConfig =
|
||||
|
||||
var argCtr: int = 0
|
||||
|
||||
var hashCfg = defHashCfg
|
||||
var globCfg = defGlobCfg
|
||||
var dsetCfg = defDSetCfg
|
||||
var fullCfg = defFullCfg
|
||||
@ -123,6 +133,8 @@ proc parseCliOptions(): FullConfig =
|
||||
of "K", "ncells" : dsetCfg.ncells = checkPowerOfTwo(parseInt(value),"nCells")
|
||||
of "o", "output" : fullCfg.outFile = value
|
||||
of "C", "circom" : fullCfg.circomFile = value
|
||||
of "F", "field" : hashCfg.field = parseField(value)
|
||||
of "H", "hash" : hashCfg.hashFun = parseHashFun(value)
|
||||
else:
|
||||
echo "Unknown option: ", key
|
||||
echo "use --help to get a list of options"
|
||||
@ -131,6 +143,7 @@ proc parseCliOptions(): FullConfig =
|
||||
of cmdEnd:
|
||||
discard
|
||||
|
||||
fullCfg.hashCfg = hashCfg
|
||||
fullCfg.globCfg = globCfg
|
||||
fullCfg.dsetCfg = dsetCfg
|
||||
|
||||
@ -140,9 +153,12 @@ proc parseCliOptions(): FullConfig =
|
||||
|
||||
proc printConfig(fullCfg: FullConfig) =
|
||||
|
||||
let hashCfg = fullCfg.hashCfg
|
||||
let globCfg = fullCfg.globCfg
|
||||
let dsetCfg = fullCfg.dsetCfg
|
||||
|
||||
echo "field = " & ($hashCfg.field)
|
||||
echo "hash func. = " & ($hashCfg.hashFun)
|
||||
echo "maxDepth = " & ($globCfg.maxDepth)
|
||||
echo "maxSlots = " & ($pow2(globCfg.maxLog2NSlots))
|
||||
echo "cellSize = " & ($globCfg.cellSize)
|
||||
@ -186,7 +202,7 @@ when isMainModule:
|
||||
printConfig(fullCfg)
|
||||
|
||||
if fullCfg.circomFile == "" and fullCfg.outFile == "":
|
||||
echo "nothing do!"
|
||||
echo "nothing to do!"
|
||||
echo "use --help for getting a list of options"
|
||||
quit()
|
||||
|
||||
|
||||
@ -1,21 +1,21 @@
|
||||
|
||||
import sugar
|
||||
import std/sequtils
|
||||
#import std/sequtils
|
||||
|
||||
import constantine/math/arithmetic
|
||||
#import constantine/math/arithmetic
|
||||
|
||||
import poseidon2/types
|
||||
import poseidon2/merkle
|
||||
import poseidon2/io
|
||||
|
||||
import types
|
||||
import blocks
|
||||
import slot
|
||||
import dataset
|
||||
import sample
|
||||
import merkle
|
||||
import gen_input
|
||||
import json
|
||||
#import blocks
|
||||
#import slot
|
||||
#import dataset
|
||||
#import sample
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
|
||||
@ -106,6 +106,18 @@ type
|
||||
cellSize* : int # size of the cells we prove (2048)
|
||||
blockSize* : int # size of the network block (65536)
|
||||
|
||||
HashConfig* = object
|
||||
field* : FieldSelect
|
||||
hashFun* : HashSelect
|
||||
|
||||
FieldSelect* = enum
|
||||
BN254,
|
||||
Goldilocks
|
||||
|
||||
HashSelect* = enum
|
||||
Poseidon2,
|
||||
Monolith
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
func cellsPerBlock*(glob: GlobalConfig): int =
|
||||
@ -114,3 +126,19 @@ func cellsPerBlock*(glob: GlobalConfig): int =
|
||||
return k
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
func parseField*(str0: string): FieldSelect =
|
||||
let str = strutils.toLowerAscii(str0)
|
||||
case str:
|
||||
of "bn254": return BN254
|
||||
of "goldilocks": return Goldilocks
|
||||
else: raiseAssert("parsefield: unrecognized field `" & str0 & "`")
|
||||
|
||||
func parseHashFun*(str0: string): HashSelect =
|
||||
let str = strutils.toLowerAscii(str0)
|
||||
case str:
|
||||
of "poseidon2": return Poseidon2
|
||||
of "monolith": return Monolith
|
||||
else: raiseAssert("parsefield: unrecognized hash function `" & str0 & "`")
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user