Skip to content

Conversation

@danlaine
Copy link
Collaborator

@danlaine danlaine commented May 23, 2025

Resolves: #755
Resolves: #1049
Unblocks: #432

This PR updates the cryptography traits defined in cryptography/src/lib.rs. Notably, it removes Specification and Scheme. The new crypto design has several interlocking traits:

  • A Signer is capable of producing a signature over a message
  • A Verifier is capable of verifying a signature over a message
  • A PrivateKey is a Signer that is serializable and had a PublicKey
  • A PublicKey is a Verifier that is serializable

The vast majority of the diff is updating downstream code. There are also many generic types C: Scheme (Scheme in the old code is most analogous to PrivateKey in the new code) that have been turned into C: PublicKey because they don't rely on private key capabilities.

@danlaine danlaine self-assigned this May 30, 2025
@danlaine danlaine marked this pull request as ready for review June 3, 2025 17:04
@danlaine danlaine changed the title [crypto] [WIP] Refactor crypto traits [crypto] Refactor crypto traits Jun 3, 2025
message: &[u8],
public_key: &Self::PublicKey,
signature: &Self::Signature,
public_key: &K::PublicKey,
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we may be able to get away with impl PublicKey and impl Signature?

Copy link
Contributor

Choose a reason for hiding this comment

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

I suppose they should be fixed for a single instance of a BatchVerfier (so maybe we should make both generic)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm not sure I follow. We can't put impl PublicKey / impl Signature because a BatchVerifier is parameterized on a PublicKey type, so it can only verify using its PublicKey type and associated Signature.

@danlaine danlaine marked this pull request as draft June 3, 2025 21:45
@patrick-ogrady patrick-ogrady changed the title [crypto] Refactor crypto traits [cryptography] Refactor Scheme Jun 3, 2025
@patrick-ogrady patrick-ogrady marked this pull request as ready for review June 3, 2025 23:18
@patrick-ogrady patrick-ogrady merged commit 2aa10dd into main Jun 3, 2025
15 checks passed
@patrick-ogrady patrick-ogrady deleted the danlaine/crypto-refactor-2 branch June 3, 2025 23:30
@codecov
Copy link

codecov bot commented Jun 4, 2025

Codecov Report

Attention: Patch coverage is 98.50058% with 13 lines in your changes missing coverage. Please review.

Project coverage is 91.09%. Comparing base (0fd24f3) to head (c6da8b7).
Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
cryptography/src/ed25519/scheme.rs 87.09% 8 Missing ⚠️
cryptography/src/bls12381/scheme.rs 89.28% 3 Missing ⚠️
consensus/src/ordered_broadcast/mocks/reporter.rs 75.00% 1 Missing ⚠️
p2p/src/authenticated/types.rs 93.33% 1 Missing ⚠️
@@            Coverage Diff             @@
##             main     #991      +/-   ##
==========================================
- Coverage   91.18%   91.09%   -0.10%     
==========================================
  Files         191      191              
  Lines       54967    54836     -131     
==========================================
- Hits        50124    49954     -170     
- Misses       4843     4882      +39     
Files with missing lines Coverage Δ
broadcast/src/buffered/mod.rs 99.58% <100.00%> (ø)
consensus/src/ordered_broadcast/ack_manager.rs 100.00% <100.00%> (ø)
consensus/src/ordered_broadcast/engine.rs 89.67% <100.00%> (+0.01%) ⬆️
consensus/src/ordered_broadcast/mod.rs 99.61% <100.00%> (+<0.01%) ⬆️
consensus/src/ordered_broadcast/tip_manager.rs 100.00% <100.00%> (ø)
consensus/src/ordered_broadcast/types.rs 98.24% <100.00%> (-0.01%) ⬇️
consensus/src/simplex/actors/resolver/actor.rs 92.07% <100.00%> (ø)
consensus/src/simplex/actors/resolver/ingress.rs 100.00% <ø> (ø)
consensus/src/simplex/actors/voter/actor.rs 92.83% <100.00%> (ø)
consensus/src/simplex/actors/voter/ingress.rs 100.00% <ø> (ø)
... and 41 more

... and 1 file with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0fd24f3...c6da8b7. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

[cryptography] Clarify namespace in Signer::sign interface [cryptography] Cleanup Trait Definition

2 participants