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

Speed up JoinSplit proving by running is_satisfied() only if verification fails #2005

Closed
tromer opened this issue Jan 10, 2017 · 13 comments
Closed
Assignees
Labels
A-circuit Area: zk-SNARK circuits I-error-handling Problems and improvements related to error handling I-performance Problems and improvements with respect to performance

Comments

@tromer
Copy link
Contributor

tromer commented Jan 10, 2017

Creating a JoinSplit currently spends about 1 second merely doing an is_satisfied() sanity check on the witness.

VTune analysis of CreateJoinSplit: vtune-createjoinsplit-is_satisfied

The implementation of r1cs_constraint_system<FieldT>::is_satisfied() (in libsnark's r1cs.tcc) is single-threaded, and can be easily parallelized to reduce the wallclock time.

Alternatively, the call can be removed, relying just on the eventual verification (when entering the local mempool?) as a sanity check.

@ebfull
Copy link
Contributor

ebfull commented Jan 10, 2017

Concept ACK.

I like the approach of removing the call; it is (theoretically) not possible to use the API to construct an invalid proof, and we have tests for all the known cases in which the constraint system would be violated. It's an assertion that is done inside of JoinSplitCircuit::prove() -- feel free to open a PR that removes this call.

@tromer tromer changed the title Parallel or remove is_satisfied() to speed up JoinSplit creation Parallelize or remove is_satisfied() to speed up JoinSplit creation Jan 10, 2017
@daira
Copy link
Contributor

daira commented Jan 10, 2017

NACK to removing the call, at least for now. Actually, let's not try to optimise it either until we have fixed the bug(s) mentioned below.

We left this check deliberately to get better diagnostics for cases where the constraint system is not satisfied (and also, to get those diagnostics by an assertion on the node where the actual problem is, not when the proof is verified by other nodes). In fact we only recently improved that error reporting, in #1752, because we have at least one bug that causes is_satisfied to fail (#1668, which had been incorrectly closed). It's too early to remove this just for a 1-second speedup.

@daira daira added I-performance Problems and improvements with respect to performance A-circuit Area: zk-SNARK circuits labels Jan 10, 2017
@tromer
Copy link
Contributor Author

tromer commented Jan 10, 2017

Agreed about removing, but why not parallelize?

@ebfull
Copy link
Contributor

ebfull commented Jan 10, 2017

I don't personally believe there is much purpose to the assertion anymore.

@daira
Copy link
Contributor

daira commented Jan 10, 2017

@tromer: because we might accidentally break it, and that's a disruptive thing to do while we still have bugs that fail the check.

@ebfull: I'll be happy to remove it when we're confident that it can't actually fail, but that is not the case now, and the diagnostics produced by #1752 in the meantime could be useful.

@daira
Copy link
Contributor

daira commented Jan 10, 2017

Oh, I hadn't seen that #1752 is intended to make this check redundant. Hmm. On reflection I still think we should wait until we've resolved #1668.

@ebfull
Copy link
Contributor

ebfull commented Jan 10, 2017

We have no reason to believe there are any outstanding bugs with the diagnostics. #1668 was filed before any diagnostics were added. There were bugs in the wallet which would trigger the assertion. In order to find them, we improved the diagnostics and closed that ticket. We eventually did find and fix them.

The assertion, to my knowledge, has not been triggered by users since #1797 was merged.

@tromer
Copy link
Contributor Author

tromer commented Jan 10, 2017

How about running the SNARK verifier on the proof, locally, while the R1CS is still instantiated, and if that fails, running is_satisfiable()?

Since the SNARK verifier is much faster, that gives the best of both worlds (assuming soundness, and if soundness is violated, then diagnostics of bad witness on honest nodes is the least of our concerns.)

@daira
Copy link
Contributor

daira commented Jan 10, 2017

I like @tromer's idea.

@daira daira changed the title Parallelize or remove is_satisfied() to speed up JoinSplit creation Speed up JoinSplit proving by running is_satisfied() only if verification fails Apr 20, 2017
@daira
Copy link
Contributor

daira commented Jul 13, 2017

Does anyone have any objection to @tromer's idea? I think it achieves the best of both worlds (performance and good diagnostics). It's also what we recommend doing in https://z.cash/blog/pay-to-sudoku-revisited.html , BTW ("As an additional precaution, verify the proof after you construct it!").

It should be orthogonal to Sapling.

@ebfull
Copy link
Contributor

ebfull commented Jul 14, 2017

@daira I don't object.

@daira
Copy link
Contributor

daira commented Oct 13, 2017

I'll file a PR for this on top of #2243 #2670.

@daira daira self-assigned this Oct 22, 2017
@daira daira added the I-error-handling Problems and improvements related to error handling label Oct 22, 2017
@str4d str4d added this to the 1.0.15 milestone Jan 2, 2018
@str4d str4d modified the milestones: 1.0.15, 1.1.0 Jan 26, 2018
@str4d str4d modified the milestones: v1.1.0, v2.0.0, v1.1.1 Mar 30, 2018
@str4d str4d modified the milestones: v1.1.1, v2.0.0 Jun 19, 2018
@daira daira modified the milestones: v2.0.0, v2.0.1 Aug 16, 2018
@str4d str4d removed this from the v2.0.1 milestone Oct 8, 2018
@str4d
Copy link
Contributor

str4d commented Oct 8, 2018

We never found time to do this, and with Sapling activation in three weeks, we won't be using the libsnark prover for much longer (and certainly not by the time the next release happens). So there's no longer a benefit to implementing this (beyond slightly speeding up tests, but we will be migrating those to use hybrid Sprout proofs instead at some point).

@str4d str4d closed this as completed Oct 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-circuit Area: zk-SNARK circuits I-error-handling Problems and improvements related to error handling I-performance Problems and improvements with respect to performance
Projects
None yet
Development

No branches or pull requests

5 participants