Skip to content

Commit

Permalink
fixup: bug fix wip
Browse files Browse the repository at this point in the history
  • Loading branch information
arijitdutta67 committed Feb 20, 2025
1 parent 0ba1538 commit 4cae671
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 26 deletions.
38 changes: 22 additions & 16 deletions prover/protocol/compiler/distributedprojection/verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,35 +59,41 @@ func (va *distributedProjectionVerifierAction) scaledHornerCheck(run wizard.Runt
)
if va.IsA[index] && va.IsB[index] {
var (
multA = field.One()
multB = field.One()
multA = field.One()
multB = field.One()
hornerA, hornerB field.Element
)
elemParam = run.GetLocalPointEvalParams(va.HornerB0[index].ID).Y
multB = run.GetRandomCoinField(va.EvalCoins[index].Name)
multB.Exp(multB, &va.CumNumOnesPrevSegmentsB[index])
elemParam.Mul(&elemParam, &multB)
elemParam.Neg(&elemParam)
temp := run.GetLocalPointEvalParams(va.HornerA0[index].ID).Y
hornerA = run.GetLocalPointEvalParams(va.HornerA0[index].ID).Y
multA = run.GetRandomCoinField(va.EvalCoins[index].Name)
multA.Exp(multA, &va.CumNumOnesPrevSegmentsA[index])
temp.Mul(&temp, &multA)
elemParam.Add(&elemParam, &temp)
hornerA.Mul(&hornerA, &multA)
elemParam.Add(&elemParam, &hornerA)

hornerB = run.GetLocalPointEvalParams(va.HornerB0[index].ID).Y
multB = run.GetRandomCoinField(va.EvalCoins[index].Name)
multB.Exp(multB, &va.CumNumOnesPrevSegmentsB[index])
hornerB.Mul(&elemParam, &multB)
elemParam.Sub(&elemParam, &hornerB)
} else if va.IsA[index] && !va.IsB[index] {
var (
multA = field.One()
multA = field.One()
hornerA field.Element
)
elemParam = run.GetLocalPointEvalParams(va.HornerA0[index].ID).Y
hornerA = run.GetLocalPointEvalParams(va.HornerA0[index].ID).Y
multA = run.GetRandomCoinField(va.EvalCoins[index].Name)
multA.Exp(multA, &va.CumNumOnesPrevSegmentsA[index])
elemParam.Mul(&elemParam, &multA)
hornerA.Mul(&hornerA, &multA)
elemParam.Add(&elemParam, &hornerA)
} else if !va.IsA[index] && va.IsB[index] {
var (
multB = field.One()
multB = field.One()
hornerB field.Element
)
elemParam = run.GetLocalPointEvalParams(va.HornerB0[index].ID).Y
hornerB = run.GetLocalPointEvalParams(va.HornerB0[index].ID).Y
multB = run.GetRandomCoinField(va.EvalCoins[index].Name)
multB.Exp(multB, &va.CumNumOnesPrevSegmentsB[index])
elemParam.Mul(&elemParam, &multB)
hornerB.Mul(&elemParam, &multB)
elemParam.Sub(&elemParam, &hornerB)
} else {
utils.Panic("Unsupported verifier action registered for %v", va.Name)
}
Expand Down
22 changes: 12 additions & 10 deletions prover/protocol/distributed/compiler/projection/projection.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func NewDistributeProjectionCtx(
DistProjectionInput: make([]*query.DistributedProjectionInput, 0, MaxNumOfQueriesPerModule),
EvalCoins: make([]coin.Info, 0, MaxNumOfQueriesPerModule),
TargetModuleName: targetModuleName,
LastRoundProjection: getLastRoundPerm(initialComp),
LastRoundProjection: getLastRoundProjection(initialComp),
NumSegmentsPerModule: numSegmentPerModule,
QIds: make([]query.Projection, 0, MaxNumOfQueriesPerModule),
}
Expand Down Expand Up @@ -169,8 +169,8 @@ func (p *DistributeProjectionCtx) push(comp *wizard.CompiledIOP, q query.Project
ColumnB: wizardutils.RandLinCombColSymbolic(alpha, q.Inp.ColumnB),
FilterA: fA,
FilterB: fB,
SizeA: utils.NextPowerOfTwo(q.Inp.FilterA.Size() / p.NumSegmentsPerModule),
SizeB: utils.NextPowerOfTwo(q.Inp.FilterB.Size() / p.NumSegmentsPerModule),
SizeA: q.Inp.FilterA.Size(),
SizeB: q.Inp.FilterB.Size(),
EvalCoin: beta.Name,
IsAInModule: true,
IsBInModule: true,
Expand All @@ -183,7 +183,7 @@ func (p *DistributeProjectionCtx) push(comp *wizard.CompiledIOP, q query.Project
ColumnB: symbolic.NewConstant(1),
FilterA: fA,
FilterB: symbolic.NewConstant(1),
SizeA: q.Inp.FilterA.Size() / p.NumSegmentsPerModule,
SizeA: q.Inp.FilterA.Size(),
EvalCoin: beta.Name,
IsAInModule: true,
IsBInModule: false,
Expand All @@ -196,7 +196,7 @@ func (p *DistributeProjectionCtx) push(comp *wizard.CompiledIOP, q query.Project
ColumnB: wizardutils.RandLinCombColSymbolic(alpha, q.Inp.ColumnB),
FilterA: symbolic.NewConstant(1),
FilterB: fB,
SizeB: q.Inp.FilterB.Size() / p.NumSegmentsPerModule,
SizeB: q.Inp.FilterB.Size(),
EvalCoin: beta.Name,
IsAInModule: false,
IsBInModule: true,
Expand Down Expand Up @@ -371,9 +371,11 @@ func (p *DistributeProjectionCtx) assignSumNumOnes(run *wizard.ProverRuntime) {
func (p *DistributeProjectionCtx) computeScaledHorner(run *wizard.ProverRuntime) field.Element {
var (
queryParam = field.Zero()
elemParam = field.Zero()
)
for elemIndex, inp := range p.DistProjectionInput {
var (
elemParam = field.Zero()
)
if inp.IsAInModule && inp.IsBInModule {
var (
colABoard = inp.ColumnA.Board()
Expand All @@ -392,7 +394,7 @@ func (p *DistributeProjectionCtx) computeScaledHorner(run *wizard.ProverRuntime)
multA.Exp(multA, &inp.CumulativeNumOnesPrevSegmentsA)
hornerA = hornerATrace[0]
hornerA.Mul(&hornerA, &multA)
elemParam.Sub(&elemParam, &hornerA)
elemParam.Add(&elemParam, &hornerA)
// Subtract hornerB after scaling
hornerBTrace := poly.GetHornerTrace(colB, filterB, run.GetRandomCoinField(p.EvalCoins[elemIndex].Name))
hornerB = hornerBTrace[0]
Expand All @@ -414,7 +416,7 @@ func (p *DistributeProjectionCtx) computeScaledHorner(run *wizard.ProverRuntime)
multA.Exp(multA, &inp.CumulativeNumOnesPrevSegmentsA)
hornerA = hornerATrace[0]
hornerA.Mul(&hornerA, &multA)
elemParam.Sub(&elemParam, &hornerA)
elemParam.Add(&elemParam, &hornerA)
} else if !inp.IsAInModule && inp.IsBInModule {
var (
colBBoard = inp.ColumnB.Board()
Expand Down Expand Up @@ -505,9 +507,9 @@ func (p *DistributeProjectionCtx) getCoinName(name string, round, queryInRound i
return deriveName[coin.Name](p.QueryID(), name, round, queryInRound)
}

// getLastRoundPerm scans the initialComp and looks for uncompiled projection queries. It returns
// getLastRoundProjection scans the initialComp and looks for uncompiled projection queries. It returns
// the highest round found for a matched projection query. It returns -1 if no queries are found.
func getLastRoundPerm(initialComp *wizard.CompiledIOP) int {
func getLastRoundProjection(initialComp *wizard.CompiledIOP) int {

var (
lastRound = -1
Expand Down

0 comments on commit 4cae671

Please sign in to comment.