mirror of
https://github.com/arnaucube/gnark-plonky2-verifier.git
synced 2026-01-12 00:51:33 +01:00
Renamed symbol a bunch in goldilocks, goldilocks tests pass
This commit is contained in:
@@ -20,15 +20,15 @@ const BN254_SPONGE_WIDTH int = 4
|
||||
const BN254_SPONGE_RATE int = 3
|
||||
|
||||
type BN254Chip struct {
|
||||
api frontend.API `gnark:"-"`
|
||||
gl gl.Chip `gnark:"-"`
|
||||
api frontend.API `gnark:"-"`
|
||||
gl gl.GoldilocksApi `gnark:"-"`
|
||||
}
|
||||
|
||||
type BN254State = [BN254_SPONGE_WIDTH]frontend.Variable
|
||||
type BN254HashOut = frontend.Variable
|
||||
|
||||
func NewBN254Chip(api frontend.API) *BN254Chip {
|
||||
return &BN254Chip{api: api, gl: *gl.NewChip(api)}
|
||||
return &BN254Chip{api: api, gl: *gl.NewGoldilocksApi(api)}
|
||||
}
|
||||
|
||||
func (c *BN254Chip) Poseidon(state BN254State) BN254State {
|
||||
@@ -39,7 +39,7 @@ func (c *BN254Chip) Poseidon(state BN254State) BN254State {
|
||||
return state
|
||||
}
|
||||
|
||||
func (c *BN254Chip) HashNoPad(input []gl.Variable) BN254HashOut {
|
||||
func (c *BN254Chip) HashNoPad(input []gl.GoldilocksVariable) BN254HashOut {
|
||||
state := BN254State{
|
||||
frontend.Variable(0),
|
||||
frontend.Variable(0),
|
||||
@@ -69,7 +69,7 @@ func (c *BN254Chip) HashNoPad(input []gl.Variable) BN254HashOut {
|
||||
return BN254HashOut(state[0])
|
||||
}
|
||||
|
||||
func (c *BN254Chip) HashOrNoop(input []gl.Variable) BN254HashOut {
|
||||
func (c *BN254Chip) HashOrNoop(input []gl.GoldilocksVariable) BN254HashOut {
|
||||
if len(input) <= 3 {
|
||||
returnVal := frontend.Variable(0)
|
||||
|
||||
@@ -94,10 +94,10 @@ func (c *BN254Chip) TwoToOne(left BN254HashOut, right BN254HashOut) BN254HashOut
|
||||
return state[0]
|
||||
}
|
||||
|
||||
func (c *BN254Chip) ToVec(hash BN254HashOut) []gl.Variable {
|
||||
func (c *BN254Chip) ToVec(hash BN254HashOut) []gl.GoldilocksVariable {
|
||||
bits := c.api.ToBinary(hash)
|
||||
|
||||
returnElements := []gl.Variable{}
|
||||
returnElements := []gl.GoldilocksVariable{}
|
||||
|
||||
// Split into 7 byte chunks, since 8 byte chunks can result in collisions
|
||||
chunkSize := 56
|
||||
|
||||
@@ -11,17 +11,17 @@ const MAX_WIDTH = 12
|
||||
const SPONGE_WIDTH = 12
|
||||
const SPONGE_RATE = 8
|
||||
|
||||
type GoldilocksState = [SPONGE_WIDTH]gl.Variable
|
||||
type GoldilocksState = [SPONGE_WIDTH]gl.GoldilocksVariable
|
||||
type GoldilocksStateExtension = [SPONGE_WIDTH]gl.QuadraticExtensionVariable
|
||||
type GoldilocksHashOut = [4]gl.Variable
|
||||
type GoldilocksHashOut = [4]gl.GoldilocksVariable
|
||||
|
||||
type GoldilocksChip struct {
|
||||
api frontend.API `gnark:"-"`
|
||||
gl gl.Chip `gnark:"-"`
|
||||
api frontend.API `gnark:"-"`
|
||||
gl gl.GoldilocksApi `gnark:"-"`
|
||||
}
|
||||
|
||||
func NewGoldilocksChip(api frontend.API) *GoldilocksChip {
|
||||
return &GoldilocksChip{api: api, gl: *gl.NewChip(api)}
|
||||
return &GoldilocksChip{api: api, gl: *gl.NewGoldilocksApi(api)}
|
||||
}
|
||||
|
||||
// The permutation function.
|
||||
@@ -38,7 +38,7 @@ func (c *GoldilocksChip) Poseidon(input GoldilocksState) GoldilocksState {
|
||||
|
||||
// The input elements MUST have all it's elements be within Goldilocks field.
|
||||
// The returned slice's elements will all be within Goldilocks field.
|
||||
func (c *GoldilocksChip) HashNToMNoPad(input []gl.Variable, nbOutputs int) []gl.Variable {
|
||||
func (c *GoldilocksChip) HashNToMNoPad(input []gl.GoldilocksVariable, nbOutputs int) []gl.GoldilocksVariable {
|
||||
var state GoldilocksState
|
||||
|
||||
for i := 0; i < SPONGE_WIDTH; i++ {
|
||||
@@ -54,7 +54,7 @@ func (c *GoldilocksChip) HashNToMNoPad(input []gl.Variable, nbOutputs int) []gl.
|
||||
state = c.Poseidon(state)
|
||||
}
|
||||
|
||||
var outputs []gl.Variable
|
||||
var outputs []gl.GoldilocksVariable
|
||||
|
||||
for {
|
||||
for i := 0; i < SPONGE_RATE; i++ {
|
||||
@@ -69,9 +69,9 @@ func (c *GoldilocksChip) HashNToMNoPad(input []gl.Variable, nbOutputs int) []gl.
|
||||
|
||||
// The input elements can be outside of the Goldilocks field.
|
||||
// The returned slice's elements will all be within Goldilocks field.
|
||||
func (c *GoldilocksChip) HashNoPad(input []gl.Variable) GoldilocksHashOut {
|
||||
func (c *GoldilocksChip) HashNoPad(input []gl.GoldilocksVariable) GoldilocksHashOut {
|
||||
var hash GoldilocksHashOut
|
||||
inputVars := []gl.Variable{}
|
||||
inputVars := []gl.GoldilocksVariable{}
|
||||
|
||||
for i := 0; i < len(input); i++ {
|
||||
inputVars = append(inputVars, c.gl.Reduce(input[i]))
|
||||
@@ -85,7 +85,7 @@ func (c *GoldilocksChip) HashNoPad(input []gl.Variable) GoldilocksHashOut {
|
||||
return hash
|
||||
}
|
||||
|
||||
func (c *GoldilocksChip) ToVec(hash GoldilocksHashOut) []gl.Variable {
|
||||
func (c *GoldilocksChip) ToVec(hash GoldilocksHashOut) []gl.GoldilocksVariable {
|
||||
return hash[:]
|
||||
}
|
||||
|
||||
@@ -135,7 +135,7 @@ func (c *GoldilocksChip) ConstantLayerExtension(state GoldilocksStateExtension,
|
||||
return state
|
||||
}
|
||||
|
||||
func (c *GoldilocksChip) sBoxMonomial(x gl.Variable) gl.Variable {
|
||||
func (c *GoldilocksChip) sBoxMonomial(x gl.GoldilocksVariable) gl.GoldilocksVariable {
|
||||
x2 := c.gl.MulNoReduce(x, x)
|
||||
x3 := c.gl.MulNoReduce(x, x2)
|
||||
x3 = c.gl.ReduceWithMaxBits(x3, 192)
|
||||
@@ -169,7 +169,7 @@ func (c *GoldilocksChip) SBoxLayerExtension(state GoldilocksStateExtension) Gold
|
||||
return state
|
||||
}
|
||||
|
||||
func (c *GoldilocksChip) mdsRowShf(r int, v [SPONGE_WIDTH]gl.Variable) gl.Variable {
|
||||
func (c *GoldilocksChip) mdsRowShf(r int, v [SPONGE_WIDTH]gl.GoldilocksVariable) gl.GoldilocksVariable {
|
||||
res := gl.Zero()
|
||||
|
||||
for i := 0; i < 12; i++ {
|
||||
|
||||
@@ -25,7 +25,7 @@ func (circuit *TestPoseidonCircuit) Define(api frontend.API) error {
|
||||
poseidonChip := NewGoldilocksChip(api)
|
||||
output := poseidonChip.Poseidon(input)
|
||||
|
||||
glApi := gl.NewChip(api)
|
||||
glApi := gl.NewGoldilocksApi(api)
|
||||
|
||||
for i := 0; i < 12; i++ {
|
||||
glApi.AssertIsEqual(output[i], gl.NewVariable(circuit.Out[i]))
|
||||
|
||||
@@ -18,10 +18,10 @@ type TestPublicInputsHashCircuit struct {
|
||||
}
|
||||
|
||||
func (circuit *TestPublicInputsHashCircuit) Define(api frontend.API) error {
|
||||
glAPI := gl.NewChip(api)
|
||||
glAPI := gl.NewGoldilocksApi(api)
|
||||
|
||||
// BN254 -> Binary(64) -> F
|
||||
var input [3]gl.Variable
|
||||
var input [3]gl.GoldilocksVariable
|
||||
for i := 0; i < 3; i++ {
|
||||
input[i] = gl.NewVariable(api.FromBinary(api.ToBinary(circuit.In[i], 64)...))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user