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

feat: Solidity verification of light client proofs with Plonk #27

Closed
wants to merge 13 commits into from

Conversation

storojs72
Copy link
Member

@storojs72 storojs72 commented Jun 18, 2024

This PR adds Foundry project for verification the Plonk proofs of light client programs (epoch-change and inclusion) using Solidity contract from Sphinx artefacts.

The solidity folder now contains three subfolders:

  • contracts (Foundry project with Solidity code);
  • contracts-generator (Rust program for generating the contracts using Sphinx);
  • fixture-generator (Rust program for generating a so-called fixture - a JSON file with the encoded proof, public values and vk necessary for the verification).

Currently, executing Solidity verification should give tentatively following:

artemstorozhuk@Artems-MacBook-Pro aptos % cd solidity/contracts
artemstorozhuk@Artems-MacBook-Pro contracts % forge test
[⠊] Compiling...
[⠒] Compiling 9 files with Solc 0.8.26
[⠢] Solc 0.8.26 finished in 1.06s
Compiler run successful!

Ran 8 tests for test/test_lc_proofs.sol:SolidityVerificationTest
[PASS] testFail_FakeProofEpochChange() (gas: 8660281895700906415)
[PASS] testFail_FakeProofInclusion() (gas: 8660281895700906410)
[FAIL. Reason: assertion failed] testFail_FakePublicValuesEpochChange() (gas: 320971)
[FAIL. Reason: assertion failed] testFail_FakePublicValuesInclusion() (gas: 325381)
[FAIL. Reason: assertion failed] testFail_WrongVkValuesEpochChange() (gas: 2385538)
[FAIL. Reason: assertion failed] testFail_WrongVkValuesInclusion() (gas: 2385702)
[PASS] testValidEpochChangeProofPlonk() (gas: 318083)
[PASS] testValidInclusionProofPlonk() (gas: 318091)
Suite result: FAILED. 4 passed; 4 failed; 0 skipped; finished in 13.00ms (41.70ms CPU time)

Two positive tests that demonstrate Plonk verification of epoch-change and inclusion proofs at ~318k gas are successful and two negative tests if fake proofs are used are successful.

There are also additionally four negative tests - when fake public values or wrong vk are used - that are currently failed. That means essentially that current version of Plonk contract (e48c01ec tag from Sphinx) allows submitting those fake input. I have checked that in recent versions of SP1 (in v1.0.7-testnet) it is fixed, so we in theory should get those tests passing once forward porting latest SP1 changes to sphinx.

If you want to use custom fixture, you can regenerate it with fixture-generator program:

cd aptos
RUST_LOG=info RUSTFLAGS="-C target-cpu=native --cfg tokio_unstable" SHARD_SIZE=4194304 SHARD_BATCH_SIZE=0 cargo +nightly run --bin generate-fixture --features aptos --release -- --program <inclusion | epoch_change>

This will run either inclusion or epoch_change proving (depending on --program flag value) and will end up with fixture JSON file replaced the current one in aptos/solidity/contracts/src/plonk_fixtures.

In case when new Sphinx is released and new version contains some breaking changes in the Plonk contracts, one can reinstall the Sphinx artefacts using contracts-generator program:

cd aptos
cargo run --bin generate-contracts --release

this will invoke try_install_plonk_bn254_artifacts which will either tries to download the parameters from SP1 AWS bucket (their parameters don't work with our LC programs so we are going to replace this with our bucket containing our rebuilt parameters) or if they already exist, it will end up with just copying the *.sol files to the aptos/solidity/contracts/src/plonk. So until we have our own AWS bucket, the Plonk parameters have to be rebuilt manually (this process takes ~1 hour on R7 machine) and copied into ~/.sp1/circuits/plonk_bn254/<commit> directory.

@tchataigner
Copy link
Contributor

Thank you for the PR @storojs72! Could you add the documentation for this? I think what you have written in the PR header is already quite interesting and should be added to our mdBook

@storojs72 storojs72 changed the base branch from dev to plonk June 18, 2024 12:58
@storojs72 storojs72 changed the base branch from plonk to dev June 18, 2024 12:58
@wwared
Copy link
Contributor

wwared commented Jun 18, 2024

Can you change the base branch to be plonk instead of dev? Though the docs are in dev not plonk (you could make a separate PR for the docs), the plonk branch has the LC changes to use prove_plonk

It might require a rebase

@storojs72 storojs72 changed the base branch from dev to plonk June 18, 2024 13:15
@storojs72 storojs72 force-pushed the artem/solidity-plonk branch 3 times, most recently from a412dee to 220bac3 Compare June 18, 2024 21:19
huitseeker and others added 12 commits June 18, 2024 22:20
* docs: proof server rust doc

Signed-off-by: Thomas Chataigner <[email protected]>

* docs: mdbook

Signed-off-by: Thomas Chataigner <[email protected]>

* chore: missing link in summary

Co-authored-by: wwared <[email protected]>

* docs: document release

Signed-off-by: Thomas Chataigner <[email protected]>

* docs: integrate suggested changes

Co-authored-by: wwared <[email protected]>

* docs: integrate review

Signed-off-by: Thomas Chataigner <[email protected]>

* docs: apply suggested updates

Co-authored-by: wwared <[email protected]>
Co-authored-by: Artem Storozhuk <[email protected]>

* docs: another batch of suggestions

Co-authored-by: wwared <[email protected]>

* docs: integrate more review

Signed-off-by: Thomas Chataigner <[email protected]>

* docs: Add list of useful tests, mention e2e.rs is STARK-only, remove hackmd link

* docs: Groth16 -> Plonk/SNARK

---------

Signed-off-by: Thomas Chataigner <[email protected]>
Co-authored-by: wwared <[email protected]>
Co-authored-by: Artem Storozhuk <[email protected]>
* ci: release ci

Signed-off-by: Thomas Chataigner <[email protected]>

* ci: add release creation

Signed-off-by: Thomas Chataigner <[email protected]>

* ci: fix release files

Signed-off-by: Thomas Chataigner <[email protected]>

* ci: update based on review

Signed-off-by: Thomas Chataigner <[email protected]>

* ci: dry files & hotfix flow

Signed-off-by: Thomas Chataigner <[email protected]>

* Apply suggestions from code review

Co-authored-by: Samuel Burnham <[email protected]>

* ci: base for PR

Signed-off-by: Thomas Chataigner <[email protected]>

* ci: Update release workflow (#26)

* ci: Update release workflow

* fix: Enforce `major.minor` version only for initial release

* fix: Use full `major.minor.patch` for `Cargo.toml` and tag

---------

Signed-off-by: Thomas Chataigner <[email protected]>
Co-authored-by: Samuel Burnham <[email protected]>
* docs: proof server rust doc

Signed-off-by: Thomas Chataigner <[email protected]>

* docs: mdbook

Signed-off-by: Thomas Chataigner <[email protected]>

* chore: missing link in summary

Co-authored-by: wwared <[email protected]>

* docs: document release

Signed-off-by: Thomas Chataigner <[email protected]>

* docs: integrate suggested changes

Co-authored-by: wwared <[email protected]>

* docs: integrate review

Signed-off-by: Thomas Chataigner <[email protected]>

* docs: apply suggested updates

Co-authored-by: wwared <[email protected]>
Co-authored-by: Artem Storozhuk <[email protected]>

* docs: another batch of suggestions

Co-authored-by: wwared <[email protected]>

* docs: integrate more review

Signed-off-by: Thomas Chataigner <[email protected]>

* docs: Add list of useful tests, mention e2e.rs is STARK-only, remove hackmd link

* docs: Groth16 -> Plonk/SNARK

---------

Signed-off-by: Thomas Chataigner <[email protected]>
Co-authored-by: wwared <[email protected]>
Co-authored-by: Artem Storozhuk <[email protected]>
@storojs72 storojs72 force-pushed the artem/solidity-plonk branch 2 times, most recently from 97477e8 to e1cfd7a Compare June 18, 2024 21:28
@storojs72 storojs72 force-pushed the artem/solidity-plonk branch from e1cfd7a to fd6416f Compare June 18, 2024 21:34
@storojs72
Copy link
Member Author

storojs72 commented Jun 18, 2024

Some update.

We have set own private AWS S3 bucket (s3://sphinx-plonk-params) for Plonk parameters distribution. Anyone from us can use it via requesting the access from @samuelburnham. Also aws cli needs to be installed. I uploaded the valid artefacts for e48c01ec tag of Sphinx to AWS, so with recent commit they can now be downloaded via contract-generator program introduced in this PR:

cd aptos
cargo run --bin generate-contracts --release

@storojs72
Copy link
Member Author

storojs72 commented Jun 18, 2024

Closing this PR in favour of #28 for easier reviewing (new PR excludes already merged commits from dev)

@storojs72 storojs72 closed this Jun 18, 2024
@tchataigner tchataigner deleted the artem/solidity-plonk branch July 26, 2024 09:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants