Skip to content

Commit

Permalink
Update serialization section
Browse files Browse the repository at this point in the history
  • Loading branch information
AgustinBadi committed Apr 10, 2024
1 parent 9401bf2 commit 2e4b1d4
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 8 deletions.
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,18 @@ And should output the following:
[INFO] snarkJS: OK!
```

### The conversion
### Serialization of circom files.

In order to make the circom files interoperable with the Plutus VM, it is necessary to serialize the proof and verification key generated by circom. To serialize the circom files you can run the following:

```bash
$ ./convert.sh
Folder of your circom files?
#It will ask to the folder of circom files, in our case is 3_fac.
$ 3_fac
```

This will output the serialized proof and vk in its uncompressed form. It is important to point that the Plutus VM can operate uncompressed values, but will not let you store the uncompressed values as PlutusData. To store them as PlutusData you must do it in its compressed form, though the Aiken compiler can do the transformation under the hood for you.

Capabilities to convert values in its compressed form will be incorporated in the future.

Todo
19 changes: 13 additions & 6 deletions conversion/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ const fs = require("fs");
const bb = require("bigint-buffer");
const ff = require("ffjavascript");

const args = process.argv;

if (args.length == 1) {
console.log('Just one path argument is needed!');
}

const proof = JSON.parse(fs.readFileSync("proof.json", "utf-8"));
const verificationKey = JSON.parse(fs.readFileSync("verification_key.json", "utf-8"));

Expand Down Expand Up @@ -118,17 +124,14 @@ async function convertVerificationKeyToUncompressed(verificationKey) {
}

async function printCompressedProof() {
console.log("Compressed proof", JSON.stringify(await convertProofToUncompressed(proof)));
console.log("Uncompressed proof", JSON.stringify(await convertProofToUncompressed(proof)));
}

printCompressedProof();

async function printCompressedVerificationKey() {
console.log("\n\nUncompressed verification key", JSON.stringify(await convertVerificationKeyToUncompressed(verificationKey)));
}

printCompressedVerificationKey();


async function ffTest() {
const curve = await ff.getCurveFromName("bls12381");
Expand Down Expand Up @@ -165,6 +168,10 @@ async function ffTest() {
console.log("G1 from compressed is valid", curve.G1.isValid(g1ElementFromCompressed));
}

// ffTest();

async function run_program () {
await printCompressedVerificationKey();
await printCompressedProof();
process.exit();
}

run_program();
21 changes: 21 additions & 0 deletions convert.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

# Step 1: Echo "Path of your file?"
echo "Folder of your circom files?"

# Step 2: Take the relative path of the file from stdin and stored it in a variable called PROOF_PATH.
read CIRCOM_FILES_PATH

# Step 3: cd conversion.
cd $CIRCOM_FILES_PATH || exit 1

# Step 4: Inside conversion mkdir output.
#mkdir -p conv_outputs

#node ../conversion/index.js "$CIRCOM_FILES_PATH" > conv_outputs/output.txt || exit 1
node ../conversion/index.js "$CIRCOM_FILES_PATH" || exit 1

echo "Conversion done!"



0 comments on commit 2e4b1d4

Please sign in to comment.