Skip to content

Commit

Permalink
Fixes for Quick Tests
Browse files Browse the repository at this point in the history
This puts through various minor fixes for the quick tests.  What remains
now is to update the larger tests.  At this stage, performance may be
starting to become an issue.
  • Loading branch information
DavePearce committed Dec 13, 2024
1 parent 67d6b61 commit 65a1a9a
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 35 deletions.
19 changes: 15 additions & 4 deletions pkg/corset/stdlib.lisp
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
(defpurefun ((vanishes! :@loob) x) x)

;; =============================================================================
;; Logical
;; =============================================================================
(defpurefun ((or! :@loob) x y) (* x y))
(defpurefun ((eq! :@loob) x y) (- x y))

(defpurefun (prev x) (shift x -1))
(defpurefun (next x) (shift x 1))

;;
;; =============================================================================
;; Control Flow
;; =============================================================================
(defpurefun (if-not-eq lhs rhs then)
(if
(eq! lhs rhs)
Expand All @@ -28,3 +30,12 @@
then
;; False branch
else))

;; =============================================================================
;; Temporal
;; =============================================================================
(defpurefun (prev x) (shift x -1))
(defpurefun (next x) (shift x 1))
(defpurefun (will-eq! e0 e1) (eq! (next e0) e1))
(defpurefun (will-inc! e0 offset) (will-eq! e0 (+ e0 offset)))
(defpurefun (will-remain-constant! e0) (will-eq! e0 e0))
20 changes: 10 additions & 10 deletions pkg/test/valid_corset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -625,47 +625,47 @@ func Test_PureFun_04(t *testing.T) {
// ===================================================================

func Test_Counter(t *testing.T) {
Check(t, false, "counter")
Check(t, true, "counter")
}

func Test_ByteDecomp(t *testing.T) {
Check(t, false, "byte_decomposition")
Check(t, true, "byte_decomposition")
}

func Test_BitDecomp(t *testing.T) {
Check(t, false, "bit_decomposition")
Check(t, true, "bit_decomposition")
}

func Test_ByteSorting(t *testing.T) {
Check(t, false, "byte_sorting")
Check(t, true, "byte_sorting")
}

func Test_WordSorting(t *testing.T) {
Check(t, false, "word_sorting")
Check(t, true, "word_sorting")
}

func Test_Memory(t *testing.T) {
Check(t, true, "memory")
}

func TestSlow_Add(t *testing.T) {
Check(t, false, "add")
Check(t, true, "add")
}

func TestSlow_BinStatic(t *testing.T) {
Check(t, false, "bin-static")
Check(t, true, "bin-static")
}

func TestSlow_BinDynamic(t *testing.T) {
Check(t, false, "bin-dynamic")
Check(t, true, "bin-dynamic")
}

func TestSlow_Wcp(t *testing.T) {
Check(t, false, "wcp")
Check(t, true, "wcp")
}

func TestSlow_Mxp(t *testing.T) {
Check(t, false, "mxp")
Check(t, true, "mxp")
}

// ===================================================================
Expand Down
2 changes: 1 addition & 1 deletion testdata/bit_decomposition.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
(BIT_3 :i1@prove))

;; NIBBLE = 8*BIT_3 + 4*BIT_2 + 2*BIT_1 + BIT_0
(defconstraint decomp () (- NIBBLE (+ BIT_0 (* 2 BIT_1) (* 4 BIT_2) (* 8 BIT_3))))
(defconstraint decomp () (eq! NIBBLE (+ BIT_0 (* 2 BIT_1) (* 4 BIT_2) (* 8 BIT_3))))
4 changes: 2 additions & 2 deletions testdata/byte_decomposition.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
;; If CT[k] == 3
(if-eq-else CT 3
;; Then, CT[k+1] == 0
(shift CT 1)
(eq! (next CT) 0)
;; Else, CT[k]+1 == CT[k+1]
(- (+ 1 CT) (next CT))))
(eq! (+ 1 CT) (next CT))))

;; Argument accumulates byte values.
(defconstraint accumulator (:guard ST)
Expand Down
2 changes: 1 addition & 1 deletion testdata/byte_sorting.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
(defcolumns (Delta :i8@prove))

;; Delta == X - X[i-1]
(defconstraint sort () (- Delta (- X (shift X -1))))
(defconstraint sort () (eq! Delta (- X (shift X -1))))
15 changes: 1 addition & 14 deletions testdata/counter.lisp
Original file line number Diff line number Diff line change
@@ -1,24 +1,11 @@
(defpurefun (vanishes! e0) e0)
;;
(defpurefun (next X) (shift X 1))
(defpurefun (prev X) (shift X -1))
;;
(defpurefun (eq! x y) (- x y))
;;
(defpurefun (will-eq! e0 e1) (eq! (next e0) e1))
(defpurefun (will-inc! e0 offset) (will-eq! e0 (+ e0 offset)))
(defpurefun (will-remain-constant! e0) (will-eq! e0 e0))
;;
(defpurefun (if-eq-else x val then else) (if (eq! x val) then else))

;; ===================================================
;; Constraints
;; ===================================================
(defcolumns STAMP CT)

;; In the first row, STAMP is always zero. This allows for an
;; arbitrary amount of padding at the beginning which has no function.
(defconstraint first (:domain {0}) STAMP)
(defconstraint first (:domain {0}) (eq! STAMP 0))

;; In the last row of a valid frame, the counter must have its max
;; value. This ensures that all non-padding frames are complete.
Expand Down
2 changes: 1 addition & 1 deletion testdata/type_invalid_05.lisp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(defcolumns
(BIT :binary@loob)
(BIT :binary)
(X :binary@loob))

(defconstraint c1 () (if (+ 2 BIT) X))
4 changes: 2 additions & 2 deletions testdata/word_sorting.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
(defcolumns (Byte_0 :i8@prove) (Byte_1 :i8@prove))

;; Ensure Delta is a u16
(defconstraint delta_type () (- Delta (+ (* 256 Byte_1) Byte_0)))
(defconstraint delta_type () (eq! Delta (+ (* 256 Byte_1) Byte_0)))

;; Delta == X - X[i-1]
(defconstraint sort () (- Delta (- X (shift X -1))))
(defconstraint sort () (eq! Delta (- X (shift X -1))))

0 comments on commit 65a1a9a

Please sign in to comment.