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 the repository contains a project called move that demonstrates the verification on Aptos devnet / testnet 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. These fixtures are generated from a SNARK proof generated by the proof servers, but currently the fixtures generated are meant for simple testing only.

The contracts used for testing can be found in ethereum/move/sources directory

Run the tests

Running Aptos tests requires installing Aptos CLI. Please, follow this instructions to install it.

To run verifier's tests:

cd ethereum/move
% aptos move test --named-addresses plonk_verifier_addr=testnet
INCLUDING DEPENDENCY AptosFramework
INCLUDING DEPENDENCY AptosStdlib
INCLUDING DEPENDENCY MoveStdlib
BUILDING plonk-verifier
Running Move unit tests
[ PASS    ] _::utilities::test_32bytes_u256_conversion
[ PASS    ] _::plonk_verifier::test_compute_public_values_hash
[ PASS    ] _::plonk_verifier::test_compute_zeta_power_r_minus_one
[ PASS    ] _::plonk_verifier::test_derive_alpha
[ PASS    ] _::utilities::test_bn254_g1_points_addition
[ PASS    ] _::utilities::test_bn254_g1_scalar_multiplication
[ PASS    ] _::utilities::test_bn254_scalars_addition
[ PASS    ] _::utilities::test_bn254_scalars_multiplication
[ PASS    ] _::plonk_verifier::test_derive_beta
[ PASS    ] _::utilities::test_point_acc_mul
[ PASS    ] _::plonk_verifier::test_derive_gamma
[ PASS    ] _::utilities::test_pow_small
[ PASS    ] _::utilities::test_sha256_move_eth_precompile_compatibility
[ PASS    ] _::plonk_verifier::test_derive_zeta
[ PASS    ] _::plonk_verifier::test_pairing_kzg_check
[ PASS    ] _::wrapper::test_committee_change_is_allowed
[ PASS    ] _::plonk_verifier::test_verify_inner
[ PASS    ] _::wrapper::test_committee_change_is_allowed_too
[ PASS    ] _::wrapper::test_committee_change_is_not_allowed
[ PASS    ] _::wrapper::test_inclusion_is_allowed
[ PASS    ] _::wrapper::test_inclusion_is_allowed_too
[ PASS    ] _::wrapper::test_inclusion_is_not_allowed
[ PASS    ] _::wrapper::test_storage_flow
Test result: OK. Total tests: 23; passed: 23; failed: 0
{
  "Result": "Success"
}

This module is configured using setup from this tutorial.

It is also possible to run verification over custom JSON fixtures via Move scripting mechanism. In this settings, proof, public inputs and verification key are passed via arguments to Move script. Note, that fixture should have Aptos-specific format (see /move/sources/fixtures for examples).

To run Move script that executes verification code using JSON fixture (running on Aptos testnet):

aptos move compile --named-addresses plonk_verifier_addr=testnet
aptos move create-resource-account-and-publish-package --address-name plonk_verifier_addr --profile testnet --seed $(openssl rand -hex 32) --assume-yes
aptos move run-script --compiled-script-path build/plonk-verifier/bytecode_scripts/run_verification.mv --json-file sources/fixtures/epoch_change_fixture.json --profile testnet --assume-yes

You should see tentatively following result if verification passed:

{
  "Result": {
    "transaction_hash": "0x62f976db6ba0eaa1951d3ec70d4e7afa9c3189856f54bc3f029e86dc6e6f0330",
    "gas_used": 786,
    "gas_unit_price": 100,
    "sender": "4207422239492c11a6499620c869fe2248c7fe52c05ca1c443bffe8a8878d32d",
    "success": true,
    "version": 26230959,
    "vm_status": "status EXECUTED of type Execution"
  }
}

It is possible to run Move verification flow locally. This requires running Aptos node locally using Docker (see this tutorial for more details).

Fixture generation

If you wish to run the Move script with custom fixtures, you can regeenrate them 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 (ethereum/move/sources/fixtures).

To run the fixture-generator for the inclusion program, execute the following command:

cd fixture-generator
RUST_LOG=info RUSTFLAGS="-C target-cpu=native --cfg tokio_unstable -C opt-level=3" SHARD_SIZE=4194304 SHARD_BATCH_SIZE=0 cargo run --release --bin generate-fixture -- --program inclusion --language move