Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce first version of ECDSA adaptor signature spec #114

Merged
merged 15 commits into from
May 7, 2021

Conversation

LLFourn
Copy link
Contributor

@LLFourn LLFourn commented Nov 10, 2020

This is a draft of the ECDSA adaptor signature spec.

Feel free to post an early review on structure, format and design decisions.
See if you can find any mistakes in the algorithms.

TODO:

  • test vectors
  • review Jonas' implementation to see if there are any meaningful differences (@jesseposner)
  • reference table

Fixes #50

Copy link
Contributor

@nkohen nkohen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple nits

ecdsa_adaptor.md Outdated Show resolved Hide resolved
ecdsa_adaptor.md Outdated Show resolved Hide resolved
ecdsa_adaptor.md Outdated Show resolved Hide resolved
ecdsa_adaptor.md Outdated Show resolved Hide resolved
Copy link
Contributor

@benthecarman benthecarman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of the links have an extra [] around them it seems as well

ecdsa_adaptor.md Outdated Show resolved Hide resolved
ecdsa_adaptor.md Outdated Show resolved Hide resolved
Copy link
Member

@Tibo-lg Tibo-lg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some nits. Also it might be better to keep file names consistents with the others (maybe Ecdsa-Adaptor.md instead of ecdsa_adaptor.md.

ecdsa_adaptor.md Outdated Show resolved Hide resolved
ecdsa_adaptor.md Outdated Show resolved Hide resolved
ecdsa_adaptor.md Outdated Show resolved Hide resolved
@LLFourn
Copy link
Contributor Author

LLFourn commented Nov 11, 2020

@benthecarman That was intentional. I tried to put references in [ ]. I haven't put a list of references at the bottom yet. I find just putting links annoying because then you have to figure out what word to put them on. Perhaps now is the time to make a convention for how to do this?

@NicolasDorier
Copy link

NicolasDorier commented Nov 27, 2020

@LLFourn trying to make your test pass:

First vector, I can't parse the adaptor sig,

036c2f34833942e6eebb9e01b71c1d5f6ea185e7af607805ab5a39a829ad7a30400220f57f812e043e0f5b5c8c22a5c6efe6f76cdaa71490f7b3a3adb7a39101bf7ad4ee4d049e573adee6647ab7d97445d87c4252d91a627935269e99703a7d4161a5b4e2675d09e0da65deb2ed6210e5e99244153e9600ed17d90f6f31853e2c5ff8680adcbd1393d1ae8eed5cd8a8e396275be95506bf40a20ac22f66ca875bf4

It seems to fail here

nkohen/secp256k1@3383459#diff-af7e1bf67c999123aba5f3f14622539c6ac8eb6ce92676ccaa1f5c418bed6574R45

Basically the first FE seems to be too big?

@NicolasDorier
Copy link

What is the verification_key?

@LLFourn
Copy link
Contributor Author

LLFourn commented Nov 30, 2020

@NicolasDorier This code doesn't conform the spec yet.

From the spec:

  • Set a to R || R_a || s_a || proof

So it can parsed like

036c2f34833942e6eebb9e01b71c1d5f6ea185e7af607805ab5a39a829ad7a3040  #R
0220f57f812e043e0f5b5c8c22a5c6efe6f76cdaa71490f7b3a3adb7a39101bf7a      #R_a
d4ee4d049e573adee6647ab7d97445d87c4252d91a627935269e99703a7d4161   #s_a
a5b4e2675d09e0da65deb2ed6210e5e99244153e9600ed17d90f6f31853e2c5ff8680adcbd1393d1ae8eed5cd8a8e396275be95506bf40a20ac22f66ca875bf4 # proof

To make the code conform I think there are only a few small changes:

needs to be instead:

    secp256k1_sha256_initialize_tagged(&sha, algo16, algo16_len(algo16)); # this needs to be the tag from the spec instead
    secp256k1_dleq_hash_point(&sha, p1);
    secp256k1_dleq_hash_point(&sha, gen2);
    secp256k1_dleq_hash_point(&sha, p2); 
    secp256k1_dleq_hash_point(&sha, r1);
    secp256k1_dleq_hash_point(&sha, r2);
  • The serialization and de serialization code needs to match what I've specified. I think there is a difference here in what is considered the "proof" and what is considered the "adaptor_sig". The proof in what I've specified is only 64 bytes. What is important is that deserialization takes a 162 byte buffer what the internals are like after that is not too important.

I think that's all you'll need to change to get the verification test vectors to pass. After that I would go over the signing code and make sure the nonces are produced in a way that at least approximates the spec (everything that is recommended to be hashed to produce a nonce it hashed).

@jesseposner has offered to do the work to make the above happen.

What is the verification_key?

I meant the public signing key. I've changed the test vector to use this instead.

@NicolasDorier
Copy link

does that mean that all tests vectors that we finally all pass from @nkohen need to follow this new spec?
If not, it should be same format, else we are testing different things.

@LLFourn
Copy link
Contributor Author

LLFourn commented Nov 30, 2020

@NicolasDorier Yes. Any end-to-end test vectors need to be updated. My main goal with this spec is to separate the DLEQ proof from the ECDSA adaptor (since it might be independently useful). Obviously another approach could be just to spec what's in the branch but I thought it would be better to come up with something a little more thought out and easy to justify (not that the all the justifications are in the document yet).

@NicolasDorier
Copy link

NicolasDorier commented Nov 30, 2020

Not to say the spec is frozen, but at this stage several implementation follow it, and breaking it without good reason (like security fix/features) will just waste everybody's time.

Both those tests and the specs must be in sync. If somebody come to this repository, and implement DLC starting by this document, most of his effort won't help him to implement the DLC specification. (Formatting data correctly is as much time consuming as monkey porting the math)

So in the worst case: A developer come here, pass the tests, then find out that it is not following the spec, update his code to follow the spec, but then the unit tests he did to pass this vector won't pass anymore.

@NicolasDorier
Copy link

036c2f34833942e6eebb9e01b71c1d5f6ea185e7af607805ab5a39a829ad7a3040  #R
0220f57f812e043e0f5b5c8c22a5c6efe6f76cdaa71490f7b3a3adb7a39101bf7a      #R_a
d4ee4d049e573adee6647ab7d97445d87c4252d91a627935269e99703a7d4161   #s_a
a5b4e2675d09e0da65deb2ed6210e5e99244153e9600ed17d90f6f31853e2c5ff8680adcbd1393d1ae8eed5cd8a8e396275be95506bf40a20ac22f66ca875bf4 # proof

For R, in the spec, the first byte seems to have meaning. nkohen/secp256k1@3383459#diff-af7e1bf67c999123aba5f3f14622539c6ac8eb6ce92676ccaa1f5c418bed6574R48

@LLFourn
Copy link
Contributor Author

LLFourn commented Nov 30, 2020

Not to say the spec is frozen, but at this stage several implementation follow it, and breaking it without good reason (like security fix/features) will just waste everybody's time.

My feeling was when I was asked to do this specification the expectation was that there would be breaking changes to what exists in the branch.

The purpose of this spec is to do the DLEQ proof something like how it a generalized framework for expressing these kinds of proofs would specify it (I am working on such a framework). Perhaps this is premature but I think it's better to be as close as possible to "textbook".
The time waste may additionally come when someone wants to use a DLEQ proof for their protocol but does want to use the branch as it has some rough edges to it -- so they re-write an incompatible one.

For R, in the spec, the first byte seems to have meaning. nkohen/secp256k1@3383459#diff-af7e1bf67c999123aba5f3f14622539c6ac8eb6ce92676ccaa1f5c418bed6574R48

Well spotted. It seems that points are not being SECG encoded but rather being prefixed with a 0 or a 1 instead of the usual 2 or 3.

@nkohen
Copy link
Contributor

nkohen commented Dec 4, 2020

I think breaking changes here are okay/good to have, but I will note that I do not plan to actually make any other part of the DLC spec or implementations conform to this new ECDSA adaptor spec until there is a stable branch on secp256k1-zkp that we can all use. Once such a branch exists, it should be significantly easier for everyone to switch to using that branch instead of my temporary one and I have code to auto-regenerate the test vectors (which other impls should be able to pass, simply by using the new crypto library)

test/ecdsa_adaptor.json Outdated Show resolved Hide resolved
ECDSA-adaptor.md Outdated Show resolved Hide resolved
ECDSA-adaptor.md Outdated
## Adaptor Signatures

*Adaptor signatures* are an efficient form of verifiable signature encryption that can achieve our required structure.
Given a anticipated signature `Y` we may encrypt a signature (for the purposes of this document, an ECDSA signature) under `Y` such that once a party learns the discrete logarithm of `Y` they can decrypt it and get a valid ECDSA signature.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Y isn't a signature per se, bur rather a commitment to a signature, or a public key derived from an anticipated signature

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name I use for the commitment/public key is "anticipated signature". It came from Tadge: https://diyhpl.us/wiki/transcripts/discreet-log-contracts/.

I think I am using it correctly here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From that transcript, it looks like it's ambiguous as to whether "Anticipated Signature" refers to Y or just the scheme in general. However, my point might be a little pedantic and I don't think it matters all that much, and I can see the utility of having a shorthand like "Anticipated Signature."

ECDSA-adaptor.md Outdated Show resolved Hide resolved
ECDSA-adaptor.md Outdated Show resolved Hide resolved
ECDSA-adaptor.md Outdated Show resolved Hide resolved
@jesseposner
Copy link
Contributor

I implemented the spec in Python here and it runs and passes all the test vectors.

@jesseposner
Copy link
Contributor

jesseposner commented Dec 11, 2020

Here's my secp branch that updates the implementation to match the spec: https://github.com/jesseposner/secp256k1/tree/jp/ecdsa-adaptor-sigs

This commit has the diff showing the changes that are required to match the spec: bitcoin-core/secp256k1@3246e15

I've also added the first test vector and it passes: bitcoin-core/secp256k1@a8ae212

I will be continuing to work on that branch to finish the TODO items and add more test coverage.

draft PR: BlockstreamResearch/secp256k1-zkp#117

test/ecdsa_adaptor.json Outdated Show resolved Hide resolved
@NicolasDorier
Copy link

I think breaking changes here are okay/good to have, but I will note that I do not plan to actually make any other part of the DLC spec or implementations conform to this new ECDSA adaptor spec until there is a stable branch on secp256k1-zkp

In this case, this spec should conform to the current spec, then we should just change this spec and the old spec later.
If we merge this we start having different spec inside the same repo, this is confusing as hell.

ECDSA-adaptor.md Outdated Show resolved Hide resolved
@jesseposner
Copy link
Contributor

@LLFourn I've updated BlockstreamResearch/secp256k1-zkp#117 with the new changes and test vectors.

Co-authored-by: Jesse Posner <[email protected]>
@LLFourn
Copy link
Contributor Author

LLFourn commented Jan 22, 2021

@jesseposner Thanks. Will review soon.

@jesseposner
Copy link
Contributor

@LLFourn I'm going to be rebasing to clean up the commits soon in the PR, which should make it much easier to review as a whole (but more difficult to isolate the changes from the original branch).

@jesseposner
Copy link
Contributor

jesseposner commented Jan 27, 2021

I've cleaned up the commits and it should be a lot easier to review now by proceeding commit by commit. I'm giving it one last round of polish today and then I will fill out the PR description and move it out of draft mode.

jesseposner added a commit to jesseposner/secp256k1-zkp that referenced this pull request Jan 27, 2021
This commit adds proving and verification functions for discrete
logarithm equality.

From the spec (discreetlogcontracts/dlcspecs#114):

  "As part of the ECDSA adaptor signature a proof of discrete logarithm
  equality must be provided. This is a proof that the discrete logarithm of
  some X to the standard base G is the same as the discrete logarithm of
  some Z to the base Y. This proof can be constructed by using equality
  composition on two Sigma protocols proving knowledge of the discrete
  logarithm between both pairs of points. In other words the prover proves
  knowledge of a such that X = a * G and b such that Z = b * Y and that
  a = b. We make the resulting Sigma protocol non-interactive by applying
  the Fiat-Shamir transformation with SHA256 as the challenge hash."
jesseposner added a commit to jesseposner/secp256k1-zkp that referenced this pull request Jan 28, 2021
This commit adds proving and verification functions for discrete
logarithm equality.

From the spec (discreetlogcontracts/dlcspecs#114):

  "As part of the ECDSA adaptor signature a proof of discrete logarithm
  equality must be provided. This is a proof that the discrete logarithm of
  some X to the standard base G is the same as the discrete logarithm of
  some Z to the base Y. This proof can be constructed by using equality
  composition on two Sigma protocols proving knowledge of the discrete
  logarithm between both pairs of points. In other words the prover proves
  knowledge of a such that X = a * G and b such that Z = b * Y and that
  a = b. We make the resulting Sigma protocol non-interactive by applying
  the Fiat-Shamir transformation with SHA256 as the challenge hash."
jesseposner added a commit to jesseposner/secp256k1-zkp that referenced this pull request Jan 28, 2021
This commit adds proving and verification functions for discrete
logarithm equality.

From the spec (discreetlogcontracts/dlcspecs#114):

  "As part of the ECDSA adaptor signature a proof of discrete logarithm
  equality must be provided. This is a proof that the discrete logarithm of
  some X to the standard base G is the same as the discrete logarithm of
  some Z to the base Y. This proof can be constructed by using equality
  composition on two Sigma protocols proving knowledge of the discrete
  logarithm between both pairs of points. In other words the prover proves
  knowledge of a such that X = a * G and b such that Z = b * Y and that
  a = b. We make the resulting Sigma protocol non-interactive by applying
  the Fiat-Shamir transformation with SHA256 as the challenge hash."
@jesseposner
Copy link
Contributor

@LLFourn The PR is now stable and out of draft mode. The only thing that should change at this point is updates to respond to comments and potentially adding some additional test cases.

jesseposner added a commit to jesseposner/secp256k1-zkp that referenced this pull request Mar 5, 2021
This commit adds proving and verification functions for discrete
logarithm equality.

From the spec (discreetlogcontracts/dlcspecs#114):

"As part of the ECDSA adaptor signature a proof of discrete logarithm
equality must be provided. This is a proof that the discrete logarithm of
some X to the standard base G is the same as the discrete logarithm of
some Z to the base Y. This proof can be constructed by using equality
composition on two Sigma protocols proving knowledge of the discrete
logarithm between both pairs of points. In other words the prover proves
knowledge of a such that X = a * G and b such that Z = b * Y and that
a = b. We make the resulting Sigma protocol non-interactive by applying
the Fiat-Shamir transformation with SHA256 as the challenge hash."
jesseposner added a commit to jesseposner/secp256k1-zkp that referenced this pull request Mar 5, 2021
This commit adds proving and verification functions for discrete
logarithm equality.

From the spec (discreetlogcontracts/dlcspecs#114):

"As part of the ECDSA adaptor signature a proof of discrete logarithm
equality must be provided. This is a proof that the discrete logarithm of
some X to the standard base G is the same as the discrete logarithm of
some Z to the base Y. This proof can be constructed by using equality
composition on two Sigma protocols proving knowledge of the discrete
logarithm between both pairs of points. In other words the prover proves
knowledge of a such that X = a * G and b such that Z = b * Y and that
a = b. We make the resulting Sigma protocol non-interactive by applying
the Fiat-Shamir transformation with SHA256 as the challenge hash."
jesseposner added a commit to jesseposner/secp256k1-zkp that referenced this pull request Mar 9, 2021
This commit adds proving and verification functions for discrete
logarithm equality.

From the spec (discreetlogcontracts/dlcspecs#114):

"As part of the ECDSA adaptor signature a proof of discrete logarithm
equality must be provided. This is a proof that the discrete logarithm of
some X to the standard base G is the same as the discrete logarithm of
some Z to the base Y. This proof can be constructed by using equality
composition on two Sigma protocols proving knowledge of the discrete
logarithm between both pairs of points. In other words the prover proves
knowledge of a such that X = a * G and b such that Z = b * Y and that
a = b. We make the resulting Sigma protocol non-interactive by applying
the Fiat-Shamir transformation with SHA256 as the challenge hash."
jesseposner added a commit to jesseposner/secp256k1-zkp that referenced this pull request Mar 17, 2021
This commit adds proving and verification functions for discrete
logarithm equality.

From the spec (discreetlogcontracts/dlcspecs#114):

"As part of the ECDSA adaptor signature a proof of discrete logarithm
equality must be provided. This is a proof that the discrete logarithm of
some X to the standard base G is the same as the discrete logarithm of
some Z to the base Y. This proof can be constructed by using equality
composition on two Sigma protocols proving knowledge of the discrete
logarithm between both pairs of points. In other words the prover proves
knowledge of a such that X = a * G and b such that Z = b * Y and that
a = b. We make the resulting Sigma protocol non-interactive by applying
the Fiat-Shamir transformation with SHA256 as the challenge hash."
@jesseposner
Copy link
Contributor

@LLFourn Any thoughts on including a warning about the leakage of the DH key between the signing key and encryption key? I was thinking some guidance might be warranted here, for example suggesting that DH protocols not be used for these keys.

@LLFourn
Copy link
Contributor Author

LLFourn commented Apr 8, 2021

This document is ready. As I said before I think it would be good if all spectests were updated to align with this one so all the documents are consistent.

test/ecdsa_adaptor.json Outdated Show resolved Hide resolved
@NicolasDorier
Copy link

NicolasDorier commented Apr 10, 2021

A reminder that this should be merged (or not). I am waiting for the spec to be stable before continuing any work on DLC, so as long as this is in "maybe merge, maybe not", I am on the sideline. :/

@nkohen nkohen merged commit fcc9619 into discreetlogcontracts:master May 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Adaptor signature documentation / explaination
6 participants