Skip to content

Commit

Permalink
feat: support display forms (#485)
Browse files Browse the repository at this point in the history
* Add minimal test case

* Parse `:display` attributes

Whilst these are not currently used within `go-corset`, they are now
parsed so as to allow existing files to be compiled.

* Enable OOB test

This updates the oob test so that it now parses and runs correctly.
  • Loading branch information
DavePearce authored Dec 21, 2024
1 parent 1875cc5 commit 33e467b
Show file tree
Hide file tree
Showing 14 changed files with 113 additions and 14 deletions.
16 changes: 15 additions & 1 deletion pkg/corset/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,8 +379,22 @@ func (p *Parser) parseColumnDeclarationAttributes(attrs []sexp.SExp) (Type, bool
}
//
switch symbol.Value {
case ":display", ":opcode":
case ":display":
// skip these for now, as they are only relevant to the inspector.
if i+1 == len(attrs) {
return nil, false, p.translator.SyntaxError(ith, "incomplete display definition")
} else if attrs[i+1].AsSymbol() == nil {
return nil, false, p.translator.SyntaxError(ith, "malformed display definition")
}
// Check what display attribute we have
switch attrs[i+1].AsSymbol().String(false) {
case ":dec", ":hex", ":bytes", ":opcode":
// all good
i = i + 1
default:
// not good
return nil, false, p.translator.SyntaxError(ith, "unknown display definition")
}
case ":array":
if array, err = p.parseArrayDimension(attrs[i+1]); err != nil {
return nil, false, err
Expand Down
24 changes: 24 additions & 0 deletions pkg/test/invalid_corset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,30 @@ func Test_Invalid_Type_08(t *testing.T) {
CheckInvalid(t, "type_invalid_08")
}

func Test_Invalid_Type_09(t *testing.T) {
CheckInvalid(t, "type_invalid_09")
}

func Test_Invalid_Type_10(t *testing.T) {
CheckInvalid(t, "type_invalid_10")
}

func Test_Invalid_Type_11(t *testing.T) {
CheckInvalid(t, "type_invalid_11")
}

func Test_Invalid_Type_12(t *testing.T) {
CheckInvalid(t, "type_invalid_12")
}

func Test_Invalid_Type_13(t *testing.T) {
CheckInvalid(t, "type_invalid_13")
}

func Test_Invalid_Type_14(t *testing.T) {
CheckInvalid(t, "type_invalid_14")
}

// ===================================================================
// Range Constraints
// ===================================================================
Expand Down
17 changes: 12 additions & 5 deletions pkg/test/valid_corset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,14 @@ func Test_Type_08(t *testing.T) {
Check(t, false, "type_08")
}

func Test_Type_09(t *testing.T) {
Check(t, false, "type_09")
}

func Test_Type_10(t *testing.T) {
Check(t, false, "type_10")
}

// ===================================================================
// Range Constraints
// ===================================================================
Expand Down Expand Up @@ -794,11 +802,10 @@ func TestSlow_Euc(t *testing.T) {
Check(t, true, "euc")
}

/*
func TestSlow_Oob(t *testing.T) {
Check(t, true, "oob")
}
*/
func TestSlow_Oob(t *testing.T) {
Check(t, true, "oob")
}

func TestSlow_Stp(t *testing.T) {
Check(t, true, "stp")
}
Expand Down
39 changes: 39 additions & 0 deletions testdata/oob.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,45 @@
(OUTGOING_DATA :i128 :array [4])
(OUTGOING_RES_LO :i128))

(defconst
;; Stop and Arithmetic Operations
EVM_INST_ADD 0x01
EVM_INST_DIV 0x04
EVM_INST_MOD 0x06
;; Comparison & Bitwise Logic Operations
EVM_INST_LT 0x10
EVM_INST_GT 0x11
EVM_INST_EQ 0x14
EVM_INST_ISZERO 0x15
;;
MAX_CODE_SIZE 24576
EIP2681_MAX_NONCE 18446744073709551615 ;; = 2^64 - 1
;;
GAS_CONST_G_CALL_STIPEND 2300
;;
OOB_INST_JUMP 0x56
OOB_INST_JUMPI 0x57
OOB_INST_RDC 0x3E
OOB_INST_CDL 0x35
OOB_INST_XCALL 0xCC
OOB_INST_CALL 0xCA
OOB_INST_CREATE 0xCE
OOB_INST_SSTORE 0x55
OOB_INST_DEPLOYMENT 0xF3
OOB_INST_ECRECOVER 0xFF01
OOB_INST_SHA2 0xFF02
OOB_INST_RIPEMD 0xFF03
OOB_INST_IDENTITY 0xFF04
OOB_INST_ECADD 0xFF06
OOB_INST_ECMUL 0xFF07
OOB_INST_ECPAIRING 0xFF08
OOB_INST_BLAKE_CDS 0xFA09
OOB_INST_BLAKE_PARAMS 0xFB09
OOB_INST_MODEXP_CDS 0xFA05
OOB_INST_MODEXP_XBS 0xFB05
OOB_INST_MODEXP_LEAD 0xFC05
OOB_INST_MODEXP_PRICING 0xFD05
OOB_INST_MODEXP_EXTRACT 0xFE05)

(module oob)

Expand Down
2 changes: 1 addition & 1 deletion testdata/type_09.accepts
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@
{ "BIT": [0,1], "X": [1,0] }
{ "BIT": [0,1], "X": [2,0] }
;;
{ "BIT": [1,1], "X": [1,1] }
{ "BIT": [1,1], "X": [0,0] }
4 changes: 2 additions & 2 deletions testdata/type_09.lisp
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
(defcolumns (X :i1@bool@prove) (Y :i4@loob))
(defconstraint c1 () (if X Y))
(defcolumns (BIT :i1@bool@prove) (X :i4@loob))
(defconstraint c1 () (if BIT X))
6 changes: 6 additions & 0 deletions testdata/type_10.accepts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{ "A": [], "B": [], "C": [], "D": [] }
{ "A": [0], "B": [0], "C": [0], "D": [0] }
{ "A": [1], "B": [0], "C": [0], "D": [0] }
{ "A": [0], "B": [1], "C": [0], "D": [0] }
{ "A": [0], "B": [0], "C": [1], "D": [0] }
{ "A": [0], "B": [0], "C": [0], "D": [1] }
5 changes: 5 additions & 0 deletions testdata/type_10.lisp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(defcolumns
(A :display :dec)
(B :display :hex)
(C :display :bytes)
(D :display :opcode))
2 changes: 1 addition & 1 deletion testdata/type_invalid_09.lisp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
;;error:2:1-2:blah
;;error:6:26-27:invalid condition (neither loobean nor boolean)
(defcolumns (X :i1) (Y :i1) (A :i4@loob) (B :i4@loob))
(definterleaved Z (X Y))
(definterleaved C (A B))
Expand Down
2 changes: 1 addition & 1 deletion testdata/type_invalid_10.lisp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
;;error:2:1-2:blah
;;error:6:26-27:invalid condition (neither loobean nor boolean)
(defcolumns (X :i1@loob) (Y :i1) (A :i4@loob) (B :i4@loob))
(definterleaved Z (X Y))
(definterleaved C (A B))
Expand Down
2 changes: 1 addition & 1 deletion testdata/type_invalid_11.lisp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
;;error:2:1-2:blah
;;error:6:26-27:invalid condition (neither loobean nor boolean)
(defcolumns (X :i1) (Y :i1@loob) (A :i4@loob) (B :i4@loob))
(definterleaved Z (X Y))
(definterleaved C (A B))
Expand Down
2 changes: 1 addition & 1 deletion testdata/type_invalid_12.lisp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
;;error:2:1-2:blah
;;error:6:26-27:invalid condition (neither loobean nor boolean)
(defcolumns (X :i1@bool) (Y :i1) (A :i4@loob) (B :i4@loob))
(definterleaved Z (X Y))
(definterleaved C (A B))
Expand Down
2 changes: 1 addition & 1 deletion testdata/type_invalid_13.lisp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
;;error:2:1-2:blah
;;error:6:26-27:invalid condition (neither loobean nor boolean)
(defcolumns (X :i1) (Y :i1@bool) (A :i4@loob) (B :i4@loob))
(definterleaved Z (X Y))
(definterleaved C (A B))
Expand Down
4 changes: 4 additions & 0 deletions testdata/type_invalid_14.lisp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
;;error:3:16-24:incomplete display definition
;;error:4:16-24:unknown display definition
(defcolumns (X :display))
(defcolumns (Y :display :int))

0 comments on commit 33e467b

Please sign in to comment.