Commit graph

182 commits

Author SHA1 Message Date
Claude
8335b11a85
feat(wire): v2+ transaction serialisation with real testnet verification
Fix three bugs in the v2+ wire format and add complete variant tag handlers
for Zarcanum proof and signature structures. Verified byte-identical
round-trip against a real post-HF4 coinbase transaction from testnet block
101 (1323 bytes, tx hash 543bc3c2...3b61e0).

Bugs fixed:
- V2 suffix order was attachment+proofs, corrected to attachment+signatures+proofs
- TransactionHash was hashing full blob, corrected to prefix-only (matching C++)
- tagSignedParts was reading 4 fixed bytes, corrected to two varints

New: TxInputZC type, SignaturesRaw field, tagZarcanumTxDataV1 handler,
proof tags 46-48, signature tags 42-45, crypto blob readers for BPP/BPPE/
BGE/CLSAG GGX/GGXXG/aggregation proof/double Schnorr structures.

Co-Authored-By: Charon <charon@lethean.io>
2026-02-21 19:09:34 +00:00
Claude
dd04cc9dee
feat(crypto): wire BPP/BPPE/BGE proof verification with real testnet data
Add cn_bpp_verify for Bulletproofs++ (1 delta, bpp_crypto_trait_ZC_out)
used by zc_outs_range_proof in post-HF4 transactions. Distinguish from
cn_bppe_verify (2 deltas, bpp_crypto_trait_Zarcanum) used for Zarcanum
PoS proofs.

Key changes:
- Add deserialise_bpp() and cn_bpp_verify() to bridge.cpp
- Add VerifyBPP() Go wrapper in proof.go
- Wire BPPE and BGE stubs into real C++ verify functions
- Add try/catch to all proof verifiers (C++ throws on invalid points)
- Add nil/empty input guards to all Go proof functions
- Test with real BPP proof from testnet block 101 coinbase tx

The BPP proof from tx 543bc3c2... (first post-HF4 coinbase) verifies
successfully through the full CGo pipeline, confirming wire format
deserialisation matches the C++ daemon output.

Co-Authored-By: Charon <charon@lethean.io>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-21 18:37:08 +00:00
Claude
cef9a34bea
docs: Phase 8 mining complete
Co-Authored-By: Charon <charon@lethean.io>
2026-02-21 02:21:36 +00:00
Claude
f9ff8ad877
test(mining): integration test against C++ testnet daemon
Build-tagged //go:build integration. Fetches a real template,
decodes it, computes header mining hash.

Co-Authored-By: Charon <charon@lethean.io>
2026-02-21 02:20:05 +00:00
Claude
340aa99db6
test(mining): add CheckNonce and OnNewTemplate coverage
Brings mining/ package coverage from 78% to 86.6%.

Co-Authored-By: Charon <charon@lethean.io>
2026-02-21 02:19:05 +00:00
Claude
9bc3158384
test(mining): error handling for invalid difficulty, blob, and submit
Co-Authored-By: Charon <charon@lethean.io>
2026-02-21 02:16:32 +00:00
Claude
ad121a2dd4
test(mining): block submission and stats verification
Tests with difficulty=1 for guaranteed block finding. Verifies
OnBlockFound callback, submit count, hashrate > 0.

Co-Authored-By: Charon <charon@lethean.io>
2026-02-21 02:15:05 +00:00
Claude
538b7b2e02
feat(mining): mining loop with template fetch and nonce grinding
Start(ctx) blocks until cancelled. Polls daemon for new blocks,
decodes template, computes header hash once, grinds nonces with
RandomX, submits solutions.

Co-Authored-By: Charon <charon@lethean.io>
2026-02-21 02:11:25 +00:00
Claude
a5185cacf4
feat(mining): Config, Stats, and Miner struct
TemplateProvider interface for testability. Atomic stats for
lock-free reads from any goroutine.

Co-Authored-By: Charon <charon@lethean.io>
2026-02-21 02:07:05 +00:00
Claude
c6631e555b
feat(mining): header mining hash and nonce checking
Port of C++ get_block_header_mining_hash(). Computes BlockHashingBlob
with nonce=0, Keccak-256's it. CheckNonce wraps RandomX + difficulty.

Co-Authored-By: Charon <charon@lethean.io>
2026-02-21 02:04:33 +00:00
Claude
8735e535d5
feat(rpc): add GetBlockTemplate endpoint
Co-Authored-By: Charon <charon@lethean.io>
2026-02-21 02:01:12 +00:00
Claude
5624d33de4
docs: Phase 8 mining implementation plan
10 tasks: RPC addition, header hash, miner struct, mining loop,
submission tests, error handling, integration test, docs.

Co-Authored-By: Charon <charon@lethean.io>
2026-02-21 01:56:36 +00:00
Claude
d41be2d12e
docs: Phase 8 mining design
Solo PoW miner against C++ daemon via JSON-RPC. Single-threaded
RandomX nonce grinding with daemon-provided block templates.

Co-Authored-By: Charon <charon@lethean.io>
2026-02-21 01:53:12 +00:00
Claude
153fc6a3e0
docs: Phase 7 consensus rules complete
Add integration test, update architecture docs with consensus/ package
description, record Phase 7 in project history.

Co-Authored-By: Charon <charon@lethean.io>
2026-02-21 01:14:41 +00:00
Claude
112da0e123
feat(chain): integrate consensus validation into sync
Add SyncOptions with VerifySignatures flag and hardfork schedule.
ValidateMinerTx and ValidateTransaction called during block processing.

Co-Authored-By: Charon <charon@lethean.io>
2026-02-21 01:11:33 +00:00
Claude
940155e822
feat(consensus): signature verification scaffold
VerifyTransactionSignatures with structural checks for v1 NLSAG and
v2+ CLSAG. Crypto bridge calls marked as TODO for wiring.

Co-Authored-By: Charon <charon@lethean.io>
2026-02-21 01:04:59 +00:00
Claude
c2888c487b
feat(consensus): PoW difficulty check with RandomX
CheckDifficulty compares a 256-bit LE hash against a difficulty target.
CheckPoWHash computes RandomX hash and checks against difficulty.

Co-Authored-By: Charon <charon@lethean.io>
2026-02-21 01:04:16 +00:00
Claude
4fe3fdfbd2
feat(crypto): RandomX PoW hash via CGo bridge
Vendor RandomX source, add bridge_randomx_hash() with static
VM lifecycle. Key: LetheanRandomXv1. Input: header_hash || nonce.

Co-Authored-By: Charon <charon@lethean.io>
2026-02-21 01:01:23 +00:00
Claude
7abac5e011
feat(consensus): full block validation orchestrator
ValidateBlock combines timestamp, miner tx, and reward checks into
a single entry point for block-level consensus validation.

Co-Authored-By: Charon <charon@lethean.io>
2026-02-21 00:53:51 +00:00
Claude
83a715cdb8
feat(consensus): block reward validation
ValidateBlockReward checks miner tx output sum against expected reward
with size penalty and hardfork-aware fee treatment.

Co-Authored-By: Charon <charon@lethean.io>
2026-02-21 00:52:55 +00:00
Claude
3ee066e233
feat(consensus): miner transaction validation
ValidateMinerTx checks genesis input height, input count (1 for PoW,
2 for PoS), and stake input type per hardfork version.

Co-Authored-By: Charon <charon@lethean.io>
2026-02-21 00:51:56 +00:00
Claude
b3f33f5265
feat(consensus): block timestamp validation
CheckTimestamp enforces future time limits (7200s PoW, 1200s PoS)
and median-of-last-60 timestamp ordering.

Co-Authored-By: Charon <charon@lethean.io>
2026-02-21 00:50:39 +00:00
Claude
e2068338a5
feat(consensus): transaction semantic validation
Eight checks matching C++ validate_tx_semantic(): blob size, input
count, input types, output validation, overflow, key image uniqueness,
and pre-HF4 balance. Hardfork-aware for HF4+ Zarcanum types.

Co-Authored-By: Charon <charon@lethean.io>
2026-02-21 00:47:43 +00:00
Claude
7ac618d339
feat(consensus): fee extraction with overflow checks
TxFee calculates pre-HF4 fees as sum(inputs) - sum(outputs) with
overflow detection. Coinbase transactions return zero fee.

Co-Authored-By: Charon <charon@lethean.io>
2026-02-21 00:45:01 +00:00
Claude
cf20259e96
feat(consensus): block reward with size penalty
BaseReward returns premine at genesis, fixed 1 LTHN otherwise.
BlockReward applies the C++ size penalty using 128-bit arithmetic.
MinerReward handles pre/post HF4 fee treatment.

Co-Authored-By: Charon <charon@lethean.io>
2026-02-21 00:42:46 +00:00
Claude
fa1c127e12
feat(consensus): scaffold package with error types
Add consensus/ package with doc.go and sentinel error types for all
validation failures. Add MaxTransactionBlobSize constant to config.

Co-Authored-By: Charon <charon@lethean.io>
2026-02-21 00:39:41 +00:00
Claude
bd8a42562a
docs: Phase 7 consensus rules implementation plan
13-task TDD plan covering block reward, fee extraction, transaction
semantic validation, block validation, PoW verification, signature
verification, and chain sync integration.

Co-Authored-By: Charon <charon@lethean.io>
2026-02-21 00:35:03 +00:00
Claude
eb039fea38
docs: Phase 7 consensus rules design
Layered validation architecture (structural, economic, cryptographic)
in a standalone consensus/ package. Full hardfork coverage (HF0-HF6),
PoW via CGo bridge, optional signature verification during sync.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-21 00:26:58 +00:00
Claude
459ff80f1f
docs: Phase 6 wallet core documentation and integration test
Co-Authored-By: Charon <charon@lethean.io>
2026-02-20 23:32:07 +00:00
Claude
11b50d0491
feat(wallet): orchestrator with sync, balance, and send
Co-Authored-By: Charon <charon@lethean.io>
2026-02-20 23:29:42 +00:00
Claude
b8841a1a3b
feat(wallet): V1Builder for transaction construction with ring signatures
Builder interface with V1Builder that constructs signed v1 transactions.
Handles change outputs, ECDH output key derivation, ring construction
with sorted global indices, and NLSAG signing per input.

Co-Authored-By: Charon <charon@lethean.io>
2026-02-20 23:23:33 +00:00
Claude
7e31e706c5
feat(wallet): RPCRingSelector for decoy output selection
RingSelector interface with RPCRingSelector that fetches random outputs
from the daemon, excludes the real output and duplicates, and returns
the requested ring size.

Co-Authored-By: Charon <charon@lethean.io>
2026-02-20 23:20:15 +00:00
Claude
359952075a
feat(wallet): V1Scanner with ECDH output detection
Scanner interface with V1Scanner implementation for v0/v1 transactions.
Derives ephemeral keys via ECDH, generates key images, and tracks
coinbase status and unlock times.

Co-Authored-By: Charon <charon@lethean.io>
2026-02-20 23:17:22 +00:00
Claude
f66ef2e61d
feat(wallet): account key management with Argon2id encryption
GenerateAccount, RestoreFromSeed, RestoreViewOnly with deterministic
view key derivation (sc_reduce32(Keccak256(spend_secret))), matching
C++ account_base::generate(). Encrypted persistence via Argon2id
(time=3, mem=64MB) + AES-256-GCM in go-store.

Adds cn_sc_reduce32 to the CGo bridge for scalar reduction mod l,
required to convert a hash output into a valid Ed25519 secret key.

Co-Authored-By: Charon <charon@lethean.io>
2026-02-20 23:14:17 +00:00
Claude
ff97d51550
feat(wallet): NLSAGSigner with ring signature interface
Signer interface abstracts signature generation for v1/v2+ extensibility.
NLSAGSigner wraps the CGo ring signature functions for v0/v1 transactions.

Co-Authored-By: Charon <charon@lethean.io>
2026-02-20 23:08:50 +00:00
Claude
3a5db81e13
feat(rpc): add GetRandomOutputs and SendRawTransaction endpoints
GetRandomOutputs wraps /getrandom_outs1 for ring selection decoys.
SendRawTransaction wraps /sendrawtransaction for tx submission.

Co-Authored-By: Charon <charon@lethean.io>
2026-02-20 23:07:00 +00:00
Claude
b7349a054d
feat(wallet): transfer type and go-store persistence
Transfer struct tracks owned outputs with key image, amount, block height,
and spend status. Storage helpers use go-store JSON serialisation keyed by
key image hex. IsSpendable checks coinbase maturity and unlock time.

Co-Authored-By: Charon <charon@lethean.io>
2026-02-20 23:05:08 +00:00
Claude
ee257baa83
feat(wallet): TX extra parsing for wallet-critical tags
Parses tags 22 (tx public key), 14 (unlock time), and 11 (derivation
hint) from raw extra bytes. Unknown tags are skipped. Raw bytes preserved
for round-tripping.

Adds PublicKey.IsZero() to types package.

Co-Authored-By: Charon <charon@lethean.io>
2026-02-20 23:02:13 +00:00
Claude
5b677d1f36
feat(wallet): mnemonic seed encode/decode with Electrum wordlist
24-word Electrum encoding (4 bytes → 3 words × 8 groups) plus CRC32
checksum word. 1626-word dictionary extracted from C++ source.

Co-Authored-By: Charon <charon@lethean.io>
2026-02-20 22:59:16 +00:00
Claude
b506c9c0a1
docs: Phase 6 wallet core implementation plan
11 tasks covering mnemonic seeds, TX extra parsing, account management,
transfer storage, scanning, signing, ring selection, tx building, and
wallet orchestration. TDD with complete code for every step.

Co-Authored-By: Charon <charon@lethean.io>
2026-02-20 22:51:19 +00:00
Claude
4a07e6ca70
docs: Phase 6 wallet core design
Interface-driven wallet with Scanner, Signer, Builder, RingSelector
abstractions. v1 NLSAG ships first, v2+ Zarcanum architecture ready.
Full send+receive: key management, output scanning, tx construction,
ring selection via RPC, encrypted key storage in go-store.

Co-Authored-By: Charon <charon@lethean.io>
2026-02-20 22:29:01 +00:00
Claude
28e3da63cb
test(chain): boost coverage to >80% with multi-block sync and error paths
Add comprehensive tests exercising regular transaction processing through
the sync pipeline (key image marking, output indexing, cumulative
difficulty) and not-found error paths for all query methods. Coverage
rises from 65.8% to 80.1%.

Co-Authored-By: Charon <charon@lethean.io>
2026-02-20 22:02:10 +00:00
Claude
c2e6b165e7
docs: Phase 5 chain storage and sync client documentation
Co-Authored-By: Charon <charon@lethean.io>
2026-02-20 21:56:05 +00:00
Claude
ef4edd669a
test(chain): integration test syncing first 10 blocks from testnet
Co-Authored-By: Charon <charon@lethean.io>
2026-02-20 21:55:19 +00:00
Claude
23d337e397
feat(chain): RPC sync loop with block processing and indexing
Co-Authored-By: Charon <charon@lethean.io>
2026-02-20 21:53:49 +00:00
Claude
f5822e7222
feat(chain): block header validation (linkage, height, size)
Co-Authored-By: Charon <charon@lethean.io>
2026-02-20 21:50:12 +00:00
Claude
89f5f0ebdf
feat(chain): transaction, key image, and output index operations
Co-Authored-By: Charon <charon@lethean.io>
2026-02-20 21:49:15 +00:00
Claude
d5976d33c3
feat(chain): Chain struct with block storage and retrieval
Co-Authored-By: Charon <charon@lethean.io>
2026-02-20 21:44:57 +00:00
Claude
8cb5cb4ad2
feat(chain): go-store dependency and metadata types
Co-Authored-By: Charon <charon@lethean.io>
2026-02-20 21:42:22 +00:00
Claude
46cf1a747a
docs: Phase 5 chain storage implementation plan
7-task plan covering chain/ package: meta types, block storage,
transaction/output indexing, header validation, sync loop,
integration test, and documentation updates.

Co-Authored-By: Charon <charon@lethean.io>
2026-02-20 21:37:27 +00:00