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

Optimize bls #122

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

Optimize bls #122

wants to merge 6 commits into from

Conversation

spalmer25
Copy link
Collaborator

This PR add optimization to BLS signing.

  • Stop hashing if the hash is not required.
  • Store the public key and use it in the signature (instead of derivates it again)

Unused if the command is SIGN and the curve of the signee key is BLS
@spalmer25 spalmer25 self-assigned this Oct 31, 2024
@spalmer25 spalmer25 marked this pull request as ready for review October 31, 2024 10:08
prepare to stop derivating the pk too frequently
Since `global.public_key` is the key associated to
`global.path_with_curve`, if the `path_with_curve` to derive is equal
to `global.path_with_curve`, then the key associated to the
`path_with_curve` is `global.public_key`. There is no need to
re-derive it again.
#ifndef TARGET_NANOS
// There is no need to hash the message if it is not used for signing or if it is not sent at
// the end.
if (with_hash || (global.path_with_curve.derivation_type != DERIVATION_TYPE_BLS12_381)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

What is the purpose of with_hash here. Is it used for BLS.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I mean if the derivation type is BLS dont hash at all.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The with_hash comes from the request SIGN_WITH_HASH.
We have to compute/send it if the sender requests it.

@@ -33,6 +33,26 @@
#include <stdint.h>
#include <string.h>

tz_exc read_path_with_curve(derivation_type_t derivation_type,
Copy link
Collaborator

Choose a reason for hiding this comment

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

The derivation type is selected at the time of setup. It can not be changed during signing. so it makes sense to derivce the public key when read_path_with_curve is called from handle_setup. Rather create a new function setup_path_with_curve and derive public key there along with a call to read_path_with_curve. Call setup_path_with_curve from handle_setup and read_path_with_curve from other places.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The SETUP instruction is not required to sign:

  • AUTHORIZE_BAKING will setup the authorized key too.
  • If the authorized key was present in the RAM, SIGN with index 0x00 will tell which public key to sign with

The aims of this function is too make sure that, every time the stored Bip32-path-with-curve is updated, the stored PK is updated to.

TZ_ASSERT(read_bip32_path(buf, &tmp_path_with_curve.bip32_path), EXC_WRONG_VALUES);

// Do not derive the public key if the two path_with_curve are equal
if (!bip32_path_with_curve_eq(path_with_curve, &tmp_path_with_curve)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

It seems my previous comment is addressed here. you can still think if a setup_path_with_curve makes sense.

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.

2 participants