-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1805 from o1-labs/optional-proving-zkprogram
Optional proving for zkProgram
- Loading branch information
Showing
3 changed files
with
128 additions
and
26 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { | ||
SelfProof, | ||
Field, | ||
ZkProgram, | ||
verify, | ||
Proof, | ||
JsonProof, | ||
Provable, | ||
Empty, | ||
Cache, | ||
} from 'o1js'; | ||
|
||
let MyProgram = ZkProgram({ | ||
name: 'example-without-proving', | ||
publicOutput: Field, | ||
publicInput: Field, | ||
methods: { | ||
baseCase: { | ||
privateInputs: [], | ||
async method(publicInput: Field) { | ||
return publicInput.add(4); | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
console.log('program digest', await MyProgram.digest()); | ||
|
||
// enable proofs to compile the program | ||
const proofsEnabled = true; | ||
|
||
await MyProgram.compile({ | ||
proofsEnabled, | ||
}); | ||
|
||
console.log('proofs enabled?', MyProgram.proofsEnabled); | ||
|
||
console.log('proving base case... (proofs enabled)'); | ||
console.time('proving'); | ||
let proof = await MyProgram.baseCase(Field(2)); | ||
console.timeEnd('proving'); | ||
proof.publicOutput.assertEquals(Field(2).add(4)); | ||
|
||
console.log('disable proofs, generate dummy proof'); | ||
MyProgram.setProofsEnabled(false); | ||
console.log('proofs enabled?', MyProgram.proofsEnabled); | ||
console.time('noProving'); | ||
proof = await MyProgram.baseCase(Field(2)); | ||
console.timeEnd('noProving'); | ||
proof.publicOutput.assertEquals(Field(2).add(4)); |
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