@@ -26,8 +26,7 @@ import R1CS (R1CS, Witness (Witness), isValidWitness, toR1CS)
26
26
import Prelude (MonadFail (fail ))
27
27
28
28
data GlobalOpts = GlobalOpts
29
- { cmd :: Command ,
30
- encoding :: Encoding
29
+ { cmd :: Command
31
30
}
32
31
33
32
optsParser :: Text -> ParserInfo GlobalOpts
@@ -43,27 +42,6 @@ optsParser progName =
43
42
globalOptsParser =
44
43
GlobalOpts
45
44
<$> hsubparser (compileCommand <> solveCommand <> verifyCommand)
46
- <*> encodingParser
47
-
48
- encodingParser :: Parser Encoding
49
- encodingParser =
50
- let readEncoding = eitherReader $ \ case
51
- " hex" -> pure HexString
52
- " decimal-string" -> pure DecString
53
- " decimal" -> pure Dec
54
- _ -> throwError $ " Invalid encoding, expected one of: hex, decimal-string, decimal"
55
- in option
56
- readEncoding
57
- ( long " encoding"
58
- <> help " encoding for inputs and outputs"
59
- <> showDefaultWith
60
- ( \ case
61
- HexString -> " hex"
62
- DecString -> " decimal-string"
63
- Dec -> " decimal"
64
- )
65
- <> value Dec
66
- )
67
45
68
46
compileCommand :: Mod CommandFields Command
69
47
compileCommand =
@@ -88,7 +66,8 @@ data CompileOpts = CompileOpts
88
66
coGenDotFile :: Bool ,
89
67
coIncludeJson :: Bool ,
90
68
coR1CSFile :: FilePath ,
91
- coCircuitBinFile :: FilePath
69
+ coCircuitBinFile :: FilePath ,
70
+ coEncoding :: Encoding
92
71
}
93
72
94
73
compileOptsParser :: Text -> Parser CompileOpts
@@ -119,6 +98,27 @@ compileOptsParser progName =
119
98
<> showDefault
120
99
<> value (Text. unpack progName <> " .bin" )
121
100
)
101
+ <*> encodingParser
102
+
103
+ encodingParser :: Parser Encoding
104
+ encodingParser =
105
+ let readEncoding = eitherReader $ \ case
106
+ " hex" -> pure HexString
107
+ " decimal-string" -> pure DecString
108
+ " decimal" -> pure Dec
109
+ _ -> throwError $ " Invalid encoding, expected one of: hex, decimal-string, decimal"
110
+ in option
111
+ readEncoding
112
+ ( long " encoding"
113
+ <> help " encoding for inputs and outputs"
114
+ <> showDefaultWith
115
+ ( \ case
116
+ HexString -> " hex"
117
+ DecString -> " decimal-string"
118
+ Dec -> " decimal"
119
+ )
120
+ <> value Dec
121
+ )
122
122
123
123
data OptimizeOpts = OptimizeOpts
124
124
{ removeUnreachable :: Bool
@@ -137,7 +137,8 @@ data SolveOpts = SolveOpts
137
137
soIncludeJson :: Bool ,
138
138
soCircuitBinFile :: FilePath ,
139
139
soWitnessFile :: FilePath ,
140
- soShowOutputs :: Bool
140
+ soShowOutputs :: Bool ,
141
+ soEncoding :: Encoding
141
142
}
142
143
143
144
solveOptsParser :: Text -> Parser SolveOpts
@@ -169,6 +170,7 @@ solveOptsParser progName =
169
170
( long " show-outputs"
170
171
<> help " print the output values as json"
171
172
)
173
+ <*> encodingParser
172
174
173
175
data VerifyOpts = VerifyOpts
174
176
{ voR1CSFile :: FilePath ,
@@ -209,7 +211,7 @@ defaultMain progName program = do
209
211
let binFilePath = coCircuitBinFile compilerOpts
210
212
encodeFile binFilePath prog
211
213
when (coGenInputsTemplate compilerOpts) $ do
212
- let inputsTemplate = mkInputsTemplate (encoding opts ) (cpVars prog)
214
+ let inputsTemplate = mkInputsTemplate (coEncoding compilerOpts ) (cpVars prog)
213
215
inputsTemplateFilePath = Text. unpack progName <> " -inputs-template.json"
214
216
writeIOVars inputsTemplateFilePath inputsTemplate
215
217
when (coIncludeJson compilerOpts) $ do
@@ -220,7 +222,7 @@ defaultMain progName program = do
220
222
writeFile dotFilePath $ arithCircuitToDot (cpCircuit prog)
221
223
Solve solveOpts -> do
222
224
inputs <- do
223
- IOVars _ is <- readIOVars (encoding opts ) (soInputsFile solveOpts)
225
+ IOVars _ is <- readIOVars (soEncoding solveOpts ) (soInputsFile solveOpts)
224
226
pure $ map (map (fromInteger @ f . unFieldElem)) is
225
227
let binFilePath = soCircuitBinFile solveOpts
226
228
circuit <- decodeFile binFilePath
@@ -230,7 +232,7 @@ defaultMain progName program = do
230
232
when (soIncludeJson solveOpts) $ do
231
233
A. encodeFile (wtnsFilePath <> " .json" ) (map fromP wtns)
232
234
when (soShowOutputs solveOpts) $ do
233
- let outputs = mkOutputs (encoding opts ) (cpVars circuit) (witnessFromCircomWitness wtns)
235
+ let outputs = mkOutputs (soEncoding solveOpts ) (cpVars circuit) (witnessFromCircomWitness wtns)
234
236
print $ A. encode $ encodeIOVars outputs
235
237
Verify verifyOpts -> do
236
238
let r1csFilePath = voR1CSFile verifyOpts
0 commit comments