Skip to content

Commit

Permalink
explicit bigint arithmetic builtins removed
Browse files Browse the repository at this point in the history
  • Loading branch information
utkn committed Nov 9, 2024
1 parent d1e73ab commit 2ba3cff
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 71 deletions.
45 changes: 0 additions & 45 deletions Lampe/Lampe/Builtin/BigInt.lean
Original file line number Diff line number Diff line change
@@ -1,51 +1,6 @@
import Lampe.Builtin.Basic
namespace Lampe.Builtin

/--
Defines the addition of two bigints `(a b : Int)`.
The builtin is assumed to return `a + b`.
In Noir, this builtin corresponds to `a + b` for bigints `a`, `b`.
-/
def bigIntAdd := newPureBuiltin
⟨[.bi, .bi], (.bi)⟩
(fun h![a, b] => ⟨True,
fun _ => a + b⟩)

/--
Defines the subtraction of two bigints `(a b : Int)`.
The builtin is assumed to return `a - b`.
In Noir, this builtin corresponds to `a - b` for bigints `a`, `b`.
-/
def bigIntSub := newPureBuiltin
⟨[.bi, .bi], (.bi)⟩
(fun h![a, b] => ⟨True,
fun _ => a - b⟩)

/--
Defines the multiplication of two bigints `(a b : Int)`.
The builtin is assumed to return `a * b`.
In Noir, this builtin corresponds to `a * b` for bigints `a`, `b`.
-/
def bigIntMul := newPureBuiltin
⟨[.bi, .bi], (.bi)⟩
(fun h![a, b] => ⟨True,
fun _ => a * b⟩)

/--
Defines the division of two bigints `(a b : Int)`. We make the following assumptions:
- If `b = 0`, an exception is thrown.
- Otherwise, the builtin is assumed to return `a / b`.
In Noir, this builtin corresponds to `a / b` for bigints `a`, `b`.
-/
def bigIntDiv := newPureBuiltin
⟨[.bi, .bi], (.bi)⟩
(fun h![a, b] => ⟨b ≠ 0,
fun _ => a / b⟩)

/--
Defines the conversion of a byte slice `bytes : List (U 8)` in little-endian encoding to a `BigInt`.
Modulus parameter is ignored.
Expand Down
36 changes: 10 additions & 26 deletions Lampe/Lampe/Hoare/Builtins.lean
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,10 @@ theorem div_intro {ha : Builtin.ArithTp tp}: STHoare p Γ ⟦⟧
theorem rem_intro : STHoare p Γ ⟦⟧
(.call h![] [tp, tp] tp (.builtin .rem) h![a, b])
(fun v => Builtin.canDivide a b ∧
v = match tp with
| .u _ => a % b
| .i _ => Builtin.intRem a b
| _ => a) := by
match tp with
| .u _ => v = a % b
| .i _ => v = Builtin.intRem a b
| _ => False) := by
unfold STHoare
intros H st h
constructor
Expand All @@ -138,11 +138,11 @@ theorem rem_intro : STHoare p Γ ⟦⟧

theorem neg_intro : STHoare p Γ ⟦⟧
(.call h![] [tp, tp] tp (.builtin .neg) h![a, b])
(fun v => v = match tp with
| .i _ => -a
| .field => -a
| .bi => -a
| _ => a) := by
(fun v => match tp with
| .i _ => v = -a
| .field => v = -a
| .bi => v = -a
| _ => False) := by
unfold STHoare
intros H st h
constructor
Expand All @@ -162,23 +162,7 @@ theorem arrayAsSlice_intro : STHoarePureBuiltin p Γ Builtin.arrayAsSlice (by ta
apply pureBuiltin_intro_consequence <;> try rfl
tauto

-- BigInt

theorem bigIntAdd_intro : STHoarePureBuiltin p Γ Builtin.bigIntAdd (by tauto) h![a, b] (a := ()) := by
apply pureBuiltin_intro_consequence <;> tauto
tauto

theorem bigIntSub_intro : STHoarePureBuiltin p Γ Builtin.bigIntSub (by tauto) h![a, b] (a := ()) := by
apply pureBuiltin_intro_consequence <;> tauto
tauto

theorem bigIntMul_intro : STHoarePureBuiltin p Γ Builtin.bigIntMul (by tauto) h![a, b] (a := ()) := by
apply pureBuiltin_intro_consequence <;> tauto
tauto

theorem bigIntDiv_intro : STHoarePureBuiltin p Γ Builtin.bigIntDiv (by tauto) h![a, b] (a := ()) := by
apply pureBuiltin_intro_consequence <;> tauto
tauto
-- BigInt misc

theorem bigIntFromLeBytes_intro : STHoarePureBuiltin p Γ Builtin.bigIntFromLeBytes (by tauto) h![bs, mbs] (a := ()) := by
apply pureBuiltin_intro_consequence <;> tauto
Expand Down

0 comments on commit 2ba3cff

Please sign in to comment.