Skip to content

Commit

Permalink
fix: ensure IsActive column does not re-activate (#172)
Browse files Browse the repository at this point in the history
* chore: use common constraints for binary

* chore: use common constraint for zero when inactive

* fix: enforce IsActive activation

* chore: use common constraint for binary

* chore: use common cs for zero when inactive

* fix: enforce activation constraints for ecdata antichamber
  • Loading branch information
ivokub authored Oct 16, 2024
1 parent 215b60c commit 9763bf2
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 95 deletions.
13 changes: 8 additions & 5 deletions prover/zkevm/prover/ecdsa/adress.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/consensys/linea-monorepo/prover/protocol/wizard"
sym "github.com/consensys/linea-monorepo/prover/symbolic"
"github.com/consensys/linea-monorepo/prover/zkevm/prover/common"
commoncs "github.com/consensys/linea-monorepo/prover/zkevm/prover/common/common_constraints"
"github.com/consensys/linea-monorepo/prover/zkevm/prover/hash/generic"
)

Expand Down Expand Up @@ -82,11 +83,13 @@ func newAddress(comp *wizard.CompiledIOP, size int, ecRec *EcRecover, ac *antich
comp.InsertGlobal(0, ifaces.QueryIDf("Format_IsAddress"),
sym.Sub(addr.isAddress, sym.Add(addr.isAddressFromEcRec, addr.isAddressFromTxnData)))

mustBeBinary(comp, addr.isAddress)
mustBeBinary(comp, addr.isAddressFromEcRec)
mustBeBinary(comp, addr.isAddressFromTxnData)
isZeroWhenInactive(comp, addr.isAddress, ac.IsActive)
isZeroWhenInactive(comp, addr.hashNum, ac.IsActive)
commoncs.MustBeBinary(comp, addr.isAddress)
commoncs.MustBeBinary(comp, addr.isAddressFromEcRec)
commoncs.MustBeBinary(comp, addr.isAddressFromTxnData)
commoncs.MustZeroWhenInactive(comp, ac.IsActive,
addr.isAddress,
addr.hashNum,
)

// check the trimming of hashHi to the addressHi
addr.csAddressTrimming(comp)
Expand Down
2 changes: 1 addition & 1 deletion prover/zkevm/prover/ecdsa/antichamber.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func newAntichamber(comp *wizard.CompiledIOP, inputs *antichamberInput) *anticha
res.AlignedGnarkData = plonk.DefineAlignment(comp, toAlign)

// root module constraints
res.csIsActive(comp)
res.csIsActiveActivation(comp)
res.csZeroWhenInactive(comp)
res.csConsistentPushingFetching(comp)
res.csIDSequential(comp)
Expand Down
37 changes: 13 additions & 24 deletions prover/zkevm/prover/ecdsa/antichamber_constraints.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,27 @@ 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"
commoncs "github.com/consensys/linea-monorepo/prover/zkevm/prover/common/common_constraints"
)

// csIsActive constraints that IsActive module to be only one for antichamber rounds.
func (ac *antichamber) csIsActive(comp *wizard.CompiledIOP) {
// column must be binary
mustBeBinary(comp, ac.IsActive)
// allow becoming inactive from active but now vice versa
isZeroWhenInactive(comp, ac.IsActive, column.Shift(ac.IsActive, -1))
// csIsActiveActivation constraints that IsActive module to be only one for antichamber rounds.
func (ac *antichamber) csIsActiveActivation(comp *wizard.CompiledIOP) {
// IsActive must be binary and cannot transition from 0 to 1
commoncs.MustBeActivationColumns(comp, ac.IsActive)
}

func (ac *antichamber) csZeroWhenInactive(comp *wizard.CompiledIOP) {
for _, c := range ac.cols(false) {
isZeroWhenInactive(comp, c, ac.IsActive)
}
for _, c := range ac.EcRecover.cols() {
isZeroWhenInactive(comp, c, ac.IsActive)
}
for _, c := range ac.Addresses.cols() {
isZeroWhenInactive(comp, c, ac.IsActive)
}
for _, c := range ac.txSignature.cols() {
isZeroWhenInactive(comp, c, ac.IsActive)
}
for _, c := range ac.UnalignedGnarkData.cols() {
isZeroWhenInactive(comp, c, ac.IsActive)
}
commoncs.MustZeroWhenInactive(comp, ac.IsActive, ac.cols(false)...)
commoncs.MustZeroWhenInactive(comp, ac.IsActive, ac.EcRecover.cols()...)
commoncs.MustZeroWhenInactive(comp, ac.IsActive, ac.Addresses.cols()...)
commoncs.MustZeroWhenInactive(comp, ac.IsActive, ac.txSignature.cols()...)
commoncs.MustZeroWhenInactive(comp, ac.IsActive, ac.UnalignedGnarkData.cols()...)
}

func (ac *antichamber) csConsistentPushingFetching(comp *wizard.CompiledIOP) {
// pushing and fetching must be binary
mustBeBinary(comp, ac.IsPushing)
mustBeBinary(comp, ac.IsFetching)
commoncs.MustBeBinary(comp, ac.IsPushing)
commoncs.MustBeBinary(comp, ac.IsFetching)
// pushing and fetching cannot be active at the same time
comp.InsertGlobal(
ROUND_NR,
Expand All @@ -58,7 +47,7 @@ func (ac *antichamber) csIDSequential(comp *wizard.CompiledIOP) {
func (ac *antichamber) csSource(comp *wizard.CompiledIOP) {
// source must be binary
// Source=0 <> ECRecover, Source=1 <> TxSignature
mustBeBinary(comp, ac.Source)
commoncs.MustBeBinary(comp, ac.Source)
}

func (ac *antichamber) csTransitions(comp *wizard.CompiledIOP) {
Expand Down
3 changes: 2 additions & 1 deletion prover/zkevm/prover/ecdsa/ecdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,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"
commoncs "github.com/consensys/linea-monorepo/prover/zkevm/prover/common/common_constraints"
)

var (
Expand Down Expand Up @@ -173,7 +174,7 @@ func (ec *EcRecover) csEcDataProjection(comp *wizard.CompiledIOP, src *ecDataSou
}

func (ec *EcRecover) csConstraintAuxProjectionMask(comp *wizard.CompiledIOP) {
mustBeBinary(comp, ec.AuxProjectionMask)
commoncs.MustBeBinary(comp, ec.AuxProjectionMask)
}

// TODO: must be called from the antichamber to ensure that the mask is consistent with the column in the root antichamber
Expand Down
27 changes: 0 additions & 27 deletions prover/zkevm/prover/ecdsa/utils.go

This file was deleted.

2 changes: 2 additions & 0 deletions prover/zkevm/prover/ecpair/ecpair.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ func newECPair(comp *wizard.CompiledIOP, limits *Limits, ecSource *ECPairSource)
UnalignedG2MembershipData: newUnalignedG2MembershipData(comp, limits),
}

// IsActive activation - can only go from 1 to {0, 1} and from 0 to 0.
res.csIsActiveActivation(comp)
// masks and flags are binary
res.csBinaryConstraints(comp)
// IsActive is only active when we are either pulling or computing in the unaligned submodules
Expand Down
61 changes: 24 additions & 37 deletions prover/zkevm/prover/ecpair/ecpair_constraints.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,26 @@ 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"
common "github.com/consensys/linea-monorepo/prover/zkevm/prover/common/common_constraints"
)

func (ec *ECPair) csIsActiveActivation(comp *wizard.CompiledIOP) {
// IsActive is binary and cannot transition from 0 to 1
common.MustBeActivationColumns(comp, ec.IsActive)
}

func (ec *ECPair) csBinaryConstraints(comp *wizard.CompiledIOP) {
mustBeBinary(comp, ec.IsActive)
mustBeBinary(comp, ec.UnalignedPairingData.IsPulling)
mustBeBinary(comp, ec.UnalignedPairingData.IsComputed)
mustBeBinary(comp, ec.UnalignedPairingData.IsFirstLineOfInstance)
mustBeBinary(comp, ec.UnalignedPairingData.IsAccumulatorInit)
mustBeBinary(comp, ec.UnalignedPairingData.IsAccumulatorCurr)
mustBeBinary(comp, ec.UnalignedPairingData.IsAccumulatorPrev)
mustBeBinary(comp, ec.UnalignedPairingData.ToMillerLoopCircuitMask)
mustBeBinary(comp, ec.UnalignedPairingData.ToFinalExpCircuitMask)
mustBeBinary(comp, ec.UnalignedG2MembershipData.IsPulling)
mustBeBinary(comp, ec.UnalignedG2MembershipData.IsComputed)
mustBeBinary(comp, ec.UnalignedG2MembershipData.ToG2MembershipCircuitMask)
common.MustBeBinary(comp, ec.UnalignedPairingData.IsPulling)
common.MustBeBinary(comp, ec.UnalignedPairingData.IsComputed)
common.MustBeBinary(comp, ec.UnalignedPairingData.IsFirstLineOfInstance)
common.MustBeBinary(comp, ec.UnalignedPairingData.IsAccumulatorInit)
common.MustBeBinary(comp, ec.UnalignedPairingData.IsAccumulatorCurr)
common.MustBeBinary(comp, ec.UnalignedPairingData.IsAccumulatorPrev)
common.MustBeBinary(comp, ec.UnalignedPairingData.ToMillerLoopCircuitMask)
common.MustBeBinary(comp, ec.UnalignedPairingData.ToFinalExpCircuitMask)
common.MustBeBinary(comp, ec.UnalignedG2MembershipData.IsPulling)
common.MustBeBinary(comp, ec.UnalignedG2MembershipData.IsComputed)
common.MustBeBinary(comp, ec.UnalignedG2MembershipData.ToG2MembershipCircuitMask)
}

func (ec *ECPair) csFlagConsistency(comp *wizard.CompiledIOP) {
Expand All @@ -41,11 +46,13 @@ func (ec *ECPair) csFlagConsistency(comp *wizard.CompiledIOP) {

func (ec *ECPair) csOffWhenInactive(comp *wizard.CompiledIOP) {
// nothing is set when inactive
isZeroWhenInactive(comp, ec.UnalignedPairingData.Limb, ec.IsActive)
isZeroWhenInactive(comp, ec.UnalignedPairingData.ToMillerLoopCircuitMask, ec.IsActive)
isZeroWhenInactive(comp, ec.UnalignedPairingData.ToFinalExpCircuitMask, ec.IsActive)
isZeroWhenInactive(comp, ec.UnalignedG2MembershipData.Limb, ec.IsActive)
isZeroWhenInactive(comp, ec.UnalignedG2MembershipData.ToG2MembershipCircuitMask, ec.IsActive)
common.MustZeroWhenInactive(comp, ec.IsActive,
ec.UnalignedPairingData.Limb,
ec.UnalignedPairingData.ToMillerLoopCircuitMask,
ec.UnalignedPairingData.ToFinalExpCircuitMask,
ec.UnalignedG2MembershipData.Limb,
ec.UnalignedG2MembershipData.ToG2MembershipCircuitMask,
)
}

func (ec *ECPair) csProjections(comp *wizard.CompiledIOP) {
Expand Down Expand Up @@ -277,23 +284,3 @@ func (ec *ECPair) csAccumulatorMask(comp *wizard.CompiledIOP) {
),
)
}

// -- utils. Copied from prover/zkevm/prover/statemanager/statesummary/state_summary.go

// isZeroWhenInactive constraints the column to cancel when inactive.
func isZeroWhenInactive(comp *wizard.CompiledIOP, c, isActive ifaces.Column) {
comp.InsertGlobal(
roundNr,
ifaces.QueryIDf("%v_IS_ZERO_WHEN_INACTIVE", c.GetColID()),
sym.Sub(c, sym.Mul(c, isActive)),
)
}

// mustBeBinary constrains the current column to be binary.
func mustBeBinary(comp *wizard.CompiledIOP, c ifaces.Column) {
comp.InsertGlobal(
roundNr,
ifaces.QueryIDf("%v_MUST_BE_BINARY", c.GetColID()),
sym.Mul(c, sym.Sub(c, 1)),
)
}

0 comments on commit 9763bf2

Please sign in to comment.