Skip to content

Commit

Permalink
Prover/Codehash Non Power of Two Column Size (#618)
Browse files Browse the repository at this point in the history
* Revert "adjusted size for corset columns"

This reverts commit b1a7319.

* fixed bug and added panic message for a non power of two size column

* removing panic

* reinsteaded the panic

---------

Co-authored-by: gusiri <[email protected]>
  • Loading branch information
arijitdutta67 and gusiri authored Jan 29, 2025
1 parent b1a7319 commit 4cf988c
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 11 deletions.
5 changes: 4 additions & 1 deletion prover/protocol/column/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/consensys/linea-monorepo/prover/protocol/ifaces"
"github.com/consensys/linea-monorepo/prover/utils"
"github.com/consensys/linea-monorepo/prover/utils/collection"
"github.com/sirupsen/logrus"
)

// Store registers [Natural] for structs that can return the infos given a name
Expand Down Expand Up @@ -63,7 +64,9 @@ func (s *Store) AddToRound(round int, name ifaces.ColID, size int, status Status
}

if !utils.IsPowerOfTwo(size) {
utils.Panic("can't register %v because it has a non-power of two size (%v)", name, size)
adjustedSize := utils.NextPowerOfTwo(size)
logrus.Infof("Can't register %v because it has a non-power of two size (%v). Adjusted size to next power of two: %v", name, size, adjustedSize)
size = adjustedSize
}

// Compute the location of the commitment in the store
Expand Down
5 changes: 4 additions & 1 deletion prover/protocol/wizard/compiled.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,10 @@ func (c *CompiledIOP) InsertCommit(round int, name ifaces.ColID, size int) iface
// - if the size of the column is not a power of 2
// - if a column using the same name has already been registered
func (c *CompiledIOP) InsertColumn(round int, name ifaces.ColID, size int, status column.Status) ifaces.Column {

// Panic if the size is not a power of 2
if !utils.IsPowerOfTwo(size) {
utils.Panic("Registering column %v with a non power of two size = %v", name, size)
}
// @alex: this has actually caught a few typos. When wrongly setting an
// incorrect but very large size here, it will generate a disproportionate
// wizard
Expand Down
11 changes: 4 additions & 7 deletions prover/zkevm/arithmetization/definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,14 @@ func (s *schemaScanner) scanColumns() {
module = s.Modules[ctx.Module()]
moduleLimit = s.LimitMap[module.Name]
mult = ctx.LengthMultiplier()
size = int(mult) * moduleLimit
)

// adjust the size , this adjusts the size for interleaved columns and their permuted version.
// Since these are the only columns from corset with non-power of two.
if !utils.IsPowerOfTwo(size) {
size = utils.NextPowerOfTwo(int(mult) * moduleLimit)
}
/*if _, isIL := s.InterleavedColumns[name]; isIL {
continue
}*/

// #nosec G115 -- this bound will not overflow
s.Comp.InsertCommit(0, ifaces.ColID(name), size)
s.Comp.InsertCommit(0, ifaces.ColID(name), int(mult)*moduleLimit)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/consensys/linea-monorepo/prover/protocol/ifaces"
"github.com/consensys/linea-monorepo/prover/protocol/wizard"
sym "github.com/consensys/linea-monorepo/prover/symbolic"
"github.com/consensys/linea-monorepo/prover/utils"
"github.com/consensys/linea-monorepo/prover/zkevm/prover/common"
commonconstraints "github.com/consensys/linea-monorepo/prover/zkevm/prover/common/common_constraints"
"github.com/consensys/linea-monorepo/prover/zkevm/prover/statemanager/mimccodehash"
Expand Down Expand Up @@ -57,7 +58,7 @@ type Module struct {
func NewModule(comp *wizard.CompiledIOP, name string, ss *statesummary.Module, mch *mimccodehash.Module) Module {

name = name + "_CODEHASH_CONSISTENCY"
size := ss.IsActive.Size() + mch.IsActive.Size()
size := utils.NextPowerOfTwo[int](ss.IsActive.Size() + mch.IsActive.Size())

ch := Module{
StateSummaryInput: ss,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func TestConsistency(t *testing.T) {
mimcCodeHash *mimccodehash.Module
consistency Module
sizeStateSummary = 128
sizeMimcCodeHash = 128
sizeMimcCodeHash = 256
)

define := func(b *wizard.Builder) {
Expand Down

0 comments on commit 4cf988c

Please sign in to comment.