Kevin Jue c01f530fe1
fix: Support range checking non aligned bitwidth values (#47)
* initial commit

* most of the code done

* made global poseidon chip

* changed decompSize and added some panics

* made all gl chip as pointers

* working code

* revert go.mod and go.sum

* cleanup and comments

* cleaned up range checker selection

* renamed gnarkRangeCheckSelector to gnarkRangeCheckerSelector

* addressed PR comment

* addressed overflow issue identified by Veridise

* added some comments

* fixed some comment typos

* restore change made from commit hash 85d20ce and 9617141
2024-01-04 13:56:13 -08:00

55 lines
1.6 KiB
Go

package gates
import (
"fmt"
"regexp"
"github.com/consensys/gnark/frontend"
gl "github.com/succinctlabs/gnark-plonky2-verifier/goldilocks"
)
type Gate interface {
Id() string
EvalUnfiltered(
api frontend.API,
glApi *gl.Chip,
vars EvaluationVars,
) []gl.QuadraticExtensionVariable
}
var gateRegexHandlers = map[*regexp.Regexp]func(parameters map[string]string) Gate{
arithmeticGateRegex: deserializeArithmeticGate,
arithmeticExtensionGateRegex: deserializeExtensionArithmeticGate,
baseSumGateRegex: deserializeBaseSumGate,
constantGateRegex: deserializeConstantGate,
cosetInterpolationGateRegex: deserializeCosetInterpolationGate,
exponentiationGateRegex: deserializeExponentiationGate,
mulExtensionGateRegex: deserializeMulExtensionGate,
noopGateRegex: deserializeNoopGate,
poseidonGateRegex: deserializePoseidonGate,
poseidonMdsGateRegex: deserializePoseidonMdsGate,
publicInputGateRegex: deserializePublicInputGate,
randomAccessGateRegex: deserializeRandomAccessGate,
reducingExtensionGateRegex: deserializeReducingExtensionGate,
reducingGateRegex: deserializeReducingGate,
}
func GateInstanceFromId(gateId string) Gate {
for regex, handler := range gateRegexHandlers {
matches := regex.FindStringSubmatch(gateId)
if matches != nil {
parameters := make(map[string]string)
for i, name := range regex.SubexpNames() {
if i != 0 && name != "" {
parameters[name] = matches[i]
}
}
if matches != nil {
return handler(parameters)
}
}
}
panic(fmt.Sprintf("Unknown gate ID %s", gateId))
}