From b01894f4d31ddb62170bc7a8640aa20e39d1e40b Mon Sep 17 00:00:00 2001 From: Rodrigo Doria Medina Date: Tue, 3 Jun 2025 14:53:11 -0400 Subject: [PATCH 1/6] Add pallet benchmark dummy --- Cargo.lock | 80 ++++++++++------- Cargo.toml | 2 + pallets/benchmark-dummy/Cargo.toml | 47 ++++++++++ pallets/benchmark-dummy/src/benchmarking.rs | 86 +++++++++++++++++++ pallets/benchmark-dummy/src/lib.rs | 30 +++++++ pallets/benchmark-dummy/src/mock.rs | 44 ++++++++++ pallets/benchmark-dummy/src/weights.rs | 48 +++++++++++ runtime/Cargo.toml | 4 + runtime/src/benchmark.rs | 1 + runtime/src/lib.rs | 8 ++ runtime/src/weights.rs | 1 + runtime/src/weights/pallet_benchmark_dummy.rs | 65 ++++++++++++++ 12 files changed, 387 insertions(+), 29 deletions(-) create mode 100644 pallets/benchmark-dummy/Cargo.toml create mode 100644 pallets/benchmark-dummy/src/benchmarking.rs create mode 100644 pallets/benchmark-dummy/src/lib.rs create mode 100644 pallets/benchmark-dummy/src/mock.rs create mode 100644 pallets/benchmark-dummy/src/weights.rs create mode 100644 runtime/src/weights/pallet_benchmark_dummy.rs diff --git a/Cargo.lock b/Cargo.lock index 2d71369..f414221 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -180,7 +180,7 @@ dependencies = [ "cfg-if", "const-hex", "derive_more 0.99.19", - "hex-literal", + "hex-literal 0.4.1", "itoa", "proptest", "rand 0.8.5", @@ -200,7 +200,7 @@ dependencies = [ "cfg-if", "const-hex", "derive_more 0.99.19", - "hex-literal", + "hex-literal 0.4.1", "itoa", "k256", "keccak-asm", @@ -3804,7 +3804,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8d162beedaa69905488a8da94f5ac3edb4dd4788b732fadb7bd120b2625c1976" dependencies = [ "data-encoding", - "syn 1.0.109", + "syn 2.0.100", ] [[package]] @@ -5961,6 +5961,12 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" +[[package]] +name = "hex-literal" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bcaaec4551594c969335c98c903c1397853d4198408ea609190f420500f6be71" + [[package]] name = "hkdf" version = "0.12.4" @@ -6071,7 +6077,7 @@ name = "hp-verifiers" version = "0.1.0" source = "git+https://github.com/zkVerify/zkVerify.git?tag=0.9.1-0.13.0#44fed482a11e6185c67e193627863ec729e43b07" dependencies = [ - "hex-literal", + "hex-literal 0.4.1", "parity-scale-codec", "scale-info", "sp-core", @@ -7689,7 +7695,7 @@ dependencies = [ "ed25519-dalek", "futures", "futures-timer", - "hex-literal", + "hex-literal 0.4.1", "indexmap 2.9.0", "libc", "mockall 0.12.1", @@ -8828,7 +8834,7 @@ dependencies = [ "frame-benchmarking", "frame-support", "frame-system", - "hex-literal", + "hex-literal 0.4.1", "hp-dispatch", "hp-on-proof-verified", "ismp", @@ -9164,6 +9170,21 @@ dependencies = [ "sp-state-machine", ] +[[package]] +name = "pallet-benchmark-dummy" +version = "0.1.0" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "hex-literal 1.0.0", + "pallet-balances", + "pallet-evm", + "parity-scale-codec", + "scale-info", + "sp-core", +] + [[package]] name = "pallet-bounties" version = "37.0.2" @@ -9645,7 +9666,7 @@ dependencies = [ "frame-support", "frame-system", "hash-db", - "hex-literal", + "hex-literal 0.4.1", "impl-trait-for-tuples", "log", "parity-scale-codec", @@ -9799,7 +9820,7 @@ dependencies = [ "frame-benchmarking", "frame-support", "frame-system", - "hex-literal", + "hex-literal 0.4.1", "ismp", "log", "pallet-balances", @@ -9907,7 +9928,7 @@ dependencies = [ "anyhow", "hash-db", "hex", - "hex-literal", + "hex-literal 0.4.1", "ismp", "jsonrpsee", "pallet-ismp", @@ -10272,7 +10293,7 @@ dependencies = [ "frame-benchmarking", "frame-support", "frame-system", - "hex-literal", + "hex-literal 0.4.1", "hp-verifiers", "log", "pallet-verifiers", @@ -10519,7 +10540,7 @@ dependencies = [ "frame-benchmarking", "frame-support", "frame-system", - "hex-literal", + "hex-literal 0.4.1", "hp-verifiers", "log", "native", @@ -10969,7 +10990,7 @@ dependencies = [ "frame-benchmarking", "frame-support", "frame-system", - "hex-literal", + "hex-literal 0.4.1", "hp-verifiers", "log", "native", @@ -12432,7 +12453,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b57bc055fa389372ec5fc0001b99aeffd50f3fd379280ce572d935189bb58dd8" dependencies = [ "bitvec", - "hex-literal", + "hex-literal 0.4.1", "log", "parity-scale-codec", "polkadot-core-primitives", @@ -12459,7 +12480,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6bb20b75d33212150242d39890d7ededab55f1084160c337f15d0eb8ca8c3ad4" dependencies = [ "bitvec", - "hex-literal", + "hex-literal 0.4.1", "log", "parity-scale-codec", "polkadot-core-primitives", @@ -14278,7 +14299,7 @@ dependencies = [ "cfg-if", "digest 0.10.7", "hex", - "hex-literal", + "hex-literal 0.4.1", "metal", "paste", "rand_core 0.6.4", @@ -14347,7 +14368,7 @@ dependencies = [ "frame-system-benchmarking", "frame-system-rpc-runtime-api", "frame-try-runtime", - "hex-literal", + "hex-literal 0.4.1", "log", "pallet-asset-rate", "pallet-authority-discovery", @@ -16876,7 +16897,7 @@ dependencies = [ "ethabi-decode", "frame-support", "frame-system", - "hex-literal", + "hex-literal 0.4.1", "parity-scale-codec", "polkadot-parachain-primitives", "scale-info", @@ -16900,7 +16921,7 @@ dependencies = [ "ethabi-decode", "ethbloom", "ethereum-types", - "hex-literal", + "hex-literal 0.4.1", "parity-bytes", "parity-scale-codec", "rlp", @@ -16962,7 +16983,7 @@ dependencies = [ "frame-benchmarking", "frame-support", "frame-system", - "hex-literal", + "hex-literal 0.4.1", "log", "pallet-timestamp", "parity-scale-codec", @@ -16985,7 +17006,7 @@ version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3984b98465af1d862d4e87ba783e1731f2a3f851b148d6cb98d526cebd351185" dependencies = [ - "hex-literal", + "hex-literal 0.4.1", "snowbridge-beacon-primitives", "snowbridge-core", "sp-core", @@ -17003,7 +17024,7 @@ dependencies = [ "frame-benchmarking", "frame-support", "frame-system", - "hex-literal", + "hex-literal 0.4.1", "log", "pallet-balances", "parity-scale-codec", @@ -17027,7 +17048,7 @@ version = "0.18.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b1f251e579b3d3d93cf833c8e503122808742dee33e7ea53b0f292a76c024d66" dependencies = [ - "hex-literal", + "hex-literal 0.4.1", "snowbridge-beacon-primitives", "snowbridge-core", "sp-core", @@ -17085,7 +17106,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "aefe74eafeac92e1d9e46b7bb76ec297f6182b4a023f7e7eb7eb8be193f93bef" dependencies = [ "frame-support", - "hex-literal", + "hex-literal 0.4.1", "log", "parity-scale-codec", "scale-info", @@ -19446,7 +19467,7 @@ dependencies = [ "ark-ff 0.5.0", "ark-models-ext 0.6.0", "ark-std 0.5.0", - "hex-literal", + "hex-literal 0.4.1", "sha3", "snafu", ] @@ -20191,7 +20212,7 @@ dependencies = [ "frame-system-benchmarking", "frame-system-rpc-runtime-api", "frame-try-runtime", - "hex-literal", + "hex-literal 0.4.1", "log", "pallet-asset-rate", "pallet-authority-discovery", @@ -21058,7 +21079,7 @@ dependencies = [ "frame-benchmarking-cli", "frame-system", "futures", - "hex-literal", + "hex-literal 0.4.1", "jsonrpsee", "log", "pallet-transaction-payment", @@ -21129,11 +21150,12 @@ dependencies = [ "frame-system-rpc-runtime-api", "frame-try-runtime", "hex", - "hex-literal", + "hex-literal 0.4.1", "pallet-aura", "pallet-authorship", "pallet-balances", "pallet-base-fee", + "pallet-benchmark-dummy", "pallet-collator-selection", "pallet-ethereum", "pallet-evm", @@ -21194,7 +21216,7 @@ dependencies = [ "frame-system-benchmarking", "frame-system-rpc-runtime-api", "frame-try-runtime", - "hex-literal", + "hex-literal 0.4.1", "hp-dispatch", "hp-verifiers", "ismp", @@ -21290,7 +21312,7 @@ dependencies = [ "frame-system", "frame-system-rpc-runtime-api", "futures", - "hex-literal", + "hex-literal 0.4.1", "is_executable", "jsonrpsee", "kvdb", diff --git a/Cargo.toml b/Cargo.toml index f941854..b222e01 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,6 +8,7 @@ license = "GPL-3.0-only" [workspace] members = [ "node", + "pallets/benchmark-dummy", "pallets/parachain-inherent", "runtime", ] @@ -17,6 +18,7 @@ resolver = "2" # Local cumulus-client-parachain-inherent = {path = "pallets/parachain-inherent", default-features = false} +pallet-benchmark-dummy = {path = "pallets/benchmark-dummy", default-features = false} zkv-para-evm-runtime = {path = "runtime"} # Common diff --git a/pallets/benchmark-dummy/Cargo.toml b/pallets/benchmark-dummy/Cargo.toml new file mode 100644 index 0000000..72f7186 --- /dev/null +++ b/pallets/benchmark-dummy/Cargo.toml @@ -0,0 +1,47 @@ +[package] +name = "pallet-benchmark-dummy" +version = "0.1.0" +authors.workspace = true +edition.workspace = true +repository.workspace = true + +[dependencies] +hex-literal = { version = "1", default-features = false} +frame-benchmarking = {workspace = true, optional = true} +frame-support = {workspace = true} +frame-system = {workspace = true} +pallet-evm = {workspace = true} +parity-scale-codec = {workspace = true} +scale-info = {workspace = true} +sp-core = {workspace = true} + +[dev-dependencies] +pallet-balances = {workspace = true } + +[features] +default = [ "std" ] +std = [ + "frame-benchmarking?/std", + "frame-support/std", + "frame-system/std", + "pallet-evm/std", + "parity-scale-codec/std", + "scale-info/std", + "sp-core/std", +] +runtime-benchmarks = [ + "frame-benchmarking/runtime-benchmarks", + "frame-support/runtime-benchmarks", + "frame-system/runtime-benchmarks", + "pallet-balances/runtime-benchmarks", + "pallet-evm/runtime-benchmarks", +] +try-runtime = [ + "frame-support/try-runtime", + "frame-system/try-runtime", + "pallet-balances/try-runtime", + "pallet-evm/try-runtime", +] + +[package.metadata.cargo-machete] +ignored = ["parity-scale-codec", "scale-info"] \ No newline at end of file diff --git a/pallets/benchmark-dummy/src/benchmarking.rs b/pallets/benchmark-dummy/src/benchmarking.rs new file mode 100644 index 0000000..dda5108 --- /dev/null +++ b/pallets/benchmark-dummy/src/benchmarking.rs @@ -0,0 +1,86 @@ +use super::*; +use alloc::{vec, vec::Vec}; +use frame_benchmarking::v2::*; +use pallet_evm::AddressMapping; + +#[benchmarks(where T: pallet_evm::Config)] +mod benchmarks { + use super::*; + #[cfg(test)] + use crate::pallet::Pallet as Template; + + #[benchmark] + fn bench_heavy_contract_call(n: Linear<0, 100>) { + use frame_support::traits::Currency; + use hex_literal::hex; + use sp_core::{H160, U256}; + + // Fund an EVM account + let source = H160::repeat_byte(0x11); + + // Fund the account with a large balance + let account_id = ::AddressMapping::into_account_id(source); + let balance = 10_000_000_000_000_000_000u128 + .try_into() + .unwrap_or_default(); + let _ = ::Currency::deposit_creating(&account_id, balance); + + // Contract bytecode - simple counter contract + let contract_bytecode: Vec = hex!( + "6080604052348015600e575f5ffd5b506102308061001c5f395ff3fe608060405234801561000f575f5ffd5b5060043610610034575f3560e01c80633fa4f245146100385780636584ad8b14610056575b5f5ffd5b610040610072565b60405161004d91906100dd565b60405180910390f35b610070600480360381019061006b9190610124565b610077565b005b5f5481565b805f54610084919061017c565b5f819055505f5f548260405160200161009e9291906101cf565b604051602081830303815290604052805190602001205f1c9050805f54185f819055505050565b5f819050919050565b6100d7816100c5565b82525050565b5f6020820190506100f05f8301846100ce565b92915050565b5f5ffd5b610103816100c5565b811461010d575f5ffd5b50565b5f8135905061011e816100fa565b92915050565b5f60208284031215610139576101386100f6565b5b5f61014684828501610110565b91505092915050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b5f610186826100c5565b9150610191836100c5565b92508282019050808211156101a9576101a861014f565b5b92915050565b5f819050919050565b6101c96101c4826100c5565b6101af565b82525050565b5f6101da82856101b8565b6020820191506101ea82846101b8565b602082019150819050939250505056fea26469706673582212208e02abce628bcfccab523202b1013d6da271be717c0a9a2cd26b6e881aa76e1964736f6c634300081e0033" + ).to_vec(); + + let value = U256::zero(); + let gas_limit: u64 = 5_000_000; + let max_fee_per_gas = U256::from(1_000_000_000u64); + let max_priority_fee_per_gas = Some(U256::from(1_000_000_000u64)); + let nonce = Some(U256::zero()); + let access_list: Vec<(H160, Vec)> = vec![]; + + // Deploy contract - the deployment should succeed since we've granted permission + let _ = pallet_evm::Pallet::::create( + frame_system::RawOrigin::Root.into(), + source, + contract_bytecode.clone(), + value, + gas_limit, + max_fee_per_gas, + max_priority_fee_per_gas, + nonce, + access_list.clone(), + ); + + // Use a hardcoded contract address for the benchmark + // This is deterministic for the given source + nonce + let contract_address = H160::from(hex!("d9145cce52d386f254917e481eb44e9943f39138")); + + // Function selector for doWork(uint256) + let selector = [0x65, 0x84, 0xad, 0x8b]; + let mut arg = [0u8; 32]; + U256::from(n.min(1)).to_big_endian(&mut arg); // Use at most 1 to avoid computation errors + let mut input: Vec = selector.to_vec(); + input.extend_from_slice(&arg); + + // Instead of asserting the call result, let's just benchmark the execution + #[block] + { + // Just call the contract without asserting the result + // This will still benchmark the cost of making the call + let _ = pallet_evm::Pallet::::call( + frame_system::RawOrigin::Root.into(), + source, + contract_address, + input.clone(), + value, + gas_limit, + max_fee_per_gas, + max_priority_fee_per_gas, + Some(U256::from(1)), // increment nonce for each call + access_list.clone(), + ); + } + } + + #[cfg(test)] + impl_benchmark_test_suite!(Template, crate::mock::new_test_ext(), crate::mock::Test); +} diff --git a/pallets/benchmark-dummy/src/lib.rs b/pallets/benchmark-dummy/src/lib.rs new file mode 100644 index 0000000..099cbb8 --- /dev/null +++ b/pallets/benchmark-dummy/src/lib.rs @@ -0,0 +1,30 @@ +#![cfg_attr(not(feature = "std"), no_std)] + +extern crate alloc; + +use frame_support::pallet_prelude::Weight; +pub use pallet::*; + +/// A trait for pallet-specific weight information. +pub trait WeightInfo { + /// The range of component `n` is `[0, 100]`. + fn bench_heavy_contract_call(_n: u32) -> Weight; +} + +#[frame_support::pallet] +pub mod pallet { + #[pallet::pallet] + pub struct Pallet(_); + + #[pallet::config] + pub trait Config: frame_system::Config + pallet_evm::Config { + type WeightInfo: crate::WeightInfo; + } +} + +#[cfg(test)] +mod mock; + +#[cfg(feature = "runtime-benchmarks")] +mod benchmarking; +mod weights; diff --git a/pallets/benchmark-dummy/src/mock.rs b/pallets/benchmark-dummy/src/mock.rs new file mode 100644 index 0000000..0fee4c7 --- /dev/null +++ b/pallets/benchmark-dummy/src/mock.rs @@ -0,0 +1,44 @@ +use frame_support::{construct_runtime, derive_impl, traits::Currency}; +use sp_core::{H160, U256}; +use sp_runtime::BuildStorage; + +pub type Block = frame_system::mocking::MockBlock; +pub type AccountIdOf = + <::AccountProvider as pallet_evm::AccountProvider>::AccountId; +pub type BalanceOf = <::Currency as Currency>>::Balance; + +frame_support::construct_runtime!( + pub enum Test { + System: frame_system = 0, + Balances: pallet_balances = 1, + Evm: pallet_evm = 2, + } +); + +#[derive_impl(frame_system::config_preludes::TestDefaultConfig)] +impl frame_system::Config for Test { + type Block = Block; + type AccountId = sp_runtime::AccountId32; + type AccountData = pallet_balances::AccountData; + type Lookup = sp_runtime::traits::IdentityLookup; +} + +#[derive_impl(pallet_balances::config_preludes::TestDefaultConfig)] +impl pallet_balances::Config for Test { + type AccountStore = System; +} + +#[derive_impl(pallet_evm::config_preludes::TestDefaultConfig)] +impl pallet_evm::Config for Test { + type AccountProvider = pallet_evm::FrameSystemAccountProvider; + type Currency = Balances; + type Runner = pallet_evm::runner::stack::Runner; +} + +// Test externalities initialization +pub fn new_test_ext() -> sp_io::TestExternalities { + frame_system::GenesisConfig::::default() + .build_storage() + .unwrap() + .into() +} diff --git a/pallets/benchmark-dummy/src/weights.rs b/pallets/benchmark-dummy/src/weights.rs new file mode 100644 index 0000000..5b1f729 --- /dev/null +++ b/pallets/benchmark-dummy/src/weights.rs @@ -0,0 +1,48 @@ + +//! Autogenerated weights for `pallet_deployment_permissions` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 43.0.0 +//! DATE: 2025-04-18, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` +//! HOSTNAME: `DESKTOP-37J5UBI`, CPU: `Intel(R) Core(TM) Ultra 9 185H` +//! WASM-EXECUTION: `Compiled`, CHAIN: `None`, DB CACHE: `1024` +// Executed Command: +// ./target/release/zkv-para-evm-node +// benchmark +// pallet +// --pallet +// pallet-deployment-permissions +// --extrinsic +// +// --template +// scripts/templates/pallets-weight-template.hbs +// --output +// pallets/deployment-permissions/src/weights.rs + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] +#![allow(missing_docs)] + +use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; +use core::marker::PhantomData; + +/// Weight functions needed for `pallet_deployment_permissions`. +pub trait WeightInfo { + fn bench_heavy_contract_call() -> Weight; +} + +// For backwards compatibility and tests. +impl WeightInfo for () { + /// Storage: `DeploymentPermissions::Deployers` (r:1 w:1) + /// Proof: `DeploymentPermissions::Deployers` (`max_values`: None, `max_size`: Some(36), added: 2511, mode: `MaxEncodedLen`) + fn bench_heavy_contract_call() -> Weight { + // Proof Size summary in bytes: + // Measured: `109` + // Estimated: `3501` + // Minimum execution time: 8_740_000 picoseconds. + Weight::from_parts(9_191_000, 3501) + .saturating_add(RocksDbWeight::get().reads(1_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) + } +} \ No newline at end of file diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index f29324b..51c3cc9 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -28,6 +28,7 @@ frame-try-runtime = {workspace = true, optional = true} pallet-aura = {workspace = true} pallet-authorship = {workspace = true} pallet-balances = {workspace = true, features = ["insecure_zero_ed"]} +pallet-benchmark-dummy = {workspace = true} pallet-message-queue = {workspace = true} pallet-multisig = {workspace = true} pallet-proxy = {workspace = true} @@ -121,6 +122,7 @@ std = [ "pallet-balances/std", "pallet-base-fee/std", "pallet-collator-selection/std", + "pallet-benchmark-dummy/std", "pallet-ethereum/std", "pallet-evm-chain-id/std", "pallet-evm-precompile-modexp/std", @@ -173,6 +175,7 @@ runtime-benchmarks = [ "frame-system/runtime-benchmarks", "pallet-balances/runtime-benchmarks", "pallet-collator-selection/runtime-benchmarks", + "pallet-benchmark-dummy/runtime-benchmarks", "pallet-ethereum/runtime-benchmarks", "pallet-evm/runtime-benchmarks", "pallet-message-queue/runtime-benchmarks", @@ -204,6 +207,7 @@ try-runtime = [ "pallet-balances/try-runtime", "pallet-base-fee/try-runtime", "pallet-collator-selection/try-runtime", + "pallet-benchmark-dummy/try-runtime", "pallet-ethereum/try-runtime", "pallet-evm-chain-id/try-runtime", "pallet-evm/try-runtime", diff --git a/runtime/src/benchmark.rs b/runtime/src/benchmark.rs index f70cbfb..ffca686 100644 --- a/runtime/src/benchmark.rs +++ b/runtime/src/benchmark.rs @@ -33,6 +33,7 @@ frame_benchmarking::define_benchmarks!( [pallet_message_queue, MessageQueue] [pallet_evm, EVM] + [pallet_benchmark_dummy, BenchmarkDummy] ); use cumulus_primitives_core::{ChannelStatus, GetChannelInfo}; diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 833e514..c68d5e6 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -218,6 +218,11 @@ cumulus_pallet_parachain_system::register_validate_block! { #[cfg(feature = "runtime-benchmarks")] mod benchmark; +// BenchmarkDummy pallet configuration +impl pallet_benchmark_dummy::Config for Runtime { + type WeightInfo = weights::pallet_benchmark_dummy::ZKVEvmWeight; +} + // Create the runtime by composing the FRAME pallets that were previously // configured. construct_runtime!( @@ -258,6 +263,9 @@ construct_runtime!( EVM: pallet_evm = 41, BaseFee: pallet_base_fee = 42, // No weight EVMChainId: pallet_evm_chain_id = 43, // No weight + + // Benchmarking + BenchmarkDummy: pallet_benchmark_dummy = 50, } ); diff --git a/runtime/src/weights.rs b/runtime/src/weights.rs index e908b38..0f48991 100644 --- a/runtime/src/weights.rs +++ b/runtime/src/weights.rs @@ -23,6 +23,7 @@ pub mod db; pub mod extrinsic_weights; pub mod frame_system; pub mod pallet_balances; +pub mod pallet_benchmark_dummy; pub mod pallet_collator_selection; pub mod pallet_evm; pub mod pallet_message_queue; diff --git a/runtime/src/weights/pallet_benchmark_dummy.rs b/runtime/src/weights/pallet_benchmark_dummy.rs new file mode 100644 index 0000000..6244093 --- /dev/null +++ b/runtime/src/weights/pallet_benchmark_dummy.rs @@ -0,0 +1,65 @@ +// Copyright 2024, Horizen Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//! Autogenerated weights for `pallet_benchmark_dummy` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 43.0.0 +//! DATE: 2025-06-03, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` +//! HOSTNAME: `Rodrigos-MacBook-Pro.local`, CPU: `` +//! WASM-EXECUTION: `Compiled`, CHAIN: `None`, DB CACHE: `1024` + +// Executed Command: +// /Users/rdoria/horizen/bis/bis/zkVerify-EVM-Parachain/target/production/zkv-para-evm-node +// benchmark +// pallet +// --genesis-builder=spec +// --pallet +// pallet-benchmark-dummy +// --extrinsic +// * +// --steps +// 50 +// --repeat +// 20 +// --heap-pages=4096 +// --header +// /Users/rdoria/horizen/bis/bis/zkVerify-EVM-Parachain/HEADER-APACHE2 +// --output +// /Users/rdoria/horizen/bis/bis/zkVerify-EVM-Parachain/runtime/src/weights/pallet_benchmark_dummy.rs +// --template +// /Users/rdoria/horizen/bis/bis/zkVerify-EVM-Parachain/scripts/templates/deploy-weight-template.hbs + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] +#![allow(missing_docs)] + +use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; +use core::marker::PhantomData; + +/// Weights for `pallet_benchmark_dummy` using the zkVerify node and recommended hardware. +pub struct ZKVEvmWeight(PhantomData); + +impl pallet_benchmark_dummy::WeightInfo for ZKVEvmWeight { + /// The range of component `n` is `[0, 100]`. + fn bench_heavy_contract_call(_n: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 1_000_000 picoseconds. + Weight::from_parts(1_614_161, 0) + } +} From 9a98dc5068f4e4707b31c49f226634bd8c75442f Mon Sep 17 00:00:00 2001 From: Rodrigo Doria Medina Date: Tue, 3 Jun 2025 15:29:40 -0400 Subject: [PATCH 2/6] fix: format --- pallets/benchmark-dummy/Cargo.toml | 34 +++++++++++++++--------------- runtime/Cargo.toml | 6 +++--- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/pallets/benchmark-dummy/Cargo.toml b/pallets/benchmark-dummy/Cargo.toml index 72f7186..49bbe51 100644 --- a/pallets/benchmark-dummy/Cargo.toml +++ b/pallets/benchmark-dummy/Cargo.toml @@ -21,27 +21,27 @@ pallet-balances = {workspace = true } [features] default = [ "std" ] std = [ - "frame-benchmarking?/std", - "frame-support/std", - "frame-system/std", - "pallet-evm/std", - "parity-scale-codec/std", - "scale-info/std", - "sp-core/std", + "frame-benchmarking?/std", + "frame-support/std", + "frame-system/std", + "pallet-evm/std", + "parity-scale-codec/std", + "scale-info/std", + "sp-core/std", ] runtime-benchmarks = [ - "frame-benchmarking/runtime-benchmarks", - "frame-support/runtime-benchmarks", - "frame-system/runtime-benchmarks", - "pallet-balances/runtime-benchmarks", - "pallet-evm/runtime-benchmarks", + "frame-benchmarking/runtime-benchmarks", + "frame-support/runtime-benchmarks", + "frame-system/runtime-benchmarks", + "pallet-balances/runtime-benchmarks", + "pallet-evm/runtime-benchmarks", ] try-runtime = [ - "frame-support/try-runtime", - "frame-system/try-runtime", - "pallet-balances/try-runtime", - "pallet-evm/try-runtime", + "frame-support/try-runtime", + "frame-system/try-runtime", + "pallet-balances/try-runtime", + "pallet-evm/try-runtime", ] [package.metadata.cargo-machete] -ignored = ["parity-scale-codec", "scale-info"] \ No newline at end of file +ignored = ["parity-scale-codec", "scale-info"] diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index 51c3cc9..4414a7b 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -121,8 +121,8 @@ std = [ "pallet-authorship/std", "pallet-balances/std", "pallet-base-fee/std", - "pallet-collator-selection/std", "pallet-benchmark-dummy/std", + "pallet-collator-selection/std", "pallet-ethereum/std", "pallet-evm-chain-id/std", "pallet-evm-precompile-modexp/std", @@ -174,8 +174,8 @@ runtime-benchmarks = [ "frame-system-benchmarking/runtime-benchmarks", "frame-system/runtime-benchmarks", "pallet-balances/runtime-benchmarks", - "pallet-collator-selection/runtime-benchmarks", "pallet-benchmark-dummy/runtime-benchmarks", + "pallet-collator-selection/runtime-benchmarks", "pallet-ethereum/runtime-benchmarks", "pallet-evm/runtime-benchmarks", "pallet-message-queue/runtime-benchmarks", @@ -206,8 +206,8 @@ try-runtime = [ "pallet-authorship/try-runtime", "pallet-balances/try-runtime", "pallet-base-fee/try-runtime", - "pallet-collator-selection/try-runtime", "pallet-benchmark-dummy/try-runtime", + "pallet-collator-selection/try-runtime", "pallet-ethereum/try-runtime", "pallet-evm-chain-id/try-runtime", "pallet-evm/try-runtime", From af0fe449c21887e3564ab3a8293f5da020d7490d Mon Sep 17 00:00:00 2001 From: Rodrigo Doria Medina Date: Tue, 3 Jun 2025 16:22:56 -0400 Subject: [PATCH 3/6] fix: format --- pallets/benchmark-dummy/Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pallets/benchmark-dummy/Cargo.toml b/pallets/benchmark-dummy/Cargo.toml index 49bbe51..2e6092d 100644 --- a/pallets/benchmark-dummy/Cargo.toml +++ b/pallets/benchmark-dummy/Cargo.toml @@ -24,6 +24,7 @@ std = [ "frame-benchmarking?/std", "frame-support/std", "frame-system/std", + "pallet-balances/std", "pallet-evm/std", "parity-scale-codec/std", "scale-info/std", From 1995100518907b15de4f6eecb924d9d16ae2b635 Mon Sep 17 00:00:00 2001 From: Rodrigo Doria Medina Date: Wed, 4 Jun 2025 08:47:14 -0400 Subject: [PATCH 4/6] fix: errors --- Cargo.lock | 4 ++++ pallets/benchmark-dummy/Cargo.toml | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index f414221..df85f61 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9180,9 +9180,13 @@ dependencies = [ "hex-literal 1.0.0", "pallet-balances", "pallet-evm", + "pallet-timestamp", "parity-scale-codec", "scale-info", "sp-core", + "sp-io", + "sp-runtime", + "sp-std", ] [[package]] diff --git a/pallets/benchmark-dummy/Cargo.toml b/pallets/benchmark-dummy/Cargo.toml index 2e6092d..1e96034 100644 --- a/pallets/benchmark-dummy/Cargo.toml +++ b/pallets/benchmark-dummy/Cargo.toml @@ -16,7 +16,11 @@ scale-info = {workspace = true} sp-core = {workspace = true} [dev-dependencies] +sp-io = { workspace = true, features = ["std"] } pallet-balances = {workspace = true } +pallet-timestamp = {workspace = true } +sp-runtime = {workspace = true} +sp-std = {workspace = true} [features] default = [ "std" ] @@ -26,9 +30,13 @@ std = [ "frame-system/std", "pallet-balances/std", "pallet-evm/std", + "pallet-timestamp/std", "parity-scale-codec/std", "scale-info/std", "sp-core/std", + "sp-io/std", + "sp-runtime/std", + "sp-std/std", ] runtime-benchmarks = [ "frame-benchmarking/runtime-benchmarks", @@ -36,12 +44,16 @@ runtime-benchmarks = [ "frame-system/runtime-benchmarks", "pallet-balances/runtime-benchmarks", "pallet-evm/runtime-benchmarks", + "pallet-timestamp/runtime-benchmarks", + "sp-runtime/runtime-benchmarks", ] try-runtime = [ "frame-support/try-runtime", "frame-system/try-runtime", "pallet-balances/try-runtime", "pallet-evm/try-runtime", + "pallet-timestamp/try-runtime", + "sp-runtime/try-runtime", ] [package.metadata.cargo-machete] From 3edbcacc7f4785f3f472f25a1ac4330305557a87 Mon Sep 17 00:00:00 2001 From: Rodrigo Doria Medina Date: Wed, 4 Jun 2025 10:39:42 -0400 Subject: [PATCH 5/6] fix: errors --- pallets/benchmark-dummy/src/mock.rs | 10 ++++++++-- pallets/benchmark-dummy/src/weights.rs | 10 ++++------ runtime/src/weights/pallet_benchmark_dummy.rs | 10 ++++++---- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/pallets/benchmark-dummy/src/mock.rs b/pallets/benchmark-dummy/src/mock.rs index 0fee4c7..e9141c2 100644 --- a/pallets/benchmark-dummy/src/mock.rs +++ b/pallets/benchmark-dummy/src/mock.rs @@ -10,8 +10,9 @@ pub type BalanceOf = <::Currency as Currency; } +#[derive_impl(pallet_timestamp::config_preludes::TestDefaultConfig)] +impl pallet_timestamp::Config for Test {} + #[derive_impl(pallet_balances::config_preludes::TestDefaultConfig)] impl pallet_balances::Config for Test { type AccountStore = System; @@ -31,6 +35,8 @@ impl pallet_balances::Config for Test { #[derive_impl(pallet_evm::config_preludes::TestDefaultConfig)] impl pallet_evm::Config for Test { type AccountProvider = pallet_evm::FrameSystemAccountProvider; + type BlockHashMapping = pallet_evm::SubstrateBlockHashMapping; + type Timestamp = Timestamp; type Currency = Balances; type Runner = pallet_evm::runner::stack::Runner; } diff --git a/pallets/benchmark-dummy/src/weights.rs b/pallets/benchmark-dummy/src/weights.rs index 5b1f729..4fe7364 100644 --- a/pallets/benchmark-dummy/src/weights.rs +++ b/pallets/benchmark-dummy/src/weights.rs @@ -1,5 +1,5 @@ -//! Autogenerated weights for `pallet_deployment_permissions` +//! Autogenerated weights for `pallet_benchmark_dummy` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 43.0.0 //! DATE: 2025-04-18, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` @@ -11,13 +11,13 @@ // benchmark // pallet // --pallet -// pallet-deployment-permissions +// pallet-benchmark-dummy // --extrinsic // // --template // scripts/templates/pallets-weight-template.hbs // --output -// pallets/deployment-permissions/src/weights.rs +// pallets/pallet-benchmark-dummy/src/weights.rs #![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] @@ -27,15 +27,13 @@ use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; use core::marker::PhantomData; -/// Weight functions needed for `pallet_deployment_permissions`. +/// Weight function needed for `pallet_benchmark_dummy`. pub trait WeightInfo { fn bench_heavy_contract_call() -> Weight; } // For backwards compatibility and tests. impl WeightInfo for () { - /// Storage: `DeploymentPermissions::Deployers` (r:1 w:1) - /// Proof: `DeploymentPermissions::Deployers` (`max_values`: None, `max_size`: Some(36), added: 2511, mode: `MaxEncodedLen`) fn bench_heavy_contract_call() -> Weight { // Proof Size summary in bytes: // Measured: `109` diff --git a/runtime/src/weights/pallet_benchmark_dummy.rs b/runtime/src/weights/pallet_benchmark_dummy.rs index 6244093..997020d 100644 --- a/runtime/src/weights/pallet_benchmark_dummy.rs +++ b/runtime/src/weights/pallet_benchmark_dummy.rs @@ -16,9 +16,9 @@ //! Autogenerated weights for `pallet_benchmark_dummy` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 43.0.0 -//! DATE: 2025-06-03, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2025-06-04, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` -//! HOSTNAME: `Rodrigos-MacBook-Pro.local`, CPU: `` +//! HOSTNAME: `mac.lan`, CPU: `` //! WASM-EXECUTION: `Compiled`, CHAIN: `None`, DB CACHE: `1024` // Executed Command: @@ -55,11 +55,13 @@ pub struct ZKVEvmWeight(PhantomData); impl pallet_benchmark_dummy::WeightInfo for ZKVEvmWeight { /// The range of component `n` is `[0, 100]`. - fn bench_heavy_contract_call(_n: u32, ) -> Weight { + fn bench_heavy_contract_call(n: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` // Minimum execution time: 1_000_000 picoseconds. - Weight::from_parts(1_614_161, 0) + Weight::from_parts(1_486_106, 0) + // Standard Error: 763 + .saturating_add(Weight::from_parts(159, 0).saturating_mul(n.into())) } } From 6b084fbb6b640643a0a1e1d711e679a9c7a6db01 Mon Sep 17 00:00:00 2001 From: Rodrigo Doria Medina Date: Wed, 4 Jun 2025 15:25:59 -0400 Subject: [PATCH 6/6] fix: errors --- pallets/benchmark-dummy/src/lib.rs | 13 +++++-------- pallets/benchmark-dummy/src/mock.rs | 15 +++++++++------ pallets/benchmark-dummy/src/weights.rs | 20 +++++++++++++++++--- 3 files changed, 31 insertions(+), 17 deletions(-) diff --git a/pallets/benchmark-dummy/src/lib.rs b/pallets/benchmark-dummy/src/lib.rs index 099cbb8..64bcb9c 100644 --- a/pallets/benchmark-dummy/src/lib.rs +++ b/pallets/benchmark-dummy/src/lib.rs @@ -2,23 +2,20 @@ extern crate alloc; -use frame_support::pallet_prelude::Weight; pub use pallet::*; - -/// A trait for pallet-specific weight information. -pub trait WeightInfo { - /// The range of component `n` is `[0, 100]`. - fn bench_heavy_contract_call(_n: u32) -> Weight; -} +pub use weights::SubstrateWeight; +pub use weights::WeightInfo; #[frame_support::pallet] pub mod pallet { + use super::WeightInfo; + #[pallet::pallet] pub struct Pallet(_); #[pallet::config] pub trait Config: frame_system::Config + pallet_evm::Config { - type WeightInfo: crate::WeightInfo; + type WeightInfo: WeightInfo; } } diff --git a/pallets/benchmark-dummy/src/mock.rs b/pallets/benchmark-dummy/src/mock.rs index e9141c2..d49ae49 100644 --- a/pallets/benchmark-dummy/src/mock.rs +++ b/pallets/benchmark-dummy/src/mock.rs @@ -1,18 +1,16 @@ -use frame_support::{construct_runtime, derive_impl, traits::Currency}; -use sp_core::{H160, U256}; +use crate::weights::SubstrateWeight; +use frame_support::derive_impl; use sp_runtime::BuildStorage; pub type Block = frame_system::mocking::MockBlock; -pub type AccountIdOf = - <::AccountProvider as pallet_evm::AccountProvider>::AccountId; -pub type BalanceOf = <::Currency as Currency>>::Balance; frame_support::construct_runtime!( pub enum Test { System: frame_system = 0, - Timestamp: pallet_timestamp = 1 + Timestamp: pallet_timestamp = 1, Balances: pallet_balances = 2, Evm: pallet_evm = 3, + BenchmarkDummy: crate = 4, } ); @@ -41,6 +39,11 @@ impl pallet_evm::Config for Test { type Runner = pallet_evm::runner::stack::Runner; } +// Implement the Config trait for our pallet +impl crate::Config for Test { + type WeightInfo = SubstrateWeight; +} + // Test externalities initialization pub fn new_test_ext() -> sp_io::TestExternalities { frame_system::GenesisConfig::::default() diff --git a/pallets/benchmark-dummy/src/weights.rs b/pallets/benchmark-dummy/src/weights.rs index 4fe7364..868c1d4 100644 --- a/pallets/benchmark-dummy/src/weights.rs +++ b/pallets/benchmark-dummy/src/weights.rs @@ -1,4 +1,3 @@ - //! Autogenerated weights for `pallet_benchmark_dummy` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 43.0.0 @@ -29,12 +28,27 @@ use core::marker::PhantomData; /// Weight function needed for `pallet_benchmark_dummy`. pub trait WeightInfo { - fn bench_heavy_contract_call() -> Weight; + fn bench_heavy_contract_call(n: u32) -> Weight; +} + +/// Substrate weight implementation for the pallet. +pub struct SubstrateWeight(PhantomData); + +impl WeightInfo for SubstrateWeight { + fn bench_heavy_contract_call(_n: u32) -> Weight { + // Proof Size summary in bytes: + // Measured: `109` + // Estimated: `3501` + // Minimum execution time: 8_740_000 picoseconds. + Weight::from_parts(9_191_000, 3501) + .saturating_add(RocksDbWeight::get().reads(1_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) + } } // For backwards compatibility and tests. impl WeightInfo for () { - fn bench_heavy_contract_call() -> Weight { + fn bench_heavy_contract_call(_n: u32) -> Weight { // Proof Size summary in bytes: // Measured: `109` // Estimated: `3501`