aboutsummaryrefslogtreecommitdiff
path: root/wasm/solver.c
diff options
context:
space:
mode:
authorRunxi Yu <me@runxiyu.org>2025-03-25 10:40:22 +0800
committerRunxi Yu <me@runxiyu.org>2025-03-25 10:40:22 +0800
commit77456c33a7ee34876f6c860d2888a1442362dcea (patch)
treee53efe3e330312335eeb11be1123c623d3db652a /wasm/solver.c
parentMerge branch 'master' into irclog (diff)
parentMore C style changes (diff)
downloadpowxy-77456c33a7ee34876f6c860d2888a1442362dcea.tar.gz
powxy-77456c33a7ee34876f6c860d2888a1442362dcea.tar.zst
powxy-77456c33a7ee34876f6c860d2888a1442362dcea.zip
Merge branch 'master' into irclogirclog-v0.1.80
Diffstat (limited to 'wasm/solver.c')
-rw-r--r--wasm/solver.c14
1 files changed, 5 insertions, 9 deletions
diff --git a/wasm/solver.c b/wasm/solver.c
index 890a34c..2eb39c5 100644
--- a/wasm/solver.c
+++ b/wasm/solver.c
@@ -11,16 +11,13 @@ char validate_hash(unsigned char *hash, unsigned char zero_bit_count)
unsigned char q = zero_bit_count / 8;
unsigned char r = zero_bit_count % 8;
- for (unsigned char i = 0; i < q; i++) {
- if (hash[i] != 0) {
+ for (unsigned char i = 0; i < q; i++)
+ if (hash[i] != 0)
return 0;
- }
- }
if (r > 0) {
unsigned char mask = (unsigned char)(0xFF << (8 - r));
- if (hash[q] & mask) {
+ if (hash[q] & mask)
return 0;
- }
}
return 1;
@@ -40,16 +37,15 @@ unsigned long long solve(unsigned char difficulty)
nonce = 0;
- while (1) {
+ for (;;) {
sha256_init(&context);
sha256_update(&context, challenge, sizeof(challenge));
sha256_update(&context, (unsigned char *)(&nonce),
sizeof(nonce));
sha256_final(&context, hash);
- if (validate_hash(hash, difficulty)) {
+ if (validate_hash(hash, difficulty))
break;
- }
nonce++;
}