Skip to content

Commit

Permalink
Update Utilities.sol: Optimized For loops (#31)
Browse files Browse the repository at this point in the history
* End-to-end "pp-spartan" verification contract (#25)

* 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

* End-to-end "pp-spartan" verification contract (Step 3) (#27)

* Add PolyEvalInstance building block

* Refactor building blocks

* Add step 3 of verification to the e2e contract

* Remove data contracts for step 2 and step 3

* Adjust CI

* KeccakTranscript and Sumcheck blocks adjustments

* Requested changes

* Update Utilities.sol

---------

Co-authored-by: Artem Storozhuk <[email protected]>
  • Loading branch information
0xScratch and storojs72 authored Oct 15, 2023
1 parent 5526c9a commit d52e978
Show file tree
Hide file tree
Showing 50 changed files with 4,092 additions and 4,238 deletions.
53 changes: 37 additions & 16 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ env:
ANVIL_URL: ${{secrets.ANVIL_RPC_URL}}

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

name: Spark building block testing
name: E2E verification
runs-on: [self-hosted]
steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -56,28 +55,53 @@ jobs:
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)(bool)" "3" "[1]" "[0]" "true" --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 @@ -94,15 +118,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 d52e978

Please sign in to comment.