|
1 | | -import Ix.Aiur.Meta |
2 | | -import Ix.Aiur.Simple |
3 | | -import Ix.Aiur.Compile |
4 | | -import Ix.Aiur.Protocol |
5 | | -import Ix.Benchmark.Bench |
6 | | - |
7 | | -def toplevel := ⟦ |
8 | | - enum Nat { |
9 | | - Zero, |
10 | | - Succ(&Nat) |
11 | | - } |
12 | | - |
13 | | - fn g_to_nat(g: G) -> Nat { |
14 | | - match g { |
15 | | - 0 => Nat.Zero, |
16 | | - _ => Nat.Succ(store(g_to_nat(g - 1))), |
17 | | - } |
18 | | - } |
19 | | - |
20 | | - fn nat_to_g(n: Nat) -> G { |
21 | | - match n { |
22 | | - Nat.Zero => 0, |
23 | | - Nat.Succ(ptr) => nat_to_g(load(ptr)) + 1, |
24 | | - } |
25 | | - } |
26 | | - |
27 | | - fn nat_add(a: Nat, b: Nat) -> Nat { |
28 | | - match b { |
29 | | - Nat.Zero => a, |
30 | | - Nat.Succ(b'ptr) => nat_add(Nat.Succ(store(a)), load(b'ptr)), |
31 | | - } |
32 | | - } |
33 | | - |
34 | | - fn nat_fib(n: Nat) -> Nat { |
35 | | - match n { |
36 | | - Nat.Zero => Nat.Succ(store(Nat.Zero)), |
37 | | - Nat.Succ(n'ptr) => |
38 | | - let n' = load(n'ptr); |
39 | | - match n' { |
40 | | - Nat.Zero => Nat.Succ(store(Nat.Zero)), |
41 | | - Nat.Succ(n''ptr) => |
42 | | - let n'' = load(n''ptr); |
43 | | - nat_add(nat_fib(n'), nat_fib(n'')), |
44 | | - }, |
45 | | - } |
46 | | - } |
47 | | - |
48 | | - fn main(g: G) -> G { |
49 | | - nat_to_g(nat_fib(g_to_nat(g))) |
50 | | - } |
51 | | -⟧ |
52 | | - |
53 | | -def commitmentParameters : Aiur.CommitmentParameters := { |
54 | | - logBlowup := 1 |
55 | | -} |
56 | | - |
57 | | -def friParameters : Aiur.FriParameters := { |
58 | | - logFinalPolyLen := 0 |
59 | | - numQueries := 100 |
60 | | - proofOfWorkBits := 20 |
61 | | -} |
62 | | - |
63 | | -def proveE2E (name: Lean.Name) : IO UInt32 := do |
64 | | - match toplevel.checkAndSimplify with |
65 | | - | .error e => IO.eprintln e; return 1 |
66 | | - | .ok decls => |
67 | | - let bytecode := decls.compile |
68 | | - let system := Aiur.AiurSystem.build bytecode commitmentParameters |
69 | | - let funIdx := toplevel.getFuncIdx name |>.get! |
70 | | - let (claim, proof, _) := system.prove friParameters funIdx #[10] default |
71 | | - match system.verify friParameters claim proof with |
72 | | - | .ok _ => return 0 |
73 | | - | .error e => IO.eprintln e; return 1 |
74 | | - |
75 | | - |
76 | | --- End-to-end proof generation and verification benchmark |
77 | | -def proveE2EBench := bgroup "prove E2E" [ |
78 | | - benchIO "fib 10" proveE2E `main |
79 | | -] { samplingMode := .flat } |
80 | | - |
81 | | --- Individual benchmarks of each step from `proveE2E` |
82 | | - |
83 | | -def toplevelBench := bgroup "nat_fib" [ |
84 | | - bench "simplify toplevel" Aiur.Toplevel.checkAndSimplify toplevel |
85 | | -] |
86 | | - |
87 | | -def compileBench : IO Unit := do |
88 | | - match toplevel.checkAndSimplify with |
89 | | - | .error e => IO.eprintln e |
90 | | - | .ok decls => |
91 | | - bgroup "nat_fib" [ |
92 | | - bench "compile decls" Aiur.TypedDecls.compile decls |
93 | | - ] |
94 | | - |
95 | | -def buildAiurSystemBench : IO Unit := do |
96 | | - match toplevel.checkAndSimplify with |
97 | | - | .error e => IO.eprintln e |
98 | | - | .ok decls => |
99 | | - let bytecode := decls.compile |
100 | | - bgroup "nat_fib" [ |
101 | | - bench "build AiurSystem" (Aiur.AiurSystem.build bytecode) commitmentParameters |
102 | | - ] |
103 | | - |
104 | | -def proveBench : IO Unit := do |
105 | | - match toplevel.checkAndSimplify with |
106 | | - | .error e => IO.eprintln e |
107 | | - | .ok decls => |
108 | | - let bytecode := decls.compile |
109 | | - let system := Aiur.AiurSystem.build bytecode commitmentParameters |
110 | | - let funIdx := toplevel.getFuncIdx `main |>.get! |
111 | | - bgroup "nat_fib" [ |
112 | | - bench "prove fib 10" (Aiur.AiurSystem.prove system friParameters funIdx) #[10] |
113 | | - ] |
114 | | - |
115 | | -def verifyBench : IO Unit := do |
116 | | - match toplevel.checkAndSimplify with |
117 | | - | .error e => IO.eprintln e |
118 | | - | .ok decls => |
119 | | - let bytecode := decls.compile |
120 | | - let system := Aiur.AiurSystem.build bytecode commitmentParameters |
121 | | - let funIdx := toplevel.getFuncIdx `main |>.get! |
122 | | - let (claim, proof, _) := system.prove friParameters funIdx #[10] default |
123 | | - bgroup "nat_fib" [ |
124 | | - bench "verify fib 10" (Aiur.AiurSystem.verify system friParameters claim) proof |
125 | | - ] |
126 | | - |
| 1 | +--import Ix.Aiur.Meta |
| 2 | +--import Ix.Aiur.Simple |
| 3 | +--import Ix.Aiur.Compile |
| 4 | +--import Ix.Aiur.Protocol |
| 5 | +--import Ix.Benchmark.Bench |
| 6 | +-- |
| 7 | +--def toplevel := ⟦ |
| 8 | +-- enum Nat { |
| 9 | +-- Zero, |
| 10 | +-- Succ(&Nat) |
| 11 | +-- } |
| 12 | +-- |
| 13 | +-- fn g_to_nat(g: G) -> Nat { |
| 14 | +-- match g { |
| 15 | +-- 0 => Nat.Zero, |
| 16 | +-- _ => Nat.Succ(store(g_to_nat(g - 1))), |
| 17 | +-- } |
| 18 | +-- } |
| 19 | +-- |
| 20 | +-- fn nat_to_g(n: Nat) -> G { |
| 21 | +-- match n { |
| 22 | +-- Nat.Zero => 0, |
| 23 | +-- Nat.Succ(ptr) => nat_to_g(load(ptr)) + 1, |
| 24 | +-- } |
| 25 | +-- } |
| 26 | +-- |
| 27 | +-- fn nat_add(a: Nat, b: Nat) -> Nat { |
| 28 | +-- match b { |
| 29 | +-- Nat.Zero => a, |
| 30 | +-- Nat.Succ(b'ptr) => nat_add(Nat.Succ(store(a)), load(b'ptr)), |
| 31 | +-- } |
| 32 | +-- } |
| 33 | +-- |
| 34 | +-- fn nat_fib(n: Nat) -> Nat { |
| 35 | +-- match n { |
| 36 | +-- Nat.Zero => Nat.Succ(store(Nat.Zero)), |
| 37 | +-- Nat.Succ(n'ptr) => |
| 38 | +-- let n' = load(n'ptr); |
| 39 | +-- match n' { |
| 40 | +-- Nat.Zero => Nat.Succ(store(Nat.Zero)), |
| 41 | +-- Nat.Succ(n''ptr) => |
| 42 | +-- let n'' = load(n''ptr); |
| 43 | +-- nat_add(nat_fib(n'), nat_fib(n'')), |
| 44 | +-- }, |
| 45 | +-- } |
| 46 | +-- } |
| 47 | +-- |
| 48 | +-- fn main(g: G) -> G { |
| 49 | +-- nat_to_g(nat_fib(g_to_nat(g))) |
| 50 | +-- } |
| 51 | +--⟧ |
| 52 | +-- |
| 53 | +--def commitmentParameters : Aiur.CommitmentParameters := { |
| 54 | +-- logBlowup := 1 |
| 55 | +--} |
| 56 | +-- |
| 57 | +--def friParameters : Aiur.FriParameters := { |
| 58 | +-- logFinalPolyLen := 0 |
| 59 | +-- numQueries := 100 |
| 60 | +-- proofOfWorkBits := 20 |
| 61 | +--} |
| 62 | +-- |
| 63 | +--def proveE2E (name: Lean.Name) : IO UInt32 := do |
| 64 | +-- match toplevel.checkAndSimplify with |
| 65 | +-- | .error e => IO.eprintln e; return 1 |
| 66 | +-- | .ok decls => |
| 67 | +-- let bytecode := decls.compile |
| 68 | +-- let system := Aiur.AiurSystem.build bytecode commitmentParameters |
| 69 | +-- let funIdx := toplevel.getFuncIdx name |>.get! |
| 70 | +-- let (claim, proof, _) := system.prove friParameters funIdx #[10] default |
| 71 | +-- match system.verify friParameters claim proof with |
| 72 | +-- | .ok _ => return 0 |
| 73 | +-- | .error e => IO.eprintln e; return 1 |
| 74 | +-- |
| 75 | +-- |
| 76 | +---- End-to-end proof generation and verification benchmark |
| 77 | +--def proveE2EBench := bgroup "prove E2E" [ |
| 78 | +-- benchIO "fib 10" proveE2E `main |
| 79 | +--] { samplingMode := .flat } |
| 80 | +-- |
| 81 | +---- Individual benchmarks of each step from `proveE2E` |
| 82 | +-- |
| 83 | +--def toplevelBench := bgroup "nat_fib" [ |
| 84 | +-- bench "simplify toplevel" Aiur.Toplevel.checkAndSimplify toplevel |
| 85 | +--] |
| 86 | +-- |
| 87 | +--def compileBench : IO Unit := do |
| 88 | +-- match toplevel.checkAndSimplify with |
| 89 | +-- | .error e => IO.eprintln e |
| 90 | +-- | .ok decls => |
| 91 | +-- bgroup "nat_fib" [ |
| 92 | +-- bench "compile decls" Aiur.TypedDecls.compile decls |
| 93 | +-- ] |
| 94 | +-- |
| 95 | +--def buildAiurSystemBench : IO Unit := do |
| 96 | +-- match toplevel.checkAndSimplify with |
| 97 | +-- | .error e => IO.eprintln e |
| 98 | +-- | .ok decls => |
| 99 | +-- let bytecode := decls.compile |
| 100 | +-- bgroup "nat_fib" [ |
| 101 | +-- bench "build AiurSystem" (Aiur.AiurSystem.build bytecode) commitmentParameters |
| 102 | +-- ] |
| 103 | +-- |
| 104 | +--def proveBench : IO Unit := do |
| 105 | +-- match toplevel.checkAndSimplify with |
| 106 | +-- | .error e => IO.eprintln e |
| 107 | +-- | .ok decls => |
| 108 | +-- let bytecode := decls.compile |
| 109 | +-- let system := Aiur.AiurSystem.build bytecode commitmentParameters |
| 110 | +-- let funIdx := toplevel.getFuncIdx `main |>.get! |
| 111 | +-- bgroup "nat_fib" [ |
| 112 | +-- bench "prove fib 10" (Aiur.AiurSystem.prove system friParameters funIdx) #[10] |
| 113 | +-- ] |
| 114 | +-- |
| 115 | +--def verifyBench : IO Unit := do |
| 116 | +-- match toplevel.checkAndSimplify with |
| 117 | +-- | .error e => IO.eprintln e |
| 118 | +-- | .ok decls => |
| 119 | +-- let bytecode := decls.compile |
| 120 | +-- let system := Aiur.AiurSystem.build bytecode commitmentParameters |
| 121 | +-- let funIdx := toplevel.getFuncIdx `main |>.get! |
| 122 | +-- let (claim, proof, _) := system.prove friParameters funIdx #[10] default |
| 123 | +-- bgroup "nat_fib" [ |
| 124 | +-- bench "verify fib 10" (Aiur.AiurSystem.verify system friParameters claim) proof |
| 125 | +-- ] |
| 126 | +-- |
127 | 127 | def main (_args : List String) : IO Unit := do |
128 | | - let _result ← proveBench |
| 128 | + return () |
| 129 | +-- let _result ← proveBench |
0 commit comments