# roycesteven/dilithium-msc-project architecture

> Architecture diagram of the GitHub repository roycesteven/dilithium-msc-project, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-22). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/roycesteven/dilithium-msc-project
- Repository: https://github.com/roycesteven/dilithium-msc-project

## Overview

#### Purpose and entry points
This is a research implementation and evidence pipeline for post-quantum Lattice-based Adaptor Signatures (LAS) built from simplified Dilithium / ML-DSA primitives, with atomic-swap applications. Primary entry points are the C build in `ref/Makefile`, the Rust crate in `rust/fips204-las/Cargo.toml`, and reproducible experiment runners in `scripts/run_benchmark_suite.sh` and `scripts/run_rust_bench_suite.sh`.

#### Core C protocol implementation
The C implementation is the reference protocol stack. It defines shared public parameters and protocol object types, generates hard-relation statements/witnesses, implements the base signature, then implements adaptor operations: presign, preverify, adapt, and extract.
- `ref/setup.c`
- `ref/relation.c`
- `ref/basesig.c`
- `ref/las.c`
- `ref/serialize.c`

The cryptographic arithmetic and hashing boundary is the reused Dilithium-style polynomial/NTT/SHAKE substrate, rather than application code:
- `ref/poly.c`
- `ref/ntt.c`
- `ref/fips202.c`

#### Rust mirror and interoperability boundary
`rust/fips204-las/` is a parallel Rust implementation intended to emit byte-identical protocol objects to C. Its public library surface is rooted in `src/lib.rs`; LAS logic, base signatures, relation construction, and canonical encoding are separated into matching modules.
- `rust/fips204-las/src/lib.rs`
- `rust/fips204-las/src/las.rs`
- `rust/fips204-las/src/basesig.rs`
- `rust/fips204-las/src/serialize.rs`

The key system invariant is cross-language wire compatibility, with deterministic known-answer testing serving as the gate before measurement or application use:
- `ref/test/test_kat.c`
- `rust/fips204-las/tests/las_kat.rs`

#### Proof and swap layer
The optional proof-of-knowledge layer proves knowledge of the relation witness used by the Figure-1-style atomic swap. C exposes relation-proof abstractions and backends, including the vendored-LaZer integration; the Rust port can use the same proof-system path through an opt-in feature.
- `ref/relation_zk.c`
- `ref/relation_zk_lazer.c`
- `ref/test/test_swap.c`
- `rust/fips204-las/tests/las_swap.rs`

A separate Rust swap crate models protocol orchestration, UTXO state, interchangeable LAS/ECDSA backends, and benchmarkable swap flows:
- `rust/las-swap/src/protocol.rs`
- `rust/las-swap/src/utxo.rs`
- `rust/las-swap/src/las_backend.rs`

#### Blockchain integration surfaces
Bitcoin integration has two levels: a standalone C consensus-oriented LAS verifier/tool and a patch against Bitcoin Script semantics, with Python drivers for transaction construction, spending, recovery, and model checks.
- `bitcoin/las_consensus/las_consensus.c`
- `bitcoin/las_consensus/las_btc_tool.c`
- `bitcoin/patches/0001-op-checklassigverify-v31.1.patch`
- `bitcoin/tools/btc_las_spend.py`

Ethereum integration is Solidity verification and swap/claim contracts, driven by Foundry scripts. Contract verification is distinct from swap state management.
- `evm/src/LASVerifier.sol`
- `evm/src/AdaptorSwap.sol`
- `evm/src/AdaptorSwapBound.sol`
- `evm/script/TwoLeg.s.sol`

These external-runtime boundaries require Bitcoin Core/regtest for node experiments and an EVM/Foundry environment for gas and transaction experiments.

#### Succinct-proof research branch
`rust/las-stark/` is an independent Rust STARK proving/verification implementation for LAS relations and role-specific computations. It has CLI binaries for proof generation, verification, and benchmarking rather than being part of the C/Rust byte-identical signing path.
- `rust/las-stark/src/air.rs`
- `rust/las-stark/src/prover.rs`
- `rust/las-stark/src/bin/prove_relation.rs`
- `rust/las-stark/src/bin/verify_relation.rs`

#### Measurement-to-report pipeline
Correctness-gated benchmark drivers generate timestamped immutable evidence; scripts transform evidence into tables, plots, generated LaTeX macros, and the final report. Evidence also captures Bitcoin regtest and EVM receipts/calldata, preserving application-level outcomes separately from local microbenchmarks.
- `scripts/run_benchmark_suite.sh`
- `scripts/gen_report_data.py`
- `evidence/runs/`
- `report/latex/report.tex`
- `report/latex/generated/`

The architectural control flow is: implementations → interoperability/functional gates → benchmarks and blockchain experiments → timestamped evidence → generated report artifacts. Documentation maps mathematical construction and experimental claims back to implementation and evidence:
- `docs/02-methodology/THEORY_IMPL_BRIDGE.md`
- `README_EXTENDED.md`

Main entry points: [`ref/las.c`](https://github.com/roycesteven/dilithium-msc-project/blob/main/ref/las.c) (LAS protocol core), [`rust/fips204-las/src/lib.rs`](https://github.com/roycesteven/dilithium-msc-project/blob/main/rust/fips204-las/src/lib.rs) (Rust LAS library), [`ref/test/test_kat.c`](https://github.com/roycesteven/dilithium-msc-project/blob/main/ref/test/test_kat.c) (C known-answer gate), [`rust/fips204-las/tests/las_kat.rs`](https://github.com/roycesteven/dilithium-msc-project/blob/main/rust/fips204-las/tests/las_kat.rs) (Rust known-answer gate)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_c["C reference stack"]
  node_c_build["C build<br/>build entry point"]
  node_c_protocol["LAS protocol core<br/>C protocol<br/>[las.c]"]
  node_c_relation["Relation construction<br/>C relation module<br/>[relation.c]"]
  node_c_arithmetic["Dilithium arithmetic<br/>crypto substrate<br/>[poly.c]"]
  node_c_kat["C known-answer gate<br/>C test<br/>[test_kat.c]"]
  node_c_zk["Relation proof layer<br/>C ZK proof<br/>[relation_zk.c]"]
  node_c_swap_test["C atomic-swap test<br/>C test<br/>[test_swap.c]"]
end

subgraph group_rust["Rust implementations"]
  node_rust_las["Rust LAS library<br/>Rust crate<br/>[lib.rs]"]
  node_rust_las_logic["Rust adaptor logic<br/>Rust LAS module<br/>[las.rs]"]
  node_rust_kat["Rust known-answer gate<br/>Rust integration test<br/>[las_kat.rs]"]
  node_rust_swap["Swap orchestration<br/>Rust swap crate<br/>[protocol.rs]"]
  node_stark["STARK research branch<br/>Rust proving system<br/>[prover.rs]"]
  node_stark_prove["STARK proof CLI<br/>Rust CLI<br/>[prove_relation.rs]"]
end

subgraph group_chain["Blockchain integrations"]
  node_bitcoin["Bitcoin LAS verifier<br/>C consensus tool<br/>[las_consensus.c]"]
  node_bitcoin_patch["Bitcoin Script patch<br/>Bitcoin Core patch"]
  node_bitcoin_driver["Bitcoin spend driver<br/>Python experiment driver<br/>[btc_las_spend.py]"]
  node_evm_verifier["EVM LAS verifier<br/>Solidity contract<br/>[LASVerifier.sol]"]
  node_evm_swap["EVM adaptor swap<br/>Solidity contract<br/>[AdaptorSwap.sol]"]
  node_evm_driver["EVM two-leg runner<br/>Foundry script<br/>[TwoLeg.s.sol]"]
end

subgraph group_evidence["Evidence and report"]
  node_bench["Benchmark runner<br/>experiment runner"]
  node_evidence[("Timestamped evidence<br/>immutable run outputs")]
  node_report_data["Report data generator<br/>Python data pipeline<br/>[gen_report_data.py]"]
  node_report["Final research report<br/>LaTeX report<br/>[report.tex]"]
end

node_c_build -->|"builds"| node_c_protocol
node_c_protocol -->|"constructs relations"| node_c_relation
node_c_protocol -->|"uses"| node_c_arithmetic
node_c_protocol -->|"validated by"| node_c_kat
node_c_protocol -->|"supplies witness relation"| node_c_zk
node_c_zk -->|"exercised by"| node_c_swap_test
node_c_protocol -.->|"wire-compatible mirror"| node_rust_las
node_rust_las -->|"exports"| node_rust_las_logic
node_rust_las -->|"validated by"| node_rust_kat
node_c_kat -.->|"cross-language gate"| node_rust_kat
node_rust_las -->|"LAS backend"| node_rust_swap
node_c_relation -.->|"proves equivalent relations"| node_stark
node_stark -->|"drives"| node_stark_prove
node_c_protocol -.->|"verification semantics"| node_bitcoin
node_bitcoin -.->|"informs"| node_bitcoin_patch
node_bitcoin_patch -->|"used in regtest experiments"| node_bitcoin_driver
node_c_protocol -.->|"verification semantics"| node_evm_verifier
node_evm_verifier -->|"verifies claims"| node_evm_swap
node_evm_swap -->|"executed by"| node_evm_driver
node_c_kat -->|"correctness gate"| node_bench
node_rust_kat -.->|"interoperability gate"| node_bench
node_bench -->|"writes measurements"| node_evidence
node_bitcoin_driver -->|"records regtest outcomes"| node_evidence
node_evm_driver -->|"records receipts and calldata"| node_evidence
node_evidence -->|"transforms"| node_report_data
node_report_data -->|"generates tables and macros"| node_report

click node_c_build "https://github.com/roycesteven/dilithium-msc-project/blob/main/ref/Makefile"
click node_c_protocol "https://github.com/roycesteven/dilithium-msc-project/blob/main/ref/las.c"
click node_c_relation "https://github.com/roycesteven/dilithium-msc-project/blob/main/ref/relation.c"
click node_c_arithmetic "https://github.com/roycesteven/dilithium-msc-project/blob/main/ref/poly.c"
click node_c_kat "https://github.com/roycesteven/dilithium-msc-project/blob/main/ref/test/test_kat.c"
click node_c_zk "https://github.com/roycesteven/dilithium-msc-project/blob/main/ref/relation_zk.c"
click node_c_swap_test "https://github.com/roycesteven/dilithium-msc-project/blob/main/ref/test/test_swap.c"
click node_rust_las "https://github.com/roycesteven/dilithium-msc-project/blob/main/rust/fips204-las/src/lib.rs"
click node_rust_las_logic "https://github.com/roycesteven/dilithium-msc-project/blob/main/rust/fips204-las/src/las.rs"
click node_rust_kat "https://github.com/roycesteven/dilithium-msc-project/blob/main/rust/fips204-las/tests/las_kat.rs"
click node_rust_swap "https://github.com/roycesteven/dilithium-msc-project/blob/main/rust/las-swap/src/protocol.rs"
click node_stark "https://github.com/roycesteven/dilithium-msc-project/blob/main/rust/las-stark/src/prover.rs"
click node_stark_prove "https://github.com/roycesteven/dilithium-msc-project/blob/main/rust/las-stark/src/bin/prove_relation.rs"
click node_bitcoin "https://github.com/roycesteven/dilithium-msc-project/blob/main/bitcoin/las_consensus/las_consensus.c"
click node_bitcoin_patch "https://github.com/roycesteven/dilithium-msc-project/blob/main/bitcoin/patches/0001-op-checklassigverify-v31.1.patch"
click node_bitcoin_driver "https://github.com/roycesteven/dilithium-msc-project/blob/main/bitcoin/tools/btc_las_spend.py"
click node_evm_verifier "https://github.com/roycesteven/dilithium-msc-project/blob/main/evm/src/LASVerifier.sol"
click node_evm_swap "https://github.com/roycesteven/dilithium-msc-project/blob/main/evm/src/AdaptorSwap.sol"
click node_evm_driver "https://github.com/roycesteven/dilithium-msc-project/blob/main/evm/script/TwoLeg.s.sol"
click node_bench "https://github.com/roycesteven/dilithium-msc-project/blob/main/scripts/run_benchmark_suite.sh"
click node_report_data "https://github.com/roycesteven/dilithium-msc-project/blob/main/scripts/gen_report_data.py"
click node_report "https://github.com/roycesteven/dilithium-msc-project/blob/main/report/latex/report.tex"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_c_build,node_c_protocol,node_c_relation,node_c_arithmetic,node_c_kat,node_c_zk,node_c_swap_test toneBlue
class node_rust_las,node_rust_las_logic,node_rust_kat,node_rust_swap,node_stark,node_stark_prove toneAmber
class node_bitcoin,node_bitcoin_patch,node_bitcoin_driver,node_evm_verifier,node_evm_swap,node_evm_driver toneMint
class node_bench,node_evidence,node_report_data,node_report toneRose
```

## Components

### C reference stack

- [C build](https://github.com/roycesteven/dilithium-msc-project/blob/main/ref/Makefile): build entry point · `ref/Makefile`
- [LAS protocol core](https://github.com/roycesteven/dilithium-msc-project/blob/main/ref/las.c): C protocol · Parameters, relations, base signatures, adaptor operations, and encoding. · `ref/las.c`
- [Relation construction](https://github.com/roycesteven/dilithium-msc-project/blob/main/ref/relation.c): C relation module · `ref/relation.c`
- [Dilithium arithmetic](https://github.com/roycesteven/dilithium-msc-project/blob/main/ref/poly.c): crypto substrate · Polynomial, NTT, and SHAKE primitives. · `ref/poly.c`
- [C known-answer gate](https://github.com/roycesteven/dilithium-msc-project/blob/main/ref/test/test_kat.c): C test · `ref/test/test_kat.c`
- [Relation proof layer](https://github.com/roycesteven/dilithium-msc-project/blob/main/ref/relation_zk.c): C ZK proof · Optional witness proofs with a LaZer backend. · `ref/relation_zk.c`
- [C atomic-swap test](https://github.com/roycesteven/dilithium-msc-project/blob/main/ref/test/test_swap.c): C test · `ref/test/test_swap.c`

### Rust implementations

- [Rust LAS library](https://github.com/roycesteven/dilithium-msc-project/blob/main/rust/fips204-las/src/lib.rs): Rust crate · Byte-identical mirror of the C protocol surface. · `rust/fips204-las/src/lib.rs`
- [Rust adaptor logic](https://github.com/roycesteven/dilithium-msc-project/blob/main/rust/fips204-las/src/las.rs): Rust LAS module · `rust/fips204-las/src/las.rs`
- [Rust known-answer gate](https://github.com/roycesteven/dilithium-msc-project/blob/main/rust/fips204-las/tests/las_kat.rs): Rust integration test · `rust/fips204-las/tests/las_kat.rs`
- [Swap orchestration](https://github.com/roycesteven/dilithium-msc-project/blob/main/rust/las-swap/src/protocol.rs): Rust swap crate · Models UTXOs and interchangeable LAS/ECDSA swap backends. · `rust/las-swap/src/protocol.rs`
- [STARK research branch](https://github.com/roycesteven/dilithium-msc-project/blob/main/rust/las-stark/src/prover.rs): Rust proving system · Independent LAS relation proving and verification path. · `rust/las-stark/src/prover.rs`
- [STARK proof CLI](https://github.com/roycesteven/dilithium-msc-project/blob/main/rust/las-stark/src/bin/prove_relation.rs): Rust CLI · `rust/las-stark/src/bin/prove_relation.rs`

### Blockchain integrations

- [Bitcoin LAS verifier](https://github.com/roycesteven/dilithium-msc-project/blob/main/bitcoin/las_consensus/las_consensus.c): C consensus tool · Standalone consensus-oriented verifier and transaction tool. · `bitcoin/las_consensus/las_consensus.c`
- [Bitcoin Script patch](https://github.com/roycesteven/dilithium-msc-project/blob/main/bitcoin/patches/0001-op-checklassigverify-v31.1.patch): Bitcoin Core patch · Adds LAS verification semantics to Script. · `bitcoin/patches/0001-op-checklassigverify-v31.1.patch`
- [Bitcoin spend driver](https://github.com/roycesteven/dilithium-msc-project/blob/main/bitcoin/tools/btc_las_spend.py): Python experiment driver · `bitcoin/tools/btc_las_spend.py`
- [EVM LAS verifier](https://github.com/roycesteven/dilithium-msc-project/blob/main/evm/src/LASVerifier.sol): Solidity contract · `evm/src/LASVerifier.sol`
- [EVM adaptor swap](https://github.com/roycesteven/dilithium-msc-project/blob/main/evm/src/AdaptorSwap.sol): Solidity contract · Swap and bound-claim state management. · `evm/src/AdaptorSwap.sol`
- [EVM two-leg runner](https://github.com/roycesteven/dilithium-msc-project/blob/main/evm/script/TwoLeg.s.sol): Foundry script · `evm/script/TwoLeg.s.sol`

### Evidence and report

- [Benchmark runner](https://github.com/roycesteven/dilithium-msc-project/blob/main/scripts/run_benchmark_suite.sh): experiment runner · Runs correctness-gated C measurements. · `scripts/run_benchmark_suite.sh`
- **Timestamped evidence**: immutable run outputs · Includes local benchmarks and chain experiment outcomes.
- [Report data generator](https://github.com/roycesteven/dilithium-msc-project/blob/main/scripts/gen_report_data.py): Python data pipeline · `scripts/gen_report_data.py`
- [Final research report](https://github.com/roycesteven/dilithium-msc-project/blob/main/report/latex/report.tex): LaTeX report · `report/latex/report.tex`

## Connections

- C build → LAS protocol core: builds
- LAS protocol core → Relation construction: constructs relations
- LAS protocol core → Dilithium arithmetic: uses
- LAS protocol core → C known-answer gate: validated by
- LAS protocol core → Relation proof layer: supplies witness relation
- Relation proof layer → C atomic-swap test: exercised by
- LAS protocol core → Rust LAS library: wire-compatible mirror
- Rust LAS library → Rust adaptor logic: exports
- Rust LAS library → Rust known-answer gate: validated by
- C known-answer gate → Rust known-answer gate: cross-language gate
- Rust LAS library → Swap orchestration: LAS backend
- Relation construction → STARK research branch: proves equivalent relations
- STARK research branch → STARK proof CLI: drives
- LAS protocol core → Bitcoin LAS verifier: verification semantics
- Bitcoin LAS verifier → Bitcoin Script patch: informs
- Bitcoin Script patch → Bitcoin spend driver: used in regtest experiments
- LAS protocol core → EVM LAS verifier: verification semantics
- EVM LAS verifier → EVM adaptor swap: verifies claims
- EVM adaptor swap → EVM two-leg runner: executed by
- C known-answer gate → Benchmark runner: correctness gate
- Rust known-answer gate → Benchmark runner: interoperability gate
- Benchmark runner → Timestamped evidence: writes measurements
- Bitcoin spend driver → Timestamped evidence: records regtest outcomes
- EVM two-leg runner → Timestamped evidence: records receipts and calldata
- Timestamped evidence → Report data generator: transforms
- Report data generator → Final research report: generates tables and macros
