-
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.
- Loading branch information
Showing
6 changed files
with
126 additions
and
4 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { ProofData } from '@noir-lang/noir_js'; | ||
|
||
import hash_1 from '@ultralane/circuits/bin/hash_1/target/hash_1.json'; | ||
import hash_2 from '@ultralane/circuits/bin/hash_2/target/hash_2.json'; | ||
import hash_3 from '@ultralane/circuits/bin/hash_3/target/hash_3.json'; | ||
|
||
import { toBigInt } from 'ethers'; | ||
|
||
import { circuit } from './utils'; | ||
import { Field } from './field'; | ||
|
||
export async function hash(preimage: Field[]): Promise<Field> { | ||
const json = hash_json(preimage.length); | ||
const noir = await circuit(json); | ||
const result = await noir.execute({ | ||
input: preimage.map((x) => x.hex()), | ||
}); | ||
return new Field(toBigInt(result.returnValue as string)); | ||
} | ||
|
||
export async function hash_prove(preimage: Field[]): Promise<ProofData> { | ||
const json = hash_json(preimage.length); | ||
const noir = await circuit(json); | ||
const proof = await noir.generateProof({ | ||
input: preimage.map((x) => x.hex()), | ||
}); | ||
return proof; | ||
} | ||
|
||
export function hash_json(length: number) { | ||
let json; | ||
switch (length) { | ||
case 1: | ||
json = hash_1; | ||
break; | ||
case 2: | ||
json = hash_2; | ||
break; | ||
case 3: | ||
json = hash_3; | ||
break; | ||
default: | ||
throw new Error('preimage length not supported: ' + length); | ||
} | ||
return json; | ||
} |
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,9 @@ | ||
import { BarretenbergBackend } from '@noir-lang/backend_barretenberg'; | ||
import { Noir } from '@noir-lang/noir_js'; | ||
|
||
export async function circuit(json: any) { | ||
const backend = new BarretenbergBackend(json); | ||
const noir = new Noir(json, backend); | ||
await noir.init(); | ||
return noir; | ||
} |
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