Skip to content

Test Mode Verification

davidotero edited this page Jan 1, 2026 · 1 revision

Test Mode Verification

MacMetal CLI includes a built-in test mode that mathematically proves correct SHA256d computation.


Running Test Mode

./MacMetalCLI --test

What It Tests

Test 1: CPU SHA256d Verification

Computes the hash of Bitcoin Block #125552 using CPU and verifies against the known hash.

Block 125552 Details:

  • Mined: May 21, 2011
  • Nonce: 1,118,806,677
  • Hash: 00000000000000001e8d6829a8a21adc5d38d0a473b144b6765798e61f98bd1d

This block is commonly used for testing Bitcoin implementations because:

  1. Well-documented
  2. Has many leading zeros (67 bits)
  3. Verifiable on any block explorer

Test 2: GPU Mining Verification

Uses the GPU to search for the winning nonce of Block #125552.

The test:

  1. Takes the block header (without nonce)
  2. Searches nonces around the known winning value
  3. Verifies the GPU finds the exact correct nonce
  4. Confirms the resulting hash matches

If the GPU finds the correct nonce, it proves:

  • GPU SHA256d implementation is correct
  • Buffer handling is correct
  • Result parsing is correct
  • The miner would correctly identify real Bitcoin blocks

Test 3: Hashrate Benchmark

Runs three batches of 16 million hashes each:

  • Measures time for each batch
  • Calculates hashes per second
  • Reports average hashrate

Expected Output

╔══════════════════════════════════════════════════════════════════════════╗
║           MacMetal CLI Miner v2.1 - TEST MODE                            ║
║                   SHA256d Verification Suite                             ║
╚══════════════════════════════════════════════════════════════════════════╝

[TEST] Initializing Metal GPU...
[TEST] ✓ GPU: Apple M3 Pro

[TEST 1] Bitcoin Block #125552 Header Hash
─────────────────────────────────────────────────────────────────────────
   Header:   0100000081cd02ab7e569e8bcd9317e2fe99f2de...
   Expected: 00000000000000001e8d6829a8a21adc5d38d0a473b144b6765798e61f98bd1d
   CPU Hash: 00000000000000001e8d6829a8a21adc5d38d0a473b144b6765798e61f98bd1d
   [PASS] ✓ CPU SHA256d correct

[TEST 2] GPU Mining - Find Known Nonce
─────────────────────────────────────────────────────────────────────────
   Searching for nonce around: 2504433986
   Target: 32+ zero bits (difficulty 1)
   Hashes computed: 16777216
   Time: 0.048 seconds
   Hashrate: 349.52 MH/s
   Results found: 1
   → Nonce: 0x9546a142 (2504433986) - 67 bits
   [PASS] ✓ GPU found correct nonce!
   Verified hash: 00000000000000001e8d6829a8a21adc5d38d0a473b144b6765798e61f98bd1d

[TEST 3] GPU Hashrate Benchmark
─────────────────────────────────────────────────────────────────────────
   Running 3 batches of 16M hashes each...
   Batch 1: 16777216 hashes in 0.047s = 357.07 MH/s
   Batch 2: 16777216 hashes in 0.048s = 349.52 MH/s
   Batch 3: 16777216 hashes in 0.048s = 349.52 MH/s
   ─────────────────────────────────
   Average: 352.04 MH/s
   [PASS] ✓ GPU hashrate > 100 MH/s

═══════════════════════════════════════════════════════════════════════════
TEST RESULTS
═══════════════════════════════════════════════════════════════════════════

   Passed: 3
   Failed: 0

   ╔═══════════════════════════════════════════════════════════════════╗
   ║  ✅ ALL TESTS PASSED - GPU MINER VERIFIED WORKING                 ║
   ╚═══════════════════════════════════════════════════════════════════╝

   Your GPU is computing correct Bitcoin SHA256d hashes.
   The miner is ready for production use.

What Each Result Means

"CPU SHA256d correct"

The basic SHA256d algorithm is implemented correctly. This is the foundation.

"GPU found correct nonce"

This is the smoking gun. The GPU searched through millions of hashes and found the exact nonce (2,504,433,986) that produces Block #125552's hash.

The hash produced:

00000000000000001e8d6829a8a21adc5d38d0a473b144b6765798e61f98bd1d

This has 67 leading zero bits - matching the real Bitcoin block from 2011.

"GPU hashrate > 100 MH/s"

Performance is acceptable for Apple Silicon.


Why This Proves Correctness

  1. Block #125552 is real - You can verify it on any block explorer
  2. The nonce is unique - Only one nonce produces this hash
  3. The hash is cryptographically secure - Can't be faked
  4. If GPU finds it, SHA256d is correct - QED

If Tests Fail

"CPU SHA256d incorrect"

The basic hash function is broken. This shouldn't happen - report as a bug.

"No valid nonces found"

  1. GPU may not be working correctly
  2. Buffer sizes may be wrong
  3. Shader compilation may have failed

Try rebuilding:

./build.sh
./MacMetalCLI --test

"GPU hashrate < 100 MH/s"

  1. Mac may be thermal throttling
  2. Running on battery
  3. Other GPU workloads active

This is a warning, not a failure.


Technical Details

Block #125552 Header

Version:     01000000
Prev Block:  81cd02ab7e569e8bcd9317e2fe99f2de44d49ab2b8851ba4a308000000000000
Merkle Root: e320b6c2fffc8d750423db8b1eb942ae710e951ed797f7affc8892b0f1fc122b
Timestamp:   c7f5d74d (2011-05-21 17:26:31 UTC)
Bits:        f2b9441a
Nonce:       42a14695 (little-endian) = 0x9546a142 (big-endian) = 2,504,433,986

Nonce Encoding

The nonce 1118806677 appears as 42a14695 in the block header (little-endian).

When read as big-endian for computation: 0x9546a142 = 2504433986


See Also

Clone this wiki locally