File tree Expand file tree Collapse file tree 2 files changed +15
-4
lines changed Expand file tree Collapse file tree 2 files changed +15
-4
lines changed Original file line number Diff line number Diff line change 11// RUN: zkir-opt -prime-field-to-mod-arith --split-input-file %s | FileCheck %s --enable-var-scope
22!PF1 = !field.pf <3 :i32 >
33!PFv = tensor <4 x!PF1 >
4- #elem = #field.pf_elem <31 :i32 > : !PF1
54#root_elem = #field.pf_elem <2 :i32 > : !PF1
65#root = #field.root_of_unity <#root_elem , 2 >
76
Original file line number Diff line number Diff line change @@ -8,13 +8,25 @@ namespace mlir::zkir::field {
88
99LogicalResult PrimeFieldAttr::verify (
1010 ::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError,
11- PrimeFieldType type, IntegerAttr value) {
12- if (type.getModulus ().getValue ().getBitWidth () !=
13- value.getValue ().getBitWidth ()) {
11+ PrimeFieldType type, IntegerAttr _value) {
12+ APInt modulus = type.getModulus ().getValue ();
13+ APInt value = _value.getValue ();
14+
15+ // check if storage type is same
16+ if (modulus.getBitWidth () != value.getBitWidth ()) {
1417 emitError ()
1518 << " prime field modulus bitwidth does not match the value bitwidth" ;
1619 return failure ();
1720 }
21+
22+ // check if value is in the field defined by modulus
23+ if (value.uge (modulus)) {
24+ emitError () << value.getZExtValue ()
25+ << " is not in the field defined by modulus "
26+ << modulus.getZExtValue ();
27+ return failure ();
28+ }
29+
1830 return success ();
1931}
2032
You can’t perform that action at this time.
0 commit comments