-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
341 additions
and
22 deletions.
There are no files selected for viewing
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,23 @@ | ||
import { ICircuitParams } from "./interfaces"; | ||
|
||
/** | ||
* Validate the circuit parameters | ||
* @param params - The circuit parameters | ||
*/ | ||
export const validateParams = ({ | ||
stateTreeDepth, | ||
intStateTreeDepth, | ||
voteOptionTreeDepth, | ||
messageBatchSize, | ||
}: ICircuitParams): boolean => { | ||
// validate args | ||
if (stateTreeDepth < 1 || intStateTreeDepth < 1 || voteOptionTreeDepth < 1 || messageBatchSize < 1) { | ||
throw new Error("Invalid depth or batch size parameters"); | ||
} | ||
|
||
if (stateTreeDepth < intStateTreeDepth) { | ||
throw new Error("Invalid state tree depth or intermediate state tree depth"); | ||
} | ||
|
||
return true; | ||
}; |
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,35 @@ | ||
import os from "os"; | ||
|
||
declare global { | ||
interface ITerminatable { | ||
terminate: () => Promise<unknown>; | ||
} | ||
|
||
// eslint-disable-next-line vars-on-top, no-var, camelcase | ||
var curve_bn128: ITerminatable | undefined; | ||
|
||
// eslint-disable-next-line vars-on-top, no-var, camelcase | ||
var curve_bls12381: ITerminatable | undefined; | ||
} | ||
|
||
/** | ||
* Check if we are running on an arm chip | ||
* @returns whether we are running on an arm chip | ||
*/ | ||
export const isArm = (): boolean => os.arch().includes("arm"); | ||
|
||
/* | ||
* https://github.com/iden3/snarkjs/issues/152 | ||
* Need to cleanup the threads to avoid stalling | ||
*/ | ||
export const cleanThreads = async (): Promise<void> => { | ||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition | ||
if (!globalThis) { | ||
return; | ||
} | ||
|
||
const curves = ["curve_bn128", "curve_bls12381"]; | ||
await Promise.all( | ||
curves.map((curve) => globalThis[curve as "curve_bn128" | "curve_bls12381"]?.terminate()).filter(Boolean), | ||
); | ||
}; |
Oops, something went wrong.