Skip to content

Commit

Permalink
Update integration testing infrastructure
Browse files Browse the repository at this point in the history
  • Loading branch information
storojs72 committed Aug 21, 2023
1 parent c13658e commit e730f26
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 24 deletions.
54 changes: 40 additions & 14 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +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/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
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
- name: Run forge fmt on re-generated contracts
run: |
Expand All @@ -54,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
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,19 @@ forge script script/Deployment.s.sol:NovaVerifierDeployer --fork-url http://127.
To load proof and verifier-key into the blockchain (`CONTRACT_ADDRESS` can be obtained from the output of previous step):

```
python loader.py pp-verifier-key.json pp-compressed-snark.json <CONTRACT_ADDRESS>
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>
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
29 changes: 21 additions & 8 deletions loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,19 @@
import sys
import binascii

# Parsing verifier-key.json
if len(sys.argv) != 6:
print("Correct loader's invocation should contain 5 parameters:\n1) Path to verifier key JSON\n2) Path to proof JSON\n3) Deployed contract address\n4) URL of RPC endpoint\n5) Private key\n\nFor example:\npython loader.py verifier-key.json compressed-snark.json 0x720472c8ce72c2a2d711333e064abd3e6bbeadd3 http://127.0.0.1:8545 0x0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80")
os.exit(1)

# Parsing JSON with public parameters
vk_file = sys.argv[1]
if not os.path.exists(vk_file):
print("verifier-key (json) input file is missing")
exit(1)

vk_f = open(os.path.basename(vk_file))
vk_data = json.load(vk_f)

ro_consts_primary = vk_data['ro_consts_primary']
mds = ro_consts_primary['mds']
constants_mixConstantsPrimary = mds['m']
Expand All @@ -23,6 +28,7 @@
f_arity_primary = vk_data['F_arity_primary']
f_arity_secondary = vk_data['F_arity_secondary']
digest = vk_data['digest']

vk_secondary = vk_data['vk_secondary']
S_comm = vk_secondary['S_comm']
vk_secondary_S_comm_N = S_comm['N']
Expand All @@ -36,6 +42,7 @@
vk_secondary_S_comm_comm_col_read_ts = S_comm['comm_col_read_ts']['comm']
vk_secondary_S_comm_comm_col_audit_ts = S_comm['comm_col_audit_ts']['comm']
vk_secondary_digest = vk_secondary['digest']

vk_primary = vk_data['vk_primary']
vk_primary_num_cons = vk_primary['num_cons']
vk_primary_num_vars = vk_primary['num_vars']
Expand All @@ -52,7 +59,7 @@
vk_primary_S_comm_comm_col_audit_ts = S_comm['comm_col_audit_ts']['comm']
vk_primary_digest = vk_primary['digest']

# Parsing compressed-snark.json
# Parsing JSON with proof
compressed_snark_file = sys.argv[2]
if not os.path.exists(compressed_snark_file):
print("compressed-snark (json) input file is missing")
Expand Down Expand Up @@ -489,9 +496,10 @@
vk_primary_digest,
)

# FIXME: Hardcoded provate key is only for testing!
PRIVATE_KEY = "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"
CONTRACT_ADDRESS = sys.argv[3]
RPC_URL = sys.argv[4]
PRIVATE_KEY = sys.argv[5]

PUSH_TO_PROOF_FUNC_SIG = "pushToProof((" \
"(uint256,uint256[])," \
"(uint256,uint256,uint256[],uint256)," \
Expand Down Expand Up @@ -536,7 +544,6 @@ def addSumcheckProof(scSat, useReversing):
scSatString = scSatString + ')'
return scSatString + '])'


# Constructing 'cast send' string for sending transaction with the proof to the deployed Anvil node
def pushToProof(data):
command = 'cast send' + ' '
Expand Down Expand Up @@ -628,10 +635,13 @@ def pushToProof(data):
command = command + addSumcheckProof(data.r_W_snark_primary_sc_proof_batch, True) + ','
command = command + addNumbersArray(data.r_W_snark_primary_eval_output2_arr, True) + ')'
command = command + ')\" --private-key ' + PRIVATE_KEY
os.system(command)
command = command + ' --rpc-url ' + RPC_URL
if os.system(command) != 0:
print("pushToProof failed")
exit(1)

# TODO currently it pushes only constants for a single round of Poseidon just for comparison with hardcoded ones in Poseidon Solidity contract
# Constructing 'cast send' string for sending transaction with the verifier key to the deployed Anvil node
# Constructing 'cast send' string for sending transaction with the public parameters to the deployed Anvil node
def pushToVk(data):
command = 'cast send' + ' '
command = command + CONTRACT_ADDRESS + ' \"'
Expand Down Expand Up @@ -668,7 +678,10 @@ def pushToVk(data):
command = command + addNumber(data.vk_primary_S_comm_comm_col_audit_ts, False) + '),'
command = command + addNumber(data.vk_primary_digest, True) + ')'
command = command + ')\" --private-key ' + PRIVATE_KEY
os.system(command)
command = command + ' --rpc-url ' + RPC_URL
if os.system(command) != 0:
print("pushToVk failed")
exit(1)

pushToProof(parsedProof)
pushToVk(parsedVk)

0 comments on commit e730f26

Please sign in to comment.