├── .cargo └── config.toml ├── .dockerignore ├── .editorconfig ├── .github ├── ISSUE_TEMPLATE │ └── new-issue.md ├── actions │ └── install-dependencies │ │ └── action.yaml ├── dependabot.yml └── workflows │ ├── build-and-release.yaml │ ├── build-and-run-node-test.yaml │ ├── check-chainspecs.yaml │ ├── check-doc-build.yaml │ ├── cla.yaml │ ├── container-build-and-push.yaml │ ├── dependabot-auto-merge.yml │ ├── git-ref-basename.yaml │ ├── lint-and-check-licenses.yaml │ └── test-runtime-benchmarks.yaml ├── .gitignore ├── .maintain ├── AGPL-3.0-header.txt ├── frame-weight-template.hbs └── ignore_clippy_header.txt ├── .rustfmt.toml ├── .taplo.toml ├── CHANGELOG.md ├── Cargo.lock ├── Cargo.toml ├── Dockerfile ├── LICENSE ├── README.md ├── RELEASE_CHECKLIST.md ├── bin └── entrypoint.sh ├── chains └── devnet.json ├── crates ├── README.md ├── client │ ├── Cargo.toml │ ├── entropy_metadata.scale │ └── src │ │ ├── chain_api.rs │ │ ├── client.rs │ │ ├── errors.rs │ │ ├── lib.rs │ │ ├── substrate.rs │ │ ├── tests.rs │ │ ├── user.rs │ │ └── util.rs ├── kvdb │ ├── Cargo.toml │ ├── MIT-LICENSE │ ├── README.md │ └── src │ │ ├── encrypted_sled │ │ ├── constants.rs │ │ ├── kv.rs │ │ ├── mod.rs │ │ ├── record.rs │ │ ├── result.rs │ │ └── tests.rs │ │ ├── kv_manager │ │ ├── error.rs │ │ ├── helpers.rs │ │ ├── kv.rs │ │ ├── mod.rs │ │ ├── sled_bindings.rs │ │ ├── tests.rs │ │ ├── types.rs │ │ └── value.rs │ │ └── lib.rs ├── protocol │ ├── Cargo.toml │ ├── Makefile │ ├── README.md │ ├── js-README.md │ ├── nodejs-test │ │ ├── index.test.js │ │ ├── package.json │ │ └── yarn.lock │ ├── src │ │ ├── errors.rs │ │ ├── execute_protocol.rs │ │ ├── lib.rs │ │ ├── listener.rs │ │ ├── protocol_message.rs │ │ ├── protocol_transport │ │ │ ├── broadcaster.rs │ │ │ ├── errors.rs │ │ │ ├── mod.rs │ │ │ ├── noise.rs │ │ │ └── subscribe_message.rs │ │ └── sign_and_encrypt │ │ │ ├── hpke.rs │ │ │ ├── mod.rs │ │ │ └── wasm.rs │ └── tests │ │ ├── helpers │ │ └── mod.rs │ │ └── protocol.rs ├── shared │ ├── Cargo.toml │ ├── README.md │ ├── device_key_proxy.wasm │ └── src │ │ ├── attestation.rs │ │ ├── constants.rs │ │ ├── lib.rs │ │ ├── types.rs │ │ └── user.rs ├── test-cli │ ├── Cargo.toml │ ├── README.md │ └── src │ │ ├── lib.rs │ │ └── main.rs ├── testing-utils │ ├── Cargo.toml │ ├── example_barebones_with_auxilary.wasm │ ├── example_custom_hash.wasm │ ├── faucet_program.wasm │ ├── infinite_loop.wasm │ ├── keyshares │ │ ├── README.md │ │ └── production │ │ │ ├── keyshare-held-by-alice.keyshare │ │ │ ├── keyshare-held-by-bob.keyshare │ │ │ └── keyshare-held-by-charlie.keyshare │ ├── null_interface │ ├── oracle_example.wasm │ ├── src │ │ ├── constants.rs │ │ ├── create_test_keyshares.rs │ │ ├── helpers.rs │ │ ├── lib.rs │ │ ├── node_proc.rs │ │ └── substrate_context.rs │ ├── template_barebones.wasm │ └── template_basic_transaction.wasm └── threshold-signature-server │ ├── .gitignore │ ├── Cargo.toml │ ├── README.md │ ├── build.rs │ ├── src │ ├── attestation │ │ ├── api.rs │ │ ├── errors.rs │ │ ├── mod.rs │ │ └── tests.rs │ ├── backup_provider │ │ ├── api.rs │ │ ├── errors.rs │ │ ├── mod.rs │ │ └── tests.rs │ ├── health │ │ ├── api.rs │ │ ├── mod.rs │ │ └── tests.rs │ ├── helpers │ │ ├── app_state.rs │ │ ├── launch.rs │ │ ├── logger.rs │ │ ├── mod.rs │ │ ├── signing.rs │ │ ├── substrate.rs │ │ ├── tests.rs │ │ ├── user.rs │ │ └── validator.rs │ ├── lib.rs │ ├── main.rs │ ├── node_info │ │ ├── api.rs │ │ ├── errors.rs │ │ ├── mod.rs │ │ └── tests.rs │ ├── sign_init.rs │ ├── signing_client │ │ ├── api.rs │ │ ├── errors.rs │ │ ├── mod.rs │ │ ├── protocol_execution │ │ │ ├── context.rs │ │ │ └── mod.rs │ │ ├── protocol_transport.rs │ │ └── tests.rs │ ├── unsafe │ │ ├── api.rs │ │ ├── mod.rs │ │ └── tests.rs │ ├── user │ │ ├── api.rs │ │ ├── errors.rs │ │ ├── mod.rs │ │ └── tests.rs │ ├── validation │ │ ├── errors.rs │ │ └── mod.rs │ └── validator │ │ ├── api.rs │ │ ├── errors.rs │ │ ├── mod.rs │ │ └── tests.rs │ └── tests │ ├── helpers │ └── mod.rs │ ├── jumpstart_register_sign.rs │ └── sign_eth_tx.rs ├── data ├── README.md └── testnet │ └── testnet-accounts.json ├── deny.toml ├── docker-compose-common.yaml ├── docker-compose.yaml ├── node └── cli │ ├── Cargo.toml │ ├── Chainspec-README.md │ ├── build.rs │ ├── src │ ├── benchmarking.rs │ ├── chain_spec │ │ ├── dev.rs │ │ ├── integration_tests.rs │ │ ├── mod.rs │ │ └── testnet.rs │ ├── cli.rs │ ├── command.rs │ ├── endowed_accounts.rs │ ├── main.rs │ ├── rpc.rs │ └── service.rs │ └── test-chainspec-inputs │ └── example-chainspec-inputs.json ├── pallets ├── attestation │ ├── Cargo.toml │ ├── src │ │ ├── benchmarking.rs │ │ ├── lib.rs │ │ ├── mock.rs │ │ ├── tests.rs │ │ └── weights.rs │ └── test_pck_certs │ │ ├── pck_cert.der │ │ └── platform_pcs_cert.der ├── oracle │ ├── Cargo.toml │ └── src │ │ ├── benchmarking.rs │ │ ├── lib.rs │ │ ├── mock.rs │ │ ├── tests.rs │ │ └── weights.rs ├── outtie │ ├── Cargo.toml │ └── src │ │ ├── benchmarking.rs │ │ ├── lib.rs │ │ ├── mock.rs │ │ ├── tests.rs │ │ └── weights.rs ├── parameters │ ├── Cargo.toml │ └── src │ │ ├── benchmarking.rs │ │ ├── lib.rs │ │ ├── mock.rs │ │ ├── tests.rs │ │ └── weights.rs ├── programs │ ├── Cargo.toml │ ├── README.md │ └── src │ │ ├── benchmarking.rs │ │ ├── lib.rs │ │ ├── mock.rs │ │ ├── tests.rs │ │ └── weights.rs ├── propagation │ ├── Cargo.toml │ ├── README.md │ └── src │ │ ├── benchmarking.rs │ │ ├── lib.rs │ │ ├── mock.rs │ │ ├── tests.rs │ │ └── weights.rs ├── registry │ ├── Cargo.toml │ ├── README.md │ └── src │ │ ├── benchmarking.rs │ │ ├── lib.rs │ │ ├── mock.rs │ │ ├── tests.rs │ │ └── weights.rs ├── slashing │ ├── Cargo.toml │ ├── README.md │ └── src │ │ ├── benchmarking.rs │ │ ├── lib.rs │ │ ├── mock.rs │ │ └── tests.rs ├── staking │ ├── Cargo.toml │ ├── README.md │ └── src │ │ ├── benchmarking.rs │ │ ├── lib.rs │ │ ├── mock.rs │ │ ├── tests.rs │ │ └── weights.rs └── transaction-pause │ ├── Cargo.toml │ └── src │ ├── benchmarking.rs │ ├── lib.rs │ ├── mock.rs │ ├── tests.rs │ └── weights.rs ├── runtime ├── Cargo.toml ├── build.rs └── src │ ├── constants.rs │ ├── impls.rs │ ├── lib.rs │ ├── voter_bags.rs │ └── weights │ ├── frame_benchmarking.rs │ ├── frame_election_provider_support.rs │ ├── frame_system.rs │ ├── mod.rs │ ├── pallet_attestation.rs │ ├── pallet_babe.rs │ ├── pallet_bags_list.rs │ ├── pallet_balances.rs │ ├── pallet_bounties.rs │ ├── pallet_collective.rs │ ├── pallet_democracy.rs │ ├── pallet_election_provider_multi_phase.rs │ ├── pallet_elections_phragmen.rs │ ├── pallet_grandpa.rs │ ├── pallet_identity.rs │ ├── pallet_im_online.rs │ ├── pallet_indices.rs │ ├── pallet_membership.rs │ ├── pallet_multisig.rs │ ├── pallet_nomination_pools.rs │ ├── pallet_offences.rs │ ├── pallet_oracle.rs │ ├── pallet_outtie.rs │ ├── pallet_parameters.rs │ ├── pallet_preimage.rs │ ├── pallet_programs.rs │ ├── pallet_propagation.rs │ ├── pallet_proxy.rs │ ├── pallet_recovery.rs │ ├── pallet_registry.rs │ ├── pallet_scheduler.rs │ ├── pallet_session.rs │ ├── pallet_staking.rs │ ├── pallet_staking_extension.rs │ ├── pallet_sudo.rs │ ├── pallet_timestamp.rs │ ├── pallet_tips.rs │ ├── pallet_transaction_pause.rs │ ├── pallet_transaction_payment.rs │ ├── pallet_transaction_storage.rs │ ├── pallet_treasury.rs │ ├── pallet_utility.rs │ └── pallet_vesting.rs ├── rust-toolchain.toml ├── scripts ├── add-license-headers.sh ├── benchmarks.sh ├── build-devnet-chainspec.sh ├── check-entropy-shared.sh ├── create-test-keyshares.sh ├── create-test-keyshares │ ├── Cargo.toml │ ├── README.md │ └── src │ │ └── main.rs ├── fmt.sh ├── generate-validator-node-keys.sh ├── git │ └── hooks │ │ └── pre-commit ├── insert-validator-node-keys.sh ├── pull_entropy_metadata.sh ├── single_benchmark.sh └── update-substrate.sh └── target └── doc └── index.html /.cargo/config.toml: -------------------------------------------------------------------------------- 1 | # This is needed to fetch private dependencies (e.g. `synedrion`). 2 | # This will make Cargo use the locally installed Git, 3 | # and whatever SSH config you have to access Github. 4 | [net] 5 | git-fetch-with-cli=true 6 | -------------------------------------------------------------------------------- /.dockerignore: -------------------------------------------------------------------------------- 1 | # This file lists filesystem patterns to omit from the container 2 | # build context. Omitting files from the build context speeds up 3 | # the build by reducing the amount of files transferred by the 4 | # container engine client to the image build server. 5 | # 6 | # See: 7 | # https://docs.docker.com/build/building/context/#dockerignore-files 8 | 9 | ### 10 | # Docker and container engine preparation/runtime stuff. 11 | ### 12 | .dockerignore 13 | docker-compose.yaml 14 | 15 | ################################# 16 | # General editor and IDE stuff. # 17 | ################################# 18 | *.swp 19 | .editorconfig 20 | 21 | # Microsoft Visual Studio Code 22 | .vscode 23 | .devcontainer 24 | 25 | ############################################## 26 | # Git, GitHub, CI/CD, and Rust system stuff. # 27 | ############################################## 28 | .circleci 29 | .git 30 | .github 31 | .gitignore 32 | .rustfmt.toml 33 | .taplo.toml 34 | CHANGELOG.md 35 | LICENSE 36 | Makefile 37 | README.md 38 | cliff.toml 39 | target 40 | 41 | # Our own generated stuff. 42 | .cargo 43 | .cargo-remote.toml 44 | .entropy 45 | chains 46 | 47 | # We specifically want to include the `create-test-keyshares` crate as part of our builds. 48 | scripts 49 | !scripts/create-test-keyshares/ 50 | 51 | service 52 | shell.nix 53 | 54 | # No idea what this stuff is for but we don't seem to need it. 55 | # TODO: Are these actually just temporary things that we can 56 | # delete because they're no longer needed? Is it cruft? 57 | .envrc 58 | file_header.txt 59 | local-share1.json 60 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig helps developers define and maintain consistent 2 | # coding styles between different editors and IDEs 3 | # editorconfig.org 4 | 5 | root = true 6 | 7 | [*] 8 | indent_style=space 9 | indent_size=4 10 | tab_width=4 11 | end_of_line=lf 12 | charset=utf-8 13 | trim_trailing_whitespace=true 14 | insert_final_newline = true 15 | max_line_length=100 16 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/new-issue.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: New Issue 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | Why is this issue relevant? 11 | 12 | What steps are required to resolve this? 13 | 14 | Does this change the spec? HTTP, extrinsic, or storage? Is it breaking? Clearly describe the new interface. 15 | -------------------------------------------------------------------------------- /.github/actions/install-dependencies/action.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | name: 'Install Dependencies' 3 | description: 'Install the dependencies and Rust components used across jobs' 4 | runs: 5 | using: "composite" 6 | steps: 7 | - name: Install dependencies 8 | run: | 9 | sudo sed -i "/#\$nrconf{restart} = 'i';/s/.*/\$nrconf{restart} = 'a';/" /etc/needrestart/needrestart.conf 10 | sudo apt-get update 11 | sudo apt install -y libssl-dev clang libclang-dev protobuf-compiler 12 | shell: bash 13 | - name: Add Rust components 14 | run: | 15 | rustup target add wasm32-unknown-unknown 16 | rustup component add rust-src 17 | shell: bash 18 | - name: Install wasm-pack 19 | run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh 20 | shell: bash 21 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: "cargo" 4 | directory: "/" 5 | schedule: 6 | interval: "daily" 7 | # Let's get all patch updates grouped in a single PR to minimize spam. 8 | groups: 9 | # This is the name for our group 10 | patch-dependencies: 11 | applies-to: version-updates 12 | update-types: 13 | - "patch" 14 | # Ignore any Substrate major or minor updates. 15 | # 16 | # Automated Substrate releases cause Dependabot PR spam, so these must be updated manually when 17 | # required. 18 | ignore: 19 | - dependency-name: "frame-*" 20 | versions: "*" 21 | - dependency-name: "pallet-*" 22 | versions: "*" 23 | - dependency-name: "sc-*" 24 | versions: "*" 25 | - dependency-name: "sp-*" 26 | versions: "*" 27 | - dependency-name: "substrate-*" 28 | versions: "*" 29 | - package-ecosystem: github-actions 30 | directory: '/' 31 | schedule: 32 | interval: daily 33 | -------------------------------------------------------------------------------- /.github/workflows/build-and-release.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | name: Build and release 3 | run-name: Build and release (started by @${{ github.triggering_actor }}) 4 | 5 | on: 6 | push: 7 | tags: 8 | # First, match SemVer.org conformant tags in the `release/` tagspace. 9 | - release/v[0-9]+.[0-9]+.[0-9]+-?** # Release, or pre-release build. 10 | - release/v[0-9]+.[0-9]+.[0-9]+\+?** # Release with build identifier. 11 | # Then, also, basically any release-ish name in the `test/` tagspace. 12 | - test/**release/** 13 | schedule: 14 | # Build the default branch weekly. Our version of "nightly." 15 | - cron: 55 4 * * 0 # Every Sunday at 4:55 AM. 16 | 17 | jobs: 18 | 19 | git-ref-basename: 20 | uses: ./.github/workflows/git-ref-basename.yaml 21 | 22 | test-e2e-reshare: 23 | runs-on: core-build-runner 24 | steps: 25 | - name: Checkout code 26 | uses: actions/checkout@v4 27 | - name: Install dependencies 28 | uses: ./.github/actions/install-dependencies/ 29 | - name: Test 30 | run: | 31 | pushd node 32 | cargo build --release --features=reshare-test 33 | cargo test -p entropy-tss --release --features=reshare-test test_reshare_e2e 34 | 35 | build-entropy: 36 | uses: ./.github/workflows/container-build-and-push.yaml 37 | needs: 38 | - git-ref-basename 39 | with: 40 | docker_build_arg_package: entropy 41 | git_ref_basename: ${{ needs.git-ref-basename.outputs.git_ref_basename }} 42 | secrets: 43 | DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }} 44 | DOCKER_HUB_CI_TOKEN: ${{ secrets.DOCKER_HUB_CI_TOKEN }} 45 | CI_MACHINE_USER_TOKEN: ${{ secrets.CI_MACHINE_USER_TOKEN }} 46 | 47 | build-entropy-tss: 48 | uses: ./.github/workflows/container-build-and-push.yaml 49 | needs: 50 | - git-ref-basename 51 | with: 52 | docker_build_arg_package: entropy-tss 53 | git_ref_basename: ${{ needs.git-ref-basename.outputs.git_ref_basename }} 54 | secrets: 55 | DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }} 56 | DOCKER_HUB_CI_TOKEN: ${{ secrets.DOCKER_HUB_CI_TOKEN }} 57 | CI_MACHINE_USER_TOKEN: ${{ secrets.CI_MACHINE_USER_TOKEN }} 58 | 59 | release: 60 | name: Publish new release 61 | if: github.event_name != 'schedule' 62 | needs: 63 | - git-ref-basename 64 | - build-entropy 65 | - build-entropy-tss 66 | permissions: 67 | contents: write 68 | runs-on: ubuntu-22.04 69 | steps: 70 | - uses: actions/checkout@v4 71 | - uses: actions/download-artifact@v4 72 | with: 73 | pattern: "!*.dockerbuild" 74 | - name: Create release 75 | env: 76 | GH_TOKEN: ${{ github.token }} 77 | run: | 78 | gh release create \ 79 | --draft \ 80 | --target "${{ github.sha }}" \ 81 | --title "${{ needs.build.outputs.git_ref_basename }}" \ 82 | $(echo ${{ github.ref_name }} | grep --quiet -E '^test|v[0-9]\.[0-9]\.[0-9]-' && echo '--prerelease') \ 83 | --verify-tag "${{ github.ref_name }}" \ 84 | {entropy,entropy-tss}_${{ needs.git-ref-basename.outputs.git_ref_basename }}/* 85 | -------------------------------------------------------------------------------- /.github/workflows/build-and-run-node-test.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | name: "Build and test" 3 | on: ["push"] 4 | 5 | jobs: 6 | code-paths-changed: 7 | name: Detect whether code changes have been made 8 | runs-on: ubuntu-latest 9 | outputs: 10 | run_tests: ${{ steps.filter.outputs.changes_detected }} 11 | steps: 12 | - uses: actions/checkout@v4 13 | with: 14 | fetch-depth: 0 15 | - name: Check for relevant changes 16 | id: filter 17 | run: | 18 | ## If this is the first commit on a branch, then the default behaviour of github.event.before is to show the previous ref as 19 | ## repeated zeroes, as the previous ref is null 20 | if [ "${{ github.event.before }}" = "0000000000000000000000000000000000000000" ]; then 21 | echo "changes_detected=true" >> $GITHUB_OUTPUT 22 | elif git diff --name-only ${{ github.event.before }} ${{ github.sha }} | grep -E "^(node/|crates/|pallets/|runtime/)"; then 23 | echo "changes_detected=true" >> $GITHUB_OUTPUT 24 | else 25 | echo "changes_detected=false" >> $GITHUB_OUTPUT 26 | fi 27 | 28 | node-test: 29 | needs: code-paths-changed 30 | runs-on: core-build-runner 31 | timeout-minutes: 90 32 | steps: 33 | - uses: actions/checkout@v4 34 | - name: Increase swap 35 | if: needs.code-paths-changed.outputs.run_tests == 'true' 36 | run: | 37 | sudo swapoff -a 38 | sudo dd if=/dev/zero of=/swapfile bs=1G count=8 39 | sudo chmod 0600 /swapfile 40 | sudo mkswap /swapfile 41 | sudo swapon /swapfile 42 | grep Swap /proc/meminfo 43 | - name: Install dependencies 44 | if: needs.code-paths-changed.outputs.run_tests == 'true' 45 | uses: ./.github/actions/install-dependencies/ 46 | - name: Build entropy-protocol nodejs package 47 | if: needs.code-paths-changed.outputs.run_tests == 'true' 48 | run: | 49 | cd crates/protocol 50 | make build-nodejs-testing 51 | cd nodejs-test 52 | yarn 53 | cd ../../.. 54 | - name: Run `cargo build && cargo test` 55 | if: needs.code-paths-changed.outputs.run_tests == 'true' 56 | run: | 57 | pushd node 58 | cargo build --all-targets --release -j $(nproc) 59 | cargo test --all-targets --release 60 | yarn --cwd ../crates/protocol/nodejs-test test 61 | cargo test -p entropy-tss --release --features=test_helpers -F wasm_test test_wasm 62 | - name: Skip tests when no code changes have been made 63 | if: needs.code-paths-changed.outputs.run_tests == 'false' 64 | run: | 65 | echo "Skipping tests as no code changes have been made" 66 | -------------------------------------------------------------------------------- /.github/workflows/check-chainspecs.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | name: "Check chainspecs" 3 | on: ["push"] 4 | 5 | jobs: 6 | check-chainspecs: 7 | runs-on: ubuntu-latest 8 | steps: 9 | - name: Checkout code 10 | uses: actions/checkout@v4 11 | - name: Install dependencies 12 | uses: ./.github/actions/install-dependencies/ 13 | - name: Check chainspecs 14 | run: | 15 | cargo run -p entropy -- build-spec --raw --chain dev > chainspec-dev-raw.json 16 | cargo run -p entropy -- build-spec --raw --chain integration-tests > chainspec-integration-raw.json 17 | cargo run -p entropy -- build-spec --raw --chain testnet-blank > chainspec-testnet-blank-raw.json 18 | cargo run -p entropy -- build-spec --raw --chain ./node/cli/test-chainspec-inputs/example-chainspec-inputs.json > chainspec-testnet-raw.json 19 | -------------------------------------------------------------------------------- /.github/workflows/check-doc-build.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | name: "Check documentation build" 3 | on: ["push"] 4 | 5 | jobs: 6 | check-doc-build: 7 | runs-on: ubuntu-latest 8 | steps: 9 | - name: Checkout code 10 | uses: actions/checkout@v4 11 | - name: Install dependencies 12 | uses: ./.github/actions/install-dependencies/ 13 | - name: Build documentation 14 | run: cargo doc --no-deps -------------------------------------------------------------------------------- /.github/workflows/cla.yaml: -------------------------------------------------------------------------------- 1 | # This workflow automates the process of signing our CLA. It makes use of 2 | # the action at https://github.com/contributor-assistant/github-action in 3 | # order to provide automations. 4 | # 5 | # This workflow file should be present in every repository that wants to 6 | # use the Contributor License Agreement automation process. Ideally, it 7 | # would remain more-or-less synchronized across each repository as updates 8 | # are rolled out. 9 | # 10 | # Since the database of signatories is maintained in a remote repository, 11 | # each repository that wishes to make use of the CLA Assistant will also 12 | # need to have a repository secret (named `CLA_ASSISTANT_LITE_PAT`) that 13 | # grants permission to write to the "signatures" file in that repository. 14 | --- 15 | name: "CLA Assistant" 16 | on: 17 | issue_comment: 18 | types: 19 | - created 20 | pull_request_target: 21 | types: 22 | - opened 23 | - closed 24 | - synchronize 25 | 26 | # Explicitly configure permissions, in case the GITHUB_TOKEN workflow permissions 27 | # are set to read-only in the repository's settings. 28 | permissions: 29 | actions: write 30 | contents: read # We only need to `read` since signatures are in a remote repo. 31 | pull-requests: write 32 | statuses: write 33 | 34 | jobs: 35 | CLAAssistant: 36 | runs-on: ubuntu-latest 37 | steps: 38 | - name: "CLA Assistant" 39 | if: (github.event.comment.body == 'recheck' || github.event.comment.body == 'I have read the CLA Document and I hereby sign the CLA') || github.event_name == 'pull_request_target' 40 | uses: entropyxyz/contributor-assistant-github-action@c5f4628ffe1edb97724edb64e0dd4795394d33e5 # exemptRepoOrgMembers 41 | env: 42 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 43 | # Required, so that the bot in this repository has `write` permissions to Contents of remote repo. 44 | PERSONAL_ACCESS_TOKEN: ${{ secrets.CLA_ASSISTANT_LITE_PAT }} 45 | with: 46 | path-to-signatures: 'legal/cla/v1/signatures.json' 47 | path-to-document: 'https://github.com/entropyxyz/.github/blob/main/legal/cla/v1/cla.md' 48 | branch: 'main' 49 | allowlist: dependabot[bot],entropyxyz 50 | exemptRepoOrgMembers: true 51 | remote-organization-name: entropyxyz 52 | remote-repository-name: .github 53 | lock-pullrequest-aftermerge: false 54 | -------------------------------------------------------------------------------- /.github/workflows/dependabot-auto-merge.yml: -------------------------------------------------------------------------------- 1 | name: Dependabot auto-merge 2 | on: pull_request 3 | 4 | permissions: 5 | contents: write 6 | pull-requests: write 7 | 8 | jobs: 9 | dependabot-approve: 10 | runs-on: ubuntu-22.04 11 | if: github.actor == 'dependabot[bot]' 12 | steps: 13 | - name: Dependabot metadata 14 | id: metadata 15 | uses: dependabot/fetch-metadata@v2 16 | with: 17 | github-token: "${{ secrets.GITHUB_TOKEN }}" 18 | - name: Approve a PR 19 | if: steps.metadata.outputs.update-type == 'version-update:semver-patch' 20 | run: gh pr review --approve "$PR_URL" 21 | env: 22 | PR_URL: ${{github.event.pull_request.html_url}} 23 | GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} 24 | - name: Enable auto-merge for Dependabot PRs 25 | if: steps.metadata.outputs.update-type == 'version-update:semver-patch' 26 | run: gh pr merge --auto --squash "$PR_URL" 27 | env: 28 | PR_URL: ${{github.event.pull_request.html_url}} 29 | GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} 30 | -------------------------------------------------------------------------------- /.github/workflows/git-ref-basename.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | name: Get basename(1) of Git ref 3 | 4 | permissions: 5 | contents: read 6 | 7 | on: 8 | workflow_call: 9 | outputs: 10 | git_ref_basename: 11 | description: Last portion of a Git ref, like `basename(1)`. 12 | value: ${{ jobs.git-ref-basename.outputs.git_ref_basename }} 13 | 14 | jobs: 15 | git-ref-basename: 16 | name: Git ref basename 17 | runs-on: ubuntu-latest 18 | outputs: 19 | git_ref_basename: ${{ steps.git-ref-basename.outputs.git_ref_basename }} 20 | steps: 21 | - name: Get basename of Git ref. 22 | id: git-ref-basename 23 | shell: bash 24 | run: | 25 | echo git_ref_basename="$(basename "${{ github.ref_name }}")" >> $GITHUB_OUTPUT 26 | -------------------------------------------------------------------------------- /.github/workflows/lint-and-check-licenses.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | name: "Lint and check licenses" 3 | on: ["push"] 4 | 5 | jobs: 6 | lint: 7 | runs-on: ubuntu-latest 8 | steps: 9 | - name: Checkout code 10 | uses: actions/checkout@v4 11 | - name: Install dependencies 12 | uses: ./.github/actions/install-dependencies/ 13 | - name: Format and lint 14 | run: | 15 | curl -LsSf https://github.com/tamasfe/taplo/releases/download/0.8.0/taplo-full-linux-x86_64.gz | gunzip -N -d - > ${CARGO_HOME:-~/.cargo}/bin/taplo && chmod +x ${CARGO_HOME:-~/.cargo}/bin/taplo 16 | rustup component add rustfmt 17 | rustup component add clippy 18 | cargo fmt --check 19 | taplo fmt --check 20 | cargo clippy -- -D warnings 21 | check-licenses: 22 | runs-on: ubuntu-22.04 23 | steps: 24 | - name: Checkout code 25 | uses: actions/checkout@v4 26 | - name: Check licenses with cargo deny 27 | run: | 28 | cargo install --locked cargo-deny 29 | cargo deny --all-features check license 30 | -------------------------------------------------------------------------------- /.github/workflows/test-runtime-benchmarks.yaml: -------------------------------------------------------------------------------- 1 | name: "Test: check runtime benchmarks" 2 | on: ["push"] 3 | 4 | jobs: 5 | test-runtime-benchmarks: 6 | runs-on: ubuntu-latest 7 | steps: 8 | - name: Checkout code 9 | uses: actions/checkout@v4 10 | - name: Install dependencies 11 | uses: ./.github/actions/install-dependencies/ 12 | - name: Check runtime-benchmarks 13 | run: | 14 | pushd node && cargo build --features=runtime-benchmarks 15 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # The `target` directory is generated by Cargo. 2 | # It will contain mostly compiled files and executables. 3 | target/* 4 | 5 | # But the API documentation eventually gets published, so we want to 6 | # make sure these files are also included in commits for downstream 7 | # services to consume, and these are by default output to `target/doc`. 8 | !target/doc 9 | target/doc/* 10 | !target/doc/index.html 11 | 12 | # These are backup files generated by `rustfmt` 13 | **/*.rs.bk 14 | 15 | # Some standard macOS, text editor, and IDE cruft should be omitted. 16 | .DS_Store 17 | *.swp 18 | .idea 19 | .vscode 20 | 21 | # The cache for chain data in container. 22 | .local 23 | 24 | # Some utilities that our developers use create temporary files and 25 | # directories we also don't want to commit. 26 | .direnv 27 | 28 | # Node.js's vendor code doesn't need to be committed, either. 29 | node_modules/ 30 | 31 | # TODO: Comment what these are for. 32 | kvstore 33 | 34 | test_db/ 35 | test_db_0/ 36 | test_db_1/ 37 | main_test_db/ 38 | test_db_3001 39 | test_db_3002 40 | 41 | */.entropy 42 | .entropy 43 | 44 | ./scripts/copy-releases-to-sdk.sh 45 | 46 | # Keyshare files from the test CLI 47 | crates/test-cli/keyshare-* 48 | -------------------------------------------------------------------------------- /.maintain/AGPL-3.0-header.txt: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2023 Entropy Cryptography Inc. 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU Affero General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU Affero General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU Affero General Public License 14 | // along with this program. If not, see . 15 | -------------------------------------------------------------------------------- /.maintain/frame-weight-template.hbs: -------------------------------------------------------------------------------- 1 | {{header}} 2 | //! Autogenerated weights for `{{pallet}}` 3 | //! 4 | //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION {{version}} 5 | //! DATE: {{date}}, STEPS: `{{cmd.steps}}`, REPEAT: `{{cmd.repeat}}`, LOW RANGE: `{{cmd.lowest_range_values}}`, HIGH RANGE: `{{cmd.highest_range_values}}` 6 | //! WORST CASE MAP SIZE: `{{cmd.worst_case_map_values}}` 7 | //! HOSTNAME: `{{hostname}}`, CPU: `{{cpuname}}` 8 | //! WASM-EXECUTION: `{{cmd.wasm_execution}}`, CHAIN: `{{cmd.chain}}`, DB CACHE: {{cmd.db_cache}} 9 | 10 | // Executed Command: 11 | {{#each args as |arg|}} 12 | // {{arg}} 13 | {{/each}} 14 | 15 | #![cfg_attr(rustfmt, rustfmt_skip)] 16 | #![allow(unused_parens)] 17 | #![allow(unused_imports)] 18 | #![allow(missing_docs)] 19 | 20 | use frame_support::{traits::Get, weights::Weight}; 21 | use core::marker::PhantomData; 22 | 23 | /// Weight functions for `{{pallet}}`. 24 | pub struct WeightInfo(PhantomData); 25 | impl {{pallet}}::WeightInfo for WeightInfo { 26 | {{#each benchmarks as |benchmark|}} 27 | {{#each benchmark.comments as |comment|}} 28 | /// {{comment}} 29 | {{/each}} 30 | {{#each benchmark.component_ranges as |range|}} 31 | /// The range of component `{{range.name}}` is `[{{range.min}}, {{range.max}}]`. 32 | {{/each}} 33 | fn {{benchmark.name~}} 34 | ( 35 | {{~#each benchmark.components as |c| ~}} 36 | {{~#if (not c.is_used)}}_{{/if}}{{c.name}}: u32, {{/each~}} 37 | ) -> Weight { 38 | // Proof Size summary in bytes: 39 | // Measured: `{{benchmark.base_recorded_proof_size}}{{#each benchmark.component_recorded_proof_size as |cp|}} + {{cp.name}} * ({{cp.slope}} ±{{underscore cp.error}}){{/each}}` 40 | // Estimated: `{{benchmark.base_calculated_proof_size}}{{#each benchmark.component_calculated_proof_size as |cp|}} + {{cp.name}} * ({{cp.slope}} ±{{underscore cp.error}}){{/each}}` 41 | // Minimum execution time: {{underscore benchmark.min_execution_time}}_000 picoseconds. 42 | Weight::from_parts({{underscore benchmark.base_weight}}, 0) 43 | .saturating_add(Weight::from_parts(0, {{benchmark.base_calculated_proof_size}})) 44 | {{#each benchmark.component_weight as |cw|}} 45 | // Standard Error: {{underscore cw.error}} 46 | .saturating_add(Weight::from_parts({{underscore cw.slope}}, 0).saturating_mul({{cw.name}}.into())) 47 | {{/each}} 48 | {{#if (ne benchmark.base_reads "0")}} 49 | .saturating_add(T::DbWeight::get().reads({{benchmark.base_reads}})) 50 | {{/if}} 51 | {{#each benchmark.component_reads as |cr|}} 52 | .saturating_add(T::DbWeight::get().reads(({{cr.slope}}_u64).saturating_mul({{cr.name}}.into()))) 53 | {{/each}} 54 | {{#if (ne benchmark.base_writes "0")}} 55 | .saturating_add(T::DbWeight::get().writes({{benchmark.base_writes}})) 56 | {{/if}} 57 | {{#each benchmark.component_writes as |cw|}} 58 | .saturating_add(T::DbWeight::get().writes(({{cw.slope}}_u64).saturating_mul({{cw.name}}.into()))) 59 | {{/each}} 60 | {{#each benchmark.component_calculated_proof_size as |cp|}} 61 | .saturating_add(Weight::from_parts(0, {{cp.slope}}).saturating_mul({{cp.name}}.into())) 62 | {{/each}} 63 | } 64 | {{/each}} 65 | } -------------------------------------------------------------------------------- /.maintain/ignore_clippy_header.txt: -------------------------------------------------------------------------------- 1 | #![allow(clippy::all)] 2 | -------------------------------------------------------------------------------- /.rustfmt.toml: -------------------------------------------------------------------------------- 1 | # Opinionated whitespace and tabs. The most important of these are imports and width settings. 2 | # https://rust-lang.github.io/rustfmt 3 | 4 | # version-related 5 | use_try_shorthand=true # replace any `try!` (2015 Rust) with `?` 6 | edition ="2018" 7 | 8 | # misc formatting 9 | match_block_trailing_comma=true # include comma in match blocks after '}' 10 | use_field_init_shorthand =true # struct initialization short {x: x} -> {x} 11 | 12 | # reduce whitespace 13 | newline_style="Unix" # not auto, we won the culture war. \n over \r\n 14 | 15 | # width settings: everything to 100 16 | max_width =100 # default: 100 17 | use_small_heuristics="Max" # don't ever newline short of `max_width`. 18 | 19 | # tabs and spaces (use spaces) 20 | hard_tabs=false # (default: false) use spaces over tabs 21 | -------------------------------------------------------------------------------- /.taplo.toml: -------------------------------------------------------------------------------- 1 | # .toml file formatting settings for `taplo` 2 | # https://taplo.tamasfe.dev/configuration/formatter-options.html 3 | 4 | [formatting] 5 | align_entries =true # align entries vertically 6 | allowed_blank_lines=1 # allow up to 1 consecutive empty line (default: 2) 7 | array_auto_collapse=true # collapse arrays into one line if they fit 8 | column_width =100 # default: 80 9 | compact_entries =true # remove whitespace around '=' 10 | reorder_keys =false # alphabetically sort entries not separated by line breaks 11 | # align_comments =false # align entries vertically (default: true) 12 | # array_auto_expand =false # expand arrays into multiple lines (default: true) 13 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [workspace] 2 | resolver="2" 3 | members =['crates/*', 'node/*', 'pallets/*', 'runtime', 'scripts/create-test-keyshares'] 4 | 5 | [workspace.lints.clippy] 6 | result_large_err="allow" 7 | -------------------------------------------------------------------------------- /bin/entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | ### 3 | # Container entrypoint script. 4 | ### 5 | 6 | # Function main simply wraps execution of the binary set in the 7 | # image's build environment. This makes it possible to use one 8 | # Dockerfile and still ultimately run a few different bianries. 9 | main () { 10 | exec "/usr/local/bin/${entropy_binary}" "$@" 11 | } 12 | 13 | main "$@" 14 | -------------------------------------------------------------------------------- /crates/README.md: -------------------------------------------------------------------------------- 1 | # Crates 2 | 3 | This directory contains the [Threshold Signature Server](https://github.com/entropyxyz/entropy-core/tree/master/crates/threshold-signature-server) and some utility crates related to it: 4 | 5 | - [`shared`](https://github.com/entropyxyz/entropy-core/tree/master/crates/shared) - Common types shared by the chain node and TSS server 6 | - [`kvdb`](https://github.com/entropyxyz/entropy-core/tree/master/crates/kvdb) - An encrypted key-value datastore 7 | - [`protocol`](https://github.com/entropyxyz/entropy-core/tree/master/crates/protocol) - Transport logic for running the Entropy protocols 8 | - [`testing-utils`](https://github.com/entropyxyz/entropy-core/tree/master/crates/testing-utils) - Testing utility methods shared across the workspace 9 | - [`test-cli`](https://github.com/entropyxyz/entropy-core/tree/master/crates/test-cli) - A simple command line client for test purposes 10 | 11 | Programs have now moved to [entropyxyz/programs](https://github.com/entropyxyz/programs). 12 | -------------------------------------------------------------------------------- /crates/client/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name ="entropy-client" 3 | version ="0.4.0-rc.1" 4 | edition ="2021" 5 | authors =['Entropy Cryptography '] 6 | homepage ='https://entropy.xyz/' 7 | description='A client for the Entropy chain node and Entropy TSS server' 8 | license ='AGPL-3.0-or-later' 9 | repository ='https://github.com/entropyxyz/entropy-core' 10 | 11 | [dependencies] 12 | sha3 ="0.10.8" 13 | serde ={ version="1.0", default-features=false, features=["derive"] } 14 | entropy-shared={ version="0.4.0-rc.1", path="../shared", default-features=false } 15 | subxt ={ version="0.42.0", default-features=false, features=["jsonrpsee"] } 16 | subxt-core ={ version="0.42.0", default-features=false } 17 | num ="0.4.3" 18 | thiserror ="2.0.12" 19 | futures ="0.3" 20 | sp-core ={ version="36.1.0", default-features=false, features=["full_crypto", "serde"] } 21 | tracing ="0.1.41" 22 | rand ={ version="0.8", default-features=false } 23 | anyhow ="1.0.98" 24 | 25 | # Present when "full-client" feature is active 26 | blake2 ={ version="0.10.4", optional=true } 27 | rand_core ={ version="0.6.4", optional=true } 28 | serde_json ={ version="1.0", optional=true } 29 | x25519-dalek ={ version="2.0.1", features=["static_secrets"], optional=true } 30 | entropy-protocol ={ version="0.4.0-rc.1", path="../protocol", optional=true, default-features=false } 31 | reqwest ={ version="0.12.19", features=["json", "stream"], optional=true } 32 | base64 ={ version="0.22.0", optional=true } 33 | synedrion ={ version="0.3.0", optional=true, features=["k256"] } 34 | hex ={ version="0.4.3", optional=true } 35 | parity-scale-codec={ version="3.7.2", default-features=false, optional=true } 36 | k256 ={ version="0.13", default-features=false, features=["ecdsa"], optional=true } 37 | 38 | # Only for the browser 39 | js-sys={ version="0.3.74", optional=true } 40 | tokio ={ version="1.44", features=["time"] } 41 | 42 | [dev-dependencies] 43 | serial_test ="3.2.0" 44 | sp-keyring ="41.0.0" 45 | entropy-testing-utils={ path="../testing-utils" } 46 | tdx-quote ={ version="0.0.3", features=["mock"] } 47 | 48 | [features] 49 | default=["native", "full-client-native"] 50 | native =["entropy-shared/std", "entropy-shared/user-native", "subxt/native"] 51 | wasm =["entropy-shared/wasm", "entropy-shared/user-wasm", "subxt/web"] 52 | 53 | # This adds full client functionality. It is behind a feature flag because it is not needed by 54 | # entropy-tss 55 | full-client=[ 56 | "dep:blake2", 57 | "dep:rand_core", 58 | "dep:serde_json", 59 | "dep:x25519-dalek", 60 | "dep:entropy-protocol", 61 | "dep:reqwest", 62 | "dep:base64", 63 | "dep:synedrion", 64 | "dep:k256", 65 | "dep:hex", 66 | "dep:parity-scale-codec", 67 | ] 68 | full-client-native=["full-client", "entropy-protocol/server"] 69 | full-client-wasm=["full-client", "entropy-protocol/wasm", "dep:js-sys"] 70 | -------------------------------------------------------------------------------- /crates/client/entropy_metadata.scale: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/entropyxyz/entropy-core/22f3d43664e4acf87445e06cedcb6a7851f6b3a7/crates/client/entropy_metadata.scale -------------------------------------------------------------------------------- /crates/client/src/chain_api.rs: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2023 Entropy Cryptography Inc. 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU Affero General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU Affero General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU Affero General Public License 14 | // along with this program. If not, see . 15 | 16 | //! A client interface for communicating with the Entropy blockchain 17 | #![allow(clippy::all)] 18 | pub use subxt::PolkadotConfig as EntropyConfig; 19 | use subxt::{ 20 | backend::{legacy::LegacyRpcMethods, rpc::RpcClient}, 21 | OnlineClient, 22 | }; 23 | 24 | #[subxt::subxt( 25 | runtime_metadata_path = "entropy_metadata.scale", 26 | substitute_type( 27 | path = "entropy_shared::types::ValidatorInfo", 28 | with = "::subxt::utils::Static<::entropy_shared::ValidatorInfo>", 29 | ) 30 | )] 31 | pub mod entropy {} 32 | 33 | /// Creates an api instance to talk to chain 34 | /// Chain endpoint set on launch 35 | pub async fn get_api(url: &str) -> Result, subxt::Error> { 36 | // insecure url is fine since binaries are on the same machine 37 | let api = OnlineClient::::from_insecure_url(url).await?; 38 | Ok(api) 39 | } 40 | 41 | /// Creates a rpc instance to talk to chain 42 | /// Chain endpoint set on launch 43 | pub async fn get_rpc(url: &str) -> Result, subxt::Error> { 44 | // insecure url is fine since binaries are on the same machine 45 | let rpc_client = RpcClient::from_insecure_url(url).await?; 46 | let rpc_methods = LegacyRpcMethods::::new(rpc_client); 47 | Ok(rpc_methods) 48 | } 49 | -------------------------------------------------------------------------------- /crates/client/src/lib.rs: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2023 Entropy Cryptography Inc. 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU Affero General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU Affero General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU Affero General Public License 14 | // along with this program. If not, see . 15 | //! A client for the Entropy chain node and Entropy TSS Server. 16 | //! Since the TSS server communicates with the chain node, this is also a dependency of entropy-tss. 17 | pub mod chain_api; 18 | pub mod errors; 19 | pub mod substrate; 20 | pub mod user; 21 | pub mod util; 22 | pub use util::Hasher; 23 | 24 | #[cfg(test)] 25 | mod tests; 26 | 27 | #[cfg(feature = "full-client")] 28 | pub mod client; 29 | #[cfg(feature = "full-client")] 30 | pub use client::*; 31 | -------------------------------------------------------------------------------- /crates/client/src/util.rs: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2023 Entropy Cryptography Inc. 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU Affero General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU Affero General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU Affero General Public License 14 | // along with this program. If not, see . 15 | //! Utilities 16 | 17 | use sha3::{Digest, Keccak256}; 18 | 19 | /// Produces a specific hash on a given message 20 | pub struct Hasher; 21 | 22 | impl Hasher { 23 | /// Produces the Keccak256 hash on a given message. 24 | /// 25 | /// In practice, if `data` is an RLP-serialized Ethereum transaction, this should produce the 26 | /// corrosponding . 27 | pub fn keccak(data: &[u8]) -> [u8; 32] { 28 | let mut keccak = Keccak256::new(); 29 | keccak.update(data); 30 | keccak.finalize().into() 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /crates/kvdb/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name ="entropy-kvdb" 3 | description="Encrypted key-value database for the Entropy Theshold Signing Server" 4 | version ="0.4.0-rc.1" 5 | authors =['Entropy Cryptography '] 6 | homepage ='https://entropy.xyz/' 7 | license ='AGPL-3.0-or-later' 8 | repository ='https://github.com/entropyxyz/entropy-core' 9 | edition ='2021' 10 | 11 | [dependencies] 12 | # Common 13 | rand ={ version="0.8", default-features=false } 14 | serde ={ version="1.0", features=["derive"] } 15 | thiserror="2.0.12" 16 | hex ="0.4.3" 17 | 18 | # Substrate 19 | sp-core={ version="36.1.0", default-features=false } 20 | 21 | # Crypto 22 | zeroize ={ version="1.8", features=["zeroize_derive"], default-features=false } 23 | rpassword ={ version="7.4.0", default-features=false } 24 | scrypt ={ version="0.11.0", default-features=false, features=["std"] } 25 | chacha20poly1305={ version="0.9", features=["alloc"], default-features=false } 26 | synedrion ={ version="0.3.0", features=["k256"] } 27 | 28 | # Async 29 | tokio ={ version="1.44", features=["macros", "sync", "fs", "rt-multi-thread", "io-util"] } 30 | tracing={ version="0.1", default-features=false } 31 | 32 | # Misc 33 | sled ="0.34.7" 34 | bincode ="1.3.3" 35 | entropy-protocol={ version="0.4.0-rc.1", path="../protocol" } 36 | 37 | [dev-dependencies] 38 | serial_test="3.2.0" 39 | -------------------------------------------------------------------------------- /crates/kvdb/MIT-LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2021 Axelar Foundation 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 4 | associated documentation files (the “Software”), to deal in the Software without restriction, 5 | including without limitation the rights to use, copy, modify, merge, publish, distribute, 6 | sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 7 | furnished to do so, subject to the following conditions: 8 | 9 | The above copyright notice and this permission notice shall be included in all copies or substantial 10 | portions of the Software. 11 | 12 | THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 13 | NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 14 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES 15 | OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 16 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 17 | -------------------------------------------------------------------------------- /crates/kvdb/README.md: -------------------------------------------------------------------------------- 1 | ### Licensing 2 | 3 | This crate is built with code from the [Axelar](https://axelar.network/) project's [tofnd](https://github.com/axelarnetwork/tofnd) crate. 4 | 5 | The original code is licensed under [`MIT`](./MIT-LICENSE). The modifications made in this repository are licensed 6 | under [AGPL-3.0](../../LICENSE). 7 | -------------------------------------------------------------------------------- /crates/kvdb/src/encrypted_sled/constants.rs: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2023 Entropy Cryptography Inc. 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU Affero General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU Affero General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU Affero General Public License 14 | // along with this program. If not, see . 15 | 16 | //! Constants for [encrypted_sled](crate::encrypted_sled) 17 | pub(super) const PASSWORD_VERIFICATION_KEY: &str = "verification_key"; 18 | pub(super) const PASSWORD_VERIFICATION_VALUE: &str = "verification_value"; 19 | -------------------------------------------------------------------------------- /crates/kvdb/src/encrypted_sled/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2023 Entropy Cryptography Inc. 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU Affero General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU Affero General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU Affero General Public License 14 | // along with this program. If not, see . 15 | 16 | //! Wrap a layer of encryption around [sled]. We use [chacha20poly1305] to encrypt/decrypt values. 17 | //! Specifically, use [chacha20poly1305::XChaCha20Poly1305] because the nonces are generated 18 | //! randomly. To create an new [Db], an key to use as entropy for the stream cipher needs to be 19 | //! provided. 20 | 21 | mod constants; 22 | mod kv; 23 | mod record; 24 | mod result; 25 | 26 | // match the API of sled 27 | pub use kv::EncryptedDb as Db; 28 | pub use result::{EncryptedDbError as Error, EncryptedDbResult as Result}; 29 | 30 | #[cfg(test)] 31 | mod tests; 32 | -------------------------------------------------------------------------------- /crates/kvdb/src/encrypted_sled/record.rs: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2023 Entropy Cryptography Inc. 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU Affero General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU Affero General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU Affero General Public License 14 | // along with this program. If not, see . 15 | 16 | //! The value of [super::Db]. 17 | 18 | use chacha20poly1305::XNonce; 19 | use serde::{Deserialize, Serialize}; 20 | use sled::IVec; 21 | 22 | use super::result::{ 23 | EncryptedDbError::{Deserialization, Serialization}, 24 | EncryptedDbResult, 25 | }; 26 | use crate::kv_manager::helpers::{deserialize, serialize}; 27 | 28 | /// The value of [super::Db]. 29 | #[derive(Serialize, Deserialize, Debug)] 30 | pub(super) struct EncryptedRecord { 31 | encrypted_value: Vec, 32 | nonce: [u8; 24], 33 | } 34 | 35 | impl EncryptedRecord { 36 | pub(super) fn new(encrypted_value: Vec, nonce: XNonce) -> Self { 37 | EncryptedRecord { encrypted_value, nonce: nonce.into() } 38 | } 39 | 40 | /// Convert a [EncryptedRecord] to bytes using serde. 41 | pub(super) fn to_bytes(&self) -> EncryptedDbResult> { 42 | serialize(&self).map_err(|_| Serialization) 43 | } 44 | 45 | /// Convert bytes to a [EncryptedRecord] using serde. 46 | pub(super) fn from_bytes(bytes: &IVec) -> EncryptedDbResult { 47 | deserialize(bytes).ok_or(Deserialization) 48 | } 49 | } 50 | 51 | impl From for (Vec, XNonce) { 52 | fn from(record: EncryptedRecord) -> Self { 53 | (record.encrypted_value, record.nonce.into()) 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /crates/kvdb/src/encrypted_sled/result.rs: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2023 Entropy Cryptography Inc. 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU Affero General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU Affero General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU Affero General Public License 14 | // along with this program. If not, see . 15 | 16 | //! Custom error handling 17 | 18 | #[derive(thiserror::Error, Debug)] 19 | pub enum EncryptedDbError { 20 | #[error("Your kv store may be corrupted. Sled error: {0}")] 21 | CorruptedKv(sled::Error), 22 | #[error("Password read error: {0}")] 23 | PasswordRead(#[from] std::io::Error), // rpassword::read_password() Error 24 | #[error("Password scrypt params error: {0}")] 25 | PasswordScryptParams(#[from] scrypt::errors::InvalidParams), 26 | #[error("Password scrypt error: {0}")] 27 | PasswordScryptError(#[from] scrypt::errors::InvalidOutputLen), 28 | #[error("Sled error: {0}")] 29 | SledError(#[from] sled::Error), 30 | #[error("Serialization error: failed to serialize the encrypted record")] 31 | Serialization, 32 | #[error("Deserialization error: failed to deserialize encrypted record bytes")] 33 | Deserialization, 34 | #[error("ChaCha20 encryption error: {0}")] 35 | Encryption(String), 36 | #[error("ChaCha20 decryption error: {0}")] 37 | Decryption(String), 38 | #[error("Wrong password")] 39 | WrongPassword, 40 | #[error("Missing password salt")] 41 | MissingPasswordSalt, 42 | #[error("Malformed password salt: {0}")] 43 | MalformedPasswordSalt(#[from] std::array::TryFromSliceError), 44 | } 45 | pub type EncryptedDbResult = Result; 46 | -------------------------------------------------------------------------------- /crates/kvdb/src/kv_manager/error.rs: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2023 Entropy Cryptography Inc. 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU Affero General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU Affero General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU Affero General Public License 14 | // along with this program. If not, see . 15 | 16 | //! Custom error types for [crate::kv_manager]. 17 | 18 | use crate::encrypted_sled; 19 | 20 | #[allow(clippy::enum_variant_names)] // allow Err postfix 21 | #[derive(thiserror::Error, Debug)] 22 | pub enum KvError { 23 | #[error("Kv initialization Error: {0}")] 24 | InitErr(#[from] encrypted_sled::Error), 25 | #[error("Recv Error: {0}")] // errors receiving from "actor pattern"'s channels 26 | RecvErr(#[from] tokio::sync::oneshot::error::RecvError), 27 | #[error("Send Error: {0}")] // errors sending to "actor pattern"'s channels 28 | SendErr(String), 29 | #[error("Reserve Error: {0}")] 30 | ReserveErr(InnerKvError), 31 | #[error("Put Error: {0}")] 32 | PutErr(InnerKvError), 33 | #[error("Get Error: {0}")] 34 | GetErr(InnerKvError), 35 | #[error("Delete Error: {0}")] 36 | DeleteErr(InnerKvError), 37 | #[error("Exits Error: {0}")] 38 | ExistsErr(InnerKvError), 39 | } 40 | pub type KvResult = Result; 41 | 42 | #[allow(clippy::enum_variant_names)] // allow Err postfix 43 | #[derive(thiserror::Error, Debug)] 44 | pub enum InnerKvError { 45 | #[error("Sled Error: {0}")] // Delegate Sled's errors 46 | SledErr(#[from] encrypted_sled::Error), 47 | #[error("Logical Error: {0}")] // Logical errors (eg double deletion) 48 | LogicalErr(String), 49 | #[error("Serialization Error: failed to serialize value")] 50 | SerializationErr, 51 | #[error("Deserialization Error: failed to deserialize kvstore bytes")] 52 | DeserializationErr, 53 | } 54 | 55 | pub(super) type InnerKvResult = Result; 56 | -------------------------------------------------------------------------------- /crates/kvdb/src/kv_manager/helpers.rs: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2023 Entropy Cryptography Inc. 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU Affero General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU Affero General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU Affero General Public License 14 | // along with this program. If not, see . 15 | 16 | use bincode::{ 17 | config::{ 18 | BigEndian, Bounded, RejectTrailing, VarintEncoding, WithOtherEndian, WithOtherIntEncoding, 19 | WithOtherLimit, WithOtherTrailing, 20 | }, 21 | DefaultOptions, Options, 22 | }; 23 | use serde::de::DeserializeOwned; 24 | use tracing::{error, warn}; 25 | 26 | #[derive(Debug, Clone, Copy, Eq, PartialEq)] 27 | pub struct KVDBFatal; 28 | pub type KVDBResult = Result; 29 | pub type BytesVec = Vec; 30 | /// Max message length allowed to be (de)serialized 31 | const MAX_MSG_LEN: u64 = 1000 * 1000; // 1 MB 32 | 33 | /// Serialize a value using bincode and log errors 34 | pub fn serialize(value: &T) -> KVDBResult 35 | where 36 | T: serde::Serialize + ?Sized, 37 | { 38 | let bincode = bincoder(); 39 | 40 | bincode.serialize(value).map_err(|err| { 41 | error!("serialization failure: {}", err.to_string()); 42 | KVDBFatal 43 | }) 44 | } 45 | 46 | /// Deserialize bytes to a type using bincode and log errors. 47 | /// Return an Option type since deserialization isn't treated as a Fatal error 48 | /// for the purposes of fault identification. 49 | pub fn deserialize(bytes: &[u8]) -> Option { 50 | let bincode = bincoder(); 51 | 52 | bincode 53 | .deserialize(bytes) 54 | .map_err(|err| { 55 | warn!("deserialization failure: {}", err.to_string()); 56 | }) 57 | .ok() 58 | } 59 | 60 | /// Prepare a `bincode` serde backend with our preferred config 61 | #[allow(clippy::type_complexity)] 62 | fn bincoder() -> WithOtherTrailing< 63 | WithOtherIntEncoding< 64 | WithOtherEndian, BigEndian>, 65 | VarintEncoding, 66 | >, 67 | RejectTrailing, 68 | > { 69 | DefaultOptions::new() 70 | .with_limit(MAX_MSG_LEN) 71 | .with_big_endian() // do not ignore extra bytes at the end of the buffer 72 | .with_varint_encoding() // saves a lot of space in smaller messages 73 | .reject_trailing_bytes() // do not ignore extra bytes at the end of the buffer 74 | } 75 | -------------------------------------------------------------------------------- /crates/kvdb/src/kv_manager/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2023 Entropy Cryptography Inc. 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU Affero General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU Affero General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU Affero General Public License 14 | // along with this program. If not, see . 15 | 16 | //! Key-Value Store service. We use [sled][sled] for the underlying db implementation. 17 | //! For every kvstore initialized, a daemon is spawned that serves basic 18 | //! database functionality using the "actor" pattern (`kv::Kv` is the "handle"): 19 | //! See for tokio channels 20 | //! See `kv` module for the public API. 21 | 22 | /// Custom error types for `kv` and `sled_bindings` 23 | pub mod error; 24 | pub mod helpers; 25 | /// public API of kv manager 26 | mod kv; 27 | /// sled bindings for basic kv operations 28 | mod sled_bindings; 29 | /// definition of kv_manager types and default paths 30 | mod types; 31 | /// wrapers for values stored by services 32 | pub mod value; 33 | pub use types::KeyReservation; 34 | pub use value::{KvManager, PartyInfo}; 35 | 36 | // tests for low-level operations 37 | #[cfg(test)] 38 | mod tests; 39 | -------------------------------------------------------------------------------- /crates/kvdb/src/kv_manager/types.rs: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2023 Entropy Cryptography Inc. 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU Affero General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU Affero General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU Affero General Public License 14 | // along with this program. If not, see . 15 | 16 | //! useful types and default paths for the kv_manager 17 | 18 | use std::fmt::Debug; 19 | 20 | // default KV store names 21 | pub const DEFAULT_KV_NAME: &str = "kv"; 22 | 23 | /// default path of kv store 24 | /// the full name of the kv store is "DEFAULT_KV_PATH/kv_name" 25 | pub(super) const DEFAULT_KV_PATH: &str = "kvstore"; 26 | 27 | /// default value for reserved key 28 | pub(super) const DEFAULT_RESERVE: &str = ""; 29 | 30 | /// Returned from a successful `ReserveKey` command 31 | #[derive(Debug)] // disallow derive Clone, Copy 32 | pub struct KeyReservation { 33 | pub key: String, 34 | } 35 | /// kv store needs PartialEq to complare values 36 | impl PartialEq for KeyReservation { 37 | fn eq(&self, other: &Self) -> bool { 38 | self.key == other.key 39 | } 40 | } 41 | 42 | // Provided by the requester and used by the manager task to send the command response back to the 43 | // requester. 44 | type Responder = tokio::sync::oneshot::Sender>; 45 | 46 | #[derive(Debug)] 47 | pub(super) enum Command { 48 | ReserveKey { 49 | key: String, 50 | resp: Responder, 51 | }, 52 | UnreserveKey { 53 | reservation: KeyReservation, 54 | }, 55 | Put { 56 | reservation: KeyReservation, 57 | value: V, 58 | resp: Responder<()>, 59 | }, 60 | Get { 61 | key: String, // TODO should be &str except lifetimes... 62 | resp: Responder, 63 | }, 64 | Exists { 65 | key: String, // TODO should be &str except lifetimes... 66 | resp: Responder, 67 | }, 68 | Delete { 69 | key: String, 70 | resp: Responder<()>, 71 | }, 72 | } 73 | -------------------------------------------------------------------------------- /crates/kvdb/src/lib.rs: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2023 Entropy Cryptography Inc. 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU Affero General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU Affero General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU Affero General Public License 14 | // along with this program. If not, see . 15 | 16 | //! An encrypted key-value store used for storing keyshares and other private data 17 | pub mod encrypted_sled; 18 | pub mod kv_manager; 19 | use std::{fs, path::PathBuf}; 20 | 21 | /// The intended environment entropy-tss is built for 22 | #[derive(PartialEq)] 23 | pub enum BuildType { 24 | /// Automated tests 25 | Test, 26 | /// A production-like test deployment without TDX 27 | ProductionNoTdx, 28 | /// A production deployment with TDX 29 | ProductionTdx, 30 | } 31 | 32 | /// Build the path used to store the key-value database 33 | pub fn get_db_path(build_type: BuildType) -> String { 34 | let mut root: PathBuf = if build_type == BuildType::ProductionTdx { 35 | "/persist".into() 36 | } else { 37 | std::env::current_dir().expect("could not get home directory") 38 | }; 39 | root.push(".entropy"); 40 | if build_type == BuildType::Test { 41 | root.push("testing"); 42 | } else { 43 | root.push("production"); 44 | } 45 | root.push("db"); 46 | let result: String = root.clone().display().to_string(); 47 | fs::create_dir_all(root) 48 | .unwrap_or_else(|_| panic!("could not create database path at: {}", result.clone())); 49 | result 50 | } 51 | 52 | pub fn clean_tests() { 53 | let db_path = get_db_path(BuildType::Test); 54 | if fs::metadata(db_path.clone()).is_ok() { 55 | let _result = std::fs::remove_dir_all(db_path); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /crates/protocol/Makefile: -------------------------------------------------------------------------------- 1 | # Builds a JS Module for nodejs with glue for the compiled WASM. 2 | build-nodejs :: 3 | wasm-pack build --target nodejs --scope "entropyxyz" . --no-default-features -F wasm 4 | cp js-README.md ./pkg/README.md 5 | cp ../../LICENSE ./pkg/ 6 | 7 | # Builds a JS Module for web with glue for the compiled WASM. 8 | build-web :: 9 | wasm-pack build --target web --scope "entropyxyz" . --no-default-features -F wasm 10 | cp js-README.md ./pkg/README.md 11 | cp ../../LICENSE ./pkg/ 12 | 13 | # Another build option for compiling to webpack, builds a typescript library around the WASM for use 14 | # with npm. 15 | build-bundler :: 16 | wasm-pack build --target bundler --scope "entropyxyz" . --no-default-features -F wasm 17 | cp js-README.md ./pkg/README.md 18 | cp ../../LICENSE ./pkg/ 19 | 20 | # Builds a JS Module for nodejs with testing features 21 | build-nodejs-testing :: 22 | wasm-pack build --target nodejs --scope "entropyxyz" . --no-default-features -F wasm-test 23 | cp js-README.md ./pkg/README.md 24 | cp ../../LICENSE ./pkg/ 25 | 26 | # Cleans out build artifacts. 27 | clean :: 28 | rm -rf pkg/ nodejs-test/node_modules/ 29 | -------------------------------------------------------------------------------- /crates/protocol/README.md: -------------------------------------------------------------------------------- 1 | # `entropy-protocol` 2 | 3 | Protocol execution and transport logic for the Entropy signing, DKG, and proactive refresh 4 | protocols. 5 | 6 | For explanations of the JS bindings see [`./js-README.md`](./js-README.md) 7 | 8 | ## Compiling on wasm: 9 | 10 | To check that things compile correctly on wasm: 11 | 12 | ```bash 13 | make build-nodejs 14 | ``` 15 | 16 | ## Running Nodejs tests: 17 | 18 | To run tests for JS bindings to the `sign_and_encrypt` api: 19 | ```bash 20 | make build-nodejs-testing 21 | cd nodejs-test 22 | yarn 23 | yarn test 24 | ``` 25 | If you have issues when re-running these tests following changes, remove `nodejs-test/node_modules` 26 | before re-running `yarn`. 27 | 28 | For instructions on running entropy-tss integration test using JS bindings to the user private mode 29 | signing and DKG functions, see 30 | [`../threshold-signature-server/README.md`](../threshold-signature-server/README.md) 31 | -------------------------------------------------------------------------------- /crates/protocol/nodejs-test/index.test.js: -------------------------------------------------------------------------------- 1 | const protocol = require('entropy-protocol') 2 | const test = require('tape') 3 | 4 | test('Convert Uint8Array to and from hex', function (t) { 5 | t.plan(2) 6 | 7 | const empty = new Uint8Array(32) 8 | const emptyHex = protocol.toHex(empty) 9 | t.equal(Buffer.from(empty).toString('hex'), emptyHex) 10 | const emptyArray = protocol.fromHex(emptyHex) 11 | t.true(protocol.constantTimeEq(empty, emptyArray)) 12 | }) 13 | 14 | test('Encrypt, decrypt with HPKE', function (t) { 15 | t.plan(2) 16 | 17 | const { generateSigningKey, encryptAndSign, decryptAndVerify } = protocol.Hpke 18 | 19 | const aliceSk = generateSigningKey() 20 | 21 | const bobX25519Keypair = protocol.X25519Keypair.generate() 22 | 23 | const plaintext = new Uint8Array(32) 24 | 25 | // Alice encrypts and signs the message to bob. 26 | const encryptedAndSignedMessage = encryptAndSign(aliceSk, plaintext, bobX25519Keypair.publicKey()) 27 | 28 | // Bob decrypts the message. 29 | const decryptedPlaintext = decryptAndVerify(bobX25519Keypair.secretKey(), encryptedAndSignedMessage) 30 | 31 | // Check the original plaintext equals the decrypted plaintext. 32 | t.true(protocol.constantTimeEq(decryptedPlaintext, plaintext)) 33 | 34 | const malloryX25519Keypair = protocol.X25519Keypair.generate() 35 | 36 | // Malloy cannot decrypt the message. 37 | let error 38 | try { 39 | decryptAndVerify(malloryX25519Keypair.secretKey(), encryptedAndSignedMessage) 40 | } catch (e) { 41 | error = e.toString() 42 | } 43 | t.equals(error, 'Error: Hpke: HPKE Error: OpenError') 44 | }) 45 | -------------------------------------------------------------------------------- /crates/protocol/nodejs-test/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "nodejs-test", 3 | "version": "1.0.0", 4 | "main": "index.js", 5 | "license": "AGPL-3.0-only", 6 | "scripts": { 7 | "test": "tape *.test.js" 8 | }, 9 | "dependencies": { 10 | "entropy-protocol": "file:../pkg", 11 | "ws": "^8.14.2" 12 | }, 13 | "devDependencies": { 14 | "tape": "^5.7.2" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /crates/protocol/src/protocol_message.rs: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2023 Entropy Cryptography Inc. 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU Affero General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU Affero General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU Affero General Public License 14 | // along with this program. If not, see . 15 | 16 | use std::str; 17 | 18 | use manul::session::Message; 19 | use serde::{Deserialize, Serialize}; 20 | 21 | use crate::{protocol_transport::errors::ProtocolMessageErr, PartyId}; 22 | 23 | /// A Message send during one of the synedrion protocols 24 | #[derive(Debug, Clone, Serialize, Deserialize)] 25 | pub struct ProtocolMessage { 26 | /// Identifier of the author of this message 27 | pub from: PartyId, 28 | /// Identifier of the destination of this message 29 | pub to: PartyId, 30 | /// Either a Synedrion protocol message or a verifying key. 31 | /// 32 | /// We need to send verifying keys during DKG to parties who were not present for the key init 33 | /// session. 34 | pub payload: ProtocolMessagePayload, 35 | } 36 | 37 | /// The payload of a message sent during one of the synedrion protocols 38 | #[derive(Debug, Clone, Serialize, Deserialize)] 39 | pub enum ProtocolMessagePayload { 40 | /// The signed protocol message 41 | Message(Box>), 42 | /// A verifying key for parties who were not present in the key init session 43 | VerifyingKey(Vec), 44 | } 45 | 46 | impl TryFrom<&[u8]> for ProtocolMessage { 47 | type Error = ProtocolMessageErr; 48 | 49 | fn try_from(value: &[u8]) -> Result { 50 | let parsed_msg: ProtocolMessage = bincode::deserialize(value)?; 51 | Ok(parsed_msg) 52 | } 53 | } 54 | 55 | impl ProtocolMessage { 56 | pub(crate) fn new(from: &PartyId, to: &PartyId, payload: Message) -> Self { 57 | Self { 58 | from: from.clone(), 59 | to: to.clone(), 60 | payload: ProtocolMessagePayload::Message(Box::new(payload)), 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /crates/protocol/src/protocol_transport/broadcaster.rs: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2023 Entropy Cryptography Inc. 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU Affero General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU Affero General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU Affero General Public License 14 | // along with this program. If not, see . 15 | 16 | //! Listener becomes Broadcaster when all other parties have subscribed. 17 | use tokio::sync::{ 18 | broadcast::{self, error::SendError}, 19 | mpsc, 20 | }; 21 | 22 | use crate::protocol_message::ProtocolMessage; 23 | 24 | /// A wrapper around [broadcast::Sender] for broadcasting protocol messages 25 | #[derive(Debug, Clone)] 26 | pub struct Broadcaster { 27 | /// Channel for outgoing protocol messages to all parties 28 | pub broadcast: broadcast::Sender, 29 | /// Channel for incoming protocol messages from all parties 30 | /// A clone of the sender is kept here so that we can use it in the session loop to put messages 31 | /// destined for a different sub-session back into the incoming queue 32 | pub incoming_sender: mpsc::Sender, 33 | } 34 | 35 | impl Broadcaster { 36 | /// Send an outgoing protocol message 37 | pub fn send(&self, msg: ProtocolMessage) -> Result>> { 38 | Ok(self.broadcast.send(msg)?) 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /crates/protocol/src/protocol_transport/errors.rs: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2023 Entropy Cryptography Inc. 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU Affero General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU Affero General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU Affero General Public License 14 | // along with this program. If not, see . 15 | 16 | use std::string::FromUtf8Error; 17 | 18 | use thiserror::Error; 19 | 20 | /// An error relating to a websocket connection 21 | #[derive(Debug, Error)] 22 | pub enum WsError { 23 | #[error("Ws Connection closed unexpectedly")] 24 | ConnectionClosed, 25 | #[error("Connection error: {0}")] 26 | ConnectionError(String), 27 | #[error("Message received after signing protocol has finished")] 28 | MessageAfterProtocolFinish, 29 | #[error("UTF8 parse error {0}")] 30 | UTF8Parse(#[from] FromUtf8Error), 31 | #[error("Cannot get signer from app state")] 32 | SignerFromAppState, 33 | #[error("Unexpected message type")] 34 | UnexpectedMessageType, 35 | #[error("Encrypted connection error {0}")] 36 | EncryptedConnection(String), 37 | #[error("Error parsing Signing Message")] 38 | ProtocolMessage(#[from] super::errors::ProtocolMessageErr), 39 | #[error("Serialization Error: {0:?}")] 40 | Serialization(#[from] bincode::Error), 41 | #[error("Received bad subscribe message")] 42 | BadSubscribeMessage, 43 | #[error("Node has started fresh and is not yet successfully set up")] 44 | NotReady, 45 | } 46 | 47 | /// An error relating to handling a `ProtocolMessage` 48 | #[derive(Debug, Error)] 49 | pub enum ProtocolMessageErr { 50 | #[error("Utf8Error: {0:?}")] 51 | Utf8(#[from] std::str::Utf8Error), 52 | #[error("Deserialization Error: {0:?}")] 53 | Deserialization(#[from] bincode::Error), 54 | } 55 | 56 | /// Errors relating to encrypted WS connections / noise handshaking 57 | #[derive(Debug, Error)] 58 | pub enum EncryptedConnectionErr { 59 | #[error("Noise error: {0}")] 60 | Noise(#[from] snow::error::Error), 61 | #[error("Utf8Error: {0:?}")] 62 | Utf8(#[from] std::str::Utf8Error), 63 | #[error("Utf8Error: {0:?}")] 64 | FromUtf8(#[from] FromUtf8Error), 65 | #[error("Websocket error: {0}")] 66 | WebSocket(#[from] WsError), 67 | #[error("Could not get remote public key")] 68 | RemotePublicKey, 69 | } 70 | 71 | /// Error when checking supported protocol versions 72 | #[derive(Debug, Error, PartialEq)] 73 | pub enum ProtocolVersionMismatchError { 74 | #[error("This version of the protocol is newer than ours - we are on version {0}")] 75 | VersionTooNew(u32), 76 | #[error("This version of the protocol is no longer supported - the oldest we support is {0}")] 77 | VersionTooOld(u32), 78 | } 79 | -------------------------------------------------------------------------------- /crates/shared/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name ="entropy-shared" 3 | description="Shared types used by the Entropy chain node and Entropy Threshold Signing Server" 4 | version ="0.4.0-rc.1" 5 | authors =['Entropy Cryptography '] 6 | homepage ='https://entropy.xyz/' 7 | license ='AGPL-3.0-or-later' 8 | repository ='https://github.com/entropyxyz/entropy-core' 9 | edition ='2021' 10 | 11 | [dependencies] 12 | codec ={ package="parity-scale-codec", version="3.0.0", default-features=false } 13 | scale-info ={ version='2.11.6', default-features=false, features=['derive'] } 14 | serde ={ version="1.0", default-features=false, features=["derive"] } 15 | serde_derive="1.0.147" 16 | strum ={ version="0.27.1", optional=true } 17 | strum_macros={ version="0.27.1", optional=true } 18 | blake2 ={ version="0.10.4", default-features=false } 19 | 20 | sp-runtime ={ version="41.1.0", default-features=false, optional=true, features=["serde"] } 21 | sp-std ={ version="14.0.0", default-features=false } 22 | lazy_static={ version="1.5.0", features=["spin_no_std"] } 23 | hex-literal="1.0.0" 24 | sp-core ={ version="36.1.0", default-features=false } 25 | subxt ={ version="0.42.0", default-features=false, optional=true } 26 | tdx-quote ="0.0.3" 27 | 28 | [features] 29 | default=["std"] 30 | std=[ 31 | "codec/std", 32 | "scale-info/std", 33 | "serde/std", 34 | "sp-runtime/std", 35 | "sp-std/std", 36 | "strum", 37 | "strum_macros", 38 | ] 39 | wasm=["codec/std", "scale-info/std", "serde/std", "sp-std/std"] 40 | wasm-no-std=["sp-runtime"] 41 | user-native=["dep:subxt", "subxt/native"] 42 | user-wasm=["dep:subxt", "subxt/web"] 43 | # Enables non-mock TDX quote verification 44 | production=[] 45 | -------------------------------------------------------------------------------- /crates/shared/README.md: -------------------------------------------------------------------------------- 1 | # entropy-shared 2 | 3 | This includes shared types between `server` and `entropy`. They also get used in `entropy-js` via `@polkadot/typegen`. 4 | -------------------------------------------------------------------------------- /crates/shared/device_key_proxy.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/entropyxyz/entropy-core/22f3d43664e4acf87445e06cedcb6a7851f6b3a7/crates/shared/device_key_proxy.wasm -------------------------------------------------------------------------------- /crates/shared/src/lib.rs: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2023 Entropy Cryptography Inc. 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU Affero General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU Affero General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU Affero General Public License 14 | // along with this program. If not, see . 15 | 16 | #![cfg_attr(not(any(feature = "std", feature = "user-wasm")), no_std)] 17 | //! Types that is shared by clients and substrate nodes, 18 | //! i.e. messages sent from one to the other and structs contained in those messages 19 | //! 20 | //! This helps ensures those structs are synced among clients and nodes. 21 | pub use constants::*; 22 | pub use types::*; 23 | pub mod attestation; 24 | pub mod constants; 25 | pub mod types; 26 | 27 | #[cfg(any(feature = "user-native", feature = "user-wasm"))] 28 | pub mod user; 29 | -------------------------------------------------------------------------------- /crates/shared/src/user.rs: -------------------------------------------------------------------------------- 1 | use crate::X25519PublicKey; 2 | use serde::{Deserialize, Serialize}; 3 | use subxt::utils::AccountId32; 4 | 5 | /// Details of a TSS server 6 | /// This is different from `entropy_shared::ValidatorInfo` in that it is used for interacting 7 | /// with the client rather than with the chain - since it uses types which we cannot use in the 8 | /// chain runtime 9 | #[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq)] 10 | pub struct ValidatorInfo { 11 | pub x25519_public_key: X25519PublicKey, 12 | pub ip_address: String, 13 | pub tss_account: AccountId32, 14 | } 15 | -------------------------------------------------------------------------------- /crates/test-cli/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name ="entropy-test-cli" 3 | description="Simple command line interface client for testing Entropy" 4 | version ='0.4.0-rc.1' 5 | authors =['Entropy Cryptography '] 6 | homepage ='https://entropy.xyz/' 7 | license ='AGPL-3.0-or-later' 8 | repository ='https://github.com/entropyxyz/entropy-core' 9 | edition ='2021' 10 | 11 | [dependencies] 12 | entropy-client ={ version="0.4.0-rc.1", path="../client" } 13 | clap ={ version="4.5.39", features=["derive"] } 14 | colored ="3.0.0" 15 | subxt ="0.42.0" 16 | sp-core ="36.1.0" 17 | anyhow ="1.0.98" 18 | tokio ={ version="1.44", features=["macros", "rt-multi-thread", "io-util", "process"] } 19 | hex ="0.4.3" 20 | bincode ="1.3.3" 21 | x25519-dalek ="2.0.1" 22 | sp-runtime ={ version="41.1.0", default-features=false } 23 | entropy-shared ={ version="0.4.0-rc.1", path="../shared" } 24 | serde_json ="1.0.140" 25 | serde ={ version="1.0.219", features=["derive"] } 26 | reqwest ="0.12.19" 27 | parity-scale-codec={ version="3.7.2", default-features=false } 28 | -------------------------------------------------------------------------------- /crates/test-cli/src/main.rs: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2023 Entropy Cryptography Inc. 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU Affero General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU Affero General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU Affero General Public License 14 | // along with this program. If not, see . 15 | 16 | //! Simple CLI to test registering, updating programs and signing 17 | use clap::Parser; 18 | use colored::Colorize; 19 | use entropy_test_cli::{run_command, Cli}; 20 | use std::time::Instant; 21 | 22 | #[tokio::main] 23 | async fn main() -> anyhow::Result<()> { 24 | let now = Instant::now(); 25 | let cli = Cli::parse(); 26 | let json_ouput = cli.json; 27 | match run_command(cli, None, None, None, None, None).await { 28 | Ok(output) => { 29 | if json_ouput { 30 | println!("{}", output); 31 | } else { 32 | println!("Success: {}", output.green()); 33 | println!("{}", format!("That took {:?}", now.elapsed()).yellow()); 34 | } 35 | Ok(()) 36 | }, 37 | Err(err) => { 38 | if !json_ouput { 39 | eprintln!("{}", "Failed!".red()); 40 | } 41 | Err(err) 42 | }, 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /crates/testing-utils/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name ="entropy-testing-utils" 3 | description="Utilities for testing the Entropy Threshold Signature Server" 4 | version ='0.4.0-rc.1' 5 | authors =['Entropy Cryptography '] 6 | homepage ='https://entropy.xyz/' 7 | license ='AGPL-3.0-or-later' 8 | repository ='https://github.com/entropyxyz/entropy-core' 9 | edition ='2021' 10 | 11 | [dependencies] 12 | subxt="0.42.0" 13 | sp-keyring="41.0.0" 14 | project-root="0.2.2" 15 | sp-core={ version="36.1.0", default-features=false } 16 | parity-scale-codec="3.7.2" 17 | lazy_static="1.5.0" 18 | hex-literal="1.0.0" 19 | tokio={ version="1.44", features=["macros", "fs", "rt-multi-thread", "io-util", "process"] } 20 | axum={ version="0.8.4" } 21 | entropy-shared={ version="0.4.0-rc.1", path="../shared" } 22 | entropy-kvdb={ version="0.4.0-rc.1", path="../kvdb", default-features=false } 23 | entropy-tss={ version="0.4.0-rc.1", path="../threshold-signature-server", features=[ 24 | "test_helpers", 25 | ] } 26 | entropy-protocol={ version="0.4.0-rc.1", path="../protocol" } 27 | hex="0.4.3" 28 | rand_core="0.6.4" 29 | rand="0.8.5" 30 | tdx-quote={ version="0.0.3", features=["mock"] } 31 | k256={ version="0.13", default-features=false, features=["ecdsa"] } 32 | synedrion={ version="0.3.0", features=["k256", "dev"] } 33 | manul={ version="0.2.1", features=["tokio", "dev"] } 34 | 35 | # Logging 36 | tracing ="0.1.41" 37 | tracing-subscriber={ version="0.3.19", features=["env-filter"] } 38 | -------------------------------------------------------------------------------- /crates/testing-utils/example_barebones_with_auxilary.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/entropyxyz/entropy-core/22f3d43664e4acf87445e06cedcb6a7851f6b3a7/crates/testing-utils/example_barebones_with_auxilary.wasm -------------------------------------------------------------------------------- /crates/testing-utils/example_custom_hash.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/entropyxyz/entropy-core/22f3d43664e4acf87445e06cedcb6a7851f6b3a7/crates/testing-utils/example_custom_hash.wasm -------------------------------------------------------------------------------- /crates/testing-utils/faucet_program.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/entropyxyz/entropy-core/22f3d43664e4acf87445e06cedcb6a7851f6b3a7/crates/testing-utils/faucet_program.wasm -------------------------------------------------------------------------------- /crates/testing-utils/infinite_loop.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/entropyxyz/entropy-core/22f3d43664e4acf87445e06cedcb6a7851f6b3a7/crates/testing-utils/infinite_loop.wasm -------------------------------------------------------------------------------- /crates/testing-utils/keyshares/README.md: -------------------------------------------------------------------------------- 1 | See [`create-test-keyshares`](../../../scripts/create-test-keyshares) for an explanation of how 2 | these are generated and what the different keyshare sets represent. 3 | -------------------------------------------------------------------------------- /crates/testing-utils/keyshares/production/keyshare-held-by-alice.keyshare: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/entropyxyz/entropy-core/22f3d43664e4acf87445e06cedcb6a7851f6b3a7/crates/testing-utils/keyshares/production/keyshare-held-by-alice.keyshare -------------------------------------------------------------------------------- /crates/testing-utils/keyshares/production/keyshare-held-by-bob.keyshare: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/entropyxyz/entropy-core/22f3d43664e4acf87445e06cedcb6a7851f6b3a7/crates/testing-utils/keyshares/production/keyshare-held-by-bob.keyshare -------------------------------------------------------------------------------- /crates/testing-utils/keyshares/production/keyshare-held-by-charlie.keyshare: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/entropyxyz/entropy-core/22f3d43664e4acf87445e06cedcb6a7851f6b3a7/crates/testing-utils/keyshares/production/keyshare-held-by-charlie.keyshare -------------------------------------------------------------------------------- /crates/testing-utils/null_interface: -------------------------------------------------------------------------------- 1 | [] -------------------------------------------------------------------------------- /crates/testing-utils/oracle_example.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/entropyxyz/entropy-core/22f3d43664e4acf87445e06cedcb6a7851f6b3a7/crates/testing-utils/oracle_example.wasm -------------------------------------------------------------------------------- /crates/testing-utils/src/lib.rs: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2023 Entropy Cryptography Inc. 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU Affero General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU Affero General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU Affero General Public License 14 | // along with this program. If not, see . 15 | 16 | #[macro_use] 17 | extern crate lazy_static; 18 | 19 | pub use entropy_tss::chain_api; 20 | pub mod constants; 21 | pub mod create_test_keyshares; 22 | pub mod helpers; 23 | mod node_proc; 24 | pub mod substrate_context; 25 | pub use entropy_tss::helpers::tests::{spawn_testing_validators, ChainSpecType}; 26 | pub use node_proc::TestNodeProcess; 27 | pub use substrate_context::*; 28 | 29 | pub use entropy_tss::helpers::validator::get_signer_and_x25519_secret_from_mnemonic; 30 | -------------------------------------------------------------------------------- /crates/testing-utils/template_barebones.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/entropyxyz/entropy-core/22f3d43664e4acf87445e06cedcb6a7851f6b3a7/crates/testing-utils/template_barebones.wasm -------------------------------------------------------------------------------- /crates/testing-utils/template_basic_transaction.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/entropyxyz/entropy-core/22f3d43664e4acf87445e06cedcb6a7851f6b3a7/crates/testing-utils/template_basic_transaction.wasm -------------------------------------------------------------------------------- /crates/threshold-signature-server/.gitignore: -------------------------------------------------------------------------------- 1 | test_db_* 2 | -------------------------------------------------------------------------------- /crates/threshold-signature-server/README.md: -------------------------------------------------------------------------------- 1 | # `entropy-tss` 2 | 3 | The threshold signature server which stores keyshares and executes the Entropy protocols. 4 | 5 | ## Running integrations tests for the JS bindings to the `entropy-protocol` private user API 6 | 7 | ```bash 8 | cd crates/protocol 9 | make build-nodejs-testing 10 | cd nodejs-test 11 | yarn 12 | cd ../../.. 13 | cargo test -p entropy-tss --release -F wasm_test test_wasm 14 | ``` 15 | 16 | If you have issues when re-running these tests following changes, remove `nodejs-test/node_modules` 17 | before re-running `yarn`. 18 | -------------------------------------------------------------------------------- /crates/threshold-signature-server/build.rs: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2023 Entropy Cryptography Inc. 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU Affero General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU Affero General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU Affero General Public License 14 | // along with this program. If not, see . 15 | 16 | use std::error::Error; 17 | use vergen::EmitBuilder; 18 | 19 | fn main() -> Result<(), Box> { 20 | // Emit the instructions 21 | EmitBuilder::builder().all_git().emit()?; 22 | Ok(()) 23 | } 24 | -------------------------------------------------------------------------------- /crates/threshold-signature-server/src/attestation/errors.rs: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2023 Entropy Cryptography Inc. 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU Affero General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU Affero General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU Affero General Public License 14 | // along with this program. If not, see . 15 | 16 | use std::array::TryFromSliceError; 17 | 18 | use axum::{ 19 | http::StatusCode, 20 | response::{IntoResponse, Response}, 21 | }; 22 | use thiserror::Error; 23 | 24 | #[derive(Debug, Error)] 25 | pub enum AttestationErr { 26 | #[error("Generic Substrate error: {0}")] 27 | GenericSubstrate(#[from] subxt::error::Error), 28 | #[error("User Error: {0}")] 29 | UserErr(#[from] crate::user::UserErr), 30 | #[error("Input must be 32 bytes: {0}")] 31 | TryFromSlice(#[from] TryFromSliceError), 32 | #[error("Substrate: {0}")] 33 | SubstrateClient(#[from] entropy_client::substrate::SubstrateError), 34 | #[error("Could not decode message: {0}")] 35 | Codec(#[from] parity_scale_codec::Error), 36 | #[cfg(feature = "production")] 37 | #[error("Quote generation: {0}")] 38 | QuoteGeneration(String), 39 | #[error("Cannot encode verifying key: {0}")] 40 | EncodeVerifyingKey(#[from] tdx_quote::VerifyingKeyError), 41 | #[error("Verifying key is not 33 bytes long")] 42 | BadVerifyingKeyLength, 43 | #[error("Kv error: {0}")] 44 | Kv(#[from] entropy_kvdb::kv_manager::error::KvError), 45 | #[error("Attestation request: {0}")] 46 | AttestationRequest(#[from] entropy_client::errors::AttestationRequestError), 47 | #[error("Invalid or unknown context value given in query string")] 48 | UnknownContext, 49 | #[cfg(feature = "production")] 50 | #[error("Quote parse: {0}")] 51 | QuoteParse(#[from] tdx_quote::QuoteParseError), 52 | #[error("anyhow error: {0}")] 53 | Anyhow(#[from] anyhow::Error), 54 | #[error("Application State Error: {0}")] 55 | AppStateError(#[from] crate::helpers::app_state::AppStateError), 56 | } 57 | 58 | impl IntoResponse for AttestationErr { 59 | fn into_response(self) -> Response { 60 | tracing::error!("{:?}", format!("{self}")); 61 | let body = format!("{self}").into_bytes(); 62 | (StatusCode::INTERNAL_SERVER_ERROR, body).into_response() 63 | } 64 | } 65 | 66 | /// Error when checking quote measurement value 67 | #[derive(Debug, Error)] 68 | pub enum QuoteMeasurementErr { 69 | #[error("Substrate: {0}")] 70 | SubstrateClient(#[from] entropy_client::substrate::SubstrateError), 71 | #[error("Could not get accepted measurement values from on-chain parameters")] 72 | NoMeasurementValues, 73 | #[error("Quote verification: {0}")] 74 | Kv(#[from] entropy_shared::attestation::VerifyQuoteError), 75 | } 76 | -------------------------------------------------------------------------------- /crates/threshold-signature-server/src/attestation/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2023 Entropy Cryptography Inc. 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU Affero General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU Affero General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU Affero General Public License 14 | // along with this program. If not, see . 15 | 16 | //! Makes attestations that this program is running on TDX hardware 17 | 18 | pub mod api; 19 | pub mod errors; 20 | 21 | #[cfg(test)] 22 | mod tests; 23 | -------------------------------------------------------------------------------- /crates/threshold-signature-server/src/attestation/tests.rs: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2023 Entropy Cryptography Inc. 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU Affero General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU Affero General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU Affero General Public License 14 | // along with this program. If not, see . 15 | use crate::{ 16 | chain_api::{entropy, get_api, get_rpc}, 17 | helpers::{ 18 | substrate::query_chain, 19 | tests::{initialize_test_logger, spawn_testing_validators, ChainSpecType}, 20 | }, 21 | }; 22 | use entropy_kvdb::clean_tests; 23 | use entropy_testing_utils::{ 24 | constants::BOB_STASH_ADDRESS, substrate_context::test_node_process_stationary, 25 | }; 26 | use serial_test::serial; 27 | use subxt::utils::AccountId32; 28 | use tdx_quote::{decode_verifying_key, Quote}; 29 | 30 | #[tokio::test] 31 | #[serial] 32 | async fn test_get_attest() { 33 | initialize_test_logger().await; 34 | clean_tests(); 35 | 36 | let cxt = test_node_process_stationary().await; 37 | let (_validator_ips, _validator_ids) = 38 | spawn_testing_validators(ChainSpecType::Integration).await; 39 | 40 | let api = get_api(&cxt.ws_url).await.unwrap(); 41 | let rpc = get_rpc(&cxt.ws_url).await.unwrap(); 42 | 43 | let quote_bytes = reqwest::get("http://127.0.0.1:3002/v1/attest?context=validate") 44 | .await 45 | .unwrap() 46 | .bytes() 47 | .await 48 | .unwrap(); 49 | let quote = Quote::from_bytes("e_bytes).unwrap(); 50 | 51 | let query = 52 | entropy::storage().staking_extension().threshold_servers(&AccountId32(BOB_STASH_ADDRESS.0)); 53 | let server_info = query_chain(&api, &rpc, query, None).await.unwrap().unwrap(); 54 | 55 | let provisioning_certification_key = 56 | decode_verifying_key(&server_info.provisioning_certification_key.0.try_into().unwrap()) 57 | .unwrap(); 58 | 59 | assert!(quote.verify_with_pck(&provisioning_certification_key).is_ok()) 60 | } 61 | -------------------------------------------------------------------------------- /crates/threshold-signature-server/src/backup_provider/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2023 Entropy Cryptography Inc. 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU Affero General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU Affero General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU Affero General Public License 14 | // along with this program. If not, see . 15 | 16 | //! Backup database encryption key provider service 17 | pub mod api; 18 | pub mod errors; 19 | 20 | #[cfg(test)] 21 | mod tests; 22 | -------------------------------------------------------------------------------- /crates/threshold-signature-server/src/health/api.rs: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2023 Entropy Cryptography Inc. 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU Affero General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU Affero General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU Affero General Public License 14 | // along with this program. If not, see . 15 | 16 | use axum::http::StatusCode; 17 | 18 | /// For checking the health of the TSS 19 | #[tracing::instrument] 20 | pub async fn healthz() -> StatusCode { 21 | StatusCode::OK 22 | } 23 | -------------------------------------------------------------------------------- /crates/threshold-signature-server/src/health/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2023 Entropy Cryptography Inc. 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU Affero General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU Affero General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU Affero General Public License 14 | // along with this program. If not, see . 15 | 16 | pub mod api; 17 | 18 | #[cfg(test)] 19 | mod tests; 20 | -------------------------------------------------------------------------------- /crates/threshold-signature-server/src/health/tests.rs: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2023 Entropy Cryptography Inc. 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU Affero General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU Affero General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU Affero General Public License 14 | // along with this program. If not, see . 15 | 16 | use axum::http::StatusCode; 17 | use entropy_kvdb::clean_tests; 18 | use serial_test::serial; 19 | 20 | use crate::helpers::tests::{initialize_test_logger, setup_client}; 21 | 22 | #[tokio::test] 23 | #[serial] 24 | async fn health() { 25 | clean_tests(); 26 | initialize_test_logger().await; 27 | setup_client().await; 28 | 29 | let client = reqwest::Client::new(); 30 | let response = client.get("http://127.0.0.1:3001/healthz").send().await.unwrap(); 31 | assert_eq!(response.status(), StatusCode::OK); 32 | clean_tests(); 33 | } 34 | -------------------------------------------------------------------------------- /crates/threshold-signature-server/src/helpers/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2023 Entropy Cryptography Inc. 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU Affero General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU Affero General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU Affero General Public License 14 | // along with this program. If not, see . 15 | 16 | //! Helper modules for various components of the TSS server 17 | pub mod app_state; 18 | pub mod launch; 19 | pub mod logger; 20 | pub mod signing; 21 | pub mod substrate; 22 | pub mod user; 23 | pub mod validator; 24 | 25 | #[cfg(any(test, feature = "test_helpers"))] 26 | pub mod tests; 27 | -------------------------------------------------------------------------------- /crates/threshold-signature-server/src/helpers/validator.rs: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2023 Entropy Cryptography Inc. 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU Affero General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU Affero General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU Affero General Public License 14 | // along with this program. If not, see . 15 | 16 | //! Utilites relating to [crate::validator] 17 | use bip39::{Language, Mnemonic}; 18 | use entropy_client::substrate::PairSigner; 19 | use hkdf::Hkdf; 20 | use sha2::Sha256; 21 | use sp_core::{sr25519, Pair}; 22 | use x25519_dalek::StaticSecret; 23 | use zeroize::Zeroize; 24 | 25 | use crate::user::UserErr; 26 | 27 | /// Constants used in the derivation path 28 | const KDF_SR25519: &[u8] = b"sr25519-threshold-account"; 29 | const KDF_X25519: &[u8] = b"X25519-keypair"; 30 | 31 | /// Get the PairSigner, seed, and also the x25519 encryption keypair for 32 | /// this threshold server 33 | pub fn get_signer_and_x25519_secret( 34 | mnemonic: &str, 35 | ) -> Result<(sr25519::Pair, [u8; 32], StaticSecret), UserErr> { 36 | let hkdf = get_hkdf_from_mnemonic(mnemonic)?; 37 | let (pair_signer, seed) = get_signer_from_hkdf(&hkdf)?; 38 | let static_secret = get_x25519_secret_from_hkdf(&hkdf)?; 39 | Ok((pair_signer, seed, static_secret)) 40 | } 41 | 42 | /// Given a mnemonic, setup hkdf 43 | fn get_hkdf_from_mnemonic(mnemonic: &str) -> Result, UserErr> { 44 | let mnemonic = Mnemonic::parse_in_normalized(Language::English, mnemonic) 45 | .map_err(|e| UserErr::Mnemonic(e.to_string()))?; 46 | Ok(Hkdf::::new(None, &mnemonic.to_seed(""))) 47 | } 48 | 49 | /// Derive signing keypair and return it together with the seed 50 | pub fn get_signer_from_hkdf(hkdf: &Hkdf) -> Result<(sr25519::Pair, [u8; 32]), UserErr> { 51 | let mut sr25519_seed = [0u8; 32]; 52 | hkdf.expand(KDF_SR25519, &mut sr25519_seed)?; 53 | let pair = sr25519::Pair::from_seed(&sr25519_seed); 54 | Ok((pair, sr25519_seed)) 55 | } 56 | 57 | /// Derive x25519 secret 58 | fn get_x25519_secret_from_hkdf(hkdf: &Hkdf) -> Result { 59 | let mut secret = [0u8; 32]; 60 | hkdf.expand(KDF_X25519, &mut secret)?; 61 | let static_secret = StaticSecret::from(secret); 62 | secret.zeroize(); 63 | Ok(static_secret) 64 | } 65 | 66 | /// For testing where we sometimes don't have access to the kvdb, derive directly from the mnemonic 67 | #[cfg(any(test, feature = "test_helpers"))] 68 | pub fn get_signer_and_x25519_secret_from_mnemonic( 69 | mnemonic: &str, 70 | ) -> Result<(PairSigner, StaticSecret), UserErr> { 71 | let hkdf = get_hkdf_from_mnemonic(mnemonic)?; 72 | let (pair, _) = get_signer_from_hkdf(&hkdf)?; 73 | let pair_signer = PairSigner::new(pair); 74 | let static_secret = get_x25519_secret_from_hkdf(&hkdf)?; 75 | Ok((pair_signer, static_secret)) 76 | } 77 | -------------------------------------------------------------------------------- /crates/threshold-signature-server/src/node_info/errors.rs: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2023 Entropy Cryptography Inc. 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU Affero General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU Affero General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU Affero General Public License 14 | // along with this program. If not, see . 15 | use axum::{ 16 | http::StatusCode, 17 | response::{IntoResponse, Response}, 18 | }; 19 | use thiserror::Error; 20 | 21 | /// Errors for protocol execution 22 | #[derive(Debug, Error)] 23 | pub enum GetInfoError { 24 | #[error("Could not get public keys: {0}")] 25 | User(#[from] crate::user::errors::UserErr), 26 | #[error("Could not get Provisioning Certification Key: {0}")] 27 | Attestation(#[from] crate::attestation::errors::AttestationErr), 28 | } 29 | 30 | impl IntoResponse for GetInfoError { 31 | fn into_response(self) -> Response { 32 | tracing::error!("{:?}", format!("{self}")); 33 | let body = format!("{self}").into_bytes(); 34 | (StatusCode::INTERNAL_SERVER_ERROR, body).into_response() 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /crates/threshold-signature-server/src/node_info/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2023 Entropy Cryptography Inc. 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU Affero General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU Affero General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU Affero General Public License 14 | // along with this program. If not, see . 15 | 16 | //! Provides information about this instance of `entropy-tss` 17 | pub mod api; 18 | mod errors; 19 | 20 | #[cfg(test)] 21 | mod tests; 22 | -------------------------------------------------------------------------------- /crates/threshold-signature-server/src/sign_init.rs: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2023 Entropy Cryptography Inc. 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU Affero General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU Affero General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU Affero General Public License 14 | // along with this program. If not, see . 15 | 16 | //! Message sent to Signing Client on protocol initiation. 17 | use entropy_protocol::{SigningSessionInfo, ValidatorInfo}; 18 | use serde::{Deserialize, Serialize}; 19 | 20 | use entropy_client::user::RelayerSignatureRequest; 21 | 22 | /// Information passed to the Signing Client, to initiate the signing process. 23 | /// Most of this information comes from a `Message` struct which gets propagated when a user's 24 | /// signature request transaction is included in a finalized block. 25 | #[derive(Debug, Deserialize, Serialize, Clone)] 26 | pub struct SignInit { 27 | /// Unique id of this signature (may be repeated if this party fails) 28 | pub signing_session_info: SigningSessionInfo, 29 | /// Participating nodes' info. 30 | pub validators_info: Vec, 31 | } 32 | 33 | impl SignInit { 34 | /// Creates new signing object based on passed in data 35 | #[allow(dead_code)] 36 | pub fn new(message: RelayerSignatureRequest, signing_session_info: SigningSessionInfo) -> Self { 37 | Self { signing_session_info, validators_info: message.validators_info } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /crates/threshold-signature-server/src/signing_client/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2023 Entropy Cryptography Inc. 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU Affero General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU Affero General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU Affero General Public License 14 | // along with this program. If not, see . 15 | 16 | //! Communicate with other threshold servers and carry out the signing and DKG protocols 17 | pub mod api; 18 | mod errors; 19 | pub(crate) mod protocol_execution; 20 | pub(crate) mod protocol_transport; 21 | 22 | #[cfg(test)] 23 | mod tests; 24 | 25 | use std::{ 26 | collections::HashMap, 27 | sync::{Arc, Mutex}, 28 | }; 29 | 30 | use entropy_protocol::{Listener, SessionId}; 31 | 32 | pub use self::{errors::*, protocol_execution::ProtocolMessage}; 33 | 34 | /// The state used when setting up protocol connections to track who we are expecting to connect 35 | /// to for a particular protcol execution (Signing or DKG). 36 | #[derive(Default, Debug, Clone)] 37 | pub struct ListenerState { 38 | /// Mapping of [SessionId]s for the protocol run to [Listener]s. 39 | pub listeners: Arc>>, 40 | } 41 | 42 | impl ListenerState { 43 | /// Create a new `ListenerState` 44 | pub fn contains_listener(&self, session_id: &SessionId) -> Result { 45 | Ok(self 46 | .listeners 47 | .lock() 48 | .map_err(|e| SubscribeErr::LockError(e.to_string()))? 49 | .contains_key(session_id)) 50 | } 51 | 52 | /// Gets the list of peers who haven't yet subscribed to us for this particular session. 53 | pub fn unsubscribed_peers( 54 | &self, 55 | session_id: &SessionId, 56 | ) -> Result, SubscribeErr> { 57 | let listeners = 58 | self.listeners.lock().map_err(|e| SubscribeErr::LockError(e.to_string()))?; 59 | let listener = 60 | listeners.get(session_id).ok_or(SubscribeErr::NoSessionId(session_id.clone()))?; 61 | 62 | let unsubscribed_peers = 63 | listener.validators.keys().map(|id| subxt::utils::AccountId32(*id)).collect(); 64 | 65 | Ok(unsubscribed_peers) 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /crates/threshold-signature-server/src/signing_client/protocol_execution/context.rs: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2023 Entropy Cryptography Inc. 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU Affero General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU Affero General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU Affero General Public License 14 | // along with this program. If not, see . 15 | 16 | use entropy_protocol::{KeyParams, PartyId}; 17 | use synedrion::{AuxInfo, ThresholdKeyShare}; 18 | 19 | use crate::sign_init::SignInit; 20 | 21 | /// Context for Signing Protocol execution. 22 | #[derive(Clone)] 23 | pub struct SignContext { 24 | /// Party context from block proposer 25 | pub sign_init: SignInit, 26 | /// Signing key share 27 | pub key_share: ThresholdKeyShare, 28 | pub aux_info: AuxInfo, 29 | } 30 | 31 | impl SignContext { 32 | pub fn new( 33 | sign_init: SignInit, 34 | key_share: ThresholdKeyShare, 35 | aux_info: AuxInfo, 36 | ) -> Self { 37 | Self { sign_init, key_share, aux_info } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /crates/threshold-signature-server/src/unsafe/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2023 Entropy Cryptography Inc. 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU Affero General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU Affero General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU Affero General Public License 14 | // along with this program. If not, see . 15 | 16 | //! Unsafe functionality to be used for testing or development purposes 17 | pub mod api; 18 | 19 | #[cfg(test)] 20 | mod tests; 21 | -------------------------------------------------------------------------------- /crates/threshold-signature-server/src/unsafe/tests.rs: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2023 Entropy Cryptography Inc. 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU Affero General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU Affero General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU Affero General Public License 14 | // along with this program. If not, see . 15 | 16 | use entropy_kvdb::clean_tests; 17 | use serial_test::serial; 18 | 19 | use crate::{ 20 | helpers::tests::{ 21 | initialize_test_logger, put_keyshares_in_state, setup_client, unsafe_get_network_keyshare, 22 | }, 23 | launch::ValidatorName, 24 | }; 25 | 26 | #[tokio::test] 27 | #[serial] 28 | async fn test_unsafe_get_network_key() { 29 | clean_tests(); 30 | initialize_test_logger().await; 31 | let app_state = setup_client().await; 32 | let client = reqwest::Client::new(); 33 | 34 | assert!(unsafe_get_network_keyshare(&client, 3001).await.is_none()); 35 | put_keyshares_in_state(ValidatorName::Alice, &app_state).await; 36 | assert!(unsafe_get_network_keyshare(&client, 3001).await.is_some()); 37 | 38 | clean_tests(); 39 | } 40 | -------------------------------------------------------------------------------- /crates/threshold-signature-server/src/user/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2023 Entropy Cryptography Inc. 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU Affero General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU Affero General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU Affero General Public License 14 | // along with this program. If not, see . 15 | 16 | //! Functionality and HTTP endpoints relating to user interaction 17 | pub mod api; 18 | pub mod errors; 19 | 20 | use entropy_kvdb::kv_manager::value::{KvValue, PartyInfo}; 21 | use serde::{Deserialize, Serialize}; 22 | use subxt::utils::AccountId32; 23 | 24 | pub use self::errors::*; 25 | 26 | #[cfg(test)] 27 | pub(crate) mod tests; 28 | 29 | /// User input, contains key (substrate key) and value (entropy shard) 30 | #[derive(Debug, Deserialize, Serialize, Clone)] 31 | pub struct UserInputPartyInfo { 32 | /// User's substrate key 33 | pub key: AccountId32, 34 | // An encoded SecretKeyShare for this node 35 | pub value: KvValue, 36 | } 37 | 38 | impl TryInto for UserInputPartyInfo { 39 | type Error = UserErr; 40 | 41 | fn try_into(self) -> Result { 42 | let parsed_input = ParsedUserInputPartyInfo { key: self.key, value: self.value }; 43 | Ok(parsed_input) 44 | } 45 | } 46 | 47 | /// Parsed user input 48 | #[derive(Debug, Deserialize, Clone, Serialize)] 49 | pub struct ParsedUserInputPartyInfo { 50 | /// User's substrate key 51 | pub key: AccountId32, 52 | // An encoded SecretKeyShare for this node 53 | pub value: KvValue, // TODO(TK): write this type 54 | } 55 | 56 | // TODO(TK) 57 | impl TryInto for ParsedUserInputPartyInfo { 58 | type Error = UserErr; 59 | 60 | fn try_into(self) -> Result { 61 | // todo!() 62 | Err(UserErr::InputValidation("error")) 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /crates/threshold-signature-server/src/validation/errors.rs: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2023 Entropy Cryptography Inc. 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU Affero General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU Affero General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU Affero General Public License 14 | // along with this program. If not, see . 15 | 16 | use thiserror::Error; 17 | 18 | #[derive(Debug, Error)] 19 | pub enum ValidationErr { 20 | #[error("Secret String failure: {0:?}")] 21 | SecretString(&'static str), 22 | #[error("Message is too old")] 23 | StaleMessage, 24 | #[error("Time subtraction error: {0}")] 25 | SystemTime(#[from] std::time::SystemTimeError), 26 | #[error("Error getting block number")] 27 | BlockNumber, 28 | #[error("Generic Substrate error: {0}")] 29 | GenericSubstrate(#[from] subxt::error::Error), 30 | } 31 | -------------------------------------------------------------------------------- /crates/threshold-signature-server/src/validation/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2023 Entropy Cryptography Inc. 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU Affero General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU Affero General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU Affero General Public License 14 | // along with this program. If not, see . 15 | 16 | use bip39::Mnemonic; 17 | pub use entropy_protocol::sign_and_encrypt::{ 18 | EncryptedSignedMessage, EncryptedSignedMessageErr, SignedMessage, 19 | }; 20 | use entropy_shared::BlockNumber; 21 | use rand_core::{OsRng, RngCore}; 22 | use sp_core::{sr25519, Pair}; 23 | pub mod errors; 24 | use errors::ValidationErr; 25 | 26 | pub const BLOCK_BUFFER: BlockNumber = 5u32; 27 | 28 | /// Derives a sr25519::Pair from a Mnemonic 29 | pub fn mnemonic_to_pair(m: &Mnemonic) -> Result { 30 | Ok(::from_phrase(&m.to_string(), None) 31 | .map_err(|_| ValidationErr::SecretString("Secret String Error"))? 32 | .0) 33 | } 34 | 35 | /// Checks if the message sent was within X amount of time 36 | pub async fn check_stale( 37 | user_block_number: BlockNumber, 38 | chain_block_number: BlockNumber, 39 | ) -> Result<(), ValidationErr> { 40 | let block_difference = chain_block_number.abs_diff(user_block_number); 41 | if block_difference > BLOCK_BUFFER { 42 | return Err(ValidationErr::StaleMessage); 43 | } 44 | Ok(()) 45 | } 46 | 47 | /// Creates a new random Mnemonic. 48 | pub fn new_mnemonic() -> Result { 49 | let mut entropy = [0u8; 32]; 50 | OsRng.fill_bytes(&mut entropy); 51 | Mnemonic::from_entropy(&entropy) 52 | } 53 | 54 | #[cfg(test)] 55 | mod tests { 56 | use super::*; 57 | 58 | #[tokio::test] 59 | async fn test_stale_check() { 60 | let result = check_stale(1, 1).await; 61 | assert!(result.is_ok()); 62 | 63 | let result_server_larger = check_stale(1, 2).await; 64 | assert!(result_server_larger.is_ok()); 65 | 66 | let result_user_larger = check_stale(2, 1).await; 67 | assert!(result_user_larger.is_ok()); 68 | 69 | let fail_stale = check_stale(1, 2 + BLOCK_BUFFER).await.unwrap_err(); 70 | assert_eq!(fail_stale.to_string(), "Message is too old".to_string()); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /crates/threshold-signature-server/src/validator/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2023 Entropy Cryptography Inc. 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU Affero General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU Affero General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU Affero General Public License 14 | // along with this program. If not, see . 15 | 16 | //! Logic around subgroups and interaction with other TSS servers 17 | pub mod api; 18 | pub mod errors; 19 | 20 | #[cfg(test)] 21 | mod tests; 22 | -------------------------------------------------------------------------------- /crates/threshold-signature-server/tests/helpers/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2023 Entropy Cryptography Inc. 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU Affero General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU Affero General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU Affero General Public License 14 | // along with this program. If not, see . 15 | 16 | //! Helper functions for integration tests 17 | use base64::prelude::{Engine, BASE64_STANDARD}; 18 | use entropy_protocol::KeyParams; 19 | use entropy_testing_utils::constants::TSS_ACCOUNTS; 20 | use sp_core::{sr25519, sr25519::Signature, Pair}; 21 | use synedrion::{ 22 | k256::ecdsa::{RecoveryId, Signature as k256Signature, VerifyingKey}, 23 | KeyShare, 24 | }; 25 | 26 | /// Verfiy a signature in a response from `/user/sign_tx` 27 | pub async fn verify_signature( 28 | test_user_res: Vec>, 29 | message_should_succeed_hash: [u8; 32], 30 | keyshare_option: Option>, 31 | ) { 32 | let mut i = 0; 33 | for res in test_user_res { 34 | let mut res = res.unwrap(); 35 | 36 | assert_eq!(res.status(), 200); 37 | let chunk = res.chunk().await.unwrap().unwrap(); 38 | let signing_result: Result<(String, Signature), String> = 39 | serde_json::from_slice(&chunk).unwrap(); 40 | assert_eq!(signing_result.clone().unwrap().0.len(), 88); 41 | let mut decoded_sig = BASE64_STANDARD.decode(signing_result.clone().unwrap().0).unwrap(); 42 | let recovery_digit = decoded_sig.pop().unwrap(); 43 | let signature = k256Signature::from_slice(&decoded_sig).unwrap(); 44 | let recover_id = RecoveryId::from_byte(recovery_digit).unwrap(); 45 | let recovery_key_from_sig = VerifyingKey::recover_from_prehash( 46 | &message_should_succeed_hash, 47 | &signature, 48 | recover_id, 49 | ) 50 | .unwrap(); 51 | assert_eq!(keyshare_option.clone().unwrap().verifying_key(), recovery_key_from_sig); 52 | 53 | let sig_recovery = ::verify( 54 | &signing_result.clone().unwrap().1, 55 | BASE64_STANDARD.decode(signing_result.unwrap().0).unwrap(), 56 | &sr25519::Public::from(TSS_ACCOUNTS[i].0), 57 | ); 58 | assert!(sig_recovery); 59 | i += 1; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /data/README.md: -------------------------------------------------------------------------------- 1 | # Data 2 | 3 | This directory holds static data used during development, build, or run, or test time for Entropy. 4 | 5 | Subdirectories in this directory map to an environment in which the data is relevant. For example: 6 | 7 | * `./testnet/testnet-accounts.json` - Accounts endowed with a starting balance at the Entropy Network's testnet genesis block. 8 | -------------------------------------------------------------------------------- /data/testnet/testnet-accounts.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "address": "5FCAitPANbeRoujX9RryzDPre4HW6vTMpqJyusZFoDEN6wXG", 4 | "name": "Entropy" 5 | }, 6 | { 7 | "address": "5H94EYDDPQEfoY8bqKFBNNDqYQD1R5MSPJZKnbkYV6AHYoos", 8 | "name": "Entropy" 9 | }, 10 | { 11 | "address": "5HZ151yLivMZWzNSkn5TeSrCHXnmxTFRKW11yudkuLPGdNvr", 12 | "name": "Entropy" 13 | }, 14 | { 15 | "address": "5H3amtSuHo72G1XBP2eDy7XVP1u8BxGTjPRwqKWicAztLoQY", 16 | "name": "Entropy" 17 | }, 18 | { 19 | "address": "5CDCKtBALeqgVGqEK1cVm9S2ANTuhk7FAjRrx1fhj9gqAcC4", 20 | "name": "Entropy" 21 | }, 22 | { 23 | "address": "5CfTqWGGcuD317TBvYRPiWssMXrTzxRoDayBQgQqH3CpyCmp", 24 | "name": "Entropy" 25 | }, 26 | { 27 | "address": "5HQCNMVFmkfMjztdFthKoBtwshsQhkw2tzyF2snQWtK122w7", 28 | "name": "Entropy" 29 | }, 30 | { 31 | "address": "5EHDWvPuio2dTSfgdVokshwLsG9eNUGkynuqduHBVjAJYX82", 32 | "name": "Entropy" 33 | }, 34 | { 35 | "address": "5CrFp9txcb5UECpNKsD6DTBsG4cj1z58DA43YikSVeeJqXJR", 36 | "name": "Entropy" 37 | }, 38 | { 39 | "address": "5CqJyjALDFz4sKjQgK8NXBQGHCWAiV63xXn2Dye393Y6Vghz", 40 | "name": "Entropy" 41 | }, 42 | { 43 | "address": "5Dc72pFuRp5HBYFzDbnnttc9PHpbCQ4ubgR7EKDdTayA5Ln1", 44 | "name": "Johnny_Entropy" 45 | }, 46 | { 47 | "address": "5CtViLgvdHoLDvdsSsfEPxczsF6D7FtQ59h6B4Gey5EXE47t", 48 | "name": "Peg_Entropy" 49 | }, 50 | { 51 | "address": "5Dts39fos5FZzskckjtgbnDPnp9ijvKUDz4C2oS4GRWJiGzZ", 52 | "name": "Nayyir_Entropy" 53 | }, 54 | { 55 | "address": "5E4gyvQ5XtyoKJgSMkh4t3DJ9BgrP7JU8A1M8kXdNnjNeyH9", 56 | "name": "Vi_Entropy" 57 | }, 58 | { 59 | "address": "5GKEmNJeUpBzGTaXjsTDCXMPtpbhaHDSF9wezMSCZJfGPkez", 60 | "name": "Frankie_Entropy" 61 | }, 62 | { 63 | "address": "5FqDurx4mBKFvywkAWfZWtjziKTChoyUjZ4gRKY9hnWRuFZT", 64 | "name": "Bogdan_Entropy" 65 | }, 66 | { 67 | "address": "5FtB82HkqHxoqYZvep9WzYje76AXZQJp8fEYKWbA9Y8aUSiE", 68 | "name": "Juni_Entropy" 69 | } 70 | ] -------------------------------------------------------------------------------- /deny.toml: -------------------------------------------------------------------------------- 1 | [licenses] 2 | # The lint level for crates which do not have a detectable license 3 | version=2 4 | # List of explicitly allowed licenses 5 | # See https://spdx.org/licenses/ for list of possible licenses 6 | # [possible values: any SPDX 3.11 short identifier (+ optional exception)]. 7 | allow=[ 8 | "Apache-2.0 WITH LLVM-exception", 9 | "Apache-2.0", 10 | "BSD-2-Clause", 11 | "BSD-3-Clause", 12 | "CC0-1.0", 13 | "CDLA-Permissive-2.0", 14 | "GPL-3.0", 15 | "GPL-3.0 WITH Classpath-exception-2.0", # For Substrate crates 16 | "ISC", 17 | "MIT", 18 | "MIT-0", 19 | "MPL-2.0", 20 | "Unicode-3.0", 21 | "Zlib", 22 | ] 23 | 24 | # If true, ignores workspace crates that aren't published, or are only 25 | # published to private registries. 26 | # To see how to mark a crate as unpublished (to the official registry), 27 | # visit https://doc.rust-lang.org/cargo/reference/manifest.html#the-publish-field. 28 | private={ ignore=true } 29 | 30 | # Each entry is the crate and version constraint, and its specific allow list 31 | exceptions=[ 32 | # We allow crates that we publish from our own workspace here 33 | { allow=["AGPL-3.0"], name="entropy-kvdb" }, 34 | { allow=["AGPL-3.0"], name="entropy-protocol" }, 35 | { allow=["AGPL-3.0"], name="entropy-shared" }, 36 | { allow=["AGPL-3.0"], name="entropy-tss" }, 37 | { allow=["AGPL-3.0"], name="entropy-client" }, 38 | { allow=["AGPL-3.0"], name="entropy-testing-utils" }, 39 | { allow=["AGPL-3.0"], name="entropy-test-cli" }, 40 | 41 | # Other Entropy crates 42 | { allow=["AGPL-3.0"], name="entropy-programs-core" }, 43 | { allow=["AGPL-3.0"], name="entropy-programs-runtime" }, 44 | { allow=["AGPL-3.0"], name="synedrion" }, 45 | { allow=["AGPL-3.0"], name="manul" }, 46 | { allow=["AGPL-3.0"], name="tdx-quote" }, 47 | { allow=["AGPL-3.0"], name="configfs-tsm" }, 48 | 49 | # These are the only crates using these licenses, put them here instead of globally allowing 50 | # them 51 | { allow=["Zlib"], name="const_format" }, 52 | { allow=["Zlib"], name="const_format_proc_macros" }, 53 | ] 54 | 55 | # Some crates don't have (easily) machine readable licensing information, 56 | # adding a clarification entry for it allows you to manually specify the 57 | # licensing information 58 | [[licenses.clarify]] 59 | # The name of the crate the clarification applies to 60 | name="ring" 61 | 62 | # The SPDX expression for the license requirements of the crate 63 | expression="MIT AND ISC AND OpenSSL" 64 | 65 | # One or more files in the crate's source used as the "source of truth" for 66 | # the license expression. If the contents match, the clarification will be used 67 | # when running the license check, otherwise the clarification will be ignored 68 | # and the crate will be checked normally, which may produce warnings or errors 69 | # depending on the rest of your configuration 70 | license-files=[ 71 | # Each entry is a crate relative path, and the (opaque) hash of its contents 72 | { path="LICENSE", hash=0xbd0eed23 }, 73 | ] 74 | -------------------------------------------------------------------------------- /docker-compose-common.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | name: entropy 3 | 4 | secrets: &common-secrets 5 | credentials: 6 | file: ${XDG_DATA_HOME:-~/.local/share}/entropy-cryptography/.entropy.auth.sh 7 | 8 | x-common-build-auth: &common-build-auth 9 | ssh: 10 | - default 11 | secrets: 12 | - credentials 13 | 14 | services: 15 | # Threshold Signature Scheme server 16 | tss-server: 17 | image: entropyxyz/entropy-tss 18 | build: 19 | <<: *common-build-auth 20 | args: 21 | PACKAGE: entropy-tss 22 | tags: 23 | - entropyxyz/entropy-tss 24 | 25 | # Sometimes also called simply a "chain," or a "validator." 26 | chain-node: 27 | image: entropyxyz/entropy 28 | build: 29 | <<: *common-build-auth 30 | args: 31 | PACKAGE: entropy 32 | tags: 33 | - entropyxyz/entropy 34 | -------------------------------------------------------------------------------- /node/cli/build.rs: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2023 Entropy Cryptography Inc. 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU Affero General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU Affero General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU Affero General Public License 14 | // along with this program. If not, see . 15 | 16 | use substrate_build_script_utils::{generate_cargo_keys, rerun_if_git_head_changed}; 17 | 18 | fn main() { 19 | generate_cargo_keys(); 20 | 21 | rerun_if_git_head_changed(); 22 | } 23 | -------------------------------------------------------------------------------- /node/cli/src/endowed_accounts.rs: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2023 Entropy Cryptography Inc. 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU Affero General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU Affero General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU Affero General Public License 14 | // along with this program. If not, see . 15 | 16 | //! Pre-endowed accounts used for the development network 17 | use crate::chain_spec::get_account_id_from_seed; 18 | use entropy_runtime::AccountId; 19 | use serde::{Deserialize, Serialize}; 20 | use sp_core::sr25519; 21 | 22 | #[derive(Debug, Clone, Serialize, Deserialize)] 23 | pub struct AddressStruct { 24 | address: String, 25 | name: String, 26 | } 27 | 28 | /// Development accounts which correspond to our usual cast of characters (e.g `//Alice`, `//Bob`). 29 | pub fn endowed_accounts_dev() -> Vec { 30 | vec![ 31 | get_account_id_from_seed::("Alice"), 32 | get_account_id_from_seed::("Bob"), 33 | get_account_id_from_seed::("Charlie"), 34 | get_account_id_from_seed::("Dave"), 35 | get_account_id_from_seed::("Eve"), 36 | get_account_id_from_seed::("Ferdie"), 37 | get_account_id_from_seed::("One"), 38 | get_account_id_from_seed::("Two"), 39 | get_account_id_from_seed::("Alice//stash"), 40 | get_account_id_from_seed::("Bob//stash"), 41 | get_account_id_from_seed::("Charlie//stash"), 42 | get_account_id_from_seed::("Dave//stash"), 43 | get_account_id_from_seed::("Eve//stash"), 44 | get_account_id_from_seed::("Ferdie//stash"), 45 | get_account_id_from_seed::("One//stash"), 46 | get_account_id_from_seed::("Two//stash"), 47 | crate::chain_spec::tss_account_id::ALICE.clone(), 48 | crate::chain_spec::tss_account_id::BOB.clone(), 49 | crate::chain_spec::tss_account_id::CHARLIE.clone(), 50 | crate::chain_spec::tss_account_id::DAVE.clone(), 51 | ] 52 | } 53 | -------------------------------------------------------------------------------- /node/cli/src/main.rs: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2023 Entropy Cryptography Inc. 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU Affero General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU Affero General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU Affero General Public License 14 | // along with this program. If not, see . 15 | 16 | // Copyright (C) Parity Technologies (UK) Ltd. 17 | // SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 18 | 19 | // This program is free software: you can redistribute it and/or modify 20 | // it under the terms of the GNU General Public License as published by 21 | // the Free Software Foundation, either version 3 of the License, or 22 | // (at your option) any later version. 23 | 24 | // This program is distributed in the hope that it will be useful, 25 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 26 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 27 | // GNU General Public License for more details. 28 | 29 | // You should have received a copy of the GNU General Public License 30 | // along with this program. If not, see . 31 | 32 | //! Entropy Node CLI library. 33 | #![doc(html_logo_url = "https://entropy.xyz/assets/logo_02.png")] 34 | #![warn(missing_docs)] 35 | 36 | mod chain_spec; 37 | #[macro_use] 38 | mod service; 39 | mod benchmarking; 40 | mod cli; 41 | mod command; 42 | mod endowed_accounts; 43 | mod rpc; 44 | 45 | fn main() -> sc_cli::Result<()> { 46 | command::run() 47 | } 48 | -------------------------------------------------------------------------------- /pallets/attestation/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name ="pallet-attestation" 3 | version ="0.4.0-rc.1" 4 | authors =['Entropy Cryptography '] 5 | homepage ='https://entropy.xyz/' 6 | license ='AGPL-3.0-or-later' 7 | repository='https://github.com/entropyxyz/entropy-core' 8 | edition ='2021' 9 | publish =false 10 | 11 | [dependencies] 12 | codec ={ package="parity-scale-codec", version="3.6.3", default-features=false, features=["derive"] } 13 | scale-info ={ version="2.11", default-features=false, features=["derive"] } 14 | log ={ version="0.4.27", default-features=false } 15 | frame-support ={ version="40.1.0", default-features=false } 16 | frame-system ={ version="40.1.0", default-features=false } 17 | sp-io ={ version="40.0.1", default-features=false } 18 | sp-core ={ version="36.1.0", default-features=false } 19 | sp-runtime ={ version="41.1.0", default-features=false } 20 | sp-staking ={ version="38.0.0", default-features=false } 21 | frame-benchmarking={ version="40.0.0", default-features=false, optional=true } 22 | sp-std ={ version="14.0.0", default-features=false } 23 | pallet-session ={ version="40.0.0", default-features=false, optional=true } 24 | rand_chacha ={ version="0.3", default-features=false } 25 | 26 | pallet-parameters={ version="0.4.0-rc.1", path="../parameters", default-features=false } 27 | entropy-shared={ version="0.4.0-rc.1", path="../../crates/shared", features=[ 28 | "wasm-no-std", 29 | ], default-features=false } 30 | pallet-staking-extension={ version="0.4.0-rc.1", path="../staking", default-features=false } 31 | tdx-quote="0.0.3" 32 | 33 | [dev-dependencies] 34 | pallet-session ={ version="40.0.0", default-features=false } 35 | pallet-staking ={ version="40.1.0", default-features=false } 36 | pallet-balances ={ version="41.1.0", default-features=false } 37 | pallet-bags-list ={ version="39.1.0", default-features=false } 38 | pallet-timestamp ={ version="39.0.0", default-features=false } 39 | sp-npos-elections ={ version="36.1.0", default-features=false } 40 | frame-election-provider-support={ version="40.1.0", default-features=false } 41 | pallet-staking-reward-curve ={ version="12.0.0" } 42 | tdx-quote ={ version="0.0.3", features=["mock"] } 43 | rand_core ="0.6.4" 44 | 45 | pallet-slashing={ version="0.4.0-rc.1", path="../slashing", default-features=false } 46 | 47 | [features] 48 | default=['std'] 49 | runtime-benchmarks=['frame-benchmarking', 'tdx-quote/mock', 'pallet-session'] 50 | std=[ 51 | 'frame-benchmarking/std', 52 | 'frame-support/std', 53 | 'frame-system/std', 54 | 'log/std', 55 | 'pallet-staking-extension/std', 56 | 'pallet-balances/std', 57 | 'pallet-parameters/std', 58 | 'sp-io/std', 59 | "sp-runtime/std", 60 | "rand_chacha/std", 61 | ] 62 | try-runtime=['frame-support/try-runtime'] 63 | # When enabled, use real PCK certificate chain verification 64 | production=['entropy-shared/production'] 65 | -------------------------------------------------------------------------------- /pallets/attestation/src/benchmarking.rs: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2023 Entropy Cryptography Inc. 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU Affero General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU Affero General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU Affero General Public License 14 | // along with this program. If not, see . 15 | 16 | use frame_benchmarking::v2::*; 17 | 18 | use frame_system::{EventRecord, RawOrigin}; 19 | 20 | use super::*; 21 | #[allow(unused)] 22 | use crate::Pallet as AttestationPallet; 23 | 24 | fn assert_last_event(generic_event: ::RuntimeEvent) { 25 | let events = frame_system::Pallet::::events(); 26 | let system_event: ::RuntimeEvent = generic_event.into(); 27 | // compare to the last event record 28 | let EventRecord { event, .. } = &events[events.len() - 1]; 29 | assert_eq!(event, &system_event); 30 | } 31 | 32 | #[benchmarks] 33 | mod benchmarks { 34 | use super::*; 35 | 36 | #[benchmark] 37 | fn attest() { 38 | let attestee: T::AccountId = whitelisted_caller(); 39 | let quote = [0; 32].to_vec(); 40 | 41 | #[extrinsic_call] 42 | _(RawOrigin::Signed(attestee.clone()), quote.clone()); 43 | assert_last_event::(Event::::AttestationMade.into()); 44 | 45 | // Check that there is no longer a pending attestation 46 | assert!(!>::contains_key(attestee)); 47 | } 48 | 49 | #[benchmark] 50 | fn request_attestation() { 51 | let attestee: T::AccountId = whitelisted_caller(); 52 | 53 | #[extrinsic_call] 54 | _(RawOrigin::Signed(attestee.clone())); 55 | // We're expecting a pending attestation queued up 56 | assert!(>::contains_key(attestee)); 57 | } 58 | impl_benchmark_test_suite!(AttestationPallet, crate::mock::new_test_ext(), crate::mock::Test); 59 | } 60 | -------------------------------------------------------------------------------- /pallets/attestation/test_pck_certs/pck_cert.der: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/entropyxyz/entropy-core/22f3d43664e4acf87445e06cedcb6a7851f6b3a7/pallets/attestation/test_pck_certs/pck_cert.der -------------------------------------------------------------------------------- /pallets/attestation/test_pck_certs/platform_pcs_cert.der: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/entropyxyz/entropy-core/22f3d43664e4acf87445e06cedcb6a7851f6b3a7/pallets/attestation/test_pck_certs/platform_pcs_cert.der -------------------------------------------------------------------------------- /pallets/oracle/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name ="pallet-oracle" 3 | version ='0.4.0-rc.1' 4 | authors =['Entropy Cryptography '] 5 | homepage ='https://entropy.xyz/' 6 | license ='AGPL-3.0-or-later' 7 | repository='https://github.com/entropyxyz/entropy-core' 8 | edition ='2021' 9 | publish =false 10 | 11 | [dependencies] 12 | codec ={ package="parity-scale-codec", version="3.6.3", default-features=false, features=["derive"] } 13 | scale-info={ version="2.11", default-features=false, features=["derive"] } 14 | 15 | frame-benchmarking={ version="40.0.0", default-features=false, optional=true } 16 | frame-support ={ version="40.1.0", default-features=false } 17 | frame-system ={ version="40.1.0", default-features=false } 18 | sp-runtime ={ version="41.1.0", default-features=false } 19 | sp-std ={ version="14.0.0", default-features=false } 20 | 21 | [dev-dependencies] 22 | sp-core={ version="36.1.0" } 23 | sp-io ={ version="40.0.1" } 24 | 25 | [features] 26 | default=["std"] 27 | runtime-benchmarks=[ 28 | 'frame-benchmarking', 29 | 'frame-support/runtime-benchmarks', 30 | 'frame-system/runtime-benchmarks', 31 | ] 32 | std=[ 33 | "frame-support/std", 34 | "frame-system/std", 35 | "scale-info/std", 36 | "sp-runtime/std", 37 | "sp-std/std", 38 | 'frame-benchmarking/std', 39 | ] 40 | try-runtime=["frame-support/try-runtime"] 41 | -------------------------------------------------------------------------------- /pallets/oracle/src/benchmarking.rs: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2023 Entropy Cryptography Inc. 2 | 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU Affero General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | 8 | // This program is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU Affero General Public License for more details. 12 | 13 | // You should have received a copy of the GNU Affero General Public License 14 | // along with this program. If not, see . 15 | 16 | // //! Benchmarking setup for pallet-oracle 17 | 18 | use super::*; 19 | 20 | #[allow(unused)] 21 | use crate::Pallet as Oracle; 22 | use frame_benchmarking::v2::*; 23 | 24 | #[benchmarks] 25 | mod benchmarks { 26 | use super::*; 27 | 28 | #[benchmark] 29 | fn on_initialize() { 30 | #[block] 31 | { 32 | Oracle::::on_initialize(50u32.into()); 33 | } 34 | 35 | assert_eq!( 36 | OracleData::::get(BoundedVec::try_from("block_number_entropy".encode()).unwrap()) 37 | .unwrap()[0], 38 | 50 39 | ); 40 | } 41 | 42 | impl_benchmark_test_suite!(Oracle, crate::mock::new_test_ext(), crate::mock::Test); 43 | } 44 | -------------------------------------------------------------------------------- /pallets/oracle/src/mock.rs: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2023 Entropy Cryptography Inc. 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU Affero General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU Affero General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU Affero General Public License 14 | // along with this program. If not, see . 15 | 16 | //! Mocks for the parameters pallet. 17 | 18 | #![cfg(test)] 19 | 20 | use frame_support::{ 21 | construct_runtime, derive_impl, parameter_types, 22 | traits::{ConstU64, Everything}, 23 | }; 24 | use sp_core::H256; 25 | use sp_runtime::{traits::IdentityLookup, BuildStorage}; 26 | 27 | use super::*; 28 | 29 | pub type AccountId = u128; 30 | 31 | use crate as pallet_oracle; 32 | 33 | #[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)] 34 | impl frame_system::Config for Test { 35 | type AccountData = (); 36 | type AccountId = AccountId; 37 | type BaseCallFilter = Everything; 38 | type Block = Block; 39 | type BlockHashCount = ConstU64<250>; 40 | type BlockLength = (); 41 | type BlockWeights = (); 42 | type DbWeight = (); 43 | type Hash = H256; 44 | type Hashing = sp_runtime::traits::BlakeTwo256; 45 | type Lookup = IdentityLookup; 46 | type MaxConsumers = frame_support::traits::ConstU32<16>; 47 | type Nonce = u64; 48 | type OnKilledAccount = (); 49 | type OnNewAccount = (); 50 | type OnSetCode = (); 51 | type PalletInfo = PalletInfo; 52 | type RuntimeCall = RuntimeCall; 53 | type RuntimeEvent = RuntimeEvent; 54 | type RuntimeOrigin = RuntimeOrigin; 55 | type SS58Prefix = (); 56 | type SystemWeightInfo = (); 57 | type Version = (); 58 | } 59 | 60 | parameter_types! { 61 | pub const MaxOracleKeyLength: u32 = 100; 62 | pub const MaxOracleValueLength: u32 = 100; 63 | } 64 | 65 | impl Config for Test { 66 | type RuntimeEvent = RuntimeEvent; 67 | type MaxOracleKeyLength = MaxOracleKeyLength; 68 | type MaxOracleValueLength = MaxOracleValueLength; 69 | type WeightInfo = (); 70 | } 71 | 72 | type Block = frame_system::mocking::MockBlock; 73 | 74 | construct_runtime!( 75 | pub enum Test 76 | { 77 | System: frame_system, 78 | Oracle: pallet_oracle, 79 | } 80 | ); 81 | 82 | // Build genesis storage according to the mock runtime. 83 | pub fn new_test_ext() -> sp_io::TestExternalities { 84 | frame_system::GenesisConfig::::default().build_storage().unwrap().into() 85 | } 86 | -------------------------------------------------------------------------------- /pallets/oracle/src/tests.rs: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2023 Entropy Cryptography Inc. 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU Affero General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU Affero General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU Affero General Public License 14 | // along with this program. If not, see . 15 | 16 | //! Unit tests for the parameters pallet. 17 | 18 | #![cfg(test)] 19 | use frame_support::traits::OnInitialize; 20 | use mock::*; 21 | 22 | use super::*; 23 | 24 | #[test] 25 | fn test_set_block_number() { 26 | new_test_ext().execute_with(|| { 27 | assert_eq!( 28 | Oracle::oracle_data(BoundedVec::try_from("block_number_entropy".encode()).unwrap()), 29 | None 30 | ); 31 | 32 | >::on_initialize(50); 33 | 34 | assert_eq!( 35 | Oracle::oracle_data(BoundedVec::try_from("block_number_entropy".encode()).unwrap()) 36 | .unwrap()[0], 37 | 50 38 | ); 39 | }); 40 | } 41 | -------------------------------------------------------------------------------- /pallets/oracle/src/weights.rs: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2023 Entropy Cryptography Inc. 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU Affero General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU Affero General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU Affero General Public License 14 | // along with this program. If not, see . 15 | 16 | 17 | //! Autogenerated weights for pallet_oracle 18 | //! 19 | //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev 20 | //! DATE: 2023-11-02, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` 21 | //! WORST CASE MAP SIZE: `1000000` 22 | //! HOSTNAME: `hcastano`, CPU: `` 23 | //! EXECUTION: , WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024 24 | 25 | // Executed Command: 26 | // ./target/release/entropy 27 | // benchmark 28 | // pallet 29 | // --chain 30 | // dev 31 | // --wasm-execution=compiled 32 | // --pallet 33 | // pallet_oracle 34 | // --extrinsic 35 | // * 36 | // --steps 37 | // 5 38 | // --repeat 39 | // 2 40 | // --template 41 | // .maintain/frame-weight-template.hbs 42 | // --output 43 | // pallets/oracle/src/weights.rs 44 | 45 | #![cfg_attr(rustfmt, rustfmt_skip)] 46 | #![allow(unused_parens)] 47 | #![allow(unused_imports)] 48 | #![allow(missing_docs)] 49 | 50 | use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; 51 | use core::marker::PhantomData; 52 | 53 | /// Weight functions needed for pallet_oracle. 54 | pub trait WeightInfo { 55 | fn on_initialize() -> Weight; 56 | } 57 | 58 | /// Weights for pallet_oracle using the Substrate node and recommended hardware. 59 | pub struct SubstrateWeight(PhantomData); 60 | impl WeightInfo for SubstrateWeight { 61 | /// Storage: `Oracle::OracleData` (r:0 w:1) 62 | /// Proof: `Oracle::OracleData` (`max_values`: None, `max_size`: None, mode: `Measured`) 63 | fn on_initialize() -> Weight { 64 | // Proof Size summary in bytes: 65 | // Measured: `0` 66 | // Estimated: `0` 67 | // Minimum execution time: 1_000_000 picoseconds. 68 | Weight::from_parts(2_000_000, 0) 69 | .saturating_add(Weight::from_parts(0, 0)) 70 | .saturating_add(T::DbWeight::get().writes(1)) 71 | } 72 | 73 | } 74 | 75 | // For backwards compatibility and tests 76 | impl WeightInfo for () { 77 | /// Storage: `Oracle::OracleData` (r:0 w:1) 78 | /// Proof: `Oracle::OracleData` (`max_values`: None, `max_size`: None, mode: `Measured`) 79 | fn on_initialize() -> Weight { 80 | // Proof Size summary in bytes: 81 | // Measured: `0` 82 | // Estimated: `0` 83 | // Minimum execution time: 1_000_000 picoseconds. 84 | Weight::from_parts(2_000_000, 0) 85 | .saturating_add(Weight::from_parts(0, 0)) 86 | .saturating_add(RocksDbWeight::get().writes(1)) 87 | } 88 | 89 | } 90 | -------------------------------------------------------------------------------- /pallets/outtie/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name ="pallet-outtie" 3 | version ='0.4.0-rc.1' 4 | authors =['Entropy Cryptography '] 5 | homepage ='https://entropy.xyz/' 6 | license ='AGPL-3.0-or-later' 7 | repository='https://github.com/entropyxyz/entropy-core' 8 | edition ='2021' 9 | publish =false 10 | 11 | [dependencies] 12 | codec ={ package="parity-scale-codec", version="3.6.3", default-features=false, features=["derive"] } 13 | scale-info={ version="2.11", default-features=false, features=["derive"] } 14 | 15 | frame-benchmarking={ version="40.0.0", default-features=false, optional=true } 16 | frame-support ={ version="40.1.0", default-features=false } 17 | frame-system ={ version="40.1.0", default-features=false } 18 | sp-runtime ={ version="41.1.0", default-features=false } 19 | sp-std ={ version="14.0.0", default-features=false } 20 | pallet-session ={ version="40.0.0", default-features=false } 21 | serde ={ version="1.0.219", default-features=false } 22 | rand ={ version="0.8.5", default-features=false, optional=true } 23 | 24 | entropy-shared={ version="0.4.0-rc.1", path="../../crates/shared", features=[ 25 | "wasm-no-std", 26 | ], default-features=false } 27 | tdx-quote={ version="0.0.3", features=["mock"], optional=true } 28 | 29 | [dev-dependencies] 30 | sp-core ={ version="36.1.0" } 31 | sp-io ={ version="40.0.1" } 32 | sp-staking={ version="38.0.0", default-features=false } 33 | 34 | [features] 35 | default=["std"] 36 | runtime-benchmarks=[ 37 | 'frame-benchmarking', 38 | 'frame-support/runtime-benchmarks', 39 | 'frame-system/runtime-benchmarks', 40 | "tdx-quote", 41 | "rand", 42 | ] 43 | std=[ 44 | "frame-support/std", 45 | "frame-system/std", 46 | "pallet-session/std", 47 | "scale-info/std", 48 | "sp-runtime/std", 49 | "sp-std/std", 50 | 'frame-benchmarking/std', 51 | ] 52 | try-runtime=["frame-support/try-runtime"] 53 | -------------------------------------------------------------------------------- /pallets/outtie/src/tests.rs: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2023 Entropy Cryptography Inc. 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU Affero General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU Affero General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU Affero General Public License 14 | // along with this program. If not, see . 15 | 16 | //! Unit tests for the outtie pallet. 17 | 18 | #![cfg(test)] 19 | 20 | use super::*; 21 | use crate::JoiningOuttieServerInfo; 22 | use frame_support::{assert_noop, assert_ok}; 23 | use mock::*; 24 | 25 | const NULL_ARR: [u8; 32] = [0; 32]; 26 | 27 | #[test] 28 | fn add_box() { 29 | new_test_ext().execute_with(|| { 30 | let mut server_info = 31 | JoiningOuttieServerInfo { x25519_public_key: NULL_ARR, endpoint: vec![20] }; 32 | 33 | assert_ok!(Outtie::add_box( 34 | RuntimeOrigin::signed(1), 35 | server_info.clone(), 36 | VALID_QUOTE.to_vec() 37 | )); 38 | 39 | assert_noop!( 40 | Outtie::add_box(RuntimeOrigin::signed(1), server_info.clone(), VALID_QUOTE.to_vec()), 41 | Error::::BoxAccountAlreadyExists 42 | ); 43 | 44 | assert_noop!( 45 | Outtie::add_box(RuntimeOrigin::signed(2), server_info.clone(), INVALID_QUOTE.to_vec()), 46 | Error::::BadQuote 47 | ); 48 | 49 | server_info.endpoint = [20; (crate::tests::MaxEndpointLength::get() + 1) as usize].to_vec(); 50 | assert_noop!( 51 | Outtie::add_box(RuntimeOrigin::signed(3), server_info, VALID_QUOTE.to_vec()), 52 | Error::::EndpointTooLong 53 | ); 54 | }); 55 | } 56 | -------------------------------------------------------------------------------- /pallets/outtie/src/weights.rs: -------------------------------------------------------------------------------- 1 | #![cfg_attr(rustfmt, rustfmt_skip)] 2 | #![allow(unused_parens)] 3 | #![allow(unused_imports)] 4 | #![allow(missing_docs)] 5 | 6 | use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; 7 | use core::marker::PhantomData; 8 | 9 | /// Weight functions needed for pallet_oracle. 10 | pub trait WeightInfo { 11 | fn add_box() -> Weight; 12 | } 13 | 14 | /// Weights for pallet_oracle using the Substrate node and recommended hardware. 15 | pub struct SubstrateWeight(PhantomData); 16 | impl WeightInfo for SubstrateWeight { 17 | /// Storage: `Outtie::ApiBoxes` (r:1 w:1) 18 | /// Proof: `Outtie::ApiBoxes` (`max_values`: None, `max_size`: None, mode: `Measured`) 19 | fn add_box() -> Weight { 20 | // Proof Size summary in bytes: 21 | // Measured: `76` 22 | // Estimated: `3541` 23 | // Minimum execution time: 9_000_000 picoseconds. 24 | Weight::from_parts(9_000_000, 0) 25 | .saturating_add(Weight::from_parts(0, 3541)) 26 | .saturating_add(T::DbWeight::get().reads(1)) 27 | .saturating_add(T::DbWeight::get().writes(1)) 28 | } 29 | } 30 | 31 | // For backwards compatibility and tests 32 | impl WeightInfo for () { 33 | /// Storage: `Outtie::ApiBoxes` (r:1 w:1) 34 | /// Proof: `Outtie::ApiBoxes` (`max_values`: None, `max_size`: None, mode: `Measured`) 35 | fn add_box() -> Weight { 36 | // Proof Size summary in bytes: 37 | // Measured: `76` 38 | // Estimated: `3541` 39 | // Minimum execution time: 9_000_000 picoseconds. 40 | Weight::from_parts(9_000_000, 0) 41 | .saturating_add(Weight::from_parts(0, 3541)) 42 | .saturating_add(RocksDbWeight::get().reads(1)) 43 | .saturating_add(RocksDbWeight::get().writes(1)) 44 | } 45 | } -------------------------------------------------------------------------------- /pallets/parameters/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name ="pallet-parameters" 3 | version ='0.4.0-rc.1' 4 | authors =['Entropy Cryptography '] 5 | homepage ='https://entropy.xyz/' 6 | license ='AGPL-3.0-or-later' 7 | repository='https://github.com/entropyxyz/entropy-core' 8 | edition ='2021' 9 | publish =false 10 | 11 | [dependencies] 12 | codec ={ package="parity-scale-codec", version="3.6.3", default-features=false, features=["derive"] } 13 | scale-info={ version="2.11", default-features=false, features=["derive"] } 14 | 15 | frame-benchmarking={ version="40.0.0", default-features=false, optional=true } 16 | frame-support ={ version="40.1.0", default-features=false } 17 | frame-system ={ version="40.1.0", default-features=false } 18 | sp-runtime ={ version="41.1.0", default-features=false } 19 | sp-std ={ version="14.0.0", default-features=false } 20 | pallet-session ={ version="40.0.0", default-features=false } 21 | serde ={ version="1.0.219", default-features=false } 22 | 23 | entropy-shared={ version="0.4.0-rc.1", path="../../crates/shared", features=[ 24 | "wasm-no-std", 25 | ], default-features=false } 26 | 27 | [dev-dependencies] 28 | sp-core ={ version="36.1.0" } 29 | sp-io ={ version="40.0.1" } 30 | sp-staking={ version="38.0.0", default-features=false } 31 | 32 | [features] 33 | default=["std"] 34 | runtime-benchmarks=[ 35 | 'frame-benchmarking', 36 | 'frame-support/runtime-benchmarks', 37 | 'frame-system/runtime-benchmarks', 38 | ] 39 | std=[ 40 | "frame-support/std", 41 | "frame-system/std", 42 | "pallet-session/std", 43 | "scale-info/std", 44 | "sp-runtime/std", 45 | "sp-std/std", 46 | 'frame-benchmarking/std', 47 | ] 48 | try-runtime=["frame-support/try-runtime"] 49 | -------------------------------------------------------------------------------- /pallets/programs/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name ='pallet-programs' 3 | version ='0.4.0-rc.1' 4 | authors =['Entropy Cryptography '] 5 | homepage ='https://entropy.xyz/' 6 | license ='AGPL-3.0-or-later' 7 | repository='https://github.com/entropyxyz/entropy-core' 8 | edition ='2021' 9 | publish =false 10 | 11 | [package.metadata.docs.rs] 12 | targets=['x86_64-unknown-linux-gnu'] 13 | 14 | [dependencies] 15 | codec ={ package="parity-scale-codec", version="3.6.3", default-features=false, features=["derive"] } 16 | scale-info={ version="2.11", default-features=false, features=["derive"] } 17 | log ={ version="0.4.27", default-features=false } 18 | 19 | frame-benchmarking={ version="40.0.0", default-features=false, optional=true } 20 | frame-support ={ version="40.1.0", default-features=false } 21 | frame-system ={ version="40.1.0", default-features=false } 22 | sp-io ={ version="40.0.1", default-features=false } 23 | sp-runtime ={ version="41.1.0", default-features=false } 24 | sp-staking ={ version="38.0.0", default-features=false } 25 | sp-std ={ version="14.0.0", default-features=false } 26 | pallet-oracle ={ version='0.4.0-rc.1', path='../oracle', default-features=false } 27 | 28 | [dev-dependencies] 29 | pallet-balances={ version="41.1.0" } 30 | sp-core ={ version="36.1.0", default-features=false } 31 | 32 | [features] 33 | default=['std'] 34 | runtime-benchmarks=['frame-benchmarking'] 35 | std=[ 36 | "scale-info/std", 37 | "sp-io/std", 38 | "sp-runtime/std", 39 | 'codec/std', 40 | 'frame-benchmarking/std', 41 | 'frame-support/std', 42 | 'frame-system/std', 43 | 'log/std', 44 | 'pallet-oracle/std', 45 | ] 46 | try-runtime=['frame-support/try-runtime'] 47 | -------------------------------------------------------------------------------- /pallets/programs/README.md: -------------------------------------------------------------------------------- 1 | License: AGPL-3.0-or-later 2 | -------------------------------------------------------------------------------- /pallets/propagation/README.md: -------------------------------------------------------------------------------- 1 | License: AGPL-3.0-or-later 2 | -------------------------------------------------------------------------------- /pallets/propagation/src/benchmarking.rs: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2023 Entropy Cryptography Inc. 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU Affero General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU Affero General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU Affero General Public License 14 | // along with this program. If not, see . 15 | 16 | // //! Benchmarking setup for pallet-propgation 17 | 18 | use super::*; 19 | 20 | #[allow(unused)] 21 | use crate::Pallet as Propgation; 22 | use frame_benchmarking::benchmarks; 23 | use frame_support::traits::OnInitialize; 24 | use pallet_staking_extension::RefreshInfo; 25 | use scale_info::prelude::vec; 26 | 27 | benchmarks! { 28 | on_initialize { 29 | let block_number = 50u32; 30 | 31 | >::put(RefreshInfo { 32 | validators_info: vec![], 33 | proactive_refresh_keys: vec![vec![10]] 34 | }); 35 | }: { 36 | Propgation::::on_initialize(block_number.into()); 37 | } verify { 38 | assert_eq!(>::get().proactive_refresh_keys.len(), 0); 39 | } 40 | 41 | impl_benchmark_test_suite!(Propgation, crate::mock::new_test_ext(), crate::mock::Test); 42 | } 43 | -------------------------------------------------------------------------------- /pallets/registry/README.md: -------------------------------------------------------------------------------- 1 | License: AGPL-3.0-or-later 2 | -------------------------------------------------------------------------------- /pallets/slashing/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name ='pallet-slashing' 3 | version ='0.4.0-rc.1' 4 | authors =['Entropy Cryptography '] 5 | homepage ='https://entropy.xyz/' 6 | license ='AGPL-3.0-or-later' 7 | repository='https://github.com/entropyxyz/entropy-core' 8 | edition ='2021' 9 | publish =false 10 | 11 | [package.metadata.docs.rs] 12 | targets=['x86_64-unknown-linux-gnu'] 13 | 14 | [dependencies] 15 | codec ={ package="parity-scale-codec", version="3.6.3", default-features=false, features=["derive"] } 16 | scale-info={ version="2.11", default-features=false, features=["derive"] } 17 | log ={ version="0.4.27", default-features=false } 18 | 19 | frame-benchmarking ={ version="40.0.0", default-features=false, optional=true } 20 | frame-support ={ version="40.1.0", default-features=false } 21 | frame-system ={ version="40.1.0", default-features=false } 22 | sp-application-crypto={ version="40.1.0", default-features=false } 23 | sp-io ={ version="40.0.1", default-features=false } 24 | sp-runtime ={ version="41.1.0", default-features=false } 25 | sp-staking ={ version="38.0.0", default-features=false } 26 | sp-std ={ version="14.0.0", default-features=false } 27 | 28 | [dev-dependencies] 29 | frame-election-provider-support={ version="40.1.0", default-features=false } 30 | pallet-bags-list ={ version="39.1.0", default-features=false } 31 | pallet-balances ={ version="41.1.0", default-features=false } 32 | pallet-session ={ version="40.0.0", default-features=false } 33 | pallet-staking ={ version="40.1.0", default-features=false } 34 | pallet-staking-reward-curve ={ version="12.0.0", default-features=false } 35 | pallet-timestamp ={ version="39.0.0", default-features=false } 36 | sp-core ={ version="36.1.0", default-features=false } 37 | sp-npos-elections ={ version="36.1.0", default-features=false } 38 | 39 | [features] 40 | default=['std'] 41 | runtime-benchmarks=['frame-benchmarking'] 42 | std=[ 43 | "pallet-balances/std", 44 | "pallet-staking/std", 45 | "scale-info/std", 46 | "sp-application-crypto/std", 47 | "sp-io/std", 48 | "sp-npos-elections/std", 49 | "sp-runtime/std", 50 | "sp-std/std", 51 | 'codec/std', 52 | 'frame-benchmarking/std', 53 | 'frame-support/std', 54 | 'frame-system/std', 55 | 'log/std', 56 | ] 57 | try-runtime=['frame-support/try-runtime'] 58 | -------------------------------------------------------------------------------- /pallets/slashing/README.md: -------------------------------------------------------------------------------- 1 | License: AGPL-3.0-or-later 2 | -------------------------------------------------------------------------------- /pallets/slashing/src/benchmarking.rs: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2023 Entropy Cryptography Inc. 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU Affero General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU Affero General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU Affero General Public License 14 | // along with this program. If not, see . 15 | 16 | // //! Benchmarking setup for pallet-propgation 17 | 18 | // use super::*; 19 | 20 | // #[allow(unused)] 21 | // use crate::Pallet as Template; 22 | // use frame_benchmarking::{benchmarks, impl_benchmark_test_suite, whitelisted_caller}; 23 | // use frame_system::RawOrigin; 24 | 25 | // benchmarks! { 26 | 27 | // } 28 | 29 | // impl_benchmark_test_suite!(Template, crate::mock::new_test_ext(), crate::mock::Test); 30 | -------------------------------------------------------------------------------- /pallets/slashing/src/tests.rs: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2023 Entropy Cryptography Inc. 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU Affero General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU Affero General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU Affero General Public License 14 | // along with this program. If not, see . 15 | 16 | use frame_support::assert_ok; 17 | 18 | use super::*; 19 | use crate::mock::*; 20 | 21 | #[test] 22 | fn can_note_report() { 23 | new_test_ext().execute_with(|| { 24 | let (alice, mallory) = (1, 2); 25 | 26 | assert_eq!(Slashing::failed_registrations(mallory), 0); 27 | assert_ok!(Slashing::note_report(alice, mallory)); 28 | assert_eq!(Slashing::failed_registrations(mallory), 1); 29 | }) 30 | } 31 | 32 | #[test] 33 | fn offence_report_submitted_if_above_threshold() { 34 | new_test_ext().execute_with(|| { 35 | let (alice, mallory) = (1, 2); 36 | 37 | // A peer was reported, but not enough to for an offence to be filed 38 | let below_threshold = ::ReportThreshold::get() - 1; 39 | for _ in 0..below_threshold { 40 | assert_ok!(Slashing::note_report(alice, mallory)); 41 | } 42 | assert_eq!(Slashing::failed_registrations(mallory), below_threshold); 43 | 44 | // New session, the reports should be reset for our peer, and no offences should've been 45 | // filed 46 | Session::rotate_session(); 47 | assert_eq!(Slashing::failed_registrations(mallory), 0); 48 | assert!(Offences::get().len() == 0); 49 | 50 | // Now our peer has been reported enough times to get an Offence filed 51 | let above_threshold = ::ReportThreshold::get(); 52 | for _ in 0..above_threshold { 53 | assert_ok!(Slashing::note_report(alice, mallory)); 54 | } 55 | 56 | // New session, reports should have been reset and we should see the offence report for 57 | // Mallory 58 | Session::rotate_session(); 59 | assert_eq!(Slashing::failed_registrations(mallory), 0); 60 | 61 | let offences = Offences::get(); 62 | assert!(offences.len() == 1); 63 | 64 | let offenders = &offences[0].offenders; 65 | assert!(offenders[0] == (mallory, mallory)); 66 | }) 67 | } 68 | -------------------------------------------------------------------------------- /pallets/staking/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name ='pallet-staking-extension' 3 | version ='0.4.0-rc.1' 4 | authors =['Entropy Cryptography '] 5 | homepage ='https://entropy.xyz/' 6 | license ='AGPL-3.0-or-later' 7 | repository='https://github.com/entropyxyz/entropy-core' 8 | edition ='2021' 9 | publish =false 10 | 11 | [package.metadata.docs.rs] 12 | targets=['x86_64-unknown-linux-gnu'] 13 | 14 | [dependencies] 15 | codec ={ package="parity-scale-codec", version="3.6.3", default-features=false, features=["derive"] } 16 | scale-info ={ version="2.11", default-features=false, features=["derive"] } 17 | log ={ version="0.4.27", default-features=false } 18 | serde ={ version="1.0.219", default-features=false } 19 | rand_chacha={ version="0.3", default-features=false } 20 | 21 | frame-benchmarking={ version="40.0.0", default-features=false, optional=true } 22 | frame-support ={ version="40.1.0", default-features=false } 23 | frame-system ={ version="40.1.0", default-features=false } 24 | pallet-session ={ version="40.0.0", default-features=false } 25 | pallet-staking ={ version="40.1.0", default-features=false } 26 | sp-core ={ version="36.1.0", default-features=false } 27 | sp-runtime ={ version="41.1.0", default-features=false } 28 | sp-staking ={ version="38.0.0", default-features=false } 29 | sp-std ={ version="14.0.0", default-features=false } 30 | sp-consensus-babe ={ version="0.42.1", default-features=false } 31 | rand ={ version="0.8.5", default-features=false, features=["alloc"] } 32 | 33 | pallet-parameters={ version="0.4.0-rc.1", path="../parameters", default-features=false } 34 | pallet-slashing={ version="0.4.0-rc.1", path="../slashing", default-features=false } 35 | entropy-shared={ version="0.4.0-rc.1", path="../../crates/shared", features=[ 36 | "wasm-no-std", 37 | ], default-features=false } 38 | tdx-quote={ version="0.0.3", features=["mock"], optional=true } 39 | 40 | [dev-dependencies] 41 | frame-election-provider-support={ version="40.1.0", default-features=false } 42 | pallet-bags-list ={ version="39.1.0", default-features=false } 43 | pallet-balances ={ version="41.1.0", default-features=false } 44 | pallet-staking-reward-curve ={ version="12.0.0" } 45 | pallet-timestamp ={ version="39.0.0", default-features=false } 46 | sp-io ={ version="40.0.1", default-features=false } 47 | sp-npos-elections ={ version="36.1.0", default-features=false } 48 | 49 | rand_core="0.6.4" 50 | 51 | [features] 52 | default=['std'] 53 | runtime-benchmarks=['frame-benchmarking', "tdx-quote"] 54 | std=[ 55 | "sp-npos-elections/std", 56 | "sp-staking/std", 57 | "sp-std/std", 58 | 'codec/std', 59 | 'frame-benchmarking/std', 60 | 'frame-support/std', 61 | 'frame-system/std', 62 | 'log/std', 63 | 'pallet-balances/std', 64 | 'pallet-parameters/std', 65 | 'pallet-session/std', 66 | 'pallet-slashing/std', 67 | 'pallet-staking/std', 68 | 'scale-info/std', 69 | 'sp-consensus-babe/std', 70 | 'sp-runtime/std', 71 | "rand_chacha/std", 72 | ] 73 | try-runtime=['frame-support/try-runtime'] 74 | -------------------------------------------------------------------------------- /pallets/staking/README.md: -------------------------------------------------------------------------------- 1 | License: AGPL-3.0-or-later 2 | -------------------------------------------------------------------------------- /pallets/transaction-pause/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name ="pallet-transaction-pause" 3 | version ='0.4.0-rc.1' 4 | authors =['Entropy Cryptography '] 5 | homepage ='https://entropy.xyz/' 6 | license ='AGPL-3.0-or-later' 7 | repository='https://github.com/entropyxyz/entropy-core' 8 | edition ='2021' 9 | publish =false 10 | 11 | [dependencies] 12 | codec ={ package="parity-scale-codec", version="3.6.3", default-features=false, features=["derive"] } 13 | scale-info={ version="2.11", default-features=false, features=["derive"] } 14 | 15 | frame-benchmarking={ version="40.0.0", default-features=false, optional=true } 16 | frame-support ={ version="40.1.0", default-features=false } 17 | frame-system ={ version="40.1.0", default-features=false } 18 | sp-runtime ={ version="41.1.0", default-features=false } 19 | sp-std ={ version="14.0.0", default-features=false } 20 | 21 | [dev-dependencies] 22 | smallvec="1.15.1" 23 | 24 | pallet-balances={ version="41.1.0" } 25 | pallet-oracle ={ version='0.4.0-rc.1', path='../oracle', default-features=false } 26 | sp-core ={ version="36.1.0" } 27 | sp-io ={ version="40.0.1" } 28 | 29 | pallet-programs={ version="0.4.0-rc.1", default-features=false, path="../programs" } 30 | 31 | [features] 32 | default=["std"] 33 | runtime-benchmarks=[ 34 | 'frame-benchmarking', 35 | 'frame-support/runtime-benchmarks', 36 | 'frame-system/runtime-benchmarks', 37 | ] 38 | std=[ 39 | "frame-support/std", 40 | "frame-system/std", 41 | "pallet-programs/std", 42 | "scale-info/std", 43 | "sp-runtime/std", 44 | "sp-std/std", 45 | ] 46 | try-runtime=["frame-support/try-runtime"] 47 | -------------------------------------------------------------------------------- /pallets/transaction-pause/src/benchmarking.rs: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2023 Entropy Cryptography Inc. 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU Affero General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU Affero General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU Affero General Public License 14 | // along with this program. If not, see . 15 | 16 | use frame_benchmarking::v2::*; 17 | use frame_system::EventRecord; 18 | 19 | use super::*; 20 | #[allow(unused)] 21 | use crate::Pallet as TransactionPause; 22 | 23 | fn assert_last_event(generic_event: ::RuntimeEvent) { 24 | let events = frame_system::Pallet::::events(); 25 | let system_event: ::RuntimeEvent = generic_event.into(); 26 | // compare to the last event record 27 | let EventRecord { event, .. } = &events[events.len() - 1]; 28 | assert_eq!(event, &system_event); 29 | } 30 | 31 | #[benchmarks] 32 | mod benchmarks { 33 | use super::*; 34 | 35 | #[benchmark] 36 | fn pause_transaction() { 37 | let origin = T::UpdateOrigin::try_successful_origin().unwrap(); 38 | 39 | #[extrinsic_call] 40 | _(origin as T::RuntimeOrigin, b"Balances".to_vec(), b"transfer".to_vec()); 41 | 42 | assert_last_event::( 43 | Event::TransactionPaused { 44 | pallet_name_bytes: b"Balances".to_vec(), 45 | function_name_bytes: b"transfer".to_vec(), 46 | } 47 | .into(), 48 | ); 49 | } 50 | 51 | #[benchmark] 52 | fn unpause_transaction() { 53 | let origin = T::UpdateOrigin::try_successful_origin().unwrap(); 54 | >::pause_transaction( 55 | origin.clone(), 56 | b"Balances".to_vec(), 57 | b"transfer".to_vec(), 58 | ) 59 | .unwrap(); 60 | 61 | #[extrinsic_call] 62 | _(origin as T::RuntimeOrigin, b"Balances".to_vec(), b"transfer".to_vec()); 63 | 64 | assert_last_event::( 65 | Event::TransactionUnpaused { 66 | pallet_name_bytes: b"Balances".to_vec(), 67 | function_name_bytes: b"transfer".to_vec(), 68 | } 69 | .into(), 70 | ); 71 | } 72 | 73 | impl_benchmark_test_suite!( 74 | TransactionPause, 75 | crate::mock::ExtBuilder::default().build(), 76 | crate::mock::Runtime 77 | ); 78 | } 79 | -------------------------------------------------------------------------------- /runtime/build.rs: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2023 Entropy Cryptography Inc. 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU Affero General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU Affero General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU Affero General Public License 14 | // along with this program. If not, see . 15 | 16 | fn main() { 17 | #[cfg(feature = "std")] 18 | { 19 | substrate_wasm_builder::WasmBuilder::new() 20 | .with_current_project() 21 | .export_heap_base() 22 | .import_memory() 23 | .build(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /runtime/src/weights/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2023 Entropy Cryptography Inc. 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU Affero General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU Affero General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU Affero General Public License 14 | // along with this program. If not, see . 15 | 16 | // Copyright (C) 2023 Entropy Cryptography Inc. 17 | // 18 | // This program is free software: you can redistribute it and/or modify 19 | // it under the terms of the GNU Affero General Public License as published by 20 | // the Free Software Foundation, either version 3 of the License, or 21 | // (at your option) any later version. 22 | // 23 | // This program is distributed in the hope that it will be useful, 24 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 25 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 26 | // GNU Affero General Public License for more details. 27 | // 28 | // You should have received a copy of the GNU Affero General Public License 29 | // along with this program. If not, see . 30 | 31 | pub mod frame_election_provider_support; 32 | pub mod frame_system; 33 | pub mod pallet_attestation; 34 | pub mod pallet_bags_list; 35 | pub mod pallet_balances; 36 | pub mod pallet_bounties; 37 | pub mod pallet_collective; 38 | pub mod pallet_democracy; 39 | pub mod pallet_election_provider_multi_phase; 40 | pub mod pallet_elections_phragmen; 41 | pub mod pallet_identity; 42 | pub mod pallet_im_online; 43 | pub mod pallet_indices; 44 | pub mod pallet_membership; 45 | pub mod pallet_multisig; 46 | pub mod pallet_nomination_pools; 47 | pub mod pallet_oracle; 48 | pub mod pallet_outtie; 49 | pub mod pallet_parameters; 50 | pub mod pallet_preimage; 51 | pub mod pallet_programs; 52 | pub mod pallet_propagation; 53 | pub mod pallet_proxy; 54 | pub mod pallet_recovery; 55 | pub mod pallet_registry; 56 | pub mod pallet_scheduler; 57 | pub mod pallet_session; 58 | pub mod pallet_staking; 59 | pub mod pallet_staking_extension; 60 | pub mod pallet_sudo; 61 | pub mod pallet_timestamp; 62 | pub mod pallet_tips; 63 | pub mod pallet_transaction_pause; 64 | pub mod pallet_transaction_payment; 65 | pub mod pallet_transaction_storage; 66 | pub mod pallet_treasury; 67 | pub mod pallet_utility; 68 | pub mod pallet_vesting; 69 | -------------------------------------------------------------------------------- /runtime/src/weights/pallet_attestation.rs: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2023 Entropy Cryptography Inc. 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU Affero General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU Affero General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU Affero General Public License 14 | // along with this program. If not, see . 15 | 16 | //! Autogenerated weights for `pallet_attestation` 17 | //! 18 | //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 43.0.0 19 | //! DATE: 2025-04-17, STEPS: `5`, REPEAT: `2`, LOW RANGE: `[]`, HIGH RANGE: `[]` 20 | //! WORST CASE MAP SIZE: `1000000` 21 | //! HOSTNAME: `Jesses-MacBook-Pro.local`, CPU: `` 22 | //! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: 1024 23 | 24 | // Executed Command: 25 | // ./target/release/entropy 26 | // benchmark 27 | // pallet 28 | // --chain 29 | // dev 30 | // --pallet=pallet_attestation 31 | // --extrinsic=* 32 | // --steps=5 33 | // --repeat=2 34 | // --header=.maintain/AGPL-3.0-header.txt 35 | // --output=./runtime/src/weights/ 36 | 37 | #![cfg_attr(rustfmt, rustfmt_skip)] 38 | #![allow(unused_parens)] 39 | #![allow(unused_imports)] 40 | #![allow(missing_docs)] 41 | 42 | use frame_support::{traits::Get, weights::Weight}; 43 | use core::marker::PhantomData; 44 | 45 | /// Weight functions for `pallet_attestation`. 46 | pub struct WeightInfo(PhantomData); 47 | impl pallet_attestation::WeightInfo for WeightInfo { 48 | fn attest() -> Weight { 49 | // Proof Size summary in bytes: 50 | // Measured: `0` 51 | // Estimated: `0` 52 | // Minimum execution time: 5_000_000 picoseconds. 53 | Weight::from_parts(6_000_000, 0) 54 | .saturating_add(Weight::from_parts(0, 0)) 55 | } 56 | /// Storage: `Attestation::PendingAttestations` (r:1 w:1) 57 | /// Proof: `Attestation::PendingAttestations` (`max_values`: None, `max_size`: None, mode: `Measured`) 58 | /// Storage: `Babe::NextRandomness` (r:1 w:0) 59 | /// Proof: `Babe::NextRandomness` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`) 60 | /// Storage: `Babe::EpochStart` (r:1 w:0) 61 | /// Proof: `Babe::EpochStart` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`) 62 | fn request_attestation() -> Weight { 63 | // Proof Size summary in bytes: 64 | // Measured: `385` 65 | // Estimated: `3850` 66 | // Minimum execution time: 16_000_000 picoseconds. 67 | Weight::from_parts(18_000_000, 0) 68 | .saturating_add(Weight::from_parts(0, 3850)) 69 | .saturating_add(T::DbWeight::get().reads(3)) 70 | .saturating_add(T::DbWeight::get().writes(1)) 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /runtime/src/weights/pallet_babe.rs: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2023 Entropy Cryptography Inc. 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU Affero General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU Affero General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU Affero General Public License 14 | // along with this program. If not, see . 15 | 16 | //! Autogenerated weights for `pallet_babe` 17 | //! 18 | //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 33.0.0 19 | //! DATE: 2024-10-03, STEPS: `25`, REPEAT: `10`, LOW RANGE: `[]`, HIGH RANGE: `[]` 20 | //! WORST CASE MAP SIZE: `1000000` 21 | //! HOSTNAME: `ip-172-31-28-93`, CPU: `Intel(R) Xeon(R) Platinum 8375C CPU @ 2.90GHz` 22 | //! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: 1024 23 | 24 | // Executed Command: 25 | // ./target/release/entropy 26 | // benchmark 27 | // pallet 28 | // --chain 29 | // dev 30 | // --wasm-execution=compiled 31 | // --pallet=pallet_babe 32 | // --extrinsic=* 33 | // --steps=25 34 | // --repeat=10 35 | // --header=.maintain/AGPL-3.0-header.txt 36 | // --template 37 | // .maintain/frame-weight-template.hbs 38 | // --output=./runtime/src/weights/ 39 | 40 | #![cfg_attr(rustfmt, rustfmt_skip)] 41 | #![allow(unused_parens)] 42 | #![allow(unused_imports)] 43 | #![allow(missing_docs)] 44 | 45 | use frame_support::{traits::Get, weights::Weight}; 46 | use core::marker::PhantomData; 47 | 48 | /// Weight functions for `pallet_babe`. 49 | pub struct WeightInfo(PhantomData); 50 | impl pallet_babe::WeightInfo for WeightInfo { 51 | /// The range of component `x` is `[0, 1]`. 52 | fn check_equivocation_proof(_x: u32, ) -> Weight { 53 | // Proof Size summary in bytes: 54 | // Measured: `0` 55 | // Estimated: `0` 56 | // Minimum execution time: 91_936_000 picoseconds. 57 | Weight::from_parts(92_786_241, 0) 58 | .saturating_add(Weight::from_parts(0, 0)) 59 | } 60 | } -------------------------------------------------------------------------------- /runtime/src/weights/pallet_grandpa.rs: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2023 Entropy Cryptography Inc. 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU Affero General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU Affero General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU Affero General Public License 14 | // along with this program. If not, see . 15 | 16 | //! Autogenerated weights for `pallet_grandpa` 17 | //! 18 | //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 33.0.0 19 | //! DATE: 2024-10-03, STEPS: `25`, REPEAT: `10`, LOW RANGE: `[]`, HIGH RANGE: `[]` 20 | //! WORST CASE MAP SIZE: `1000000` 21 | //! HOSTNAME: `ip-172-31-28-93`, CPU: `Intel(R) Xeon(R) Platinum 8375C CPU @ 2.90GHz` 22 | //! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: 1024 23 | 24 | // Executed Command: 25 | // ./target/release/entropy 26 | // benchmark 27 | // pallet 28 | // --chain 29 | // dev 30 | // --wasm-execution=compiled 31 | // --pallet=pallet_grandpa 32 | // --extrinsic=* 33 | // --steps=25 34 | // --repeat=10 35 | // --header=.maintain/AGPL-3.0-header.txt 36 | // --template 37 | // .maintain/frame-weight-template.hbs 38 | // --output=./runtime/src/weights/ 39 | 40 | #![cfg_attr(rustfmt, rustfmt_skip)] 41 | #![allow(unused_parens)] 42 | #![allow(unused_imports)] 43 | #![allow(missing_docs)] 44 | 45 | use frame_support::{traits::Get, weights::Weight}; 46 | use core::marker::PhantomData; 47 | 48 | /// Weight functions for `pallet_grandpa`. 49 | pub struct WeightInfo(PhantomData); 50 | impl pallet_grandpa::WeightInfo for WeightInfo { 51 | /// The range of component `x` is `[0, 1]`. 52 | fn check_equivocation_proof(x: u32, ) -> Weight { 53 | // Proof Size summary in bytes: 54 | // Measured: `0` 55 | // Estimated: `0` 56 | // Minimum execution time: 106_958_000 picoseconds. 57 | Weight::from_parts(107_904_133, 0) 58 | .saturating_add(Weight::from_parts(0, 0)) 59 | // Standard Error: 100_086 60 | .saturating_add(Weight::from_parts(16_366, 0).saturating_mul(x.into())) 61 | } 62 | /// Storage: `Grandpa::Stalled` (r:0 w:1) 63 | /// Proof: `Grandpa::Stalled` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`) 64 | fn note_stalled() -> Weight { 65 | // Proof Size summary in bytes: 66 | // Measured: `0` 67 | // Estimated: `0` 68 | // Minimum execution time: 4_083_000 picoseconds. 69 | Weight::from_parts(4_736_000, 0) 70 | .saturating_add(Weight::from_parts(0, 0)) 71 | .saturating_add(T::DbWeight::get().writes(1)) 72 | } 73 | } -------------------------------------------------------------------------------- /runtime/src/weights/pallet_oracle.rs: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2023 Entropy Cryptography Inc. 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU Affero General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU Affero General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU Affero General Public License 14 | // along with this program. If not, see . 15 | 16 | //! Autogenerated weights for `pallet_oracle` 17 | //! 18 | //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 43.0.0 19 | //! DATE: 2025-04-17, STEPS: `5`, REPEAT: `2`, LOW RANGE: `[]`, HIGH RANGE: `[]` 20 | //! WORST CASE MAP SIZE: `1000000` 21 | //! HOSTNAME: `Jesses-MacBook-Pro.local`, CPU: `` 22 | //! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: 1024 23 | 24 | // Executed Command: 25 | // ./target/release/entropy 26 | // benchmark 27 | // pallet 28 | // --chain 29 | // dev 30 | // --pallet=pallet_oracle 31 | // --extrinsic=* 32 | // --steps=5 33 | // --repeat=2 34 | // --header=.maintain/AGPL-3.0-header.txt 35 | // --output=./runtime/src/weights/ 36 | 37 | #![cfg_attr(rustfmt, rustfmt_skip)] 38 | #![allow(unused_parens)] 39 | #![allow(unused_imports)] 40 | #![allow(missing_docs)] 41 | 42 | use frame_support::{traits::Get, weights::Weight}; 43 | use core::marker::PhantomData; 44 | 45 | /// Weight functions for `pallet_oracle`. 46 | pub struct WeightInfo(PhantomData); 47 | impl pallet_oracle::WeightInfo for WeightInfo { 48 | /// Storage: `Oracle::OracleData` (r:0 w:1) 49 | /// Proof: `Oracle::OracleData` (`max_values`: None, `max_size`: None, mode: `Measured`) 50 | fn on_initialize() -> Weight { 51 | // Proof Size summary in bytes: 52 | // Measured: `0` 53 | // Estimated: `0` 54 | // Minimum execution time: 2_000_000 picoseconds. 55 | Weight::from_parts(2_000_000, 0) 56 | .saturating_add(Weight::from_parts(0, 0)) 57 | .saturating_add(T::DbWeight::get().writes(1)) 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /runtime/src/weights/pallet_outtie.rs: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2023 Entropy Cryptography Inc. 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU Affero General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU Affero General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU Affero General Public License 14 | // along with this program. If not, see . 15 | 16 | //! Autogenerated weights for `pallet_outtie` 17 | //! 18 | //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 43.0.0 19 | //! DATE: 2025-05-05, STEPS: `5`, REPEAT: `2`, LOW RANGE: `[]`, HIGH RANGE: `[]` 20 | //! WORST CASE MAP SIZE: `1000000` 21 | //! HOSTNAME: `Jesses-MacBook-Pro.local`, CPU: `` 22 | //! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: 1024 23 | 24 | // Executed Command: 25 | // ./target/release/entropy 26 | // benchmark 27 | // pallet 28 | // --chain 29 | // dev 30 | // --pallet=pallet_outtie 31 | // --extrinsic=* 32 | // --steps=5 33 | // --repeat=2 34 | // --header=.maintain/AGPL-3.0-header.txt 35 | // --output=./runtime/src/weights/ 36 | 37 | #![cfg_attr(rustfmt, rustfmt_skip)] 38 | #![allow(unused_parens)] 39 | #![allow(unused_imports)] 40 | #![allow(missing_docs)] 41 | 42 | use frame_support::{traits::Get, weights::Weight}; 43 | use core::marker::PhantomData; 44 | 45 | /// Weight functions for `pallet_outtie`. 46 | pub struct WeightInfo(PhantomData); 47 | impl pallet_outtie::WeightInfo for WeightInfo { 48 | /// Storage: `Outtie::ApiBoxes` (r:1 w:1) 49 | /// Proof: `Outtie::ApiBoxes` (`max_values`: None, `max_size`: None, mode: `Measured`) 50 | fn add_box() -> Weight { 51 | // Proof Size summary in bytes: 52 | // Measured: `76` 53 | // Estimated: `3541` 54 | // Minimum execution time: 9_000_000 picoseconds. 55 | Weight::from_parts(9_000_000, 0) 56 | .saturating_add(Weight::from_parts(0, 3541)) 57 | .saturating_add(T::DbWeight::get().reads(1)) 58 | .saturating_add(T::DbWeight::get().writes(1)) 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /runtime/src/weights/pallet_propagation.rs: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2023 Entropy Cryptography Inc. 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU Affero General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU Affero General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU Affero General Public License 14 | // along with this program. If not, see . 15 | 16 | //! Autogenerated weights for `pallet_propagation` 17 | //! 18 | //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 33.0.0 19 | //! DATE: 2024-10-03, STEPS: `25`, REPEAT: `10`, LOW RANGE: `[]`, HIGH RANGE: `[]` 20 | //! WORST CASE MAP SIZE: `1000000` 21 | //! HOSTNAME: `ip-172-31-28-93`, CPU: `Intel(R) Xeon(R) Platinum 8375C CPU @ 2.90GHz` 22 | //! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: 1024 23 | 24 | // Executed Command: 25 | // ./target/release/entropy 26 | // benchmark 27 | // pallet 28 | // --chain 29 | // dev 30 | // --wasm-execution=compiled 31 | // --pallet=pallet_propagation 32 | // --extrinsic=* 33 | // --steps=25 34 | // --repeat=10 35 | // --header=.maintain/AGPL-3.0-header.txt 36 | // --template 37 | // .maintain/frame-weight-template.hbs 38 | // --output=./runtime/src/weights/ 39 | 40 | #![cfg_attr(rustfmt, rustfmt_skip)] 41 | #![allow(unused_parens)] 42 | #![allow(unused_imports)] 43 | #![allow(missing_docs)] 44 | 45 | use frame_support::{traits::Get, weights::Weight}; 46 | use core::marker::PhantomData; 47 | 48 | /// Weight functions for `pallet_propagation`. 49 | pub struct WeightInfo(PhantomData); 50 | impl pallet_propagation::WeightInfo for WeightInfo { 51 | /// Storage: `StakingExtension::ProactiveRefresh` (r:1 w:1) 52 | /// Proof: `StakingExtension::ProactiveRefresh` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) 53 | fn on_initialize() -> Weight { 54 | // Proof Size summary in bytes: 55 | // Measured: `148` 56 | // Estimated: `1633` 57 | // Minimum execution time: 4_156_000 picoseconds. 58 | Weight::from_parts(4_484_000, 0) 59 | .saturating_add(Weight::from_parts(0, 1633)) 60 | .saturating_add(T::DbWeight::get().reads(1)) 61 | .saturating_add(T::DbWeight::get().writes(1)) 62 | } 63 | } -------------------------------------------------------------------------------- /runtime/src/weights/pallet_timestamp.rs: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2023 Entropy Cryptography Inc. 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU Affero General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU Affero General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU Affero General Public License 14 | // along with this program. If not, see . 15 | 16 | //! Autogenerated weights for `pallet_timestamp` 17 | //! 18 | //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 33.0.0 19 | //! DATE: 2024-10-03, STEPS: `25`, REPEAT: `10`, LOW RANGE: `[]`, HIGH RANGE: `[]` 20 | //! WORST CASE MAP SIZE: `1000000` 21 | //! HOSTNAME: `ip-172-31-28-93`, CPU: `Intel(R) Xeon(R) Platinum 8375C CPU @ 2.90GHz` 22 | //! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: 1024 23 | 24 | // Executed Command: 25 | // ./target/release/entropy 26 | // benchmark 27 | // pallet 28 | // --chain 29 | // dev 30 | // --wasm-execution=compiled 31 | // --pallet=pallet_timestamp 32 | // --extrinsic=* 33 | // --steps=25 34 | // --repeat=10 35 | // --header=.maintain/AGPL-3.0-header.txt 36 | // --template 37 | // .maintain/frame-weight-template.hbs 38 | // --output=./runtime/src/weights/ 39 | 40 | #![cfg_attr(rustfmt, rustfmt_skip)] 41 | #![allow(unused_parens)] 42 | #![allow(unused_imports)] 43 | #![allow(missing_docs)] 44 | 45 | use frame_support::{traits::Get, weights::Weight}; 46 | use core::marker::PhantomData; 47 | 48 | /// Weight functions for `pallet_timestamp`. 49 | pub struct WeightInfo(PhantomData); 50 | impl pallet_timestamp::WeightInfo for WeightInfo { 51 | /// Storage: `Timestamp::Now` (r:1 w:1) 52 | /// Proof: `Timestamp::Now` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`) 53 | /// Storage: `Babe::CurrentSlot` (r:1 w:0) 54 | /// Proof: `Babe::CurrentSlot` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`) 55 | fn set() -> Weight { 56 | // Proof Size summary in bytes: 57 | // Measured: `245` 58 | // Estimated: `1493` 59 | // Minimum execution time: 10_827_000 picoseconds. 60 | Weight::from_parts(11_210_000, 0) 61 | .saturating_add(Weight::from_parts(0, 1493)) 62 | .saturating_add(T::DbWeight::get().reads(2)) 63 | .saturating_add(T::DbWeight::get().writes(1)) 64 | } 65 | fn on_finalize() -> Weight { 66 | // Proof Size summary in bytes: 67 | // Measured: `94` 68 | // Estimated: `0` 69 | // Minimum execution time: 4_708_000 picoseconds. 70 | Weight::from_parts(4_930_000, 0) 71 | .saturating_add(Weight::from_parts(0, 0)) 72 | } 73 | } -------------------------------------------------------------------------------- /runtime/src/weights/pallet_transaction_pause.rs: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2023 Entropy Cryptography Inc. 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU Affero General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU Affero General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU Affero General Public License 14 | // along with this program. If not, see . 15 | 16 | //! Autogenerated weights for `pallet_transaction_pause` 17 | //! 18 | //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 43.0.0 19 | //! DATE: 2025-04-24, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` 20 | //! WORST CASE MAP SIZE: `1000000` 21 | //! HOSTNAME: `Jesses-MacBook-Pro.local`, CPU: `` 22 | //! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: 1024 23 | 24 | // Executed Command: 25 | // ./target/release/entropy 26 | // benchmark 27 | // pallet 28 | // --chain 29 | // dev 30 | // --pallet=pallet_transaction_pause 31 | // --extrinsic=* 32 | // --steps=50 33 | // --repeat=20 34 | // --header=.maintain/AGPL-3.0-header.txt 35 | // --output=./runtime/src/weights/ 36 | 37 | #![cfg_attr(rustfmt, rustfmt_skip)] 38 | #![allow(unused_parens)] 39 | #![allow(unused_imports)] 40 | #![allow(missing_docs)] 41 | 42 | use frame_support::{traits::Get, weights::Weight}; 43 | use core::marker::PhantomData; 44 | 45 | /// Weight functions for `pallet_transaction_pause`. 46 | pub struct WeightInfo(PhantomData); 47 | impl pallet_transaction_pause::WeightInfo for WeightInfo { 48 | /// Storage: `TransactionPause::PausedTransactions` (r:1 w:1) 49 | /// Proof: `TransactionPause::PausedTransactions` (`max_values`: None, `max_size`: None, mode: `Measured`) 50 | fn pause_transaction() -> Weight { 51 | // Proof Size summary in bytes: 52 | // Measured: `109` 53 | // Estimated: `3574` 54 | // Minimum execution time: 8_000_000 picoseconds. 55 | Weight::from_parts(8_000_000, 0) 56 | .saturating_add(Weight::from_parts(0, 3574)) 57 | .saturating_add(T::DbWeight::get().reads(1)) 58 | .saturating_add(T::DbWeight::get().writes(1)) 59 | } 60 | /// Storage: `TransactionPause::PausedTransactions` (r:1 w:1) 61 | /// Proof: `TransactionPause::PausedTransactions` (`max_values`: None, `max_size`: None, mode: `Measured`) 62 | fn unpause_transaction() -> Weight { 63 | // Proof Size summary in bytes: 64 | // Measured: `160` 65 | // Estimated: `3625` 66 | // Minimum execution time: 9_000_000 picoseconds. 67 | Weight::from_parts(10_000_000, 0) 68 | .saturating_add(Weight::from_parts(0, 3625)) 69 | .saturating_add(T::DbWeight::get().reads(1)) 70 | .saturating_add(T::DbWeight::get().writes(1)) 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /runtime/src/weights/pallet_transaction_payment.rs: -------------------------------------------------------------------------------- 1 | // Copyright (C) Parity Technologies and the various Polkadot contributors, see Contributions.md 2 | // for a list of specific contributors. 3 | // SPDX-License-Identifier: Apache-2.0 4 | 5 | // Licensed under the Apache License, Version 2.0 (the "License"); 6 | // you may not use this file except in compliance with the License. 7 | // You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, software 12 | // distributed under the License is distributed on an "AS IS" BASIS, 13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | // See the License for the specific language governing permissions and 15 | // limitations under the License. 16 | 17 | //! Autogenerated weights for `pallet_transaction_payment` 18 | //! 19 | //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 46.1.0 20 | //! DATE: 2025-04-24, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` 21 | //! WORST CASE MAP SIZE: `1000000` 22 | //! HOSTNAME: `ggwpez-ref-hw`, CPU: `AMD EPYC 7232P 8-Core Processor` 23 | //! WASM-EXECUTION: `Compiled`, CHAIN: `Some("./kusama-chain-spec.json")`, DB CACHE: 1024 24 | 25 | // Executed Command: 26 | // ./target/production/polkadot 27 | // benchmark 28 | // pallet 29 | // --chain=./kusama-chain-spec.json 30 | // --steps=50 31 | // --repeat=20 32 | // --pallet=pallet_transaction_payment 33 | // --extrinsic=* 34 | // --wasm-execution=compiled 35 | // --heap-pages=4096 36 | // --output=./kusama-weights/ 37 | // --header=./file_header.txt 38 | 39 | #![cfg_attr(rustfmt, rustfmt_skip)] 40 | #![allow(unused_parens)] 41 | #![allow(unused_imports)] 42 | #![allow(missing_docs)] 43 | 44 | use frame_support::{traits::Get, weights::Weight}; 45 | use core::marker::PhantomData; 46 | 47 | /// Weight functions for `pallet_transaction_payment`. 48 | pub struct WeightInfo(PhantomData); 49 | impl pallet_transaction_payment::WeightInfo for WeightInfo { 50 | /// Storage: `System::Account` (r:1 w:1) 51 | /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) 52 | fn charge_transaction_payment() -> Weight { 53 | // Proof Size summary in bytes: 54 | // Measured: `101` 55 | // Estimated: `3593` 56 | // Minimum execution time: 64_220_000 picoseconds. 57 | Weight::from_parts(64_810_000, 0) 58 | .saturating_add(Weight::from_parts(0, 3593)) 59 | .saturating_add(T::DbWeight::get().reads(1)) 60 | .saturating_add(T::DbWeight::get().writes(1)) 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /rust-toolchain.toml: -------------------------------------------------------------------------------- 1 | [toolchain] 2 | channel="stable" 3 | targets=["wasm32-unknown-unknown"] 4 | -------------------------------------------------------------------------------- /scripts/add-license-headers.sh: -------------------------------------------------------------------------------- 1 | #/bin/bash 2 | set -eux 3 | 4 | script_parent_path=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P ) 5 | header_file_path="$script_parent_path/../.maintain/AGPL-3.0-header.txt" 6 | 7 | # We only want to run the subsitution on files which don't already have a Copyright header. 8 | # 9 | # When we do run the substitution then we first need to make sure that we add a new line after the 10 | # header, and then make sure that we print the header before the old "first line" of the file (with 11 | # `N`). 12 | # 13 | # NOTE: This sometimes removes the last line of a file and I'm not sure why. So double check before 14 | # committing any changes. 15 | rg --type rust "Copyright" --files-without-match | xargs sed -i '' -e "1r $header_file_path" -e "1s|^|\n|" -e "N" 16 | -------------------------------------------------------------------------------- /scripts/benchmarks.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -eux 4 | 5 | steps=50 6 | repeat=20 7 | entropyOutput=./runtime/src/weights/ 8 | entropyChain=dev 9 | entropyTemplate=.maintain/frame-weight-template.hbs 10 | licenseHeader=.maintain/AGPL-3.0-header.txt 11 | # Manually exclude some pallets. 12 | excluded_pallets=( 13 | # FIXME (#914): Changes to the ED have broken these benchmarks, we need to address that before 14 | # we can run them. 15 | pallet_nomination_pools 16 | ) 17 | 18 | # Load all pallet names in an array. 19 | all_pallets=($( 20 | cargo run -p entropy --release --features runtime-benchmarks -- benchmark pallet --list --chain=dev |\ 21 | tail -n+2 |\ 22 | cut -d',' -f1 |\ 23 | sort |\ 24 | uniq 25 | )) 26 | 27 | pallets=($({ printf '%s\n' "${all_pallets[@]}" "${excluded_pallets[@]}"; } | sort | uniq -u)) 28 | 29 | echo "[+] Benchmarking ${#pallets[@]} pallets by excluding ${#excluded_pallets[@]} from ${#all_pallets[@]}." 30 | 31 | for p in ${pallets[@]} 32 | do 33 | ./target/release/entropy benchmark pallet \ 34 | --chain $entropyChain \ 35 | --wasm-execution=compiled \ 36 | --pallet=$p \ 37 | --extrinsic='*' \ 38 | --steps=$steps \ 39 | --repeat=$repeat \ 40 | --header=$licenseHeader \ 41 | --template $entropyTemplate \ 42 | --output=$entropyOutput 43 | done 44 | -------------------------------------------------------------------------------- /scripts/build-devnet-chainspec.sh: -------------------------------------------------------------------------------- 1 | # This script is meant to be run once before launching the devnet to build the inital chain spec 2 | ./target/release/entropy build-spec --disable-default-bootnode --raw --chain=devnet > chains/devnet.json 3 | -------------------------------------------------------------------------------- /scripts/check-entropy-shared.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # This script checks that entropy-shared will compile with all the different combinations of feature 3 | # flags / targets which will be used. This is useful to check that changes to entropy-shared have 4 | # not broken anything without needing to run the entire CI pipeline. 5 | # 6 | # Used by entropy-tss 7 | cargo check -p entropy-shared 8 | # Used by entropy-tss in production 9 | cargo check -p entropy-shared -F production 10 | # Used by entropy-protocol 11 | cargo check -p entropy-shared -F std -F user-native --no-default-features 12 | # Used by entropy-protocol built for wasm 13 | cargo check -p entropy-shared -F user-wasm -F wasm --no-default-features --target wasm32-unknown-unknown 14 | # Used by pallets 15 | cargo check -p entropy-shared -F wasm-no-std --no-default-features --target wasm32-unknown-unknown 16 | # Used by pallets in production 17 | cargo check -p entropy-shared -F wasm-no-std -F production --no-default-features --target wasm32-unknown-unknown 18 | -------------------------------------------------------------------------------- /scripts/create-test-keyshares.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Creates a set of keyshares for use in entropy-tss tests 4 | 5 | cargo run -p entropy-create-test-keyshares -- ./crates/testing-utils/keyshares 6 | -------------------------------------------------------------------------------- /scripts/create-test-keyshares/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name ="entropy-create-test-keyshares" 3 | description="Makes a set of keyshares for testing entropy-tss" 4 | version ='0.4.0-rc.1' 5 | authors =['Entropy Cryptography '] 6 | homepage ='https://entropy.xyz/' 7 | license ='AGPL-3.0-or-later' 8 | repository ='https://github.com/entropyxyz/entropy-core' 9 | edition ='2021' 10 | publish =false 11 | 12 | [dependencies] 13 | entropy-testing-utils={ version="0.4.0-rc.1", path="../../crates/testing-utils" } 14 | tokio={ version="1.44", features=["macros", "fs", "rt-multi-thread", "io-util", "process"] } 15 | entropy-shared={ version="0.4.0-rc.1", path="../../crates/shared" } 16 | entropy-kvdb={ version="0.4.0-rc.1", path="../../crates/kvdb", default-features=false } 17 | sp-core="36.0.1" 18 | synedrion="0.3.0" 19 | entropy-tss={ version="0.4.0-rc.1", path="../../crates/threshold-signature-server", features=[ 20 | "test_helpers", 21 | ] } 22 | -------------------------------------------------------------------------------- /scripts/create-test-keyshares/README.md: -------------------------------------------------------------------------------- 1 | # `entropy-create-test-keyshares` 2 | 3 | This is used to create sets of pre-generated keyshares. These are used in some of the `entropy-tss` 4 | tests to speed up the test by not needing to run a distributed key generation during the test. 5 | 6 | There are different keyshare sets for 'test' or 'production' parameters used by Synedrion. Test 7 | parameters are less secure but mean that the protocols run much faster. 8 | -------------------------------------------------------------------------------- /scripts/create-test-keyshares/src/main.rs: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2023 Entropy Cryptography Inc. 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU Affero General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU Affero General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU Affero General Public License 14 | // along with this program. If not, see . 15 | 16 | //! Create threshold keyshares for use in tests 17 | //! The base path for where to store keyshares is given as a single command line argument 18 | //! If it is not given, the current working directory is used 19 | use entropy_kvdb::kv_manager::helpers::serialize; 20 | use entropy_shared::DETERMINISTIC_KEY_SHARE_NETWORK; 21 | use entropy_testing_utils::create_test_keyshares::create_test_keyshares; 22 | use entropy_tss::helpers::{ 23 | launch::{ 24 | ValidatorName, DEFAULT_ALICE_MNEMONIC, DEFAULT_BOB_MNEMONIC, DEFAULT_CHARLIE_MNEMONIC, 25 | }, 26 | validator::get_signer_and_x25519_secret_from_mnemonic, 27 | }; 28 | use sp_core::sr25519; 29 | use std::{env::args, iter::zip, path::PathBuf}; 30 | 31 | #[tokio::main] 32 | async fn main() { 33 | let base_path = PathBuf::from(args().nth(1).unwrap_or_else(|| ".".to_string())); 34 | 35 | let keypairs_and_names: Vec<_> = [ 36 | (DEFAULT_ALICE_MNEMONIC, ValidatorName::Alice), 37 | (DEFAULT_BOB_MNEMONIC, ValidatorName::Bob), 38 | (DEFAULT_CHARLIE_MNEMONIC, ValidatorName::Charlie), 39 | ] 40 | .into_iter() 41 | .map(|(mnemonic, name)| { 42 | let (pair, _) = get_signer_and_x25519_secret_from_mnemonic(mnemonic).unwrap(); 43 | (pair.signer().clone(), name) 44 | }) 45 | .collect(); 46 | 47 | let secret_key = *DETERMINISTIC_KEY_SHARE_NETWORK; 48 | 49 | let (keypairs, names): (Vec, Vec) = 50 | keypairs_and_names.iter().cloned().unzip(); 51 | 52 | let keypairs: [sr25519::Pair; 3] = 53 | keypairs.try_into().map_err(|_| "Cannot convert keypair vector to array").unwrap(); 54 | 55 | // Create and write production keyshares 56 | let production_keyshares = create_test_keyshares(secret_key, keypairs.clone()).await; 57 | let production_keyshres_serialized: Vec<_> = 58 | production_keyshares.iter().map(|k| serialize(k).unwrap()).collect(); 59 | let keyshares_and_names = zip(production_keyshres_serialized, names).collect(); 60 | write_keyshares(base_path.join("production"), keyshares_and_names).await; 61 | } 62 | 63 | async fn write_keyshares(base_path: PathBuf, keyshares_and_names: Vec<(Vec, ValidatorName)>) { 64 | for (keyshare, name) in keyshares_and_names { 65 | let mut filepath = base_path.clone(); 66 | let filename = format!("keyshare-held-by-{}.keyshare", name); 67 | filepath.push(filename); 68 | println!("Writing keyshare file: {:?}", filepath); 69 | std::fs::write(filepath, keyshare).unwrap(); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /scripts/fmt.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cargo fmt --all 3 | taplo fmt 4 | cargo clippy -- -D warnings 5 | -------------------------------------------------------------------------------- /scripts/generate-validator-node-keys.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # A script used to generate all the keys needed for validators. 4 | # 5 | # The derivation paths here (so the `//name` bit) should match that of the 6 | # `insert-validator-node-keys` script. 7 | # 8 | # **This should not be used anywhere sensitive, it prints out your new seed phrase!** 9 | 10 | set -eu 11 | 12 | secretPhrase=$(cargo run -p entropy -- key generate --output-type json | jq -r .secretPhrase) 13 | 14 | # Not safe, I know...but this is a development tool. 15 | echo -e "Secret Phrase: $secretPhrase\n" 16 | 17 | declare -A keyTypes=( 18 | ["controller"]="Sr25519" 19 | ["stash"]="Sr25519" 20 | ["babe"]="Sr25519" 21 | ["imon"]="Sr25519" 22 | ["audi"]="Sr25519" 23 | ["gran"]="Ed25519" 24 | ) 25 | 26 | for name in "${!keyTypes[@]}"; do 27 | scheme="${keyTypes[$name]}" 28 | ./target/debug/entropy key inspect "$secretPhrase//$name" --scheme $scheme 29 | echo 30 | done 31 | -------------------------------------------------------------------------------- /scripts/insert-validator-node-keys.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # A helper for inserting keys into a validator's keystore. 4 | # 5 | # This assumes that you're using our Docker images running on infrastructure provisioned by our 6 | # Terraform code. Otherwise the volume mounts won't work. 7 | # 8 | # The derivation paths here (so the `//name` bit) should match that of the 9 | # `generate-validator-node-keys.sh` script. 10 | # 11 | # Expected usage: ./insert-validator-node-keys.sh "secret seed ... phrase" 12 | 13 | set -eu 14 | 15 | secretPhrase=$1 16 | 17 | keyInsert="docker run -it --init -v /srv/entropy/:/srv/entropy/ \ 18 | entropyxyz/entropy key insert \ 19 | --base-path /srv/entropy \ 20 | --chain /srv/entropy/entropy-testnet.json" 21 | 22 | declare -A keyTypes=( 23 | ["babe"]="Sr25519" 24 | ["imon"]="Sr25519" 25 | ["audi"]="Sr25519" 26 | ["gran"]="Ed25519" 27 | ) 28 | 29 | for name in "${!keyTypes[@]}"; do 30 | scheme="${keyTypes[$name]}" 31 | $keyInsert \ 32 | --scheme $scheme \ 33 | --suri "$secretPhrase//$name" \ 34 | --key-type $name 35 | done 36 | -------------------------------------------------------------------------------- /scripts/pull_entropy_metadata.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | subxt metadata -f bytes > ./crates/client/entropy_metadata.scale 3 | -------------------------------------------------------------------------------- /scripts/single_benchmark.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | steps=5 4 | repeat=2 5 | entropyOutput=./runtime/src/weights/ 6 | entropyChain=dev 7 | pallets=( 8 | pallet_registry 9 | ) 10 | licenseHeader=.maintain/AGPL-3.0-header.txt 11 | 12 | for p in ${pallets[@]} 13 | do 14 | ./target/release/entropy benchmark pallet \ 15 | --chain $entropyChain \ 16 | --pallet=$p \ 17 | --extrinsic='*' \ 18 | --steps=$steps \ 19 | --repeat=$repeat \ 20 | --header=$licenseHeader \ 21 | --output=$entropyOutput 22 | 23 | done 24 | -------------------------------------------------------------------------------- /scripts/update-substrate.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # This script uses psvm to update substrate repos 4 | # It uses psvm repo https://github.com/paritytech/psvm 5 | 6 | # Takes first arugment as version i.e ./scripts/update-substrate.sh 1.7.0 7 | version=$1 8 | dir=( 9 | runtime 10 | node/cli 11 | pallets/* 12 | crates/* 13 | ) 14 | 15 | for d in ${dir[@]} 16 | do 17 | psvm -v $version -p "$d" 18 | 19 | done 20 | 21 | 22 | # Some packages that are not part of substrate need to be updated manually sometimes 23 | # Below is a list 24 | # /node/cli - jsonrpsee -------------------------------------------------------------------------------- /target/doc/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Entropy API documentation 7 | 42 | 43 | 44 |
45 |

46 | 47 | Entropy logo 48 | 49 |

50 |

Entropy API documentation

51 | 55 |
56 | 57 | 58 | --------------------------------------------------------------------------------