Last active
March 9, 2024 02:35
-
-
Save Exponential-Workload/2e87a7e9377ce206d039153f7b4d6bf6 to your computer and use it in GitHub Desktop.
Small Proof-of-Work Proof-of-Concept
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Simple hash-rate checking proof-of-work proof-of-concept script | |
const exec = (digits) => { | |
const crypto = require('crypto'); | |
while (true) { | |
const start = performance.now(); | |
let i = 0; | |
const nextHash = () => crypto.createHash('sha512').update(`${++i}`).digest('hex'); | |
let hash = ''; | |
let target = Math.floor(Math.random() * (10 ** digits)).toString(16).padStart(digits, '0'); | |
while (!hash.startsWith(target)) { | |
hash = nextHash() | |
} | |
console.log('Calculated', hash, 'with', i, 'which starts with target', target, 'in', (performance.now() - start) + 'ms') | |
} | |
} | |
exec(5); // Using a digit count above 6 is just asking for trouble; 6 already takes up to ~60s on a Ryzen 5 3600x - ideally, you should just use 5 and check multiple results with 5 until you achieve the desired complexity |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment