From 2e4b1d44225734f2cf9e3393d3eac2bf212a7c3f Mon Sep 17 00:00:00 2001 From: AgustinBadi Date: Wed, 10 Apr 2024 16:16:38 -0400 Subject: [PATCH] Update serialization section --- README.md | 16 ++++++++++++++-- conversion/index.js | 19 +++++++++++++------ convert.sh | 21 +++++++++++++++++++++ 3 files changed, 48 insertions(+), 8 deletions(-) create mode 100755 convert.sh diff --git a/README.md b/README.md index 1cda2c2..2158d39 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/conversion/index.js b/conversion/index.js index 2da6c96..7edc1d3 100644 --- a/conversion/index.js +++ b/conversion/index.js @@ -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")); @@ -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"); @@ -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(); diff --git a/convert.sh b/convert.sh new file mode 100755 index 0000000..6b7d992 --- /dev/null +++ b/convert.sh @@ -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!" + + +