-
Notifications
You must be signed in to change notification settings - Fork 179
feat: increase sha256 byte size and add new rsa circuits #986
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
14f90ef
2a431a0
503b5c3
7a2d887
ae7a86f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| pragma circom 2.1.9; | ||
|
|
||
| include "../dsc.circom"; | ||
|
|
||
| component main { public [ merkle_root ] } = DSC(50, 120, 35); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| pragma circom 2.1.9; | ||
|
|
||
| include "../dsc.circom"; | ||
|
|
||
| component main { public [ merkle_root ] } = DSC(49, 120, 35); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| pragma circom 2.1.9; | ||
|
|
||
| include "../dsc.circom"; | ||
|
|
||
| component main { public [ merkle_root ] } = DSC(48, 120, 35); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| pragma circom 2.1.9; | ||
|
|
||
| include "../dsc.circom"; | ||
|
|
||
| component main { public [ merkle_root ] } = DSC(51, 120, 35); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| pragma circom 2.1.9; | ||
|
|
||
| include "../register.circom"; | ||
|
|
||
| component main { public [ merkle_root ] } = REGISTER(160, 160, 47, 120, 35, 384, 128); | ||
Nesopie marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| pragma circom 2.1.9; | ||
|
|
||
| include "../register.circom"; | ||
|
|
||
| component main { public [ merkle_root ] } = REGISTER(256, 160, 3, 120, 35, 512, 128); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| pragma circom 2.1.9; | ||
|
|
||
| include "../register.circom"; | ||
|
|
||
| component main { public [ merkle_root ] } = REGISTER(256, 256, 12, 120, 35, 512, 256); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| pragma circom 2.1.9; | ||
|
|
||
| include "../register.circom"; | ||
|
|
||
| component main { public [ merkle_root ] } = REGISTER(512, 512, 4, 120, 35, 896, 256); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,4 +2,4 @@ pragma circom 2.1.9; | |
|
|
||
| include "../register_id.circom"; | ||
|
|
||
| component main { public [ merkle_root ] } = REGISTER_ID(256, 256, 37, 64, 6, 512, 128); | ||
| component main { public [ merkle_root ] } = REGISTER_ID(256, 256, 37, 64, 6, 512, 256); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainConfirm param semantics and repo-wide consistency (breaking-change risk). You changed the last REGISTER_ID param from 128 → 256. If this param controls SHA-256 digest/truncation length or max signed-attr bytes, this is a protocol-level change that can invalidate existing proofs/keys and any mobile/contract integration expecting the old shape. Verify the template’s param order and ensure all dependent instances, witness builders, and verifiers are aligned. Run to confirm template signature and spot any remaining 128s: If production relies on the 128-param variant, prefer adding a new v2 instance (filename + circuit ID) and deprecate the old one, so mobile clients and contracts can migrate explicitly. 🏁 Script executed: #!/bin/bash
# 1) Inspect REGISTER_ID template signature(s)
rg -nC3 -g 'circuits/**/*.circom' -P '\btemplate\s+REGISTER_ID\s*\('
# 2) List all REGISTER_ID instantiations and diff the last param
rg -n -g 'circuits/**/*.circom' 'REGISTER_ID\(' | sed -E 's/.*REGISTER_ID\((.*)\).*/\1/' | awk -F, '{print NF "\t" $0}' | sort -u
# 3) Find any lingering instances still using 128 as last arg
rg -n -g 'circuits/**/*.circom' -P 'REGISTER_ID\([^)]*128\s*\)\s*;'Length of output: 2866 Align REGISTER_ID last parameter across all instances
💡 Verification agent 🧩 Analysis chainBoundary conditions and witness-builder alignment. If 256 represents max bytes for the SHA-256 preimage of signed attributes, add/verify checks that:
🏁 Script executed: #!/bin/bash
# Grep for the REGISTER_ID param usage in the witness builder to ensure 256 is reflected there
rg -n -C3 -P '(Sha256(Bytes|General)|REGISTER_ID).*256' app/witnesscalc src scripts
# Find tests touching REGISTER_ID limits to extend with 0/1/255/256/257 byte cases
rg -n -g '**/*test*' -P 'REGISTER_ID|sha256.*(limit|bytes|max|length)'Length of output: 460 🏁 Script executed: #!/bin/bash
# Locate REGISTER_ID usage in the TypeScript client
rg -n -C3 'REGISTER_ID' --glob 'app/**/*.ts'
# Find witness-builder or similar implementations
rg -n -C3 'witness' --glob 'app/**/*.ts'
# Check for SHA-256 preimage handling
rg -n -C3 'sha256' --glob 'app/**/*.ts'
# Search for hardcoded 256 limit references
rg -n -C3 '256' --glob 'app/**/*.ts'Length of output: 19341 Enforce 256-byte SHA-256 preimage limit across all layers
🤖 Prompt for AI Agents💡 Verification agent 🧩 Analysis chainDomain separation/tag invariants. Per spec, Register outputs must keep the Poseidon domain tag “register-v1”. Ensure this param change did not alter the commitment derivation or tag; otherwise, on-chain/verifier-side equality checks can silently break. If semantics changed (e.g., digest width), consider bumping the circuit ID or file name to make versioning explicit and prevent accidental mixing in clients/contracts. 🏁 Script executed: #!/bin/bash
# Ensure the domain tag remains unchanged across register/register_id circuits
rg -n -g 'circuits/**/*.circom' -P 'register-v1|register_id.*domain|Poseidon.*domain'Length of output: 87 🏁 Script executed: #!/bin/bash
# Locate REGISTER_ID definition and inspect Poseidon domain separation tag usage
rg -n 'template REGISTER_ID' -g 'circuits/**/*.circom'
rg -n 'REGISTER_ID\(' -C3 -g 'circuits/**/*.circom'
rg -n 'Poseidon' -C3 -g 'circuits/**/*.circom'Length of output: 37528 🏁 Script executed: #!/bin/bash
# Inspect header of register circuit for domain tag definitions
sed -n '1,200p' circuits/circuits/register/register.circom
# Inspect header of register_id circuit for domain tag definitions
sed -n '1,200p' circuits/circuits/register_id/register_id.circom
# Search for any domain or tag constants across all circom files
rg -n 'domain' -g 'circuits/**/*.circom'
rg -n 'tag' -g 'circuits/**/*.circom'Length of output: 16846 🏁 Script executed: #!/bin/bash
# Inspect constants for domain separation tags
sed -n '1,200p' circuits/circuits/utils/passport/constants.circom
rg -n 'register-v1' -g circuits/circuits/utils/passport/constants.circom
rg -n 'domain' -g circuits/circuits/utils/passport/constants.circomLength of output: 909 Commitment generation omits required 🤖 Prompt for AI Agents |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,4 +2,4 @@ pragma circom 2.1.9; | |
|
|
||
| include "../register_id.circom"; | ||
|
|
||
| component main { public [ merkle_root ] } = REGISTER_ID(256, 256, 23, 64, 6, 512, 128); | ||
| component main { public [ merkle_root ] } = REGISTER_ID(256, 256, 23, 64, 6, 512, 256); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainBump to 256: verify REGISTER_ID’s 7th param semantics and capacity If this arg is the SHA-256 input byte bound (as implied by the PR), confirm register_id.circom resized buffers, range checks, and any packing logic accordingly. A mismatch (old 128 caps still in template) would truncate/overflow and silently weaken soundness; also watch for proving-time/constraint growth regressions. Run to confirm template contract and repo-wide consistency: 🏁 Script executed: #!/bin/bash
set -euo pipefail
# 1) Inspect REGISTER_ID signature/param names
rg -nC3 -P 'template\s+REGISTER_ID\s*\(' circuits/circuits/register_id.circom
# 2) Ensure all instances use 256 as the last arg (no stragglers at 128)
echo "[instances last-arg distribution]"
rg -nP 'REGISTER_ID\([^)]*\)' circuits/circuits/register_id/instances \
| sed -E 's/.*REGISTER_ID\((.*)\).*/\1/' \
| awk -F',' '{gsub(/ /,"",$NF); print $NF}' | sort | uniq -c
rg -nP 'REGISTER_ID\([^)]*128\)' circuits/circuits/register_id/instances || true
# 3) Confirm domain-separation tag still enforced in base template
rg -nP 'register-v1' circuits/circuits/register_id.circom circuits/circuits/register/register.circom || trueLength of output: 176 🏁 Script executed: #!/bin/bash
set -euo pipefail
# 1) Locate REGISTER_ID template definition across all .circom files
echo "Locating REGISTER_ID template definition"
rg -nC3 -P 'template\s+REGISTER_ID\s*\(' -g '*.circom'
# 2) Enumerate all REGISTER_ID invocations project-wide
echo "Listing REGISTER_ID invocations"
rg -nHP 'REGISTER_ID\(' -g '*.circom'
# 3) Check last-arg distribution in instances under register_id/instances
echo "[instances last-arg distribution under circuits/circuits/register_id/instances]"
rg -nP 'REGISTER_ID\([^)]*\)' circuits/circuits/register_id/instances/**/*.circom \
| sed -E 's/.*REGISTER_ID\((.*)\).*/\1/' \
| awk -F',' '{gsub(/ /,"",$NF); print $NF}' | sort | uniq -c
# 4) Verify domain-separation tag enforcement in base templates
echo "Checking for domain separation tag 'register-v1'"
rg -nP 'register-v1' -g '*.circom'Length of output: 6597 #!/usr/bin/env bash
set -euo pipefail
echo "1) Inspect REGISTER_ID template signature"
rg -nC3 -P 'template\s+REGISTER_ID\s*\(' circuits/circuits/register_id/register_id.circom
echo
echo "2) List all REGISTER_ID instances and check 7th parameter distribution"
rg -nP 'REGISTER_ID\([^)]*\)' circuits/circuits/register_id/instances/*.circom \
| sed -E 's/.*REGISTER_ID\((.*)\).*/\1/' \
| awk -F',' '{gsub(/ /,"",$NF); print "last_arg="$NF}' \
| sort | uniq -c
echo
echo "3) Verify domain-separation tag 'register-v1' is still enforced"
rg -nP 'register-v1' circuits/circuits/register_id/register_id.circom circuits/circuits/register/register.circom || echo "tag not found"Bump all REGISTER_ID instances’ 7th param to 256 and verify template logic & domain-sep tag
🤖 Prompt for AI Agents |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,4 +2,4 @@ pragma circom 2.1.9; | |
|
|
||
| include "../register_id.circom"; | ||
|
|
||
| component main { public [ merkle_root ] } = REGISTER_ID(256, 256, 13, 120, 35, 512, 128); | ||
| component main { public [ merkle_root ] } = REGISTER_ID(256, 256, 13, 120, 35, 512, 256); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainVerify 128→256 parameter bump is fully plumbed (inputs, constants, and witnesses). If this arg maps to max SHA padded bytes or signed-attr length, you must align:
Run: 🏁 Script executed: #!/bin/bash
# Find all REGISTER_ID invocations and last-arg values
rg -nP 'REGISTER_ID\([^)]*\)' circuits | sed -E 's/.*REGISTER_ID\(([^)]*)\).*/\1/' | awk -F, '{print $NF}' | sort -u
# Check constants and usage in TS
rg -n 'MAX_PADDED_SIGNED_ATTR_LEN|MAX_SHA_BYTES|datahashes_padded_length' common | catLength of output: 537 Align REGISTER_ID size parameter across all instances 🤖 Prompt for AI Agents |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,4 +2,4 @@ pragma circom 2.1.9; | |
|
|
||
| include "../register_id.circom"; | ||
|
|
||
| component main { public [ merkle_root ] } = REGISTER_ID(256, 256, 4, 120, 35, 512, 128); | ||
| component main { public [ merkle_root ] } = REGISTER_ID(256, 256, 4, 120, 35, 512, 256); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainParameter bump to 256: confirm it matches the intended signed-attr/byte-cap and is applied repo-wide. If this is the SHA-256 signed-attributes/cert-bytes cap, centralize it as a named constant to avoid drift and recompile all dependent instances. Also check proving key size impact. Run: Optional refactor within this file: -component main { public [ merkle_root ] } = REGISTER_ID(256, 256, 4, 120, 35, 512, 256);
+// TODO: replace 256 with a shared constant (e.g., SIGNED_ATTR_MAX_BYTES) defined once
+component main { public [ merkle_root ] } = REGISTER_ID(256, 256, 4, 120, 35, 512, 256);🏁 Script executed: #!/bin/bash
set -euo pipefail
# Any remaining REGISTER_ID/REGISTER instances still using 128 as the last arg?
rg -nP 'REGISTER(_ID)?\([^)]*[, ]128\)' circuits/circuits -g '!**/node_modules/**' -S | sed -n '1,200p'Length of output: 2269 Define a shared constant for the signed-attributes cap and replace all literal 128 usages Replace the last argument in every REGISTER and REGISTER_ID call (12 instances still use 128) with a single constant, e.g. // shared/constants.circom
const SIGNED_ATTR_MAX_BYTES = 256;then update each instance: - … REGISTER_ID(…, 128);
+ … REGISTER_ID(…, SIGNED_ATTR_MAX_BYTES);Finally, regenerate all proving keys to account for the new cap. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,4 +2,4 @@ pragma circom 2.1.9; | |
|
|
||
| include "../register_id.circom"; | ||
|
|
||
| component main { public [ merkle_root ] } = REGISTER_ID(256, 256, 46, 120, 35, 512, 128); | ||
| component main { public [ merkle_root ] } = REGISTER_ID(256, 256, 46, 120, 35, 512, 256); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainConsistent 128 → 256 update: validate semantics and centralize the constant. Same note as other instances: ensure the last arg represents the intended byte cap (e.g., SHA-256 signed attrs) and is uniformly updated across all REGISTER/REGISTER_ID instances to prevent mismatched witness sizing. Use the same script shared in the other comment to detect any lingering 128s. 🏁 Script executed: #!/bin/bash
# Search for REGISTER_ID invocations with a last argument of 128 to ensure consistency
rg -nP 'REGISTER_ID\([^)]*128\)' -n .Length of output: 972 Centralize and unify the signature-attribute byte cap
🤖 Prompt for AI Agents |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| pragma circom 2.1.9; | ||
|
|
||
| include "../register_id.circom"; | ||
|
|
||
| component main { public [ merkle_root ] } = REGISTER_ID(512, 512, 4, 120, 35, 896, 256); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainFix CHUNK_NUMBER: 2048-bit wrapper is using 4096-bit limb count (35). 35 limbs at 120 bits target ~4096-bit moduli; for 2048-bit RSA this should be 18. Mismatch will break witness generation and inflate constraints. Apply: -component main { public [ merkle_root ] } = REGISTER_ID(512, 512, 4, 120, 35, 896, 256);
+component main { public [ merkle_root ] } = REGISTER_ID(512, 512, 4, 120, 18, 896, 256);🏁 Script executed: #!/bin/bash
# Confirm all 2048-bit register_id instances use 18 limbs and 4096-bit use 35.
rg -nP 'register_id_.*_2048\.circom|REGISTER_ID\(' circuits/circuits/register_id/instances -C1 | sed -n 'N;p' | rg -nP 'REGISTER_ID\([^)]*\)' -nLength of output: 5307 Fix CHUNK_NUMBER for 2048-bit REGISTER_ID instances 🤖 Prompt for AI Agents |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| pragma circom 2.1.9; | ||
|
|
||
| include "../../../utils/crypto/signature/rsa/verifyRsaGenericPkcs1v1_5.circom"; | ||
|
|
||
| template VerifyRsaPkcs1v1_5Tester() { | ||
| signal input signature[35]; | ||
| signal input modulus[35]; | ||
| signal input message[35]; | ||
|
|
||
| VerifyRsaGenericPkcs1v1_5(120, 35, 160, 47)(signature, modulus, message); | ||
| } | ||
|
|
||
| component main = VerifyRsaPkcs1v1_5Tester(); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| pragma circom 2.1.9; | ||
|
|
||
| include "../../../utils/crypto/signature/rsa/verifyRsaGenericPkcs1v1_5.circom"; | ||
|
|
||
| template VerifyRsaPkcs1v1_5Tester() { | ||
| signal input signature[35]; | ||
| signal input modulus[35]; | ||
| signal input message[35]; | ||
|
|
||
| VerifyRsaGenericPkcs1v1_5(120, 35, 256, 50)(signature, modulus, message); | ||
| } | ||
|
|
||
| component main = VerifyRsaPkcs1v1_5Tester(); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| pragma circom 2.1.9; | ||
|
|
||
| include "../../../utils/crypto/signature/rsa/verifyRsaGenericPkcs1v1_5.circom"; | ||
|
|
||
| template VerifyRsaPkcs1v1_5Tester() { | ||
| signal input signature[35]; | ||
| signal input modulus[35]; | ||
| signal input message[35]; | ||
|
|
||
| VerifyRsaGenericPkcs1v1_5(120, 35, 256, 49)(signature, modulus, message); | ||
| } | ||
|
|
||
| component main = VerifyRsaPkcs1v1_5Tester(); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| pragma circom 2.1.9; | ||
|
|
||
| include "../../../utils/crypto/signature/rsa/verifyRsaGenericPkcs1v1_5.circom"; | ||
|
|
||
| template VerifyRsaPkcs1v1_5Tester() { | ||
| signal input signature[35]; | ||
| signal input modulus[35]; | ||
| signal input message[35]; | ||
|
|
||
| VerifyRsaGenericPkcs1v1_5(120, 35, 256, 48)(signature, modulus, message); | ||
| } | ||
|
|
||
| component main = VerifyRsaPkcs1v1_5Tester(); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| pragma circom 2.1.9; | ||
|
|
||
| include "../../../utils/crypto/signature/rsa/verifyRsaGenericPkcs1v1_5.circom"; | ||
|
|
||
| template VerifyRsaPkcs1v1_5Tester() { | ||
| signal input signature[35]; | ||
| signal input modulus[35]; | ||
| signal input message[35]; | ||
|
|
||
| VerifyRsaGenericPkcs1v1_5(120, 35, 256, 51)(signature, modulus, message); | ||
| } | ||
|
|
||
| component main = VerifyRsaPkcs1v1_5Tester(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Verification agent
🧩 Analysis chain
Confirm algorithm ID (50) mapping and input chunking alignment
Ensure ID 50 maps to rsa_sha256_107903_4096 and that (120,35) matches JS splitToWords usage for 4096-bit RSA in input generation.
🏁 Script executed:
Length of output: 1001
🏁 Script executed:
Length of output: 10917
🏁 Script executed:
Length of output: 1908
Synchronize DSC circuit chunking with JS splitToWords parameters
• Algorithm ID 50 correctly maps to rsa_sha256_107903_4096 in signatureAlgorithm.circom, but the circuit instantiates DSC(50, 120, 35) (120-bit words × 35 chunks) whereas getNAndK('rsa_sha256_107903_4096') yields wordsize 32 bits and 128 chunks (4096/32 = 128). Update the circuit parameters or JS mapping so both use the same (bits-per-word, number-of-words).
🤖 Prompt for AI Agents