You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
pubfnfrom_byte_be_to_fields<letNBytes: u32, letN: u32>(x: [u8; NBytes]) -> [Field; N] {
letmut result = [0asField; N];
letmut limb: Field = 0;
letmut k = 0;
for_jin0..(15 - (N * 15 - NBytes)) {
limb *= 256;
limb += x[k] asField;
k += 1;
}
result[N - 1] = limb;
foriin1..N {
letmut limb: Field = 0;
for_jin0..15 {
limb *= 256;
limb += x[k] asField;
k += 1;
}
result[N - i - 1] = limb;
}
result
}
The byte representation of an RSA public key and its corresponding Barrett reduction parameter (as required by the BigNum library) are converted to an array of 120-bit fields. Then, it is used to instantiate the parameters for the runtime bignum used for the signature verification.
The conversion from bytes to fields should happen with a reasonable amount of constraints (i.e. <10k)
Bug
When compiling the sig_check_dsc_rsa_pkcs_4096 circuit, using this function twice (to convert the public key and its reduction parameter), the total number of constraints totals over 680k, largely above expectations.
Open /crates/lib/utils/src/lib.nr and look for from_byte_be_to_fields
Comment the std::as_witness calls
run ./scripts/info.sh sig_check_dsc_rsa_pkcs_4096, it will compile the corresponding circuit, compute the number of gates with bb and output it in a json file in the info folder
You should see around 680k gates for the circuit
Open /crates/lib/utils/src/lib.nr again and uncomment the std::as_witness calls
You should see around 260k gates for the circuit
Workaround
Yes
Workaround Description
The workaround is to mark the variable operated on in the loops with std::as_witness reducing the amount of constraints by over 400k
Additional Context
No response
Project Impact
Nice-to-have
Blocker Context
No response
Nargo Version
nargo version = 0.36.0 noirc version = 0.36.0+801c71880ecf8386a26737a5d8bb5b4cb164b2ab
NoirJS Version
No response
Proving Backend Tooling & Version
Barretenberg - bb cli - 0.58.0
Would you like to submit a PR for this Issue?
None
Support Needs
No response
The text was updated successfully, but these errors were encountered:
This is a known issue (#4629) and why we added as_witness. If you can pull out the from_byte_be_to_fields function and get it to compile on its own then that would be helpful to have as a simpler reproduction case.
Aim
Using the following function
The byte representation of an RSA public key and its corresponding Barrett reduction parameter (as required by the BigNum library) are converted to an array of 120-bit fields. Then, it is used to instantiate the parameters for the runtime bignum used for the signature verification.
All of this can be found in ZKpassport repo here.
Expected Behavior
The conversion from bytes to fields should happen with a reasonable amount of constraints (i.e. <10k)
Bug
When compiling the
sig_check_dsc_rsa_pkcs_4096
circuit, using this function twice (to convert the public key and its reduction parameter), the total number of constraints totals over 680k, largely above expectations.To Reproduce
/crates/lib/utils/src/lib.nr
and look forfrom_byte_be_to_fields
std::as_witness
calls./scripts/info.sh sig_check_dsc_rsa_pkcs_4096
, it will compile the corresponding circuit, compute the number of gates with bb and output it in a json file in theinfo
folder/crates/lib/utils/src/lib.nr
again and uncomment thestd::as_witness
callsWorkaround
Yes
Workaround Description
The workaround is to mark the variable operated on in the loops with
std::as_witness
reducing the amount of constraints by over 400kAdditional Context
No response
Project Impact
Nice-to-have
Blocker Context
No response
Nargo Version
nargo version = 0.36.0 noirc version = 0.36.0+801c71880ecf8386a26737a5d8bb5b4cb164b2ab
NoirJS Version
No response
Proving Backend Tooling & Version
Barretenberg - bb cli - 0.58.0
Would you like to submit a PR for this Issue?
None
Support Needs
No response
The text was updated successfully, but these errors were encountered: