From 3d8f26ee119059ddb05b53290a636760219ad09e Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Tue, 14 Jan 2025 14:44:32 -0800 Subject: [PATCH] Replace m[0-1] with nonce vector. --- src/shaders/compute.wgsl | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/src/shaders/compute.wgsl b/src/shaders/compute.wgsl index 4df2fb0..28c4a2a 100644 --- a/src/shaders/compute.wgsl +++ b/src/shaders/compute.wgsl @@ -35,8 +35,7 @@ fn main(@builtin(global_invocation_id) id: vec3) { /** * Initialize (nonce||blockhash) concatenation */ - var m0: u32 = ubo.random.x ^ id.x; - var m1: u32 = ubo.random.y ^ id.y; + var nonce: vec2 = vec2(ubo.random.x ^ id.x, ubo.random.y ^ id.y); var m2: u32 = ubo.blockhash[0u].x; var m3: u32 = ubo.blockhash[0u].y; var m4: u32 = ubo.blockhash[0u].z; @@ -94,7 +93,7 @@ fn main(@builtin(global_invocation_id) id: vec3) { v0 = v0 + v4 + select(vec2(0u), vec2(0u, 1u), v0.x + v4.x < v0.x); // a = a + m[sigma[r][2*i+0]] - v0 = v0 + vec2(m0, m1) + select(vec2(0u), vec2(0u, 1u), v0.x + m0 < v0.x); + v0 = v0 + nonce + select(vec2(0u), vec2(0u, 1u), v0.x + nonce.x < v0.x); // d = rotr64(d ^ a, 32) xor = v12 ^ v0; @@ -644,7 +643,7 @@ fn main(@builtin(global_invocation_id) id: vec3) { v1 = v1 + v6 + select(vec2(0u), vec2(0u, 1u), v1.x + v6.x < v1.x); // a = a + m[sigma[r][2*i+0]] - v1 = v1 + vec2(m0, m1) + select(vec2(0u), vec2(0u, 1u), v1.x + m0 < v1.x); + v1 = v1 + nonce + select(vec2(0u), vec2(0u, 1u), v1.x + nonce.x < v1.x); // d = rotr64(d ^ a, 32) xor = v12 ^ v1; @@ -833,7 +832,7 @@ fn main(@builtin(global_invocation_id) id: vec3) { v1 = v1 + v5 + select(vec2(0u), vec2(0u, 1u), v1.x + v5.x < v1.x); // a = a + m[sigma[r][2*i+1]] - v1 = v1 + vec2(m0, m1) + select(vec2(0u), vec2(0u, 1u), v1.x + m0 < v1.x); + v1 = v1 + nonce + select(vec2(0u), vec2(0u, 1u), v1.x + nonce.x < v1.x); // d = rotr64(d ^ a, 16) xor = v13 ^ v1; @@ -1383,7 +1382,7 @@ fn main(@builtin(global_invocation_id) id: vec3) { v2 = v2 + v7 + select(vec2(0u), vec2(0u, 1u), v2.x + v7.x < v2.x); // a = a + m[sigma[r][2*i+1]] - v2 = v2 + vec2(m0, m1) + select(vec2(0u), vec2(0u, 1u), v2.x + m0 < v2.x); + v2 = v2 + nonce + select(vec2(0u), vec2(0u, 1u), v2.x + nonce.x < v2.x); // d = rotr64(d ^ a, 16) xor = v13 ^ v2; @@ -1471,7 +1470,7 @@ fn main(@builtin(global_invocation_id) id: vec3) { v0 = v0 + v4 + select(vec2(0u), vec2(0u, 1u), v0.x + v4.x < v0.x); // a = a + m[sigma[r][2*i+1]] - v0 = v0 + vec2(m0, m1) + select(vec2(0u), vec2(0u, 1u), v0.x + m0 < v0.x); + v0 = v0 + nonce + select(vec2(0u), vec2(0u, 1u), v0.x + nonce.x < v0.x); // d = rotr64(d ^ a, 16) xor = v12 ^ v0; @@ -1878,7 +1877,7 @@ fn main(@builtin(global_invocation_id) id: vec3) { v2 = v2 + v6 + select(vec2(0u), vec2(0u, 1u), v2.x + v6.x < v2.x); // a = a + m[sigma[r][2*i+0]] - v2 = v2 + vec2(m0, m1) + select(vec2(0u), vec2(0u, 1u), v2.x + m0 < v2.x); + v2 = v2 + nonce + select(vec2(0u), vec2(0u, 1u), v2.x + nonce.x < v2.x); // d = rotr64(d ^ a, 32) xor = v14 ^ v2; @@ -2302,7 +2301,7 @@ fn main(@builtin(global_invocation_id) id: vec3) { v0 = v0 + v5 + select(vec2(0u), vec2(0u, 1u), v0.x + v5.x < v0.x); // a = a + m[sigma[r][2*i+0]] - v0 = v0 + vec2(m0, m1) + select(vec2(0u), vec2(0u, 1u), v0.x + m0 < v0.x); + v0 = v0 + nonce + select(vec2(0u), vec2(0u, 1u), v0.x + nonce.x < v0.x); // d = rotr64(d ^ a, 32) xor = v15 ^ v0; @@ -2659,7 +2658,7 @@ fn main(@builtin(global_invocation_id) id: vec3) { v0 = v0 + v5 + select(vec2(0u), vec2(0u, 1u), v0.x + v5.x < v0.x); // a = a + m[sigma[r][2*i+1]] - v0 = v0 + vec2(m0, m1) + select(vec2(0u), vec2(0u, 1u), v0.x + m0 < v0.x); + v0 = v0 + nonce + select(vec2(0u), vec2(0u, 1u), v0.x + nonce.x < v0.x); // d = rotr64(d ^ a, 16) xor = v15 ^ v0; @@ -2940,7 +2939,7 @@ fn main(@builtin(global_invocation_id) id: vec3) { v3 = v3 + v7 + select(vec2(0u), vec2(0u, 1u), v3.x + v7.x < v3.x); // a = a + m[sigma[r][2*i+0]] - v3 = v3 + vec2(m0, m1) + select(vec2(0u), vec2(0u, 1u), v3.x + m0 < v3.x); + v3 = v3 + nonce + select(vec2(0u), vec2(0u, 1u), v3.x + nonce.x < v3.x); // d = rotr64(d ^ a, 32) xor = v15 ^ v3; @@ -3465,7 +3464,7 @@ fn main(@builtin(global_invocation_id) id: vec3) { v3 = v3 + v4 + select(vec2(0u), vec2(0u, 1u), v3.x + v4.x < v3.x); // a = a + m[sigma[r][2*i+1]] - v3 = v3 + vec2(m0, m1) + select(vec2(0u), vec2(0u, 1u), v3.x + m0 < v3.x); + v3 = v3 + nonce + select(vec2(0u), vec2(0u, 1u), v3.x + nonce.x < v3.x); // d = rotr64(d ^ a, 16) xor = v14 ^ v3; @@ -3494,7 +3493,7 @@ fn main(@builtin(global_invocation_id) id: vec3) { v0 = v0 + v4 + select(vec2(0u), vec2(0u, 1u), v0.x + v4.x < v0.x); // a = a + m[sigma[r][2*i+0]] - v0 = v0 + vec2(m0, m1) + select(vec2(0u), vec2(0u, 1u), v0.x + m0 < v0.x); + v0 = v0 + nonce + select(vec2(0u), vec2(0u, 1u), v0.x + nonce.x < v0.x); // d = rotr64(d ^ a, 32) xor = v12 ^ v0; @@ -4044,7 +4043,7 @@ fn main(@builtin(global_invocation_id) id: vec3) { v1 = v1 + v6 + select(vec2(0u), vec2(0u, 1u), v1.x + v6.x < v1.x); // a = a + m[sigma[r][2*i+0]] - v1 = v1 + vec2(m0, m1) + select(vec2(0u), vec2(0u, 1u), v1.x + m0 < v1.x); + v1 = v1 + nonce + select(vec2(0u), vec2(0u, 1u), v1.x + nonce.x < v1.x); // d = rotr64(d ^ a, 32) xor = v12 ^ v1; @@ -4171,8 +4170,7 @@ fn main(@builtin(global_invocation_id) id: vec3) { */ if ((BLAKE2B_IV32_1 ^ v0.y ^ v8.y) > threshold && atomicLoad(&work.found) == 0u) { atomicStore(&work.found, 1u); - work.nonce.x = m0; - work.nonce.y = m1; + work.nonce = nonce; } return; } -- 2.34.1