-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Sign and SignWithPrivKey produce different signatures #8448
Comments
@tac0turtle can we take this issue? |
yea!! would need to check if its still the case since the issue is so old |
Just checked with a test if both signing methods are returning the same result, and in fact they are.
If that is a desirable fix, I'm happy to fix it and add a specific test that checks that both signatures match. |
Sorry @raynaudoe can you re-summarize the proposal? Are you suggesting to modify |
yes, I meant that by pointing out that the same tests that run with |
Yeah, let's fix that and ensure they're in line. |
Chiming in here. We should have one sign function, we should better understand why there are two and see if we can deprecate one. If we have to ways of signing that do the samething one should be removed not fixed to match the other. Please always think of less code is less to maintain. |
Absolutely, I'll check that |
IIRC, there is one way to sign. But we provide methods with explicit and implicit usage of private keys. |
Both Another option, if the intention is to keep both, is to have |
After a quick search on sourcegraph this function is definitely used:
|
ok, so refactoring it would have a considerable impact on those repos. |
works with me. In the future they may both be deprecated so may not be worth doing it now |
Summary of Bug
Currently, the
client/tx/tx.go
file contains two methods:SignWithPrivKey
andSign
. These produce two different signatures with the same input due to a difference in their behaviors.Version
v0.40.1
Steps to Reproduce
While trying to use the Cosmos SDK as a library to build, sign and broadcast some transactions I ran into a difference of behavior between
Sign
andSignWithPrivKey
.Here is the code I used to sign with
SignWithPrivKey
:Sign with SignWithPrivKey code
At the same time, I was trying to sign the same transaction with the following CLI command:
Sign with Sign method code
I made sure that the account address, number and sequence were the same. However, using
SignWithPrivKey
kept returning the following error when I tried broadcasting the transaction:After debugging the behavior of
Sign
andSignWithPrivKey
, I noticed thatSign
performs the following operations:As you can see, the
Sign
method adds anil
signature under the hood, so that it can properly sign the data using theSIGN_MODE_DIRECT
method. This, however, is not done by theSignWithPrivKey
method.After I added the following code before calling
SignWithPrivKey
, everything worked properly:I think that it might be better to add the same code also to
SignWithPrivKey
, as it might be a method particularly used by third-parties that want to make sure they sign everything correctly.For Admin Use
The text was updated successfully, but these errors were encountered: