paulmillr / noble-secp256k1

Fastest 4KB JS implementation of secp256k1 signatures and ECDH
https://paulmillr.com/noble
MIT License
757 stars 114 forks source link

verifySync returns false when it should return true #68

Closed cameri closed 2 years ago

cameri commented 2 years ago

Library version: 1.6.3

schnorr.verifySync is not working as expected

const sig = "ec8b2bc640c8c7e92fbc0e0a6f539da2635068a99809186f15106174d727456132977c78f3371d0ab01c108173df75750f33d8e04c4d7980bbb3fb70ba1e3848";
const message = "b1601d26958e6508b7b9df0af609c652346c09392b6534d93aead9819a51b4ef";
const pubkey = "22e804d26ed16b68db5259e78449e96dab5d464c8f470bda3eb1a70467f2c793";

const secp = require("@noble/secp256k1")

secp.schnorr.verifySync(sig, message, pubkey) 
// expected: true
// actual: false (incorrect)

secp.schnorr.verifySync(secp.utils.hexToBytes(sig), secp.utils.hexToBytes(message), secp.utils.hexToBytes(pubkey)) 
// expected: true
// actual: false (incorrect)

secp.schnorr.verifySync(Buffer.from(sig, 'hex'), Buffer.from(message, 'hex'), Buffer.from(pubkey, 'hex')) 
// expected: true
// actual: false (incorrect)

await secp.schnorr.verify(sig, message, pubkey)
// expected: true
// actual: true (correct)

await secp.schnorr.verify(secp.utils.hexToBytes(sig), secp.utils.hexToBytes(message), secp.utils.hexToBytes(pubkey))
// expected: true
// actual: true (correct)

await secp.schnorr.verify(Buffer.from(sig, 'hex'), Buffer.from(message, 'hex'), Buffer.from(pubkey, 'hex'))
// expected: true
// actual: true (correct)
paulmillr commented 2 years ago

You did not show your sync sha256 initialization code. Where is it?

fiatjaf commented 2 years ago

You must provide your own sync sha256 and hmac256 functions.