forked from zkopru-network/zkopru
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: template LessThan is not secure for large numbers; closes zkopru…
- Loading branch information
Showing
4 changed files
with
60 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
include "../node_modules/circomlib/circuits/bitify.circom"; | ||
|
||
template RangeLimit(bitLength) { | ||
signal input in; | ||
// This automatically limits its max value to 2**bitLength - 1 | ||
component bits = Num2Bits(bitLength); | ||
bits.in <== in; | ||
} |
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,3 @@ | ||
include "../lib/range_limit.circom"; | ||
|
||
component main = RangeLimit(3); |
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,40 @@ | ||
/** | ||
* @jest-environment node | ||
*/ | ||
/* eslint-disable jest/require-tothrow-message */ | ||
/* eslint-disable jest/no-expect-resolves */ | ||
/* eslint-disable @typescript-eslint/camelcase */ | ||
/* eslint-disable jest/no-hooks */ | ||
|
||
import { genSNARK, SNARKResult } from '~utils/snark' | ||
import { | ||
checkPhase1Setup, | ||
compileCircuit, | ||
getArtifactPaths, | ||
phase2Setup, | ||
prepareArtifactsDirectory, | ||
} from './helper' | ||
|
||
const fileName = 'range_limit.test.circom' | ||
const artifacts = getArtifactPaths(fileName) | ||
const { wasm, finalZkey, vk } = artifacts | ||
|
||
describe('multiplier.test.circom', () => { | ||
beforeAll(() => { | ||
checkPhase1Setup() | ||
prepareArtifactsDirectory() | ||
}) | ||
it('should compile circuits', () => { | ||
compileCircuit(fileName) | ||
}) | ||
it('should setup phase 2 for the circuit', () => { | ||
phase2Setup(fileName) | ||
}) | ||
it('should create SNARK proof', async () => { | ||
const result: SNARKResult = await genSNARK({ in: 7 }, wasm, finalZkey, vk) | ||
expect(result).toBeDefined() | ||
}) | ||
it('should throw error with invalid inputs', async () => { | ||
await expect(genSNARK({ in: 8 }, wasm, finalZkey, vk)).rejects.toThrow() | ||
}) | ||
}) |