upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/src/randomx_pow.h
diff options
context:
space:
mode:
authorbitflash-coin <bookofshamers@outlook.com>2026-08-04 06:34:32 -0700
committerbitflash-coin <bookofshamers@outlook.com>2026-08-04 06:34:32 -0700
commit5ce650382352c1503f40abf08129ada69402af55 (patch)
tree6a18198901f1e2c4933f1ac53c9365eec512bf63 /src/randomx_pow.h
parentf34113291da7e5e3dc7d2468d4f9c212c05c584b (diff)
public commit
Diffstat (limited to 'src/randomx_pow.h')
-rw-r--r--src/randomx_pow.h44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/randomx_pow.h b/src/randomx_pow.h
new file mode 100644
index 0000000..0027571
--- /dev/null
+++ b/src/randomx_pow.h
@@ -0,0 +1,44 @@
1// Copyright (c) 2026 Bitflash developers
2// Distributed under the MIT/X11 software license.
3//
4// Memory-hard Proof of Work (CPU + RAM) via RandomX -- replaces SHA-256d as
5// the PoW algorithm. The block IDENTITY hash stays SHA-256d (GetHash),
6// preserving all indexing; what changes is the PROOF-OF-WORK hash
7// (GetPoWHash), computed with RandomX.
8//
9// Modes:
10// - Verification (all nodes): 256 MB cache, "light" VM. Cheap.
11// - Mining (optional, fast): ~2 GB dataset, "full" VMs. Fast.
12// GPUs and ASICs are neutralized by RandomX's memory cost/latency.
13
14#ifndef BITFLASH_RANDOMX_POW_H
15#define BITFLASH_RANDOMX_POW_H
16
17// uint256 comes from uint256.h, already included by headers.h before this file.
18
19// Initialize the cache (256 MB) and the verification VM. Call once at startup.
20// Returns false if allocation fails.
21bool RandomXInit();
22
23// Allocate and initialize the ~2 GB dataset for fast mining (fast mode),
24// using nThreads to speed it up. Idempotent. Returns false on failure (the
25// miner then falls back to light mode automatically).
26bool RandomXInitDataset(int nThreads);
27
28// PoW hash of an 80-byte header, using the verification VM (thread-safe,
29// guarded by a critical section).
30uint256 RandomXPoWHash(const void* pHeader, size_t nSize);
31
32// Create a VM for a mining thread (own VM, not shared). Uses the dataset
33// (fast) if available, otherwise the cache (light). Release with
34// RandomXDestroyMinerVM. Returns NULL on failure.
35void* RandomXCreateMinerVM();
36void RandomXDestroyMinerVM(void* vm);
37
38// Compute a PoW hash on an owned mining VM (not guarded).
39uint256 RandomXHashWithVM(void* vm, const void* pHeader, size_t nSize);
40
41// True when the 2 GB dataset is ready (fast mode active).
42bool RandomXFastReady();
43
44#endif