Skip to content

Fix DirectedHamiltonianVerifier missing closing-edge check - #507

Open
Trosper3 wants to merge 1 commit into
CSharpAPIfrom
fix/directed-hamiltonian-verifier-closure
Open

Fix DirectedHamiltonianVerifier missing closing-edge check#507
Trosper3 wants to merge 1 commit into
CSharpAPIfrom
fix/directed-hamiltonian-verifier-closure

Conversation

@Trosper3

Copy link
Copy Markdown
Contributor

Summary

  • DirectedHamiltonianVerifier checked consecutive edges in a certificate but never required the walk to close back to its starting vertex — the loop was for (i = 0; i < order.Count - 1; i++), so the last listed node's closing edge back to the start was never checked. An off-by-one in the coverage check happened to mask this for exact-length certificates, but an (n+1)-length certificate that visits every node via valid edges without ever returning to the start was incorrectly accepted.
  • Note: the sibling undirected HamiltonianVerifier already had this exact bug fixed in b719fda ("Fix TSP and Hamiltonian verifiers missing closing-edge check") — only the directed verifier still had the hole, so this PR ports that same fix, adapted for directed edges (no reverse-edge fallback, since direction matters here).
  • Also removes an unused pairCheck2 variable left over from copying the undirected verifier (issue's "Bug 3").
  • The exploit was independently confirmed by extracting the original buggy logic into a scratch console app and running it against a constructed instance/certificate pair before writing the fix.

Closes #255

Test plan

  • dotnet test --filter "...DIRECTEDHAMILTONIAN_Tests" — 8/8 passed (new test file; no prior tests existed for this problem)
  • dotnet build --configuration Release (gates on dotnet format --verify-no-changes) — clean
  • dotnet test (full suite) — 906/906 passed

The verifier checked consecutive edges in a certificate but never
required the walk to close back to its starting vertex, and had an
off-by-one in its coverage check that happened to mask the gap for
exact-length certificates. Ports the closure fix already applied to
the undirected HamiltonianVerifier in b719fda, adapted for directed
edges (no reverse-edge fallback), and removes an unused pairCheck2
left over from that copy.
@github-actions

Copy link
Copy Markdown

Redux Build System — CI Report

dotnet · commit f3497ac

Operation Status Summary Time
audit no known vulnerabilities 4.0s
format-check all files formatted 19.8s
lint 0 issues 31.8s
typecheck ⏭️ covered by lint (dotnet build)
unit-test 906 passed · coverage 70% (min 80%) 40.4s
build built local/redux:ci · 234MB 35.9s
integration-test ⏭️ no [integration] command
push ⏭️ not implemented

Overall: ❌ 4 passed · 1 failed · 3 skipped

Trosper3 added a commit that referenced this pull request Sep 1, 2026
Superseded by the fix+test file already open in PR #507 (fixes the missing closing-edge check and adds fuller test coverage vs. this PR's 3-test format smoke check). Keeping the instanceFormat/certificateFormat declaration changes; only dropping the file that would otherwise collide on merge.
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.

Hamiltonian verifiers (undirected & directed) accept open paths as cycles — closing edge not checked

1 participant