# Reproduce the native PowLayer audit

The commands below use the package root as the current directory. The actual
run used macOS 15.5 arm64 and Apple clang 17 from Command Line Tools. Use
Python 3.10 or newer for the tool environment; this recipe uses Python 3.12.
Install Meson 1.12.0, Ninja
1.13.2 and clang-format 14.0.6 in a virtual environment or put equivalent
executables on PATH. The full project and the required submodules need
network access. Linux is not validated by this audit.

```sh
python3.12 -m venv .venv
.venv/bin/python -m pip install meson==1.12.0 ninja==1.13.2 clang-format==14.0.6
export PATH="$PWD/.venv/bin:$PATH"
mkdir -p work
git clone https://github.com/nntrainer/nntrainer.git work/nntrainer
git -C work/nntrainer checkout --detach a7ea056e79ab8e14447ea305c1b634e233343258
git -C work/nntrainer submodule update --init --depth 1 subprojects/googletest subprojects/iniparser
git -C work/nntrainer apply ../../evidence/tests.patch
python3 build.py baseline
python3 run_validation.py baseline affected
```

`build.py` configures the same CPU FP32 profile, disables BLAS and the thread
backend, sets one NNTrainer thread and uses `ninja -j1`. On Darwin it adds the
retained platform-include header and generated `malloc.h` shim; these do not
change the mathematical code. It builds the actual complete layer-test target.
It does not run the complete nntrainer project test suite.

`run_validation.py` obtains the real shared-library compile flags from Meson's
compilation database, compiles `evidence/pow_audit.cpp`, links it to that newly
built library, and executes it in fresh processes. It then executes all Pow
tests in `unittest_layers`. Recorded JSON and GoogleTest XML are written to
`evidence/`.

For the original source, the driver requires exactly 180 NaN coordinate
failures among 385 cases and exactly the two expected native test failures
among 25 tests. The driver's own successful exit means that the expected
defect was reproduced; it does not mean that the original library passed.
An exception, crash, missing test or unexpected failure fails the driver.

Apply and test the candidate:

```sh
git -C work/nntrainer apply ../../evidence/source.patch
python3 build.py candidate
python3 run_validation.py candidate corrected
```

Expected: 385/385 coordinate cases and 25/25 Pow tests pass. Three fresh
processes must agree. The finite-difference result and backward at zero are
both zero.

Run the restoration/mutation check:

```sh
python3 mutation_check.py
```

This temporarily restores the original PowLayer source, requires the same
failures to return, then restores and rebuilds the candidate and verifies the
corrected results again. Use an isolated checkout: this script intentionally
changes the one audited production file in `work/nntrainer`.

The archived `logs/`, JSON and XML files are the original recorded results.
Reproducing in place overwrites output files; use a fresh extracted copy if
you need to retain them. The full repository and compiled binaries are not
inside this evidence archive. Relevant original source files, exact commit
identifiers, patches, compiler commands and library hashes are included.
