-
Notifications
You must be signed in to change notification settings - Fork 1
Claim builder API and Prove CLI #89
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
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
6e672dd
WIP: ix hash command
johnchandlerburnham 8271d54
make Proof serialize as an Ixon Const
johnchandlerburnham d34dc40
broken: connect canonicalizer to Ix.Meta
johnchandlerburnham 4b3cfbe
fix: Nix devShell & light refactor (#55)
samuelburnham 216bee1
Merge branch 'main' of github.com:argumentcomputer/ix into jcb/ix-cli
johnchandlerburnham 5938727
ix store cli command
johnchandlerburnham 52431bf
WIP: store command and new IxM structure
johnchandlerburnham e6a212c
megacommit implementing Ix commitment API
johnchandlerburnham 63faf25
Merge branch 'main' of github.com:argumentcomputer/ix into jcb/ix-cli
johnchandlerburnham 35d1311
fixup merge
johnchandlerburnham 685f565
fixup merge 2
johnchandlerburnham 93309c8
ix prove check command
johnchandlerburnham c9b3565
Merge branch 'main' of github.com:argumentcomputer/ix into jcb/ix-cli
johnchandlerburnham b90fd9b
implement ix prove CLI and simplify metaprogramming
johnchandlerburnham 221f352
provecmd examples
johnchandlerburnham 5aa0fc4
cleanup repo
johnchandlerburnham ed79280
simplify ZKVoting example app
johnchandlerburnham f8d7176
Merge branch 'main' of github.com:argumentcomputer/ix into jcb/ix-cli
johnchandlerburnham 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 was deleted.
Oops, something went wrong.
This file contains hidden or 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,52 +1,64 @@ | ||
| import Ix | ||
| import Apps.ZKVoting.ProverInit | ||
| import Apps.ZKVoting.Common | ||
| import Ix.Claim | ||
| import Ix.Address | ||
| import Ix.Meta | ||
| import Ix.CompileM | ||
| import Batteries | ||
|
|
||
| open Lean | ||
| inductive Candidate | ||
| | alice | bob | charlie | ||
| deriving Inhabited, Lean.ToExpr, Repr, BEq, Ord | ||
|
|
||
| partial def collectVotes (env : Environment) : IO $ List Vote := | ||
| collectVotesLoop [] initSecret (0 : UInt64) | ||
| where | ||
| collectVotesLoop votes secret count := do | ||
| let input := (← (← IO.getStdin).getLine).trim | ||
| let consts := env.constants | ||
| let voteAbe ← mkCommit secret Candidate.abe consts | ||
| let voteBam ← mkCommit secret Candidate.bam consts | ||
| let voteCot ← mkCommit secret Candidate.cot consts | ||
| IO.println s!"a: Abe | {voteAbe}" | ||
| IO.println s!"b: Bam | {voteBam}" | ||
| IO.println s!"b: Cot | {voteCot}" | ||
| IO.println "_: End voting" | ||
| let vote ← match input with | ||
| | "a" => pure voteAbe | "b" => pure voteBam | "c" => pure voteCot | ||
| | _ => return votes | ||
| let secret' := (← mkCommit secret count consts).adr | ||
| IO.println vote | ||
| collectVotesLoop (vote :: votes) secret' (count + 1) | ||
| structure Result where | ||
| aliceVotes: Nat | ||
| bobVotes: Nat | ||
| charlieVotes: Nat | ||
| deriving Repr, Lean.ToExpr | ||
|
|
||
| structure VoteCounts where | ||
| abe : UInt64 | ||
| bam : UInt64 | ||
| cot : UInt64 | ||
| deriving ToExpr | ||
| def privateVotes : List Candidate := | ||
| [.alice, .alice, .bob] | ||
|
|
||
| def countVotes : List Vote → VoteCounts | ||
| | [] => ⟨0, 0, 0⟩ | ||
| | vote :: votes => | ||
| let counts := countVotes votes | ||
| match (reveal vote : Candidate) with | ||
| | .abe => { counts with abe := counts.abe + 1 } | ||
| | .bam => { counts with bam := counts.bam + 1 } | ||
| | .cot => { counts with cot := counts.cot + 1 } | ||
| def runElection (votes: List Candidate) : Result := | ||
| votes.foldr tally ⟨0,0,0⟩ | ||
| where | ||
| tally (comm: Candidate) (res: Result): Result := | ||
| match comm, res with | ||
| | .alice, ⟨a, b, c⟩ => ⟨a+1, b, c⟩ | ||
| | .bob, ⟨a, b, c⟩ => ⟨a, b+1, c⟩ | ||
| | .charlie, ⟨a, b, c⟩ => ⟨a, b, c+1⟩ | ||
|
|
||
| open Ix.Compile | ||
|
|
||
| def main : IO UInt32 := do | ||
| let env ← get_env! | ||
| let votes ← collectVotes env | ||
| let .defnInfo countVotesDefn ← runCore (getConstInfo ``countVotes) env | ||
| | unreachable! | ||
| let claimValue := .app countVotesDefn.value (toExpr votes) | ||
| let claimType ← runMeta (Meta.inferType claimValue) env | ||
| let claimAdr := computeIxAddress (mkAnonDefInfoRaw claimType claimValue) env.constants | ||
| match ← prove claimAdr with | ||
| | .ok proof => IO.FS.writeBinFile proofPath $ Ixon.Serialize.put proof; return 0 | ||
| | .error err => IO.eprintln $ toString err; return 1 | ||
| let mut stt : CompileState := .init (<- get_env!) | ||
| -- simulate getting the votes from somewhere | ||
| let votes : List Candidate <- pure privateVotes | ||
| let mut as : List Lean.Name := [] | ||
| -- default maxHeartBeats | ||
| let ticks : USize := 200000 | ||
| -- the type of each vote to commit | ||
| let voteType := Lean.toTypeExpr Candidate | ||
| -- loop over the votes | ||
| for v in votes do | ||
| -- add each vote to our environment as a commitment | ||
| let (lvls, typ, val) <- runMeta (metaMakeDef v) stt.env | ||
| let ((addr, _), stt') <- (commitDef lvls typ val).runIO' ticks stt | ||
| stt := stt' | ||
| as := (Address.toUniqueName addr)::as | ||
| IO.println s!"vote: {repr v}, commitment: {addr}" | ||
| -- build a Lean list of our commitments as the argument to runElection | ||
| let arg : Lean.Expr <- runMeta (metaMakeList voteType as) stt.env | ||
| let (lvls, input, output, type, sort) <- | ||
| runMeta (metaMakeEvalClaim ``runElection [arg]) stt.env | ||
| let inputPretty <- runMeta (Lean.Meta.ppExpr input) stt.env | ||
| let outputPretty <- runMeta (Lean.Meta.ppExpr output) stt.env | ||
| let typePretty <- runMeta (Lean.Meta.ppExpr type) stt.env | ||
| IO.println s!"claim: {inputPretty}" | ||
| IO.println s!" ~> {outputPretty}" | ||
| IO.println s!" : {typePretty}" | ||
| IO.println s!" @ {repr lvls}" | ||
| let ((claim,_,_,_), _stt') <- | ||
| (evalClaim lvls input output type sort true).runIO' ticks stt | ||
| IO.println s!"{claim}" | ||
| -- Ix.prove claim stt | ||
| return 0 | ||
|
|
||
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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,18 +1,18 @@ | ||
| import Ix.Ixon.Serialize | ||
| import Ix.Prove | ||
| import Apps.ZKVoting.Common | ||
|
|
||
| def main (args : List String) : IO UInt32 := do | ||
| let mut votes := #[] | ||
| for commStr in args do | ||
| match Commitment.ofString commStr with | ||
| | none => IO.eprintln s!"Couldn't parse {commStr} as a commitment"; return 1 | ||
| | some (comm : Vote) => votes := votes.push comm | ||
| let proofBytes ← IO.FS.readBinFile proofPath | ||
| match Ixon.Serialize.get proofBytes with | ||
| | .error err => IO.eprintln s!"Proof deserialization error: {err}"; return 1 | ||
| | .ok (_proof : Proof) => | ||
| -- TODO: print the resulting vote counts in the claim | ||
| -- TODO: assert that every vote in `votes` is in the proof claim | ||
| -- TODO: verify proof | ||
| -- TODO | ||
| -- let mut votes := #[] | ||
| -- for commStr in args do | ||
| -- match Commitment.ofString commStr with | ||
| -- | none => IO.eprintln s!"Couldn't parse {commStr} as a commitment"; return 1 | ||
| -- | some (comm : Vote) => votes := votes.push comm | ||
| -- let proofBytes ← IO.FS.readBinFile proofPath | ||
| -- match Ixon.Serialize.get proofBytes with | ||
| -- | .error err => IO.eprintln s!"Proof deserialization error: {err}"; return 1 | ||
| -- | .ok (_proof : Proof) => | ||
| -- -- TODO: print the resulting vote counts in the claim | ||
| -- -- TODO: assert that every vote in `votes` is in the proof claim | ||
| -- -- TODO: verify proof | ||
| return 0 |
This file contains hidden or 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,9 +1,9 @@ | ||
| -- This module serves as the root of the `Ix` library. | ||
| -- Import modules here that should be built as part of the library. | ||
| import Ix.BuiltIn | ||
| import Ix.Ixon | ||
| import Ix.CanonM | ||
| import Ix.TransportM | ||
| import Ix.IR | ||
| import Ix.Meta | ||
| import Ix.CompileM | ||
| import Ix.Claim | ||
| import Ix.Prove |
This file contains hidden or 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 was deleted.
Oops, something went wrong.
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.
It doesn't apply here, but direct recursion (as I had implemented it) is generally better than
foldr/foldl/tail-recursion/etc in the IxVM due to auto-memoization. But it doesn't matter at this point. Just something to keep in mind as we want to showcase opinionated guidelines for writing efficient Lean code for our VM.