3

We faced a situation the other day where we needed some result of std operations inside of our benchmarks. Specifically, we were looking to generate key pairs and signatures from types given by app_crypto!(Pair and Signature). I imagine there are plenty of other use cases for performing operations depending on std though. So I was curious if there is any existing way around this limitation at the moment.

1
  • Could you please share the code or some snippets of it? Maybe the benchmarking code that does not work? There is a sig-verify example here. Aug 12, 2022 at 11:11

2 Answers 2

1

Ultimately, there's no "right" way to do it. Some script outside of the benchmark would have to be run to generate the values. Here's a FRAME example where primitive types such as keypairs are generated and scale-encoded in the script, and decoded in the benchmark.

0

We faced a situation the other day where we needed some result of std operations inside of our benchmarks.

There is two ways this goes:

  • It runs in the runtime and is therefore no-std: Use the pallet benchmarking.
  • It is std and does not run in the runtime: Use some other benchmarking tools like criterion. However I dont see where this could be needed, since pallet benchmarks cover everything that is normally needed.

I imagine there are plenty of other use cases for performing operations depending on std though.

No. Since the runtime is entirely no-std and the benchmarks only cover on-chain code.
The only exception is the setup phase, where it would be reasonable to have no-std access for convenience. Otherwise all setup code needs to be no-std as well which is annoying.

Specifically, we were looking to generate key pairs and signatures from types given by app_crypto!(Pair and Signature).

I dont understand why you generate key-pairs on-chain. These are public for everyone to see.

2
  • Forgot about this issue. I found a pretty good example that I'll link. To be clear, I'm not generating key-pairs on-chain. I'm not sure why you're suggesting that I was doing that. Nov 22, 2022 at 15:02
  • 1
    Though I do see the value of posting safe reminders like this on SE, out of abundance of caution 👍 Nov 22, 2022 at 15:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.