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
This commit is contained in:
Kevin Jue
2024-01-04 13:56:13 -08:00
committed by GitHub
parent c82e6f3747
commit c01f530fe1
24 changed files with 224 additions and 41 deletions

View File

@@ -22,7 +22,7 @@ const BN254_SPONGE_RATE int = 3
type BN254Chip struct {
api frontend.API `gnark:"-"`
gl gl.Chip `gnark:"-"`
gl *gl.Chip `gnark:"-"`
}
type BN254State = [BN254_SPONGE_WIDTH]frontend.Variable
@@ -33,7 +33,7 @@ func NewBN254Chip(api frontend.API) *BN254Chip {
panic("Gnark compiler not set to BN254 scalar field")
}
return &BN254Chip{api: api, gl: *gl.New(api)}
return &BN254Chip{api: api, gl: gl.New(api)}
}
func (c *BN254Chip) Poseidon(state BN254State) BN254State {

View File

@@ -17,11 +17,11 @@ type GoldilocksHashOut = [POSEIDON_GL_HASH_SIZE]gl.Variable
type GoldilocksChip struct {
api frontend.API `gnark:"-"`
gl gl.Chip `gnark:"-"`
gl *gl.Chip `gnark:"-"`
}
func NewGoldilocksChip(api frontend.API) *GoldilocksChip {
return &GoldilocksChip{api: api, gl: *gl.New(api)}
return &GoldilocksChip{api: api, gl: gl.New(api)}
}
// The permutation function.

View File

@@ -26,7 +26,7 @@ func (circuit *TestPublicInputsHashCircuit) Define(api frontend.API) error {
input[i] = gl.NewVariable(api.FromBinary(api.ToBinary(circuit.In[i], 64)...))
}
poseidonChip := &GoldilocksChip{api: api, gl: *glAPI}
poseidonChip := &GoldilocksChip{api: api, gl: glAPI}
output := poseidonChip.HashNoPad(input[:])
// Check that output is correct