uniform uvec4 u_work0;
// Last 4 bytes remain as generated externally
uniform uvec4 u_work1;
-
// Precalculated block hash components
uniform uint blockHash[8];
-
// Threshold is 0xfffffff8 for send/change blocks and 0xfffffe for all else
uniform uint threshold;
-
// Defines canvas size
uniform float workload;
-// Offsets into the input data buffer for each mixing step.
-// They are multiplied by 2 from the original SIGMA values in
-// the C reference implementation, which refered to uint64s.
-uniform int SIGMA82[192];
-
// Defined separately from uint v[32] below as the original value is required
// to calculate the second uint32 of the digest for threshold comparison
#define BLAKE2B_IV32_1 0x6A09E667u
// Input data buffer
uint m[32];
+// These are offsets into the input data buffer for each mixing step.
+// They are multiplied by 2 from the original SIGMA values in
+// the C reference implementation, which refered to uint64s.
+const int SIGMA82[192] = int[192](
+ 0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,28,20,8,16,18,30,26,12,2,24,
+ 0,4,22,14,10,6,22,16,24,0,10,4,30,26,20,28,6,12,14,2,18,8,14,18,6,2,26,
+ 24,22,28,4,12,10,20,8,0,30,16,18,0,10,14,4,8,20,30,28,2,22,24,12,16,6,
+ 26,4,24,12,20,0,22,16,6,8,26,14,10,30,28,2,18,24,10,2,30,28,26,8,20,0,
+ 14,12,6,18,4,16,22,26,22,14,28,24,2,6,18,10,0,30,8,16,12,4,20,12,30,28,
+ 18,22,6,0,16,24,4,26,14,2,8,20,10,20,4,16,8,14,12,2,10,30,22,18,28,6,24,
+ 26,0,0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,28,20,8,16,18,30,26,12,
+ 2,24,0,4,22,14,10,6
+);
+
// 64-bit unsigned addition within the compression buffer
// Sets v[a,a+1] += b
// b0 is the low 32 bits of b, b1 represents the high 32 bits
static #WORKLOAD: number = 256 * Math.max(1, Math.floor(navigator.hardwareConcurrency / 2))
static #work0 = new Uint8Array(4)
static #work1 = new Uint8Array(4)
- /**
- * Offsets into the input data buffer for each mixing step. They are multiplied
- * by 2 from the original SIGMA values in the C reference implementation, which
- * refered to uint64s.
- */
static #SIGMA82: number[] = [
- 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30,
- 28, 20, 8, 16, 18, 30, 26, 12, 2, 24, 0, 4, 22, 14, 10, 6,
- 22, 16, 24, 0, 10, 4, 30, 26, 20, 28, 6, 12, 14, 2, 18, 8,
- 14, 18, 6, 2, 26, 24, 22, 28, 4, 12, 10, 20, 8, 0, 30, 16,
- 18, 0, 10, 14, 4, 8, 20, 30, 28, 2, 22, 24, 12, 16, 6, 26,
- 4, 24, 12, 20, 0, 22, 16, 6, 8, 26, 14, 10, 30, 28, 2, 18,
- 24, 10, 2, 30, 28, 26, 8, 20, 0, 14, 12, 6, 18, 4, 16, 22,
- 26, 22, 14, 28, 24, 2, 6, 18, 10, 0, 30, 8, 16, 12, 4, 20,
- 12, 30, 28, 18, 22, 6, 0, 16, 24, 4, 26, 14, 2, 8, 20, 10,
- 20, 4, 16, 8, 14, 12, 2, 10, 30, 22, 18, 28, 6, 24, 26, 0,
- 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30,
- 28, 20, 8, 16, 18, 30, 26, 12, 2, 24, 0, 4, 22, 14, 10, 6
+ 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 28, 20, 8, 16, 18, 30, 26, 12, 2, 24,
+ 0, 4, 22, 14, 10, 6, 22, 16, 24, 0, 10, 4, 30, 26, 20, 28, 6, 12, 14, 2, 18, 8, 14, 18, 6, 2, 26,
+ 24, 22, 28, 4, 12, 10, 20, 8, 0, 30, 16, 18, 0, 10, 14, 4, 8, 20, 30, 28, 2, 22, 24, 12, 16, 6,
+ 26, 4, 24, 12, 20, 0, 22, 16, 6, 8, 26, 14, 10, 30, 28, 2, 18, 24, 10, 2, 30, 28, 26, 8, 20, 0,
+ 14, 12, 6, 18, 4, 16, 22, 26, 22, 14, 28, 24, 2, 6, 18, 10, 0, 30, 8, 16, 12, 4, 20, 12, 30, 28,
+ 18, 22, 6, 0, 16, 24, 4, 26, 14, 2, 8, 20, 10, 20, 4, 16, 8, 14, 12, 2, 10, 30, 22, 18, 28, 6, 24,
+ 26, 0, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 28, 20, 8, 16, 18, 30, 26, 12,
+ 2, 24, 0, 4, 22, 14, 10, 6
]
static #B2B_G_params: number[] = []
static {
static #blockHashLocation: WebGLUniformLocation | null
static #thresholdLocation: WebGLUniformLocation | null
static #workloadLocation: WebGLUniformLocation | null
- static #sigma82Location: WebGLUniformLocation | null
static #vertexShader: WebGLShader | null
static #fragmentShader: WebGLShader | null
static #positionBuffer: WebGLBuffer | null
this.#blockHashLocation = this.#gl.getUniformLocation(this.#program, "blockHash")
this.#thresholdLocation = this.#gl.getUniformLocation(this.#program, "threshold")
this.#workloadLocation = this.#gl.getUniformLocation(this.#program, "workload")
- this.#sigma82Location = this.#gl.getUniformLocation(this.#program, "SIGMA82")
}
static #calculate (hashHex: string, callback: (nonce: string | PromiseLike<string>) => any, threshold: number): void {
Pow.#gl.uniform1uiv(Pow.#blockHashLocation, hashBytes)
Pow.#gl.uniform1ui(Pow.#thresholdLocation, threshold)
Pow.#gl.uniform1f(Pow.#workloadLocation, this.#WORKLOAD - 1)
- Pow.#gl.uniform1iv(Pow.#sigma82Location, this.#SIGMA82)
Pow.#gl.clear(Pow.#gl.COLOR_BUFFER_BIT)
Pow.#gl.drawArrays(Pow.#gl.TRIANGLES, 0, 6)