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

update btcec to v2 and use the latest btcutil #9250

Merged
merged 4 commits into from
Sep 9, 2022
Merged

update btcec to v2 and use the latest btcutil #9250

merged 4 commits into from
Sep 9, 2022

Conversation

wcsiu
Copy link
Contributor

@wcsiu wcsiu commented Aug 14, 2022


PR checklist

  • Tests written/updated, or no tests needed
  • CHANGELOG_PENDING.md updated, or no changelog entry needed
  • Updated relevant documentation (docs/) and code comments, or no
    documentation updates needed

Closes #9249

@cmwaters
Copy link
Contributor

We have recently changed the default branch to main. Could you rebase your changes of that branch?

Is v2 backwards compatible. i.e. will v2 secp256k1 still verify old signatures?

@wcsiu
Copy link
Contributor Author

wcsiu commented Aug 19, 2022

We have recently changed the default branch to main. Could you rebase your changes of that branch?

Is v2 backwards compatible. i.e. will v2 secp256k1 still verify old signatures?

I have checked the test cases from both the older and newer versions. The are the same.
https://github.com/btcsuite/btcd/blob/btcec/v2.2.1/btcec/ecdsa/signature_test.go#L40
https://github.com/btcsuite/btcd/blob/v0.22.1/btcec/signature_test.go#L38

I have also updated the tests in tendermint to make sure the signature verification tests pass.

Hence, the new version should still be able to verify old secp256k1 signatures.

Of course, as always, more tests on it will be better.

I will finish the rebase as soon as possible, but it is not trivial. In the worst case, I will submit a new PR.

@wcsiu wcsiu changed the base branch from master to main August 19, 2022 17:35
@wcsiu wcsiu requested review from a team August 19, 2022 17:35
@wcsiu wcsiu changed the base branch from main to master August 19, 2022 17:37
@wcsiu wcsiu changed the base branch from master to main August 22, 2022 14:46
@wcsiu
Copy link
Contributor Author

wcsiu commented Aug 22, 2022

@cmwaters I have rebased my branch to main branch. Please have a look.

@odeke-em
Copy link
Contributor

Kindly cc-ing @veorq and @elias-orijtech to help with a security review.

Copy link
Contributor

@elias-orijtech elias-orijtech left a comment

Choose a reason for hiding this comment

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

LGTM other than a suggestion about splitting the change in two; leaving for @veorq.


sig, err := priv.Sign(crypto.Sha256(msg))
sig, err := ecdsa.SignCompact(priv, crypto.Sha256(msg), false)
Copy link
Contributor

Choose a reason for hiding this comment

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

I suggest using https://pkg.go.dev/github.com/btcsuite/btcd/btcec/v2/ecdsa#Sign to gain a smaller diff. Then, a follow-up commit (maybe same PR) can replace Sign with SignCompact and delete serializeSig

Copy link
Contributor Author

@wcsiu wcsiu Sep 2, 2022

Choose a reason for hiding this comment

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

Just found that they no longer expose R and S as exported fields anymore(https://github.com/decred/dcrd/blob/dcrec/secp256k1/v4.1.0/dcrec/secp256k1/ecdsa/signature.go#L52) so logic in serializeSig will no longer work.

Do you think we still need to break it into two commits?

Copy link
Contributor

Choose a reason for hiding this comment

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

I see, thanks. In that case, using SignCompact is probably ok.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK.

Copy link
Contributor

@thanethomson thanethomson left a comment

Choose a reason for hiding this comment

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

Apart from the minor changelog nit, I'd recommend considering the change mentioned by @elias-orijtech.

CHANGELOG_PENDING.md Outdated Show resolved Hide resolved
@thanethomson
Copy link
Contributor

@wcsiu just checking in here. This seems like a valuable change for us to have, but it needs some minor updates.

@wcsiu
Copy link
Contributor Author

wcsiu commented Aug 31, 2022

@wcsiu just checking in here. This seems like a valuable change for us to have, but it needs some minor updates.

I agree with your suggestions. I will update the code according to them. I am having a busy week. I will try to finish it in the coming few days. Thank you.

@thanethomson
Copy link
Contributor

I agree with your suggestions. I will update the code according to them. I am having a busy week. I will try to finish it in the coming few days. Thank you.

No rush 🙂 Just wanted to check in. Thanks very much!

@thanethomson thanethomson added the S:wip Work in progress (prevents stalebot from automatically closing) label Sep 2, 2022
@wcsiu
Copy link
Contributor Author

wcsiu commented Sep 7, 2022

@thanethomson @elias-orijtech has agreed the fix is no longer necessary. I think the PR should now be ready.

wcsiu and others added 3 commits September 8, 2022 11:00
Co-authored-by: Thane Thomson <connect@thanethomson.com>
@thanethomson thanethomson merged commit 0f45086 into tendermint:main Sep 9, 2022
elias-orijtech added a commit to elias-orijtech/cosmos-sdk that referenced this pull request Oct 11, 2022
Similar to Tendermint's PR,

tendermint/tendermint#9250

Note that crypto/ledger is not updated in this PR, because if its
dependency on the R and S values being exposed by ParseDERSignature.

Updates cosmos#13423

Signed-off-by: Elias Naur <elias@orijtech.com>
elias-orijtech added a commit to elias-orijtech/cosmos-sdk that referenced this pull request Oct 14, 2022
Similar to Tendermint's PR,

tendermint/tendermint#9250

Note that crypto/ledger is not updated in this PR, because if its
dependency on the R and S values being exposed by ParseDERSignature.

Updates cosmos#13423

Signed-off-by: Elias Naur <elias@orijtech.com>
elias-orijtech added a commit to elias-orijtech/cosmos-sdk that referenced this pull request Oct 16, 2022
Similar to Tendermint's PR,

tendermint/tendermint#9250

Note that crypto/ledger is not updated in this PR, because if its
dependency on the R and S values being exposed by ParseDERSignature.

Updates cosmos#13423

Signed-off-by: Elias Naur <elias@orijtech.com>
tac0turtle added a commit to cosmos/cosmos-sdk that referenced this pull request Oct 17, 2022
Similar to Tendermint's PR,

tendermint/tendermint#9250

Note that crypto/ledger is not updated in this PR, because if its
dependency on the R and S values being exposed by ParseDERSignature.

Updates #13423

Signed-off-by: Elias Naur <elias@orijtech.com>

Signed-off-by: Elias Naur <elias@orijtech.com>
Co-authored-by: Marko <marbar3778@yahoo.com>
@sergio-mena sergio-mena added the S:backport-to-v0.37.x Tell mergify to backport the PR to v0.37.x label Nov 29, 2022
sergio-mena pushed a commit that referenced this pull request Nov 29, 2022
* secp256k1: upgrade to latest btcec v2 and btcutil

* Update CHANGELOG_PENDING.md

Co-authored-by: Thane Thomson <connect@thanethomson.com>

* fix rebase

Co-authored-by: Thane Thomson <connect@thanethomson.com>
thanethomson added a commit that referenced this pull request Nov 29, 2022
…9250) (#9784)

* update btcec to v2 and use the latest btcutil (#9250)

* secp256k1: upgrade to latest btcec v2 and btcutil

* Update CHANGELOG_PENDING.md

Co-authored-by: Thane Thomson <connect@thanethomson.com>

* fix rebase

Co-authored-by: Thane Thomson <connect@thanethomson.com>

* Minor spacing

Co-authored-by: Wachiu Siu <5212960+wcsiu@users.noreply.github.com>
Co-authored-by: Thane Thomson <connect@thanethomson.com>
sergio-mena pushed a commit that referenced this pull request Nov 29, 2022
* secp256k1: upgrade to latest btcec v2 and btcutil

* Update CHANGELOG_PENDING.md

Co-authored-by: Thane Thomson <connect@thanethomson.com>

* fix rebase

Co-authored-by: Thane Thomson <connect@thanethomson.com>
sergio-mena added a commit that referenced this pull request Nov 29, 2022
…9250) (#9787)

* update btcec to v2 and use the latest btcutil (#9250)

* secp256k1: upgrade to latest btcec v2 and btcutil

* Update CHANGELOG_PENDING.md

Co-authored-by: Thane Thomson <connect@thanethomson.com>

* fix rebase

Co-authored-by: Thane Thomson <connect@thanethomson.com>

* go mod tidy

Co-authored-by: Wachiu Siu <5212960+wcsiu@users.noreply.github.com>
Co-authored-by: Thane Thomson <connect@thanethomson.com>
yihuang pushed a commit to cosmos/cosmos-sdk that referenced this pull request Feb 7, 2023
Similar to Tendermint's PR,

tendermint/tendermint#9250

Note that crypto/ledger is not updated in this PR, because if its
dependency on the R and S values being exposed by ParseDERSignature.

Updates #13423

Signed-off-by: Elias Naur <elias@orijtech.com>

Signed-off-by: Elias Naur <elias@orijtech.com>
Co-authored-by: Marko <marbar3778@yahoo.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S:backport-to-v0.37.x Tell mergify to backport the PR to v0.37.x S:wip Work in progress (prevents stalebot from automatically closing)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update github.com/btcsuite/btcd versions
6 participants