7f01cafc62
Crypto Backend Refactoring
──────────────────────────
- Delete src/ed25519.js — all scalar/point operations now route through
the crypto provider (WASM/FFI/JSI backends only)
- Remove duplicate JS BigInt implementations of scReduce32, scReduce64,
scalarAdd, scalarMul from scanning.js, carrot.js, and carrot-scanning.js;
delegate to Rust backend via crypto/index.js
- Remove debug/test exports from index.js (randomPoint, testDouble,
getBasePoint, isOnCurve, etc.) that were only used during development
- Rebuild WASM binary (476KB → 487KB) with updated Rust crate
Consolidated CryptoNote Scanner (cn_scan)
─────────────────────────────────────────
- New Rust module crates/salvium-crypto/src/cn_scan.rs replaces 5-12
individual FFI round-trips per output with a single native call:
view tag check → derive subaddress pubkey → subaddress map lookup →
amount decryption → commitment mask → key image generation
- FFI wrapper salvium_cn_scan_output in ffi.rs + C header declaration
- FFI backend scanCnOutput() with full subaddress map marshaling
(32-byte key + u32 major/minor LE per entry) and JSON result parsing
- JSI backend delegation via this.native.cnScanOutput()
- wallet-sync.js _scanCNOutput() tries native path first when available
(FFI/JSI), falls through to existing JS pipeline for WASM/JS backends
- Change pub(crate) visibility on subaddress.rs cn_subaddress_secret_key
- 8 Rust unit tests covering view tag, amount, commitment mask,
subaddress matching, and key image generation
- Verified identical results: WASM (JS fallback) and FFI (native cn_scan)
produce same 964 outputs at same chain height; FFI is 3x faster sync
(0.8s vs 2.5s) with 12x less heap (12MB vs 150MB)
RCT Batch Signature Verification
─────────────────────────────────
- New Rust module crates/salvium-crypto/src/rct_verify.rs — single-call
verification of all ring signatures in a transaction (CLSAG + TCLSAG),
avoiding N individual JS↔Rust boundary crossings
- Computes pre-MLSAG message hash matching C++ get_pre_mlsag_hash
- FFI export salvium_verify_rct_signatures with flat byte array interface
- FFI backend verifyRctSignatures() method
- JS backend stub returns null (validation.js handles JS fallback)
- validation.js: 200+ lines of RCT verification logic including
flattenKeyImages, packTclsagSigsFlat, packClsagSigsFlat helpers
Transaction Expansion
─────────────────────
- transaction.js: add expandTransaction() matching C++ expand_transaction_2
(copies key images from prefix inputs into TCLSAG/CLSAG signature structs)
- New test/expand-transaction.test.js (634 lines)
- New test/rct-verify-testnet.test.js (430 lines)
Mining Resilience
─────────────────
- salvium-miner main.rs: retry get_info and get_block_template up to 5
times with 2s delay for transient daemon errors
- full-testnet.js mineTo(): retry miner up to 3 times with 3s delay,
check for partial progress between attempts
Testnet Tooling
───────────────
- sync-only.js: CRYPTO_BACKEND env var for A/B testing (wasm vs ffi)
- full-testnet.js: daemon URL update (node12.whiskymine.io)
- Debug scripts for cn_scan development (debug-cn-scan/marshal/match/wasm)
- Android .gitignore and build-bundle.sh for mobile builds
83 lines
3.1 KiB
JavaScript
83 lines
3.1 KiB
JavaScript
#!/usr/bin/env bun
|
|
/**
|
|
* Debug a single CN transfer on the fresh testnet.
|
|
* Captures full daemon response and TX details.
|
|
*/
|
|
import { setCryptoBackend } from '../src/crypto/index.js';
|
|
import { DaemonRPC } from '../src/rpc/daemon.js';
|
|
import { MemoryStorage } from '../src/wallet-store.js';
|
|
import { createWalletSync } from '../src/wallet-sync.js';
|
|
import { transfer } from '../src/wallet/transfer.js';
|
|
import { getRctType, getTxVersion, getActiveAssetType } from '../src/consensus.js';
|
|
import { TX_TYPE } from '../src/transaction/constants.js';
|
|
|
|
await setCryptoBackend('wasm');
|
|
|
|
const daemon = new DaemonRPC({ url: 'http://node12.whiskymine.io:29081' });
|
|
const info = await daemon.getInfo();
|
|
const h = info.result.height;
|
|
console.log('Height:', h);
|
|
console.log('HF version:', info.result.version);
|
|
console.log('Active asset type:', getActiveAssetType(h, 'testnet'));
|
|
console.log('RCT type:', getRctType(h, 'testnet'));
|
|
console.log('TX version:', getTxVersion(TX_TYPE.TRANSFER, h, 'testnet'));
|
|
console.log('Block weight median:', info.result.block_weight_median);
|
|
console.log('Block weight limit:', info.result.block_weight_limit);
|
|
console.log();
|
|
|
|
const raw = JSON.parse(await Bun.file(process.env.HOME + '/testnet-wallet/wallet-a.json').text());
|
|
const keys = {
|
|
viewSecretKey: raw.viewSecretKey,
|
|
spendSecretKey: raw.spendSecretKey,
|
|
viewPublicKey: raw.viewPublicKey,
|
|
spendPublicKey: raw.spendPublicKey,
|
|
};
|
|
|
|
const storage = new MemoryStorage();
|
|
const sync = createWalletSync({ daemon, keys, carrotKeys: raw.carrotKeys, storage, network: 'testnet' });
|
|
await sync.start();
|
|
|
|
const allOutputs = await storage.getOutputs({ isSpent: false });
|
|
const spendable = allOutputs.filter(o => o.isSpendable(h));
|
|
console.log('Total outputs:', allOutputs.length);
|
|
console.log('Spendable:', spendable.length);
|
|
console.log('First output sample:', JSON.stringify({
|
|
amount: spendable[0]?.amount.toString(),
|
|
assetType: spendable[0]?.assetType,
|
|
blockHeight: spendable[0]?.blockHeight,
|
|
globalIndex: spendable[0]?.globalIndex,
|
|
outputIndex: spendable[0]?.outputIndex,
|
|
}));
|
|
console.log();
|
|
|
|
// Destination: wallet B
|
|
const bData = JSON.parse(await Bun.file(process.env.HOME + '/testnet-wallet/wallet-b.json').text());
|
|
const destAddr = bData.address;
|
|
console.log('Dest:', destAddr);
|
|
|
|
// Intercept daemon.sendRawTransaction
|
|
const origSend = daemon.sendRawTransaction.bind(daemon);
|
|
daemon.sendRawTransaction = async function(txHex, opts) {
|
|
console.log('\n--- Submitting TX ---');
|
|
console.log('TX hex length:', txHex.length);
|
|
console.log('Opts:', JSON.stringify(opts));
|
|
const resp = await origSend(txHex, opts);
|
|
console.log('Full daemon response:', JSON.stringify(resp, null, 2));
|
|
return resp;
|
|
};
|
|
|
|
try {
|
|
const result = await transfer({
|
|
wallet: { keys, storage, carrotKeys: raw.carrotKeys },
|
|
daemon,
|
|
destinations: [{ address: destAddr, amount: 500_000_000n }], // 5 SAL
|
|
options: { priority: 'default', network: 'testnet' }
|
|
});
|
|
console.log('\nSUCCESS!');
|
|
console.log('TX Hash:', result.txHash);
|
|
console.log('Fee:', result.fee?.toString());
|
|
console.log('Inputs:', result.inputCount, 'Outputs:', result.outputCount);
|
|
} catch (e) {
|
|
console.log('\nFAILED:', e.message);
|
|
}
|