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

feat: verifySignature function #2776

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

Villaquiranm
Copy link
Contributor

@Villaquiranm Villaquiranm commented Sep 9, 2024

related to #2777

Contributors' checklist...
  • Added new tests, or not needed, or not feasible
  • Provided an example (e.g. screenshot) to aid review or the PR is self-explanatory
  • Updated the official documentation or not needed
  • No breaking changes were made, or a BREAKING CHANGE: xxx message was included in the description
  • Added references to related issues and PRs
  • Provided any useful hints for running manual tests
  • Added new benchmarks to generated graphs, if any. More info here.

@github-actions github-actions bot added the 📦 🤖 gnovm Issues or PRs gnovm related label Sep 9, 2024
Copy link

codecov bot commented Sep 9, 2024

Codecov Report

Attention: Patch coverage is 89.47368% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
gnovm/stdlibs/std/native.go 60.00% 2 Missing and 2 partials ⚠️

📢 Thoughts on this report? Let us know!

@Villaquiranm Villaquiranm force-pushed the feat/verifySignature branch 3 times, most recently from 76ec144 to 74ed842 Compare September 11, 2024 06:56
@Kouteki Kouteki added the review/triage-pending PRs opened by external contributors that are waiting for the 1st review label Oct 3, 2024
@notJoon
Copy link
Member

notJoon commented Oct 10, 2024

CI failed. could you please check and fix this?

@Villaquiranm
Copy link
Contributor Author

Villaquiranm commented Oct 11, 2024

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
@notJoon

Copy link
Member

@notJoon notJoon left a 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

@notJoon notJoon removed the review/triage-pending PRs opened by external contributors that are waiting for the 1st review label Oct 18, 2024
@thehowl
Copy link
Member

thehowl commented Oct 23, 2024

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?

Copy link
Member

@zivkovicmilos zivkovicmilos left a 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
Copy link
Member

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() {
Copy link
Member

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 {
Copy link
Member

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)
Copy link
Member

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) {
Copy link
Member

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) {
Copy link
Member

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) {
Copy link
Member

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"
Copy link
Member

Choose a reason for hiding this comment

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

Please, drop this

@zivkovicmilos
Copy link
Member

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?

@thehowl
I think what @Villaquiranm is aiming at is having generic signature verification, the signature doesn't have to originate from a message / transaction, but can be arbitrary data we sign and push to the chain (not sure what this use case would be, and why we'd verify sigs on chain).

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

@Gno2D2
Copy link
Collaborator

Gno2D2 commented Jan 8, 2025

🛠 PR Checks Summary

🔴 Maintainers must be able to edit this pull request (more info)

Manual Checks (for Reviewers):
  • IGNORE the bot requirements for this PR (force green CI check)
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:
  1. Fix any issues flagged by automated checks.
  2. Follow the Contributor Checklist to ensure your PR is ready for review.
    • Add new tests, or document why they are unnecessary.
    • Provide clear examples/screenshots, if necessary.
    • Update documentation, if required.
    • Ensure no breaking changes, or include BREAKING CHANGE notes.
    • Link related issues/PRs, where applicable.
☑️ Reviewer Actions:
  1. Complete manual checks for the PR, including the guidelines and additional checks if applicable.
📚 Resources:
Debug
Automated Checks
Maintainers must be able to edit this pull request (more info)

If

🟢 Condition met
└── 🟢 The pull request was created from a fork (head branch repo: TERITORI/gno)

Then

🔴 Requirement not satisfied
└── 🔴 Maintainer can modify this pull request

Manual Checks
**IGNORE** the bot requirements for this PR (force green CI check)

If

🟢 Condition met
└── 🟢 On every pull request

Can be checked by

  • Any user with comment edit permission

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📦 🤖 gnovm Issues or PRs gnovm related
Projects
Status: In Progress
Status: In Review
Development

Successfully merging this pull request may close these issues.

6 participants