Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

contracts: Sr25519 (Schnorrkel) signature verification #13703

Closed
goastler opened this issue Mar 21, 2023 · 6 comments · Fixed by #13724
Closed

contracts: Sr25519 (Schnorrkel) signature verification #13703

goastler opened this issue Mar 21, 2023 · 6 comments · Fixed by #13724
Assignees
Labels
J0-enhancement An additional feature request. Z1-easy Can be fixed primarily by duplicating and adapting code by an intermediate coder

Comments

@goastler
Copy link

Questions

  • Is this a bug concerning building of ink! smart contracts?
    • no
  • Is this a bug that appears when interacting with smart contracts via the Polkadot JS browser UI?
    • no

FAQ

  • Are you using the nightly Rust channel to compile your smart contract?
  • no
  • Are you using an up-to-date cargo-contract? Check via cargo contract --version.
  • yes
  • Are you using an up-to-date ink! version in your smart contract?
  • yes

Describe the bug
I cannot verify a sr25519 (schnorrkel) signature.

Expected behavior
Ability to verify a sr25519 (schnorrkel) signature in a manner similar to the ecdsa_recover() function.

Screenshots

Additional context
Our business logic dictates that we need to sign a payload on our frontend using the polkadot JS extension. Unfortunately, the keyring used by the extension stores the keys in sr25519 format and provide no functionality to load keys in a different format.

We need to verify these sr25519 signatures in ink. However, only ecdsa verification is currently provided via the ecdsa_recover() function. As we cannot access ecdsa on the polkadot JS extension, ecdsa_recover() is a no-go.

I've managed to add the schnorrkel crate to our ink contract and successfully verify sr25519 signatures from the frontend. Anyone wanting to do the same can see our ink contract code here and js code here (one thing to note is that the polkadot js extension wraps the payload to sign in a <Bytes> tag - this was a big "gotcha!" for us).

My question is: is sr25519 going to be implemented in ink? Or is importing the schnorrkel crate the only option? Schnorrkel adds ~30KB to the contract size, which is an unfortunate but necessary hit for us at the moment.

@goastler
Copy link
Author

@forgetso

@goastler
Copy link
Author

corresponding polkadot js extension issue: polkadot-js/extension#1237

@shunsukew
Copy link
Contributor

shunsukew commented Mar 24, 2023

It is possible to do Sr25519/Ed25519 signature verification in ink! by using chain extensions (pallet-contracts extension).
And it worked as expected in my local environment AstarNetwork/astar-frame#141, although still work in progress.

However, I also would like to know about potential ink! native multi signature schemes verification support, and current plans.

@athei
Copy link
Member

athei commented Mar 24, 2023

As a cryptographic primitive which is native to substrate we should include such a function into the core API of pallet-contracts.

@athei athei transferred this issue from use-ink/ink Mar 24, 2023
@athei athei changed the title Sr25519 (Schnorrkel) signature verification contracts: Sr25519 (Schnorrkel) signature verification Mar 24, 2023
@github-actions github-actions bot added the J2-unconfirmed Issue might be valid, but it’s not yet known. label Mar 24, 2023
@athei athei added J0-enhancement An additional feature request. Z1-easy Can be fixed primarily by duplicating and adapting code by an intermediate coder and removed J2-unconfirmed Issue might be valid, but it’s not yet known. labels Mar 24, 2023
@pgherveou pgherveou moved this from Backlog 🗒 to In Progress 🛠 in Smart Contracts Mar 29, 2023
@athei athei moved this from In Progress 🛠 to Code in review 🧐 in Smart Contracts Mar 30, 2023
@github-project-automation github-project-automation bot moved this from Code in review 🧐 to Done ✅ in Smart Contracts Apr 12, 2023
@burdges
Copy link

burdges commented Apr 13, 2023

Ink should use the substrate host calls for sr25519, no?

@athei
Copy link
Member

athei commented Apr 14, 2023

Yes. The PR that closes this issue did exactly this. It exposes this host functions to contracts.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
J0-enhancement An additional feature request. Z1-easy Can be fixed primarily by duplicating and adapting code by an intermediate coder
Projects
Status: No status
Development

Successfully merging a pull request may close this issue.

5 participants