Skip to content

Commit

Permalink
End-to-end "pp-spartan" verification contract (#25)
Browse files Browse the repository at this point in the history
* Add JSONs generated by pp-spartan

* Separate path (src/blocks/) for low-level crypto building blocks

* Add e2e verification contract skeleton

* Move FieldLib and PolyLib code to Utilities.sol file

* Step 1

* Step 2

* CI adjustments

* Update README

* Update integration testing infrastructure
  • Loading branch information
storojs72 authored Aug 23, 2023
1 parent 845c64e commit 9d0d641
Show file tree
Hide file tree
Showing 41 changed files with 1,402 additions and 418 deletions.
59 changes: 42 additions & 17 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,70 @@ name: test
on: [workflow_dispatch, push, pull_request]

env:
FOUNDRY_PROFILE: ci
ANVIL_PRIVATE_KEY: ${{secrets.ANVIL_PRIVATE_KEY}}
ANVIL_URL: ${{secrets.ANVIL_RPC_URL}}


jobs:
check:
integration-tests-e2e:
needs: [unit-tests]
strategy:
fail-fast: true

name: Foundry project
runs-on: ubuntu-latest
name: E2E verification
runs-on: [self-hosted]
steps:
- uses: actions/checkout@v3
with:
submodules: recursive

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly

- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: 3.8

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
- name: Deploy main contract
run: |
echo "CONTRACT_ADDRESS=$(forge script script/Deployment.s.sol:NovaVerifierDeployer --fork-url $ANVIL_URL --private-key $ANVIL_PRIVATE_KEY --broadcast --non-interactive | sed -n 's/.*Contract Address: //p' | tail -1)" >> $GITHUB_OUTPUT
id: deployment

- name: Load proof and public parameters
run: |
python loader.py pp-verifier-key.json pp-compressed-snark.json ${{steps.deployment.outputs.CONTRACT_ADDRESS}} $ANVIL_URL $ANVIL_PRIVATE_KEY
- name: Check proof verification status
run: |
[[ $(cast call ${{steps.deployment.outputs.CONTRACT_ADDRESS}} "verify(uint32,uint256[],uint256[])(bool)" "3" "[1]" "[0]" --private-key $ANVIL_PRIVATE_KEY --rpc-url $ANVIL_URL) == true ]] && exit 0 || exit 1
unit-tests:
strategy:
fail-fast: true

name: Unit Tests
runs-on: [self-hosted]
steps:
- uses: actions/checkout@v3
with:
version: nightly
submodules: recursive

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.8

- name: Check formatting
run: |
forge fmt --check
id: formatting
- name: Regenerate Contracts
run: |
python src/poseidon/poseidon-contract-gen.py neptune-constants-U24-pallas.json PoseidonU24Pallas > src/poseidon/PoseidonNeptuneU24pallas.sol
python src/poseidon/poseidon-contract-gen.py neptune-constants-U24-vesta.json PoseidonU24Vesta > src/poseidon/PoseidonNeptuneU24vesta.sol
python src/verifier/step1/step1-data-contract-gen.py compressed-snark.json > src/verifier/step1/Step1Data.sol
python src/verifier/step2/step2-data-contract-gen.py verifier-key.json compressed-snark.json > src/verifier/step2/Step2Data.sol
python src/verifier/step3/step3-data-contract-gen.py verifier-key.json compressed-snark.json > src/verifier/step3/Step3Data.sol
python src/blocks/poseidon/poseidon-contract-gen.py neptune-constants-U24-pallas.json PoseidonU24Pallas > src/blocks/poseidon/PoseidonNeptuneU24pallas.sol
python src/blocks/poseidon/poseidon-contract-gen.py neptune-constants-U24-vesta.json PoseidonU24Vesta > src/blocks/poseidon/PoseidonNeptuneU24vesta.sol
- name: Run forge fmt on re-generated contracts
run: |
Expand All @@ -55,15 +83,12 @@ jobs:
run: |
forge --version
forge build
id: build
- name: Run Forge tests
run: |
forge test -vvv
id: test
- name: Get sizes of compiled contracts
run: |
forge --version
forge build --sizes || true
id: build-with-sizes
24 changes: 18 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,34 @@ To run Solidity unit-tests:
forge test --match-path test/* -vv
```

To deploy the contract (pasta curves) to the Hyperspace test network of Filecoin:
To run Anvil node locally (with maximum gas-limit and code-size-limit):

```
export PRIVATE_KEY='<YOUR PRIVATE KEY>'
forge create --rpc-url https://api.hyperspace.node.glif.io/rpc/v1 --private-key $PRIVATE_KEY --contracts src/pasta/PastaContracts.sol PallasContract
anvil --gas-limit 18446744073709551615 --code-size-limit 18446744073709551615
```

This requires getting private key with some tokens (TFIL) allocated. More details [here](https://github.com/filecoin-project/fevm-foundry-kit).
To deploy the e2e verification contract to locally running Anvil node (`PRIVATE_KEY` can be obtained from output of running Anvil):

To interact with the deployed contract:
```
forge script script/Deployment.s.sol:NovaVerifierDeployer --fork-url http://127.0.0.1:8545 --private-key <PRIVATE_KEY> --broadcast
```

To load proof and verifier-key into the blockchain (`CONTRACT_ADDRESS` can be obtained from the output of previous step):

```
forge script script/PastaInteraction.s.sol:PastaInteraction --rpc-url https://api.hyperspace.node.glif.io/rpc/v1 --broadcast -g 10000
python loader.py pp-verifier-key.json pp-compressed-snark.json <CONTRACT_ADDRESS> http://127.0.0.1:8545 <PRIVATE_KEY>
```

To run the verification logic:

```
cast call <CONTRACT_ADDRESS> "verify(uint32,uint256[],uint256[])(bool)" "3" "[1]" "[0]" --private-key <PRIVATE_KEY> --rpc-url http://127.0.0.1:8545
```

More details about Foundry tooling is [here](https://book.getfoundry.sh/).

P.S.: This E2E integration testing flow is enforced by Github Actions with our cloud-based Anvil node. See `integration-tests-e2e` job description from `.github/workflows/test.yml` for more details.

# Solidity contracts generation

Some contracts in this repository have been generated with a help of correspondent Python scripts.
Expand Down
Loading

0 comments on commit 9d0d641

Please sign in to comment.