@ -0,0 +1,50 @@ |
|||||
|
package plonky2_verifier |
||||
|
|
||||
|
import ( |
||||
|
. "gnark-plonky2-verifier/field" |
||||
|
) |
||||
|
|
||||
|
type gate interface { |
||||
|
EvalUnfiltered(vars EvaluationVars) []QuadraticExtension |
||||
|
} |
||||
|
|
||||
|
func (p *PlonkChip) computeFilter( |
||||
|
row int, |
||||
|
groupRange Range, |
||||
|
s QuadraticExtension, |
||||
|
manySelector bool, |
||||
|
) QuadraticExtension { |
||||
|
product := p.qeAPI.ONE_QE |
||||
|
for i := groupRange.start; i < groupRange.end; i++ { |
||||
|
if i == uint64(row) { |
||||
|
continue |
||||
|
} |
||||
|
|
||||
|
product = p.qeAPI.MulExtension(product, p.qeAPI.SubExtension(p.qeAPI.FieldToQE(NewFieldElement(i)), s)) |
||||
|
} |
||||
|
|
||||
|
if manySelector { |
||||
|
product = p.qeAPI.MulExtension(product, p.qeAPI.SubExtension(p.qeAPI.FieldToQE(NewFieldElement(UNUSED_SELECTOR)), s)) |
||||
|
} |
||||
|
|
||||
|
return product |
||||
|
} |
||||
|
|
||||
|
func (p *PlonkChip) evalFiltered( |
||||
|
g gate, |
||||
|
vars EvaluationVars, |
||||
|
row int, |
||||
|
selectorIndex int, |
||||
|
groupRange Range, |
||||
|
numSelectors int, |
||||
|
) []QuadraticExtension { |
||||
|
filter := p.computeFilter(row, groupRange, vars.localConstants[selectorIndex], numSelectors > 1) |
||||
|
|
||||
|
vars.RemovePrefix(numSelectors) |
||||
|
|
||||
|
unfiltered := g.EvalUnfiltered(vars) |
||||
|
for i := range unfiltered { |
||||
|
unfiltered[i] = p.qeAPI.MulExtension(unfiltered[i], filter) |
||||
|
} |
||||
|
return unfiltered |
||||
|
} |
@ -0,0 +1,32 @@ |
|||||
|
package plonky2_verifier |
||||
|
|
||||
|
import ( |
||||
|
. "gnark-plonky2-verifier/field" |
||||
|
) |
||||
|
|
||||
|
type PublicInputGate struct { |
||||
|
} |
||||
|
|
||||
|
func (p *PublicInputGate) WiresPublicInputsHash() []int { |
||||
|
return []int{0, 1, 2, 3} |
||||
|
} |
||||
|
|
||||
|
func (p *PublicInputGate) EvalUnfiltered(pc *PlonkChip, vars EvaluationVars) []QuadraticExtension { |
||||
|
constraints := []QuadraticExtension{} |
||||
|
|
||||
|
wires := p.WiresPublicInputsHash() |
||||
|
hash_parts := vars.publicInputsHash.elements |
||||
|
for i := 0; i < 4; i++ { |
||||
|
wire := wires[i] |
||||
|
hash_part := hash_parts[i] |
||||
|
|
||||
|
diff := pc.qeAPI.SubExtension(vars.localWires[wire], pc.qeAPI.FieldToQE(hash_part)) |
||||
|
constraints = append(constraints, diff) |
||||
|
} |
||||
|
|
||||
|
return constraints |
||||
|
} |
||||
|
|
||||
|
func (p *PublicInputGate) EvalFiltered(vars EvaluationVars) []QuadraticExtension { |
||||
|
return nil |
||||
|
} |
@ -0,0 +1,17 @@ |
|||||
|
package plonky2_verifier |
||||
|
|
||||
|
const UNUSED_SELECTOR = ^uint64(0) // max uint
|
||||
|
|
||||
|
type Range struct { |
||||
|
start uint64 |
||||
|
end uint64 |
||||
|
} |
||||
|
|
||||
|
type SelectorsInfo struct { |
||||
|
selectorIndices []uint64 |
||||
|
groups []Range |
||||
|
} |
||||
|
|
||||
|
func (s *SelectorsInfo) NumSelectors() int { |
||||
|
return len(s.groups) |
||||
|
} |
@ -0,0 +1,19 @@ |
|||||
|
package plonky2_verifier |
||||
|
|
||||
|
import ( |
||||
|
. "gnark-plonky2-verifier/field" |
||||
|
) |
||||
|
|
||||
|
type HashOut struct { |
||||
|
elements [4]F |
||||
|
} |
||||
|
|
||||
|
type EvaluationVars struct { |
||||
|
localConstants []QuadraticExtension |
||||
|
localWires []QuadraticExtension |
||||
|
publicInputsHash HashOut |
||||
|
} |
||||
|
|
||||
|
func (e *EvaluationVars) RemovePrefix(numSelectors int) { |
||||
|
e.localConstants = e.localConstants[numSelectors:] |
||||
|
} |