-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feature/eddsa/sha512
- Loading branch information
Showing
25 changed files
with
644 additions
and
59 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#!/usr/bin/env node | ||
import Client from './dist/node/mina-signer/mina-signer.js'; | ||
|
||
let client = new Client({ network: 'testnet' }); | ||
let client = new Client({ network: 'devnet' }); | ||
|
||
console.log(client.genKeys()); |
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,72 @@ | ||
/** | ||
* This shows how to prove an arbitrarily long chain of hashes using ZkProgram, i.e. | ||
* `hash^n(x) = y`. | ||
* | ||
* We implement this as a self-recursive ZkProgram, using `proveRecursivelyIf()` | ||
*/ | ||
import { | ||
assert, | ||
Bool, | ||
Experimental, | ||
Field, | ||
Poseidon, | ||
Provable, | ||
Struct, | ||
ZkProgram, | ||
} from 'o1js'; | ||
|
||
const HASHES_PER_PROOF = 30; | ||
|
||
class HashChainSpec extends Struct({ x: Field, n: Field }) {} | ||
|
||
const hashChain = ZkProgram({ | ||
name: 'hash-chain', | ||
publicInput: HashChainSpec, | ||
publicOutput: Field, | ||
|
||
methods: { | ||
chain: { | ||
privateInputs: [], | ||
|
||
async method({ x, n }: HashChainSpec) { | ||
Provable.log('hashChain (start method)', n); | ||
let y = x; | ||
let k = Field(0); | ||
let reachedN = Bool(false); | ||
|
||
for (let i = 0; i < HASHES_PER_PROOF; i++) { | ||
reachedN = k.equals(n); | ||
y = Provable.if(reachedN, y, Poseidon.hash([y])); | ||
k = Provable.if(reachedN, n, k.add(1)); | ||
} | ||
|
||
// we have y = hash^k(x) | ||
// now do z = hash^(n-k)(y) = hash^n(x) by calling this method recursively | ||
// except if we have k = n, then ignore the output and use y | ||
let z: Field = await hashChainRecursive.chain.if(reachedN.not(), { | ||
x: y, | ||
n: n.sub(k), | ||
}); | ||
z = Provable.if(reachedN, y, z); | ||
Provable.log('hashChain (start proving)', n); | ||
return { publicOutput: z }; | ||
}, | ||
}, | ||
}, | ||
}); | ||
let hashChainRecursive = Experimental.Recursive(hashChain); | ||
|
||
await hashChain.compile(); | ||
|
||
let n = 100; | ||
let x = Field.random(); | ||
|
||
let { proof } = await hashChain.chain({ x, n: Field(n) }); | ||
|
||
assert(await hashChain.verify(proof), 'Proof invalid'); | ||
|
||
// check that the output is correct | ||
let z = Array.from({ length: n }, () => 0).reduce((y) => Poseidon.hash([y]), x); | ||
proof.publicOutput.assertEquals(z, 'Output is incorrect'); | ||
|
||
console.log('Finished hash chain proof'); |
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
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.