You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
2.5 KiB

  1. # ADR 014: Secp256k1 Signature Malleability
  2. ## Context
  3. Secp256k1 has two layers of malleability.
  4. The signer has a random nonce, and thus can produce many different valid signatures.
  5. This ADR is not concerned with that.
  6. The second layer of malleability basically allows one who is given a signature
  7. to produce exactly one more valid signature for the same message from the same public key.
  8. (They don't even have to know the message!)
  9. The math behind this will be explained in the subsequent section.
  10. Note that in many downstream applications, signatures will appear in a transaction, and therefore in the tx hash.
  11. This means that if someone broadcasts a transaction with secp256k1 signature, the signature can be altered into the other form by anyone in the p2p network.
  12. Thus the tx hash will change, and this altered tx hash may be committed instead.
  13. This breaks the assumption that you can broadcast a valid transaction and just wait for its hash to be included on chain.
  14. One example is if you are broadcasting a tx in cosmos,
  15. and you wait for it to appear on chain before incrementing your sequence number.
  16. You may never increment your sequence number if a different tx hash got committed.
  17. Removing this second layer of signature malleability concerns could ease downstream development.
  18. ### ECDSA context
  19. Secp256k1 is ECDSA over a particular curve.
  20. The signature is of the form `(r, s)`, where `s` is an elliptic curve group element.
  21. However `(r, -s)` is also another valid solution.
  22. Note that anyone can negate a group element, and therefore can get this second signature.
  23. ## Decision
  24. We can just distinguish a canonical form for the ECDSA signatures.
  25. Then we require that all ECDSA signatures be in the form which we defined as canonical.
  26. A canonical form is rather easy to define and check.
  27. It would just be the smaller of the two y coordinates for the given x coordinate, defined lexicographically.
  28. Example of other systems using this: https://github.com/zkcrypto/pairing/tree/master/src/bls12_381#serialization.
  29. ## Proposed Implementation
  30. Fork https://github.com/btcsuite/btcd, and just update the [parse sig method](https://github.com/btcsuite/btcd/blob/master/btcec/signature.go#195) and serialize functions to enforce our canonical form.
  31. ## Status
  32. Proposed.
  33. ## Consequences
  34. ### Positive
  35. * Lets us maintain the ability to expect a tx hash to appear in the blockchain.
  36. ### Negative
  37. * More work in all future implementations (Though this is a very simple check)
  38. * Requires us to maintain another fork
  39. ### Neutral