Commit graph

92 commits

Author SHA1 Message Date
Claude
37a70c0ff1
feat(chain): add sparse chain history builder for P2P sync
Implements get_short_chain_history() algorithm: recent 10 block hashes
then exponentially-spaced hashes back to genesis.

Co-Authored-By: Charon <charon@lethean.io>
2026-02-21 20:56:41 +00:00
Claude
3fe8dec1a4
feat(p2p): add RequestGetObjects and ResponseGetObjects types
Encode/decode for NOTIFY_REQUEST_GET_OBJECTS (2003) and
NOTIFY_RESPONSE_GET_OBJECTS (2004), including BlockCompleteEntry
for block + transaction blob pairs.

Co-Authored-By: Charon <charon@lethean.io>
2026-02-21 20:54:14 +00:00
Claude
0e35c2996d
refactor(chain): extract processBlockBlobs for shared RPC/P2P use
The block processing logic is now in processBlockBlobs() which takes
raw wire bytes. The RPC processBlock() becomes a thin hex-decode
wrapper. The P2P sync path will call processBlockBlobs() directly.

Co-Authored-By: Charon <charon@lethean.io>
2026-02-21 20:50:36 +00:00
Claude
c395c2ff18
test(chain): add full sync-to-tip integration test
Syncs the entire testnet chain via RPC and verifies every block
decodes, validates, and stores correctly.

Co-Authored-By: Charon <charon@lethean.io>
2026-02-21 20:47:01 +00:00
Claude
53311b14d1
fix(chain): resolve missing block blobs from daemon RPC
The Zano daemon's get_blocks_details RPC does not populate the blob
field. This adds resolveBlockBlobs() which batch-fetches miner tx
blobs via /gettransactions and reconstructs block wire blobs from
the parsed header (object_in_json AGGREGATED section) and raw tx
bytes. Also fixes regular tx processing to skip the miner tx entry
that the daemon includes in transactions_details.

Co-Authored-By: Charon <charon@lethean.io>
2026-02-21 20:46:56 +00:00
Claude
ad4139c012
fix(chain): mark ZC input key images as spent during sync
TxInputZC (v2+) inputs have key images that must be tracked for
double-spend detection, same as TxInputToKey.

Co-Authored-By: Charon <charon@lethean.io>
2026-02-21 20:36:00 +00:00
Claude
c066f4ac92
feat(chain): add context cancellation and progress logging to Sync
Sync() now accepts context.Context for graceful shutdown. Logs progress
every 100 blocks.

Co-Authored-By: Charon <charon@lethean.io>
2026-02-21 20:33:08 +00:00
Claude
4bac1f6c04
feat(chain): add GetRingOutputs callback for signature verification
Implements consensus.RingOutputsFn by looking up output public keys from
the chain's global output index and transaction store. Wired into the
sync loop so VerifySignatures=true uses real crypto verification.

Co-Authored-By: Charon <charon@lethean.io>
2026-02-21 20:28:54 +00:00
Claude
2c6211d78e
feat(consensus): wire up NLSAG ring signature verification
Connect crypto.CheckRingSignature() to verifyV1Signatures() so
pre-HF4 transactions have their ring signatures cryptographically
verified when a RingOutputsFn callback is provided.

Co-Authored-By: Charon <charon@lethean.io>
2026-02-21 20:26:33 +00:00
Claude
ca3d8e04d1
docs: add block sync design and implementation plan
Three-part design: NLSAG signature verification, full RPC sync to tip,
and P2P block sync via REQUEST_CHAIN / REQUEST_GET_OBJECTS. 13-task
implementation plan with TDD steps.

Co-Authored-By: Charon <charon@lethean.io>
2026-02-21 20:21:14 +00:00
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