test fix for exponents#405
Conversation
There was a problem hiding this comment.
Pull request overview
Updates the RSA exponent-related unit tests for the verify_rsa_pubkey_in_tbs helper in the Noir passport utilities, switching from minimal byte arrays to a more realistic DER-shaped TBS builder (build_test_tbs).
Changes:
- Replaces old small-buffer exponent tests with new tests built on
build_test_tbsand a 256-byte modulus. - Adjusts test inputs to match the function’s DER-structure expectations (modulus INTEGER + exponent INTEGER).
- Reorders the exponent tests to live after the
build_test_tbshelper.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
/claude-review |
Code ReviewSummaryThis PR ("test fix for exponents") targets the ReviewCorrectness & Soundness There is one consistent bug across all five new tests (and, for context, the pre-existing tests share the same pattern):
Every new test passes The function asserts This means the tests do not confirm the intended security property — that both modulus and exponent are authenticated by the certificate signature. Fix for all five new tests: let tbs_len: u32 = offset + 261; // 276 — covers through the last byte of a 3-byte exponentor simply Note: the function itself should also be hardened with an additional assertion: assert(exponent_offset + exponent_byte_count <= tbs_certificate_len,
"Exponent bytes exceed signed TBS length");This is a pre-existing gap in Code Quality The new test code is clear and well-structured. Comments explaining the DER byte layout ( Minor: in Testing The two negative tests ( Suggestions
Verdict🔄 Request changes — the |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.
Comments suppressed due to low confidence (1)
noir-examples/noir-passport/utils/data-check/tbs-pubkey/src/lib.nr:110
- Exponent verification still relies entirely on the prover-supplied
exponent_offsetand does not validate the DER structure around it (e.g., INTEGER tag/length atexponent_offset - 2) or that it is the INTEGER immediately following the modulus inside the same RSAPublicKey SEQUENCE. This allows a proof to satisfy the exponent check by pointing at a matching byte pattern elsewhere in the signed TBS. Consider deriving the expected exponent position frompubkey_offset/DSC_KEY_SIZE(and the modulus form) and/or asserting the DER tag/length and thatexponent_offsetmatches the derived location.
// Verify exponent bytes match the authenticated TBS certificate at exponent_offset.
//
// All 8 allowed exponents are either 1 byte (exponent=3) or 3 bytes (all others).
//
// 3-byte exponents and their expected DER value bytes:
// 38129 (0x94B1) -> [0x00, 0x94, 0xB1] (sign byte needed, MSB >= 128)
// 56611 (0xDD23) -> [0x00, 0xDD, 0x23] (sign byte needed, MSB >= 128)
// 65537 (0x010001) -> [0x01, 0x00, 0x01]
// 107903 (0x01A57F) -> [0x01, 0xA5, 0x7F]
// 109729 (0x01AC61) -> [0x01, 0xAC, 0x61]
// 122125 (0x01DC0D) -> [0x01, 0xDC, 0x0D]
// 130689 (0x01FF01) -> [0x01, 0xFF, 0x01]
//
// For the 3-byte case, u32 >> 16 naturally gives 0x00 for exponents needing a sign byte,
// and the expected 3-byte sequence matches the DER value encoding directly.
if exponent < 0x100 {
assert(exponent_offset < TBS_CERT_SIZE, "Exponent offset out of bounds");
// 1-byte exponent (only exponent=3 in the allowed list).
// exponent_offset must point to the single value byte in TBS.
assert(tbs_certificate[exponent_offset] == exponent as u8, "Exponent mismatch in TBS");
} else {
// 3-byte exponent. exponent_offset points to the first value byte (incl. sign byte).
assert(exponent_offset + 3 <= TBS_CERT_SIZE, "Exponent bytes out of bounds");
assert(
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
No description provided.