// Clear local buffers
verify_blocks_pub.fill(0)
- // Copy input buffer to local parameters, then clear input buffer
+ // Copy public key input buffer to local parameter, then clear input buffer
memory.copy(changetype<usize>(verify_blocks_pub), changetype<usize>(PUB_BUFFER), KEY_BYTELENGTH)
PUB_BUFFER.fill(0)
- // Verify public key, then clear local input
- const validPubkey = crypto_verify_pubkey(verify_blocks_pub)
-
- // Iterate over block hash/signature pairs
- for (let i = 0; i < count; i++) {
- // Copy message buffer to local block hash/signature buffers
- memory.copy(changetype<usize>(verify_blocks_msg), changetype<usize>(MESSAGE_BUFFER) + (96 * i), BLOCKHASH_BYTELENGTH)
- memory.copy(changetype<usize>(verify_blocks_sig), changetype<usize>(MESSAGE_BUFFER) + BLOCKHASH_BYTELENGTH + (96 * i), SIGNATURE_BYTELENGTH)
-
- // Verify hash and signature, then copy local result to output buffer
- verify_blocks_out[i] = u8(validPubkey | crypto_verify_relaxed(verify_blocks_sig, verify_blocks_msg, BLOCKHASH_BYTELENGTH, verify_blocks_pub))
+ // Set all output to false so errors fail closed
+ OUTPUT_BUFFER.fill(255)
+
+ // Verify public key before proceeding with signature verification
+ if (crypto_verify_pubkey(verify_blocks_pub) {
+
+ // Iterate over block hash/signature pairs
+ for (let i = 0; i < count; i++) {
+ // Copy message buffer to local block hash/signature buffers
+ memory.copy(changetype<usize>(verify_blocks_msg), changetype<usize>(MESSAGE_BUFFER) + (96 * i), BLOCKHASH_BYTELENGTH)
+ memory.copy(changetype<usize>(verify_blocks_sig), changetype<usize>(MESSAGE_BUFFER) + BLOCKHASH_BYTELENGTH + (96 * i), SIGNATURE_BYTELENGTH)
+
+ // Verify hash and signature
+ verify_blocks_out[i] = u8(crypto_verify_relaxed(verify_blocks_sig, verify_blocks_msg, BLOCKHASH_BYTELENGTH, verify_blocks_pub))
+ }
}
// Clear local input