use "1 + (h mod (n - 1))" instead of "mod n" to cast a hash to a private key

a private key must be in range [1, n - 1]

this change neatly eliminates the scenario where the private key value ends up being 0, though it was extremely unlikely to occur in the first place (and could not even be easily forced)

this changes the encoding -- players need to use the same encoding for submissions as the one used to post challenges
main
SI 2024-04-05 01:40:07 +02:00
parent 470a92264d
commit 512ecf13d6
1 changed files with 1 additions and 1 deletions

View File

@ -34,7 +34,7 @@
return null;
h += c.toString(16).padStart(2, "0");
}
return "0x" + new BN(keccak256(h).slice(2), 16).mod(secp256k1n).toString(16).padStart(64, 0);
return "0x" + new BN(keccak256(h).slice(2), 16).mod(secp256k1n.sub(new BN(1))).add(new BN(1)).toString(16).padStart(64, 0);
}
function updateOutputValues(ev) {