-
Notifications
You must be signed in to change notification settings - Fork 386
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
feat: verifySignature function #2776
base: master
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
📢 Thoughts on this report? Let us know! |
76ec144
to
74ed842
Compare
74ed842
to
707ba33
Compare
CI failed. could you please check and fix this? |
I think it is ok just one does not want to finish do not know why |
98a6ec0
to
43e14eb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked it purely through test runs, it executed well without any significant issues.
Although I also looked into related issues, it might be better to conduct a more detailed review in the next stage.
remove: review/triage-pending
I'm still not convinced by this approach. I think we should have verification happen at the protol level rather than happen at the Gno level. Can we not use the message signers as I pointed out in the discussion on #2777? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the direction, but we need better naming and more tests 🙏
Thinking about this a bit, let's discuss if it's even required, and why
@@ -0,0 +1,14 @@ | |||
package main |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not add multiple stdlib tests for valid and invalid signature verification?
t.Error("verify failed") | ||
} | ||
|
||
if signer != info.GetAddress().String() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assert.Equal
} | ||
|
||
signatureValid, _ = X_verifySignature(publicKey, maliciousMessage, signatureHex) | ||
if signatureValid { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assert.True
func TestVerify(t *testing.T) { | ||
kb := keys.NewInMemory() | ||
pass := "hardPass" | ||
info, err := kb.CreateAccount("user", DefaultAccount_Seed, pass, pass, 0, 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need to use the keybase to generate a key, you can just use something like ed25519.GenPrivKey()
or even better secp256k1.GenPrivKey()
, which will mimic what the keybase is doing under the hood
Not to mention it is exponentially faster 🚀
@@ -192,3 +196,31 @@ func TestPrevRealmIsOrigin(t *testing.T) { | |||
}) | |||
} | |||
} | |||
|
|||
func TestVerify(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be named TestVerifyECSignature
or something similar
@@ -150,6 +152,22 @@ func X_encodeBech32(prefix string, bytes [20]byte) string { | |||
return b32 | |||
} | |||
|
|||
func X_verifySignature(pubKeySigner string, msg string, signature string) (bool, string) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, let's rename this method to something more descriptive, since this is the sig verification method for both ed25519 and secp256k1. What do you think about VerifyECSignature
, as the name for the native method?
Also, I'd rename the args here:
pubKeySigner
->bech32PubKey
(to be explicit)msg
->rawData
(and please make this a[]byte
)- change the type of
signature
to[]byte
@@ -56,6 +56,10 @@ func DecodeBech32(addr Address) (prefix string, bz [20]byte, ok bool) { | |||
return decodeBech32(string(addr)) | |||
} | |||
|
|||
func VerifySignature(pubKeySigner string, signature string, msg string) (bool, string) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check my comment below for the rename 🙏
) | ||
|
||
const DefaultAccount_Seed = "source bonus chronic canvas draft south burst lottery vacant surface solve popular case indicate oppose farm nothing bullet exhibit title speed wink action roast" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, drop this
@thehowl I'm not necessarily for or against this idea, but I'd like to hear why @Villaquiranm would need signature verification on-chain through native methods 👀 For reference, Ethereum has native methods in Solidity for deriving the address from the ECDSA signature, but not for verifying it (there are library contracts that people can import and use) -- which supports the argument that sig verification is something that should be done off-chain |
🛠 PR Checks Summary🔴 Maintainers must be able to edit this pull request (more info) Manual Checks (for Reviewers):
Read More🤖 This bot helps streamline PR reviews by verifying automated checks and providing guidance for contributors and reviewers. ✅ Automated Checks (for Contributors):🔴 Maintainers must be able to edit this pull request (more info) ☑️ Contributor Actions:
☑️ Reviewer Actions:
📚 Resources:Debug
|
related to #2777
Contributors' checklist...
BREAKING CHANGE: xxx
message was included in the description