onflow / flow-go

A fast, secure, and developer-friendly blockchain built to support the next generation of games, apps, and the digital assets that power them.
GNU Affero General Public License v3.0
532 stars 175 forks source link

[Crypto] handling of ecdsa signature malleability #2251

Open LanfordCai opened 2 years ago

LanfordCai commented 2 years ago

Flow is using ecdsa as signing algorithms(nistp256 and secp256k1). In ecdsa, the signature is in the form of (r, s), but there is a second valid signature (r, -s), which can be generated by using (r, s). One of the signatures' s-value is less than half of the curve order(aka, low-s signature), and the other one is not. For other blockchains like Bitcoin/Ethereum, they choose the low-s signature as the canonical one to prevent the problems caused by transaction malleability. But on Flow, both low-s form signature and high-s form signature are regarded as valid(check it here). The malleability of signature might cause transaction malleability problem on Flow(check it here).

I wrote a demo to show these problems here.

In my opinion:

Should we change this behavior?

tarakby commented 2 years ago

Hi @LanfordCai, thank you for submitting the issue and providing the demos 👌🏼 We have been looking at this flag since we received your question on Discord. We'll get back to you about transaction malleability soon with more details.