From ad79f448cb5e82cf6dfcf2ec7052add87edfc5a3 Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Tue, 25 Mar 2025 10:33:56 +0800 Subject: More C style changes --- wasm/solver.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'wasm/solver.c') 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++; } -- cgit v1.2.3