We present an efficient method for verifying membership of key-value pairs in JWS/JWT payloads within zero-knowledge circuits without performing full payload decoding. The algorithm exploits the base64url encoding properties to enable direct comparison of encoded strings, reducing computational overhead in resource-constrained environments.
Modern digital signature formats such as JWS (JSON Web Signature) and JWT (JSON Web Token) apply cryptographic signatures to base64url-encoded content. Verification of specific claims within these tokens traditionally requires decoding the payload—an operation that proves computationally expensive within zero-knowledge circuits.
The fundamental problem. Let
Our approach: Rather than decode
Let us establish the basic parameters of our encoding scheme:
- JSON text is UTF-8 encoded, where each character occupies 8 bits
- Base64url encoding maps 6-bit chunks to printable ASCII characters
- The encoding function
$E: {0,1}^{8n} \to \mathcal{B}^{\lceil 4n/3 \rceil}$ maps$n$ bytes to base64url alphabet$\mathcal{B}$
The alignment problem. Since
We make the following simplifying assumptions, valid for most practical credential formats:
- Assumption 1 (Unique keys). All keys appearing in the JSON object are distinct.
- Assumption 2 (Canonical form). The JSON representation contains no extraneous whitespace, newlines, or duplicate keys.
Let
Algorithm ALIGN (Boundary adjustment)
function ALIGN(i_start, i_end)
r_start <- (i_start × 8) mod 6
r_end <- (i_end × 8) mod 6
i'_start <- i_start - ⌊r_start/2⌋
if r_end = 2 then
i'_end <- i_end + 2
else if r_end = 4 then
i'_end <- i_end + 1
else
i'_end <- i_end
return (i'_start, i'_end)After applying ALIGN, we have $(i'{\text{start}} \times 8) \bmod 6 = 0$ and the encoding of bytes $[i'{\text{start}}, i'_{\text{end}}]$ aligns with base64 character boundaries.
Proof. The residue
Having computed aligned boundaries, we construct a matchable fragment:
Algorithm VERIFY-MEMBERSHIP
- Identify target key-value pair
$(k,v)$ in original JSON coordinate space - Compute
$(i_{\text{start}}, i_{\text{end}})$ spanning the complete JSON expression for$(k,v)$ - Apply ALIGN to obtain $(i'{\text{start}}, i'{\text{end}})$
- Construct JSON fragment
$S$ containing$(k,v)$ with appropriate delimiters - Prepend/append padding characters to
$S$ to match aligned boundaries - Compute
$E(S)$ and extract corresponding substring from$E(P)$ - Return whether
$E(S)$ equals the extracted substring
Example: Consider verifying "role":"admin" appears in a JWT payload. If this string starts at byte position 10:
- Compute
$r = (10 \times 8) \bmod 6 = 80 \bmod 6 = 2$ - Adjust:
$i'_{\text{start}} = 10 - 1 = 9$ - Construct padded fragment matching byte 9 through end of value
- Compare base64url encodings directly
To ensure exact matching, we must include appropriate JSON structural characters:
- For key-value verification: include surrounding quotes and colon:
"key":"value" - For object membership: may include braces:
{"key":"value"} - For array elements: may include brackets and commas as needed
The padding characters added during alignment must come from the actual JSON context to ensure encoding equivalence.
Multiple matches. If Assumption 1 fails and keys are non-unique, our method returns success if any instance matches. Disambiguation requires additional positional constraints.
Complex JSON structures. For nested objects or arrays, the fragment construction must carefully preserve structural context and more sophisticated processing.
Non-canonical JSON. Variable whitespace violates Assumption 2 and breaks exact matching. Preprocessing or canonicalization may be necessary.
We have presented a practical algorithm for membership verification in base64url-encoded JSON without full decoding. The key insight—that base64 encoding alignment can be computed and corrected in constant time—enables direct comparison of encoded substrings, eliminating expensive decoding operations while maintaining verification soundness under reasonable assumptions about JSON structure.