├── .devcontainer
└── devcontainer.json
├── .dockerignore
├── .dvc
├── .gitignore
└── config
├── .dvcignore
├── .editorconfig
├── .envrc
├── .github
├── CONTRIBUTING.md
├── ISSUE_TEMPLATE
│ ├── bug_report.md
│ ├── checklist_issue.md
│ ├── config.yml
│ ├── new_issue.md
│ ├── spec_issue.md
│ └── task_issue.md
├── PULL_REQUEST_TEMPLATE.md
└── workflows
│ ├── check.yml
│ ├── coverage.yaml
│ ├── image-publish.yml
│ ├── publish-docs.yml
│ ├── publish-types.yml
│ └── update-types.yml
├── .gitignore
├── .maintain
└── webb-weight-template.hbs
├── .taplo.toml
├── Cargo.lock
├── Cargo.toml
├── LICENSE
├── README.md
├── assets
├── w3f.jpeg
├── webb-icon.svg
├── webb_banner_dark.png
└── webb_banner_light.png
├── circom-proving
├── Cargo.toml
└── src
│ └── lib.rs
├── client
├── Cargo.toml
├── metadata
│ └── protocol_substrate_runtime.scale
├── src
│ └── lib.rs
└── tests
│ ├── integration_tests.rs
│ └── utils.rs
├── doc
├── parachain-local.md
└── rust-setup.md
├── docker
├── Coverage.Dockerfile
├── Standalone.Dockerfile
├── readme.md
└── standalone-docker-compose.yml
├── flake.lock
├── flake.nix
├── pallets
├── asset-registry
│ ├── Cargo.toml
│ └── src
│ │ ├── benchmarking.rs
│ │ ├── lib.rs
│ │ ├── mock.rs
│ │ ├── tests.rs
│ │ ├── traits.rs
│ │ ├── types.rs
│ │ └── weights.rs
├── hasher
│ ├── Cargo.toml
│ └── src
│ │ ├── benchmarking.rs
│ │ ├── lib.rs
│ │ ├── mock.rs
│ │ ├── tests.rs
│ │ └── weights.rs
├── key-storage
│ ├── Cargo.toml
│ └── src
│ │ ├── benchmarking.rs
│ │ ├── lib.rs
│ │ ├── mock.rs
│ │ ├── tests.rs
│ │ └── weights.rs
├── linkable-tree
│ ├── Cargo.toml
│ ├── rpc
│ │ ├── Cargo.toml
│ │ ├── runtime-api
│ │ │ ├── Cargo.toml
│ │ │ └── src
│ │ │ │ └── lib.rs
│ │ └── src
│ │ │ ├── error.rs
│ │ │ └── lib.rs
│ └── src
│ │ ├── benchmarking.rs
│ │ ├── lib.rs
│ │ ├── mock.rs
│ │ ├── tests.rs
│ │ ├── types.rs
│ │ └── weights.rs
├── masp
│ ├── anonymity-mining-claims
│ │ ├── Cargo.toml
│ │ ├── firstTransactionInputs.json
│ │ ├── secondTransactionInputs.json
│ │ └── src
│ │ │ ├── lib.rs
│ │ │ ├── mock.rs
│ │ │ ├── test_utils.rs
│ │ │ └── tests.rs
│ ├── anonymity-mining-rewards
│ │ ├── Cargo.toml
│ │ └── src
│ │ │ ├── lib.rs
│ │ │ ├── mock.rs
│ │ │ └── tests.rs
│ └── claims-verifier
│ │ ├── Cargo.toml
│ │ └── src
│ │ ├── benchmarking.rs
│ │ ├── lib.rs
│ │ ├── mock.rs
│ │ ├── tests.rs
│ │ └── weights.rs
├── mixer
│ ├── Cargo.toml
│ └── src
│ │ ├── benchmarking.rs
│ │ ├── lib.rs
│ │ ├── mock.rs
│ │ ├── test_utils.rs
│ │ ├── tests.rs
│ │ ├── types.rs
│ │ ├── weights.rs
│ │ └── zk_config.rs
├── mt
│ ├── Cargo.toml
│ ├── rpc
│ │ ├── Cargo.toml
│ │ ├── runtime-api
│ │ │ ├── Cargo.toml
│ │ │ └── src
│ │ │ │ └── lib.rs
│ │ └── src
│ │ │ ├── error.rs
│ │ │ └── lib.rs
│ └── src
│ │ ├── benchmarking.rs
│ │ ├── lib.rs
│ │ ├── mock.rs
│ │ ├── tests.rs
│ │ ├── types.rs
│ │ └── weights.rs
├── relayer-registry
│ ├── Cargo.toml
│ └── src
│ │ ├── benchmarking.rs
│ │ ├── lib.rs
│ │ ├── mock.rs
│ │ ├── tests.rs
│ │ ├── types.rs
│ │ └── weights.rs
├── signature-bridge
│ ├── Cargo.toml
│ └── src
│ │ ├── benchmarking.rs
│ │ ├── lib.rs
│ │ ├── mock.rs
│ │ ├── tests.rs
│ │ └── weights.rs
├── token-wrapper-handler
│ ├── Cargo.toml
│ └── src
│ │ ├── lib.rs
│ │ ├── mock_signature_bridge.rs
│ │ └── tests_signature_bridge.rs
├── token-wrapper
│ ├── Cargo.toml
│ └── src
│ │ ├── benchmarking.rs
│ │ ├── lib.rs
│ │ ├── mock.rs
│ │ ├── tests.rs
│ │ ├── traits.rs
│ │ └── weights.rs
├── vanchor-handler
│ ├── Cargo.toml
│ └── src
│ │ ├── lib.rs
│ │ ├── mock_signature_bridge.rs
│ │ └── tests_signature_bridge.rs
├── vanchor-verifier
│ ├── Cargo.toml
│ └── src
│ │ ├── benchmarking.rs
│ │ ├── lib.rs
│ │ ├── mock.rs
│ │ ├── tests.rs
│ │ └── weights.rs
├── vanchor
│ ├── Cargo.toml
│ └── src
│ │ ├── benchmarking.rs
│ │ ├── benchmarking_utils.rs
│ │ ├── lib.rs
│ │ ├── mock.rs
│ │ ├── test_utils.rs
│ │ ├── tests.rs
│ │ ├── tests_circom.rs
│ │ ├── weights.rs
│ │ └── zerokit_utils.rs
├── verifier
│ ├── Cargo.toml
│ └── src
│ │ ├── benchmarking.rs
│ │ ├── lib.rs
│ │ ├── mock.rs
│ │ ├── tests.rs
│ │ └── weights.rs
└── xanchor
│ ├── Cargo.toml
│ └── src
│ ├── lib.rs
│ ├── mock
│ ├── mod.rs
│ ├── parachain.rs
│ └── relay_chain.rs
│ ├── tests.rs
│ └── types.rs
├── primitives
├── Cargo.toml
└── src
│ ├── field_ops
│ ├── arkworks.rs
│ └── mod.rs
│ ├── hasher.rs
│ ├── hashing
│ ├── arkworks.rs
│ ├── ethereum.rs
│ └── mod.rs
│ ├── lib.rs
│ ├── runtime.rs
│ ├── signing
│ ├── ecdsa.rs
│ └── mod.rs
│ ├── traits
│ ├── anchor.rs
│ ├── key_storage.rs
│ ├── linkable_tree.rs
│ ├── merkle_tree.rs
│ ├── mixer.rs
│ ├── mod.rs
│ ├── signature_bridge.rs
│ └── vanchor.rs
│ ├── types
│ ├── anonymity_mining.rs
│ ├── mod.rs
│ ├── runtime.rs
│ └── vanchor.rs
│ ├── utils.rs
│ ├── verifier.rs
│ └── verifying
│ ├── arkworks.rs
│ ├── circom.rs
│ └── mod.rs
├── rust-toolchain.toml
├── rustfmt.toml
├── scripts
├── build-standalone-docker.sh
├── docker_run.sh
├── fetch-fixtures.sh
├── generate-weights.sh
├── run-integration.sh
└── run-standalone.sh
├── solidity-fixtures.dvc
├── standalone
├── node
│ ├── Cargo.toml
│ ├── build.rs
│ └── src
│ │ ├── benchmarking.rs
│ │ ├── chain_spec.rs
│ │ ├── cli.rs
│ │ ├── command.rs
│ │ ├── lib.rs
│ │ ├── main.rs
│ │ ├── rpc.rs
│ │ └── service.rs
└── runtime
│ ├── Cargo.toml
│ ├── build.rs
│ └── src
│ ├── constants.rs
│ ├── impls.rs
│ ├── lib.rs
│ └── voter_bags.rs
├── substrate-fixtures.dvc
└── types
├── LICENSE
├── README.md
├── babel-config-cjs.cjs
├── package.json
├── polkadot-dev-configs
├── babel-config-cjs.cjs
├── babel-general.cjs
├── babel-plugins.cjs
├── babel-presets.cjs
└── babel-resolver.cjs
├── scripts
├── build.js
├── publish-types.js
└── updateMetadata.ts
├── src
├── index.ts
├── interfaces
│ ├── augment-api-consts.ts
│ ├── augment-api-errors.ts
│ ├── augment-api-events.ts
│ ├── augment-api-query.ts
│ ├── augment-api-rpc.ts
│ ├── augment-api-runtime.ts
│ ├── augment-api-tx.ts
│ ├── augment-api.ts
│ ├── augment-types.ts
│ ├── lookup.ts
│ ├── registry.ts
│ └── types-lookup.ts
└── metadata
│ ├── metadata.json
│ └── static-latest.ts
├── tsconfig.json
└── yarn.lock
/.devcontainer/devcontainer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "Substrate Node template",
3 | "context": "..",
4 | "settings": {
5 | "terminal.integrated.shell.linux": "/bin/bash",
6 | "lldb.executable": "/usr/bin/lldb"
7 | },
8 | "extensions": [
9 | "bungcip.better-toml",
10 | "vadimcn.vscode-lldb",
11 | "matklad.rust-analyzer"
12 | ],
13 | "forwardPorts": [
14 | 3000,
15 | 9944
16 | ],
17 | "preCreateCommand": [
18 | "cargo build",
19 | "cargo check"
20 | ],
21 | "postStartCommand": "./target/debug/node-template --dev --ws-external",
22 | "menuActions": [
23 | {
24 | "id": "polkadotjs",
25 | "label": "Open PolkadotJS Apps",
26 | "type": "external-preview",
27 | "args": [
28 | "https://polkadot.js.org/apps/?rpc=wss%3A%2F%2F/$HOST/wss"
29 | ]
30 | }
31 | ]
32 | }
--------------------------------------------------------------------------------
/.dockerignore:
--------------------------------------------------------------------------------
1 | # Generated by Cargo
2 | # will have compiled files and executables
3 | **/target/
4 | # These are backup files generated by rustfmt
5 | **/*.rs.bk
6 |
7 | .DS_Store
8 |
9 | # The cache for docker container dependency
10 | .cargo
11 |
12 | # The cache for chain data in container
13 | .local
14 | tmp
15 |
16 | local-test
17 |
18 | # NodeJS
19 | **/node_modules/
20 | docker/
21 | .github/
22 | doc/
23 |
--------------------------------------------------------------------------------
/.dvc/.gitignore:
--------------------------------------------------------------------------------
1 | /config.local
2 | /tmp
3 | /cache
4 |
--------------------------------------------------------------------------------
/.dvc/config:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tangle-network/protocol-substrate/2efe48b9544ffb6bcf0ebac5e0ebd1081ffa1dfd/.dvc/config
--------------------------------------------------------------------------------
/.dvcignore:
--------------------------------------------------------------------------------
1 | # Add patterns of files dvc should ignore, which could improve
2 | # the performance. Learn more at
3 | # https://dvc.org/doc/user-guide/dvcignore
4 |
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | root = true
2 | [*.rs]
3 | indent_style=tab
4 | indent_size=tab
5 | tab_width=4
6 | end_of_line=lf
7 | charset=utf-8
8 | trim_trailing_whitespace=true
9 | max_line_length=100
10 | insert_final_newline=true
11 |
12 | [*.yml]
13 | indent_style=space
14 | indent_size=2
15 | tab_width=8
16 | end_of_line=lf
17 |
18 | [*.sh]
19 | indent_style=space
20 | indent_size=2
21 | tab_width=8
22 | end_of_line=lf
23 |
--------------------------------------------------------------------------------
/.envrc:
--------------------------------------------------------------------------------
1 | if ! has nix_direnv_version || ! nix_direnv_version 2.3.0; then
2 | source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/2.3.0/direnvrc" "sha256-Dmd+j63L84wuzgyjITIfSxSD57Tx7v51DMxVZOsiUD8="
3 | fi
4 |
5 | watch_file flake.nix
6 | dotenv_if_exists
7 | use flake
8 | # vi: ft=sh
9 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/bug_report.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Bug report
3 | about: Create a report to help us improve
4 | title: '[BUG] '
5 | labels: 'type: bug'
6 | assignees: ''
7 |
8 | ---
9 |
10 | **Describe the bug**
11 |
12 |
13 |
14 |
15 | **To Reproduce**
16 | Steps to reproduce the behavior:
17 | 1. Go to '...'
18 | 2. Run '....'
19 | 3. See error
20 |
21 |
22 |
23 | **Log output**
24 |
25 |
26 | Log Output
27 |
28 | ```Paste log output here
29 | paste log output...
30 | ```
31 |
32 |
33 |
34 |
35 | **Expected behaviour**
36 |
37 |
38 |
39 |
40 | **Screenshots**
41 |
42 |
43 |
44 |
45 | **Environment (please complete the following information):**
46 | - OS:
47 | - Rust version(e.g. `rustc --version`)
48 | - Branch/commit
49 |
50 |
51 |
52 | **Other information and links**
53 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/checklist_issue.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Checklist
3 | about: Creates a checklist of tasks that make up a larger milestone
4 | title: '[CHECKLIST] '
5 | labels: 'type: checklist'
6 | assignees: ''
7 |
8 | ---
9 |
10 | # Overview
11 |
12 | The goal of this checklist is to...
13 |
14 | ## Checklist
15 |
16 |
17 | ### Functionality
18 | - [ ] # Issue number
19 | - [ ] # Issue number
20 | - [ ] # Issue number
21 |
22 | ### Testing
23 | - [ ] # Issue number
24 | - [ ] # Issue number
25 | - [ ] # Issue number
26 |
27 | ### Related Repos
28 | - [ ] # Issue number
29 | - [ ] # Issue number
30 | - [ ] # Issue number
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/config.yml:
--------------------------------------------------------------------------------
1 | blank_issues_enabled: true
2 | contact_links:
3 | - name: Webb Telegram
4 | url: https://t.me/webbprotocol
5 | about: Please ask questions here.
6 | - name: Webb Discord Server
7 | url: https://discord.com/invite/cv8EfJu3Tn
8 | about: Please ask and answer questions here.
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/new_issue.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: New issue
3 | about: New issue template
4 | title: ''
5 | labels: 'needs triage'
6 | assignees: ''
7 |
8 | ---
9 |
10 | **Issue summary**
11 |
12 |
13 |
14 | **Other information and links**
15 |
16 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/spec_issue.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Specification
3 | about: Create a spec for dicussion and solution discovery
4 | title: '[SPEC] '
5 | labels: 'type: spec'
6 | assignees: ''
7 |
8 | ---
9 |
10 | # Overview
11 |
12 |
13 | ## Research
14 |
15 |
16 | ## Examples
17 |
18 |
19 | # Questions/Issues
20 |
21 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/task_issue.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Task requirement
3 | about: Required tasks to complete
4 | title: '[TASK] '
5 | labels: 'type: task'
6 | assignees: ''
7 |
8 | ---
9 |
10 | **Task summary**
11 |
12 |
13 |
14 |
15 | **Specification reference**
16 |
17 | -
18 |
19 |
20 |
21 | **Other information and links**
22 |
--------------------------------------------------------------------------------
/.github/PULL_REQUEST_TEMPLATE.md:
--------------------------------------------------------------------------------
1 | **Summary of changes**
2 | Changes introduced in this pull request:
3 | -
4 |
5 |
6 | **Reference issue to close (if applicable)**
7 |
8 |
9 | Closes
10 |
--------------------------------------------------------------------------------
/.github/workflows/coverage.yaml:
--------------------------------------------------------------------------------
1 | name: ci
2 |
3 | # Controls when the action will run.
4 | on:
5 | # Triggers the workflow on push or pull request events but only for the master branch
6 | push:
7 | branches: [ main ]
8 | pull_request:
9 | branches: [ main ]
10 |
11 | # Allows you to run this workflow manually from the Actions tab
12 | workflow_dispatch:
13 |
14 | # A workflow run is made up of one or more jobs that can run sequentially or in parallel
15 | jobs:
16 | coverage:
17 | name: coverage
18 | runs-on: ubuntu-latest
19 |
20 | strategy:
21 | matrix:
22 | version:
23 | - nightly
24 | target:
25 | - x86_64-unknown-linux-gnu
26 | fail-fast: false
27 |
28 | steps:
29 | - name: Checkout repository
30 | uses: actions/checkout@v2
31 |
32 | - name: Setup DVC
33 | uses: iterative/setup-dvc@v1
34 |
35 | - name: Fetch Fixtures
36 | uses: nick-fields/retry@v2
37 | with:
38 | max_attempts: 10
39 | timeout_minutes: 30
40 | command: dvc pull -v
41 |
42 | - name: Install apt dependencies
43 | run: |
44 | sudo apt-get update && \
45 | sudo apt-get install -y clang libssl-dev llvm libudev-dev libgmp3-dev protobuf-compiler && \
46 | sudo rm -rf /var/lib/apt/lists/*
47 |
48 | - name: Rust Cache
49 | uses: Swatinem/rust-cache@v1.3.0
50 |
51 | - name: Install Tarpaulin
52 | run: cargo install cargo-tarpaulin
53 |
54 | - name: Generate code coverage
55 | run: |
56 | SKIP_WASM_BUILD=1 cargo tarpaulin --engine llvm --follow-exec --post-test-delay 10 \
57 | -p pallet-token-wrapper-handler \
58 | -p pallet-token-wrapper \
59 | -p pallet-signature-bridge \
60 | -p pallet-vanchor \
61 | -p pallet-vanchor-handler \
62 | -p pallet-mixer \
63 | -p pallet-linkable-tree \
64 | -p pallet-mt \
65 | -p pallet-verifier \
66 | -p pallet-hasher \
67 | -p pallet-asset-registry \
68 | --timeout 3600
69 |
70 | - name: Upload to codecov.io
71 | uses: codecov/codecov-action@v3
72 | with:
73 | fail_ci_if_error: true
74 | token: ${{ secrets.CODECOV_TOKEN }}
75 |
--------------------------------------------------------------------------------
/.github/workflows/image-publish.yml:
--------------------------------------------------------------------------------
1 | name: Container Image Release
2 |
3 | on:
4 | push:
5 | # Publish `main` as Container `edge` image.
6 | branches:
7 | - main
8 | # Publish `v1.2.3` tags as releases.
9 | tags:
10 | - v*
11 |
12 | jobs:
13 | push:
14 | runs-on: ubuntu-latest
15 | if: github.event_name == 'push'
16 | permissions:
17 | packages: write
18 | contents: read
19 | steps:
20 | - uses: actions/checkout@v2
21 | - name: Build Image
22 | run: ./scripts/build-standalone-docker.sh
23 | - name: Log into registry
24 | run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
25 | - name: Push image
26 | run: |
27 | IMAGE_ID=ghcr.io/${{ github.repository_owner }}/protocol-substrate-standalone-node
28 | # Change all uppercase to lowercase
29 | IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
30 | # Strip git ref prefix from version
31 | VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
32 | # Strip "v" prefix from tag name
33 | [[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
34 | # Use Docker `edge` tag convention
35 | [ "$VERSION" == "main" ] && VERSION=edge
36 | echo IMAGE_ID=$IMAGE_ID
37 | echo VERSION=$VERSION
38 | docker tag webb-tools/protocol-substrate-standalone-node $IMAGE_ID:$VERSION
39 | docker push $IMAGE_ID:$VERSION
40 |
--------------------------------------------------------------------------------
/.github/workflows/publish-docs.yml:
--------------------------------------------------------------------------------
1 | name: publish
2 |
3 | on:
4 | push:
5 | branches: [ main ]
6 | pull_request:
7 | branches: [ main ]
8 |
9 | jobs:
10 | docs:
11 | if: github.event_name == 'push' && github.event.ref == 'refs/heads/main'
12 | name: docs
13 | runs-on: ubuntu-20.04
14 | steps:
15 | - uses: actions/checkout@v2
16 |
17 | - name: Set-Up
18 | run: sudo apt install -y cmake pkg-config libssl-dev git build-essential clang libclang-dev curl protobuf-compiler
19 |
20 | - name: Install toolchain
21 | uses: dtolnay/rust-toolchain@stable
22 | with:
23 | toolchain: stable
24 |
25 | - name: Update apt repositories
26 | run: sudo apt update
27 |
28 | - name: Setup DVC
29 | uses: iterative/setup-dvc@v1
30 |
31 | - name: Fetch Fixtures
32 | run: ./scripts/fetch-fixtures.sh
33 |
34 | - name: Cache Cargo
35 | uses: actions/cache@v2
36 | with:
37 | path: |
38 | ~/.cargo/registry
39 | ~/.cargo/git
40 | ~/.cargo/bin
41 | target
42 | target/debug
43 | target/release
44 | key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
45 |
46 | - name: Build documentation
47 | run: cargo doc --release --no-deps
48 | - name: Publish documentation
49 | run: |
50 | cd target/doc
51 | git init
52 | echo '' > index.html
53 | git add .
54 | git -c user.name='ci' -c user.email='ci' commit -m 'Deploy documentation 🚀'
55 | git push -f -q https://git:${{ secrets.github_token }}@github.com/${{ github.repository }} HEAD:gh-pages
--------------------------------------------------------------------------------
/.github/workflows/publish-types.yml:
--------------------------------------------------------------------------------
1 | name: Publish Types
2 |
3 | # If changes are made to the types package.json,
4 | # Issue a new release to npm for the types package.
5 | on:
6 | push:
7 | branches:
8 | - main
9 | paths:
10 | - "types/package.json"
11 |
12 | jobs:
13 | build:
14 | runs-on: ubuntu-latest
15 | permissions:
16 | packages: write
17 | contents: read
18 | steps:
19 | - uses: actions/checkout@main
20 | with:
21 | token: ${{ secrets.GITHUB_TOKEN }}
22 | - uses: actions/setup-node@v3
23 | with:
24 | node-version: '18.x'
25 | registry-url: 'https://registry.npmjs.org'
26 | - name: Install npm dependencies
27 | run: cd types && yarn install
28 | - name: Configure Github Actions user
29 | run: |
30 | git config --global user.email "action@github.com"
31 | git config --global user.name "Github Actions"
32 | - name: Run a build
33 | run: cd types && yarn build
34 | - name: Publish the package
35 | run: cd types && yarn publish-types
36 | env:
37 | NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
38 |
--------------------------------------------------------------------------------
/.github/workflows/update-types.yml:
--------------------------------------------------------------------------------
1 | name: Bump types package
2 |
3 | # If changes are made to the types/src folder,
4 | # Create a pull request to bump the package.json
5 | on:
6 | push:
7 | branches:
8 | - main
9 | paths:
10 | - "types/src/*"
11 | - "types/package.json"
12 | - "types/yarn.lock"
13 |
14 | jobs:
15 | build:
16 | runs-on: ubuntu-latest
17 | permissions:
18 | packages: write
19 | contents: read
20 | steps:
21 | - uses: actions/checkout@main
22 | with:
23 | token: ${{ secrets.GITHUB_TOKEN }}
24 | - uses: actions/setup-node@v3
25 | with:
26 | node-version: "18.x"
27 | registry-url: "https://registry.npmjs.org"
28 | - name: Install npm dependencies
29 | run: cd types && yarn install
30 | - name: Configure Github Actions user
31 | run: |
32 | git config --global user.email "action@github.com"
33 | git config --global user.name "Github Actions"
34 | - name: Do a patch update for the package
35 | run: cd types && yarn version --patch
36 | - name: Create Pull Request
37 | uses: peter-evans/create-pull-request@v4
38 | with:
39 | commit-message: update protocol-substrate-types package version
40 | title: Update types package version
41 | branch: update-types
42 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Generated by Cargo
2 | # will have compiled files and executables
3 | **/target/
4 | # These are backup files generated by rustfmt
5 | **/*.rs.bk
6 |
7 | .DS_Store
8 |
9 | # The cache for docker container dependency
10 | .cargo
11 |
12 | # The cache for chain data in container
13 | .local
14 |
15 | #vscode files
16 | .vscode/
17 | .vscode/launch.json
18 |
19 | .idea/
20 |
21 | *.iml
22 | /substrate-fixtures
23 | /solidity-fixtures
24 | **/node_modules
25 | types/build
26 | types/ts-types
27 | .direnv
28 |
--------------------------------------------------------------------------------
/.taplo.toml:
--------------------------------------------------------------------------------
1 | exclude = ["target/*"]
2 | [formatting]
3 | array_auto_collapse = false
4 | array_auto_expand = false
5 | reorder_keys = true
6 |
--------------------------------------------------------------------------------
/Cargo.toml:
--------------------------------------------------------------------------------
1 | [profile.release]
2 | lto = "thin"
3 | panic = "unwind"
4 | strip = "symbols"
5 |
6 | [profile.dev]
7 | debug = 0
8 | strip = "symbols"
9 |
10 | [workspace]
11 | members = [
12 | "client",
13 | "primitives",
14 | "pallets/masp/anonymity-mining-rewards",
15 | "pallets/masp/anonymity-mining-claims",
16 | "pallets/masp/claims-verifier",
17 | "pallets/asset-registry",
18 | "pallets/hasher",
19 | "pallets/verifier",
20 | "pallets/mt",
21 | "pallets/linkable-tree",
22 | "pallets/mixer",
23 | "pallets/signature-bridge",
24 | "pallets/vanchor",
25 | "pallets/vanchor-handler",
26 | "pallets/vanchor-verifier",
27 | # "pallets/xanchor",
28 | "pallets/token-wrapper",
29 | "pallets/token-wrapper-handler",
30 | "pallets/relayer-registry",
31 | "pallets/key-storage",
32 | "standalone/*",
33 | "circom-proving",
34 | ]
35 |
--------------------------------------------------------------------------------
/assets/w3f.jpeg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tangle-network/protocol-substrate/2efe48b9544ffb6bcf0ebac5e0ebd1081ffa1dfd/assets/w3f.jpeg
--------------------------------------------------------------------------------
/assets/webb_banner_dark.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tangle-network/protocol-substrate/2efe48b9544ffb6bcf0ebac5e0ebd1081ffa1dfd/assets/webb_banner_dark.png
--------------------------------------------------------------------------------
/assets/webb_banner_light.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tangle-network/protocol-substrate/2efe48b9544ffb6bcf0ebac5e0ebd1081ffa1dfd/assets/webb_banner_light.png
--------------------------------------------------------------------------------
/circom-proving/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | edition = "2021"
3 | name = "circom-proving"
4 | version = "0.1.0"
5 |
6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7 |
8 | [dependencies]
9 | ark-bn254 = { version = "0.3.0" }
10 | ark-circom = { git = "https://github.com/vacp2p/ark-circom", branch = "wasm", default-features = false, features = ["circom-2"] }
11 | ark-ec = { version = "^0.3.0", default-features = false }
12 | ark-ff = { version = "0.3.0", default-features = false, features = ["asm"] }
13 | # ark-groth16 = { version = "^0.3.0", default-features = false }
14 | ark-groth16 = { git = "https://github.com/arkworks-rs/groth16", rev = "765817f", default-features = false, features = ["parallel"] }
15 | ark-relations = { version = "^0.3.0", default-features = false }
16 | ark-serialize = { version = "^0.3.0", default-features = false, features = ["derive"] }
17 | ark-std = { version = "^0.3.0", default-features = false }
18 | num-bigint = { version = "0.4", default-features = false, features = ["rand"] }
19 | # For ark-circom
20 | ark-crypto-primitives = { version = "^0.3.0", features = ["r1cs"], default-features = false }
21 | arkworks-native-gadgets = { version = "1.2.0", default-features = false }
22 | cfg-if = "1.0"
23 | color-eyre = "0.6.1"
24 | num-traits = "0.2.11"
25 | once_cell = "1.14.0"
26 | serde_json = "1.0.48"
27 | thiserror = "1.0.0"
28 | wasmer = { version = "2.3.0", default-features = false }
29 |
30 | [features]
31 | default = ["wasmer/sys-default"]
32 |
--------------------------------------------------------------------------------
/client/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | edition = "2021"
3 | name = "webb-client"
4 | version = "0.1.0"
5 |
6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7 |
8 | [dependencies]
9 | codec = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive", "full", "bit-vec"] }
10 | frame-support = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
11 | frame-system = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
12 | subxt = { version = "0.25.0" }
13 |
14 | [dev-dependencies]
15 | hex = "0.4"
16 | scale-info = { version = "2.1.1", default-features = false, features = ["derive"] }
17 | serde = { version = "1.0.119" }
18 | sp-core = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
19 | sp-keyring = { default-features = false, version = "7.0.0" }
20 | sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
21 | tokio = { version = "1.17.0", features = ["full"] }
22 |
23 | # arkworks related deps
24 | ark-bls12-381 = { version = "^0.3.0", default-features = false, features = ["curve"] }
25 | ark-bn254 = { version = "^0.3.0", default-features = false, features = ["curve"] }
26 | ark-circom = { git = "https://github.com/vacp2p/ark-circom", branch = "wasm", default-features = false, features = ["circom-2"] }
27 | ark-crypto-primitives = { version = "^0.3.0", features = ["r1cs"], default-features = false }
28 | ark-ec = { version = "^0.3.0", default-features = false }
29 | ark-ff = { version = "^0.3.0", default-features = false }
30 | ark-groth16 = { git = "https://github.com/arkworks-rs/groth16", rev = "765817f", features = ["parallel"] }
31 | ark-relations = { version = "^0.3.0", default-features = false }
32 | ark-serialize = { version = "^0.3.0", default-features = false, features = ["derive"] }
33 | ark-std = { version = "^0.3.0", default-features = false }
34 | arkworks-setups = { version = "1.2.1", features = ["r1cs"], default-features = false }
35 | frame-benchmarking = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
36 | num-bigint = { version = "0.4", default-features = false, features = ["rand"] }
37 | orml-currencies = { git = "https://github.com/open-web3-stack/open-runtime-module-library.git", branch = "polkadot-v0.9.39", default-features = false }
38 | orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library.git", branch = "polkadot-v0.9.39", default-features = false }
39 | pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
40 | rand = "0.8.4"
41 | sp-io = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
42 |
43 | # For ark-circom
44 | cfg-if = "1.0"
45 | color-eyre = "0.6.1"
46 | num-traits = "0.2.11"
47 | once_cell = "1.14.0"
48 | serde_json = "1.0.48"
49 | thiserror = "1.0.0"
50 | wasmer = { version = "2.3.0", default-features = false }
51 |
52 | # Webb deps
53 | arkworks-native-gadgets = { version = "1.2.0", default-features = false }
54 | webb-primitives = { path = "../primitives", features = ["hashing", "verifying", "field_ops"] }
55 | circom-proving = { path = "../circom-proving", default-features = false }
56 |
57 | [features]
58 | default = ["std", "wasmer/sys-default"]
59 | std = [
60 | "frame-support/std",
61 | "frame-system/std",
62 | "frame-benchmarking/std",
63 | ]
64 | wasm = ["wasmer/js", "wasmer/std"]
65 |
--------------------------------------------------------------------------------
/client/metadata/protocol_substrate_runtime.scale:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tangle-network/protocol-substrate/2efe48b9544ffb6bcf0ebac5e0ebd1081ffa1dfd/client/metadata/protocol_substrate_runtime.scale
--------------------------------------------------------------------------------
/client/src/lib.rs:
--------------------------------------------------------------------------------
1 | #![allow(clippy::too_many_arguments)]
2 | #[subxt::subxt(runtime_metadata_path = "metadata/protocol_substrate_runtime.scale")]
3 | pub mod webb_runtime {}
4 |
--------------------------------------------------------------------------------
/doc/rust-setup.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Installation
3 | ---
4 |
5 | This page will guide you through the steps needed to prepare a computer for development with the
6 | Substrate Node Template. Since Substrate is built with
7 | [the Rust programming language](https://www.rust-lang.org/), the first thing you will need to do is
8 | prepare the computer for Rust development - these steps will vary based on the computer's operating
9 | system. Once Rust is configured, you will use its toolchains to interact with Rust projects; the
10 | commands for Rust's toolchains will be the same for all supported, Unix-based operating systems.
11 |
12 | ## Unix-Based Operating Systems
13 |
14 | Substrate development is easiest on Unix-based operating systems like macOS or Linux. The examples
15 | in the Substrate [Tutorials](https://substrate.dev/tutorials) and [Recipes](https://substrate.dev/recipes/)
16 | use Unix-style terminals to demonstrate how to interact with Substrate from the command line.
17 |
18 | ### macOS
19 |
20 | Open the Terminal application and execute the following commands:
21 |
22 | ```bash
23 | # Install Homebrew if necessary https://brew.sh/
24 | /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
25 |
26 | # Make sure Homebrew is up-to-date, install openssl and cmake
27 | brew update
28 | brew install openssl cmake
29 | ```
30 |
31 | ### Ubuntu/Debian
32 |
33 | Use a terminal shell to execute the following commands:
34 |
35 | ```bash
36 | sudo apt update
37 | # May prompt for location information
38 | sudo apt install -y cmake pkg-config libssl-dev git build-essential clang libclang-dev curl
39 | ```
40 |
41 | ### Arch Linux
42 |
43 | Run these commands from a terminal:
44 |
45 | ```bash
46 | pacman -Syu --needed --noconfirm cmake gcc openssl-1.0 pkgconf git clang
47 | export OPENSSL_LIB_DIR="/usr/lib/openssl-1.0"
48 | export OPENSSL_INCLUDE_DIR="/usr/include/openssl-1.0"
49 | ```
50 |
51 | ### Fedora/RHEL/CentOS
52 |
53 | Use a terminal to run the following commands:
54 |
55 | ```bash
56 | # Update
57 | sudo dnf update
58 | # Install packages
59 | sudo dnf install cmake pkgconfig rocksdb rocksdb-devel llvm git libcurl libcurl-devel curl-devel clang
60 | ```
61 |
62 | ## Rust Developer Environment
63 |
64 | This project uses [`rustup`](https://rustup.rs/) to help manage the Rust toolchain. First install
65 | and configure `rustup`:
66 |
67 | ```bash
68 | # Install
69 | curl https://sh.rustup.rs -sSf | sh
70 | # Configure
71 | source ~/.cargo/env
72 | ```
73 |
74 | Finally, configure the Rust toolchain:
75 |
76 | ```bash
77 | rustup default stable
78 | rustup update nightly
79 | rustup update stable
80 | rustup target add wasm32-unknown-unknown --toolchain nightly
81 | ```
82 |
--------------------------------------------------------------------------------
/docker/Coverage.Dockerfile:
--------------------------------------------------------------------------------
1 | FROM rust:1
2 | WORKDIR /webb
3 |
4 | # Install Required Packages
5 | RUN apt-get update && \
6 | apt-get install -y git pkg-config clang curl libssl-dev llvm libudev-dev libgmp3-dev && \
7 | rm -rf /var/lib/apt/lists/*
8 |
9 | COPY . .
10 |
11 | RUN rustup default nightly
12 |
13 | RUN cargo install cargo-tarpaulin
14 |
15 | # Build Standalone Node.
16 | CMD SKIP_WASM_BUILD=1 cargo +nightly tarpaulin --out Xml \
17 | -p webb-standalone-runtime \
18 | -p pallet-token-wrapper-handler \
19 | -p pallet-token-wrapper \
20 | -p pallet-vanchor \
21 | -p pallet-vanchor-handler \
22 | -p pallet-signature-bridge \
23 | -p pallet-mixer \
24 | -p pallet-linkable-tree \
25 | -p pallet-mt \
26 | -p pallet-verifier \
27 | -p pallet-hasher \
28 | -p pallet-asset-registry \
29 | --timeout 3600
30 |
--------------------------------------------------------------------------------
/docker/Standalone.Dockerfile:
--------------------------------------------------------------------------------
1 | # Use a specific version tag for the alpine base image
2 | FROM rust:1 AS base
3 |
4 | # Install required packages
5 | RUN apt-get update && \
6 | apt-get install --yes git python3 python3-pip pkg-config clang curl libssl-dev llvm libudev-dev libgmp3-dev protobuf-compiler libc6 && \
7 | rm -rf /var/lib/apt/lists/*
8 |
9 | # Create a non-root user to run
10 | RUN adduser --uid 1000 --ingroup users --disabled-password --gecos "" --home /webb webb \
11 | && mkdir -p /data /webb/.local/share/webb \
12 | && chown -R webb:users /data /webb/.local/share/webb \
13 | && ln -s /data /webb/.local/share/webb
14 |
15 |
16 | # Set the user and working directory
17 | USER webb
18 | WORKDIR /webb
19 |
20 | # Use a multi-stage build to reduce the size of the final image
21 | FROM rust:1 AS builder
22 |
23 | # Install required packages
24 | RUN apt-get update && \
25 | apt-get install -y git python3 python3-pip pkg-config clang curl libssl-dev llvm libudev-dev libgmp3-dev protobuf-compiler libc6 && \
26 | rm -rf /var/lib/apt/lists/*
27 |
28 | RUN pip3 install dvc
29 |
30 | # Copy the source code into the container
31 | WORKDIR /webb
32 | COPY . .
33 |
34 | # Use "RUN" instructions to combine multiple commands into a single layer
35 | RUN dvc pull -v \
36 | && RUST_BACKTRACE=1 cargo build --release -p webb-standalone-node --verbose
37 |
38 | # Use the final stage to reduce the size of the final image
39 | FROM base
40 |
41 | # Create the /data directory and set permissions
42 | USER root
43 | RUN mkdir -p /data \
44 | && chown webb:users /data
45 | USER webb
46 |
47 | # Copy the binary into the final image
48 | COPY --from=builder /webb/target/release/webb-standalone-node /usr/local/bin
49 |
50 | # Expose ports and volume
51 | EXPOSE 30333 9933 9944 9615 33334
52 | VOLUME ["/data"]
53 |
54 | # Set the user and working directory
55 | USER webb
56 | WORKDIR /webb
57 |
58 | # Sanity check
59 | CMD ["/usr/local/bin/webb-standalone-node", "--version"]
60 |
--------------------------------------------------------------------------------
/docker/readme.md:
--------------------------------------------------------------------------------
1 | # Running Docker compose
2 | ```bash
3 | ## setup the nodes
4 | docker-compose -f standalone-docker-compose.yml up
5 | ## Remove the setup
6 | docker-compose -f standalone-docker-compose.yml down
7 | ```
8 |
9 | # Todos
10 | - [ ] Adding .env file for custom ports mapping
11 | - [ ] Adding volumes for nodes storage
12 |
--------------------------------------------------------------------------------
/docker/standalone-docker-compose.yml:
--------------------------------------------------------------------------------
1 | version: '3.3'
2 | services:
3 | main-node:
4 | container_name: main-node
5 | restart: "no"
6 | image: ghcr.io/webb-tools/protocol-substrate-standalone-node:edge
7 | networks:
8 | - webb-network
9 | entrypoint: webb-standalone-node --dev --alice --node-key 0000000000000000000000000000000000000000000000000000000000000001 --ws-port=9944 --rpc-cors all --ws-external
10 | ports:
11 | - 9944:9944
12 | - 30333:30333
13 | validator-node:
14 | container_name: validator-node
15 | restart: "no"
16 | networks:
17 | - webb-network
18 | image: ghcr.io/webb-tools/protocol-substrate-standalone-node:edge
19 | entrypoint: webb-standalone-node --dev --bob --port 33334 --tmp --bootnodes /ip4/127.0.0.1/tcp/30333/p2p/12D3KooWEyoppNCUx8Yx66oV9fJnriXwCcXwDDUA2kj6vnc6iDEp --ws-port=9993
20 | ports:
21 | - 9993:9993
22 | - 33334:33334
23 | networks:
24 | webb-network:
25 | driver: bridge
--------------------------------------------------------------------------------
/flake.lock:
--------------------------------------------------------------------------------
1 | {
2 | "nodes": {
3 | "flake-utils": {
4 | "inputs": {
5 | "systems": "systems"
6 | },
7 | "locked": {
8 | "lastModified": 1685518550,
9 | "narHash": "sha256-o2d0KcvaXzTrPRIo0kOLV0/QXHhDQ5DTi+OxcjO8xqY=",
10 | "owner": "numtide",
11 | "repo": "flake-utils",
12 | "rev": "a1720a10a6cfe8234c0e93907ffe81be440f4cef",
13 | "type": "github"
14 | },
15 | "original": {
16 | "owner": "numtide",
17 | "repo": "flake-utils",
18 | "type": "github"
19 | }
20 | },
21 | "nixpkgs": {
22 | "locked": {
23 | "lastModified": 1686519857,
24 | "narHash": "sha256-VkBhuq67aXXiCoEmicziuDLUPPjeOTLQoj6OeVai5zM=",
25 | "owner": "NixOS",
26 | "repo": "nixpkgs",
27 | "rev": "6b1b72c0f887a478a5aac355674ff6df0fc44f44",
28 | "type": "github"
29 | },
30 | "original": {
31 | "owner": "NixOS",
32 | "ref": "nixpkgs-unstable",
33 | "repo": "nixpkgs",
34 | "type": "github"
35 | }
36 | },
37 | "root": {
38 | "inputs": {
39 | "flake-utils": "flake-utils",
40 | "nixpkgs": "nixpkgs",
41 | "rust-overlay": "rust-overlay"
42 | }
43 | },
44 | "rust-overlay": {
45 | "inputs": {
46 | "flake-utils": [
47 | "flake-utils"
48 | ],
49 | "nixpkgs": [
50 | "nixpkgs"
51 | ]
52 | },
53 | "locked": {
54 | "lastModified": 1686537156,
55 | "narHash": "sha256-mJD80brS6h6P4jzwdKID0S9RvfyiruxgJbXvPPIDqF0=",
56 | "owner": "oxalica",
57 | "repo": "rust-overlay",
58 | "rev": "e75da5cfc7da874401decaa88f4ccb3b4d64d20d",
59 | "type": "github"
60 | },
61 | "original": {
62 | "owner": "oxalica",
63 | "repo": "rust-overlay",
64 | "type": "github"
65 | }
66 | },
67 | "systems": {
68 | "locked": {
69 | "lastModified": 1681028828,
70 | "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
71 | "owner": "nix-systems",
72 | "repo": "default",
73 | "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
74 | "type": "github"
75 | },
76 | "original": {
77 | "owner": "nix-systems",
78 | "repo": "default",
79 | "type": "github"
80 | }
81 | }
82 | },
83 | "root": "root",
84 | "version": 7
85 | }
86 |
--------------------------------------------------------------------------------
/flake.nix:
--------------------------------------------------------------------------------
1 | {
2 | description = "Protocol Substrate development environment";
3 | inputs = {
4 | nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
5 | flake-utils.url = "github:numtide/flake-utils";
6 | # Rust
7 | rust-overlay = {
8 | url = "github:oxalica/rust-overlay";
9 | inputs = {
10 | nixpkgs.follows = "nixpkgs";
11 | flake-utils.follows = "flake-utils";
12 | };
13 | };
14 | };
15 |
16 | outputs = { self, nixpkgs, rust-overlay, flake-utils }:
17 | flake-utils.lib.eachDefaultSystem (system:
18 | let
19 | overlays = [ (import rust-overlay) ];
20 | pkgs = import nixpkgs {
21 | inherit system overlays;
22 | };
23 | lib = pkgs.lib;
24 | toolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
25 | in
26 | {
27 | devShells.default = pkgs.mkShell {
28 | name = "protocol-substrate";
29 | nativeBuildInputs = [
30 | pkgs.protobuf
31 | pkgs.pkg-config
32 | # Needed for rocksdb-sys
33 | pkgs.clang
34 | pkgs.libclang.lib
35 | pkgs.rustPlatform.bindgenHook
36 | # Mold Linker for faster builds (only on Linux)
37 | (lib.optionals pkgs.stdenv.isLinux pkgs.mold)
38 | ];
39 | buildInputs = [
40 | # Used for DVC
41 | # use `pipx run dvc ` instead
42 | pkgs.python311
43 | pkgs.python311Packages.pipx
44 | # We want the unwrapped version, wrapped comes with nixpkgs' toolchain
45 | pkgs.rust-analyzer-unwrapped
46 | # Nodejs for test suite
47 | pkgs.nodePackages.typescript-language-server
48 | pkgs.nodejs_18
49 | pkgs.nodePackages.yarn
50 | # Finally the toolchain
51 | toolchain
52 | ];
53 | packages = [
54 | pkgs.cargo-nextest
55 | ];
56 | # Environment variables
57 | RUST_SRC_PATH = "${toolchain}/lib/rustlib/src/rust/library";
58 | };
59 | });
60 | }
61 |
--------------------------------------------------------------------------------
/pallets/asset-registry/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | authors = ["GalacticCouncil"]
3 | description = "Pallet for asset registry management"
4 | edition = "2018"
5 | homepage = "https://github.com/galacticcouncil/basilisk-node"
6 | license = "Apache 2.0"
7 | name = "pallet-asset-registry"
8 | repository = "https://github.com/galacticcouncil/basilisk-node"
9 | version = "0.1.0"
10 |
11 | [package.metadata.docs.rs]
12 | targets = ["x86_64-unknown-linux-gnu"]
13 |
14 | [dependencies]
15 | codec = { default-features = false, features = ["derive", "max-encoded-len"], package = "parity-scale-codec", version = "3" }
16 | primitive-types = { default-features = false, version = "0.8.0" }
17 | scale-info = { version = "2.1.1", default-features = false, features = ["derive"] }
18 | serde = { features = ["derive"], optional = true, version = "1.0.101" }
19 |
20 | # ORML dependencies
21 | orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library.git", branch = "polkadot-v0.9.39", default-features = false }
22 |
23 | # Substrate dependencies
24 | frame-support = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
25 | frame-system = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
26 | sp-arithmetic = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
27 | sp-core = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
28 | sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
29 | sp-std = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
30 |
31 | frame-benchmarking = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39", optional = true }
32 | frame-system-benchmarking = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39", optional = true }
33 | sp-api = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39", optional = true }
34 |
35 | [dev-dependencies]
36 | polkadot-xcm = { package = "xcm", git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.39", default-features = false }
37 | sp-io = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
38 | webb-primitives = { path = "../../primitives", default-features = false }
39 |
40 | [features]
41 | default = ["std"]
42 | runtime-benchmarks = [
43 | "frame-benchmarking",
44 | "frame-system/runtime-benchmarks",
45 | "frame-support/runtime-benchmarks",
46 | ]
47 | std = [
48 | "serde",
49 | "scale-info/std",
50 | "codec/std",
51 | "frame-support/std",
52 | "frame-system/std",
53 | "webb-primitives/std",
54 | "sp-runtime/std",
55 | "sp-core/std",
56 | "sp-std/std",
57 | "sp-api/std",
58 | "sp-arithmetic/std",
59 | ]
60 |
--------------------------------------------------------------------------------
/pallets/asset-registry/src/traits.rs:
--------------------------------------------------------------------------------
1 | #![allow(clippy::ptr_arg, clippy::type_complexity)]
2 | use crate::*;
3 | use frame_support::dispatch::fmt::Debug;
4 |
5 | pub trait Registry<
6 | AssetId,
7 | AssetName,
8 | Balance,
9 | BoundedString,
10 | MaxAssetIdInPool: Get + Clone + Debug + Eq + PartialEq,
11 | Error,
12 | >
13 | {
14 | fn get_by_id(
15 | id: AssetId,
16 | ) -> Result, Error>;
17 |
18 | fn exists(name: AssetId) -> bool;
19 |
20 | fn retrieve_asset(name: &AssetName) -> Result;
21 |
22 | fn create_asset(name: &AssetName, existential_deposit: Balance) -> Result;
23 |
24 | fn get_or_create_asset(
25 | name: AssetName,
26 | existential_deposit: Balance,
27 | ) -> Result {
28 | if let Ok(asset_id) = Self::retrieve_asset(&name) {
29 | Ok(asset_id)
30 | } else {
31 | Self::create_asset(&name, existential_deposit)
32 | }
33 | }
34 | }
35 |
36 | pub trait ShareTokenRegistry<
37 | AssetId,
38 | AssetName,
39 | Balance,
40 | BoundedString,
41 | MaxAssetIdInPool: Get + Clone + Debug + Eq + PartialEq,
42 | Error,
43 | >: Registry
44 | {
45 | fn retrieve_shared_asset(name: &AssetName, assets: &[AssetId]) -> Result;
46 |
47 | fn create_shared_asset(
48 | name: &AssetName,
49 | assets: &[AssetId],
50 | existential_deposit: Balance,
51 | ) -> Result;
52 |
53 | fn get_or_create_shared_asset(
54 | name: AssetName,
55 | assets: Vec,
56 | existential_deposit: Balance,
57 | ) -> Result {
58 | if let Ok(asset_id) = Self::retrieve_shared_asset(&name, &assets) {
59 | Ok(asset_id)
60 | } else {
61 | Self::create_shared_asset(&name, &assets, existential_deposit)
62 | }
63 | }
64 |
65 | fn contains_asset(pool_share_id: AssetId, asset_id: AssetId) -> bool;
66 | fn add_asset_to_existing_pool(name: &Vec, asset_id: AssetId) -> Result;
67 | fn delete_asset_from_existing_pool(name: &Vec, asset_id: AssetId)
68 | -> Result;
69 | }
70 |
--------------------------------------------------------------------------------
/pallets/asset-registry/src/types.rs:
--------------------------------------------------------------------------------
1 | use frame_support::{dispatch::fmt::Debug, pallet_prelude::*, BoundedVec};
2 | use scale_info::TypeInfo;
3 |
4 | #[cfg(feature = "std")]
5 | use serde::{Deserialize, Serialize};
6 |
7 | #[derive(Encode, Decode, Eq, PartialEq, Clone, RuntimeDebug, TypeInfo, MaxEncodedLen)]
8 | #[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
9 | pub enum AssetType + Clone + Debug + Eq + PartialEq> {
10 | Token,
11 | PoolShare(BoundedVec),
12 | }
13 |
14 | #[derive(Encode, Decode, Eq, PartialEq, Clone, RuntimeDebug, TypeInfo, MaxEncodedLen)]
15 | #[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
16 | pub struct AssetDetails<
17 | AssetId,
18 | Balance,
19 | BoundedString,
20 | MaxAssetIdInPool: Get + Clone + Debug + Eq + PartialEq,
21 | > {
22 | /// The name of this asset. Limited in length by `StringLimit`.
23 | pub name: BoundedString,
24 |
25 | pub asset_type: AssetType,
26 |
27 | pub existential_deposit: Balance,
28 |
29 | pub locked: bool,
30 | }
31 |
32 | #[derive(Clone, Encode, Decode, Eq, PartialEq, Default, RuntimeDebug, TypeInfo, MaxEncodedLen)]
33 | pub struct AssetMetadata {
34 | /// The ticker symbol for this asset. Limited in length by `StringLimit`.
35 | pub symbol: BoundedString,
36 | /// The number of decimals this asset uses to represent one unit.
37 | pub decimals: u8,
38 | }
39 |
--------------------------------------------------------------------------------
/pallets/asset-registry/src/weights.rs:
--------------------------------------------------------------------------------
1 | // This file is part of HydraDX-node.
2 |
3 | // Copyright (C) 2021 Intergalactic Ltd.
4 | // SPDX-License-Identifier: Apache-2.0
5 |
6 | // Licensed under the Apache License, Version 2.0 (the "License");
7 | // you may not use this file except in compliance with the License.
8 | // You may obtain a copy of the License at
9 | //
10 | // http://www.apache.org/licenses/LICENSE-2.0
11 | //
12 | // Unless required by applicable law or agreed to in writing, software
13 | // distributed under the License is distributed on an "AS IS" BASIS,
14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | // See the License for the specific language governing permissions and
16 | // limitations under the License.
17 |
18 | //! Autogenerated weights for asset-registry
19 | //!
20 | //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 3.0.0
21 | //! DATE: 2021-06-16, STEPS: [5, ], REPEAT: 20, LOW RANGE: [], HIGH RANGE: []
22 | //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB
23 | //! CACHE: 128
24 |
25 | // Executed Command:
26 | // target/release/basilisk
27 | // benchmark
28 | // --pallet=asset-registry
29 | // --chain=dev
30 | // --steps=5
31 | // --repeat=20
32 | // --extrinsic=*
33 | // --execution=wasm
34 | // --wasm-execution=compiled
35 | // --heap-pages=496
36 | // --template=.maintain/pallet-weight-template.hbs
37 | // --output=lbp.rs
38 |
39 | #![allow(unused_parens)]
40 | #![allow(unused_imports)]
41 |
42 | use frame_support::{
43 | traits::Get,
44 | weights::{constants::RocksDbWeight, Weight},
45 | };
46 | use sp_std::marker::PhantomData;
47 |
48 | pub trait WeightInfo {
49 | fn register() -> Weight;
50 | fn update() -> Weight;
51 | fn set_metadata() -> Weight;
52 | fn set_location() -> Weight;
53 | }
54 |
55 | pub struct WebbWeight(PhantomData);
56 |
57 | impl WeightInfo for WebbWeight {
58 | fn register() -> Weight {
59 | Weight::from_ref_time(0)
60 | }
61 |
62 | fn update() -> Weight {
63 | Weight::from_ref_time(0)
64 | }
65 |
66 | fn set_metadata() -> Weight {
67 | Weight::from_ref_time(0)
68 | }
69 |
70 | fn set_location() -> Weight {
71 | Weight::from_ref_time(0)
72 | }
73 | }
74 |
75 | // For backwards compatibility and tests
76 | impl WeightInfo for () {
77 | fn register() -> Weight {
78 | Weight::from_ref_time(0)
79 | }
80 |
81 | fn update() -> Weight {
82 | Weight::from_ref_time(0)
83 | }
84 |
85 | fn set_metadata() -> Weight {
86 | Weight::from_ref_time(0)
87 | }
88 |
89 | fn set_location() -> Weight {
90 | Weight::from_ref_time(0)
91 | }
92 | }
93 |
--------------------------------------------------------------------------------
/pallets/hasher/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | authors = ["Webb Technologies Inc."]
3 | description = "Pallet that provides a single hash function + parameters for use in other pallets."
4 | edition = "2021"
5 | homepage = "https://substrate.dev"
6 | license = "Unlicense"
7 | name = "pallet-hasher"
8 | repository = "https://github.com/webb-tools/protocol-substrate"
9 | version = "1.0.0"
10 |
11 | [package.metadata.docs.rs]
12 | targets = ["x86_64-unknown-linux-gnu"]
13 |
14 | [dependencies]
15 | codec = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive", "max-encoded-len"] }
16 | scale-info = { version = "2.1.1", default-features = false, features = ["derive"] }
17 |
18 | frame-support = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
19 | frame-system = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
20 | sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
21 | sp-std = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
22 | webb-primitives = { path = "../../primitives", default-features = false }
23 |
24 | #Optional dependencies
25 | frame-benchmarking = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39", optional = true }
26 |
27 | [dev-dependencies]
28 | ark-bls12-381 = { version = "^0.3.0", default-features = false, features = ["curve"] }
29 | ark-bn254 = { version = "^0.3.0", default-features = false, features = ["curve"] }
30 | ark-crypto-primitives = { version = "^0.3.0", features = ["r1cs"], default-features = false }
31 | ark-ec = { version = "^0.3.0", default-features = false }
32 | ark-ff = { version = "^0.3.0", default-features = false }
33 | ark-relations = { version = "^0.3.0", default-features = false }
34 | ark-serialize = { version = "^0.3.0", default-features = false, features = ["derive"] }
35 | ark-std = { version = "^0.3.0", default-features = false }
36 | arkworks-setups = { version = "1.2.1", features = ["r1cs"], default-features = false }
37 | hex = "0.4"
38 | hex-literal = "0.2.1"
39 | pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
40 | serde = { version = "1.0.119" }
41 | sp-core = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
42 | sp-io = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
43 | sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
44 |
45 | [features]
46 | default = ["std"]
47 | runtime-benchmarks = [
48 | "frame-benchmarking",
49 | "frame-system/runtime-benchmarks",
50 | "frame-support/runtime-benchmarks",
51 | ]
52 | std = [
53 | "codec/std",
54 | "frame-support/std",
55 | "frame-system/std",
56 | "sp-runtime/std",
57 | "sp-std/std",
58 | "webb-primitives/std",
59 | "webb-primitives/hashing",
60 | ]
61 |
--------------------------------------------------------------------------------
/pallets/hasher/src/benchmarking.rs:
--------------------------------------------------------------------------------
1 | // This file is part of Webb.
2 |
3 | // Copyright (C) 2021-2023 Webb Technologies Inc.
4 | // SPDX-License-Identifier: Apache-2.0
5 |
6 | // Licensed under the Apache License, Version 2.0 (the "License");
7 | // you may not use this file except in compliance with the License.
8 | // You may obtain a copy of the License at
9 | //
10 | // http://www.apache.org/licenses/LICENSE-2.0
11 | //
12 | // Unless required by applicable law or agreed to in writing, software
13 | // distributed under the License is distributed on an "AS IS" BASIS,
14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | // See the License for the specific language governing permissions and
16 | // limitations under the License.
17 |
18 | //! Hasher pallet benchmarking.
19 |
20 | #![cfg(feature = "runtime-benchmarks")]
21 |
22 | use super::*;
23 | use crate::Pallet;
24 | use frame_benchmarking::{
25 | account, benchmarks_instance_pallet, impl_benchmark_test_suite, whitelist_account,
26 | whitelisted_caller,
27 | };
28 | use frame_support::traits::Currency;
29 | use frame_system::RawOrigin;
30 | use sp_runtime::traits::Bounded;
31 | use webb_primitives::types::DepositDetails;
32 | fn assert_last_event, I: 'static>(generic_event: >::RuntimeEvent) {
33 | frame_system::Pallet::::assert_last_event(generic_event.into());
34 | }
35 |
36 | const SEED: u32 = 0;
37 | // Based on parameters generated from these functions below using the
38 | // arkworks_gadgets package, 16k was the max parameter length, so it's safe to
39 | // benchmark with 20k
40 | // poseidon_bls381_x5_5 poseidon_bn254_x3_5
41 | // poseidon_circom_bn254_x5_5
42 | // poseidon_circom_bn254_x5_3
43 | // poseidon_bls381_x3_5
44 | // poseidon_circom_bn254_x5_5
45 | // poseidon_circom_bn254_x5_3
46 | const MAX_PARAMETER_LENGTH: u32 = 10000;
47 |
48 | benchmarks_instance_pallet! {
49 | force_set_parameters {
50 | let c in 0..MAX_PARAMETER_LENGTH;
51 | let depositor: T::AccountId = account("depositor", 0, SEED);
52 | let parameters = vec![0u8;c as usize];
53 | }: _(RawOrigin::Root, parameters.clone().try_into().unwrap())
54 | verify {
55 | assert_eq!(Pallet::::parameters(), parameters);
56 | }
57 | }
58 |
59 | impl_benchmark_test_suite!(Pallet, crate::mock::new_test_ext(), crate::mock::Test);
60 |
--------------------------------------------------------------------------------
/pallets/hasher/src/mock.rs:
--------------------------------------------------------------------------------
1 | use super::*;
2 | use crate::{self as pallet_hasher};
3 |
4 | use frame_support::parameter_types;
5 | use frame_system as system;
6 | use sp_core::H256;
7 | use sp_runtime::{
8 | testing::Header,
9 | traits::{BlakeTwo256, ConstU32, IdentityLookup},
10 | };
11 | use sp_std::convert::{TryFrom, TryInto};
12 | pub use webb_primitives::hasher::{HasherModule, InstanceHasher};
13 | use webb_primitives::AccountId;
14 |
15 | type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic;
16 | type Block = frame_system::mocking::MockBlock;
17 |
18 | // Configure a mock runtime to test the pallet.
19 | frame_support::construct_runtime!(
20 | pub enum Test where
21 | Block = Block,
22 | NodeBlock = Block,
23 | UncheckedExtrinsic = UncheckedExtrinsic,
24 | {
25 | System: frame_system::{Pallet, Call, Config, Storage, Event},
26 | DefaultPalletHasher: pallet_hasher::{Pallet, Call, Storage, Event, Config},
27 | Balances: pallet_balances::{Pallet, Call, Storage, Event},
28 | }
29 | );
30 |
31 | parameter_types! {
32 | pub const BlockHashCount: u64 = 250;
33 | pub const SS58Prefix: u8 = 42;
34 | }
35 |
36 | impl system::Config for Test {
37 | type AccountData = pallet_balances::AccountData;
38 | type AccountId = AccountId;
39 | type BaseCallFilter = frame_support::traits::Everything;
40 | type BlockHashCount = BlockHashCount;
41 | type BlockLength = ();
42 | type BlockNumber = u64;
43 | type BlockWeights = ();
44 | type RuntimeCall = RuntimeCall;
45 | type DbWeight = ();
46 | type RuntimeEvent = RuntimeEvent;
47 | type Hash = H256;
48 | type Hashing = BlakeTwo256;
49 | type Header = Header;
50 | type Index = u64;
51 | type Lookup = IdentityLookup;
52 | type MaxConsumers = frame_support::traits::ConstU32<16>;
53 | type OnKilledAccount = ();
54 | type OnNewAccount = ();
55 | type OnSetCode = ();
56 | type RuntimeOrigin = RuntimeOrigin;
57 | type PalletInfo = PalletInfo;
58 | type SS58Prefix = SS58Prefix;
59 | type SystemWeightInfo = ();
60 | type Version = ();
61 | }
62 |
63 | parameter_types! {
64 | pub const ExistentialDeposit: u64 = 1;
65 | }
66 |
67 | impl pallet_balances::Config for Test {
68 | type AccountStore = System;
69 | type Balance = u64;
70 | type DustRemoval = ();
71 | type RuntimeEvent = RuntimeEvent;
72 | type ExistentialDeposit = ExistentialDeposit;
73 | type MaxLocks = ();
74 | type MaxReserves = ();
75 | type ReserveIdentifier = [u8; 8];
76 | type WeightInfo = ();
77 | }
78 |
79 | parameter_types! {
80 | pub const ParameterDeposit: u64 = 1;
81 | pub const StringLimit: u32 = 50;
82 | pub const MetadataDepositBase: u64 = 1;
83 | pub const MetadataDepositPerByte: u64 = 1;
84 | }
85 |
86 | impl pallet_hasher::Config for Test {
87 | type RuntimeEvent = RuntimeEvent;
88 | type ForceOrigin = frame_system::EnsureRoot;
89 | type Hasher = webb_primitives::hashing::ArkworksPoseidonHasherBn254;
90 | type MaxParameterLength = ConstU32<10000>;
91 | type WeightInfo = ();
92 | }
93 |
94 | // Build genesis storage according to the mock runtime.
95 | pub fn new_test_ext() -> sp_io::TestExternalities {
96 | system::GenesisConfig::default().build_storage::().unwrap().into()
97 | }
98 |
--------------------------------------------------------------------------------
/pallets/hasher/src/weights.rs:
--------------------------------------------------------------------------------
1 | // This file is part of Webb.
2 |
3 | // Copyright (C) 2022 Webb Technologies Inc.
4 | // SPDX-License-Identifier: Apache-2.0
5 |
6 | // Licensed under the Apache License, Version 2.0 (the "License");
7 | // you may not use this file except in compliance with the License.
8 | // You may obtain a copy of the License at
9 | //
10 | // http://www.apache.org/licenses/LICENSE-2.0
11 | //
12 | // Unless required by applicable law or agreed to in writing, software
13 | // distributed under the License is distributed on an "AS IS" BASIS,
14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | // See the License for the specific language governing permissions and
16 | // limitations under the License.
17 |
18 |
19 | //! Autogenerated weights for pallet_hasher
20 | //!
21 | //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
22 | //! DATE: 2023-04-24, STEPS: `20`, REPEAT: `1`, LOW RANGE: `[]`, HIGH RANGE: `[]`
23 | //! WORST CASE MAP SIZE: `1000000`
24 | //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024
25 |
26 | // Executed Command:
27 | // ./target/release/webb-standalone-node
28 | // benchmark
29 | // pallet
30 | // --chain=dev
31 | // --steps=20
32 | // --repeat=1
33 | // --log=warn
34 | // --pallet=pallet-hasher
35 | // --extrinsic=*
36 | // --execution=wasm
37 | // --wasm-execution=compiled
38 | // --output=./pallets/hasher/src/weights.rs
39 | // --template=./.maintain/webb-weight-template.hbs
40 |
41 | #![cfg_attr(rustfmt, rustfmt_skip)]
42 | #![allow(unused_parens)]
43 | #![allow(unused_imports)]
44 |
45 | use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}};
46 | use core::marker::PhantomData;
47 |
48 | /// Weight functions needed for pallet_hasher.
49 | pub trait WeightInfo {
50 | fn force_set_parameters(c: u32, ) -> Weight;
51 | }
52 |
53 | /// Weights for pallet_hasher using the Substrate node and recommended hardware.
54 | pub struct WebbWeight(PhantomData);
55 | impl WeightInfo for WebbWeight {
56 | /// Storage: HasherBn254 Parameters (r:1 w:1)
57 | /// Proof: HasherBn254 Parameters (max_values: Some(1), max_size: Some(10002), added: 10497, mode: MaxEncodedLen)
58 | /// The range of component `c` is `[0, 10000]`.
59 | fn force_set_parameters(c: u32, ) -> Weight {
60 | // Proof Size summary in bytes:
61 | // Measured: `6604`
62 | // Estimated: `10497`
63 | // Minimum execution time: 17_000_000 picoseconds.
64 | Weight::from_parts(18_214_525, 10497)
65 | // Standard Error: 186
66 | .saturating_add(Weight::from_parts(527, 0).saturating_mul(c.into()))
67 | .saturating_add(T::DbWeight::get().reads(1_u64))
68 | .saturating_add(T::DbWeight::get().writes(1_u64))
69 | }
70 | }
71 |
72 | // For backwards compatibility and tests
73 | impl WeightInfo for () {
74 | /// Storage: HasherBn254 Parameters (r:1 w:1)
75 | /// Proof: HasherBn254 Parameters (max_values: Some(1), max_size: Some(10002), added: 10497, mode: MaxEncodedLen)
76 | /// The range of component `c` is `[0, 10000]`.
77 | fn force_set_parameters(c: u32, ) -> Weight {
78 | // Proof Size summary in bytes:
79 | // Measured: `6604`
80 | // Estimated: `10497`
81 | // Minimum execution time: 17_000_000 picoseconds.
82 | Weight::from_parts(18_214_525, 10497)
83 | // Standard Error: 186
84 | .saturating_add(Weight::from_parts(527, 0).saturating_mul(c.into()))
85 | .saturating_add(RocksDbWeight::get().reads(1_u64))
86 | .saturating_add(RocksDbWeight::get().writes(1_u64))
87 | }
88 | }
--------------------------------------------------------------------------------
/pallets/key-storage/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | authors = ["Webb Technologies Inc."]
3 | description = "A pallet that stores an account and public key mapping."
4 | edition = "2021"
5 | homepage = "https://substrate.dev"
6 | license = "Unlicense"
7 | name = "pallet-key-storage"
8 | repository = "https://github.com/webb-tools/protocol-substrate"
9 | version = "1.0.0"
10 |
11 | [package.metadata.docs.rs]
12 | targets = ["x86_64-unknown-linux-gnu"]
13 |
14 | [dependencies]
15 | codec = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive", "max-encoded-len"] }
16 | frame-benchmarking = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39", optional = true }
17 | frame-support = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
18 | frame-system = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
19 | frame-system-benchmarking = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39", optional = true }
20 | log = { version = "0.4.14", default-features = false }
21 | scale-info = { version = "2.1.1", default-features = false, features = ["derive"] }
22 | sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
23 | sp-std = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
24 | webb-primitives = { path = "../../primitives", default-features = false, features = ["verifying"] }
25 |
26 | [dev-dependencies]
27 | pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
28 | serde = { version = "1.0.119" }
29 | sp-core = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
30 | sp-io = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
31 | sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
32 |
33 | [features]
34 | default = ["std"]
35 | runtime-benchmarks = [
36 | "frame-benchmarking",
37 | "frame-system/runtime-benchmarks",
38 | "frame-support/runtime-benchmarks",
39 | ]
40 | std = [
41 | "codec/std",
42 | "frame-support/std",
43 | "frame-system/std",
44 | "sp-runtime/std",
45 | "sp-std/std",
46 | "webb-primitives/std",
47 | "frame-benchmarking/std",
48 | ]
49 |
--------------------------------------------------------------------------------
/pallets/key-storage/src/benchmarking.rs:
--------------------------------------------------------------------------------
1 | // This file is part of Webb.
2 |
3 | // Copyright (C) 2021-2023 Webb Technologies Inc.
4 | // SPDX-License-Identifier: Apache-2.0
5 |
6 | // Licensed under the Apache License, Version 2.0 (the "License");
7 | // you may not use this file except in compliance with the License.
8 | // You may obtain a copy of the License at
9 | //
10 | // http://www.apache.org/licenses/LICENSE-2.0
11 | //
12 | // Unless required by applicable law or agreed to in writing, software
13 | // distributed under the License is distributed on an "AS IS" BASIS,
14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | // See the License for the specific language governing permissions and
16 | // limitations under the License.
17 |
18 | #![cfg(feature = "runtime-benchmarks")]
19 | use super::*;
20 | use crate::Pallet;
21 | use frame_benchmarking::{
22 | benchmarks_instance_pallet, impl_benchmark_test_suite, whitelisted_caller,
23 | };
24 | use frame_system::RawOrigin;
25 | use sp_std::vec;
26 | fn assert_last_event, I: 'static>(generic_event: >::RuntimeEvent) {
27 | frame_system::Pallet::::assert_last_event(generic_event.into());
28 | }
29 |
30 | const MAX_PARAMETER_LENGTH: u32 = 10000;
31 |
32 | benchmarks_instance_pallet! {
33 | register {
34 | let c in 0..MAX_PARAMETER_LENGTH;
35 | let owner: T::AccountId = whitelisted_caller();
36 | let public_key = vec![0u8;c as usize];
37 | }: _(RawOrigin::Signed(owner.clone()), owner.clone(), public_key.clone().try_into().unwrap())
38 | verify {
39 | assert_last_event::(Event::PublicKeyRegistration{owner, public_key : public_key.try_into().unwrap()}.into());
40 | }
41 | }
42 |
43 | impl_benchmark_test_suite!(Pallet, crate::mock::new_test_ext(), crate::mock::Test);
44 |
--------------------------------------------------------------------------------
/pallets/key-storage/src/mock.rs:
--------------------------------------------------------------------------------
1 | use super::*;
2 | use crate::{self as pallet_key_storage};
3 |
4 | use frame_support::parameter_types;
5 | use frame_system as system;
6 | use sp_core::H256;
7 | use sp_runtime::{
8 | testing::Header,
9 | traits::{BlakeTwo256, ConstU32, IdentityLookup},
10 | };
11 | use sp_std::convert::{TryFrom, TryInto};
12 | use webb_primitives::AccountId;
13 |
14 | type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic;
15 | type Block = frame_system::mocking::MockBlock;
16 |
17 | // Configure a mock runtime to test the pallet.
18 | frame_support::construct_runtime!(
19 | pub enum Test where
20 | Block = Block,
21 | NodeBlock = Block,
22 | UncheckedExtrinsic = UncheckedExtrinsic,
23 | {
24 | System: frame_system::{Pallet, Call, Config, Storage, Event},
25 | KeyStorage: pallet_key_storage::{Pallet, Call, Storage, Event, Config}
26 | }
27 | );
28 |
29 | parameter_types! {
30 | pub const BlockHashCount: u64 = 250;
31 | pub const SS58Prefix: u8 = 42;
32 | }
33 |
34 | impl system::Config for Test {
35 | type AccountData = pallet_balances::AccountData;
36 | type AccountId = AccountId;
37 | type BaseCallFilter = frame_support::traits::Everything;
38 | type BlockHashCount = BlockHashCount;
39 | type BlockLength = ();
40 | type BlockNumber = u64;
41 | type BlockWeights = ();
42 | type RuntimeCall = RuntimeCall;
43 | type DbWeight = ();
44 | type RuntimeEvent = RuntimeEvent;
45 | type Hash = H256;
46 | type Hashing = BlakeTwo256;
47 | type Header = Header;
48 | type Index = u64;
49 | type Lookup = IdentityLookup;
50 | type MaxConsumers = frame_support::traits::ConstU32<16>;
51 | type OnKilledAccount = ();
52 | type OnNewAccount = ();
53 | type OnSetCode = ();
54 | type RuntimeOrigin = RuntimeOrigin;
55 | type PalletInfo = PalletInfo;
56 | type SS58Prefix = SS58Prefix;
57 | type SystemWeightInfo = ();
58 | type Version = ();
59 | }
60 |
61 | parameter_types! {
62 | pub const ExistentialDeposit: u64 = 1;
63 | }
64 |
65 | parameter_types! {
66 | pub const ParameterDeposit: u64 = 1;
67 | pub const StringLimit: u32 = 50;
68 | pub const MetadataDepositBase: u64 = 1;
69 | pub const MetadataDepositPerByte: u64 = 1;
70 | }
71 |
72 | impl pallet_key_storage::Config for Test {
73 | type RuntimeEvent = RuntimeEvent;
74 | type MaxPubkeyLength = ConstU32<100>;
75 | type MaxPubKeyOwners = ConstU32<100>;
76 | type WeightInfo = ();
77 | }
78 |
79 | // Build genesis storage according to the mock runtime.
80 | pub fn new_test_ext() -> sp_io::TestExternalities {
81 | system::GenesisConfig::default().build_storage::().unwrap().into()
82 | }
83 |
--------------------------------------------------------------------------------
/pallets/key-storage/src/tests.rs:
--------------------------------------------------------------------------------
1 | use super::*;
2 | use crate::mock::*;
3 | use frame_benchmarking::account;
4 | use frame_support::assert_ok;
5 | use webb_primitives::runtime::AccountId;
6 |
7 | #[test]
8 | fn should_register_public_key_with_owner() {
9 | new_test_ext().execute_with(|| {
10 | let owner = account::("", 0, 0);
11 | let public_key = [0u8; 32].to_vec();
12 | let res = KeyStorage::register(
13 | RuntimeOrigin::signed(owner.clone()),
14 | owner,
15 | public_key.try_into().unwrap(),
16 | );
17 | assert_ok!(res);
18 | });
19 | }
20 |
--------------------------------------------------------------------------------
/pallets/key-storage/src/weights.rs:
--------------------------------------------------------------------------------
1 | // This file is part of Webb.
2 |
3 | // Copyright (C) 2022 Webb Technologies Inc.
4 | // SPDX-License-Identifier: Apache-2.0
5 |
6 | // Licensed under the Apache License, Version 2.0 (the "License");
7 | // you may not use this file except in compliance with the License.
8 | // You may obtain a copy of the License at
9 | //
10 | // http://www.apache.org/licenses/LICENSE-2.0
11 | //
12 | // Unless required by applicable law or agreed to in writing, software
13 | // distributed under the License is distributed on an "AS IS" BASIS,
14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | // See the License for the specific language governing permissions and
16 | // limitations under the License.
17 |
18 | //! Autogenerated weights for `pallet_key_storage`
19 | //!
20 | //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
21 | //! DATE: 2022-09-13, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]`
22 | //! HOSTNAME: `MACBOOKs-MacBook-Pro.local`, CPU: ``
23 | //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024
24 |
25 | // Executed Command:
26 | // ./target/release/webb-standalone-node
27 | // benchmark
28 | // pallet
29 | // --chain
30 | // dev
31 | // --execution=wasm
32 | // --wasm-execution=compiled
33 | // --pallet
34 | // pallet-key-storage
35 | // --extrinsic
36 | // *
37 | // --steps
38 | // 50
39 | // --repeat
40 | // 20
41 | // --output
42 | // pallets/all-weight.rs
43 |
44 | #![cfg_attr(rustfmt, rustfmt_skip)]
45 | #![allow(unused_parens)]
46 | #![allow(unused_imports)]
47 |
48 | use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}};
49 | use sp_std::marker::PhantomData;
50 |
51 | /// Weight functions needed for pallet_key_storage.
52 | pub trait WeightInfo {
53 | fn register(c: u32, ) -> Weight;
54 | }
55 |
56 | /// Weight functions for `pallet_key_storage`.
57 | pub struct WebbWeight(PhantomData);
58 | impl WeightInfo for WebbWeight {
59 | // Storage: KeyStorage PublicKeyOwners (r:1 w:0)
60 | /// The range of component `c` is `[0, 20000]`.
61 | fn register(c: u32, ) -> Weight {
62 | Weight::from_ref_time(33_025_000)
63 | // Standard Error: 0
64 | .saturating_add(Weight::from_ref_time(1_000).saturating_mul(c as u64))
65 | .saturating_add(T::DbWeight::get().reads(1_u64))
66 | }
67 | }
68 |
69 | // For backwards compatibility and tests
70 | impl WeightInfo for () {
71 | fn register(_c: u32, ) -> Weight {
72 | Weight::from_ref_time(33_025_000)
73 | // Standard Error: 0
74 | .saturating_add(Weight::from_ref_time(1_000).saturating_mul(1_u64))
75 | .saturating_add(RocksDbWeight::get().reads(1_u64))
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/pallets/linkable-tree/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | authors = ["Webb Technologies Inc."]
3 | edition = "2021"
4 | homepage = "https://substrate.dev"
5 | license = "Unlicense"
6 | name = "pallet-linkable-tree"
7 | version = "1.0.0"
8 |
9 | [package.metadata.docs.rs]
10 | targets = ["x86_64-unknown-linux-gnu"]
11 |
12 | [dependencies]
13 | codec = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive", "max-encoded-len"] }
14 | scale-info = { version = "2.1.1", default-features = false, features = ["derive"] }
15 |
16 | frame-support = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
17 | frame-system = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
18 | pallet-mt = { path = "../mt", default-features = false }
19 | sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
20 | sp-std = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
21 | webb-primitives = { path = "../../primitives", default-features = false }
22 |
23 | frame-benchmarking = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39", optional = true }
24 | frame-system-benchmarking = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39", optional = true }
25 | sp-io = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
26 |
27 | serde = { version = "1.0.119", optional = true }
28 |
29 | [dev-dependencies]
30 | pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
31 | pallet-hasher = { path = "../hasher", default-features = false }
32 | rand = "0.8.4"
33 | sp-core = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
34 | sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
35 |
36 | ark-crypto-primitives = { version = "^0.3.0", features = ["r1cs"], default-features = false }
37 | ark-ec = { version = "^0.3.0", default-features = false }
38 | ark-ff = { version = "^0.3.0", default-features = false }
39 | ark-relations = { version = "^0.3.0", default-features = false }
40 | ark-serialize = { version = "^0.3.0", default-features = false, features = ["derive"] }
41 | ark-std = { version = "^0.3.0", default-features = false }
42 |
43 | ark-bn254 = { version = "^0.3.0", default-features = false, features = ["curve"] }
44 | arkworks-setups = { version = "1.2.1", features = ["r1cs"], default-features = false }
45 |
46 | [features]
47 | default = ["std"]
48 | runtime-benchmarks = [
49 | "frame-benchmarking",
50 | "frame-system/runtime-benchmarks",
51 | "frame-support/runtime-benchmarks",
52 | ]
53 | std = [
54 | "serde",
55 | "codec/std",
56 | "scale-info/std",
57 | "frame-support/std",
58 | "frame-system/std",
59 | "sp-runtime/std",
60 | "sp-std/std",
61 | "sp-io/std",
62 | "pallet-hasher/std",
63 | "pallet-mt/std",
64 | "webb-primitives/std",
65 | "frame-benchmarking/std",
66 | ]
67 |
--------------------------------------------------------------------------------
/pallets/linkable-tree/rpc/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | authors = ["Webb Tools"]
3 | edition = "2018"
4 | name = "pallet-linkable-tree-rpc"
5 | version = "0.1.0"
6 |
7 | [dependencies]
8 | jsonrpsee = { version = "0.16.2", features = ["server"] }
9 | sc-rpc = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
10 | thiserror = "1.0"
11 |
12 | codec = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
13 | sp-api = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
14 | sp-blockchain = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
15 | sp-core = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
16 | sp-runtime = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
17 |
18 | pallet-linkable-tree = { path = "../", default-features = false }
19 | pallet-linkable-tree-rpc-runtime-api = { path = "./runtime-api", default-features = false }
20 | webb-primitives = { path = "../../../primitives", default-features = false }
21 |
22 | [features]
23 | default = ["std"]
24 | std = [
25 | "codec/std",
26 | "webb-primitives/std",
27 | "pallet-linkable-tree/std",
28 | "pallet-linkable-tree-rpc-runtime-api/std",
29 | "sp-core/std",
30 | "sp-runtime/std",
31 | "sp-api/std",
32 | ]
33 |
--------------------------------------------------------------------------------
/pallets/linkable-tree/rpc/runtime-api/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | authors = ["Webb"]
3 | description = "Linkable tree RPC API for linkable tree pallet"
4 | edition = "2018"
5 | license = "Apache-2.0"
6 | name = "pallet-linkable-tree-rpc-runtime-api"
7 | readme = "README.md"
8 | version = "1.0.0"
9 |
10 | [package.metadata.docs.rs]
11 | targets = ["x86_64-unknown-linux-gnu"]
12 |
13 | [dependencies]
14 | codec = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
15 | pallet-linkable-tree = { default-features = false, path = "../../" }
16 | sp-api = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
17 | sp-std = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
18 | webb-primitives = { path = "../../../../primitives", default-features = false }
19 |
20 | [features]
21 | default = ["std"]
22 | std = [
23 | "codec/std",
24 | "sp-api/std",
25 | "sp-std/std",
26 | "pallet-linkable-tree/std",
27 | "webb-primitives/std",
28 | ]
29 |
--------------------------------------------------------------------------------
/pallets/linkable-tree/rpc/runtime-api/src/lib.rs:
--------------------------------------------------------------------------------
1 | #![cfg_attr(not(feature = "std"), no_std)]
2 |
3 | use codec::{Decode, Encode};
4 | use pallet_linkable_tree::types::EdgeMetadata;
5 | use sp_std::vec::Vec;
6 | use webb_primitives::ElementTrait;
7 |
8 | sp_api::decl_runtime_apis! {
9 | pub trait LinkableTreeApi
10 | where
11 | C: Encode + Decode,
12 | E: ElementTrait,
13 | L: Encode + Decode,
14 | {
15 | /// Get the neighbor roots including the roots for default (empty) edges
16 | fn get_neighbor_roots(tree_id: u32) -> Vec;
17 | /// Get the neighbor edge metadata including the metadata for default (empty) edges
18 | fn get_neighbor_edges(tree_id: u32) -> Vec>;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/pallets/linkable-tree/rpc/src/error.rs:
--------------------------------------------------------------------------------
1 | // This file is part of Webb.
2 |
3 | // Copyright (C) 2021-2023 Webb Technologies Inc.
4 | // SPDX-License-Identifier: Apache-2.0
5 |
6 | // Licensed under the Apache License, Version 2.0 (the "License");
7 | // you may not use this file except in compliance with the License.
8 | // You may obtain a copy of the License at
9 | //
10 | // http://www.apache.org/licenses/LICENSE-2.0
11 | //
12 | // Unless required by applicable law or agreed to in writing, software
13 | // distributed under the License is distributed on an "AS IS" BASIS,
14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | // See the License for the specific language governing permissions and
16 | // limitations under the License.
17 |
18 | use jsonrpsee::{
19 | core::Error as JsonRpseeError,
20 | types::error::{CallError, ErrorObject},
21 | };
22 |
23 | #[derive(Debug, thiserror::Error)]
24 | /// Top-level error type for the RPC handler
25 | pub enum Error {
26 | /// The Linkable Tree RPC endpoint is not ready.
27 | #[error("Linkable Tree RPC endpoint not ready")]
28 | EndpointNotReady,
29 | /// The roots request failed
30 | #[error("Linkable Tree roots request failed")]
31 | RootsRequestFailure,
32 | /// The edges request failed
33 | #[error("Linkable Tree edges request failed")]
34 | EdgesRequestFailure,
35 | }
36 |
37 | /// The error codes returned by jsonrpc.
38 | pub enum ErrorCode {
39 | /// Returned when Linkable Tree RPC endpoint is not ready.
40 | NotReady = 1,
41 | /// Roots request failed
42 | RootsRequestFailure,
43 | /// Edges request failed
44 | EdgesRequestFailure,
45 | }
46 |
47 | impl From for ErrorCode {
48 | fn from(error: Error) -> Self {
49 | match error {
50 | Error::EndpointNotReady => ErrorCode::NotReady,
51 | Error::RootsRequestFailure => ErrorCode::RootsRequestFailure,
52 | Error::EdgesRequestFailure => ErrorCode::EdgesRequestFailure,
53 | }
54 | }
55 | }
56 |
57 | impl From for JsonRpseeError {
58 | fn from(error: Error) -> Self {
59 | let message = error.to_string();
60 | let code = ErrorCode::from(error);
61 | JsonRpseeError::Call(CallError::Custom(ErrorObject::owned(
62 | code as i32,
63 | message,
64 | None::<()>,
65 | )))
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/pallets/linkable-tree/src/benchmarking.rs:
--------------------------------------------------------------------------------
1 | // This file is part of Webb.
2 |
3 | // Copyright (C) 2021-2023 Webb Technologies Inc.
4 | // SPDX-License-Identifier: Apache-2.0
5 |
6 | // Licensed under the Apache License, Version 2.0 (the "License");
7 | // you may not use this file except in compliance with the License.
8 | // You may obtain a copy of the License at
9 | //
10 | // http://www.apache.org/licenses/LICENSE-2.0
11 | //
12 | // Unless required by applicable law or agreed to in writing, software
13 | // distributed under the License is distributed on an "AS IS" BASIS,
14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | // See the License for the specific language governing permissions and
16 | // limitations under the License.
17 |
18 | //! Anchor pallet benchmarking.
19 |
20 | #![cfg(feature = "runtime-benchmarks")]
21 |
22 | use super::*;
23 |
24 | use frame_benchmarking::{
25 | account, benchmarks_instance_pallet, impl_benchmark_test_suite, whitelisted_caller,
26 | };
27 | use frame_system::RawOrigin;
28 |
29 | use frame_support::traits::Get;
30 |
31 | const MAX_EDGES: u32 = 256;
32 |
33 | benchmarks_instance_pallet! {
34 | create {
35 | let i in 1..MAX_EDGES;
36 | let d in 1..>::MaxTreeDepth::get() as u32;
37 | }: _(RawOrigin::Root, i, d as u8)
38 | }
39 |
40 | impl_benchmark_test_suite!(Pallet, crate::mock::new_test_ext(), crate::mock::Test);
41 |
--------------------------------------------------------------------------------
/pallets/linkable-tree/src/types.rs:
--------------------------------------------------------------------------------
1 | //! All the traits exposed to be used in other custom pallets
2 | use crate::*;
3 | use codec::{Decode, Encode, MaxEncodedLen};
4 | use scale_info::TypeInfo;
5 | use webb_primitives::webb_proposals::ResourceId;
6 |
7 | #[cfg(feature = "std")]
8 | use serde::{Deserialize, Serialize};
9 |
10 | #[derive(Clone, Encode, Decode, Eq, PartialEq, Default, Debug, TypeInfo, MaxEncodedLen)]
11 | #[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
12 | pub struct EdgeMetadata {
13 | /// chain id
14 | pub src_chain_id: ChainID,
15 | /// root of source chain anchor's native merkle tree
16 | pub root: Element,
17 | /// height of source chain anchor's native merkle tree
18 | pub latest_leaf_index: LastLeafIndex,
19 | /// Target contract address or tree identifier
20 | pub src_resource_id: ResourceId,
21 | }
22 |
--------------------------------------------------------------------------------
/pallets/linkable-tree/src/weights.rs:
--------------------------------------------------------------------------------
1 | //! Autogenerated weights for `pallet_linkable_tree`
2 | //!
3 | //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
4 | //! DATE: 2021-11-05, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]`
5 | //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 128
6 |
7 | // Executed Command:
8 | // ./target/release/webb-standalone-node
9 | // benchmark
10 | // --chain=dev
11 | // --execution
12 | // wasm
13 | // --wasm-execution
14 | // compiled
15 | // --pallet
16 | // pallet_linkable_tree
17 | // --extrinsic
18 | // *
19 | // --steps
20 | // 50
21 | // --repeat
22 | // 20
23 | // --raw
24 | // --output
25 | // ./pallets/linkable-tree/src/weights.rs
26 |
27 |
28 | #![cfg_attr(rustfmt, rustfmt_skip)]
29 | #![allow(unused_parens)]
30 | #![allow(unused_imports)]
31 |
32 | use frame_support::{traits::Get, weights::Weight};
33 | use sp_std::marker::PhantomData;
34 |
35 | pub trait WeightInfo {
36 | fn create(i: u32, d: u32, ) -> Weight;
37 | fn set_maintainer() -> Weight;
38 | fn force_set_maintainer() -> Weight;
39 | }
40 |
41 | /// Weight functions for `pallet_linkable_tree`.
42 | pub struct WebbWeight(PhantomData);
43 | impl WeightInfo for WebbWeight {
44 | // Storage: MerkleTree NextTreeId (r:1 w:1)
45 | // Storage: MerkleTree DefaultHashes (r:1 w:0)
46 | // Storage: MerkleTree Trees (r:0 w:1)
47 | // Storage: LinkableTree MaxEdges (r:0 w:1)
48 | fn create(i: u32, d: u32, ) -> Weight {
49 | Weight::from_ref_time(53_487_000)
50 | // Standard Error: 3_000
51 | .saturating_add(Weight::from_ref_time(4_000_u64).saturating_mul(i as u64))
52 | // Standard Error: 33_000
53 | .saturating_add(Weight::from_ref_time(43_000_u64).saturating_mul(d as u64))
54 | .saturating_add(T::DbWeight::get().reads(2_u64))
55 | .saturating_add(T::DbWeight::get().writes(3_u64))
56 | }
57 | // Storage: LinkableTree Maintainer (r:1 w:1)
58 | fn set_maintainer() -> Weight {
59 | Weight::from_ref_time(38_000_000)
60 | .saturating_add(T::DbWeight::get().reads(1_u64))
61 | .saturating_add(T::DbWeight::get().writes(1_u64))
62 | }
63 | // Storage: LinkableTree Maintainer (r:1 w:1)
64 | fn force_set_maintainer() -> Weight {
65 | Weight::from_ref_time(32_000_000)
66 | .saturating_add(T::DbWeight::get().reads(1_u64))
67 | .saturating_add(T::DbWeight::get().writes(1_u64))
68 | }
69 | }
70 |
71 | #[allow(unused_variables)]
72 | impl WeightInfo for () {
73 | fn create(i: u32, d: u32, ) -> Weight {
74 | Weight::from_ref_time(0)
75 | }
76 | fn set_maintainer() -> Weight {
77 | Weight::from_ref_time(0)
78 | }
79 | fn force_set_maintainer() -> Weight {
80 | Weight::from_ref_time(0)
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/pallets/masp/claims-verifier/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | authors = ["Webb Technologies Inc."]
3 | description = "A pallet that stores zero-knowledge verifier parameters and provides verification of zero-knowledge proofs for anonimity mining claims."
4 | edition = "2021"
5 | homepage = "https://substrate.dev"
6 | license = "Unlicense"
7 | name = "pallet-claims-verifier"
8 | repository = "https://github.com/webb-tools/protocol-substrate"
9 | version = "1.0.0"
10 |
11 | [package.metadata.docs.rs]
12 | targets = ["x86_64-unknown-linux-gnu"]
13 |
14 | [dependencies]
15 | codec = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive", "max-encoded-len"] }
16 | frame-support = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
17 | frame-system = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
18 | log = { version = "0.4.14", default-features = false }
19 | scale-info = { version = "2.1.1", default-features = false, features = ["derive"] }
20 | sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
21 | sp-std = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
22 | webb-primitives = { path = "../../../primitives", default-features = false, features = ["verifying"] }
23 |
24 | frame-benchmarking = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39", optional = true }
25 | frame-system-benchmarking = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39", optional = true }
26 |
27 | [dev-dependencies]
28 | ark-crypto-primitives = { version = "^0.3.0", features = ["r1cs"], default-features = false }
29 | pallet-balances = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
30 | serde = { version = "1.0.119" }
31 | sp-core = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
32 | sp-io = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
33 | sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
34 |
35 | [features]
36 | default = ["std"]
37 | runtime-benchmarks = [
38 | "frame-benchmarking",
39 | "frame-system/runtime-benchmarks",
40 | "frame-support/runtime-benchmarks",
41 | ]
42 | std = [
43 | "codec/std",
44 | "frame-support/std",
45 | "frame-system/std",
46 | "sp-runtime/std",
47 | "sp-std/std",
48 | "webb-primitives/std",
49 | ]
50 |
--------------------------------------------------------------------------------
/pallets/masp/claims-verifier/src/benchmarking.rs:
--------------------------------------------------------------------------------
1 | // This file is part of Webb.
2 |
3 | // Copyright (C) 2021-2023 Webb Technologies Inc.
4 | // SPDX-License-Identifier: Apache-2.0
5 |
6 | // Licensed under the Apache License, Version 2.0 (the "License");
7 | // you may not use this file except in compliance with the License.
8 | // You may obtain a copy of the License at
9 | //
10 | // http://www.apache.org/licenses/LICENSE-2.0
11 | //
12 | // Unless required by applicable law or agreed to in writing, software
13 | // distributed under the License is distributed on an "AS IS" BASIS,
14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | // See the License for the specific language governing permissions and
16 | // limitations under the License.
17 |
18 | //! Verifier pallet benchmarking.
19 |
20 | #![cfg(feature = "runtime-benchmarks")]
21 |
22 | use super::*;
23 | use crate::Pallet;
24 | use frame_benchmarking::{
25 | account, benchmarks_instance_pallet, impl_benchmark_test_suite, whitelist_account,
26 | whitelisted_caller,
27 | };
28 | use frame_support::traits::Currency;
29 | use frame_system::RawOrigin;
30 | use sp_runtime::traits::Bounded;
31 | use webb_primitives::types::DepositDetails;
32 |
33 | fn assert_last_event, I: 'static>(generic_event: >::RuntimeEvent) {
34 | frame_system::Pallet::::assert_last_event(generic_event.into());
35 | }
36 |
37 | const SEED: u32 = 0;
38 | // Based on verifier bytes generated from the zero knowledge setup for anchor
39 | // pallet and mixer pallet, Max verifier bytes length generated ranged between
40 | // 456 - 552
41 | const MAX_VERIFIER_LENGTH: u32 = 1024;
42 |
43 | benchmarks_instance_pallet! {
44 | force_set_parameters {
45 | let c in 0..MAX_VERIFIER_LENGTH;
46 | let depositor: T::AccountId = account("depositor", 0, SEED);
47 | let parameters = vec![0u8;c as usize];
48 | }: _(RawOrigin::Root, 1u8, parameters.clone().try_into().unwrap())
49 | verify {
50 | assert_eq!(Pallet::::parameters(1u8), parameters);
51 | }
52 | }
53 |
54 | impl_benchmark_test_suite!(Pallet, crate::mock::new_test_ext(), crate::mock::Test);
55 |
--------------------------------------------------------------------------------
/pallets/masp/claims-verifier/src/tests.rs:
--------------------------------------------------------------------------------
1 | use super::*;
2 | use crate::mock::*;
3 | use frame_support::assert_err;
4 |
5 | #[test]
6 | fn should_fail_to_verify_without_parameters() {
7 | new_test_ext().execute_with(|| {
8 | // Pass arbitrary
9 | assert_err!(
10 | ::verify(&[], &[1u8; 32], 0),
11 | Error::::VerifyingParametersNotInitialized
12 | );
13 | });
14 | }
15 |
--------------------------------------------------------------------------------
/pallets/masp/claims-verifier/src/weights.rs:
--------------------------------------------------------------------------------
1 | // This file is part of Webb.
2 |
3 | // Copyright (C) 2022 Webb Technologies Inc.
4 | // SPDX-License-Identifier: Apache-2.0
5 |
6 | // Licensed under the Apache License, Version 2.0 (the "License");
7 | // you may not use this file except in compliance with the License.
8 | // You may obtain a copy of the License at
9 | //
10 | // http://www.apache.org/licenses/LICENSE-2.0
11 | //
12 | // Unless required by applicable law or agreed to in writing, software
13 | // distributed under the License is distributed on an "AS IS" BASIS,
14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | // See the License for the specific language governing permissions and
16 | // limitations under the License.
17 |
18 | //! Autogenerated weights for pallet_vanchor_verifier
19 | //!
20 | //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
21 | //! DATE: 2022-06-14, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]`
22 | //! HOSTNAME: ``, CPU: ``
23 | //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024
24 |
25 | // Executed Command:
26 | // ./target/release/webb-standalone-node
27 | // benchmark
28 | // pallet
29 | // --chain=dev
30 | // --steps=20
31 | // --repeat=10
32 | // --log=warn
33 | // --pallet=pallet-vanchor-verifier
34 | // --extrinsic=*
35 | // --execution=wasm
36 | // --wasm-execution=compiled
37 | // --output=./pallets/verifier/src/weights.rs
38 | // --template=./.maintain/webb-weight-template.hbs
39 |
40 | #![cfg_attr(rustfmt, rustfmt_skip)]
41 | #![allow(unused_parens)]
42 | #![allow(unused_imports)]
43 |
44 | use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}};
45 | use sp_std::marker::PhantomData;
46 |
47 | /// Weight functions needed for pallet_vanchor_verifier.
48 | pub trait WeightInfo {
49 | fn force_set_parameters(c: u32, ) -> Weight;
50 | }
51 |
52 | /// Weights for pallet_vanchor_verifier using the Substrate node and recommended hardware.
53 | pub struct WebbWeight(PhantomData);
54 | impl WeightInfo for WebbWeight {
55 | // Storage: MixerVerifierBn254 Parameters (r:1 w:1)
56 | fn force_set_parameters(c: u32, ) -> Weight {
57 | Weight::from_ref_time(3_653_000)
58 | // Standard Error: 0
59 | .saturating_add(Weight::from_ref_time(1_000).saturating_mul(c as u64))
60 | .saturating_add(T::DbWeight::get().reads(1_u64))
61 | .saturating_add(T::DbWeight::get().writes(1_u64))
62 | }
63 | }
64 |
65 | // For backwards compatibility and tests
66 | impl WeightInfo for () {
67 | // Storage: MixerVerifierBn254 Parameters (r:1 w:1)
68 | fn force_set_parameters(c: u32, ) -> Weight {
69 | Weight::from_ref_time(3_653_000)
70 | // Standard Error: 0
71 | .saturating_add(Weight::from_ref_time(1_000).saturating_mul(c as u64))
72 | .saturating_add(RocksDbWeight::get().reads(1_u64))
73 | .saturating_add(RocksDbWeight::get().writes(1_u64))
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/pallets/mixer/src/test_utils.rs:
--------------------------------------------------------------------------------
1 | use ark_bn254::Bn254;
2 | use arkworks_setups::{
3 | common::{Leaf, MixerProof},
4 | r1cs::mixer::MixerR1CSProver,
5 | Curve, MixerProver,
6 | };
7 | use webb_primitives::ElementTrait;
8 |
9 | use crate::mock::Element;
10 |
11 | pub const DEFAULT_LEAF: [u8; 32] = [
12 | 47, 229, 76, 96, 211, 172, 171, 243, 52, 58, 53, 182, 235, 161, 93, 180, 130, 27, 52, 15, 118,
13 | 231, 65, 226, 36, 150, 133, 237, 72, 153, 175, 108,
14 | ];
15 | const TREE_HEIGHT: usize = 30;
16 | type MixerR1csproverBn254_30 = MixerR1CSProver;
17 |
18 | pub fn setup_zk_circuit(
19 | curve: Curve,
20 | recipient_bytes: Vec,
21 | relayer_bytes: Vec,
22 | pk_bytes: Vec,
23 | fee_value: u128,
24 | refund_value: u128,
25 | ) -> (
26 | Vec, // proof bytes
27 | Element, // root
28 | Element, // nullifier_hash
29 | Element, // leaf
30 | ) {
31 | let rng = &mut ark_std::test_rng();
32 |
33 | match curve {
34 | Curve::Bn254 => {
35 | // fit inputs to the curve.
36 | let Leaf { secret_bytes, nullifier_bytes, leaf_bytes, nullifier_hash_bytes, .. } =
37 | MixerR1csproverBn254_30::create_random_leaf(curve, rng).unwrap();
38 |
39 | let leaves = vec![leaf_bytes.clone()];
40 | let index = 0;
41 | let MixerProof { proof, root_raw, .. } = MixerR1csproverBn254_30::create_proof(
42 | curve,
43 | secret_bytes,
44 | nullifier_bytes,
45 | leaves,
46 | index,
47 | recipient_bytes,
48 | relayer_bytes,
49 | fee_value,
50 | refund_value,
51 | pk_bytes,
52 | DEFAULT_LEAF,
53 | rng,
54 | )
55 | .unwrap();
56 |
57 | let leaf_element = Element::from_bytes(&leaf_bytes);
58 | let nullifier_hash_element = Element::from_bytes(&nullifier_hash_bytes);
59 | let root_element = Element::from_bytes(&root_raw);
60 |
61 | (proof, root_element, nullifier_hash_element, leaf_element)
62 | },
63 | Curve::Bls381 => {
64 | unimplemented!()
65 | },
66 | }
67 | }
68 |
69 | /// Truncate and pad 256 bit slice in reverse
70 | pub fn truncate_and_pad_reverse(t: &[u8]) -> Vec {
71 | let mut truncated_bytes = t[12..].to_vec();
72 | truncated_bytes.extend_from_slice(&[0u8; 12]);
73 | truncated_bytes
74 | }
75 |
--------------------------------------------------------------------------------
/pallets/mixer/src/types.rs:
--------------------------------------------------------------------------------
1 | //! All the traits exposed to be used in other custom pallets
2 | use crate::*;
3 | use codec::{Decode, Encode, MaxEncodedLen};
4 | use scale_info::TypeInfo;
5 |
6 | #[derive(Clone, Encode, Decode, TypeInfo, MaxEncodedLen)]
7 | pub struct MixerMetadata {
8 | /// Balance size of deposit
9 | pub deposit_size: Balance,
10 | /// Option of specifying a fungible asset. When None, the asset is the
11 | /// native currency.
12 | pub asset: AssetId,
13 | }
14 |
--------------------------------------------------------------------------------
/pallets/mt/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | authors = ["Webb Technologies Inc."]
3 | edition = "2021"
4 | homepage = "https://substrate.dev"
5 | license = "Unlicense"
6 | name = "pallet-mt"
7 | version = "1.0.0"
8 |
9 | [package.metadata.docs.rs]
10 | targets = ["x86_64-unknown-linux-gnu"]
11 |
12 | [dependencies]
13 | ark-bn254 = { version = "^0.3.0", default-features = false, features = ["curve"] }
14 | arkworks-setups = { version = "1.2.1", default-features = false }
15 | codec = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive", "max-encoded-len"] }
16 | frame-benchmarking = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39", optional = true }
17 | frame-support = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
18 | frame-system = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
19 | frame-system-benchmarking = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39", optional = true }
20 | pallet-hasher = { path = "../hasher", default-features = false }
21 | scale-info = { version = "2.1.1", default-features = false, features = ["derive"] }
22 | sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
23 | sp-std = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
24 | webb-primitives = { path = "../../primitives", default-features = false }
25 |
26 | [dev-dependencies]
27 | ark-bn254 = { version = "^0.3.0", default-features = false, features = ["curve"] }
28 | ark-crypto-primitives = { version = "^0.3.0", features = ["r1cs"], default-features = false }
29 | ark-ff = { version = "^0.3.0", default-features = false }
30 | ark-std = { version = "^0.3.0", default-features = false }
31 | hex = "0.4"
32 | hex-literal = "0.2.1"
33 | pallet-balances = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
34 | pallet-hasher = { path = "../hasher", default-features = false }
35 | serde = { version = "1.0.119" }
36 | sp-core = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
37 | sp-io = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
38 | sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
39 |
40 |
41 | [features]
42 | default = ["std"]
43 | runtime-benchmarks = [
44 | "frame-benchmarking",
45 | "frame-system/runtime-benchmarks",
46 | "frame-support/runtime-benchmarks",
47 | ]
48 | std = [
49 | "codec/std",
50 | "scale-info/std",
51 | "frame-support/std",
52 | "frame-system/std",
53 | "sp-runtime/std",
54 | "sp-std/std",
55 | "pallet-hasher/std",
56 | "webb-primitives/std",
57 | "pallet-hasher/std",
58 | ]
59 |
--------------------------------------------------------------------------------
/pallets/mt/rpc/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | authors = ["Webb Tools"]
3 | edition = "2018"
4 | name = "pallet-mt-rpc"
5 | version = "0.1.0"
6 |
7 | [dependencies]
8 | jsonrpsee = { version = "0.16.2", features = ["server"] }
9 | sc-rpc = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
10 | thiserror = "1.0"
11 |
12 | codec = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
13 | sp-api = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
14 | sp-blockchain = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
15 | sp-core = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
16 | sp-runtime = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
17 |
18 | pallet-mt-rpc-runtime-api = { path = "./runtime-api", default-features = false }
19 | webb-primitives = { path = "../../../primitives", default-features = false }
20 |
21 | [features]
22 | default = ["std"]
23 | std = [
24 | "codec/std",
25 | "webb-primitives/std",
26 | "pallet-mt-rpc-runtime-api/std",
27 | "sp-core/std",
28 | "sp-runtime/std",
29 | "sp-api/std",
30 | ]
31 |
--------------------------------------------------------------------------------
/pallets/mt/rpc/runtime-api/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | authors = ["Webb"]
3 | description = "RPC runtime API for merkle tree pallet"
4 | edition = "2018"
5 | license = "Apache-2.0"
6 | name = "pallet-mt-rpc-runtime-api"
7 | readme = "README.md"
8 | version = "1.0.0"
9 |
10 | [package.metadata.docs.rs]
11 | targets = ["x86_64-unknown-linux-gnu"]
12 |
13 | [dependencies]
14 | sp-api = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
15 | webb-primitives = { path = "../../../../primitives", default-features = false }
16 |
17 | [features]
18 | default = ["std"]
19 | std = [
20 | "sp-api/std",
21 | "webb-primitives/std",
22 | ]
23 |
--------------------------------------------------------------------------------
/pallets/mt/rpc/runtime-api/src/lib.rs:
--------------------------------------------------------------------------------
1 | #![cfg_attr(not(feature = "std"), no_std)]
2 |
3 | use webb_primitives::ElementTrait;
4 |
5 | sp_api::decl_runtime_apis! {
6 | pub trait MerkleTreeApi {
7 | /// Get the leaf of tree id at a given index.
8 | fn get_leaf(tree_id: u32, index: u32) -> Option;
9 | /// Checks if the given root is a known root.
10 | fn is_known_root(tree_id: u32, target_root: E) -> bool;
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/pallets/mt/rpc/src/error.rs:
--------------------------------------------------------------------------------
1 | // This file is part of Webb.
2 |
3 | // Copyright (C) 2021-2023 Webb Technologies Inc.
4 | // SPDX-License-Identifier: Apache-2.0
5 |
6 | // Licensed under the Apache License, Version 2.0 (the "License");
7 | // you may not use this file except in compliance with the License.
8 | // You may obtain a copy of the License at
9 | //
10 | // http://www.apache.org/licenses/LICENSE-2.0
11 | //
12 | // Unless required by applicable law or agreed to in writing, software
13 | // distributed under the License is distributed on an "AS IS" BASIS,
14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | // See the License for the specific language governing permissions and
16 | // limitations under the License.
17 |
18 | use jsonrpsee::{
19 | core::Error as JsonRpseeError,
20 | types::error::{CallError, ErrorObject},
21 | };
22 |
23 | #[derive(Debug, thiserror::Error)]
24 | /// Top-level error type for the RPC handler
25 | pub enum Error {
26 | /// The Merkle Tree RPC endpoint is not ready.
27 | #[error("Merkle Tree RPC endpoint not ready")]
28 | EndpointNotReady,
29 | /// Too many leaves requested
30 | #[error("Merkle Tree leaves request is too large")]
31 | TooManyLeavesRequested,
32 | /// Request to check if a given root is known to merkle tree failed.
33 | #[error("Request to check merkle tree root failed")]
34 | RootCheckRequestFailed,
35 | }
36 |
37 | /// The error codes returned by jsonrpc.
38 | pub enum ErrorCode {
39 | /// Returned when Merkle Tree RPC endpoint is not ready.
40 | NotReady = 1,
41 | /// Too many leaves are requested
42 | TooManyLeaves,
43 | /// Merkle Tree Root Checking failed
44 | RootCheckRequestFailed,
45 | }
46 |
47 | impl From for ErrorCode {
48 | fn from(error: Error) -> Self {
49 | match error {
50 | Error::EndpointNotReady => ErrorCode::NotReady,
51 | Error::TooManyLeavesRequested => ErrorCode::TooManyLeaves,
52 | Error::RootCheckRequestFailed => ErrorCode::RootCheckRequestFailed,
53 | }
54 | }
55 | }
56 |
57 | impl From for JsonRpseeError {
58 | fn from(error: Error) -> Self {
59 | let message = error.to_string();
60 | let code = ErrorCode::from(error);
61 | JsonRpseeError::Call(CallError::Custom(ErrorObject::owned(
62 | code as i32,
63 | message,
64 | None::<()>,
65 | )))
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/pallets/mt/src/benchmarking.rs:
--------------------------------------------------------------------------------
1 | // This file is part of Webb.
2 |
3 | // Copyright (C) 2021-2023 Webb Technologies Inc.
4 | // SPDX-License-Identifier: Apache-2.0
5 |
6 | // Licensed under the Apache License, Version 2.0 (the "License");
7 | // you may not use this file except in compliance with the License.
8 | // You may obtain a copy of the License at
9 | //
10 | // http://www.apache.org/licenses/LICENSE-2.0
11 | //
12 | // Unless required by applicable law or agreed to in writing, software
13 | // distributed under the License is distributed on an "AS IS" BASIS,
14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | // See the License for the specific language governing permissions and
16 | // limitations under the License.
17 |
18 | //! Merkle Tree pallet benchmarking.
19 |
20 | #![cfg(feature = "runtime-benchmarks")]
21 |
22 | use super::*;
23 |
24 | use arkworks_setups::{common::setup_params, Curve};
25 | use frame_benchmarking::{
26 | benchmarks_instance_pallet, impl_benchmark_test_suite, whitelisted_caller,
27 | };
28 | use frame_support::traits::Currency;
29 | use frame_system::RawOrigin;
30 | use sp_runtime::traits::Bounded;
31 | use sp_std::vec;
32 | use webb_primitives::traits::merkle_tree::TreeInterface;
33 |
34 | type BalanceOf =
35 | <>::Currency as Currency<::AccountId>>::Balance;
36 |
37 | fn assert_last_event, I: 'static>(generic_event: >::RuntimeEvent) {
38 | frame_system::Pallet::::assert_last_event(generic_event.into());
39 | }
40 |
41 | pub fn hasher_params() -> Vec {
42 | let curve = Curve::Bn254;
43 | let params = setup_params::(curve, 5, 3);
44 | params.to_bytes()
45 | }
46 |
47 | benchmarks_instance_pallet! {
48 | where_clause { where T: pallet_hasher::Config }
49 |
50 | create {
51 | let d in 1..>::MaxTreeDepth::get() as u32;
52 | pallet_hasher::Pallet::::force_set_parameters(RawOrigin::Root.into(), hasher_params().try_into().unwrap()).unwrap();
53 | let caller: T::AccountId = whitelisted_caller();
54 | <>::Currency as Currency>::make_free_balance_be(&caller, BalanceOf::::max_value());
55 | let tree_id = Pallet::::next_tree_id();
56 |
57 | }:_(RawOrigin::Signed(caller.clone()), d as u8)
58 | verify {
59 | assert_last_event::(Event::TreeCreation{tree_id: tree_id, who: caller}.into())
60 | }
61 |
62 | insert {
63 | let caller: T::AccountId = whitelisted_caller();
64 | pallet_hasher::Pallet::::force_set_parameters(RawOrigin::Root.into(), hasher_params().try_into().unwrap()).unwrap();
65 | let tree_id: T::TreeId = as TreeInterface<_,_,_>>::create(Some(caller.clone()), T::MaxTreeDepth::get()).unwrap();
66 | let leaf_index = Pallet::::next_leaf_index(tree_id);
67 | let element: T::Element = T::DefaultZeroElement::get();
68 |
69 | }:_(RawOrigin::Signed(caller.clone()), tree_id, element)
70 | verify {
71 | assert_last_event::(Event::LeafInsertion{tree_id, leaf_index, leaf: element}.into())
72 | }
73 |
74 | force_set_default_hashes {
75 | let p in 1..>::MaxTreeDepth::get() as u32;
76 |
77 | let default_hashes = vec![>::DefaultZeroElement::get();p as usize];
78 |
79 | }:_(RawOrigin::Root, default_hashes.try_into().unwrap())
80 | verify {
81 | assert_eq!(DefaultHashes::::get().len(), p as usize)
82 | }
83 |
84 | }
85 |
86 | impl_benchmark_test_suite!(Pallet, crate::mock::new_test_ext(), crate::mock::Test);
87 |
--------------------------------------------------------------------------------
/pallets/mt/src/types.rs:
--------------------------------------------------------------------------------
1 | //! All the traits exposed to be used in other custom pallets
2 | use crate::*;
3 | use codec::{Decode, Encode, MaxEncodedLen};
4 | use frame_support::BoundedVec;
5 | use scale_info::TypeInfo;
6 |
7 | #[derive(Default, Clone, Encode, Decode, TypeInfo, MaxEncodedLen)]
8 | pub struct TreeMetadata> {
9 | /// Creator account
10 | pub creator: Option,
11 | /// Is paused
12 | pub paused: bool,
13 | /// Current number of leaves in the tree
14 | pub leaf_count: LeafIndex,
15 | /// Maximum allowed leaves in the tree
16 | pub max_leaves: LeafIndex,
17 | /// Depth of the tree
18 | pub depth: u8,
19 | /// The root hash of the tree
20 | pub root: Element,
21 | /// Edge nodes of tree, used to compute roots on the fly
22 | pub edge_nodes: BoundedVec,
23 | }
24 |
--------------------------------------------------------------------------------
/pallets/relayer-registry/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | authors = ["Webb Technologies Inc."]
3 | description = "A pallet that maintains relayer configuration metadata."
4 | edition = "2021"
5 | homepage = "https://substrate.dev"
6 | license = "Unlicense"
7 | name = "pallet-relayer-registry"
8 | repository = "https://github.com/webb-tools/protocol-substrate"
9 | version = "1.0.0"
10 |
11 | [package.metadata.docs.rs]
12 | targets = ["x86_64-unknown-linux-gnu"]
13 |
14 | [dependencies]
15 | codec = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive", "max-encoded-len"] }
16 | frame-support = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
17 | frame-system = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
18 | log = { version = "0.4.14", default-features = false }
19 | pallet-identity = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39", default-features = false }
20 | scale-info = { version = "2.1.1", default-features = false, features = ["derive"] }
21 | sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
22 | sp-std = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
23 |
24 | frame-benchmarking = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39", optional = true }
25 | frame-system-benchmarking = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39", optional = true }
26 |
27 | webb-primitives = { path = "../../primitives", default-features = false, features = ["verifying"] }
28 |
29 | [dev-dependencies]
30 | pallet-balances = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
31 | serde = { version = "1.0.119" }
32 | sp-core = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
33 | sp-io = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
34 | sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
35 |
36 | [features]
37 | default = ["std"]
38 | runtime-benchmarks = [
39 | "frame-benchmarking",
40 | "frame-system/runtime-benchmarks",
41 | "frame-support/runtime-benchmarks",
42 | ]
43 | std = [
44 | "codec/std",
45 | "frame-support/std",
46 | "frame-system/std",
47 | "sp-runtime/std",
48 | "sp-std/std",
49 | "webb-primitives/std",
50 | "pallet-identity/std",
51 | ]
52 |
--------------------------------------------------------------------------------
/pallets/relayer-registry/src/benchmarking.rs:
--------------------------------------------------------------------------------
1 | // This file is part of Webb.
2 |
3 | // Copyright (C) 2021-2023 Webb Technologies Inc.
4 | // SPDX-License-Identifier: Apache-2.0
5 |
6 | // Licensed under the Apache License, Version 2.0 (the "License");
7 | // you may not use this file except in compliance with the License.
8 | // You may obtain a copy of the License at
9 | //
10 | // http://www.apache.org/licenses/LICENSE-2.0
11 | //
12 | // Unless required by applicable law or agreed to in writing, software
13 | // distributed under the License is distributed on an "AS IS" BASIS,
14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | // See the License for the specific language governing permissions and
16 | // limitations under the License.
17 |
18 | //! Verifier pallet benchmarking.
19 |
20 | #![cfg(feature = "runtime-benchmarks")]
21 |
22 | use super::*;
23 |
24 | use frame_benchmarking::{benchmarks, impl_benchmark_test_suite, whitelisted_caller};
25 | use frame_support::traits::Get;
26 | use frame_system::RawOrigin;
27 | use webb_primitives::webb_proposals::ResourceId;
28 |
29 | fn assert_last_event(generic_event: ::RuntimeEvent) {
30 | frame_system::Pallet::::assert_last_event(generic_event.into());
31 | }
32 |
33 | benchmarks! {
34 | set_resource {
35 | let caller: T::AccountId = whitelisted_caller();
36 | let bridge_index = 0_u32;
37 | let resource_id : ResourceId = [0u8;32].into();
38 | let metadata : ResourceInfo = Default::default();
39 | T::Currency::make_free_balance_be(&caller.clone(), 200_000_000u32.into());
40 | }: _(RawOrigin::Signed(caller.clone()), resource_id, Box::new(metadata))
41 | verify {
42 | assert_last_event::(Event::ResourceSet{ who : caller}.into())
43 | }
44 |
45 | clear_resource {
46 | let caller: T::AccountId = whitelisted_caller();
47 | let bridge_index = 0_u32;
48 | let resource_id : ResourceId = [0u8;32].into();
49 | let metadata : ResourceInfo = Default::default();
50 | T::Currency::make_free_balance_be(&caller.clone(), 200_000_000u32.into());
51 | Pallet::::set_resource(RawOrigin::Signed(caller.clone()).into(), resource_id, Box::new(metadata)).unwrap();
52 | }: _(RawOrigin::Signed(caller.clone()), resource_id)
53 | verify {
54 | assert_last_event::(Event::ResourceCleared{ who : caller, deposit : T::BasicDeposit::get() }.into())
55 | }
56 | }
57 |
58 | impl_benchmark_test_suite!(Pallet, crate::mock::new_test_ext(), crate::mock::Test);
59 |
--------------------------------------------------------------------------------
/pallets/relayer-registry/src/mock.rs:
--------------------------------------------------------------------------------
1 | use super::*;
2 | use crate as pallet_relayer_registry;
3 |
4 | use frame_support::parameter_types;
5 | use frame_system as system;
6 | use sp_core::H256;
7 | use sp_runtime::{
8 | testing::Header,
9 | traits::{BlakeTwo256, IdentityLookup},
10 | AccountId32,
11 | };
12 | use sp_std::convert::{TryFrom, TryInto};
13 | use webb_primitives::AccountId;
14 | pub use webb_primitives::{
15 | verifier::{InstanceVerifier, VerifierModule},
16 | verifying::ArkworksVerifierBn254,
17 | };
18 |
19 | type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic;
20 | type Block = frame_system::mocking::MockBlock;
21 |
22 | // Configure a mock runtime to test the pallet.
23 | frame_support::construct_runtime!(
24 | pub enum Test where
25 | Block = Block,
26 | NodeBlock = Block,
27 | UncheckedExtrinsic = UncheckedExtrinsic,
28 | {
29 | System: frame_system::{Pallet, Call, Config, Storage, Event},
30 | RelayerRegistry: pallet_relayer_registry::{Pallet, Call, Storage, Event},
31 | Balances: pallet_balances::{Pallet, Call, Storage, Event},
32 | }
33 | );
34 |
35 | parameter_types! {
36 | pub const BlockHashCount: u64 = 250;
37 | pub const SS58Prefix: u8 = 42;
38 | }
39 |
40 | impl system::Config for Test {
41 | type AccountData = pallet_balances::AccountData;
42 | type AccountId = AccountId;
43 | type BaseCallFilter = frame_support::traits::Everything;
44 | type BlockHashCount = BlockHashCount;
45 | type BlockLength = ();
46 | type BlockNumber = u64;
47 | type BlockWeights = ();
48 | type RuntimeCall = RuntimeCall;
49 | type DbWeight = ();
50 | type RuntimeEvent = RuntimeEvent;
51 | type Hash = H256;
52 | type Hashing = BlakeTwo256;
53 | type Header = Header;
54 | type Index = u64;
55 | type Lookup = IdentityLookup;
56 | type MaxConsumers = frame_support::traits::ConstU32<16>;
57 | type OnKilledAccount = ();
58 | type OnNewAccount = ();
59 | type OnSetCode = ();
60 | type RuntimeOrigin = RuntimeOrigin;
61 | type PalletInfo = PalletInfo;
62 | type SS58Prefix = SS58Prefix;
63 | type SystemWeightInfo = ();
64 | type Version = ();
65 | }
66 |
67 | parameter_types! {
68 | pub const ExistentialDeposit: u64 = 1;
69 | }
70 |
71 | impl pallet_balances::Config for Test {
72 | type AccountStore = System;
73 | type Balance = u128;
74 | type DustRemoval = ();
75 | type RuntimeEvent = RuntimeEvent;
76 | type ExistentialDeposit = ExistentialDeposit;
77 | type MaxLocks = ();
78 | type MaxReserves = ();
79 | type ReserveIdentifier = [u8; 8];
80 | type WeightInfo = ();
81 | }
82 |
83 | parameter_types! {
84 | pub const MaxAdditionalFields: u32 = 10;
85 | pub const FieldDeposit: u64 = 1;
86 | pub const BasicDeposit: u64 = 1;
87 | }
88 |
89 | impl pallet_relayer_registry::Config for Test {
90 | type RuntimeEvent = RuntimeEvent;
91 | type Currency = Balances;
92 | type BasicDeposit = BasicDeposit;
93 | type FieldDeposit = FieldDeposit;
94 | type MaxAdditionalFields = MaxAdditionalFields;
95 | type ForceOrigin = frame_system::EnsureRoot;
96 | type WeightInfo = ();
97 | }
98 |
99 | // Build genesis storage according to the mock runtime.
100 | pub fn new_test_ext() -> sp_io::TestExternalities {
101 | let mut storage = system::GenesisConfig::default().build_storage::().unwrap();
102 | let _ = pallet_balances::GenesisConfig:: {
103 | balances: vec![
104 | (AccountId32::new([1u8; 32]), 10u128.pow(18)),
105 | (AccountId32::new([2u8; 32]), 20u128.pow(18)),
106 | (AccountId32::new([3u8; 32]), 30u128.pow(18)),
107 | ],
108 | }
109 | .assimilate_storage(&mut storage);
110 | storage.into()
111 | }
112 |
--------------------------------------------------------------------------------
/pallets/relayer-registry/src/tests.rs:
--------------------------------------------------------------------------------
1 | use super::*;
2 | use crate::mock::*;
3 | use frame_support::assert_ok;
4 | use sp_runtime::AccountId32;
5 | use webb_primitives::webb_proposals::ResourceId;
6 | #[test]
7 | fn set_resource_works() {
8 | new_test_ext().execute_with(|| {
9 | // Prepare some balance to pay deposit
10 | let caller = AccountId32::new([1u8; 32]);
11 | let resource_id: ResourceId = [1u8; 32].into();
12 | Balances::make_free_balance_be(&caller, 1000_u32.into());
13 |
14 | assert_ok!(RelayerRegistry::set_resource(
15 | RuntimeOrigin::signed(caller.clone()),
16 | resource_id,
17 | Default::default()
18 | ));
19 |
20 | // ensure the deposit has been deducted
21 | assert_eq!(Balances::free_balance(&caller), 999_u32.into());
22 |
23 | assert_eq!(
24 | ResourceOf::::get(caller, resource_id).unwrap(),
25 | ResourceRecord { deposit: 1_u32.into(), info: Default::default() }
26 | )
27 | });
28 | }
29 |
30 | #[test]
31 | fn clear_resource_works() {
32 | new_test_ext().execute_with(|| {
33 | // Prepare some balance to pay deposit
34 | let caller = AccountId32::new([1u8; 32]);
35 | let resource_id: ResourceId = [1u8; 32].into();
36 | Balances::make_free_balance_be(&caller, 1000_u32.into());
37 |
38 | assert_ok!(RelayerRegistry::set_resource(
39 | RuntimeOrigin::signed(caller.clone()),
40 | resource_id,
41 | Default::default()
42 | ));
43 |
44 | assert_ok!(RelayerRegistry::clear_resource(
45 | RuntimeOrigin::signed(caller.clone()),
46 | resource_id
47 | ));
48 |
49 | // ensure the deposit has been retured
50 | assert_eq!(Balances::free_balance(&caller), 1000_u32.into());
51 |
52 | assert_eq!(ResourceOf::::get(caller, resource_id), None)
53 | });
54 | }
55 |
--------------------------------------------------------------------------------
/pallets/relayer-registry/src/types.rs:
--------------------------------------------------------------------------------
1 | // This file is part of Substrate.
2 |
3 | // Copyright (C) 2021-2022 Parity Technologies (UK) Ltd.
4 | // SPDX-License-Identifier: Apache-2.0
5 |
6 | // Licensed under the Apache License, Version 2.0 (the "License");
7 | // you may not use this file except in compliance with the License.
8 | // You may obtain a copy of the License at
9 | //
10 | // http://www.apache.org/licenses/LICENSE-2.0
11 | //
12 | // Unless required by applicable law or agreed to in writing, software
13 | // distributed under the License is distributed on an "AS IS" BASIS,
14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | // See the License for the specific language governing permissions and
16 | // limitations under the License.
17 |
18 | use super::*;
19 | use codec::{Decode, Encode, MaxEncodedLen};
20 | use frame_support::{traits::Get, BoundedVec, CloneNoBound, PartialEqNoBound, RuntimeDebugNoBound};
21 | use pallet_identity::Data;
22 | use scale_info::TypeInfo;
23 | use sp_std::{fmt::Debug, prelude::*};
24 | use webb_primitives::webb_proposals::{TargetSystem, TypedChainId};
25 |
26 | /// Information concerning the identity of the controller of an account.
27 | ///
28 | /// NOTE: This should be stored at the end of the storage item to facilitate the addition of extra
29 | /// fields in a backwards compatible way through a specialized `Decode` impl.
30 | #[derive(
31 | CloneNoBound,
32 | Encode,
33 | Decode,
34 | Eq,
35 | MaxEncodedLen,
36 | PartialEqNoBound,
37 | RuntimeDebugNoBound,
38 | TypeInfo,
39 | frame_support::DefaultNoBound,
40 | )]
41 | #[codec(mel_bound())]
42 | #[scale_info(skip_type_params(FieldLimit))]
43 | pub struct ResourceInfo> {
44 | /// Additional fields of the identity that are not catered for with the struct's explicit
45 | /// fields.
46 | pub additional: BoundedVec<(Data, Data), FieldLimit>,
47 |
48 | /// A reasonable display name for the controller of the account. This should be whatever it is
49 | /// that it is typically known as and should not be confusable with other entities, given
50 | /// reasonable context.
51 | ///
52 | /// Stored as UTF-8.
53 | pub display: Data,
54 |
55 | /// The TypedChainId of where the resource is located.
56 | pub chain: TypedChainId,
57 |
58 | /// The TargetSystem of the resource
59 | pub target_system: TargetSystem,
60 | }
61 |
62 | /// Information concerning the identity of the controller of an account.
63 | ///
64 | /// NOTE: This is stored separately primarily to facilitate the addition of extra fields in a
65 | /// backwards compatible way through a specialized `Decode` impl.
66 | #[derive(
67 | CloneNoBound, Encode, Eq, MaxEncodedLen, PartialEqNoBound, RuntimeDebugNoBound, TypeInfo,
68 | )]
69 | #[codec(mel_bound())]
70 | #[scale_info(skip_type_params(MaxAdditionalFields))]
71 | pub struct ResourceRecord<
72 | Balance: Encode + Decode + MaxEncodedLen + Copy + Clone + Debug + Eq + PartialEq,
73 | MaxAdditionalFields: Get,
74 | > {
75 | /// Amount held on deposit for this information.
76 | pub deposit: Balance,
77 |
78 | /// Information on the identity.
79 | pub info: ResourceInfo,
80 | }
81 |
82 | impl<
83 | Balance: Encode + Decode + MaxEncodedLen + Copy + Clone + Debug + Eq + PartialEq,
84 | MaxAdditionalFields: Get,
85 | > Decode for ResourceRecord
86 | {
87 | fn decode(input: &mut I) -> sp_std::result::Result {
88 | let (deposit, info) = Decode::decode(&mut AppendZerosInput::new(input))?;
89 | Ok(Self { deposit, info })
90 | }
91 | }
92 |
--------------------------------------------------------------------------------
/pallets/relayer-registry/src/weights.rs:
--------------------------------------------------------------------------------
1 | // This file is part of Webb.
2 |
3 | // Copyright (C) 2022 Webb Technologies Inc.
4 | // SPDX-License-Identifier: Apache-2.0
5 |
6 | // Licensed under the Apache License, Version 2.0 (the "License");
7 | // you may not use this file except in compliance with the License.
8 | // You may obtain a copy of the License at
9 | //
10 | // http://www.apache.org/licenses/LICENSE-2.0
11 | //
12 | // Unless required by applicable law or agreed to in writing, software
13 | // distributed under the License is distributed on an "AS IS" BASIS,
14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | // See the License for the specific language governing permissions and
16 | // limitations under the License.
17 |
18 | //! Autogenerated weights for pallet_relayer_registry
19 | //!
20 | //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
21 | //! DATE: 2022-08-01, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]`
22 | //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024
23 |
24 | // Executed Command:
25 | // ./target/release/webb-standalone-node
26 | // benchmark
27 | // pallet
28 | // --chain=dev
29 | // --steps=20
30 | // --repeat=10
31 | // --log=warn
32 | // --pallet=pallet-relayer-registry
33 | // --extrinsic=*
34 | // --execution=wasm
35 | // --wasm-execution=compiled
36 | // --output=./pallets/relayer-registry/src/weights.rs
37 | // --template=./.maintain/webb-weight-template.hbs
38 |
39 | #![cfg_attr(rustfmt, rustfmt_skip)]
40 | #![allow(unused_parens)]
41 | #![allow(unused_imports)]
42 |
43 | use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}};
44 | use sp_std::marker::PhantomData;
45 |
46 | /// Weight functions needed for pallet_relayer_registry.
47 | pub trait WeightInfo {
48 | fn set_resource() -> Weight;
49 | fn clear_resource() -> Weight;
50 | }
51 |
52 | /// Weights for pallet_relayer_registry using the Substrate node and recommended hardware.
53 | pub struct WebbWeight(PhantomData);
54 | impl WeightInfo for WebbWeight {
55 | // Storage: RelayerRegistry ResourceOf (r:1 w:1)
56 | fn set_resource() -> Weight {
57 | Weight::from_ref_time(28_000_000)
58 | .saturating_add(T::DbWeight::get().reads(1_u64))
59 | .saturating_add(T::DbWeight::get().writes(1_u64))
60 | }
61 | // Storage: RelayerRegistry ResourceOf (r:1 w:1)
62 | fn clear_resource() -> Weight {
63 | Weight::from_ref_time(25_000_000)
64 | .saturating_add(T::DbWeight::get().reads(1_u64))
65 | .saturating_add(T::DbWeight::get().writes(1_u64))
66 | }
67 | }
68 |
69 | // For backwards compatibility and tests
70 | impl WeightInfo for () {
71 | // Storage: RelayerRegistry ResourceOf (r:1 w:1)
72 | fn set_resource() -> Weight {
73 | Weight::from_ref_time(28_000_000)
74 | .saturating_add(RocksDbWeight::get().reads(1_u64))
75 | .saturating_add(RocksDbWeight::get().writes(1_u64))
76 | }
77 | // Storage: RelayerRegistry ResourceOf (r:1 w:1)
78 | fn clear_resource() -> Weight {
79 | Weight::from_ref_time(25_000_000)
80 | .saturating_add(RocksDbWeight::get().reads(1_u64))
81 | .saturating_add(RocksDbWeight::get().writes(1_u64))
82 | }
83 | }
--------------------------------------------------------------------------------
/pallets/signature-bridge/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | authors = ["Webb Technologies Inc."]
3 | description = "FRAME pallet for Webb bridge."
4 | edition = "2021"
5 | homepage = "https://substrate.dev"
6 | license = "Unlicense"
7 | name = "pallet-signature-bridge"
8 | repository = "https://github.com/webb-tools/protocol-substrate"
9 | version = "1.0.0"
10 |
11 | [package.metadata.docs.rs]
12 | targets = ["x86_64-unknown-linux-gnu"]
13 |
14 | [dependencies]
15 | # primitives
16 | codec = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive", "max-encoded-len"] }
17 | scale-info = { version = "2.1.1", default-features = false, features = ["derive"] }
18 |
19 | sp-core = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
20 | sp-io = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
21 | sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
22 | sp-std = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
23 | # frame dependencies
24 | frame-support = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
25 | frame-system = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
26 |
27 | frame-benchmarking = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39", optional = true }
28 | frame-system-benchmarking = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39", optional = true }
29 |
30 | impl-trait-for-tuples = "0.2.2"
31 | libsecp256k1 = { version = "0.7.0", default-features = false, optional = true }
32 | webb-primitives = { path = "../../primitives", default-features = false }
33 |
34 | [dev-dependencies]
35 | hex-literal = "0.3.4"
36 | libsecp256k1 = "0.7.0"
37 | pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
38 | sp-keystore = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39", default-features = false }
39 |
40 | [features]
41 | default = ["std"]
42 | runtime-benchmarks = [
43 | "frame-benchmarking/runtime-benchmarks",
44 | "libsecp256k1",
45 | ]
46 | std = [
47 | "codec/std",
48 | "sp-std/std",
49 | "sp-runtime/std",
50 | "sp-io/std",
51 | "sp-core/std",
52 | "frame-support/std",
53 | "frame-system/std",
54 | "pallet-balances/std",
55 | "webb-primitives/std",
56 | ]
57 |
--------------------------------------------------------------------------------
/pallets/token-wrapper-handler/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | authors = ["Webb Technologies Inc."]
3 | description = "A token wrapper handler for the bridging system"
4 | edition = "2021"
5 | homepage = "https://substrate.dev"
6 | license = "Unlicense"
7 | name = "pallet-token-wrapper-handler"
8 | repository = "https://github.com/webb-tools/protocol-substrate"
9 | version = "1.0.0"
10 |
11 | [package.metadata.docs.rs]
12 | targets = ["x86_64-unknown-linux-gnu"]
13 |
14 | [dependencies]
15 | asset-registry = { package = "pallet-asset-registry", path = "../asset-registry", default-features = false }
16 | codec = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive", "max-encoded-len"] }
17 | frame-support = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
18 | frame-system = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
19 | orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library.git", branch = "polkadot-v0.9.39", default-features = false }
20 | pallet-token-wrapper = { path = "../token-wrapper", default-features = false }
21 | scale-info = { version = "2.1.1", default-features = false, features = ["derive"] }
22 | sp-arithmetic = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
23 | sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
24 | sp-std = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
25 |
26 | #Optional dependencies
27 | frame-benchmarking = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39", optional = true }
28 |
29 | [dev-dependencies]
30 | hex-literal = "0.3.4"
31 | orml-currencies = { git = "https://github.com/open-web3-stack/open-runtime-module-library.git", branch = "polkadot-v0.9.39", default-features = false }
32 | orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library.git", branch = "polkadot-v0.9.39", default-features = false }
33 | pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39" }
34 | pallet-signature-bridge = { path = "../signature-bridge", default-features = false }
35 | pallet-treasury = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39" }
36 | sp-core = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
37 | sp-io = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
38 | webb-primitives = { path = "../../primitives", default-features = false }
39 | webb-proposals = { git = "https://github.com/webb-tools/webb-rs", default-features = false, features = ["scale", "substrate"] }
40 |
41 | [features]
42 | default = ["std"]
43 | runtime-benchmarks = [
44 | "frame-system/runtime-benchmarks",
45 | "frame-support/runtime-benchmarks",
46 | ]
47 | std = [
48 | "codec/std",
49 | "scale-info/std",
50 | "frame-support/std",
51 | "frame-system/std",
52 | "sp-runtime/std",
53 | "sp-std/std",
54 | "orml-traits/std",
55 | "asset-registry/std",
56 | "webb-primitives/std",
57 | "sp-arithmetic/std",
58 | "pallet-token-wrapper/std",
59 | ]
60 |
--------------------------------------------------------------------------------
/pallets/token-wrapper/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | authors = ["Webb Technologies Inc."]
3 | description = "A pallet for maintaing wrapping relationships for various tokens."
4 | edition = "2021"
5 | homepage = "https://substrate.dev"
6 | license = "Unlicense"
7 | name = "pallet-token-wrapper"
8 | repository = "https://github.com/webb-tools/protocol-substrate"
9 | version = "1.0.0"
10 |
11 | [package.metadata.docs.rs]
12 | targets = ["x86_64-unknown-linux-gnu"]
13 |
14 | [dependencies]
15 | codec = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive", "max-encoded-len"] }
16 | scale-info = { version = "2.1.1", default-features = false, features = ["derive"] }
17 |
18 | asset-registry = { package = "pallet-asset-registry", path = "../asset-registry", default-features = false }
19 | frame-support = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
20 | frame-system = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
21 | sp-arithmetic = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
22 | sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
23 | sp-std = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
24 |
25 | orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library.git", branch = "polkadot-v0.9.39", default-features = false }
26 |
27 | #Optional dependencies
28 | frame-benchmarking = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39", optional = true }
29 |
30 | [dev-dependencies]
31 | orml-currencies = { git = "https://github.com/open-web3-stack/open-runtime-module-library.git", branch = "polkadot-v0.9.39", default-features = false }
32 | orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library.git", branch = "polkadot-v0.9.39", default-features = false }
33 | pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39" }
34 | pallet-treasury = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39" }
35 | sp-core = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
36 | sp-io = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
37 | webb-primitives = { path = "../../primitives", default-features = false }
38 |
39 | [features]
40 | default = ["std"]
41 | runtime-benchmarks = [
42 | "frame-benchmarking",
43 | "frame-system/runtime-benchmarks",
44 | "frame-support/runtime-benchmarks",
45 | ]
46 | std = [
47 | "codec/std",
48 | "scale-info/std",
49 | "frame-support/std",
50 | "frame-system/std",
51 | "sp-runtime/std",
52 | "sp-std/std",
53 | "orml-traits/std",
54 | "webb-primitives/std",
55 | "asset-registry/std",
56 | "sp-arithmetic/std",
57 | ]
58 |
--------------------------------------------------------------------------------
/pallets/token-wrapper/src/traits.rs:
--------------------------------------------------------------------------------
1 | #![allow(clippy::ptr_arg, clippy::type_complexity)]
2 | use frame_support::dispatch;
3 | use sp_std::vec::Vec;
4 |
5 | pub trait TokenWrapperInterface {
6 | fn set_wrapping_fee(
7 | into_pool_share_id: AssetId,
8 | fee: Balance,
9 | nonce: Nonce,
10 | ) -> Result<(), dispatch::DispatchError>;
11 | fn set_fee_recipient(
12 | pool_share_id: AssetId,
13 | fee_recipient: AccountId,
14 | nonce: Nonce,
15 | ) -> Result<(), dispatch::DispatchError>;
16 | fn rescue_tokens(
17 | from_pool_share_id: AssetId,
18 | asset_id: AssetId,
19 | amount: Balance,
20 | recipient: AccountId,
21 | nonce: Nonce,
22 | ) -> Result<(), dispatch::DispatchError>;
23 | fn wrap(
24 | from: AccountId,
25 | from_asset_id: AssetId,
26 | into_pool_share_id: AssetId,
27 | amount: Balance,
28 | recipient: AccountId,
29 | ) -> Result<(), dispatch::DispatchError>;
30 | fn unwrap(
31 | from: AccountId,
32 | from_pool_share_id: AssetId,
33 | into_asset_id: AssetId,
34 | amount: Balance,
35 | recipient: AccountId,
36 | ) -> Result<(), dispatch::DispatchError>;
37 | fn add_asset_to_existing_pool(
38 | name: &Vec,
39 | asset_id: AssetId,
40 | nonce: Nonce,
41 | ) -> Result;
42 | fn delete_asset_from_existing_pool(
43 | name: &Vec,
44 | asset_id: AssetId,
45 | nonce: Nonce,
46 | ) -> Result;
47 | }
48 |
--------------------------------------------------------------------------------
/pallets/token-wrapper/src/weights.rs:
--------------------------------------------------------------------------------
1 |
2 | //! Autogenerated weights for `pallet_token_wrapper`
3 | //!
4 | //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
5 | //! DATE: 2021-11-11, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]`
6 | //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 128
7 |
8 | // Executed Command:
9 | // ./target/release/webb-standalone-node
10 | // benchmark
11 | // --chain=dev
12 | // --execution
13 | // wasm
14 | // --wasm-execution
15 | // compiled
16 | // --pallet
17 | // pallet_token_wrapper
18 | // --extrinsic
19 | // *
20 | // --steps
21 | // 50
22 | // --repeat
23 | // 20
24 | // --raw
25 | // --output
26 | // ./pallets/token-wrapper/src/weights.rs
27 |
28 |
29 | #![cfg_attr(rustfmt, rustfmt_skip)]
30 | #![allow(unused_parens)]
31 | #![allow(unused_imports)]
32 |
33 | use frame_support::{traits::Get, weights::Weight};
34 | use sp_std::marker::PhantomData;
35 |
36 | pub trait WeightInfo {
37 | fn wrap() -> Weight;
38 | fn unwrap() -> Weight;
39 | fn set_wrapping_fee() -> Weight;
40 | }
41 |
42 | /// Weight functions for `pallet_token_wrapper`.
43 | pub struct WebbWeight(PhantomData);
44 | impl WeightInfo for WebbWeight {
45 | // Storage: AssetRegistry Assets (r:2 w:0)
46 | // Storage: TokenWrapper WrappingFeePercent (r:1 w:0)
47 | // Storage: Tokens Accounts (r:3 w:3)
48 | // Storage: System Account (r:1 w:1)
49 | // Storage: Tokens TotalIssuance (r:1 w:1)
50 | fn wrap() -> Weight {
51 | Weight::from_ref_time(141_546_000_u64)
52 | .saturating_add(T::DbWeight::get().reads(8_u64))
53 | .saturating_add(T::DbWeight::get().writes(5_u64))
54 | }
55 | // Storage: AssetRegistry Assets (r:2 w:0)
56 | // Storage: Tokens Accounts (r:3 w:3)
57 | // Storage: Tokens TotalIssuance (r:1 w:1)
58 | // Storage: System Account (r:1 w:1)
59 | fn unwrap() -> Weight {
60 | Weight::from_ref_time(125_843_000_u64)
61 | .saturating_add(T::DbWeight::get().reads(7_u64))
62 | .saturating_add(T::DbWeight::get().writes(5_u64))
63 | }
64 | // Storage: TokenWrapper WrappingFeePercent (r:0 w:1)
65 | fn set_wrapping_fee() -> Weight {
66 | Weight::from_ref_time(16_705_000_u64)
67 | .saturating_add(T::DbWeight::get().writes(1_u64))
68 | }
69 | }
70 |
71 | impl WeightInfo for () {
72 | fn wrap() -> Weight {
73 | Weight::from_ref_time(0)
74 | }
75 |
76 | fn unwrap() -> Weight {
77 | Weight::from_ref_time(0)
78 | }
79 |
80 | fn set_wrapping_fee() -> Weight {
81 | Weight::from_ref_time(0)
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/pallets/vanchor-verifier/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | authors = ["Webb Technologies Inc."]
3 | description = "A pallet that stores zero-knowledge verifier parameters and provides verification of zero-knowledge proofs for VAnchors."
4 | edition = "2021"
5 | homepage = "https://substrate.dev"
6 | license = "Unlicense"
7 | name = "pallet-vanchor-verifier"
8 | repository = "https://github.com/webb-tools/protocol-substrate"
9 | version = "1.0.0"
10 |
11 | [package.metadata.docs.rs]
12 | targets = ["x86_64-unknown-linux-gnu"]
13 |
14 | [dependencies]
15 | codec = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive", "max-encoded-len"] }
16 | frame-support = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
17 | frame-system = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
18 | log = { version = "0.4.14", default-features = false }
19 | scale-info = { version = "2.1.1", default-features = false, features = ["derive"] }
20 | sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
21 | sp-std = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
22 | webb-primitives = { path = "../../primitives", default-features = false, features = ["verifying"] }
23 |
24 | frame-benchmarking = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39", optional = true }
25 | frame-system-benchmarking = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39", optional = true }
26 |
27 | [dev-dependencies]
28 | ark-crypto-primitives = { version = "^0.3.0", features = ["r1cs"], default-features = false }
29 | pallet-balances = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
30 | serde = { version = "1.0.119" }
31 | sp-core = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
32 | sp-io = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
33 | sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
34 |
35 | [features]
36 | default = ["std"]
37 | runtime-benchmarks = [
38 | "frame-benchmarking",
39 | "frame-system/runtime-benchmarks",
40 | "frame-support/runtime-benchmarks",
41 | "sp-runtime/runtime-benchmarks",
42 | ]
43 | std = [
44 | "codec/std",
45 | "frame-support/std",
46 | "frame-system/std",
47 | "sp-runtime/std",
48 | "sp-std/std",
49 | "webb-primitives/std",
50 | ]
51 |
--------------------------------------------------------------------------------
/pallets/vanchor-verifier/src/benchmarking.rs:
--------------------------------------------------------------------------------
1 | // This file is part of Webb.
2 |
3 | // Copyright (C) 2021-2023 Webb Technologies Inc.
4 | // SPDX-License-Identifier: Apache-2.0
5 |
6 | // Licensed under the Apache License, Version 2.0 (the "License");
7 | // you may not use this file except in compliance with the License.
8 | // You may obtain a copy of the License at
9 | //
10 | // http://www.apache.org/licenses/LICENSE-2.0
11 | //
12 | // Unless required by applicable law or agreed to in writing, software
13 | // distributed under the License is distributed on an "AS IS" BASIS,
14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | // See the License for the specific language governing permissions and
16 | // limitations under the License.
17 |
18 | //! Verifier pallet benchmarking.
19 |
20 | #![cfg(feature = "runtime-benchmarks")]
21 |
22 | use super::*;
23 | use crate::Pallet;
24 | use frame_benchmarking::{
25 | account, benchmarks_instance_pallet, impl_benchmark_test_suite, whitelist_account,
26 | whitelisted_caller,
27 | };
28 | use frame_support::traits::Currency;
29 | use frame_system::RawOrigin;
30 | use webb_primitives::types::DepositDetails;
31 |
32 | fn assert_last_event, I: 'static>(generic_event: >::RuntimeEvent) {
33 | frame_system::Pallet::::assert_last_event(generic_event.into());
34 | }
35 |
36 | const SEED: u32 = 0;
37 | // Based on verifier bytes generated from the zero knowledge setup for anchor
38 | // pallet and mixer pallet, Max verifier bytes length generated ranged between
39 | // 456 - 552
40 | const MAX_VERIFIER_LENGTH: u32 = 1024;
41 |
42 | benchmarks_instance_pallet! {
43 | force_set_parameters {
44 | let c in 0..MAX_VERIFIER_LENGTH;
45 | let depositor: T::AccountId = account("depositor", 0, SEED);
46 | let parameters = vec![0u8;c as usize];
47 | }: _(RawOrigin::Root, (1u8,1u8), parameters.clone().try_into().unwrap())
48 | verify {
49 | assert_eq!(Pallet::::parameters((1u8,1u8)), parameters);
50 | }
51 | }
52 |
53 | impl_benchmark_test_suite!(Pallet, crate::mock::new_test_ext(), crate::mock::Test);
54 |
--------------------------------------------------------------------------------
/pallets/vanchor-verifier/src/mock.rs:
--------------------------------------------------------------------------------
1 | use super::*;
2 | use crate as pallet_vanchor_verifier;
3 |
4 | use frame_support::parameter_types;
5 | use frame_system as system;
6 | use sp_core::H256;
7 | use sp_runtime::{
8 | testing::Header,
9 | traits::{BlakeTwo256, ConstU32, IdentityLookup},
10 | AccountId32,
11 | };
12 | use sp_std::convert::{TryFrom, TryInto};
13 | use webb_primitives::AccountId;
14 | pub use webb_primitives::{
15 | verifier::{InstanceVerifier, VerifierModule},
16 | verifying::ArkworksVerifierBn254,
17 | };
18 |
19 | type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic;
20 | type Block = frame_system::mocking::MockBlock;
21 |
22 | // Configure a mock runtime to test the pallet.
23 | frame_support::construct_runtime!(
24 | pub enum Test where
25 | Block = Block,
26 | NodeBlock = Block,
27 | UncheckedExtrinsic = UncheckedExtrinsic,
28 | {
29 | System: frame_system::{Pallet, Call, Config, Storage, Event},
30 | VerifierPallet: pallet_vanchor_verifier::{Pallet, Call, Storage, Event},
31 | Balances: pallet_balances::{Pallet, Call, Storage, Event},
32 | }
33 | );
34 |
35 | parameter_types! {
36 | pub const BlockHashCount: u64 = 250;
37 | pub const SS58Prefix: u8 = 42;
38 | }
39 |
40 | impl system::Config for Test {
41 | type AccountData = pallet_balances::AccountData;
42 | type AccountId = AccountId;
43 | type BaseCallFilter = frame_support::traits::Everything;
44 | type BlockHashCount = BlockHashCount;
45 | type BlockLength = ();
46 | type BlockNumber = u64;
47 | type BlockWeights = ();
48 | type RuntimeCall = RuntimeCall;
49 | type DbWeight = ();
50 | type RuntimeEvent = RuntimeEvent;
51 | type Hash = H256;
52 | type Hashing = BlakeTwo256;
53 | type Header = Header;
54 | type Index = u64;
55 | type Lookup = IdentityLookup;
56 | type MaxConsumers = frame_support::traits::ConstU32<16>;
57 | type OnKilledAccount = ();
58 | type OnNewAccount = ();
59 | type OnSetCode = ();
60 | type RuntimeOrigin = RuntimeOrigin;
61 | type PalletInfo = PalletInfo;
62 | type SS58Prefix = SS58Prefix;
63 | type SystemWeightInfo = ();
64 | type Version = ();
65 | }
66 |
67 | parameter_types! {
68 | pub const ExistentialDeposit: u64 = 1;
69 | }
70 |
71 | impl pallet_balances::Config for Test {
72 | type AccountStore = System;
73 | type Balance = u128;
74 | type DustRemoval = ();
75 | type RuntimeEvent = RuntimeEvent;
76 | type ExistentialDeposit = ExistentialDeposit;
77 | type MaxLocks = ();
78 | type MaxReserves = ();
79 | type ReserveIdentifier = [u8; 8];
80 | type WeightInfo = ();
81 | }
82 |
83 | parameter_types! {
84 | pub const ParameterDeposit: u64 = 1;
85 | pub const StringLimit: u32 = 50;
86 | pub const MetadataDepositBase: u64 = 1;
87 | pub const MetadataDepositPerByte: u64 = 1;
88 | }
89 |
90 | impl pallet_vanchor_verifier::Config for Test {
91 | type RuntimeEvent = RuntimeEvent;
92 | type ForceOrigin = frame_system::EnsureRoot;
93 | type Verifier = ArkworksVerifierBn254;
94 | type MaxParameterLength = ConstU32<100>;
95 | type WeightInfo = ();
96 | }
97 |
98 | // Build genesis storage according to the mock runtime.
99 | pub fn new_test_ext() -> sp_io::TestExternalities {
100 | let mut storage = system::GenesisConfig::default().build_storage::().unwrap();
101 | let _ = pallet_balances::GenesisConfig:: {
102 | balances: vec![
103 | (AccountId32::new([1u8; 32]), 10u128.pow(18)),
104 | (AccountId32::new([2u8; 32]), 20u128.pow(18)),
105 | (AccountId32::new([3u8; 32]), 30u128.pow(18)),
106 | ],
107 | }
108 | .assimilate_storage(&mut storage);
109 | storage.into()
110 | }
111 |
--------------------------------------------------------------------------------
/pallets/vanchor-verifier/src/tests.rs:
--------------------------------------------------------------------------------
1 | use super::*;
2 | use crate::mock::*;
3 | use frame_support::assert_err;
4 |
5 | #[test]
6 | fn should_fail_to_verify_without_parameters() {
7 | new_test_ext().execute_with(|| {
8 | // Pass arbitrary
9 | assert_err!(
10 | ::verify(&[], &[1u8; 32], 0, 0),
11 | Error::::VerifyingParametersNotInitialized
12 | );
13 | });
14 | }
15 |
--------------------------------------------------------------------------------
/pallets/vanchor-verifier/src/weights.rs:
--------------------------------------------------------------------------------
1 | // This file is part of Webb.
2 |
3 | // Copyright (C) 2022 Webb Technologies Inc.
4 | // SPDX-License-Identifier: Apache-2.0
5 |
6 | // Licensed under the Apache License, Version 2.0 (the "License");
7 | // you may not use this file except in compliance with the License.
8 | // You may obtain a copy of the License at
9 | //
10 | // http://www.apache.org/licenses/LICENSE-2.0
11 | //
12 | // Unless required by applicable law or agreed to in writing, software
13 | // distributed under the License is distributed on an "AS IS" BASIS,
14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | // See the License for the specific language governing permissions and
16 | // limitations under the License.
17 |
18 | //! Autogenerated weights for pallet_vanchor_verifier
19 | //!
20 | //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
21 | //! DATE: 2022-06-14, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]`
22 | //! HOSTNAME: ``, CPU: ``
23 | //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024
24 |
25 | // Executed Command:
26 | // ./target/release/webb-standalone-node
27 | // benchmark
28 | // pallet
29 | // --chain=dev
30 | // --steps=20
31 | // --repeat=10
32 | // --log=warn
33 | // --pallet=pallet-vanchor-verifier
34 | // --extrinsic=*
35 | // --execution=wasm
36 | // --wasm-execution=compiled
37 | // --output=./pallets/verifier/src/weights.rs
38 | // --template=./.maintain/webb-weight-template.hbs
39 |
40 | #![cfg_attr(rustfmt, rustfmt_skip)]
41 | #![allow(unused_parens)]
42 | #![allow(unused_imports)]
43 |
44 | use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}};
45 | use sp_std::marker::PhantomData;
46 |
47 | /// Weight functions needed for pallet_vanchor_verifier.
48 | pub trait WeightInfo {
49 | fn force_set_parameters(c: u32, ) -> Weight;
50 | }
51 |
52 | /// Weights for pallet_vanchor_verifier using the Substrate node and recommended hardware.
53 | pub struct WebbWeight(PhantomData);
54 | impl WeightInfo for WebbWeight {
55 | // Storage: MixerVerifierBn254 Parameters (r:1 w:1)
56 | fn force_set_parameters(c: u32, ) -> Weight {
57 | Weight::from_ref_time(3_653_000)
58 | // Standard Error: 0
59 | .saturating_add(Weight::from_ref_time(1_000).saturating_mul(c as u64))
60 | .saturating_add(T::DbWeight::get().reads(1_u64))
61 | .saturating_add(T::DbWeight::get().writes(1_u64))
62 | }
63 | }
64 |
65 | // For backwards compatibility and tests
66 | impl WeightInfo for () {
67 | // Storage: MixerVerifierBn254 Parameters (r:1 w:1)
68 | fn force_set_parameters(c: u32, ) -> Weight {
69 | Weight::from_ref_time(3_653_000)
70 | // Standard Error: 0
71 | .saturating_add(Weight::from_ref_time(1_000).saturating_mul(c as u64))
72 | .saturating_add(RocksDbWeight::get().reads(1_u64))
73 | .saturating_add(RocksDbWeight::get().writes(1_u64))
74 | }
75 | }
--------------------------------------------------------------------------------
/pallets/verifier/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | authors = ["Webb Technologies Inc."]
3 | description = "A pallet that stores zero-knowledge verifier parameters and provides verification of zero-knowledge proofs."
4 | edition = "2021"
5 | homepage = "https://substrate.dev"
6 | license = "Unlicense"
7 | name = "pallet-verifier"
8 | repository = "https://github.com/webb-tools/protocol-substrate"
9 | version = "1.0.0"
10 |
11 | [package.metadata.docs.rs]
12 | targets = ["x86_64-unknown-linux-gnu"]
13 |
14 | [dependencies]
15 | codec = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive", "max-encoded-len"] }
16 | frame-support = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
17 | frame-system = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
18 | log = { version = "0.4.14", default-features = false }
19 | scale-info = { version = "2.1.1", default-features = false, features = ["derive"] }
20 | sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
21 | sp-std = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
22 | webb-primitives = { path = "../../primitives", default-features = false, features = ["verifying"] }
23 |
24 | frame-benchmarking = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39", optional = true }
25 | frame-system-benchmarking = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39", optional = true }
26 |
27 | [dev-dependencies]
28 | ark-crypto-primitives = { version = "^0.3.0", features = ["r1cs"], default-features = false }
29 | pallet-balances = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
30 | serde = { version = "1.0.119" }
31 | sp-core = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
32 | sp-io = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
33 | sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
34 |
35 | [features]
36 | default = ["std"]
37 | runtime-benchmarks = [
38 | "frame-benchmarking",
39 | "frame-system/runtime-benchmarks",
40 | "frame-support/runtime-benchmarks",
41 | ]
42 | std = [
43 | "codec/std",
44 | "frame-support/std",
45 | "frame-system/std",
46 | "sp-runtime/std",
47 | "sp-std/std",
48 | "webb-primitives/std",
49 | ]
50 |
--------------------------------------------------------------------------------
/pallets/verifier/src/benchmarking.rs:
--------------------------------------------------------------------------------
1 | // This file is part of Webb.
2 |
3 | // Copyright (C) 2021-2023 Webb Technologies Inc.
4 | // SPDX-License-Identifier: Apache-2.0
5 |
6 | // Licensed under the Apache License, Version 2.0 (the "License");
7 | // you may not use this file except in compliance with the License.
8 | // You may obtain a copy of the License at
9 | //
10 | // http://www.apache.org/licenses/LICENSE-2.0
11 | //
12 | // Unless required by applicable law or agreed to in writing, software
13 | // distributed under the License is distributed on an "AS IS" BASIS,
14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | // See the License for the specific language governing permissions and
16 | // limitations under the License.
17 |
18 | //! Verifier pallet benchmarking.
19 |
20 | #![cfg(feature = "runtime-benchmarks")]
21 |
22 | use super::*;
23 | use crate::Pallet;
24 | use frame_benchmarking::{
25 | account, benchmarks_instance_pallet, impl_benchmark_test_suite, whitelist_account,
26 | whitelisted_caller,
27 | };
28 | use frame_support::traits::Currency;
29 | use frame_system::RawOrigin;
30 | use sp_runtime::traits::Bounded;
31 | use webb_primitives::types::DepositDetails;
32 |
33 | fn assert_last_event, I: 'static>(generic_event: >::RuntimeEvent) {
34 | frame_system::Pallet::::assert_last_event(generic_event.into());
35 | }
36 |
37 | const SEED: u32 = 0;
38 | // Based on verifier bytes generated from the zero knowledge setup for anchor
39 | // pallet and mixer pallet, Max verifier bytes length generated ranged between
40 | // 456 - 552
41 | const MAX_VERIFIER_LENGTH: u32 = 1024;
42 |
43 | benchmarks_instance_pallet! {
44 | force_set_parameters {
45 | let c in 0..MAX_VERIFIER_LENGTH;
46 | let depositor: T::AccountId = account("depositor", 0, SEED);
47 | let parameters = vec![0u8;c as usize];
48 | }: _(RawOrigin::Root, parameters.clone().try_into().unwrap())
49 | verify {
50 | assert_eq!(Pallet::::parameters().into_inner(), parameters);
51 | }
52 | }
53 |
54 | impl_benchmark_test_suite!(Pallet, crate::mock::new_test_ext(), crate::mock::Test);
55 |
--------------------------------------------------------------------------------
/pallets/verifier/src/mock.rs:
--------------------------------------------------------------------------------
1 | use super::*;
2 | use crate as pallet_verifier;
3 |
4 | use frame_support::parameter_types;
5 | use frame_system as system;
6 | use sp_core::H256;
7 | use sp_runtime::{
8 | testing::Header,
9 | traits::{BlakeTwo256, ConstU32, IdentityLookup},
10 | AccountId32,
11 | };
12 | use sp_std::convert::{TryFrom, TryInto};
13 | use webb_primitives::AccountId;
14 | pub use webb_primitives::{
15 | verifier::{InstanceVerifier, VerifierModule},
16 | verifying::ArkworksVerifierBn254,
17 | };
18 |
19 | type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic;
20 | type Block = frame_system::mocking::MockBlock;
21 |
22 | // Configure a mock runtime to test the pallet.
23 | frame_support::construct_runtime!(
24 | pub enum Test where
25 | Block = Block,
26 | NodeBlock = Block,
27 | UncheckedExtrinsic = UncheckedExtrinsic,
28 | {
29 | System: frame_system::{Pallet, Call, Config, Storage, Event},
30 | VerifierPallet: pallet_verifier::{Pallet, Call, Storage, Event},
31 | Balances: pallet_balances::{Pallet, Call, Storage, Event},
32 | }
33 | );
34 |
35 | parameter_types! {
36 | pub const BlockHashCount: u64 = 250;
37 | pub const SS58Prefix: u8 = 42;
38 | }
39 |
40 | impl system::Config for Test {
41 | type AccountData = pallet_balances::AccountData;
42 | type AccountId = AccountId;
43 | type BaseCallFilter = frame_support::traits::Everything;
44 | type BlockHashCount = BlockHashCount;
45 | type BlockLength = ();
46 | type BlockNumber = u64;
47 | type BlockWeights = ();
48 | type RuntimeCall = RuntimeCall;
49 | type DbWeight = ();
50 | type RuntimeEvent = RuntimeEvent;
51 | type Hash = H256;
52 | type Hashing = BlakeTwo256;
53 | type Header = Header;
54 | type Index = u64;
55 | type Lookup = IdentityLookup;
56 | type MaxConsumers = frame_support::traits::ConstU32<16>;
57 | type OnKilledAccount = ();
58 | type OnNewAccount = ();
59 | type OnSetCode = ();
60 | type RuntimeOrigin = RuntimeOrigin;
61 | type PalletInfo = PalletInfo;
62 | type SS58Prefix = SS58Prefix;
63 | type SystemWeightInfo = ();
64 | type Version = ();
65 | }
66 |
67 | parameter_types! {
68 | pub const ExistentialDeposit: u64 = 1;
69 | }
70 |
71 | impl pallet_balances::Config for Test {
72 | type AccountStore = System;
73 | type Balance = u128;
74 | type DustRemoval = ();
75 | type RuntimeEvent = RuntimeEvent;
76 | type ExistentialDeposit = ExistentialDeposit;
77 | type MaxLocks = ();
78 | type MaxReserves = ();
79 | type ReserveIdentifier = [u8; 8];
80 | type WeightInfo = ();
81 | }
82 |
83 | parameter_types! {
84 | pub const ParameterDeposit: u64 = 1;
85 | pub const StringLimit: u32 = 50;
86 | pub const MetadataDepositBase: u64 = 1;
87 | pub const MetadataDepositPerByte: u64 = 1;
88 | }
89 |
90 | impl pallet_verifier::Config for Test {
91 | type RuntimeEvent = RuntimeEvent;
92 | type ForceOrigin = frame_system::EnsureRoot;
93 | type MaxParameterLength = ConstU32<100>;
94 | type Verifier = ArkworksVerifierBn254;
95 | type WeightInfo = ();
96 | }
97 |
98 | // Build genesis storage according to the mock runtime.
99 | pub fn new_test_ext() -> sp_io::TestExternalities {
100 | let mut storage = system::GenesisConfig::default().build_storage::().unwrap();
101 | let _ = pallet_balances::GenesisConfig:: {
102 | balances: vec![
103 | (AccountId32::new([1u8; 32]), 10u128.pow(18)),
104 | (AccountId32::new([2u8; 32]), 20u128.pow(18)),
105 | (AccountId32::new([3u8; 32]), 30u128.pow(18)),
106 | ],
107 | }
108 | .assimilate_storage(&mut storage);
109 | storage.into()
110 | }
111 |
--------------------------------------------------------------------------------
/pallets/verifier/src/tests.rs:
--------------------------------------------------------------------------------
1 | use super::*;
2 | use crate::mock::*;
3 | use frame_support::assert_err;
4 |
5 | #[test]
6 | fn should_fail_to_verify_without_parameters() {
7 | new_test_ext().execute_with(|| {
8 | // Pass arbitrary
9 | assert_err!(
10 | ::verify(&[], &[1u8; 32]),
11 | Error::::VerifyingParametersNotInitialized
12 | );
13 | });
14 | }
15 |
--------------------------------------------------------------------------------
/pallets/verifier/src/weights.rs:
--------------------------------------------------------------------------------
1 | // This file is part of Webb.
2 |
3 | // Copyright (C) 2022 Webb Technologies Inc.
4 | // SPDX-License-Identifier: Apache-2.0
5 |
6 | // Licensed under the Apache License, Version 2.0 (the "License");
7 | // you may not use this file except in compliance with the License.
8 | // You may obtain a copy of the License at
9 | //
10 | // http://www.apache.org/licenses/LICENSE-2.0
11 | //
12 | // Unless required by applicable law or agreed to in writing, software
13 | // distributed under the License is distributed on an "AS IS" BASIS,
14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | // See the License for the specific language governing permissions and
16 | // limitations under the License.
17 |
18 | //! Autogenerated weights for pallet_verifier
19 | //!
20 | //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
21 | //! DATE: 2022-06-14, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]`
22 | //! HOSTNAME: ``, CPU: ``
23 | //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024
24 |
25 | // Executed Command:
26 | // ./target/release/webb-standalone-node
27 | // benchmark
28 | // pallet
29 | // --chain=dev
30 | // --steps=20
31 | // --repeat=10
32 | // --log=warn
33 | // --pallet=pallet-verifier
34 | // --extrinsic=*
35 | // --execution=wasm
36 | // --wasm-execution=compiled
37 | // --output=./pallets/verifier/src/weights.rs
38 | // --template=./.maintain/webb-weight-template.hbs
39 |
40 | #![cfg_attr(rustfmt, rustfmt_skip)]
41 | #![allow(unused_parens)]
42 | #![allow(unused_imports)]
43 |
44 | use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}};
45 | use sp_std::marker::PhantomData;
46 |
47 | /// Weight functions needed for pallet_verifier.
48 | pub trait WeightInfo {
49 | fn force_set_parameters(c: u32, ) -> Weight;
50 | }
51 |
52 | /// Weights for pallet_verifier using the Substrate node and recommended hardware.
53 | pub struct WebbWeight(PhantomData);
54 | impl WeightInfo for WebbWeight {
55 | // Storage: MixerVerifierBn254 Parameters (r:1 w:1)
56 | fn force_set_parameters(c: u32, ) -> Weight {
57 | Weight::from_ref_time(3_653_000)
58 | // Standard Error: 0
59 | .saturating_add(Weight::from_ref_time(1_000).saturating_mul(c as u64))
60 | .saturating_add(T::DbWeight::get().reads(1_u64))
61 | .saturating_add(T::DbWeight::get().writes(1_u64))
62 | }
63 | }
64 |
65 | // For backwards compatibility and tests
66 | impl WeightInfo for () {
67 | // Storage: MixerVerifierBn254 Parameters (r:1 w:1)
68 | fn force_set_parameters(c: u32, ) -> Weight {
69 | Weight::from_ref_time(3_653_000)
70 | // Standard Error: 0
71 | .saturating_add(Weight::from_ref_time(1_000).saturating_mul(c as u64))
72 | .saturating_add(RocksDbWeight::get().reads(1_u64))
73 | .saturating_add(RocksDbWeight::get().writes(1_u64))
74 | }
75 | }
--------------------------------------------------------------------------------
/pallets/xanchor/src/types.rs:
--------------------------------------------------------------------------------
1 | use scale_info::TypeInfo;
2 |
3 | use crate::*;
4 | pub trait DemocracyGovernanceDelegate {
5 | fn propose(origin: OriginFor, proposal: Proposal, value: Balance) -> DispatchResult;
6 | }
7 |
8 | #[cfg_attr(feature = "std", derive(Debug))]
9 | #[derive(Clone, Encode, Decode, PartialEq, TypeInfo)]
10 | pub struct LinkProposal {
11 | pub target_chain_id: ChainId,
12 | pub target_tree_id: TreeId,
13 | pub local_tree_id: TreeId,
14 | }
15 |
--------------------------------------------------------------------------------
/primitives/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | authors = ["Drew Stone "]
3 | edition = "2018"
4 | name = "webb-primitives"
5 | version = "0.1.0"
6 |
7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
8 |
9 | [dependencies]
10 | codec = { default-features = false, features = ["derive", "max-encoded-len"], package = "parity-scale-codec", version = "3" }
11 | frame-support = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
12 | scale-info = { version = "2.1.1", default-features = false, features = ["derive"] }
13 | serde = { version = "1.0.119", optional = true, features = ["derive"] }
14 | sp-consensus-aura = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
15 | sp-consensus-babe = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
16 | sp-core = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
17 | sp-io = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
18 | sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
19 | sp-std = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
20 |
21 | # Arkworks
22 | ark-bls12-381 = { version = "^0.3.0", default-features = false, features = ["curve"], optional = true }
23 | ark-bn254 = { version = "^0.3.0", default-features = false, features = ["curve"], optional = true }
24 | ark-ec = { version = "^0.3.0", default-features = false }
25 | ark-ff = { version = "^0.3.0", default-features = false }
26 | ark-groth16 = { git = "https://github.com/arkworks-rs/groth16", rev = "765817f", default-features = false }
27 | # ark-groth16 = { version = "^0.3.0", default-features = false }
28 | ark-relations = { version = "^0.3.0", default-features = false }
29 | ark-serialize = { version = "^0.3.0", default-features = false, features = ["derive"] }
30 | ark-std = { version = "^0.3.0", default-features = false }
31 | # ark-circom = { git = "https://github.com/gakonst/ark-circom.git", default-features = false }
32 |
33 | blake2 = { version = "0.9", default-features = false }
34 | byteorder = { version = "1", default-features = false }
35 | digest = { version = "0.9", default-features = false }
36 | hex = { version = "0.4", default-features = false }
37 |
38 | ark-crypto-primitives = { version = "^0.3.0", default-features = false }
39 | arkworks-native-gadgets = { version = "1.2.0", default-features = false, optional = true }
40 |
41 | ethabi = { version = "15.0.0", default-features = false }
42 |
43 | webb-proposals = { git = "https://github.com/webb-tools/webb-rs", default-features = false, features = ["scale", "substrate", "evm"] }
44 |
45 |
46 | [features]
47 | default = ["std", "hashing", "verifying", "field_ops"]
48 | field_ops = [
49 | "ark-bls12-381",
50 | "ark-bn254",
51 | ]
52 | hashing = [
53 | "arkworks-native-gadgets",
54 | "ark-bls12-381",
55 | "ark-bn254",
56 | ]
57 | std = [
58 | "serde",
59 | "codec/std",
60 | "frame-support/std",
61 | "sp-core/std",
62 | "sp-std/std",
63 | "sp-io/std",
64 | "sp-runtime/std",
65 | "sp-consensus-aura/std",
66 | "sp-consensus-babe/std",
67 | "ark-ff/std",
68 | "ark-ec/std",
69 | "ark-std/std",
70 | "ark-relations/std",
71 | "webb-proposals/std",
72 | "hex/std",
73 | ]
74 | verifying = [
75 | "arkworks-native-gadgets",
76 | "ark-bls12-381",
77 | "ark-bn254",
78 | ]
79 |
--------------------------------------------------------------------------------
/primitives/src/field_ops/arkworks.rs:
--------------------------------------------------------------------------------
1 | use ark_bn254::Fr as Bn254;
2 | use ark_ff::{BigInteger, PrimeField};
3 | use sp_std::{marker::PhantomData, vec::Vec};
4 |
5 | pub trait IntoPrimeField {
6 | fn into_field(value: T) -> Vec;
7 | }
8 |
9 | pub struct ArkworksIntoField(PhantomData);
10 |
11 | impl IntoPrimeField for ArkworksIntoField {
12 | fn into_field(value: i128) -> Vec {
13 | let mut f = F::from(value.unsigned_abs());
14 | if value.is_negative() {
15 | f = -f;
16 | }
17 | f.into_repr().to_bytes_be()
18 | }
19 | }
20 |
21 | pub type ArkworksIntoFieldBn254 = ArkworksIntoField;
22 |
--------------------------------------------------------------------------------
/primitives/src/field_ops/mod.rs:
--------------------------------------------------------------------------------
1 | pub mod arkworks;
2 | pub use arkworks::*;
3 |
--------------------------------------------------------------------------------
/primitives/src/hasher.rs:
--------------------------------------------------------------------------------
1 | use ark_crypto_primitives::Error;
2 | use frame_support::pallet_prelude::DispatchError;
3 | use sp_std::vec::Vec;
4 |
5 | // A trait meant to be implemented over a hash function instance
6 | pub trait InstanceHasher {
7 | fn hash(data: &[u8], params: &[u8]) -> Result, Error>;
8 | }
9 |
10 | // A trait meant to be implemented by a pallet
11 | pub trait HasherModule {
12 | /// hash arbitrary slice
13 | fn hash(data: &[u8]) -> Result, DispatchError>;
14 | /// hash two elements
15 | fn hash_two(left: &[u8], right: &[u8]) -> Result, DispatchError>;
16 | }
17 |
--------------------------------------------------------------------------------
/primitives/src/hashing/arkworks.rs:
--------------------------------------------------------------------------------
1 | use crate::*;
2 | use ark_crypto_primitives::Error;
3 | use ark_ff::{BigInteger, PrimeField};
4 | use arkworks_native_gadgets::{
5 | poseidon::{FieldHasher, Poseidon, PoseidonParameters},
6 | to_field_elements,
7 | };
8 | use sp_std::{marker::PhantomData, vec::Vec};
9 |
10 | pub struct ArkworksPoseidonHasher(PhantomData);
11 |
12 | impl InstanceHasher for ArkworksPoseidonHasher {
13 | fn hash(input: &[u8], param_bytes: &[u8]) -> Result, Error> {
14 | let els = to_field_elements(input)?;
15 | let params = PoseidonParameters::::from_bytes(param_bytes)?;
16 | let poseidon = Poseidon::new(params);
17 | let output: F = poseidon.hash(&els)?;
18 | let value = output.into_repr().to_bytes_be();
19 | Ok(value)
20 | }
21 | }
22 |
23 | use ark_bn254::Fr as Bn254;
24 | pub type ArkworksPoseidonHasherBn254 = ArkworksPoseidonHasher;
25 |
--------------------------------------------------------------------------------
/primitives/src/hashing/ethereum.rs:
--------------------------------------------------------------------------------
1 | use crate::hasher::InstanceHasher;
2 | use ark_crypto_primitives::Error;
3 | use ark_ff::{BigInteger, PrimeField};
4 | pub use sp_io::hashing::keccak_256;
5 | use sp_std::{marker::PhantomData, vec::Vec};
6 |
7 | pub struct Keccak256Hasher(PhantomData);
8 |
9 | impl InstanceHasher for Keccak256Hasher {
10 | fn hash(data: &[u8], _: &[u8]) -> Result, Error> {
11 | let res = keccak_256(data);
12 | let field_res = F::from_be_bytes_mod_order(&res);
13 | let value = field_res.into_repr().to_bytes_be();
14 | Ok(value)
15 | }
16 | }
17 |
18 | use ark_bn254::Fr as Bn254;
19 | pub type Keccak256HasherBn254 = Keccak256Hasher;
20 |
--------------------------------------------------------------------------------
/primitives/src/hashing/mod.rs:
--------------------------------------------------------------------------------
1 | pub mod arkworks;
2 | pub use arkworks::*;
3 | pub mod ethereum;
4 |
--------------------------------------------------------------------------------
/primitives/src/lib.rs:
--------------------------------------------------------------------------------
1 | #![cfg_attr(not(feature = "std"), no_std)]
2 |
3 | pub mod hasher;
4 | pub mod runtime;
5 | pub mod signing;
6 | pub mod traits;
7 | pub mod types;
8 | pub mod utils;
9 | pub mod verifier;
10 |
11 | #[cfg(feature = "hashing")]
12 | pub mod hashing;
13 |
14 | #[cfg(feature = "verifying")]
15 | pub mod verifying;
16 |
17 | #[cfg(feature = "field_ops")]
18 | pub mod field_ops;
19 |
20 | pub use hasher::*;
21 | pub use runtime::*;
22 | pub use traits::*;
23 | pub use types::*;
24 | pub use verifier::*;
25 |
26 | pub use runtime::*;
27 |
28 | pub use webb_proposals;
29 |
30 | /// Opaque types. These are used by the CLI to instantiate machinery that don't
31 | /// need to know the specifics of the runtime. They can then be made to be
32 | /// agnostic over specific formats of data like extrinsics, allowing for them to
33 | /// continue syncing the network through upgrades to even the core data
34 | /// structures.
35 | pub mod opaque {
36 | use super::*;
37 | use sp_runtime::{generic, traits::BlakeTwo256};
38 |
39 | pub use sp_runtime::OpaqueExtrinsic as UncheckedExtrinsic;
40 | /// Opaque block header type.
41 | pub type Header = generic::Header;
42 | /// Opaque block type.
43 | pub type Block = generic::Block;
44 | /// Opaque block identifier type.
45 | pub type BlockId = generic::BlockId;
46 | }
47 |
--------------------------------------------------------------------------------
/primitives/src/runtime.rs:
--------------------------------------------------------------------------------
1 | use crate::ElementTrait;
2 | use codec::{Decode, Encode};
3 | use frame_support::sp_runtime::{
4 | generic,
5 | traits::{BlakeTwo256, IdentifyAccount, Verify},
6 | MultiSignature,
7 | };
8 |
9 | /// An index to a block.
10 | pub type BlockNumber = u64;
11 |
12 | /// Alias to 512-bit hash when used in the context of a transaction
13 | /// signature on the chain.
14 | pub type Signature = MultiSignature;
15 |
16 | /// Some way of identifying an account on the chain. We intentionally make
17 | /// it equivalent to the public key of our transaction signing scheme.
18 | pub type AccountId = <::Signer as IdentifyAccount>::AccountId;
19 |
20 | /// The type for looking up accounts. We don't expect more than 4 billion of
21 | /// them, but you never know...
22 | pub type AccountIndex = u32;
23 |
24 | pub type AssetId = u32;
25 |
26 | /// Balance of an account.
27 | pub type Balance = u128;
28 |
29 | pub type Amount = i128;
30 |
31 | /// Index of a transaction in the chain.
32 | pub type Index = u32;
33 |
34 | /// Index of a leaf in a merkle tree
35 | pub type LeafIndex = u32;
36 |
37 | /// Chain Id for Webb-encoded chain identifiers
38 | pub type ChainId = u64;
39 |
40 | /// A hash of some data used by the chain.
41 | pub type Hash = sp_core::H256;
42 |
43 | /// Digest item type.
44 | pub type DigestItem = generic::DigestItem;
45 |
46 | /// Opaque types. These are used by the CLI to instantiate machinery that
47 | /// don't need to know the specifics of the runtime. They can then be made
48 | /// to be agnostic over specific formats of data like extrinsics, allowing
49 | /// for them to continue syncing the network through upgrades to even the
50 | /// core data structures.
51 | pub mod opaque {
52 | use super::*;
53 |
54 | pub use sp_runtime::OpaqueExtrinsic as UncheckedExtrinsic;
55 |
56 | /// Opaque block header type.
57 | pub type Header = generic::Header;
58 | /// Opaque block type.
59 | pub type Block = generic::Block;
60 | /// Opaque block identifier type.
61 | pub type BlockId = generic::BlockId;
62 | }
63 |
64 | #[derive(
65 | Debug,
66 | Encode,
67 | Decode,
68 | Default,
69 | Copy,
70 | Clone,
71 | PartialEq,
72 | Eq,
73 | scale_info::TypeInfo,
74 | codec::MaxEncodedLen,
75 | )]
76 | #[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))]
77 | pub struct Element(pub [u8; 32]);
78 |
79 | impl ElementTrait for Element {
80 | fn to_bytes(&self) -> &[u8] {
81 | &self.0
82 | }
83 |
84 | fn from_bytes(input: &[u8]) -> Self {
85 | let mut buf = [0u8; 32];
86 | buf.iter_mut().zip(input).for_each(|(a, b)| *a = *b);
87 | Self(buf)
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/primitives/src/signing/ecdsa.rs:
--------------------------------------------------------------------------------
1 | pub use sp_io::{hashing::keccak_256, EcdsaVerifyError};
2 | use sp_std::vec::Vec;
3 |
4 | pub const SIGNATURE_LENGTH: usize = 65;
5 |
6 | pub fn validate_ecdsa_signature(data: &[u8], signature: &[u8]) -> bool {
7 | if signature.len() == SIGNATURE_LENGTH {
8 | let mut sig = [0u8; SIGNATURE_LENGTH];
9 | sig[..SIGNATURE_LENGTH].copy_from_slice(signature);
10 |
11 | let hash = keccak_256(data);
12 |
13 | sp_io::crypto::secp256k1_ecdsa_recover(&sig, &hash).is_ok()
14 | } else {
15 | false
16 | }
17 | }
18 |
19 | pub fn recover_ecdsa_pub_key(data: &[u8], signature: &[u8]) -> Result, EcdsaVerifyError> {
20 | if signature.len() == SIGNATURE_LENGTH {
21 | let mut sig = [0u8; SIGNATURE_LENGTH];
22 | sig[..SIGNATURE_LENGTH].copy_from_slice(signature);
23 |
24 | let hash = keccak_256(data);
25 | let pub_key = sp_io::crypto::secp256k1_ecdsa_recover(&sig, &hash)?;
26 | return Ok(pub_key.to_vec())
27 | }
28 | Err(EcdsaVerifyError::BadSignature)
29 | }
30 |
--------------------------------------------------------------------------------
/primitives/src/signing/mod.rs:
--------------------------------------------------------------------------------
1 | use sp_std::vec::Vec;
2 | pub mod ecdsa;
3 |
4 | pub trait SigningSystem {
5 | type Error;
6 |
7 | fn verify(key: &[u8], msg: &[u8], sig: &[u8]) -> Result {
8 | let public_key = Self::recover_pub_key(msg, sig)?;
9 | Ok(public_key == *key)
10 | }
11 | /// should return the uncompressed public key (64-bytes) without the 0x04 prefix
12 | fn recover_pub_key(msg: &[u8], sig: &[u8]) -> Result, Self::Error>;
13 | }
14 |
15 | pub struct SignatureVerifier;
16 |
17 | impl SigningSystem for SignatureVerifier {
18 | type Error = ecdsa::EcdsaVerifyError;
19 |
20 | /// returns the uncompressed public key(64bytes) without the 0x04 prefix
21 | fn recover_pub_key(msg: &[u8], sig: &[u8]) -> Result, Self::Error> {
22 | ecdsa::recover_ecdsa_pub_key(msg, sig)
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/primitives/src/traits/anchor.rs:
--------------------------------------------------------------------------------
1 | //! All the traits exposed to be used in other custom pallets
2 | use frame_support::dispatch;
3 | use sp_std::vec::Vec;
4 | use webb_proposals::ResourceId;
5 |
6 | pub trait AnchorConfig {
7 | type LeafIndex;
8 | type AccountId;
9 | type Balance;
10 | type CurrencyId;
11 | type ChainId;
12 | type TreeId;
13 | type Element;
14 | }
15 |
16 | /// Anchor trait definition to be used in other pallets
17 | pub trait AnchorInterface {
18 | // Creates a new anchor
19 | fn create(
20 | creator: Option,
21 | deposit_size: C::Balance,
22 | depth: u8,
23 | max_edges: u32,
24 | asset: C::CurrencyId,
25 | ) -> Result;
26 | /// Deposit into the anchor
27 | fn deposit(
28 | account: C::AccountId,
29 | id: C::TreeId,
30 | leaf: C::Element,
31 | ) -> Result<(), dispatch::DispatchError>;
32 | /// Withdraw from the anchor
33 | #[allow(clippy::too_many_arguments)]
34 | fn withdraw(
35 | id: C::TreeId,
36 | proof_bytes: &[u8],
37 | roots: Vec,
38 | nullifier_hash: C::Element,
39 | recipient: C::AccountId,
40 | relayer: C::AccountId,
41 | fee: C::Balance,
42 | refund: C::Balance,
43 | commitment: C::Element,
44 | ) -> Result<(), dispatch::DispatchError>;
45 | // Stores nullifier hash from a spend tx
46 | fn add_nullifier_hash(
47 | id: C::TreeId,
48 | nullifier_hash: C::Element,
49 | ) -> Result<(), dispatch::DispatchError>;
50 | /// Add an edge to this tree
51 | fn add_edge(
52 | id: C::TreeId,
53 | src_chain_id: C::ChainId,
54 | root: C::Element,
55 | latest_leaf_index: C::LeafIndex,
56 | src_resource_id: ResourceId,
57 | ) -> Result<(), dispatch::DispatchError>;
58 | /// Update an edge for this tree
59 | fn update_edge(
60 | id: C::TreeId,
61 | src_chain_id: C::ChainId,
62 | root: C::Element,
63 | latest_leaf_index: C::LeafIndex,
64 | src_resource_id: ResourceId,
65 | ) -> Result<(), dispatch::DispatchError>;
66 | }
67 |
68 | /// Anchor trait for inspecting tree state
69 | pub trait AnchorInspector {
70 | /// Check if a nullifier has been used in a tree or returns
71 | /// `InvalidNullifier`
72 | fn is_nullifier_used(id: C::TreeId, nullifier: C::Element) -> bool;
73 | /// Check if a nullifier has been used in a tree and throws if not
74 | fn ensure_nullifier_unused(
75 | id: C::TreeId,
76 | nullifier: C::Element,
77 | ) -> Result<(), dispatch::DispatchError>;
78 | /// Check if this linked tree has this edge (for backwards compatability)
79 | fn has_edge(id: C::TreeId, src_chain_id: C::ChainId) -> bool;
80 | /// Compute the updated chain id type for this chain
81 | fn get_chain_id_type() -> C::ChainId;
82 | fn get_chain_type() -> [u8; 2];
83 | }
84 |
--------------------------------------------------------------------------------
/primitives/src/traits/key_storage.rs:
--------------------------------------------------------------------------------
1 | //! All the traits exposed to be used in other custom pallets
2 | use codec::Codec;
3 | use frame_support::dispatch;
4 | use sp_std::vec::Vec;
5 |
6 | /// KeyStorage trait definition to be used in other pallets
7 | pub trait KeyStorageInterface {
8 | /// Registers a new public key to the owner
9 | fn register(owner: AccountId, key: Vec) -> Result<(), dispatch::DispatchError>;
10 | }
11 |
--------------------------------------------------------------------------------
/primitives/src/traits/linkable_tree.rs:
--------------------------------------------------------------------------------
1 | //! All the traits exposed to be used in other custom pallets
2 | use frame_support::dispatch;
3 | use sp_std::vec::Vec;
4 | use webb_proposals::ResourceId;
5 |
6 | pub trait LinkableTreeConfig {
7 | type LeafIndex;
8 | type AccountId;
9 | type ChainId;
10 | type TreeId;
11 | type Element;
12 | }
13 |
14 | /// LinkableTree trait definition to be used in other pallets
15 | pub trait LinkableTreeInterface {
16 | // Creates a new linkable tree
17 | fn create(
18 | creator: Option,
19 | max_edges: u32,
20 | depth: u8,
21 | ) -> Result;
22 | // Insert new leaf to the tree
23 | fn insert_in_order(
24 | id: C::TreeId,
25 | leaf: C::Element,
26 | ) -> Result;
27 | /// Add an edge to this tree
28 | fn add_edge(
29 | id: C::TreeId,
30 | src_chain_id: C::ChainId,
31 | root: C::Element,
32 | last_leaf_index: C::LeafIndex,
33 | src_resource_id: ResourceId,
34 | ) -> Result<(), dispatch::DispatchError>;
35 | /// Update an edge for this tree
36 | fn update_edge(
37 | id: C::TreeId,
38 | src_chain_id: C::ChainId,
39 | root: C::Element,
40 | last_leaf_index: C::LeafIndex,
41 | src_resource_id: ResourceId,
42 | ) -> Result<(), dispatch::DispatchError>;
43 | }
44 |
45 | /// Trait for inspecting tree state
46 | pub trait LinkableTreeInspector {
47 | fn get_chain_id() -> C::ChainId;
48 | fn get_chain_id_type() -> C::ChainId;
49 | fn get_chain_type() -> [u8; 2];
50 | /// Checks if a merkle root is in a tree's cached history or returns
51 | fn is_known_root(id: C::TreeId, root: C::Element) -> Result;
52 | // Ensure that passed root is in history
53 | fn ensure_known_root(id: C::TreeId, root: C::Element) -> Result<(), dispatch::DispatchError>;
54 | /// Gets the merkle root for a tree or returns `TreeDoesntExist`
55 | fn get_root(id: C::TreeId) -> Result;
56 | /// Gets the merkle root for a tree or returns `TreeDoesntExist`
57 | fn get_neighbor_roots(id: C::TreeId) -> Result, dispatch::DispatchError>;
58 | /// Checks if a merkle root is in a tree's cached history or returns
59 | /// `TreeDoesntExist`
60 | fn is_known_neighbor_root(
61 | id: C::TreeId,
62 | src_chain_id: C::ChainId,
63 | target_root: C::Element,
64 | ) -> Result