Add differential fuzz tests for EC precompiles #694
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What ❔
This PR contains differential fuzz tests for the EC precompiles (EcAdd, EcMul, EcPairing), testing the correctness of the precompiles implementation against the go-ethereum implementation.
Under the hood, pseudo-random inputs are generated via a Python script (
python/EcHelper.py
) using https://github.com/ethereum/py_pairing and then passed to both the ZKsync precompile and the go-ethereum precompile. The output of both precompiles is then compared.Moreover, the existing fuzz tests in
EcPairing.spec.ts
are broken due to using the high-levelforEach
together withawait
, which does not wait for the promise to finish. Thus, the tests prematurely end, wrongly indicating that the tests passed. These tests have been fixed as well and added toEcPairing_diff.spec.ts
to test the result against the go-ethereum precompile.Prerequisites to run the tests
system-contracts
How to run the tests
EcAdd:
yarn test:diff --grep "diff-fuzz\(EcAdd\)"
EcMul:
yarn test:diff --grep "diff-fuzz\(EcMul\)"
EcPairing:
yarn test:diff --grep "diff-fuzz\(EcPairing\)"