1const DOC_URL: &str = "https://github.com/trailofbits/circomspect/blob/main/doc/analysis_passes.md";
2
3#[derive(Copy, Clone)]
4pub enum ReportCode {
5 AssertWrongType,
6 ParseFail,
7 CompilerVersionError,
8 WrongTypesInAssignOperation,
9 WrongNumberOfArguments(usize, usize),
10 UndefinedFunction,
11 UndefinedTemplate,
12 UninitializedSymbolInExpression,
13 UnableToTypeFunction,
14 UnreachableConstraints,
15 UnknownIndex,
16 UnknownDimension,
17 SameFunctionDeclaredTwice,
18 SameTemplateDeclaredTwice,
19 SameSymbolDeclaredTwice,
20 StaticInfoWasOverwritten,
21 SignalInLineInitialization,
22 SignalOutsideOriginalScope,
23 FunctionWrongNumberOfArguments,
24 FunctionInconsistentTyping,
25 FunctionPathWithoutReturn,
26 FunctionReturnError,
27 ForbiddenDeclarationInFunction,
28 NonHomogeneousArray,
29 NonBooleanCondition,
30 NonCompatibleBranchTypes,
31 NonEqualTypesInExpression,
32 NonExistentSymbol,
33 NoMainFoundInProject,
34 NoCompilerVersionWarning,
35 MultipleMainInComponent,
36 TemplateCallAsArgument,
37 TemplateWrongNumberOfArguments,
38 TemplateWithReturnStatement,
39 TypeCantBeUseAsCondition,
40 EmptyArrayInlineDeclaration,
41 PrefixOperatorWithWrongTypes,
42 InfixOperatorWithWrongTypes,
43 InvalidArgumentInCall,
44 InconsistentReturnTypesInBlock,
45 InconsistentStaticInformation,
46 InvalidArrayAccess,
47 InvalidSignalAccess,
48 InvalidArraySize,
49 InvalidArrayType,
50 ForStatementIllConstructed,
51 BadArrayAccess,
52 AssigningAComponentTwice,
53 AssigningASignalTwice,
54 NotAllowedOperation,
55 ConstraintGeneratorInFunction,
56 WrongSignalTags,
57 InvalidPartialArray,
58 MustBeSingleArithmetic,
59 ExpectedDimDiffGotDim(usize, usize),
60 RuntimeError,
61 UnknownTemplate,
62 NonQuadratic,
63 NonConstantArrayLength,
64 NonComputableExpression,
65 AnonymousComponentError,
66 TupleError,
67 UnconstrainedSignal,
69 OneConstraintIntermediate,
70 NoOutputInInstance,
71 ErrorWat2Wasm,
72 ShadowingVariable,
74 ParameterNameCollision,
75 FieldElementComparison,
76 FieldElementArithmetic,
77 SignalAssignmentStatement,
78 UnnecessarySignalAssignment,
79 UnusedVariableValue,
80 UnusedParameterValue,
81 VariableWithoutSideEffect,
82 ConstantBranchCondition,
83 NonStrictBinaryConversion,
84 CyclomaticComplexity,
85 TooManyArguments,
86 UnconstrainedLessThan,
87 UnconstrainedDivision,
88 Bn254SpecificCircuit,
89 UnderConstrainedSignal,
90 UnusedOutputSignal,
91}
92
93impl ReportCode {
94 pub fn id(&self) -> String {
95 use self::ReportCode::*;
96 match self {
97 ParseFail => "P1000",
98 NoMainFoundInProject => "P1001",
99 MultipleMainInComponent => "P1002",
100 CompilerVersionError => "P1003",
101 NoCompilerVersionWarning => "P1004",
102 WrongTypesInAssignOperation => "T2000",
103 UndefinedFunction => "T2001",
104 UndefinedTemplate => "T2002",
105 UninitializedSymbolInExpression => "T2003",
106 UnableToTypeFunction => "T2004",
107 UnreachableConstraints => "T2005",
108 SameFunctionDeclaredTwice => "T2006",
109 SameTemplateDeclaredTwice => "T2007",
110 SameSymbolDeclaredTwice => "T2008",
111 StaticInfoWasOverwritten => "T2009",
112 SignalInLineInitialization => "T2010",
113 SignalOutsideOriginalScope => "T2011",
114 FunctionWrongNumberOfArguments => "T2012",
115 FunctionInconsistentTyping => "T2013",
116 FunctionPathWithoutReturn => "T2014",
117 FunctionReturnError => "T2015",
118 ForbiddenDeclarationInFunction => "T2016",
119 NonHomogeneousArray => "T2017",
120 NonBooleanCondition => "T2018",
121 NonCompatibleBranchTypes => "T2019",
122 NonEqualTypesInExpression => "T2020",
123 NonExistentSymbol => "T2021",
124 TemplateCallAsArgument => "T2022",
125 TemplateWrongNumberOfArguments => "T2023",
126 TemplateWithReturnStatement => "T2024",
127 TypeCantBeUseAsCondition => "T2025",
128 EmptyArrayInlineDeclaration => "T2026",
129 PrefixOperatorWithWrongTypes => "T2027",
130 InfixOperatorWithWrongTypes => "T2028",
131 InvalidArgumentInCall => "T2029",
132 InconsistentReturnTypesInBlock => "T2030",
133 InconsistentStaticInformation => "T2031",
134 InvalidArrayAccess => "T2032",
135 InvalidSignalAccess => "T2046",
136 InvalidArraySize => "T2033",
137 InvalidArrayType => "T2034",
138 ForStatementIllConstructed => "T2035",
139 BadArrayAccess => "T2035",
140 AssigningAComponentTwice => "T2036",
141 AssigningASignalTwice => "T2037",
142 NotAllowedOperation => "T2038",
143 ConstraintGeneratorInFunction => "T2039",
144 WrongSignalTags => "T2040",
145 AssertWrongType => "T2041",
146 UnknownIndex => "T2042",
147 InvalidPartialArray => "T2043",
148 MustBeSingleArithmetic => "T2044",
149 ExpectedDimDiffGotDim(..) => "T2045",
150 RuntimeError => "T3001",
151 UnknownDimension => "T20460",
152 UnknownTemplate => "T20461",
153 NonQuadratic => "T20462",
154 NonConstantArrayLength => "T20463",
155 NonComputableExpression => "T20464",
156 WrongNumberOfArguments(..) => "T20465",
157 AnonymousComponentError => "TAC01",
158 TupleError => "TAC02",
159 UnconstrainedSignal => "CA01",
161 OneConstraintIntermediate => "CA02",
162 NoOutputInInstance => "CA03",
163 ErrorWat2Wasm => "W01",
164 ShadowingVariable => "CS0001",
166 ParameterNameCollision => "CS0002",
167 FieldElementComparison => "CS0003",
168 FieldElementArithmetic => "CS0004",
169 SignalAssignmentStatement => "CS0005",
170 UnusedVariableValue => "CS0006",
171 UnusedParameterValue => "CS0007",
172 VariableWithoutSideEffect => "CS0008",
173 ConstantBranchCondition => "CS0009",
174 NonStrictBinaryConversion => "CS0010",
175 CyclomaticComplexity => "CS0011",
176 TooManyArguments => "CS0012",
177 UnnecessarySignalAssignment => "CS0013",
178 UnconstrainedLessThan => "CS0014",
179 UnconstrainedDivision => "CS0015",
180 Bn254SpecificCircuit => "CS0016",
181 UnderConstrainedSignal => "CS0017",
182 UnusedOutputSignal => "CS0018",
183 }
184 .to_string()
185 }
186
187 pub fn name(&self) -> String {
188 use self::ReportCode::*;
189 match self {
190 AssertWrongType => "assert-wrong-type",
191 ParseFail => "parse-fail",
192 CompilerVersionError => "compiler-version-error",
193 WrongTypesInAssignOperation => "wrong-types-in-assign-operation",
194 WrongNumberOfArguments(..) => "wrong-number-of-arguments",
195 AnonymousComponentError => "anonymous-component-error",
196 TupleError => "tuple-error",
197 UndefinedFunction => "undefined-function",
198 UndefinedTemplate => "undefined-template",
199 UninitializedSymbolInExpression => "uninitialized-symbol-in-expression",
200 UnableToTypeFunction => "unable-to-type-function",
201 UnreachableConstraints => "unreachable-constraints",
202 UnknownIndex => "unknown-index",
203 UnknownDimension => "unknown-dimension",
204 SameFunctionDeclaredTwice => "same-function-declared-twice",
205 SameTemplateDeclaredTwice => "same-template-declared-twice",
206 SameSymbolDeclaredTwice => "same-symbol-declared-twice",
207 StaticInfoWasOverwritten => "static-info-was-overwritten",
208 SignalInLineInitialization => "signal-in-line-initialization",
209 SignalOutsideOriginalScope => "signal-outside-original-scope",
210 FunctionWrongNumberOfArguments => "function-wrong-number-of-arguments",
211 FunctionInconsistentTyping => "function-inconsistent-typing",
212 FunctionPathWithoutReturn => "function-path-without-return",
213 FunctionReturnError => "function-return-error",
214 ForbiddenDeclarationInFunction => "forbidden-declaration-in-function",
215 NonHomogeneousArray => "non-homogeneous-array",
216 NonBooleanCondition => "non-boolean-condition",
217 NonCompatibleBranchTypes => "non-compatible-branch-types",
218 NonEqualTypesInExpression => "non-equal-types-in-expression",
219 NonExistentSymbol => "non-existent-symbol",
220 NoMainFoundInProject => "no-main-found-in-project",
221 NoCompilerVersionWarning => "no-compiler-version-warning",
222 MultipleMainInComponent => "multiple-main-in-component",
223 TemplateCallAsArgument => "template-call-as-argument",
224 TemplateWrongNumberOfArguments => "template-wrong-number-of-arguments",
225 TemplateWithReturnStatement => "template-with-return-statement",
226 TypeCantBeUseAsCondition => "type-cant-be-use-as-condition",
227 EmptyArrayInlineDeclaration => "empty-array-inline-declaration",
228 PrefixOperatorWithWrongTypes => "prefix-operator-with-wrong-types",
229 InfixOperatorWithWrongTypes => "infix-operator-with-wrong-types",
230 InvalidArgumentInCall => "invalid-argument-in-call",
231 InconsistentReturnTypesInBlock => "inconsistent-return-types-in-block",
232 InconsistentStaticInformation => "inconsistent-static-information",
233 InvalidArrayAccess => "invalid-array-access",
234 InvalidSignalAccess => "invalid-signal-access",
235 InvalidArraySize => "invalid-array-size",
236 InvalidArrayType => "invalid-array-type",
237 ForStatementIllConstructed => "for-statement-ill-constructed",
238 BadArrayAccess => "bad-array-access",
239 AssigningAComponentTwice => "assigning-a-component-twice",
240 AssigningASignalTwice => "assigning-a-signal-twice",
241 NotAllowedOperation => "not-allowed-operation",
242 ConstraintGeneratorInFunction => "constraint-generator-in-function",
243 WrongSignalTags => "wrong-signal-tags",
244 InvalidPartialArray => "invalid-partial-array",
245 MustBeSingleArithmetic => "must-be-single-arithmetic",
246 ExpectedDimDiffGotDim(..) => "expected-dim-diff-got-dim",
247 RuntimeError => "runtime-error",
248 UnknownTemplate => "unknown-template",
249 NonQuadratic => "non-quadratic",
250 NonConstantArrayLength => "non-constant-array-length",
251 NonComputableExpression => "non-computable-expression",
252 UnconstrainedSignal => "unconstrained-signal",
253 OneConstraintIntermediate => "one-constraint-intermediate",
254 NoOutputInInstance => "no-output-in-instance",
255 ErrorWat2Wasm => "error-wat2-wasm",
256 ShadowingVariable => "shadowing-variable",
257 ParameterNameCollision => "parameter-name-collision",
258 FieldElementComparison => "field-element-comparison",
259 FieldElementArithmetic => "field-element-arithmetic",
260 SignalAssignmentStatement => "signal-assignment-statement",
261 UnnecessarySignalAssignment => "unnecessary-signal-assignment",
262 UnusedVariableValue => "unused-variable-value",
263 UnusedParameterValue => "unused-parameter-value",
264 VariableWithoutSideEffect => "variable-without-side-effect",
265 ConstantBranchCondition => "constant-branch-condition",
266 NonStrictBinaryConversion => "non-strict-binary-conversion",
267 CyclomaticComplexity => "cyclomatic-complexity",
268 TooManyArguments => "too-many-arguments",
269 UnconstrainedLessThan => "unconstrained-less-than",
270 UnconstrainedDivision => "unconstrained-division",
271 Bn254SpecificCircuit => "bn254-specific-circuit",
272 UnderConstrainedSignal => "under-constrained-signal",
273 UnusedOutputSignal => "unused-output-signal",
274 }
275 .to_string()
276 }
277
278 pub fn url(&self) -> Option<String> {
279 use ReportCode::*;
280 match self {
281 ShadowingVariable => Some("shadowing-variable"),
282 FieldElementComparison => Some("field-element-comparison"),
283 FieldElementArithmetic => Some("field-element-arithmetic"),
284 SignalAssignmentStatement => Some("signal-assignment"),
285 UnusedVariableValue => Some("unused-variable-or-parameter"),
286 UnusedParameterValue => Some("unused-variable-or-parameter"),
287 VariableWithoutSideEffect => Some("side-effect-free-assignment"),
288 ConstantBranchCondition => Some("constant-branch-condition"),
289 NonStrictBinaryConversion => Some("non-strict-binary-conversion"),
290 CyclomaticComplexity => Some("overly-complex-function-or-template"),
291 TooManyArguments => Some("overly-complex-function-or-template"),
292 UnnecessarySignalAssignment => Some("unnecessary-signal-assignment"),
293 UnconstrainedLessThan => Some("unconstrained-less-than"),
294 UnconstrainedDivision => Some("unconstrained-division"),
295 Bn254SpecificCircuit => Some("bn254-specific-circuit"),
296 UnderConstrainedSignal => Some("under-constrained-signal"),
297 UnusedOutputSignal => Some("unused-output-signal"),
298 _ => None,
300 }
301 .map(|section| format!("{DOC_URL}#{section}"))
302 }
303}