diff --git a/.env b/.env
new file mode 100644
index 00000000..f2059ab7
--- /dev/null
+++ b/.env
@@ -0,0 +1,2 @@
+# required by oz-foundry-upgrades. See https://github.com/OpenZeppelin/openzeppelin-foundry-upgrades/tree/main?tab=readme-ov-file#optional-custom-output-directory
+FOUNDRY_OUT=artifacts
diff --git a/.github/actions/shielder-relayer/deploy/action.yml b/.github/actions/shielder-relayer/deploy/action.yml
index 74d0c1f1..5d0385df 100644
--- a/.github/actions/shielder-relayer/deploy/action.yml
+++ b/.github/actions/shielder-relayer/deploy/action.yml
@@ -23,10 +23,13 @@ inputs:
environment:
type: choice
options:
- - testnet-dev
- - testnet
- - mainnet
+ - dev
+ - stage
+ - prod
required: true
+ overwrite-shielder-address:
+ description: Shielder address to replace the exist one
+ required: false
runs:
using: composite
@@ -44,6 +47,13 @@ runs:
with:
kustomize-version: ${{ inputs.kustomize-version }}
+ - name: Modify shielder address in the config map
+ if: ${{ inputs.overwrite-shielder-address != '' }}
+ shell: bash
+ run: |
+ yq -i '.data.SHIELDER_CONTRACT_ADDRESS="${{ inputs.overwrite-shielder-address }}"' \
+ aleph-apps/shielder-relayer/overlays/${{ inputs.environment }}/eu-central-1/configmap.yaml
+
- name: KUSTOMIZE | Update docker image tag
shell: bash
env:
diff --git a/.github/scripts/gas_diff.py b/.github/scripts/gas_diff.py
new file mode 100644
index 00000000..8d62b234
--- /dev/null
+++ b/.github/scripts/gas_diff.py
@@ -0,0 +1,49 @@
+import re
+
+def parse_report(file_path):
+ data = {}
+ with open(file_path, 'r') as file:
+ for line in file:
+ match = re.match(r'(\w+):\s*(\d+)', line)
+ if match:
+ name, value = match.groups()
+ data[name] = int(value)
+ return data
+
+def calculate_differences(main_data, current_data):
+ differences = []
+ for name in main_data:
+ main_value = main_data[name]
+ current_value = current_data.get(name, 0)
+ if main_value > 0:
+ difference = ((current_value - main_value) / main_value) * 100
+ else:
+ difference = 0 # handle case where main value is zero
+ differences.append((name, main_value, current_value, difference))
+ return differences
+
+def generate_html_report(differences):
+ # Generate single-line HTML content without formatting
+ html_content = "
Transaction Name | Main | Current | Difference (%) |
"
+ for name, main, current, diff in differences:
+ sign = '+' if diff > 0 else '-' if diff < 0 else ''
+ diff_value = f"{sign}{abs(diff):.5f}%"
+ html_content += f"{name} | {main} | {current} | {diff_value} |
"
+ html_content += "
"
+ return html_content
+
+def main():
+ main_report_path = 'main-report.txt'
+ current_report_path = 'current-report.txt'
+
+ main_data = parse_report(main_report_path)
+ current_data = parse_report(current_report_path)
+ differences = calculate_differences(main_data, current_data)
+
+ html_report = generate_html_report(differences)
+
+ with open('report.html', 'w') as report_file:
+ report_file.write(html_report)
+
+if __name__ == "__main__":
+ main()
diff --git a/.github/workflows/_build-contracts.yml b/.github/workflows/_build-contracts.yml
index 48bdf2c4..1d7fec56 100644
--- a/.github/workflows/_build-contracts.yml
+++ b/.github/workflows/_build-contracts.yml
@@ -57,3 +57,10 @@ jobs:
name: contract-artifacts
path: artifacts
retention-days: 1
+
+ - name: Upload generated build cache
+ uses: actions/upload-artifact@v4
+ with:
+ name: generated-build-cache
+ path: cache
+ retention-days: 1
diff --git a/.github/workflows/_check-vars-and-secrets.yml b/.github/workflows/_check-vars-and-secrets.yml
index 676611d8..57c0bd80 100644
--- a/.github/workflows/_check-vars-and-secrets.yml
+++ b/.github/workflows/_check-vars-and-secrets.yml
@@ -13,14 +13,16 @@ jobs:
- name: Check vars
run: |
if [[ \
- -z '${{ vars.SHIELDER_CONTRACT_ADDRESS }}' || \
-z '${{ vars.KUSTOMIZE_VERSION }}' || \
- -z '${{ vars.CI_TESTNET_ALICE_PUBLIC_KEY }} }}' || \
- -z '${{ vars.CI_TESTNET_BOB_PUBLIC_KEY }} }}' || \
- -z '${{ vars.CI_TESTNET_CHARLIE_PUBLIC_KEY }} }}' || \
- -z '${{ vars.CI_TESTNET_TS_SDK_PUBLIC_KEY }} }}' || \
- -z '${{ vars.CI_TESTNET_RELAYER_SIGNER_ADDRESSES }} }}' || \
- -z '${{ vars.CI_TESTNET_FEE_DESTINATION }} }}'
+ -z '${{ vars.CI_TESTNET_ALICE_PUBLIC_KEY }}' || \
+ -z '${{ vars.CI_TESTNET_BOB_PUBLIC_KEY }}' || \
+ -z '${{ vars.CI_TESTNET_CHARLIE_PUBLIC_KEY }}' || \
+ -z '${{ vars.CI_TESTNET_FEE_DESTINATION }}' || \
+ -z '${{ vars.CI_TESTNET_RELAYER_SIGNER_ADDRESSES }}' || \
+ -z '${{ vars.CI_TESTNET_STAGE_OWNER_ADDRESS }}' || \
+ -z '${{ vars.CI_TESTNET_TS_SDK_PUBLIC_KEY }}' || \
+ -z '${{ vars.MAINNET_PROD_OWNER_ADDRESS }}' || \
+ -z '${{ vars.SHIELDER_CONTRACT_ADDRESS }}'
]]; then
echo '!!! Some repository variables are either missing or empty.'
echo '!!! Please check either repository or organization settings.'
@@ -30,26 +32,38 @@ jobs:
- name: Check secrets
run: |
if [[ \
- -z '${{ secrets.ZKOS_CIRCUITS_SSH_PRIVATE_KEY }}' || \
- -z '${{ secrets.SSH_PRIVATE_KEY }}' || \
- -z '${{ secrets.VERCEL_ORG_ID }}' || \
- -z '${{ secrets.VERCEL_PROJECT_ID }}' || \
- -z '${{ secrets.VERCEL_TOKEN }}' || \
- -z '${{ secrets.AWS_MAINNET_ECR_ACCESS_KEY_ID }}' || \
-z '${{ secrets.AWS_MAINNET_ECR_ACCESS_KEY }}' || \
- -z '${{ secrets.ECR_PRIVATE_HOST }}' || \
- -z '${{ secrets.AUTOCOMMIT_AUTHOR }}' || \
- -z '${{ secrets.AUTOCOMMIT_EMAIL }}' || \
+ -z '${{ secrets.AWS_MAINNET_ECR_ACCESS_KEY_ID }}' || \
-z '${{ secrets.CI_GH_TOKEN }}' || \
- -z '${{ secrets.SLACK_WEBHOOK_ZKOS }}' || \
- -z '${{ secrets.CI_TESTNET_DEPLOYER_PRIVATE_KEY }}' || \
+ -z '${{ secrets.CI_MAINNET_DEPLOYER_PRIVATE_KEY }}' || \
-z '${{ secrets.CI_TESTNET_ALICE_PRIVATE_KEY }}' || \
-z '${{ secrets.CI_TESTNET_BOB_PRIVATE_KEY }}' || \
-z '${{ secrets.CI_TESTNET_CHARLIE_PRIVATE_KEY }}' || \
- -z '${{ secrets.CI_TESTNET_TS_SDK_PRIVATE_KEY }}' || \
+ -z '${{ secrets.CI_TESTNET_DEPLOYER_PRIVATE_KEY }}' || \
-z '${{ secrets.CI_TESTNET_FEE_DESTINATION_KEY }}' || \
-z '${{ secrets.CI_TESTNET_RELAYER_SIGNING_KEYS }}' || \
- -z '${{ secrets.NPM_PUBLISHING_KEY }}'
+ -z '${{ secrets.CI_TESTNET_TS_SDK_PRIVATE_KEY }}' || \
+ -z '${{ secrets.NPM_PUBLISHING_KEY }}' || \
+ -z '${{ secrets.SLACK_WEBHOOK_ZKOS }}' || \
+ -z '${{ secrets.VERCEL_ORG_ID }}' || \
+ -z '${{ secrets.VERCEL_PROJECT_ID }}' || \
+ -z '${{ secrets.VERCEL_TOKEN }}' || \
+ -z '${{ secrets.ZKOS_CIRCUITS_SSH_PRIVATE_KEY }}' || \
+
+ -z '${{ secrets.AUTOCOMMIT_AUTHOR }}' || \
+ -z '${{ secrets.AUTOCOMMIT_EMAIL }}' || \
+ -z '${{ secrets.CONTRACTS_S3BUCKET_NAME }}' || \
+ -z '${{ secrets.CONTRACTS_S3BUCKET_REGION }}' || \
+ -z '${{ secrets.CONTRACTS_ZKOS_ADDRESSES_MAINNET_PROD_RW_AWS_ACCESS_KEY_ID }}' || \
+ -z '${{ secrets.CONTRACTS_ZKOS_ADDRESSES_MAINNET_PROD_RW_AWS_SECRET_ACCESS_KEY }}' || \
+ -z '${{ secrets.CONTRACTS_ZKOS_ADDRESSES_TESTNET_DEV_RW_AWS_ACCESS_KEY_ID }}' || \
+ -z '${{ secrets.CONTRACTS_ZKOS_ADDRESSES_TESTNET_DEV_RW_AWS_SECRET_ACCESS_KEY }}' || \
+ -z '${{ secrets.CONTRACTS_ZKOS_ADDRESSES_TESTNET_STAGE_RW_AWS_ACCESS_KEY_ID }}' || \
+ -z '${{ secrets.CONTRACTS_ZKOS_ADDRESSES_TESTNET_STAGE_RW_AWS_SECRET_ACCESS_KEY }}' || \
+ -z '${{ secrets.CONTRACTS_ZKOS_ARTIFACTS_RW_AWS_ACCESS_KEY_ID }}' || \
+ -z '${{ secrets.CONTRACTS_ZKOS_ARTIFACTS_RW_AWS_SECRET_ACCESS_KEY }}' || \
+ -z '${{ secrets.ECR_PRIVATE_HOST }}' || \
+ -z '${{ secrets.SSH_PRIVATE_KEY }}'
]]; then
echo '!!! Some repository secrets are either missing or empty.'
echo '!!! Please check either repository or organization settings.'
diff --git a/.github/workflows/_deploy-contracts.yml b/.github/workflows/_deploy-contracts.yml
index f7c407bf..a1b6c21f 100644
--- a/.github/workflows/_deploy-contracts.yml
+++ b/.github/workflows/_deploy-contracts.yml
@@ -46,6 +46,12 @@ jobs:
name: contract-artifacts
path: artifacts
+ - name: Download generated build cache
+ uses: actions/download-artifact@v4
+ with:
+ name: generated-build-cache
+ path: cache
+
- name: deploy eth contracts
shell: bash
run: NETWORK=anvil make deploy-contracts
diff --git a/.github/workflows/_measure-gas.yml b/.github/workflows/_measure-gas.yml
new file mode 100644
index 00000000..13a29460
--- /dev/null
+++ b/.github/workflows/_measure-gas.yml
@@ -0,0 +1,100 @@
+---
+name: Measure gas
+
+on:
+ workflow_dispatch:
+ workflow_call:
+
+jobs:
+ main:
+ name: Measure circuits
+ runs-on: [self-hosted, Linux, X64, large]
+ timeout-minutes: 20
+ steps:
+
+ - name: Checkout code (from the current branch)
+ uses: actions/checkout@v4
+
+ - name: Prepare Rust env
+ uses: ./.github/actions/prepare-rust-env
+ with:
+ poseidon-gadget-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
+ zkos-circuits-private-key: ${{ secrets.ZKOS_CIRCUITS_SSH_PRIVATE_KEY }}
+
+ - name: Setup node
+ uses: asdf-vm/actions/install@v3
+
+ - name: Install solc compiler
+ uses: ./.github/actions/install-solc
+ with:
+ solc-version: 0.8.26
+
+ - name: Build binary
+ run: cargo build -p integration-tests --bin gas-consumption --release
+
+ #################### Run measurements on the current branch ####################
+
+ - name: Install dependencies
+ run: make deps
+
+ - name: Generate all contracts
+ run: make generate-contracts
+
+ - name: Run measure-circuits binary on the current branch
+ run: |
+ export CONTRACTS_DIR="contracts"
+ export CARGO_MANIFEST_DIR=./Cargo.toml
+ ./target/release/gas-consumption current-report.txt
+
+ - name: Print gas measured on the current branch
+ run: cat current-report.txt
+
+ #################### Run measurements on the main branch ####################
+
+ - name: Checkout repository from `main`
+ uses: actions/checkout@v4
+ with:
+ ref: main
+ path: main
+
+ - name: Install dependencies
+ run: |
+ cd main
+ make deps
+
+ - name: Generate all contracts
+ run: |
+ cd main
+ make generate-contracts
+
+ - name: Run measure-circuits on the `main` branch
+ run: |
+ export CONTRACTS_DIR="main/contracts"
+ export CARGO_MANIFEST_DIR=./main/Cargo.toml
+ ./target/release/gas-consumption main-report.txt
+
+ - name: Print gas measured on the `main` branch
+ run: cat main-report.txt
+
+ #################### Generate report ####################
+
+ - name: Install Python 3.10
+ uses: actions/setup-python@v5
+ with:
+ python-version: '3.10'
+
+ - name: Install python deps
+ run: pip install prettytable
+
+ - name: Run metrics-diff-presenter script
+ run: python3 .github/scripts/gas_diff.py > report.html
+
+ - name: Print gas report with diff
+ run: cat report.html
+
+ - name: Post measurements difference
+ uses: thollander/actions-comment-pull-request@v3
+ with:
+ file-path: report.html
+ comment-tag: hashFiles('report.html')
+
diff --git a/.github/workflows/_rust-crates-checks.yml b/.github/workflows/_rust-crates-checks.yml
index a905b478..5be05439 100644
--- a/.github/workflows/_rust-crates-checks.yml
+++ b/.github/workflows/_rust-crates-checks.yml
@@ -31,6 +31,12 @@ jobs:
name: contract-artifacts
path: artifacts
+ - name: Download generated build cache
+ uses: actions/download-artifact@v4
+ with:
+ name: generated-build-cache
+ path: cache
+
- name: Prepare Rust env
uses: ./.github/actions/prepare-rust-env
with:
@@ -86,6 +92,12 @@ jobs:
name: contract-artifacts
path: artifacts
+ - name: Download generated build cache
+ uses: actions/download-artifact@v4
+ with:
+ name: generated-build-cache
+ path: cache
+
- name: Prepare Rust env
uses: ./.github/actions/prepare-rust-env
with:
diff --git a/.github/workflows/_ts-checks.yml b/.github/workflows/_ts-checks.yml
index f9e8a19f..24cdf132 100644
--- a/.github/workflows/_ts-checks.yml
+++ b/.github/workflows/_ts-checks.yml
@@ -47,6 +47,12 @@ jobs:
name: crates-shielder-wasm-pkg
path: crates/shielder-wasm/pkg
+ - name: Download generated build cache
+ uses: actions/download-artifact@v4
+ with:
+ name: generated-build-cache
+ path: cache
+
- name: Install Node.js
uses: actions/setup-node@v4
with:
diff --git a/.github/workflows/_ts-sdk-playwright-tests.yml b/.github/workflows/_ts-sdk-playwright-tests.yml
index 66a3eabf..b62e9e4e 100644
--- a/.github/workflows/_ts-sdk-playwright-tests.yml
+++ b/.github/workflows/_ts-sdk-playwright-tests.yml
@@ -122,6 +122,12 @@ jobs:
name: crates-shielder-wasm-pkg
path: crates/shielder-wasm/pkg
+ - name: Download generated build cache
+ uses: actions/download-artifact@v4
+ with:
+ name: generated-build-cache
+ path: cache
+
- name: Download binary from artifacts
uses: actions/download-artifact@v4
with:
diff --git a/.github/workflows/mainnet-prod-build-and-deploy-shielder-relayer.yml b/.github/workflows/mainnet-prod-build-and-deploy-shielder-relayer.yml
new file mode 100644
index 00000000..b639a9ec
--- /dev/null
+++ b/.github/workflows/mainnet-prod-build-and-deploy-shielder-relayer.yml
@@ -0,0 +1,59 @@
+---
+name: "[PROD] Build and deploy shielder-relayer"
+
+on:
+ workflow_dispatch:
+ inputs:
+ overwrite-shielder-address:
+ type: string
+ required: false
+ default: ''
+ description: Overwrite shielder address - if empty it's not changed
+
+jobs:
+ build-and-push:
+ name: Build and push shielder-relayer
+ runs-on: [self-hosted, Linux, X64, medium]
+ steps:
+ - name: GIT | Checkout
+ uses: actions/checkout@v4
+
+ - name: Prepare Rust env
+ uses: ./.github/actions/prepare-rust-env
+ with:
+ poseidon-gadget-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
+ zkos-circuits-private-key: ${{ secrets.ZKOS_CIRCUITS_SSH_PRIVATE_KEY }}
+
+ - name: Build relayer
+ run: cd crates/shielder-relayer && make build
+
+ - name: DOCKER | Build and push
+ uses: ./.github/actions/shielder-relayer/build-and-push
+ id: build_shielder_relayer
+ with:
+ aws-mainnet-ecr-access-key-id: ${{ secrets.AWS_MAINNET_ECR_ACCESS_KEY_ID }}
+ aws-mainnet-ecr-access-key: ${{ secrets.AWS_MAINNET_ECR_ACCESS_KEY }}
+ ecr-private-host: ${{ secrets.ECR_PRIVATE_HOST }}
+ outputs:
+ image_tag: ${{ steps.build_shielder_relayer.outputs.image_tag }}
+
+ deploy:
+ name: Deploy shielder-relayer
+ needs: [build-and-push]
+ runs-on: [self-hosted, Linux, X64, medium]
+ steps:
+ - name: GIT | Checkout
+ uses: actions/checkout@v4
+
+ - name: KUSTOMIZE | Deploy
+ uses: ./.github/actions/shielder-relayer/deploy
+ id: deploy_shielder_relayer
+ with:
+ environment: prod
+ image-tag: ${{ needs.build-and-push.outputs.image_tag }}
+ autocommit-author: ${{ secrets.AUTOCOMMIT_AUTHOR }}
+ autocommit-email: ${{ secrets.AUTOCOMMIT_EMAIL }}
+ github-token: ${{ secrets.CI_GH_TOKEN }}
+ kustomize-version: ${{ vars.KUSTOMIZE_VERSION }}
+ ecr-private-host: ${{ secrets.ECR_PRIVATE_HOST }}
+ overwrite-shielder-address: ${{ inputs.overwrite-shielder-address }}
diff --git a/.github/workflows/manual-browser-extension-deployment.yml b/.github/workflows/manual-browser-extension-deployment.yml
index d930119b..f9c81529 100644
--- a/.github/workflows/manual-browser-extension-deployment.yml
+++ b/.github/workflows/manual-browser-extension-deployment.yml
@@ -55,6 +55,11 @@ jobs:
with:
name: crates-shielder-wasm-pkg
path: crates/shielder-wasm/pkg
+ - name: Download generated build cache
+ uses: actions/download-artifact@v4
+ with:
+ name: generated-build-cache
+ path: cache
- name: Use Node.js ${{ env.NODE_VERSION }}
uses: actions/setup-node@v4.0.2
with:
diff --git a/.github/workflows/manual-deploy-contract.yml b/.github/workflows/manual-deploy-contract.yml
new file mode 100644
index 00000000..6c874ff2
--- /dev/null
+++ b/.github/workflows/manual-deploy-contract.yml
@@ -0,0 +1,161 @@
+---
+name: "Manually Deploy contracts"
+
+on:
+ workflow_dispatch:
+ inputs:
+ environment:
+ description: "Environment to deploy to"
+ required: true
+ default: "dev"
+ type: choice
+ options:
+ - "dev"
+ - "stage"
+ - "prod"
+
+jobs:
+ deploy-contracts:
+ name: Deploy contracts on ${{ github.event.inputs.environment }}
+ runs-on: [self-hosted, Linux, X64, medium]
+ steps:
+ - name: GIT | Checkout
+ uses: actions/checkout@v4
+
+ - name: Install Node.js
+ uses: actions/setup-node@v4
+ with:
+ node-version: 18
+
+ - name: Prepare Rust env
+ uses: ./.github/actions/prepare-rust-env
+ with:
+ poseidon-gadget-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
+ zkos-circuits-private-key: ${{ secrets.ZKOS_CIRCUITS_SSH_PRIVATE_KEY }}
+
+ - name: Install Foundry
+ uses: foundry-rs/foundry-toolchain@v1.2.0
+ with:
+ cache-key: custom-seed-coverage-${{ github.ref_name }}
+ cache-restore-keys: |-
+ contract-suite
+ version: nightly-31dd1f77fd9156d09836486d97963cec7f555343
+
+ - name: Install deps
+ run: make deps
+
+ # for "dev" we use default owner address, as it's not important
+ - name: Set environment-specific variables
+ run: |
+ if [ "${{ github.event.inputs.environment }}" == "dev" ]; then
+ echo "PRIVATE_KEY=${{ secrets.CI_TESTNET_DEPLOYER_PRIVATE_KEY }}" >> $GITHUB_ENV
+ echo "NETWORK=https://rpc.alephzero-testnet.gelato.digital" >> $GITHUB_ENV
+ echo "EXPLORER_URL=https://evm-explorer-testnet.alephzero.org/api" >> $GITHUB_ENV
+ elif [ "${{ github.event.inputs.environment }}" == "stage" ]; then
+ echo "OWNER_ADDRESS=${{ vars.CI_TESTNET_STAGE_OWNER_ADDRESS }}" >> $GITHUB_ENV
+ echo "PRIVATE_KEY=${{ secrets.CI_TESTNET_DEPLOYER_PRIVATE_KEY }}" >> $GITHUB_ENV
+ echo "NETWORK=https://rpc.alephzero-testnet.gelato.digital" >> $GITHUB_ENV
+ echo "EXPLORER_URL=https://evm-explorer-testnet.alephzero.org/api" >> $GITHUB_ENV
+ elif [ "${{ github.event.inputs.environment }}" == "prod" ]; then
+ echo "OWNER_ADDRESS=${{ vars.MAINNET_PROD_OWNER_ADDRESS }}" >> $GITHUB_ENV
+ echo "PRIVATE_KEY=${{ secrets.CI_MAINNET_DEPLOYER_PRIVATE_KEY }}" >> $GITHUB_ENV
+ echo "NETWORK=https://rpc.alephzero.raas.gelato.cloud" >> $GITHUB_ENV
+ echo "EXPLORER_URL=https://evm-explorer.alephzero.org/api" >> $GITHUB_ENV
+ else
+ echo "Invalid environment selected!" >&2
+ exit 1
+ fi
+
+ - name: Compile eth contracts
+ run: make compile-contracts
+
+ - name: Deploy contracts
+ run: |
+ make deploy-contracts
+
+ - name: Verify Shielder contract
+ run: ./scripts/verify-shielder.sh
+
+ - name: Upload Shielder abi to artifacts
+ uses: actions/upload-artifact@v4
+ with:
+ name: shielder_abi
+ path: artifacts/Shielder.sol/Shielder.json
+ include-hidden-files: true
+ retention-days: 14
+
+ - name: Upload Shielder contract address to artifacts
+ uses: actions/upload-artifact@v4
+ with:
+ name: shielder_address
+ path: shielder_address.txt
+ include-hidden-files: true
+ retention-days: 14
+
+ - name: Create a JSON with address
+ run: |
+ echo -n $(cat shielder_address.txt | xargs) | jq -Rs '{ shielder: . }' \
+ > evm_addresses.json
+
+ - name: Prepare contract_spec JSON
+ uses: Cardinal-Cryptography/github-actions/generate-contract-spec@v6
+ with:
+ src-files: |-
+ evm_addresses.json|evm_
+ dst-file: contract_spec.json
+ spec-version: "0.1"
+ contract-version: "${{ github.sha }}"
+
+ - name: Add block numbers to contract_spec JSON
+ shell: bash
+ run: |
+ cat contract_spec.json | \
+ jq ".start_blocks = { evm: \"$(cat shielder_block_number.txt)\" }" \
+ > contract_spec_with_block_numbers.json
+
+ cat contract_spec_with_block_numbers.json
+
+ # yamllint disable rule:line-length
+ - name: Store addresses in S3 bucket (dev)
+ if: ${{ inputs.environment == 'dev' }}
+ shell: bash
+ env:
+ AWS_REGION: ${{ secrets.CONTRACTS_S3BUCKET_REGION }}
+ AWS_ACCESS_KEY_ID: ${{ secrets.CONTRACTS_ZKOS_ADDRESSES_TESTNET_DEV_RW_AWS_ACCESS_KEY_ID }}
+ AWS_SECRET_ACCESS_KEY: ${{ secrets.CONTRACTS_ZKOS_ADDRESSES_TESTNET_DEV_RW_AWS_SECRET_ACCESS_KEY }}
+ run: |
+ aws s3 cp contract_spec_with_block_numbers.json s3://${{ secrets.CONTRACTS_S3BUCKET_NAME }}/zkos/addresses/testnet/dev.json
+ aws s3 cp broadcast/Shielder.s.sol/2039/run-latest.json s3://${{ secrets.CONTRACTS_S3BUCKET_NAME }}/zkos/addresses/testnet/dev-broadcast.json
+
+ # yamllint disable rule:line-length
+ - name: Store addresses in S3 bucket (stage)
+ if: ${{ inputs.environment == 'stage' }}
+ shell: bash
+ env:
+ AWS_REGION: ${{ secrets.CONTRACTS_S3BUCKET_REGION }}
+ AWS_ACCESS_KEY_ID: ${{ secrets.CONTRACTS_ZKOS_ADDRESSES_TESTNET_STAGE_RW_AWS_ACCESS_KEY_ID }}
+ AWS_SECRET_ACCESS_KEY: ${{ secrets.CONTRACTS_ZKOS_ADDRESSES_TESTNET_STAGE_RW_AWS_SECRET_ACCESS_KEY }}
+ run: |
+ aws s3 cp contract_spec_with_block_numbers.json s3://${{ secrets.CONTRACTS_S3BUCKET_NAME }}/zkos/addresses/testnet/stage.json
+ aws s3 cp broadcast/Shielder.s.sol/2039/run-latest.json s3://${{ secrets.CONTRACTS_S3BUCKET_NAME }}/zkos/addresses/testnet/stage-broadcast.json
+
+ # yamllint disable rule:line-length
+ - name: Store addresses in S3 bucket (prod)
+ if: ${{ inputs.environment == 'prod' }}
+ shell: bash
+ env:
+ AWS_REGION: ${{ secrets.CONTRACTS_S3BUCKET_REGION }}
+ AWS_ACCESS_KEY_ID: ${{ secrets.CONTRACTS_ZKOS_ADDRESSES_MAINNET_PROD_RW_AWS_ACCESS_KEY_ID }}
+ AWS_SECRET_ACCESS_KEY: ${{ secrets.CONTRACTS_ZKOS_ADDRESSES_MAINNET_PROD_RW_AWS_SECRET_ACCESS_KEY }}
+ run: |
+ aws s3 cp contract_spec_with_block_numbers.json s3://${{ secrets.CONTRACTS_S3BUCKET_NAME }}/zkos/addresses/mainnet/prod.json
+ aws s3 cp broadcast/Shielder.s.sol/41455/run-latest.json s3://${{ secrets.CONTRACTS_S3BUCKET_NAME }}/zkos/addresses/mainnet/prod-broadcast.json
+
+ - name: Store artifact in S3 bucket
+ shell: bash
+ env:
+ AWS_ACCESS_KEY_ID: ${{ secrets.CONTRACTS_ZKOS_ARTIFACTS_RW_AWS_ACCESS_KEY_ID }}
+ AWS_SECRET_ACCESS_KEY: ${{ secrets.CONTRACTS_ZKOS_ARTIFACTS_RW_AWS_SECRET_ACCESS_KEY }}
+ AWS_REGION: ${{ secrets.CONTRACTS_S3BUCKET_REGION }}
+ run: |
+ aws s3 cp artifacts/Shielder.sol/Shielder.json s3://${{ secrets.CONTRACTS_S3BUCKET_NAME }}/zkos/artifacts/${{ github.sha }}/eth_shielder/
diff --git a/.github/workflows/manual-testnet-deploy-contract.yml b/.github/workflows/manual-testnet-deploy-contract.yml
deleted file mode 100644
index d1dd5bed..00000000
--- a/.github/workflows/manual-testnet-deploy-contract.yml
+++ /dev/null
@@ -1,63 +0,0 @@
----
-name: "[TESTNET] Deploy contracts"
-
-on:
- workflow_dispatch:
-
-jobs:
- deploy-contracts:
- name: Deploy contracts on testnet
- runs-on: [self-hosted, Linux, X64, medium]
- steps:
- - name: GIT | Checkout
- uses: actions/checkout@v4
-
- - name: Install Node.js
- uses: actions/setup-node@v4
- with:
- node-version: 18
-
- - name: Prepare Rust env
- uses: ./.github/actions/prepare-rust-env
- with:
- poseidon-gadget-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
- zkos-circuits-private-key: ${{ secrets.ZKOS_CIRCUITS_SSH_PRIVATE_KEY }}
-
- - name: Install Foundry
- uses: foundry-rs/foundry-toolchain@v1.2.0
- with:
- cache-key: custom-seed-coverage-${{ github.ref_name }}
- cache-restore-keys: |-
- contract-suite
- version: nightly-31dd1f77fd9156d09836486d97963cec7f555343
-
- - name: Install deps
- run: make deps
-
- - name: Compile eth contracts
- run: make compile-contracts
-
- - name: Deploy contracts
- run: |
- PRIVATE_KEY=${{ secrets.CI_TESTNET_DEPLOYER_PRIVATE_KEY }} \
- NETWORK=https://rpc.alephzero-testnet.gelato.digital \
- make deploy-contracts
-
- - name: Verify Shielder contract
- run: ./scripts/verify-shielder-testnet.sh
-
- - name: Upload Shielder abi to artifacts
- uses: actions/upload-artifact@v4
- with:
- name: shielder_abi
- path: artifacts/Shielder.sol/Shielder.json
- include-hidden-files: true
- retention-days: 14
-
- - name: Upload Shielder contract address to artifacts
- uses: actions/upload-artifact@v4
- with:
- name: shielder_address
- path: shielder_address.txt
- include-hidden-files: true
- retention-days: 14
diff --git a/.github/workflows/on-pull-request-commit.yml b/.github/workflows/on-pull-request-commit.yml
index fb416a45..cbd42bb2 100644
--- a/.github/workflows/on-pull-request-commit.yml
+++ b/.github/workflows/on-pull-request-commit.yml
@@ -63,3 +63,8 @@ jobs:
with:
name: |
crates-shielder-wasm-pkg
+
+ measure-gas-usage:
+ name: Measure gas usage
+ uses: ./.github/workflows/_measure-gas.yml
+ secrets: inherit
diff --git a/.github/workflows/testnet-build-and-deploy-shielder-relayer.yml b/.github/workflows/testnet-dev-build-and-deploy-shielder-relayer.yml
similarity index 83%
rename from .github/workflows/testnet-build-and-deploy-shielder-relayer.yml
rename to .github/workflows/testnet-dev-build-and-deploy-shielder-relayer.yml
index 1244b97e..075ab69c 100644
--- a/.github/workflows/testnet-build-and-deploy-shielder-relayer.yml
+++ b/.github/workflows/testnet-dev-build-and-deploy-shielder-relayer.yml
@@ -1,8 +1,14 @@
---
-name: "[TESTNET] Build and deploy shielder-relayer"
+name: "[DEV] Build and deploy shielder-relayer"
on:
workflow_dispatch:
+ inputs:
+ overwrite-shielder-address:
+ type: string
+ required: false
+ default: ''
+ description: Overwrite shielder address - if empty it's not changed
jobs:
build-and-push:
@@ -43,10 +49,11 @@ jobs:
uses: ./.github/actions/shielder-relayer/deploy
id: deploy_shielder_relayer
with:
- environment: testnet-dev
+ environment: dev
image-tag: ${{ needs.build-and-push.outputs.image_tag }}
autocommit-author: ${{ secrets.AUTOCOMMIT_AUTHOR }}
autocommit-email: ${{ secrets.AUTOCOMMIT_EMAIL }}
github-token: ${{ secrets.CI_GH_TOKEN }}
kustomize-version: ${{ vars.KUSTOMIZE_VERSION }}
ecr-private-host: ${{ secrets.ECR_PRIVATE_HOST }}
+ overwrite-shielder-address: ${{ inputs.overwrite-shielder-address }}
diff --git a/.github/workflows/testnet-stage-build-and-deploy-shielder-relayer.yml b/.github/workflows/testnet-stage-build-and-deploy-shielder-relayer.yml
new file mode 100644
index 00000000..d5fc5557
--- /dev/null
+++ b/.github/workflows/testnet-stage-build-and-deploy-shielder-relayer.yml
@@ -0,0 +1,59 @@
+---
+name: "[STAGE] Build and deploy shielder-relayer"
+
+on:
+ workflow_dispatch:
+ inputs:
+ overwrite-shielder-address:
+ type: string
+ required: false
+ default: ''
+ description: Overwrite shielder address - if empty it's not changed
+
+jobs:
+ build-and-push:
+ name: Build and push shielder-relayer
+ runs-on: [self-hosted, Linux, X64, medium]
+ steps:
+ - name: GIT | Checkout
+ uses: actions/checkout@v4
+
+ - name: Prepare Rust env
+ uses: ./.github/actions/prepare-rust-env
+ with:
+ poseidon-gadget-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
+ zkos-circuits-private-key: ${{ secrets.ZKOS_CIRCUITS_SSH_PRIVATE_KEY }}
+
+ - name: Build relayer
+ run: cd crates/shielder-relayer && make build
+
+ - name: DOCKER | Build and push
+ uses: ./.github/actions/shielder-relayer/build-and-push
+ id: build_shielder_relayer
+ with:
+ aws-mainnet-ecr-access-key-id: ${{ secrets.AWS_MAINNET_ECR_ACCESS_KEY_ID }}
+ aws-mainnet-ecr-access-key: ${{ secrets.AWS_MAINNET_ECR_ACCESS_KEY }}
+ ecr-private-host: ${{ secrets.ECR_PRIVATE_HOST }}
+ outputs:
+ image_tag: ${{ steps.build_shielder_relayer.outputs.image_tag }}
+
+ deploy:
+ name: Deploy shielder-relayer
+ needs: [build-and-push]
+ runs-on: [self-hosted, Linux, X64, medium]
+ steps:
+ - name: GIT | Checkout
+ uses: actions/checkout@v4
+
+ - name: KUSTOMIZE | Deploy
+ uses: ./.github/actions/shielder-relayer/deploy
+ id: deploy_shielder_relayer
+ with:
+ environment: stage
+ image-tag: ${{ needs.build-and-push.outputs.image_tag }}
+ autocommit-author: ${{ secrets.AUTOCOMMIT_AUTHOR }}
+ autocommit-email: ${{ secrets.AUTOCOMMIT_EMAIL }}
+ github-token: ${{ secrets.CI_GH_TOKEN }}
+ kustomize-version: ${{ vars.KUSTOMIZE_VERSION }}
+ ecr-private-host: ${{ secrets.ECR_PRIVATE_HOST }}
+ overwrite-shielder-address: ${{ inputs.overwrite-shielder-address }}
diff --git a/.gitignore b/.gitignore
index dec0f4a3..d2831e15 100644
--- a/.gitignore
+++ b/.gitignore
@@ -12,7 +12,12 @@ contracts/*Key.sol
contracts/*Verifier.sol
contracts/Poseidon2T8Assembly.sol
**/*output.log
+*.txt
+*.html
tooling-dev/*
!tooling-dev/Makefile
-!tooling-dev/README.md
\ No newline at end of file
+!tooling-dev/README.md
+
+shielder_address.txt
+shielder_block_number.txt
diff --git a/CHANGELOG.md b/CHANGELOG.md
new file mode 100644
index 00000000..98c5f258
--- /dev/null
+++ b/CHANGELOG.md
@@ -0,0 +1,17 @@
+# Changelog
+
+All notable changes to this project will be documented in this file.
+
+The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
+
+## [Unreleased]
+
+### Added
+
+### Changed
+
+- The relayer's account, where the fees are paid, is now exposed at `/fee_address` endpoint. Both `shielder-cli` and TS client fetch it (it is no longer passed as a configuration parameter) [#61](https://github.com/Cardinal-Cryptography/zkOS-monorepo/pull/61).
+
+### Removed
+
+## [0.1.0] - 2024-12-13
diff --git a/Cargo.lock b/Cargo.lock
index 9a492e66..0f1e242e 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -34,6 +34,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011"
dependencies = [
"cfg-if",
+ "getrandom",
"once_cell",
"version_check",
"zerocopy",
@@ -67,25 +68,40 @@ dependencies = [
[[package]]
name = "alloy-consensus"
-version = "0.4.2"
+version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "705687d5bfd019fee57cf9e206b27b30a9a9617535d5590a02b171e813208f8e"
+checksum = "a205d0cbb7bfdf9f4fd4b0ec842bc4c5f926e8c14ec3072d3fd75dd363baf1e0"
dependencies = [
"alloy-eips",
"alloy-primitives",
"alloy-rlp",
"alloy-serde",
+ "alloy-trie",
"auto_impl",
"c-kzg",
"derive_more",
"serde",
]
+[[package]]
+name = "alloy-consensus-any"
+version = "0.8.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "993c34090a3f281cb746fd1604520cf21f8407ffbeb006aaa34c0556bffa718e"
+dependencies = [
+ "alloy-consensus",
+ "alloy-eips",
+ "alloy-primitives",
+ "alloy-rlp",
+ "alloy-serde",
+ "serde",
+]
+
[[package]]
name = "alloy-contract"
-version = "0.4.2"
+version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "917f7d12cf3971dc8c11c9972f732b35ccb9aaaf5f28f2f87e9e6523bee3a8ad"
+checksum = "aec7945dff98ba68489aa6da455bf66f6c0fee8157df06747fbae7cb03c368e2"
dependencies = [
"alloy-dyn-abi",
"alloy-json-abi",
@@ -98,14 +114,14 @@ dependencies = [
"alloy-transport",
"futures",
"futures-util",
- "thiserror 1.0.69",
+ "thiserror 2.0.9",
]
[[package]]
name = "alloy-dyn-abi"
-version = "0.8.13"
+version = "0.8.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "1cf633ae9a1f0c82fdb9e559ed2be1c8e415c3e48fc47e1feaf32c6078ec0cdd"
+checksum = "41056bde53ae10ffbbf11618efbe1e0290859e5eab0fe9ef82ebdb62f12a866f"
dependencies = [
"alloy-json-abi",
"alloy-primitives",
@@ -131,21 +147,22 @@ dependencies = [
[[package]]
name = "alloy-eip7702"
-version = "0.1.1"
+version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ea59dc42102bc9a1905dc57901edc6dd48b9f38115df86c7d252acba70d71d04"
+checksum = "4c986539255fb839d1533c128e190e557e52ff652c9ef62939e233a81dd93f7e"
dependencies = [
"alloy-primitives",
"alloy-rlp",
+ "derive_more",
"k256",
"serde",
]
[[package]]
name = "alloy-eips"
-version = "0.4.2"
+version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "6ffb906284a1e1f63c4607da2068c8197458a352d0b3e9796e67353d72a9be85"
+checksum = "d1d9907c29ce622946759bf4fd3418166bfeae76c1c544b8081c7be3acd9b4be"
dependencies = [
"alloy-eip2930",
"alloy-eip7702",
@@ -161,9 +178,9 @@ dependencies = [
[[package]]
name = "alloy-json-abi"
-version = "0.8.13"
+version = "0.8.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "1a500037938085feed8a20dbfc8fce58c599db68c948cfae711147175dee392c"
+checksum = "c357da577dfb56998d01f574d81ad7a1958d248740a7981b205d69d65a7da404"
dependencies = [
"alloy-primitives",
"alloy-sol-type-parser",
@@ -173,29 +190,31 @@ dependencies = [
[[package]]
name = "alloy-json-rpc"
-version = "0.4.2"
+version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f8fa8a1a3c4cbd221f2b8e3693aeb328fca79a757fe556ed08e47bbbc2a70db7"
+checksum = "39a786ce6bc7539dc30cabac6b7875644247c9e7d780e71a9f254d42ebdc013c"
dependencies = [
"alloy-primitives",
"alloy-sol-types",
"serde",
"serde_json",
- "thiserror 1.0.69",
+ "thiserror 2.0.9",
"tracing",
]
[[package]]
name = "alloy-network"
-version = "0.4.2"
+version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "85fa23a6a9d612b52e402c995f2d582c25165ec03ac6edf64c861a76bc5b87cd"
+checksum = "99051f82f77159d5bee06108f33cffee02849e2861fc500bf74213aa2ae8a26e"
dependencies = [
"alloy-consensus",
+ "alloy-consensus-any",
"alloy-eips",
"alloy-json-rpc",
"alloy-network-primitives",
"alloy-primitives",
+ "alloy-rpc-types-any",
"alloy-rpc-types-eth",
"alloy-serde",
"alloy-signer",
@@ -203,14 +222,16 @@ dependencies = [
"async-trait",
"auto_impl",
"futures-utils-wasm",
- "thiserror 1.0.69",
+ "serde",
+ "serde_json",
+ "thiserror 2.0.9",
]
[[package]]
name = "alloy-network-primitives"
-version = "0.4.2"
+version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "801492711d4392b2ccf5fc0bc69e299fa1aab15167d74dcaa9aab96a54f684bd"
+checksum = "d2aff127863f8279921397be8af0ac3f05a8757d5c4c972b491c278518fa07c7"
dependencies = [
"alloy-consensus",
"alloy-eips",
@@ -221,9 +242,9 @@ dependencies = [
[[package]]
name = "alloy-primitives"
-version = "0.8.13"
+version = "0.8.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3aeeb5825c2fc8c2662167058347cd0cafc3cb15bcb5cdb1758a63c2dca0409e"
+checksum = "6259a506ab13e1d658796c31e6e39d2e2ee89243bcc505ddc613b35732e0a430"
dependencies = [
"alloy-rlp",
"bytes",
@@ -250,9 +271,9 @@ dependencies = [
[[package]]
name = "alloy-provider"
-version = "0.4.2"
+version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "fcfaa4ffec0af04e3555686b8aacbcdf7d13638133a0672749209069750f78a6"
+checksum = "0280a4f68e0cefde9449ee989a248230efbe3f95255299d2a7a92009e154629d"
dependencies = [
"alloy-chains",
"alloy-consensus",
@@ -272,14 +293,17 @@ dependencies = [
"futures",
"futures-utils-wasm",
"lru",
+ "parking_lot",
"pin-project",
"reqwest",
+ "schnellru",
"serde",
"serde_json",
- "thiserror 1.0.69",
+ "thiserror 2.0.9",
"tokio",
"tracing",
"url",
+ "wasmtimer",
]
[[package]]
@@ -306,9 +330,9 @@ dependencies = [
[[package]]
name = "alloy-rpc-client"
-version = "0.4.2"
+version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "370143ed581aace6e663342d21d209c6b2e34ee6142f7d6675adb518deeaf0dc"
+checksum = "b6fc8b0f68619cfab3a2e15dca7b80ab266f78430bb4353dec546528e04b7449"
dependencies = [
"alloy-json-rpc",
"alloy-primitives",
@@ -324,13 +348,14 @@ dependencies = [
"tower",
"tracing",
"url",
+ "wasmtimer",
]
[[package]]
name = "alloy-rpc-types"
-version = "0.4.2"
+version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "9ffc534b7919e18f35e3aa1f507b6f3d9d92ec298463a9f6beaac112809d8d06"
+checksum = "986f23fe42ac95832901a24b93c20f7ed2b9644394c02b86222801230da60041"
dependencies = [
"alloy-primitives",
"alloy-rpc-types-engine",
@@ -339,11 +364,22 @@ dependencies = [
"serde",
]
+[[package]]
+name = "alloy-rpc-types-any"
+version = "0.8.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "57e3aa433d3657b42e98e257ee6fa201f5c853245648a33da8fbb7497a5008bf"
+dependencies = [
+ "alloy-consensus-any",
+ "alloy-rpc-types-eth",
+ "alloy-serde",
+]
+
[[package]]
name = "alloy-rpc-types-engine"
-version = "0.4.2"
+version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e0285c4c09f838ab830048b780d7f4a4f460f309aa1194bb049843309524c64c"
+checksum = "30814f8b9ac10219fb77fe42c277a0ffa1c369fbc3961f14d159f51fb221966e"
dependencies = [
"alloy-consensus",
"alloy-eips",
@@ -359,11 +395,12 @@ dependencies = [
[[package]]
name = "alloy-rpc-types-eth"
-version = "0.4.2"
+version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "413f4aa3ccf2c3e4234a047c5fa4727916d7daf25a89f9b765df0ba09784fd87"
+checksum = "0643cc497a71941f526454fe4fecb47e9307d3a7b6c05f70718a0341643bcc79"
dependencies = [
"alloy-consensus",
+ "alloy-consensus-any",
"alloy-eips",
"alloy-network-primitives",
"alloy-primitives",
@@ -378,9 +415,9 @@ dependencies = [
[[package]]
name = "alloy-serde"
-version = "0.4.2"
+version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "9dff0ab1cdd43ca001e324dc27ee0e8606bd2161d6623c63e0e0b8c4dfc13600"
+checksum = "ea61b049d7ecc66a29f107970dae493d0908e366048f7484a1ca9b02c85f9b2b"
dependencies = [
"alloy-primitives",
"serde",
@@ -389,23 +426,23 @@ dependencies = [
[[package]]
name = "alloy-signer"
-version = "0.4.2"
+version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "2fd4e0ad79c81a27ca659be5d176ca12399141659fef2bcbfdc848da478f4504"
+checksum = "93461b0e79c2ddd791fec5f369ab5c2686a33bbb03530144972edf5248f8a2c7"
dependencies = [
"alloy-primitives",
"async-trait",
"auto_impl",
"elliptic-curve",
"k256",
- "thiserror 1.0.69",
+ "thiserror 2.0.9",
]
[[package]]
name = "alloy-signer-local"
-version = "0.4.2"
+version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "494e0a256f3e99f2426f994bcd1be312c02cb8f88260088dacb33a8b8936475f"
+checksum = "6f08ec1bfa433f9e9f7c5af05af07e5cf86d27d93170de76b760e63b925f1c9c"
dependencies = [
"alloy-consensus",
"alloy-network",
@@ -414,14 +451,14 @@ dependencies = [
"async-trait",
"k256",
"rand",
- "thiserror 1.0.69",
+ "thiserror 2.0.9",
]
[[package]]
name = "alloy-sol-macro"
-version = "0.8.13"
+version = "0.8.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "5c0279d09463a4695788a3622fd95443625f7be307422deba4b55dd491a9c7a1"
+checksum = "d9d64f851d95619233f74b310f12bcf16e0cbc27ee3762b6115c14a84809280a"
dependencies = [
"alloy-sol-macro-expander",
"alloy-sol-macro-input",
@@ -433,9 +470,9 @@ dependencies = [
[[package]]
name = "alloy-sol-macro-expander"
-version = "0.8.13"
+version = "0.8.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "4feea540fc8233df2ad1156efd744b2075372f43a8f942a68b3b19c8a00e2c12"
+checksum = "6bf7ed1574b699f48bf17caab4e6e54c6d12bc3c006ab33d58b1e227c1c3559f"
dependencies = [
"alloy-json-abi",
"alloy-sol-macro-input",
@@ -452,9 +489,9 @@ dependencies = [
[[package]]
name = "alloy-sol-macro-input"
-version = "0.8.13"
+version = "0.8.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "2a0ad281f3d1b613af814b66977ee698e443d4644a1510962d0241f26e0e53ae"
+checksum = "8c02997ccef5f34f9c099277d4145f183b422938ed5322dc57a089fe9b9ad9ee"
dependencies = [
"alloy-json-abi",
"const-hex",
@@ -469,9 +506,9 @@ dependencies = [
[[package]]
name = "alloy-sol-type-parser"
-version = "0.8.13"
+version = "0.8.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "96eff16c797438add6c37bb335839d015b186c5421ee5626f5559a7bfeb38ef5"
+checksum = "ce13ff37285b0870d0a0746992a4ae48efaf34b766ae4c2640fa15e5305f8e73"
dependencies = [
"serde",
"winnow",
@@ -479,9 +516,9 @@ dependencies = [
[[package]]
name = "alloy-sol-types"
-version = "0.8.13"
+version = "0.8.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "cff34e0682d6665da243a3e81da96f07a2dd50f7e64073e382b1a141f5a2a2f6"
+checksum = "1174cafd6c6d810711b4e00383037bdb458efc4fe3dbafafa16567e0320c54d8"
dependencies = [
"alloy-json-abi",
"alloy-primitives",
@@ -492,9 +529,9 @@ dependencies = [
[[package]]
name = "alloy-transport"
-version = "0.4.2"
+version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "2ac3e97dad3d31770db0fc89bd6a63b789fbae78963086733f960cf32c483904"
+checksum = "baf656f983e14812df65b5aee37e7b37535f68a848295e6ed736b2054a405cb7"
dependencies = [
"alloy-json-rpc",
"base64 0.22.1",
@@ -502,18 +539,19 @@ dependencies = [
"futures-utils-wasm",
"serde",
"serde_json",
- "thiserror 1.0.69",
+ "thiserror 2.0.9",
"tokio",
"tower",
"tracing",
"url",
+ "wasmtimer",
]
[[package]]
name = "alloy-transport-http"
-version = "0.4.2"
+version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b367dcccada5b28987c2296717ee04b9a5637aacd78eacb1726ef211678b5212"
+checksum = "ec938d51a47b7953b1c0fd8ddeb89a29eb113cd4908dfc4e01c7893b252d669f"
dependencies = [
"alloy-json-rpc",
"alloy-transport",
@@ -524,6 +562,22 @@ dependencies = [
"url",
]
+[[package]]
+name = "alloy-trie"
+version = "0.7.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3a5fd8fea044cc9a8c8a50bb6f28e31f0385d820f116c5b98f6f4e55d6e5590b"
+dependencies = [
+ "alloy-primitives",
+ "alloy-rlp",
+ "arrayvec",
+ "derive_more",
+ "nybbles",
+ "serde",
+ "smallvec",
+ "tracing",
+]
+
[[package]]
name = "android-tzdata"
version = "0.1.1"
@@ -590,9 +644,9 @@ dependencies = [
[[package]]
name = "anyhow"
-version = "1.0.93"
+version = "1.0.94"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "4c95c10ba0b00a02636238b814946408b1322d5ac4760326e6fb8ec956d85775"
+checksum = "c1fd03a028ef38ba2276dce7e33fcd6369c158a1bca17946c4b1b701891c1ff7"
[[package]]
name = "ark-ff"
@@ -729,6 +783,9 @@ name = "arrayvec"
version = "0.7.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50"
+dependencies = [
+ "serde",
+]
[[package]]
name = "askama"
@@ -967,6 +1024,22 @@ version = "0.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "349f9b6a179ed607305526ca489b34ad0a41aed5f7980fa90eb03160b69598fb"
+[[package]]
+name = "bitcoin-io"
+version = "0.1.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0b47c4ab7a93edb0c7198c5535ed9b52b63095f4e9b45279c6736cec4b856baf"
+
+[[package]]
+name = "bitcoin_hashes"
+version = "0.14.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "bb18c03d0db0247e147a21a6faafd5a7eb851c743db062de72018b6b7e8e4d16"
+dependencies = [
+ "bitcoin-io",
+ "hex-conservative",
+]
+
[[package]]
name = "bitflags"
version = "1.3.2"
@@ -1267,9 +1340,9 @@ dependencies = [
[[package]]
name = "const-hex"
-version = "1.13.2"
+version = "1.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "487981fa1af147182687064d0a2c336586d337a606595ced9ffb0c685c250c73"
+checksum = "4b0485bab839b018a8f1723fc5391819fea5f8f0f32288ef8a735fd096b6160c"
dependencies = [
"cfg-if",
"cpufeatures",
@@ -1719,7 +1792,7 @@ dependencies = [
"hex",
"revm",
"revm-primitives",
- "thiserror 1.0.69",
+ "thiserror 2.0.9",
]
[[package]]
@@ -2068,14 +2141,17 @@ version = "0.12.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888"
+[[package]]
+name = "hashbrown"
+version = "0.13.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e"
+
[[package]]
name = "hashbrown"
version = "0.14.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1"
-dependencies = [
- "ahash",
-]
[[package]]
name = "hashbrown"
@@ -2110,6 +2186,15 @@ dependencies = [
"serde",
]
+[[package]]
+name = "hex-conservative"
+version = "0.2.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5313b072ce3c597065a808dbf612c4c8e8590bdbf8b579508bf7a762c5eae6cd"
+dependencies = [
+ "arrayvec",
+]
+
[[package]]
name = "hex-literal"
version = "0.4.1"
@@ -2855,9 +2940,9 @@ checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
[[package]]
name = "metrics"
-version = "0.23.0"
+version = "0.24.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "884adb57038347dfbaf2d5065887b6cf4312330dc8e94bc30a1a839bd79d3261"
+checksum = "7a7deb012b3b2767169ff203fadb4c6b0b82b947512e5eb9e0b78c2e186ad9e3"
dependencies = [
"ahash",
"portable-atomic",
@@ -2865,9 +2950,9 @@ dependencies = [
[[package]]
name = "metrics-exporter-prometheus"
-version = "0.15.3"
+version = "0.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b4f0c8427b39666bf970460908b213ec09b3b350f20c0c2eabcbba51704a08e6"
+checksum = "85b6f8152da6d7892ff1b7a1c0fa3f435e92b5918ad67035c3bb432111d9a29b"
dependencies = [
"base64 0.22.1",
"indexmap 2.6.0",
@@ -2879,15 +2964,14 @@ dependencies = [
[[package]]
name = "metrics-util"
-version = "0.17.0"
+version = "0.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "4259040465c955f9f2f1a4a8a16dc46726169bca0f88e8fb2dbeced487c3e828"
+checksum = "15b482df36c13dd1869d73d14d28cd4855fbd6cfc32294bee109908a9f4a4ed7"
dependencies = [
"crossbeam-epoch",
"crossbeam-utils",
- "hashbrown 0.14.5",
+ "hashbrown 0.15.2",
"metrics",
- "num_cpus",
"quanta",
"sketches-ddsketch",
]
@@ -3103,6 +3187,17 @@ dependencies = [
"syn 2.0.89",
]
+[[package]]
+name = "nybbles"
+version = "0.2.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "95f06be0417d97f81fe4e5c86d7d01b392655a9cac9c19a848aa033e18937b23"
+dependencies = [
+ "const-hex",
+ "serde",
+ "smallvec",
+]
+
[[package]]
name = "object"
version = "0.36.5"
@@ -3513,7 +3608,7 @@ dependencies = [
"rustc-hash",
"rustls 0.23.19",
"socket2",
- "thiserror 2.0.3",
+ "thiserror 2.0.9",
"tokio",
"tracing",
]
@@ -3532,7 +3627,7 @@ dependencies = [
"rustls 0.23.19",
"rustls-pki-types",
"slab",
- "thiserror 2.0.3",
+ "thiserror 2.0.9",
"tinyvec",
"tracing",
"web-time",
@@ -3770,9 +3865,9 @@ dependencies = [
[[package]]
name = "revm"
-version = "14.0.3"
+version = "18.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "641702b12847f9ed418d552f4fcabe536d867a2c980e96b6e7e25d7b992f929f"
+checksum = "15689a3c6a8d14b647b4666f2e236ef47b5a5133cdfd423f545947986fff7013"
dependencies = [
"auto_impl",
"cfg-if",
@@ -3785,9 +3880,9 @@ dependencies = [
[[package]]
name = "revm-interpreter"
-version = "10.0.3"
+version = "14.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "2e5e14002afae20b5bf1566f22316122f42f57517000e559c55b25bf7a49cba2"
+checksum = "74e3f11d0fed049a4a10f79820c59113a79b38aed4ebec786a79d5c667bfeb51"
dependencies = [
"revm-primitives",
"serde",
@@ -3795,9 +3890,9 @@ dependencies = [
[[package]]
name = "revm-precompile"
-version = "11.0.3"
+version = "15.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3198c06247e8d4ad0d1312591edf049b0de4ddffa9fecb625c318fd67db8639b"
+checksum = "e381060af24b750069a2b2d2c54bba273d84e8f5f9e8026fc9262298e26cc336"
dependencies = [
"aurora-engine-modexp",
"c-kzg",
@@ -3806,16 +3901,16 @@ dependencies = [
"once_cell",
"revm-primitives",
"ripemd",
- "secp256k1",
+ "secp256k1 0.29.1",
"sha2",
"substrate-bn",
]
[[package]]
name = "revm-primitives"
-version = "10.0.0"
+version = "14.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "6f1525851a03aff9a9d6a1d018b414d76252d6802ab54695b27093ecd7e7a101"
+checksum = "3702f132bb484f4f0d0ca4f6fbde3c82cfd745041abbedd6eda67730e1868ef0"
dependencies = [
"alloy-eip2930",
"alloy-eip7702",
@@ -4112,6 +4207,17 @@ dependencies = [
"windows-sys 0.59.0",
]
+[[package]]
+name = "schnellru"
+version = "0.2.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c9a8ef13a93c54d20580de1e5c413e624e53121d42fc7e2c11d10ef7f8b02367"
+dependencies = [
+ "ahash",
+ "cfg-if",
+ "hashbrown 0.13.2",
+]
+
[[package]]
name = "scopeguard"
version = "1.2.0"
@@ -4142,6 +4248,17 @@ dependencies = [
"secp256k1-sys",
]
+[[package]]
+name = "secp256k1"
+version = "0.30.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b50c5943d326858130af85e049f2661ba3c78b26589b8ab98e65e80ae44a1252"
+dependencies = [
+ "bitcoin_hashes",
+ "rand",
+ "secp256k1-sys",
+]
+
[[package]]
name = "secp256k1-sys"
version = "0.10.1"
@@ -4464,12 +4581,12 @@ dependencies = [
"log",
"num-bigint",
"rand",
- "secp256k1",
+ "secp256k1 0.30.0",
"serde",
"sha3 0.10.8",
"shielder-circuits",
"static_assertions",
- "thiserror 1.0.69",
+ "thiserror 2.0.9",
"tracing",
]
@@ -4551,9 +4668,9 @@ dependencies = [
[[package]]
name = "sketches-ddsketch"
-version = "0.2.2"
+version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "85636c14b73d81f541e525f585c0a2109e6744e1565b5c1668e31c70c10ed65c"
+checksum = "c1e9a774a6c28142ac54bb25d25562e6bcf957493a184f15ad4eebccb23e410a"
[[package]]
name = "slab"
@@ -4569,6 +4686,9 @@ name = "smallvec"
version = "1.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67"
+dependencies = [
+ "serde",
+]
[[package]]
name = "socket2"
@@ -4719,9 +4839,9 @@ dependencies = [
[[package]]
name = "syn-solidity"
-version = "0.8.13"
+version = "0.8.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "6bdaa7b9e815582ba343a20c66627437cf45f1c6fba7f69772cbfd1358c7e197"
+checksum = "219389c1ebe89f8333df8bdfb871f6631c552ff399c23cac02480b6088aad8f0"
dependencies = [
"paste",
"proc-macro2",
@@ -4844,11 +4964,11 @@ dependencies = [
[[package]]
name = "thiserror"
-version = "2.0.3"
+version = "2.0.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "c006c85c7651b3cf2ada4584faa36773bd07bac24acfb39f3c431b36d7e667aa"
+checksum = "f072643fd0190df67a8bab670c20ef5d8737177d6ac6b2e9a236cb096206b2cc"
dependencies = [
- "thiserror-impl 2.0.3",
+ "thiserror-impl 2.0.9",
]
[[package]]
@@ -4864,9 +4984,9 @@ dependencies = [
[[package]]
name = "thiserror-impl"
-version = "2.0.3"
+version = "2.0.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f077553d607adc1caf65430528a576c757a71ed73944b66ebb58ef2bbd243568"
+checksum = "7b50fa271071aae2e6ee85f842e2e28ba8cd2c5fb67f11fcb1fd70b276f9e7d4"
dependencies = [
"proc-macro2",
"quote",
@@ -4957,6 +5077,20 @@ version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
+[[package]]
+name = "token-distributor"
+version = "0.1.0"
+dependencies = [
+ "alloy-primitives",
+ "alloy-provider",
+ "alloy-rpc-types",
+ "alloy-signer-local",
+ "anyhow",
+ "clap",
+ "rand",
+ "tokio",
+]
+
[[package]]
name = "tokio"
version = "1.41.1"
@@ -5447,6 +5581,20 @@ dependencies = [
"web-sys",
]
+[[package]]
+name = "wasmtimer"
+version = "0.4.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0048ad49a55b9deb3953841fa1fc5858f0efbcb7a18868c899a360269fac1b23"
+dependencies = [
+ "futures",
+ "js-sys",
+ "parking_lot",
+ "pin-utils",
+ "slab",
+ "wasm-bindgen",
+]
+
[[package]]
name = "web-sys"
version = "0.3.70"
diff --git a/Cargo.toml b/Cargo.toml
index 11d45a02..2b7558c0 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -9,20 +9,20 @@ authors = ["Cardinal"]
homepage = "https://alephzero.org"
license = "Apache-2.0"
categories = ["cryptography"]
-repository = "https://github.com/Cardinal-Cryptography/zkOS"
+repository = "https://github.com/Cardinal-Cryptography/zkOS-monorepo"
[workspace.dependencies]
-alloy-contract = { version = "0.4.2" }
-alloy-eips = { version = "0.4.2" }
-alloy-network = { version = "0.4.2" }
+alloy-contract = { version = "0.8.1" }
+alloy-eips = { version = "0.8.1" }
+alloy-network = { version = "0.8.1" }
alloy-primitives = { version = "0.8.5" }
-alloy-provider = { version = "0.4.2" }
-alloy-rpc-types = { version = "0.4.2" }
-alloy-rpc-types-eth = { version = "0.4.2" }
-alloy-signer = { version = "0.4.2" }
-alloy-signer-local = { version = "0.4.2" }
+alloy-provider = { version = "0.8.1" }
+alloy-rpc-types = { version = "0.8.1" }
+alloy-rpc-types-eth = { version = "0.8.1" }
+alloy-signer = { version = "0.8.1" }
+alloy-signer-local = { version = "0.8.1" }
alloy-sol-types = { version = "0.8.5" }
-alloy-transport = { version = "0.4.2" }
+alloy-transport = { version = "0.8.1" }
anyhow = { version = "1.0.86", default-features = false }
askama = { version = "0.12.0", default-features = false }
async-channel = { version = "2.3.1" }
@@ -39,8 +39,8 @@ inquire = { version = "0.7.5" }
itertools = { version = "0.13.0" }
lazy_static = { version = "1.5.0" }
log = { version = "0.4.22" }
-metrics = { version = "0.23.0", default-features = false }
-metrics-exporter-prometheus = { version = "0.15.3", default-features = false }
+metrics = { version = "0.24.1", default-features = false }
+metrics-exporter-prometheus = { version = "0.16.0", default-features = false }
num-bigint = { version = "0.4.3" }
openssl = { version = "0.10.59" }
rand = { version = "0.8.5" }
@@ -48,12 +48,12 @@ rand_chacha = { version = "0.3.1" }
rand_core = { version = "0.6.4" }
rayon = { version = "1.8" }
reqwest = { version = "0.12.5" }
-revm = { version = "14.0.3", default-features = false }
-revm-primitives = { version = "10.0.0", default-features = false }
+revm = { version = "18.0.0", default-features = false }
+revm-primitives = { version = "14.0.0", default-features = false }
rstest = "0.23.0"
ruint = { version = "1" }
rust-argon2 = { version = "2.1.0" }
-secp256k1 = { version = "0.29.1" }
+secp256k1 = { version = "0.30.0" }
serde = { version = "1.0.203" }
serde_json = { version = "1.0.120" }
sha2 = { version = "0.10.8" }
@@ -63,7 +63,7 @@ shellexpand = { version = "3.1.0" }
shielder-circuits = { git = "ssh://git@github.com/Cardinal-Cryptography/zkOS-circuits", rev = "7743b2f" }
static_assertions = { version = "1.1.0" }
testcontainers = { version = "0.19.0" }
-thiserror = { version = "1.0.61" }
+thiserror = { version = "2.0.9" }
tokio = { version = "1.38.0" }
tower-http = { version = "0.6.1" }
tracing = { version = "0.1.40" }
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 00000000..f49a4e16
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,201 @@
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
\ No newline at end of file
diff --git a/LICENSE-GPL-3.0-only-with-Classpath-exception b/LICENSE-GPL-3.0-only-with-Classpath-exception
new file mode 100644
index 00000000..12925793
--- /dev/null
+++ b/LICENSE-GPL-3.0-only-with-Classpath-exception
@@ -0,0 +1,207 @@
+GNU GENERAL PUBLIC LICENSE
+Version 3, 29 June 2007
+
+Copyright © 2007 Free Software Foundation, Inc.
+
+Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.
+
+Preamble
+
+The GNU General Public License is a free, copyleft license for software and other kinds of works.
+
+The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too.
+
+When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things.
+
+To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others.
+
+For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights.
+
+Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it.
+
+For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions.
+
+Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users.
+
+Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free.
+
+The precise terms and conditions for copying, distribution and modification follow.
+
+TERMS AND CONDITIONS
+
+ 0. Definitions.
+
+ "This License" refers to version 3 of the GNU General Public License.
+
+ "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks.
+
+ "The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations.
+
+ To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work.
+
+ A "covered work" means either the unmodified Program or a work based on the Program.
+
+ To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well.
+
+ To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying.
+
+ An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion.
+ 1. Source Code.
+ The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work.
+
+ A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language.
+
+ The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it.
+
+ The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work.
+
+ The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source.
+
+ The Corresponding Source for a work in source code form is that same work.
+ 2. Basic Permissions.
+ All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law.
+
+ You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you.
+
+ Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary.
+ 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
+ No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures.
+
+ When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures.
+ 4. Conveying Verbatim Copies.
+ You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program.
+
+ You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee.
+ 5. Conveying Modified Source Versions.
+ You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions:
+ a) The work must carry prominent notices stating that you modified it, and giving a relevant date.
+ b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices".
+ c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it.
+ d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so.
+
+ A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate.
+ 6. Conveying Non-Source Forms.
+ You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways:
+ a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange.
+ b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge.
+ c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b.
+ d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements.
+ e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d.
+
+ A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work.
+
+ A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product.
+
+ "Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made.
+
+ If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM).
+
+ The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network.
+
+ Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying.
+ 7. Additional Terms.
+ "Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions.
+
+ When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission.
+
+ Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms:
+ a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or
+ b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or
+ c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or
+ d) Limiting the use for publicity purposes of names of licensors or authors of the material; or
+ e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or
+ f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors.
+
+ All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying.
+
+ If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms.
+
+ Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way.
+ 8. Termination.
+ You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11).
+
+ However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation.
+
+ Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice.
+
+ Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10.
+ 9. Acceptance Not Required for Having Copies.
+ You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so.
+ 10. Automatic Licensing of Downstream Recipients.
+ Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License.
+
+ An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts.
+
+ You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it.
+ 11. Patents.
+ A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version".
+
+ A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License.
+
+ Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version.
+
+ In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party.
+
+ If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid.
+
+ If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it.
+
+ A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007.
+
+ Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law.
+ 12. No Surrender of Others' Freedom.
+ If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program.
+ 13. Use with the GNU Affero General Public License.
+ Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such.
+ 14. Revised Versions of this License.
+ The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.
+
+ Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation.
+
+ If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program.
+
+ Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version.
+ 15. Disclaimer of Warranty.
+ THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+ 16. Limitation of Liability.
+ IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ 17. Interpretation of Sections 15 and 16.
+
+ If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee.
+
+END OF TERMS AND CONDITIONS
+
+How to Apply These Terms to Your New Programs
+
+If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms.
+
+To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found.
+
+
+Copyright (C)
+
+This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License along with this program. If not, see .
+
+Also add information on how to contact you by electronic and paper mail.
+
+If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode:
+
+ Copyright (C)
+This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an "about box".
+
+You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see .
+
+The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read .
+
+CLASS PATH EXCEPTION
+
+Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination.
+
+As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.
diff --git a/Makefile b/Makefile
index 6f1fbca4..0ebb0331 100644
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,6 @@
NETWORK ?= anvil
PRIVATE_KEY ?= 0xb6b15c8cb491557369f3c7d2c287b053eb229daa9c22138887752191c9520659 # pkey of the dev account `0x3f1Eae7D46d88F08fc2F8ed27FCb2AB183EB2d0E` prefunded with ETH on all networks
+OWNER_ADDRESS ?= $(shell cast wallet address $(PRIVATE_KEY))
.PHONY: help
help: # Show help for each of the Makefile recipes.
@@ -28,30 +29,31 @@ stop-anvil:
.PHONY: watch-contracts
watch-contracts: # watcher on the eth contracts. Scripts dir is watched by default
watch-contracts:
- forge build --watch contracts/*.sol --watch scripts/*.sol
+ forge clean && forge build --watch contracts/**/*.sol --watch scripts/*.sol --watch test/*.sol
.PHONY: format-contracts
format-contracts: # Format solidity contracts
format-contracts:
- npx prettier --write --plugin=prettier-plugin-solidity 'contracts/*.sol' 'scripts/*.sol'
+ npx prettier --write --plugin=prettier-plugin-solidity 'contracts/**/*.sol' 'scripts/*.sol' 'test/*.sol'
.PHONY: lint-contracts
lint-contracts: # Lint solidity contracts
lint-contracts:
- npx solhint -c .solhint.json 'contracts/*.sol' 'scripts/*.sol'
+ npx solhint -c .solhint.json 'contracts/*.sol' 'scripts/*.sol' 'test/*.sol'
.PHONY: compile-contracts
compile-contracts: # Compile solidity contracts
-compile-contracts: generate-verifier-contracts generate-poseidon-contracts
- forge build
+compile-contracts: deps generate-contracts
+ forge clean && forge build
.PHONY: deploy-contracts
deploy-contracts: # Deploy solidity contracts
deploy-contracts:
ifeq ($(NETWORK),anvil)
- PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 forge script DeployShielderScript --broadcast --rpc-url anvil
+ $(eval PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80) \
+ PRIVATE_KEY=$(PRIVATE_KEY) OWNER_ADDRESS=$(OWNER_ADDRESS) forge script DeployShielderScript --broadcast --rpc-url anvil --sender $(shell cast wallet address $(PRIVATE_KEY))
else
- PRIVATE_KEY=$(PRIVATE_KEY) forge script DeployShielderScript --broadcast --rpc-url $(NETWORK)
+ PRIVATE_KEY=$(PRIVATE_KEY) OWNER_ADDRESS=$(OWNER_ADDRESS) forge script DeployShielderScript --broadcast --rpc-url $(NETWORK) --sender $(shell cast wallet address $(PRIVATE_KEY))
endif
.PHONY: generate-poseidon-contracts
@@ -71,6 +73,11 @@ generate-verifier-contracts:
generate-contracts: # Generate poseidon & relation verifier contracts
generate-contracts: generate-poseidon-contracts generate-verifier-contracts
+.PHONY: measure-gas
+measure-gas: # measure shielder gas usage
+measure-gas: compile-contracts
+ CONTRACTS_DIR=contracts CARGO_MANIFEST_DIR=./Cargo.toml cargo run -p integration-tests --bin gas-consumption --release -- current-report.txt
+
.PHONY: format-rust
format-rust: # Format all rust crates
format-rust:
diff --git a/NOTICE b/NOTICE
new file mode 100644
index 00000000..859380f2
--- /dev/null
+++ b/NOTICE
@@ -0,0 +1,4 @@
+NOTICE
+
+This project depends on `shielder-circuits`, which is licensed under GPL-3.0-only with Classpath exception.
+The full text of this license is available in LICENSE-GPL-3.0-only-with-Classpath-exception.
\ No newline at end of file
diff --git a/README.md b/README.md
index e21aa9d2..545ba24f 100644
--- a/README.md
+++ b/README.md
@@ -1,8 +1,8 @@
[![LOGO][logo]][aleph-homepage]
[![Nightly Testnet E2E tests][nightly-tests-badge]][nightly-tests]
-[![Contracts Testnet deployment][contracts-deployment-badge]][contracts-deployment]
-[![Relayer Testnet deployment][relayer-deployment-badge]][relayer-deployment]
+[![Contracts deployment][contracts-deployment-badge]][contracts-deployment]
+[![Relayer deployment][relayer-deployment-badge]][relayer-deployment]
# Shielder: A First Iteration of zkOS
@@ -35,7 +35,6 @@ Shielder is part of the Aleph Zero zkOS initiative, aimed at delivering Privacy-
Shielder is built utilizing the following components:
-- **Aleph Zero WASM L1**: Serves as the Data Availability layer.
- **EVM Layer 2 Rollup**: Leverages Arbitrum Anytrust DAC technology for fast and secure execution.
- **Developer Tooling**: Includes Gelato’s web3 services, account abstraction, functions, VRF, oracles, block explorers, indexers, and multisig support.
@@ -65,12 +64,37 @@ Boot a local node:
make anvil
```
+Generate additional contract sources:
+
+```bash
+make generate-contracts
+```
+
Compile & deploy the smart contract suite:
```bash
make deploy-contracts
```
+### Running e2e tests
+
+Install dependencies and generate additional contract sources:
+
+```bash
+make deps
+make generate-contracts
+```
+
+Run:
+
+```bash
+run tooling-e2e-tests/full_scenario.sh
+```
+
+(or another `.sh` file from that directory). For maximum compatibility `export BUILD=docker` - this will be slower but
+will build the relayer image inside docker. Otherwise the binary is built on your machine and then copied into the image
+which might not work, depending on the exact configuration of the host.
+
### Deploying to anvil
The command below will use `0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266` as a deployer:
@@ -81,13 +105,22 @@ NETWORK=anvil make deploy-contracts
## License
-Shielder is licensed under the MIT License. See the LICENSE file for more details.
+Shielder is licensed under the Apache-2.0 License. See the LICENSE file for more details.
+
+## Private components and future open sourcing plan
+While this repository represents the majority of our work, there are still some components that are kept in private repositories.
+These include halo2 circuits and Poseidon2 hashing function.
+
+The main reason for keeping these components private at this time is that they are waiting for an external audit to ensure they meet all compliance, security, and quality standards.
+This step is essential to ensure that when we open source these parts, they adhere to our community's expectations for transparency, security, and usability.
+
+We are fully committed to open-sourcing these remaining components as soon as the audit is complete. Stay tuned for updates, and feel free to reach out with any questions or feedback in the meantime!
[aleph-homepage]: https://alephzero.org
[logo]: logo.png
-[contracts-deployment]: https://github.com/Cardinal-Cryptography/zkOS-monorepo/actions/workflows/manual-testnet-deploy-contract.yml
-[contracts-deployment-badge]: https://github.com/Cardinal-Cryptography/zkOS-monorepo/actions/workflows/manual-testnet-deploy-contract.yml/badge.svg
-[relayer-deployment]: https://github.com/Cardinal-Cryptography/zkOS-monorepo/actions/workflows/testnet-build-and-deploy-shielder-relayer.yml
-[relayer-deployment-badge]: https://github.com/Cardinal-Cryptography/zkOS-monorepo/actions/workflows/testnet-build-and-deploy-shielder-relayer.yml/badge.svg
+[contracts-deployment]: https://github.com/Cardinal-Cryptography/zkOS-monorepo/actions/workflows/manual-deploy-contract.yml
+[contracts-deployment-badge]: https://github.com/Cardinal-Cryptography/zkOS-monorepo/actions/workflows/manual-deploy-contract.yml/badge.svg
+[relayer-deployment]: https://github.com/Cardinal-Cryptography/zkOS-monorepo/actions/workflows/testnet-stage-build-and-deploy-shielder-relayer.yml
+[relayer-deployment-badge]: https://github.com/Cardinal-Cryptography/zkOS-monorepo/actions/workflows/testnet-stage-build-and-deploy-shielder-relayer.yml/badge.svg
[nightly-tests]: https://github.com/Cardinal-Cryptography/zkOS-monorepo/actions/workflows/testnet-nightly-e2e.yml
[nightly-tests-badge]: https://github.com/Cardinal-Cryptography/zkOS-monorepo/actions/workflows/testnet-nightly-e2e.yml/badge.svg
diff --git a/contracts/ArbSysMock.sol b/contracts/ArbSysMock.sol
index 4785bb4a..d17d3e54 100644
--- a/contracts/ArbSysMock.sol
+++ b/contracts/ArbSysMock.sol
@@ -1,4 +1,4 @@
-// SPDX-License-Identifier: MIT
+// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.8.26;
import { IArbSys } from "./IArbSys.sol";
diff --git a/contracts/DepositLimit.sol b/contracts/DepositLimit.sol
index 4d50a98d..0ce923a3 100644
--- a/contracts/DepositLimit.sol
+++ b/contracts/DepositLimit.sol
@@ -1,4 +1,4 @@
-// SPDX-License-Identifier: MIT
+// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.8.26;
import { Initializable } from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
diff --git a/contracts/IArbSys.sol b/contracts/IArbSys.sol
index fb94c591..7ee76c77 100644
--- a/contracts/IArbSys.sol
+++ b/contracts/IArbSys.sol
@@ -1,4 +1,4 @@
-// SPDX-License-Identifier: MIT
+// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.14;
// Interface taken from https://docs.arbitrum.io/build-decentralized-apps/precompiles/reference#arbsys.
diff --git a/contracts/MerkleTree.sol b/contracts/MerkleTree.sol
index b226c1bb..d7c51342 100644
--- a/contracts/MerkleTree.sol
+++ b/contracts/MerkleTree.sol
@@ -1,4 +1,4 @@
-// SPDX-License-Identifier: MIT
+// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.8.26;
@@ -70,12 +70,13 @@ abstract contract MerkleTree is Initializable {
}
/*
- * Given an index of a leaf return the path from a leaf index to the root,
- * omitting the root and leaf for gas efficiency,
- * as they can be derived from hashing their children.
+ * Given an index of a leaf return the Merkle path from this leaf to the root.
+ *
* Leaves are indexed from 0.
- * Path is an array of length TREE_HEIGHT*ARITY+1, where the first TREE_HEIGHT*ARITY elements are the siblings of the path,
- * and the last element is the root.
+ *
+ * Path is an array of length TREE_HEIGHT*ARITY+1, where the first TREE_HEIGHT*ARITY elements is the full path
+ * (ancestors with their siblings, ordered) and the last element is the root.
+ *
* If tree looks like this:
* l_3 = hash(l_1, l_2)
* l_5 = hash(l_3, l_4)
@@ -96,21 +97,15 @@ abstract contract MerkleTree is Initializable {
uint256[] memory path = new uint256[](TREE_HEIGHT * ARITY + 1);
uint256 parent = 0;
- for (uint256 i = 0; i < TREE_HEIGHT; ) {
+ for (uint256 i = 0; i < TREE_HEIGHT; ++i) {
unchecked {
parent = (index + ARITY - 2) / ARITY;
}
- for (uint256 j = 0; j < ARITY; ) {
+ for (uint256 j = 0; j < ARITY; ++j) {
path[i * ARITY + j] = $.notes[parent * ARITY + j - (ARITY - 2)];
- unchecked {
- j++;
- }
}
index = parent;
- unchecked {
- i++;
- }
}
path[TREE_HEIGHT * ARITY] = $.root;
@@ -132,23 +127,17 @@ abstract contract MerkleTree is Initializable {
uint256[ARITY] memory subtrees;
$.notes[index] = note;
- for (uint256 i = 0; i < TREE_HEIGHT; ) {
+ for (uint256 i = 0; i < TREE_HEIGHT; ++i) {
unchecked {
parent = (index + ARITY - 2) / ARITY;
}
- for (uint256 j = 0; j < ARITY; ) {
+ for (uint256 j = 0; j < ARITY; ++j) {
subtrees[j] = $.notes[parent * ARITY + j - (ARITY - 2)];
- unchecked {
- j++;
- }
}
note = Poseidon2.hash(subtrees);
$.notes[parent] = note;
index = parent;
- unchecked {
- i++;
- }
}
$.root = note;
$.nextFreeLeafId += 1;
diff --git a/contracts/Nullifiers.sol b/contracts/Nullifiers.sol
index 917fdf50..dd47e672 100644
--- a/contracts/Nullifiers.sol
+++ b/contracts/Nullifiers.sol
@@ -1,4 +1,4 @@
-// SPDX-License-Identifier: MIT
+// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.8.26;
import { IArbSys } from "./IArbSys.sol";
diff --git a/contracts/Permit2.sol b/contracts/Permit2.sol
deleted file mode 100644
index ed2e1140..00000000
--- a/contracts/Permit2.sol
+++ /dev/null
@@ -1,7 +0,0 @@
-// SPDX-License-Identifier: MIT
-
-pragma solidity ^0.8.14;
-
-/* @dev: needed to compile Permit2 */
-/* solhint-disable no-unused-import */
-import { Permit2 } from "@uniswap/permit2/src/Permit2.sol";
diff --git a/contracts/Shielder.sol b/contracts/Shielder.sol
index 6fb928e3..c88b5201 100644
--- a/contracts/Shielder.sol
+++ b/contracts/Shielder.sol
@@ -1,23 +1,24 @@
-// SPDX-License-Identifier: MIT
+// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.8.26;
import { DepositLimit } from "./DepositLimit.sol";
-import { Halo2Verifier as NewAccountVerifier } from "./NewAccountVerifier.sol";
import { Halo2Verifier as DepositVerifier } from "./DepositVerifier.sol";
+import { Halo2Verifier as NewAccountVerifier } from "./NewAccountVerifier.sol";
import { Halo2Verifier as WithdrawVerifier } from "./WithdrawVerifier.sol";
import { Initializable } from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import { MerkleTree } from "./MerkleTree.sol";
import { Nullifiers } from "./Nullifiers.sol";
-import { OwnableUpgradeable } from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
+import { Ownable2StepUpgradeable } from "@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol";
import { PausableUpgradeable } from "@openzeppelin/contracts-upgradeable/utils/PausableUpgradeable.sol";
import { UUPSUpgradeable } from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
/// @title Shielder
/// @author CardinalCryptography
+/// @custom:oz-upgrades-unsafe-allow external-library-linking
contract Shielder is
Initializable,
UUPSUpgradeable,
- OwnableUpgradeable,
+ Ownable2StepUpgradeable,
PausableUpgradeable,
MerkleTree,
Nullifiers,
@@ -45,6 +46,10 @@ contract Shielder is
/// so we control the sum of balances instead.
uint256 public constant MAX_CONTRACT_BALANCE = MAX_TRANSACTION_AMOUNT;
+ /// The modulus of the field used in the circuits.
+ uint256 private constant FIELD_MODULUS =
+ 21888242871839275222246405745257275088548364400416034343698204186575808495617;
+
// -- Events --
event NewAccountNative(
bytes3 contractVersion,
@@ -84,6 +89,7 @@ contract Shielder is
error AmountTooHigh();
error ContractBalanceLimitReached();
error WrongContractVersion(bytes3 actual, bytes3 expectedByCaller);
+ error NotAFieldElement();
modifier restrictContractVersion(bytes3 expectedByCaller) {
if (expectedByCaller != CONTRACT_VERSION) {
@@ -92,13 +98,11 @@ contract Shielder is
_;
}
+ /// @custom:oz-upgrades-unsafe-allow constructor
constructor() {
_disableInitializers();
}
- /// @dev disable possibility to renounce ownership
- function renounceOwnership() public virtual override onlyOwner {}
-
function initialize(
address initialOwner,
uint256 _depositLimit
@@ -113,6 +117,9 @@ contract Shielder is
/// @dev required by the OZ UUPS module
function _authorizeUpgrade(address) internal override onlyOwner {}
+ /// @dev disable possibility to renounce ownership
+ function renounceOwnership() public virtual override onlyOwner {}
+
function pause() external onlyOwner {
_pause();
}
@@ -137,6 +144,8 @@ contract Shielder is
whenNotPaused
withinDepositLimit
restrictContractVersion(expectedContractVersion)
+ fieldElement(newNote)
+ fieldElement(idHash)
{
uint256 amount = msg.value;
if (nullifiers(idHash) != 0) revert DuplicatedNullifier();
@@ -177,6 +186,9 @@ contract Shielder is
whenNotPaused
withinDepositLimit
restrictContractVersion(expectedContractVersion)
+ fieldElement(idHiding)
+ fieldElement(oldNullifierHash)
+ fieldElement(newNote)
{
uint256 amount = msg.value;
if (amount == 0) revert ZeroAmount();
@@ -202,13 +214,7 @@ contract Shielder is
uint256 index = _addNote(newNote);
_registerNullifier(oldNullifierHash);
- emit DepositNative(
- CONTRACT_VERSION,
- idHiding,
- msg.value,
- newNote,
- index
- );
+ emit DepositNative(CONTRACT_VERSION, idHiding, amount, newNote, index);
}
/*
@@ -225,7 +231,14 @@ contract Shielder is
bytes calldata proof,
address relayerAddress,
uint256 relayerFee
- ) external whenNotPaused restrictContractVersion(expectedContractVersion) {
+ )
+ external
+ whenNotPaused
+ restrictContractVersion(expectedContractVersion)
+ fieldElement(idHiding)
+ fieldElement(oldNullifierHash)
+ fieldElement(newNote)
+ {
if (amount == 0) revert ZeroAmount();
if (amount <= relayerFee) revert FeeHigherThanAmount();
if (amount > MAX_TRANSACTION_AMOUNT) revert AmountTooHigh();
@@ -287,6 +300,11 @@ contract Shielder is
return uint256(uint160(addr));
}
+ modifier fieldElement(uint256 x) {
+ require(x < FIELD_MODULUS, NotAFieldElement());
+ _;
+ }
+
// -- Setters ---
/*
diff --git a/contracts/ShielderV2Mock.sol b/contracts/ShielderV2Mock.sol
new file mode 100644
index 00000000..68cbfa30
--- /dev/null
+++ b/contracts/ShielderV2Mock.sol
@@ -0,0 +1,53 @@
+// SPDX-License-Identifier: Apache-2.0
+pragma solidity 0.8.26;
+
+import { Initializable } from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
+import { MerkleTree } from "./MerkleTree.sol";
+import { Nullifiers } from "./Nullifiers.sol";
+import { OwnableUpgradeable } from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
+import { PausableUpgradeable } from "@openzeppelin/contracts-upgradeable/utils/PausableUpgradeable.sol";
+import { UUPSUpgradeable } from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
+
+/**
+ * @title ShielderV2Mock
+ * @author CardinalCryptography
+ * @dev This is a mock version on ShielderV2 for testing purposes only.
+ * Most of the functionality has been removed for clarity.
+ *
+ * @custom:oz-upgrades-from Shielder
+ * @custom:oz-upgrades-unsafe-allow external-library-linking
+ */
+contract ShielderV2Mock is
+ Initializable,
+ UUPSUpgradeable,
+ OwnableUpgradeable,
+ PausableUpgradeable,
+ MerkleTree,
+ Nullifiers
+{
+ uint256 public mockStateVariable;
+
+ /// @custom:oz-upgrades-unsafe-allow constructor
+ constructor() {
+ _disableInitializers();
+ }
+
+ /// @dev required by the OZ UUPS module
+ function _authorizeUpgrade(address) internal override onlyOwner {}
+
+ function initialize(
+ address initialOwner,
+ uint256 _mockVariable
+ ) public initializer {
+ __Ownable_init(initialOwner);
+ __Pausable_init();
+ __MerkleTree_init();
+ _pause();
+
+ mockStateVariable = _mockVariable;
+ }
+
+ function reinitialize(uint256 _mockVariable) public reinitializer(2) {
+ mockStateVariable = _mockVariable;
+ }
+}
diff --git a/contracts/Token.sol b/contracts/Token.sol
deleted file mode 100644
index 17386621..00000000
--- a/contracts/Token.sol
+++ /dev/null
@@ -1,11 +0,0 @@
-// SPDX-License-Identifier: MIT
-
-pragma solidity 0.8.26;
-
-import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
-
-contract Token is ERC20 {
- constructor(uint256 initialSupply) ERC20("MyToken", "MTK") {
- _mint(msg.sender, initialSupply);
- }
-}
diff --git a/contracts/UIntSet.sol b/contracts/UIntSet.sol
index 87702ef5..fd3d0042 100644
--- a/contracts/UIntSet.sol
+++ b/contracts/UIntSet.sol
@@ -1,4 +1,4 @@
-// SPDX-License-Identifier: MIT
+// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.8.26;
library UIntSet {
diff --git a/crates/integration-tests/Cargo.toml b/crates/integration-tests/Cargo.toml
index b2c54072..27fc9bd8 100644
--- a/crates/integration-tests/Cargo.toml
+++ b/crates/integration-tests/Cargo.toml
@@ -8,6 +8,12 @@ license.workspace = true
categories.workspace = true
repository.workspace = true
+[lib]
+
+[[bin]]
+name = "gas-consumption"
+path = "src/bin/gas_consumption.rs"
+
[dependencies]
alloy-primitives = { workspace = true }
alloy-sol-types = { workspace = true, features = ["json"] }
@@ -18,4 +24,4 @@ hex = { workspace = true }
rand = { workspace = true, features = ["small_rng"] }
rstest = { workspace = true }
shielder-circuits = { workspace = true }
-shielder-rust-sdk = { workspace = true, features = ["account", "contract", "conversion", "parameter_generation", "powers_of_tau", "permit2"] }
+shielder-rust-sdk = { workspace = true, features = ["account", "contract", "conversion", "parameter_generation", "powers_of_tau"] }
diff --git a/crates/integration-tests/src/bin/gas_consumption.rs b/crates/integration-tests/src/bin/gas_consumption.rs
new file mode 100644
index 00000000..1519a306
--- /dev/null
+++ b/crates/integration-tests/src/bin/gas_consumption.rs
@@ -0,0 +1,117 @@
+use core::fmt;
+use std::{env, fs::File, io::Write};
+
+use alloy_primitives::U256;
+use integration_tests::{
+ calls::{
+ deposit_native::{
+ invoke_call as deposit_native_call, prepare_call as deposit_native_calldata,
+ },
+ new_account_native::{
+ invoke_call as new_account_native_call, prepare_call as new_account_native_calldata,
+ },
+ withdraw_native::{
+ invoke_call as withdraw_native_call, prepare_args,
+ prepare_call as withdraw_native_calldata,
+ },
+ },
+ deploy::{deployment, Deployment},
+ deposit_native_proving_params, new_account_native_proving_params,
+ withdraw_native_proving_params,
+};
+use shielder_rust_sdk::{
+ account::ShielderAccount,
+ contract::ShielderContract::{depositNativeCall, newAccountNativeCall, withdrawNativeCall},
+};
+
+#[derive(Debug)]
+enum Calldata {
+ NewAccount(newAccountNativeCall),
+ Deposit(depositNativeCall),
+ Withdraw(withdrawNativeCall),
+}
+
+impl fmt::Display for Calldata {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ match self {
+ Calldata::NewAccount(_) => write!(f, "NewAccountNative"),
+ Calldata::Deposit(_) => write!(f, "DepositNative"),
+ Calldata::Withdraw(_) => write!(f, "WithdrawNative"),
+ }
+ }
+}
+
+fn main() {
+ let args: Vec = env::args().collect();
+ let filename = &args[1];
+ let mut file = File::create(filename).unwrap();
+
+ let mut deployment = deployment(
+ &new_account_native_proving_params(),
+ &deposit_native_proving_params(),
+ &withdraw_native_proving_params(),
+ );
+
+ let mut shielder_account = ShielderAccount::new(U256::from(1));
+ let amount = U256::from(10);
+ let calldata = Calldata::NewAccount(new_account_native_calldata(
+ &mut deployment,
+ &mut shielder_account,
+ amount,
+ ));
+
+ let gas_used = measure_gas(&calldata, &mut deployment, &mut shielder_account);
+ let mut content: Vec = vec![];
+
+ content.extend(&mut format!("{}: {gas_used}\n", &calldata).as_bytes().iter());
+
+ let calldata = Calldata::Deposit(
+ deposit_native_calldata(&mut deployment, &mut shielder_account, amount).0,
+ );
+
+ let gas_used = measure_gas(&calldata, &mut deployment, &mut shielder_account);
+
+ content.extend(&mut format!("{}: {gas_used}\n", &calldata).as_bytes().iter());
+
+ let calldata = Calldata::Withdraw(
+ withdraw_native_calldata(
+ &mut deployment,
+ &mut shielder_account,
+ prepare_args(amount, U256::from(1)),
+ )
+ .0,
+ );
+
+ let gas_used = measure_gas(&calldata, &mut deployment, &mut shielder_account);
+
+ content.extend(&mut format!("{}: {gas_used}\n", &calldata).as_bytes().iter());
+
+ file.write_all(&content).unwrap();
+}
+
+fn measure_gas(
+ calldata: &Calldata,
+ deployment: &mut Deployment,
+ shielder_account: &mut ShielderAccount,
+) -> u64 {
+ match calldata {
+ Calldata::NewAccount(calldata) => {
+ new_account_native_call(deployment, shielder_account, U256::from(10), calldata)
+ .unwrap()
+ .1
+ .gas_used
+ }
+ Calldata::Deposit(calldata) => {
+ deposit_native_call(deployment, shielder_account, U256::from(10), calldata)
+ .unwrap()
+ .1
+ .gas_used
+ }
+ Calldata::Withdraw(calldata) => {
+ withdraw_native_call(deployment, shielder_account, calldata)
+ .unwrap()
+ .1
+ .gas_used
+ }
+ }
+}
diff --git a/crates/integration-tests/src/lib.rs b/crates/integration-tests/src/lib.rs
index 5096d00a..1fcc3ecd 100644
--- a/crates/integration-tests/src/lib.rs
+++ b/crates/integration-tests/src/lib.rs
@@ -1,24 +1,26 @@
-#![cfg(test)]
#![feature(assert_matches)]
-use std::{fs::File, io::Read};
+use std::{env, fs::File, io::Read};
use alloy_primitives::Address;
use evm_utils::{compilation::source_to_bytecode, EvmRunner};
-mod permit2;
mod poseidon2;
mod proving_utils;
mod shielder;
-mod token;
mod verifier;
-const CONTRACTS_DIR: &str = "../../contracts";
+pub use proving_utils::*;
+pub use shielder::*;
fn read_contract(contract_name: &str) -> String {
let mut contents = String::new();
- let mut file = File::open(format!("{CONTRACTS_DIR}/{contract_name}"))
- .expect("Cannot open contract source file");
+
+ let mut file = File::open(format!(
+ "{}/{contract_name}",
+ env::var("CONTRACTS_DIR").unwrap_or(String::from("../../contracts"))
+ ))
+ .expect("Cannot open contract source file");
file.read_to_string(&mut contents)
.expect("Cannot read contract source file");
contents
diff --git a/crates/integration-tests/src/permit2.rs b/crates/integration-tests/src/permit2.rs
deleted file mode 100644
index 3eedb04e..00000000
--- a/crates/integration-tests/src/permit2.rs
+++ /dev/null
@@ -1,26 +0,0 @@
-use alloy_sol_types::{sol, SolCall};
-use shielder_rust_sdk::permit2::{get_eip712_hash, sign_message, PermitTransferFrom};
-
-// @dev compile the SC suite with forge and:
-// cat artifacts/Permit2.sol/Permit2.json | jq .bytecode.object
-pub const PERMIT2_BYTECODE: &str = "60c0346100bb574660a052602081017f8cad95687ba82c2ce50e74f7b754645e5117c3a5bec8151c0726d5857980a86681527f9ac997416e8ff9d2ff6bebeb7149f65cdae5e32e2b90440b566bb3044041d36a60408301524660608301523060808301526080825260a082019180831060018060401b038411176100a55782604052519020608052611b5990816100c18239608051816114c4015260a0518161149e0152f35b634e487b7160e01b600052604160045260246000fd5b600080fdfe6040608081526004908136101561001557600080fd5b600090813560e01c80630d58b1db14610e9f578063137c29fe14610d1c5780632a2d80d114610abd5780632b67b5701461094757806330f28b7a146108845780633644e5151461086157806336c78516146108175780633ff9dcb1146107b55780634fe02b441461077657806365d9723c1461066657806387517c4514610584578063927da105146104f8578063cc53287f14610417578063edd9444b146102eb5763fe8ec1a7146100c657600080fd5b346102e75760c03660031901126102e7576001600160401b0383358181116102e3576100f59036908601611185565b6024358281116102df5761010c9036908701611155565b610114611069565b916084358581116102db5761012c9036908a016110fe565b98909560a4359081116102d757610145913691016110fe565b96909581519061015482610fcb565b606b82527f5065726d697442617463685769746e6573735472616e7366657246726f6d285460208301527f6f6b656e5065726d697373696f6e735b5d207065726d69747465642c61646472838301527f657373207370656e6465722c75696e74323536206e6f6e63652c75696e74323560608301526a0d88191958591b1a5b994b60aa1b608083015282519a8b91816101f16020850180966117e7565b918237018a8152039961020c601f199b8c8101835282611001565b5190209085515161021c81611763565b908a5b8181106102aa5750506102a7999a61029e918351610251816102456020820180956117ba565b03848101835282611001565b519020602089810151858b015195519182019687526040820192909252336060820152608081019190915260a081019390935260643560c08401528260e081015b03908101835282611001565b5190209361161a565b80f35b806102c26102bc6102d2938c5161127e565b51611899565b6102cc828661127e565b52611795565b61021f565b8880fd5b8780fd5b8480fd5b8380fd5b5080fd5b5091346102e75760803660031901126102e7576001600160401b039080358281116102e35761031d9036908301611185565b6024358381116102df576103349036908401611155565b93909261033f611069565b9160643590811161041357610356913691016110fe565b9490938351519761036689611763565b98885b8181106103f15750506102a7979881516103998161038b6020820180956117ba565b03601f198101835282611001565b5190206020860151828701519083519260208401947ffcf35f5ac6a2c28868dc44c302166470266239195f02b0ee408334829333b7668652840152336060840152608083015260a082015260a0815261029e81610fe6565b808b6102cc826104086102bc61040e968d5161127e565b9261127e565b610369565b8680fd5b5082346104f457602090816003193601126102e3578035906001600160401b0382116102df5761044991369101611155565b929091845b848110610459578580f35b8061046f61046a600193888861136c565b61137c565b6104848461047e848a8a61136c565b0161137c565b33895283855285892091848060a01b0380911692838b528652868a20911690818a5285528589206bffffffffffffffffffffffff60a01b81541690558551918252848201527f89b1add15eff56b3dfe299ad94e01f2b52fbcb80ae1a3baea6ae8c04cb2b98a4853392a20161044e565b8280fd5b50346102e75760603660031901126102e7576105808161051661103d565b9361051f611053565b610527611069565b6001600160a01b03968716835260016020908152848420928816845291825283832090871683528152919020549251938316845260a083901c65ffffffffffff169084015260d09190911c604083015281906060820190565b0390f35b50346102e75760803660031901126102e75761059e61103d565b906105a7611053565b916105b0611069565b906064359265ffffffffffff93848116908181036102db577fda9fa7c1b00402c17d0161b249b1ab8bbec047c5a52207b9c112deffd817036b9333895260016020528389209660018060a01b0380921697888b5260205281858b20991698898b52602052848a2092841560001461065e57504216905b82546001600160d01b03191660a09290921b65ffffffffffff60a01b169190911795169485179055815193845260208401523392a480f35b905090610626565b5082346104f45760603660031901126104f45761068161103d565b9061068a611053565b9265ffffffffffff60443581811693908481036102db57338852602091600183528489209660018060a01b0380911697888b528452858a20981697888a5283528489205460d01c93848711156107675761ffff90858403161161075957503380895260018352848920878a528352848920888a52835284892080546001600160d01b031660d09390931b6001600160d01b03191692909217909155835194855290840191909152917f55eb90d810e1700b35a8e7e25395ff7f2b2259abd7415ca2284dfb1c246418f39190a480f35b8451631269ad1360e11b8152fd5b508451633ab3447f60e11b8152fd5b50346102e757806003193601126102e75760209181906001600160a01b0361079c61103d565b1681528084528181206024358252845220549051908152f35b5082346104f457816003193601126104f4577f3704902f963766a4e561bbaab6e6cdc1b1dd12f6e9e99648da8843b3f46b918d90359160243533855284602052818520848652602052818520818154179055815193845260208401523392a280f35b823461085e57608036600319011261085e5761083161103d565b610839611053565b610841611069565b606435916001600160a01b03831683036102df576102a7936112a8565b80fd5b50346102e757816003193601126102e75760209061087d61149b565b9051908152f35b508290346104f4576101003660031901126104f4576108a236611093565b90806083193601126102e3576108b6611022565b9160e4356001600160401b038111610943576102a7946108d8913691016110fe565b9390926108e58351611899565b6020840151828501519083519260208401947f939c21a48a8dbe3a9a2404a1d46691e4d39f6583d6ec6b35714604c986d801068652840152336060840152608083015260a082015260a0815261093a81610fe6565b51902091611587565b8580fd5b5091346102e7576101003660031901126102e75761096361103d565b366023190160c081126102e357608085519161097e83610fb0565b126102e35784519061098f82610f7f565b6001600160a01b03916024358381168103610413578152604435838116810361041357602082015265ffffffffffff60643581811681036102db57888301526084359081168103610413576060820152815260a435938285168503610943576020820194855260c4359087830182815260e4356001600160401b0381116102d757610a1d90369084016110fe565b929093804211610aa7575050918591610a976102a7999a610a9d95610a428851611812565b90898c511690519083519260208401947ff3841cd1ff0085026a6327b620b67997ce40f282c88a8e905a7a5626e310f3d086528401526060830152608082015260808152610a8f81610fcb565b519020611556565b916118fe565b5192511691611390565b8a5163cd21db4f60e01b81529182015260249150fd5b5091346102e75760606003199381853601126102e357610adb61103d565b926024908135926001600160401b03978885116102db57859085360301126104135780519785890189811082821117610d0a578252848301358181116102d757850190366023830112156102d7578382013591610b378361112b565b90610b4485519283611001565b838252602093878584019160071b83010191368311610d06578801905b828210610ca9575050508a526044610b7a86880161107f565b96838c01978852013594838b0191868352604435908111610ca557610ba290369087016110fe565b959096804211610c93575050508998995151610bbd81611763565b908b5b818110610c7057505092889492610a9792610c3d97958351610be98161038b86820180956117ba565b5190209060018060a01b039a8b8b51169151928551948501957faf1b0d30d2cab0380e68f0689007e3254993c596f2fdd0aaa7f4d04f794408638752850152830152608082015260808152610a8f81610fcb565b51169082515192845b848110610c51578580f35b80610c6a8585610c64600195875161127e565b51611390565b01610c46565b806102c2610c858e9f9e93610c8b945161127e565b51611812565b9b9a9b610bc0565b855163cd21db4f60e01b815291820152fd5b8a80fd5b608082360312610d0657856080918851610cc281610f7f565b610ccb8561107f565b8152610cd883860161107f565b83820152610ce78a8601611142565b8a8201528d610cf7818701611142565b90820152815201910190610b61565b8c80fd5b634e487b7160e01b8952604184528489fd5b5082346104f4576101403660031901126104f457610d3936611093565b91806083193601126102e357610d4d611022565b6001600160401b0393906101043585811161041357610d6f90369086016110fe565b9093610124359687116102db57610d8f61093a966102a7983691016110fe565b969095825190610d9e82610fcb565b606482527f5065726d69745769746e6573735472616e7366657246726f6d28546f6b656e5060208301527f65726d697373696f6e73207065726d69747465642c6164647265737320737065848301527f6e6465722c75696e74323536206e6f6e63652c75696e7432353620646561646c6060830152631a5b994b60e21b6080830152835194859181610e346020850180966117e7565b918237018b81520393610e4f601f1995868101835282611001565b51902092610e5d8651611899565b6020878101518589015195519182019687526040820192909252336060820152608081019190915260a081019390935260e43560c08401528260e08101610292565b5082346104f4576020806003193601126102e35781356001600160401b03928382116109435736602383011215610943578101359283116102df576024906007368386831b8401011161041357865b858110610ef9578780f35b80821b830190608060231983360301126102d757610f79888760019460608351610f2281610f7f565b610f5e6084610f328d860161107f565b94858452610f426044820161107f565b8097850152610f536064820161107f565b80988501520161107f565b9182910152868060a01b0380808093169516931691166112a8565b01610eee565b608081019081106001600160401b03821117610f9a57604052565b634e487b7160e01b600052604160045260246000fd5b606081019081106001600160401b03821117610f9a57604052565b60a081019081106001600160401b03821117610f9a57604052565b60c081019081106001600160401b03821117610f9a57604052565b90601f801991011681019081106001600160401b03821117610f9a57604052565b60c435906001600160a01b038216820361103857565b600080fd5b600435906001600160a01b038216820361103857565b602435906001600160a01b038216820361103857565b604435906001600160a01b038216820361103857565b35906001600160a01b038216820361103857565b6003190190608082126110385760408051906110ae82610fb0565b808294126110385780518181018181106001600160401b03821117610f9a5782526004356001600160a01b0381168103611038578152602435602082015282526044356020830152606435910152565b9181601f84011215611038578235916001600160401b038311611038576020838186019501011161103857565b6001600160401b038111610f9a5760051b60200190565b359065ffffffffffff8216820361103857565b9181601f84011215611038578235916001600160401b038311611038576020808501948460061b01011161103857565b9190916060818403126110385760408051916111a083610fb0565b829481356001600160401b039081811161103857830182601f820112156110385780356111cc8161112b565b926111d987519485611001565b818452602094858086019360061b85010193818511611038579086899897969594939201925b84841061121c575050505050855280820135908501520135910152565b909192939495969784830312611038578851908982019082821085831117611269578a928992845261124d8761107f565b81528287013583820152815201930191908897969594936111ff565b60246000634e487b7160e01b81526041600452fd5b80518210156112925760209160051b010190565b634e487b7160e01b600052603260045260246000fd5b92919260018060a01b03604060008284168152600160205282828220961695868252602052818120338252602052209485549565ffffffffffff8760a01c1680421161135457508287169683880361130b575b505061130995501692611ad0565b565b87848416116000146113305760405163f96fb07160e01b815260048101899052602490fd5b8383611309990316906bffffffffffffffffffffffff60a01b1617905538806112fb565b60249060405190636c0d979760e11b82526004820152fd5b91908110156112925760061b0190565b356001600160a01b03811681036110385790565b9065ffffffffffff908160608401511660018060a01b03908185511694826020820151169280866040809401511695169560009187835260016020528383208984526020528383209916988983526020528282209184835460d01c0361148a57918561147e94927fc6a377bfc4eb120024a8ac08eef205be16b817020812c73223e81d1bdb9708ec989796945087156000146114835742165b6001850160d01b6001600160d01b03191660a09190911b65ffffffffffff60a01b1617179055516001600160a01b03909316835265ffffffffffff938416602084015290921660408201529081906060820190565b0390a4565b5086611429565b8351633ab3447f60e11b8152600490fd5b467f0000000000000000000000000000000000000000000000000000000000000000036114e6577f000000000000000000000000000000000000000000000000000000000000000090565b60405160208101907f8cad95687ba82c2ce50e74f7b754645e5117c3a5bec8151c0726d5857980a86682527f9ac997416e8ff9d2ff6bebeb7149f65cdae5e32e2b90440b566bb3044041d36a60408201524660608201523060808201526080815261155081610fcb565b51902090565b61155e61149b565b9060405190602082019261190160f01b8452602283015260428201526042815261155081610f7f565b9192909360a43593604084015180421161160257506020845101518086116115ea5750918591610a976115c7946115c2602088015186611715565b611556565b51516001600160a01b039081169260843591821682036110385761130993611ad0565b60249060405190633728b83d60e01b82526004820152fd5b6024906040519063cd21db4f60e01b82526004820152fd5b9590939580515195604092838301518042116116fe57508488036116ea57611651918691610a9760209b6115c28d88015186611715565b60005b868110611665575050505050505050565b61167081835161127e565b518861167d83878a61136c565b013590898101518083116116d35750918188888860019685966116a7575b50505050505001611654565b6116c8956116c29261046a928a8060a01b039051169561136c565b91611ad0565b80388888888361169b565b602490865190633728b83d60e01b82526004820152fd5b83516001621398b960e31b03198152600490fd5b60249085519063cd21db4f60e01b82526004820152fd5b90600160ff82161b9160018060a01b0316600052600060205260406000209060081c600052602052604060002081815418809155161561175157565b604051633ab3447f60e11b8152600490fd5b9061176d8261112b565b61177a6040519182611001565b828152809261178b601f199161112b565b0190602036910137565b60001981146117a45760010190565b634e487b7160e01b600052601160045260246000fd5b805160208092019160005b8281106117d3575050505090565b8351855293810193928101926001016117c5565b9081519160005b8381106117ff575050016000815290565b80602080928401015181850152016117ee565b60405160208101917f65626cad6cb96493bf6f5ebea28756c966f023ab9e8a83a7101849d5573b3678835260018060a01b038082511660408401526020820151166060830152606065ffffffffffff9182604082015116608085015201511660a082015260a0815260c081018181106001600160401b03821117610f9a5760405251902090565b6040516020808201927f618358ac3db8dc274f0cd8829da7e234bd48cd73c4a740aede1adec9846d06a1845260018060a01b038151166040840152015160608201526060815261155081610f7f565b9190826040910312611038576020823592013590565b6000843b6119f75750604182036119a75761191b828201826118e8565b939092604010156112925760209360009360ff6040608095013560f81c5b60405194855216868401526040830152606082015282805260015afa1561199b576000516001600160a01b0390811691821561198957160361197757565b604051632057875960e21b8152600490fd5b604051638baa579f60e01b8152600490fd5b6040513d6000823e3d90fd5b604082036119e5576119bb918101906118e8565b6001600160ff1b0381169260ff91821c601b019182116117a45760209360009360ff608094611939565b604051634be6321b60e01b8152600490fd5b918093946020926064604051809781958294630b135d3f60e11b9b8c8552600485015260406024850152816044850152848401378181018301889052601f01601f191681010301916001600160a01b03165afa918215611ac3578192611a7d575b50506001600160e01b03191603611a6b57565b604051632c19a72f60e21b8152600490fd5b9091506020813d8211611abb575b81611a9860209383611001565b810103126102e75751906001600160e01b03198216820361085e57503880611a58565b3d9150611a8b565b50604051903d90823e3d90fd5b9060006064926020958295604051946323b872dd60e01b86526004860152602485015260448401525af13d15601f3d1160016000511416171615611b1057565b60405162461bcd60e51b81526020600482015260146024820152731514905394d1915497d19493d357d1905253115160621b6044820152606490fdfea164736f6c6343000811000a";
-
-sol! {
- function DOMAIN_SEPARATOR() public view override returns (bytes32);
-}
-
-pub fn domain_separator_calldata() -> Vec {
- DOMAIN_SEPARATORCall {}.abi_encode()
-}
-
-pub fn sign_permit(
- permit: &PermitTransferFrom,
- eip712_domain_separator: &[u8; 32],
- private_key: &[u8; 32],
-) -> Vec {
- let message = get_eip712_hash(permit, eip712_domain_separator);
-
- let (r, s, v) = sign_message(&message, private_key);
-
- [r.to_vec(), s.to_vec(), vec![v]].concat()
-}
diff --git a/crates/integration-tests/src/poseidon2.rs b/crates/integration-tests/src/poseidon2.rs
index a4aee47a..c5f0c23a 100644
--- a/crates/integration-tests/src/poseidon2.rs
+++ b/crates/integration-tests/src/poseidon2.rs
@@ -1,43 +1,51 @@
-use alloy_primitives::U256;
-use alloy_sol_types::{sol, SolCall, SolValue};
-use evm_utils::{EvmRunner, SuccessResult};
-use halo2_proofs::halo2curves::bn256::Fr;
-use shielder_circuits::poseidon::off_circuit::hash;
-use shielder_rust_sdk::conversion::field_to_u256;
-
-use crate::deploy_contract;
-
-const POSEIDON2_CONTRACT_NAME: &str = "Poseidon2T8Assembly";
-const POSEIDON2_FILE_NAME: &str = "Poseidon2T8Assembly.sol";
+use alloy_sol_types::sol;
sol! {
function hash(uint[7] memory) public pure returns (uint);
}
-fn encode_calldata(values: &[Fr; 7]) -> Vec {
- let values = values
- .iter()
- .map(field_to_u256::)
- .collect::>();
- let values = values.try_into().unwrap();
- hashCall { _0: values }.abi_encode()
-}
-
-#[test]
-fn verify_off_chain_and_on_chain_poseidon_preimage() {
- let preimage = [1, 2, 3, 4, 5, 6, 7].map(Fr::from);
-
- let mut evm = EvmRunner::aleph_evm();
- let poseidon2_address = deploy_contract(POSEIDON2_FILE_NAME, POSEIDON2_CONTRACT_NAME, &mut evm);
-
- let calldata = encode_calldata(&preimage);
- let response = match evm.call(poseidon2_address, calldata, None, None) {
- Ok(SuccessResult { output, .. }) => output,
- Err(why) => panic!("Failed to call Poseidon2 contract: {why}"),
- };
-
- let image_on_chain = ::abi_decode(&response, true).unwrap();
- let image_off_chain = hash(&preimage);
-
- assert_eq!(image_on_chain, field_to_u256(image_off_chain));
+#[cfg(test)]
+mod tests {
+
+ use alloy_primitives::U256;
+ use alloy_sol_types::{SolCall, SolValue};
+ use evm_utils::{EvmRunner, SuccessResult};
+ use halo2_proofs::halo2curves::bn256::Fr;
+ use shielder_circuits::poseidon::off_circuit::hash;
+ use shielder_rust_sdk::conversion::field_to_u256;
+
+ use super::hashCall;
+ use crate::deploy_contract;
+
+ const POSEIDON2_CONTRACT_NAME: &str = "Poseidon2T8Assembly";
+ const POSEIDON2_FILE_NAME: &str = "Poseidon2T8Assembly.sol";
+
+ fn encode_calldata(values: &[Fr; 7]) -> Vec {
+ let values = values
+ .iter()
+ .map(field_to_u256::)
+ .collect::>();
+ let values = values.try_into().unwrap();
+ hashCall { _0: values }.abi_encode()
+ }
+
+ #[test]
+ fn verify_off_chain_and_on_chain_poseidon_preimage() {
+ let preimage = [1, 2, 3, 4, 5, 6, 7].map(Fr::from);
+
+ let mut evm = EvmRunner::aleph_evm();
+ let poseidon2_address =
+ deploy_contract(POSEIDON2_FILE_NAME, POSEIDON2_CONTRACT_NAME, &mut evm);
+
+ let calldata = encode_calldata(&preimage);
+ let response = match evm.call(poseidon2_address, calldata, None, None) {
+ Ok(SuccessResult { output, .. }) => output,
+ Err(why) => panic!("Failed to call Poseidon2 contract: {why}"),
+ };
+
+ let image_on_chain = ::abi_decode(&response, true).unwrap();
+ let image_off_chain = hash(&preimage);
+
+ assert_eq!(image_on_chain, field_to_u256(image_off_chain));
+ }
}
diff --git a/crates/integration-tests/src/shielder/address_conversion.rs b/crates/integration-tests/src/shielder/address_conversion.rs
index 78094345..fc45709a 100644
--- a/crates/integration-tests/src/shielder/address_conversion.rs
+++ b/crates/integration-tests/src/shielder/address_conversion.rs
@@ -1,32 +1,41 @@
-use alloy_primitives::{address, U256};
-use alloy_sol_types::{sol, SolCall, SolValue};
-use halo2_proofs::halo2curves::bn256::Fr;
-use rstest::rstest;
-use shielder_rust_sdk::conversion::{address_to_field, field_to_u256};
-
-use crate::shielder::deploy::{deployment, Deployment};
+use alloy_sol_types::sol;
sol! {
function addressToUInt256(address addr) public pure returns (uint256);
}
-#[rstest]
-fn verify_off_chain_and_on_chain_address_to_u256_conversion(mut deployment: Deployment) {
- let some_address = address!("f39Fd6e51aad88F6F4ce6aB8827279cffFb92266");
-
- let on_chain_result = deployment
- .evm
- .call(
- deployment.contract_suite.shielder,
- addressToUInt256Call { addr: some_address }.abi_encode(),
- None,
- None,
- )
- .expect("Failed to convert address to field on-chain");
- let on_chain = ::abi_decode(&on_chain_result.output, true)
- .expect("Failed to decode on-chain result");
-
- let off_chain = field_to_u256(address_to_field::(some_address));
-
- assert_eq!(on_chain, off_chain);
+#[cfg(test)]
+mod tests {
+
+ use alloy_primitives::{address, U256};
+ use alloy_sol_types::{SolCall, SolValue};
+ use halo2_proofs::halo2curves::bn256::Fr;
+ use rstest::rstest;
+ use shielder_rust_sdk::conversion::{address_to_field, field_to_u256};
+
+ use crate::{
+ address_conversion::addressToUInt256Call,
+ shielder::deploy::{deployment, Deployment},
+ };
+
+ #[rstest]
+ fn verify_off_chain_and_on_chain_address_to_u256_conversion(mut deployment: Deployment) {
+ let some_address = address!("f39Fd6e51aad88F6F4ce6aB8827279cffFb92266");
+
+ let on_chain_result = deployment
+ .evm
+ .call(
+ deployment.contract_suite.shielder,
+ addressToUInt256Call { addr: some_address }.abi_encode(),
+ None,
+ None,
+ )
+ .expect("Failed to convert address to field on-chain");
+ let on_chain = ::abi_decode(&on_chain_result.output, true)
+ .expect("Failed to decode on-chain result");
+
+ let off_chain = field_to_u256(address_to_field::(some_address));
+
+ assert_eq!(on_chain, off_chain);
+ }
}
diff --git a/crates/integration-tests/src/shielder/calls/deposit_native.rs b/crates/integration-tests/src/shielder/calls/deposit_native.rs
index 4c3bfe45..f38954fc 100644
--- a/crates/integration-tests/src/shielder/calls/deposit_native.rs
+++ b/crates/integration-tests/src/shielder/calls/deposit_native.rs
@@ -1,31 +1,16 @@
-use std::assert_matches::assert_matches;
-
-use alloy_primitives::{Bytes, FixedBytes, TxHash, U256};
-use evm_utils::SuccessResult;
-use rstest::rstest;
+use alloy_primitives::{TxHash, U256};
use shielder_rust_sdk::{
account::{
call_data::{DepositCallType, MerkleProof},
ShielderAccount,
},
- contract::ShielderContract::{
- depositNativeCall, DepositNative, ShielderContractErrors, ShielderContractEvents,
- WrongContractVersion,
- },
+ contract::ShielderContract::depositNativeCall,
};
use crate::shielder::{
- actor_balance_decreased_by,
- calls::new_account_native,
- deploy::{deployment, Deployment},
- invoke_shielder_call,
- limits::{get_deposit_limit, set_deposit_limit},
- merkle::get_merkle_args,
- CallResult,
+ deploy::Deployment, invoke_shielder_call, merkle::get_merkle_args, CallResult,
};
-const GAS_CONSUMPTION: u64 = 1827769;
-
pub fn prepare_call(
deployment: &mut Deployment,
shielder_account: &mut ShielderAccount,
@@ -44,7 +29,7 @@ pub fn prepare_call(
let calldata = shielder_account.prepare_call::(
¶ms,
&pk,
- U256::from(amount),
+ amount,
&MerkleProof {
root: merkle_root,
path: merkle_path,
@@ -72,249 +57,341 @@ pub fn invoke_call(
}
}
-#[rstest]
-fn gas_consumption_regression(mut deployment: Deployment) {
- let mut shielder_account =
- new_account_native::create_account_and_call(&mut deployment, U256::from(1), U256::from(10))
- .unwrap();
-
- let amount = U256::from(5);
- let (calldata, _) = prepare_call(&mut deployment, &mut shielder_account, amount);
- let (_, SuccessResult { gas_used, .. }) =
- invoke_call(&mut deployment, &mut shielder_account, amount, &calldata).unwrap();
-
- assert!(
- gas_used < 110 * GAS_CONSUMPTION / 100,
- "deposit transaction consumes {gas_used}, which is 10% beyond baseline of {GAS_CONSUMPTION}"
- );
-}
-
-#[rstest]
-fn succeeds(mut deployment: Deployment) {
- let mut shielder_account =
- new_account_native::create_account_and_call(&mut deployment, U256::from(1), U256::from(10))
- .unwrap();
-
- let amount = U256::from(5);
- let (calldata, note_index) = prepare_call(&mut deployment, &mut shielder_account, amount);
- let events = invoke_call(&mut deployment, &mut shielder_account, amount, &calldata)
- .unwrap()
- .0;
-
- assert_eq!(
- events,
- vec![ShielderContractEvents::DepositNative(DepositNative {
- contractVersion: FixedBytes([0, 0, 1]),
- idHiding: calldata.idHiding,
- amount: U256::from(amount),
- newNote: calldata.newNote,
- newNoteIndex: note_index.saturating_add(U256::from(1)),
- })]
- );
- assert!(actor_balance_decreased_by(&deployment, U256::from(15)));
- assert_eq!(shielder_account.shielded_amount, U256::from(15))
-}
-#[rstest]
-fn fails_if_incorrect_expected_version(mut deployment: Deployment) {
- let mut shielder_account =
- new_account_native::create_account_and_call(&mut deployment, U256::from(1), U256::from(10))
- .unwrap();
- let (mut calldata, _) = prepare_call(&mut deployment, &mut shielder_account, U256::ZERO);
- calldata.expectedContractVersion = FixedBytes([9, 8, 7]);
- let result = invoke_call(
- &mut deployment,
- &mut shielder_account,
- U256::from(5),
- &calldata,
- );
-
- assert_matches!(
- result,
- Err(ShielderContractErrors::WrongContractVersion(
- WrongContractVersion {
- actual: FixedBytes([0, 0, 1]),
- expectedByCaller: FixedBytes([9, 8, 7])
- }
- ))
- );
- assert!(actor_balance_decreased_by(&deployment, U256::from(10)))
-}
+#[cfg(test)]
+mod tests {
+
+ use std::{assert_matches::assert_matches, mem, str::FromStr};
+
+ use alloy_primitives::{Bytes, FixedBytes, U256};
+ use evm_utils::SuccessResult;
+ use halo2_proofs::halo2curves::ff::PrimeField;
+ use rstest::rstest;
+ use shielder_circuits::F;
+ use shielder_rust_sdk::{
+ account::ShielderAccount,
+ contract::ShielderContract::{
+ depositNativeCall, DepositNative, ShielderContractErrors, ShielderContractEvents,
+ WrongContractVersion,
+ },
+ };
-#[rstest]
-fn can_consume_entire_contract_balance_limit(mut deployment: Deployment) {
- let mut shielder_account = new_account_native::create_account_and_call(
- &mut deployment,
- U256::from(1),
- U256::from((1u128 << 112) - 2),
- )
- .unwrap();
-
- let amount = U256::from(1);
- let (calldata, _) = prepare_call(&mut deployment, &mut shielder_account, amount);
- let result = invoke_call(&mut deployment, &mut shielder_account, amount, &calldata);
-
- assert!(result.is_ok());
- assert!(actor_balance_decreased_by(
- &deployment,
- U256::from((1u128 << 112) - 1)
- ))
-}
+ use crate::{
+ calls::deposit_native::{invoke_call, prepare_call},
+ recipient_balance_increased_by, relayer_balance_increased_by,
+ shielder::{
+ actor_balance_decreased_by,
+ calls::new_account_native,
+ deploy::{deployment, Deployment},
+ limits::{get_deposit_limit, set_deposit_limit},
+ },
+ };
-#[rstest]
-fn fails_if_contract_balance_limit_reached(mut deployment: Deployment) {
- let mut shielder_account = new_account_native::create_account_and_call(
- &mut deployment,
- U256::from(1),
- U256::from((1u128 << 112) - 1),
- )
- .unwrap();
-
- let amount = U256::from(1);
- let (calldata, _) = prepare_call(&mut deployment, &mut shielder_account, amount);
- let result = invoke_call(&mut deployment, &mut shielder_account, amount, &calldata);
-
- assert_matches!(
- result,
- Err(ShielderContractErrors::ContractBalanceLimitReached(_))
- );
- assert!(actor_balance_decreased_by(
- &deployment,
- U256::from((1u128 << 112) - 1)
- ))
-}
+ const GAS_CONSUMPTION: u64 = 1827769;
-#[rstest]
-fn correctly_handles_max_u256_value(mut deployment: Deployment) {
- let initial_amount = U256::from(10);
- let mut shielder_account =
- new_account_native::create_account_and_call(&mut deployment, U256::from(1), initial_amount)
- .unwrap();
+ #[rstest]
+ fn gas_consumption_regression(mut deployment: Deployment) {
+ let mut shielder_account = new_account_native::create_account_and_call(
+ &mut deployment,
+ U256::from(1),
+ U256::from(10),
+ )
+ .unwrap();
- let amount = U256::MAX - initial_amount;
- let (calldata, _) = prepare_call(&mut deployment, &mut shielder_account, amount);
- let result = invoke_call(&mut deployment, &mut shielder_account, amount, &calldata);
+ let amount = U256::from(5);
+ let (calldata, _) = prepare_call(&mut deployment, &mut shielder_account, amount);
+ let (_, SuccessResult { gas_used, .. }) =
+ invoke_call(&mut deployment, &mut shielder_account, amount, &calldata).unwrap();
- assert_matches!(
- result,
- Err(ShielderContractErrors::ContractBalanceLimitReached(_))
+ assert!(
+ gas_used < 110 * GAS_CONSUMPTION / 100,
+ "deposit transaction consumes {gas_used}, which is 10% beyond baseline of {GAS_CONSUMPTION}"
);
- assert!(actor_balance_decreased_by(&deployment, U256::from(10)))
-}
-
-#[rstest]
-fn cannot_use_same_note_twice(mut deployment: Deployment) {
- let mut shielder_account =
- new_account_native::create_account_and_call(&mut deployment, U256::from(1), U256::from(10))
- .unwrap();
-
- let amount = U256::from(5);
- let (calldata, _) = prepare_call(&mut deployment, &mut shielder_account, amount);
- let result_1 = invoke_call(&mut deployment, &mut shielder_account, amount, &calldata);
- assert!(result_1.is_ok());
-
- let result_2 = invoke_call(&mut deployment, &mut shielder_account, amount, &calldata);
+ }
- assert_matches!(
- result_2,
- Err(ShielderContractErrors::DuplicatedNullifier(_))
- );
- assert!(actor_balance_decreased_by(&deployment, U256::from(15)))
-}
+ #[rstest]
+ fn succeeds(mut deployment: Deployment) {
+ let mut shielder_account = new_account_native::create_account_and_call(
+ &mut deployment,
+ U256::from(1),
+ U256::from(10),
+ )
+ .unwrap();
+
+ let amount = U256::from(5);
+ let (calldata, note_index) = prepare_call(&mut deployment, &mut shielder_account, amount);
+ let events = invoke_call(&mut deployment, &mut shielder_account, amount, &calldata)
+ .unwrap()
+ .0;
+
+ assert_eq!(
+ events,
+ vec![ShielderContractEvents::DepositNative(DepositNative {
+ contractVersion: FixedBytes([0, 0, 1]),
+ idHiding: calldata.idHiding,
+ amount: U256::from(amount),
+ newNote: calldata.newNote,
+ newNoteIndex: note_index.saturating_add(U256::from(1)),
+ })]
+ );
+ assert!(actor_balance_decreased_by(&deployment, U256::from(15)));
+ assert_eq!(shielder_account.shielded_amount, U256::from(15))
+ }
+ #[rstest]
+ fn fails_if_incorrect_expected_version(mut deployment: Deployment) {
+ let mut shielder_account = new_account_native::create_account_and_call(
+ &mut deployment,
+ U256::from(1),
+ U256::from(10),
+ )
+ .unwrap();
+ let (mut calldata, _) = prepare_call(&mut deployment, &mut shielder_account, U256::ZERO);
+ calldata.expectedContractVersion = FixedBytes([9, 8, 7]);
+ let result = invoke_call(
+ &mut deployment,
+ &mut shielder_account,
+ U256::from(5),
+ &calldata,
+ );
+
+ assert_matches!(
+ result,
+ Err(ShielderContractErrors::WrongContractVersion(
+ WrongContractVersion {
+ actual: FixedBytes([0, 0, 1]),
+ expectedByCaller: FixedBytes([9, 8, 7])
+ }
+ ))
+ );
+ assert!(actor_balance_decreased_by(&deployment, U256::from(10)))
+ }
-#[rstest]
-fn fails_if_merkle_root_does_not_exist(mut deployment: Deployment) {
- let mut shielder_account = ShielderAccount::default();
-
- let calldata = depositNativeCall {
- expectedContractVersion: FixedBytes([0, 0, 1]),
- idHiding: U256::ZERO,
- oldNullifierHash: U256::ZERO,
- newNote: U256::ZERO,
- merkleRoot: U256::ZERO,
- proof: Bytes::from(vec![]),
- };
- let result = invoke_call(
- &mut deployment,
- &mut shielder_account,
- U256::from(10),
- &calldata,
- );
+ #[rstest]
+ fn can_consume_entire_contract_balance_limit(mut deployment: Deployment) {
+ let mut shielder_account = new_account_native::create_account_and_call(
+ &mut deployment,
+ U256::from(1),
+ U256::from((1u128 << 112) - 2),
+ )
+ .unwrap();
+
+ let amount = U256::from(1);
+ let (calldata, _) = prepare_call(&mut deployment, &mut shielder_account, amount);
+ let result = invoke_call(&mut deployment, &mut shielder_account, amount, &calldata);
+
+ assert!(result.is_ok());
+ assert!(actor_balance_decreased_by(
+ &deployment,
+ U256::from((1u128 << 112) - 1)
+ ))
+ }
- assert_matches!(
- result,
- Err(ShielderContractErrors::MerkleRootDoesNotExist(_))
- );
- assert!(actor_balance_decreased_by(&deployment, U256::ZERO))
-}
+ #[rstest]
+ fn fails_if_contract_balance_limit_reached(mut deployment: Deployment) {
+ let mut shielder_account = new_account_native::create_account_and_call(
+ &mut deployment,
+ U256::from(1),
+ U256::from((1u128 << 112) - 1),
+ )
+ .unwrap();
+
+ let amount = U256::from(1);
+ let (calldata, _) = prepare_call(&mut deployment, &mut shielder_account, amount);
+ let result = invoke_call(&mut deployment, &mut shielder_account, amount, &calldata);
+
+ assert_matches!(
+ result,
+ Err(ShielderContractErrors::ContractBalanceLimitReached(_))
+ );
+ assert!(actor_balance_decreased_by(
+ &deployment,
+ U256::from((1u128 << 112) - 1)
+ ))
+ }
-#[rstest]
-fn fails_if_proof_incorrect(mut deployment: Deployment) {
- let mut shielder_account =
- new_account_native::create_account_and_call(&mut deployment, U256::from(1), U256::from(10))
- .unwrap();
+ #[rstest]
+ fn correctly_handles_max_u256_value(mut deployment: Deployment) {
+ let initial_amount = U256::from(10);
+ let mut shielder_account = new_account_native::create_account_and_call(
+ &mut deployment,
+ U256::from(1),
+ initial_amount,
+ )
+ .unwrap();
+
+ let amount = U256::MAX - initial_amount;
+ let (calldata, _) = prepare_call(&mut deployment, &mut shielder_account, amount);
+ let result = invoke_call(&mut deployment, &mut shielder_account, amount, &calldata);
+
+ assert_matches!(
+ result,
+ Err(ShielderContractErrors::ContractBalanceLimitReached(_))
+ );
+ assert!(actor_balance_decreased_by(&deployment, U256::from(10)))
+ }
- let amount = U256::from(5);
- let (mut calldata, _) = prepare_call(&mut deployment, &mut shielder_account, amount);
- calldata.proof = Bytes::from(vec![]);
- let result = invoke_call(&mut deployment, &mut shielder_account, amount, &calldata);
+ #[rstest]
+ fn cannot_use_same_note_twice(mut deployment: Deployment) {
+ let mut shielder_account = new_account_native::create_account_and_call(
+ &mut deployment,
+ U256::from(1),
+ U256::from(10),
+ )
+ .unwrap();
+
+ let amount = U256::from(5);
+ let (calldata, _) = prepare_call(&mut deployment, &mut shielder_account, amount);
+ let result_1 = invoke_call(&mut deployment, &mut shielder_account, amount, &calldata);
+ assert!(result_1.is_ok());
+
+ let result_2 = invoke_call(&mut deployment, &mut shielder_account, amount, &calldata);
+
+ assert_matches!(
+ result_2,
+ Err(ShielderContractErrors::DuplicatedNullifier(_))
+ );
+ assert!(actor_balance_decreased_by(&deployment, U256::from(15)))
+ }
- assert_matches!(
- result,
- Err(ShielderContractErrors::DepositVerificationFailed(_))
- );
- assert!(actor_balance_decreased_by(&deployment, U256::from(10)))
-}
+ #[rstest]
+ fn cannot_use_input_greater_than_field_modulus(mut deployment: Deployment) {
+ let mut shielder_account = new_account_native::create_account_and_call(
+ &mut deployment,
+ U256::from(1),
+ U256::from(10),
+ )
+ .unwrap();
+
+ let amount = U256::from(5);
+ let (mut calldata, _) = prepare_call(&mut deployment, &mut shielder_account, amount);
+ let mut swap_value = U256::from_str(F::MODULUS).unwrap();
+
+ mem::swap(&mut calldata.oldNullifierHash, &mut swap_value);
+ let result = invoke_call(&mut deployment, &mut shielder_account, amount, &calldata);
+ assert_matches!(result, Err(ShielderContractErrors::NotAFieldElement(_)));
+ mem::swap(&mut calldata.oldNullifierHash, &mut swap_value);
+
+ mem::swap(&mut calldata.newNote, &mut swap_value);
+ let result = invoke_call(&mut deployment, &mut shielder_account, amount, &calldata);
+ assert_matches!(result, Err(ShielderContractErrors::NotAFieldElement(_)));
+ mem::swap(&mut calldata.newNote, &mut swap_value);
+
+ mem::swap(&mut calldata.idHiding, &mut swap_value);
+ let result = invoke_call(&mut deployment, &mut shielder_account, amount, &calldata);
+ assert_matches!(result, Err(ShielderContractErrors::NotAFieldElement(_)));
+ mem::swap(&mut calldata.idHiding, &mut swap_value);
+
+ assert!(actor_balance_decreased_by(&deployment, U256::from(10)));
+ assert!(recipient_balance_increased_by(&deployment, U256::from(0)));
+ assert!(relayer_balance_increased_by(&deployment, U256::from(0)))
+ }
-#[rstest]
-fn rejects_value_zero(mut deployment: Deployment) {
- let initial_amount = U256::from(10);
- let mut shielder_account =
- new_account_native::create_account_and_call(&mut deployment, U256::from(1), initial_amount)
- .unwrap();
+ #[rstest]
+ fn fails_if_merkle_root_does_not_exist(mut deployment: Deployment) {
+ let mut shielder_account = ShielderAccount::default();
+
+ let calldata = depositNativeCall {
+ expectedContractVersion: FixedBytes([0, 0, 1]),
+ idHiding: U256::ZERO,
+ oldNullifierHash: U256::ZERO,
+ newNote: U256::ZERO,
+ merkleRoot: U256::ZERO,
+ proof: Bytes::from(vec![]),
+ };
+ let result = invoke_call(
+ &mut deployment,
+ &mut shielder_account,
+ U256::from(10),
+ &calldata,
+ );
+
+ assert_matches!(
+ result,
+ Err(ShielderContractErrors::MerkleRootDoesNotExist(_))
+ );
+ assert!(actor_balance_decreased_by(&deployment, U256::ZERO))
+ }
- let amount = U256::ZERO;
- let (calldata, _) = prepare_call(&mut deployment, &mut shielder_account, amount);
- let result = invoke_call(&mut deployment, &mut shielder_account, amount, &calldata);
+ #[rstest]
+ fn fails_if_proof_incorrect(mut deployment: Deployment) {
+ let mut shielder_account = new_account_native::create_account_and_call(
+ &mut deployment,
+ U256::from(1),
+ U256::from(10),
+ )
+ .unwrap();
+
+ let amount = U256::from(5);
+ let (mut calldata, _) = prepare_call(&mut deployment, &mut shielder_account, amount);
+ calldata.proof = Bytes::from(vec![]);
+ let result = invoke_call(&mut deployment, &mut shielder_account, amount, &calldata);
+
+ assert_matches!(
+ result,
+ Err(ShielderContractErrors::DepositVerificationFailed(_))
+ );
+ assert!(actor_balance_decreased_by(&deployment, U256::from(10)))
+ }
- assert_matches!(result, Err(ShielderContractErrors::ZeroAmount(_)));
- assert!(actor_balance_decreased_by(&deployment, U256::from(10)))
-}
+ #[rstest]
+ fn rejects_value_zero(mut deployment: Deployment) {
+ let initial_amount = U256::from(10);
+ let mut shielder_account = new_account_native::create_account_and_call(
+ &mut deployment,
+ U256::from(1),
+ initial_amount,
+ )
+ .unwrap();
+
+ let amount = U256::ZERO;
+ let (calldata, _) = prepare_call(&mut deployment, &mut shielder_account, amount);
+ let result = invoke_call(&mut deployment, &mut shielder_account, amount, &calldata);
+
+ assert_matches!(result, Err(ShielderContractErrors::ZeroAmount(_)));
+ assert!(actor_balance_decreased_by(&deployment, U256::from(10)))
+ }
-#[rstest]
-fn fails_if_over_deposit_limit(mut deployment: Deployment) {
- let initial_amount = U256::from(101);
- let mut shielder_account =
- new_account_native::create_account_and_call(&mut deployment, U256::from(1), initial_amount)
- .unwrap();
+ #[rstest]
+ fn fails_if_over_deposit_limit(mut deployment: Deployment) {
+ let initial_amount = U256::from(101);
+ let mut shielder_account = new_account_native::create_account_and_call(
+ &mut deployment,
+ U256::from(1),
+ initial_amount,
+ )
+ .unwrap();
- let amount = U256::from(1);
- let (calldata, _) = prepare_call(&mut deployment, &mut shielder_account, amount);
- let result = invoke_call(&mut deployment, &mut shielder_account, amount, &calldata);
+ let amount = U256::from(1);
+ let (calldata, _) = prepare_call(&mut deployment, &mut shielder_account, amount);
+ let result = invoke_call(&mut deployment, &mut shielder_account, amount, &calldata);
- assert!(result.is_ok());
+ assert!(result.is_ok());
- let old_limit = get_deposit_limit(&mut deployment);
+ let old_limit = get_deposit_limit(&mut deployment);
- assert_eq!(old_limit, U256::MAX);
+ assert_eq!(old_limit, U256::MAX);
- let new_limit = U256::from(100);
- set_deposit_limit(&mut deployment, new_limit);
+ let new_limit = U256::from(100);
+ set_deposit_limit(&mut deployment, new_limit);
- let returned_new_limit = get_deposit_limit(&mut deployment);
+ let returned_new_limit = get_deposit_limit(&mut deployment);
- assert_eq!(returned_new_limit, U256::from(100));
+ assert_eq!(returned_new_limit, U256::from(100));
- let initial_amount = U256::from(10);
- let mut shielder_account =
- new_account_native::create_account_and_call(&mut deployment, U256::from(2), initial_amount)
- .unwrap();
+ let initial_amount = U256::from(10);
+ let mut shielder_account = new_account_native::create_account_and_call(
+ &mut deployment,
+ U256::from(2),
+ initial_amount,
+ )
+ .unwrap();
- let amount = U256::from(101);
- let (calldata, _) = prepare_call(&mut deployment, &mut shielder_account, amount);
- let result = invoke_call(&mut deployment, &mut shielder_account, amount, &calldata);
+ let amount = U256::from(101);
+ let (calldata, _) = prepare_call(&mut deployment, &mut shielder_account, amount);
+ let result = invoke_call(&mut deployment, &mut shielder_account, amount, &calldata);
- assert_matches!(
- result,
- Err(ShielderContractErrors::AmountOverDepositLimit(_))
- )
+ assert_matches!(
+ result,
+ Err(ShielderContractErrors::AmountOverDepositLimit(_))
+ )
+ }
}
diff --git a/crates/integration-tests/src/shielder/calls/domain_separator.rs b/crates/integration-tests/src/shielder/calls/domain_separator.rs
deleted file mode 100644
index 3ef0b40c..00000000
--- a/crates/integration-tests/src/shielder/calls/domain_separator.rs
+++ /dev/null
@@ -1,27 +0,0 @@
-use alloy_primitives::U256;
-use rstest::rstest;
-use shielder_rust_sdk::permit2::get_domain_separator;
-
-use crate::{
- permit2,
- shielder::deploy::{deployment, Deployment},
-};
-
-#[rstest]
-fn domain_separator(mut deployment: Deployment) {
- let expected = deployment
- .evm
- .call(
- deployment.contract_suite.permit2,
- permit2::domain_separator_calldata(),
- None,
- None,
- )
- .expect("Permit2 DOMAIN_SEPARATOR call failed")
- .output;
-
- assert_eq!(
- get_domain_separator(U256::from(1), deployment.contract_suite.permit2).to_vec(),
- expected
- );
-}
diff --git a/crates/integration-tests/src/shielder/calls/mod.rs b/crates/integration-tests/src/shielder/calls/mod.rs
index 7cedc55c..407d2934 100644
--- a/crates/integration-tests/src/shielder/calls/mod.rs
+++ b/crates/integration-tests/src/shielder/calls/mod.rs
@@ -1,4 +1,3 @@
pub mod deposit_native;
-pub mod domain_separator;
pub mod new_account_native;
pub mod withdraw_native;
diff --git a/crates/integration-tests/src/shielder/calls/new_account_native.rs b/crates/integration-tests/src/shielder/calls/new_account_native.rs
index 1c1b050d..55e85b69 100644
--- a/crates/integration-tests/src/shielder/calls/new_account_native.rs
+++ b/crates/integration-tests/src/shielder/calls/new_account_native.rs
@@ -1,23 +1,10 @@
-use std::assert_matches::assert_matches;
-
-use alloy_primitives::{FixedBytes, TxHash, U256};
-use evm_utils::SuccessResult;
-use rstest::rstest;
+use alloy_primitives::{TxHash, U256};
use shielder_rust_sdk::{
account::{call_data::NewAccountCallType, ShielderAccount},
- contract::ShielderContract::{
- newAccountNativeCall, NewAccountNative, ShielderContractErrors, ShielderContractEvents,
- WrongContractVersion,
- },
-};
-
-use crate::shielder::{
- actor_balance_decreased_by, deployment, invoke_shielder_call,
- limits::{get_deposit_limit, set_deposit_limit},
- CallResult, Deployment,
+ contract::ShielderContract::{newAccountNativeCall, ShielderContractErrors},
};
-const GAS_CONSUMPTION: u64 = 2000279;
+use crate::shielder::{invoke_shielder_call, CallResult, Deployment};
pub fn prepare_call(
deployment: &mut Deployment,
@@ -63,162 +50,226 @@ pub fn create_account_and_call(
}
}
-#[rstest]
-fn gas_consumption_regression(mut deployment: Deployment) {
- let mut shielder_account = ShielderAccount::default();
- let amount = U256::from(10);
- let calldata = prepare_call(&mut deployment, &mut shielder_account, amount);
-
- let (_, SuccessResult { gas_used, .. }) =
- invoke_call(&mut deployment, &mut shielder_account, amount, &calldata).unwrap();
-
- assert!(
+#[cfg(test)]
+mod tests {
+
+ use std::{assert_matches::assert_matches, mem, str::FromStr};
+
+ use alloy_primitives::{FixedBytes, U256};
+ use evm_utils::SuccessResult;
+ use halo2_proofs::halo2curves::ff::PrimeField;
+ use rstest::rstest;
+ use shielder_circuits::F;
+ use shielder_rust_sdk::{
+ account::ShielderAccount,
+ contract::ShielderContract::{
+ NewAccountNative, ShielderContractErrors, ShielderContractEvents, WrongContractVersion,
+ },
+ };
+
+ use crate::{
+ calls::new_account_native::{create_account_and_call, invoke_call, prepare_call},
+ deploy::deployment,
+ recipient_balance_increased_by, relayer_balance_increased_by,
+ shielder::{
+ actor_balance_decreased_by,
+ limits::{get_deposit_limit, set_deposit_limit},
+ Deployment,
+ },
+ };
+
+ const GAS_CONSUMPTION: u64 = 2000279;
+
+ #[rstest]
+ fn gas_consumption_regression(mut deployment: Deployment) {
+ let mut shielder_account = ShielderAccount::default();
+ let amount = U256::from(10);
+ let calldata = prepare_call(&mut deployment, &mut shielder_account, amount);
+
+ let (_, SuccessResult { gas_used, .. }) =
+ invoke_call(&mut deployment, &mut shielder_account, amount, &calldata).unwrap();
+
+ assert!(
gas_used < 110 * GAS_CONSUMPTION / 100,
"new account native transaction consumes {gas_used}, which is 10% beyond baseline of {GAS_CONSUMPTION}"
);
-}
+ }
-#[rstest]
-fn succeeds(mut deployment: Deployment) {
- let mut shielder_account = ShielderAccount::default();
- let amount = U256::from(10);
- let calldata = prepare_call(&mut deployment, &mut shielder_account, amount);
-
- let events = invoke_call(&mut deployment, &mut shielder_account, amount, &calldata)
- .unwrap()
- .0;
-
- assert_eq!(
- events,
- vec![ShielderContractEvents::NewAccountNative(NewAccountNative {
- contractVersion: FixedBytes([0, 0, 1]),
- idHash: calldata.idHash,
- amount,
- newNote: calldata.newNote,
- newNoteIndex: U256::ZERO,
- })]
- );
- assert!(actor_balance_decreased_by(&deployment, amount));
- assert_eq!(shielder_account.shielded_amount, U256::from(amount))
-}
+ #[rstest]
+ fn succeeds(mut deployment: Deployment) {
+ let mut shielder_account = ShielderAccount::default();
+ let amount = U256::from(10);
+ let calldata = prepare_call(&mut deployment, &mut shielder_account, amount);
+
+ let events = invoke_call(&mut deployment, &mut shielder_account, amount, &calldata)
+ .unwrap()
+ .0;
+
+ assert_eq!(
+ events,
+ vec![ShielderContractEvents::NewAccountNative(NewAccountNative {
+ contractVersion: FixedBytes([0, 0, 1]),
+ idHash: calldata.idHash,
+ amount,
+ newNote: calldata.newNote,
+ newNoteIndex: U256::ZERO,
+ })]
+ );
+ assert!(actor_balance_decreased_by(&deployment, amount));
+ assert_eq!(shielder_account.shielded_amount, U256::from(amount))
+ }
-#[rstest]
-fn fails_if_incorrect_expected_version(mut deployment: Deployment) {
- let mut shielder_account = ShielderAccount::default();
- let amount = U256::from(10);
- let mut calldata = prepare_call(&mut deployment, &mut shielder_account, amount);
- calldata.expectedContractVersion = FixedBytes([9, 8, 7]);
-
- let result = invoke_call(&mut deployment, &mut shielder_account, amount, &calldata);
-
- assert_matches!(
- result,
- Err(ShielderContractErrors::WrongContractVersion(
- WrongContractVersion {
- actual: FixedBytes([0, 0, 1]),
- expectedByCaller: FixedBytes([9, 8, 7]),
- }
- ))
- );
- assert!(actor_balance_decreased_by(&deployment, U256::ZERO))
-}
+ #[rstest]
+ fn fails_if_incorrect_expected_version(mut deployment: Deployment) {
+ let mut shielder_account = ShielderAccount::default();
+ let amount = U256::from(10);
+ let mut calldata = prepare_call(&mut deployment, &mut shielder_account, amount);
+ calldata.expectedContractVersion = FixedBytes([9, 8, 7]);
+
+ let result = invoke_call(&mut deployment, &mut shielder_account, amount, &calldata);
+
+ assert_matches!(
+ result,
+ Err(ShielderContractErrors::WrongContractVersion(
+ WrongContractVersion {
+ actual: FixedBytes([0, 0, 1]),
+ expectedByCaller: FixedBytes([9, 8, 7]),
+ }
+ ))
+ );
+ assert!(actor_balance_decreased_by(&deployment, U256::ZERO))
+ }
-#[rstest]
-fn cannot_use_same_id_twice(mut deployment: Deployment) {
- assert!(create_account_and_call(&mut deployment, U256::from(1), U256::from(10)).is_ok());
+ #[rstest]
+ fn cannot_use_same_id_twice(mut deployment: Deployment) {
+ assert!(create_account_and_call(&mut deployment, U256::from(1), U256::from(10)).is_ok());
- let result = create_account_and_call(&mut deployment, U256::from(1), U256::from(10));
+ let result = create_account_and_call(&mut deployment, U256::from(1), U256::from(10));
- assert_matches!(result, Err(ShielderContractErrors::DuplicatedNullifier(_)));
- assert!(actor_balance_decreased_by(&deployment, U256::from(10)))
-}
+ assert_matches!(result, Err(ShielderContractErrors::DuplicatedNullifier(_)));
+ assert!(actor_balance_decreased_by(&deployment, U256::from(10)))
+ }
-#[rstest]
-fn can_consume_entire_contract_balance_limit(mut deployment: Deployment) {
- let mut shielder_account = ShielderAccount::default();
- let amount = U256::from((1u128 << 112) - 1);
- let calldata = prepare_call(&mut deployment, &mut shielder_account, amount);
+ #[rstest]
+ fn cannot_use_input_greater_than_field_modulus(mut deployment: Deployment) {
+ let mut shielder_account = ShielderAccount::new(U256::from(1));
+
+ let initial_amount = U256::from(10);
+ let mut calldata = prepare_call(&mut deployment, &mut shielder_account, initial_amount);
+ let mut swap_value = U256::from_str(F::MODULUS).unwrap();
+
+ mem::swap(&mut calldata.idHash, &mut swap_value);
+ let result = invoke_call(
+ &mut deployment,
+ &mut shielder_account,
+ initial_amount,
+ &calldata,
+ );
+ assert_matches!(result, Err(ShielderContractErrors::NotAFieldElement(_)));
+ mem::swap(&mut calldata.idHash, &mut swap_value);
+
+ mem::swap(&mut calldata.newNote, &mut swap_value);
+ let result = invoke_call(
+ &mut deployment,
+ &mut shielder_account,
+ initial_amount,
+ &calldata,
+ );
+ assert_matches!(result, Err(ShielderContractErrors::NotAFieldElement(_)));
+ mem::swap(&mut calldata.newNote, &mut swap_value);
+
+ assert!(actor_balance_decreased_by(&deployment, U256::from(0)));
+ assert!(recipient_balance_increased_by(&deployment, U256::from(0)));
+ assert!(relayer_balance_increased_by(&deployment, U256::from(0)))
+ }
- let result = invoke_call(&mut deployment, &mut shielder_account, amount, &calldata);
+ #[rstest]
+ fn can_consume_entire_contract_balance_limit(mut deployment: Deployment) {
+ let mut shielder_account = ShielderAccount::default();
+ let amount = U256::from((1u128 << 112) - 1);
+ let calldata = prepare_call(&mut deployment, &mut shielder_account, amount);
- assert!(result.is_ok());
- let events = result.unwrap().0;
- assert!(events.len() == 1);
- assert_matches!(events[0], ShielderContractEvents::NewAccountNative(_));
- assert!(actor_balance_decreased_by(&deployment, amount))
-}
+ let result = invoke_call(&mut deployment, &mut shielder_account, amount, &calldata);
-#[rstest]
-fn fails_if_contract_balance_limit_reached(mut deployment: Deployment) {
- let amount_1 = U256::from((1u128 << 112) - 1);
- assert!(create_account_and_call(&mut deployment, U256::from(1), amount_1).is_ok());
+ assert!(result.is_ok());
+ let events = result.unwrap().0;
+ assert!(events.len() == 1);
+ assert_matches!(events[0], ShielderContractEvents::NewAccountNative(_));
+ assert!(actor_balance_decreased_by(&deployment, amount))
+ }
- let amount_2 = U256::from(1);
- let result_2 = create_account_and_call(&mut deployment, U256::from(2), amount_2);
+ #[rstest]
+ fn fails_if_contract_balance_limit_reached(mut deployment: Deployment) {
+ let amount_1 = U256::from((1u128 << 112) - 1);
+ assert!(create_account_and_call(&mut deployment, U256::from(1), amount_1).is_ok());
- assert_matches!(
- result_2,
- Err(ShielderContractErrors::ContractBalanceLimitReached(_))
- );
- assert!(actor_balance_decreased_by(&deployment, amount_1))
-}
+ let amount_2 = U256::from(1);
+ let result_2 = create_account_and_call(&mut deployment, U256::from(2), amount_2);
-#[rstest]
-fn correctly_handles_max_u256_value(mut deployment: Deployment) {
- let result = create_account_and_call(&mut deployment, U256::from(1), U256::MAX);
+ assert_matches!(
+ result_2,
+ Err(ShielderContractErrors::ContractBalanceLimitReached(_))
+ );
+ assert!(actor_balance_decreased_by(&deployment, amount_1))
+ }
- assert_matches!(
- result,
- Err(ShielderContractErrors::ContractBalanceLimitReached(_))
- );
- assert!(actor_balance_decreased_by(&deployment, U256::ZERO))
-}
+ #[rstest]
+ fn correctly_handles_max_u256_value(mut deployment: Deployment) {
+ let result = create_account_and_call(&mut deployment, U256::from(1), U256::MAX);
-#[rstest]
-fn fails_if_proof_incorrect(mut deployment: Deployment) {
- let mut shielder_account = ShielderAccount::default();
- let amount = U256::from(10);
- let mut calldata = prepare_call(&mut deployment, &mut shielder_account, amount);
- calldata.idHash = calldata.idHash.wrapping_add(U256::from(1));
+ assert_matches!(
+ result,
+ Err(ShielderContractErrors::ContractBalanceLimitReached(_))
+ );
+ assert!(actor_balance_decreased_by(&deployment, U256::ZERO))
+ }
- let result = invoke_call(&mut deployment, &mut shielder_account, amount, &calldata);
+ #[rstest]
+ fn fails_if_proof_incorrect(mut deployment: Deployment) {
+ let mut shielder_account = ShielderAccount::default();
+ let amount = U256::from(10);
+ let mut calldata = prepare_call(&mut deployment, &mut shielder_account, amount);
+ calldata.idHash = calldata.idHash.wrapping_add(U256::from(1));
- assert_matches!(
- result,
- Err(ShielderContractErrors::NewAccountVerificationFailed(_))
- );
- assert!(actor_balance_decreased_by(&deployment, U256::ZERO))
-}
+ let result = invoke_call(&mut deployment, &mut shielder_account, amount, &calldata);
-#[rstest]
-fn fails_if_over_deposit_limit(mut deployment: Deployment) {
- let mut shielder_account = ShielderAccount::default();
- let amount = U256::from(101);
- let calldata = prepare_call(&mut deployment, &mut shielder_account, amount);
+ assert_matches!(
+ result,
+ Err(ShielderContractErrors::NewAccountVerificationFailed(_))
+ );
+ assert!(actor_balance_decreased_by(&deployment, U256::ZERO))
+ }
+
+ #[rstest]
+ fn fails_if_over_deposit_limit(mut deployment: Deployment) {
+ let mut shielder_account = ShielderAccount::default();
+ let amount = U256::from(101);
+ let calldata = prepare_call(&mut deployment, &mut shielder_account, amount);
- let result = invoke_call(&mut deployment, &mut shielder_account, amount, &calldata);
+ let result = invoke_call(&mut deployment, &mut shielder_account, amount, &calldata);
- assert!(result.is_ok());
+ assert!(result.is_ok());
- let old_limit = get_deposit_limit(&mut deployment);
+ let old_limit = get_deposit_limit(&mut deployment);
- assert_eq!(old_limit, U256::MAX);
+ assert_eq!(old_limit, U256::MAX);
- let new_limit = U256::from(100);
- set_deposit_limit(&mut deployment, new_limit);
+ let new_limit = U256::from(100);
+ set_deposit_limit(&mut deployment, new_limit);
- let returned_new_limit = get_deposit_limit(&mut deployment);
+ let returned_new_limit = get_deposit_limit(&mut deployment);
- assert_eq!(returned_new_limit, new_limit);
+ assert_eq!(returned_new_limit, new_limit);
- let mut shielder_account = ShielderAccount::default();
- let amount = U256::from(101);
- let calldata = prepare_call(&mut deployment, &mut shielder_account, amount);
+ let mut shielder_account = ShielderAccount::default();
+ let amount = U256::from(101);
+ let calldata = prepare_call(&mut deployment, &mut shielder_account, amount);
- let result = invoke_call(&mut deployment, &mut shielder_account, amount, &calldata);
+ let result = invoke_call(&mut deployment, &mut shielder_account, amount, &calldata);
- assert_matches!(
- result,
- Err(ShielderContractErrors::AmountOverDepositLimit(_))
- )
+ assert_matches!(
+ result,
+ Err(ShielderContractErrors::AmountOverDepositLimit(_))
+ )
+ }
}
diff --git a/crates/integration-tests/src/shielder/calls/withdraw_native.rs b/crates/integration-tests/src/shielder/calls/withdraw_native.rs
index 13b645d3..507435d9 100644
--- a/crates/integration-tests/src/shielder/calls/withdraw_native.rs
+++ b/crates/integration-tests/src/shielder/calls/withdraw_native.rs
@@ -1,39 +1,30 @@
-use std::{assert_matches::assert_matches, str::FromStr};
+use std::str::FromStr;
-use alloy_primitives::{Address, Bytes, FixedBytes, TxHash, U256};
-use evm_utils::SuccessResult;
-use rstest::rstest;
+use alloy_primitives::{Address, TxHash, U256};
use shielder_rust_sdk::{
account::{
call_data::{MerkleProof, WithdrawCallType, WithdrawExtra},
ShielderAccount,
},
- contract::ShielderContract::{
- withdrawNativeCall, ShielderContractErrors, ShielderContractEvents, WithdrawNative,
- WrongContractVersion,
- },
+ contract::ShielderContract::withdrawNativeCall,
version::ContractVersion,
};
use crate::shielder::{
- actor_balance_decreased_by,
- calls::{deposit_native, new_account_native},
- deploy::{deployment, Deployment, RECIPIENT_ADDRESS, RELAYER_ADDRESS, REVERTING_ADDRESS},
- destination_balances_unchanged, invoke_shielder_call,
+ deploy::{Deployment, RECIPIENT_ADDRESS, RELAYER_ADDRESS},
+ invoke_shielder_call,
merkle::get_merkle_args,
- recipient_balance_increased_by, relayer_balance_increased_by, CallResult,
+ CallResult,
};
-const GAS_CONSUMPTION: u64 = 1898039;
-
-struct PrepareCallArgs {
+pub struct PrepareCallArgs {
amount: U256,
withdraw_address: Address,
relayer_address: Address,
relayer_fee: U256,
}
-fn prepare_args(amount: U256, relayer_fee: U256) -> PrepareCallArgs {
+pub fn prepare_args(amount: U256, relayer_fee: U256) -> PrepareCallArgs {
PrepareCallArgs {
amount,
withdraw_address: Address::from_str(RECIPIENT_ADDRESS).unwrap(),
@@ -42,7 +33,7 @@ fn prepare_args(amount: U256, relayer_fee: U256) -> PrepareCallArgs {
}
}
-fn prepare_call(
+pub fn prepare_call(
deployment: &mut Deployment,
shielder_account: &mut ShielderAccount,
args: PrepareCallArgs,
@@ -81,7 +72,7 @@ fn prepare_call(
(calldata, note_index)
}
-fn invoke_call(
+pub fn invoke_call(
deployment: &mut Deployment,
shielder_account: &mut ShielderAccount,
calldata: &withdrawNativeCall,
@@ -99,327 +90,427 @@ fn invoke_call(
}
}
-#[rstest]
-fn gas_consumption_regression(mut deployment: Deployment) {
- let mut shielder_account =
- new_account_native::create_account_and_call(&mut deployment, U256::from(1), U256::from(20))
- .unwrap();
+#[cfg(test)]
+mod tests {
+
+ use std::{assert_matches::assert_matches, mem, str::FromStr};
+
+ use alloy_primitives::{Address, Bytes, FixedBytes, U256};
+ use evm_utils::SuccessResult;
+ use halo2_proofs::halo2curves::ff::PrimeField;
+ use rstest::rstest;
+ use shielder_circuits::F;
+ use shielder_rust_sdk::{
+ account::ShielderAccount,
+ contract::ShielderContract::{
+ withdrawNativeCall, ShielderContractErrors, ShielderContractEvents, WithdrawNative,
+ WrongContractVersion,
+ },
+ };
- let (withdraw_calldata, _) = prepare_call(
- &mut deployment,
- &mut shielder_account,
- prepare_args(U256::from(5), U256::from(1)),
- );
- let (_, SuccessResult { gas_used, .. }) =
- invoke_call(&mut deployment, &mut shielder_account, &withdraw_calldata).unwrap();
+ use crate::{
+ calls::withdraw_native::{invoke_call, prepare_args, prepare_call, PrepareCallArgs},
+ shielder::{
+ actor_balance_decreased_by,
+ calls::{deposit_native, new_account_native},
+ deploy::{
+ deployment, Deployment, RECIPIENT_ADDRESS, RELAYER_ADDRESS, REVERTING_ADDRESS,
+ },
+ destination_balances_unchanged, recipient_balance_increased_by,
+ relayer_balance_increased_by,
+ },
+ };
- assert!(
+ const GAS_CONSUMPTION: u64 = 1898039;
+
+ #[rstest]
+ fn gas_consumption_regression(mut deployment: Deployment) {
+ let mut shielder_account = new_account_native::create_account_and_call(
+ &mut deployment,
+ U256::from(1),
+ U256::from(20),
+ )
+ .unwrap();
+
+ let (withdraw_calldata, _) = prepare_call(
+ &mut deployment,
+ &mut shielder_account,
+ prepare_args(U256::from(5), U256::from(1)),
+ );
+ let (_, SuccessResult { gas_used, .. }) =
+ invoke_call(&mut deployment, &mut shielder_account, &withdraw_calldata).unwrap();
+
+ assert!(
gas_used < 110 * GAS_CONSUMPTION / 100,
"withdraw native transaction consumes {gas_used}, which is 10% beyond baseline of {GAS_CONSUMPTION}"
);
-}
-
-#[rstest]
-fn succeeds(mut deployment: Deployment) {
- let mut shielder_account =
- new_account_native::create_account_and_call(&mut deployment, U256::from(1), U256::from(20))
- .unwrap();
-
- let (withdraw_calldata, withdraw_note_index) = prepare_call(
- &mut deployment,
- &mut shielder_account,
- prepare_args(U256::from(5), U256::from(1)),
- );
- let events = invoke_call(&mut deployment, &mut shielder_account, &withdraw_calldata)
- .unwrap()
- .0;
-
- assert_eq!(
- events,
- vec![ShielderContractEvents::WithdrawNative(WithdrawNative {
- contractVersion: FixedBytes([0, 0, 1]),
- idHiding: withdraw_calldata.idHiding,
- amount: U256::from(5),
- withdrawAddress: Address::from_str(RECIPIENT_ADDRESS).unwrap(),
- newNote: withdraw_calldata.newNote,
- relayerAddress: Address::from_str(RELAYER_ADDRESS).unwrap(),
- newNoteIndex: withdraw_note_index.saturating_add(U256::from(1)),
- fee: U256::from(1),
- })]
- );
- assert!(actor_balance_decreased_by(&deployment, U256::from(20)));
- assert!(recipient_balance_increased_by(&deployment, U256::from(4)));
- assert!(relayer_balance_increased_by(&deployment, U256::from(1)));
- assert_eq!(shielder_account.shielded_amount, U256::from(15))
-}
-
-#[rstest]
-fn succeeds_after_deposit(mut deployment: Deployment) {
- let mut shielder_account =
- new_account_native::create_account_and_call(&mut deployment, U256::from(1), U256::from(20))
- .unwrap();
-
- let deposit_amount = U256::from(10);
- let (deposit_calldata, _) =
- deposit_native::prepare_call(&mut deployment, &mut shielder_account, deposit_amount);
- deposit_native::invoke_call(
- &mut deployment,
- &mut shielder_account,
- deposit_amount,
- &deposit_calldata,
- )
- .unwrap();
-
- let (withdraw_calldata, withdraw_note_index) = prepare_call(
- &mut deployment,
- &mut shielder_account,
- prepare_args(U256::from(5), U256::from(1)),
- );
- let events = invoke_call(&mut deployment, &mut shielder_account, &withdraw_calldata)
- .unwrap()
- .0;
-
- assert_eq!(
- events,
- vec![ShielderContractEvents::WithdrawNative(WithdrawNative {
- contractVersion: FixedBytes([0, 0, 1]),
- idHiding: withdraw_calldata.idHiding,
- amount: U256::from(5),
- withdrawAddress: Address::from_str(RECIPIENT_ADDRESS).unwrap(),
- newNote: withdraw_calldata.newNote,
- relayerAddress: Address::from_str(RELAYER_ADDRESS).unwrap(),
- newNoteIndex: withdraw_note_index.saturating_add(U256::from(1)),
- fee: U256::from(1),
- })]
- );
- assert!(actor_balance_decreased_by(&deployment, U256::from(30)));
- assert!(recipient_balance_increased_by(&deployment, U256::from(4)));
- assert!(relayer_balance_increased_by(&deployment, U256::from(1)));
- assert_eq!(shielder_account.shielded_amount, U256::from(25))
-}
-
-#[rstest]
-fn fails_if_proof_incorrect(mut deployment: Deployment) {
- let mut shielder_account =
- new_account_native::create_account_and_call(&mut deployment, U256::from(1), U256::from(20))
- .unwrap();
-
- let (mut calldata, _) = prepare_call(
- &mut deployment,
- &mut shielder_account,
- prepare_args(U256::from(5), U256::from(1)),
- );
- calldata.newNote = calldata.newNote.wrapping_add(U256::from(1));
-
- let result = invoke_call(&mut deployment, &mut shielder_account, &calldata);
-
- assert_matches!(
- result,
- Err(ShielderContractErrors::WithdrawVerificationFailed(_))
- );
- assert!(actor_balance_decreased_by(&deployment, U256::from(20)));
- assert!(destination_balances_unchanged(&deployment))
-}
-
-#[rstest]
-fn rejects_value_zero(mut deployment: Deployment) {
- let mut shielder_account =
- new_account_native::create_account_and_call(&mut deployment, U256::from(1), U256::from(20))
- .unwrap();
-
- let (calldata, _) = prepare_call(
- &mut deployment,
- &mut shielder_account,
- prepare_args(U256::from(0), U256::from(1)),
- );
- let result = invoke_call(&mut deployment, &mut shielder_account, &calldata);
-
- assert_matches!(result, Err(ShielderContractErrors::ZeroAmount(_)));
- assert!(actor_balance_decreased_by(&deployment, U256::from(20)));
- assert!(destination_balances_unchanged(&deployment))
-}
-
-#[rstest]
-fn fails_if_fee_higher_than_amount(mut deployment: Deployment) {
- let mut shielder_account =
- new_account_native::create_account_and_call(&mut deployment, U256::from(1), U256::from(20))
- .unwrap();
+ }
- let (calldata, _) = prepare_call(
- &mut deployment,
- &mut shielder_account,
- prepare_args(U256::from(3), U256::from(3)),
- );
- let result = invoke_call(&mut deployment, &mut shielder_account, &calldata);
+ #[rstest]
+ fn succeeds(mut deployment: Deployment) {
+ let mut shielder_account = new_account_native::create_account_and_call(
+ &mut deployment,
+ U256::from(1),
+ U256::from(20),
+ )
+ .unwrap();
+
+ let (withdraw_calldata, withdraw_note_index) = prepare_call(
+ &mut deployment,
+ &mut shielder_account,
+ prepare_args(U256::from(5), U256::from(1)),
+ );
+ let events = invoke_call(&mut deployment, &mut shielder_account, &withdraw_calldata)
+ .unwrap()
+ .0;
+
+ assert_eq!(
+ events,
+ vec![ShielderContractEvents::WithdrawNative(WithdrawNative {
+ contractVersion: FixedBytes([0, 0, 1]),
+ idHiding: withdraw_calldata.idHiding,
+ amount: U256::from(5),
+ withdrawAddress: Address::from_str(RECIPIENT_ADDRESS).unwrap(),
+ newNote: withdraw_calldata.newNote,
+ relayerAddress: Address::from_str(RELAYER_ADDRESS).unwrap(),
+ newNoteIndex: withdraw_note_index.saturating_add(U256::from(1)),
+ fee: U256::from(1),
+ })]
+ );
+ assert!(actor_balance_decreased_by(&deployment, U256::from(20)));
+ assert!(recipient_balance_increased_by(&deployment, U256::from(4)));
+ assert!(relayer_balance_increased_by(&deployment, U256::from(1)));
+ assert_eq!(shielder_account.shielded_amount, U256::from(15))
+ }
- assert_matches!(result, Err(ShielderContractErrors::FeeHigherThanAmount(_)));
- assert!(actor_balance_decreased_by(&deployment, U256::from(20)));
- assert!(destination_balances_unchanged(&deployment))
-}
+ #[rstest]
+ fn succeeds_after_deposit(mut deployment: Deployment) {
+ let mut shielder_account = new_account_native::create_account_and_call(
+ &mut deployment,
+ U256::from(1),
+ U256::from(20),
+ )
+ .unwrap();
+
+ let deposit_amount = U256::from(10);
+ let (deposit_calldata, _) =
+ deposit_native::prepare_call(&mut deployment, &mut shielder_account, deposit_amount);
+ deposit_native::invoke_call(
+ &mut deployment,
+ &mut shielder_account,
+ deposit_amount,
+ &deposit_calldata,
+ )
+ .unwrap();
+
+ let (withdraw_calldata, withdraw_note_index) = prepare_call(
+ &mut deployment,
+ &mut shielder_account,
+ prepare_args(U256::from(5), U256::from(1)),
+ );
+ let events = invoke_call(&mut deployment, &mut shielder_account, &withdraw_calldata)
+ .unwrap()
+ .0;
+
+ assert_eq!(
+ events,
+ vec![ShielderContractEvents::WithdrawNative(WithdrawNative {
+ contractVersion: FixedBytes([0, 0, 1]),
+ idHiding: withdraw_calldata.idHiding,
+ amount: U256::from(5),
+ withdrawAddress: Address::from_str(RECIPIENT_ADDRESS).unwrap(),
+ newNote: withdraw_calldata.newNote,
+ relayerAddress: Address::from_str(RELAYER_ADDRESS).unwrap(),
+ newNoteIndex: withdraw_note_index.saturating_add(U256::from(1)),
+ fee: U256::from(1),
+ })]
+ );
+ assert!(actor_balance_decreased_by(&deployment, U256::from(30)));
+ assert!(recipient_balance_increased_by(&deployment, U256::from(4)));
+ assert!(relayer_balance_increased_by(&deployment, U256::from(1)));
+ assert_eq!(shielder_account.shielded_amount, U256::from(25))
+ }
-#[rstest]
-fn accepts_max_amount(mut deployment: Deployment) {
- let mut shielder_account = new_account_native::create_account_and_call(
- &mut deployment,
- U256::from(1),
- U256::from((1u128 << 112) - 1),
- )
- .unwrap();
-
- let (calldata, _) = prepare_call(
- &mut deployment,
- &mut shielder_account,
- prepare_args(U256::from((1u128 << 112) - 1), U256::from(1)),
- );
- let result = invoke_call(&mut deployment, &mut shielder_account, &calldata);
-
- assert!(result.is_ok());
- assert!(actor_balance_decreased_by(
- &deployment,
- U256::from((1u128 << 112) - 1)
- ));
- assert!(recipient_balance_increased_by(
- &deployment,
- U256::from((1u128 << 112) - 2)
- ));
- assert!(relayer_balance_increased_by(&deployment, U256::from(1)))
-}
+ #[rstest]
+ fn fails_if_proof_incorrect(mut deployment: Deployment) {
+ let mut shielder_account = new_account_native::create_account_and_call(
+ &mut deployment,
+ U256::from(1),
+ U256::from(20),
+ )
+ .unwrap();
+
+ let (mut calldata, _) = prepare_call(
+ &mut deployment,
+ &mut shielder_account,
+ prepare_args(U256::from(5), U256::from(1)),
+ );
+ calldata.newNote = calldata.newNote.wrapping_add(U256::from(1));
+
+ let result = invoke_call(&mut deployment, &mut shielder_account, &calldata);
+
+ assert_matches!(
+ result,
+ Err(ShielderContractErrors::WithdrawVerificationFailed(_))
+ );
+ assert!(actor_balance_decreased_by(&deployment, U256::from(20)));
+ assert!(destination_balances_unchanged(&deployment))
+ }
-#[rstest]
-fn rejects_too_high_amount(mut deployment: Deployment) {
- let mut shielder_account =
- new_account_native::create_account_and_call(&mut deployment, U256::from(1), U256::from(20))
- .unwrap();
+ #[rstest]
+ fn rejects_value_zero(mut deployment: Deployment) {
+ let mut shielder_account = new_account_native::create_account_and_call(
+ &mut deployment,
+ U256::from(1),
+ U256::from(20),
+ )
+ .unwrap();
+
+ let (calldata, _) = prepare_call(
+ &mut deployment,
+ &mut shielder_account,
+ prepare_args(U256::from(0), U256::from(1)),
+ );
+ let result = invoke_call(&mut deployment, &mut shielder_account, &calldata);
+
+ assert_matches!(result, Err(ShielderContractErrors::ZeroAmount(_)));
+ assert!(actor_balance_decreased_by(&deployment, U256::from(20)));
+ assert!(destination_balances_unchanged(&deployment))
+ }
- let (mut calldata, _) = prepare_call(
- &mut deployment,
- &mut shielder_account,
- prepare_args(U256::from(2), U256::from(1)),
- );
- calldata.amount = U256::from(1u128 << 112);
- let result = invoke_call(&mut deployment, &mut shielder_account, &calldata);
+ #[rstest]
+ fn fails_if_fee_higher_than_amount(mut deployment: Deployment) {
+ let mut shielder_account = new_account_native::create_account_and_call(
+ &mut deployment,
+ U256::from(1),
+ U256::from(20),
+ )
+ .unwrap();
+
+ let (calldata, _) = prepare_call(
+ &mut deployment,
+ &mut shielder_account,
+ prepare_args(U256::from(3), U256::from(3)),
+ );
+ let result = invoke_call(&mut deployment, &mut shielder_account, &calldata);
+
+ assert_matches!(result, Err(ShielderContractErrors::FeeHigherThanAmount(_)));
+ assert!(actor_balance_decreased_by(&deployment, U256::from(20)));
+ assert!(destination_balances_unchanged(&deployment))
+ }
- assert_matches!(result, Err(ShielderContractErrors::AmountTooHigh(_)));
- assert!(actor_balance_decreased_by(&deployment, U256::from(20)));
- assert!(destination_balances_unchanged(&deployment))
-}
+ #[rstest]
+ fn accepts_max_amount(mut deployment: Deployment) {
+ let mut shielder_account = new_account_native::create_account_and_call(
+ &mut deployment,
+ U256::from(1),
+ U256::from((1u128 << 112) - 1),
+ )
+ .unwrap();
+
+ let (calldata, _) = prepare_call(
+ &mut deployment,
+ &mut shielder_account,
+ prepare_args(U256::from((1u128 << 112) - 1), U256::from(1)),
+ );
+ let result = invoke_call(&mut deployment, &mut shielder_account, &calldata);
+
+ assert!(result.is_ok());
+ assert!(actor_balance_decreased_by(
+ &deployment,
+ U256::from((1u128 << 112) - 1)
+ ));
+ assert!(recipient_balance_increased_by(
+ &deployment,
+ U256::from((1u128 << 112) - 2)
+ ));
+ assert!(relayer_balance_increased_by(&deployment, U256::from(1)))
+ }
-#[rstest]
-fn fails_if_incorrect_expected_version(mut deployment: Deployment) {
- let mut shielder_account = ShielderAccount::default();
-
- let calldata = withdrawNativeCall {
- expectedContractVersion: FixedBytes([9, 8, 7]),
- idHiding: U256::ZERO,
- withdrawAddress: Address::from_str(RECIPIENT_ADDRESS).unwrap(),
- relayerAddress: Address::from_str(RELAYER_ADDRESS).unwrap(),
- relayerFee: U256::ZERO,
- amount: U256::from(10),
- merkleRoot: U256::ZERO,
- oldNullifierHash: U256::ZERO,
- newNote: U256::ZERO,
- proof: Bytes::from(vec![]),
- };
- let result = invoke_call(&mut deployment, &mut shielder_account, &calldata);
-
- assert_matches!(
- result,
- Err(ShielderContractErrors::WrongContractVersion(
- WrongContractVersion {
- actual: FixedBytes([0, 0, 1]),
- expectedByCaller: FixedBytes([9, 8, 7]),
- }
- ))
- );
- assert!(actor_balance_decreased_by(&deployment, U256::from(0)));
- assert!(destination_balances_unchanged(&deployment))
-}
+ #[rstest]
+ fn rejects_too_high_amount(mut deployment: Deployment) {
+ let mut shielder_account = new_account_native::create_account_and_call(
+ &mut deployment,
+ U256::from(1),
+ U256::from(20),
+ )
+ .unwrap();
+
+ let (mut calldata, _) = prepare_call(
+ &mut deployment,
+ &mut shielder_account,
+ prepare_args(U256::from(2), U256::from(1)),
+ );
+ calldata.amount = U256::from(1u128 << 112);
+ let result = invoke_call(&mut deployment, &mut shielder_account, &calldata);
+
+ assert_matches!(result, Err(ShielderContractErrors::AmountTooHigh(_)));
+ assert!(actor_balance_decreased_by(&deployment, U256::from(20)));
+ assert!(destination_balances_unchanged(&deployment))
+ }
-#[rstest]
-fn fails_if_merkle_root_does_not_exist(mut deployment: Deployment) {
- let mut shielder_account = ShielderAccount::default();
-
- let calldata = withdrawNativeCall {
- expectedContractVersion: FixedBytes([0, 0, 1]),
- idHiding: U256::ZERO,
- withdrawAddress: Address::from_str(RECIPIENT_ADDRESS).unwrap(),
- relayerAddress: Address::from_str(RELAYER_ADDRESS).unwrap(),
- relayerFee: U256::ZERO,
- amount: U256::from(10),
- merkleRoot: U256::ZERO,
- oldNullifierHash: U256::ZERO,
- newNote: U256::ZERO,
- proof: Bytes::from(vec![]),
- };
- let result = invoke_call(&mut deployment, &mut shielder_account, &calldata);
+ #[rstest]
+ fn fails_if_incorrect_expected_version(mut deployment: Deployment) {
+ let mut shielder_account = ShielderAccount::default();
- assert_matches!(
- result,
- Err(ShielderContractErrors::MerkleRootDoesNotExist(_))
- );
- assert!(actor_balance_decreased_by(&deployment, U256::from(0)));
- assert!(destination_balances_unchanged(&deployment))
-}
+ let calldata = withdrawNativeCall {
+ expectedContractVersion: FixedBytes([9, 8, 7]),
+ idHiding: U256::ZERO,
+ withdrawAddress: Address::from_str(RECIPIENT_ADDRESS).unwrap(),
+ relayerAddress: Address::from_str(RELAYER_ADDRESS).unwrap(),
+ relayerFee: U256::ZERO,
+ amount: U256::from(10),
+ merkleRoot: U256::ZERO,
+ oldNullifierHash: U256::ZERO,
+ newNote: U256::ZERO,
+ proof: Bytes::from(vec![]),
+ };
+ let result = invoke_call(&mut deployment, &mut shielder_account, &calldata);
+
+ assert_matches!(
+ result,
+ Err(ShielderContractErrors::WrongContractVersion(
+ WrongContractVersion {
+ actual: FixedBytes([0, 0, 1]),
+ expectedByCaller: FixedBytes([9, 8, 7]),
+ }
+ ))
+ );
+ assert!(actor_balance_decreased_by(&deployment, U256::from(0)));
+ assert!(destination_balances_unchanged(&deployment))
+ }
-#[rstest]
-fn cannot_use_same_note_twice(mut deployment: Deployment) {
- let mut shielder_account =
- new_account_native::create_account_and_call(&mut deployment, U256::from(1), U256::from(20))
- .unwrap();
+ #[rstest]
+ fn fails_if_merkle_root_does_not_exist(mut deployment: Deployment) {
+ let mut shielder_account = ShielderAccount::default();
- let (calldata, _) = prepare_call(
- &mut deployment,
- &mut shielder_account,
- prepare_args(U256::from(5), U256::from(1)),
- );
- assert!(invoke_call(&mut deployment, &mut shielder_account, &calldata).is_ok());
+ let calldata = withdrawNativeCall {
+ expectedContractVersion: FixedBytes([0, 0, 1]),
+ idHiding: U256::ZERO,
+ withdrawAddress: Address::from_str(RECIPIENT_ADDRESS).unwrap(),
+ relayerAddress: Address::from_str(RELAYER_ADDRESS).unwrap(),
+ relayerFee: U256::ZERO,
+ amount: U256::from(10),
+ merkleRoot: U256::ZERO,
+ oldNullifierHash: U256::ZERO,
+ newNote: U256::ZERO,
+ proof: Bytes::from(vec![]),
+ };
+ let result = invoke_call(&mut deployment, &mut shielder_account, &calldata);
+
+ assert_matches!(
+ result,
+ Err(ShielderContractErrors::MerkleRootDoesNotExist(_))
+ );
+ assert!(actor_balance_decreased_by(&deployment, U256::from(0)));
+ assert!(destination_balances_unchanged(&deployment))
+ }
- let result = invoke_call(&mut deployment, &mut shielder_account, &calldata);
+ #[rstest]
+ fn cannot_use_same_note_twice(mut deployment: Deployment) {
+ let mut shielder_account = new_account_native::create_account_and_call(
+ &mut deployment,
+ U256::from(1),
+ U256::from(20),
+ )
+ .unwrap();
+
+ let (calldata, _) = prepare_call(
+ &mut deployment,
+ &mut shielder_account,
+ prepare_args(U256::from(5), U256::from(1)),
+ );
+ assert!(invoke_call(&mut deployment, &mut shielder_account, &calldata).is_ok());
+
+ let result = invoke_call(&mut deployment, &mut shielder_account, &calldata);
+
+ assert_matches!(result, Err(ShielderContractErrors::DuplicatedNullifier(_)));
+ assert!(actor_balance_decreased_by(&deployment, U256::from(20)));
+ assert!(recipient_balance_increased_by(&deployment, U256::from(4)));
+ assert!(relayer_balance_increased_by(&deployment, U256::from(1)))
+ }
- assert_matches!(result, Err(ShielderContractErrors::DuplicatedNullifier(_)));
- assert!(actor_balance_decreased_by(&deployment, U256::from(20)));
- assert!(recipient_balance_increased_by(&deployment, U256::from(4)));
- assert!(relayer_balance_increased_by(&deployment, U256::from(1)))
-}
+ #[rstest]
+ fn cannot_use_input_greater_than_field_modulus(mut deployment: Deployment) {
+ let mut shielder_account = new_account_native::create_account_and_call(
+ &mut deployment,
+ U256::from(1),
+ U256::from(20),
+ )
+ .unwrap();
+
+ let (mut calldata, _) = prepare_call(
+ &mut deployment,
+ &mut shielder_account,
+ prepare_args(U256::from(5), U256::from(1)),
+ );
+ let mut swap_value = U256::from_str(F::MODULUS).unwrap();
+
+ mem::swap(&mut calldata.oldNullifierHash, &mut swap_value);
+ let result = invoke_call(&mut deployment, &mut shielder_account, &calldata);
+ assert_matches!(result, Err(ShielderContractErrors::NotAFieldElement(_)));
+ mem::swap(&mut calldata.oldNullifierHash, &mut swap_value);
+
+ mem::swap(&mut calldata.newNote, &mut swap_value);
+ let result = invoke_call(&mut deployment, &mut shielder_account, &calldata);
+ assert_matches!(result, Err(ShielderContractErrors::NotAFieldElement(_)));
+ mem::swap(&mut calldata.newNote, &mut swap_value);
+
+ mem::swap(&mut calldata.idHiding, &mut swap_value);
+ let result = invoke_call(&mut deployment, &mut shielder_account, &calldata);
+ assert_matches!(result, Err(ShielderContractErrors::NotAFieldElement(_)));
+ mem::swap(&mut calldata.idHiding, &mut swap_value);
+
+ assert!(actor_balance_decreased_by(&deployment, U256::from(20)));
+ assert!(recipient_balance_increased_by(&deployment, U256::from(0)));
+ assert!(relayer_balance_increased_by(&deployment, U256::from(0)))
+ }
-#[rstest]
-fn handles_withdraw_transfer_failure(mut deployment: Deployment) {
- let mut shielder_account =
- new_account_native::create_account_and_call(&mut deployment, U256::from(1), U256::from(20))
- .unwrap();
-
- let (calldata, _) = prepare_call(
- &mut deployment,
- &mut shielder_account,
- PrepareCallArgs {
- withdraw_address: Address::from_str(REVERTING_ADDRESS).unwrap(),
- ..prepare_args(U256::from(5), U256::from(1))
- },
- );
- let result = invoke_call(&mut deployment, &mut shielder_account, &calldata);
+ #[rstest]
+ fn handles_withdraw_transfer_failure(mut deployment: Deployment) {
+ let mut shielder_account = new_account_native::create_account_and_call(
+ &mut deployment,
+ U256::from(1),
+ U256::from(20),
+ )
+ .unwrap();
+
+ let (calldata, _) = prepare_call(
+ &mut deployment,
+ &mut shielder_account,
+ PrepareCallArgs {
+ withdraw_address: Address::from_str(REVERTING_ADDRESS).unwrap(),
+ ..prepare_args(U256::from(5), U256::from(1))
+ },
+ );
+ let result = invoke_call(&mut deployment, &mut shielder_account, &calldata);
- assert_matches!(result, Err(ShielderContractErrors::NativeTransferFailed(_)));
- assert!(actor_balance_decreased_by(&deployment, U256::from(20)));
- assert!(destination_balances_unchanged(&deployment))
-}
+ assert_matches!(result, Err(ShielderContractErrors::NativeTransferFailed(_)));
+ assert!(actor_balance_decreased_by(&deployment, U256::from(20)));
+ assert!(destination_balances_unchanged(&deployment))
+ }
-#[rstest]
-fn handles_fee_transfer_failure(mut deployment: Deployment) {
- let mut shielder_account =
- new_account_native::create_account_and_call(&mut deployment, U256::from(1), U256::from(20))
- .unwrap();
-
- let (calldata, _) = prepare_call(
- &mut deployment,
- &mut shielder_account,
- PrepareCallArgs {
- relayer_address: Address::from_str(REVERTING_ADDRESS).unwrap(),
- ..prepare_args(U256::from(5), U256::from(1))
- },
- );
- let result = invoke_call(&mut deployment, &mut shielder_account, &calldata);
+ #[rstest]
+ fn handles_fee_transfer_failure(mut deployment: Deployment) {
+ let mut shielder_account = new_account_native::create_account_and_call(
+ &mut deployment,
+ U256::from(1),
+ U256::from(20),
+ )
+ .unwrap();
+
+ let (calldata, _) = prepare_call(
+ &mut deployment,
+ &mut shielder_account,
+ PrepareCallArgs {
+ relayer_address: Address::from_str(REVERTING_ADDRESS).unwrap(),
+ ..prepare_args(U256::from(5), U256::from(1))
+ },
+ );
+ let result = invoke_call(&mut deployment, &mut shielder_account, &calldata);
- assert_matches!(result, Err(ShielderContractErrors::NativeTransferFailed(_)));
- assert!(actor_balance_decreased_by(&deployment, U256::from(20)));
- assert!(destination_balances_unchanged(&deployment))
+ assert_matches!(result, Err(ShielderContractErrors::NativeTransferFailed(_)));
+ assert!(actor_balance_decreased_by(&deployment, U256::from(20)));
+ assert!(destination_balances_unchanged(&deployment))
+ }
}
diff --git a/crates/integration-tests/src/shielder/deploy.rs b/crates/integration-tests/src/shielder/deploy.rs
index 70f8ce64..84b60438 100644
--- a/crates/integration-tests/src/shielder/deploy.rs
+++ b/crates/integration-tests/src/shielder/deploy.rs
@@ -12,7 +12,6 @@ use shielder_rust_sdk::contract::ShielderContract::initializeCall;
use crate::{
deploy_contract,
- permit2::PERMIT2_BYTECODE,
proving_utils::{
deposit_native_proving_params, new_account_native_proving_params,
withdraw_native_proving_params, ProvingParams,
@@ -22,7 +21,6 @@ use crate::{
erc1967proxy::{self, ERC_1967_PROXY_BYTECODE},
unpause_shielder,
},
- token,
verifier::deploy_verifiers,
};
@@ -57,9 +55,7 @@ pub const INITIAL_DEPOSIT_LIMIT: U256 = U256::MAX;
/// Contains full deployment addresses.
pub struct ShielderContractSuite {
- pub permit2: Address,
pub shielder: Address,
- pub token: Address,
}
pub fn prepare_account(
@@ -104,7 +100,7 @@ pub fn deployment(
) -> Deployment {
let mut evm = EvmRunner::aleph_evm();
let owner = prepare_account(&mut evm, DEPLOYER_ADDRESS, DEPLOYER_INITIAL_BALANCE, None);
- let actor = prepare_account(&mut evm, ACTOR_ADDRESS, ACTOR_INITIAL_BALANCE, None);
+ prepare_account(&mut evm, ACTOR_ADDRESS, ACTOR_INITIAL_BALANCE, None);
prepare_account(&mut evm, RECIPIENT_ADDRESS, RECIPIENT_INITIAL_BALANCE, None);
prepare_account(&mut evm, RELAYER_ADDRESS, RELAYER_INITIAL_BALANCE, None);
let reverting_bytecode = Bytecode::new_raw(Bytes::from_static(&REVERTING_BYTECODE));
@@ -115,17 +111,12 @@ pub fn deployment(
Some(reverting_bytecode),
);
- let token = deploy_token(&mut evm, owner);
- let permit2 = deploy_permit2(&mut evm, owner);
let shielder_address = deploy_shielder_contract(&mut evm, owner);
unpause_shielder(shielder_address, &mut evm);
- instrument_token(&mut evm, owner, actor, token, permit2);
Deployment {
evm,
contract_suite: ShielderContractSuite {
- token,
- permit2,
shielder: shielder_address,
},
new_account_native_proving_params: new_account_native_proving_params.clone(),
@@ -134,52 +125,6 @@ pub fn deployment(
}
}
-/// Deploy ERC20 token contract
-fn deploy_token(evm: &mut EvmRunner, caller: Address) -> Address {
- let solidity_code = read_contract("Token.sol");
- let compiled_bytecode = source_to_bytecode(solidity_code, "Token", true);
-
- let constructor_calldata = token::constructor_calldata(U256::from(1000000));
- let calldata = [compiled_bytecode, constructor_calldata].concat();
-
- evm.create(calldata, Some(caller))
- .expect("Failed to deploy the Token contract")
-}
-
-/// Performs basic instrumentation:
-/// - Transfer an initial amount of ERC20 to the actor account
-/// - Approve Permit2 as spender
-fn instrument_token(
- evm: &mut EvmRunner,
- owner: Address,
- actor: Address,
- token: Address,
- permit2: Address,
-) {
- evm.call(
- token,
- token::transfer_calldata(actor, U256::from(100000)),
- Some(owner),
- None,
- )
- .expect("ERC20 transfer call failed");
-
- evm.call(
- token,
- token::approve_calldata(permit2, U256::MAX),
- Some(actor),
- None,
- )
- .expect("ERC20 approve call failed");
-}
-
-/// deploy Permit2 contract from a pre-compiled bytecode.
-fn deploy_permit2(evm: &mut EvmRunner, caller: Address) -> Address {
- let bytecode = hex::decode(PERMIT2_BYTECODE).expect("Failed to decode permit2 bytecode");
- evm.create(bytecode, Some(caller))
- .expect("Failed to deploy Shielder implementation contract")
-}
-
/// Deploys the Shielder implementation contract.
///
/// This requires more steps than deploying a regular contract because Solc leaves placeholders
diff --git a/crates/integration-tests/src/shielder/merkle.rs b/crates/integration-tests/src/shielder/merkle.rs
index 6a0769d4..ac6927b6 100644
--- a/crates/integration-tests/src/shielder/merkle.rs
+++ b/crates/integration-tests/src/shielder/merkle.rs
@@ -1,18 +1,9 @@
-use std::assert_matches::assert_matches;
-
use alloy_primitives::{Address, U256};
use alloy_sol_types::{SolCall, SolValue};
use evm_utils::EvmRunner;
-use rstest::rstest;
use shielder_circuits::consts::merkle_constants::{ARITY, NOTE_TREE_HEIGHT};
use shielder_rust_sdk::contract::ShielderContract::getMerklePathCall;
-use crate::shielder::{
- calls::new_account_native,
- deploy::{deployment, Deployment},
- invoke_shielder_call,
-};
-
pub fn get_merkle_args(
shielder_address: Address,
note_index: U256,
@@ -44,18 +35,34 @@ fn reorganize_merkle_path(merkle_path: Vec) -> (U256, [[U256; ARITY]; NOTE
(root, result)
}
-#[rstest]
-fn succeeds(mut deployment: Deployment) {
- assert!(new_account_native::create_account_and_call(
- &mut deployment,
- U256::from(1),
- U256::from(10)
- )
- .is_ok());
+#[cfg(test)]
+mod tests {
+
+ use std::assert_matches::assert_matches;
+
+ use alloy_primitives::U256;
+ use rstest::rstest;
+ use shielder_rust_sdk::contract::ShielderContract::getMerklePathCall;
- let calldata = getMerklePathCall { id: U256::ZERO };
- let result = invoke_shielder_call(&mut deployment, &calldata, None);
+ use crate::shielder::{
+ calls::new_account_native,
+ deploy::{deployment, Deployment},
+ invoke_shielder_call,
+ };
- assert_matches!(result, Ok(_));
- assert!(result.unwrap().0.is_empty())
+ #[rstest]
+ fn succeeds(mut deployment: Deployment) {
+ assert!(new_account_native::create_account_and_call(
+ &mut deployment,
+ U256::from(1),
+ U256::from(10)
+ )
+ .is_ok());
+
+ let calldata = getMerklePathCall { id: U256::ZERO };
+ let result = invoke_shielder_call(&mut deployment, &calldata, None);
+
+ assert_matches!(result, Ok(_));
+ assert!(result.unwrap().0.is_empty())
+ }
}
diff --git a/crates/integration-tests/src/shielder/mod.rs b/crates/integration-tests/src/shielder/mod.rs
index b00a8db9..c16c5e8e 100644
--- a/crates/integration-tests/src/shielder/mod.rs
+++ b/crates/integration-tests/src/shielder/mod.rs
@@ -3,20 +3,20 @@ use std::str::FromStr;
use alloy_primitives::{Address, U256};
use alloy_sol_types::{SolCall, SolEventInterface, SolInterface};
use deploy::{
- deployment, Deployment, ACTOR_ADDRESS, ACTOR_INITIAL_BALANCE, DEPLOYER_ADDRESS,
- RECIPIENT_ADDRESS, RECIPIENT_INITIAL_BALANCE, RELAYER_ADDRESS, RELAYER_INITIAL_BALANCE,
+ Deployment, ACTOR_ADDRESS, ACTOR_INITIAL_BALANCE, DEPLOYER_ADDRESS, RECIPIENT_ADDRESS,
+ RECIPIENT_INITIAL_BALANCE, RELAYER_ADDRESS, RELAYER_INITIAL_BALANCE,
};
use evm_utils::{EvmRunner, EvmRunnerError, SuccessResult};
use shielder_rust_sdk::contract::ShielderContract::{
unpauseCall, ShielderContractErrors, ShielderContractEvents,
};
-mod address_conversion;
-mod calls;
-mod deploy;
-mod erc1967proxy;
-mod limits;
-mod merkle;
+pub mod address_conversion;
+pub mod calls;
+pub mod deploy;
+pub mod erc1967proxy;
+pub mod limits;
+pub mod merkle;
fn unpause_shielder(shielder: Address, evm: &mut EvmRunner) {
evm.call(
@@ -30,7 +30,7 @@ fn unpause_shielder(shielder: Address, evm: &mut EvmRunner) {
type CallResult = Result<(Vec, SuccessResult), ShielderContractErrors>;
-fn invoke_shielder_call(
+pub fn invoke_shielder_call(
deployment: &mut Deployment,
calldata: &impl SolCall,
value: Option,
@@ -43,11 +43,14 @@ fn invoke_shielder_call(
Some(Address::from_str(ACTOR_ADDRESS).unwrap()),
value,
)
- .map_err(|e| match e {
- EvmRunnerError::Revert(e) => {
- ShielderContractErrors::abi_decode(e.output().unwrap(), true).unwrap()
+ .map_err(|e| {
+ println!("ERROR {:?}", e);
+ match e {
+ EvmRunnerError::Revert(e) => {
+ ShielderContractErrors::abi_decode(e.output().unwrap(), true).unwrap()
+ }
+ _ => panic!("Expected EvmRunnerError::Revert"),
}
- _ => panic!("Expected EvmRunnerError::Revert"),
})?;
let events: Vec<_> = success_result
@@ -63,26 +66,26 @@ fn invoke_shielder_call(
Ok((events, success_result))
}
-fn get_balance(deployment: &Deployment, address: &str) -> U256 {
+pub fn get_balance(deployment: &Deployment, address: &str) -> U256 {
deployment
.evm
.get_balance(Address::from_str(address).unwrap())
.unwrap()
}
-fn actor_balance_decreased_by(deployment: &Deployment, amount: U256) -> bool {
- get_balance(&deployment, ACTOR_ADDRESS) == ACTOR_INITIAL_BALANCE - amount
+pub fn actor_balance_decreased_by(deployment: &Deployment, amount: U256) -> bool {
+ get_balance(deployment, ACTOR_ADDRESS) == ACTOR_INITIAL_BALANCE - amount
}
-fn recipient_balance_increased_by(deployment: &Deployment, amount: U256) -> bool {
- get_balance(&deployment, RECIPIENT_ADDRESS) == RECIPIENT_INITIAL_BALANCE + amount
+pub fn recipient_balance_increased_by(deployment: &Deployment, amount: U256) -> bool {
+ get_balance(deployment, RECIPIENT_ADDRESS) == RECIPIENT_INITIAL_BALANCE + amount
}
-fn relayer_balance_increased_by(deployment: &Deployment, amount: U256) -> bool {
- get_balance(&deployment, RELAYER_ADDRESS) == RELAYER_INITIAL_BALANCE + amount
+pub fn relayer_balance_increased_by(deployment: &Deployment, amount: U256) -> bool {
+ get_balance(deployment, RELAYER_ADDRESS) == RELAYER_INITIAL_BALANCE + amount
}
-fn destination_balances_unchanged(deployment: &Deployment) -> bool {
+pub fn destination_balances_unchanged(deployment: &Deployment) -> bool {
recipient_balance_increased_by(deployment, U256::ZERO)
&& relayer_balance_increased_by(deployment, U256::ZERO)
}
diff --git a/crates/integration-tests/src/token.rs b/crates/integration-tests/src/token.rs
deleted file mode 100644
index 6546ebdf..00000000
--- a/crates/integration-tests/src/token.rs
+++ /dev/null
@@ -1,25 +0,0 @@
-use alloy_primitives::{Address, U256};
-use alloy_sol_types::{sol, SolCall, SolConstructor};
-
-sol! {
- constructor(uint256 initialSupply);
-
- function approve(address spender, uint256 value) external returns (bool);
-
- function transfer(address to, uint256 value) external returns (bool);
-}
-
-pub fn constructor_calldata(initial_supply: U256) -> Vec {
- constructorCall {
- initialSupply: initial_supply,
- }
- .abi_encode()
-}
-
-pub fn approve_calldata(spender: Address, value: U256) -> Vec {
- approveCall { spender, value }.abi_encode()
-}
-
-pub fn transfer_calldata(to: Address, value: U256) -> Vec {
- transferCall { to, value }.abi_encode()
-}
diff --git a/crates/integration-tests/src/verifier.rs b/crates/integration-tests/src/verifier.rs
index 06bd579e..64066c45 100644
--- a/crates/integration-tests/src/verifier.rs
+++ b/crates/integration-tests/src/verifier.rs
@@ -1,14 +1,7 @@
use alloy_primitives::Address;
-use alloy_sol_types::SolValue;
use evm_utils::EvmRunner;
-use halo2_proofs::halo2curves::bn256::Fr;
-use halo2_solidity_verifier::verifier_contract;
-use shielder_circuits::{
- consts::RANGE_PROOF_CHUNK_SIZE, deposit::DepositProverKnowledge,
- new_account::NewAccountProverKnowledge, withdraw::WithdrawProverKnowledge, F,
-};
-use crate::{deploy_contract, proving_utils};
+use crate::deploy_contract;
const VERIFIER_CONTRACT_NAME: &str = "Halo2Verifier";
@@ -32,113 +25,130 @@ pub fn deploy_verifiers(evm: &mut EvmRunner) -> VerificationContracts {
}
}
-#[test]
-fn deploy_verification_contracts() {
- deploy_verifiers(&mut EvmRunner::aleph_evm());
-}
+#[cfg(test)]
+mod tests {
+
+ use alloy_primitives::Address;
+ use alloy_sol_types::SolValue;
+ use evm_utils::EvmRunner;
+ use halo2_proofs::halo2curves::bn256::Fr;
+ use halo2_solidity_verifier::verifier_contract;
+ use shielder_circuits::{
+ consts::RANGE_PROOF_CHUNK_SIZE, deposit::DepositProverKnowledge,
+ new_account::NewAccountProverKnowledge, withdraw::WithdrawProverKnowledge, F,
+ };
+
+ use super::deploy_verifiers;
+ use crate::proving_utils;
+
+ #[test]
+ fn deploy_verification_contracts() {
+ deploy_verifiers(&mut EvmRunner::aleph_evm());
+ }
-fn verify_with_contract(
- proof: Vec,
- pub_input: Vec,
- verifier_address: Address,
- evm: &mut EvmRunner,
-) -> bool {
- let calldata = verifier_contract::encode_calldata(&proof, &pub_input);
- let response = evm
- .call(verifier_address, calldata, None, None)
- .expect("Call failed")
- .output;
- ::abi_decode(&response, true).expect("Decoding contract response failed")
-}
+ fn verify_with_contract(
+ proof: Vec,
+ pub_input: Vec,
+ verifier_address: Address,
+ evm: &mut EvmRunner,
+ ) -> bool {
+ let calldata = verifier_contract::encode_calldata(&proof, &pub_input);
+ let response = evm
+ .call(verifier_address, calldata, None, None)
+ .expect("Call failed")
+ .output;
+ ::abi_decode(&response, true).expect("Decoding contract response failed")
+ }
-#[test]
-fn new_account_contract_verification_works() {
- let mut evm = EvmRunner::aleph_evm();
- let verification_contracts = deploy_verifiers(&mut evm);
-
- let (proof, pub_input) = proving_utils::prepare_proof::>();
- assert!(verify_with_contract(
- proof,
- pub_input,
- verification_contracts.new_account_verifier,
- &mut evm,
- ));
-}
+ #[test]
+ fn new_account_contract_verification_works() {
+ let mut evm = EvmRunner::aleph_evm();
+ let verification_contracts = deploy_verifiers(&mut evm);
+
+ let (proof, pub_input) = proving_utils::prepare_proof::>();
+ assert!(verify_with_contract(
+ proof,
+ pub_input,
+ verification_contracts.new_account_verifier,
+ &mut evm,
+ ));
+ }
-#[test]
-fn deposit_contract_verification_works() {
- let mut evm = EvmRunner::aleph_evm();
- let verification_contracts = deploy_verifiers(&mut evm);
-
- let (proof, pub_input) =
- proving_utils::prepare_proof::>();
- assert!(verify_with_contract(
- proof,
- pub_input,
- verification_contracts.deposit_verifier,
- &mut evm,
- ));
-}
+ #[test]
+ fn deposit_contract_verification_works() {
+ let mut evm = EvmRunner::aleph_evm();
+ let verification_contracts = deploy_verifiers(&mut evm);
+
+ let (proof, pub_input) =
+ proving_utils::prepare_proof::>();
+ assert!(verify_with_contract(
+ proof,
+ pub_input,
+ verification_contracts.deposit_verifier,
+ &mut evm,
+ ));
+ }
-#[test]
-fn withdraw_contract_verification_works() {
- let mut evm = EvmRunner::aleph_evm();
- let verification_contracts = deploy_verifiers(&mut evm);
-
- let (proof, pub_input) =
- proving_utils::prepare_proof::>();
- assert!(verify_with_contract(
- proof,
- pub_input,
- verification_contracts.withdraw_verifier,
- &mut evm,
- ));
-}
+ #[test]
+ fn withdraw_contract_verification_works() {
+ let mut evm = EvmRunner::aleph_evm();
+ let verification_contracts = deploy_verifiers(&mut evm);
+
+ let (proof, pub_input) =
+ proving_utils::prepare_proof::>();
+ assert!(verify_with_contract(
+ proof,
+ pub_input,
+ verification_contracts.withdraw_verifier,
+ &mut evm,
+ ));
+ }
-// Should trigger an early return in `Halo2Verifier`.
-#[test]
-fn fails_on_empty_proof() {
- let mut evm = EvmRunner::aleph_evm();
- let verification_contracts = deploy_verifiers(&mut evm);
-
- assert!(!verify_with_contract(
- vec![],
- vec![],
- verification_contracts.new_account_verifier,
- &mut evm,
- ));
-}
+ // Should trigger an early return in `Halo2Verifier`.
+ #[test]
+ fn fails_on_empty_proof() {
+ let mut evm = EvmRunner::aleph_evm();
+ let verification_contracts = deploy_verifiers(&mut evm);
+
+ assert!(!verify_with_contract(
+ vec![],
+ vec![],
+ verification_contracts.new_account_verifier,
+ &mut evm,
+ ));
+ }
-// Should trigger a late return in `Halo2Verifier`.
-#[test]
-fn fails_on_proof_with_wrong_input() {
- let mut evm = EvmRunner::aleph_evm();
- let verification_contracts = deploy_verifiers(&mut evm);
-
- let (proof, mut pub_input) = proving_utils::prepare_proof::>();
- pub_input[0] += Fr::from(1);
-
- assert!(!verify_with_contract(
- proof,
- pub_input,
- verification_contracts.new_account_verifier,
- &mut evm,
- ));
-}
+ // Should trigger a late return in `Halo2Verifier`.
+ #[test]
+ fn fails_on_proof_with_wrong_input() {
+ let mut evm = EvmRunner::aleph_evm();
+ let verification_contracts = deploy_verifiers(&mut evm);
+
+ let (proof, mut pub_input) = proving_utils::prepare_proof::>();
+ pub_input[0] += Fr::from(1);
+
+ assert!(!verify_with_contract(
+ proof,
+ pub_input,
+ verification_contracts.new_account_verifier,
+ &mut evm,
+ ));
+ }
-// Should trigger a late return in `Halo2Verifier`.
-#[test]
-fn fails_on_corrupted_proof() {
- let mut evm = EvmRunner::aleph_evm();
- let verification_contracts = deploy_verifiers(&mut evm);
-
- let (mut proof, pub_input) = proving_utils::prepare_proof::>();
- proof[0] = proof[0].wrapping_add(1u8);
-
- assert!(!verify_with_contract(
- proof,
- pub_input,
- verification_contracts.new_account_verifier,
- &mut evm,
- ));
+ // Should trigger a late return in `Halo2Verifier`.
+ #[test]
+ fn fails_on_corrupted_proof() {
+ let mut evm = EvmRunner::aleph_evm();
+ let verification_contracts = deploy_verifiers(&mut evm);
+
+ let (mut proof, pub_input) = proving_utils::prepare_proof::>();
+ proof[0] = proof[0].wrapping_add(1u8);
+
+ assert!(!verify_with_contract(
+ proof,
+ pub_input,
+ verification_contracts.new_account_verifier,
+ &mut evm,
+ ));
+ }
}
diff --git a/crates/shielder-cli/src/app_state.rs b/crates/shielder-cli/src/app_state.rs
index 2623d141..35484107 100644
--- a/crates/shielder-cli/src/app_state.rs
+++ b/crates/shielder-cli/src/app_state.rs
@@ -36,6 +36,10 @@ impl RelayerRpcUrl {
format!("{}/quote_fees", self.base_url)
}
+ pub fn fee_address_url(&self) -> String {
+ format!("{}/fee_address", self.base_url)
+ }
+
pub async fn check_connection(&self) -> anyhow::Result<()> {
let response = reqwest::get(self.healthcheck_url()).await?;
if response.status().is_success() {
@@ -58,7 +62,6 @@ pub struct AppState {
pub node_rpc_url: String,
pub contract_address: Address,
pub relayer_rpc_url: RelayerRpcUrl,
- pub relayer_address: Address,
pub signing_key: String,
}
@@ -83,12 +86,10 @@ impl AppState {
Node address: {}
Contract address: {}
Relayer url: {}
-Relayer address: {}
Depositor signing key: {}",
self.node_rpc_url,
self.contract_address,
self.relayer_rpc_url.relay_url(),
- self.relayer_address,
self.signing_key
)
}
diff --git a/crates/shielder-cli/src/config.rs b/crates/shielder-cli/src/config.rs
index 037c04f1..fb0dbc01 100644
--- a/crates/shielder-cli/src/config.rs
+++ b/crates/shielder-cli/src/config.rs
@@ -76,11 +76,6 @@ pub enum StateWriteCommand {
/// Address of the relayer.
url: String,
},
- /// Set relayer chain address.
- RelayerAddress {
- /// Address of the relayer.
- address: Address,
- },
/// Recover state from the blockchain.
RecoverState,
}
diff --git a/crates/shielder-cli/src/main.rs b/crates/shielder-cli/src/main.rs
index b82a5a6d..23be8b40 100644
--- a/crates/shielder-cli/src/main.rs
+++ b/crates/shielder-cli/src/main.rs
@@ -67,10 +67,6 @@ async fn perform_state_write_action(
info!("Setting relayer url to {url}");
app_state.relayer_rpc_url = relayer_rpc_url;
}
- StateWriteCommand::RelayerAddress { address } => {
- info!("Setting relayer address to {address}");
- app_state.relayer_address = address;
- }
StateWriteCommand::RecoverState => {
recover_state(app_state).await?;
}
diff --git a/crates/shielder-cli/src/recovery.rs b/crates/shielder-cli/src/recovery.rs
index 6b48bfa5..1a486135 100644
--- a/crates/shielder-cli/src/recovery.rs
+++ b/crates/shielder-cli/src/recovery.rs
@@ -1,7 +1,10 @@
use alloy_eips::BlockNumberOrTag;
use alloy_primitives::{BlockHash, BlockNumber, U256};
-use alloy_provider::Provider;
-use alloy_rpc_types_eth::Transaction;
+use alloy_provider::{
+ network::{primitives::BlockTransactionsKind, TransactionResponse},
+ Provider,
+};
+use alloy_rpc_types_eth::{Transaction, TransactionTrait};
use alloy_sol_types::SolCall;
use anyhow::{anyhow, bail, Result};
use shielder_circuits::{poseidon::off_circuit::hash, F};
@@ -78,7 +81,10 @@ async fn find_shielder_transaction(
account: &ShielderAccount,
) -> Result {
let block = provider
- .get_block_by_number(BlockNumberOrTag::Number(block_number), true)
+ .get_block_by_number(
+ BlockNumberOrTag::Number(block_number),
+ BlockTransactionsKind::Full,
+ )
.await?
.ok_or(anyhow!("Block not found"))?;
let txs = block
@@ -93,7 +99,7 @@ async fn find_shielder_transaction(
};
event.check_version().map_err(|_| anyhow!("Bad version"))?;
let event_note = event.note();
- let action = ShielderAction::from((tx.hash, event));
+ let action = ShielderAction::from((tx.tx_hash(), event));
let mut hypothetical_account = account.clone();
hypothetical_account.register_action(action.clone());
@@ -113,15 +119,15 @@ async fn try_get_shielder_event_for_tx(
tx: &Transaction,
block_hash: BlockHash,
) -> Result