zkevm-circuits icon indicating copy to clipboard operation
zkevm-circuits copied to clipboard

Unify testing-randomness usage across the entire workspace

Open CPerezz opened this issue 3 years ago • 9 comments

LGTM for now to merge and prevent PR outdating. I'd really consider to use testing setup/teardown to reduce the verbosity and redundancy in the tests. Also, I think it would be benefitial to setup a final solution that unifies ALL the randomness used across all the tests so that we don't do different things on each PR/test. See: #641 Originally posted by @CPerezz in https://github.com/privacy-scaling-explorations/zkevm-circuits/pull/654#pullrequestreview-1073967710

As seen in this PR too, there are a lot of different ways on which we're using the randomness in our tests. And As mentioned in #641, it would be nice to have a Rand value for testing that is easy to see (No seeded RNG's) and that is constant across tests.

Therefore I think we could simply set a "random" passed by env-var and simply use it on each test we need to perform. We can simply have a [cgf(test)] lazy_static block that fetches the env var when required.

Closing #641 in favor of this PR as it is a superset.

CPerezz avatar Aug 16 '22 11:08 CPerezz

Would like to know your takes on that @ChihChengLiang @han0110

CPerezz avatar Aug 16 '22 11:08 CPerezz

I'd say keep it simple before we get the challenge API.

ChihChengLiang avatar Aug 16 '22 12:08 ChihChengLiang

I'd say keep it simple before we get the challenge API.

@ChihChengLiang note that this has nothing to do with the RLC or the circuits. This is just a universal way for us to set random values for our tests (constructing a random Tx or Block for example.)

CPerezz avatar Aug 16 '22 12:08 CPerezz

I believe we have 2 cases of randomness in tests:

  1. The randomness value for RLC. I think we could have a fixed constant for this used across all tests. This could be 0x1000
  2. Deterministic but random-looking values to generate inputs for tests. For this I think the easiest way is a seedable rng with a fixed seed.

The idea of getting the fixed random constant from an env var sounds good to me, as long as there's a sensible default value when the env var is not defined.

ed255 avatar Aug 17 '22 09:08 ed255

Thanks for the feedback @ed255

Regarding 1. Not going to make a PR as this will be superset by the new halo2 version removing the randomness requirements. As per 2. I like too the idea of using a seedable rng with a fixed seed passed via env or set as default. NOTE that this will make it a bit more difficult to see randomness-related values (the seed will derive in a consistent but likely large and very random number.

CPerezz avatar Aug 17 '22 10:08 CPerezz

We have now the CHallenge-API. Are we still considering this an issue? Or should I close it?? cc: @ed255 @ChihChengLiang

CPerezz avatar Nov 30 '22 15:11 CPerezz

We have now the CHallenge-API. Are we still considering this an issue? Or should I close it?? cc: @ed255 @ChihChengLiang

It makes sense to me to close this issue considering that with the Challenge-API we don't have the original issue with mock random values everywhere!

ed255 avatar Dec 02 '22 07:12 ed255

I agreee @ed255 but we're still using randomness in a lot of tests. I'd mark this as a good_first issue and leave it without a milestone for now. WDYT?

CPerezz avatar Dec 02 '22 09:12 CPerezz

I agreee @ed255 but we're still using randomness in a lot of tests. I'd mark this as a good_first issue and leave it without a milestone for now. WDYT?

Right, we still have rng used to fill test inputs non-deterministically. It makes sense to leave this as a good first isse :)

ed255 avatar Dec 02 '22 13:12 ed255

close for inactivity

ChihChengLiang avatar May 19 '23 09:05 ChihChengLiang