-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix bug with the linearization of public signals (#9)
* Fixed bug with the linearization of public signals * Changed to Public signals to NumberLike * Used flatMap * Reduced code duplication * Updated versions
- Loading branch information
Showing
12 changed files
with
252 additions
and
27 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { PublicSignals } from "@solarity/zkit"; | ||
|
||
export function normalizePublicSignals( | ||
publicSignals: any[], | ||
signalNames: string[], | ||
getSignalDimensions: (name: string) => number[], | ||
): any { | ||
let index = 0; | ||
return signalNames.reduce((acc: any, signalName) => { | ||
const dimensions = getSignalDimensions(signalName); | ||
const size = dimensions.reduce((a, b) => a * b, 1); | ||
|
||
acc[signalName] = reshape(publicSignals.slice(index, index + size), dimensions); | ||
index += size; | ||
|
||
return acc; | ||
}, {}); | ||
} | ||
|
||
export function denormalizePublicSignals(publicSignals: any, signalNames: string[]): PublicSignals { | ||
return signalNames.reduce((acc: any[], signalName) => { | ||
return acc.concat(flatten(publicSignals[signalName])); | ||
}, []); | ||
} | ||
|
||
function reshape(array: number[], dimensions: number[]): any { | ||
if (dimensions.length === 0) { | ||
return array[0]; | ||
} | ||
|
||
const [first, ...rest] = dimensions; | ||
const size = rest.reduce((a, b) => a * b, 1); | ||
|
||
const result = []; | ||
for (let i = 0; i < first; i++) { | ||
result.push(reshape(array.slice(i * size, (i + 1) * size), rest)); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
function flatten(array: any): number[] { | ||
return Array.isArray(array) ? array.flatMap((array) => flatten(array)) : array; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.