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

Add example for BLS signature #1153

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Add example for BLS signature #1153

wants to merge 2 commits into from

Conversation

jayz22
Copy link
Contributor

@jayz22 jayz22 commented Dec 21, 2024

@stellar-jenkins
Copy link


### BLS Signature verification

```
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be ```rust


Most of what's here is needed in order to create the contract client and ensure the invocation of its custom account interface for signature authorization. After the setup, calling `env.try_invoke_contract_check_auth` on the client will invoke the `__check_auth` logic we've defined in our contract.

The invocation will return nothing on success, and will panic on failure. The other thing we are interested here is budget consumption for this call. At the beginning setting `env.budget().reset_unlimited()` ensure all the prep work (which emulates the off-chain work needed to be performed by e.g. a smart wallet) will not run out of budget. This isn't strictly necessary since the default budget should be large enough. `env.budget().reset_default()` right before the invocation makes sure the budget is reset to default state (also resetting metering counters) so that we can get an accurate capture of the budget for the invocation alone. `env.budget().print()` at the end prints out the budget.
Copy link
Contributor

Choose a reason for hiding this comment

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

Since SDK 22.0.4 we shouldn't need to do budget resets anymore. We should update the example first, but I think for the doc we can just omit this, so that there is less to change when the example is updated.

Running this test will produce the following budget output, the total cpu consumption for signature verification is around 31M. And you can add as many additional public keys as you like. In general `pairing_check` is a function with linear cost, so the more unique messages that needs to be signed, the higher cost. Here because all signers sign the same content (hash of the call stack of this contract), we can do this in constant time.

```
---- test::test stdout ----
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it make sense to omit all the cost type rows here and just leave the non-zero BLS rows?

@stellar-jenkins
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants