# Contributing to sha256.fail / sha2.fail

Thank you for helping push the reversible-circuit frontier. This guide explains how to submit a SHA-256 compression circuit, how the benchmark validates it, and how to open a pull request.

> **TL;DR** — fork the repo, edit only `solver/`, run `./setup.sh && ./benchmark.sh`, and open a PR if you strictly beat the current best score.

---

## What you are optimizing

Compute one reversible SHA-256 compression:

```
SHA256Compress : (state[256], message_block[512]) -> state'[256]
```

using only reversible gates, with **all ancilla returned to |0⟩**.

The score is:

```
score = round(avg executed Toffoli per shot) × peak live qubits   # LOWER is better
```

Clifford gates (X, CX, SWAP, CZ, …) are free.

---

## Quick start

### 1. Fork and clone

```bash
gh auth login                    # if not already logged in
gh repo fork febuz/sha256.fail --clone=true
cd sha256.fail
```

Or with plain Git:

```bash
git clone https://github.com/YOUR_USERNAME/sha256.fail.git
cd sha256.fail
git remote add upstream https://github.com/febuz/sha256.fail.git
```

### 2. Create a branch

```bash
git checkout -b solver/my-approach-name
```

### 3. Implement your circuit

Only files under `solver/` are editable in a submission. The harness expects:

- `solver/build_circuit` — builds the circuit and writes `ops.bin`.
- `solver/eval_circuit` (optional local helper) — validates and scores the circuit.

Example structure:

```
solver/
├── Cargo.toml
├── src/
│   ├── main.rs          # build_circuit entry point
│   └── lib.rs           # your circuit construction logic
└── README.md            # short description of your approach
```

Rules:

- Emit reversible gates only (X, CX, CCX/Toffoli, CCZ, …).
- Every ancilla must be uncomputed back to |0⟩.
- The circuit must match the reference SHA-256 compression on every test vector.

### 4. Run the benchmark locally

```bash
./setup.sh
./benchmark.sh
```

If the circuit passes, `score.json` is written:

```json
{
  "score": 150000000000,
  "toffoli": 50000000,
  "qubits": 3000,
  "valid": true
}
```

### 5. Commit and push

```bash
git add solver/
git commit -m "solver: add carry-save baseline with Gidney adders

- Toffoli: 50,000,000
- Qubits: 3,000
- Score: 150,000,000,000"
git push origin solver/my-approach-name
```

### 6. Open a pull request

```bash
gh pr create --title "solver: my approach name" --body "Score: 150,000,000,000. Approach described in solver/README.md."
```

A submission is **promoted only if it strictly beats the current best**. Tiny wins count.

---

## Validation rules

The evaluator (`eval_circuit`) runs every shot through three gates:

1. **Classical correctness** — output equals `SHA256Compress(state, block)` for NIST vectors + randomized blocks.
2. **Reversibility** — forward followed by reverse is the identity.
3. **Cleanliness** — every ancilla returns to |0⟩; no leftover phase garbage.

Skipping uncompute to save gates **fails** the cleanliness check.

---

## Editing the website

The public page lives at `index.html`. If you want to improve the site:

1. Open an issue first describing the change.
2. Edit `index.html`, `SCORING.md`, `POST_QUANTUM_SIGNATURES.md`, or this file.
3. Include screenshots or a link to a deployed preview.
4. Open a PR against `main`.

Website-only PRs do not need to pass the circuit benchmark.

---

## Code of conduct

- Be respectful and constructive in issues and PRs.
- Credit prior work when your approach builds on published techniques.
- Keep the benchmark honest: do not game the validator.

---

## Need help?

- Read [`README.md`](./README.md) for motivation and roadmap.
- Read [`SCORING.md`](./SCORING.md) for exact scoring rules.
- Read [`POST_QUANTUM_SIGNATURES.md`](./POST_QUANTUM_SIGNATURES.md) for the signature migration rationale.
- Open a [discussion or issue](https://github.com/febuz/sha256.fail/issues).
