Skip to content

chore: add NUT spec quotes (greatspectations Layer 1) - #327

Merged
c03rad0r merged 5 commits into
OpenTollGate:mainfrom
Amperstrand:chore/nut-spec-quotes
Aug 19, 2026
Merged

c03rad0r merged 5 commits into
OpenTollGate:mainfrom
Amperstrand:chore/nut-spec-quotes

Conversation

@Amperstrand

Copy link
Copy Markdown
Collaborator

What

Adds verbatim NUT specification quotes as comments at key Cashu code locations, enabling CI-enforced spec drift detection via greatspectations.

Quotes Added

NUT Quote Location Spec Text
NUT-00 main.go above extractCashuToken Token format prefix: cashu[version][token]
NUT-00 tollwallet.go above Receive Verification: k*hash_to_curve(x) == C
NUT-05 tollwallet.go above Send Melt quote: POST /v1/melt/quote/{method}

Config

specquotes.toml configured for greatspectations:

[sources.NUT]
format = "markdown"
dir = "nuts"
pattern = "{id:02d}.md"

Context

Part of the cashu-audit framework — Layer 1 adoption. The gonuts-tollgate library already has 85 spec quotes. This adds TollGate's own Cashu handling code to the same framework.

Verification

  • go build passes
  • gofmt clean
  • Comments only, no code changes

@Amperstrand

Copy link
Copy Markdown
Collaborator Author

Local test evidence

Method: Built from PR branch, tested against mock Cashu mint + Go backend via scripts/local-test.sh (9 API payment scenarios).

Results:

  • Build: OK
  • API tests: 9/9 passed, 0 failed, 0 errors
  • Merge conflicts with main: 0
  • CI checks: All green

Ready for review.

@felixfelix-bot felixfelix-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All three quotes verified verbatim against cashubtc/nuts main (NUT-00 token format, NUT-00 verification, NUT-05 melt-quote). One placement question and one process note:

  1. The NUT-05 melt-quote comment sits above TollWallet.Send(). Melt (NUT-05) is the Lightning-payment path. If Send() is doing a P2PK transfer via swap, the relevant spec is NUT-03, not NUT-05. Can you confirm Send() actually drives a melt? If so, a one-line comment in the function body pointing at the melt call site would make the connection obvious.

  2. The config is only useful if something runs it. The header documents a manual spectate check invocation, but there's no Makefile target or CI step. Suggest adding at minimum a make speccheck target so it's discoverable, even if CI is added separately.

@Amperstrand

Copy link
Copy Markdown
Collaborator Author

Re-tested against latest main (Jul 29)

Amperstrand pushed a commit that referenced this pull request Jul 29, 2026
felixfelix-bot feedback: NUT-05 (melt) quote was above Send(), but
Send() does a NUT-03 swap, not a melt. Moved NUT-05 quote above
MeltToLightning() which is the actual melt path. Added NUT-03
quote above Send() to match the swap operation.
@Amperstrand

Copy link
Copy Markdown
Collaborator Author

Re: NUT-05 quote placement — fixed

You were correct: Send() does a NUT-03 swap (splits proofs, requests new signatures), not a NUT-05 melt.

Fixed:

  • Moved NUT-05 quote from above Send() to above MeltToLightning() (the actual melt path)
  • Added NUT-03 quote above Send() to match the swap operation
// NUT #03: Alice requests swapping proofs she holds for new proofs...
func (w *TollWallet) Send(...) {

// NUT #05: To request a melt quote, the wallet of Alice makes a POST /v1/melt/quote/{method}...
func (w *TollWallet) MeltToLightning(...) {

Pushed.

@Amperstrand
Amperstrand marked this pull request as draft July 29, 2026 12:00
@Amperstrand

Copy link
Copy Markdown
Collaborator Author

felixfelix-bot feedback

1. Send() / NUT-05 question:

TollWallet.Send() calls w.wallet.Send() which is gonuts' swap path (NUT-03), NOT a melt (NUT-05). The NUT-05 spec quote above Send() is indeed misplaced — it should be NUT-03. Will fix the comment placement.

2. make speccheck target:

Not yet added. Will add in a follow-up commit:

speccheck:
	@greatspectations check .

Amperstrand pushed a commit to Amperstrand/tollgate-module-basic-go that referenced this pull request Jul 29, 2026
Adds make/speccheck.sh for local greatspectations spec checking.
Adds docs/ai-audit/ with three AI audit prompt templates:
- nut-compliance.md, security.md, dependency-drift.md

Addresses felixfelix-bot review feedback requesting discoverability.

Note: CI workflow changes (.github/workflows/test.yml) require workflow
scope to push. Suggested additions documented in PR OpenTollGate#327 description.
Amperstrand pushed a commit that referenced this pull request Jul 29, 2026
Requested by @felixfelix-bot — makes the greatspectations check
discoverable via standard make target.
@Amperstrand

Copy link
Copy Markdown
Collaborator Author

felixfelix-bot feedback — both items addressed

1. Send() / NUT-05 → NUT-03: The NUT-05 quote was moved to MeltToLightning and NUT-03 quote placed above Send() (already done in commit on branch).

2. make speccheck target: Added to Makefile:

speccheck:
	@greatspectations check .

@felixfelix-bot — ready for re-review.

@Amperstrand

Copy link
Copy Markdown
Collaborator Author

CI Integration (requires maintainer with workflow scope)

Added make/speccheck.sh and docs/ai-audit/ prompts. The CI workflow changes to .github/workflows/test.yml need to be pushed by someone with workflow scope.

Suggested additions to test.yml

  dep-sync:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v6
      - uses: actions/setup-go@v6
        with:
          go-version-file: src/go.mod
      - uses: actions/setup-python@v5
        with:
          python-version: "3.12"
      - name: Dependency sync check
        run: python3 tests/contract/check-deps-sync.py

  spec-drift:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v6
      - uses: actions/setup-python@v5
        with:
          python-version: "3.12"
      - name: Install greatspectations
        run: pip install git+https://github.com/rustyrussell/greatspectations.git
      - name: Clone NUT specs
        run: git clone --depth=1 https://github.com/cashubtc/nuts.git nuts
      - name: Check spec quotes
        run: spectate check --config specquotes.toml --comment-start '//' --comment-continue '//' "src/**/*.go"

Amperstrand pushed a commit to Amperstrand/tollgate-module-basic-go that referenced this pull request Jul 30, 2026
…03 above Send

felixfelix-bot feedback: NUT-05 (melt) quote was above Send(), but
Send() does a NUT-03 swap, not a melt. Moved NUT-05 quote above
MeltToLightning() which is the actual melt path. Added NUT-03
quote above Send() to match the swap operation.
Amperstrand pushed a commit to Amperstrand/tollgate-module-basic-go that referenced this pull request Jul 30, 2026
Adds make/speccheck.sh for local greatspectations spec checking.
Adds docs/ai-audit/ with three AI audit prompt templates:
- nut-compliance.md, security.md, dependency-drift.md

Addresses felixfelix-bot review feedback requesting discoverability.

Note: CI workflow changes (.github/workflows/test.yml) require workflow
scope to push. Suggested additions documented in PR OpenTollGate#327 description.
@Amperstrand
Amperstrand force-pushed the chore/nut-spec-quotes branch 2 times, most recently from 49c6eaa to 7b416cd Compare July 30, 2026 13:00
@Amperstrand
Amperstrand marked this pull request as ready for review July 30, 2026 13:00
@Amperstrand

Copy link
Copy Markdown
Collaborator Author

greatspectations audit complete ✅

All 9 spec quotes verified against NUT specs. greatspectate check exits 0.

What was fixed

  • comment-start flag: // (with space) required by greatspectations
  • speccheck.sh: Fixed command name (greatspectate not spectate), proper file glob expansion
  • 6 quote texts: Updated to match NUT spec verbatim (NUT-00, 03, 04, 05)
  • Blank lines: Added between NUT quotes and docstrings to prevent continuation merging
  • gofmt: Fixed formatting on modified files

Coverage

NUT Quotes Location
NUT-00 3 main.go (token prefix, serialized tokens), tollwallet.go (verification), merchant.go (verification)
NUT-03 1 tollwallet.go (swap operation)
NUT-04 3 tollwallet.go (mint quote request, check state, mint execution)
NUT-05 1 tollwallet.go (melt quote)

Total: 9 verified spec quotes across 3 files.

How to run locally

make/speccheck.sh

Installs greatspectations, clones NUT specs, runs check + coverage report.

PR marked ready for review.

Amperstrand added 3 commits August 18, 2026 08:44
Adds verbatim NUT spec text as comments at key code locations:
- NUT #00: Token format prefix (cashu[version][token]) above extractCashuToken
- NUT #00: Verification flow above tollwallet.Receive
- NUT #5: Melt quote flow above tollwallet.Send

Adds specquotes.toml for greatspectations CI drift detection.
See: https://github.com/OpenTollGate/cashu-audit (Layer 1 framework)
…03 above Send

felixfelix-bot feedback: NUT-05 (melt) quote was above Send(), but
Send() does a NUT-03 swap, not a melt. Moved NUT-05 quote above
MeltToLightning() which is the actual melt path. Added NUT-03
quote above Send() to match the swap operation.
- Fixed comment-start: '// ' (with space) per greatspectations requirement
- Fixed speccheck.sh: correct command name + glob expansion
- Fixed 6 quote texts to match NUT spec verbatim
- Added blank lines between quotes and docstrings
- Added 5 new NUT quotes across main.go, tollwallet.go, merchant.go

All 9 quotes verified: greatspectate check exit 0.
@Amperstrand
Amperstrand force-pushed the chore/nut-spec-quotes branch from 7b416cd to 1240589 Compare August 18, 2026 06:45
@Amperstrand

Copy link
Copy Markdown
Collaborator Author

Cold-review items + rebuild: resolved, and the PR is now much smaller. Rebuilt from current main keeping only the quotes work — now +35/−2 across 5 files (specquotes.toml, in-code NUT quotes in main/merchant/tollwallet, nuts/ gitignore). Two things removed in the process:

  1. make/speccheck.sh + docs/ai-audit/ — this branch and feat: token recovery tool + AI audit prompts + speccheck #340 carried divergent copies (different command names: greatspectate here vs spectate there, different doc expansions). Tooling now lives only in feat: token recovery tool + AI audit prompts + speccheck #340, which has the corrected version (exit-0-on-drift fix, see that PR).
  2. The old branch predated feat(identity): unified NIP-06 + HKDF + RevealSeed (v2, rebased) #331's identity-module merge; the rebuild drops all of that stale merge-base noise.

Quote verification history is preserved (9/9 verified, NUT-05→MeltToLightning move from the July review round). CI green.

@felixfelix-bot felixfelix-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cold review — new findings only (3 issues previously raised, not repeated).

3 minor:

  1. NUT-03 quote in tollwallet.go:155 is truncated — drops the final sentence "These are then used by the wallet to generate new Proofs (see [NUT-00][00])." For a verbatim spec-quote tool, this is incomplete

  2. src/main.go has unrelated gofmt alignment changes (redirect_url/auth_delay field alignment) mixed into a spec-quote PR

  3. The NUT-00 verification quote is duplicated verbatim in both merchant.go:445 and tollwallet.go:119 — the greatspectations tool may flag duplicate quotes against the same spec section

All quotes verified accurate against NUT-00 through NUT-05 specs. No blockers — mergeable with follow-up if desired.

…only diff

- NUT-03 quote above TollWallet.Send gains the spec's final sentence
  ("These are then used by the wallet to generate new Proofs").
- The NUT-00 verification quote appeared verbatim above both
  Merchant.PurchaseSession and TollWallet.Receive; keeping the
  wallet-level one (verification is the mint-side swap check) and
  leaving a pointer at the merchant site — duplicate quotes against
  the same spec section flag in speccheck.
- Dropped the unrelated gofmt field-alignment change in main.go; the
  file now matches main byte-for-byte outside the quotes (main's
  existing gofmt dirt is OpenTollGate#341's scope).

Review findings: cold review 2026-08-18 (3 minors).
@Amperstrand

Copy link
Copy Markdown
Collaborator Author

Cold-review response — all 3 minors fixed in 3e20040 (CI green):

  1. NUT-03 quote completed with the spec's final sentence ("These are then used by the wallet to generate new Proofs (see [NUT-00][00])").
  2. The unrelated gofmt field-alignment hunks in main.go are dropped — main.go's diff is now quotes-only, byte-identical to main elsewhere (main's own gofmt dirt there is chore: gofmt cleanup — 16 files #341's scope).
  3. NUT-00 verification quote deduped: kept above TollWallet.Receive (verification is the mint-side swap check), pointer comment left at the PurchaseSession site so speccheck won't see duplicates.

@felixfelix-bot felixfelix-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed at 3e20040: NUT-03 quote completed, NUT-00 deduped (kept at Receive, pointer at PurchaseSession), gofmt hunks dropped — diff is quotes-only. All findings resolved. Good to merge.

@c03rad0r
c03rad0r self-requested a review August 19, 2026 13:02
@c03rad0r
c03rad0r merged commit 2702668 into OpenTollGate:main Aug 19, 2026
19 checks passed
Amperstrand pushed a commit that referenced this pull request Aug 21, 2026
Fresh gofmt pass over main after the #299/#312/#327/#342/#343/#348/
#349/#351 merge wave (the wave brought new unformatted code in its
wake — scanner.go struct alignment from #312, test files across
modules, config_schema.go).

Includes the validator.go import regrouping from the previous round
of this PR (7b124b0, originally Felix's fix): stdlib and third-party
groups separated with a blank line — that file came to main via #337
carrying the misgrouping.

Supersedes the pre-wave branch; rebuilt fresh from current main.
gofmt -l: clean across src/. Builds + tests green in touched modules
(wgm, tollgate_protocol); import-paths (117) and deps-sync (125)
contract checks pass.
Amperstrand pushed a commit that referenced this pull request Aug 21, 2026
…post-wave main)

Content-first rebuild after the merge wave made a straight rebase
impossible (the tool files historically rode inside an unrelated
'SSID comment' commit; skipping it during rebase deleted them —
same mislabeled-commit pathology this branch line had with the ELF
binary). Rebuilt directly from the reviewed tip's content (3ca91f5)
onto current main.

Carries both cold-review fix rounds: unspent-only recovery (PENDING
→ retry-later, never double-spend), single lazily-loaded wallet per
run, no proof secrets in output (also fixes the short-secret panic),
dry-run recoverables counted separately — and the 30s per-mint
checkstate timeout (a hung mint cannot stall recovery).

Tool builds + vets clean standalone; speccheck is the exit-0-on-drift
version and is functional now that specquotes.toml is on main (#327).
gitignore guard for the built binary included. CHANGELOG entry added.
No src/ changes — main's vendor_element_manager supersedes the old
branch copy.
felixfelix-bot pushed a commit to felixfelix-bot/tollgate-module-basic-go that referenced this pull request Sep 20, 2026
* chore: add NUT spec quotes (Layer 1 greatspectations adoption)

Adds verbatim NUT spec text as comments at key code locations:
- NUT #00: Token format prefix (cashu[version][token]) above extractCashuToken
- NUT #00: Verification flow above tollwallet.Receive
- NUT #5: Melt quote flow above tollwallet.Send

Adds specquotes.toml for greatspectations CI drift detection.
See: https://github.com/OpenTollGate/cashu-audit (Layer 1 framework)

* fix(OpenTollGate#327): move NUT-05 quote to MeltToLightning, add NUT-03 above Send

felixfelix-bot feedback: NUT-05 (melt) quote was above Send(), but
Send() does a NUT-03 swap, not a melt. Moved NUT-05 quote above
MeltToLightning() which is the actual melt path. Added NUT-03
quote above Send() to match the swap operation.

* fix: verify all spec quotes pass greatspectations

- Fixed comment-start: '// ' (with space) per greatspectations requirement
- Fixed speccheck.sh: correct command name + glob expansion
- Fixed 6 quote texts to match NUT spec verbatim
- Added blank lines between quotes and docstrings
- Added 5 new NUT quotes across main.go, tollwallet.go, merchant.go

All 9 quotes verified: greatspectate check exit 0.

* fix: spec-quote polish — complete NUT-03 quote, dedupe NUT-00, scope-only diff

- NUT-03 quote above TollWallet.Send gains the spec's final sentence
  ("These are then used by the wallet to generate new Proofs").
- The NUT-00 verification quote appeared verbatim above both
  Merchant.PurchaseSession and TollWallet.Receive; keeping the
  wallet-level one (verification is the mint-side swap check) and
  leaving a pointer at the merchant site — duplicate quotes against
  the same spec section flag in speccheck.
- Dropped the unrelated gofmt field-alignment change in main.go; the
  file now matches main byte-for-byte outside the quotes (main's
  existing gofmt dirt is OpenTollGate#341's scope).

Review findings: cold review 2026-08-18 (3 minors).

---------

Co-authored-by: Amperstrand <amperstrand@localhost>
Co-authored-by: amperstand <atlas@oh-my-opencode.com>
Co-authored-by: c03rad0r <1100745+c03rad0r@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants