Skip to content

Commit 0f21106

Browse files
authored
feat: conditional modules (#878)
This puts in place support for "conditional modules". That is, modules which can be enabled or disabled using a constant-time expression (e.g. `(>= EVM_FORK SHANGHAI_FORK)`). The system works using a "remapper" which essentially allows one to delete modules, and then it takes care of remapping all module and column identifiers in whatever remains. This adds a test for conditional modules which simply checks that the given trace does not need to have columns for missing modules.
1 parent 0c1dbfd commit 0f21106

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+736
-164
lines changed

.golangci.yml

Lines changed: 62 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,97 +1,75 @@
1+
version: "2"
12
linters:
2-
disable-all: true
3+
default: none
34
enable:
45
- errcheck
5-
- goimports
6-
- revive
7-
- gosimple
86
- govet
97
- ineffassign
108
- lll
119
- misspell
10+
- revive
1211
- staticcheck
13-
- typecheck
1412
- unconvert
1513
- unparam
1614
- unused
1715
- whitespace
1816
- wsl
19-
# - godot
20-
21-
# don't enable:
22-
# - gochecknoglobals
23-
# - gocognit
24-
# - godox
25-
# - maligned
26-
# - prealloc
27-
28-
# output configuration options
29-
output:
30-
# print lines of code with issue, default is true
31-
print-issued-lines: true
32-
33-
# print linter name in the end of issue text, default is true
34-
print-linter-name: true
35-
36-
# golangci.com configuration
37-
# https://github.com/golangci/golangci/wiki/Configuration
38-
service:
39-
golangci-lint-version: 1.64.3 # use the fixed version to not introduce new linters unexpectedly
40-
41-
linters-settings:
42-
errcheck:
43-
# report about assignment of errors to blank identifier: `num, _ := strconv.Atoi(numStr)`;
44-
# default is false: such cases aren't reported by default.
45-
check-blank: true
46-
47-
govet:
48-
# report about shadowed variables
49-
shadow: true
50-
51-
revive:
52-
# see https://github.com/mgechev/revive#available-rules for details.
53-
ignore-generated-header: true
54-
severity: warning
55-
confidence: 0.8
56-
rules:
57-
- name: errorf
58-
severity: warning
59-
- name: context-as-argument
60-
severity: warning
61-
- name: exported
62-
severity: warning
63-
- name: error-naming
64-
severity: warning
65-
- name: increment-decrement
66-
severity: warning
67-
- name: receiver-naming
68-
severity: warning
69-
- name: superfluous-else
70-
severity: warning
71-
- name: useless-break
72-
severity: warning
73-
- name: defer
74-
severity: warning
75-
- name: identical-branches
76-
severity: warning
77-
- name: early-return
78-
severity: warning
79-
- name: unnecessary-stmt
80-
severity: warning
81-
- name: unreachable-code
82-
severity: warning
83-
- name: confusing-naming
84-
severity: warning
85-
86-
staticcheck:
87-
go: "1.22"
88-
# https://staticcheck.io/docs/options#checks
89-
checks: [ "all" ]
90-
91-
92-
issues:
93-
exclude-use-default: false # this one is used due to golangci v1 blocking revive linter exported rule, this should be fixed in v2
94-
95-
godot:
96-
period: true
97-
capital: true
17+
settings:
18+
errcheck:
19+
check-blank: true
20+
revive:
21+
confidence: 0.8
22+
severity: warning
23+
rules:
24+
- name: errorf
25+
severity: warning
26+
- name: context-as-argument
27+
severity: warning
28+
- name: exported
29+
severity: warning
30+
- name: error-naming
31+
severity: warning
32+
- name: increment-decrement
33+
severity: warning
34+
- name: receiver-naming
35+
severity: warning
36+
- name: superfluous-else
37+
severity: warning
38+
- name: useless-break
39+
severity: warning
40+
- name: defer
41+
severity: warning
42+
- name: identical-branches
43+
severity: warning
44+
- name: early-return
45+
severity: warning
46+
- name: unnecessary-stmt
47+
severity: warning
48+
- name: unreachable-code
49+
severity: warning
50+
- name: confusing-naming
51+
severity: warning
52+
staticcheck:
53+
checks:
54+
- all
55+
- -ST1000
56+
- -ST1003
57+
- -ST1019
58+
- -ST1023
59+
- -QF1001
60+
- -QF1011
61+
exclusions:
62+
generated: lax
63+
paths:
64+
- third_party$
65+
- builtin$
66+
- examples$
67+
formatters:
68+
enable:
69+
- goimports
70+
exclusions:
71+
generated: lax
72+
paths:
73+
- third_party$
74+
- builtin$
75+
- examples$

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ repos:
1313
- id: go-test-mod
1414
args: [ --run=Test_Basic ]
1515
- repo: https://github.com/golangci/golangci-lint
16-
rev: v1.61.0
16+
rev: v2.1.6
1717
hooks:
1818
- id: golangci-lint
1919
- repo: https://github.com/executablebooks/mdformat

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
GOCORSET_VERSION:=$(shell git describe --always --tags)
22
GOCORSET_VERSION_PATH:="github.com/consensys/go-corset/pkg/cmd"
3-
GOLANGCI_VERSION:=1.64.8
3+
GOLANGCI_VERSION:=2.1.6
44
PROJECT_NAME:=go-corset
55
GOPATH_BIN:=$(shell go env GOPATH)/bin
66

pkg/asm/compiler/function.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func (p *Compiler) Schema() *hir.Schema {
5454
func (p *Compiler) Compile(name string, regs []insn.Register, code []micro.Instruction) {
5555
var (
5656
// Allocate module id
57-
mid = p.schema.AddModule(name)
57+
mid = p.schema.AddModule(name, hir.VOID)
5858
// Map fn registers to schema columns
5959
rids = make([]uint, len(regs))
6060
)

pkg/asm/util.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func ReadTrace(bytes []byte, program MacroProgram) (MacroTrace, error) {
8080
tr, ok := traces[fn.Name]
8181
// Sanity check
8282
if !ok {
83-
return trace, fmt.Errorf("missing inputs/outputs for function %s\n", fn.Name)
83+
return trace, fmt.Errorf("missing inputs/outputs for function %s", fn.Name)
8484
}
8585
//
8686
fnInsts, err := readTraceInstances(tr, uint(i), fn)

pkg/cmd/check.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,8 @@ func checkTraceWithLowering(traces [][]tr.RawColumn, schema *hir.Schema, cfg che
257257
mirCoverage sc.CoverageMap
258258
hirCoverage sc.CoverageMap
259259
)
260+
// Consolidate schema
261+
schema.Consolidate()
260262
//
261263
res := true
262264
// Process individually

pkg/cmd/generate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func generateJavaHeader(pkgname string, metadata typed.Map, builder *strings.Bui
100100
builder.WriteString(license)
101101
// Write package line
102102
if pkgname != "" {
103-
builder.WriteString(fmt.Sprintf("package %s;\n", pkgname))
103+
fmt.Fprintf(builder, "package %s;\n", pkgname)
104104
}
105105
//
106106
builder.WriteString(javaImports)

pkg/cmd/tracediff.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func diffColumns(index int, columns1 []trace.RawColumn, columns2 []trace.RawColu
8484
count2, ok2 := set2[val]
8585
//
8686
if ok1 != ok2 || count1 != count2 {
87-
err := fmt.Errorf("Column %s, element %s occurs %d or %d times.", name, val.String(), count1, count2)
87+
err := fmt.Errorf("column %s, element %s occurs %d or %d times", name, val.String(), count1, count2)
8888
errors = append(errors, err)
8989
}
9090
}

pkg/cmd/util.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ func writeTraceFile(filename string, tracefile *lt.TraceFile) {
427427
}
428428
}
429429
default:
430-
err = fmt.Errorf("Unknown trace file format: %s", ext)
430+
err = fmt.Errorf("unknown trace file format: %s", ext)
431431
}
432432
// Handle error
433433
fmt.Println(err)
@@ -470,7 +470,7 @@ func ReadTraceFile(filename string) *lt.TraceFile {
470470
}
471471
//
472472
default:
473-
err = fmt.Errorf("Unknown trace file format: %s", ext)
473+
err = fmt.Errorf("unknown trace file format: %s", ext)
474474
}
475475
}
476476
// Handle error

pkg/corset/ast/declaration.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ type Circuit struct {
3434
type Module struct {
3535
Name string
3636
Declarations []Declaration
37+
// Condition determines when this module is enabled. The condition must be
38+
// a constant expression, as nothing else could be typed.
39+
Condition Expr
3740
}
3841

3942
// Node provides common functionality across all elements of the Abstract Syntax

0 commit comments

Comments
 (0)