Skip to content

Commit 3d4b7ea

Browse files
authored
Merge pull request #26 from xorddotcom/development
Fix (debug)
2 parents bfc818f + ce40163 commit 3d4b7ea

File tree

2 files changed

+27
-19
lines changed

2 files changed

+27
-19
lines changed

utils/logger.ts

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
import { readWtnsHeader } from "./witness";
88
// @ts-ignore
99
import { Scalar } from "ffjavascript";
10+
import { arrayLogger } from "./utils";
1011

1112
const TYPES = {
1213
info: "info",
@@ -55,7 +56,7 @@ export const logSignals = async (
5556
r1cs: any,
5657
wtnsFile: any,
5758
symFile: any,
58-
inputSignals: any
59+
jsonInputs: any
5960
) => {
6061
if (r1cs) {
6162
const { fd: fdWtns, sections: sectionsWtns } = await readBinFile(
@@ -70,7 +71,6 @@ export const logSignals = async (
7071
const buffWitness = await readSection(fdWtns, sectionsWtns, 2);
7172

7273
let outputPrefixes: any = {};
73-
let inputPrefixes: any = {};
7474
let lastPos = 0;
7575
let dec = new TextDecoder("utf-8");
7676
for (let i = 0; i < symFile.length; i++) {
@@ -80,8 +80,6 @@ export const logSignals = async (
8080
if (wireNo <= r1cs.nOutputs) {
8181
outputPrefixes[wireNo] =
8282
line.split(",")[3].replace("main.", "") + " = ";
83-
} else {
84-
inputPrefixes[line.split(",")[3].replace("main.", "")] = 0;
8583
}
8684
lastPos = i;
8785
}
@@ -109,29 +107,25 @@ export const logSignals = async (
109107
}
110108
}
111109

112-
const sortedKeys = Object.keys(inputPrefixes).sort();
113-
const sortedSignals = Object.keys(inputSignals).sort();
110+
const sortedSignals = Object.keys(jsonInputs).sort();
111+
112+
let inputSignals: any = {};
114113

115-
let iterator = 0;
116114
for (const key of sortedSignals) {
117-
if (Object.prototype.hasOwnProperty.call(inputSignals, key)) {
118-
const element = inputSignals[key];
115+
if (Object.prototype.hasOwnProperty.call(jsonInputs, key)) {
116+
const element = jsonInputs[key];
119117
if (typeof element === "object") {
120-
const flatArray = element.flat();
121-
for (const signal of flatArray) {
122-
inputPrefixes[sortedKeys[iterator]] = signal;
123-
iterator++;
124-
}
118+
inputSignals = { ...inputSignals, ...arrayLogger("matrix", element) };
125119
} else {
126-
inputPrefixes[sortedKeys[iterator]] = element;
127-
iterator++;
120+
inputSignals[key] = jsonInputs[key];
128121
}
122+
} else {
129123
}
130124
}
131125

132-
if (Object.keys(inputSignals).length !== 0) {
126+
if (Object.keys(jsonInputs).length !== 0) {
133127
console.log(chalk.cyan(`\nInput Signals:\n`));
134-
console.table(inputPrefixes);
128+
console.table(inputSignals);
135129
} else {
136130
console.log(chalk.yellow(`No input signal found:\n`));
137131
}

utils/utils.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,6 @@ export const createInterface = async (
157157
}
158158
};
159159

160-
161160
export const bumpSolidityVersion = async (
162161
SOLIDITY_VERSION: string,
163162
CIRCUIT_NAME: string,
@@ -203,3 +202,18 @@ export const bumpSolidityVersion = async (
203202
throw error;
204203
}
205204
};
205+
206+
207+
export const arrayLogger = (key: string, array: any[]): any => {
208+
let prefixes: any = {};
209+
for (let index = 0; index < array.length; index++) {
210+
const element = array[index];
211+
if (typeof element === "object") {
212+
const subPrefixes = arrayLogger(`${key}[${index}]`, element);
213+
prefixes = { ...prefixes, ...subPrefixes };
214+
} else {
215+
prefixes[`${key}[${index}]`] = element;
216+
}
217+
}
218+
return prefixes;
219+
};

0 commit comments

Comments
 (0)