@@ -55,9 +55,9 @@ data Command
55
55
| Solve SolveOpts
56
56
57
57
data CompileOpts = CompileOpts
58
- { optimizeOpts :: OptimizeOpts ,
59
- genDotFile :: Bool ,
60
- includeJson :: Bool
58
+ { coOptimizeOpts :: OptimizeOpts ,
59
+ coGenDotFile :: Bool ,
60
+ coIncludeJson :: Bool
61
61
}
62
62
63
63
compileOptsParser :: Parser CompileOpts
@@ -86,7 +86,8 @@ optimizeOptsParser =
86
86
)
87
87
88
88
data SolveOpts = SolveOpts
89
- { inputsFile :: FilePath
89
+ { soInputsFile :: FilePath ,
90
+ soIncludeJson :: Bool
90
91
}
91
92
92
93
solveOptsParser :: Parser SolveOpts
@@ -98,6 +99,10 @@ solveOptsParser =
98
99
<> showDefault
99
100
<> value " inputs.json"
100
101
)
102
+ <*> switch
103
+ ( long " json"
104
+ <> help " also write json versions of artifacts"
105
+ )
101
106
102
107
defaultMain ::
103
108
forall f a .
@@ -111,25 +116,28 @@ defaultMain progName program = do
111
116
case cmd opts of
112
117
Compile compilerOpts -> do
113
118
let BuilderState {.. } = snd $ runCircuitBuilder program
114
- prog = optimize (optimizeOpts compilerOpts) $ mkCircomProgram bsVars bsCircuit
119
+ prog = optimize (coOptimizeOpts compilerOpts) $ mkCircomProgram bsVars bsCircuit
115
120
r1cs = r1csToCircomR1CS $ toR1CS (cpVars prog) (cpCircuit prog)
116
121
createDirectoryIfMissing True outDir
117
122
encodeFile (r1csFilePath outDir) r1cs
118
123
encodeFile (binFilePath outDir) prog
119
124
-- We generarate a template json file for the inputs with default values set to null
120
125
let inputsTemplate = map (const A. Null ) $ labelToVar $ cvInputsLabels $ cpVars prog
121
126
A. encodeFile (inputsTemplateFilePath outDir) inputsTemplate
122
- when (includeJson compilerOpts) $ do
127
+ when (coIncludeJson compilerOpts) $ do
123
128
A. encodeFile (r1csFilePath outDir <> " .json" ) (map fromP r1cs)
124
- when (genDotFile compilerOpts) $ do
129
+ A. encodeFile (binFilePath outDir <> " .json" ) (map fromP prog)
130
+ when (coGenDotFile compilerOpts) $ do
125
131
writeFile (dotFilePath outDir) $ arithCircuitToDot (cpCircuit prog)
126
132
Solve solveOpts -> do
127
133
inputs <- do
128
- mInputs <- decodeFileStrict (inputsFile solveOpts)
134
+ mInputs <- decodeFileStrict (soInputsFile solveOpts)
129
135
maybe (panic " Failed to decode inputs" ) (pure . map (fromInteger @ f )) mInputs
130
136
circuit <- decodeFile (binFilePath outDir)
131
137
let wtns = nativeGenWitness circuit inputs
132
138
encodeFile (witnessFilePath outDir) wtns
139
+ when (soIncludeJson solveOpts) $ do
140
+ A. encodeFile (witnessFilePath outDir <> " .json" ) (map fromP wtns)
133
141
where
134
142
baseFilePath :: FilePath -> FilePath
135
143
baseFilePath dir = dir <> " /" <> Text. unpack progName
0 commit comments