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

Update Utilities.sol: Optimized For loops #31

Merged
merged 4 commits into from
Oct 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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