]> git.codecow.com Git - nano-pow.git/commitdiff
Fix WASM in puppeteer.
authorChris Duncan <chris@zoso.dev>
Sat, 21 Jun 2025 06:17:08 +0000 (23:17 -0700)
committerChris Duncan <chris@zoso.dev>
Sat, 21 Jun 2025 06:17:08 +0000 (23:17 -0700)
The puppeteer browser instance loads NanoPow with a script and includes CSP. While it specifically uses WebGPU for performance, it was discovered that WASM would not load due to missing required CSP directives, so they have been added.
The reduced WASM iteration count has been reverted since it seems to be an issue with Firefox and not Chromium.
Adjust logging.

src/bin/server.ts
src/lib/generate/wasm/asm/generate.ts
src/lib/generate/wasm/index.ts
src/lib/generate/webgl/index.ts
src/utils/api-support/wasm.ts

index c5c8193373425d53bd7f58bcaa778cbe0ad6cd02..a00ac4eefcf1f6aed755f4b431b4e15887e508f7 100755 (executable)
@@ -112,7 +112,7 @@ const enc = `sha256-${hash('sha256', src, 'base64')}`
 const body = `
        <!DOCTYPE html>
        <link rel="icon" href="data:,">
-       <meta http-equiv="Content-Security-Policy" content="default-src 'none'; base-uri 'none'; form-action 'none'; script-src '${enc}';">
+       <meta http-equiv="Content-Security-Policy" content="default-src 'none'; base-uri 'none'; form-action 'none'; script-src '${enc}' 'wasm-unsafe-eval'; worker-src blob: https://nanopow.invalid;">
        <script type="module">${src}</script>
 `
 
index 463b22a76031ab25ed2e1c91cc3df0a019a3777a..7c3449201bfc96d24f3b35ded42d0c18c57d22f9 100644 (file)
@@ -153,7 +153,7 @@ console.log(`export function main (seed: u64, h0: u64, h1: u64, h2: u64, h3: u64
        let r0: u64 = 0
        let r1: u64 = 0
        let result = v128.splat<u64>(0)
-       const iterations: u64 = 1 << 20
+       const iterations: u64 = 1 << 24
 
        for (let i: u64 = 0; i < iterations; i++) {
                m0 = i64x2(unchecked(seed + i), unchecked(seed + i + 1))
index d9d99e8d5f3a3d21e68423c997009955dbe92903..704d659cdd8bf973d1d01ccb50c506a31aeaecd5 100644 (file)
@@ -74,7 +74,7 @@ async function dispatch (): Promise<bigint> {
        return new Promise(resolve => {
                const attempts = []
                for (let i = 0; i < workers.length; i++) {
-                       data.seed = bigintToHex((bigintRandom() & ~((1n << 20n) - 1n)), 16)
+                       data.seed = bigintToHex((bigintRandom() & ~((1n << 24n) - 1n)), 16)
                        attempts.push(new Promise((found, err) => {
                                const w = workers[i]
                                w.onerror = err
index 288aca7684f1858aff2ee5a03a06313e771075c2..16594cf87ab8d445479955c8eb8e16496b4745d4 100644 (file)
@@ -432,10 +432,8 @@ export async function generate (hash: bigint, difficulty: bigint, effort: number
                                draw(bigintRandom(), drawFbos[2], queries[2])
                                let drawIndex = 3
                                do {
-                                       LOG: logger.log(`drawing frame ${drawIndex}`)
                                        draw(bigintRandom(), drawFbos[drawIndex], queries[drawIndex])
                                        drawIndex = (drawIndex + 1) % 4
-                                       LOG: logger.log(`checking frame ${drawIndex}`)
                                        found = await check(queries[drawIndex])
                                } while (!found && !timeout)
                                if (found) result = read(drawFbos[drawIndex])
index 8bff74268cd5c35f881b3da14db09e38188b6c37..947976e566d52183dc04ed617a1f44c74d1bdf52 100644 (file)
@@ -23,8 +23,8 @@ Object.defineProperty(wasm, 'isSupported', {
                        const module = await WebAssembly.compile(wasmBuffer)
                        const instance = await WebAssembly.instantiate(module)
                        isWasmSupported = (instance instanceof WebAssembly.Instance)
-               } catch (err) {
-                       console.warn('WASM is not supported in this environment.\n', err)
+               } catch (err: any) {
+                       console.warn('WASM is not supported in this environment.\n', err.message ?? err)
                        isWasmSupported = false
                } finally {
                        delete this.isSupported