├── .editorconfig ├── .gitignore ├── Cargo.lock ├── Cargo.toml ├── Dockerfile ├── LICENSE ├── file_header.txt ├── frontier ├── .editorconfig ├── .github │ ├── CODEOWNERS │ ├── dependabot.yml │ └── workflows │ │ ├── cancel.yml │ │ ├── docs.yml │ │ ├── editorconfig.yml │ │ └── rust.yml ├── .gitignore ├── .maintain │ ├── frame-weight-template.hbs │ ├── node-template-release.sh │ ├── node-template-release │ │ ├── Cargo.lock │ │ ├── Cargo.toml │ │ └── src │ │ │ └── main.rs │ └── release-polkadot-branch.sh ├── Cargo.lock ├── Cargo.toml ├── HEADER-APACHE2 ├── LICENSE-APACHE2 ├── LICENSE-GPL3 ├── client │ ├── cli │ │ ├── Cargo.toml │ │ └── src │ │ │ ├── frontier_db_cmd │ │ │ ├── mapping_db.rs │ │ │ ├── meta_db.rs │ │ │ ├── mod.rs │ │ │ ├── tests.rs │ │ │ └── utils.rs │ │ │ └── lib.rs │ ├── consensus │ │ ├── Cargo.toml │ │ └── src │ │ │ └── lib.rs │ ├── db │ │ ├── Cargo.toml │ │ └── src │ │ │ ├── kv │ │ │ ├── mod.rs │ │ │ ├── parity_db_adapter.rs │ │ │ ├── upgrade.rs │ │ │ └── utils.rs │ │ │ ├── lib.rs │ │ │ └── sql │ │ │ └── mod.rs │ ├── mapping-sync │ │ ├── Cargo.toml │ │ └── src │ │ │ ├── kv │ │ │ ├── mod.rs │ │ │ └── worker.rs │ │ │ ├── lib.rs │ │ │ └── sql │ │ │ └── mod.rs │ ├── rpc-core │ │ ├── Cargo.toml │ │ └── src │ │ │ ├── eth.rs │ │ │ ├── eth_pubsub.rs │ │ │ ├── lib.rs │ │ │ ├── net.rs │ │ │ ├── txpool.rs │ │ │ ├── types │ │ │ ├── account_info.rs │ │ │ ├── block.rs │ │ │ ├── block_number.rs │ │ │ ├── bytes.rs │ │ │ ├── call_request.rs │ │ │ ├── fee.rs │ │ │ ├── filter.rs │ │ │ ├── index.rs │ │ │ ├── log.rs │ │ │ ├── mod.rs │ │ │ ├── pubsub.rs │ │ │ ├── receipt.rs │ │ │ ├── sync.rs │ │ │ ├── transaction.rs │ │ │ ├── transaction_request.rs │ │ │ ├── txpool.rs │ │ │ └── work.rs │ │ │ └── web3.rs │ ├── rpc │ │ ├── Cargo.toml │ │ └── src │ │ │ ├── eth │ │ │ ├── block.rs │ │ │ ├── cache │ │ │ │ ├── lru_cache.rs │ │ │ │ └── mod.rs │ │ │ ├── client.rs │ │ │ ├── execute.rs │ │ │ ├── fee.rs │ │ │ ├── filter.rs │ │ │ ├── format.rs │ │ │ ├── mining.rs │ │ │ ├── mod.rs │ │ │ ├── state.rs │ │ │ ├── submit.rs │ │ │ └── transaction.rs │ │ │ ├── eth_pubsub.rs │ │ │ ├── lib.rs │ │ │ ├── net.rs │ │ │ ├── signer.rs │ │ │ ├── txpool.rs │ │ │ └── web3.rs │ └── storage │ │ ├── Cargo.toml │ │ └── src │ │ ├── lib.rs │ │ └── overrides │ │ ├── mod.rs │ │ ├── schema_v1_override.rs │ │ ├── schema_v2_override.rs │ │ └── schema_v3_override.rs ├── docs │ ├── .gitignore │ ├── .vuepress │ │ ├── config.js │ │ └── styles │ │ │ ├── index.styl │ │ │ └── palette.styl │ ├── package.json │ └── yarn.lock ├── frame │ ├── base-fee │ │ ├── Cargo.toml │ │ └── src │ │ │ ├── lib.rs │ │ │ └── tests.rs │ ├── dynamic-fee │ │ ├── Cargo.toml │ │ └── src │ │ │ ├── lib.rs │ │ │ └── tests.rs │ ├── ethereum │ │ ├── Cargo.toml │ │ └── src │ │ │ ├── lib.rs │ │ │ ├── mock.rs │ │ │ └── tests │ │ │ ├── eip1559.rs │ │ │ ├── eip2930.rs │ │ │ ├── legacy.rs │ │ │ ├── mod.rs │ │ │ └── res │ │ │ └── erc20_contract_bytecode.txt │ ├── evm-chain-id │ │ ├── Cargo.toml │ │ └── src │ │ │ └── lib.rs │ ├── evm │ │ ├── Cargo.toml │ │ ├── precompile │ │ │ ├── blake2 │ │ │ │ ├── Cargo.toml │ │ │ │ └── src │ │ │ │ │ ├── eip_152.rs │ │ │ │ │ └── lib.rs │ │ │ ├── bls12377 │ │ │ │ ├── Cargo.toml │ │ │ │ └── src │ │ │ │ │ ├── lib.rs │ │ │ │ │ └── tests.rs │ │ │ ├── bn128 │ │ │ │ ├── Cargo.toml │ │ │ │ └── src │ │ │ │ │ └── lib.rs │ │ │ ├── bw6761 │ │ │ │ ├── Cargo.toml │ │ │ │ └── src │ │ │ │ │ ├── lib.rs │ │ │ │ │ └── tests.rs │ │ │ ├── curve25519 │ │ │ │ ├── Cargo.toml │ │ │ │ └── src │ │ │ │ │ └── lib.rs │ │ │ ├── dispatch │ │ │ │ ├── Cargo.toml │ │ │ │ └── src │ │ │ │ │ ├── lib.rs │ │ │ │ │ ├── mock.rs │ │ │ │ │ └── tests.rs │ │ │ ├── ed25519 │ │ │ │ ├── Cargo.toml │ │ │ │ └── src │ │ │ │ │ └── lib.rs │ │ │ ├── modexp │ │ │ │ ├── Cargo.toml │ │ │ │ └── src │ │ │ │ │ └── lib.rs │ │ │ ├── sha3fips │ │ │ │ ├── Cargo.toml │ │ │ │ └── src │ │ │ │ │ └── lib.rs │ │ │ ├── simple │ │ │ │ ├── Cargo.toml │ │ │ │ └── src │ │ │ │ │ └── lib.rs │ │ │ └── testdata │ │ │ │ ├── blake2F.json │ │ │ │ ├── bls12377G1Add.json │ │ │ │ ├── bls12377G1Mul.json │ │ │ │ ├── bls12377G1MultiExp.json │ │ │ │ ├── bls12377G2Add.json │ │ │ │ ├── bls12377G2Mul.json │ │ │ │ ├── bls12377G2MultiExp.json │ │ │ │ ├── bls12377Pairing.json │ │ │ │ ├── bw6761G1Add.json │ │ │ │ ├── bw6761G1Mul.json │ │ │ │ ├── bw6761G1MultiExp.json │ │ │ │ ├── bw6761G2Add.json │ │ │ │ ├── bw6761G2Mul.json │ │ │ │ ├── bw6761G2MultiExp.json │ │ │ │ ├── bw6761Pairing.json │ │ │ │ ├── common_bnadd.json │ │ │ │ ├── common_bnmul.json │ │ │ │ ├── common_bnpair.json │ │ │ │ ├── common_ripemd.json │ │ │ │ ├── common_sha256.json │ │ │ │ ├── ecRecover.json │ │ │ │ ├── fail-bls12377G1Add.json │ │ │ │ ├── fail-bls12377G1Mul.json │ │ │ │ ├── fail-bls12377G1MultiExp.json │ │ │ │ ├── fail-bls12377G2Add.json │ │ │ │ ├── fail-bls12377G2Mul.json │ │ │ │ ├── fail-bls12377G2Mul_Fail.json │ │ │ │ ├── fail-bls12377G2MultiExp.json │ │ │ │ ├── fail-bls12377Pairing.json │ │ │ │ ├── fail-bw6761G1Add.json │ │ │ │ ├── fail-bw6761G1Mul.json │ │ │ │ ├── fail-bw6761G1MultiExp.json │ │ │ │ ├── fail-bw6761G2Add.json │ │ │ │ ├── fail-bw6761G2Mul.json │ │ │ │ ├── fail-bw6761G2MultiExp.json │ │ │ │ ├── fail-bw6761Pairing.json │ │ │ │ └── modexp_eip2565.json │ │ ├── src │ │ │ ├── benchmarking.rs │ │ │ ├── lib.rs │ │ │ ├── mock.rs │ │ │ ├── res │ │ │ │ ├── proof_size_test_callee_contract_bytecode.txt │ │ │ │ └── proof_size_test_contract_bytecode.txt │ │ │ ├── runner │ │ │ │ ├── mod.rs │ │ │ │ └── stack.rs │ │ │ ├── tests.rs │ │ │ └── weights.rs │ │ └── test-vector-support │ │ │ ├── Cargo.toml │ │ │ └── src │ │ │ └── lib.rs │ └── hotfix-sufficients │ │ ├── Cargo.toml │ │ └── src │ │ ├── benchmarking.rs │ │ ├── lib.rs │ │ ├── mock.rs │ │ ├── tests.rs │ │ └── weights.rs ├── primitives │ ├── account │ │ ├── Cargo.toml │ │ └── src │ │ │ └── lib.rs │ ├── consensus │ │ ├── Cargo.toml │ │ └── src │ │ │ └── lib.rs │ ├── dynamic-fee │ │ ├── Cargo.toml │ │ └── src │ │ │ └── lib.rs │ ├── ethereum │ │ ├── Cargo.toml │ │ └── src │ │ │ └── lib.rs │ ├── evm │ │ ├── Cargo.toml │ │ └── src │ │ │ ├── lib.rs │ │ │ ├── precompile.rs │ │ │ └── validation.rs │ ├── rpc │ │ ├── Cargo.toml │ │ └── src │ │ │ └── lib.rs │ ├── self-contained │ │ ├── Cargo.toml │ │ └── src │ │ │ ├── checked_extrinsic.rs │ │ │ ├── lib.rs │ │ │ └── unchecked_extrinsic.rs │ └── storage │ │ ├── Cargo.toml │ │ └── src │ │ └── lib.rs ├── rust-toolchain ├── rustfmt.toml ├── scripts │ └── benchmark.sh ├── shell.nix ├── taplo.toml ├── template │ ├── .dockerignore │ ├── Dockerfile │ ├── LICENSE │ ├── examples │ │ ├── contract-erc20 │ │ │ ├── .gitignore │ │ │ ├── create-erc20-rpc.ts │ │ │ ├── create-erc20.ts │ │ │ ├── package-lock.json │ │ │ ├── package.json │ │ │ ├── truffle │ │ │ │ ├── .gitignore │ │ │ │ ├── contracts │ │ │ │ │ ├── MyToken.json │ │ │ │ │ └── MyToken.sol │ │ │ │ ├── package-lock.json │ │ │ │ ├── package.json │ │ │ │ └── truffle-config.js │ │ │ └── tsconfig.json │ │ └── contract-hello │ │ │ ├── .gitignore │ │ │ ├── Hello.sol │ │ │ ├── index.js │ │ │ ├── package-lock.json │ │ │ └── package.json │ ├── node │ │ ├── Cargo.toml │ │ ├── build.rs │ │ └── src │ │ │ ├── benchmarking.rs │ │ │ ├── chain_spec.rs │ │ │ ├── cli.rs │ │ │ ├── client.rs │ │ │ ├── command.rs │ │ │ ├── eth.rs │ │ │ ├── main.rs │ │ │ ├── rpc │ │ │ ├── eth.rs │ │ │ └── mod.rs │ │ │ └── service.rs │ ├── runtime │ │ ├── Cargo.toml │ │ ├── build.rs │ │ └── src │ │ │ ├── lib.rs │ │ │ └── precompiles.rs │ └── utils │ │ ├── .gitignore │ │ ├── erc20-slot.js │ │ ├── evm-address.js │ │ ├── index.js │ │ ├── package-lock.json │ │ └── package.json └── ts-tests │ ├── .gitignore │ ├── .prettierrc.js │ ├── contracts │ ├── ECRecoverTests.sol │ ├── ExplicitRevertReason.sol │ ├── ForceGasLimit.sol │ ├── InvalidOpcode.sol │ ├── StateOverrideTest.sol │ ├── Storage.sol │ ├── StorageLoop.sol │ └── Test.sol │ ├── package-lock.json │ ├── package.json │ ├── tests │ ├── config.ts │ ├── test-balance.ts │ ├── test-block-tags.ts │ ├── test-block.ts │ ├── test-bloom.ts │ ├── test-contract-methods.ts │ ├── test-contract-storage.ts │ ├── test-contract.ts │ ├── test-deprecated.ts │ ├── test-execute.ts │ ├── test-fee-history.ts │ ├── test-filter-api.ts │ ├── test-gas.ts │ ├── test-log-filtering.ts │ ├── test-log-tags.ts │ ├── test-max-priority-fee-per-gas-rpc.ts │ ├── test-netapi.ts │ ├── test-nonce.ts │ ├── test-pending-pool.ts │ ├── test-precompiles.ts │ ├── test-revert-reason.ts │ ├── test-revert-receipt.ts │ ├── test-rpc-constants.ts │ ├── test-state-override.ts │ ├── test-state-root.ts │ ├── test-subscription.ts │ ├── test-transaction-cost.ts │ ├── test-transaction-priority.ts │ ├── test-transaction-version.ts │ ├── test-web3api.ts │ ├── txpool.ts │ └── util.ts │ ├── truffle-config.js │ └── tsconfig.json ├── node ├── Cargo.toml ├── bin │ └── main.rs ├── build.rs ├── res │ ├── Raw.json │ └── gpu.json └── src │ ├── benchmarking.rs │ ├── chain_spec.rs │ ├── cli.rs │ ├── command.rs │ ├── eth.rs │ ├── lib.rs │ └── service.rs ├── pallets ├── custom-signatures │ ├── Cargo.toml │ └── src │ │ ├── ethereum.rs │ │ ├── lib.rs │ │ └── tests.rs └── precompiles │ ├── assets-erc20 │ ├── Cargo.toml │ ├── ERC20.sol │ └── src │ │ ├── lib.rs │ │ ├── mock.rs │ │ └── tests.rs │ ├── batch │ ├── Batch.sol │ ├── Cargo.toml │ └── src │ │ ├── lib.rs │ │ ├── mock.rs │ │ └── tests.rs │ ├── sr25519 │ ├── Cargo.toml │ ├── SR25519.sol │ └── src │ │ ├── lib.rs │ │ ├── mock.rs │ │ └── tests.rs │ ├── substrate-ecdsa │ ├── Cargo.toml │ ├── SubstrateEcdsa.sol │ └── src │ │ ├── lib.rs │ │ ├── mock.rs │ │ └── tests.rs │ └── utils │ ├── Cargo.toml │ ├── macro │ ├── Cargo.toml │ ├── src │ │ └── lib.rs │ └── tests │ │ └── tests.rs │ └── src │ ├── bytes.rs │ ├── data.rs │ ├── lib.rs │ ├── testing │ ├── account.rs │ ├── execution.rs │ ├── handle.rs │ └── mod.rs │ └── tests.rs ├── primitives ├── Cargo.toml └── src │ ├── assets.rs │ └── lib.rs ├── rpc ├── Cargo.toml └── src │ ├── eth.rs │ └── lib.rs ├── runtime ├── common │ ├── Cargo.toml │ └── src │ │ ├── elections.rs │ │ ├── impls.rs │ │ └── lib.rs └── gpu │ ├── Cargo.toml │ ├── build.rs │ ├── constants │ ├── Cargo.toml │ └── src │ │ ├── lib.rs │ │ └── weights │ │ ├── block_weights.rs │ │ ├── extrinsic_weights.rs │ │ ├── mod.rs │ │ ├── paritydb_weights.rs │ │ └── rocksdb_weights.rs │ └── src │ ├── bag_thresholds.rs │ ├── evm │ ├── mod.rs │ └── precompiles.rs │ ├── governance │ ├── mod.rs │ ├── origins.rs │ └── tracks.rs │ ├── lib.rs │ ├── proxy_config.rs │ └── weights │ ├── frame_benchmarking_baseline.rs │ ├── frame_election_provider_support.rs │ ├── frame_system.rs │ ├── mod.rs │ ├── pallet_bags_list.rs │ ├── pallet_balances.rs │ ├── pallet_bounties.rs │ ├── pallet_child_bounties.rs │ ├── pallet_contracts.rs │ ├── pallet_conviction_voting.rs │ ├── pallet_election_provider_multi_phase.rs │ ├── pallet_fast_unstake.rs │ ├── pallet_identity.rs │ ├── pallet_im_online.rs │ ├── pallet_indices.rs │ ├── pallet_membership.rs │ ├── pallet_multisig.rs │ ├── pallet_offences.rs │ ├── pallet_preimage.rs │ ├── pallet_proxy.rs │ ├── pallet_referenda.rs │ ├── pallet_scheduler.rs │ ├── pallet_session.rs │ ├── pallet_staking.rs │ ├── pallet_timestamp.rs │ ├── pallet_treasury.rs │ ├── pallet_utility.rs │ ├── pallet_vesting.rs │ └── pallet_whitelist.rs ├── rust-toolchain ├── rustfmt.toml ├── scripts ├── build_with_docker.sh ├── cargo_test.sh ├── dockerfiles │ └── selendra │ │ ├── build.sh │ │ └── selendra_builder.Dockerfile ├── get_selendra.sh ├── init.sh ├── packaging │ └── selendra.service ├── prepare-testnet.sh ├── run_benches_for_runtime.sh ├── sessions │ ├── audi1 │ ├── audi2 │ ├── audi3 │ ├── audi4 │ ├── babe1 │ ├── babe2 │ ├── babe3 │ ├── babe4 │ ├── gran1 │ ├── gran2 │ ├── gran3 │ ├── gran4 │ ├── imol1 │ ├── imol2 │ ├── imol3 │ ├── imol4 │ ├── run.sh │ ├── run1.sh │ └── run2.sh └── srtool_with_docker.sh └── utils ├── generate-bags ├── Cargo.toml └── src │ └── main.rs └── staking-miner ├── .gitignore ├── Cargo.lock ├── Cargo.toml ├── src ├── dry_run.rs ├── emergency_solution.rs ├── main.rs ├── monitor.rs ├── opts.rs ├── prelude.rs ├── rpc.rs ├── runtime_versions.rs └── signer.rs └── tests └── cli.rs /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style=space 5 | indent_size=2 6 | tab_width=2 7 | end_of_line=lf 8 | charset=utf-8 9 | trim_trailing_whitespace=true 10 | insert_final_newline = true 11 | 12 | [*.{rs,toml}] 13 | indent_style=tab 14 | indent_size=tab 15 | tab_width=4 16 | max_line_length=100 17 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # will have compiled files and executables 3 | **/target/ 4 | # These are backup files generated by rustfmt 5 | **/*.rs.bk 6 | 7 | .DS_Store 8 | 9 | # The cache for docker container dependency 10 | .cargo 11 | 12 | # The cache for chain data in container 13 | .local 14 | local 15 | 16 | # direnv cache 17 | .direnv 18 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [workspace] 2 | members = [ 3 | "rpc", 4 | "node", 5 | "primitives", 6 | "runtime/common", 7 | "runtime/gpu", 8 | "runtime/gpu/constants", 9 | "pallets/precompiles/*", 10 | "pallets/custom-signatures" 11 | ] 12 | 13 | exclude = [ 14 | "frontier" 15 | ] 16 | 17 | [profile.release] 18 | # gpu runtime requires unwinding. 19 | panic = "unwind" 20 | opt-level = 3 21 | 22 | # make sure dev builds with backtrace do 23 | # not slow us down 24 | [profile.dev.package.backtrace] 25 | inherits = "release" 26 | 27 | [profile.production] 28 | inherits = "release" 29 | lto = true 30 | codegen-units = 1 31 | 32 | [profile.testnet] 33 | inherits = "release" 34 | debug = 1 # debug symbols are useful for profilers 35 | debug-assertions = true 36 | overflow-checks = true 37 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | # Start from the Ubuntu base image 2 | FROM ubuntu:latest 3 | 4 | # Install necessary packages 5 | RUN apt-get update && apt-get install -y wget && apt-get install -y curl 6 | 7 | # Set the working directory 8 | WORKDIR /app 9 | 10 | # Download the binary file from GitHub 11 | RUN wget -O binary-file https://github.com/brahmGAN/ganchain-v2/releases/download/v2.0.0/gpu 12 | 13 | # Give execute permission to the binary 14 | RUN chmod +x binary-file 15 | 16 | #Get name from env 17 | ENV NAME="GANValidator" 18 | 19 | # Command to run the binary 20 | CMD ./binary-file --base-path chaindata/GanValidator --chain gpu --port 30333 --rpc-port 9933 --validator --name ${NAME} --bootnodes /ip4/3.64.87.46/tcp/30335/ws/p2p/12D3KooWDnsUzPhi6Dra6wRLooM9BSwDS4QmrfmzkTz6YW5nGVcm -------------------------------------------------------------------------------- /file_header.txt: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2021-2022 gpu. 2 | // SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 3 | 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | -------------------------------------------------------------------------------- /frontier/.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*.rs] 4 | indent_style=tab 5 | indent_size=tab 6 | tab_width=4 7 | end_of_line=lf 8 | charset=utf-8 9 | trim_trailing_whitespace=true 10 | insert_final_newline=true 11 | 12 | [*.toml] 13 | indent_style=tab 14 | indent_size=tab 15 | tab_width=4 16 | 17 | [*.ts] 18 | indent_style=tab 19 | indent_size=tab 20 | tab_width=4 -------------------------------------------------------------------------------- /frontier/.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | # A codeowner just oversees some part of the codebase. If an owned file is changed then the 2 | # corresponding codeowner receives a review request. An approval of the codeowner is 3 | # not required for merging a PR. 4 | 5 | * @sorpaas 6 | -------------------------------------------------------------------------------- /frontier/.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | 3 | updates: 4 | - package-ecosystem: github-actions 5 | directory: "/" 6 | schedule: 7 | interval: daily 8 | time: "03:00" 9 | timezone: Europe/Berlin 10 | - package-ecosystem: npm 11 | directory: "/docs" 12 | schedule: 13 | interval: "daily" 14 | - package-ecosystem: cargo 15 | directory: "/" 16 | # Handle updates for crates from github.com/paritytech/substrate manually. 17 | ignore: 18 | - dependency-name: "sc-*" 19 | - dependency-name: "sp-*" 20 | - dependency-name: "frame-*" 21 | - dependency-name: "pallet-*" 22 | - dependency-name: "substrate-*" 23 | - dependency-name: "beefy-*" 24 | - dependency-name: "fork-tree" 25 | schedule: 26 | interval: "daily" 27 | -------------------------------------------------------------------------------- /frontier/.github/workflows/cancel.yml: -------------------------------------------------------------------------------- 1 | name: Cancel 2 | 3 | on: 4 | push: 5 | branches: 6 | - '**' 7 | - '!master' 8 | - '!polkadot-v**' 9 | 10 | jobs: 11 | cancel: 12 | name: 'Cancel previous runs' 13 | runs-on: ubuntu-latest 14 | timeout-minutes: 3 15 | steps: 16 | - uses: styfle/cancel-workflow-action@0.11.0 17 | with: 18 | workflow_id: 1303397 19 | access_token: ${{ github.token }} 20 | -------------------------------------------------------------------------------- /frontier/.github/workflows/docs.yml: -------------------------------------------------------------------------------- 1 | name: Docs 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | 7 | jobs: 8 | release: 9 | name: Deploy docs 10 | runs-on: ubuntu-latest 11 | 12 | steps: 13 | - name: Checkout repository 14 | uses: actions/checkout@v3 15 | - name: Rust Setup 16 | uses: actions-rs/toolchain@v1 17 | with: 18 | profile: minimal 19 | toolchain: nightly-2023-05-23 20 | target: wasm32-unknown-unknown 21 | override: true 22 | components: rust-docs 23 | - name: Install protoc 24 | uses: arduino/setup-protoc@v1 25 | with: 26 | repo-token: ${{ secrets.GITHUB_TOKEN }} 27 | 28 | - name: Build website 29 | run: | 30 | cd docs 31 | yarn install 32 | yarn run build 33 | 34 | - name: Build rustdocs 35 | uses: actions-rs/cargo@v1 36 | with: 37 | command: doc 38 | args: --all --no-deps 39 | 40 | - name: Copy rustdocs 41 | run: | 42 | cp -r ./target/doc docs/.vuepress/dist/rustdocs 43 | 44 | - name: Deploy documentation 45 | uses: peaceiris/actions-gh-pages@v3 46 | with: 47 | deploy_key: ${{ secrets.ACTIONS_DEPLOY_KEY }} 48 | publish_branch: gh-pages 49 | publish_dir: ./docs/.vuepress/dist 50 | keep_files: true 51 | -------------------------------------------------------------------------------- /frontier/.github/workflows/editorconfig.yml: -------------------------------------------------------------------------------- 1 | name: Editorconfig 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | - 'polkadot-v**' 8 | pull_request: 9 | branches: 10 | - master 11 | - 'polkadot-v**' 12 | 13 | jobs: 14 | check: 15 | name: 'Check editorconfig' 16 | runs-on: ubuntu-latest 17 | steps: 18 | - uses: actions/checkout@v3 19 | - name: Submodules 20 | run: git submodule update --init --recursive 21 | - name: Init 22 | run: | 23 | wget https://github.com/editorconfig-checker/editorconfig-checker/releases/download/2.1.0/ec-linux-amd64.tar.gz 24 | tar xvf ec-linux-amd64.tar.gz 25 | chmod +x bin/ec-linux-amd64 26 | - name: Check 27 | run: bin/ec-linux-amd64 28 | -------------------------------------------------------------------------------- /frontier/.gitignore: -------------------------------------------------------------------------------- 1 | **/target/ 2 | **/node_modules/ 3 | **/*.rs.bk 4 | *.swp 5 | .wasm-binaries 6 | polkadot/runtime/wasm/target/ 7 | core/executor/wasm/target/ 8 | core/test-runtime/wasm/target/ 9 | pwasm-alloc/target/ 10 | pwasm-libc/target/ 11 | pwasm-alloc/Cargo.lock 12 | pwasm-libc/Cargo.lock 13 | node/runtime/wasm/target/ 14 | **/._* 15 | **/.criterion/ 16 | .vscode 17 | polkadot.* 18 | .DS_Store 19 | .idea/ 20 | .cargo-remote.toml 21 | 22 | # Added by cargo 23 | /target 24 | 25 | # NixOS development environment 26 | .envrc 27 | -------------------------------------------------------------------------------- /frontier/.maintain/node-template-release.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -e 4 | 5 | export TERM=xterm 6 | PROJECT_ROOT=`git rev-parse --show-toplevel` 7 | 8 | if [ "$#" -ne 1 ]; then 9 | echo "node-template-release.sh path_to_target_archive" 10 | exit 1 11 | fi 12 | 13 | PATH_TO_ARCHIVE=$1 14 | cd $PROJECT_ROOT/.maintain/node-template-release 15 | 16 | cargo run $PROJECT_ROOT/template $PROJECT_ROOT/$PATH_TO_ARCHIVE 17 | -------------------------------------------------------------------------------- /frontier/.maintain/node-template-release/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "node-template-release" 3 | version = "3.0.0" 4 | authors = ["Parity Technologies "] 5 | edition = "2018" 6 | license = "GPL-3.0" 7 | 8 | [dependencies] 9 | toml = "0.4" 10 | tar = "0.4" 11 | glob = "0.2" 12 | structopt = "0.3" 13 | tempfile = "3" 14 | fs_extra = "1" 15 | git2 = "0.16" 16 | flate2 = "1.0" 17 | 18 | [workspace] 19 | 20 | [package.metadata.docs.rs] 21 | targets = ["x86_64-unknown-linux-gnu"] 22 | -------------------------------------------------------------------------------- /frontier/.maintain/release-polkadot-branch.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # This script can be used for releasing polkadot branch. 4 | 5 | if [[ $# -eq 1 && "${1}" == "--help" ]]; then 6 | echo "USAGE:" 7 | echo " ${0} [] , like master or polkadot-v0.9.27" 8 | elif [[ $# -ne 2 ]]; then 9 | to_branch=${1} 10 | rg "https://github.com/brahmGAN/substrate" -t toml -T lock -l | xargs sed -i "s/master/$to_branch/g" 11 | else 12 | from_branch=${1} 13 | to_branch=${2} 14 | rg "https://github.com/brahmGAN/substrate" -t toml -T lock -l | xargs sed -i "s/$from_branch/$to_branch/g" 15 | fi 16 | -------------------------------------------------------------------------------- /frontier/HEADER-APACHE2: -------------------------------------------------------------------------------- 1 | // This file is part of Frontier. 2 | 3 | // Copyright (C) Parity Technologies (UK) Ltd. 4 | // SPDX-License-Identifier: Apache-2.0 5 | 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | -------------------------------------------------------------------------------- /frontier/client/cli/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "fc-cli" 3 | version = "1.0.0-dev" 4 | license = "GPL-3.0-or-later WITH Classpath-exception-2.0" 5 | description = "Frontier CLI interface" 6 | authors = { workspace = true } 7 | edition = { workspace = true } 8 | repository = { workspace = true } 9 | 10 | [package.metadata.docs.rs] 11 | targets = ["x86_64-unknown-linux-gnu"] 12 | 13 | [dependencies] 14 | clap = { workspace = true } 15 | ethereum-types = { workspace = true } 16 | serde = { workspace = true } 17 | serde_json = { workspace = true } 18 | # Substrate 19 | sc-cli = { workspace = true } 20 | sp-api = { workspace = true } 21 | sp-blockchain = { workspace = true } 22 | sp-runtime = { workspace = true } 23 | # Frontier 24 | fc-db = { workspace = true } 25 | fp-rpc = { workspace = true, features = ["default"] } 26 | fp-storage = { workspace = true, features = ["default"] } 27 | 28 | [dev-dependencies] 29 | futures = { workspace = true } 30 | scale-codec = { package = "parity-scale-codec", workspace = true } 31 | tempfile = "3.3.0" 32 | # Substrate 33 | sc-block-builder = { workspace = true } 34 | sc-client-db = { workspace = true, features = ["rocksdb"] } 35 | sp-consensus = { workspace = true } 36 | sp-io = { workspace = true } 37 | substrate-test-runtime-client = { workspace = true } 38 | # Frontier 39 | fc-db = { workspace = true, features = ["rocksdb"] } 40 | frontier-template-runtime = { workspace = true, features = ["default"] } 41 | 42 | [features] 43 | default = ["rocksdb"] 44 | rocksdb = [ 45 | "sc-cli/rocksdb", 46 | "fc-db/rocksdb", 47 | ] 48 | -------------------------------------------------------------------------------- /frontier/client/cli/src/lib.rs: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 2 | // This file is part of Frontier. 3 | // 4 | // Copyright (c) 2021-2022 Parity Technologies (UK) Ltd. 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | 19 | #![deny(unused_crate_dependencies)] 20 | 21 | mod frontier_db_cmd; 22 | 23 | pub use self::frontier_db_cmd::FrontierDbCmd; 24 | -------------------------------------------------------------------------------- /frontier/client/consensus/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "fc-consensus" 3 | version = "2.0.0-dev" 4 | license = "GPL-3.0-or-later WITH Classpath-exception-2.0" 5 | description = "Frontier consensus for substrate." 6 | authors = { workspace = true } 7 | edition = { workspace = true } 8 | repository = { workspace = true } 9 | 10 | [package.metadata.docs.rs] 11 | targets = ["x86_64-unknown-linux-gnu"] 12 | 13 | [dependencies] 14 | async-trait = { workspace = true } 15 | thiserror = { workspace = true } 16 | # Substrate 17 | sc-consensus = { workspace = true } 18 | sp-api = { workspace = true } 19 | sp-block-builder = { workspace = true, features = ["default"] } 20 | sp-consensus = { workspace = true } 21 | sp-runtime = { workspace = true } 22 | # Frontier 23 | fp-consensus = { workspace = true, features = ["default"] } 24 | fp-rpc = { workspace = true, features = ["default"] } 25 | -------------------------------------------------------------------------------- /frontier/client/db/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "fc-db" 3 | version = "2.0.0-dev" 4 | license = "GPL-3.0-or-later WITH Classpath-exception-2.0" 5 | description = "Frontier database backend" 6 | authors = { workspace = true } 7 | edition = { workspace = true } 8 | repository = { workspace = true } 9 | 10 | [package.metadata.docs.rs] 11 | targets = ["x86_64-unknown-linux-gnu"] 12 | 13 | [dependencies] 14 | async-trait = { workspace = true } 15 | ethereum = { workspace = true, features = ["with-codec"], optional = true } 16 | futures = { workspace = true, optional = true } 17 | kvdb-rocksdb = { workspace = true, optional = true } 18 | log = { workspace = true } 19 | parity-db = { workspace = true } 20 | parking_lot = { workspace = true } 21 | scale-codec = { package = "parity-scale-codec", workspace = true } 22 | smallvec = { version = "1.10", optional = true } 23 | sqlx = { workspace = true, features = ["runtime-tokio-native-tls", "sqlite"], optional = true } 24 | tokio = { workspace = true, features = ["macros", "sync"], optional = true } 25 | # Substrate 26 | sc-client-api = { workspace = true, optional = true } 27 | sc-client-db = { workspace = true } 28 | sp-api = { workspace = true, optional = true } 29 | sp-blockchain = { workspace = true } 30 | sp-core = { workspace = true } 31 | sp-database = { workspace = true } 32 | sp-runtime = { workspace = true } 33 | sp-storage = { workspace = true, optional = true } 34 | # Frontier 35 | fc-storage = { workspace = true, optional = true } 36 | fp-consensus = { workspace = true, features = ["default"], optional = true } 37 | fp-rpc = { workspace = true, features = ["default"], optional = true } 38 | fp-storage = { workspace = true, features = ["default"] } 39 | 40 | [dev-dependencies] 41 | futures = { workspace = true } 42 | maplit = "1.0.2" 43 | tempfile = "3.3.0" 44 | # Substrate 45 | sc-block-builder = { workspace = true } 46 | sp-consensus = { workspace = true } 47 | substrate-test-runtime-client = { workspace = true } 48 | 49 | [features] 50 | default = ["rocksdb"] 51 | rocksdb = [ 52 | "kvdb-rocksdb", 53 | "sc-client-db/rocksdb", 54 | "smallvec", 55 | ] 56 | sql = [ 57 | "ethereum", 58 | "futures", 59 | "sqlx", 60 | "tokio", 61 | "sc-client-api", 62 | "sp-api", 63 | "sp-storage", 64 | "fc-storage", 65 | "fp-consensus", 66 | "fp-rpc", 67 | ] 68 | -------------------------------------------------------------------------------- /frontier/client/db/src/kv/parity_db_adapter.rs: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 2 | // This file is part of Frontier. 3 | // 4 | // Copyright (c) 2022 Parity Technologies (UK) Ltd. 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | 19 | // Substrate 20 | use sp_database::{error::DatabaseError, Change, ColumnId, Database, Transaction}; 21 | 22 | fn handle_err(result: parity_db::Result) -> T { 23 | match result { 24 | Ok(r) => r, 25 | Err(e) => { 26 | panic!("Critical database error: {:?}", e); 27 | } 28 | } 29 | } 30 | 31 | pub struct DbAdapter(pub parity_db::Db); 32 | 33 | impl> Database for DbAdapter { 34 | fn commit(&self, transaction: Transaction) -> Result<(), DatabaseError> { 35 | handle_err( 36 | self.0 37 | .commit(transaction.0.into_iter().map(|change| match change { 38 | Change::Set(col, key, value) => (col as u8, key, Some(value)), 39 | Change::Remove(col, key) => (col as u8, key, None), 40 | _ => unimplemented!(), 41 | })), 42 | ); 43 | 44 | Ok(()) 45 | } 46 | 47 | fn get(&self, col: ColumnId, key: &[u8]) -> Option> { 48 | handle_err(self.0.get(col as u8, key)) 49 | } 50 | 51 | fn contains(&self, col: ColumnId, key: &[u8]) -> bool { 52 | handle_err(self.0.get_size(col as u8, key)).is_some() 53 | } 54 | 55 | fn value_size(&self, col: ColumnId, key: &[u8]) -> Option { 56 | handle_err(self.0.get_size(col as u8, key)).map(|s| s as usize) 57 | } 58 | 59 | fn supports_ref_counting(&self) -> bool { 60 | true 61 | } 62 | 63 | fn sanitize_key(&self, key: &mut Vec) { 64 | let _prefix = key.drain(0..key.len() - super::DB_HASH_LEN); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /frontier/client/db/src/lib.rs: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 2 | // This file is part of Frontier. 3 | // 4 | // Copyright (c) 2020-2022 Parity Technologies (UK) Ltd. 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | 19 | #![deny(unused_crate_dependencies)] 20 | 21 | use scale_codec::{Decode, Encode}; 22 | // Substrate 23 | pub use sc_client_db::DatabaseSource; 24 | use sp_core::H256; 25 | use sp_runtime::traits::Block as BlockT; 26 | 27 | pub mod kv; 28 | use kv::{columns, static_keys}; 29 | 30 | #[cfg(feature = "sql")] 31 | pub mod sql; 32 | 33 | #[derive(Clone)] 34 | pub enum Backend { 35 | KeyValue(kv::Backend), 36 | #[cfg(feature = "sql")] 37 | Sql(sql::Backend), 38 | } 39 | 40 | #[derive(Clone, Encode, Debug, Decode, Eq, PartialEq)] 41 | pub struct TransactionMetadata { 42 | pub block_hash: Block::Hash, 43 | pub ethereum_block_hash: H256, 44 | pub ethereum_index: u32, 45 | } 46 | 47 | #[derive(Debug, Eq, PartialEq)] 48 | pub struct FilteredLog { 49 | pub substrate_block_hash: Block::Hash, 50 | pub ethereum_block_hash: H256, 51 | pub block_number: u32, 52 | pub ethereum_storage_schema: fp_storage::EthereumStorageSchema, 53 | pub transaction_index: u32, 54 | pub log_index: u32, 55 | } 56 | 57 | #[async_trait::async_trait] 58 | pub trait BackendReader { 59 | async fn block_hash( 60 | &self, 61 | ethereum_block_hash: &H256, 62 | ) -> Result>, String>; 63 | 64 | async fn transaction_metadata( 65 | &self, 66 | ethereum_transaction_hash: &H256, 67 | ) -> Result>, String>; 68 | 69 | async fn filter_logs( 70 | &self, 71 | from_block: u64, 72 | to_block: u64, 73 | addresses: Vec, 74 | topics: Vec>>, 75 | ) -> Result>, String>; 76 | 77 | fn is_indexed(&self) -> bool; 78 | } 79 | -------------------------------------------------------------------------------- /frontier/client/mapping-sync/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "fc-mapping-sync" 3 | version = "2.0.0-dev" 4 | license = "GPL-3.0-or-later WITH Classpath-exception-2.0" 5 | description = "Mapping sync logic for Frontier." 6 | authors = { workspace = true } 7 | edition = { workspace = true } 8 | repository = { workspace = true } 9 | 10 | [package.metadata.docs.rs] 11 | targets = ["x86_64-unknown-linux-gnu"] 12 | 13 | [dependencies] 14 | futures = { workspace = true } 15 | futures-timer = "3.0.2" 16 | log = { workspace = true } 17 | parking_lot = { workspace = true } 18 | tokio = { workspace = true, features = ["macros", "sync"], optional = true } 19 | # Substrate 20 | sc-client-api = { workspace = true } 21 | sc-utils = { workspace = true } 22 | sp-api = { workspace = true } 23 | sp-blockchain = { workspace = true } 24 | sp-consensus = { workspace = true, features = ["default"] } 25 | sp-core = { workspace = true, optional = true } 26 | sp-runtime = { workspace = true } 27 | # Frontier 28 | fc-db = { workspace = true, default-features = false } 29 | fc-storage = { workspace = true } 30 | fp-consensus = { workspace = true, features = ["default"] } 31 | fp-rpc = { workspace = true, features = ["default"] } 32 | 33 | [dev-dependencies] 34 | ethereum = { workspace = true } 35 | ethereum-types = { workspace = true } 36 | scale-codec = { package = "parity-scale-codec", workspace = true } 37 | sqlx = { workspace = true, features = ["runtime-tokio-native-tls", "sqlite"] } 38 | tempfile = "3.3.0" 39 | tokio = { workspace = true, features = ["sync"] } 40 | # Substrate 41 | sc-block-builder = { workspace = true } 42 | sc-client-db = { workspace = true, features = ["rocksdb"] } 43 | sp-consensus = { workspace = true } 44 | sp-core = { workspace = true, features = ["default"] } 45 | sp-io = { workspace = true } 46 | substrate-test-runtime-client = { workspace = true } 47 | # Frontier 48 | fp-consensus = { workspace = true, features = ["default"] } 49 | fp-storage = { workspace = true, features = ["default"] } 50 | frontier-template-runtime = { workspace = true, features = ["default"] } 51 | 52 | [features] 53 | default = ["rocksdb"] 54 | rocksdb = ["fc-db/rocksdb"] 55 | sql = [ 56 | "tokio", 57 | "sp-core", 58 | "fc-db/sql", 59 | ] 60 | -------------------------------------------------------------------------------- /frontier/client/mapping-sync/src/lib.rs: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 2 | // This file is part of Frontier. 3 | // 4 | // Copyright (c) 2020-2022 Parity Technologies (UK) Ltd. 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | 19 | #![deny(unused_crate_dependencies)] 20 | #![allow(clippy::too_many_arguments)] 21 | 22 | pub mod kv; 23 | #[cfg(feature = "sql")] 24 | pub mod sql; 25 | 26 | use sp_api::BlockT; 27 | 28 | #[derive(Copy, Clone, Eq, PartialEq)] 29 | pub enum SyncStrategy { 30 | Normal, 31 | Parachain, 32 | } 33 | 34 | pub type EthereumBlockNotificationSinks = 35 | parking_lot::Mutex>>; 36 | 37 | #[derive(Copy, Clone, Debug, Eq, PartialEq)] 38 | pub struct EthereumBlockNotification { 39 | pub is_new_best: bool, 40 | pub hash: Block::Hash, 41 | } 42 | -------------------------------------------------------------------------------- /frontier/client/rpc-core/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "fc-rpc-core" 3 | version = "1.1.0-dev" 4 | license = "GPL-3.0-or-later WITH Classpath-exception-2.0" 5 | description = "RPC traits of Ethereum." 6 | authors = { workspace = true } 7 | edition = { workspace = true } 8 | repository = { workspace = true } 9 | 10 | [package.metadata.docs.rs] 11 | targets = ["x86_64-unknown-linux-gnu"] 12 | 13 | [dependencies] 14 | ethereum = { workspace = true, features = ["with-codec", "with-serde"] } 15 | ethereum-types = { workspace = true } 16 | jsonrpsee = { workspace = true, features = ["server", "macros"] } 17 | rustc-hex = "2.1.0" 18 | serde = { workspace = true } 19 | serde_json = { workspace = true } 20 | 21 | [features] 22 | txpool = [] 23 | -------------------------------------------------------------------------------- /frontier/client/rpc-core/src/eth_pubsub.rs: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 2 | // This file is part of Frontier. 3 | // 4 | // Copyright (c) 2015-2022 Parity Technologies (UK) Ltd. 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | 19 | //! Eth PUB-SUB rpc interface. 20 | 21 | use jsonrpsee::proc_macros::rpc; 22 | 23 | use crate::types::pubsub; 24 | 25 | /// Eth PUB-SUB rpc interface. 26 | #[rpc(server)] 27 | pub trait EthPubSubApi { 28 | /// Subscribe to Eth subscription. 29 | #[subscription( 30 | name = "eth_subscribe" => "eth_subscription", 31 | unsubscribe = "eth_unsubscribe", 32 | item = pubsub::Result 33 | )] 34 | fn subscribe(&self, kind: pubsub::Kind, params: Option); 35 | } 36 | -------------------------------------------------------------------------------- /frontier/client/rpc-core/src/lib.rs: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 2 | // This file is part of Frontier. 3 | // 4 | // Copyright (c) 2015-2022 Parity Technologies (UK) Ltd. 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | 19 | #![deny(unused_crate_dependencies)] 20 | 21 | pub mod types; 22 | 23 | mod eth; 24 | mod eth_pubsub; 25 | mod net; 26 | #[cfg(feature = "txpool")] 27 | mod txpool; 28 | mod web3; 29 | 30 | #[cfg(feature = "txpool")] 31 | pub use self::txpool::TxPoolApiServer; 32 | pub use self::{ 33 | eth::{EthApiServer, EthFilterApiServer}, 34 | eth_pubsub::EthPubSubApiServer, 35 | net::NetApiServer, 36 | web3::Web3ApiServer, 37 | }; 38 | -------------------------------------------------------------------------------- /frontier/client/rpc-core/src/net.rs: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 2 | // This file is part of Frontier. 3 | // 4 | // Copyright (c) 2015-2022 Parity Technologies (UK) Ltd. 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | 19 | //! Net rpc interface. 20 | 21 | use jsonrpsee::{core::RpcResult, proc_macros::rpc}; 22 | 23 | use crate::types::PeerCount; 24 | 25 | /// Net rpc interface. 26 | #[rpc(server)] 27 | pub trait NetApi { 28 | /// Returns protocol version. 29 | #[method(name = "net_version")] 30 | fn version(&self) -> RpcResult; 31 | 32 | /// Returns number of peers connected to node. 33 | #[method(name = "net_peerCount")] 34 | fn peer_count(&self) -> RpcResult; 35 | 36 | /// Returns true if client is actively listening for network connections. 37 | /// Otherwise false. 38 | #[method(name = "net_listening")] 39 | fn is_listening(&self) -> RpcResult; 40 | } 41 | -------------------------------------------------------------------------------- /frontier/client/rpc-core/src/txpool.rs: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 2 | // This file is part of Frontier. 3 | // 4 | // Copyright (c) 2015-2022 Parity Technologies (UK) Ltd. 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | 19 | //! tx pool rpc interface 20 | 21 | use ethereum_types::U256; 22 | use jsonrpsee::{core::RpcResult, proc_macros::rpc}; 23 | 24 | use crate::types::*; 25 | 26 | /// TxPool rpc interface 27 | #[rpc(server)] 28 | pub trait TxPoolApi { 29 | #[method(name = "txpool_content")] 30 | fn content(&self) -> RpcResult>>; 31 | 32 | #[method(name = "txpool_inspect")] 33 | fn inspect(&self) -> RpcResult>>; 34 | 35 | #[method(name = "txpool_status")] 36 | fn status(&self) -> RpcResult>; 37 | } 38 | -------------------------------------------------------------------------------- /frontier/client/rpc-core/src/types/fee.rs: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 2 | // This file is part of Frontier. 3 | // 4 | // Copyright (c) 2015-2022 Parity Technologies (UK) Ltd. 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | 19 | use std::{ 20 | collections::BTreeMap, 21 | sync::{Arc, Mutex}, 22 | }; 23 | 24 | use ethereum_types::U256; 25 | use serde::Serialize; 26 | 27 | /// `eth_feeHistory` response 28 | #[derive(Debug, Serialize)] 29 | #[serde(rename_all = "camelCase")] 30 | pub struct FeeHistory { 31 | /// Lowest number block of the returned range. 32 | pub oldest_block: U256, 33 | /// An array of block base fees per gas. 34 | /// This includes the next block after the newest of the returned range, 35 | /// because this value can be derived from the newest block. Zeroes are 36 | /// returned for pre-EIP-1559 blocks. 37 | pub base_fee_per_gas: Vec, 38 | /// An array of block gas used ratios. These are calculated as the ratio 39 | /// of gasUsed and gasLimit. 40 | pub gas_used_ratio: Vec, 41 | /// An array of effective priority fee per gas data points from a single 42 | /// block. All zeroes are returned if the block is empty. 43 | pub reward: Option>>, 44 | } 45 | 46 | pub type FeeHistoryCache = Arc>>; 47 | /// Maximum fee history cache size. 48 | pub type FeeHistoryCacheLimit = u64; 49 | 50 | pub struct FeeHistoryCacheItem { 51 | pub base_fee: u64, 52 | pub gas_used_ratio: f64, 53 | pub rewards: Vec, 54 | } 55 | -------------------------------------------------------------------------------- /frontier/client/rpc-core/src/types/log.rs: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 2 | // This file is part of Frontier. 3 | // 4 | // Copyright (c) 2015-2022 Parity Technologies (UK) Ltd. 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | 19 | use ethereum_types::{H160, H256, U256}; 20 | use serde::Serialize; 21 | 22 | use crate::types::Bytes; 23 | 24 | /// Log 25 | #[derive(Clone, Debug, Eq, PartialEq, Hash, Serialize)] 26 | #[serde(rename_all = "camelCase")] 27 | pub struct Log { 28 | /// H160 29 | pub address: H160, 30 | /// Topics 31 | pub topics: Vec, 32 | /// Data 33 | pub data: Bytes, 34 | /// Block Hash 35 | pub block_hash: Option, 36 | /// Block Number 37 | pub block_number: Option, 38 | /// Transaction Hash 39 | pub transaction_hash: Option, 40 | /// Transaction Index 41 | pub transaction_index: Option, 42 | /// Log Index in Block 43 | pub log_index: Option, 44 | /// Log Index in Transaction 45 | pub transaction_log_index: Option, 46 | /// Whether Log Type is Removed (Geth Compatibility Field) 47 | #[serde(default)] 48 | pub removed: bool, 49 | } 50 | -------------------------------------------------------------------------------- /frontier/client/rpc-core/src/types/receipt.rs: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 2 | // This file is part of Frontier. 3 | // 4 | // Copyright (c) 2015-2022 Parity Technologies (UK) Ltd. 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | 19 | use ethereum_types::{Bloom as H2048, H160, H256, U256, U64}; 20 | use serde::Serialize; 21 | 22 | use crate::types::Log; 23 | 24 | /// Receipt 25 | #[derive(Clone, Debug, Serialize)] 26 | #[serde(rename_all = "camelCase")] 27 | pub struct Receipt { 28 | /// Transaction Hash 29 | pub transaction_hash: Option, 30 | /// Transaction index 31 | pub transaction_index: Option, 32 | /// Block hash 33 | pub block_hash: Option, 34 | /// Sender 35 | pub from: Option, 36 | /// Recipient 37 | pub to: Option, 38 | /// Block number 39 | pub block_number: Option, 40 | /// Cumulative gas used 41 | pub cumulative_gas_used: U256, 42 | /// Gas used 43 | pub gas_used: Option, 44 | /// Contract address 45 | pub contract_address: Option, 46 | /// Logs 47 | pub logs: Vec, 48 | /// State Root 49 | // NOTE(niklasad1): EIP98 makes this optional field, if it's missing then skip serializing it 50 | #[serde(skip_serializing_if = "Option::is_none", rename = "root")] 51 | pub state_root: Option, 52 | /// Logs bloom 53 | pub logs_bloom: H2048, 54 | /// Status code 55 | // NOTE(niklasad1): Unknown after EIP98 rules, if it's missing then skip serializing it 56 | #[serde(skip_serializing_if = "Option::is_none", rename = "status")] 57 | pub status_code: Option, 58 | /// Effective gas price. Pre-eip1559 this is just the gasprice. Post-eip1559 this is base fee + priority fee. 59 | pub effective_gas_price: U256, 60 | /// EIP-2718 type 61 | #[serde(rename = "type")] 62 | pub transaction_type: U256, 63 | } 64 | -------------------------------------------------------------------------------- /frontier/client/rpc-core/src/types/work.rs: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 2 | // This file is part of Frontier. 3 | // 4 | // Copyright (c) 2015-2022 Parity Technologies (UK) Ltd. 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | 19 | use ethereum_types::{H256, U256}; 20 | use serde::{Serialize, Serializer}; 21 | 22 | /// The result of an `eth_getWork` call: it differs based on an option 23 | /// whether to send the block number. 24 | #[derive(Debug, Eq, PartialEq, Default)] 25 | pub struct Work { 26 | /// The proof-of-work hash. 27 | pub pow_hash: H256, 28 | /// The seed hash. 29 | pub seed_hash: H256, 30 | /// The target. 31 | pub target: H256, 32 | /// The block number: this isn't always stored. 33 | pub number: Option, 34 | } 35 | 36 | impl Serialize for Work { 37 | fn serialize(&self, s: S) -> Result 38 | where 39 | S: Serializer, 40 | { 41 | match self.number.as_ref() { 42 | Some(num) => ( 43 | &self.pow_hash, 44 | &self.seed_hash, 45 | &self.target, 46 | U256::from(*num), 47 | ) 48 | .serialize(s), 49 | None => (&self.pow_hash, &self.seed_hash, &self.target).serialize(s), 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /frontier/client/rpc-core/src/web3.rs: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 2 | // This file is part of Frontier. 3 | // 4 | // Copyright (c) 2015-2022 Parity Technologies (UK) Ltd. 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | 19 | //! Web3 rpc interface. 20 | 21 | use ethereum_types::H256; 22 | use jsonrpsee::{core::RpcResult, proc_macros::rpc}; 23 | 24 | use crate::types::Bytes; 25 | 26 | /// Web3 rpc interface. 27 | #[rpc(server)] 28 | pub trait Web3Api { 29 | /// Returns current client version. 30 | #[method(name = "web3_clientVersion")] 31 | fn client_version(&self) -> RpcResult; 32 | 33 | /// Returns sha3 of the given data 34 | #[method(name = "web3_sha3")] 35 | fn sha3(&self, input: Bytes) -> RpcResult; 36 | } 37 | -------------------------------------------------------------------------------- /frontier/client/rpc/src/eth/format.rs: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 2 | // This file is part of Frontier. 3 | // 4 | // Copyright (c) 2020 Parity Technologies (UK) Ltd. 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | 19 | // Substrate 20 | use sc_transaction_pool_api::error::{Error as PError, IntoPoolError}; 21 | use sp_runtime::transaction_validity::InvalidTransaction; 22 | // Frontier 23 | use fp_ethereum::TransactionValidationError as VError; 24 | 25 | // Formats the same way Geth node formats responses. 26 | pub struct Geth; 27 | 28 | impl Geth { 29 | pub fn pool_error(err: impl IntoPoolError) -> String { 30 | // Error strings from : 31 | // https://github.com/ethereum/go-ethereum/blob/794c6133efa2c7e8376d9d141c900ea541790bce/core/error.go 32 | match err.into_pool_error() { 33 | Ok(PError::AlreadyImported(_)) => "already known".to_string(), 34 | Ok(PError::TemporarilyBanned) => "already known".into(), 35 | Ok(PError::TooLowPriority { .. }) => "replacement transaction underpriced".into(), 36 | Ok(PError::InvalidTransaction(inner)) => match inner { 37 | InvalidTransaction::Stale => "nonce too low".into(), 38 | InvalidTransaction::Payment => "insufficient funds for gas * price + value".into(), 39 | InvalidTransaction::ExhaustsResources => "exceeds block gas limit".into(), 40 | InvalidTransaction::Custom(inner) => match inner.into() { 41 | VError::UnknownError => "unknown error".into(), 42 | VError::InvalidChainId => "invalid chain id".into(), 43 | VError::InvalidSignature => "invalid sender".into(), 44 | VError::GasLimitTooLow => "intrinsic gas too low".into(), 45 | VError::GasLimitTooHigh => "exceeds block gas limit".into(), 46 | VError::MaxFeePerGasTooLow => { 47 | "max priority fee per gas higher than max fee per gas".into() 48 | } 49 | }, 50 | _ => "unknown error".into(), 51 | }, 52 | err => format!("submit transaction to pool failed: {:?}", err), 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /frontier/client/rpc/src/eth/mining.rs: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 2 | // This file is part of Frontier. 3 | // 4 | // Copyright (c) 2022 Parity Technologies (UK) Ltd. 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | 19 | use ethereum_types::{H256, H64, U256}; 20 | use jsonrpsee::core::RpcResult; 21 | // Substrate 22 | use sc_transaction_pool::ChainApi; 23 | use sp_runtime::traits::Block as BlockT; 24 | // Frontier 25 | use fc_rpc_core::types::*; 26 | 27 | use crate::eth::{Eth, EthConfig}; 28 | 29 | impl> Eth { 30 | pub fn is_mining(&self) -> RpcResult { 31 | Ok(self.is_authority) 32 | } 33 | 34 | pub fn hashrate(&self) -> RpcResult { 35 | Ok(U256::zero()) 36 | } 37 | 38 | pub fn work(&self) -> RpcResult { 39 | Ok(Work::default()) 40 | } 41 | 42 | pub fn submit_hashrate(&self, _: U256, _: H256) -> RpcResult { 43 | Ok(false) 44 | } 45 | 46 | pub fn submit_work(&self, _: H64, _: H256, _: H256) -> RpcResult { 47 | Ok(false) 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /frontier/client/rpc/src/net.rs: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 2 | // This file is part of Frontier. 3 | // 4 | // Copyright (c) 2020-2022 Parity Technologies (UK) Ltd. 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | 19 | use std::sync::Arc; 20 | 21 | use jsonrpsee::core::RpcResult; 22 | // Substrate 23 | use sc_network::{NetworkPeers, NetworkService}; 24 | use sc_network_common::ExHashT; 25 | use sp_api::ProvideRuntimeApi; 26 | use sp_blockchain::HeaderBackend; 27 | use sp_runtime::traits::Block as BlockT; 28 | // Frontier 29 | use fc_rpc_core::{types::PeerCount, NetApiServer}; 30 | use fp_rpc::EthereumRuntimeRPCApi; 31 | 32 | use crate::internal_err; 33 | 34 | /// Net API implementation. 35 | pub struct Net { 36 | client: Arc, 37 | network: Arc>, 38 | peer_count_as_hex: bool, 39 | } 40 | 41 | impl Net { 42 | pub fn new( 43 | client: Arc, 44 | network: Arc>, 45 | peer_count_as_hex: bool, 46 | ) -> Self { 47 | Self { 48 | client, 49 | network, 50 | peer_count_as_hex, 51 | } 52 | } 53 | } 54 | 55 | impl NetApiServer for Net 56 | where 57 | B: BlockT, 58 | C: ProvideRuntimeApi, 59 | C::Api: EthereumRuntimeRPCApi, 60 | C: HeaderBackend + 'static, 61 | { 62 | fn version(&self) -> RpcResult { 63 | let hash = self.client.info().best_hash; 64 | Ok(self 65 | .client 66 | .runtime_api() 67 | .chain_id(hash) 68 | .map_err(|_| internal_err("fetch runtime chain id failed"))? 69 | .to_string()) 70 | } 71 | 72 | fn peer_count(&self) -> RpcResult { 73 | let peer_count = self.network.sync_num_connected(); 74 | Ok(match self.peer_count_as_hex { 75 | true => PeerCount::String(format!("0x{:x}", peer_count)), 76 | false => PeerCount::U32(peer_count as u32), 77 | }) 78 | } 79 | 80 | fn is_listening(&self) -> RpcResult { 81 | Ok(true) 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /frontier/client/rpc/src/web3.rs: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 2 | // This file is part of Frontier. 3 | // 4 | // Copyright (c) 2020-2022 Parity Technologies (UK) Ltd. 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | 19 | use std::{marker::PhantomData, sync::Arc}; 20 | 21 | use ethereum_types::H256; 22 | use jsonrpsee::core::RpcResult; 23 | // Substrate 24 | use sp_api::{Core, ProvideRuntimeApi}; 25 | use sp_blockchain::HeaderBackend; 26 | use sp_core::keccak_256; 27 | use sp_runtime::traits::Block as BlockT; 28 | // Frontier 29 | use fc_rpc_core::{types::Bytes, Web3ApiServer}; 30 | use fp_rpc::EthereumRuntimeRPCApi; 31 | 32 | use crate::internal_err; 33 | 34 | /// Web3 API implementation. 35 | pub struct Web3 { 36 | client: Arc, 37 | _marker: PhantomData, 38 | } 39 | 40 | impl Web3 { 41 | pub fn new(client: Arc) -> Self { 42 | Self { 43 | client, 44 | _marker: PhantomData, 45 | } 46 | } 47 | } 48 | 49 | impl Web3ApiServer for Web3 50 | where 51 | B: BlockT, 52 | C: ProvideRuntimeApi, 53 | C::Api: EthereumRuntimeRPCApi, 54 | C: HeaderBackend + 'static, 55 | { 56 | fn client_version(&self) -> RpcResult { 57 | let hash = self.client.info().best_hash; 58 | let version = self 59 | .client 60 | .runtime_api() 61 | .version(hash) 62 | .map_err(|err| internal_err(format!("fetch runtime version failed: {:?}", err)))?; 63 | Ok(format!( 64 | "{spec_name}/v{spec_version}.{impl_version}/{pkg_name}-{pkg_version}", 65 | spec_name = version.spec_name, 66 | spec_version = version.spec_version, 67 | impl_version = version.impl_version, 68 | pkg_name = env!("CARGO_PKG_NAME"), 69 | pkg_version = env!("CARGO_PKG_VERSION") 70 | )) 71 | } 72 | 73 | fn sha3(&self, input: Bytes) -> RpcResult { 74 | Ok(H256::from(keccak_256(&input.into_vec()))) 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /frontier/client/storage/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "fc-storage" 3 | version = "1.0.0-dev" 4 | license = "GPL-3.0-or-later WITH Classpath-exception-2.0" 5 | description = "Ethereum storage compatibility layer for Substrate." 6 | authors = { workspace = true } 7 | edition = { workspace = true } 8 | repository = { workspace = true } 9 | 10 | [package.metadata.docs.rs] 11 | targets = ["x86_64-unknown-linux-gnu"] 12 | 13 | [dependencies] 14 | ethereum = { workspace = true, features = ["with-codec"] } 15 | ethereum-types = { workspace = true } 16 | scale-codec = { package = "parity-scale-codec", workspace = true } 17 | 18 | # Substrate 19 | sc-client-api = { workspace = true } 20 | sp-api = { workspace = true } 21 | sp-blockchain = { workspace = true } 22 | sp-io = { workspace = true } 23 | sp-runtime = { workspace = true } 24 | sp-storage = { workspace = true } 25 | # Frontier 26 | fp-rpc = { workspace = true, features = ["default"] } 27 | fp-storage = { workspace = true, features = ["default"] } 28 | -------------------------------------------------------------------------------- /frontier/docs/.gitignore: -------------------------------------------------------------------------------- 1 | pids 2 | logs 3 | node_modules 4 | npm-debug.log 5 | coverage/ 6 | run 7 | dist 8 | .DS_Store 9 | .nyc_output 10 | .basement 11 | config.local.js 12 | basement_dist 13 | -------------------------------------------------------------------------------- /frontier/docs/.vuepress/config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | title: 'Frontier', 3 | description: 'Ethereum compatibility layer for Substrate', 4 | base: '/frontier/', 5 | 6 | head: [ 7 | ['meta', { name: 'theme-color', content: '#3eaf7c' }], 8 | ['meta', { name: 'apple-mobile-web-app-capable', content: 'yes' }], 9 | ['meta', { name: 'apple-mobile-web-app-status-bar-style', content: 'black' }] 10 | ], 11 | 12 | themeConfig: { 13 | repo: 'https://github.com/paritytech/frontier', 14 | editLinks: false, 15 | docsDir: 'docs', 16 | editLinkText: '', 17 | lastUpdated: false, 18 | nav: [ 19 | { text: 'API reference', link: 'https://paritytech.github.io/frontier/rustdocs/pallet_evm' } 20 | ], 21 | sidebar: [ 22 | 'overview', 23 | 'frame/evm', 24 | 'frame/ethereum' 25 | ] 26 | }, 27 | 28 | plugins: [ 29 | '@vuepress/plugin-back-to-top', 30 | '@vuepress/plugin-medium-zoom', 31 | ] 32 | } 33 | -------------------------------------------------------------------------------- /frontier/docs/.vuepress/styles/index.styl: -------------------------------------------------------------------------------- 1 | .home .hero img 2 | max-width 450px!important 3 | -------------------------------------------------------------------------------- /frontier/docs/.vuepress/styles/palette.styl: -------------------------------------------------------------------------------- 1 | $accentColor = #3eaf7c 2 | $textColor = #2c3e50 3 | $borderColor = #eaecef 4 | $codeBgColor = #282c34 5 | -------------------------------------------------------------------------------- /frontier/docs/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "frontier-docs", 3 | "version": "0.0.1", 4 | "description": "Frontier documentation.", 5 | "authors": { 6 | "name": "admin@parity.io", 7 | "email": "Parity Technologies" 8 | }, 9 | "repository": "https://github.com/paritytech/frontier", 10 | "scripts": { 11 | "dev": "NODE_OPTIONS=--openssl-legacy-provider vuepress dev .", 12 | "build": "NODE_OPTIONS=--openssl-legacy-provider vuepress build ." 13 | }, 14 | "license": "Apache-2.0", 15 | "dependencies": { 16 | "vuepress": "^1.9.9" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /frontier/frame/base-fee/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "pallet-base-fee" 3 | version = "1.0.0" 4 | license = "Apache-2.0" 5 | description = "EIP-1559 fee utils." 6 | authors = { workspace = true } 7 | edition = { workspace = true } 8 | repository = { workspace = true } 9 | 10 | [package.metadata.docs.rs] 11 | targets = ["x86_64-unknown-linux-gnu"] 12 | 13 | [dependencies] 14 | scale-codec = { package = "parity-scale-codec", workspace = true } 15 | scale-info = { workspace = true } 16 | # Substrate 17 | frame-support = { workspace = true } 18 | frame-system = { workspace = true } 19 | sp-core = { workspace = true } 20 | sp-runtime = { workspace = true } 21 | # Frontier 22 | fp-evm = { workspace = true } 23 | 24 | [dev-dependencies] 25 | # Substrate 26 | sp-io = { workspace = true, features = ["default"] } 27 | 28 | [features] 29 | default = ["std"] 30 | std = [ 31 | "scale-codec/std", 32 | "scale-info/std", 33 | # Substrate 34 | "frame-support/std", 35 | "frame-system/std", 36 | "sp-core/std", 37 | "sp-runtime/std", 38 | # Frontier 39 | "fp-evm/std", 40 | ] 41 | try-runtime = [ 42 | "frame-support/try-runtime", 43 | "frame-system/try-runtime", 44 | ] 45 | -------------------------------------------------------------------------------- /frontier/frame/dynamic-fee/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "pallet-dynamic-fee" 3 | version = "4.0.0-dev" 4 | license = "Apache-2.0" 5 | description = "Dynamic fee handling for EVM." 6 | authors = { workspace = true } 7 | edition = { workspace = true } 8 | repository = { workspace = true } 9 | 10 | [package.metadata.docs.rs] 11 | targets = ["x86_64-unknown-linux-gnu"] 12 | 13 | [dependencies] 14 | scale-codec = { package = "parity-scale-codec", workspace = true } 15 | scale-info = { workspace = true } 16 | # Substrate 17 | frame-support = { workspace = true } 18 | frame-system = { workspace = true } 19 | sp-core = { workspace = true } 20 | sp-inherents = { workspace = true } 21 | sp-runtime = { workspace = true } 22 | sp-std = { workspace = true } 23 | # Frontier 24 | fp-dynamic-fee = { workspace = true } 25 | fp-evm = { workspace = true } 26 | 27 | [dev-dependencies] 28 | # Substrate 29 | pallet-timestamp = { workspace = true, features = ["default"] } 30 | sp-io = { workspace = true, features = ["default"] } 31 | sp-runtime = { workspace = true, features = ["default"] } 32 | 33 | [features] 34 | default = ["std"] 35 | std = [ 36 | "scale-codec/std", 37 | "scale-info/std", 38 | # Substrate 39 | "sp-core/std", 40 | "sp-inherents/std", 41 | "sp-runtime/std", 42 | "sp-std/std", 43 | # Substrate 44 | "frame-system/std", 45 | "frame-support/std", 46 | # Frontier 47 | "fp-dynamic-fee/std", 48 | "fp-evm/std", 49 | ] 50 | try-runtime = [ 51 | "frame-support/try-runtime", 52 | "frame-system/try-runtime", 53 | ] 54 | -------------------------------------------------------------------------------- /frontier/frame/ethereum/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "pallet-ethereum" 3 | version = "4.0.0-dev" 4 | license = "Apache-2.0" 5 | description = "Ethereum compatibility full block processing emulation pallet for Substrate." 6 | authors = { workspace = true } 7 | edition = { workspace = true } 8 | repository = { workspace = true } 9 | 10 | [package.metadata.docs.rs] 11 | targets = ["x86_64-unknown-linux-gnu"] 12 | 13 | [dependencies] 14 | ethereum = { workspace = true, features = ["with-codec"] } 15 | ethereum-types = { workspace = true } 16 | evm = { workspace = true, features = ["with-codec"] } 17 | scale-codec = { package = "parity-scale-codec", workspace = true } 18 | scale-info = { workspace = true } 19 | # Substrate 20 | frame-support = { workspace = true } 21 | frame-system = { workspace = true } 22 | sp-io = { workspace = true } 23 | sp-runtime = { workspace = true } 24 | sp-std = { workspace = true } 25 | # Frontier 26 | fp-consensus = { workspace = true } 27 | fp-ethereum = { workspace = true } 28 | fp-evm = { workspace = true } 29 | fp-rpc = { workspace = true } 30 | fp-storage = { workspace = true } 31 | pallet-evm = { workspace = true } 32 | 33 | [dev-dependencies] 34 | hex = { workspace = true } 35 | libsecp256k1 = { workspace = true, features = ["static-context", "hmac"] } 36 | rlp = { workspace = true } 37 | # Substrate 38 | pallet-balances = { workspace = true, features = ["default"] } 39 | pallet-timestamp = { workspace = true, features = ["default"] } 40 | sp-core = { workspace = true, features = ["default"] } 41 | # Frontier 42 | fp-self-contained = { workspace = true, features = ["default"] } 43 | 44 | [features] 45 | default = ["std"] 46 | std = [ 47 | "ethereum/std", 48 | "evm/std", 49 | "ethereum-types/std", 50 | "rlp/std", 51 | "scale-codec/std", 52 | "scale-info/std", 53 | # Substrate 54 | "frame-support/std", 55 | "frame-system/std", 56 | "sp-io/std", 57 | "sp-runtime/std", 58 | "sp-std/std", 59 | # Frontier 60 | "fp-consensus/std", 61 | "fp-ethereum/std", 62 | "fp-evm/std", 63 | "fp-rpc/std", 64 | "fp-self-contained/std", 65 | "fp-storage/std", 66 | "pallet-evm/std", 67 | ] 68 | runtime-benchmarks = [ 69 | "frame-support/runtime-benchmarks", 70 | "frame-system/runtime-benchmarks", 71 | "pallet-evm/runtime-benchmarks", 72 | ] 73 | try-runtime = [ 74 | "frame-support/try-runtime", 75 | "frame-system/try-runtime", 76 | "pallet-evm/try-runtime", 77 | ] 78 | forbid-evm-reentrancy = ["pallet-evm/forbid-evm-reentrancy"] 79 | -------------------------------------------------------------------------------- /frontier/frame/evm-chain-id/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "pallet-evm-chain-id" 3 | version = "1.0.0-dev" 4 | license = "Apache-2.0" 5 | description = "EVM chain id storage pallet." 6 | authors = { workspace = true } 7 | edition = { workspace = true } 8 | repository = { workspace = true } 9 | 10 | [package.metadata.docs.rs] 11 | targets = ["x86_64-unknown-linux-gnu"] 12 | 13 | [dependencies] 14 | scale-codec = { package = "parity-scale-codec", workspace = true } 15 | scale-info = { workspace = true } 16 | # Substrate 17 | frame-support = { workspace = true } 18 | frame-system = { workspace = true } 19 | sp-runtime = { workspace = true } 20 | 21 | [features] 22 | default = ["std"] 23 | std = [ 24 | "scale-codec/std", 25 | "scale-info/std", 26 | # Substrate 27 | "frame-support/std", 28 | "frame-system/std", 29 | "sp-runtime/std", 30 | ] 31 | try-runtime = [ 32 | "frame-support/try-runtime", 33 | "frame-system/try-runtime", 34 | ] 35 | -------------------------------------------------------------------------------- /frontier/frame/evm-chain-id/src/lib.rs: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // This file is part of Frontier. 3 | // 4 | // Copyright (c) 2022 Parity Technologies (UK) Ltd. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | //! # EVM chain ID pallet 19 | //! 20 | //! The pallet that stores the numeric Ethereum-style chain id in the runtime. 21 | //! It can simplify setting up multiple networks with different chain ID by configuring the 22 | //! chain spec without requiring changes to the runtime config. 23 | //! 24 | //! **NOTE**: we recommend that the production chains still use the const parameter type, as 25 | //! this extra storage access would imply some performance penalty. 26 | 27 | // Ensure we're `no_std` when compiling for Wasm. 28 | #![cfg_attr(not(feature = "std"), no_std)] 29 | #![warn(unused_crate_dependencies)] 30 | 31 | pub use pallet::*; 32 | 33 | #[frame_support::pallet] 34 | pub mod pallet { 35 | use frame_support::pallet_prelude::*; 36 | 37 | const STORAGE_VERSION: StorageVersion = StorageVersion::new(0); 38 | 39 | #[pallet::pallet] 40 | #[pallet::storage_version(STORAGE_VERSION)] 41 | pub struct Pallet(PhantomData); 42 | 43 | #[pallet::config] 44 | pub trait Config: frame_system::Config {} 45 | 46 | impl Get for Pallet { 47 | fn get() -> u64 { 48 | >::get() 49 | } 50 | } 51 | 52 | /// The EVM chain ID. 53 | #[pallet::storage] 54 | pub type ChainId = StorageValue<_, u64, ValueQuery>; 55 | 56 | #[pallet::genesis_config] 57 | #[derive(frame_support::DefaultNoBound)] 58 | pub struct GenesisConfig { 59 | pub chain_id: u64, 60 | #[serde(skip)] 61 | pub _marker: PhantomData, 62 | } 63 | 64 | #[pallet::genesis_build] 65 | impl BuildGenesisConfig for GenesisConfig { 66 | fn build(&self) { 67 | ChainId::::put(self.chain_id); 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /frontier/frame/evm/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "pallet-evm" 3 | version = "6.0.0-dev" 4 | license = "Apache-2.0" 5 | readme = "README.md" 6 | description = "FRAME EVM contracts pallet." 7 | authors = { workspace = true } 8 | edition = { workspace = true } 9 | repository = { workspace = true } 10 | 11 | [package.metadata.docs.rs] 12 | targets = ["x86_64-unknown-linux-gnu"] 13 | 14 | [dependencies] 15 | environmental = { workspace = true, optional = true } 16 | evm = { workspace = true, features = ["with-codec"] } 17 | hex = { workspace = true, optional = true } 18 | hex-literal = { workspace = true } 19 | impl-trait-for-tuples = "0.2.2" 20 | log = { workspace = true } 21 | rlp = { workspace = true, optional = true } 22 | scale-codec = { package = "parity-scale-codec", workspace = true } 23 | scale-info = { workspace = true } 24 | # Substrate 25 | frame-benchmarking = { workspace = true, optional = true } 26 | frame-support = { workspace = true } 27 | frame-system = { workspace = true } 28 | sp-core = { workspace = true } 29 | sp-io = { workspace = true } 30 | sp-runtime = { workspace = true } 31 | sp-std = { workspace = true } 32 | # Frontier 33 | fp-account = { workspace = true } 34 | fp-evm = { workspace = true, features = ["serde"] } 35 | 36 | [dev-dependencies] 37 | hex = { workspace = true } 38 | # Substrate 39 | pallet-balances = { workspace = true, features = ["default", "insecure_zero_ed"] } 40 | pallet-evm-precompile-simple = { workspace = true, features = ["default"] } 41 | pallet-timestamp = { workspace = true, features = ["default"] } 42 | 43 | [features] 44 | default = ["std"] 45 | std = [ 46 | "environmental?/std", 47 | "evm/std", 48 | "evm/with-serde", 49 | "hex?/std", 50 | "log/std", 51 | "rlp?/std", 52 | "scale-codec/std", 53 | "scale-info/std", 54 | # Substrate 55 | "frame-benchmarking?/std", 56 | "frame-support/std", 57 | "frame-system/std", 58 | "sp-core/std", 59 | "sp-io/std", 60 | "sp-runtime/std", 61 | "sp-std/std", 62 | # Frontier 63 | "fp-account/std", 64 | "fp-evm/std", 65 | ] 66 | runtime-benchmarks = [ 67 | "hex", 68 | "rlp", 69 | "frame-benchmarking/runtime-benchmarks", 70 | "frame-support/runtime-benchmarks", 71 | "frame-system/runtime-benchmarks", 72 | ] 73 | try-runtime = [ 74 | "frame-support/try-runtime", 75 | "frame-system/try-runtime", 76 | ] 77 | forbid-evm-reentrancy = ["dep:environmental"] 78 | -------------------------------------------------------------------------------- /frontier/frame/evm/precompile/blake2/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "pallet-evm-precompile-blake2" 3 | version = "2.0.0-dev" 4 | license = "Apache-2.0" 5 | description = "BLAKE2 precompiles for EVM pallet." 6 | authors = { workspace = true } 7 | edition = { workspace = true } 8 | repository = { workspace = true } 9 | 10 | [dependencies] 11 | # Frontier 12 | fp-evm = { workspace = true } 13 | 14 | [dev-dependencies] 15 | pallet-evm-test-vector-support = { workspace = true } 16 | 17 | [features] 18 | default = ["std"] 19 | std = [ 20 | # Frontier 21 | "fp-evm/std", 22 | ] 23 | -------------------------------------------------------------------------------- /frontier/frame/evm/precompile/bls12377/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "pallet-evm-precompile-bls12377" 3 | version = "1.0.0-dev" 4 | authors = { workspace = true } 5 | edition = { workspace = true } 6 | repository = { workspace = true } 7 | 8 | [dependencies] 9 | # Arkworks 10 | ark-bls12-377 = { workspace = true } 11 | ark-ec = { workspace = true } 12 | ark-ff = { workspace = true } 13 | ark-std = { workspace = true } 14 | 15 | # Frontier 16 | fp-evm = { workspace = true } 17 | 18 | [dev-dependencies] 19 | # Frontier 20 | pallet-evm-test-vector-support = { workspace = true } 21 | 22 | [features] 23 | default = ["std"] 24 | std = [ 25 | # Arkworks 26 | "ark-bls12-377/std", 27 | "ark-ec/std", 28 | "ark-ff/std", 29 | "ark-std/std", 30 | 31 | # Frontier 32 | "fp-evm/std", 33 | ] 34 | -------------------------------------------------------------------------------- /frontier/frame/evm/precompile/bls12377/src/tests.rs: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // This file is part of Frontier. 3 | // 4 | // Copyright (c) 2020-2022 Parity Technologies (UK) Ltd. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | use super::*; 19 | use pallet_evm_test_vector_support::{ 20 | test_precompile_failure_test_vectors, test_precompile_test_vectors, 21 | }; 22 | 23 | #[test] 24 | fn process_consensus_tests() -> Result<(), String> { 25 | test_precompile_test_vectors::("../testdata/bls12377G1Add.json")?; 26 | test_precompile_test_vectors::("../testdata/bls12377G1Mul.json")?; 27 | test_precompile_test_vectors::("../testdata/bls12377G1MultiExp.json")?; 28 | test_precompile_test_vectors::("../testdata/bls12377G2Add.json")?; 29 | test_precompile_test_vectors::("../testdata/bls12377G2Mul.json")?; 30 | test_precompile_test_vectors::("../testdata/bls12377G2MultiExp.json")?; 31 | test_precompile_test_vectors::("../testdata/bls12377Pairing.json")?; 32 | Ok(()) 33 | } 34 | 35 | #[test] 36 | fn process_consensus_failure_tests() -> Result<(), String> { 37 | test_precompile_failure_test_vectors::("../testdata/fail-bls12377G1Add.json")?; 38 | test_precompile_failure_test_vectors::("../testdata/fail-bls12377G1Mul.json")?; 39 | test_precompile_failure_test_vectors::( 40 | "../testdata/fail-bls12377G1MultiExp.json", 41 | )?; 42 | test_precompile_failure_test_vectors::("../testdata/fail-bls12377G2Add.json")?; 43 | test_precompile_failure_test_vectors::("../testdata/fail-bls12377G2Mul.json")?; 44 | test_precompile_failure_test_vectors::( 45 | "../testdata/fail-bls12377G2MultiExp.json", 46 | )?; 47 | test_precompile_failure_test_vectors::( 48 | "../testdata/fail-bls12377Pairing.json", 49 | )?; 50 | Ok(()) 51 | } 52 | -------------------------------------------------------------------------------- /frontier/frame/evm/precompile/bn128/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "pallet-evm-precompile-bn128" 3 | version = "2.0.0-dev" 4 | license = "Apache-2.0" 5 | description = "BN128 precompiles for EVM pallet." 6 | authors = { workspace = true } 7 | edition = { workspace = true } 8 | repository = { workspace = true } 9 | 10 | [dependencies] 11 | bn = { workspace = true } 12 | # Substrate 13 | sp-core = { workspace = true } 14 | # Frontier 15 | fp-evm = { workspace = true } 16 | 17 | [dev-dependencies] 18 | # Frontier 19 | pallet-evm-test-vector-support = { workspace = true } 20 | 21 | [features] 22 | default = ["std"] 23 | std = [ 24 | # Substrate 25 | "sp-core/std", 26 | # Frontier 27 | "fp-evm/std", 28 | ] 29 | -------------------------------------------------------------------------------- /frontier/frame/evm/precompile/bw6761/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "pallet-evm-precompile-bw6761" 3 | version = "1.0.0-dev" 4 | authors = { workspace = true } 5 | edition = { workspace = true } 6 | repository = { workspace = true } 7 | 8 | [dependencies] 9 | # Arkworks 10 | ark-bw6-761 = { workspace = true } 11 | ark-ec = { workspace = true } 12 | ark-ff = { workspace = true } 13 | ark-std = { workspace = true } 14 | 15 | # Frontier 16 | fp-evm = { workspace = true } 17 | 18 | [dev-dependencies] 19 | # Frontier 20 | pallet-evm-test-vector-support = { workspace = true } 21 | 22 | [features] 23 | default = ["std"] 24 | std = [ 25 | # Arkworks 26 | "ark-bw6-761/std", 27 | "ark-ec/std", 28 | "ark-ff/std", 29 | "ark-std/std", 30 | 31 | # Frontier 32 | "fp-evm/std", 33 | ] 34 | -------------------------------------------------------------------------------- /frontier/frame/evm/precompile/bw6761/src/tests.rs: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // This file is part of Frontier. 3 | // 4 | // Copyright (c) 2020-2022 Parity Technologies (UK) Ltd. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | use super::*; 19 | use pallet_evm_test_vector_support::{ 20 | test_precompile_failure_test_vectors, test_precompile_test_vectors, 21 | }; 22 | 23 | #[test] 24 | fn process_consensus_tests() -> Result<(), String> { 25 | test_precompile_test_vectors::("../testdata/bw6761G1Add.json")?; 26 | test_precompile_test_vectors::("../testdata/bw6761G1Mul.json")?; 27 | test_precompile_test_vectors::("../testdata/bw6761G1MultiExp.json")?; 28 | test_precompile_test_vectors::("../testdata/bw6761G2Add.json")?; 29 | test_precompile_test_vectors::("../testdata/bw6761G2Mul.json")?; 30 | test_precompile_test_vectors::("../testdata/bw6761G2MultiExp.json")?; 31 | test_precompile_test_vectors::("../testdata/bw6761Pairing.json")?; 32 | Ok(()) 33 | } 34 | 35 | #[test] 36 | fn process_consensus_failure_tests() -> Result<(), String> { 37 | test_precompile_failure_test_vectors::("../testdata/fail-bw6761G1Add.json")?; 38 | test_precompile_failure_test_vectors::("../testdata/fail-bw6761G1Mul.json")?; 39 | test_precompile_failure_test_vectors::( 40 | "../testdata/fail-bw6761G1MultiExp.json", 41 | )?; 42 | test_precompile_failure_test_vectors::("../testdata/fail-bw6761G2Add.json")?; 43 | test_precompile_failure_test_vectors::("../testdata/fail-bw6761G2Mul.json")?; 44 | test_precompile_failure_test_vectors::( 45 | "../testdata/fail-bw6761G2MultiExp.json", 46 | )?; 47 | test_precompile_failure_test_vectors::("../testdata/fail-bw6761Pairing.json")?; 48 | Ok(()) 49 | } 50 | -------------------------------------------------------------------------------- /frontier/frame/evm/precompile/curve25519/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "pallet-evm-precompile-curve25519" 3 | version = "1.0.0-dev" 4 | authors = ["Parity Technologies ", "Drew Stone "] 5 | license = "Apache-2.0" 6 | description = "Curve25519 elliptic curve precompiles for EVM pallet." 7 | edition = { workspace = true } 8 | repository = { workspace = true } 9 | 10 | [dependencies] 11 | curve25519-dalek = { version = "4.0.0-rc.1", default-features = false, features = ["alloc"] } 12 | # Frontier 13 | fp-evm = { workspace = true } 14 | 15 | [features] 16 | default = ["std"] 17 | std = [ 18 | # Frontier 19 | "fp-evm/std", 20 | ] 21 | -------------------------------------------------------------------------------- /frontier/frame/evm/precompile/dispatch/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "pallet-evm-precompile-dispatch" 3 | version = "2.0.0-dev" 4 | license = "Apache-2.0" 5 | description = "DISPATCH precompiles for EVM pallet." 6 | authors = { workspace = true } 7 | edition = { workspace = true } 8 | repository = { workspace = true } 9 | 10 | [dependencies] 11 | # Substrate 12 | frame-support = { workspace = true } 13 | # Frontier 14 | fp-evm = { workspace = true } 15 | pallet-evm = { workspace = true } 16 | 17 | [dev-dependencies] 18 | scale-codec = { package = "parity-scale-codec", workspace = true } 19 | scale-info = { workspace = true } 20 | # Substrate 21 | frame-system = { workspace = true, features = ["default"] } 22 | pallet-balances = { workspace = true, features = ["default", "insecure_zero_ed"] } 23 | pallet-timestamp = { workspace = true, features = ["default"] } 24 | pallet-utility = { workspace = true, features = ["default"] } 25 | sp-core = { workspace = true, features = ["default"] } 26 | sp-io = { workspace = true, features = ["default"] } 27 | sp-runtime = { workspace = true, features = ["default"] } 28 | sp-std = { workspace = true, features = ["default"] } 29 | 30 | [features] 31 | default = ["std"] 32 | std = [ 33 | # Substrate 34 | "frame-support/std", 35 | # Frontier 36 | "fp-evm/std", 37 | "pallet-evm/std", 38 | ] 39 | -------------------------------------------------------------------------------- /frontier/frame/evm/precompile/ed25519/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "pallet-evm-precompile-ed25519" 3 | version = "2.0.0-dev" 4 | license = "Apache-2.0" 5 | description = "ED25519 precompiles for EVM pallet." 6 | authors = { workspace = true } 7 | edition = { workspace = true } 8 | repository = { workspace = true } 9 | 10 | [dependencies] 11 | ed25519-dalek = { version = "1.0.0", default-features = false, features = ["alloc", "u64_backend"] } 12 | # Frontier 13 | fp-evm = { workspace = true } 14 | 15 | [features] 16 | default = ["std"] 17 | std = [ 18 | # Frontier 19 | "fp-evm/std", 20 | ] 21 | -------------------------------------------------------------------------------- /frontier/frame/evm/precompile/modexp/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "pallet-evm-precompile-modexp" 3 | version = "2.0.0-dev" 4 | license = "Apache-2.0" 5 | description = "MODEXP precompiles for EVM pallet." 6 | authors = { workspace = true } 7 | edition = { workspace = true } 8 | repository = { workspace = true } 9 | 10 | [dependencies] 11 | num = { version = "0.4", default-features = false, features = ["alloc"] } 12 | # Frontier 13 | fp-evm = { workspace = true } 14 | 15 | [dev-dependencies] 16 | hex = { workspace = true } 17 | # Frontier 18 | pallet-evm-test-vector-support = { workspace = true } 19 | 20 | [features] 21 | default = ["std"] 22 | std = [ 23 | "num/std", 24 | # Frontier 25 | "fp-evm/std", 26 | ] 27 | -------------------------------------------------------------------------------- /frontier/frame/evm/precompile/sha3fips/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "pallet-evm-precompile-sha3fips" 3 | version = "2.0.0-dev" 4 | authors = ["Parity Technologies ", "Drew Stone "] 5 | license = "Apache-2.0" 6 | description = "SHA3 FIPS202 precompile for EVM pallet." 7 | edition = { workspace = true } 8 | repository = { workspace = true } 9 | 10 | [dependencies] 11 | tiny-keccak = { version = "2.0", features = ["fips202"] } 12 | # Frontier 13 | fp-evm = { workspace = true } 14 | 15 | [features] 16 | default = ["std"] 17 | std = [ 18 | # Frontier 19 | "fp-evm/std", 20 | ] 21 | -------------------------------------------------------------------------------- /frontier/frame/evm/precompile/simple/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "pallet-evm-precompile-simple" 3 | version = "2.0.0-dev" 4 | license = "Apache-2.0" 5 | description = "Simple precompiles for EVM pallet." 6 | edition = { workspace = true } 7 | repository = { workspace = true } 8 | 9 | [dependencies] 10 | ripemd = { version = "0.1", default-features = false } 11 | # Substrate 12 | sp-io = { workspace = true } 13 | # Frontier 14 | fp-evm = { workspace = true } 15 | 16 | [dev-dependencies] 17 | # Frontier 18 | pallet-evm-test-vector-support = { workspace = true } 19 | 20 | [features] 21 | default = ["std"] 22 | std = [ 23 | "ripemd/std", 24 | # Substrate 25 | "sp-io/std", 26 | # Frontier 27 | "fp-evm/std", 28 | ] 29 | -------------------------------------------------------------------------------- /frontier/frame/evm/precompile/testdata/ecRecover.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "Input": "a8b53bdf3306a35a7103ab5504a0c9b492295564b6202b1942a84ef300107281000000000000000000000000000000000000000000000000000000000000001b307835653165303366353363653138623737326363623030393366663731663366353366356337356237346463623331613835616138623838393262346538621122334455667788991011121314151617181920212223242526272829303132", 4 | "Expected": "", 5 | "Gas": 3000, 6 | "Name": "CallEcrecoverUnrecoverableKey", 7 | "NoBenchmark": false 8 | }, 9 | { 10 | "Input": "18c547e4f7b0f325ad1e56f57e26c745b09a3e503d86e00e5255ff7f715d3d1c000000000000000000000000000000000000000000000000000000000000001c73b1693892219d736caba55bdb67216e485557ea6b6af75f37096c9aa6a5a75feeb940b1d03b21e36b0e47e79769f095fe2ab855bd91e3a38756b7d75a9c4549", 11 | "Expected": "000000000000000000000000a94f5374fce5edbc8e2a8697c15331677e6ebf0b", 12 | "Gas": 3000, 13 | "Name": "ValidKey", 14 | "NoBenchmark": false 15 | }, 16 | { 17 | "Input": "38d18acb67d25c8bb9942764b62f18e17054f66a817bd4295423adf9ed98873e000000000000000000000000000000000000000000000000000000000000001b38d18acb67d25c8bb9942764b62f18e17054f66a817bd4295423adf9ed98873e789d1dd423d25f0772d2748d60f7e4b81bb14d086eba8e8e8efb6dcff8a4ae02", 18 | "Expected": "000000000000000000000000ceaccac640adf55b2028469bd36ba501f28b699d", 19 | "Name": "From contracts_test.go" 20 | } 21 | ] 22 | -------------------------------------------------------------------------------- /frontier/frame/evm/precompile/testdata/fail-bls12377G1Add.json: -------------------------------------------------------------------------------- 1 | [{"Input":"","ExpectedError":"invalid input length","Name":"invalid_input_length_empty"},{"Input":"","ExpectedError":"invalid input length","Name":"invalid_input_length_short"},{"Input":"0101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101","ExpectedError":"invalid input length","Name":"invalid_input_length_large"},{"Input":"01010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101","ExpectedError":"invalid Fq","Name":"violate_top_zero_bytes"},{"Input":"00000000000000000000000000000000017c18c6b2960463b342c4c0a224fdc680f054616db84d5bb73ef0ac74e03bfdb399ffbc2b7d0a1b0b3030375364efa300000000000000000000000000000000010d25278ded718c9b057cd3b9fd1d8794112d642c18a11078ffd00b4bf3b7f2d036f8573649f34d0c3973fc6657eb570000000000000000000000000000000001ae3a4617c510eac63b05c06ca1493b1a22d9f300f5138f1ef3622fba094800170b5d44300000008508c0000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","ExpectedError":"invalid Fq","Name":"large_field_element"},{"Input":"0000000000000000000000000000000000c6c2e86491ec9771f965bfa290484658b743025f0840751f2e50be8704f2b3888ec9c9ecb21e44ec73eab529dbe4eb0000000000000000000000000000000000ef40fe385fa8fb29faef11dda0a246446e3cd1796528f2a7bd0eb0be3f0d51ae0e6f22764a1888fe6ca21222942b1a000000000000000000000000000000000199e1755a3a4cdfa17454dba7fa7ac40715e575b43a4ed1f47408dc2e2c97d5433a142af15266349437b343298b4b94000000000000000000000000000000000192a7f9914c19174cfc3a865e64bc8da3952c1ed52e4e8f41fb45596faa52a6990f4e33da271b475122542ba8d5cf88","ExpectedError":"point is not on curve","Name":"point_not_on_curve"}] -------------------------------------------------------------------------------- /frontier/frame/evm/precompile/testdata/fail-bls12377G1Mul.json: -------------------------------------------------------------------------------- 1 | [{"Input":"","ExpectedError":"invalid input length","Name":"invalid_input_length_empty"},{"Input":"","ExpectedError":"invalid input length","Name":"invalid_input_length_short"},{"Input":"0101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101","ExpectedError":"invalid input length","Name":"invalid_input_length_large"},{"Input":"01010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101","ExpectedError":"invalid Fq","Name":"violate_top_zero_bytes"},{"Input":"0000000000000000000000000000000001ae3a4617c510eac63b05c06ca1493b1a22d9f300f5138f1ef3622fba094800170b5d44300000008508c00000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","ExpectedError":"invalid Fq","Name":"large_field_element"},{"Input":"000000000000000000000000000000000199e1755a3a4cdfa17454dba7fa7ac40715e575b43a4ed1f47408dc2e2c97d5433a142af15266349437b343298b4b94000000000000000000000000000000000192a7f9914c19174cfc3a865e64bc8da3952c1ed52e4e8f41fb45596faa52a6990f4e33da271b475122542ba8d5cf880000000000000000000000000000000000000000000000000000000000000000","ExpectedError":"point is not on curve","Name":"point_not_on_curve"}] -------------------------------------------------------------------------------- /frontier/frame/evm/precompile/testdata/fail-bw6761G1Add.json: -------------------------------------------------------------------------------- 1 | [{"Input":"","ExpectedError":"invalid input length","Name":"invalid_input_length_empty"},{"Input":"","ExpectedError":"invalid input length","Name":"invalid_input_length_short"},{"Input":"01010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101","ExpectedError":"invalid input length","Name":"invalid_input_length_large"},{"Input":"00843f49ff357946e0e5a0a84721d690f99362151f1da2787e199a6cf1b7a8efd853269ab172a026ac6723b4d6e52f4b78a092e3d630bd96d52f8d5a70fb12bbf21016a1f65401b2af5a6c514ccf92651e2484ab777c05f64a23982a564053ce003cee9d3cc2e6f9ca21014afacc1b976c4451d114979cbe045e76ba2a8f8d9028425b16ec0bcf75df8c6c9cbd4f53b6b3099727b5696b869dc42d1b3100c15a9ca95ecf2383a1d16ed0155a38bbe362234c0b9f814c015d6e25037c191ae1dc0122e824fb83ce0ad187c94004faff3eb926186a81d14688528275ef8087be41707ba638e584e91903cebaff25b423048689c8ed12f9fd9071dcd3dc73ebff2e98a116c25667a8f8160cf8aeeaf0a437e6913e6870000082f49d00000000008f000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","ExpectedError":"invalid Fq","Name":"large_field_element"},{"Input":"0091a18f79876ac313ee909dcd643a68c8f5946e3b5aca863fe09a078d9c6a1faa8ac31a1d28fe6cb3a306a906c8c4186769c5e5d138014cc4bc684e48c19887d566e92c3961f43d710ccc91370e39f9b590ef3581f21222279a36df018c500f0035bb86c53e8617144ed2aa3c80f313cf8b712cc35aa9839dd0ca841bb9265a2644d1c2693f1dca1dbba2942f30a33aa88a37348ef00abb8228ae98e24ff927e2a816b910bfea745b9a46fe1ecb536c0ba0b8cd8f18c552d5d98d6cc7ec68b600f80782be1355a952b2f60f2e3b0cc70ce497518b37fac950b0b38e196ac8420655274aa4601cce8a958d674ce064e99b4318feb13be3dd6b702907a7b9f4826f87b1ed3a9d97e776ca5928e34810f0563886005cc10587cf1dc3b803d77d51010395f7b84d0e70a5e002bd1a0f6b37f89b1ae3c90c2bf6a127c77e7b974cd4b899bc893c0e2af49a7eafca0e175a883e528231ecfb0d9352ea22a144b22747242356aa6a0c8d05c8111a56bc35b497f07d586ec7b026a50ac8ef747b50ead4","ExpectedError":"point is not on curve","Name":"point_not_on_curve"}] -------------------------------------------------------------------------------- /frontier/frame/evm/precompile/testdata/fail-bw6761G1Mul.json: -------------------------------------------------------------------------------- 1 | [{"Input":"","ExpectedError":"invalid input length","Name":"invalid_input_length_empty"},{"Input":"","ExpectedError":"invalid input length","Name":"invalid_input_length_short"},{"Input":"0101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101","ExpectedError":"invalid input length","Name":"invalid_input_length_large"},{"Input":"0122e824fb83ce0ad187c94004faff3eb926186a81d14688528275ef8087be41707ba638e584e91903cebaff25b423048689c8ed12f9fd9071dcd3dc73ebff2e98a116c25667a8f8160cf8aeeaf0a437e6913e6870000082f49d00000000008f00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","ExpectedError":"invalid Fq","Name":"large_field_element"},{"Input":"00f80782be1355a952b2f60f2e3b0cc70ce497518b37fac950b0b38e196ac8420655274aa4601cce8a958d674ce064e99b4318feb13be3dd6b702907a7b9f4826f87b1ed3a9d97e776ca5928e34810f0563886005cc10587cf1dc3b803d77d51010395f7b84d0e70a5e002bd1a0f6b37f89b1ae3c90c2bf6a127c77e7b974cd4b899bc893c0e2af49a7eafca0e175a883e528231ecfb0d9352ea22a144b22747242356aa6a0c8d05c8111a56bc35b497f07d586ec7b026a50ac8ef747b50ead400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","ExpectedError":"point is not on curve","Name":"point_not_on_curve"}] -------------------------------------------------------------------------------- /frontier/frame/evm/precompile/testdata/fail-bw6761G2Add.json: -------------------------------------------------------------------------------- 1 | [{"Input":"","ExpectedError":"invalid input length","Name":"invalid_input_length_empty"},{"Input":"","ExpectedError":"invalid input length","Name":"invalid_input_length_short"},{"Input":"01010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101","ExpectedError":"invalid input length","Name":"invalid_input_length_large"},{"Input":"002cf5a28d8f7db8387b1997aa79ba5724c540bcee1454fea72356d2f447f1d5904e99ff0212bb4cf508e28e18f249ef081899485fefc1249c02c29fdf4d329ebfbe298e5d157d1ce7e1707ff2c965385514391c87c1817b2049630f9eb857ce00ded23dc619dce7ad8bdc48f0f539be30eb35c54b7aa1d97782c732e9ba80608fbd339842663030c59ea69eb19383565cbe809aef94ef922bb4501162d59dbbad5fef6e8d1ee89e036706e535347afa016e57d599bd0b62e02ba439e2c335c10122e824fb83ce0ad187c94004faff3eb926186a81d14688528275ef8087be41707ba638e584e91903cebaff25b423048689c8ed12f9fd9071dcd3dc73ebff2e98a116c25667a8f8160cf8aeeaf0a437e6913e6870000082f49d00000000008f000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","ExpectedError":"invalid Fq","Name":"large_field_element"},{"Input":"005042a1a523264bb718f5d5af316ff4571b55a0a543623fffc6f2a8dd0ab5fe7dd88bf30fe58e911239d71240a564604ff0cd110b8913ab30106b97ec6c62bfe55f7e35cf0a9c52e300537e6e074e3b757433927008aae5212d9b1dc4c8c34d00157055308897ae7bb6f00b386f37ac097b678938a64f8840ea000bf4f725cb8e2bd8fd5d6ed7c1dbab7ee308baee7815f31a8cb581c4c81a3a6c2e041d6a965973657a02cda033990d60ea6d3e1794f09f6fb3e97c51ef4c556f84ce2b51fd00f80782be1355a952b2f60f2e3b0cc70ce497518b37fac950b0b38e196ac8420655274aa4601cce8a958d674ce064e99b4318feb13be3dd6b702907a7b9f4826f87b1ed3a9d97e776ca5928e34810f0563886005cc10587cf1dc3b803d77d51010395f7b84d0e70a5e002bd1a0f6b37f89b1ae3c90c2bf6a127c77e7b974cd4b899bc893c0e2af49a7eafca0e175a883e528231ecfb0d9352ea22a144b22747242356aa6a0c8d05c8111a56bc35b497f07d586ec7b026a50ac8ef747b50ead4","ExpectedError":"point is not on curve","Name":"point_not_on_curve"}] -------------------------------------------------------------------------------- /frontier/frame/evm/precompile/testdata/fail-bw6761G2Mul.json: -------------------------------------------------------------------------------- 1 | [{"Input":"","ExpectedError":"invalid input length","Name":"invalid_input_length_empty"},{"Input":"","ExpectedError":"invalid input length","Name":"invalid_input_length_short"},{"Input":"0101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101","ExpectedError":"invalid input length","Name":"invalid_input_length_large"},{"Input":"0122e824fb83ce0ad187c94004faff3eb926186a81d14688528275ef8087be41707ba638e584e91903cebaff25b423048689c8ed12f9fd9071dcd3dc73ebff2e98a116c25667a8f8160cf8aeeaf0a437e6913e6870000082f49d00000000008f00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","ExpectedError":"invalid Fq","Name":"large_field_element"},{"Input":"00f80782be1355a952b2f60f2e3b0cc70ce497518b37fac950b0b38e196ac8420655274aa4601cce8a958d674ce064e99b4318feb13be3dd6b702907a7b9f4826f87b1ed3a9d97e776ca5928e34810f0563886005cc10587cf1dc3b803d77d51010395f7b84d0e70a5e002bd1a0f6b37f89b1ae3c90c2bf6a127c77e7b974cd4b899bc893c0e2af49a7eafca0e175a883e528231ecfb0d9352ea22a144b22747242356aa6a0c8d05c8111a56bc35b497f07d586ec7b026a50ac8ef747b50ead400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","ExpectedError":"point is not on curve","Name":"point_not_on_curve"}] -------------------------------------------------------------------------------- /frontier/frame/evm/src/res/proof_size_test_callee_contract_bytecode.txt: -------------------------------------------------------------------------------- 1 | 6080604052348015600f57600080fd5b50607480601d6000396000f3fe6080604052348015600f57600080fd5b506004361060285760003560e01c8063ac4c25b214602d575b600080fd5b60336035565b005b6000600190505056fea2646970667358221220eae4df57558ab19ae5b916be34b7789b8e52d806b4680224965e76ab9554d77d64736f6c63430008120033 -------------------------------------------------------------------------------- /frontier/frame/evm/src/res/proof_size_test_contract_bytecode.txt: -------------------------------------------------------------------------------- 1 | 608060405234801561001057600080fd5b506006600081905550610410806100286000396000f3fe608060405234801561001057600080fd5b50600436106100575760003560e01c806335f56c3b1461005c5780634f3080a914610078578063944ddc6214610082578063c6d6f6061461008c578063e27a0ecd146100a8575b600080fd5b61007660048036038101906100719190610265565b6100c6565b005b610080610103565b005b61008a610115565b005b6100a660048036038101906100a191906102d0565b610189565b005b6100b06101ec565b6040516100bd9190610316565b60405180910390f35b60008173ffffffffffffffffffffffffffffffffffffffff1631905060008273ffffffffffffffffffffffffffffffffffffffff16319050505050565b60046000819055506005600081905550565b6000600190505b6001156101865760008160001b604051602001610139919061035c565b6040516020818303038152906040528051906020012060001c905060008173ffffffffffffffffffffffffffffffffffffffff1631905060018361017d91906103a6565b9250505061011c565b50565b8073ffffffffffffffffffffffffffffffffffffffff1663ac4c25b26040518163ffffffff1660e01b8152600401600060405180830381600087803b1580156101d157600080fd5b505af11580156101e5573d6000803e3d6000fd5b5050505050565b6000806000549050600080549050809250505090565b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b600061023282610207565b9050919050565b61024281610227565b811461024d57600080fd5b50565b60008135905061025f81610239565b92915050565b60006020828403121561027b5761027a610202565b5b600061028984828501610250565b91505092915050565b600061029d82610227565b9050919050565b6102ad81610292565b81146102b857600080fd5b50565b6000813590506102ca816102a4565b92915050565b6000602082840312156102e6576102e5610202565b5b60006102f4848285016102bb565b91505092915050565b6000819050919050565b610310816102fd565b82525050565b600060208201905061032b6000830184610307565b92915050565b6000819050919050565b6000819050919050565b61035661035182610331565b61033b565b82525050565b60006103688284610345565b60208201915081905092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b60006103b1826102fd565b91506103bc836102fd565b92508282019050808211156103d4576103d3610377565b5b9291505056fea26469706673582212202182fa69ea8e39cf4dcbadb7f3ccba2544ba38c9be05a5087cd41f59a174e1d164736f6c63430008120033 -------------------------------------------------------------------------------- /frontier/frame/evm/test-vector-support/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "pallet-evm-test-vector-support" 3 | version = "1.0.0-dev" 4 | license = "Apache-2.0" 5 | description = "Test vector support for EVM pallet." 6 | authors = { workspace = true } 7 | edition = { workspace = true } 8 | repository = { workspace = true } 9 | 10 | [dependencies] 11 | evm = { workspace = true, features = ["with-codec"] } 12 | hex = { workspace = true } 13 | serde = { workspace = true } 14 | serde_json = { workspace = true } 15 | # Substrate 16 | sp-core = { workspace = true, features = ["default"] } 17 | # Frontier 18 | fp-evm = { workspace = true, features = ["default"] } 19 | -------------------------------------------------------------------------------- /frontier/frame/hotfix-sufficients/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "pallet-hotfix-sufficients" 3 | version = "1.0.0" 4 | license = "Apache-2.0" 5 | readme = "README.md" 6 | description = "Hotfix zero-value account sufficients with non-zero-value nonces." 7 | authors = { workspace = true } 8 | edition = { workspace = true } 9 | repository = { workspace = true } 10 | 11 | [package.metadata.docs.rs] 12 | targets = ["x86_64-unknown-linux-gnu"] 13 | 14 | [dependencies] 15 | scale-codec = { package = "parity-scale-codec", workspace = true } 16 | scale-info = { workspace = true } 17 | # Substrate 18 | frame-benchmarking = { workspace = true, optional = true } 19 | frame-support = { workspace = true } 20 | frame-system = { workspace = true } 21 | sp-core = { workspace = true } 22 | sp-runtime = { workspace = true } 23 | sp-std = { workspace = true } 24 | # Frontier 25 | pallet-evm = { workspace = true } 26 | 27 | [dev-dependencies] 28 | # Substrate 29 | sp-io = { workspace = true, features = ["default"] } 30 | 31 | [features] 32 | default = ["std"] 33 | std = [ 34 | "scale-codec/std", 35 | "scale-info/std", 36 | # Substrate 37 | "frame-benchmarking?/std", 38 | "frame-support/std", 39 | "frame-system/std", 40 | "sp-core/std", 41 | "sp-runtime/std", 42 | "sp-std/std", 43 | # Frontier 44 | "pallet-evm/std", 45 | ] 46 | runtime-benchmarks = [ 47 | "frame-benchmarking/runtime-benchmarks", 48 | "frame-support/runtime-benchmarks", 49 | "frame-system/runtime-benchmarks", 50 | "pallet-evm/runtime-benchmarks", 51 | ] 52 | try-runtime = [ 53 | "frame-support/try-runtime", 54 | "frame-system/try-runtime", 55 | "pallet-evm/try-runtime", 56 | ] 57 | -------------------------------------------------------------------------------- /frontier/frame/hotfix-sufficients/src/benchmarking.rs: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // This file is part of Frontier. 3 | // 4 | // Copyright (c) 2020-2022 Parity Technologies (UK) Ltd. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | #![cfg(feature = "runtime-benchmarks")] 19 | 20 | use frame_benchmarking::{benchmarks, impl_benchmark_test_suite}; 21 | 22 | use super::*; 23 | 24 | benchmarks! { 25 | hotfix_inc_account_sufficients { 26 | // This benchmark tests the resource utilization by hotfixing N number of accounts 27 | // by incrementing their `sufficients` if `nonce` is > 0. 28 | 29 | let n in 0 .. 1000; 30 | 31 | use frame_benchmarking::{whitelisted_caller}; 32 | use sp_core::H160; 33 | use frame_system::RawOrigin; 34 | 35 | // The caller account is whitelisted for DB reads/write by the benchmarking macro. 36 | let caller: T::AccountId = whitelisted_caller(); 37 | let addresses = (0..n as u64) 38 | .map(H160::from_low_u64_le) 39 | .collect::>(); 40 | let accounts = addresses 41 | .iter() 42 | .cloned() 43 | .map(|addr| { 44 | let account_id = T::AddressMapping::into_account_id(addr); 45 | frame_system::Pallet::::inc_account_nonce(&account_id); 46 | assert_eq!(frame_system::Pallet::::sufficients(&account_id), 0); 47 | 48 | account_id 49 | }) 50 | .collect::>(); 51 | 52 | }: _(RawOrigin::Signed(caller), addresses) 53 | verify { 54 | accounts 55 | .iter() 56 | .for_each(|id| { 57 | assert_eq!(frame_system::Pallet::::sufficients(id), 1); 58 | }); 59 | } 60 | } 61 | 62 | impl_benchmark_test_suite!(Pallet, crate::mock::new_test_ext(), crate::mock::Test); 63 | -------------------------------------------------------------------------------- /frontier/frame/hotfix-sufficients/src/mock.rs: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // This file is part of Frontier. 3 | // 4 | // Copyright (c) 2021-2022 Parity Technologies (UK) Ltd. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | use frame_support::{parameter_types, traits::ConstU32, weights::Weight}; 19 | use sp_core::{H160, H256}; 20 | use sp_runtime::{ 21 | traits::{BlakeTwo256, IdentityLookup}, 22 | BuildStorage, 23 | }; 24 | 25 | use super::*; 26 | use crate as pallet_hotfix_sufficients; 27 | 28 | pub fn new_test_ext() -> sp_io::TestExternalities { 29 | frame_system::GenesisConfig::::default() 30 | .build_storage() 31 | .unwrap() 32 | .into() 33 | } 34 | 35 | frame_support::construct_runtime!( 36 | pub enum Test { 37 | System: frame_system::{Pallet, Call, Config, Storage, Event}, 38 | HotfixSufficients: pallet_hotfix_sufficients::{Pallet, Call}, 39 | } 40 | ); 41 | 42 | parameter_types! { 43 | pub const BlockHashCount: u64 = 250; 44 | pub BlockWeights: frame_system::limits::BlockWeights = 45 | frame_system::limits::BlockWeights::simple_max(Weight::from_parts(1024, 0)); 46 | } 47 | impl frame_system::Config for Test { 48 | type RuntimeEvent = RuntimeEvent; 49 | type BaseCallFilter = frame_support::traits::Everything; 50 | type BlockWeights = (); 51 | type BlockLength = (); 52 | type RuntimeOrigin = RuntimeOrigin; 53 | type RuntimeCall = RuntimeCall; 54 | type Nonce = u64; 55 | type Hash = H256; 56 | type Hashing = BlakeTwo256; 57 | type AccountId = H160; 58 | type Lookup = IdentityLookup; 59 | type Block = frame_system::mocking::MockBlock; 60 | type BlockHashCount = BlockHashCount; 61 | type DbWeight = (); 62 | type Version = (); 63 | type PalletInfo = PalletInfo; 64 | type AccountData = (); 65 | type OnNewAccount = (); 66 | type OnKilledAccount = (); 67 | type SystemWeightInfo = (); 68 | type SS58Prefix = (); 69 | type OnSetCode = (); 70 | type MaxConsumers = ConstU32<16>; 71 | } 72 | 73 | impl Config for Test { 74 | type AddressMapping = pallet_evm::IdentityAddressMapping; 75 | type WeightInfo = (); 76 | } 77 | -------------------------------------------------------------------------------- /frontier/primitives/account/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "fp-account" 3 | version = "1.0.0-dev" 4 | license = "Apache-2.0" 5 | description = "Primitives for Frontier AccountId20." 6 | authors = { workspace = true } 7 | edition = { workspace = true } 8 | repository = { workspace = true } 9 | 10 | [dependencies] 11 | hex = { workspace = true } 12 | impl-serde = { workspace = true, optional = true } 13 | libsecp256k1 = { workspace = true } 14 | log = { workspace = true } 15 | scale-codec = { package = "parity-scale-codec", workspace = true } 16 | scale-info = { workspace = true } 17 | serde = { workspace = true, optional = true } 18 | 19 | # Substrate 20 | sp-core = { workspace = true } 21 | sp-io = { workspace = true } 22 | sp-runtime = { workspace = true } 23 | sp-runtime-interface = { workspace = true } 24 | sp-std = { workspace = true } 25 | 26 | [dev-dependencies] 27 | 28 | [features] 29 | default = ["std"] 30 | std = [ 31 | "hex/std", 32 | "impl-serde/std", 33 | "libsecp256k1/std", 34 | "log/std", 35 | "scale-codec/std", 36 | "scale-info/std", 37 | "serde/std", 38 | # Substrate 39 | "sp-core/std", 40 | "sp-io/std", 41 | "sp-runtime/std", 42 | "sp-runtime-interface/std", 43 | "sp-std/std", 44 | ] 45 | serde = [ 46 | "dep:serde", 47 | "impl-serde", 48 | "scale-info/serde", 49 | "sp-core/serde", 50 | "sp-runtime/serde", 51 | ] 52 | -------------------------------------------------------------------------------- /frontier/primitives/consensus/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "fp-consensus" 3 | version = "2.0.0-dev" 4 | license = "Apache-2.0" 5 | description = "Primitives for Frontier consensus." 6 | authors = { workspace = true } 7 | edition = { workspace = true } 8 | repository = { workspace = true } 9 | 10 | [dependencies] 11 | ethereum = { workspace = true, features = ["with-codec"] } 12 | scale-codec = { package = "parity-scale-codec", workspace = true } 13 | # Substrate 14 | sp-core = { workspace = true } 15 | sp-runtime = { workspace = true } 16 | sp-std = { workspace = true } 17 | 18 | [features] 19 | default = ["std"] 20 | std = [ 21 | "ethereum/std", 22 | "scale-codec/std", 23 | # Substrate 24 | "sp-core/std", 25 | "sp-runtime/std", 26 | "sp-std/std", 27 | ] 28 | -------------------------------------------------------------------------------- /frontier/primitives/dynamic-fee/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "fp-dynamic-fee" 3 | version = "1.0.0" 4 | license = "Apache-2.0" 5 | description = "Dynamic fee inherent primitives for Ethereum RPC (web3) compatibility layer for Substrate." 6 | authors = { workspace = true } 7 | edition = { workspace = true } 8 | repository = { workspace = true } 9 | 10 | [package.metadata.docs.rs] 11 | targets = ["x86_64-unknown-linux-gnu"] 12 | 13 | [dependencies] 14 | async-trait = { workspace = true, optional = true } 15 | # Substrate 16 | sp-core = { workspace = true } 17 | sp-inherents = { workspace = true } 18 | 19 | [features] 20 | default = ["std"] 21 | std = [ 22 | "async-trait", 23 | # Substrate 24 | "sp-core/std", 25 | "sp-inherents/std", 26 | ] 27 | -------------------------------------------------------------------------------- /frontier/primitives/dynamic-fee/src/lib.rs: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // This file is part of Frontier. 3 | // 4 | // Copyright (c) 2022 Parity Technologies (UK) Ltd. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | //! Core types and inherents for dynamic fee. 19 | 20 | #![cfg_attr(not(feature = "std"), no_std)] 21 | #![deny(unused_crate_dependencies)] 22 | 23 | use sp_core::U256; 24 | use sp_inherents::InherentIdentifier; 25 | #[cfg(feature = "std")] 26 | use sp_inherents::{Error, InherentData}; 27 | 28 | pub const INHERENT_IDENTIFIER: InherentIdentifier = *b"dynfee0_"; 29 | 30 | pub type InherentType = U256; 31 | 32 | #[cfg(feature = "std")] 33 | pub struct InherentDataProvider(pub InherentType); 34 | 35 | #[cfg(feature = "std")] 36 | #[async_trait::async_trait] 37 | impl sp_inherents::InherentDataProvider for InherentDataProvider { 38 | async fn provide_inherent_data(&self, inherent_data: &mut InherentData) -> Result<(), Error> { 39 | inherent_data.put_data(INHERENT_IDENTIFIER, &self.0) 40 | } 41 | 42 | async fn try_handle_error( 43 | &self, 44 | _identifier: &InherentIdentifier, 45 | _error: &[u8], 46 | ) -> Option> { 47 | None 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /frontier/primitives/ethereum/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "fp-ethereum" 3 | version = "1.0.0-dev" 4 | license = "Apache-2.0" 5 | description = "Primitive Ethereum types." 6 | authors = { workspace = true } 7 | edition = { workspace = true } 8 | repository = { workspace = true } 9 | 10 | [package.metadata.docs.rs] 11 | targets = ["x86_64-unknown-linux-gnu"] 12 | 13 | [dependencies] 14 | ethereum = { workspace = true, features = ["with-codec"] } 15 | ethereum-types = { workspace = true } 16 | num_enum = { version = "0.6.1", default-features = false } 17 | scale-codec = { package = "parity-scale-codec", workspace = true } 18 | # Substrate 19 | frame-support = { workspace = true } 20 | sp-std = { workspace = true } 21 | # Frontier 22 | fp-evm = { workspace = true } 23 | 24 | [features] 25 | default = ["std"] 26 | std = [ 27 | "ethereum/std", 28 | "ethereum-types/std", 29 | "num_enum/std", 30 | "scale-codec/std", 31 | # Substrate 32 | "frame-support/std", 33 | "sp-std/std", 34 | # Frontier 35 | "fp-evm/std", 36 | ] 37 | -------------------------------------------------------------------------------- /frontier/primitives/evm/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "fp-evm" 3 | version = "3.0.0-dev" 4 | license = "Apache-2.0" 5 | description = "Primitive EVM abstractions for Substrate." 6 | authors = { workspace = true } 7 | edition = { workspace = true } 8 | repository = { workspace = true } 9 | 10 | [package.metadata.docs.rs] 11 | targets = ["x86_64-unknown-linux-gnu"] 12 | 13 | [dependencies] 14 | evm = { workspace = true, features = ["with-codec"] } 15 | scale-codec = { package = "parity-scale-codec", workspace = true } 16 | scale-info = { workspace = true } 17 | serde = { workspace = true, optional = true } 18 | # Substrate 19 | frame-support = { workspace = true } 20 | sp-core = { workspace = true } 21 | sp-runtime = { workspace = true } 22 | sp-std = { workspace = true } 23 | 24 | [features] 25 | default = ["std"] 26 | std = [ 27 | "evm/std", 28 | "evm/with-serde", 29 | "serde/std", 30 | "scale-codec/std", 31 | # Substrate 32 | "frame-support/std", 33 | "sp-core/std", 34 | "sp-runtime/std", 35 | "sp-std/std", 36 | ] 37 | serde = [ 38 | "dep:serde", 39 | "evm/with-serde", 40 | "scale-info/serde", 41 | "sp-core/serde", 42 | "sp-runtime/serde", 43 | ] 44 | -------------------------------------------------------------------------------- /frontier/primitives/rpc/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "fp-rpc" 3 | version = "3.0.0-dev" 4 | license = "Apache-2.0" 5 | description = "Runtime primitives for Ethereum RPC (web3) compatibility layer for Substrate." 6 | authors = { workspace = true } 7 | edition = { workspace = true } 8 | repository = { workspace = true } 9 | 10 | [package.metadata.docs.rs] 11 | targets = ["x86_64-unknown-linux-gnu"] 12 | 13 | [dependencies] 14 | ethereum = { workspace = true, features = ["with-codec"] } 15 | ethereum-types = { workspace = true } 16 | scale-codec = { package = "parity-scale-codec", workspace = true } 17 | scale-info = { workspace = true } 18 | # Substrate 19 | sp-api = { workspace = true } 20 | sp-core = { workspace = true } 21 | sp-runtime = { workspace = true } 22 | sp-state-machine = { workspace = true } 23 | sp-std = { workspace = true } 24 | # Frontier 25 | fp-evm = { workspace = true } 26 | 27 | [features] 28 | default = ["std"] 29 | std = [ 30 | "ethereum/std", 31 | "ethereum-types/std", 32 | "scale-codec/std", 33 | "scale-info/std", 34 | # Substrate 35 | "sp-api/std", 36 | "sp-state-machine/std", 37 | "sp-core/std", 38 | "sp-runtime/std", 39 | "sp-std/std", 40 | # Frontier 41 | "fp-evm/std", 42 | ] 43 | -------------------------------------------------------------------------------- /frontier/primitives/self-contained/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "fp-self-contained" 3 | version = "1.0.0-dev" 4 | license = "Apache-2.0" 5 | description = "Primitive Ethereum abstractions for Substrate." 6 | authors = { workspace = true } 7 | edition = { workspace = true } 8 | repository = { workspace = true } 9 | 10 | [package.metadata.docs.rs] 11 | targets = ["x86_64-unknown-linux-gnu"] 12 | 13 | [dependencies] 14 | scale-codec = { package = "parity-scale-codec", workspace = true } 15 | scale-info = { workspace = true } 16 | serde = { workspace = true, optional = true } 17 | # Substrate 18 | frame-support = { workspace = true } 19 | sp-runtime = { workspace = true } 20 | 21 | [features] 22 | default = ["std"] 23 | std = [ 24 | "scale-codec/std", 25 | "scale-info/std", 26 | "serde/std", 27 | # Substrate 28 | "frame-support/std", 29 | "sp-runtime/std", 30 | ] 31 | serde = [ 32 | "dep:serde", 33 | "scale-info/serde", 34 | "sp-runtime/serde", 35 | ] 36 | try-runtime = [ 37 | "sp-runtime/try-runtime", 38 | ] 39 | -------------------------------------------------------------------------------- /frontier/primitives/storage/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "fp-storage" 3 | version = "2.0.0" 4 | license = "Apache-2.0" 5 | description = "Storage primitives for Ethereum RPC (web3) compatibility layer for Substrate." 6 | authors = { workspace = true } 7 | edition = { workspace = true } 8 | repository = { workspace = true } 9 | 10 | [package.metadata.docs.rs] 11 | targets = ["x86_64-unknown-linux-gnu"] 12 | 13 | [dependencies] 14 | scale-codec = { package = "parity-scale-codec", workspace = true } 15 | serde = { workspace = true, optional = true } 16 | 17 | [features] 18 | default = ["std"] 19 | std = [ 20 | "scale-codec/std", 21 | "serde/std", 22 | ] 23 | serde = [ 24 | "dep:serde", 25 | ] 26 | -------------------------------------------------------------------------------- /frontier/primitives/storage/src/lib.rs: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // This file is part of Frontier. 3 | // 4 | // Copyright (c) 2020-2022 Parity Technologies (UK) Ltd. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | #![cfg_attr(not(feature = "std"), no_std)] 19 | #![deny(unused_crate_dependencies)] 20 | 21 | use scale_codec::{Decode, Encode}; 22 | 23 | /// Current version of pallet Ethereum's storage schema is stored under this key. 24 | pub const PALLET_ETHEREUM_SCHEMA: &[u8] = b":ethereum_schema"; 25 | /// Cached version of pallet Ethereum's storage schema is stored under this key in the AuxStore. 26 | pub const PALLET_ETHEREUM_SCHEMA_CACHE: &[u8] = b":ethereum_schema_cache"; 27 | 28 | /// Pallet Evm storage items 29 | pub const PALLET_EVM: &[u8] = b"EVM"; 30 | pub const EVM_ACCOUNT_CODES: &[u8] = b"AccountCodes"; 31 | pub const EVM_ACCOUNT_STORAGES: &[u8] = b"AccountStorages"; 32 | 33 | /// Pallet Ethereum storage items 34 | pub const PALLET_ETHEREUM: &[u8] = b"Ethereum"; 35 | pub const ETHEREUM_CURRENT_BLOCK: &[u8] = b"CurrentBlock"; 36 | pub const ETHEREUM_CURRENT_RECEIPTS: &[u8] = b"CurrentReceipts"; 37 | pub const ETHEREUM_CURRENT_TRANSACTION_STATUS: &[u8] = b"CurrentTransactionStatuses"; 38 | 39 | /// Pallet BaseFee storage items 40 | pub const PALLET_BASE_FEE: &[u8] = b"BaseFee"; 41 | pub const BASE_FEE_PER_GAS: &[u8] = b"BaseFeePerGas"; 42 | pub const BASE_FEE_ELASTICITY: &[u8] = b"Elasticity"; 43 | 44 | /// The schema version for Pallet Ethereum's storage 45 | #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Encode, Decode)] 46 | #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] 47 | pub enum EthereumStorageSchema { 48 | Undefined, 49 | V1, 50 | V2, 51 | V3, 52 | } 53 | 54 | impl Default for EthereumStorageSchema { 55 | fn default() -> Self { 56 | Self::Undefined 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /frontier/rust-toolchain: -------------------------------------------------------------------------------- 1 | [toolchain] 2 | channel = "nightly-2023-05-22" 3 | components = [ "rustfmt", "clippy" ] 4 | targets = [ "wasm32-unknown-unknown"] 5 | -------------------------------------------------------------------------------- /frontier/rustfmt.toml: -------------------------------------------------------------------------------- 1 | hard_tabs = true 2 | imports_granularity = "Crate" 3 | use_field_init_shorthand = true 4 | merge_derives = false 5 | -------------------------------------------------------------------------------- /frontier/scripts/benchmark.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # This script can be used for running frontier's benchmarks. 4 | # 5 | # The frontier binary is required to be compiled with --features=runtime-benchmarks 6 | # in release mode. 7 | 8 | set -e 9 | 10 | BINARY="./target/release/frontier-template-node" 11 | 12 | function choose_and_bench { 13 | readarray -t options < <(${BINARY} benchmark pallet --list | sed 1d) 14 | options+=('EXIT') 15 | 16 | select opt in "${options[@]}"; do 17 | IFS=', ' read -ra parts <<< "${opt}" 18 | echo "${parts[0]} -- ${parts[1]}" 19 | [[ "${opt}" == 'EXIT' ]] && exit 0 20 | 21 | bench "${parts[0]}" "${parts[1]}" 22 | break 23 | done 24 | } 25 | 26 | function bench { 27 | echo "benchmarking ${1}::${2}" 28 | WASMTIME_BACKTRACE_DETAILS=1 ${BINARY} benchmark pallet \ 29 | --chain=dev \ 30 | --steps=50 \ 31 | --repeat=20 \ 32 | --pallet="${1}" \ 33 | --extrinsic="${2}" \ 34 | --execution=wasm \ 35 | --wasm-execution=compiled \ 36 | --output=weights.rs \ 37 | --template=./benchmarking/frame-weight-template.hbs 38 | } 39 | 40 | if [[ $# -eq 1 && "${1}" == "--help" ]]; then 41 | echo "USAGE:" 42 | echo " ${0} [ ]" 43 | elif [[ $# -ne 2 ]]; then 44 | choose_and_bench 45 | else 46 | bench "${1}" "${2}" 47 | fi 48 | -------------------------------------------------------------------------------- /frontier/shell.nix: -------------------------------------------------------------------------------- 1 | let 2 | mozillaOverlay = 3 | import (builtins.fetchGit { 4 | url = "https://github.com/mozilla/nixpkgs-mozilla.git"; 5 | rev = "78e723925daf5c9e8d0a1837ec27059e61649cb6"; 6 | }); 7 | nixpkgs = import { overlays = [ mozillaOverlay ]; }; 8 | rust-nightly = with nixpkgs; ((rustChannelOf { date = "2022-11-15"; channel = "nightly"; }).rust.override { 9 | extensions = [ "rust-src" ]; 10 | targets = [ "wasm32-unknown-unknown" ]; 11 | }); 12 | in 13 | with nixpkgs; pkgs.mkShell { 14 | nativeBuildInputs = [ 15 | rust-nightly 16 | ]; 17 | buildInputs = [ 18 | clang 19 | rocksdb 20 | pkg-config 21 | openssl.dev 22 | ] ++ lib.optionals stdenv.isDarwin [ 23 | darwin.apple_sdk.frameworks.Security 24 | ]; 25 | 26 | RUST_SRC_PATH = "${rust-nightly}/lib/rustlib/src/rust/src"; 27 | LIBCLANG_PATH = "${llvmPackages.libclang.lib}/lib"; 28 | PROTOC = "${protobuf}/bin/protoc"; 29 | ROCKSDB_LIB_DIR = "${rocksdb}/lib"; 30 | } 31 | -------------------------------------------------------------------------------- /frontier/taplo.toml: -------------------------------------------------------------------------------- 1 | ## https://taplo.tamasfe.dev/configuration/#configuration-file 2 | 3 | include = ["**/Cargo.toml"] 4 | exclude = [".maintain/**/Cargo.toml", "target/**/Cargo.toml"] 5 | 6 | [formatting] 7 | # Align consecutive entries vertically. 8 | align_entries = false 9 | # Append trailing commas for multi-line arrays. 10 | array_trailing_comma = true 11 | # Expand arrays to multiple lines that exceed the maximum column width. 12 | array_auto_expand = true 13 | # Collapse arrays that don't exceed the maximum column width and don't contain comments. 14 | array_auto_collapse = false 15 | # Omit white space padding from single-line arrays 16 | compact_arrays = true 17 | # Omit white space padding from the start and end of inline tables. 18 | compact_inline_tables = false 19 | # Maximum column width in characters, affects array expansion and collapse, this doesn't take whitespace into account. 20 | # Note that this is not set in stone, and works on a best-effort basis. 21 | column_width = 160 22 | # Indent based on tables and arrays of tables and their subtables, subtables out of order are not indented. 23 | indent_tables = false 24 | # The substring that is used for indentation, should be tabs or spaces (but technically can be anything). 25 | indent_string = ' ' 26 | # Add trailing newline at the end of the file if not present. 27 | trailing_newline = true 28 | # Alphabetically reorder keys that are not separated by empty lines. 29 | reorder_keys = false 30 | # Maximum amount of allowed consecutive blank lines. This does not affect the whitespace at the end of the document, as it is always stripped. 31 | allowed_blank_lines = 1 32 | # Use CRLF for line endings. 33 | crlf = false 34 | 35 | [[rule]] 36 | keys = ["workspace.dependencies", "dependencies", "dev-dependencies", "build-dependencies"] 37 | formatting = { reorder_keys = true } 38 | -------------------------------------------------------------------------------- /frontier/template/.dockerignore: -------------------------------------------------------------------------------- 1 | **/target/ 2 | Dockerfile 3 | -------------------------------------------------------------------------------- /frontier/template/Dockerfile: -------------------------------------------------------------------------------- 1 | # Note: This is currently designed to simplify development 2 | # To get a smaller docker image, there should be 2 images generated, in 2 stages. 3 | 4 | FROM rustlang/rust:nightly 5 | 6 | 7 | ARG PROFILE=release 8 | WORKDIR /frontier 9 | 10 | # Upcd dates core parts 11 | RUN apt-get update -y && \ 12 | apt-get install -y cmake pkg-config libssl-dev git gcc build-essential clang libclang-dev protobuf-compiler 13 | 14 | # Install rust wasm. Needed for substrate wasm engine 15 | RUN rustup target add wasm32-unknown-unknown 16 | 17 | # Download Frontier repo 18 | RUN git clone https://github.com/paritytech/frontier /frontier 19 | RUN cd /frontier && git submodule init && git submodule update 20 | 21 | # Download rust dependencies and build the rust binary 22 | RUN cargo build "--$PROFILE" 23 | 24 | # 30333 for p2p traffic 25 | # 9933 for RPC call 26 | # 9944 for Websocket 27 | # 9615 for Prometheus (metrics) 28 | EXPOSE 30333 9933 9944 9615 29 | 30 | 31 | ENV PROFILE ${PROFILE} 32 | 33 | # The execution will re-compile the project to run it 34 | # This allows to modify the code and not have to re-compile the 35 | # dependencies. 36 | CMD cargo run --bin frontier-template-node "--$PROFILE" -- --dev 37 | -------------------------------------------------------------------------------- /frontier/template/LICENSE: -------------------------------------------------------------------------------- 1 | This is free and unencumbered software released into the public domain. 2 | 3 | Anyone is free to copy, modify, publish, use, compile, sell, or 4 | distribute this software, either in source code form or as a compiled 5 | binary, for any purpose, commercial or non-commercial, and by any 6 | means. 7 | 8 | In jurisdictions that recognize copyright laws, the author or authors 9 | of this software dedicate any and all copyright interest in the 10 | software to the public domain. We make this dedication for the benefit 11 | of the public at large and to the detriment of our heirs and 12 | successors. We intend this dedication to be an overt act of 13 | relinquishment in perpetuity of all present and future rights to this 14 | software under copyright law. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | For more information, please refer to 25 | -------------------------------------------------------------------------------- /frontier/template/examples/contract-erc20/.gitignore: -------------------------------------------------------------------------------- 1 | /build/ 2 | /node_modules/ 3 | -------------------------------------------------------------------------------- /frontier/template/examples/contract-erc20/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "frontier-template-contract-erc20", 3 | "version": "0.0.0", 4 | "dependencies": { 5 | "@polkadot/api": "^1.16.0-beta.2", 6 | "@polkadot/util-crypto": "^2.10.1", 7 | "ts-node": "^8.10.1", 8 | "typescript": "^3.9.3", 9 | "web3x": "^4.0.6" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /frontier/template/examples/contract-erc20/truffle/.gitignore: -------------------------------------------------------------------------------- 1 | /build/ 2 | /node_modules/ 3 | -------------------------------------------------------------------------------- /frontier/template/examples/contract-erc20/truffle/contracts/MyToken.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | import '@openzeppelin/contracts/token/ERC20/ERC20.sol'; 4 | 5 | // This ERC-20 contract mints the maximum amount of tokens to the contract creator. 6 | contract MyToken is ERC20 { 7 | constructor() public { 8 | _mint(msg.sender, 2**256 - 1); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /frontier/template/examples/contract-erc20/truffle/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "substrate-evm-contracts", 3 | "version": "0.0.0", 4 | "dependencies": { 5 | "@openzeppelin/contracts": "^4.9.2", 6 | "truffle": "^5.6.7" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /frontier/template/examples/contract-erc20/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "esModuleInterop": true 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /frontier/template/examples/contract-hello/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | -------------------------------------------------------------------------------- /frontier/template/examples/contract-hello/Hello.sol: -------------------------------------------------------------------------------- 1 | pragma solidity =0.5.15; 2 | 3 | contract Hello { 4 | event Said(string message); 5 | address public owner; 6 | 7 | constructor() public { 8 | owner = msg.sender; 9 | emit Said("Hello, world!"); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /frontier/template/examples/contract-hello/index.js: -------------------------------------------------------------------------------- 1 | const Web3 = require('web3'); 2 | const web3 = new Web3('http://127.0.0.1:8545'); 3 | 4 | const ABI = [{"inputs":[],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"string","name":"message","type":"string"}],"name":"Said","type":"event"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"}]; 5 | const BYTECODE = "0x608060405234801561001057600080fd5b50336000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055507fc68045c3c562488255b55aa2c4c7849de001859ff0d8a36a75c2d5ed80100fb660405180806020018281038252600d8152602001807f48656c6c6f2c20776f726c64210000000000000000000000000000000000000081525060200191505060405180910390a160cf806100c76000396000f3fe6080604052348015600f57600080fd5b506004361060285760003560e01c80638da5cb5b14602d575b600080fd5b60336075565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff168156fea265627a7a72315820fae816ad954005c42bea7bc7cb5b19f7fd5d3a250715ca2023275c9ca7ce644064736f6c634300050f0032"; 6 | 7 | const main = async () => { 8 | const devAccount = web3.eth.accounts.create(); 9 | 10 | const createTransaction = await web3.eth.accounts.signTransaction({ 11 | from: devAccount.address, 12 | data: BYTECODE, 13 | value: "0x00", 14 | gasPrice: "0x00", 15 | gas: "0x100000", 16 | }, devAccount.privateKey); 17 | console.log(createTransaction); 18 | 19 | const createReceipt = await web3.eth.sendSignedTransaction(createTransaction.rawTransaction); 20 | console.log("Contract deployed at address", createReceipt.contractAddress); 21 | }; 22 | 23 | main(); 24 | -------------------------------------------------------------------------------- /frontier/template/examples/contract-hello/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "frontier-example-contract-hello", 3 | "version": "0.1.0", 4 | "description": "Hello contract example for Frontier project", 5 | "main": "index.js", 6 | "repository": { 7 | "type": "git", 8 | "url": "git+https://github.com/paritytech/frontier.git" 9 | }, 10 | "keywords": [ 11 | "ethereum", 12 | "substrate" 13 | ], 14 | "author": "Parity Technologies ", 15 | "license": "GPL-3.0", 16 | "bugs": { 17 | "url": "https://github.com/paritytech/frontier/issues" 18 | }, 19 | "homepage": "https://github.com/paritytech/frontier", 20 | "dependencies": { 21 | "web3": "^1.8.0" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /frontier/template/node/build.rs: -------------------------------------------------------------------------------- 1 | use substrate_build_script_utils::{generate_cargo_keys, rerun_if_git_head_changed}; 2 | 3 | fn main() { 4 | generate_cargo_keys(); 5 | 6 | rerun_if_git_head_changed(); 7 | } 8 | -------------------------------------------------------------------------------- /frontier/template/node/src/cli.rs: -------------------------------------------------------------------------------- 1 | use crate::service::EthConfiguration; 2 | 3 | /// Available Sealing methods. 4 | #[derive(Copy, Clone, Debug, Default, clap::ValueEnum)] 5 | pub enum Sealing { 6 | /// Seal using rpc method. 7 | #[default] 8 | Manual, 9 | /// Seal when transaction is executed. 10 | Instant, 11 | } 12 | 13 | #[derive(Debug, clap::Parser)] 14 | pub struct Cli { 15 | #[command(subcommand)] 16 | pub subcommand: Option, 17 | 18 | #[allow(missing_docs)] 19 | #[command(flatten)] 20 | pub run: sc_cli::RunCmd, 21 | 22 | /// Choose sealing method. 23 | #[arg(long, value_enum, ignore_case = true)] 24 | pub sealing: Option, 25 | 26 | #[command(flatten)] 27 | pub eth: EthConfiguration, 28 | } 29 | 30 | #[derive(Debug, clap::Subcommand)] 31 | pub enum Subcommand { 32 | /// Key management cli utilities 33 | #[command(subcommand)] 34 | Key(sc_cli::KeySubcommand), 35 | 36 | /// Build a chain specification. 37 | BuildSpec(sc_cli::BuildSpecCmd), 38 | 39 | /// Validate blocks. 40 | CheckBlock(sc_cli::CheckBlockCmd), 41 | 42 | /// Export blocks. 43 | ExportBlocks(sc_cli::ExportBlocksCmd), 44 | 45 | /// Export the state of a given block into a chain spec. 46 | ExportState(sc_cli::ExportStateCmd), 47 | 48 | /// Import blocks. 49 | ImportBlocks(sc_cli::ImportBlocksCmd), 50 | 51 | /// Remove the whole chain. 52 | PurgeChain(sc_cli::PurgeChainCmd), 53 | 54 | /// Revert the chain to a previous state. 55 | Revert(sc_cli::RevertCmd), 56 | 57 | /// Sub-commands concerned with benchmarking. 58 | #[cfg(feature = "runtime-benchmarks")] 59 | #[command(subcommand)] 60 | Benchmark(frame_benchmarking_cli::BenchmarkCmd), 61 | 62 | /// Sub-commands concerned with benchmarking. 63 | #[cfg(not(feature = "runtime-benchmarks"))] 64 | Benchmark, 65 | 66 | /// Db meta columns information. 67 | FrontierDb(fc_cli::FrontierDbCmd), 68 | } 69 | -------------------------------------------------------------------------------- /frontier/template/node/src/main.rs: -------------------------------------------------------------------------------- 1 | //! Substrate Node Template CLI library. 2 | 3 | #![warn(missing_docs)] 4 | #![allow( 5 | clippy::type_complexity, 6 | clippy::too_many_arguments, 7 | clippy::large_enum_variant 8 | )] 9 | #![cfg_attr(feature = "runtime-benchmarks", deny(unused_crate_dependencies))] 10 | 11 | #[cfg(feature = "runtime-benchmarks")] 12 | mod benchmarking; 13 | mod chain_spec; 14 | mod cli; 15 | mod client; 16 | mod command; 17 | mod eth; 18 | mod rpc; 19 | mod service; 20 | 21 | fn main() -> sc_cli::Result<()> { 22 | command::run() 23 | } 24 | -------------------------------------------------------------------------------- /frontier/template/runtime/build.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | #[cfg(feature = "std")] 3 | substrate_wasm_builder::WasmBuilder::new() 4 | .with_current_project() 5 | .export_heap_base() 6 | .import_memory() 7 | .build() 8 | } 9 | -------------------------------------------------------------------------------- /frontier/template/runtime/src/precompiles.rs: -------------------------------------------------------------------------------- 1 | use pallet_evm::{ 2 | IsPrecompileResult, Precompile, PrecompileHandle, PrecompileResult, PrecompileSet, 3 | }; 4 | use sp_core::H160; 5 | use sp_std::marker::PhantomData; 6 | 7 | use pallet_evm_precompile_modexp::Modexp; 8 | use pallet_evm_precompile_sha3fips::Sha3FIPS256; 9 | use pallet_evm_precompile_simple::{ECRecover, ECRecoverPublicKey, Identity, Ripemd160, Sha256}; 10 | 11 | pub struct FrontierPrecompiles(PhantomData); 12 | 13 | impl FrontierPrecompiles 14 | where 15 | R: pallet_evm::Config, 16 | { 17 | pub fn new() -> Self { 18 | Self(Default::default()) 19 | } 20 | pub fn used_addresses() -> [H160; 7] { 21 | [ 22 | hash(1), 23 | hash(2), 24 | hash(3), 25 | hash(4), 26 | hash(5), 27 | hash(1024), 28 | hash(1025), 29 | ] 30 | } 31 | } 32 | impl PrecompileSet for FrontierPrecompiles 33 | where 34 | R: pallet_evm::Config, 35 | { 36 | fn execute(&self, handle: &mut impl PrecompileHandle) -> Option { 37 | match handle.code_address() { 38 | // Ethereum precompiles : 39 | a if a == hash(1) => Some(ECRecover::execute(handle)), 40 | a if a == hash(2) => Some(Sha256::execute(handle)), 41 | a if a == hash(3) => Some(Ripemd160::execute(handle)), 42 | a if a == hash(4) => Some(Identity::execute(handle)), 43 | a if a == hash(5) => Some(Modexp::execute(handle)), 44 | // Non-Frontier specific nor Ethereum precompiles : 45 | a if a == hash(1024) => Some(Sha3FIPS256::execute(handle)), 46 | a if a == hash(1025) => Some(ECRecoverPublicKey::execute(handle)), 47 | _ => None, 48 | } 49 | } 50 | 51 | fn is_precompile(&self, address: H160, _gas: u64) -> IsPrecompileResult { 52 | IsPrecompileResult::Answer { 53 | is_precompile: Self::used_addresses().contains(&address), 54 | extra_cost: 0, 55 | } 56 | } 57 | } 58 | 59 | fn hash(a: u64) -> H160 { 60 | H160::from_low_u64_be(a) 61 | } 62 | -------------------------------------------------------------------------------- /frontier/template/utils/.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules/ 2 | -------------------------------------------------------------------------------- /frontier/template/utils/erc20-slot.js: -------------------------------------------------------------------------------- 1 | const help = `--erc20-slot
: Calculate the storage slot for an (EVM) address's ERC-20 balance, where is the storage slot for the ERC-20 balances map.`; 2 | 3 | module.exports = () => { 4 | if (process.argv.length < 5) { 5 | console.error('Please provide both the and
parameters.'); 6 | console.error(help); 7 | process.exit(9); 8 | } 9 | 10 | const slot = process.argv[3]; 11 | const address = process.argv[4]; 12 | if (!address.match(/^0x[a-f0-9]{40}$/)) { 13 | console.error('Please enter a valid EVM address.'); 14 | console.error(help); 15 | process.exit(9); 16 | } 17 | 18 | const mapStorageSlot = slot.padStart(64, '0'); 19 | const mapKey = address.substring(2).padStart(64, '0'); 20 | 21 | console.log('0x'.concat(mapKey.concat(mapStorageSlot))) 22 | const web3 = require('web3'); 23 | return web3.utils.sha3('0x'.concat(mapKey.concat(mapStorageSlot))); 24 | }; 25 | -------------------------------------------------------------------------------- /frontier/template/utils/evm-address.js: -------------------------------------------------------------------------------- 1 | const help = `--evm-address
: Calculate the EVM address that corresponds to a native Substrate address.`; 2 | 3 | module.exports = () => { 4 | if (process.argv.length < 4) { 5 | console.error('Please provide the
parameter.'); 6 | console.error(help); 7 | process.exit(9); 8 | } 9 | 10 | const address = process.argv[3]; 11 | if (!address.match(/^[A-z0-9]{48}$/)) { 12 | console.error('Please enter a valid Substrate address.'); 13 | console.error(help); 14 | process.exit(9); 15 | } 16 | 17 | const crypto = require('@polkadot/util-crypto'); 18 | return `0x${crypto.blake2AsHex(crypto.decodeAddress(address), 256).substring(26)}`; 19 | }; 20 | -------------------------------------------------------------------------------- /frontier/template/utils/index.js: -------------------------------------------------------------------------------- 1 | const help = 2 | `--erc20-slot
: Calculate the storage slot for an (EVM) address's ERC-20 balance, where is the storage slot for the ERC-20 balances map. 3 | --evm-address
: Calculate the EVM address that corresponds to a native Substrate address. 4 | --help: Print this message.`; 5 | 6 | if (process.argv.length < 3) { 7 | console.error('Please provide a command.'); 8 | console.error(help); 9 | process.exit(9); 10 | } 11 | 12 | const command = process.argv[2]; 13 | switch (command) { 14 | case "--erc20-slot": 15 | console.log(require('./erc20-slot')()); 16 | break; 17 | case "--evm-address": 18 | console.log(require('./evm-address')()); 19 | break; 20 | case "--help": 21 | console.log(help); 22 | break; 23 | default: 24 | console.error(`Unrecognized command: ${command}.`); 25 | console.error(help); 26 | process.exit(9); 27 | } 28 | -------------------------------------------------------------------------------- /frontier/template/utils/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "substrate-evm-utils", 3 | "version": "0.0.0", 4 | "dependencies": { 5 | "@polkadot/util-crypto": "^2.2.1", 6 | "keccak": "^3.0.0", 7 | "web3": "^1.8.0" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /frontier/ts-tests/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | frontier-test-tmp 3 | build/ 4 | -------------------------------------------------------------------------------- /frontier/ts-tests/.prettierrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | printWidth: 120, 3 | useTabs: true, 4 | tabWidth: 4 5 | } 6 | -------------------------------------------------------------------------------- /frontier/ts-tests/contracts/ECRecoverTests.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.8.2; 2 | 3 | contract ECRecoverTests { 4 | function ecrecover(bytes memory input) public returns(bytes memory) { 5 | address ecrecoverAddress = address(0x0000000000000000000000000000000000000001); 6 | (bool success, bytes memory returnData) = ecrecoverAddress.call(input); 7 | return returnData; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /frontier/ts-tests/contracts/ExplicitRevertReason.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.8.2; 2 | 3 | contract ExplicitRevertReason { 4 | function max10(uint256 a) public returns (uint256) { 5 | if (a > 10) 6 | revert("Value must not be greater than 10."); 7 | return a; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /frontier/ts-tests/contracts/ForceGasLimit.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | contract ForceGasLimit { 6 | uint public number; 7 | function force_gas(uint require_gas) public returns (uint) { 8 | require(gasleft() > require_gas, "not enough gas"); 9 | number++; 10 | return number; 11 | } 12 | } -------------------------------------------------------------------------------- /frontier/ts-tests/contracts/InvalidOpcode.sol: -------------------------------------------------------------------------------- 1 | pragma solidity >=0.8.0; 2 | 3 | contract InvalidOpcode { 4 | uint public number; 5 | 6 | function call() public { 7 | number = 1; 8 | if (gasleft() < 40000 ){ 9 | assembly { 10 | // Calls the INVALID opcode (0xFE) 11 | invalid() 12 | } 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /frontier/ts-tests/contracts/StateOverrideTest.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | pragma solidity >=0.8.0; 3 | 4 | /// @notice Smart contract to help test state override 5 | contract StateOverrideTest { 6 | /// @notice The maxmium allowed value 7 | uint256 public MAX_ALLOWED = 3; 8 | uint256 public availableFunds; 9 | mapping(address => mapping(address => uint256)) public allowance; 10 | 11 | address owner; 12 | 13 | constructor(uint256 intialAmount) payable { 14 | owner = msg.sender; 15 | availableFunds = intialAmount; 16 | } 17 | 18 | function getBalance() external view returns (uint256) { 19 | return address(this).balance; 20 | } 21 | 22 | function getSenderBalance() external view returns (uint256) { 23 | return address(msg.sender).balance; 24 | } 25 | 26 | function getAllowance(address from, address who) 27 | external 28 | view 29 | returns (uint256) 30 | { 31 | return allowance[from][who]; 32 | } 33 | 34 | function setAllowance(address who, uint256 amount) external { 35 | allowance[address(msg.sender)][who] = amount; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /frontier/ts-tests/contracts/Storage.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.8.2; 2 | 3 | contract Storage { 4 | function getStorage(bytes32 key) public view returns (bytes32 value) { 5 | assembly { 6 | value := sload(key) 7 | } 8 | } 9 | function setStorage(bytes32 key, bytes32 value) public { 10 | assembly { 11 | sstore(key, value) 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /frontier/ts-tests/contracts/StorageLoop.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0 2 | pragma solidity >=0.8.2 <0.9.0; 3 | 4 | contract StorageLoop { 5 | mapping(address => uint) public map; 6 | 7 | // n=1 30k 8 | // n=10 37k 9 | // n=100 100k 10 | // n=250 205k 11 | // n=500 380k 12 | // n=1000 745k 13 | function storageLoop( 14 | uint16 n, 15 | address _to, 16 | uint _amount 17 | ) public { 18 | for (uint16 i = 0; i < n; i++) { 19 | map[_to] += _amount; 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /frontier/ts-tests/contracts/Test.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.8.2; 2 | 3 | contract Test { 4 | function multiply(uint a) public pure returns(uint d) { 5 | return a * 7; 6 | } 7 | function gasLimit() public view returns(uint) { 8 | return block.gaslimit; 9 | } 10 | function currentBlock() public view returns(uint) { 11 | return block.number; 12 | } 13 | function blockHash(uint number) public view returns(bytes32) { 14 | return blockhash(number); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /frontier/ts-tests/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ts-tests", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "fmt-check": "prettier ./tests --check", 8 | "fmt": "prettier ./tests --write", 9 | "build": "truffle compile", 10 | "test": "mocha -r ts-node/register 'tests/**/*.ts'", 11 | "test-sql": "FRONTIER_BACKEND_TYPE='sql' mocha -r ts-node/register 'tests/**/*.ts'" 12 | }, 13 | "author": "", 14 | "license": "ISC", 15 | "dependencies": { 16 | "@types/chai": "^4.3.5", 17 | "@types/mocha": "^10.0.1", 18 | "chai": "^4.3.7", 19 | "chai-as-promised": "^7.1.1", 20 | "ethers": "^6.3.0", 21 | "mocha": "^10.2.0", 22 | "mocha-steps": "^1.3.0", 23 | "rimraf": "^5.0.0", 24 | "truffle": "^5.8.4", 25 | "ts-node": "^10.9.1", 26 | "typescript": "^4.9.5", 27 | "web3": "^1.9.0" 28 | }, 29 | "devDependencies": { 30 | "@types/chai-as-promised": "^7.1.5", 31 | "prettier": "^2.8.8" 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /frontier/ts-tests/tests/test-balance.ts: -------------------------------------------------------------------------------- 1 | import { expect } from "chai"; 2 | import { step } from "mocha-steps"; 3 | 4 | import { GENESIS_ACCOUNT, GENESIS_ACCOUNT_PRIVATE_KEY, GENESIS_ACCOUNT_BALANCE, EXISTENTIAL_DEPOSIT } from "./config"; 5 | import { createAndFinalizeBlock, describeWithFrontier, customRequest } from "./util"; 6 | 7 | describeWithFrontier("Frontier RPC (Balance)", (context) => { 8 | const TEST_ACCOUNT = "0x1111111111111111111111111111111111111111"; 9 | 10 | step("genesis balance is setup correctly", async function () { 11 | expect(await context.web3.eth.getBalance(GENESIS_ACCOUNT)).to.equal(GENESIS_ACCOUNT_BALANCE); 12 | }); 13 | 14 | step("balance to be updated after transfer", async function () { 15 | await createAndFinalizeBlock(context.web3); 16 | this.timeout(15000); 17 | 18 | const value = "0x200"; // 512, must be higher than ExistentialDeposit 19 | const gasPrice = "0x3B9ACA00"; // 1000000000 20 | const tx = await context.web3.eth.accounts.signTransaction( 21 | { 22 | from: GENESIS_ACCOUNT, 23 | to: TEST_ACCOUNT, 24 | value: value, 25 | gasPrice: gasPrice, 26 | gas: "0x100000", 27 | }, 28 | GENESIS_ACCOUNT_PRIVATE_KEY 29 | ); 30 | await customRequest(context.web3, "eth_sendRawTransaction", [tx.rawTransaction]); 31 | 32 | // GENESIS_ACCOUNT_BALANCE - (21000 * gasPrice) - value; 33 | const expectedGenesisBalance = ( 34 | BigInt(GENESIS_ACCOUNT_BALANCE) - 35 | BigInt(21000) * BigInt(gasPrice) - 36 | BigInt(value) 37 | ).toString(); 38 | const expectedTestBalance = (Number(value) - EXISTENTIAL_DEPOSIT).toString(); 39 | expect(await context.web3.eth.getBalance(GENESIS_ACCOUNT, "pending")).to.equal(expectedGenesisBalance); 40 | expect(await context.web3.eth.getBalance(TEST_ACCOUNT, "pending")).to.equal(expectedTestBalance); 41 | 42 | await createAndFinalizeBlock(context.web3); 43 | 44 | expect(await context.web3.eth.getBalance(GENESIS_ACCOUNT)).to.equal(expectedGenesisBalance); 45 | expect(await context.web3.eth.getBalance(TEST_ACCOUNT)).to.equal(expectedTestBalance); 46 | }); 47 | }); 48 | -------------------------------------------------------------------------------- /frontier/ts-tests/tests/test-block-tags.ts: -------------------------------------------------------------------------------- 1 | import { expect } from "chai"; 2 | import { step } from "mocha-steps"; 3 | 4 | import { GENESIS_ACCOUNT, GENESIS_ACCOUNT_PRIVATE_KEY, GENESIS_ACCOUNT_BALANCE, EXISTENTIAL_DEPOSIT } from "./config"; 5 | import { createAndFinalizeBlock, describeWithFrontier, customRequest } from "./util"; 6 | 7 | describeWithFrontier("Frontier RPC (BlockNumber tags)", (context) => { 8 | before("Send some transactions across blocks", async function () { 9 | // block #1 finalized 10 | await createAndFinalizeBlock(context.web3); 11 | // block #2 not finalized 12 | await createAndFinalizeBlock(context.web3, false); 13 | }); 14 | 15 | step("`earliest` returns genesis", async function () { 16 | expect((await context.web3.eth.getBlock("earliest")).number).to.equal(0); 17 | }); 18 | 19 | step("`latest` returns `BlockchainInfo::best_hash` number", async function () { 20 | expect((await context.web3.eth.getBlock("latest")).number).to.equal(2); 21 | }); 22 | 23 | step("`finalized` uses `BlockchainInfo::finalized_hash` number", async function () { 24 | expect((await context.web3.eth.getBlock("finalized")).number).to.equal(1); 25 | }); 26 | 27 | step("`safe` is an alias for `finalized` in Polkadot", async function () { 28 | expect((await context.web3.eth.getBlock("safe")).number).to.equal(1); 29 | }); 30 | }); 31 | -------------------------------------------------------------------------------- /frontier/ts-tests/tests/test-deprecated.ts: -------------------------------------------------------------------------------- 1 | import { expect } from "chai"; 2 | 3 | import { customRequest, describeWithFrontier } from "./util"; 4 | 5 | describeWithFrontier("Frontier RPC (Deprecated)", (context) => { 6 | // List of deprecated methods 7 | [ 8 | { method: "eth_getCompilers", params: [] }, 9 | { 10 | method: "eth_compileLLL", 11 | params: ["(returnlll (suicide (caller)))"], 12 | }, 13 | { 14 | method: "eth_compileSolidity", 15 | params: ["contract test { function multiply(uint a) returns(uint d) {return a * 7;}}"], 16 | }, 17 | { method: "eth_compileSerpent", params: ["/* some serpent */"] }, 18 | ].forEach(({ method, params }) => { 19 | it(`${method} should be deprecated`, async function () { 20 | expect(await customRequest(context.web3, method, params)).to.deep.equal({ 21 | id: 1, 22 | jsonrpc: "2.0", 23 | error: { message: `Method not found`, code: -32601 }, 24 | }); 25 | }); 26 | }); 27 | }); 28 | -------------------------------------------------------------------------------- /frontier/ts-tests/tests/test-netapi.ts: -------------------------------------------------------------------------------- 1 | import { expect } from "chai"; 2 | import { step } from "mocha-steps"; 3 | 4 | import { CHAIN_ID } from "./config"; 5 | import { describeWithFrontier, customRequest } from "./util"; 6 | 7 | describeWithFrontier("Frontier RPC (Net)", (context) => { 8 | step("should return `net_version`", async function () { 9 | expect(await context.web3.eth.net.getId()).to.equal(CHAIN_ID); 10 | }); 11 | step("should return `peer_count` in hex directly using the provider", async function () { 12 | expect((await customRequest(context.web3, "net_peerCount", [])).result).to.be.eq("0x0"); 13 | }); 14 | step("should format `peer_count` as decimal using `web3.net`", async function () { 15 | expect(await context.web3.eth.net.getPeerCount()).to.equal(0); 16 | }); 17 | }); 18 | -------------------------------------------------------------------------------- /frontier/ts-tests/tests/test-nonce.ts: -------------------------------------------------------------------------------- 1 | import { expect } from "chai"; 2 | import { step } from "mocha-steps"; 3 | 4 | import { GENESIS_ACCOUNT, GENESIS_ACCOUNT_PRIVATE_KEY } from "./config"; 5 | import { createAndFinalizeBlock, describeWithFrontier, customRequest } from "./util"; 6 | 7 | describeWithFrontier("Frontier RPC (Nonce)", (context) => { 8 | const TEST_ACCOUNT = "0x1111111111111111111111111111111111111111"; 9 | 10 | step("get nonce", async function () { 11 | this.timeout(10_000); 12 | const tx = await context.web3.eth.accounts.signTransaction( 13 | { 14 | from: GENESIS_ACCOUNT, 15 | to: TEST_ACCOUNT, 16 | value: "0x200", // Must be higher than ExistentialDeposit 17 | gasPrice: "0x3B9ACA00", 18 | gas: "0x100000", 19 | }, 20 | GENESIS_ACCOUNT_PRIVATE_KEY 21 | ); 22 | 23 | expect(await context.web3.eth.getTransactionCount(GENESIS_ACCOUNT, "earliest")).to.eq(0); 24 | 25 | await customRequest(context.web3, "eth_sendRawTransaction", [tx.rawTransaction]); 26 | 27 | expect(await context.web3.eth.getTransactionCount(GENESIS_ACCOUNT, "latest")).to.eq(0); 28 | expect(await context.web3.eth.getTransactionCount(GENESIS_ACCOUNT, "pending")).to.eq(1); 29 | 30 | await createAndFinalizeBlock(context.web3); 31 | 32 | expect(await context.web3.eth.getTransactionCount(GENESIS_ACCOUNT, "latest")).to.eq(1); 33 | expect(await context.web3.eth.getTransactionCount(GENESIS_ACCOUNT, "pending")).to.eq(1); 34 | expect(await context.web3.eth.getTransactionCount(GENESIS_ACCOUNT, "earliest")).to.eq(0); 35 | }); 36 | }); 37 | -------------------------------------------------------------------------------- /frontier/ts-tests/tests/test-revert-reason.ts: -------------------------------------------------------------------------------- 1 | import { expect } from "chai"; 2 | import { AbiItem } from "web3-utils"; 3 | 4 | import ExplicitRevertReason from "../build/contracts/ExplicitRevertReason.json"; 5 | import { GENESIS_ACCOUNT, GENESIS_ACCOUNT_PRIVATE_KEY } from "./config"; 6 | import { createAndFinalizeBlock, customRequest, describeWithFrontier } from "./util"; 7 | 8 | describeWithFrontier("Frontier RPC (Revert Reason)", (context) => { 9 | let contractAddress; 10 | 11 | const REVERT_W_MESSAGE_BYTECODE = ExplicitRevertReason.bytecode; 12 | 13 | const TEST_CONTRACT_ABI = ExplicitRevertReason.abi as AbiItem[]; 14 | 15 | before("create the contract", async function () { 16 | this.timeout(15000); 17 | const tx = await context.web3.eth.accounts.signTransaction( 18 | { 19 | from: GENESIS_ACCOUNT, 20 | data: REVERT_W_MESSAGE_BYTECODE, 21 | value: "0x00", 22 | gasPrice: "0x3B9ACA00", 23 | gas: "0x100000", 24 | }, 25 | GENESIS_ACCOUNT_PRIVATE_KEY 26 | ); 27 | const r = await customRequest(context.web3, "eth_sendRawTransaction", [tx.rawTransaction]); 28 | await createAndFinalizeBlock(context.web3); 29 | const receipt = await context.web3.eth.getTransactionReceipt(r.result); 30 | contractAddress = receipt.contractAddress; 31 | }); 32 | 33 | it("should fail with revert reason", async function () { 34 | const contract = new context.web3.eth.Contract(TEST_CONTRACT_ABI, contractAddress, { 35 | from: GENESIS_ACCOUNT, 36 | gasPrice: "0x3B9ACA00", 37 | }); 38 | try { 39 | await contract.methods.max10(30).call(); 40 | } catch (error) { 41 | expect(error.message).to.be.eq( 42 | "Returned error: VM Exception while processing transaction: revert Value must not be greater than 10." 43 | ); 44 | } 45 | }); 46 | }); 47 | -------------------------------------------------------------------------------- /frontier/ts-tests/tests/test-rpc-constants.ts: -------------------------------------------------------------------------------- 1 | import { expect } from "chai"; 2 | 3 | import { CHAIN_ID } from "./config"; 4 | import { describeWithFrontier } from "./util"; 5 | 6 | // All test for the RPC 7 | 8 | describeWithFrontier("Frontier RPC (Constant)", (context) => { 9 | it("should have 0 hashrate", async function () { 10 | expect(await context.web3.eth.getHashrate()).to.equal(0); 11 | }); 12 | 13 | it("should have chainId", async function () { 14 | // The chainId is defined by the Substrate Chain Id, default to 42 15 | expect(await context.web3.eth.getChainId()).to.equal(CHAIN_ID); 16 | }); 17 | 18 | it("should have no account", async function () { 19 | expect(await context.web3.eth.getAccounts()).to.eql([]); 20 | }); 21 | 22 | it("block author should be 0x0000000000000000000000000000000000000000", async function () { 23 | // This address `0x1234567890` is hardcoded into the runtime find_author 24 | // as we are running manual sealing consensus. 25 | expect(await context.web3.eth.getCoinbase()).to.equal("0x0000000000000000000000000000000000000000"); 26 | }); 27 | }); 28 | -------------------------------------------------------------------------------- /frontier/ts-tests/tests/test-state-root.ts: -------------------------------------------------------------------------------- 1 | import { expect } from "chai"; 2 | import { step } from "mocha-steps"; 3 | 4 | import { createAndFinalizeBlock, describeWithFrontier } from "./util"; 5 | 6 | describeWithFrontier("Frontier RPC (State root hash)", (context) => { 7 | let block; 8 | step("should calculate a valid intermediate state root hash", async function () { 9 | await createAndFinalizeBlock(context.web3); 10 | block = await context.web3.eth.getBlock(1); 11 | expect(block.stateRoot.length).to.be.equal(66); // 0x prefixed 12 | expect(block.stateRoot).to.not.be.equal("0x0000000000000000000000000000000000000000000000000000000000000000"); 13 | }); 14 | 15 | step("hash should be unique between blocks", async function () { 16 | await createAndFinalizeBlock(context.web3); 17 | const anotherBlock = await context.web3.eth.getBlock(2); 18 | expect(block.stateRoot).to.not.be.equal(anotherBlock.stateRoot); 19 | }); 20 | }); 21 | -------------------------------------------------------------------------------- /frontier/ts-tests/tests/test-transaction-cost.ts: -------------------------------------------------------------------------------- 1 | import { expect } from "chai"; 2 | import { step } from "mocha-steps"; 3 | 4 | import { describeWithFrontier, customRequest } from "./util"; 5 | 6 | describeWithFrontier("Frontier RPC (Transaction cost)", (context) => { 7 | step("should take transaction cost into account and not submit it to the pool", async function () { 8 | // Simple transfer with gas limit 0 manually signed to prevent web3 from rejecting client-side. 9 | const tx = await customRequest(context.web3, "eth_sendRawTransaction", [ 10 | "0xf86180843b9aca00809412cb274aad8251c875c0bf6872b67d9983e53fdd01801ca00e28ba2dd3c5a3fd467\ 11 | d4afd7aefb4a34b373314fff470bb9db743a84d674a0aa06e5994f2d07eafe1c37b4ce5471caecec29011f6f5b\ 12 | f0b1a552c55ea348df35f", 13 | ]); 14 | let msg = "intrinsic gas too low"; 15 | expect(tx.error).to.include({ 16 | message: msg, 17 | }); 18 | }); 19 | }); 20 | -------------------------------------------------------------------------------- /frontier/ts-tests/tests/test-web3api.ts: -------------------------------------------------------------------------------- 1 | import { expect } from "chai"; 2 | import { step } from "mocha-steps"; 3 | 4 | import { RUNTIME_SPEC_NAME, RUNTIME_SPEC_VERSION, RUNTIME_IMPL_VERSION } from "./config"; 5 | import { describeWithFrontier, customRequest } from "./util"; 6 | 7 | describeWithFrontier("Frontier RPC (Web3Api)", (context) => { 8 | step("should get client version", async function () { 9 | const version = await context.web3.eth.getNodeInfo(); 10 | expect(version).to.be.equal( 11 | `${RUNTIME_SPEC_NAME}/v${RUNTIME_SPEC_VERSION}.${RUNTIME_IMPL_VERSION}/fc-rpc-2.0.0-dev` 12 | ); 13 | }); 14 | 15 | step("should remote sha3", async function () { 16 | const data = context.web3.utils.stringToHex("hello"); 17 | const hash = await customRequest(context.web3, "web3_sha3", [data]); 18 | const localHash = context.web3.utils.sha3("hello"); 19 | expect(hash.result).to.be.equal(localHash); 20 | }); 21 | }); 22 | -------------------------------------------------------------------------------- /frontier/ts-tests/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "esModuleInterop": true, 4 | "resolveJsonModule": true 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /node/bin/main.rs: -------------------------------------------------------------------------------- 1 | //! gpu Node CLI 2 | 3 | #![warn(missing_docs)] 4 | 5 | fn main() -> sc_cli::Result<()> { 6 | node_cli::run() 7 | } 8 | -------------------------------------------------------------------------------- /node/build.rs: -------------------------------------------------------------------------------- 1 | // This file is part of Substrate. 2 | 3 | // Copyright (C) Parity Technologies (UK) Ltd. 4 | // SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 5 | 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | 19 | fn main() { 20 | #[cfg(feature = "cli")] 21 | cli::main(); 22 | } 23 | 24 | #[cfg(feature = "cli")] 25 | mod cli { 26 | include!("src/cli.rs"); 27 | 28 | use clap::{CommandFactory, ValueEnum}; 29 | use clap_complete::{generate_to, Shell}; 30 | use std::{env, fs, path::Path}; 31 | use substrate_build_script_utils::{generate_cargo_keys, rerun_if_git_head_changed}; 32 | 33 | pub fn main() { 34 | build_shell_completion(); 35 | generate_cargo_keys(); 36 | 37 | rerun_if_git_head_changed(); 38 | } 39 | 40 | /// Build shell completion scripts for all known shells 41 | fn build_shell_completion() { 42 | for shell in Shell::value_variants() { 43 | build_completion(shell); 44 | } 45 | } 46 | 47 | /// Build the shell auto-completion for a given Shell 48 | fn build_completion(shell: &Shell) { 49 | let outdir = match env::var_os("OUT_DIR") { 50 | None => return, 51 | Some(dir) => dir, 52 | }; 53 | let path = Path::new(&outdir) 54 | .parent() 55 | .unwrap() 56 | .parent() 57 | .unwrap() 58 | .parent() 59 | .unwrap() 60 | .join("completion-scripts"); 61 | 62 | fs::create_dir(&path).ok(); 63 | 64 | let _ = generate_to(*shell, &mut Cli::command(), "substrate-node", &path); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /node/src/eth.rs: -------------------------------------------------------------------------------- 1 | use crate::cli::EthConfiguration; 2 | 3 | use std::{ 4 | collections::BTreeMap, 5 | path::PathBuf, 6 | sync::{Arc, Mutex}, 7 | }; 8 | 9 | // Substrate 10 | use sc_service::{error::Error as ServiceError, Configuration}; 11 | // Frontier 12 | pub use fc_consensus::FrontierBlockImport; 13 | pub use fc_rpc_core::types::{FeeHistoryCache, FeeHistoryCacheLimit, FilterPool}; 14 | // Local 15 | use gpu_primitives::Block; 16 | 17 | /// Frontier DB backend type. 18 | pub type FrontierBackend = fc_db::Backend; 19 | 20 | pub fn db_config_dir(config: &Configuration) -> PathBuf { 21 | config.base_path.config_dir(config.chain_spec.id()) 22 | } 23 | 24 | pub struct FrontierPartialComponents { 25 | pub filter_pool: Option, 26 | pub fee_history_cache: FeeHistoryCache, 27 | pub fee_history_cache_limit: FeeHistoryCacheLimit, 28 | } 29 | 30 | pub fn new_frontier_partial( 31 | config: &EthConfiguration, 32 | ) -> Result { 33 | Ok(FrontierPartialComponents { 34 | filter_pool: Some(Arc::new(Mutex::new(BTreeMap::new()))), 35 | fee_history_cache: Arc::new(Mutex::new(BTreeMap::new())), 36 | fee_history_cache_limit: config.fee_history_limit, 37 | }) 38 | } 39 | -------------------------------------------------------------------------------- /node/src/lib.rs: -------------------------------------------------------------------------------- 1 | // This file is part of Substrate. 2 | 3 | // Copyright (C) Parity Technologies (UK) Ltd. 4 | // SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 5 | 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | 19 | //! Substrate CLI library. 20 | //! 21 | //! This package has two Cargo features: 22 | //! 23 | //! - `cli` (default): exposes functions that parse command-line options, then start and run the 24 | //! node as a CLI application. 25 | //! 26 | //! - `browser`: exposes the content of the `browser` module, which consists of exported symbols 27 | //! that are meant to be passed through the `wasm-bindgen` utility and called from JavaScript. 28 | //! Despite its name the produced WASM can theoretically also be used from NodeJS, although this 29 | //! hasn't been tested. 30 | 31 | pub mod chain_spec; 32 | pub mod eth; 33 | 34 | #[macro_use] 35 | pub mod service; 36 | #[cfg(feature = "cli")] 37 | mod benchmarking; 38 | #[cfg(feature = "cli")] 39 | mod cli; 40 | #[cfg(feature = "cli")] 41 | mod command; 42 | 43 | #[cfg(feature = "cli")] 44 | pub use cli::*; 45 | #[cfg(feature = "cli")] 46 | pub use command::*; 47 | -------------------------------------------------------------------------------- /pallets/custom-signatures/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "pallet-custom-signatures" 3 | version = "4.6.0" 4 | license = "Apache-2.0" 5 | description = "FRAME pallet for user defined extrinsic signatures" 6 | edition = "2021" 7 | authors = ["Stake Technologies "] 8 | homepage = "https://astar.network" 9 | repository = "https://github.com/AstarNetwork/Astar" 10 | 11 | [dependencies] 12 | serde = { version = "1.0.81", optional = true } 13 | 14 | frame-support = { git = "https://github.com/brahmGAN/substrate", branch = "polkadot-v1.0.0", default-features = false } 15 | frame-system = { git = "https://github.com/brahmGAN/substrate", branch = "polkadot-v1.0.0", default-features = false } 16 | parity-scale-codec = { version = "3.6.1", default-features = false, features = ["derive"] } 17 | scale-info = { version = "2.5.0", default-features = false } 18 | sp-core = { git = "https://github.com/brahmGAN/substrate", branch = "polkadot-v1.0.0", default-features = false } 19 | sp-io = { git = "https://github.com/brahmGAN/substrate", branch = "polkadot-v1.0.0", default-features = false } 20 | sp-runtime = { git = "https://github.com/brahmGAN/substrate", branch = "polkadot-v1.0.0", default-features = false } 21 | sp-std = { git = "https://github.com/brahmGAN/substrate", branch = "polkadot-v1.0.0", default-features = false } 22 | 23 | [dev-dependencies] 24 | assert_matches = "1.3.0" 25 | hex-literal = "0.4.1" 26 | libsecp256k1 = "0.7.0" 27 | pallet-balances = { git = "https://github.com/brahmGAN/substrate", branch = "polkadot-v1.0.0", default-features = false } 28 | sp-keyring = { git = "https://github.com/brahmGAN/substrate", branch = "polkadot-v1.0.0", default-features = false } 29 | 30 | [features] 31 | default = ["std"] 32 | std = [ 33 | "serde", 34 | "parity-scale-codec/std", 35 | "pallet-balances/std", 36 | "scale-info/std", 37 | "sp-io/std", 38 | "sp-std/std", 39 | "sp-core/std", 40 | "sp-runtime/std", 41 | "frame-support/std", 42 | "frame-system/std", 43 | ] 44 | try-runtime = ["frame-support/try-runtime"] 45 | -------------------------------------------------------------------------------- /pallets/precompiles/assets-erc20/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "pallet-evm-precompile-assets-erc20" 3 | description = "A Precompile to expose a Assets pallet through an ERC20-compliant interface." 4 | version = "0.5.2" 5 | edition = "2021" 6 | authors = ["Stake Technologies "] 7 | homepage = "https://astar.network" 8 | repository = "https://github.com/AstarNetwork/Astar" 9 | 10 | [dependencies] 11 | parity-scale-codec = { version = "3.6.1", default-features = false, features = ["derive"] } 12 | log = { version = "0.4.17", default-features = false } 13 | num_enum = { version = "0.5.3", default-features = false } 14 | slices = "0.2.0" 15 | 16 | # Substrate 17 | frame-support = { git = "https://github.com/brahmGAN/substrate", branch = "polkadot-v1.0.0", default-features = false } 18 | frame-system = { git = "https://github.com/brahmGAN/substrate", branch = "polkadot-v1.0.0", default-features = false } 19 | pallet-assets = { git = "https://github.com/brahmGAN/substrate", branch = "polkadot-v1.0.0", default-features = false } 20 | pallet-balances = { git = "https://github.com/brahmGAN/substrate", branch = "polkadot-v1.0.0", default-features = false } 21 | sp-core = { git = "https://github.com/brahmGAN/substrate", branch = "polkadot-v1.0.0", default-features = false } 22 | sp-io = { git = "https://github.com/brahmGAN/substrate", branch = "polkadot-v1.0.0", default-features = false } 23 | sp-runtime = { git = "https://github.com/brahmGAN/substrate", branch = "polkadot-v1.0.0", default-features = false } 24 | sp-std = { git = "https://github.com/brahmGAN/substrate", branch = "polkadot-v1.0.0", default-features = false } 25 | 26 | precompile-utils = { path = "../utils", default-features = false } 27 | 28 | # Frontier 29 | fp-evm = { path = "../../../frontier/primitives/evm", default-features = false } 30 | pallet-evm = { path = "../../../frontier/frame/evm", default-features = false } 31 | 32 | [dev-dependencies] 33 | derive_more = { version = "0.99" } 34 | serde = { version = "1.0.151", features = ["derive"] } 35 | sha3 = { version = "0.10.1" } 36 | scale-info = { version = "2.5.0", features = ["derive"] } 37 | pallet-timestamp = { git = "https://github.com/brahmGAN/substrate", branch = "polkadot-v1.0.0", default-features = false } 38 | 39 | precompile-utils = { path ="../utils", features = ["testing"] } 40 | 41 | [features] 42 | default = ["std"] 43 | std = [ 44 | "parity-scale-codec/std", 45 | "fp-evm/std", 46 | "frame-support/std", 47 | "frame-system/std", 48 | "pallet-assets/std", 49 | "pallet-evm/std", 50 | "pallet-balances/std", 51 | "precompile-utils/std", 52 | "sp-core/std", 53 | "sp-io/std", 54 | "sp-runtime/std", 55 | "sp-std/std", 56 | ] 57 | runtime-benchmarks = [] 58 | -------------------------------------------------------------------------------- /pallets/precompiles/sr25519/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "pallet-evm-precompile-sr25519" 3 | description = "SR25519 crypto support for EVM." 4 | version = "1.2.1" 5 | edition = "2021" 6 | authors = ["Stake Technologies "] 7 | homepage = "https://astar.network" 8 | repository = "https://github.com/AstarNetwork/Astar" 9 | 10 | [dependencies] 11 | log = { version = "0.4.17", default-features = false } 12 | num_enum = { version = "0.5.3", default-features = false } 13 | precompile-utils = { path ="../utils", default-features = false } 14 | 15 | # Substrate 16 | parity-scale-codec = { version = "3.6.1", default-features = false, features = ["max-encoded-len"] } 17 | sp-core = { git = "https://github.com/brahmGAN/substrate", branch = "polkadot-v1.0.0", default-features = false } 18 | sp-io = { git = "https://github.com/brahmGAN/substrate", branch = "polkadot-v1.0.0", default-features = false } 19 | sp-std = { git = "https://github.com/brahmGAN/substrate", branch = "polkadot-v1.0.0", default-features = false } 20 | 21 | # Frontier 22 | fp-evm = { path = "../../../frontier/primitives/evm", default-features = false } 23 | pallet-evm = { path = "../../../frontier/frame/evm", default-features = false } 24 | 25 | [dev-dependencies] 26 | derive_more = { version = "0.99" } 27 | hex-literal = "0.4.1" 28 | scale-info = { version = "2.5.0", default-features = false, features = ["derive"] } 29 | serde = { version = "1.0.151", features = ["derive"] } 30 | 31 | precompile-utils = { path ="../utils", features = ["testing"] } 32 | 33 | frame-support = { git = "https://github.com/brahmGAN/substrate", branch = "polkadot-v1.0.0" } 34 | frame-system = { git = "https://github.com/brahmGAN/substrate", branch = "polkadot-v1.0.0" } 35 | pallet-balances = { git = "https://github.com/brahmGAN/substrate", branch = "polkadot-v1.0.0" } 36 | pallet-timestamp = { git = "https://github.com/brahmGAN/substrate", branch = "polkadot-v1.0.0" } 37 | sp-runtime = { git = "https://github.com/brahmGAN/substrate", branch = "polkadot-v1.0.0" } 38 | 39 | [features] 40 | default = ["std"] 41 | std = [ 42 | "parity-scale-codec/std", 43 | "fp-evm/std", 44 | "pallet-evm/std", 45 | "precompile-utils/std", 46 | "sp-core/std", 47 | "sp-std/std", 48 | "sp-io/std", 49 | ] 50 | -------------------------------------------------------------------------------- /pallets/precompiles/sr25519/SR25519.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.8.0; 2 | 3 | /** 4 | * @title SR25519 signature interface. 5 | */ 6 | interface SR25519 { 7 | /** 8 | * @dev Verify signed message using SR25519 crypto. 9 | * @return A boolean confirming whether the public key is signer for the message. 10 | */ 11 | function verify( 12 | bytes32 public_key, 13 | bytes calldata signature, 14 | bytes calldata message 15 | ) external view returns (bool); 16 | } -------------------------------------------------------------------------------- /pallets/precompiles/substrate-ecdsa/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "pallet-evm-precompile-substrate-ecdsa" 3 | description = "Substrate ECDSA crypto support for EVM." 4 | version = "1.2.2" 5 | edition = "2021" 6 | authors = ["Stake Technologies "] 7 | homepage = "https://astar.network" 8 | repository = "https://github.com/AstarNetwork/Astar" 9 | 10 | [dependencies] 11 | assert_matches = "1.3.0" 12 | log = { version = "0.4.17", default-features = false } 13 | num_enum = { version = "0.5.3", default-features = false } 14 | precompile-utils = { path ="../utils", default-features = false } 15 | 16 | # Substrate 17 | parity-scale-codec = { version = "3.6.1", default-features = false, features = ["max-encoded-len"] } 18 | sp-core = { git = "https://github.com/brahmGAN/substrate", branch = "polkadot-v1.0.0", default-features = false } 19 | sp-io = { git = "https://github.com/brahmGAN/substrate", branch = "polkadot-v1.0.0", default-features = false } 20 | sp-std = { git = "https://github.com/brahmGAN/substrate", branch = "polkadot-v1.0.0", default-features = false } 21 | 22 | # Frontier 23 | fp-evm = { path = "../../../frontier/primitives/evm", default-features = false } 24 | pallet-evm = { path = "../../../frontier/frame/evm", default-features = false } 25 | 26 | [dev-dependencies] 27 | derive_more = { version = "0.99" } 28 | hex-literal = "0.4.1" 29 | scale-info = { version = "2.5.0", default-features = false, features = ["derive"] } 30 | serde = { version = "1.0.151", features = ["derive"] } 31 | 32 | precompile-utils = { path ="../utils", features = ["testing"] } 33 | 34 | frame-support = { git = "https://github.com/brahmGAN/substrate", branch = "polkadot-v1.0.0" } 35 | frame-system = { git = "https://github.com/brahmGAN/substrate", branch = "polkadot-v1.0.0" } 36 | pallet-balances = { git = "https://github.com/brahmGAN/substrate", branch = "polkadot-v1.0.0" } 37 | pallet-timestamp = { git = "https://github.com/brahmGAN/substrate", branch = "polkadot-v1.0.0" } 38 | sp-runtime = { git = "https://github.com/brahmGAN/substrate", branch = "polkadot-v1.0.0" } 39 | 40 | [features] 41 | default = ["std"] 42 | std = [ 43 | "num_enum/std", 44 | "parity-scale-codec/std", 45 | "fp-evm/std", 46 | "pallet-evm/std", 47 | "precompile-utils/std", 48 | "sp-core/std", 49 | "sp-std/std", 50 | "sp-io/std", 51 | ] 52 | -------------------------------------------------------------------------------- /pallets/precompiles/substrate-ecdsa/SubstrateEcdsa.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.8.0; 2 | 3 | /** 4 | * @title SubstrateEcdsa signature interface. 5 | */ 6 | interface ISubstrateEcdsa { 7 | /** 8 | * @dev Verify signed message using Substrate version of ECDSA crypto. 9 | * @return A boolean confirming whether the public key is signer for the message. 10 | */ 11 | function verify( 12 | bytes32 public_key, 13 | bytes calldata signature, 14 | bytes calldata message 15 | ) external view returns (bool); 16 | } 17 | -------------------------------------------------------------------------------- /pallets/precompiles/utils/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "precompile-utils" 3 | authors = ["StakeTechnologies", "PureStake"] 4 | description = "Utils to write EVM precompiles." 5 | edition = "2021" 6 | version = "0.5.0" 7 | 8 | [dependencies] 9 | # There's a problem with --all-features when this is moved under dev-deps 10 | derive_more = { version = "0.99", optional = true } 11 | environmental = { version = "1.1.2", default-features = false } 12 | hex-literal = { version = "0.4.1", optional = true } 13 | impl-trait-for-tuples = "0.2.2" 14 | log = { version = "0.4.17", default-features = false } 15 | num_enum = { version = "0.5.3", default-features = false } 16 | scale-info = { version = "2.5.0", default-features = false, optional = true, features = ["derive"] } 17 | serde = { version = "1.0.151", optional = true } 18 | sha3 = { version = "0.10.1", default-features = false } 19 | similar-asserts = { version = "1.1.0", optional = true } 20 | assert_matches = "1.3.0" 21 | 22 | precompile-utils-macro = { path = "macro" } 23 | 24 | # Substrate 25 | parity-scale-codec = { version = "3.6.1", default-features = false, features = ["derive", "max-encoded-len"] } 26 | frame-support = { git = "https://github.com/brahmGAN/substrate", branch = "polkadot-v1.0.0", default-features = false } 27 | frame-system = { git = "https://github.com/brahmGAN/substrate", branch = "polkadot-v1.0.0", default-features = false } 28 | sp-core = { git = "https://github.com/brahmGAN/substrate", branch = "polkadot-v1.0.0", default-features = false } 29 | sp-io = { git = "https://github.com/brahmGAN/substrate", branch = "polkadot-v1.0.0", default-features = false } 30 | sp-runtime = { git = "https://github.com/brahmGAN/substrate", branch = "polkadot-v1.0.0", default-features = false } 31 | sp-std = { git = "https://github.com/brahmGAN/substrate", branch = "polkadot-v1.0.0", default-features = false } 32 | 33 | evm = { git = "https://github.com/rust-blockchain/evm", rev = "b7b82c7e1fc57b7449d6dfa6826600de37cc1e65", default-features = false, features = ["with-codec"] } 34 | fp-evm = { path = "../../../frontier/primitives/evm", default-features = false } 35 | pallet-evm = { path = "../../../frontier/frame/evm", default-features = false } 36 | 37 | [dev-dependencies] 38 | hex-literal = "0.4.1" 39 | 40 | [features] 41 | default = ["std"] 42 | std = [ 43 | "evm/std", 44 | "parity-scale-codec/std", 45 | "fp-evm/std", 46 | "frame-support/std", 47 | "frame-system/std", 48 | "pallet-evm/std", 49 | "sp-core/std", 50 | "sp-io/std", 51 | "sp-std/std", 52 | "sp-runtime/std", 53 | "environmental/std", 54 | ] 55 | testing = ["similar-asserts", "std", "scale-info", "serde", "derive_more", "hex-literal"] 56 | -------------------------------------------------------------------------------- /pallets/precompiles/utils/macro/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "precompile-utils-macro" 3 | authors = ["StakeTechnologies", "PureStake"] 4 | description = "" 5 | edition = "2021" 6 | version = "0.1.0" 7 | 8 | [lib] 9 | proc-macro = true 10 | 11 | [[test]] 12 | name = "tests" 13 | path = "tests/tests.rs" 14 | 15 | [dependencies] 16 | num_enum = { version = "0.5.3", default-features = false } 17 | proc-macro2 = "1.0.66" 18 | quote = "1.0.33" 19 | sha3 = { version = "0.10.1", default-features = false } 20 | syn = { version = "1.0.109", features = ["extra-traits", "fold", "full", "visit"] } 21 | -------------------------------------------------------------------------------- /pallets/precompiles/utils/macro/tests/tests.rs: -------------------------------------------------------------------------------- 1 | // This file is part of Astar. 2 | 3 | // Copyright 2019-2022 PureStake Inc. 4 | // Copyright (C) 2022-2023 Stake Technologies Pte.Ltd. 5 | // SPDX-License-Identifier: GPL-3.0-or-later 6 | // 7 | // This file is part of Utils package, originally developed by Purestake Inc. 8 | // Utils package used in Astar Network in terms of GPLv3. 9 | // 10 | // Utils is free software: you can redistribute it and/or modify 11 | // it under the terms of the GNU General Public License as published by 12 | // the Free Software Foundation, either version 3 of the License, or 13 | // (at your option) any later version. 14 | 15 | // Utils is distributed in the hope that it will be useful, 16 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | // GNU General Public License for more details. 19 | 20 | // You should have received a copy of the GNU General Public License 21 | // along with Utils. If not, see . 22 | extern crate sha3; 23 | 24 | use sha3::{Digest, Keccak256}; 25 | 26 | #[precompile_utils_macro::generate_function_selector] 27 | pub enum Action { 28 | Toto = "toto()", 29 | Tata = "tata()", 30 | } 31 | 32 | #[test] 33 | fn test_keccak256() { 34 | assert_eq!(&precompile_utils_macro::keccak256!(""), Keccak256::digest(b"").as_slice(),); 35 | assert_eq!( 36 | &precompile_utils_macro::keccak256!("toto()"), 37 | Keccak256::digest(b"toto()").as_slice(), 38 | ); 39 | assert_ne!( 40 | &precompile_utils_macro::keccak256!("toto()"), 41 | Keccak256::digest(b"tata()").as_slice(), 42 | ); 43 | } 44 | 45 | #[test] 46 | fn test_generate_function_selector() { 47 | assert_eq!(&(Action::Toto as u32).to_be_bytes()[..], &Keccak256::digest(b"toto()")[0..4],); 48 | assert_eq!(&(Action::Tata as u32).to_be_bytes()[..], &Keccak256::digest(b"tata()")[0..4],); 49 | assert_ne!(Action::Toto as u32, Action::Tata as u32); 50 | } 51 | -------------------------------------------------------------------------------- /primitives/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "gpu-primitives" 3 | version = "1.0.1" 4 | authors = ["gpu "] 5 | edition = "2021" 6 | 7 | [dependencies] 8 | sp-core = { git = "https://github.com/brahmGAN/substrate", branch = "polkadot-v1.0.0", default-features = false } 9 | sp-std = { git = "https://github.com/brahmGAN/substrate", branch = "polkadot-v1.0.0", default-features = false } 10 | sp-runtime = { git = "https://github.com/brahmGAN/substrate", branch = "polkadot-v1.0.0", default-features = false } 11 | 12 | frame-support = { git = "https://github.com/brahmGAN/substrate", branch = "polkadot-v1.0.0", default-features = false } 13 | 14 | pallet-assets = { git = "https://github.com/brahmGAN/substrate", branch = "polkadot-v1.0.0", default-features = false } 15 | pallet-evm = { path = "../frontier/frame/evm", default-features = false } 16 | pallet-evm-precompile-assets-erc20 = { path = "../pallets/precompiles/assets-erc20", default-features = false } 17 | 18 | [features] 19 | default = [ "std" ] 20 | std = [ 21 | "sp-core/std", 22 | "sp-runtime/std", 23 | "sp-std/std", 24 | "frame-support/std", 25 | "pallet-assets/std", 26 | "pallet-evm/std", 27 | "pallet-evm-precompile-assets-erc20/std" 28 | ] 29 | -------------------------------------------------------------------------------- /primitives/src/assets.rs: -------------------------------------------------------------------------------- 1 | use crate::{AccountId, AssetId}; 2 | 3 | use frame_support::ensure; 4 | use sp_std::marker::PhantomData; 5 | 6 | use pallet_assets::AssetsCallback; 7 | use pallet_evm_precompile_assets_erc20::AddressToAssetId; 8 | 9 | /// Revert opt code. It's inserted at the precompile addresses, to make them functional in EVM. 10 | pub const EVM_REVERT_CODE: &[u8] = &[0x60, 0x00, 0x60, 0x00, 0xfd]; 11 | 12 | /// Handler for automatic revert code registration. 13 | /// 14 | /// When an asset is created, it automatically becomes available to the EVM via an `ERC20-like` interface. 15 | /// In order for the precompile to work, dedicated asset address needs to have the revert code registered, otherwise the call will fail. 16 | /// 17 | /// It is important to note that if the dedicated asset EVM address is already taken, asset creation should fail. 18 | /// After asset has been destroyed, it is also safe to remove the revert code and free the address for future usage. 19 | pub struct EvmRevertCodeHandler(PhantomData<(A, R)>); 20 | impl AssetsCallback for EvmRevertCodeHandler 21 | where 22 | A: AddressToAssetId, 23 | R: pallet_evm::Config, 24 | { 25 | fn created(id: &AssetId, _: &AccountId) -> Result<(), ()> { 26 | let address = A::asset_id_to_address(*id); 27 | // In case of collision, we need to cancel the asset creation. 28 | ensure!(!pallet_evm::AccountCodes::::contains_key(&address), ()); 29 | pallet_evm::AccountCodes::::insert(address, EVM_REVERT_CODE.to_vec()); 30 | Ok(()) 31 | } 32 | 33 | fn destroyed(id: &AssetId) -> Result<(), ()> { 34 | let address = A::asset_id_to_address(*id); 35 | pallet_evm::AccountCodes::::remove(address); 36 | Ok(()) 37 | } 38 | } 39 | 40 | // #[cfg(feature = "runtime-benchmarks")] 41 | // /// Benchmark helper for `pallet-assets`. 42 | // pub struct AssetsBenchmarkHelper; 43 | // impl> pallet_assets::BenchmarkHelper 44 | // for AssetsBenchmarkHelper 45 | // { 46 | // fn create_asset_id_parameter(id: u32) -> AssetIdParameter { 47 | // AssetId::from(id).into() 48 | // } 49 | // } 50 | -------------------------------------------------------------------------------- /runtime/gpu/build.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2022 Smallworld gpu 2 | // This file is part of gpu. 3 | 4 | // gpu is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | 9 | // Substrate is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with gpu. If not, see . 16 | 17 | use substrate_wasm_builder::WasmBuilder; 18 | 19 | fn main() { 20 | WasmBuilder::new() 21 | .with_current_project() 22 | .import_memory() 23 | .export_heap_base() 24 | .build() 25 | } 26 | -------------------------------------------------------------------------------- /runtime/gpu/constants/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "gpu-runtime-constants" 3 | version = "1.0.1" 4 | authors = ["gpu "] 5 | edition = "2021" 6 | 7 | [dependencies] 8 | smallvec = "1.8.0" 9 | 10 | frame-support = { git = "https://github.com/brahmGAN/substrate", branch = "polkadot-v1.0.0", default-features = false } 11 | primitives = { package = "gpu-primitives", path = "../../../primitives", default-features = false } 12 | runtime-common = { package = "gpu-runtime-common", path = "../../common", default-features = false } 13 | sp-runtime = { git = "https://github.com/brahmGAN/substrate", branch = "polkadot-v1.0.0", default-features = false } 14 | sp-weights = { git = "https://github.com/brahmGAN/substrate", branch = "polkadot-v1.0.0", default-features = false } 15 | sp-core = { git = "https://github.com/brahmGAN/substrate", branch = "polkadot-v1.0.0", default-features = false } 16 | 17 | [features] 18 | default = ["std"] 19 | std = [ 20 | "sp-core/std", 21 | "sp-runtime/std", 22 | "sp-weights/std" 23 | ] 24 | -------------------------------------------------------------------------------- /runtime/gpu/constants/src/weights/mod.rs: -------------------------------------------------------------------------------- 1 | // This file is part of Substrate. 2 | 3 | // Copyright (C) 2022 Smallworld gpu 4 | // SPDX-License-Identifier: Apache-2.0 5 | 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | //! Expose the auto generated weight files. 19 | 20 | pub mod block_weights; 21 | pub mod extrinsic_weights; 22 | pub mod paritydb_weights; 23 | pub mod rocksdb_weights; 24 | 25 | pub use block_weights::BlockExecutionWeight; 26 | pub use extrinsic_weights::ExtrinsicBaseWeight; 27 | pub use paritydb_weights::constants::ParityDbWeight; 28 | pub use rocksdb_weights::constants::RocksDbWeight; 29 | -------------------------------------------------------------------------------- /runtime/gpu/src/weights/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright (C) Parity Technologies (UK) Ltd. 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //! A list of the different weight modules for our runtime. 17 | 18 | pub mod frame_election_provider_support; 19 | pub mod frame_system; 20 | pub mod pallet_bags_list; 21 | pub mod pallet_balances; 22 | pub mod pallet_bounties; 23 | pub mod pallet_child_bounties; 24 | pub mod pallet_contracts; 25 | pub mod pallet_conviction_voting; 26 | pub mod pallet_election_provider_multi_phase; 27 | pub mod pallet_fast_unstake; 28 | pub mod pallet_identity; 29 | pub mod pallet_im_online; 30 | pub mod pallet_indices; 31 | pub mod pallet_membership; 32 | pub mod pallet_multisig; 33 | pub mod pallet_preimage; 34 | pub mod pallet_proxy; 35 | pub mod pallet_referenda; 36 | pub mod pallet_scheduler; 37 | pub mod pallet_session; 38 | pub mod pallet_staking; 39 | pub mod pallet_timestamp; 40 | pub mod pallet_treasury; 41 | pub mod pallet_utility; 42 | pub mod pallet_vesting; 43 | pub mod pallet_whitelist; 44 | -------------------------------------------------------------------------------- /runtime/gpu/src/weights/pallet_timestamp.rs: -------------------------------------------------------------------------------- 1 | 2 | //! Autogenerated weights for `pallet_timestamp` 3 | //! 4 | //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev 5 | //! DATE: 2023-08-22, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` 6 | //! WORST CASE MAP SIZE: `1000000` 7 | //! HOSTNAME: `s-02-v-02`, CPU: `AMD Ryzen 9 5900X 12-Core Processor` 8 | //! EXECUTION: `Some(Wasm)`, WASM-EXECUTION: `Compiled`, CHAIN: `Some("gpu-dev")`, DB CACHE: 1024 9 | 10 | // Executed Command: 11 | // ./target/production/gpu 12 | // benchmark 13 | // pallet 14 | // --chain=gpu-dev 15 | // --steps=50 16 | // --repeat=20 17 | // --pallet=pallet_timestamp 18 | // --extrinsic=* 19 | // --execution=wasm 20 | // --wasm-execution=compiled 21 | // --heap-pages=4096 22 | // --output=./runtime/gpu/src/weights/pallet_timestamp.rs 23 | 24 | #![cfg_attr(rustfmt, rustfmt_skip)] 25 | #![allow(unused_parens)] 26 | #![allow(unused_imports)] 27 | #![allow(missing_docs)] 28 | 29 | use frame_support::{traits::Get, weights::Weight}; 30 | use core::marker::PhantomData; 31 | 32 | /// Weight functions for `pallet_timestamp`. 33 | pub struct WeightInfo(PhantomData); 34 | impl pallet_timestamp::WeightInfo for WeightInfo { 35 | /// Storage: `Timestamp::Now` (r:1 w:1) 36 | /// Proof: `Timestamp::Now` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`) 37 | /// Storage: `Babe::CurrentSlot` (r:1 w:0) 38 | /// Proof: `Babe::CurrentSlot` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`) 39 | fn set() -> Weight { 40 | // Proof Size summary in bytes: 41 | // Measured: `345` 42 | // Estimated: `1493` 43 | // Minimum execution time: 7_745_000 picoseconds. 44 | Weight::from_parts(7_904_000, 0) 45 | .saturating_add(Weight::from_parts(0, 1493)) 46 | .saturating_add(T::DbWeight::get().reads(2)) 47 | .saturating_add(T::DbWeight::get().writes(1)) 48 | } 49 | fn on_finalize() -> Weight { 50 | // Proof Size summary in bytes: 51 | // Measured: `128` 52 | // Estimated: `0` 53 | // Minimum execution time: 2_975_000 picoseconds. 54 | Weight::from_parts(3_046_000, 0) 55 | .saturating_add(Weight::from_parts(0, 0)) 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /rust-toolchain: -------------------------------------------------------------------------------- 1 | [toolchain] 2 | channel = "nightly-2023-05-22" 3 | components = [ "rustfmt", "clippy" ] 4 | targets = [ "wasm32-unknown-unknown"] 5 | -------------------------------------------------------------------------------- /rustfmt.toml: -------------------------------------------------------------------------------- 1 | # Basic 2 | hard_tabs = true 3 | max_width = 100 4 | use_small_heuristics = "Max" 5 | # Imports 6 | imports_granularity = "Crate" 7 | reorder_imports = true 8 | # Consistency 9 | newline_style = "Unix" 10 | # Misc 11 | chain_width = 80 12 | spaces_around_ranges = false 13 | binop_separator = "Back" 14 | reorder_impl_items = false 15 | match_arm_leading_pipes = "Preserve" 16 | match_arm_blocks = false 17 | match_block_trailing_comma = true 18 | trailing_comma = "Vertical" 19 | trailing_semicolon = false 20 | use_field_init_shorthand = true 21 | -------------------------------------------------------------------------------- /scripts/build_with_docker.sh: -------------------------------------------------------------------------------- 1 | # for support wild range os 2 | 3 | docker run --rm -it -w /project/gpu \ 4 | -v $(pwd):/project/gpu \ 5 | paritytech/ci-linux:production cargo build --profile production 6 | -------------------------------------------------------------------------------- /scripts/cargo_test.sh: -------------------------------------------------------------------------------- 1 | cargo test --workspace -- --nocapture 2 | -------------------------------------------------------------------------------- /scripts/dockerfiles/selendra/build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | 4 | pushd . 5 | 6 | # The following line ensure we run from the project root 7 | PROJECT_ROOT=`git rev-parse --show-toplevel` 8 | cd $PROJECT_ROOT 9 | 10 | # Find the current version from Cargo.toml 11 | VERSION=`grep "^version" ./node/Cargo.toml | egrep -o "([0-9\.]+)"` 12 | GITUSER=gpuchain 13 | GITREPO=gpu 14 | 15 | # Build the image 16 | echo "Building ${GITUSER}/${GITREPO}:latest docker image, hang on!" 17 | time docker build -f ./scripts/dockerfiles/gpu/gpu_builder.Dockerfile -t ${GITUSER}/${GITREPO}:latest . 18 | docker tag ${GITUSER}/${GITREPO}:latest ${GITUSER}/${GITREPO}:v${VERSION} 19 | 20 | # Show the list of available images for this repo 21 | echo "Image is ready" 22 | docker images | grep ${GITREPO} 23 | 24 | popd 25 | -------------------------------------------------------------------------------- /scripts/dockerfiles/selendra/selendra_builder.Dockerfile: -------------------------------------------------------------------------------- 1 | # This is the build stage for gpu. Here we create the binary in a temporary image. 2 | FROM docker.io/paritytech/ci-linux:production as builder 3 | 4 | WORKDIR /gpu 5 | COPY . /gpu 6 | 7 | RUN cargo build --locked --release 8 | 9 | # This is the 2nd stage: a very small image where we copy the gpu binary." 10 | FROM docker.io/library/ubuntu:20.04 11 | 12 | LABEL description="Multistage Docker image for gpu: a platform for web3" \ 13 | io.parity.image.type="builder" \ 14 | io.parity.image.authors="info@gpu.org" \ 15 | io.parity.image.vendor="gpu" \ 16 | io.parity.image.description="gpu: a platform for web3" \ 17 | io.parity.image.source="https://github.com/gpu/gpu/blob/${VCS_REF}/scripts/dockerfiles/gpu/gpu_builder.Dockerfile" \ 18 | io.parity.image.documentation="https://github.com/gpu/gpu/" 19 | 20 | COPY --from=builder /gpu/target/release/gpu /usr/local/bin 21 | 22 | RUN useradd -m -u 1000 -U -s /bin/sh -d /gpu gpu && \ 23 | mkdir -p /data /gpu/.local/share && \ 24 | chown -R gpu:gpu /data && \ 25 | ln -s /data /gpu/.local/share/gpu && \ 26 | # unclutter and minimize the attack surface 27 | rm -rf /usr/bin /usr/sbin && \ 28 | # check if executable works in this container 29 | /usr/local/bin/gpu --version 30 | 31 | USER gpu 32 | 33 | EXPOSE 30333 9933 9944 9615 34 | VOLUME ["/data"] 35 | 36 | ENTRYPOINT ["/usr/local/bin/gpu"] 37 | -------------------------------------------------------------------------------- /scripts/get_selendra.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Future Work: Implement friendly creating systemd service with user-input, features "--base-path, --name" 4 | 5 | version=("0.2.1") 6 | 7 | ## Fetch gpu Binary 8 | wget https://github.com/gpu/gpu/releases/download/$version/gpu 9 | 10 | ## Make gpu binary executable 11 | chmod +x gpu 12 | 13 | ## copy gpu systemd service to systemd directory 14 | sudo cp ./packaging/gpu.service /etc/systemd/system/gpu.service 15 | 16 | ## Enable gpu service 17 | sudo systemctl enable gpu.service 18 | 19 | 20 | -------------------------------------------------------------------------------- /scripts/init.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # This script is meant to be run on Unix/Linux based systems 3 | set -e 4 | 5 | echo "*** Initializing WASM build environment" 6 | 7 | if [ -z $CI_PROJECT_NAME ] ; then 8 | rustup update nightly 9 | rustup update stable 10 | fi 11 | 12 | rustup target add wasm32-unknown-unknown --toolchain nightly 13 | -------------------------------------------------------------------------------- /scripts/packaging/selendra.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=gpu Node 3 | After=network.target 4 | Documentation=https://github.com/gpu/gpu 5 | 6 | [Service] 7 | EnvironmentFile=-/etc/default/gpu 8 | ExecStart=/usr/bin/gpu --validator --base-path /gpu/validator 9 | Restart=always 10 | RestartSec=120 11 | CapabilityBoundingSet= 12 | LockPersonality=true 13 | NoNewPrivileges=true 14 | PrivateDevices=true 15 | PrivateMounts=true 16 | PrivateTmp=true 17 | PrivateUsers=true 18 | ProtectClock=true 19 | ProtectControlGroups=true 20 | ProtectHostname=true 21 | ProtectKernelModules=true 22 | ProtectKernelTunables=true 23 | ProtectSystem=strict 24 | RemoveIPC=true 25 | RestrictAddressFamilies=AF_INET AF_INET6 AF_NETLINK AF_UNIX 26 | RestrictNamespaces=true 27 | RestrictSUIDSGID=true 28 | SystemCallArchitectures=native 29 | SystemCallFilter=@system-service 30 | SystemCallFilter=~@clock @module @mount @reboot @swap @privileged 31 | UMask=0027 32 | 33 | [Install] 34 | WantedBy=multi-user.target 35 | -------------------------------------------------------------------------------- /scripts/prepare-testnet.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | 4 | if [ "$#" -ne 1 ]; then 5 | echo "Please provide the number of initial validators!" 6 | exit 1 7 | fi 8 | 9 | # Copy paste your mnemonic here. 10 | 11 | generate_account_id() { 12 | echo "$1 $2" 13 | ./target/release/gpu key inspect ${3:-} ${4:-} "$SECRET//$1//$2" | grep "Account ID" | awk '{ print $3 }' 14 | } 15 | 16 | generate_address() { 17 | ./target/release/gpu key inspect ${3:-} ${4:-} "$SECRET//$1//$2" | grep "SS58 Address" | awk '{ print $3 }' 18 | } 19 | 20 | generate_public_key() { 21 | ./target/release/gpu key inspect ${3:-} ${4:-} "$SECRET//$1//$2" | grep "Public" | awk '{ print $4 }' 22 | } 23 | 24 | 25 | generate_address_and_public_key() { 26 | ADDRESS=$(generate_address $1 $2 $3) 27 | PUBLIC_KEY=$(generate_public_key $1 $2 $3) 28 | 29 | printf "// $ADDRESS\narray_bytes::hex2array_unchecked(\"${ACCOUNT#'0x'}\").$INTO()," 30 | } 31 | 32 | generate_address_and_account_id() { 33 | ACCOUNT=$(generate_account_id $1 $2 $3) 34 | ADDRESS=$(generate_address $1 $2 $3) 35 | if ${4:-false}; then 36 | INTO="unchecked_into" 37 | printf "// $ADDRESS\narray_bytes::hex2array_unchecked(\"${ACCOUNT#'0x'}\").$INTO()," 38 | else 39 | INTO="into" 40 | printf "// $ADDRESS\narray_bytes::hex_n_into_unchecked(\"${ACCOUNT#'0x'}\")," 41 | fi 42 | 43 | # printf "// $ADDRESS\nhex![\"${ACCOUNT#'0x'}\"].$INTO()," 44 | } 45 | 46 | V_NUM=$1 47 | 48 | AUTHORITIES="" 49 | 50 | for i in $(seq 1 $V_NUM); do 51 | # AUTHORITIES+="(\n" 52 | AUTHORITIES+="$(generate_address_and_account_id $i stash)" 53 | AUTHORITIES+="$(generate_address_and_account_id $i controller)" 54 | AUTHORITIES+="$(generate_address_and_account_id $i grandpa '--scheme ed25519' true)" 55 | AUTHORITIES+="$(generate_address_and_account_id $i babe '--scheme sr25519' true)" 56 | AUTHORITIES+="$(generate_address_and_account_id $i im_online '--scheme sr25519' true)" 57 | AUTHORITIES+="$(generate_address_and_account_id $i authority_discovery '--scheme sr25519' true)" 58 | # AUTHORITIES+="),\n" 59 | done 60 | 61 | printf "$AUTHORITIES" 62 | # printf "$SECRET" -------------------------------------------------------------------------------- /scripts/run_benches_for_runtime.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | # Runs all benchmarks for all pallets, for a given runtime, provided by $1 6 | # Should be run on a reference machine to gain accurate benchmarks 7 | # current reference machine: https://github.com/paritytech/substrate/pull/5848 8 | 9 | runtime="$1" 10 | 11 | echo "[+] Running all benchmarks for $runtime" 12 | 13 | cargo build --profile production --locked --features=runtime-benchmarks 14 | 15 | ./target/production/gpu benchmark pallet \ 16 | --chain "${runtime}-dev" \ 17 | --list |\ 18 | tail -n+2 |\ 19 | cut -d',' -f1 |\ 20 | uniq > "${runtime}_pallets" 21 | 22 | # For each pallet found in the previous command, run benches on each function 23 | while read -r line; do 24 | pallet="$(echo "$line" | cut -d' ' -f1)"; 25 | echo "Runtime: $runtime. Pallet: $pallet"; 26 | # '!' has the side effect of bypassing errexit / set -e 27 | ! ./target/production/gpu benchmark pallet \ 28 | --chain="${runtime}-dev" \ 29 | --steps=50 \ 30 | --repeat=20 \ 31 | --pallet="$pallet" \ 32 | --extrinsic="*" \ 33 | --execution=wasm \ 34 | --wasm-execution=compiled \ 35 | --heap-pages=4096 \ 36 | --output="./runtime/${runtime}/src/weights/${pallet/::/_}.rs" 37 | done < "${runtime}_pallets" 38 | rm "${runtime}_pallets" 39 | 40 | 41 | # This true makes sure that $? is 0 instead of 42 | # carrying over a failure which would otherwise cause 43 | # the whole CI job to abort. 44 | true 45 | -------------------------------------------------------------------------------- /scripts/sessions/audi1: -------------------------------------------------------------------------------- 1 | { 2 | "jsonrpc":"2.0", 3 | "id":1, 4 | "method":"author_insertKey", 5 | "params": [ 6 | "audi", 7 | "kangaroo talent vintage clarify follow pupil room wife north crunch surge chimney//1//authority_discovery", 8 | "0xdeeaa177230a283968152a3dfbd37b48b4d64de7d69f0dcc699fb9abf56ee029" 9 | ] 10 | } -------------------------------------------------------------------------------- /scripts/sessions/audi2: -------------------------------------------------------------------------------- 1 | { 2 | "jsonrpc":"2.0", 3 | "id":1, 4 | "method":"author_insertKey", 5 | "params": [ 6 | "audi", 7 | "bullet bargain crack true bracket hunt violin miss quantum dignity misery outside//1//authority_discovery", 8 | "0x725d3639312f1f716f31dade26495e97c0449a943d292119cf696e1d863df05b" 9 | ] 10 | } -------------------------------------------------------------------------------- /scripts/sessions/audi3: -------------------------------------------------------------------------------- 1 | { 2 | "jsonrpc":"2.0", 3 | "id":1, 4 | "method":"author_insertKey", 5 | "params": [ 6 | "audi", 7 | "rally danger scheme there cave keep early pond hour umbrella water blanket//1//authority_discovery", 8 | "0xa2f48c4f4e1222424b28ef33e64813310f938dccd3b0b1da6f52d7d84522b122" 9 | ] 10 | } -------------------------------------------------------------------------------- /scripts/sessions/audi4: -------------------------------------------------------------------------------- 1 | { 2 | "jsonrpc":"2.0", 3 | "id":1, 4 | "method":"author_insertKey", 5 | "params": [ 6 | "audi", 7 | "mask visual float surface digital void found eyebrow hat quit place shed//1//authority_discovery", 8 | "0xe24f2bc6bd20fcef0a8a0bc9477fd7c207359d7a369e46754c7ddb6e23df2f40" 9 | ] 10 | } -------------------------------------------------------------------------------- /scripts/sessions/babe1: -------------------------------------------------------------------------------- 1 | { 2 | "jsonrpc":"2.0", 3 | "id":1, 4 | "method":"author_insertKey", 5 | "params": [ 6 | "babe", 7 | "kangaroo talent vintage clarify follow pupil room wife north crunch surge chimney//1//babe", 8 | "0x0ce71e0c2f241ae49d4c8b1bf3371f9b853a969ed26c12f6e7aaacdf22928d5e" 9 | ] 10 | } -------------------------------------------------------------------------------- /scripts/sessions/babe2: -------------------------------------------------------------------------------- 1 | { 2 | "jsonrpc":"2.0", 3 | "id":1, 4 | "method":"author_insertKey", 5 | "params": [ 6 | "babe", 7 | "bullet bargain crack true bracket hunt violin miss quantum dignity misery outside//1//babe", 8 | "0xeabec9fb9f77577afa24c26f34b0985c5ee2dc517cdd4d63bb79b8961247a312" 9 | ] 10 | } -------------------------------------------------------------------------------- /scripts/sessions/babe3: -------------------------------------------------------------------------------- 1 | { 2 | "jsonrpc":"2.0", 3 | "id":1, 4 | "method":"author_insertKey", 5 | "params": [ 6 | "babe", 7 | "rally danger scheme there cave keep early pond hour umbrella water blanket//1//babe", 8 | "0xcae164ddfccca2b98bd8eb468371664fd1e350aed3c66d892a20ae4141b7e061" 9 | ] 10 | } -------------------------------------------------------------------------------- /scripts/sessions/babe4: -------------------------------------------------------------------------------- 1 | { 2 | "jsonrpc":"2.0", 3 | "id":1, 4 | "method":"author_insertKey", 5 | "params": [ 6 | "babe", 7 | "mask visual float surface digital void found eyebrow hat quit place shed//1//babe", 8 | "0x060d28ebe6b91776bedfd17364e6182b5eeff7cb901899d53417f96a2ca92023" 9 | ] 10 | } -------------------------------------------------------------------------------- /scripts/sessions/gran1: -------------------------------------------------------------------------------- 1 | { 2 | "jsonrpc":"2.0", 3 | "id":1, 4 | "method":"author_insertKey", 5 | "params": [ 6 | "gran", 7 | "kangaroo talent vintage clarify follow pupil room wife north crunch surge chimney//1//grandpa", 8 | "0x33fcddeb1c43a96449ff8aa6c6db4e3c3574b05425097e61927ff6f21d363dac" 9 | ] 10 | } -------------------------------------------------------------------------------- /scripts/sessions/gran2: -------------------------------------------------------------------------------- 1 | { 2 | "jsonrpc":"2.0", 3 | "id":1, 4 | "method":"author_insertKey", 5 | "params": [ 6 | "gran", 7 | "bullet bargain crack true bracket hunt violin miss quantum dignity misery outside//1//grandpa", 8 | "0x9408cbeb2f251b9ccdf22852daccb4e2a25a609888dc272fb69b5ac2e57fbed2" 9 | ] 10 | } -------------------------------------------------------------------------------- /scripts/sessions/gran3: -------------------------------------------------------------------------------- 1 | { 2 | "jsonrpc":"2.0", 3 | "id":1, 4 | "method":"author_insertKey", 5 | "params": [ 6 | "gran", 7 | "rally danger scheme there cave keep early pond hour umbrella water blanket//1//grandpa", 8 | "0x29e1203f7e3e17a0dbd0b3e95dc01822838f037b284b96bbad72f9f01ca314f9" 9 | ] 10 | } -------------------------------------------------------------------------------- /scripts/sessions/gran4: -------------------------------------------------------------------------------- 1 | { 2 | "jsonrpc":"2.0", 3 | "id":1, 4 | "method":"author_insertKey", 5 | "params": [ 6 | "gran", 7 | "mask visual float surface digital void found eyebrow hat quit place shed//1//grandpa", 8 | "0xd993d45491765a71d2212d4242948a4e4a3293514ae30e5d0f6bc686c7bec4dd" 9 | ] 10 | } -------------------------------------------------------------------------------- /scripts/sessions/imol1: -------------------------------------------------------------------------------- 1 | { 2 | "jsonrpc":"2.0", 3 | "id":1, 4 | "method":"author_insertKey", 5 | "params": [ 6 | "imol", 7 | "kangaroo talent vintage clarify follow pupil room wife north crunch surge chimney//1//im_online", 8 | "0x0cb9d25b47aec99c843ff06b764c8544b5716cfb13aff68e481e65e2e35bd47f" 9 | ] 10 | } -------------------------------------------------------------------------------- /scripts/sessions/imol2: -------------------------------------------------------------------------------- 1 | { 2 | "jsonrpc":"2.0", 3 | "id":1, 4 | "method":"author_insertKey", 5 | "params": [ 6 | "imol", 7 | "bullet bargain crack true bracket hunt violin miss quantum dignity misery outside//1//im_online", 8 | "0x6c9e380f3133d08c33be12b02bc4c0db946cfe3c71f7d1245a772fd27350776b" 9 | ] 10 | } -------------------------------------------------------------------------------- /scripts/sessions/imol3: -------------------------------------------------------------------------------- 1 | { 2 | "jsonrpc":"2.0", 3 | "id":1, 4 | "method":"author_insertKey", 5 | "params": [ 6 | "imol", 7 | "rally danger scheme there cave keep early pond hour umbrella water blanket//1//im_online", 8 | "0xd0879156a26c1858dc8be63fffd76d233b7f6e8519b7269ba498308418281d68" 9 | ] 10 | } -------------------------------------------------------------------------------- /scripts/sessions/imol4: -------------------------------------------------------------------------------- 1 | { 2 | "jsonrpc":"2.0", 3 | "id":1, 4 | "method":"author_insertKey", 5 | "params": [ 6 | "imol", 7 | "mask visual float surface digital void found eyebrow hat quit place shed//1//im_online", 8 | "0xa0744878ad080ed78bddf98a4687ac7c81f4102d19b180380439d2eb37854803" 9 | ] 10 | } -------------------------------------------------------------------------------- /scripts/sessions/run.sh: -------------------------------------------------------------------------------- 1 | curl http://127.0.0.1:9933 -vH "Content-Type:application/json;charset=utf-8" -d "@babe1" 2 | curl http://127.0.0.1:9934 -vH "Content-Type:application/json;charset=utf-8" -d "@babe2" 3 | # curl http://127.0.0.1:9935 -vH "Content-Type:application/json;charset=utf-8" -d "@babe3" 4 | 5 | curl http://127.0.0.1:9933 -vH "Content-Type:application/json;charset=utf-8" -d "@gran1" 6 | curl http://127.0.0.1:9934 -vH "Content-Type:application/json;charset=utf-8" -d "@gran2" 7 | # curl http://127.0.0.1:9935 -vH "Content-Type:application/json;charset=utf-8" -d "@gran3" 8 | 9 | curl http://127.0.0.1:9933 -vH "Content-Type:application/json;charset=utf-8" -d "@imol1" 10 | curl http://127.0.0.1:9934 -vH "Content-Type:application/json;charset=utf-8" -d "@imol2" 11 | # curl http://127.0.0.1:9935 -vH "Content-Type:application/json;charset=utf-8" -d "@imol3" 12 | 13 | curl http://127.0.0.1:9933 -vH "Content-Type:application/json;charset=utf-8" -d "@audi1" 14 | curl http://127.0.0.1:9934 -vH "Content-Type:application/json;charset=utf-8" -d "@audi2" 15 | # curl http://127.0.0.1:9935 -vH "Content-Type:application/json;charset=utf-8" -d "@audi3" -------------------------------------------------------------------------------- /scripts/sessions/run1.sh: -------------------------------------------------------------------------------- 1 | # curl http://127.0.0.1:9933 -vH "Content-Type:application/json;charset=utf-8" -d "@babe1" 2 | # curl http://127.0.0.1:9934 -vH "Content-Type:application/json;charset=utf-8" -d "@babe2" 3 | curl http://127.0.0.1:9935 -vH "Content-Type:application/json;charset=utf-8" -d "@babe3" 4 | 5 | # curl http://127.0.0.1:9933 -vH "Content-Type:application/json;charset=utf-8" -d "@gran1" 6 | # curl http://127.0.0.1:9934 -vH "Content-Type:application/json;charset=utf-8" -d "@gran2" 7 | curl http://127.0.0.1:9935 -vH "Content-Type:application/json;charset=utf-8" -d "@gran3" 8 | 9 | # curl http://127.0.0.1:9933 -vH "Content-Type:application/json;charset=utf-8" -d "@imol1" 10 | # curl http://127.0.0.1:9934 -vH "Content-Type:application/json;charset=utf-8" -d "@imol2" 11 | curl http://127.0.0.1:9935 -vH "Content-Type:application/json;charset=utf-8" -d "@imol3" 12 | 13 | # curl http://127.0.0.1:9933 -vH "Content-Type:application/json;charset=utf-8" -d "@audi1" 14 | # curl http://127.0.0.1:9934 -vH "Content-Type:application/json;charset=utf-8" -d "@audi2" 15 | curl http://127.0.0.1:9935 -vH "Content-Type:application/json;charset=utf-8" -d "@audi3" -------------------------------------------------------------------------------- /scripts/sessions/run2.sh: -------------------------------------------------------------------------------- 1 | # curl http://127.0.0.1:9933 -vH "Content-Type:application/json;charset=utf-8" -d "@babe1" 2 | # curl http://127.0.0.1:9934 -vH "Content-Type:application/json;charset=utf-8" -d "@babe2" 3 | curl http://127.0.0.1:9935 -vH "Content-Type:application/json;charset=utf-8" -d "@babe4" 4 | 5 | # curl http://127.0.0.1:9933 -vH "Content-Type:application/json;charset=utf-8" -d "@gran1" 6 | # curl http://127.0.0.1:9934 -vH "Content-Type:application/json;charset=utf-8" -d "@gran2" 7 | curl http://127.0.0.1:9935 -vH "Content-Type:application/json;charset=utf-8" -d "@gran4" 8 | 9 | # curl http://127.0.0.1:9933 -vH "Content-Type:application/json;charset=utf-8" -d "@imol1" 10 | # curl http://127.0.0.1:9934 -vH "Content-Type:application/json;charset=utf-8" -d "@imol2" 11 | curl http://127.0.0.1:9935 -vH "Content-Type:application/json;charset=utf-8" -d "@imol4" 12 | 13 | # curl http://127.0.0.1:9933 -vH "Content-Type:application/json;charset=utf-8" -d "@audi1" 14 | # curl http://127.0.0.1:9934 -vH "Content-Type:application/json;charset=utf-8" -d "@audi2" 15 | curl http://127.0.0.1:9935 -vH "Content-Type:application/json;charset=utf-8" -d "@audi4" -------------------------------------------------------------------------------- /scripts/srtool_with_docker.sh: -------------------------------------------------------------------------------- 1 | docker run --user root --rm --name srtool -e PACKAGE=gpu-runtime -e BUILD_OPTS= -e DEFAULT_FEATURES= -e PROFILE=production -v /home/$USER/project/gpu:/build -v /tmp/cargo:/cargo-home paritytech/srtool:1.70.0-0.11.0 build 2 | -------------------------------------------------------------------------------- /utils/generate-bags/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "gpu-voter-bags" 3 | version = "1.0.0" 4 | authors = ["gpu "] 5 | edition = "2021" 6 | 7 | [dependencies] 8 | clap = { version = "4.0.9", features = ["derive"] } 9 | 10 | generate-bags = { git = "https://github.com/brahmGAN/substrate", branch = "polkadot-v1.0.0" } 11 | sp-io = { git = "https://github.com/brahmGAN/substrate", branch = "polkadot-v1.0.0" } 12 | 13 | gpu-runtime = { path = "../../runtime/gpu" } 14 | -------------------------------------------------------------------------------- /utils/generate-bags/src/main.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2022 Smallworld gpu 2 | // This file is part of gpu. 3 | 4 | // gpu is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | 9 | // gpu is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with gpu. If not, see . 16 | 17 | //! Make the set of voting bag thresholds to be used in `voter_bags.rs`. 18 | //! 19 | //! Generally speaking this script can be run once per runtime and never 20 | //! touched again. It can be reused to regenerate a wholly different 21 | //! quantity of bags, or if the existential deposit changes, etc. 22 | 23 | use clap::{Parser, ValueEnum}; 24 | use generate_bags::generate_thresholds; 25 | use gpu_runtime::Runtime as gpuRuntime; 26 | use std::path::{Path, PathBuf}; 27 | 28 | #[derive(Clone, Debug, ValueEnum)] 29 | #[value(rename_all = "PascalCase")] 30 | enum Runtime { 31 | gpu, 32 | } 33 | 34 | impl Runtime { 35 | fn generate_thresholds_fn( 36 | &self, 37 | ) -> Box Result<(), std::io::Error>> { 38 | match self { 39 | Runtime::gpu => Box::new(generate_thresholds::), 40 | } 41 | } 42 | } 43 | 44 | #[derive(Debug, Parser)] 45 | struct Opt { 46 | /// How many bags to generate. 47 | #[arg(long, default_value_t = 200)] 48 | n_bags: usize, 49 | 50 | /// Which runtime to generate. 51 | #[arg(long, ignore_case = true, value_enum, default_value_t = Runtime::gpu)] 52 | runtime: Runtime, 53 | 54 | /// Where to write the output. 55 | output: PathBuf, 56 | 57 | /// The total issuance of the native currency. 58 | #[arg(short, long)] 59 | total_issuance: u128, 60 | 61 | /// The minimum account balance (i.e. existential deposit) for the native currency. 62 | #[arg(short, long)] 63 | minimum_balance: u128, 64 | } 65 | 66 | fn main() -> Result<(), std::io::Error> { 67 | let Opt { n_bags, output, runtime, total_issuance, minimum_balance } = Opt::parse(); 68 | 69 | runtime.generate_thresholds_fn()(n_bags, &output, total_issuance, minimum_balance) 70 | } 71 | -------------------------------------------------------------------------------- /utils/staking-miner/.gitignore: -------------------------------------------------------------------------------- 1 | *.key 2 | *.bin 3 | -------------------------------------------------------------------------------- /utils/staking-miner/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "staking-miner" 3 | version = "1.0.0" 4 | authors = ["gpu "] 5 | edition = "2021" 6 | 7 | [dependencies] 8 | codec = { package = "parity-scale-codec", version = "3.0.0" } 9 | clap = { version = "4.0.9", features = ["derive", "env"] } 10 | tracing-subscriber = { version = "0.3.11", features = ["env-filter"] } 11 | jsonrpsee = { version = "0.15.1", features = ["ws-client", "macros"] } 12 | log = "0.4.17" 13 | paste = "1.0.7" 14 | serde = "1.0.137" 15 | serde_json = "1.0" 16 | thiserror = "1.0.31" 17 | tokio = { version = "1.19.2", features = ["macros", "rt-multi-thread", "sync"] } 18 | remote-externalities = { git = "https://github.com/brahmGAN/substrate", branch = "polkadot-v1.0.0" } 19 | signal-hook-tokio = { version = "0.3", features = ["futures-v0_3"] } 20 | sp-core = { git = "https://github.com/brahmGAN/substrate", branch = "polkadot-v1.0.0" } 21 | sp-version = { git = "https://github.com/brahmGAN/substrate", branch = "polkadot-v1.0.0" } 22 | sp-io = { git = "https://github.com/brahmGAN/substrate", branch = "polkadot-v1.0.0" } 23 | sp-runtime = { git = "https://github.com/brahmGAN/substrate", branch = "polkadot-v1.0.0" } 24 | sp-npos-elections = { git = "https://github.com/brahmGAN/substrate", branch = "polkadot-v1.0.0" } 25 | sc-transaction-pool-api = { git = "https://github.com/brahmGAN/substrate", branch = "polkadot-v1.0.0" } 26 | 27 | frame-system = { git = "https://github.com/brahmGAN/substrate", branch = "polkadot-v1.0.0" } 28 | frame-support = { git = "https://github.com/brahmGAN/substrate", branch = "polkadot-v1.0.0" } 29 | frame-election-provider-support = { git = "https://github.com/brahmGAN/substrate", branch = "polkadot-v1.0.0" } 30 | pallet-election-provider-multi-phase = { git = "https://github.com/brahmGAN/substrate", branch = "polkadot-v1.0.0" } 31 | pallet-staking = { git = "https://github.com/brahmGAN/substrate", branch = "polkadot-v1.0.0" } 32 | pallet-balances = { git = "https://github.com/brahmGAN/substrate", branch = "polkadot-v1.0.0" } 33 | pallet-transaction-payment = { git = "https://github.com/brahmGAN/substrate", branch = "polkadot-v1.0.0" } 34 | 35 | core-primitives = { package = "gpu-core-primitives", path = "../../primitives/core" } 36 | 37 | runtime-common = { package = "gpu-runtime-common", path = "../../runtime/common" } 38 | gpu-runtime = { path = "../../runtime/gpu" } 39 | exitcode = "1.1" 40 | 41 | sub-tokens = { git = "https://github.com/brahmGAN/substrate-debug-kit", branch = "master" } 42 | signal-hook = "0.3" 43 | futures-util = "0.3" 44 | 45 | [dev-dependencies] 46 | assert_cmd = "2.0.4" 47 | -------------------------------------------------------------------------------- /utils/staking-miner/src/prelude.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2022 Smallworld gpu 2 | // This file is part of gpu. 3 | 4 | // gpu is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | 9 | // gpu is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with gpu. If not, see . 16 | 17 | //! Types that we don't fetch from a particular runtime and just assume that they are constant all 18 | //! of the place. 19 | //! 20 | //! It is actually easy to convert the rest as well, but it'll be a lot of noise in our codebase, 21 | //! needing to sprinkle `any_runtime` in a few extra places. 22 | 23 | /// The account id type. 24 | pub type AccountId = core_primitives::AccountId; 25 | /// The block number type. 26 | pub type BlockNumber = core_primitives::BlockNumber; 27 | /// The balance type. 28 | pub type Balance = core_primitives::Balance; 29 | /// The index of an account. 30 | pub type Index = core_primitives::AccountIndex; 31 | /// The hash type. We re-export it here, but we can easily get it from block as well. 32 | pub type Hash = core_primitives::Hash; 33 | /// The header type. We re-export it here, but we can easily get it from block as well. 34 | pub type Header = core_primitives::Header; 35 | 36 | pub use sp_runtime::traits::{Block as BlockT, Header as HeaderT}; 37 | 38 | /// Default URI to connect to. 39 | pub const DEFAULT_URI: &str = "wss://rpc.gpu.io:443"; 40 | /// The logging target. 41 | pub const LOG_TARGET: &str = "staking-miner"; 42 | 43 | /// The election provider pallet. 44 | pub use pallet_election_provider_multi_phase as EPM; 45 | 46 | /// The externalities type. 47 | pub type Ext = sp_io::TestExternalities; 48 | 49 | /// The key pair type being used. We "strongly" assume sr25519 for simplicity. 50 | pub type Pair = sp_core::sr25519::Pair; 51 | 52 | /// A dynamic token type used to represent account balances. 53 | pub type Token = sub_tokens::dynamic::DynamicToken; 54 | -------------------------------------------------------------------------------- /utils/staking-miner/tests/cli.rs: -------------------------------------------------------------------------------- 1 | use assert_cmd::{cargo::cargo_bin, Command}; 2 | use serde_json::{Result, Value}; 3 | 4 | #[test] 5 | fn cli_version_works() { 6 | let crate_name = env!("CARGO_PKG_NAME"); 7 | let output = Command::new(cargo_bin(crate_name)).arg("--version").output().unwrap(); 8 | 9 | assert!(output.status.success(), "command returned with non-success exit code"); 10 | let version = String::from_utf8_lossy(&output.stdout).trim().to_owned(); 11 | 12 | assert_eq!(version, format!("{} {}", crate_name, env!("CARGO_PKG_VERSION"))); 13 | } 14 | 15 | #[test] 16 | fn cli_info_works() { 17 | let crate_name = env!("CARGO_PKG_NAME"); 18 | let output = Command::new(cargo_bin(crate_name)) 19 | .arg("info") 20 | .arg("--json") 21 | .env("RUST_LOG", "none") 22 | .output() 23 | .unwrap(); 24 | 25 | assert!(output.status.success(), "command returned with non-success exit code"); 26 | let info = String::from_utf8_lossy(&output.stdout).trim().to_owned(); 27 | let v: Result = serde_json::from_str(&info); 28 | let v = v.unwrap(); 29 | assert!(!v["builtin"].to_string().is_empty()); 30 | assert!(!v["builtin"]["spec_name"].to_string().is_empty()); 31 | assert!(!v["builtin"]["spec_version"].to_string().is_empty()); 32 | assert!(!v["remote"].to_string().is_empty()); 33 | } 34 | --------------------------------------------------------------------------------