-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Thomas Chataigner <[email protected]>
- Loading branch information
1 parent
58749a4
commit c2877b8
Showing
3 changed files
with
79 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# Benchmark on-chain verification | ||
|
||
Our Light Client is able to produce SNARK proofs that can be verified on-chain. This section will cover how to run the | ||
benchmarks for the on-chain verification. | ||
|
||
To be able to execute such tests our repository contains a project called `solidity` is based | ||
off [Foundry](https://github.com/foundry-rs/foundry) which demonstrates the Solidity verification using so-called | ||
fixtures (JSON files) containing the proof data (proof itself, public values and verification key) required for running | ||
the verification for both epoch-change and inclusion programs. | ||
|
||
The contracts used for testing can be found in the [sphinx-contracts](https://github.com/lurk-lab/sphinx-contracts) | ||
repository which is used as a dependency. | ||
|
||
## Requirements | ||
|
||
Make sure that you have properly set up the `sphinx-contracts` submodule. If you haven't done so, you can do it by | ||
running the following command: | ||
|
||
```bash | ||
git submodule update --init --recursive | ||
``` | ||
|
||
## Run the tests | ||
|
||
To run the tests, navigate to the `solidity/contracts` directory and execute the following command: | ||
|
||
```bash | ||
cd solidity/contracts && \ | ||
forge test | ||
``` | ||
|
||
The output should look like this: | ||
|
||
``` | ||
% cd solidity/contracts && forge test | ||
[⠊] Compiling... | ||
[⠒] Compiling 29 files with Solc 0.8.26 | ||
[⠢] Solc 0.8.26 finished in 1.11s | ||
Compiler run successful! | ||
Ran 4 tests for test/test_lc_proofs.sol:SolidityVerificationTest | ||
[PASS] testFail_FakeProofEpochChange() (gas: 8660281895700906413) | ||
[PASS] testFail_FakeProofInclusion() (gas: 8660281895700906417) | ||
[PASS] testValidEpochChangeProofPlonk() (gas: 318056) | ||
[PASS] testValidInclusionProofPlonk() (gas: 318103) | ||
Suite result: ok. 4 passed; 0 failed; 0 skipped; finished in 12.52ms (15.70ms CPU time) | ||
Ran 1 test suite in 154.07ms (12.52ms CPU time): 4 tests passed, 0 failed, 0 skipped (4 total tests) | ||
``` | ||
|
||
Currently, the verification of Plonk proof (either epoch-change or inclusion program) costs ~318k gas. | ||
|
||
## Fixture generation | ||
|
||
If you wish to either run the tests with custom fixtures or regenerate the existing ones, you can do so by running the | ||
`fixture-generator` Rust program. This program will run the end-to-end proving (either epoch-change or inclusion) and | ||
export the fixture file to the relevant place (`solidity/contracts/src/plonk_fixtures`). | ||
|
||
To run the `fixture-generator` for the inclusion program, execute the following command: | ||
|
||
```bash | ||
RUST_LOG=info RUSTFLAGS="-C target-cpu=native --cfg tokio_unstable" SHARD_SIZE=4194304 SHARD_BATCH_SIZE=0 cargo +nightly run --release --features aptos --bin generate-fixture -- --program inclusion | ||
``` | ||
|
||
> **Tips** | ||
> | ||
> Check that the fixtures have been updated by running `git status`. | ||
> **Note** | ||
> | ||
> You might be encountering issue with updating `sphinx-contracts` Foundry dependency, in this case try manually | ||
> specifying accessing the submodule via SSH | ||
> ``` | ||
> git config submodule.aptos/solidity/contracts/lib/sphinx-contracts.url [email protected]:lurk-lab/sphinx-contracts | ||
> ``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,67 +3,6 @@ | |
One of the requirements for the Light Client is the on-chain (Solidity) verification of Sphinx proofs generated by | ||
epoch-change and inclusion programs. | ||
|
||
This directory contains the [Foundry](https://github.com/foundry-rs/foundry) project (`solidity`) which demonstrates the | ||
Solidity verification using so-called fixtures (JSON files) | ||
containing the proof data (proof itself, public values and verification key) required for running the verification for | ||
both epoch-change and inclusion programs. | ||
The fixtures can be regenerated using `fixture-generator` Rust program. | ||
|
||
The contracts are actually located in [sphinx-contracts](https://github.com/lurk-lab/sphinx-contracts) repository which | ||
is used as a dependency. | ||
|
||
To run `contracts` forge tests: | ||
|
||
``` | ||
% cd solidity/contracts && forge test | ||
[⠊] Compiling... | ||
[⠒] Compiling 29 files with Solc 0.8.26 | ||
[⠢] Solc 0.8.26 finished in 1.11s | ||
Compiler run successful! | ||
Ran 4 tests for test/test_lc_proofs.sol:SolidityVerificationTest | ||
[PASS] testFail_FakeProofEpochChange() (gas: 8660281895700906413) | ||
[PASS] testFail_FakeProofInclusion() (gas: 8660281895700906417) | ||
[PASS] testValidEpochChangeProofPlonk() (gas: 318056) | ||
[PASS] testValidInclusionProofPlonk() (gas: 318103) | ||
Suite result: ok. 4 passed; 0 failed; 0 skipped; finished in 12.52ms (15.70ms CPU time) | ||
Ran 1 test suite in 154.07ms (12.52ms CPU time): 4 tests passed, 0 failed, 0 skipped (4 total tests) | ||
``` | ||
|
||
Currently, the verification of Plonk proof (either epoch-change or inclusion program) costs ~318k gas. | ||
|
||
If you want to use custom fixtures, you can regenerate them using `fixture-generator` which runs the e2e proving (either | ||
epoch-change or inclusion) - it may take a while - and then finally | ||
exports fixture file and puts it to the relevant place (`solidity/contracts/src/plonk_fixtures`). | ||
|
||
To run `fixture-generator` (for inclusion program): | ||
|
||
``` | ||
RUST_LOG=info RUSTFLAGS="-C target-cpu=native --cfg tokio_unstable" SHARD_SIZE=4194304 SHARD_BATCH_SIZE=0 cargo +nightly run --release --features aptos --bin generate-fixture -- --program inclusion | ||
``` | ||
|
||
Then you can check that fixture file of inclusion program has been changed: | ||
|
||
``` | ||
% git status | ||
Changes not staged for commit: | ||
(use "git add <file>..." to update what will be committed) | ||
(use "git restore <file>..." to discard changes in working directory) | ||
modified: contracts/src/plonk_fixtures/inclusion_fixture.json | ||
no changes added to commit (use "git add" and/or "git commit -a") | ||
``` | ||
|
||
And you can re-run Solidity tests with newer fixture: | ||
|
||
``` | ||
% cd solidity/contracts && forge test | ||
``` | ||
|
||
P.S.: You might be encountering issue with updating `sphinx-contracts` Foundry dependency, in this case try manually | ||
specifying accessing the submodule via SSH | ||
|
||
``` | ||
git config submodule.aptos/solidity/contracts/lib/sphinx-contracts.url [email protected]:lurk-lab/sphinx-contracts | ||
``` | ||
For more information about how to run the on-chain verification benchmarks, please refer to the dedicated section of the | ||
mdBook. Otherwise, the README can be found in the [`docs/src/benchmarks/on_chain.md`](../docs/src/benchmark/on_chain.md) | ||
folder. |