Skip to content

Fix input validation and token selection bugs#4

Merged
nisfeb merged 3 commits into
masterfrom
feature/ecash
Mar 13, 2026
Merged

Fix input validation and token selection bugs#4
nisfeb merged 3 commits into
masterfrom
feature/ecash

Conversation

@nisfeb
Copy link
Copy Markdown
Contributor

@nisfeb nisfeb commented Mar 13, 2026

Summary

Follow-up bugfixes from code review of #3.

  • Token selection: replaced greedy algorithm with recursive subset search — greedy missed valid combos (e.g. [60,50]=110 when [70] was tried first)
  • Input validation: slaw instead of slav for ship name parsing prevents agent crash on malformed @p; parse-ud validates digits before converting amounts
  • Array bounds: guard snag on mint keyset arrays with ?~ check
  • Race condition: verify-status no longer deletes entries on first read
  • Copy fix: landing page now says tokens are "included" not "encrypted"

Test plan

  • Verify ban/unban with malformed ship name returns redirect, not crash
  • Verify sats-per-pr rejects non-numeric input
  • Verify token selection finds [60,50] when [70,60,50] available and target is 100

🤖 Generated with Claude Code

nisfeb and others added 2 commits March 13, 2026 14:51
- select-proofs: replace greedy algorithm with recursive subset search
  that correctly finds optimal selections within the 110% budget
  (greedy missed valid combos like [60,50] when [70] was tried first)
- Use slaw instead of slav for ship name parsing in ban/unban forms
  and verify-commit (prevents agent crash on malformed @p input)
- Add parse-ud helper that validates all chars are digits before
  parsing, preventing garbage values from non-numeric input in
  sats-per-pr price and load-sats amount fields
- Guard snag on keysets arrays with ?~ check to prevent crash on
  empty array from mint API response
- Remove auto-deletion of completed verify entries on first poll
  to prevent race condition where second request gets "unknown"

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown

Groundwire Verification Failed

This PR will not be reviewed because commits are not signed by a recognized Groundwire ID.

UNREACHABLE 7d720687
UNREACHABLE 4d33d720

Why?

This repository requires contributors to prove ownership of an onchain Groundwire identity.
Commit signatures are cryptographically verified against the signer's on-chain networking key.

How to fix this

  1. Get a Groundwire IDgroundwire.network/get-started
  2. Install commit signing./hooks/install.sh <your-ship-url>
  3. Re-sign your commitsgit rebase --exec "true" HEAD~N (after configuring signing)

This repository is protected by Groundwire for GitHub.

Tokens in the signature block are now encrypted so adversarial users
can't read commit data and steal ecash proofs.

Encryption flow:
- Hook passes maintainer's ecash pubkey to /sign via ecash_pubkey field
- Agent generates ephemeral Curve25519 keypair
- DH shared secret via shar:ed:crypto(maintainer_pub, ephemeral_sec)
- Keystream derived from SHA-256 counter mode on the shared secret
- Token JSON XOR'd with keystream
- Response includes ecash_ciphertext + ecash_ephemeral_pubkey (hex)

Decryption (verify-commit):
- Maintainer computes same shared secret: shar:ed:crypto(eph_pub, own_sec)
- Same keystream derivation, XOR to recover plaintext
- Parsed tokens then proceed through NUT-03 swap verification

Agent changes:
- ecash-encrypt/ecash-decrypt/stream-bytes helper arms
- parse-token-list extracted as reusable helper
- /sign: encrypts when ecash_pubkey provided, plaintext fallback
- /verify-commit: tries encrypted path first, falls back to plaintext

Hook changes:
- Passes ecash_pubkey in sign request payload
- Handles ecash_ciphertext + ecash_ephemeral_pubkey in response
- Signature block uses ecash-ciphertext/ecash-ephemeral-pubkey fields

Workflow changes:
- Extracts ecash-ciphertext/ecash-ephemeral-pubkey from signature block
- Forwards encrypted fields to verify-commit endpoint

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@nisfeb nisfeb merged commit 442353b into master Mar 13, 2026
1 check passed
@nisfeb nisfeb deleted the feature/ecash branch March 13, 2026 19:12
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.

1 participant