]> zoso.dev Git - nano-pow.git/commitdiff
Fix missing compression step when resetting v. Start adding some logging for benchmar...
authorChris Duncan <chris@zoso.dev>
Mon, 3 Mar 2025 16:04:59 +0000 (08:04 -0800)
committerChris Duncan <chris@zoso.dev>
Mon, 3 Mar 2025 16:04:59 +0000 (08:04 -0800)
src/classes/cpu.ts

index 44fea21290990b12fce420b793a17e2db72b2aab..55e6d24427aabd3fe30e6c7fbc71d9f39d5fe263 100644 (file)
@@ -103,7 +103,6 @@ export class NanoPowCpu {
                v[c] += v[d]
                v[b] ^= v[c]
                v[b] = (v[b] >> 24n) | (v[b] << 40n)
-
                v[a] += v[b]
                v[a] += m[y]
                v[d] ^= v[a]
@@ -124,6 +123,7 @@ export class NanoPowCpu {
                }
                this.#v[0] ^= 0x01010008n // depth = 1; fanout = 1; outlen = 8
                this.#v[12] ^= 40n // Output length
+               this.#v[14] = ~this.#v[14] // Compression
 
                // Set up input buffers
                this.#mView.setBigUint64(0, seed, true)
@@ -171,19 +171,19 @@ export class NanoPowCpu {
                        : BigInt(`0x${options.threshold}00000000`)
                this.#debug = !!(options?.debug)
 
-               // let attempts = 0n
+               let attempts = 0n
                let result = 0n
                let nonce = 0n
-               // let start = performance.now()
+               let start = performance.now()
                do {
-                       // attempts++
+                       attempts++
                        const random0 = Math.floor(Math.random() * 0xffffffff)
                        const random1 = Math.floor(Math.random() * 0xffffffff)
                        nonce = (BigInt(random0) << 32n) | BigInt(random1)
-                       // if (this.#debug) console.log(`seed: ${seed.toString(16).padStart(16, '0')}`)
                        result = this.#hash(nonce, hash)
-                       // if (this.#debug) console.log(performance.now() - start)
+                       if (attempts % 1000000n === 0n) console.log(`${attempts} attempts`)
                } while (result < threshold)
+               console.log(performance.now() - start)
                this.#busy = false
                return result.toString(16).padStart(16, '0')
        }