Question about Hash #98
-
I wonder why the P.S type MyCircuit struct {
ByteSliceA frontend.Variable
ByteSliceB frontend.Variable
H1 frontend.Variable `gnark:",public"`
}
func (cc *MyCircuit) Define(curveID ecc.ID, cs *frontend.ConstraintSystem) error {
hFunc, err := mimc.NewMiMC("seed", curveID)
if err != nil {
return err
}
h2 := hFunc.Hash(cs, cc.ByteSliceA, cc.ByteSliceB)
//
// THESE ARE NOT EQUAL !!!
//
cs.AssertIsEqual(cc.H1, h2)
}
func TestCircuit(t *testing.T) {
...
var myCirCuit MyCircuit
r1cs, err := frontend.Compile(ecc.BN254, backend.GROTH16, &myCirCuit)
assert.NoError(err)
pk, vk, err := groth16.Setup(r1cs)
assert.NoError(err)
...
hash := hash.MIMC_BN254.New("seed")
hash.Write(byte_slice_A)
hash.Write(byte_slice_B)
h1 := hash.Sum(nil)
var witness MyCircuit
witness.ByteSliceA.Assign(byte_slice_A)
witness.ByteSliceB.Assign(byte_slice_B)
witness.H1.Assign(h1)
...
} |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Hi! Thanks for raising this, at first sight it seems indeed there is an issue with the |
Beta Was this translation helpful? Give feedback.
-
Hi @kysee , can you post the exact code which makes the test fail? I suspect that the error is linked to the fact that in a snark circuit, when you write
then
|
Beta Was this translation helpful? Give feedback.
Hi @kysee , can you post the exact code which makes the test fail? I suspect that the error is linked to the fact that in a snark circuit, when you write
hFunc.Hash(cs, cc.ByteSliceA, cc.ByteSliceB)
,cc.ByteSliceA
andcc.ByteSliceA
are interpreted as 254bits variables (in case of BN254), on the other hand when you writethen
byte_slice_A
andbyte_slice_B
are not interpreted as 254bits variables but as a raw byte slice. So it works whenbyte_slice_A
andbyte_slice_B
are of size 254bits, e.g. this works: