iden3 / circom_tester

Provides tools for testing circom circuits.
56 stars 28 forks source link

Add custom output path and recompile options #4

Closed AndriianChestnykh closed 2 years ago

AndriianChestnykh commented 2 years ago

This is to enable optional re-compilation for tests as opposed to current mandatory compilation. It may save some time when only inputs but not circuits are changed between test runs.

This PR introduces additional options property object:

outputOptions: {
    basePath: "" // path to base folder for compilation artefacts
    recompile: false // If set to false, it will recompile only if target compilation folder does not exists. Otherwise, recompile in any case
},

It is backward compatible with existing tests

Example:

        circuit = await tester(
            path.join(__dirname, "circuits", "someCircuit.circom"),
            {
                outputOptions: {
                    basePath: path.join(__dirname, "build"),
                    recompile: false,
                },
                reduceConstraints: false,
            },
        );

Note: This PR as of its being initially open does add this options only for WASM tester but not for C tester. But I can add it for C as well if get a positive feedback.

alrubio commented 2 years ago

Thanks for the proposal. I like it, but I would prefer to have "basePath" and "recompile" as direct options instead of being part of outputOptions. I'll adapt it this way and merge it. I'll also include them for the tester for C.

AndriianChestnykh commented 2 years ago

Thanks for the proposal. I like it, but I would prefer to have "basePath" and "recompile" as direct options instead of being part of outputOptions. I'll adapt it this way and merge it. I'll also include them for the tester for C.

Perfect! Let me know if you need any help to complete it.

alrubio commented 2 years ago

Now it should be used like this circuit = await tester( path.join(dirname, "circuits", "someCircuit.circom"), { output: path.join(dirname, "build"), recompile: false, }, ); and it checks if the needed folders exist and produce an exception if they don't and recompile is set to false. If this works for you as expected I'll merge it and change the tester for C accordingly.

AndriianChestnykh commented 2 years ago

Thanks, @alrubio. I'll check it later this week and let you know.

AndriianChestnykh commented 2 years ago

@alrubio, it looks good for me. As a minor improvement I would prefer to keep all the artifacts specific for the compilation under a separate folder. A folder can be named automatically after the *.circom file name which is being compiled image

alrubio commented 2 years ago

I think you can get the effect you want by calling with output: path.join(__dirname, "build/circuitName"), so I prefer to leave it as it is now. If you have no further comment I will merge it and close the PR.

AndriianChestnykh commented 2 years ago

Sure, please merge the PR.