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

Generalise to reddsa crate #87

Closed
wants to merge 2 commits into from
Closed

Conversation

str4d
Copy link
Contributor

@str4d str4d commented May 8, 2021

An implementation of RedJubjub or RedPallas on its own is very small, and something that could be implemented separately for zebrad and zcashd (although the Zcash Foundation has already proposed replacing zcashd's implementation of RedJubjub with this one).

However, the introduction of FROST for threshold multisignatures adds significant implementation complexity. I worked out a rough breakdown of the codebase (module lines, including whitespace and comments):

  • 32% keys, signatures, signing, single verification, common utilities / errors
  • 27% batch verification
  • 41% FROST

FROST in this crate is building on RedDSA, which was intentionally designed to be generic and curve-independent; this means that it should equally apply to RedJubjub (for Sapling) and RedPallas (for Orchard). But reimplementing all this logic for a second time in Rust is not an effective use of engineering resources (that could instead be directed to this implementation).

This PR takes the generalisation approach:

  • The crate is renamed from redjubjub to reddsa (a crate name I have already secured for this purpose).
  • SpendAuth and Binding traits are introduced. Both traits depend on the existing sealed traits (and use them to inherit common curve details).
    • The RedJubjub implementation is generalised to RedDSA. The RedJubjub-specific logic is moved into a sapling module.
    • The FROST implementation, which was previously restricted to RedJubjub SpendAuth signatures, is now similarly typed on S: SpendAuth.

Still todo:

  • Rebase once jubjub 0.7 #117 is merged.
  • Write a new redjubjub crate that wraps reddsa. This would probably make sense to live in this repo as part of a workspace.
  • Try to remove RedJubjub-specific code from reddsa. This might require un-sealing some traits, and then re-applying seals in redjubjub.

Comment on lines +8 to +13
// This should not exist, but is necessary to use zeroize::DefaultIsZeroes.
impl Default for SpendAuth {
fn default() -> Self {
unimplemented!()
}
}
Copy link
Contributor Author

@str4d str4d May 9, 2021

Choose a reason for hiding this comment

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

This is necessary because a DefaultIsZeroes: Default bound on Foo<S> requires S: Default. Per the comment in the commit message for 2745d37 we could replace DefaultIsZeroes with explicit Zeroize and Drop derives; I think we should do that (because having a panicking S::default() on an unconstructable type will create a Bad Time for someone.

Copy link
Contributor

Choose a reason for hiding this comment

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

I created an issue to do this later ZcashFoundation/reddsa#1

README.md Outdated Show resolved Hide resolved
@str4d
Copy link
Contributor Author

str4d commented Sep 16, 2021

I've rebased this on #131 so it includes both the latest ff trait stack, and the latest changes from main.

The last time we discussed this PR, we decided it would make sense for it to implement a workspace with both reddsa and redjubjub crates. I have not implemented this yet.

@str4d
Copy link
Contributor Author

str4d commented Nov 18, 2021

To unblock an orchard release, @teor2345 and I decided to proceed with a separate minimal reddsa repo; we can decide on how to set up a workspace later. I've updated this PR to address @daira's comment. I will rebase the PR again once #131 and #137 are merged, and then this PR branch will become the main branch of the separate repo (to which I will also push Orchard-specific supporting code prior to publishing reddsa 0.1.0).

@conradoplg conradoplg deleted the branch ZcashFoundation:main November 18, 2021 18:24
@conradoplg conradoplg closed this Nov 18, 2021
@conradoplg conradoplg reopened this Nov 18, 2021
@conradoplg conradoplg changed the base branch from dependabot/cargo/jubjub-0.8 to main November 18, 2021 18:54
The prior `SpendAuth` and `Binding` enums have been renamed to
`sapling::{SpendAuth, Binding}`. These might subsequently be removed
from the crate entirely (moving into a wrapping `redjubjub` crate).

The code assumes that scalar and point representations are [u8; 32],
which will be the case for all curves we instantiate RedDSA with for
Zcash.
Copy link
Contributor

@conradoplg conradoplg left a comment

Choose a reason for hiding this comment

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

Looks good, thank you!

There are some minor readability issues which we can address later and I created issues for them, also for some TODOs you mentioned:

The idea here is to not merge this PR but move it to the reddsa repo, right?

Comment on lines +8 to +13
// This should not exist, but is necessary to use zeroize::DefaultIsZeroes.
impl Default for SpendAuth {
fn default() -> Self {
unimplemented!()
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I created an issue to do this later ZcashFoundation/reddsa#1

@str4d
Copy link
Contributor Author

str4d commented Nov 19, 2021

The idea here is to not merge this PR but move it to the reddsa repo, right?

Correct. Eventually we will likely rectify the two repositories into a single workspace, but to unblock the orchard crate the separate repository is faster. Once we're ready to create the workspace, we can open a new PR here with the changes from the reddsa repo, then delete the current reddsa repo and rename this repo to reddsa.

This PR is now ZcashFoundation/reddsa@878dd13, and that repo also has two extra commits with Orchard support: ZcashFoundation/reddsa@878dd13...b915593

@str4d str4d closed this Nov 19, 2021
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