-
Notifications
You must be signed in to change notification settings - Fork 136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Recursion, Pt 2 #250
Merged
Merged
Recursion, Pt 2 #250
Changes from 11 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
f968632
add Program type; handles proofs & private inputs
mitschabaude 97e7ed1
common method preprocessing, tighter types
mitschabaude 94d68ca
use common logic for some method wrapping
mitschabaude ab18b17
move smart contract-specific stuff to wrapMethod
mitschabaude c8439b6
move pickles rule wrapper to proof_systems
mitschabaude 86865ee
common logic for compile
mitschabaude 8a39ed0
implement Program.compile
mitschabaude c785c06
move test code to example
mitschabaude f136aef
implement proving for Program
mitschabaude 7bfc195
fix compile
mitschabaude d4b82c1
create example with recursive proof chain
mitschabaude 5cb2315
remove Proof.dummy
mitschabaude b784561
move hlper stuff to the bottom
mitschabaude 5f7225d
better naming
mitschabaude f0d5932
update bindings
mitschabaude 6009d9f
add `SelfProof` shortcut and use it in examples
mitschabaude b624b6d
Program -> ZkProgram
mitschabaude 2b91617
Merge branch 'feature/recursion-2' into feature/recursion-bindings
mitschabaude 36ca782
`privateInput` -> `privateInputs`
mitschabaude b1fc62d
make isAsFields more general
mitschabaude 05ffd15
fix: method args have to be cloned because method can modify them
mitschabaude 1d39a45
Merge branch 'feature/recursion-2' into feature/recursion-bindings
mitschabaude b258b01
update bindings
mitschabaude c1e3d9e
Merge branch 'main' into feature/recursion-2
mitschabaude efdaee4
Merge branch 'feature/recursion-bindings' into feature/recursion-2
mitschabaude File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,43 @@ | ||
import { Proof, Field, Program } from 'snarkyjs'; | ||
|
||
class MyProof extends Proof<Field> { | ||
static publicInputType = Field; | ||
static tag: () => { name: string } = () => MyProgram; | ||
} | ||
|
||
let MyProgram = Program({ | ||
publicInput: Field, | ||
|
||
methods: { | ||
baseCase: { | ||
privateInput: [], | ||
|
||
method(publicInput: Field) { | ||
publicInput.assertEquals(Field.zero); | ||
}, | ||
}, | ||
|
||
plus1Case: { | ||
privateInput: [MyProof], | ||
|
||
method(publicInput: Field, earlierProof: MyProof) { | ||
earlierProof.verify(); | ||
earlierProof.publicInput.add(1).assertEquals(publicInput); | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
console.log('compiling MyProgram...'); | ||
await MyProgram.compile(); | ||
|
||
console.log('proving base case...'); | ||
let proof = await MyProgram.baseCase(Field.zero); | ||
|
||
console.log('proving step 1...'); | ||
proof = await MyProgram.plus1Case(Field.one, proof); | ||
|
||
console.log('proving step 2...'); | ||
proof = await MyProgram.plus1Case(Field(2), proof); | ||
|
||
console.log('ok?', proof.publicInput.toString() === '2'); |
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 |
---|---|---|
|
@@ -879,6 +879,14 @@ type PartiesProved = { | |
memo: string; | ||
}; | ||
|
||
/** | ||
* The public input for zkApps consists of certain hashes of the transaction and of the proving Party which is constructed during method execution. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this comment was just moved over from |
||
|
||
In SmartContract.prove, a method is run twice: First outside the proof, to obtain the public input, and once in the prover, | ||
which takes the public input as input. The current transaction is hashed again inside the prover, which asserts that the result equals the input public input, | ||
as part of the snark circuit. The block producer will also hash the transaction they receive and pass it as a public input to the verifier. | ||
Thus, the transaction is fully constrained by the proof - the proof couldn't be used to attest to a different transaction. | ||
*/ | ||
type ZkappPublicInput = [transaction: Field, atParty: Field]; | ||
let ZkappPublicInput = circuitValue<ZkappPublicInput>([Field, Field]); | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this type was changed because there is no
Party
in non-smart-contract proofs