Skip to content

Commit

Permalink
fix(debug\): resolve the glitch in input logs and optimized the code
Browse files Browse the repository at this point in the history
resolve the glitch in input logs and optimized the code
  • Loading branch information
sleepyqadir committed Oct 21, 2022
1 parent fb6e393 commit d49474e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 19 deletions.
30 changes: 12 additions & 18 deletions utils/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
import { readWtnsHeader } from "./witness";
// @ts-ignore
import { Scalar } from "ffjavascript";
import { arrayLogger } from "./utils";

const TYPES = {
info: "info",
Expand Down Expand Up @@ -55,7 +56,7 @@ export const logSignals = async (
r1cs: any,
wtnsFile: any,
symFile: any,
inputSignals: any
jsonInputs: any
) => {
if (r1cs) {
const { fd: fdWtns, sections: sectionsWtns } = await readBinFile(
Expand All @@ -70,7 +71,6 @@ export const logSignals = async (
const buffWitness = await readSection(fdWtns, sectionsWtns, 2);

let outputPrefixes: any = {};
let inputPrefixes: any = {};
let lastPos = 0;
let dec = new TextDecoder("utf-8");
for (let i = 0; i < symFile.length; i++) {
Expand All @@ -80,8 +80,6 @@ export const logSignals = async (
if (wireNo <= r1cs.nOutputs) {
outputPrefixes[wireNo] =
line.split(",")[3].replace("main.", "") + " = ";
} else {
inputPrefixes[line.split(",")[3].replace("main.", "")] = 0;
}
lastPos = i;
}
Expand Down Expand Up @@ -109,29 +107,25 @@ export const logSignals = async (
}
}

const sortedKeys = Object.keys(inputPrefixes).sort();
const sortedSignals = Object.keys(inputSignals).sort();
const sortedSignals = Object.keys(jsonInputs).sort();

let inputSignals: any = {};

let iterator = 0;
for (const key of sortedSignals) {
if (Object.prototype.hasOwnProperty.call(inputSignals, key)) {
const element = inputSignals[key];
if (Object.prototype.hasOwnProperty.call(jsonInputs, key)) {
const element = jsonInputs[key];
if (typeof element === "object") {
const flatArray = element.flat();
for (const signal of flatArray) {
inputPrefixes[sortedKeys[iterator]] = signal;
iterator++;
}
inputSignals = { ...inputSignals, ...arrayLogger("matrix", element) };
} else {
inputPrefixes[sortedKeys[iterator]] = element;
iterator++;
inputSignals[key] = jsonInputs[key];
}
} else {
}
}

if (Object.keys(inputSignals).length !== 0) {
if (Object.keys(jsonInputs).length !== 0) {
console.log(chalk.cyan(`\nInput Signals:\n`));
console.table(inputPrefixes);
console.table(inputSignals);
} else {
console.log(chalk.yellow(`No input signal found:\n`));
}
Expand Down
16 changes: 15 additions & 1 deletion utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ export const createInterface = async (
}
};


export const bumpSolidityVersion = async (
SOLIDITY_VERSION: string,
CIRCUIT_NAME: string,
Expand Down Expand Up @@ -203,3 +202,18 @@ export const bumpSolidityVersion = async (
throw error;
}
};


export const arrayLogger = (key: string, array: any[]): any => {
let prefixes: any = {};
for (let index = 0; index < array.length; index++) {
const element = array[index];
if (typeof element === "object") {
const subPrefixes = arrayLogger(`${key}[${index}]`, element);
prefixes = { ...prefixes, ...subPrefixes };
} else {
prefixes[`${key}[${index}]`] = element;
}
}
return prefixes;
};

0 comments on commit d49474e

Please sign in to comment.