Skip to content

Commit

Permalink
Merge pull request #376 from Consensys/374-adjust-typebound
Browse files Browse the repository at this point in the history
feat: remove some occurrences of *fr.Element
  • Loading branch information
DavePearce authored Nov 5, 2024
2 parents ca2426b + 539037a commit c637f5b
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 22 deletions.
2 changes: 1 addition & 1 deletion pkg/binfile/constraint_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func allocateRegisters(cs *constraintSet, schema *hir.Schema) map[uint]uint {
// Check whether a type constraint required or not.
if c.MustProve && col_type.AsUint() != nil {
bound := col_type.AsUint().Bound()
schema.AddRangeConstraint(c.Handle, ctx, &hir.ColumnAccess{Column: cid, Shift: 0}, *bound)
schema.AddRangeConstraint(c.Handle, ctx, &hir.ColumnAccess{Column: cid, Shift: 0}, bound)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/hir/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func (p *hirParser) parseColumnDeclaration(e sexp.SExp) error {
// Apply type constraint (if applicable)
if columnType.AsUint() != nil {
bound := columnType.AsUint().Bound()
p.env.schema.AddRangeConstraint(columnName, p.module, &ColumnAccess{cid, 0}, *bound)
p.env.schema.AddRangeConstraint(columnName, p.module, &ColumnAccess{cid, 0}, bound)
}
//
return nil
Expand Down
8 changes: 4 additions & 4 deletions pkg/schema/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type UintType struct {
// The number of bits this type represents (e.g. 8 for u8, etc).
nbits uint
// The numeric bound of all values in this type (e.g. 2^8 for u8, etc).
bound *fr.Element
bound fr.Element
}

// NewUintType constructs a new integer type for a given bit width.
Expand All @@ -45,7 +45,7 @@ func NewUintType(nbits uint) *UintType {
bound := new(fr.Element)
bound.SetBigInt(&maxBigInt)

return &UintType{nbits, bound}
return &UintType{nbits, *bound}
}

// AsUint accesses this type assuming it is a Uint. Since this is the case,
Expand Down Expand Up @@ -76,7 +76,7 @@ func (p *UintType) ByteWidth() uint {
// Accept determines whether a given value is an element of this type. For
// example, 123 is an element of the type u8 whilst 256 is not.
func (p *UintType) Accept(val fr.Element) bool {
return val.Cmp(p.bound) < 0
return val.Cmp(&p.bound) < 0
}

// BitWidth returns the bitwidth of this type. For example, the
Expand All @@ -94,7 +94,7 @@ func (p *UintType) HasBound(bound uint) bool {
}

// Bound determines the actual bound for all values which are in this type.
func (p *UintType) Bound() *fr.Element {
func (p *UintType) Bound() fr.Element {
return p.bound
}

Expand Down
16 changes: 0 additions & 16 deletions pkg/util/arrays.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,6 @@ func RemoveMatching[T any](items []T, predicate Predicate[T]) []T {
return items
}

// Equals returns true if both arrays contain equivalent elements.
func Equals(lhs []*fr.Element, rhs []*fr.Element) bool {
if len(lhs) != len(rhs) {
return false
}

for i := 0; i < len(lhs); i++ {
// Check lengths match
if lhs[i].Cmp(rhs[i]) != 0 {
return false
}
}
//
return true
}

// Equals2d returns true if two 2D arrays are equal.
func Equals2d(lhs [][]fr.Element, rhs [][]fr.Element) bool {
if len(lhs) != len(rhs) {
Expand Down

0 comments on commit c637f5b

Please sign in to comment.