mirror of
https://github.com/logos-storage/logos-storage-proofs-circuits.git
synced 2026-01-02 13:33:07 +00:00
add generating the main component to the Nim proof input generator
This commit is contained in:
parent
f9af4fa84f
commit
30740a86b5
35
reference/nim/proof_input/README.md
Normal file
35
reference/nim/proof_input/README.md
Normal file
@ -0,0 +1,35 @@
|
||||
|
||||
Proof circuit input generator
|
||||
-----------------------------
|
||||
|
||||
This is a Nim program to generate inputs for the proof circuit, and also the
|
||||
main component of the circuit (it needs some global parameters).
|
||||
|
||||
Note: this is only for testing purposes, it's not optimized, and does not
|
||||
use real data.
|
||||
|
||||
### Usage
|
||||
|
||||
$ ./cli [options] --output=proof_input.json --circom=proof_main.circom
|
||||
|
||||
available options:
|
||||
-d, --depth = <maxdepth> : maximum depth of the slot tree (eg. 32)
|
||||
-N, --maxslots = <maxslots> : maximum number of slots (eg. 256)
|
||||
-c, --cellSize = <cellSize> : cell size in bytes (eg. 2048)
|
||||
-b, --blockSize = <blockSize> : block size in bytes (eg. 65536)
|
||||
-s, --nslots = <nslots> : number of slots in the dataset (eg. 13)
|
||||
-n, --nsamples = <nsamples> : number of samples we prove (eg. 100)
|
||||
-e, --entropy = <entropy> : external randomness (eg. 1234567)
|
||||
-S, --seed = <seed> : seed to generate the fake data (eg. 12345)
|
||||
-f, --file = <datafile.bin> : slot data file
|
||||
-i, --index = <slotIndex> : index of the slot (within the dataset) we prove
|
||||
-k, --log2ncells = <log2(ncells)> : log2 of the number of cells inside this slot (eg. 10)
|
||||
-K, --ncells = <ncells> : number of cells inside this slot (eg. 1024; must be a power of two)
|
||||
-o, --output = <inupt.json> : the JSON file into which we write the proof input
|
||||
-C, --circom = <main.circom> : the circom main component to create with these parameters
|
||||
|
||||
You can generate only the `.json` or only the `.circom` file, or both at the same
|
||||
time.
|
||||
|
||||
There are some default values for all the rest of the parameters.
|
||||
|
||||
@ -28,14 +28,15 @@ type FullConfig = object
|
||||
globCfg: GlobalConfig
|
||||
dsetCfg: DataSetConfig
|
||||
slotIndex: int
|
||||
outFile: string
|
||||
entropy: int
|
||||
outFile: string
|
||||
circomFile: string
|
||||
|
||||
const defGlobCfg =
|
||||
GlobalConfig( maxDepth: 32
|
||||
, maxLog2NSlots: 8
|
||||
, cellSize: 2048
|
||||
, blockSize: 4096
|
||||
, blockSize: 65536
|
||||
)
|
||||
|
||||
const defDSetCfg =
|
||||
@ -46,18 +47,19 @@ const defDSetCfg =
|
||||
)
|
||||
|
||||
const defFullCfg =
|
||||
FullConfig( globCfg: defGlobCfg
|
||||
, dsetCfg: defDSetCfg
|
||||
, slotIndex: 0
|
||||
, outFile: "out.json"
|
||||
, entropy: 1234567
|
||||
FullConfig( globCfg: defGlobCfg
|
||||
, dsetCfg: defDSetCfg
|
||||
, slotIndex: 0
|
||||
, outFile: ""
|
||||
, circomFile: ""
|
||||
, entropy: 1234567
|
||||
)
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
proc printHelp() =
|
||||
echo "usage:"
|
||||
echo "$ ./cli [options] <proof_input.json>"
|
||||
echo "$ ./cli [options] --output=proof_input.json --circom=proof_main.circom"
|
||||
echo ""
|
||||
echo "available options:"
|
||||
echo " -d, --depth = <maxdepth> : maximum depth of the slot tree (eg. 32)"
|
||||
@ -68,10 +70,12 @@ proc printHelp() =
|
||||
echo " -n, --nsamples = <nsamples> : number of samples we prove (eg. 100)"
|
||||
echo " -e, --entropy = <entropy> : external randomness (eg. 1234567)"
|
||||
echo " -S, --seed = <seed> : seed to generate the fake data (eg. 12345)"
|
||||
echo " -f, --file = <datafile> : slot data file"
|
||||
echo " -f, --file = <datafile.bin> : slot data file"
|
||||
echo " -i, --index = <slotIndex> : index of the slot (within the dataset) we prove"
|
||||
echo " -k, --log2ncells = <log2(ncells)> : log2 of the number of cells inside this slot (eg. 10)"
|
||||
echo " -K, --ncells = <ncells> : number of cells inside this slot (eg. 1024; must be a power of two)"
|
||||
echo " -o, --output = <inupt.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 ""
|
||||
|
||||
quit()
|
||||
@ -92,7 +96,6 @@ proc parseCliOptions(): FullConfig =
|
||||
# Positional arguments
|
||||
of cmdArgument:
|
||||
# echo ("arg #" & $argCtr & " = " & key)
|
||||
if argCtr == 0: fullCfg.outFile = key
|
||||
argCtr += 1
|
||||
|
||||
# Switches
|
||||
@ -112,6 +115,8 @@ proc parseCliOptions(): FullConfig =
|
||||
of "i", "index" : fullCfg.slotIndex = parseInt(value)
|
||||
of "k", "log2ncells": dsetCfg.ncells = pow2(parseInt(value))
|
||||
of "K", "ncells" : dsetCfg.ncells = checkPowerOfTwo(parseInt(value),"nCells")
|
||||
of "o", "output" : fullCfg.outFile = value
|
||||
of "C", "circom" : fullCfg.circomFile = value
|
||||
else:
|
||||
echo "Unknown option: ", key
|
||||
echo "use --help to get a list of options"
|
||||
@ -120,11 +125,6 @@ proc parseCliOptions(): FullConfig =
|
||||
of cmdEnd:
|
||||
discard
|
||||
|
||||
if argctr != 1:
|
||||
echo "expecting exactly 1 position argument, the name of the output JSON file"
|
||||
echo "use --help for getting a list of options"
|
||||
quit()
|
||||
|
||||
fullCfg.globCfg = globCfg
|
||||
fullCfg.dsetCfg = dsetCfg
|
||||
|
||||
@ -132,10 +132,45 @@ proc parseCliOptions(): FullConfig =
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
proc writeCircomMainComponent(fullCfg: FullConfig, fname: string) =
|
||||
let blockTreeDepth = exactLog2(fullCfg.globCfg.blockSize div fullCfg.globCfg.cellSize)
|
||||
let nFieldElemsPerCell = (fullCfg.globCfg.cellSize + 30) div 31
|
||||
|
||||
let params: (int,int,int,int,int) =
|
||||
( fullCfg.globCfg.maxDepth
|
||||
, fullCfg.globCfg.maxLog2NSlots
|
||||
, blockTreeDepth
|
||||
, nFieldElemsPerCell
|
||||
, fullCfg.dsetCfg.nSamples
|
||||
)
|
||||
|
||||
let f = open(fname, fmWrite)
|
||||
defer: f.close()
|
||||
|
||||
f.writeLine("pragma circom 2.0.0;")
|
||||
f.writeLine("include \"sample_cells.circom\";")
|
||||
f.writeLine("// SampleAndProven( maxDepth, maxLog2NSlots, blockTreeDepth, nFieldElemsPerCell, nSamples )")
|
||||
f.writeLine("component main {public [entropy,dataSetRoot,slotIndex]} = SampleAndProve" & ($params) & ");")
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
when isMainModule:
|
||||
|
||||
let fullCfg = parseCliOptions()
|
||||
# echo fullCfg
|
||||
|
||||
let prfInput = generateProofInput( fullCfg.globCfg, fullCfg.dsetCfg, fullCfg.slotIndex, toF(fullCfg.entropy) )
|
||||
exportProofInput( fullCfg.outFile , prfInput )
|
||||
if fullCfg.circomFile == "" and fullCfg.outFile == "":
|
||||
echo "nothing do!"
|
||||
echo "use --help for getting a list of options"
|
||||
quit()
|
||||
|
||||
if fullCfg.circomFile != "":
|
||||
echo "writing circom main component into `" & fullCfg.circomFile & "`"
|
||||
writeCircomMainComponent(fullCfg, fullCfg.circomFile)
|
||||
|
||||
if fullCfg.outFile != "":
|
||||
echo "writing proof input into `" & fullCfg.outFile & "`..."
|
||||
let prfInput = generateProofInput( fullCfg.globCfg, fullCfg.dsetCfg, fullCfg.slotIndex, toF(fullCfg.entropy) )
|
||||
exportProofInput( fullCfg.outFile , prfInput )
|
||||
|
||||
echo "done"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user