Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: test/Assert (ProverSucceeded, ...) may incorrectly cache a compiled circuit #283

Closed
gbotrel opened this issue Mar 18, 2022 · 3 comments
Assignees
Labels
bug Something isn't working
Milestone

Comments

@gbotrel
Copy link
Collaborator

gbotrel commented Mar 18, 2022

To speed up testing, and avoid recompiling the same circuit when testing against several witnesses, test/Assert have a cache of compiled circuits.
However, the key for the circuits is too weak;

key := curveID.String() + backendID.String() + reflect.TypeOf(circuit).String()

If you consider the case where a circuit is define like so;

type MyCircuit struct {
A frontend.Variable
somethingMutable XXX
}

were somethingMutable could be a hash function or a twisted edwards curve ID, which alters the Define behavior. Then the 2nd compilation after changing this variable will not be reflected.

@gbotrel gbotrel added the bug Something isn't working label Mar 18, 2022
@gbotrel gbotrel added this to the v0.7.0 milestone Mar 18, 2022
@gbotrel gbotrel self-assigned this Mar 18, 2022
@ivokub
Copy link
Collaborator

ivokub commented Mar 18, 2022

There is Run method on assert which takes additional description arguments (for running as subtests). Maybe an easy fix would be to include the subtest name in the cache key?

@gbotrel
Copy link
Collaborator Author

gbotrel commented Mar 18, 2022

I don't think it'll work ; subtests name are derived from backendID and curveID.
So same problem applies ; a same circuit compile with same backend and curve, but with a behavior that changes will not be correctly added into the cache.

Adding the pointer (unsafe) in the key works, but, I'm also aiming for adding a t.Parallel in the assert.Run, WIP 👍

@ivokub
Copy link
Collaborator

ivokub commented Mar 18, 2022

I don't think it'll work ; subtests name are derived from backendID and curveID. So same problem applies ; a same circuit compile with same backend and curve, but with a behavior that changes will not be correctly added into the cache.

In general, it is possible to define any additional string context for the subtest (https://pkg.go.dev/github.com/consensys/gnark@v0.6.4/test#Assert.Run), but yes, currently in the most of the cases the context is just the curve and backend.

gbotrel added a commit that referenced this issue Mar 18, 2022
gbotrel added a commit that referenced this issue Mar 18, 2022
…ts of same type (#284)

* fix: closes #283. ensure test.Assert compile cache handles different object of same type

* fix: use UnsafeAddr instead of UnsafePointer to be retro compatible

* fix: fix previous commit

* fix: apply pr patch
@gbotrel gbotrel closed this as completed Mar 18, 2022
gbotrel added a commit that referenced this issue Mar 22, 2022
* build: updated to latest gnark-crypto

* build: updated to latest gnark-crypto

* refactor: introduce Curve interface in std/ and updated eddsa tests

* feat: added std/eddsa publicKey and signature assign helpers

* refactor(std): merged twistededwards and bandersnatch. IsOnCurve failing for bandersnatch

* fix: closes #283. ensure test.Assert compile cache handles different object of same type

* fix: use UnsafeAddr instead of UnsafePointer to be retro compatible

* fix: fix previous commit

* test: test all twisted ed curve operations

* Fixes #283 : ensure test.Assert compile cache handles different objects of same type (#284)

* fix: closes #283. ensure test.Assert compile cache handles different object of same type

* fix: use UnsafeAddr instead of UnsafePointer to be retro compatible

* fix: fix previous commit

* fix: apply pr patch

* style: make twistededwards/Point methods package private
gbotrel added a commit that referenced this issue Mar 24, 2022
* perf(std/tEd): first bit in ScalarMul handled separately

* perf(std/tEd): rearrange Double --> less constraints

* perf(std/EdDSA): rearrange eddsa verify (-1 addtion, -1 MustBeOnCurve)

* perf(std/tEd): Lookup2 for first 2 bits in ScalarMulFixedBase

* perf(std/tEd): FixedPoint should be hidden by the API

* test(tEd): test scalarMul for all curves and schemes

* fix(tEd): case when scalar size is odd

* fix(tEd): case when scalar size is odd

* refactor(eddsa): rearrange eddsa verif as cofactor clearing counts

* feat(tEd): implements double-base scalar mul

* perf(EdDSA): eddsa gadget using double-base scalar mul

* perf(bandersnatch): apply tEd perf changes to Bandersnatch

* fix: fixed wrong bigInt op in plonk api

* style(eddsa, tEd): no benchmarks

* style(eddsa, tEd): no benchmarks

* perf(bandersnatch): GLV scalar mul in-circuit

* test(twistededwards): randomise test

* refactor(bandersnatch): review PR 263

* fix(bandersnatch): curveID in hint not checked

* fix(bandersnatch): check curveID for endomorphism availability

* style(bandersnatch): correct comment

* style(bandersnatch): correct comment about negative scalars

* fix(bandersnatch): increase scalars size bound to 129 + comments

* fix: hint signature in bandersnatch matches new format

* refactor: eddsa factorizing and code cleaning (#285)

* build: updated to latest gnark-crypto

* build: updated to latest gnark-crypto

* refactor: introduce Curve interface in std/ and updated eddsa tests

* feat: added std/eddsa publicKey and signature assign helpers

* refactor(std): merged twistededwards and bandersnatch. IsOnCurve failing for bandersnatch

* fix: closes #283. ensure test.Assert compile cache handles different object of same type

* fix: use UnsafeAddr instead of UnsafePointer to be retro compatible

* fix: fix previous commit

* test: test all twisted ed curve operations

* Fixes #283 : ensure test.Assert compile cache handles different objects of same type (#284)

* fix: closes #283. ensure test.Assert compile cache handles different object of same type

* fix: use UnsafeAddr instead of UnsafePointer to be retro compatible

* fix: fix previous commit

* fix: apply pr patch

* style: make twistededwards/Point methods package private

* style: fix gosec errors in std/eddsa

* feat: disable GLV mul in bandersnatch until #268 is fixed

Co-authored-by: Thomas Piellard <thomas.piellard@consensys.net>
Co-authored-by: Gautam Botrel <gautam.botrel@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants