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

Change to better distinguish signature schemes #19

Merged
merged 1 commit into from
Aug 1, 2024

Conversation

ureeves
Copy link
Member

@ureeves ureeves commented Jul 31, 2024

It is currently possible to call the APK::verify or PublicKey::verify on the same signature type, leading to situations where even if a user is technically allowed to call the function, verification is in principle impossible, since the signature schemes used to produce a signature are different. Furthermore, the sign_vulnerable function is arguably misnamed, since it is only actually vulnerable to a rogue key attack when used in a multi-signature context.

In the interest of fixing this, this commit introduces a couple of changes to the API of the crate, designed to better distinguish and clarify the usage of the two different signature schemes it provides.

First and foremost, a new signature type - MultisigSignature is added, representing a signature produced using the multi-signature scheme. Conversely, the already existing Signature type is taken to mean the a signature produced using the single-key scheme.
The functions under SecretKey, sign_vulnerable and sign, are respectivelly renamed into sign and sign_multisig, and the latter is changed to return the new MultisigSignature type. The "aggregated public key" type is renamed from APK into MultisigPublicKey, to better denote its use and to be in line with the kind signature it can now verify using the verify function - which is changed to take a MultisigSignature.

On a more subtle note, the From<&PublicKey> and From<&SecretKey> implementations for MultisigPublicKey, formerly APK are removed and the API of MultisigPublicKey::aggregate is changed to not take &self, and only take a slice of PublicKey. This is designed to promote the intended usage of the struct - aggregating a collection of public keys, as opposed to just "aggregating" one.

Resolves: #18

Copy link
Member

@herr-seppia herr-seppia left a comment

Choose a reason for hiding this comment

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

LGTM

src/keys/public.rs Show resolved Hide resolved
Copy link
Member

@xevisalle xevisalle left a comment

Choose a reason for hiding this comment

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

I would consider calling it MultiSignature. Beyond that, LGTM.

derive(Archive, Deserialize, Serialize),
archive_attr(derive(bytecheck::CheckBytes))
)]
pub struct MultisigSignature(pub(crate) G1Affine);
Copy link
Member

Choose a reason for hiding this comment

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

Doesn't feel redundant to call it Multi signature signature?

Copy link
Member Author

Choose a reason for hiding this comment

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

I feel like I would then also have to change the name of MultisigPublicKey to have the pair of:

  • MultiPublicKey
  • MultiSignature

I don't like it though, since the concept of "multi-sig" refers specifically to the scheme, not the structure, and erasing it would kind of defeat the purpose of this PR.

It is currently possible to call `APK::verify` or `PublicKey::verify` on
the same signature type, leading to situations where even if a user is
technically *allowed* to call the function, verification is in principle
impossible, since the signature schemes used to produce a signature are
different. Furthermore, the `sign_vulnerable` function is arguably
misnamed, since it is only actually vulnerable to a rogue key attack
*when used in a multi-signature context*.

In the interest of fixing this, this commit introduces a couple of changes
to the API of the crate, designed to better distinguish and clarify the
usage of the two different signature schemes it provides.

First and foremost, a new signature type - `MultisigSignature` is added,
representing a signature produced using the multi-signature scheme.
Conversely, the already existing `Signature` type is taken to mean the a
signature produced using the single-key scheme.
The functions under `SecretKey`, `sign_vulnerable` and `sign`, are
respectively renamed into `sign` and `sign_multisig`, and the latter is
changed to return the new `MultisigSignature` type.
The "aggregated public key" type is renamed from `APK` into
`MultisigPublicKey`, to better denote its use and to be in line with the
kind signature it can now verify using the `verify` function - which is
changed to take a `MultisigSignature`.

On a more subtle note, the `From<&PublicKey>` and `From<&SecretKey>`
implementations for `MultisigPublicKey`, formerly `APK` are removed and
the API of `MultisigPublicKey::aggregate` is changed to *not* take
`&self`, and only take a slice of `PublicKey`. This is designed to
promote the intended usage of the struct - aggregating a collection of
public keys, as opposed to just "aggregating" one.

Resolves: #18
@ureeves ureeves force-pushed the rename-sign-vulnerable branch from 1954cc2 to d428201 Compare August 1, 2024 10:56
@ureeves ureeves merged commit 8c2e945 into main Aug 1, 2024
6 checks passed
@ureeves ureeves deleted the rename-sign-vulnerable branch August 1, 2024 11:00
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.

Refactor SecretKey signatures methods
3 participants