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

Add differential fuzz tests for EC precompiles #694

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

berndartmueller
Copy link

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-level forEach together with await, 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 to EcPairing_diff.spec.ts to test the result against the go-ethereum precompile.

Prerequisites to run the tests

  1. Make sure python3 and go are installed
  2. Change the working directory to system-contracts
  3. Run local node
    yarn test-node

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\)"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant