Git Product home page Git Product logo

r1csfile's Introduction

R1CS Binary File Format

This is a helper library to read r1cs binary files defined here

Usage

const readR1cs = require("r1csfile").readR1cs

readR1cs("myfile.r1cs").then((r1cs) => {
	console.log(r1cs);
});

r1csfile's People

Contributors

dependabot[bot] avatar jbaylina avatar kolezhniuk avatar lilyjordan avatar phated avatar xavi-pinsach avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

r1csfile's Issues

Constrains input are stored as negative numbers instead of positive as described in .r1cs documentation

Grasping over the .r1cs documentation r1cs docs the section 2 explicitly tells:

image

But in the .r1cs file, the values are not stored like that, but as negative numbers instead, taking the header.prime as the max integer.

For example:

For this constrain:

image

The expected bytes would be:

[xx-xx-xx-xx][01000000, 00000000, 00000000, 00000000, 00000000, 00000000, 00000000]
[xx-xx-xx-xx][01000000, 00000000, 00000000, 00000000, 00000000, 00000000, 00000000]
[xx-xx-xx-xx][01000000, 00000000, 00000000, 00000000, 00000000, 00000000, 00000000]

but in the .r1cs they are stored as

[xx-xx-xx-xx][000000f, 093f5e14, 39170b97, 948e8332, 85d58818, 1b64550b, 829a031e, 1724e6430]
[xx-xx-xx-xx][000000f, 093f5e14, 39170b97, 948e8332, 85d58818, 1b64550b, 829a031e, 1724e6430]
[xx-xx-xx-xx][0100000, 00000000, 00000000, 00000000, 00000000, 00000000, 00000000]

If i substract headers.prime to these bytes, the result is actually the one that is described in the documentation.

Constants are also encoded as positive numbers, for example, taking the constraint

5 + a * b ==> c

The linearCombination will be produced as:

[xx-xx-xx-xx][0500000, 00000000, 00000000, 00000000, 00000000, 00000000, 00000000]
[xx-xx-xx-xx][000000f, 093f5e14, 39170b97, 948e8332, 85d58818, 1b64550b, 829a031e, 1724e6430]
[xx-xx-xx-xx][000000f, 093f5e14, 39170b97, 948e8332, 85d58818, 1b64550b, 829a031e, 1724e6430]
[xx-xx-xx-xx][0100000, 00000000, 00000000, 00000000, 00000000, 00000000, 00000000]

This behavior is not described in the documentation of the .r1cs.

If the explanation i make for this behavior is right (Can be wrong if the reasons of this behavior are others and not just, negative numbers)

I'm proposing myself to modify the .r1cs specification to add the explanation for this fields.

Wrong description of "Number of Labels"

In the description of r1cs binary file format, the description of "Number of Labels" is unclear, because it is a verbatim copy of the description of "Number of private inputs".

Also, while at it, there is a typo in the description of the fields "Number of public outputs", "Number of public inputs", "Number of private inputs" and "Number of Labels", were the word "wire" is used twice. E.g., it reads:

Total Number of wires public output wires.

while it should read:

Total Number of public output wires.

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.