fix / improve some minor stuff

This commit is contained in:
Balazs Komuves 2026-01-15 17:54:15 +01:00
parent 91d11cda21
commit 3a2ae354db
No known key found for this signature in database
GPG Key ID: F63B7AEF18435562
8 changed files with 44 additions and 33 deletions

View File

@ -2,3 +2,4 @@
cli
*.circom
*.json
tmp/

View File

@ -7,6 +7,7 @@ Quickstart:
$ nimble build cli
$ ./cli --help
Example:
Examples:
$ ./cli -v --merkle_depth=18 --limit_bits=12 --circom=main.circom --output=input.json
$ ./cli -v --merkle_depth=18 --limit_bits=12 --circom=main.circom --output=input.json --partial=partial.json
$ ./cli -v -d=16 -b=10 --output=tmp/input.json --partial=tmp/partial.json

View File

@ -20,19 +20,19 @@ type FullConfig = object
globCfg: GlobalConfig
seed: int64
outFile: string
partialFile: string
circomFile: string
partial: bool
verbose: bool
how_many: int
const defaultFullCfg =
FullConfig( globCfg: defaultGlobalConfig
, seed: 0
, outFile: ""
, circomFile: ""
, partial: false
, verbose: false
, how_many: 1
FullConfig( globCfg: defaultGlobalConfig
, seed: 0
, outFile: ""
, partialFile: ""
, circomFile: ""
, verbose: false
, how_many: 1
)
#-------------------------------------------------------------------------------
@ -42,15 +42,15 @@ proc printHelp() =
echo "$ ./cli [options] --output=proof_input.json --circom=proof_main.circom"
echo ""
echo "available options:"
echo " -h, --help : print this help"
echo " -v, --verbose : verbose output (print the actual parameters)"
echo " -d, --merkle_depth = <depth> : Merkle tree depth (default: 20)"
echo " -b, --limit_bits = <bits> : log2 of maximum number of messages per epoch (default: 16)"
echo " -s, --seed = <seed> : seed to generate the fake data (eg. 12345; default: random)"
echo " -o, --output = <input.json> : the JSON file into which we write the proof inputs"
echo " -c, --circom = <main.circom> : the circom main component to create with these parameters"
echo " -n, --count = <K> : generate K proof inputs at the same time (instead of 1)"
echo " -p, --partial : generate partial input"
echo " -h, --help : print this help"
echo " -v, --verbose : verbose output (print the actual parameters)"
echo " -d, --merkle_depth = <depth> : Merkle tree depth (default: 20)"
echo " -b, --limit_bits = <bits> : log2 of maximum number of messages per epoch (default: 16)"
echo " -s, --seed = <seed> : seed to generate the fake data (eg. 12345; default: random)"
echo " -o, --output = <input.json> : the JSON file into which we write the full proof inputs"
echo " -p, --partial = <partial.json> : the JSON file into which we write the partial inputs"
echo " -c, --circom = <main.circom> : the circom main component to create with these parameters"
echo " -n, --count = <K> : generate K proof inputs at the same time (instead of 1)"
echo ""
quit()
@ -84,8 +84,8 @@ proc parseCliOptions(): FullConfig =
of "b", "limit_bits" : globCfg.limit_bits = parseInt(value)
of "s", "seed" : fullCfg.seed = int64(parseInt(value))
of "o", "output" : fullCfg.outFile = value
of "p", "partial" : fullCfg.partialFile = value
of "c", "circom" : fullCfg.circomFile = value
of "p", "partial" : fullCfg.partial = true
of "n", "count" : fullCfg.how_many = parseInt(value)
else:
echo "Unknown option: ", key
@ -114,7 +114,6 @@ proc printConfig(fullCfg: FullConfig) =
echo "merkle_depth = " & ($globCfg.merkle_depth)
echo "limit_bits = " & ($globCfg.limit_bits)
echo "random seed = " & ($fullCfg.seed)
echo "partial = " & ($fullCfg.partial)
echo "how many inputs = " & ($fullCfg.how_many)
#-------------------------------------------------------------------------------
@ -159,16 +158,23 @@ when isMainModule:
echo "writing circom main component into `" & fname & "`"
writeCircomMainComponent(fullCfg, fname)
if fullCfg.outFile != "":
let fname = fullCfg.outFile
if (fullCfg.outFile != "") or (fullCfg.partialFile != ""):
if (globCfg.merkle_depth > 16):
echo "note: for depth > 16 this may take a while... (we are generating a full Poseidon2 Merkle tree)"
let secretTree = genTreeWithSecrets( globCfg )
let prfInput = genProofInput( globCfg , secretTree )
if fullCfg.partial:
if fullCfg.outFile != "":
let fname = fullCfg.outFile
echo "writing full proof input into `" & fname & "`..."
exportProofInput( fname, prfInput )
if fullCfg.partialFile != "":
let fname = fullCfg.partialFile
echo "writing partial proof input into `" & fname & "`..."
let partial = extractPartialInputs( prfInput )
exportPartialInput( fname, partial )
else:
echo "writing full proof input into `" & fname & "`..."
exportProofInput( fname, prfInput )
echo "done"

View File

@ -35,7 +35,7 @@ proc genTreeWithSecrets*(globCfg: GlobalConfig): TreeWithSecrets =
for i in 0..<N:
let secret_key = randomF()
let msg_limit = min( 1 , rand(M) )
let msg_limit = max( 1 , rand(M) )
let public_key = compress( secret_key, intToBN254(msg_limit) );
assert( msg_limit <= M , "msg limit hard bound failed")

View File

@ -96,7 +96,7 @@ depends on (these are: maxdepth, maxslots, cellsize, blocksize, nsamples).
### Generate an input to the circuit
$ source ../cli_args.sh && ../../reference/nim/proof_input/cli $CLI_ARGS -v --output=input.json
$ source ../cli_args.sh && ../../test-input/cli $CLI_ARGS -v --output=input.json --partial=partial.json
### Generate the witness

View File

@ -4,11 +4,13 @@ MY_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
source ${MY_DIR}/params.sh
CLI_ARGS="--merkle_depth=${MERKLE_DEPTH} \
CLI_ARGS="--verbose \
--merkle_depth=${MERKLE_DEPTH} \
--limit_bits=${LIMIT_BITS}"
if [[ "$1" == "--export" ]]
then
echo "exporting CLI_ARGS"
echo $CLI_ARGS
export CLI_ARGS
fi

View File

@ -1,6 +1,6 @@
#!/bin/bash
MERKLE_DEPTH=10 # depth of the Merkle tree
LIMIT_BITS=6 # log2 of the maximal possible rate limit per epoch
MERKLE_DEPTH=20 # depth of the Merkle tree
LIMIT_BITS=16 # log2 of the maximal possible rate limit per epoch
# SEED=1234567 # seed for creating fake data

View File

@ -22,8 +22,9 @@ fi
echo ""
echo "generating the input for the proof circuit..."
echo "cli default arguments: $CLI_ARGS"
${NIMCLI_DIR}/cli $CLI_ARGS --output=input.json
${NIMCLI_DIR}/cli $CLI_ARGS --output=input.json --partial=partial.json
# --- generate the witness ---