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 #28

Merged
merged 10 commits into from
Jun 20, 2024

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 two subfolders:

  • contracts (Foundry project with Solidity code);
  • 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.

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 by artifacts program from sphinx-contracts repository.

@storojs72 storojs72 force-pushed the artem/solidity-plonk-1 branch from 172f620 to 0941c5a Compare June 19, 2024 21:30
Copy link
Contributor

@wwared wwared left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks very good! I haven't tested it locally yet but the code seems good to me.

We might want to merge argumentcomputer/sphinx#49 before this PR since that will require us to update the circuit artifacts

Docs are still a TODO, but that's fine for now

import {Inclusion} from "../src/Inclusion.sol";
import {EpochChange} from "../src/EpochChange.sol";

struct SP1ProofFixtureJson {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: We should eventually rename this to SphinxProofFixtureJson

@storojs72
Copy link
Member Author

storojs72 commented Jun 19, 2024

Docs are still a TODO, but that's fine for now

Yes, adding documentation, renaming SP1 -> Sphinx (in sphinx-contracts as well) and introducing CI for the Solidity testing are still a TODO

@storojs72 storojs72 merged commit e31a7be into plonk Jun 20, 2024
3 checks passed
@tchataigner tchataigner deleted the artem/solidity-plonk-1 branch June 21, 2024 11:44
tchataigner pushed a commit that referenced this pull request Jun 21, 2024
* feat: Add scaffolding for Plonk verification in Solidity

* feat: Add Plonk contract

* tests: Add more negative Solidity testing

* feat: Add Rust program for Solidity contract generating

* chore: Update Cargo.lock

* chore: Update Plonk contract according to 'e48c01ec' tag of Sphinx

* chore: Formatting

* feat: Introduce downloading from our AWS private bucket

* feat: Update Foundry project to use sphinx-contracts dependency

* chore: Rename SP1 -> Sphinx
tchataigner pushed a commit that referenced this pull request Jun 21, 2024
* feat: Add scaffolding for Plonk verification in Solidity

* feat: Add Plonk contract

* tests: Add more negative Solidity testing

* feat: Add Rust program for Solidity contract generating

* chore: Update Cargo.lock

* chore: Update Plonk contract according to 'e48c01ec' tag of Sphinx

* chore: Formatting

* feat: Introduce downloading from our AWS private bucket

* feat: Update Foundry project to use sphinx-contracts dependency

* chore: Rename SP1 -> Sphinx
tchataigner added a commit that referenced this pull request Jun 21, 2024
* feat: Update Sphinx and replace Groth16 with Plonk (#23)

* feat: Solidity verification of light client proofs with Plonk (#28)

* feat: Add scaffolding for Plonk verification in Solidity

* feat: Add Plonk contract

* tests: Add more negative Solidity testing

* feat: Add Rust program for Solidity contract generating

* chore: Update Cargo.lock

* chore: Update Plonk contract according to 'e48c01ec' tag of Sphinx

* chore: Formatting

* feat: Introduce downloading from our AWS private bucket

* feat: Update Foundry project to use sphinx-contracts dependency

* chore: Rename SP1 -> Sphinx

* chore: Add README for Solidity verification

* feat: Add CI configuration for Solidity

* ci: solidity tests on all PR

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

* chore: update programs

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

* docs: move documentation to mdBook

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

---------

Signed-off-by: Thomas Chataigner <[email protected]>
Co-authored-by: wwared <[email protected]>
Co-authored-by: Thomas Chataigner <[email protected]>
tchataigner pushed a commit that referenced this pull request Jun 24, 2024
* feat: Add scaffolding for Plonk verification in Solidity

* feat: Add Plonk contract

* tests: Add more negative Solidity testing

* feat: Add Rust program for Solidity contract generating

* chore: Update Cargo.lock

* chore: Update Plonk contract according to 'e48c01ec' tag of Sphinx

* chore: Formatting

* feat: Introduce downloading from our AWS private bucket

* feat: Update Foundry project to use sphinx-contracts dependency

* chore: Rename SP1 -> Sphinx
tchataigner added a commit that referenced this pull request Jun 24, 2024
* feat: Update Sphinx and replace Groth16 with Plonk (#23)

* feat: Solidity verification of light client proofs with Plonk (#28)

* feat: Add scaffolding for Plonk verification in Solidity

* feat: Add Plonk contract

* tests: Add more negative Solidity testing

* feat: Add Rust program for Solidity contract generating

* chore: Update Cargo.lock

* chore: Update Plonk contract according to 'e48c01ec' tag of Sphinx

* chore: Formatting

* feat: Introduce downloading from our AWS private bucket

* feat: Update Foundry project to use sphinx-contracts dependency

* chore: Rename SP1 -> Sphinx

* chore: Add README for Solidity verification

* feat: Add CI configuration for Solidity

* ci: solidity tests on all PR

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

* chore: update programs

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

* docs: move documentation to mdBook

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

---------

Signed-off-by: Thomas Chataigner <[email protected]>
Co-authored-by: wwared <[email protected]>
Co-authored-by: Thomas Chataigner <[email protected]>
wwared pushed a commit that referenced this pull request Jun 24, 2024
* feat: Add scaffolding for Plonk verification in Solidity

* feat: Add Plonk contract

* tests: Add more negative Solidity testing

* feat: Add Rust program for Solidity contract generating

* chore: Update Cargo.lock

* chore: Update Plonk contract according to 'e48c01ec' tag of Sphinx

* chore: Formatting

* feat: Introduce downloading from our AWS private bucket

* feat: Update Foundry project to use sphinx-contracts dependency

* chore: Rename SP1 -> Sphinx
wwared added a commit that referenced this pull request Jun 24, 2024
* feat: Update Sphinx and replace Groth16 with Plonk (#23)

* feat: Solidity verification of light client proofs with Plonk (#28)

* feat: Add scaffolding for Plonk verification in Solidity

* feat: Add Plonk contract

* tests: Add more negative Solidity testing

* feat: Add Rust program for Solidity contract generating

* chore: Update Cargo.lock

* chore: Update Plonk contract according to 'e48c01ec' tag of Sphinx

* chore: Formatting

* feat: Introduce downloading from our AWS private bucket

* feat: Update Foundry project to use sphinx-contracts dependency

* chore: Rename SP1 -> Sphinx

* chore: Add README for Solidity verification

* feat: Add CI configuration for Solidity

* ci: solidity tests on all PR

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

* chore: update programs

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

* docs: move documentation to mdBook

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

---------

Signed-off-by: Thomas Chataigner <[email protected]>
Co-authored-by: wwared <[email protected]>
Co-authored-by: Thomas Chataigner <[email protected]>
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.

2 participants