Skip to content

Commit 9596440

Browse files
authored
fix: crashing when checking with report (#954)
* fix source map debug output The register names were being incorrectly written. * fix: crash when reporting constraint failures This puts in place a very simple fix.
1 parent 733db83 commit 9596440

File tree

3 files changed

+112
-85
lines changed

3 files changed

+112
-85
lines changed

pkg/cmd/debug.go

Lines changed: 1 addition & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ package cmd
1414

1515
import (
1616
"fmt"
17-
"math"
1817
"os"
1918

2019
"github.com/consensys/go-corset/pkg/cmd/debug"
@@ -92,93 +91,11 @@ func printAttributes(schemas cmd_util.SchemaStack) {
9291
fmt.Printf("attribute \"%s\":\n", attr.AttributeName())
9392
//
9493
if attr.AttributeName() == "CorsetSourceMap" {
95-
printSourceMap(attr.(*corset.SourceMap))
94+
debug.PrintSourceMap(attr.(*corset.SourceMap))
9695
}
9796
}
9897
}
9998

100-
func printSourceMap(srcmap *corset.SourceMap) {
101-
printSourceMapModule(1, srcmap.Root)
102-
}
103-
104-
func printSourceMapModule(indent uint, module corset.SourceModule) {
105-
//
106-
fmt.Println()
107-
printIndent(indent)
108-
//
109-
if module.Virtual {
110-
fmt.Printf("virtual ")
111-
}
112-
//
113-
fmt.Printf("module \"%s\":\n", module.Name)
114-
//
115-
indent++
116-
// Print constants
117-
for _, c := range module.Constants {
118-
printIndent(indent)
119-
//
120-
if c.Extern {
121-
fmt.Printf("extern\t")
122-
} else {
123-
fmt.Printf("const\t")
124-
}
125-
//
126-
if c.Bitwidth != math.MaxUint {
127-
fmt.Printf("u%d ", c.Bitwidth)
128-
}
129-
//
130-
fmt.Printf("%s = %s\n", c.Name, &c.Value)
131-
}
132-
// Print columns
133-
for _, c := range module.Columns {
134-
printIndent(indent)
135-
fmt.Printf("u%d\t%s\t[", c.Bitwidth, c.Name)
136-
//
137-
for i, a := range sourceColumnAttrs(c) {
138-
if i == 0 {
139-
fmt.Print(a)
140-
} else {
141-
fmt.Printf(", %s", a)
142-
}
143-
}
144-
145-
fmt.Println("]")
146-
}
147-
// Print submodules
148-
for _, m := range module.Submodules {
149-
printSourceMapModule(indent, m)
150-
}
151-
}
152-
153-
func sourceColumnAttrs(col corset.SourceColumn) []string {
154-
var attrs []string
155-
//
156-
attrs = append(attrs, fmt.Sprintf("r%d", col.Register))
157-
//
158-
if col.Multiplier != 1 {
159-
attrs = append(attrs, fmt.Sprintf("×%d", col.Multiplier))
160-
}
161-
//
162-
if col.Computed {
163-
attrs = append(attrs, "computed")
164-
}
165-
//
166-
if col.MustProve {
167-
attrs = append(attrs, "proved")
168-
}
169-
//
170-
switch col.Display {
171-
case corset.DISPLAY_HEX:
172-
attrs = append(attrs, "hex")
173-
case corset.DISPLAY_DEC:
174-
attrs = append(attrs, "dec")
175-
case corset.DISPLAY_BYTES:
176-
attrs = append(attrs, "bytes")
177-
}
178-
//
179-
return attrs
180-
}
181-
18299
func printSpillage(schemas cmd_util.SchemaStack, defensive bool) {
183100
// fmt.Println("Spillage:")
184101
// // Compute spillage for optimisation level

pkg/cmd/debug/source_map.go

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
// Copyright Consensys Software Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
4+
// the License. You may obtain a copy of the License at
5+
//
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
//
8+
// Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
9+
// an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
10+
// specific language governing permissions and limitations under the License.
11+
//
12+
// SPDX-License-Identifier: Apache-2.0
13+
package debug
14+
15+
import (
16+
"fmt"
17+
"math"
18+
19+
"github.com/consensys/go-corset/pkg/corset"
20+
)
21+
22+
// PrintSourceMap provides a suitable human-readable view of the internal source
23+
// map attribute.
24+
func PrintSourceMap(srcmap *corset.SourceMap) {
25+
printSourceMapModule(1, srcmap.Root)
26+
}
27+
28+
func printSourceMapModule(indent uint, module corset.SourceModule) {
29+
//
30+
fmt.Println()
31+
printIndent(indent)
32+
//
33+
if module.Virtual {
34+
fmt.Printf("virtual ")
35+
}
36+
//
37+
fmt.Printf("module \"%s\"", module.Name)
38+
//
39+
if module.Selector.HasValue() {
40+
fmt.Printf(" when %s", module.Selector.Unwrap())
41+
}
42+
//
43+
fmt.Println(":")
44+
//
45+
indent++
46+
// Print constants
47+
for _, c := range module.Constants {
48+
printIndent(indent)
49+
//
50+
if c.Extern {
51+
fmt.Printf("extern\t")
52+
} else {
53+
fmt.Printf("const\t")
54+
}
55+
//
56+
if c.Bitwidth != math.MaxUint {
57+
fmt.Printf("u%d ", c.Bitwidth)
58+
}
59+
//
60+
fmt.Printf("%s = %s\n", c.Name, &c.Value)
61+
}
62+
// Print columns
63+
for _, c := range module.Columns {
64+
printIndent(indent)
65+
fmt.Printf("u%d\t%s\t[", c.Bitwidth, c.Name)
66+
//
67+
for i, a := range sourceColumnAttrs(c) {
68+
if i == 0 {
69+
fmt.Print(a)
70+
} else {
71+
fmt.Printf(", %s", a)
72+
}
73+
}
74+
75+
fmt.Println("]")
76+
}
77+
// Print submodules
78+
for _, m := range module.Submodules {
79+
printSourceMapModule(indent, m)
80+
}
81+
}
82+
83+
func sourceColumnAttrs(col corset.SourceColumn) []string {
84+
var attrs []string
85+
//
86+
attrs = append(attrs, fmt.Sprintf("r%d", col.Register.Column().Unwrap()))
87+
//
88+
if col.Multiplier != 1 {
89+
attrs = append(attrs, fmt.Sprintf("×%d", col.Multiplier))
90+
}
91+
//
92+
if col.Computed {
93+
attrs = append(attrs, "computed")
94+
}
95+
//
96+
if col.MustProve {
97+
attrs = append(attrs, "proved")
98+
}
99+
//
100+
switch col.Display {
101+
case corset.DISPLAY_HEX:
102+
attrs = append(attrs, "hex")
103+
case corset.DISPLAY_DEC:
104+
attrs = append(attrs, "dec")
105+
case corset.DISPLAY_BYTES:
106+
attrs = append(attrs, "bytes")
107+
}
108+
//
109+
return attrs
110+
}

pkg/corset/compiler/resolver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ func extractSelector(selector ast.Expr) util.Option[string] {
142142
}
143143
//
144144
if e, ok := selector.(*ast.VariableAccess); ok && e.Name.Depth() == 1 {
145-
return util.Some(e.Name.String())
145+
return util.Some(e.Name.Get(0))
146146
}
147147
// FIXME: #630
148148
panic("unsupported selector")

0 commit comments

Comments
 (0)