Code Monkey home page Code Monkey logo

Comments (3)

akosba avatar akosba commented on July 24, 2024

Hello,

A verifier can easily use runLibsnark() for verification

First, please note that runLibsnark() is not related to the verifier only. This method runs the jsnark-libsnark interface, which reads the files and computes the values of all variables, including the output variables, then calls libsnark::run_r1cs_ppzksnark or libsnark::run_r1cs_gg_ppzksnark  which run all the three algorithms: key generation, proving and verification algorithms that are provided by libsnark. This all happens in a single call (just for demonstration and performance measurement purposes). 
In practice, these algorithms will have to be separated, because key generation, proving and verification will be done at different times by different parties. The separation is not provided in this version of jsnark.

With respect to the outputs and all other intermediate variables, they are not written to a file. They are computed during execution in two places:

  • In jsnark itself when the circuit is evaluated.
  • They are computed internally in the jsnark-libsnark interface when calling run_libsnark(). This is done in the CircuitReader class, after which the assignment of all variables will be ready. 

If you would like to generate a file with the output values, a method can be added to jsnark's CircuitEvaluator class.

public void writeOutputFile() {
		try {
			LinkedHashMap<Instruction, Instruction> evalSequence = circuitGenerator.getEvaluationQueue();

			PrintWriter printWriter = new PrintWriter(circuitGenerator.getName() + ".out");
			for (Instruction e : evalSequence.keySet()) {
				if (e instanceof WireLabelInstruction) {
					WireLabelInstruction inst = (WireLabelInstruction) e;
					if (inst.getType() == LabelType.output) {
						int id = ((WireLabelInstruction) e).getWire().getWireId();
						printWriter.println(id + " " + valueAssignment[id].toString(16) + (inst.getDesc().length() > 0 ? (" \t\t# " + inst.getDesc()) : ""));
					}
				}
			}
			printWriter.close();

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

This will also print any available labels for the output wires beside its value. The above will require adding another method in the WireLabelInstruction class

public String getDesc() {
    return desc;
}

And finally add a call to circuitEvaluator.writeOutputFile(); to prepFiles() of the CircuitGenerator class.

The output values can also be provided to the verifier through other means. For example, the prover could call standard cryptographic libraries and send their outputs in the scenario you mentioned, i.e., the prover does not have to get that from the circuit. (We will need to be sure though that the circuit implements the same algorithm and to format the output properly).

Note that in order to use the above in a meaningful scenario, I think that the separation I referred to above might need to be implemented. For example, this could be done by adding support for a method, e.g., runLibsnarkVerifier, that will call a libsnark executable that takes public* input and output values and a verification key.
(* The .in file includes both public and prover private inputs. The verifier will only need the public inputs.)

from jsnark.

stark1092 avatar stark1092 commented on July 24, 2024

@akosba Thanks for your reply! This is very helpful, let me understand more about jsnark.
So if I want a prover to provide the public input(public key) and public output(proof value, cipherText) of a encryption process, and a verifier to verify these, I need to generate corresponding parameters and call libsnark?
I need to use jsnark to write circuit and generate files(.arith & .in) first, and then split prove/verify in the step of calling libsnark?

from jsnark.

thomaslavaur avatar thomaslavaur commented on July 24, 2024

Has anyone already implemented a runLibsnarkVerifier or runLibsnarkProver to avoid the execution of the three algorithms ?

from jsnark.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.