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

Redjubjub signature verifier service #460

Merged
merged 13 commits into from
Jul 8, 2020
Merged

Redjubjub signature verifier service #460

merged 13 commits into from
Jul 8, 2020

Conversation

dconnolly
Copy link
Contributor

And stub of redjubjub::BatchVerifier.

@dconnolly dconnolly added the A-rust Area: Updates to Rust code label Jun 10, 2020
@dconnolly dconnolly added this to the Validate transactions. milestone Jun 10, 2020
@dconnolly dconnolly linked an issue Jun 10, 2020 that may be closed by this pull request
@codecov
Copy link

codecov bot commented Jun 10, 2020

Codecov Report

Merging #460 into main will increase coverage by 0.30%.
The diff coverage is 86.27%.

@@            Coverage Diff             @@
##             main     #460      +/-   ##
==========================================
+ Coverage   57.95%   58.25%   +0.30%     
==========================================
  Files          91       92       +1     
  Lines        4419     4470      +51     
==========================================
+ Hits         2561     2604      +43     
- Misses       1858     1866       +8     

yaahc
yaahc previously approved these changes Jun 10, 2020
Copy link
Contributor

@yaahc yaahc left a comment

Choose a reason for hiding this comment

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

🔥

zebra-consensus/src/verify/redjubjub.rs Outdated Show resolved Hide resolved
@dconnolly
Copy link
Contributor Author

I will be closing this PR and moving the updated batch verifier (to work with the new tower-batch) into ZcashFoundation/redjubjub

@hdevalence
Copy link
Contributor

@dconnolly The batch verification implementation makes sense to have in the upstream redjubjub crate, but I think that the async tower-based interface to it is probably better here — my experience with ed25519-zebra was that it was much easier to maintain just the synchronous, IUF-style API in the library crate. Also, I don’t think we would be able to publish a version of redjubjub that depended on tower-batch, since got dependencies are not allowed in published crates.

@dconnolly
Copy link
Contributor Author

@dconnolly The batch verification implementation makes sense to have in the upstream redjubjub crate, but I think that the async tower-based interface to it is probably better here — my experience with ed25519-zebra was that it was much easier to maintain just the synchronous, IUF-style API in the library crate. Also, I don’t think we would be able to publish a version of redjubjub that depended on tower-batch, since got dependencies are not allowed in published crates.

Good point, I'll keep this open and update it with the tower interface layer and update redjubjub with its own batch::Verifier

@dconnolly dconnolly force-pushed the redjubjub-verifier branch 2 times, most recently from 6bd45de to 88121d4 Compare June 26, 2020 23:49
@dconnolly dconnolly changed the title [WIP] Add singleton redjubjub signature verifier service [WIP] Redjubjub signature verifier service Jun 26, 2020
@dconnolly dconnolly changed the title [WIP] Redjubjub signature verifier service Redjubjub signature verifier service Jun 27, 2020
@dconnolly dconnolly marked this pull request as ready for review June 27, 2020 03:51
@dconnolly dconnolly requested a review from yaahc June 27, 2020 03:51
@dconnolly
Copy link
Contributor Author

If I only run the redjubjub tests, they pass. When running with all tests, I see inconsistent failures:

image

@dconnolly
Copy link
Contributor Author

why was this removed?

image

@dconnolly
Copy link
Contributor Author

why was this removed?

image

I don't know why this worked fine when used similarly in here but removing it allowed all tests to pass.

@yaahc
Copy link
Contributor

yaahc commented Jun 27, 2020

okay, that's a bug. Removing the init will disable our logging and error handling stuff, so we want that to work. I'll open a separate issue to add them back and fix the bug though

@teor2345
Copy link
Contributor

okay, that's a bug. Removing the init will disable our logging and error handling stuff, so we want that to work. I'll open a separate issue to add them back and fix the bug though

Looks like there's a panic in one of the functions that's called during the Once.

Do we have any other copies of the old tracing code in the codebase?
The panic could be happening due to a race between the old code and the Once code.

futures-util = "0.3.5"
tower = "0.3.1"
rand = "0.7"
redjubjub = { git = "https://github.com/ZcashFoundation/redjubjub.git", branch = "batch" }
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd prefer to wait to merge this until we can depend on a published version of redjubjub, but that can happen essentially as soon as it's ready.

mod script;
mod transaction;

pub use self::redjubjub::{RedJubjubItem, RedJubjubVerifier};
Copy link
Contributor

Choose a reason for hiding this comment

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

naming: if the types are called just Item and Verifier, this reëxport can be dropped and users can choose how much they want to qualify the name, depending on their context, either redjubjub::Item and redjubjub::Verifier or Item and Verifier. I think this is more flexible than including RedJubjub in the struct names.

Copy link
Contributor

Choose a reason for hiding this comment

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

(There's then a potential naming overlap between the redjubjub crate's Verifier type and this one, but this is only ambiguous when code needs to refer to both synchronous and asynchronous batch verification APIs, which only happens in this specific module, otherwise people just use one or the other).

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 this would still be good to do. More rationale: rust-lang/rfcs#356

@hdevalence
Copy link
Contributor

👍 Nice work! The only comments I have are about naming. I guess the API might change slightly when the (sync) batch code is updated to cover both signature types.

chrono = "0.4.11"
color-eyre = "0.5"
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 probably be a dev-dependency

zebra-consensus/src/verify/redjubjub.rs Outdated Show resolved Hide resolved
let sig = sk.sign(rng, &msg[..]);

verifier.ready_and().await?;
results.push(span.in_scope(|| verifier.call((vk.into(), sig, msg).into())))
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this in_scope does what is intended, this would enter span for the duration of call, which then returns a future, but then it would push an uninstrumented future into the results. If you want the span to be active while the future is being polled you should use instrument

Suggested change
results.push(span.in_scope(|| verifier.call((vk.into(), sig, msg).into())))
results.push(verifier.call((vk.into(), sig, msg).into()).instrument(span))

@dconnolly
Copy link
Contributor Author

Ugh I messed up with my rebases.

Copy link
Contributor

@hdevalence hdevalence left a comment

Choose a reason for hiding this comment

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

I think we should change the names to remove the module prefix but otherwise this looks great!

@dconnolly dconnolly requested a review from hdevalence July 7, 2020 23:05
@yaahc yaahc removed their request for review July 7, 2020 23:30
hdevalence
hdevalence previously approved these changes Jul 8, 2020
Copy link
Contributor

@hdevalence hdevalence left a comment

Choose a reason for hiding this comment

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

Awesome!!

@dconnolly dconnolly merged commit 2cd58c8 into main Jul 8, 2020
@dconnolly dconnolly deleted the redjubjub-verifier branch July 8, 2020 21:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-rust Area: Updates to Rust code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement a RedJubjubVerifier service
4 participants