From e4affc2c6ec4cc7a6cc7cd8cca3cc43ecd407288 Mon Sep 17 00:00:00 2001 From: Patrick Dugan Date: Tue, 27 Oct 2026 13:18:29 +0800 Subject: [PATCH 01/11] research: exact CNF and Boolean polynomial circuit encoding bridge --- src/spiral_ln/crypto_encoding_bridge.py | 253 ++++++++++++++++++++++++ 1 file changed, 253 insertions(+) create mode 100644 src/spiral_ln/crypto_encoding_bridge.py diff --git a/src/spiral_ln/crypto_encoding_bridge.py b/src/spiral_ln/crypto_encoding_bridge.py new file mode 100644 index 00000000..203920bb --- /dev/null +++ b/src/spiral_ln/crypto_encoding_bridge.py @@ -0,0 +1,253 @@ +"""Exact finite encodings for ETH-to-cryptography applicability audits. + +Counts are toy exhaustions or audited gate census, never runtime estimates. +A multilinear Boolean polynomial over F2 is a set of integer monomial masks. +Symmetric difference adds polynomials; bitwise OR multiplies monomials in +F2[x]/(x_i^2-x_i). Symbolic XOR-elimination preserves the number of solutions +when uniquely-determined gate wires are removed. +""" +from __future__ import annotations + +from dataclasses import dataclass +from math import log2, sqrt +from typing import Iterable + +Gate = tuple[str, int, int] # operation, left wire, right wire (zero-based) +Clause = tuple[int, ...] # signed one-based SAT literals +Poly = frozenset[int] # monomial bitmask; mask zero is constant 1 + + +@dataclass(frozen=True) +class Circuit: + inputs: int + gates: tuple[Gate, ...] + pins: tuple[tuple[int, int], ...] = () + + def validate(self) -> None: + if type(self.inputs) is not int or not 0 <= self.inputs <= 30: + raise ValueError("bad input count") + for i, (op, a, b) in enumerate(self.gates): + if op not in ("AND", "XOR", "XNOR") or not all( + type(t) is int and 0 <= t < self.inputs + i for t in (a, b) + ): + raise ValueError("invalid gate or forward reference") + for wire, bit in self.pins: + if type(wire) is not int or not 0 <= wire < self.inputs + len(self.gates): + raise ValueError("bad output wire") + if type(bit) is not int or bit not in (0, 1): + raise ValueError("bad output bit") + + +def execute(circuit: Circuit, input_bits: int) -> tuple[int, ...]: + circuit.validate() + if type(input_bits) is not int or not 0 <= input_bits < 1 << circuit.inputs: + raise ValueError("input outside domain") + wires = [(input_bits >> i) & 1 for i in range(circuit.inputs)] + for op, a, b in circuit.gates: + x, y = wires[a], wires[b] + wires.append((x & y) if op == "AND" else (x ^ y) if op == "XOR" else (x ^ y ^ 1)) + return tuple(wires) + + +def matches(circuit: Circuit, input_bits: int) -> bool: + wires = execute(circuit, input_bits) + return all(wires[i] == bit for i, bit in circuit.pins) + + +def _reject(a: int, b: int, z: int, first: int, second: int, output: int) -> Clause: + """CNF clause excluding exactly the indicated assignment.""" + return tuple((-v if assigned else v) for v, assigned in + ((first, a), (second, b), (output, z))) + + +def tseitin(circuit: Circuit) -> tuple[int, tuple[Clause, ...]]: + """One uniquely constrained variable per gate; <=4 3-clauses per gate.""" + circuit.validate() + clauses: list[Clause] = [] + for i, (op, a, b) in enumerate(circuit.gates): + first, second, out = a + 1, b + 1, circuit.inputs + i + 1 + if op == "AND": + clauses.extend(((-first, -second, out), (first, -out), (second, -out))) + else: + invert = 1 if op == "XNOR" else 0 + for x in (0, 1): + for y in (0, 1): + wrong = 1 ^ x ^ y ^ invert + clauses.append(_reject(x, y, wrong, first, second, out)) + for wire, bit in circuit.pins: + clauses.append(((wire + 1) if bit else -(wire + 1),)) + return circuit.inputs + len(circuit.gates), tuple(clauses) + + +def eval_cnf(clauses: Iterable[Clause], assignment: int) -> bool: + return all(any(bool(assignment & (1 << (abs(lit) - 1))) == (lit > 0) + for lit in clause) for clause in clauses) + + +def count_cnf(n: int, clauses: Iterable[Clause]) -> int: + if type(n) is not int or not 0 <= n <= 20: + raise ValueError("bounded exact witness allows <=20 Boolean variables") + clauses = tuple(clauses) + return sum(eval_cnf(clauses, assignment) for assignment in range(1 << n)) + + +def poly_add(a: Poly, b: Poly) -> Poly: + return a.symmetric_difference(b) + + +def poly_mul(a: Poly, b: Poly) -> Poly: + acc: set[int] = set() + for left in a: + for right in b: + term = left | right + if term in acc: + acc.remove(term) + else: + acc.add(term) + return frozenset(acc) + + +def eval_poly(poly: Poly, assignment: int) -> int: + return sum((assignment & term) == term for term in poly) & 1 + + +def zero_count(n: int, system: Iterable[Poly]) -> int: + if type(n) is not int or not 0 <= n <= 20: + raise ValueError("bounded exact witness allows <=20 Boolean variables") + eqs = tuple(system) + return sum(all(eval_poly(p, x) == 0 for p in eqs) for x in range(1 << n)) + + +def xor_eliminate(circuit: Circuit) -> tuple[int, tuple[Poly, ...]]: + """Eliminate XOR/XNOR outputs; leave one coordinate per AND. + + For every AND z=a*b, add z + A*B=0 over F2, where A,B are affine + expressions on initial inputs and earlier AND coordinates. Endpoint pins + add affine constraints. All assignments extend uniquely to circuit wires. + """ + circuit.validate() + affine = [frozenset((1 << i,)) for i in range(circuit.inputs)] + equations: list[Poly] = [] + next_variable = circuit.inputs + for op, a, b in circuit.gates: + if op == "AND": + z = frozenset((1 << next_variable,)) + equations.append(poly_add(z, poly_mul(affine[a], affine[b]))) + affine.append(z) + next_variable += 1 + elif op == "XOR": + affine.append(poly_add(affine[a], affine[b])) + else: + affine.append(poly_add(poly_add(affine[a], affine[b]), frozenset((0,)))) + for wire, bit in circuit.pins: + equations.append(poly_add(affine[wire], frozenset((0,)) if bit else frozenset())) + return next_variable, tuple(equations) + + +def poly_to_cnf(n: int, poly: Poly, scope_limit: int = 14) -> tuple[Clause, ...]: + """Truth-table clauses with no auxiliary variables; limited toy scope. + + Each invalid assignment to variables in the polynomial's support yields + one clause. The constant polynomial 1 produces one empty clause. + """ + if type(n) is not int or n < 0: + raise ValueError("bad variable count") + if any(type(mask) is not int or not 0 <= mask < 1 << n for mask in poly): + raise ValueError("bad polynomial monomial") + scope = sorted({i for mask in poly for i in range(n) if mask & (1 << i)}) + if len(scope) > scope_limit: + raise ValueError("truth table would exceed bounded witness scope") + clauses = [] + for bits in range(1 << len(scope)): + x = sum(((bits >> j) & 1) << i for j, i in enumerate(scope)) + if eval_poly(poly, x): + clauses.append(tuple((-(i + 1) if (x >> i) & 1 else i + 1) for i in scope)) + return tuple(clauses) + + +def system_to_cnf(n: int, system: Iterable[Poly], scope_limit: int = 14) -> tuple[Clause, ...]: + return tuple(clause for poly in system for clause in poly_to_cnf(n, poly, scope_limit)) + + +def local_output_cnf(n: int, inputs: tuple[int, ...], truth_table: tuple[int, ...], target: int) -> tuple[Clause, ...]: + """Encode one output bit of a fixed-locality map directly on key bits. + + inputs are zero-based positions; truth_table indexed by low-to-high bits. + One width-d clause excludes each local tuple with an incorrect output. + """ + if type(n) is not int or n < 0 or len(set(inputs)) != len(inputs) or any( + type(i) is not int or not 0 <= i < n for i in inputs + ) or not all(type(v) is int and v in (0, 1) for v in truth_table) or len(truth_table) != 1 << len(inputs): + raise ValueError("malformed local truth table") + if type(target) is not int or target not in (0, 1): + raise ValueError("invalid desired output") + clauses = [] + for mask, value in enumerate(truth_table): + if value != target: + clauses.append(tuple((-(index + 1) if (mask >> j) & 1 else index + 1) + for j, index in enumerate(inputs))) + return tuple(clauses) + + +def sparse_lemma_inventory(n: int, polys: tuple[Poly, ...], degree_bound: int, c: int) -> dict: + """Gate the *manuscript-only* sparse polynomial counting lemma. + + Its hypotheses: n>=20; <=c*n equations; each listed equation has + <=ceil(log2(n))**c monomials and degree <=fixed k=degree_bound. + Boolean multilinearization is already baked into bitmask monomials. + This does not certify the underlying theorem or its hidden constants. + """ + if any(type(x) is not int or x < 1 for x in (n, degree_bound, c)): + raise ValueError("n, fixed degree k, fixed c must be positive integers") + if any(any(type(m) is not int or not 0 <= m < (1 << n) for m in poly) for poly in polys): + raise ValueError("monomial outside declared variables") + lam = (n - 1).bit_length() + max_terms = max((len(p) for p in polys), default=0) + max_degree = max((mon.bit_count() for p in polys for mon in p), default=0) + failures = [] + if n < 20: + failures.append("n_below_20") + if len(polys) > c * n: + failures.append("too_many_equations") + if max_terms > lam ** c: + failures.append("monomial_bound_exceeded") + if max_degree > degree_bound: + failures.append("degree_bound_exceeded") + return { + "n": n, "equations": len(polys), "maximum_monomials": max_terms, + "maximum_degree": max_degree, "fixed_k": degree_bound, "fixed_c": c, + "monomial_limit": lam ** c, "eligible_on_stated_syntactic_conditions": not failures, + "failures": failures, "proof_level": "manuscript_only_not_lean_endpoint", + } + + +NIST_AES_128 = { + "key_bits": 128, "ciphertext_pins": 128, "and": 6400, + "xor": 21356, "xnor": 844, + "source": "https://csrc.nist.gov/projects/circuit-complexity/list-of-circuits", + "object": "AES-128(k,m) published SLP census, variable key and message", +} + + +def nist_aes_cnf_census() -> dict: + """Exact gate-count arithmetic for one published SLP, not an AES attack. + + Freeze plaintext bits as constants. No gate simplification or elimination + is assumed. Each binary gate gets a Tseitin variable. Output pins each + contribute one unit clause, and key bits remain free. An implementation + would need to instantiate the NIST SLP to validate this counting model. + """ + s = NIST_AES_128 + gates = s["and"] + s["xor"] + s["xnor"] + variables = s["key_bits"] + gates + clauses = 3 * s["and"] + 4 * (s["xor"] + s["xnor"]) + s["ciphertext_pins"] + proxy = variables / sqrt(log2(variables)) + return { + **s, "gates": gates, "tseitin_variables": variables, + "tseitin_clauses": clauses, "clauses_per_variable": clauses / variables, + "variables_per_key_bit": variables / s["key_bits"], + "optimistic_fixed_density_exponent_proxy": round(proxy, 3), + "proxy_over_bruteforce_key_exponent": round(proxy / s["key_bits"], 3), + "unverified_xor_elimination_variable_count_ceiling": s["key_bits"] + s["and"], + "proxy_warning": "C=1 exponent proxy; theorem has unknown large constants and no finite-scale efficiency guarantee; eliminating XORs may densify polynomials", + } From f53e17e1654ce3a81d30651da95728c3b51d4ef4 Mon Sep 17 00:00:00 2001 From: Patrick Dugan Date: Tue, 27 Oct 2026 13:19:22 +0800 Subject: [PATCH 02/11] test: 10 exact toy controls for parsimonious CNF and sparse polynomial bridge --- tests/test_crypto_encoding_bridge.py | 176 +++++++++++++++++++++++++++ 1 file changed, 176 insertions(+) create mode 100644 tests/test_crypto_encoding_bridge.py diff --git a/tests/test_crypto_encoding_bridge.py b/tests/test_crypto_encoding_bridge.py new file mode 100644 index 00000000..bea8fd89 --- /dev/null +++ b/tests/test_crypto_encoding_bridge.py @@ -0,0 +1,176 @@ +"""Exact toy-equivalence checks; no live cryptography or key attacks.""" +from __future__ import annotations + +import itertools + +import pytest + +from spiral_ln.crypto_encoding_bridge import ( + Circuit, count_cnf, eval_cnf, eval_poly, execute, local_output_cnf, + matches, nist_aes_cnf_census, poly_add, poly_mul, poly_to_cnf, + sparse_lemma_inventory, system_to_cnf, tseitin, xor_eliminate, + zero_count, +) + + +def check(circuit): + n, cnf = tseitin(circuit) + n2, polys = xor_eliminate(circuit) + actual = sum(matches(circuit, bits) for bits in range(1 << circuit.inputs)) + assert count_cnf(n, cnf) == actual + assert zero_count(n2, polys) == actual + assert count_cnf(n2, system_to_cnf(n2, polys)) == actual + assert n2 == circuit.inputs + sum(op == "AND" for op, *_ in circuit.gates) + return n, n2, cnf, polys + + +def test_single_gate_truth_table_and_unique_witness(): + for op in ("AND", "XOR", "XNOR"): + for expected in (0, 1): + circ = Circuit(2, ((op, 0, 1),), ((2, expected),)) + n, n2, cnf, polys = check(circ) + assert n == 3 + assert n2 == (3 if op == "AND" else 2) + assert len(cnf) == (4 if op != "AND" else 3) + 1 + assert all(len(clause) <= 3 for clause in cnf) + + +def test_nontrivial_chained_affine_and_nonlinear(): + circuits = ( + Circuit(3, (("XOR", 0, 1), ("AND", 3, 2), ("XNOR", 4, 1)), ((5, 1),)), + Circuit(3, (("AND", 0, 1), ("XOR", 3, 2), ("AND", 4, 0)), ((5, 0), (4, 1))), + Circuit(2, (("XOR", 0, 0), ("AND", 2, 1), ("XNOR", 3, 1)), ((4, 1),)), + Circuit(3, (("XOR", 0, 1), ("XNOR", 3, 2), ("XOR", 4, 1)), ((5, 0),)), + ) + for circ in circuits: + check(circ) + + +def test_toy_exhaustive_gate_chains_with_output_pins(): + # All 3^2 gate types, all input pairs including identical wires, and + # both target values: independent enumeration checks both encodings. + for op1, op2 in itertools.product(("AND", "XOR", "XNOR"), repeat=2): + for a, b in itertools.product(range(3), repeat=2): + for expected in (0, 1): + circ = Circuit(2, ((op1, 0, 1), (op2, a, b)), ((3, expected),)) + check(circ) + + +def test_local_map_preserves_original_variables(): + n = 6 + seed = 0b101101 + specs = ( + ((0, 2, 4), tuple(x.bit_count() % 2 for x in range(8))), + ((1, 2, 5), tuple(int(x in (3, 7)) for x in range(8))), + ((0, 3), (0, 1, 1, 0)), + ((2, 3, 4), tuple((x & 1) & ((x >> 1) & 1) for x in range(8))), + ) + all_clauses = [] + for scope, table in specs: + idx = sum(((seed >> i) & 1) << j for j, i in enumerate(scope)) + target = table[idx] + clauses = local_output_cnf(n, scope, table, target) + assert all(len(c) == len(scope) for c in clauses) + assert len(clauses) <= 1 << len(scope) + all_clauses.extend(clauses) + assert eval_cnf(all_clauses, seed) + actual = 0 + for key in range(1 << n): + good = all(table[sum(((key >> i) & 1) << j for j, i in enumerate(scope))] == + table[sum(((seed >> i) & 1) << j for j, i in enumerate(scope))] + for scope, table in specs) + actual += good + assert good == eval_cnf(all_clauses, key) + assert count_cnf(n, all_clauses) == actual + + +def test_local_map_constant_and_malformed(): + assert local_output_cnf(2, (), (1,), 1) == () + assert local_output_cnf(2, (), (1,), 0) == ((),) + with pytest.raises(ValueError): + local_output_cnf(2, (0, 0), (0, 1, 0, 1), 0) + with pytest.raises(ValueError): + local_output_cnf(2, (2,), (0, 1), 0) + + +def test_boolean_polynomial_normalization_and_direct_cnf(): + a = frozenset((1, 3, 7)) + b = frozenset((1, 6)) + assert poly_add(a, b) == frozenset((3, 6, 7)) + assert poly_mul(frozenset((1,)), frozenset((1,))) == frozenset((1,)) + assert poly_mul(frozenset((0, 1)), frozenset((0, 1))) == frozenset((0, 1)) + for masks in ((), (0,), (1, 2, 0), (1, 2, 3), (3, 5, 7)): + p = frozenset(masks) + clauses = poly_to_cnf(3, p) + assert len(clauses) <= 1 << 3 + for x in range(8): + assert (eval_poly(p, x) == 0) == eval_cnf(clauses, x) + + +def test_structural_sparse_lemma_gate_fails_closed(): + linear = tuple(frozenset((1 << (i % 23),)) for i in range(30)) + ok = sparse_lemma_inventory(30, linear, degree_bound=2, c=2) + assert ok["eligible_on_stated_syntactic_conditions"] + assert ok["monomial_limit"] == 25 + assert ok["maximum_degree"] == 1 + dense = (frozenset(range(26)),) + bad = sparse_lemma_inventory(30, dense, 2, 2) + assert "monomial_bound_exceeded" in bad["failures"] + bad = sparse_lemma_inventory(30, (frozenset((1 << 0 | 1 << 1 | 1 << 2,)),), 2, 2) + assert "degree_bound_exceeded" in bad["failures"] + bad = sparse_lemma_inventory(30, linear * 3, 2, 2) + assert "too_many_equations" in bad["failures"] + assert "n_below_20" in sparse_lemma_inventory(5, (frozenset((1,)),), 2, 2)["failures"] + + +def test_nist_aes_census_is_published_gate_arithmetic(): + d = nist_aes_cnf_census() + assert d["gates"] == 28_600 + assert d["tseitin_variables"] == 28_728 + assert d["tseitin_clauses"] == 108_128 + assert d["unverified_xor_elimination_variable_count_ceiling"] == 6_528 + assert 7_460 < d["optimistic_fixed_density_exponent_proxy"] < 7_470 + assert d["variables_per_key_bit"] > 200 + + +def test_xor_elimination_preserves_affine_sparsity_positive_control(): + # Parity on 24 inputs produces one 25-term linear relation after XOR elimination. + gates = [("XOR", 0, 1)] + for v in range(2, 24): + gates.append(("XOR", 24 + len(gates) - 1, v)) + circ = Circuit(24, tuple(gates), ((24 + len(gates) - 1, 1),)) + n, polys = xor_eliminate(circ) + assert n == 24 and len(polys) == 1 + assert len(polys[0]) == 25 # 24 singleton monomials and constant 1 + eligibility = sparse_lemma_inventory(n, polys, degree_bound=2, c=2) + assert eligibility["eligible_on_stated_syntactic_conditions"] + assert eligibility["monomial_limit"] == 25 + for bits in (0, 1, 3, 7, (1 << 24) - 1, (1 << 24) - 2): + assert (eval_poly(polys[0], bits) == 0) == matches(circ, bits) + + +def test_xor_elimination_quadratic_monomial_explosion_negative_control(): + # Two 12-input parities multiplied into an AND give 12^2 distinct + # quadratic terms after the XOR wires are removed. + gates = [] + end = [] + for start in (0, 12): + gates.append(("XOR", start, start + 1)) + for v in range(start + 2, start + 12): + gates.append(("XOR", 24 + len(gates) - 1, v)) + end.append(24 + len(gates) - 1) + gates.append(("AND", end[0], end[1])) + circ = Circuit(24, tuple(gates), ((24 + len(gates) - 1, 1),)) + n, polys = xor_eliminate(circ) + assert n == 25 and len(polys) == 2 + assert len(polys[0]) == 145 # 144 cross terms and fresh AND output + assert len(polys[1]) == 2 # pin AND output to true + eligibility = sparse_lemma_inventory(n, polys, degree_bound=2, c=2) + assert "monomial_bound_exceeded" in eligibility["failures"] + assert eligibility["maximum_degree"] == 2 + for bits in (0, 1, 3, 7, 0x123456, 0xabcdef, (1 << 24) - 1): + computed = execute(circ, bits) + extension = bits | (computed[-1] << 24) + assert all(eval_poly(poly, extension) == 0 for poly in polys) == matches(circ, bits) + flipped = extension ^ (1 << 24) + assert eval_poly(polys[0], flipped) == 1 From b3cd2d1f6721b23d58e786bd85ed6eca34522fb1 Mon Sep 17 00:00:00 2001 From: Patrick Dugan Date: Tue, 27 Oct 2026 13:19:57 +0800 Subject: [PATCH 03/11] audit: reproduce 13 exact encoding checks with source SHA-256 receipt --- scripts/verify_crypto_encoding_bridge.py | 125 +++++++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 scripts/verify_crypto_encoding_bridge.py diff --git a/scripts/verify_crypto_encoding_bridge.py b/scripts/verify_crypto_encoding_bridge.py new file mode 100644 index 00000000..70946dfe --- /dev/null +++ b/scripts/verify_crypto_encoding_bridge.py @@ -0,0 +1,125 @@ +#!/usr/bin/env python3 +"""Deterministic finite evidence ledger for cipher-to-#SAT encodings.""" +from __future__ import annotations + +import argparse +import hashlib +import json +from pathlib import Path + +from spiral_ln.crypto_encoding_bridge import ( + Circuit, count_cnf, eval_poly, local_output_cnf, matches, + nist_aes_cnf_census, sparse_lemma_inventory, tseitin, xor_eliminate, + zero_count, +) + +ROOT = Path(__file__).resolve().parents[1] +SOURCES = ( + "src/spiral_ln/crypto_encoding_bridge.py", + "tests/test_crypto_encoding_bridge.py", + "scripts/verify_crypto_encoding_bridge.py", + "paper/crypto_encoding_bridge.md", +) + + +def _parity_block(start: int, length: int, inputs: int, existing_gates: list) -> int: + existing_gates.append(("XOR", start, start + 1)) + for v in range(start + 2, start + length): + existing_gates.append(("XOR", inputs + len(existing_gates) - 1, v)) + return inputs + len(existing_gates) - 1 + + +def make_receipt() -> dict: + circ = Circuit(3, (("XOR", 0, 1), ("AND", 3, 2), ("XNOR", 4, 1)), ((5, 1),)) + n, cnf = tseitin(circ) + n2, polys = xor_eliminate(circ) + count_direct = sum(matches(circ, x) for x in range(1 << circ.inputs)) + count_boolean = count_cnf(n, cnf) + count_algebraic = zero_count(n2, polys) + + n_local = 6 + secret = 0b101101 + locality = (0, 2, 4) + predicate = tuple(x.bit_count() % 2 for x in range(8)) + selected = sum(((secret >> i) & 1) << j for j, i in enumerate(locality)) + target = predicate[selected] + local_cnf = local_output_cnf(n_local, locality, predicate, target) + local_direct = sum(predicate[sum(((x >> i) & 1) << j for j, i in enumerate(locality))] == target + for x in range(1 << n_local)) + + sparse_gates = [] + _parity_block(0, 24, 24, sparse_gates) + linear = Circuit(24, tuple(sparse_gates), ((24 + len(sparse_gates) - 1, 1),)) + lin_n, lin_eq = xor_eliminate(linear) + lin_inventory = sparse_lemma_inventory(lin_n, lin_eq, 2, 2) + + dense_gates = [] + first = _parity_block(0, 12, 24, dense_gates) + second = _parity_block(12, 12, 24, dense_gates) + dense_gates.append(("AND", first, second)) + nonlinear = Circuit(24, tuple(dense_gates), ((24 + len(dense_gates) - 1, 1),)) + dense_n, dense_eq = xor_eliminate(nonlinear) + dense_inventory = sparse_lemma_inventory(dense_n, dense_eq, 2, 2) + + aes = nist_aes_cnf_census() + checks = { + "tseitin_toy_exact_count": count_boolean == count_direct, + "xor_eliminated_toy_exact_count": count_algebraic == count_direct, + "xor_eliminated_toy_fewer_variables": n2 < n, + "local_map_no_aux_variable": len(locality) == max(map(len, local_cnf)), + "local_map_exact_count": count_cnf(n_local, local_cnf) == local_direct, + "affine_system_meets_manuscript_syntactic_conditions": lin_inventory["eligible_on_stated_syntactic_conditions"], + "affine_system_25_terms": len(lin_eq[0]) == 25, + "quadratic_system_exceeds_fixed_sparsity": not dense_inventory["eligible_on_stated_syntactic_conditions"], + "quadratic_system_145_terms": len(dense_eq[0]) == 145, + "quadratic_system_preserves_low_degree": dense_inventory["maximum_degree"] == 2, + "nist_aes_gate_census": aes["gates"] == 28_600, + "nist_aes_tseitin_census": aes["tseitin_variables"] == 28_728 and aes["tseitin_clauses"] == 108_128, + "nist_aes_subexp_proxy_above_bruteforce": aes["optimistic_fixed_density_exponent_proxy"] > aes["key_bits"], + } + return { + "schema_version": "crypto-encoding-bridge-v1", + "evidence_levels": { + "toy_counts": "finite_verified_example", + "aes_gate_census": "cited_from_nist_not_slp_replayed", + "sparse_poly_lemma": "manuscript_statement_only", + "formal_sat_bound": "pinned_upstream_lean_scope_claim", + }, + "source_sha256": { + path: hashlib.sha256((ROOT / path).read_bytes()).hexdigest() for path in SOURCES + }, + "checks": checks, + "all_passed": all(checks.values()), + "small_circuit_counts": { + "input_bits": circ.inputs, "tseitin_variables": n, + "xor_eliminated_variables": n2, "input_preimages": count_direct, + "tseitin_preimages": count_boolean, "polynomial_preimages": count_algebraic, + }, + "local_function": { + "input_bits": n_local, "locality": len(locality), + "clauses": len(local_cnf), "preimages": local_direct, + }, + "sparse_lemma_positive_control": lin_inventory, + "sparse_lemma_negative_control": dense_inventory, + "nist_aes_128_census": aes, + "warning": "No real cipher cryptanalysis, executable ETH implementation, key search, or practical speedup is claimed.", + } + + +def main() -> int: + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("--output", type=Path, default=None) + args = parser.parse_args() + receipt = make_receipt() + serialized = json.dumps(receipt, sort_keys=True, indent=2) + "\n" + if args.output: + args.output.parent.mkdir(parents=True, exist_ok=True) + args.output.write_text(serialized, encoding="utf-8") + print(f"wrote {args.output}: {sum(receipt['checks'].values())} checks") + else: + print(serialized, end="") + return 0 if receipt["all_passed"] else 1 + + +if __name__ == "__main__": + raise SystemExit(main()) From 0e9c53ad15377881ac24dc182a06c473d3cae512 Mon Sep 17 00:00:00 2001 From: Patrick Dugan Date: Tue, 27 Oct 2026 13:21:31 +0800 Subject: [PATCH 04/11] paper: scoped manuscript transfer and published AES circuit census --- paper/crypto_encoding_bridge.md | 70 +++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 paper/crypto_encoding_bridge.md diff --git a/paper/crypto_encoding_bridge.md b/paper/crypto_encoding_bridge.md new file mode 100644 index 00000000..79278951 --- /dev/null +++ b/paper/crypto_encoding_bridge.md @@ -0,0 +1,70 @@ +# ETH counting to cipher inversion: representation audit (CA-02) + +**Date:** 2026-10-27. **Evidence levels:** cited pinned theorem statement, cited NIST circuit census, algebraic encoding identities, finite exact toy examples. No actual AES key recovery is attempted. The ETH result remains subject to independent Lean replay and expert review (EvalMath PRs #10–#11). + +## Mathematical transfer + +For any circuit on **b** Boolean input bits with **g** fan-in-two AND, XOR, or XNOR gates, introduce one fresh Boolean variable for each gate, and impose its truth table in CNF. Each AND costs three clauses, each XOR/XNOR four clauses, all of width at most three. Constrain designated output bits by unit clauses. Thus, for a chosen set of output pins, + +\[ +N=b+g,\qquad M=3g_{\wedge}+4g_{\oplus,\leftrightarrow}+h. +\] + +The encoding is *parsimonious* with respect to the b free input bits: for each input, every intermediate gate variable has exactly one consistent value. Hence each satisfying assignment of the output constraint on the original b inputs has exactly one extension to the CNF, preserving the exact preimage count. Inputs fixed as constants can be simplified, although the ledger deliberately charges all published NIST gates without simplification. + +OpenAI's October 2026 pinned Lean scope claims a deterministic exact fixed-width-CNF counter with running time + +\[ +\mathrm{poly}(L)\,2^{O_k(N(\log\log N)^2/\sqrt{\log N})}. +\] + +This implies a generic **asymptotic** subexponential inverter for circuit families with \(g=O(b)\), polynomially bounded output length and a uniformly available circuit description: adding progressively fixed input literals and testing whether the resulting count is positive reconstructs a preimage with at most b decision/counting calls. A bound of \(2^{o(b)}\) is consistent with the *polynomial-time* definition of one-way functions; it excludes a family-level \(2^{\Omega(b)}\) inversion lower bound under the stated assumptions. The fixed-density manuscript claim improves the exponent to \(O(N/\sqrt{\log N})\) for \(M\le D N\), where fixed D and the hidden constants are inherited from the encoding. These statements concern the claim in the manuscript and its pinned formalization scope; they are conditional on verification of that mathematics. + +## Compact local predicates + +For \(f:{0,1}^b\to{0,1}^m\) with each output bit determined by at most a fixed \(d\) input bits, specify each given output bit by blocking all local input tuples that would yield the wrong value. This yields at most \(m2^d\) clauses, each of width at most \(d\), directly over **b** unknown input variables. If \(d\) is fixed and \(m\) is polynomial in b, the *general-density* theorem gives a \(2^{o(b)}\)-time inverter with polynomial factor in \(b+m\). For \(m=O(b)\), the paper's stronger fixed-density theorem may apply. Goldreich's constant-locality one-way function/PRG proposal is a natural asymptotic test case: it is structurally a local CSP with a fixed predicate, and a successful algorithm would be a generic subexponential inverter, **not** a polynomial-time break of the underlying one-wayness assumption. + +## XOR elimination and sparse polynomial systems + +An AND/XOR/XNOR Boolean straight-line program can be represented without retaining any linear gate outputs. Use the original input coordinates and one variable per AND. Track each XOR/XNOR wire as an affine form over these coordinates. For every AND output \(z\) fed by forms \(A,B\), impose the quadratic Boolean equation + +\[ +z+A B=0\quad\text{in }\mathbb F_2[x_1,\ldots,x_N]/(x_i^2-x_i). +\] + +Pins become affine equations, and each complete satisfying assignment extends uniquely to the original gate wires. This reduces the *declared variables* from \(b+g\) to \(b+g_{\wedge}\). It can increase the *number of listed polynomial monomials* because products of dense affine forms expand into many quadratic terms. + +The pinned manuscript's quantitative-reduction.tex, Lemma lem:tensor-sparse-query, explicitly claims exact counting of shared zeros for \(a\le cN\) equations in **N Boolean variables**, each listed with at most \(\lceil\log_2 N\rceil^c\) monomials of degree at most fixed \(k\), in + +\[ +N^{O_{k,c}(1)}\,2^{O_{k,c}(N\log\log N/\sqrt{\log N})} +\] + +bit operations and polynomial space, for fixed positive integer \(k,c\) and \(N\ge20\). This stronger sparse-polynomial *lemma* is part of the **manuscript proof**, and does not appear in the documented Lean endpoint's statement scope. Simply saying that an equation is quadratic, or algebraically sparse in a circuit representation, does not establish its required *listed monomial* bound after elimination. In particular the degree restriction and the monomial-count restriction are separate. + +Our positive control expands a 24-input XOR parity into one 25-term linear equation, at \(N=24\), meeting \(k=c=2\), \(a\le cN\). The negative control forms the product of two disjoint 12-input parities. One fresh AND variable remains, giving \(N=25\), a quadratic equation of **145** monomials (144 cross terms plus the output), above the \(\lceil\log_2 25\rceil^2=25\) limit. Exact evaluation confirms the representation identities on finite witnesses. These are eligibility and encoding checks, not an implementation of OpenAI's counting method. + +## AES-128 census and honest bounds + +[NIST's circuit complexity catalogue](https://csrc.nist.gov/projects/circuit-complexity/list-of-circuits) publishes **AES-128(k,m)** as 6,400 AND, 21,356 XOR and 844 XNOR gates, total **28,600**. Holding one plaintext fixed and pinning 128 ciphertext bits, the unsimplified Tseitin construction above has at most **28,728** variables and **108,128** clauses, all width at most 3. The ratio is **224.4375 CNF variables per 128-bit key bit**. + +With all XOR/XNOR gate outputs *symbolically* eliminated, the 6,400 AND outputs and 128 key variables would give at most **6,528 declared coordinates** before optional linear elimination. That is only a coordinate census; the actual AES quadratic equations have not been generated or measured. The number of expanded monomials and the sparsity-lemma's fixed-c eligibility remain **unverified**. In a unit-coefficient illustration, \(N/\sqrt{\log_2 N}\) at \(N=28,728\) is **7,464.9**, compared with the 128-bit brute-force exponent. For \(N=6,528\), the corresponding sparse-lemma *scale* \(N\log_2\log_2 N/\sqrt{\log_2 N}\) is **6,718.3**. Neither value is a theorem-level finite-size runtime estimate; the big-O constants and initial thresholds are unquantified and potentially enormous. Neither encoding demonstrates any AES attack. + +Lightweight ciphers invite a larger version of this audit because gate counts differ greatly by construction. Care is needed with area metrics: gate equivalents (GE) for a time-multiplexed hardware core and the number of gates in a full unrolled encryption circuit measure different objects. PRESENT, for example, has 31 rounds and 16 four-bit S-box invocations per round; a fully unrolled counting formula still represents the entire computation, including its key schedule. Report exact bit-circuit counts before inferring a smaller CNF exponent. + +## Verification and review gates + +The crypto_encoding_bridge.py code provides count-preserving CNF encoding, symbolic XOR elimination over the Boolean quotient ring, direct fixed-locality CNF, bounded sparse-polynomial truth-table CNF, syntactic eligibility inventory, and an explicitly labelled NIST gate-census calculation. Ten exact tests cover gate and witness bijections, cancellation, local predicates, polynomial multiplication, positive/negative sparsity controls, and the AES arithmetic. Source-hashed receipts are generated by scripts/verify_crypto_encoding_bridge.py. Every claimed shortcut remains conditional on the independent correctness oracle; speedups require wall-clock, memory, operation counts and held-out-scaling evidence in addition to the inequalities above. + +### Sources and reproduction + +* Upstream source pinned to [openai/math@7ef5c0c quantitative-reduction.tex](https://github.com/openai/math/blob/7ef5c0cc5ca4b0e072b7a050fca09ab24bc6fa3a/preprints/The-Exponential-Time-Hypothesis-is-False-October-25-2026/build/quantitative-reduction.tex). +* Upstream [Lean scope 378.md](https://github.com/openai/math/blob/7ef5c0cc5ca4b0e072b7a050fca09ab24bc6fa3a/lean/docs/378.md). +* [NIST published AES gate census](https://csrc.nist.gov/projects/circuit-complexity/list-of-circuits). +* [Goldreich local-function reference, O'Donnell and Witmer](https://www.cs.cmu.edu/~dwitmer/papers/csp-prg.pdf). +* [PRESENT circuit structural overview](https://ietresearch.onlinelibrary.wiley.com/doi/10.1049/iet-cds.2019.0363). + +Reproduce from EvalMath root: + + PYTHONPATH=src python -m pytest -q tests/test_crypto_encoding_bridge.py + PYTHONPATH=src python scripts/verify_crypto_encoding_bridge.py --output /tmp/crypto_bridge.json From 1365fb1553b287016b3fc541d215bad4b656d8f7 Mon Sep 17 00:00:00 2001 From: Patrick Dugan Date: Tue, 27 Oct 2026 13:21:46 +0800 Subject: [PATCH 05/11] ci: verify exact cipher encoding witnesses and upload source-hashed receipt --- .../workflows/eth-crypto-encoding-bridge.yml | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 .github/workflows/eth-crypto-encoding-bridge.yml diff --git a/.github/workflows/eth-crypto-encoding-bridge.yml b/.github/workflows/eth-crypto-encoding-bridge.yml new file mode 100644 index 00000000..b975de9d --- /dev/null +++ b/.github/workflows/eth-crypto-encoding-bridge.yml @@ -0,0 +1,42 @@ +name: eth-crypto-encoding-bridge + +on: + push: + paths: + - "src/spiral_ln/crypto_encoding_bridge.py" + - "tests/test_crypto_encoding_bridge.py" + - "scripts/verify_crypto_encoding_bridge.py" + - "paper/crypto_encoding_bridge.md" + - ".github/workflows/eth-crypto-encoding-bridge.yml" + pull_request: + paths: + - "src/spiral_ln/crypto_encoding_bridge.py" + - "tests/test_crypto_encoding_bridge.py" + - "scripts/verify_crypto_encoding_bridge.py" + - "paper/crypto_encoding_bridge.md" + - ".github/workflows/eth-crypto-encoding-bridge.yml" + workflow_dispatch: + +jobs: + finite-encoding-audit: + runs-on: ubuntu-latest + timeout-minutes: 15 + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: "3.12" + - name: Install test dependencies + run: python -m pip install -e ".[test]" + - name: Reproduce exact toy witnesses + run: python -m pytest -q tests/test_crypto_encoding_bridge.py + - name: Source-hashed crypto encoding receipt + run: | + mkdir -p output/crypto_encoding_bridge + python scripts/verify_crypto_encoding_bridge.py --output output/crypto_encoding_bridge/bridge_v1.json + - uses: actions/upload-artifact@v4 + if: always() + with: + name: eth-crypto-encoding-evidence + path: output/crypto_encoding_bridge/*.json + if-no-files-found: warn From 31edeb0a0d9a54fcfc5885072a31017d4eaf661e Mon Sep 17 00:00:00 2001 From: Patrick Dugan Date: Tue, 27 Oct 2026 13:22:06 +0800 Subject: [PATCH 06/11] docs: link CA-02 encoding audit from Cryptomania overview --- paper/cryptomania_assumption_audit.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/paper/cryptomania_assumption_audit.md b/paper/cryptomania_assumption_audit.md index a8997888..5ccaadb9 100644 --- a/paper/cryptomania_assumption_audit.md +++ b/paper/cryptomania_assumption_audit.md @@ -142,3 +142,7 @@ Boolean assertions. Every seeded benchmark instance is deterministic; all arithmetic in the Bayesian example is rational. To add a new assumption, enter its implication only after checking the exact computational model and direction of the reduction, then add a counterexample-oriented unit test. + +## Follow-up: cipher encoding transfer + +[CA-02: ETH counting to cipher inversion](crypto_encoding_bridge.md) adds exact Boolean gate-to-CNF witnesses, XOR-eliminated quadratic systems, the manuscript-only sparse-polynomial lemma's precise syntactic gate, and a published NIST AES-128 circuit census. Review it independently of the CA-01 five-world credence ledger. From 03816e55552d9b72746c0ad931ebe096596290a4 Mon Sep 17 00:00:00 2001 From: Patrick Dugan Date: Tue, 27 Oct 2026 13:29:18 +0800 Subject: [PATCH 07/11] audit: source-pinned NIST AES gate-minimum and AND-minimum Pareto encodings --- src/spiral_ln/crypto_encoding_bridge.py | 43 +++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/src/spiral_ln/crypto_encoding_bridge.py b/src/spiral_ln/crypto_encoding_bridge.py index 203920bb..a3e68f84 100644 --- a/src/spiral_ln/crypto_encoding_bridge.py +++ b/src/spiral_ln/crypto_encoding_bridge.py @@ -251,3 +251,46 @@ def nist_aes_cnf_census() -> dict: "unverified_xor_elimination_variable_count_ceiling": s["key_bits"] + s["and"], "proxy_warning": "C=1 exponent proxy; theorem has unknown large constants and no finite-scale efficiency guarantee; eliminating XORs may densify polynomials", } + + +# Source-pinned Pareto points in NIST's full AES-128 Encipher circuit catalogue. +# The 256 circuit inputs split into 128 key bits and 128 plaintext bits. +NIST_AES_FRONTIER = ( + { + "id": "fewest_total_gates_in_nist_subset", + "and": 6400, "xor": 20840, "xnor": 616, + "source_blob_sha1": "6875e0d6f5878f9cbab255d62ebaad6848cb6c53", + "source": "https://github.com/usnistgov/Circuits/blob/8366158a4324ef902ce740f29ddc9f7ebb1018b2/data/slp/aes/aes-encipher/aes128-encipher-a6400-ad50-g27856-gd286-xx21456-616.circ.txt", + }, + { + "id": "fewest_and_gates_in_nist_subset", + "and": 5800, "xor": 23840, "xnor": 4016, + "source_blob_sha1": "a1dbbb143b13f8bb7c9e5f7b3e0f3d5c27785eae", + "source": "https://github.com/usnistgov/Circuits/blob/8366158a4324ef902ce740f29ddc9f7ebb1018b2/data/slp/aes/aes-encipher/aes128-encipher-a5800-ad50-g33656-gd388-xx27856-4016.circ.txt", + }, +) + + +def nist_aes_pareto_frontier() -> tuple[dict, ...]: + """Two published options, not a claim of global optimality. + + Counts use verified gate headers; full SLP replay remains outstanding. + """ + results = [] + for variant in NIST_AES_FRONTIER: + gate_count = variant["and"] + variant["xor"] + variant["xnor"] + n = 128 + gate_count + m = 3 * variant["and"] + 4 * (variant["xor"] + variant["xnor"]) + 128 + nonlinear_n = 128 + variant["and"] + results.append({ + **variant, "key_bits": 128, "output_pins": 128, + "gates": gate_count, + "tseitin_variables": n, "tseitin_clauses": m, + "unverified_xor_elimination_variable_count": nonlinear_n, + "optimistic_cnf_exponent_proxy": round(n / sqrt(log2(n)), 3), + "optimistic_sparse_exponent_proxy": round( + nonlinear_n * log2(log2(nonlinear_n)) / sqrt(log2(nonlinear_n)), 3 + ), + "warning": "header-source census, not an SLP execution or finite-time theorem bound", + }) + return tuple(results) From 605b1da2cc56e4b506aec6e7edecac7dc37a9a21 Mon Sep 17 00:00:00 2001 From: Patrick Dugan Date: Tue, 27 Oct 2026 13:29:46 +0800 Subject: [PATCH 08/11] test: audit two NIST AES Pareto points and prevent misleading theorem proxies --- tests/test_crypto_encoding_bridge.py | 29 +++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/tests/test_crypto_encoding_bridge.py b/tests/test_crypto_encoding_bridge.py index bea8fd89..7b1efd0e 100644 --- a/tests/test_crypto_encoding_bridge.py +++ b/tests/test_crypto_encoding_bridge.py @@ -7,7 +7,7 @@ from spiral_ln.crypto_encoding_bridge import ( Circuit, count_cnf, eval_cnf, eval_poly, execute, local_output_cnf, - matches, nist_aes_cnf_census, poly_add, poly_mul, poly_to_cnf, + matches, nist_aes_cnf_census, nist_aes_pareto_frontier, poly_add, poly_mul, poly_to_cnf, sparse_lemma_inventory, system_to_cnf, tseitin, xor_eliminate, zero_count, ) @@ -174,3 +174,30 @@ def test_xor_elimination_quadratic_monomial_explosion_negative_control(): assert all(eval_poly(poly, extension) == 0 for poly in polys) == matches(circ, bits) flipped = extension ^ (1 << 24) assert eval_poly(polys[0], flipped) == 1 + + + +def test_nist_flat_aes_pareto_header_arithmetic(): + gate_min, and_min = nist_aes_pareto_frontier() + assert (gate_min["and"], gate_min["xor"], gate_min["xnor"]) == (6400, 20840, 616) + assert (gate_min["gates"], gate_min["tseitin_variables"], gate_min["tseitin_clauses"]) == ( + 27856, 27984, 105152 + ) + assert (and_min["and"], and_min["xor"], and_min["xnor"]) == (5800, 23840, 4016) + assert (and_min["gates"], and_min["tseitin_variables"], and_min["tseitin_clauses"]) == ( + 33656, 33784, 128952 + ) + assert gate_min["gates"] < and_min["gates"] + assert and_min["unverified_xor_elimination_variable_count"] == 5928 + assert gate_min["unverified_xor_elimination_variable_count"] == 6528 + assert all(item["optimistic_cnf_exponent_proxy"] > 128 for item in (gate_min, and_min)) + assert all(item["optimistic_sparse_exponent_proxy"] > 128 for item in (gate_min, and_min)) + + +def test_nist_published_variants_have_source_and_scope_distinctions(): + options = nist_aes_pareto_frontier() + assert len(options) == 2 + assert len({x["source_blob_sha1"] for x in options}) == 2 + assert all(len(x["source_blob_sha1"]) == 40 for x in options) + assert all("/aes128-encipher-" in x["source"] for x in options) + assert all("not an SLP execution" in x["warning"] for x in options) From 6c06efd9ab75c01aeba78f1546f1db05bebda7f4 Mon Sep 17 00:00:00 2001 From: Patrick Dugan Date: Tue, 27 Oct 2026 13:30:07 +0800 Subject: [PATCH 09/11] audit: include source-pinned AES Pareto figures in deterministic verification --- scripts/verify_crypto_encoding_bridge.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/scripts/verify_crypto_encoding_bridge.py b/scripts/verify_crypto_encoding_bridge.py index 70946dfe..42643577 100644 --- a/scripts/verify_crypto_encoding_bridge.py +++ b/scripts/verify_crypto_encoding_bridge.py @@ -9,7 +9,7 @@ from spiral_ln.crypto_encoding_bridge import ( Circuit, count_cnf, eval_poly, local_output_cnf, matches, - nist_aes_cnf_census, sparse_lemma_inventory, tseitin, xor_eliminate, + nist_aes_cnf_census, nist_aes_pareto_frontier, sparse_lemma_inventory, tseitin, xor_eliminate, zero_count, ) @@ -62,6 +62,7 @@ def make_receipt() -> dict: dense_inventory = sparse_lemma_inventory(dense_n, dense_eq, 2, 2) aes = nist_aes_cnf_census() + frontier = nist_aes_pareto_frontier() checks = { "tseitin_toy_exact_count": count_boolean == count_direct, "xor_eliminated_toy_exact_count": count_algebraic == count_direct, @@ -76,6 +77,13 @@ def make_receipt() -> dict: "nist_aes_gate_census": aes["gates"] == 28_600, "nist_aes_tseitin_census": aes["tseitin_variables"] == 28_728 and aes["tseitin_clauses"] == 108_128, "nist_aes_subexp_proxy_above_bruteforce": aes["optimistic_fixed_density_exponent_proxy"] > aes["key_bits"], + "nist_frontier_header_count": [(x["gates"], x["tseitin_variables"], x["tseitin_clauses"]) for x in frontier] == [ + (27856, 27984, 105152), (33656, 33784, 128952) + ], + "nist_and_minimum_changes_coordinate_budget": ( + frontier[1]["unverified_xor_elimination_variable_count"] == 5928 + and frontier[1]["gates"] > frontier[0]["gates"] + ), } return { "schema_version": "crypto-encoding-bridge-v1", @@ -102,6 +110,7 @@ def make_receipt() -> dict: "sparse_lemma_positive_control": lin_inventory, "sparse_lemma_negative_control": dense_inventory, "nist_aes_128_census": aes, + "nist_pareto_frontier_census": list(frontier), "warning": "No real cipher cryptanalysis, executable ETH implementation, key search, or practical speedup is claimed.", } From 9be6440e352078834de9c8b5457b1ae6228b0cf3 Mon Sep 17 00:00:00 2001 From: Patrick Dugan Date: Tue, 27 Oct 2026 13:31:19 +0800 Subject: [PATCH 10/11] docs: source-pin NIST AES full-circuit Pareto alternatives and correct cost comparison --- paper/crypto_encoding_bridge.md | 36 ++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/paper/crypto_encoding_bridge.md b/paper/crypto_encoding_bridge.md index 79278951..bf8308bf 100644 --- a/paper/crypto_encoding_bridge.md +++ b/paper/crypto_encoding_bridge.md @@ -50,11 +50,45 @@ Our positive control expands a 24-input XOR parity into one 25-term linear equat With all XOR/XNOR gate outputs *symbolically* eliminated, the 6,400 AND outputs and 128 key variables would give at most **6,528 declared coordinates** before optional linear elimination. That is only a coordinate census; the actual AES quadratic equations have not been generated or measured. The number of expanded monomials and the sparsity-lemma's fixed-c eligibility remain **unverified**. In a unit-coefficient illustration, \(N/\sqrt{\log_2 N}\) at \(N=28,728\) is **7,464.9**, compared with the 128-bit brute-force exponent. For \(N=6,528\), the corresponding sparse-lemma *scale* \(N\log_2\log_2 N/\sqrt{\log_2 N}\) is **6,718.3**. Neither value is a theorem-level finite-size runtime estimate; the big-O constants and initial thresholds are unquantified and potentially enormous. Neither encoding demonstrates any AES attack. +### Updated NIST AES-128 full-circuit Pareto census + +NIST's current flat Encipher catalogue provides two source-pinned alternatives +to the older 28,600-gate reference. Each has 256 input bits (128 plaintext, +128 key), 128 output bits and a complete unrolled encryption + key expansion. + +| Variant | AND | XOR/XNOR | Total gates | Tseitin variables | Tseitin clauses | XOR-eliminated coordinates | +|---|---:|---:|---:|---:|---:|---:| +| Lower total gate count | 6,400 | 21,456 | 27,856 | 27,984 | 105,152 | 6,528 | +| Lower AND count | 5,800 | 27,856 | 33,656 | 33,784 | 128,952 | 5,928 | + +The full-circuit counts are sourced from these independently retrieved headers, +pinned to NIST Circuits commit 8366158a4324ef902ce740f29ddc9f7ebb1018b2: + +* [27,856-gate AES-128 Encipher](https://github.com/usnistgov/Circuits/blob/8366158a4324ef902ce740f29ddc9f7ebb1018b2/data/slp/aes/aes-encipher/aes128-encipher-a6400-ad50-g27856-gd286-xx21456-616.circ.txt), Git blob SHA-1 6875e0d6f5878f9cbab255d62ebaad6848cb6c53. +* [5,800-AND AES-128 Encipher](https://github.com/usnistgov/Circuits/blob/8366158a4324ef902ce740f29ddc9f7ebb1018b2/data/slp/aes/aes-encipher/aes128-encipher-a5800-ad50-g33656-gd388-xx27856-4016.circ.txt), Git blob SHA-1 a1dbbb143b13f8bb7c9e5f7b3e0f3d5c27785eae. + +The upper bounds charge every gate after the plaintext is substituted and +pin 128 ciphertext output bits. Gate-level simplification could reduce the +formula further. XOR elimination has 6,528 versus 5,928 declared coordinates, +but actual expanded monomial counts remain unknown. With an illustration +coefficient of one, the fixed-density CNF scales are approximately +7,280.9 and 8,710.2, respectively; corresponding sparse-polynomial +scales are approximately 6,718.3 and 6,107.9. These figures rank +representations under assumed cost functions. They provide no AES key-recovery +algorithm, since the manuscript's actual constants, finite-size applicability +and post-elimination sparsity are unverified. + +This is a Pareto comparison within two documented NIST options, not a +claim that either circuit is globally smallest. Both source blob hashes were +confirmed against the pinned NIST commit. A complete SLP execution is future +work. + + Lightweight ciphers invite a larger version of this audit because gate counts differ greatly by construction. Care is needed with area metrics: gate equivalents (GE) for a time-multiplexed hardware core and the number of gates in a full unrolled encryption circuit measure different objects. PRESENT, for example, has 31 rounds and 16 four-bit S-box invocations per round; a fully unrolled counting formula still represents the entire computation, including its key schedule. Report exact bit-circuit counts before inferring a smaller CNF exponent. ## Verification and review gates -The crypto_encoding_bridge.py code provides count-preserving CNF encoding, symbolic XOR elimination over the Boolean quotient ring, direct fixed-locality CNF, bounded sparse-polynomial truth-table CNF, syntactic eligibility inventory, and an explicitly labelled NIST gate-census calculation. Ten exact tests cover gate and witness bijections, cancellation, local predicates, polynomial multiplication, positive/negative sparsity controls, and the AES arithmetic. Source-hashed receipts are generated by scripts/verify_crypto_encoding_bridge.py. Every claimed shortcut remains conditional on the independent correctness oracle; speedups require wall-clock, memory, operation counts and held-out-scaling evidence in addition to the inequalities above. +The crypto_encoding_bridge.py code provides count-preserving CNF encoding, symbolic XOR elimination over the Boolean quotient ring, direct fixed-locality CNF, bounded sparse-polynomial truth-table CNF, syntactic eligibility inventory, and an explicitly labelled NIST gate-census calculation. Twelve exact tests cover gate and witness bijections, cancellation, local predicates, polynomial multiplication, positive/negative sparsity controls, and the AES arithmetic. Source-hashed receipts are generated by scripts/verify_crypto_encoding_bridge.py. Every claimed shortcut remains conditional on the independent correctness oracle; speedups require wall-clock, memory, operation counts and held-out-scaling evidence in addition to the inequalities above. ### Sources and reproduction From 472638a5bb903eb6dd9333db92d8783279fea4d2 Mon Sep 17 00:00:00 2001 From: Patrick Dugan Date: Tue, 27 Oct 2026 13:37:38 +0800 Subject: [PATCH 11/11] research: exact monomial histogram from NIST AES straight-line circuits via affine supports --- src/spiral_ln/aes_slp_sparse_census.py | 184 +++++++++++++++++++++++++ 1 file changed, 184 insertions(+) create mode 100644 src/spiral_ln/aes_slp_sparse_census.py diff --git a/src/spiral_ln/aes_slp_sparse_census.py b/src/spiral_ln/aes_slp_sparse_census.py new file mode 100644 index 00000000..62f7627a --- /dev/null +++ b/src/spiral_ln/aes_slp_sparse_census.py @@ -0,0 +1,184 @@ +"""Exact affine-support monomial census for pinned NIST AES flat circuits. + +For each AND gate z = A*B, A and B are affine Boolean functions of +128 symbolic key bits and earlier AND outputs. XOR/XNOR gate outputs are +eliminated. Quadratic monomial counts are obtained exactly using set +intersections, with no expansion or heuristic sampling. + +Usage: + python scripts/verify_nist_aes_slp.py --input aes.circ.txt --git-blob-sha1 SHA1 +""" +from __future__ import annotations + +import hashlib +import re +from dataclasses import dataclass +from math import ceil, log2 +from typing import Any + + +@dataclass(frozen=True) +class Affine: + support: int + constant: int + + def __post_init__(self) -> None: + if type(self.support) is not int or self.support < 0 or self.constant not in (0, 1): + raise ValueError("invalid affine form") + + +def monomial_counts_for_and(a: Affine, b: Affine) -> dict[str, int]: + """Counts terms in z + A*B over Boolean quotient F2[x]/(x_i^2-x_i). + + U = supp(A)\supp(B), V = supp(B)\supp(A), I = intersection. + Cross terms are U×V and I×(U union V); shared×shared cancels. + """ + common = (a.support & b.support).bit_count() + only_a = (a.support & ~b.support).bit_count() + only_b = (b.support & ~a.support).bit_count() + quadratic = only_a * only_b + common * (only_a + only_b) + linear = only_a * b.constant + only_b * a.constant + common * ( + 1 ^ a.constant ^ b.constant + ) + constant = a.constant & b.constant + return { + "quadratic": quadratic, + "linear": linear, + "constant": constant, + "fresh_nonlinear_coordinate": 1, + "total": quadratic + linear + constant + 1, + } + + +def git_blob_sha1(raw: bytes) -> str: + return hashlib.sha1(b"blob " + str(len(raw)).encode("ascii") + b"\0" + raw).hexdigest() + + +def _quantiles(values: list[int]) -> dict[str, int]: + if not values: + raise ValueError("empty sample") + s = sorted(values) + q = lambda p: s[int((len(s) - 1) * p)] + return { + "count": len(s), "minimum": s[0], "median_lower": q(0.5), + "p90": q(0.9), "p99": q(0.99), "maximum": s[-1], + "sum": sum(s), + "above_169": sum(v > 169 for v in s), + "above_2197": sum(v > 2197 for v in s), + "above_28561": sum(v > 28561 for v in s), + } + + +def slp_census( + raw: bytes, *, + key_bits: int = 128, + plaintext_bits: int = 128, + output_bits: int = 128, + plaintext_value: int = 0, + ciphertext_value: int = 0, + expected_git_blob_sha1: str | None = None, +) -> dict[str, Any]: + """Read one full NIST NCFF-2026 SLP, fail closed on unknown gates. + + ptx[i] is fixed to bit i of plaintext_value; key[i] is symbolic. + A fresh coordinate is introduced at every AND output. The ciphertext + pins only change constant terms of the output equations. + """ + sha = git_blob_sha1(raw) + if expected_git_blob_sha1 is not None and sha != expected_git_blob_sha1: + raise ValueError("NIST source blob SHA-1 mismatch") + for width in (key_bits, plaintext_bits, output_bits): + if type(width) is not int or width < 0: + raise ValueError("invalid source bit width") + if type(plaintext_value) is not int or not 0 <= plaintext_value < (1 << plaintext_bits): + raise ValueError("invalid fixed plaintext") + if type(ciphertext_value) is not int or not 0 <= ciphertext_value < (1 << output_bits): + raise ValueError("invalid pinned ciphertext") + text = raw.decode("utf-8") + lines = text.splitlines() + markers = [i for i, line in enumerate(lines) if line.strip() == "begin SLP"] + endings = [i for i, line in enumerate(lines) if line.strip() == "end SLP"] + if len(markers) != 1 or len(endings) != 1 or markers[0] >= endings[0]: + raise ValueError("expected a unique complete SLP") + header = re.search( + r"Tally of gates \(G\): (\d+) AND; (\d+) XOR; (\d+) XNOR", text + ) + if header is None: + raise ValueError("missing NIST header gate tally") + expected = dict(zip(("AND", "XOR", "XNOR"), map(int, header.groups()))) + wires = { + **{f"ptx{i}": Affine(0, (plaintext_value >> i) & 1) + for i in range(plaintext_bits)}, + **{f"key{i}": Affine(1 << i, 0) for i in range(key_bits)}, + } + counts = {"AND": 0, "XOR": 0, "XNOR": 0} + and_total: list[int] = [] + and_quadratic: list[int] = [] + and_linear: list[int] = [] + for line in lines[markers[0] + 1:endings[0]]: + stripped = line.strip() + if not stripped or stripped.startswith("%"): + continue + parts = stripped.split() + if len(parts) != 4 or parts[0] not in counts: + raise ValueError(f"unknown SLP operation: {stripped[:100]}") + op, out, left, right = parts + if out in wires: + raise ValueError(f"duplicate output wire: {out}") + if left not in wires or right not in wires: + raise ValueError(f"undefined input wire in: {stripped[:100]}") + a, b = wires[left], wires[right] + if op == "AND": + m = monomial_counts_for_and(a, b) + and_total.append(m["total"]) + and_quadratic.append(m["quadratic"]) + and_linear.append(m["linear"]) + wires[out] = Affine(1 << (key_bits + counts["AND"]), 0) + else: + wires[out] = Affine(a.support ^ b.support, + a.constant ^ b.constant ^ int(op == "XNOR")) + counts[op] += 1 + if counts != expected: + raise ValueError(f"gate tally disagrees with source header: {counts} != {expected}") + pins = [] + for j in range(output_bits): + out = wires.get(f"ctx{j}") + if out is None: + raise ValueError(f"missing ciphertext output ctx{j}") + target = (ciphertext_value >> j) & 1 + pins.append(out.support.bit_count() + (out.constant ^ target)) + n = key_bits + counts["AND"] + equations = len(and_total) + len(pins) + maximum = max(and_total + pins) + if n < 2: + raise ValueError("insufficient variables for logarithm") + lam = ceil(log2(n)) + lowest_c = next((c for c in range(1, 16) + if equations <= c * n and maximum <= lam ** c), None) + return { + "source_git_blob_sha1": sha, + "source_bytes": len(raw), + "parameterization": { + "key_bits": key_bits, "plaintext_bits": plaintext_bits, + "output_bits": output_bits, + "plaintext_value_hex": hex(plaintext_value), + "ciphertext_value_hex": hex(ciphertext_value), + }, + "gate_tally": counts, "gates": sum(counts.values()), + "xor_eliminated_coordinates": n, "equations": equations, + "degree_bound": 2, + "and_equation_monomials": _quantiles(and_total), + "and_quadratic_monomials": _quantiles(and_quadratic), + "and_linear_monomials": _quantiles(and_linear), + "ciphertext_pin_monomials": _quantiles(pins), + "max_polynomial_monomials": maximum, + "ceil_log2_coordinates": lam, + "minimum_c_at_this_fixed_size": lowest_c, + "c_bound_checks": [ + {"c": c, "max_monomials_allowed": lam ** c, + "equations_allowed": c * n, + "passes_syntactic_checks": equations <= c * n and maximum <= lam ** c} + for c in range(1, 6) + ], + "scope_note": "fixed-size syntactic census only; not a uniform family or implementation of the ETH counting theorem", + }