Skip to content

Commit 9705fd4

Browse files
Initializing Aiur2 (#179)
* feat: bytecode and execution of aiur2 * Read bytecodes from Lean in Rust * port simplification and typechecking to Aiur2 * port compilation to Aiur2 * Aiur2 execution tests
1 parent d4e17a4 commit 9705fd4

23 files changed

+2347
-2
lines changed

Cargo.lock

Lines changed: 118 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ binius_utils = { git = "https://github.com/IrreducibleOSS/binius.git", rev = "23
2121
bumpalo = "3"
2222
groestl_crypto = { package = "groestl", version = "0.10.1" }
2323
proptest = "1"
24+
p3-goldilocks = "0.3.0"
25+
p3-field = "0.3.0"
2426
rayon = "1"
2527
rand = "0.9.1"
2628
rustc-hash = "2"

Ix/Aiur/Simple.lean

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ def checkAndSimplifyToplevel (toplevel : Toplevel) : Except CheckError TypedDecl
4444
| .constructor d c => pure $ typedDecls.insert name (.constructor d c)
4545
| .dataType d => pure $ typedDecls.insert name (.dataType d)
4646
| .function f => do
47-
let _ ← (checkFunction f) (getFunctionContext f decls)
4847
let f ← (checkFunction f) (getFunctionContext f decls)
4948
pure $ typedDecls.insert name (.function f)
5049
| .gadget g => pure $ typedDecls.insert name (.gadget g)

Ix/Aiur2/Bytecode.lean

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import Ix.Aiur2.Goldilocks
2+
3+
namespace Aiur
4+
5+
namespace Bytecode
6+
7+
abbrev FunIdx := Nat
8+
abbrev ValIdx := Nat
9+
abbrev SelIdx := Nat
10+
11+
inductive Op
12+
| const : G → Op
13+
| add : ValIdx → ValIdx → Op
14+
| sub : ValIdx → ValIdx → Op
15+
| mul : ValIdx → ValIdx → Op
16+
| call : FunIdx → Array ValIdx → Op
17+
| store : Array ValIdx → Op
18+
| load : (width : Nat) → ValIdx → Op
19+
deriving Repr
20+
21+
mutual
22+
inductive Ctrl where
23+
| match : ValIdx → Array (G × Block) → Option Block → Ctrl
24+
| return : SelIdx → Array ValIdx → Ctrl
25+
deriving Inhabited, Repr
26+
27+
structure Block where
28+
ops : Array Op
29+
ctrl : Ctrl
30+
minSelIncluded: SelIdx
31+
maxSelExcluded: SelIdx
32+
deriving Inhabited, Repr
33+
end
34+
35+
/-- The circuit layout of a function -/
36+
structure CircuitLayout where
37+
/-- Bit values that identify which path the computation took.
38+
Exactly one selector must be set. -/
39+
selectors : Nat
40+
/-- Represent registers that hold temporary values and can be shared by
41+
different circuit paths, since they never overlap. -/
42+
auxiliaries : Nat
43+
/-- Constraint slots that can be shared in different paths of the circuit. -/
44+
sharedConstraints : Nat
45+
deriving Inhabited, Repr
46+
47+
structure Function where
48+
inputSize : Nat
49+
outputSize : Nat
50+
body : Block
51+
circuitLayout: CircuitLayout
52+
deriving Inhabited, Repr
53+
54+
structure Toplevel where
55+
functions : Array Function
56+
memoryWidths : Array Nat
57+
deriving Repr
58+
59+
@[extern "c_rs_toplevel_execute_test"]
60+
private opaque Toplevel.executeTest' :
61+
@& Toplevel → @& FunIdx → @& Array G → USize → Array G
62+
63+
def Toplevel.executeTest (toplevel : Toplevel) (funIdx : FunIdx) (args : Array G) : Array G :=
64+
let function := toplevel.functions[funIdx]!
65+
toplevel.executeTest' funIdx args function.outputSize.toUSize
66+
67+
end Bytecode
68+
69+
end Aiur

0 commit comments

Comments
 (0)