The encryptECIES method in src/encryption/ec.ts does not verify that the given public key string encodes a point on the secp256k1 curve. While this doesn't pose a security risk in our case -- the worst an attacker can do with this is recover the ephemeralSK by using a specially-crafted public key -- it would still be better from a correctness standpoint to verify that the publicKey string is indeed a secp256k1 point. This can be achieved by either checking that publicKey is a compresssed secp256k1 public key, or if it isn't, compressing it and decompressing it and verifying that the re-decompressed public key is equal to the original public key (and that the compress and decompress steps don't throw an exception).
h/t @dantrevino :grin: for sharing: https://github.com/christianlundkvist/blog/blob/master/2020_05_26_secp256k1_twist_attacks/secp256k1_twist_attacks.md
Gonna tackle this. What should be the desired result be if the key is not valid? Should it throw an exception? Or return something else?
Hey @gdstewart , thank you for reaching out and expressing interest. I know it's been a while, but it would be great to hear if you made any progress. As you can probably see, this repo has been refactored into a monorepo with multiple packages. This code is now in the @stacks/encryption NPM package, and the code referenced in this issue is now in packages/encryption/src/ec.ts.
I have not, but I'll take a look again this coming week when I get a chance
I am working on this issue. Assigning it to myself.
@agraebe This needs to be closed as PR is merged.