Skip to content

Prover/Global Constraint Boundary Cancellation Explainer #335

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion prover/protocol/query/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func NewGlobalConstraint(id ifaces.QueryID, expr *symbolic.Expression, noBoundCa
}

if len(noBoundCancel) > 0 {
utils.Require(len(noBoundCancel) == 1, "there should be only 2 bound cancel got %v", len(noBoundCancel))
utils.Require(len(noBoundCancel) == 1, "there should be only 1 bound cancel got %v", len(noBoundCancel))
res.NoBoundCancel = noBoundCancel[0]
}

Expand Down
23 changes: 17 additions & 6 deletions prover/protocol/query/global_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func fibonacci() (wizard.DefineFunc, wizard.ProverStep) {
n := 1 << 3
P := build.RegisterCommit(P, n) // overshadows P

// X[i-1] + X[i-2] - X[i] = 0
expr := ifaces.ColumnAsVariable(column.Shift(P, -1)).
Add(ifaces.ColumnAsVariable(column.Shift(P, -2))).
Sub(ifaces.ColumnAsVariable(P))
Expand Down Expand Up @@ -79,7 +80,7 @@ func pythagoreTriplet() (wizard.DefineFunc, wizard.ProverStep) {

X := build.RegisterCommit(X, n) // overshadows P
Y := build.RegisterCommit(Y, n) // overshadows P

// X[i]^2 + Y[i]^2 - 25 = 0
expr := ifaces.ColumnAsVariable(X).Square().
Add(ifaces.ColumnAsVariable(Y).Square()).
Sub(symbolic.NewConstant(25))
Expand All @@ -106,15 +107,25 @@ func testDummyShifted() (wizard.DefineFunc, wizard.ProverStep) {
define := func(build *wizard.Builder) {
A := build.RegisterCommit(X, 4)
B := build.RegisterCommit(Y, 4)

expr := symbolic.Sub(column.Shift(A, 1),
symbolic.Mul(2, column.Shift(B, 1)))
// X[i+2] - 2 * Y[i+2] = 0
expr := symbolic.Sub(column.Shift(A, 2),
symbolic.Mul(2, column.Shift(B, 2)))

build.InsertGlobal(0, "Q", expr)
}
Prover := func(run *wizard.ProverRuntime) {
x := smartvectors.ForTest(2, 8, 4, 0)
y := smartvectors.ForTest(1, 4, 2, 0)
// Note that the first two indices of x and y columns below does not satisfy the
// constraints. The test still passes because the boundary condition cancellation is by default
// set to true for the InsertGlobal() function. The test will fail if we modify the above line
// by build.InsertGlobal(0, "Q", expr, true) and set noBoundCancellation to true. In this case,
// the columns will behave as circular vectors.

// Also to observe that the boundary indices here are 0 and 1 because for i = 0 onwards, the constraint starts
// looking at index 2, 3, and so on i.e. X[2] = 2*Y[2], X[3] = 2*Y[3].
// The boundary indices will be 2 and 3 if we had constraint: X[i-2] - 2 * Y[i-2] = 0, i.e. we could have put
// whatever values in those indices and the constraint would be satisfied.
x := smartvectors.ForTest(2, 8, 4, 2)
y := smartvectors.ForTest(2, 3, 2, 1)
run.AssignColumn(X, x)
run.AssignColumn(Y, y)
}
Expand Down
Loading