Metadata-Version: 2.5
Name: zeropx-layercomp
Version: 0.1.0
Summary: Algebraic composition of defense-in-depth layers — pick min, sum-dB, or max correctly
Project-URL: Homepage, https://github.com/NixEngine/zeropx-layercomp
Project-URL: Repository, https://github.com/NixEngine/zeropx-layercomp
Project-URL: Issues, https://github.com/NixEngine/zeropx-layercomp/issues
Author-email: "Dr. Vander Geraldo Rodrigues da Cunha Júnior" <vgrcjr@gmail.com>
License: MIT
License-File: LICENSE
Keywords: audit,composition,container,cryptography,defense-in-depth,security,zk
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Information Technology
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Security
Classifier: Topic :: Security :: Cryptography
Classifier: Typing :: Typed
Requires-Python: >=3.10
Provides-Extra: dev
Requires-Dist: pytest>=7; extra == 'dev'
Description-Content-Type: text/markdown

# zeropx-layercomp

**Algebraic composition of defense-in-depth layers.** Pick the right operator (min, sum-dB, or max) based on the threat model — not by habit.

## Why

There is a subtle but consequential inconsistency in how the literature composes layered defenses:

- **ZK / cryptographic security** uses `λ_efetiva = min{λ_alg, λ_FRI, λ_hash, ...}` — the weakest link.
- **EM shielding / passive attenuation** uses `SE_total_dB = SE_1 + SE_2 + ...` — additive in decibels (product in linear).
- **Consensus systems** use `max` — you fail only if the majority does.

The same word "defense-in-depth" describes all three, but the arithmetic is different, and the wrong choice can inflate a bound by orders of magnitude.

`layercomp` implements the decision tree and lets you feed a stack description and get the correctly composed score, with an explanation of which operator was used and why.

## Install

```bash
pip install zeropx-layercomp
```
*(Python import module: `layercomp` | CLI command: `layercomp`)*

Zero runtime dependencies. Python 3.10+.

## Quick start

Describe your stack in a JSON file:

```json
{
  "layers": [
    { "name": "arithmetization", "score": 128, "unit": "bits", "threat_model": "adversarial" },
    { "name": "FRI",              "score": 100, "unit": "bits", "threat_model": "adversarial" },
    { "name": "Poseidon2",        "score":  95, "unit": "bits", "threat_model": "adversarial",
      "notes": "BBLP22 instance ~2^95, marked Unresolved by Least Authority" }
  ]
}
```

Then:

```bash
layercomp score my-zk-stack.json
```

Output:

```
layercomp v0.1.0

Composition result
  operator:   min
  total:      95 bits
  determined: Poseidon2

Rationale: adversarial threat model — attacker selects weakest layer.
Composition is the minimum score across layers.

Per-layer:
   arithmetization: 128 bits [adversarial, indep=True]
   FRI: 100 bits [adversarial, indep=True]
 * Poseidon2: 95 bits [adversarial, indep=True] — BBLP22 instance ~2^95, marked Unresolved by Least Authority
```

## Decision tree

```
layercomp explain
```

Prints:

```
1. Any layer ADVERSARIAL or mixed → min (most conservative)
2. All CONSENSUS → max (honest-majority)
3. All PASSIVE and all independent → sum-in-dB
4. PASSIVE but dependent → downgrade to min with warning
```

## The common mistake this fixes

Two frameworks routinely conflate these operators:

- Container hardening scored with `SE_container = SE_ns + SE_cgroup + SE_seccomp + SE_net` is wrong under the adversarial model (attacker needs to escape *one* namespace, not all). It should be `min(...)`.
- Meanwhile, `sum-in-dB` is the right composition for a Faraday cage against a passive EM leakage — the field really is attenuated through every layer in series.

The distinction is `who is choosing the attack path`: an adversary chooses the weakest link; nature/noise flows through everything.

## As a library

```python
from layercomp import Layer, ThreatModel, ScoreUnit, compose

result = compose([
    Layer("arithmetization", 128, ScoreUnit.BITS, ThreatModel.ADVERSARIAL),
    Layer("FRI",              100, ScoreUnit.BITS, ThreatModel.ADVERSARIAL),
    Layer("Poseidon2",         95, ScoreUnit.BITS, ThreatModel.ADVERSARIAL),
])

print(result.total)              # 95
print(result.operator_used)      # 'min'
print(result.layer_that_determined)  # 'Poseidon2'
print(result.rationale)          # human-readable explanation
```

## Testing

```bash
pip install -e ".[test]"
python -m pytest tests/ -v
```

## Companion tools

`zeropx-layercomp` is part of the ZeroPx Auditor's Toolkit of zero-dependency Python packages:

- **zeropx-gguf-inspect** — static read-only inspection of GGUF model files without loading them
- **zeropx-corpus-scan** — byte-honest SHA-256 inventory of a document corpus
- **zeropx-receipt-chain** — append-only tamper-evident event ledger
- **zeropx-poseidon2-goldilocks** — pure-Python Poseidon2 reference implementation over Goldilocks

## Author & Provenance

**Sole Author:** Dr. Vander Geraldo Rodrigues da Cunha Júnior (`vgrcjr@gmail.com`).

*Technical & AI-Assisted Provenance Disclosure:* Auxiliary computational/LLM tooling was used strictly for boilerplate and test-harness scaffolding under 1:1 human architectural design, algebraic verification, code review, and sole human authorship. Zero runtime third-party or AI dependencies.

## License

MIT.
