From 6cd2542f6dcf934aea6161b1a79c4668c975bf7f Mon Sep 17 00:00:00 2001 From: luckychacha <358140284@qq.com> Date: Thu, 27 Jul 2023 17:48:52 +0800 Subject: [PATCH 01/34] Init a new brnach: gas-estimation-for-zk-precompile. --- .maintain/frame-weight-template.hbs | 114 ++++++++++++++++++++++++++++ Cargo.lock | 1 + node/Cargo.toml | 10 +-- node/src/benchmarking.rs | 11 ++- node/src/command.rs | 7 +- runtime/mainnet/Cargo.toml | 6 ++ runtime/mainnet/src/lib.rs | 7 +- runtime/testnet/Cargo.toml | 9 ++- runtime/testnet/src/lib.rs | 7 +- runtime/testnet/src/poa.rs | 11 ++- 10 files changed, 167 insertions(+), 16 deletions(-) create mode 100644 .maintain/frame-weight-template.hbs diff --git a/.maintain/frame-weight-template.hbs b/.maintain/frame-weight-template.hbs new file mode 100644 index 00000000..34852daf --- /dev/null +++ b/.maintain/frame-weight-template.hbs @@ -0,0 +1,114 @@ +// This file is part of Substrate. + +// Copyright (C) 2022 Parity Technologies (UK) Ltd. +// 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}} +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION {{version}} +//! DATE: {{date}}, STEPS: `{{cmd.steps}}`, REPEAT: {{cmd.repeat}}, LOW RANGE: `{{cmd.lowest_range_values}}`, HIGH RANGE: `{{cmd.highest_range_values}}` +//! EXECUTION: {{cmd.execution}}, WASM-EXECUTION: {{cmd.wasm_execution}}, CHAIN: {{cmd.chain}}, DB CACHE: {{cmd.db_cache}} + +// Executed Command: +{{#each args as |arg|}} +// {{arg}} +{{/each}} + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] + +use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; +use sp_std::marker::PhantomData; + +/// Weight functions needed for {{pallet}}. +pub trait WeightInfo { + {{#each benchmarks as |benchmark|}} + fn {{benchmark.name~}} + ( + {{~#each benchmark.components as |c| ~}} + {{c.name}}: u32, {{/each~}} + ) -> Weight; + {{/each}} +} + +/// Weights for {{pallet}} using the Substrate node and recommended hardware. +pub struct SubstrateWeight(PhantomData); +{{#if (eq pallet "frame_system")}} +impl WeightInfo for SubstrateWeight { +{{else}} +impl WeightInfo for SubstrateWeight { +{{/if}} + {{#each benchmarks as |benchmark|}} + {{#each benchmark.comments as |comment|}} + // {{comment}} + {{/each}} + fn {{benchmark.name~}} + ( + {{~#each benchmark.components as |c| ~}} + {{~#if (not c.is_used)}}_{{/if}}{{c.name}}: u32, {{/each~}} + ) -> Weight { + ({{underscore benchmark.base_weight}} as Weight) + {{#each benchmark.component_weight as |cw|}} + // Standard Error: {{underscore cw.error}} + .saturating_add(({{underscore cw.slope}} as Weight).saturating_mul({{cw.name}} as Weight)) + {{/each}} + {{#if (ne benchmark.base_reads "0")}} + .saturating_add(T::DbWeight::get().reads({{benchmark.base_reads}} as Weight)) + {{/if}} + {{#each benchmark.component_reads as |cr|}} + .saturating_add(T::DbWeight::get().reads(({{cr.slope}} as Weight).saturating_mul({{cr.name}} as Weight))) + {{/each}} + {{#if (ne benchmark.base_writes "0")}} + .saturating_add(T::DbWeight::get().writes({{benchmark.base_writes}} as Weight)) + {{/if}} + {{#each benchmark.component_writes as |cw|}} + .saturating_add(T::DbWeight::get().writes(({{cw.slope}} as Weight).saturating_mul({{cw.name}} as Weight))) + {{/each}} + } + {{/each}} +} + +// For backwards compatibility and tests +impl WeightInfo for () { + {{#each benchmarks as |benchmark|}} + {{#each benchmark.comments as |comment|}} + // {{comment}} + {{/each}} + fn {{benchmark.name~}} + ( + {{~#each benchmark.components as |c| ~}} + {{~#if (not c.is_used)}}_{{/if}}{{c.name}}: u32, {{/each~}} + ) -> Weight { + ({{underscore benchmark.base_weight}} as Weight) + {{#each benchmark.component_weight as |cw|}} + // Standard Error: {{underscore cw.error}} + .saturating_add(({{underscore cw.slope}} as Weight).saturating_mul({{cw.name}} as Weight)) + {{/each}} + {{#if (ne benchmark.base_reads "0")}} + .saturating_add(RocksDbWeight::get().reads({{benchmark.base_reads}} as Weight)) + {{/if}} + {{#each benchmark.component_reads as |cr|}} + .saturating_add(RocksDbWeight::get().reads(({{cr.slope}} as Weight).saturating_mul({{cr.name}} as Weight))) + {{/each}} + {{#if (ne benchmark.base_writes "0")}} + .saturating_add(RocksDbWeight::get().writes({{benchmark.base_writes}} as Weight)) + {{/if}} + {{#each benchmark.component_writes as |cw|}} + .saturating_add(RocksDbWeight::get().writes(({{cw.slope}} as Weight).saturating_mul({{cw.name}} as Weight))) + {{/each}} + } + {{/each}} +} diff --git a/Cargo.lock b/Cargo.lock index 8988c9be..536cb094 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7353,6 +7353,7 @@ name = "pallet-referenda" version = "4.0.0-dev" source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.40#98f2e3451c9143278ec53c6718940aeabcd3b68a" dependencies = [ + "assert_matches", "frame-benchmarking", "frame-support", "frame-system", diff --git a/node/Cargo.toml b/node/Cargo.toml index c5126ad1..fb70d577 100644 --- a/node/Cargo.toml +++ b/node/Cargo.toml @@ -24,20 +24,19 @@ scale-codec = { package = "parity-scale-codec", workspace = true } # Substrate mmr-gadget.workspace = true mmr-rpc.workspace = true -sp-mmr-primitives.workspace = true sc-basic-authorship.workspace = true sc-cli.workspace = true sc-client-api.workspace = true sc-consensus-aura = { workspace = true } -sc-consensus-beefy.workspace = true sc-consensus-beefy-rpc.workspace = true +sc-consensus-beefy.workspace = true +sc-consensus-grandpa.workspace = true sc-consensus-manual-seal = { workspace = true, optional = true } sc-consensus.workspace = true sc-executor.workspace = true -sc-consensus-grandpa.workspace = true sc-keystore.workspace = true -sc-network.workspace = true sc-network-sync.workspace = true +sc-network.workspace = true sc-rpc-api.workspace = true sc-rpc.workspace = true sc-service.workspace = true @@ -51,6 +50,7 @@ sp-consensus-beefy = { workspace = true, features = ["std"] } sp-core = { workspace = true, features = ["std"] } sp-inherents = { workspace = true, features = ["std"] } sp-keyring.workspace = true +sp-mmr-primitives.workspace = true sp-runtime = { workspace = true, features = ["std"] } sp-timestamp = { workspace = true, features = ["std"] } # These dependencies are used for RPC @@ -99,7 +99,7 @@ web3 = { workspace = true } substrate-build-script-utils.workspace = true [features] -default = [] +default = ["runtime-benchmarks"] testnet = [ "golden-gate-runtime-testnet", ] diff --git a/node/src/benchmarking.rs b/node/src/benchmarking.rs index 8915772b..91d0e98f 100644 --- a/node/src/benchmarking.rs +++ b/node/src/benchmarking.rs @@ -30,7 +30,12 @@ use sp_inherents::{InherentData, InherentDataProvider}; use sp_keyring::Sr25519Keyring; use sp_runtime::{generic::Era, AccountId32, OpaqueExtrinsic, SaturatedConversion}; // Frontier -use golden_gate_runtime::{self as runtime, AccountId, Balance, BalancesCall, SystemCall}; +#[cfg(not(feature = "testnet"))] +use golden_gate_runtime_mainnet::{self as runtime, AccountId, Balance, BalancesCall, SystemCall}; +#[cfg(feature = "testnet")] +use golden_gate_runtime_testnet::{self as runtime, AccountId, Balance, BalancesCall, SystemCall}; + +// use golden_gate_runtime::{self as runtime, AccountId, Balance, BalancesCall, SystemCall}; use crate::service::FullClient; @@ -140,7 +145,7 @@ pub fn create_benchmark_extrinsic( .map(|c| c / 2) .unwrap_or(2) as u64; let extra: runtime::SignedExtra = ( - frame_system::CheckNonZeroSender::::new(), + //frame_system::CheckNonZeroSender::::new(), frame_system::CheckSpecVersion::::new(), frame_system::CheckTxVersion::::new(), frame_system::CheckGenesis::::new(), @@ -157,7 +162,7 @@ pub fn create_benchmark_extrinsic( call.clone(), extra.clone(), ( - (), + // (), runtime::VERSION.spec_version, runtime::VERSION.transaction_version, genesis_hash, diff --git a/node/src/command.rs b/node/src/command.rs index 0818406c..9145b7ed 100644 --- a/node/src/command.rs +++ b/node/src/command.rs @@ -182,7 +182,12 @@ pub fn run() -> sc_cli::Result<()> { use frame_benchmarking_cli::{ BenchmarkCmd, ExtrinsicFactory, SUBSTRATE_REFERENCE_HARDWARE, }; - use golden_gate_runtime::{Block, ExistentialDeposit}; + + #[cfg(not(feature = "testnet"))] + use golden_gate_runtime_mainnet::{Block, ExistentialDeposit}; + + #[cfg(feature = "testnet")] + use golden_gate_runtime_testnet::{Block, ExistentialDeposit}; let runner = cli.create_runner(cmd)?; match cmd { diff --git a/runtime/mainnet/Cargo.toml b/runtime/mainnet/Cargo.toml index c9a6f941..fb9a7fb4 100644 --- a/runtime/mainnet/Cargo.toml +++ b/runtime/mainnet/Cargo.toml @@ -186,6 +186,12 @@ runtime-benchmarks = [ "frame-system-benchmarking/runtime-benchmarks", "frame-system/runtime-benchmarks", "pallet-balances/runtime-benchmarks", + "pallet-conviction-voting/runtime-benchmarks", + "pallet-ethereum/runtime-benchmarks", "pallet-grandpa/runtime-benchmarks", + "pallet-hotfix-sufficients/runtime-benchmarks", + "pallet-ranked-collective/runtime-benchmarks", + "pallet-referenda/runtime-benchmarks", + "pallet-society/runtime-benchmarks", "pallet-timestamp/runtime-benchmarks", ] diff --git a/runtime/mainnet/src/lib.rs b/runtime/mainnet/src/lib.rs index 66942a18..dd80d157 100644 --- a/runtime/mainnet/src/lib.rs +++ b/runtime/mainnet/src/lib.rs @@ -356,6 +356,11 @@ parameter_types! { // For weight estimation, we assume that the most locks on an individual account will be 50. // This number may need to be adjusted in the future if this assumption no longer holds true. pub const MaxLocks: u32 = 50; + + // The minimum balance that an account must have in order to be kept alive on-chain. + // This value is used by the Balances pallet to determine if an account should be + // kept alive or if it should be reaped to free up storage space. + pub const ExistentialDeposit: Balance = EXISTENTIAL_DEPOSIT; } impl pallet_balances::Config for Runtime { @@ -364,7 +369,7 @@ impl pallet_balances::Config for Runtime { type DustRemoval = (); /// The ubiquitous event type. type RuntimeEvent = RuntimeEvent; - type ExistentialDeposit = ConstU128; + type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; type WeightInfo = pallet_balances::weights::SubstrateWeight; type MaxLocks = MaxLocks; diff --git a/runtime/testnet/Cargo.toml b/runtime/testnet/Cargo.toml index 1c5583de..f5887558 100644 --- a/runtime/testnet/Cargo.toml +++ b/runtime/testnet/Cargo.toml @@ -16,8 +16,8 @@ scale-codec = { package = "parity-scale-codec", workspace = true } scale-info.workspace = true # Substrate -pallet-beefy.workspace = true pallet-beefy-mmr.workspace = true +pallet-beefy.workspace = true sp-api.workspace = true sp-block-builder.workspace = true sp-consensus-aura.workspace = true @@ -85,11 +85,11 @@ pallet-contracts.workspace = true pallet-randomness-collective-flip.workspace = true # Ibc +ibc-proto.workspace = true +ibc.workspace = true +pallet-ibc-utils.workspace = true pallet-ibc.workspace = true pallet-ics20-transfer.workspace = true -pallet-ibc-utils.workspace = true -ibc.workspace = true -ibc-proto.workspace = true prost.workspace = true [build-dependencies] @@ -176,6 +176,7 @@ runtime-benchmarks = [ "frame-benchmarking/runtime-benchmarks", "frame-system-benchmarking/runtime-benchmarks", "frame-system/runtime-benchmarks", + "pallet-assets/runtime-benchmarks", "pallet-balances/runtime-benchmarks", "pallet-grandpa/runtime-benchmarks", "pallet-timestamp/runtime-benchmarks", diff --git a/runtime/testnet/src/lib.rs b/runtime/testnet/src/lib.rs index fb143123..5da0a20d 100644 --- a/runtime/testnet/src/lib.rs +++ b/runtime/testnet/src/lib.rs @@ -387,6 +387,11 @@ parameter_types! { // For weight estimation, we assume that the most locks on an individual account will be 50. // This number may need to be adjusted in the future if this assumption no longer holds true. pub const MaxLocks: u32 = 50; + + // The minimum balance that an account must have in order to be kept alive on-chain. + // This value is used by the Balances pallet to determine if an account should be + // kept alive or if it should be reaped to free up storage space. + pub const ExistentialDeposit: Balance = EXISTENTIAL_DEPOSIT; } impl pallet_balances::Config for Runtime { @@ -395,7 +400,7 @@ impl pallet_balances::Config for Runtime { type DustRemoval = (); /// The ubiquitous event type. type RuntimeEvent = RuntimeEvent; - type ExistentialDeposit = ConstU128; + type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; type WeightInfo = pallet_balances::weights::SubstrateWeight; type MaxLocks = MaxLocks; diff --git a/runtime/testnet/src/poa.rs b/runtime/testnet/src/poa.rs index 09ba0bcf..f7fa2782 100644 --- a/runtime/testnet/src/poa.rs +++ b/runtime/testnet/src/poa.rs @@ -188,6 +188,15 @@ impl pallet_identity::Config for Runtime { type WeightInfo = pallet_identity::weights::SubstrateWeight; } +#[cfg(feature = "runtime-benchmarks")] +pub struct AssetsBenchmarkHelper; +#[cfg(feature = "runtime-benchmarks")] +impl pallet_assets::BenchmarkHelper> for AssetsBenchmarkHelper { + fn create_asset_id_parameter(id: u32) -> scale_codec::Compact { + scale_codec::Compact(id) + } +} + impl pallet_assets::Config for Runtime { type RuntimeEvent = RuntimeEvent; type Balance = u128; @@ -208,7 +217,7 @@ impl pallet_assets::Config for Runtime { type WeightInfo = pallet_assets::weights::SubstrateWeight; type RemoveItemsLimit = ConstU32<1000>; #[cfg(feature = "runtime-benchmarks")] - type BenchmarkHelper = (); + type BenchmarkHelper = AssetsBenchmarkHelper; } /// The type used to represent the kinds of proxying allowed. From 7538ccbf0a9222b6b9acfefd8d43c77f151cb180 Mon Sep 17 00:00:00 2001 From: luckychacha <358140284@qq.com> Date: Fri, 28 Jul 2023 18:32:20 +0800 Subject: [PATCH 02/34] Add a pallet for benchmarking. --- node/Cargo.toml | 2 +- runtime/mainnet/src/lib.rs | 13 +++- .../benchmarking.rs | 18 +++++ .../src/zk_precompile_gas_estimation/mock.rs | 66 +++++++++++++++++++ .../src/zk_precompile_gas_estimation/mod.rs | 40 +++++++++++ 5 files changed, 137 insertions(+), 2 deletions(-) create mode 100644 runtime/mainnet/src/zk_precompile_gas_estimation/benchmarking.rs create mode 100644 runtime/mainnet/src/zk_precompile_gas_estimation/mock.rs create mode 100644 runtime/mainnet/src/zk_precompile_gas_estimation/mod.rs diff --git a/node/Cargo.toml b/node/Cargo.toml index fb70d577..39a91ae3 100644 --- a/node/Cargo.toml +++ b/node/Cargo.toml @@ -99,7 +99,7 @@ web3 = { workspace = true } substrate-build-script-utils.workspace = true [features] -default = ["runtime-benchmarks"] +default = [] testnet = [ "golden-gate-runtime-testnet", ] diff --git a/runtime/mainnet/src/lib.rs b/runtime/mainnet/src/lib.rs index dd80d157..71c1508f 100644 --- a/runtime/mainnet/src/lib.rs +++ b/runtime/mainnet/src/lib.rs @@ -23,6 +23,8 @@ mod prelude; mod version; pub use version::VERSION; +mod zk_precompile_gas_estimation; + use core::cmp::Ordering; #[cfg(feature = "std")] @@ -432,6 +434,8 @@ impl pallet_preimage::Config for Runtime { type ByteDeposit = PreimageByteDeposit; } +impl zk_precompile_gas_estimation::Config for Runtime {} + // Create the runtime by composing the FRAME pallets that were previously configured. construct_runtime!( pub enum Runtime where @@ -484,6 +488,7 @@ construct_runtime!( // GGX pallets CurrencyManager: currency, SessionPayout: session_payout, + ZKPrecompileGasEstimation: zk_precompile_gas_estimation, // Wasm contracts Contracts: pallet_contracts, @@ -564,7 +569,13 @@ extern crate frame_benchmarking; #[cfg(feature = "runtime-benchmarks")] mod benches { - define_benchmarks!([pallet_evm, EVM]); + define_benchmarks!( + [pallet_evm, EVM] + [ + zk_precompile_gas_estimation, + ZKPrecompileGasEstimation + ] + ); } use fp_rpc::TransactionStatus; diff --git a/runtime/mainnet/src/zk_precompile_gas_estimation/benchmarking.rs b/runtime/mainnet/src/zk_precompile_gas_estimation/benchmarking.rs new file mode 100644 index 00000000..9767f04f --- /dev/null +++ b/runtime/mainnet/src/zk_precompile_gas_estimation/benchmarking.rs @@ -0,0 +1,18 @@ +use super::*; + +#[allow(unused)] +use crate::zk_precompile_gas_estimation::Pallet as ZKPrecompileGasEstimation; +use frame_benchmarking::{benchmarks, whitelisted_caller}; +// use frame_system::RawOrigin; + +benchmarks! { + do_some_work { + let s in 0 .. 100; + let caller: T::AccountId = whitelisted_caller(); + }:{ + let _ = ZKPrecompileGasEstimation::::do_some_work(s.into()); + } + + // 使用mock中的new_test_ext + impl_benchmark_test_suite!(ZKPrecompileGasEstimation, crate::mock::new_test_ext(), crate::mock::Test); +} diff --git a/runtime/mainnet/src/zk_precompile_gas_estimation/mock.rs b/runtime/mainnet/src/zk_precompile_gas_estimation/mock.rs new file mode 100644 index 00000000..d9a8333b --- /dev/null +++ b/runtime/mainnet/src/zk_precompile_gas_estimation/mock.rs @@ -0,0 +1,66 @@ +use crate::zk_precompile_gas_estimation as pallet_template; +use frame_support::{pallet_prelude::Weight, parameter_types, weights::constants::RocksDbWeight}; +use frame_system as system; +use sp_core::{ConstU64, H256}; +use sp_runtime::{testing::Header, traits::IdentityLookup}; + +type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; +type Block = frame_system::mocking::MockBlock; + +// Configure a mock runtime to test the pallet. +frame_support::construct_runtime!( + pub enum Test where + Block = Block, + NodeBlock = Block, + UncheckedExtrinsic = UncheckedExtrinsic, + { + System: frame_system::{Pallet, Call, Config, Storage, Event}, + TemplateModule: pallet_template::{Pallet, Call, Storage}, + } +); + +parameter_types! { + pub BlockWeights: frame_system::limits::BlockWeights = + frame_system::limits::BlockWeights::simple_max( + Weight::from_parts(2_000_000_000_000, u64::MAX), + ); +} + +impl frame_system::Config for Test { + type BaseCallFilter = frame_support::traits::Everything; + type BlockWeights = BlockWeights; + type BlockLength = (); + type DbWeight = RocksDbWeight; + type RuntimeOrigin = RuntimeOrigin; + type Index = u64; + type BlockNumber = u64; + type RuntimeCall = RuntimeCall; + type Hash = H256; + type Version = (); + type Hashing = sp_runtime::traits::BlakeTwo256; + type AccountId = u32; + type Lookup = IdentityLookup; + type Header = Header; + type RuntimeEvent = RuntimeEvent; + type BlockHashCount = ConstU64<250>; + type PalletInfo = PalletInfo; + type AccountData = pallet_balances::AccountData; + type OnNewAccount = (); + type OnKilledAccount = (); + type SystemWeightInfo = (); + type SS58Prefix = (); + type OnSetCode = (); + type MaxConsumers = frame_support::traits::ConstU32<16>; +} + +impl pallet_template::Config for Test { + // type Event = Event; +} + +// Build genesis storage according to the mock runtime. +pub fn new_test_ext() -> sp_io::TestExternalities { + system::GenesisConfig::default() + .build_storage::() + .unwrap() + .into() +} diff --git a/runtime/mainnet/src/zk_precompile_gas_estimation/mod.rs b/runtime/mainnet/src/zk_precompile_gas_estimation/mod.rs new file mode 100644 index 00000000..c06f3d42 --- /dev/null +++ b/runtime/mainnet/src/zk_precompile_gas_estimation/mod.rs @@ -0,0 +1,40 @@ +// #![cfg_attr(not(feature = "std"), no_std)] + +pub use pallet::*; +#[frame_support::pallet] +pub mod pallet { + // use frame_support::{ + // pallet_prelude::*, sp_runtime::traits::AtLeast32BitUnsigned, sp_std::fmt::Debug, + // }; + // use frame_system::pallet_prelude::*; + + #[pallet::pallet] + #[pallet::without_storage_info] + pub struct Pallet(_); + + // 3. Runtime Configuration Trait + #[pallet::config] + pub trait Config: frame_system::Config { + // type Event: From> + IsType<::Event>; + } + + // 8. Runtime Errors + #[pallet::error] + pub enum Error {} + + // 7. Extrinsics + // Functions that are callable from outside the runtime. + impl Pallet { + pub fn do_some_work(i: u32) { + let mut i = i; + while i < 100000000 { + i += 1; + } + } + } +} + +#[cfg(feature = "runtime-benchmarks")] +mod benchmarking; +#[cfg(test)] +mod mock; From 7a536c6119811864abfc01d3f089c4c0b180e2f9 Mon Sep 17 00:00:00 2001 From: luckychacha <358140284@qq.com> Date: Sat, 29 Jul 2023 02:51:12 +0800 Subject: [PATCH 03/34] Demo benchmarking is working. --- runtime/mainnet/src/lib.rs | 1 + .../src/zk_precompile_gas_estimation/benchmarking.rs | 11 ++++++++--- .../mainnet/src/zk_precompile_gas_estimation/mock.rs | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/runtime/mainnet/src/lib.rs b/runtime/mainnet/src/lib.rs index 71c1508f..95b89a91 100644 --- a/runtime/mainnet/src/lib.rs +++ b/runtime/mainnet/src/lib.rs @@ -941,6 +941,7 @@ impl_runtime_apis! { add_benchmark!(params, batches, pallet_evm, PalletEvmBench::); add_benchmark!(params, batches, pallet_hotfix_sufficients, PalletHotfixSufficients::); + add_benchmark!(params, batches, zk_precompile_gas_estimation, ZKPrecompileGasEstimation); if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) } Ok(batches) diff --git a/runtime/mainnet/src/zk_precompile_gas_estimation/benchmarking.rs b/runtime/mainnet/src/zk_precompile_gas_estimation/benchmarking.rs index 9767f04f..0125b63b 100644 --- a/runtime/mainnet/src/zk_precompile_gas_estimation/benchmarking.rs +++ b/runtime/mainnet/src/zk_precompile_gas_estimation/benchmarking.rs @@ -2,11 +2,11 @@ use super::*; #[allow(unused)] use crate::zk_precompile_gas_estimation::Pallet as ZKPrecompileGasEstimation; -use frame_benchmarking::{benchmarks, whitelisted_caller}; +use frame_benchmarking::{benchmarks, impl_benchmark_test_suite, whitelisted_caller}; // use frame_system::RawOrigin; benchmarks! { - do_some_work { + do_some_work_t { let s in 0 .. 100; let caller: T::AccountId = whitelisted_caller(); }:{ @@ -14,5 +14,10 @@ benchmarks! { } // 使用mock中的new_test_ext - impl_benchmark_test_suite!(ZKPrecompileGasEstimation, crate::mock::new_test_ext(), crate::mock::Test); +// impl_benchmark_test_suite!(ZKPrecompileGasEstimation, crate::mock::new_test_ext(), crate::mock::Test); + impl_benchmark_test_suite!( + ZKPrecompileGasEstimation, + crate::zk_precompile_gas_estimation::mock::new_test_ext(), + crate::zk_precompile_gas_estimation::mock::Test + ); } diff --git a/runtime/mainnet/src/zk_precompile_gas_estimation/mock.rs b/runtime/mainnet/src/zk_precompile_gas_estimation/mock.rs index d9a8333b..e9f6cd0d 100644 --- a/runtime/mainnet/src/zk_precompile_gas_estimation/mock.rs +++ b/runtime/mainnet/src/zk_precompile_gas_estimation/mock.rs @@ -15,7 +15,7 @@ frame_support::construct_runtime!( UncheckedExtrinsic = UncheckedExtrinsic, { System: frame_system::{Pallet, Call, Config, Storage, Event}, - TemplateModule: pallet_template::{Pallet, Call, Storage}, + TemplateModule: pallet_template::{Pallet, Storage}, } ); From 6422f4420eb401954aeeceff6c783a811290c584 Mon Sep 17 00:00:00 2001 From: luckychacha <358140284@qq.com> Date: Mon, 31 Jul 2023 18:46:42 +0800 Subject: [PATCH 04/34] Create mock file for zk-groth16 verify --- Cargo.lock | 7 + Cargo.toml | 17 +- runtime/mainnet/Cargo.toml | 1 + runtime/mainnet/src/lib.rs | 3 +- .../src/zk_precompile_gas_estimation/mock.rs | 66 ----- runtime/runtime-common/Cargo.toml | 10 + runtime/runtime-common/src/lib.rs | 2 + .../benchmarking.rs | 10 +- .../src/zk_precompile_gas_estimation/mock.rs | 234 ++++++++++++++++++ .../src/zk_precompile_gas_estimation/mod.rs | 3 + .../src/zk_precompile_gas_estimation/tests.rs | 32 +++ runtime/testnet/Cargo.toml | 1 + 12 files changed, 309 insertions(+), 77 deletions(-) delete mode 100644 runtime/mainnet/src/zk_precompile_gas_estimation/mock.rs rename runtime/{mainnet => runtime-common}/src/zk_precompile_gas_estimation/benchmarking.rs (70%) create mode 100644 runtime/runtime-common/src/zk_precompile_gas_estimation/mock.rs rename runtime/{mainnet => runtime-common}/src/zk_precompile_gas_estimation/mod.rs (97%) create mode 100644 runtime/runtime-common/src/zk_precompile_gas_estimation/tests.rs diff --git a/Cargo.lock b/Cargo.lock index 536cb094..dc0d9b9b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8981,9 +8981,12 @@ dependencies = [ name = "runtime-common" version = "0.1.0" dependencies = [ + "fp-account", + "frame-benchmarking", "frame-support", "frame-system", "log", + "pallet-balances", "pallet-contracts", "pallet-evm", "pallet-evm-precompile-blake2", @@ -8998,12 +9001,16 @@ dependencies = [ "pallet-evm-precompile-xvm", "pallet-evm-precompile-zk-groth16-verify", "pallet-session", + "pallet-timestamp", "pallet-xvm", "parity-scale-codec 3.6.4", + "precompile-utils", "proptest", "scale-info", "serde", "sp-core", + "sp-io", + "sp-runtime", "sp-staking", "sp-std", "test-strategy", diff --git a/Cargo.toml b/Cargo.toml index 8ad38e99..329b9aaa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -56,16 +56,17 @@ web3 = "0.18.0" # Substrate Client mmr-gadget = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } mmr-rpc = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } +polkadot-rpc = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.40" } sc-basic-authorship = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } sc-cli = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } sc-client-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } sc-consensus = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } sc-consensus-aura = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } sc-consensus-beefy = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } -sc-consensus-beefy-rpc = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } +sc-consensus-beefy-rpc = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } +sc-consensus-grandpa = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } sc-consensus-manual-seal = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } sc-executor = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } -sc-consensus-grandpa = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } sc-keystore = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } sc-network = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } sc-network-sync = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } @@ -75,10 +76,8 @@ sc-service = { version = "0.10.0-dev", git = "https://github.com/paritytech/subs sc-telemetry = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } sc-transaction-pool = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } substrate-rpc-client = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } -polkadot-rpc = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.40" } # Substrate Primitive -sp-mmr-primitives = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40", default-features = false } pallet-beefy = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40", default-features = false } pallet-beefy-mmr = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40", default-features = false } sp-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40", default-features = false } @@ -92,6 +91,7 @@ sp-core = { version = "7.0.0", git = "https://github.com/paritytech/substrate", sp-inherents = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40", default-features = false } sp-io = { version = "7.0.0", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40", default-features = false } sp-keyring = { version = "7.0.0", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40", default-features = false } +sp-mmr-primitives = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40", default-features = false } sp-offchain = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40", default-features = false } sp-runtime = { version = "7.0.0", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40", default-features = false } sp-session = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40", default-features = false } @@ -159,6 +159,7 @@ fc-rpc-core = { version = "1.1.0-dev", git = "https://github.com/AstarNetwork/fr # Frontier Primitive fc-storage = { version = "1.0.0-dev", git = "https://github.com/AstarNetwork/frontier.git", branch = "polkadot-v0.9.40", default-features = false } +fp-account = { git = "https://github.com/AstarNetwork/frontier.git", branch = "polkadot-v0.9.40", default-features = false } fp-dynamic-fee = { version = "1.0.0", git = "https://github.com/AstarNetwork/frontier.git", branch = "polkadot-v0.9.40", default-features = false } fp-evm = { version = "3.0.0-dev", git = "https://github.com/AstarNetwork/frontier.git", branch = "polkadot-v0.9.40", default-features = false } fp-rpc = { version = "3.0.0-dev", git = "https://github.com/AstarNetwork/frontier.git", branch = "polkadot-v0.9.40", default-features = false } @@ -200,11 +201,13 @@ pallet-contracts-primitives = { git = "https://github.com/paritytech/substrate", pallet-randomness-collective-flip = { package = "pallet-insecure-randomness-collective-flip", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40", default-features = false } # IBC +ibc = { version = "0.28.0", default-features = false, features = ["parity-scale-codec", "serde"] } +ibc-proto = { version = "0.25.0", default-features = false, features = [ + "parity-scale-codec", +], git = "https://github.com/octopus-network/ibc-proto-rs", branch = "ibc" } pallet-ibc = { default-features = false, git = "https://github.com/ibc-test/substrate-ibc.git", branch = "icf-m3" } +pallet-ibc-utils = { git = "https://github.com/ibc-test/substrate-ibc.git", default-features = false, branch = "icf-m3" } pallet-ics20-transfer = { default-features = false, git = "https://github.com/ibc-test/substrate-ibc.git", branch = "icf-m3" } -pallet-ibc-utils = { git = "https://github.com/ibc-test/substrate-ibc.git", default-features = false, branch = "icf-m3" } -ibc = { version = "0.28.0", default-features = false, features = ["parity-scale-codec", "serde"]} -ibc-proto = { version = "0.25.0", default-features = false, features = ["parity-scale-codec"], git = "https://github.com/octopus-network/ibc-proto-rs", branch = "ibc" } prost = { version = "0.11", default-features = false } # zk precompile diff --git a/runtime/mainnet/Cargo.toml b/runtime/mainnet/Cargo.toml index fb9a7fb4..55240332 100644 --- a/runtime/mainnet/Cargo.toml +++ b/runtime/mainnet/Cargo.toml @@ -194,4 +194,5 @@ runtime-benchmarks = [ "pallet-referenda/runtime-benchmarks", "pallet-society/runtime-benchmarks", "pallet-timestamp/runtime-benchmarks", + "runtime-common/runtime-benchmarks", ] diff --git a/runtime/mainnet/src/lib.rs b/runtime/mainnet/src/lib.rs index 95b89a91..3c83b639 100644 --- a/runtime/mainnet/src/lib.rs +++ b/runtime/mainnet/src/lib.rs @@ -23,8 +23,6 @@ mod prelude; mod version; pub use version::VERSION; -mod zk_precompile_gas_estimation; - use core::cmp::Ordering; #[cfg(feature = "std")] @@ -60,6 +58,7 @@ use pallet_grandpa::{fg_primitives, AuthorityList as GrandpaAuthorityList}; use pallet_session::historical::{self as pallet_session_historical}; use pallet_transaction_payment::CurrencyAdapter; use pos::{currency, session_payout}; +use runtime_common::zk_precompile_gas_estimation; // A few exports that help ease life for downstream crates. pub use frame_support::{ diff --git a/runtime/mainnet/src/zk_precompile_gas_estimation/mock.rs b/runtime/mainnet/src/zk_precompile_gas_estimation/mock.rs deleted file mode 100644 index e9f6cd0d..00000000 --- a/runtime/mainnet/src/zk_precompile_gas_estimation/mock.rs +++ /dev/null @@ -1,66 +0,0 @@ -use crate::zk_precompile_gas_estimation as pallet_template; -use frame_support::{pallet_prelude::Weight, parameter_types, weights::constants::RocksDbWeight}; -use frame_system as system; -use sp_core::{ConstU64, H256}; -use sp_runtime::{testing::Header, traits::IdentityLookup}; - -type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; -type Block = frame_system::mocking::MockBlock; - -// Configure a mock runtime to test the pallet. -frame_support::construct_runtime!( - pub enum Test where - Block = Block, - NodeBlock = Block, - UncheckedExtrinsic = UncheckedExtrinsic, - { - System: frame_system::{Pallet, Call, Config, Storage, Event}, - TemplateModule: pallet_template::{Pallet, Storage}, - } -); - -parameter_types! { - pub BlockWeights: frame_system::limits::BlockWeights = - frame_system::limits::BlockWeights::simple_max( - Weight::from_parts(2_000_000_000_000, u64::MAX), - ); -} - -impl frame_system::Config for Test { - type BaseCallFilter = frame_support::traits::Everything; - type BlockWeights = BlockWeights; - type BlockLength = (); - type DbWeight = RocksDbWeight; - type RuntimeOrigin = RuntimeOrigin; - type Index = u64; - type BlockNumber = u64; - type RuntimeCall = RuntimeCall; - type Hash = H256; - type Version = (); - type Hashing = sp_runtime::traits::BlakeTwo256; - type AccountId = u32; - type Lookup = IdentityLookup; - type Header = Header; - type RuntimeEvent = RuntimeEvent; - type BlockHashCount = ConstU64<250>; - type PalletInfo = PalletInfo; - type AccountData = pallet_balances::AccountData; - type OnNewAccount = (); - type OnKilledAccount = (); - type SystemWeightInfo = (); - type SS58Prefix = (); - type OnSetCode = (); - type MaxConsumers = frame_support::traits::ConstU32<16>; -} - -impl pallet_template::Config for Test { - // type Event = Event; -} - -// Build genesis storage according to the mock runtime. -pub fn new_test_ext() -> sp_io::TestExternalities { - system::GenesisConfig::default() - .build_storage::() - .unwrap() - .into() -} diff --git a/runtime/runtime-common/Cargo.toml b/runtime/runtime-common/Cargo.toml index 99c4151e..a30456ca 100644 --- a/runtime/runtime-common/Cargo.toml +++ b/runtime/runtime-common/Cargo.toml @@ -12,10 +12,12 @@ scale-codec = { package = "parity-scale-codec", workspace = true } scale-info.workspace = true serde = { workspace = true, optional = true } +frame-benchmarking = { workspace = true, optional = true } frame-support.workspace = true frame-system.workspace = true pallet-session = { workspace = true, features = ["historical"] } sp-core.workspace = true +sp-runtime.workspace = true sp-staking.workspace = true sp-std.workspace = true @@ -37,8 +39,15 @@ pallet-xvm = { workspace = true, optional = true } # eth abi log.workspace = true +# Astar +precompile-utils.workspace = true + [dev-dependencies] +fp-account.workspace = true +pallet-balances.workspace = true +pallet-timestamp.workspace = true proptest.workspace = true +sp-io.workspace = true test-strategy.workspace = true [features] @@ -85,3 +94,4 @@ std = [ "pallet-evm-precompile-zk-groth16-verify?/std", "pallet-xvm?/std", ] +runtime-benchmarks = [] diff --git a/runtime/runtime-common/src/lib.rs b/runtime/runtime-common/src/lib.rs index a0e20693..d2871568 100644 --- a/runtime/runtime-common/src/lib.rs +++ b/runtime/runtime-common/src/lib.rs @@ -5,6 +5,8 @@ extern crate core; #[cfg(feature = "precompiles")] pub mod precompiles; +pub mod zk_precompile_gas_estimation; + pub mod chain_spec; pub mod validator_manager; diff --git a/runtime/mainnet/src/zk_precompile_gas_estimation/benchmarking.rs b/runtime/runtime-common/src/zk_precompile_gas_estimation/benchmarking.rs similarity index 70% rename from runtime/mainnet/src/zk_precompile_gas_estimation/benchmarking.rs rename to runtime/runtime-common/src/zk_precompile_gas_estimation/benchmarking.rs index 0125b63b..049124ca 100644 --- a/runtime/mainnet/src/zk_precompile_gas_estimation/benchmarking.rs +++ b/runtime/runtime-common/src/zk_precompile_gas_estimation/benchmarking.rs @@ -2,15 +2,21 @@ use super::*; #[allow(unused)] use crate::zk_precompile_gas_estimation::Pallet as ZKPrecompileGasEstimation; -use frame_benchmarking::{benchmarks, impl_benchmark_test_suite, whitelisted_caller}; +use frame_benchmarking::{benchmarks, whitelisted_caller}; // use frame_system::RawOrigin; benchmarks! { do_some_work_t { - let s in 0 .. 100; let caller: T::AccountId = whitelisted_caller(); }:{ let _ = ZKPrecompileGasEstimation::::do_some_work(s.into()); + + let alice = AccountId::from_str("f24FF3a9CF04c71Dbc94D0b566f7A27B94566cac").unwrap(); + ExtBuilder::default() + .with_balances(vec![(alice, 1000000000000000000000)]) + .build() + .execute_with(|| { + }) } // 使用mock中的new_test_ext diff --git a/runtime/runtime-common/src/zk_precompile_gas_estimation/mock.rs b/runtime/runtime-common/src/zk_precompile_gas_estimation/mock.rs new file mode 100644 index 00000000..abbd0199 --- /dev/null +++ b/runtime/runtime-common/src/zk_precompile_gas_estimation/mock.rs @@ -0,0 +1,234 @@ +use crate::zk_precompile_gas_estimation as pallet_template; +use fp_account::EthereumSignature; +pub use frame_support::{ + construct_runtime, + pallet_prelude::GenesisBuild, + parameter_types, + traits::{ + ConstU128, ConstU32, Hooks, KeyOwnerProofSystem, OnFinalize, OnInitialize, Randomness, + StorageInfo, + }, + weights::{IdentityFee, Weight}, + PalletId, StorageValue, +}; +use pallet_evm::{ + EnsureAddressNever, EnsureAddressRoot, IsPrecompileResult, Precompile, PrecompileHandle, + PrecompileResult, PrecompileSet, +}; +use pallet_evm_precompile_zk_groth16_verify::ZKGroth16Verify; +use sp_core::{ConstU64, H160}; +use sp_runtime::{ + testing::Header, + traits::{IdentifyAccount, IdentityLookup, Verify}, +}; +use sp_std::marker::PhantomData; + +pub type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; +pub type Block = frame_system::mocking::MockBlock; +// pub(crate) type BlockNumber = u32; +type Signature = EthereumSignature; +pub type Balance = u128; +pub type Hash = sp_core::H256; +pub(crate) type AccountId = <::Signer as IdentifyAccount>::AccountId; + +/// Constant values used within the runtime. +pub const MILLIGGX: Balance = 1_000_000_000_000_000; +pub const GGX: Balance = 1000 * MILLIGGX; +pub const KGGX: Balance = 1000 * GGX; +pub const EXISTENTIAL_DEPOSIT: Balance = GGX; +// Configure a mock runtime to test the pallet. +frame_support::construct_runtime!( + pub enum Test where + Block = Block, + NodeBlock = Block, + UncheckedExtrinsic = UncheckedExtrinsic, + { + System: frame_system::{Pallet, Call, Config, Storage, Event}, + TemplateModule: pallet_template::{Pallet, Storage}, + Evm: pallet_evm::{Pallet, Call, Storage, Event}, + Balances: pallet_balances::{Pallet, Call, Storage, Config, Event}, + Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent}, + } +); + +parameter_types! { + pub BlockWeights: frame_system::limits::BlockWeights = + frame_system::limits::BlockWeights::simple_max( + Weight::from_parts(2_000_000_000_000, u64::MAX), + ); +} + +impl frame_system::Config for Test { + type BaseCallFilter = frame_support::traits::Everything; + type BlockWeights = BlockWeights; + type BlockLength = (); + type DbWeight = (); + type RuntimeOrigin = RuntimeOrigin; + type Index = u64; + type BlockNumber = u64; + type RuntimeCall = RuntimeCall; + type Hash = Hash; + type Version = (); + type Hashing = sp_runtime::traits::BlakeTwo256; + type AccountId = AccountId; + type Lookup = IdentityLookup; + type Header = Header; + type RuntimeEvent = RuntimeEvent; + type BlockHashCount = ConstU64<250>; + type PalletInfo = PalletInfo; + type AccountData = pallet_balances::AccountData; + type OnNewAccount = (); + type OnKilledAccount = (); + type SystemWeightInfo = (); + type SS58Prefix = (); + type OnSetCode = (); + type MaxConsumers = frame_support::traits::ConstU32<16>; +} + +parameter_types! { + // For weight estimation, we assume that the most locks on an individual account will be 50. + // This number may need to be adjusted in the future if this assumption no longer holds true. + pub const MaxLocks: u32 = 50; + + // The minimum balance that an account must have in order to be kept alive on-chain. + // This value is used by the Balances pallet to determine if an account should be + // kept alive or if it should be reaped to free up storage space. + pub const ExistentialDeposit: Balance = EXISTENTIAL_DEPOSIT; +} + +impl pallet_balances::Config for Test { + type Balance = Balance; + type DustRemoval = (); + type RuntimeEvent = RuntimeEvent; + type ExistentialDeposit = ExistentialDeposit; + type AccountStore = System; + type WeightInfo = (); + type MaxLocks = MaxLocks; + type MaxReserves = (); + type ReserveIdentifier = [u8; 8]; +} + +parameter_types! { + pub const MinimumPeriod: u64 = 5; +} +impl pallet_timestamp::Config for Test { + type Moment = u64; + type OnTimestampSet = (); + type MinimumPeriod = MinimumPeriod; + type WeightInfo = (); +} + +parameter_types! { + pub const PrecompilesValue: Precompiles = Precompiles(PhantomData); + pub const WeightPerGas: Weight = Weight::from_parts(1, 0); +} + +pub struct IntoAddressMapping; + +impl> pallet_evm::AddressMapping for IntoAddressMapping { + fn into_account_id(address: H160) -> T { + address.into() + } +} + +impl pallet_evm::Config for Test { + type FeeCalculator = (); + type GasWeightMapping = pallet_evm::FixedGasWeightMapping; + type WeightPerGas = WeightPerGas; + type CallOrigin = EnsureAddressRoot; + type WithdrawOrigin = EnsureAddressNever; + type AddressMapping = IntoAddressMapping; + type Currency = Balances; + type RuntimeEvent = RuntimeEvent; + type Runner = pallet_evm::runner::stack::Runner; + type PrecompilesType = Precompiles; + type PrecompilesValue = PrecompilesValue; + type ChainId = (); + type OnChargeTransaction = (); + type BlockGasLimit = (); + type BlockHashMapping = pallet_evm::SubstrateBlockHashMapping; + type FindAuthor = (); + type OnCreate = (); + type Timestamp = Timestamp; + type WeightInfo = pallet_evm::weights::SubstrateWeight; +} + +pub const PRECOMPILE_ADDRESS: u64 = 1; + +#[derive(Default)] +pub struct Precompiles(PhantomData); + +impl PrecompileSet for Precompiles +where + R: pallet_evm::Config, +{ + fn execute(&self, handle: &mut impl PrecompileHandle) -> Option { + match handle.code_address() { + a if a == hash(PRECOMPILE_ADDRESS) => Some(ZKGroth16Verify::execute(handle)), + _ => None, + } + } + + // fn is_precompile(&self, address: H160) -> bool { + // address == hash(PRECOMPILE_ADDRESS) + // } + fn is_precompile(&self, address: H160, _gas: u64) -> IsPrecompileResult { + IsPrecompileResult::Answer { + is_precompile: address == hash(PRECOMPILE_ADDRESS), + extra_cost: 0, + } + } +} + +fn hash(a: u64) -> H160 { + H160::from_low_u64_be(a) +} + +impl pallet_template::Config for Test { + // type Event = Event; +} + +pub(crate) struct ExtBuilder { + balances: Vec<(AccountId, Balance)>, +} + +impl Default for ExtBuilder { + fn default() -> ExtBuilder { + ExtBuilder { balances: vec![] } + } +} + +impl ExtBuilder { + pub(crate) fn with_balances(mut self, balances: Vec<(AccountId, Balance)>) -> Self { + self.balances = balances; + self + } + + pub(crate) fn build(self) -> sp_io::TestExternalities { + let mut t = frame_system::GenesisConfig::default() + .build_storage::() + .expect("Frame system builds valid default genesis config"); + + pallet_balances::GenesisConfig:: { + balances: self.balances, + } + .assimilate_storage(&mut t) + .expect("Pallet balances storage can be assimilated"); + + let mut ext = sp_io::TestExternalities::new(t); + ext.execute_with(|| System::set_block_number(1)); + ext + } +} + +pub fn precompile_address() -> H160 { + H160::from_low_u64_be(1) +} + +// Build genesis storage according to the mock runtime. +pub fn new_test_ext() -> sp_io::TestExternalities { + frame_system::GenesisConfig::default() + .build_storage::() + .unwrap() + .into() +} diff --git a/runtime/mainnet/src/zk_precompile_gas_estimation/mod.rs b/runtime/runtime-common/src/zk_precompile_gas_estimation/mod.rs similarity index 97% rename from runtime/mainnet/src/zk_precompile_gas_estimation/mod.rs rename to runtime/runtime-common/src/zk_precompile_gas_estimation/mod.rs index c06f3d42..fa39078e 100644 --- a/runtime/mainnet/src/zk_precompile_gas_estimation/mod.rs +++ b/runtime/runtime-common/src/zk_precompile_gas_estimation/mod.rs @@ -38,3 +38,6 @@ pub mod pallet { mod benchmarking; #[cfg(test)] mod mock; + +#[cfg(test)] +mod tests; diff --git a/runtime/runtime-common/src/zk_precompile_gas_estimation/tests.rs b/runtime/runtime-common/src/zk_precompile_gas_estimation/tests.rs new file mode 100644 index 00000000..f1df0ce2 --- /dev/null +++ b/runtime/runtime-common/src/zk_precompile_gas_estimation/tests.rs @@ -0,0 +1,32 @@ +use crate::zk_precompile_gas_estimation::mock::*; + +use precompile_utils::{Bytes, EvmDataWriter}; +use sp_core::U256; + +use frame_support::assert_ok; +use pallet_evm::Call as EvmCall; +use std::str::FromStr; + +fn evm_call(input: Vec) -> EvmCall { + let alice = AccountId::from_str("f24FF3a9CF04c71Dbc94D0b566f7A27B94566cac").unwrap(); + EvmCall::call { + source: alice.into(), + target: precompile_address(), + input, + value: U256::zero(), + gas_limit: u64::max_value(), + max_fee_per_gas: 0.into(), + max_priority_fee_per_gas: Some(U256::zero()), + nonce: None, + access_list: Vec::new(), + } +} + +#[test] +fn zk_prove_works() { + let alice = AccountId::from_str("f24FF3a9CF04c71Dbc94D0b566f7A27B94566cac").unwrap(); + ExtBuilder::default() + .with_balances(vec![(alice, 1000000000000000000000)]) + .build() + .execute_with(|| {}) +} diff --git a/runtime/testnet/Cargo.toml b/runtime/testnet/Cargo.toml index f5887558..0bb04713 100644 --- a/runtime/testnet/Cargo.toml +++ b/runtime/testnet/Cargo.toml @@ -183,4 +183,5 @@ runtime-benchmarks = [ "pallet-ethereum/runtime-benchmarks", "pallet-evm/runtime-benchmarks", "pallet-hotfix-sufficients/runtime-benchmarks", + "runtime-common/runtime-benchmarks", ] From 7d10229e7fa48ad50424591eea23137c000782f8 Mon Sep 17 00:00:00 2001 From: luckychacha <358140284@qq.com> Date: Tue, 1 Aug 2023 00:25:55 +0800 Subject: [PATCH 05/34] Update mock file for zk-groth-precompile. --- runtime/runtime-common/Cargo.toml | 10 +- .../src/zk_precompile_gas_estimation/mock.rs | 300 +++++++++--------- .../src/zk_precompile_gas_estimation/mod.rs | 2 +- .../src/zk_precompile_gas_estimation/tests.rs | 38 +-- 4 files changed, 173 insertions(+), 177 deletions(-) diff --git a/runtime/runtime-common/Cargo.toml b/runtime/runtime-common/Cargo.toml index a30456ca..1a285d4a 100644 --- a/runtime/runtime-common/Cargo.toml +++ b/runtime/runtime-common/Cargo.toml @@ -8,7 +8,7 @@ repository.workspace = true # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -scale-codec = { package = "parity-scale-codec", workspace = true } +scale-codec = { package = "parity-scale-codec", workspace = true, features = ["max-encoded-len"] } scale-info.workspace = true serde = { workspace = true, optional = true } @@ -39,17 +39,19 @@ pallet-xvm = { workspace = true, optional = true } # eth abi log.workspace = true -# Astar -precompile-utils.workspace = true - [dev-dependencies] +derive_more.workspace = true fp-account.workspace = true +fp-evm.workspace = true pallet-balances.workspace = true pallet-timestamp.workspace = true proptest.workspace = true sp-io.workspace = true test-strategy.workspace = true +# Astar +precompile-utils = { workspace = true, features = ["testing"] } + [features] default = ["std"] precompiles = [ diff --git a/runtime/runtime-common/src/zk_precompile_gas_estimation/mock.rs b/runtime/runtime-common/src/zk_precompile_gas_estimation/mock.rs index abbd0199..dd3c4f29 100644 --- a/runtime/runtime-common/src/zk_precompile_gas_estimation/mock.rs +++ b/runtime/runtime-common/src/zk_precompile_gas_estimation/mock.rs @@ -1,117 +1,157 @@ -use crate::zk_precompile_gas_estimation as pallet_template; -use fp_account::EthereumSignature; -pub use frame_support::{ - construct_runtime, - pallet_prelude::GenesisBuild, - parameter_types, - traits::{ - ConstU128, ConstU32, Hooks, KeyOwnerProofSystem, OnFinalize, OnInitialize, Randomness, - StorageInfo, - }, - weights::{IdentityFee, Weight}, - PalletId, StorageValue, +use fp_evm::{IsPrecompileResult, PrecompileHandle}; +use frame_support::{ + construct_runtime, parameter_types, + traits::{ConstU32, ConstU64, Everything}, + weights::Weight, }; use pallet_evm::{ - EnsureAddressNever, EnsureAddressRoot, IsPrecompileResult, Precompile, PrecompileHandle, - PrecompileResult, PrecompileSet, + AddressMapping, EnsureAddressNever, EnsureAddressRoot, Precompile, PrecompileResult, + PrecompileSet, }; use pallet_evm_precompile_zk_groth16_verify::ZKGroth16Verify; -use sp_core::{ConstU64, H160}; +use scale_codec::{Decode, Encode, MaxEncodedLen}; +use scale_info::TypeInfo; +use serde::{Deserialize, Serialize}; +use sp_core::{H160, H256}; use sp_runtime::{ testing::Header, - traits::{IdentifyAccount, IdentityLookup, Verify}, + traits::{BlakeTwo256, IdentityLookup}, }; use sp_std::marker::PhantomData; -pub type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; -pub type Block = frame_system::mocking::MockBlock; -// pub(crate) type BlockNumber = u32; -type Signature = EthereumSignature; -pub type Balance = u128; -pub type Hash = sp_core::H256; -pub(crate) type AccountId = <::Signer as IdentifyAccount>::AccountId; - /// Constant values used within the runtime. pub const MILLIGGX: Balance = 1_000_000_000_000_000; pub const GGX: Balance = 1000 * MILLIGGX; pub const KGGX: Balance = 1000 * GGX; pub const EXISTENTIAL_DEPOSIT: Balance = GGX; -// Configure a mock runtime to test the pallet. -frame_support::construct_runtime!( - pub enum Test where - Block = Block, - NodeBlock = Block, - UncheckedExtrinsic = UncheckedExtrinsic, - { - System: frame_system::{Pallet, Call, Config, Storage, Event}, - TemplateModule: pallet_template::{Pallet, Storage}, - Evm: pallet_evm::{Pallet, Call, Storage, Event}, - Balances: pallet_balances::{Pallet, Call, Storage, Config, Event}, - Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent}, + +pub type AccountId = TestAccount; +pub type Balance = u128; +pub type BlockNumber = u64; +pub type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; +pub type Block = frame_system::mocking::MockBlock; + +pub const PRECOMPILE_ADDRESS: H160 = H160::repeat_byte(0xBB); + +#[derive( + Eq, + PartialEq, + Ord, + PartialOrd, + Clone, + Encode, + Decode, + Debug, + MaxEncodedLen, + Serialize, + Deserialize, + derive_more::Display, + TypeInfo, +)] +pub enum TestAccount { + Alice, + Bob, + Charlie, + Bogus, + Precompile, +} + +impl Default for TestAccount { + fn default() -> Self { + Self::Alice } -); +} + +impl AddressMapping for TestAccount { + fn into_account_id(h160_account: H160) -> TestAccount { + match h160_account { + a if a == H160::repeat_byte(0xAA) => Self::Alice, + a if a == H160::repeat_byte(0xBB) => Self::Bob, + a if a == H160::repeat_byte(0xCC) => Self::Charlie, + a if a == PRECOMPILE_ADDRESS => Self::Precompile, + _ => Self::Bogus, + } + } +} + +impl From for TestAccount { + fn from(x: H160) -> TestAccount { + TestAccount::into_account_id(x) + } +} + +impl From for H160 { + fn from(value: TestAccount) -> H160 { + match value { + TestAccount::Alice => H160::repeat_byte(0xAA), + TestAccount::Bob => H160::repeat_byte(0xBB), + TestAccount::Charlie => H160::repeat_byte(0xCC), + TestAccount::Precompile => PRECOMPILE_ADDRESS, + TestAccount::Bogus => Default::default(), + } + } +} parameter_types! { - pub BlockWeights: frame_system::limits::BlockWeights = - frame_system::limits::BlockWeights::simple_max( - Weight::from_parts(2_000_000_000_000, u64::MAX), - ); + pub const BlockHashCount: u64 = 250; + pub const SS58Prefix: u8 = 42; } -impl frame_system::Config for Test { - type BaseCallFilter = frame_support::traits::Everything; - type BlockWeights = BlockWeights; - type BlockLength = (); +impl frame_system::Config for Runtime { + type BaseCallFilter = Everything; type DbWeight = (); type RuntimeOrigin = RuntimeOrigin; type Index = u64; - type BlockNumber = u64; + type BlockNumber = BlockNumber; type RuntimeCall = RuntimeCall; - type Hash = Hash; - type Version = (); - type Hashing = sp_runtime::traits::BlakeTwo256; + type Hash = H256; + type Hashing = BlakeTwo256; type AccountId = AccountId; type Lookup = IdentityLookup; type Header = Header; type RuntimeEvent = RuntimeEvent; - type BlockHashCount = ConstU64<250>; + type BlockHashCount = BlockHashCount; + type Version = (); type PalletInfo = PalletInfo; type AccountData = pallet_balances::AccountData; type OnNewAccount = (); type OnKilledAccount = (); type SystemWeightInfo = (); - type SS58Prefix = (); + type BlockWeights = (); + type BlockLength = (); + type SS58Prefix = SS58Prefix; type OnSetCode = (); type MaxConsumers = frame_support::traits::ConstU32<16>; } -parameter_types! { - // For weight estimation, we assume that the most locks on an individual account will be 50. - // This number may need to be adjusted in the future if this assumption no longer holds true. - pub const MaxLocks: u32 = 50; +#[derive(Debug, Clone, Copy)] +pub struct TestPrecompileSet(PhantomData); - // The minimum balance that an account must have in order to be kept alive on-chain. - // This value is used by the Balances pallet to determine if an account should be - // kept alive or if it should be reaped to free up storage space. - pub const ExistentialDeposit: Balance = EXISTENTIAL_DEPOSIT; -} +impl PrecompileSet for TestPrecompileSet +where + R: pallet_evm::Config, + ZKGroth16Verify: Precompile, +{ + fn execute(&self, handle: &mut impl PrecompileHandle) -> Option { + match handle.code_address() { + a if a == PRECOMPILE_ADDRESS => Some(ZKGroth16Verify::execute(handle)), + _ => None, + } + } -impl pallet_balances::Config for Test { - type Balance = Balance; - type DustRemoval = (); - type RuntimeEvent = RuntimeEvent; - type ExistentialDeposit = ExistentialDeposit; - type AccountStore = System; - type WeightInfo = (); - type MaxLocks = MaxLocks; - type MaxReserves = (); - type ReserveIdentifier = [u8; 8]; + fn is_precompile(&self, address: H160, _gas: u64) -> IsPrecompileResult { + IsPrecompileResult::Answer { + is_precompile: address == PRECOMPILE_ADDRESS, + extra_cost: 0, + } + } } parameter_types! { pub const MinimumPeriod: u64 = 5; } -impl pallet_timestamp::Config for Test { + +impl pallet_timestamp::Config for Runtime { type Moment = u64; type OnTimestampSet = (); type MinimumPeriod = MinimumPeriod; @@ -119,116 +159,74 @@ impl pallet_timestamp::Config for Test { } parameter_types! { - pub const PrecompilesValue: Precompiles = Precompiles(PhantomData); - pub const WeightPerGas: Weight = Weight::from_parts(1, 0); + pub const ExistentialDeposit: Balance = EXISTENTIAL_DEPOSIT; } -pub struct IntoAddressMapping; +impl pallet_balances::Config for Runtime { + type MaxReserves = (); + type ReserveIdentifier = (); + type MaxLocks = (); + type Balance = Balance; + type RuntimeEvent = RuntimeEvent; + type DustRemoval = (); + type ExistentialDeposit = ExistentialDeposit; + type AccountStore = System; + type WeightInfo = (); +} -impl> pallet_evm::AddressMapping for IntoAddressMapping { - fn into_account_id(address: H160) -> T { - address.into() - } +parameter_types! { + pub const PrecompilesValue: TestPrecompileSet = + TestPrecompileSet(PhantomData); + pub const WeightPerGas: Weight = Weight::from_parts(1, 0); } -impl pallet_evm::Config for Test { +impl pallet_evm::Config for Runtime { type FeeCalculator = (); type GasWeightMapping = pallet_evm::FixedGasWeightMapping; type WeightPerGas = WeightPerGas; type CallOrigin = EnsureAddressRoot; type WithdrawOrigin = EnsureAddressNever; - type AddressMapping = IntoAddressMapping; + type AddressMapping = AccountId; type Currency = Balances; type RuntimeEvent = RuntimeEvent; type Runner = pallet_evm::runner::stack::Runner; - type PrecompilesType = Precompiles; + type PrecompilesType = TestPrecompileSet; type PrecompilesValue = PrecompilesValue; + type Timestamp = Timestamp; type ChainId = (); type OnChargeTransaction = (); type BlockGasLimit = (); type BlockHashMapping = pallet_evm::SubstrateBlockHashMapping; - type FindAuthor = (); type OnCreate = (); - type Timestamp = Timestamp; - type WeightInfo = pallet_evm::weights::SubstrateWeight; + type FindAuthor = (); + type WeightInfo = (); } -pub const PRECOMPILE_ADDRESS: u64 = 1; - -#[derive(Default)] -pub struct Precompiles(PhantomData); - -impl PrecompileSet for Precompiles -where - R: pallet_evm::Config, -{ - fn execute(&self, handle: &mut impl PrecompileHandle) -> Option { - match handle.code_address() { - a if a == hash(PRECOMPILE_ADDRESS) => Some(ZKGroth16Verify::execute(handle)), - _ => None, - } - } - - // fn is_precompile(&self, address: H160) -> bool { - // address == hash(PRECOMPILE_ADDRESS) - // } - fn is_precompile(&self, address: H160, _gas: u64) -> IsPrecompileResult { - IsPrecompileResult::Answer { - is_precompile: address == hash(PRECOMPILE_ADDRESS), - extra_cost: 0, - } +// Configure a mock runtime to test the pallet. +construct_runtime!( + pub enum Runtime where + Block = Block, + NodeBlock = Block, + UncheckedExtrinsic = UncheckedExtrinsic, + { + System: frame_system, + Balances: pallet_balances, + Evm: pallet_evm, + Timestamp: pallet_timestamp, } -} - -fn hash(a: u64) -> H160 { - H160::from_low_u64_be(a) -} - -impl pallet_template::Config for Test { - // type Event = Event; -} - -pub(crate) struct ExtBuilder { - balances: Vec<(AccountId, Balance)>, -} +); -impl Default for ExtBuilder { - fn default() -> ExtBuilder { - ExtBuilder { balances: vec![] } - } -} +#[derive(Default)] +pub(crate) struct ExtBuilder; impl ExtBuilder { - pub(crate) fn with_balances(mut self, balances: Vec<(AccountId, Balance)>) -> Self { - self.balances = balances; - self - } - pub(crate) fn build(self) -> sp_io::TestExternalities { - let mut t = frame_system::GenesisConfig::default() - .build_storage::() + let t = frame_system::GenesisConfig::default() + .build_storage::() .expect("Frame system builds valid default genesis config"); - pallet_balances::GenesisConfig:: { - balances: self.balances, - } - .assimilate_storage(&mut t) - .expect("Pallet balances storage can be assimilated"); - let mut ext = sp_io::TestExternalities::new(t); ext.execute_with(|| System::set_block_number(1)); ext } } - -pub fn precompile_address() -> H160 { - H160::from_low_u64_be(1) -} - -// Build genesis storage according to the mock runtime. -pub fn new_test_ext() -> sp_io::TestExternalities { - frame_system::GenesisConfig::default() - .build_storage::() - .unwrap() - .into() -} diff --git a/runtime/runtime-common/src/zk_precompile_gas_estimation/mod.rs b/runtime/runtime-common/src/zk_precompile_gas_estimation/mod.rs index fa39078e..355846d9 100644 --- a/runtime/runtime-common/src/zk_precompile_gas_estimation/mod.rs +++ b/runtime/runtime-common/src/zk_precompile_gas_estimation/mod.rs @@ -1,4 +1,4 @@ -// #![cfg_attr(not(feature = "std"), no_std)] +use super::*; pub use pallet::*; #[frame_support::pallet] diff --git a/runtime/runtime-common/src/zk_precompile_gas_estimation/tests.rs b/runtime/runtime-common/src/zk_precompile_gas_estimation/tests.rs index f1df0ce2..038ab454 100644 --- a/runtime/runtime-common/src/zk_precompile_gas_estimation/tests.rs +++ b/runtime/runtime-common/src/zk_precompile_gas_estimation/tests.rs @@ -1,32 +1,28 @@ use crate::zk_precompile_gas_estimation::mock::*; -use precompile_utils::{Bytes, EvmDataWriter}; +// use precompile_utils::testing::*; use sp_core::U256; use frame_support::assert_ok; use pallet_evm::Call as EvmCall; +use precompile_utils::{ + succeed, testing::*, Bytes, EvmDataWriter, EvmResult, FunctionModifier, PrecompileHandleExt, +}; use std::str::FromStr; - -fn evm_call(input: Vec) -> EvmCall { - let alice = AccountId::from_str("f24FF3a9CF04c71Dbc94D0b566f7A27B94566cac").unwrap(); - EvmCall::call { - source: alice.into(), - target: precompile_address(), - input, - value: U256::zero(), - gas_limit: u64::max_value(), - max_fee_per_gas: 0.into(), - max_priority_fee_per_gas: Some(U256::zero()), - nonce: None, - access_list: Vec::new(), - } +fn precompiles() -> TestPrecompileSet { + PrecompilesValue::get() } #[test] -fn zk_prove_works() { - let alice = AccountId::from_str("f24FF3a9CF04c71Dbc94D0b566f7A27B94566cac").unwrap(); - ExtBuilder::default() - .with_balances(vec![(alice, 1000000000000000000000)]) - .build() - .execute_with(|| {}) +fn zk_groth16_verify_work() { + ExtBuilder::default().build().execute_with(|| { + precompiles() + .prepare_test( + TestAccount::Alice, + PRECOMPILE_ADDRESS, + EvmDataWriter::new().build(), + ) + .expect_no_logs() + .execute_returns(EvmDataWriter::new().write(true).build()); + }) } From e7d70f5ba99d9a0cadbb7269903d685e134a87e8 Mon Sep 17 00:00:00 2001 From: luckychacha <358140284@qq.com> Date: Tue, 1 Aug 2023 16:31:33 +0800 Subject: [PATCH 06/34] Update zk-groth16-verify benchmarking file. --- Cargo.lock | 62 +++++- node/tests/evm_zk_verify_precompile_abi.json | 2 +- precompiles/zk-groth16-verify/src/lib.rs | 18 +- .../benchmarking.rs | 159 +++++++++++++-- .../src/zk_precompile_gas_estimation/mod.rs | 1 + .../src/zk_precompile_gas_estimation/tests.rs | 183 +++++++++++++++++- 6 files changed, 400 insertions(+), 25 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index dc0d9b9b..8ede5d12 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -559,7 +559,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "88903cb14723e4d4003335bb7f8a14f27691649105346a0f0957466c096adfe6" dependencies = [ "anstyle", - "bstr", + "bstr 1.6.0", "doc-comment", "predicates 3.0.3", "predicates-core", @@ -1020,6 +1020,17 @@ dependencies = [ "sha2 0.9.9", ] +[[package]] +name = "bstr" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba3569f383e8f1598449f1a423e72e99569137b47740b1da11ef19af3d5c3223" +dependencies = [ + "lazy_static", + "memchr", + "regex-automata 0.1.10", +] + [[package]] name = "bstr" version = "1.6.0" @@ -1416,6 +1427,18 @@ dependencies = [ "crossbeam-utils", ] +[[package]] +name = "console" +version = "0.15.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c926e00cc70edefdc64d3a5ff31cc65bb97a3460097762bd23afb4d8145fccf8" +dependencies = [ + "encode_unicode", + "lazy_static", + "libc", + "windows-sys 0.45.0", +] + [[package]] name = "const-oid" version = "0.9.4" @@ -2274,6 +2297,12 @@ dependencies = [ "log", ] +[[package]] +name = "encode_unicode" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f" + [[package]] name = "encoding_rs" version = "0.8.32" @@ -3852,7 +3881,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1391ab1f92ffcc08911957149833e682aa3fe252b9f45f966d2ef972274c97df" dependencies = [ "aho-corasick", - "bstr", + "bstr 1.6.0", "fnv", "log", "regex", @@ -8158,6 +8187,7 @@ dependencies = [ "parity-scale-codec 3.6.4", "precompile-utils-macro", "sha3 0.10.8", + "similar-asserts", "sp-core", "sp-io", "sp-runtime", @@ -8981,7 +9011,9 @@ dependencies = [ name = "runtime-common" version = "0.1.0" dependencies = [ + "derive_more", "fp-account", + "fp-evm", "frame-benchmarking", "frame-support", "frame-system", @@ -10930,6 +10962,26 @@ dependencies = [ "wide", ] +[[package]] +name = "similar" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "420acb44afdae038210c99e69aae24109f32f15500aa708e81d46c9f29d55fcf" +dependencies = [ + "bstr 0.2.17", + "unicode-segmentation", +] + +[[package]] +name = "similar-asserts" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbf644ad016b75129f01a34a355dcb8d66a5bc803e417c7a77cc5d5ee9fa0f18" +dependencies = [ + "console", + "similar", +] + [[package]] name = "siphasher" version = "0.3.10" @@ -12914,6 +12966,12 @@ dependencies = [ "tinyvec", ] +[[package]] +name = "unicode-segmentation" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" + [[package]] name = "unicode-width" version = "0.1.10" diff --git a/node/tests/evm_zk_verify_precompile_abi.json b/node/tests/evm_zk_verify_precompile_abi.json index 92d81848..42e36309 100644 --- a/node/tests/evm_zk_verify_precompile_abi.json +++ b/node/tests/evm_zk_verify_precompile_abi.json @@ -51,7 +51,7 @@ "outputs": [ { "internalType": "bool", - "name": "", + "name": "valid", "type": "bool" } ], diff --git a/precompiles/zk-groth16-verify/src/lib.rs b/precompiles/zk-groth16-verify/src/lib.rs index 590f74e7..5da413a2 100644 --- a/precompiles/zk-groth16-verify/src/lib.rs +++ b/precompiles/zk-groth16-verify/src/lib.rs @@ -9,12 +9,18 @@ use ark_crypto_primitives::snark::SNARK; use ark_groth16::Groth16; use ark::{ark_bn254_fr, ark_bn254_g1, ark_bn254_g2}; -use precompile_utils::EvmDataWriter; +use precompile_utils::{EvmDataReader, EvmDataWriter}; pub struct ZKGroth16Verify; mod ark; +#[precompile_utils::generate_function_selector] +#[derive(Debug, PartialEq)] +pub enum Action { + Verify = "verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])", +} + impl LinearCostPrecompile for ZKGroth16Verify { const BASE: u64 = 60; const WORD: u64 = 12; @@ -22,11 +28,19 @@ impl LinearCostPrecompile for ZKGroth16Verify { fn execute(input: &[u8], _cost: u64) -> Result<(ExitSucceed, Vec), PrecompileFailure> { log::trace!(target: "precompiles::zk_groth16_verify::execute", "In zk-groth16-verify"); const MIN_INPUT_LENGTH: usize = 24 * 32; + let selector: Action = EvmDataReader::read_selector(input)?; + if input.len() < 4 + MIN_INPUT_LENGTH { return Err(PrecompileFailure::from(ExitError::InvalidRange)); } - let (_selector, input_stripped) = input.split_at(4); + match selector { + Action::Verify => Self::verify(&input[4..]), + } + } +} +impl ZKGroth16Verify { + pub fn verify(input_stripped: &[u8]) -> Result<(ExitSucceed, Vec), PrecompileFailure> { let mut cursor = 0; let mut next = || { let start = cursor; diff --git a/runtime/runtime-common/src/zk_precompile_gas_estimation/benchmarking.rs b/runtime/runtime-common/src/zk_precompile_gas_estimation/benchmarking.rs index 049124ca..9e35434b 100644 --- a/runtime/runtime-common/src/zk_precompile_gas_estimation/benchmarking.rs +++ b/runtime/runtime-common/src/zk_precompile_gas_estimation/benchmarking.rs @@ -4,26 +4,161 @@ use super::*; use crate::zk_precompile_gas_estimation::Pallet as ZKPrecompileGasEstimation; use frame_benchmarking::{benchmarks, whitelisted_caller}; // use frame_system::RawOrigin; - +use sp_core::U256; benchmarks! { - do_some_work_t { + do_some_work { let caller: T::AccountId = whitelisted_caller(); }:{ - let _ = ZKPrecompileGasEstimation::::do_some_work(s.into()); - - let alice = AccountId::from_str("f24FF3a9CF04c71Dbc94D0b566f7A27B94566cac").unwrap(); - ExtBuilder::default() - .with_balances(vec![(alice, 1000000000000000000000)]) - .build() - .execute_with(|| { - }) + let ( + proof_a, + proof_b, + proof_c, + vk_alpha, + vk_beta, + vk_gamma, + vk_delta, + vk_ic, + valid_input, + _, + ) = generate_test_case_data().unwrap(); + + precompiles() + .prepare_test( + TestAccount::Alice, + PRECOMPILE_ADDRESS, + EvmDataWriter::new_with_selector(Action::Verify) + .write(proof_a) + .write(proof_b) + .write(proof_c) + .write(vk_alpha) + .write(vk_beta) + .write(vk_gamma) + .write(vk_delta) + .write(vk_ic) + .write(valid_input) + .build(), + ) + .expect_no_logs() + .execute_returns(EvmDataWriter::new().write(true).build()); + } } // 使用mock中的new_test_ext // impl_benchmark_test_suite!(ZKPrecompileGasEstimation, crate::mock::new_test_ext(), crate::mock::Test); impl_benchmark_test_suite!( ZKPrecompileGasEstimation, - crate::zk_precompile_gas_estimation::mock::new_test_ext(), - crate::zk_precompile_gas_estimation::mock::Test + ExtBuilder::default().build(),, + crate::zk_precompile_gas_estimation::mock::Runtime ); } + +fn generate_test_case_data() -> Result< + ( + (U256, U256), + ((U256, U256), (U256, U256)), + (U256, U256), + (U256, U256), + ((U256, U256), (U256, U256)), + ((U256, U256), (U256, U256)), + ((U256, U256), (U256, U256)), + Vec<(U256, U256)>, + Vec, + Vec, + ), + Box, +> { + let proof_a = decode_g1_point( + "13202079600221154376862161785979680082984660469505374274880948735521253479994", + "19032139815435908179959144311759562497239236177745989139113028703727512477837", + )?; + let proof_b = decode_g2_point( + "9517359327043802798811688827065407805934924568686293993682568334305900037151", + "13975418982386111217378923290980800393212535787789845393400867460398182717751", + "11101434469251848949317000686121782094334155840067455941163819739470030872205", + "3351121397470969456277617123820147601817413346203636355523709813813837616699", + )?; + let proof_c = decode_g1_point( + "21771166379144524714497801611702430117390298454683954881352912868492853507834", + "5971832614272362565584439633663845994795381011258125087840397908182066694531", + )?; + + let vk_alpha = decode_g1_point( + "7318409901911144874440195167086183143676595981815053389579728623121590098440", + "18845965879715444612950452554360629789407129470518446134938217746489723713219", + )?; + let vk_beta = decode_g2_point( + "4640649673239597789758809808535118135578677216672702870175791505196312738305", + "13141288066376351908866878766575256664575916601245245304316354941350328880142", + "11492338667195076401975872253943030431149343004937779351839311477974294172860", + "17604387530215185597479117283681563543587978658046512716245947218617178983155", + )?; + let vk_gamma = decode_g2_point( + "10857046999023057135944570762232829481370756359578518086990519993285655852781", + "11559732032986387107991004021392285783925812861821192530917403151452391805634", + "8495653923123431417604973247489272438418190587263600148770280649306958101930", + "4082367875863433681332203403145435568316851327593401208105741076214120093531", + )?; + let vk_delta = decode_g2_point( + "5882870888685857628232224840789532289346124290586616915986585508513239272539", + "8206718104089392401855946495573733123991363841198873660903571227166120193870", + "14275677868038957349366208693756706908778821863795564855498136614399516409168", + "20950579407520036072561845357324335488555384097745021047033651867265123837403", + )?; + let vk_ic = decode_ic(vec![ + [ + "15329034480187562940265095627808115353397553736992059710948268284574612609224" + .to_string(), + "13272704791638435782238987852007128987814629753205340563304933194747762248428" + .to_string(), + ], + [ + "17269839325091679315052274785558946544729609490743199699197195008879157661695" + .to_string(), + "4142750859697696641705372803120309740931359230261851701215055719438325633654" + .to_string(), + ], + ])?; + + let valid_input: Vec = vec![U256::from(66)]; + let invalid_input: Vec = vec![U256::from(65)]; + + Ok(( + proof_a, + proof_b, + proof_c, + vk_alpha, + vk_beta, + vk_gamma, + vk_delta, + vk_ic, + valid_input, + invalid_input, + )) +} + +fn decode_g1_point(x: &str, y: &str) -> Result<(U256, U256), Box> { + Ok((U256::from_dec_str(x)?, U256::from_dec_str(y)?)) +} + +fn decode_g2_point( + x1: &str, + x2: &str, + y1: &str, + y2: &str, +) -> Result<((U256, U256), (U256, U256)), Box> { + Ok(( + (U256::from_dec_str(x1)?, U256::from_dec_str(x2)?), + (U256::from_dec_str(y1)?, U256::from_dec_str(y2)?), + )) +} + +fn decode_ic(points: Vec<[String; 2]>) -> Result, Box> { + let mut result = Vec::new(); + for point in points { + result.push(( + U256::from_dec_str(&point[0])?, + U256::from_dec_str(&point[1])?, + )); + } + Ok(result) +} diff --git a/runtime/runtime-common/src/zk_precompile_gas_estimation/mod.rs b/runtime/runtime-common/src/zk_precompile_gas_estimation/mod.rs index 355846d9..4eeb085c 100644 --- a/runtime/runtime-common/src/zk_precompile_gas_estimation/mod.rs +++ b/runtime/runtime-common/src/zk_precompile_gas_estimation/mod.rs @@ -1,6 +1,7 @@ use super::*; pub use pallet::*; +use pallet_evm_precompile_zk_groth16_verify::ZKGroth16Verify; #[frame_support::pallet] pub mod pallet { // use frame_support::{ diff --git a/runtime/runtime-common/src/zk_precompile_gas_estimation/tests.rs b/runtime/runtime-common/src/zk_precompile_gas_estimation/tests.rs index 038ab454..f8a9b7aa 100644 --- a/runtime/runtime-common/src/zk_precompile_gas_estimation/tests.rs +++ b/runtime/runtime-common/src/zk_precompile_gas_estimation/tests.rs @@ -1,14 +1,10 @@ use crate::zk_precompile_gas_estimation::mock::*; - +use pallet_evm_precompile_zk_groth16_verify::Action; // use precompile_utils::testing::*; use sp_core::U256; -use frame_support::assert_ok; -use pallet_evm::Call as EvmCall; -use precompile_utils::{ - succeed, testing::*, Bytes, EvmDataWriter, EvmResult, FunctionModifier, PrecompileHandleExt, -}; -use std::str::FromStr; +use precompile_utils::{testing::*, EvmDataWriter}; + fn precompiles() -> TestPrecompileSet { PrecompilesValue::get() } @@ -16,13 +12,184 @@ fn precompiles() -> TestPrecompileSet { #[test] fn zk_groth16_verify_work() { ExtBuilder::default().build().execute_with(|| { + let ( + proof_a, + proof_b, + proof_c, + vk_alpha, + vk_beta, + vk_gamma, + vk_delta, + vk_ic, + valid_input, + _, + ) = generate_test_case_data().unwrap(); + precompiles() .prepare_test( TestAccount::Alice, PRECOMPILE_ADDRESS, - EvmDataWriter::new().build(), + EvmDataWriter::new_with_selector(Action::Verify) + .write(proof_a) + .write(proof_b) + .write(proof_c) + .write(vk_alpha) + .write(vk_beta) + .write(vk_gamma) + .write(vk_delta) + .write(vk_ic) + .write(valid_input) + .build(), ) .expect_no_logs() .execute_returns(EvmDataWriter::new().write(true).build()); }) } + +#[test] +fn zk_groth16_verify_work_with_invalid_proof() { + ExtBuilder::default().build().execute_with(|| { + let ( + proof_a, + proof_b, + proof_c, + vk_alpha, + vk_beta, + vk_gamma, + vk_delta, + vk_ic, + _, + invalid_input, + ) = generate_test_case_data().unwrap(); + + precompiles() + .prepare_test( + TestAccount::Alice, + PRECOMPILE_ADDRESS, + EvmDataWriter::new_with_selector(Action::Verify) + .write(proof_a) + .write(proof_b) + .write(proof_c) + .write(vk_alpha) + .write(vk_beta) + .write(vk_gamma) + .write(vk_delta) + .write(vk_ic) + .write(invalid_input) + .build(), + ) + .expect_no_logs() + .execute_returns(EvmDataWriter::new().write(false).build()); + }) +} + +fn generate_test_case_data() -> Result< + ( + (U256, U256), + ((U256, U256), (U256, U256)), + (U256, U256), + (U256, U256), + ((U256, U256), (U256, U256)), + ((U256, U256), (U256, U256)), + ((U256, U256), (U256, U256)), + Vec<(U256, U256)>, + Vec, + Vec, + ), + Box, +> { + let proof_a = decode_g1_point( + "13202079600221154376862161785979680082984660469505374274880948735521253479994", + "19032139815435908179959144311759562497239236177745989139113028703727512477837", + )?; + let proof_b = decode_g2_point( + "9517359327043802798811688827065407805934924568686293993682568334305900037151", + "13975418982386111217378923290980800393212535787789845393400867460398182717751", + "11101434469251848949317000686121782094334155840067455941163819739470030872205", + "3351121397470969456277617123820147601817413346203636355523709813813837616699", + )?; + let proof_c = decode_g1_point( + "21771166379144524714497801611702430117390298454683954881352912868492853507834", + "5971832614272362565584439633663845994795381011258125087840397908182066694531", + )?; + + let vk_alpha = decode_g1_point( + "7318409901911144874440195167086183143676595981815053389579728623121590098440", + "18845965879715444612950452554360629789407129470518446134938217746489723713219", + )?; + let vk_beta = decode_g2_point( + "4640649673239597789758809808535118135578677216672702870175791505196312738305", + "13141288066376351908866878766575256664575916601245245304316354941350328880142", + "11492338667195076401975872253943030431149343004937779351839311477974294172860", + "17604387530215185597479117283681563543587978658046512716245947218617178983155", + )?; + let vk_gamma = decode_g2_point( + "10857046999023057135944570762232829481370756359578518086990519993285655852781", + "11559732032986387107991004021392285783925812861821192530917403151452391805634", + "8495653923123431417604973247489272438418190587263600148770280649306958101930", + "4082367875863433681332203403145435568316851327593401208105741076214120093531", + )?; + let vk_delta = decode_g2_point( + "5882870888685857628232224840789532289346124290586616915986585508513239272539", + "8206718104089392401855946495573733123991363841198873660903571227166120193870", + "14275677868038957349366208693756706908778821863795564855498136614399516409168", + "20950579407520036072561845357324335488555384097745021047033651867265123837403", + )?; + let vk_ic = decode_ic(vec![ + [ + "15329034480187562940265095627808115353397553736992059710948268284574612609224" + .to_string(), + "13272704791638435782238987852007128987814629753205340563304933194747762248428" + .to_string(), + ], + [ + "17269839325091679315052274785558946544729609490743199699197195008879157661695" + .to_string(), + "4142750859697696641705372803120309740931359230261851701215055719438325633654" + .to_string(), + ], + ])?; + + let valid_input: Vec = vec![U256::from(66)]; + let invalid_input: Vec = vec![U256::from(65)]; + + Ok(( + proof_a, + proof_b, + proof_c, + vk_alpha, + vk_beta, + vk_gamma, + vk_delta, + vk_ic, + valid_input, + invalid_input, + )) +} + +fn decode_g1_point(x: &str, y: &str) -> Result<(U256, U256), Box> { + Ok((U256::from_dec_str(x)?, U256::from_dec_str(y)?)) +} + +fn decode_g2_point( + x1: &str, + x2: &str, + y1: &str, + y2: &str, +) -> Result<((U256, U256), (U256, U256)), Box> { + Ok(( + (U256::from_dec_str(x1)?, U256::from_dec_str(x2)?), + (U256::from_dec_str(y1)?, U256::from_dec_str(y2)?), + )) +} + +fn decode_ic(points: Vec<[String; 2]>) -> Result, Box> { + let mut result = Vec::new(); + for point in points { + result.push(( + U256::from_dec_str(&point[0])?, + U256::from_dec_str(&point[1])?, + )); + } + Ok(result) +} From 16fa8077a6ea6f25058ec9d7bce2de0eaae61b01 Mon Sep 17 00:00:00 2001 From: luckychacha <358140284@qq.com> Date: Wed, 2 Aug 2023 02:04:31 +0800 Subject: [PATCH 07/34] Debug benchmarking. --- runtime/runtime-common/Cargo.toml | 3 ++- .../benchmarking.rs | 20 ++++++++++--------- .../src/zk_precompile_gas_estimation/mock.rs | 7 +------ .../src/zk_precompile_gas_estimation/mod.rs | 3 --- 4 files changed, 14 insertions(+), 19 deletions(-) diff --git a/runtime/runtime-common/Cargo.toml b/runtime/runtime-common/Cargo.toml index 1a285d4a..12b6e48c 100644 --- a/runtime/runtime-common/Cargo.toml +++ b/runtime/runtime-common/Cargo.toml @@ -96,4 +96,5 @@ std = [ "pallet-evm-precompile-zk-groth16-verify?/std", "pallet-xvm?/std", ] -runtime-benchmarks = [] +runtime-benchmarks = [ +] diff --git a/runtime/runtime-common/src/zk_precompile_gas_estimation/benchmarking.rs b/runtime/runtime-common/src/zk_precompile_gas_estimation/benchmarking.rs index 9e35434b..6187f59f 100644 --- a/runtime/runtime-common/src/zk_precompile_gas_estimation/benchmarking.rs +++ b/runtime/runtime-common/src/zk_precompile_gas_estimation/benchmarking.rs @@ -1,12 +1,16 @@ -use super::*; - -#[allow(unused)] -use crate::zk_precompile_gas_estimation::Pallet as ZKPrecompileGasEstimation; +use crate::zk_precompile_gas_estimation::{mock::*, Pallet as ZKPrecompileGasEstimation}; use frame_benchmarking::{benchmarks, whitelisted_caller}; -// use frame_system::RawOrigin; +use pallet_evm_precompile_zk_groth16_verify::Action; +use precompile_utils::{testing::*, EvmDataWriter}; use sp_core::U256; +use sp_std::{boxed::Box, vec, vec::Vec}; + +fn precompiles() -> TestPrecompileSet { + PrecompilesValue::get() +} + benchmarks! { - do_some_work { + do_some_work { let caller: T::AccountId = whitelisted_caller(); }:{ let ( @@ -40,11 +44,8 @@ benchmarks! { ) .expect_no_logs() .execute_returns(EvmDataWriter::new().write(true).build()); - } } - // 使用mock中的new_test_ext -// impl_benchmark_test_suite!(ZKPrecompileGasEstimation, crate::mock::new_test_ext(), crate::mock::Test); impl_benchmark_test_suite!( ZKPrecompileGasEstimation, ExtBuilder::default().build(),, @@ -104,6 +105,7 @@ fn generate_test_case_data() -> Result< "14275677868038957349366208693756706908778821863795564855498136614399516409168", "20950579407520036072561845357324335488555384097745021047033651867265123837403", )?; + // replace vec! to Vec:: let vk_ic = decode_ic(vec![ [ "15329034480187562940265095627808115353397553736992059710948268284574612609224" diff --git a/runtime/runtime-common/src/zk_precompile_gas_estimation/mock.rs b/runtime/runtime-common/src/zk_precompile_gas_estimation/mock.rs index dd3c4f29..dc5dab0e 100644 --- a/runtime/runtime-common/src/zk_precompile_gas_estimation/mock.rs +++ b/runtime/runtime-common/src/zk_precompile_gas_estimation/mock.rs @@ -1,9 +1,5 @@ use fp_evm::{IsPrecompileResult, PrecompileHandle}; -use frame_support::{ - construct_runtime, parameter_types, - traits::{ConstU32, ConstU64, Everything}, - weights::Weight, -}; +use frame_support::{construct_runtime, parameter_types, traits::Everything, weights::Weight}; use pallet_evm::{ AddressMapping, EnsureAddressNever, EnsureAddressRoot, Precompile, PrecompileResult, PrecompileSet, @@ -22,7 +18,6 @@ use sp_std::marker::PhantomData; /// Constant values used within the runtime. pub const MILLIGGX: Balance = 1_000_000_000_000_000; pub const GGX: Balance = 1000 * MILLIGGX; -pub const KGGX: Balance = 1000 * GGX; pub const EXISTENTIAL_DEPOSIT: Balance = GGX; pub type AccountId = TestAccount; diff --git a/runtime/runtime-common/src/zk_precompile_gas_estimation/mod.rs b/runtime/runtime-common/src/zk_precompile_gas_estimation/mod.rs index 4eeb085c..3cd78b2a 100644 --- a/runtime/runtime-common/src/zk_precompile_gas_estimation/mod.rs +++ b/runtime/runtime-common/src/zk_precompile_gas_estimation/mod.rs @@ -1,7 +1,4 @@ -use super::*; - pub use pallet::*; -use pallet_evm_precompile_zk_groth16_verify::ZKGroth16Verify; #[frame_support::pallet] pub mod pallet { // use frame_support::{ From 034ca00f94d7b210b101dd9a63a2a63a5589ba83 Mon Sep 17 00:00:00 2001 From: luckychacha <358140284@qq.com> Date: Wed, 2 Aug 2023 18:35:05 +0800 Subject: [PATCH 08/34] Rewrite benchmarking... --- runtime/mainnet/src/lib.rs | 11 +- .../benchmarking.rs | 168 +------ .../src/zk_precompile_gas_estimation/mock.rs | 253 +++++------ .../src/zk_precompile_gas_estimation/mod.rs | 19 +- .../src/zk_precompile_gas_estimation/tests.rs | 412 ++++++++++-------- 5 files changed, 382 insertions(+), 481 deletions(-) diff --git a/runtime/mainnet/src/lib.rs b/runtime/mainnet/src/lib.rs index 721329d2..f2c2cb45 100644 --- a/runtime/mainnet/src/lib.rs +++ b/runtime/mainnet/src/lib.rs @@ -569,11 +569,10 @@ extern crate frame_benchmarking; #[cfg(feature = "runtime-benchmarks")] mod benches { define_benchmarks!( - [pallet_evm, EVM] - [ - zk_precompile_gas_estimation, - ZKPrecompileGasEstimation - ] + [pallet_evm, EVM] // [ + // zk_precompile_gas_estimation, + // ZKPrecompileGasEstimation + // ] ); } @@ -940,7 +939,7 @@ impl_runtime_apis! { add_benchmark!(params, batches, pallet_evm, PalletEvmBench::); add_benchmark!(params, batches, pallet_hotfix_sufficients, PalletHotfixSufficients::); - add_benchmark!(params, batches, zk_precompile_gas_estimation, ZKPrecompileGasEstimation); + // add_benchmark!(params, batches, zk_precompile_gas_estimation, ZKPrecompileGasEstimation); if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) } Ok(batches) diff --git a/runtime/runtime-common/src/zk_precompile_gas_estimation/benchmarking.rs b/runtime/runtime-common/src/zk_precompile_gas_estimation/benchmarking.rs index 6187f59f..565426e8 100644 --- a/runtime/runtime-common/src/zk_precompile_gas_estimation/benchmarking.rs +++ b/runtime/runtime-common/src/zk_precompile_gas_estimation/benchmarking.rs @@ -1,166 +1,6 @@ -use crate::zk_precompile_gas_estimation::{mock::*, Pallet as ZKPrecompileGasEstimation}; -use frame_benchmarking::{benchmarks, whitelisted_caller}; -use pallet_evm_precompile_zk_groth16_verify::Action; -use precompile_utils::{testing::*, EvmDataWriter}; -use sp_core::U256; -use sp_std::{boxed::Box, vec, vec::Vec}; +#![cfg(feature = "runtime-benchmarks")] -fn precompiles() -> TestPrecompileSet { - PrecompilesValue::get() -} +use super::*; +use frame_benchmarking::{benchmarks, impl_benchmark_test_suite}; -benchmarks! { - do_some_work { - let caller: T::AccountId = whitelisted_caller(); - }:{ - let ( - proof_a, - proof_b, - proof_c, - vk_alpha, - vk_beta, - vk_gamma, - vk_delta, - vk_ic, - valid_input, - _, - ) = generate_test_case_data().unwrap(); - - precompiles() - .prepare_test( - TestAccount::Alice, - PRECOMPILE_ADDRESS, - EvmDataWriter::new_with_selector(Action::Verify) - .write(proof_a) - .write(proof_b) - .write(proof_c) - .write(vk_alpha) - .write(vk_beta) - .write(vk_gamma) - .write(vk_delta) - .write(vk_ic) - .write(valid_input) - .build(), - ) - .expect_no_logs() - .execute_returns(EvmDataWriter::new().write(true).build()); - } - - impl_benchmark_test_suite!( - ZKPrecompileGasEstimation, - ExtBuilder::default().build(),, - crate::zk_precompile_gas_estimation::mock::Runtime - ); -} - -fn generate_test_case_data() -> Result< - ( - (U256, U256), - ((U256, U256), (U256, U256)), - (U256, U256), - (U256, U256), - ((U256, U256), (U256, U256)), - ((U256, U256), (U256, U256)), - ((U256, U256), (U256, U256)), - Vec<(U256, U256)>, - Vec, - Vec, - ), - Box, -> { - let proof_a = decode_g1_point( - "13202079600221154376862161785979680082984660469505374274880948735521253479994", - "19032139815435908179959144311759562497239236177745989139113028703727512477837", - )?; - let proof_b = decode_g2_point( - "9517359327043802798811688827065407805934924568686293993682568334305900037151", - "13975418982386111217378923290980800393212535787789845393400867460398182717751", - "11101434469251848949317000686121782094334155840067455941163819739470030872205", - "3351121397470969456277617123820147601817413346203636355523709813813837616699", - )?; - let proof_c = decode_g1_point( - "21771166379144524714497801611702430117390298454683954881352912868492853507834", - "5971832614272362565584439633663845994795381011258125087840397908182066694531", - )?; - - let vk_alpha = decode_g1_point( - "7318409901911144874440195167086183143676595981815053389579728623121590098440", - "18845965879715444612950452554360629789407129470518446134938217746489723713219", - )?; - let vk_beta = decode_g2_point( - "4640649673239597789758809808535118135578677216672702870175791505196312738305", - "13141288066376351908866878766575256664575916601245245304316354941350328880142", - "11492338667195076401975872253943030431149343004937779351839311477974294172860", - "17604387530215185597479117283681563543587978658046512716245947218617178983155", - )?; - let vk_gamma = decode_g2_point( - "10857046999023057135944570762232829481370756359578518086990519993285655852781", - "11559732032986387107991004021392285783925812861821192530917403151452391805634", - "8495653923123431417604973247489272438418190587263600148770280649306958101930", - "4082367875863433681332203403145435568316851327593401208105741076214120093531", - )?; - let vk_delta = decode_g2_point( - "5882870888685857628232224840789532289346124290586616915986585508513239272539", - "8206718104089392401855946495573733123991363841198873660903571227166120193870", - "14275677868038957349366208693756706908778821863795564855498136614399516409168", - "20950579407520036072561845357324335488555384097745021047033651867265123837403", - )?; - // replace vec! to Vec:: - let vk_ic = decode_ic(vec![ - [ - "15329034480187562940265095627808115353397553736992059710948268284574612609224" - .to_string(), - "13272704791638435782238987852007128987814629753205340563304933194747762248428" - .to_string(), - ], - [ - "17269839325091679315052274785558946544729609490743199699197195008879157661695" - .to_string(), - "4142750859697696641705372803120309740931359230261851701215055719438325633654" - .to_string(), - ], - ])?; - - let valid_input: Vec = vec![U256::from(66)]; - let invalid_input: Vec = vec![U256::from(65)]; - - Ok(( - proof_a, - proof_b, - proof_c, - vk_alpha, - vk_beta, - vk_gamma, - vk_delta, - vk_ic, - valid_input, - invalid_input, - )) -} - -fn decode_g1_point(x: &str, y: &str) -> Result<(U256, U256), Box> { - Ok((U256::from_dec_str(x)?, U256::from_dec_str(y)?)) -} - -fn decode_g2_point( - x1: &str, - x2: &str, - y1: &str, - y2: &str, -) -> Result<((U256, U256), (U256, U256)), Box> { - Ok(( - (U256::from_dec_str(x1)?, U256::from_dec_str(x2)?), - (U256::from_dec_str(y1)?, U256::from_dec_str(y2)?), - )) -} - -fn decode_ic(points: Vec<[String; 2]>) -> Result, Box> { - let mut result = Vec::new(); - for point in points { - result.push(( - U256::from_dec_str(&point[0])?, - U256::from_dec_str(&point[1])?, - )); - } - Ok(result) -} +type CurrencyOf = ::Currency; diff --git a/runtime/runtime-common/src/zk_precompile_gas_estimation/mock.rs b/runtime/runtime-common/src/zk_precompile_gas_estimation/mock.rs index dc5dab0e..7375c98a 100644 --- a/runtime/runtime-common/src/zk_precompile_gas_estimation/mock.rs +++ b/runtime/runtime-common/src/zk_precompile_gas_estimation/mock.rs @@ -1,15 +1,16 @@ use fp_evm::{IsPrecompileResult, PrecompileHandle}; use frame_support::{construct_runtime, parameter_types, traits::Everything, weights::Weight}; use pallet_evm::{ - AddressMapping, EnsureAddressNever, EnsureAddressRoot, Precompile, PrecompileResult, - PrecompileSet, + AddressMapping, EnsureAddressNever, EnsureAddressRoot, IdentityAddressMapping, Precompile, + PrecompileResult, PrecompileSet, }; use pallet_evm_precompile_zk_groth16_verify::ZKGroth16Verify; use scale_codec::{Decode, Encode, MaxEncodedLen}; use scale_info::TypeInfo; use serde::{Deserialize, Serialize}; -use sp_core::{H160, H256}; +use sp_core::{ConstU32, H160, H256}; use sp_runtime::{ + generic, testing::Header, traits::{BlakeTwo256, IdentityLookup}, }; @@ -20,133 +21,109 @@ pub const MILLIGGX: Balance = 1_000_000_000_000_000; pub const GGX: Balance = 1000 * MILLIGGX; pub const EXISTENTIAL_DEPOSIT: Balance = GGX; -pub type AccountId = TestAccount; -pub type Balance = u128; +pub type AccountId = H160; +pub type Balance = u64; pub type BlockNumber = u64; -pub type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; -pub type Block = frame_system::mocking::MockBlock; +pub type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; +pub type Block = frame_system::mocking::MockBlock; pub const PRECOMPILE_ADDRESS: H160 = H160::repeat_byte(0xBB); -#[derive( - Eq, - PartialEq, - Ord, - PartialOrd, - Clone, - Encode, - Decode, - Debug, - MaxEncodedLen, - Serialize, - Deserialize, - derive_more::Display, - TypeInfo, -)] -pub enum TestAccount { - Alice, - Bob, - Charlie, - Bogus, - Precompile, -} - -impl Default for TestAccount { - fn default() -> Self { - Self::Alice - } -} - -impl AddressMapping for TestAccount { - fn into_account_id(h160_account: H160) -> TestAccount { - match h160_account { - a if a == H160::repeat_byte(0xAA) => Self::Alice, - a if a == H160::repeat_byte(0xBB) => Self::Bob, - a if a == H160::repeat_byte(0xCC) => Self::Charlie, - a if a == PRECOMPILE_ADDRESS => Self::Precompile, - _ => Self::Bogus, - } - } -} - -impl From for TestAccount { - fn from(x: H160) -> TestAccount { - TestAccount::into_account_id(x) - } -} - -impl From for H160 { - fn from(value: TestAccount) -> H160 { - match value { - TestAccount::Alice => H160::repeat_byte(0xAA), - TestAccount::Bob => H160::repeat_byte(0xBB), - TestAccount::Charlie => H160::repeat_byte(0xCC), - TestAccount::Precompile => PRECOMPILE_ADDRESS, - TestAccount::Bogus => Default::default(), - } - } -} +// #[derive( +// Eq, +// PartialEq, +// Ord, +// PartialOrd, +// Clone, +// Encode, +// Decode, +// Debug, +// MaxEncodedLen, +// Serialize, +// Deserialize, +// derive_more::Display, +// TypeInfo, +// )] +// pub enum TestAccount { +// Alice, +// Bob, +// Charlie, +// Bogus, +// Precompile, +// } + +// impl Default for TestAccount { +// fn default() -> Self { +// Self::Alice +// } +// } + +// impl AddressMapping for TestAccount { +// fn into_account_id(h160_account: H160) -> TestAccount { +// match h160_account { +// a if a == H160::repeat_byte(0xAA) => Self::Alice, +// a if a == H160::repeat_byte(0xBB) => Self::Bob, +// a if a == H160::repeat_byte(0xCC) => Self::Charlie, +// a if a == PRECOMPILE_ADDRESS => Self::Precompile, +// _ => Self::Bogus, +// } +// } +// } + +// impl From for TestAccount { +// fn from(x: H160) -> TestAccount { +// TestAccount::into_account_id(x) +// } +// } + +// impl From for H160 { +// fn from(value: TestAccount) -> H160 { +// match value { +// TestAccount::Alice => H160::repeat_byte(0xAA), +// TestAccount::Bob => H160::repeat_byte(0xBB), +// TestAccount::Charlie => H160::repeat_byte(0xCC), +// TestAccount::Precompile => PRECOMPILE_ADDRESS, +// TestAccount::Bogus => Default::default(), +// } +// } +// } parameter_types! { pub const BlockHashCount: u64 = 250; - pub const SS58Prefix: u8 = 42; + pub BlockWeights: frame_system::limits::BlockWeights = + frame_system::limits::BlockWeights::simple_max(Weight::from_parts(1024, 0)); } - -impl frame_system::Config for Runtime { - type BaseCallFilter = Everything; - type DbWeight = (); +impl frame_system::Config for Test { + type RuntimeEvent = RuntimeEvent; + type BaseCallFilter = frame_support::traits::Everything; + type BlockWeights = (); + type BlockLength = (); type RuntimeOrigin = RuntimeOrigin; - type Index = u64; - type BlockNumber = BlockNumber; type RuntimeCall = RuntimeCall; + type Index = u64; + type BlockNumber = u64; type Hash = H256; type Hashing = BlakeTwo256; - type AccountId = AccountId; + type AccountId = H160; type Lookup = IdentityLookup; - type Header = Header; - type RuntimeEvent = RuntimeEvent; + type Header = generic::Header; type BlockHashCount = BlockHashCount; + type DbWeight = (); type Version = (); type PalletInfo = PalletInfo; - type AccountData = pallet_balances::AccountData; + type AccountData = pallet_balances::AccountData; type OnNewAccount = (); type OnKilledAccount = (); type SystemWeightInfo = (); - type BlockWeights = (); - type BlockLength = (); - type SS58Prefix = SS58Prefix; + type SS58Prefix = (); type OnSetCode = (); - type MaxConsumers = frame_support::traits::ConstU32<16>; -} - -#[derive(Debug, Clone, Copy)] -pub struct TestPrecompileSet(PhantomData); - -impl PrecompileSet for TestPrecompileSet -where - R: pallet_evm::Config, - ZKGroth16Verify: Precompile, -{ - fn execute(&self, handle: &mut impl PrecompileHandle) -> Option { - match handle.code_address() { - a if a == PRECOMPILE_ADDRESS => Some(ZKGroth16Verify::execute(handle)), - _ => None, - } - } - - fn is_precompile(&self, address: H160, _gas: u64) -> IsPrecompileResult { - IsPrecompileResult::Answer { - is_precompile: address == PRECOMPILE_ADDRESS, - extra_cost: 0, - } - } + type MaxConsumers = ConstU32<16>; } - parameter_types! { pub const MinimumPeriod: u64 = 5; } -impl pallet_timestamp::Config for Runtime { +impl pallet_timestamp::Config for Test { type Moment = u64; type OnTimestampSet = (); type MinimumPeriod = MinimumPeriod; @@ -154,60 +131,63 @@ impl pallet_timestamp::Config for Runtime { } parameter_types! { - pub const ExistentialDeposit: Balance = EXISTENTIAL_DEPOSIT; + pub const ExistentialDeposit: u64 = EXISTENTIAL_DEPOSIT; } -impl pallet_balances::Config for Runtime { - type MaxReserves = (); - type ReserveIdentifier = (); - type MaxLocks = (); - type Balance = Balance; +impl pallet_balances::Config for Test { type RuntimeEvent = RuntimeEvent; + type WeightInfo = (); + type Balance = Balance; type DustRemoval = (); type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; - type WeightInfo = (); + type ReserveIdentifier = (); + type MaxLocks = (); + type MaxReserves = (); } parameter_types! { - pub const PrecompilesValue: TestPrecompileSet = - TestPrecompileSet(PhantomData); + pub const MockPrecompiles: MockPrecompileSet = + MockPrecompileSet(PhantomData); pub const WeightPerGas: Weight = Weight::from_parts(1, 0); } -impl pallet_evm::Config for Runtime { +impl pallet_evm::Config for Test { type FeeCalculator = (); type GasWeightMapping = pallet_evm::FixedGasWeightMapping; type WeightPerGas = WeightPerGas; + + type BlockHashMapping = pallet_evm::SubstrateBlockHashMapping; type CallOrigin = EnsureAddressRoot; + type WithdrawOrigin = EnsureAddressNever; - type AddressMapping = AccountId; + type AddressMapping = IdentityAddressMapping; type Currency = Balances; + type RuntimeEvent = RuntimeEvent; - type Runner = pallet_evm::runner::stack::Runner; - type PrecompilesType = TestPrecompileSet; - type PrecompilesValue = PrecompilesValue; - type Timestamp = Timestamp; + type PrecompilesType = MockPrecompileSet; + type PrecompilesValue = MockPrecompiles; type ChainId = (); - type OnChargeTransaction = (); type BlockGasLimit = (); - type BlockHashMapping = pallet_evm::SubstrateBlockHashMapping; + type Runner = pallet_evm::runner::stack::Runner; + type OnChargeTransaction = (); type OnCreate = (); type FindAuthor = (); + type Timestamp = Timestamp; type WeightInfo = (); } // Configure a mock runtime to test the pallet. construct_runtime!( - pub enum Runtime where + pub enum Test where Block = Block, NodeBlock = Block, UncheckedExtrinsic = UncheckedExtrinsic, { System: frame_system, Balances: pallet_balances, - Evm: pallet_evm, Timestamp: pallet_timestamp, + Evm: pallet_evm, } ); @@ -217,7 +197,7 @@ pub(crate) struct ExtBuilder; impl ExtBuilder { pub(crate) fn build(self) -> sp_io::TestExternalities { let t = frame_system::GenesisConfig::default() - .build_storage::() + .build_storage::() .expect("Frame system builds valid default genesis config"); let mut ext = sp_io::TestExternalities::new(t); @@ -225,3 +205,26 @@ impl ExtBuilder { ext } } + +#[derive(Debug, Clone, Copy)] +pub struct MockPrecompileSet(PhantomData); + +impl PrecompileSet for MockPrecompileSet +where + R: pallet_evm::Config, + ZKGroth16Verify: Precompile, +{ + fn execute(&self, handle: &mut impl PrecompileHandle) -> Option { + match handle.code_address() { + a if a == PRECOMPILE_ADDRESS => Some(ZKGroth16Verify::execute(handle)), + _ => None, + } + } + + fn is_precompile(&self, address: H160, _gas: u64) -> IsPrecompileResult { + IsPrecompileResult::Answer { + is_precompile: address == PRECOMPILE_ADDRESS, + extra_cost: 0, + } + } +} diff --git a/runtime/runtime-common/src/zk_precompile_gas_estimation/mod.rs b/runtime/runtime-common/src/zk_precompile_gas_estimation/mod.rs index 3cd78b2a..62374263 100644 --- a/runtime/runtime-common/src/zk_precompile_gas_estimation/mod.rs +++ b/runtime/runtime-common/src/zk_precompile_gas_estimation/mod.rs @@ -1,4 +1,15 @@ +#![cfg_attr(not(feature = "std"), no_std)] +// #![cfg_attr(feature = "runtime-benchmarks", deny(unused_crate_dependencies))] + +#[cfg(feature = "runtime-benchmarks")] +pub mod benchmarking; +#[cfg(test)] +mod mock; +#[cfg(test)] +mod tests; + pub use pallet::*; + #[frame_support::pallet] pub mod pallet { // use frame_support::{ @@ -31,11 +42,3 @@ pub mod pallet { } } } - -#[cfg(feature = "runtime-benchmarks")] -mod benchmarking; -#[cfg(test)] -mod mock; - -#[cfg(test)] -mod tests; diff --git a/runtime/runtime-common/src/zk_precompile_gas_estimation/tests.rs b/runtime/runtime-common/src/zk_precompile_gas_estimation/tests.rs index f8a9b7aa..8eb00cc1 100644 --- a/runtime/runtime-common/src/zk_precompile_gas_estimation/tests.rs +++ b/runtime/runtime-common/src/zk_precompile_gas_estimation/tests.rs @@ -1,195 +1,251 @@ use crate::zk_precompile_gas_estimation::mock::*; +use fp_evm::GenesisAccount; +use frame_support::{ + assert_ok, + traits::{GenesisBuild, LockIdentifier, LockableCurrency, WithdrawReasons}, +}; +use pallet_evm::GenesisConfig; use pallet_evm_precompile_zk_groth16_verify::Action; -// use precompile_utils::testing::*; -use sp_core::U256; - use precompile_utils::{testing::*, EvmDataWriter}; +use sp_core::{H160, U256}; +use std::{collections::BTreeMap, str::FromStr}; -fn precompiles() -> TestPrecompileSet { - PrecompilesValue::get() +fn precompiles() -> MockPrecompileSet { + MockPrecompiles::get() } -#[test] -fn zk_groth16_verify_work() { - ExtBuilder::default().build().execute_with(|| { - let ( - proof_a, - proof_b, - proof_c, - vk_alpha, - vk_beta, - vk_gamma, - vk_delta, - vk_ic, - valid_input, - _, - ) = generate_test_case_data().unwrap(); +pub fn new_test_ext() -> sp_io::TestExternalities { + let mut t = frame_system::GenesisConfig::default() + .build_storage::() + .unwrap(); + + let mut accounts = BTreeMap::new(); + accounts.insert( + H160::from_str("1000000000000000000000000000000000000001").unwrap(), + GenesisAccount { + nonce: U256::from(1), + balance: U256::from(1000000), + storage: Default::default(), + code: vec![ + 0x00, // STOP + ], + }, + ); + accounts.insert( + H160::from_str("1000000000000000000000000000000000000002").unwrap(), + GenesisAccount { + nonce: U256::from(1), + balance: U256::from(1000000), + storage: Default::default(), + code: vec![ + 0xff, // INVALID + ], + }, + ); + accounts.insert( + H160::default(), // root + GenesisAccount { + nonce: U256::from(1), + balance: U256::max_value(), + storage: Default::default(), + code: vec![], + }, + ); - precompiles() - .prepare_test( - TestAccount::Alice, - PRECOMPILE_ADDRESS, - EvmDataWriter::new_with_selector(Action::Verify) - .write(proof_a) - .write(proof_b) - .write(proof_c) - .write(vk_alpha) - .write(vk_beta) - .write(vk_gamma) - .write(vk_delta) - .write(vk_ic) - .write(valid_input) - .build(), - ) - .expect_no_logs() - .execute_returns(EvmDataWriter::new().write(true).build()); - }) + pallet_balances::GenesisConfig:: { + // Create the block author account with some balance. + balances: vec![( + H160::from_str("0x1234500000000000000000000000000000000000").unwrap(), + 12345, + )], + } + .assimilate_storage(&mut t) + .expect("Pallet balances storage can be assimilated"); + GenesisBuild::::assimilate_storage(&GenesisConfig { accounts }, &mut t).unwrap(); + t.into() } -#[test] -fn zk_groth16_verify_work_with_invalid_proof() { - ExtBuilder::default().build().execute_with(|| { - let ( - proof_a, - proof_b, - proof_c, - vk_alpha, - vk_beta, - vk_gamma, - vk_delta, - vk_ic, - _, - invalid_input, - ) = generate_test_case_data().unwrap(); +// #[test] +// fn zk_groth16_verify_work() { +// ExtBuilder::default().build().execute_with(|| { +// let ( +// proof_a, +// proof_b, +// proof_c, +// vk_alpha, +// vk_beta, +// vk_gamma, +// vk_delta, +// vk_ic, +// valid_input, +// _, +// ) = generate_test_case_data().unwrap(); - precompiles() - .prepare_test( - TestAccount::Alice, - PRECOMPILE_ADDRESS, - EvmDataWriter::new_with_selector(Action::Verify) - .write(proof_a) - .write(proof_b) - .write(proof_c) - .write(vk_alpha) - .write(vk_beta) - .write(vk_gamma) - .write(vk_delta) - .write(vk_ic) - .write(invalid_input) - .build(), - ) - .expect_no_logs() - .execute_returns(EvmDataWriter::new().write(false).build()); - }) -} +// precompiles() +// .prepare_test( +// TestAccount::Alice, +// PRECOMPILE_ADDRESS, +// EvmDataWriter::new_with_selector(Action::Verify) +// .write(proof_a) +// .write(proof_b) +// .write(proof_c) +// .write(vk_alpha) +// .write(vk_beta) +// .write(vk_gamma) +// .write(vk_delta) +// .write(vk_ic) +// .write(valid_input) +// .build(), +// ) +// .expect_no_logs() +// .execute_returns(EvmDataWriter::new().write(true).build()); +// }) +// } -fn generate_test_case_data() -> Result< - ( - (U256, U256), - ((U256, U256), (U256, U256)), - (U256, U256), - (U256, U256), - ((U256, U256), (U256, U256)), - ((U256, U256), (U256, U256)), - ((U256, U256), (U256, U256)), - Vec<(U256, U256)>, - Vec, - Vec, - ), - Box, -> { - let proof_a = decode_g1_point( - "13202079600221154376862161785979680082984660469505374274880948735521253479994", - "19032139815435908179959144311759562497239236177745989139113028703727512477837", - )?; - let proof_b = decode_g2_point( - "9517359327043802798811688827065407805934924568686293993682568334305900037151", - "13975418982386111217378923290980800393212535787789845393400867460398182717751", - "11101434469251848949317000686121782094334155840067455941163819739470030872205", - "3351121397470969456277617123820147601817413346203636355523709813813837616699", - )?; - let proof_c = decode_g1_point( - "21771166379144524714497801611702430117390298454683954881352912868492853507834", - "5971832614272362565584439633663845994795381011258125087840397908182066694531", - )?; +// #[test] +// fn zk_groth16_verify_work_with_invalid_proof() { +// ExtBuilder::default().build().execute_with(|| { +// let ( +// proof_a, +// proof_b, +// proof_c, +// vk_alpha, +// vk_beta, +// vk_gamma, +// vk_delta, +// vk_ic, +// _, +// invalid_input, +// ) = generate_test_case_data().unwrap(); - let vk_alpha = decode_g1_point( - "7318409901911144874440195167086183143676595981815053389579728623121590098440", - "18845965879715444612950452554360629789407129470518446134938217746489723713219", - )?; - let vk_beta = decode_g2_point( - "4640649673239597789758809808535118135578677216672702870175791505196312738305", - "13141288066376351908866878766575256664575916601245245304316354941350328880142", - "11492338667195076401975872253943030431149343004937779351839311477974294172860", - "17604387530215185597479117283681563543587978658046512716245947218617178983155", - )?; - let vk_gamma = decode_g2_point( - "10857046999023057135944570762232829481370756359578518086990519993285655852781", - "11559732032986387107991004021392285783925812861821192530917403151452391805634", - "8495653923123431417604973247489272438418190587263600148770280649306958101930", - "4082367875863433681332203403145435568316851327593401208105741076214120093531", - )?; - let vk_delta = decode_g2_point( - "5882870888685857628232224840789532289346124290586616915986585508513239272539", - "8206718104089392401855946495573733123991363841198873660903571227166120193870", - "14275677868038957349366208693756706908778821863795564855498136614399516409168", - "20950579407520036072561845357324335488555384097745021047033651867265123837403", - )?; - let vk_ic = decode_ic(vec![ - [ - "15329034480187562940265095627808115353397553736992059710948268284574612609224" - .to_string(), - "13272704791638435782238987852007128987814629753205340563304933194747762248428" - .to_string(), - ], - [ - "17269839325091679315052274785558946544729609490743199699197195008879157661695" - .to_string(), - "4142750859697696641705372803120309740931359230261851701215055719438325633654" - .to_string(), - ], - ])?; +// precompiles() +// .prepare_test( +// TestAccount::Alice, +// PRECOMPILE_ADDRESS, +// EvmDataWriter::new_with_selector(Action::Verify) +// .write(proof_a) +// .write(proof_b) +// .write(proof_c) +// .write(vk_alpha) +// .write(vk_beta) +// .write(vk_gamma) +// .write(vk_delta) +// .write(vk_ic) +// .write(invalid_input) +// .build(), +// ) +// .expect_no_logs() +// .execute_returns(EvmDataWriter::new().write(false).build()); +// }) +// } - let valid_input: Vec = vec![U256::from(66)]; - let invalid_input: Vec = vec![U256::from(65)]; +// fn generate_test_case_data() -> Result< +// ( +// (U256, U256), +// ((U256, U256), (U256, U256)), +// (U256, U256), +// (U256, U256), +// ((U256, U256), (U256, U256)), +// ((U256, U256), (U256, U256)), +// ((U256, U256), (U256, U256)), +// Vec<(U256, U256)>, +// Vec, +// Vec, +// ), +// Box, +// > { +// let proof_a = decode_g1_point( +// "13202079600221154376862161785979680082984660469505374274880948735521253479994", +// "19032139815435908179959144311759562497239236177745989139113028703727512477837", +// )?; +// let proof_b = decode_g2_point( +// "9517359327043802798811688827065407805934924568686293993682568334305900037151", +// "13975418982386111217378923290980800393212535787789845393400867460398182717751", +// "11101434469251848949317000686121782094334155840067455941163819739470030872205", +// "3351121397470969456277617123820147601817413346203636355523709813813837616699", +// )?; +// let proof_c = decode_g1_point( +// "21771166379144524714497801611702430117390298454683954881352912868492853507834", +// "5971832614272362565584439633663845994795381011258125087840397908182066694531", +// )?; - Ok(( - proof_a, - proof_b, - proof_c, - vk_alpha, - vk_beta, - vk_gamma, - vk_delta, - vk_ic, - valid_input, - invalid_input, - )) -} +// let vk_alpha = decode_g1_point( +// "7318409901911144874440195167086183143676595981815053389579728623121590098440", +// "18845965879715444612950452554360629789407129470518446134938217746489723713219", +// )?; +// let vk_beta = decode_g2_point( +// "4640649673239597789758809808535118135578677216672702870175791505196312738305", +// "13141288066376351908866878766575256664575916601245245304316354941350328880142", +// "11492338667195076401975872253943030431149343004937779351839311477974294172860", +// "17604387530215185597479117283681563543587978658046512716245947218617178983155", +// )?; +// let vk_gamma = decode_g2_point( +// "10857046999023057135944570762232829481370756359578518086990519993285655852781", +// "11559732032986387107991004021392285783925812861821192530917403151452391805634", +// "8495653923123431417604973247489272438418190587263600148770280649306958101930", +// "4082367875863433681332203403145435568316851327593401208105741076214120093531", +// )?; +// let vk_delta = decode_g2_point( +// "5882870888685857628232224840789532289346124290586616915986585508513239272539", +// "8206718104089392401855946495573733123991363841198873660903571227166120193870", +// "14275677868038957349366208693756706908778821863795564855498136614399516409168", +// "20950579407520036072561845357324335488555384097745021047033651867265123837403", +// )?; +// let vk_ic = decode_ic(vec![ +// [ +// "15329034480187562940265095627808115353397553736992059710948268284574612609224" +// .to_string(), +// "13272704791638435782238987852007128987814629753205340563304933194747762248428" +// .to_string(), +// ], +// [ +// "17269839325091679315052274785558946544729609490743199699197195008879157661695" +// .to_string(), +// "4142750859697696641705372803120309740931359230261851701215055719438325633654" +// .to_string(), +// ], +// ])?; -fn decode_g1_point(x: &str, y: &str) -> Result<(U256, U256), Box> { - Ok((U256::from_dec_str(x)?, U256::from_dec_str(y)?)) -} +// let valid_input: Vec = vec![U256::from(66)]; +// let invalid_input: Vec = vec![U256::from(65)]; -fn decode_g2_point( - x1: &str, - x2: &str, - y1: &str, - y2: &str, -) -> Result<((U256, U256), (U256, U256)), Box> { - Ok(( - (U256::from_dec_str(x1)?, U256::from_dec_str(x2)?), - (U256::from_dec_str(y1)?, U256::from_dec_str(y2)?), - )) -} +// Ok(( +// proof_a, +// proof_b, +// proof_c, +// vk_alpha, +// vk_beta, +// vk_gamma, +// vk_delta, +// vk_ic, +// valid_input, +// invalid_input, +// )) +// } -fn decode_ic(points: Vec<[String; 2]>) -> Result, Box> { - let mut result = Vec::new(); - for point in points { - result.push(( - U256::from_dec_str(&point[0])?, - U256::from_dec_str(&point[1])?, - )); - } - Ok(result) -} +// fn decode_g1_point(x: &str, y: &str) -> Result<(U256, U256), Box> { +// Ok((U256::from_dec_str(x)?, U256::from_dec_str(y)?)) +// } + +// fn decode_g2_point( +// x1: &str, +// x2: &str, +// y1: &str, +// y2: &str, +// ) -> Result<((U256, U256), (U256, U256)), Box> { +// Ok(( +// (U256::from_dec_str(x1)?, U256::from_dec_str(x2)?), +// (U256::from_dec_str(y1)?, U256::from_dec_str(y2)?), +// )) +// } + +// fn decode_ic(points: Vec<[String; 2]>) -> Result, Box> { +// let mut result = Vec::new(); +// for point in points { +// result.push(( +// U256::from_dec_str(&point[0])?, +// U256::from_dec_str(&point[1])?, +// )); +// } +// Ok(result) +// } From babd2ce760aaf451390824fb80dff48291e5a87f Mon Sep 17 00:00:00 2001 From: luckychacha <358140284@qq.com> Date: Thu, 3 Aug 2023 00:36:23 +0800 Subject: [PATCH 09/34] New demo benchmarking and mock is working. --- Cargo.lock | 147 +----------------- runtime/mainnet/src/lib.rs | 11 +- runtime/runtime-common/Cargo.toml | 12 +- .../benchmarking.rs | 15 +- .../src/zk_precompile_gas_estimation/mock.rs | 27 ++-- .../src/zk_precompile_gas_estimation/tests.rs | 7 +- 6 files changed, 44 insertions(+), 175 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8ede5d12..a3a5a1ab 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -559,7 +559,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "88903cb14723e4d4003335bb7f8a14f27691649105346a0f0957466c096adfe6" dependencies = [ "anstyle", - "bstr 1.6.0", + "bstr", "doc-comment", "predicates 3.0.3", "predicates-core", @@ -1020,17 +1020,6 @@ dependencies = [ "sha2 0.9.9", ] -[[package]] -name = "bstr" -version = "0.2.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba3569f383e8f1598449f1a423e72e99569137b47740b1da11ef19af3d5c3223" -dependencies = [ - "lazy_static", - "memchr", - "regex-automata 0.1.10", -] - [[package]] name = "bstr" version = "1.6.0" @@ -1427,18 +1416,6 @@ dependencies = [ "crossbeam-utils", ] -[[package]] -name = "console" -version = "0.15.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c926e00cc70edefdc64d3a5ff31cc65bb97a3460097762bd23afb4d8145fccf8" -dependencies = [ - "encode_unicode", - "lazy_static", - "libc", - "windows-sys 0.45.0", -] - [[package]] name = "const-oid" version = "0.9.4" @@ -2297,12 +2274,6 @@ dependencies = [ "log", ] -[[package]] -name = "encode_unicode" -version = "0.3.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f" - [[package]] name = "encoding_rs" version = "0.8.32" @@ -3881,7 +3852,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1391ab1f92ffcc08911957149833e682aa3fe252b9f45f966d2ef972274c97df" dependencies = [ "aho-corasick", - "bstr 1.6.0", + "bstr", "fnv", "log", "regex", @@ -6391,7 +6362,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f30b0abd723be7e2ffca1272140fac1a2f084c77ec3e123c192b66af1ee9e6c2" dependencies = [ "autocfg", - "libm 0.2.7", ] [[package]] @@ -8187,7 +8157,6 @@ dependencies = [ "parity-scale-codec 3.6.4", "precompile-utils-macro", "sha3 0.10.8", - "similar-asserts", "sp-core", "sp-io", "sp-runtime", @@ -8391,26 +8360,6 @@ dependencies = [ "syn 1.0.109", ] -[[package]] -name = "proptest" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e35c06b98bf36aba164cc17cb25f7e232f5c4aeea73baa14b8a9f0d92dbfa65" -dependencies = [ - "bit-set", - "bitflags 1.3.2", - "byteorder", - "lazy_static", - "num-traits", - "rand 0.8.5", - "rand_chacha 0.3.1", - "rand_xorshift", - "regex-syntax 0.6.29", - "rusty-fork", - "tempfile", - "unarray", -] - [[package]] name = "prost" version = "0.11.9" @@ -8638,15 +8587,6 @@ dependencies = [ "rand_core 0.6.4", ] -[[package]] -name = "rand_xorshift" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d25bf25ec5ae4a3f1b92f929810509a2f53d7dca2f50b794ff57e3face536c8f" -dependencies = [ - "rand_core 0.6.4", -] - [[package]] name = "rawpointer" version = "0.2.1" @@ -9011,7 +8951,6 @@ dependencies = [ name = "runtime-common" version = "0.1.0" dependencies = [ - "derive_more", "fp-account", "fp-evm", "frame-benchmarking", @@ -9036,8 +8975,6 @@ dependencies = [ "pallet-timestamp", "pallet-xvm", "parity-scale-codec 3.6.4", - "precompile-utils", - "proptest", "scale-info", "serde", "sp-core", @@ -9045,7 +8982,6 @@ dependencies = [ "sp-runtime", "sp-staking", "sp-std", - "test-strategy", ] [[package]] @@ -9218,18 +9154,6 @@ version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ffc183a10b4478d04cbbbfc96d0873219d962dd5accaff2ffbd4ceb7df837f4" -[[package]] -name = "rusty-fork" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb3dcc6e454c328bb824492db107ab7c0ae8fcffe4ad210136ef014458c1bc4f" -dependencies = [ - "fnv", - "quick-error", - "tempfile", - "wait-timeout", -] - [[package]] name = "rw-stream-sink" version = "0.3.0" @@ -10962,26 +10886,6 @@ dependencies = [ "wide", ] -[[package]] -name = "similar" -version = "2.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "420acb44afdae038210c99e69aae24109f32f15500aa708e81d46c9f29d55fcf" -dependencies = [ - "bstr 0.2.17", - "unicode-segmentation", -] - -[[package]] -name = "similar-asserts" -version = "1.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbf644ad016b75129f01a34a355dcb8d66a5bc803e417c7a77cc5d5ee9fa0f18" -dependencies = [ - "console", - "similar", -] - [[package]] name = "siphasher" version = "0.3.10" @@ -11894,29 +11798,6 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" -[[package]] -name = "structmeta" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78ad9e09554f0456d67a69c1584c9798ba733a5b50349a6c0d0948710523922d" -dependencies = [ - "proc-macro2", - "quote", - "structmeta-derive", - "syn 2.0.27", -] - -[[package]] -name = "structmeta-derive" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a60bcaff7397072dca0017d1db428e30d5002e00b6847703e2e42005c95fbe00" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.27", -] - [[package]] name = "strum" version = "0.24.1" @@ -12324,18 +12205,6 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3369f5ac52d5eb6ab48c6b4ffdc8efbcad6b89c765749064ba298f2c68a16a76" -[[package]] -name = "test-strategy" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8361c808554228ad09bfed70f5c823caf8a3450b6881cc3a38eb57e8c08c1d9" -dependencies = [ - "proc-macro2", - "quote", - "structmeta", - "syn 2.0.27", -] - [[package]] name = "thiserror" version = "1.0.44" @@ -12939,12 +12808,6 @@ dependencies = [ "static_assertions", ] -[[package]] -name = "unarray" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eaea85b334db583fe3274d12b4cd1880032beab409c0d774be044d4480ab9a94" - [[package]] name = "unicode-bidi" version = "0.3.13" @@ -12966,12 +12829,6 @@ dependencies = [ "tinyvec", ] -[[package]] -name = "unicode-segmentation" -version = "1.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" - [[package]] name = "unicode-width" version = "0.1.10" diff --git a/runtime/mainnet/src/lib.rs b/runtime/mainnet/src/lib.rs index f2c2cb45..721329d2 100644 --- a/runtime/mainnet/src/lib.rs +++ b/runtime/mainnet/src/lib.rs @@ -569,10 +569,11 @@ extern crate frame_benchmarking; #[cfg(feature = "runtime-benchmarks")] mod benches { define_benchmarks!( - [pallet_evm, EVM] // [ - // zk_precompile_gas_estimation, - // ZKPrecompileGasEstimation - // ] + [pallet_evm, EVM] + [ + zk_precompile_gas_estimation, + ZKPrecompileGasEstimation + ] ); } @@ -939,7 +940,7 @@ impl_runtime_apis! { add_benchmark!(params, batches, pallet_evm, PalletEvmBench::); add_benchmark!(params, batches, pallet_hotfix_sufficients, PalletHotfixSufficients::); - // add_benchmark!(params, batches, zk_precompile_gas_estimation, ZKPrecompileGasEstimation); + add_benchmark!(params, batches, zk_precompile_gas_estimation, ZKPrecompileGasEstimation); if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) } Ok(batches) diff --git a/runtime/runtime-common/Cargo.toml b/runtime/runtime-common/Cargo.toml index 12b6e48c..52203e59 100644 --- a/runtime/runtime-common/Cargo.toml +++ b/runtime/runtime-common/Cargo.toml @@ -40,17 +40,17 @@ pallet-xvm = { workspace = true, optional = true } log.workspace = true [dev-dependencies] -derive_more.workspace = true +# derive_more.workspace = true fp-account.workspace = true fp-evm.workspace = true pallet-balances.workspace = true pallet-timestamp.workspace = true -proptest.workspace = true +# proptest.workspace = true sp-io.workspace = true -test-strategy.workspace = true +# test-strategy.workspace = true # Astar -precompile-utils = { workspace = true, features = ["testing"] } +# precompile-utils = { workspace = true, features = ["testing"] } [features] default = ["std"] @@ -80,6 +80,7 @@ std = [ "sp-core/std", "sp-staking/std", "sp-std/std", + "frame-benchmarking/std", "pallet-contracts?/std", "pallet-evm?/std", @@ -97,4 +98,7 @@ std = [ "pallet-xvm?/std", ] runtime-benchmarks = [ + "frame-benchmarking/runtime-benchmarks", + "frame-support/runtime-benchmarks", + "frame-system/runtime-benchmarks", ] diff --git a/runtime/runtime-common/src/zk_precompile_gas_estimation/benchmarking.rs b/runtime/runtime-common/src/zk_precompile_gas_estimation/benchmarking.rs index 565426e8..ddb05ca6 100644 --- a/runtime/runtime-common/src/zk_precompile_gas_estimation/benchmarking.rs +++ b/runtime/runtime-common/src/zk_precompile_gas_estimation/benchmarking.rs @@ -3,4 +3,17 @@ use super::*; use frame_benchmarking::{benchmarks, impl_benchmark_test_suite}; -type CurrencyOf = ::Currency; +// type CurrencyOf = ::Currency; +benchmarks! { + demo_runner { + let x in 1..10000000; + let mut nonce: u64 = 1; + }:{ + nonce += 1; + } +} +impl_benchmark_test_suite!( + Pallet, + crate::zk_precompile_gas_estimation::tests::new_test_ext(), + crate::zk_precompile_gas_estimation::mock::Test +); diff --git a/runtime/runtime-common/src/zk_precompile_gas_estimation/mock.rs b/runtime/runtime-common/src/zk_precompile_gas_estimation/mock.rs index 7375c98a..5785d94b 100644 --- a/runtime/runtime-common/src/zk_precompile_gas_estimation/mock.rs +++ b/runtime/runtime-common/src/zk_precompile_gas_estimation/mock.rs @@ -27,8 +27,7 @@ pub type BlockNumber = u64; pub type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; pub type Block = frame_system::mocking::MockBlock; -pub const PRECOMPILE_ADDRESS: H160 = H160::repeat_byte(0xBB); - +pub const PRECOMPILE_ADDRESS: H160 = H160::from_low_u64_be(0x8888); // #[derive( // Eq, // PartialEq, @@ -191,20 +190,20 @@ construct_runtime!( } ); -#[derive(Default)] -pub(crate) struct ExtBuilder; +// #[derive(Default)] +// pub(crate) struct ExtBuilder; -impl ExtBuilder { - pub(crate) fn build(self) -> sp_io::TestExternalities { - let t = frame_system::GenesisConfig::default() - .build_storage::() - .expect("Frame system builds valid default genesis config"); +// impl ExtBuilder { +// pub(crate) fn build(self) -> sp_io::TestExternalities { +// let t = frame_system::GenesisConfig::default() +// .build_storage::() +// .expect("Frame system builds valid default genesis config"); - let mut ext = sp_io::TestExternalities::new(t); - ext.execute_with(|| System::set_block_number(1)); - ext - } -} +// let mut ext = sp_io::TestExternalities::new(t); +// ext.execute_with(|| System::set_block_number(1)); +// ext +// } +// } #[derive(Debug, Clone, Copy)] pub struct MockPrecompileSet(PhantomData); diff --git a/runtime/runtime-common/src/zk_precompile_gas_estimation/tests.rs b/runtime/runtime-common/src/zk_precompile_gas_estimation/tests.rs index 8eb00cc1..0bb45158 100644 --- a/runtime/runtime-common/src/zk_precompile_gas_estimation/tests.rs +++ b/runtime/runtime-common/src/zk_precompile_gas_estimation/tests.rs @@ -1,12 +1,7 @@ use crate::zk_precompile_gas_estimation::mock::*; use fp_evm::GenesisAccount; -use frame_support::{ - assert_ok, - traits::{GenesisBuild, LockIdentifier, LockableCurrency, WithdrawReasons}, -}; +use frame_support::traits::GenesisBuild; use pallet_evm::GenesisConfig; -use pallet_evm_precompile_zk_groth16_verify::Action; -use precompile_utils::{testing::*, EvmDataWriter}; use sp_core::{H160, U256}; use std::{collections::BTreeMap, str::FromStr}; From 59905eb4a3f93f3041d45f4c7d00864ea5084eb6 Mon Sep 17 00:00:00 2001 From: luckychacha <358140284@qq.com> Date: Thu, 3 Aug 2023 18:35:47 +0800 Subject: [PATCH 10/34] Test benchmarking. --- Cargo.lock | 86 +++++ Cargo.toml | 3 + runtime/runtime-common/Cargo.toml | 11 +- .../benchmarking.rs | 149 +++++++- .../src/zk_precompile_gas_estimation/mock.rs | 26 +- .../src/zk_precompile_gas_estimation/mod.rs | 20 +- .../src/zk_precompile_gas_estimation/tests.rs | 318 +++++++----------- 7 files changed, 381 insertions(+), 232 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a3a5a1ab..61681623 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6362,6 +6362,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f30b0abd723be7e2ffca1272140fac1a2f084c77ec3e123c192b66af1ee9e6c2" dependencies = [ "autocfg", + "libm 0.2.7", ] [[package]] @@ -8360,6 +8361,26 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "proptest" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e35c06b98bf36aba164cc17cb25f7e232f5c4aeea73baa14b8a9f0d92dbfa65" +dependencies = [ + "bit-set", + "bitflags 1.3.2", + "byteorder", + "lazy_static", + "num-traits", + "rand 0.8.5", + "rand_chacha 0.3.1", + "rand_xorshift", + "regex-syntax 0.6.29", + "rusty-fork", + "tempfile", + "unarray", +] + [[package]] name = "prost" version = "0.11.9" @@ -8587,6 +8608,15 @@ dependencies = [ "rand_core 0.6.4", ] +[[package]] +name = "rand_xorshift" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d25bf25ec5ae4a3f1b92f929810509a2f53d7dca2f50b794ff57e3face536c8f" +dependencies = [ + "rand_core 0.6.4", +] + [[package]] name = "rawpointer" version = "0.2.1" @@ -8951,6 +8981,7 @@ dependencies = [ name = "runtime-common" version = "0.1.0" dependencies = [ + "ethabi 18.0.0", "fp-account", "fp-evm", "frame-benchmarking", @@ -8975,6 +9006,7 @@ dependencies = [ "pallet-timestamp", "pallet-xvm", "parity-scale-codec 3.6.4", + "proptest", "scale-info", "serde", "sp-core", @@ -8982,6 +9014,7 @@ dependencies = [ "sp-runtime", "sp-staking", "sp-std", + "test-strategy", ] [[package]] @@ -9154,6 +9187,18 @@ version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ffc183a10b4478d04cbbbfc96d0873219d962dd5accaff2ffbd4ceb7df837f4" +[[package]] +name = "rusty-fork" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb3dcc6e454c328bb824492db107ab7c0ae8fcffe4ad210136ef014458c1bc4f" +dependencies = [ + "fnv", + "quick-error", + "tempfile", + "wait-timeout", +] + [[package]] name = "rw-stream-sink" version = "0.3.0" @@ -11798,6 +11843,29 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" +[[package]] +name = "structmeta" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ad9e09554f0456d67a69c1584c9798ba733a5b50349a6c0d0948710523922d" +dependencies = [ + "proc-macro2", + "quote", + "structmeta-derive", + "syn 2.0.27", +] + +[[package]] +name = "structmeta-derive" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a60bcaff7397072dca0017d1db428e30d5002e00b6847703e2e42005c95fbe00" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.27", +] + [[package]] name = "strum" version = "0.24.1" @@ -12205,6 +12273,18 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3369f5ac52d5eb6ab48c6b4ffdc8efbcad6b89c765749064ba298f2c68a16a76" +[[package]] +name = "test-strategy" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8361c808554228ad09bfed70f5c823caf8a3450b6881cc3a38eb57e8c08c1d9" +dependencies = [ + "proc-macro2", + "quote", + "structmeta", + "syn 2.0.27", +] + [[package]] name = "thiserror" version = "1.0.44" @@ -12808,6 +12888,12 @@ dependencies = [ "static_assertions", ] +[[package]] +name = "unarray" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eaea85b334db583fe3274d12b4cd1880032beab409c0d774be044d4480ab9a94" + [[package]] name = "unicode-bidi" version = "0.3.13" diff --git a/Cargo.toml b/Cargo.toml index 329b9aaa..507c767b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -211,7 +211,10 @@ pallet-ics20-transfer = { default-features = false, git = "https://github.com/ib prost = { version = "0.11", default-features = false } # zk precompile +ethabi = { version = "18.0.0", default-features = false } num-bigint = { version = "0.4", default-features = false, features = ["rand"] } +rlp = { version = "0.5.2", default-features = false } + # zksnark ark-bn254 = { version = "0.4.0" } ark-crypto-primitives = { version = "0.4.0", default-features = false } diff --git a/runtime/runtime-common/Cargo.toml b/runtime/runtime-common/Cargo.toml index 52203e59..6688cc83 100644 --- a/runtime/runtime-common/Cargo.toml +++ b/runtime/runtime-common/Cargo.toml @@ -17,6 +17,7 @@ frame-support.workspace = true frame-system.workspace = true pallet-session = { workspace = true, features = ["historical"] } sp-core.workspace = true +sp-io.workspace = true sp-runtime.workspace = true sp-staking.workspace = true sp-std.workspace = true @@ -36,8 +37,10 @@ pallet-evm-precompile-xvm = { workspace = true, optional = true } pallet-evm-precompile-zk-groth16-verify = { workspace = true, optional = true } pallet-xvm = { workspace = true, optional = true } -# eth abi log.workspace = true +# zk groth16 precompile gas estimation +ethabi.workspace = true +# rlp.workspace = true [dev-dependencies] # derive_more.workspace = true @@ -45,9 +48,8 @@ fp-account.workspace = true fp-evm.workspace = true pallet-balances.workspace = true pallet-timestamp.workspace = true -# proptest.workspace = true -sp-io.workspace = true -# test-strategy.workspace = true +proptest.workspace = true +test-strategy.workspace = true # Astar # precompile-utils = { workspace = true, features = ["testing"] } @@ -81,6 +83,7 @@ std = [ "sp-staking/std", "sp-std/std", "frame-benchmarking/std", + # "rlp/std", "pallet-contracts?/std", "pallet-evm?/std", diff --git a/runtime/runtime-common/src/zk_precompile_gas_estimation/benchmarking.rs b/runtime/runtime-common/src/zk_precompile_gas_estimation/benchmarking.rs index ddb05ca6..f8cd07f0 100644 --- a/runtime/runtime-common/src/zk_precompile_gas_estimation/benchmarking.rs +++ b/runtime/runtime-common/src/zk_precompile_gas_estimation/benchmarking.rs @@ -1,15 +1,154 @@ -#![cfg(feature = "runtime-benchmarks")] +// #![cfg(feature = "runtime-benchmarks")] use super::*; use frame_benchmarking::{benchmarks, impl_benchmark_test_suite}; +// frontier +use pallet_evm::Runner; +use sp_std::prelude::*; -// type CurrencyOf = ::Currency; benchmarks! { demo_runner { - let x in 1..10000000; - let mut nonce: u64 = 1; + use frame_benchmarking::vec; + use sp_core::{H160, U256}; + use ethabi::Token; + + let caller = "1000000000000000000000000000000000000001".parse::().unwrap(); + + let contract_address = H160::from_low_u64_be(0x8888); + + let proof_a = vec![ + U256::from_dec_str("13202079600221154376862161785979680082984660469505374274880948735521253479994").unwrap(), + U256::from_dec_str("19032139815435908179959144311759562497239236177745989139113028703727512477837").unwrap() + ]; + + let proof_b = vec![ + vec![ + U256::from_dec_str("9517359327043802798811688827065407805934924568686293993682568334305900037151").unwrap(), + U256::from_dec_str("13975418982386111217378923290980800393212535787789845393400867460398182717751").unwrap() + ], + vec![ + U256::from_dec_str("11101434469251848949317000686121782094334155840067455941163819739470030872205").unwrap(), + U256::from_dec_str("3351121397470969456277617123820147601817413346203636355523709813813837616699").unwrap() + ], + ]; + + let proof_c = vec![ + U256::from_dec_str("21771166379144524714497801611702430117390298454683954881352912868492853507834").unwrap(), + U256::from_dec_str("5971832614272362565584439633663845994795381011258125087840397908182066694531").unwrap() + ]; + + let vk_alpha = vec![ + U256::from_dec_str("7318409901911144874440195167086183143676595981815053389579728623121590098440").unwrap(), + U256::from_dec_str("18845965879715444612950452554360629789407129470518446134938217746489723713219").unwrap() + ]; + + let vk_beta = vec![ + vec![ + U256::from_dec_str("4640649673239597789758809808535118135578677216672702870175791505196312738305").unwrap(), + U256::from_dec_str("13141288066376351908866878766575256664575916601245245304316354941350328880142").unwrap() + ], + vec![ + U256::from_dec_str("11492338667195076401975872253943030431149343004937779351839311477974294172860").unwrap(), + U256::from_dec_str("17604387530215185597479117283681563543587978658046512716245947218617178983155").unwrap() + ], + ]; + + let vk_gamma = vec![ + vec![ + U256::from_dec_str("10857046999023057135944570762232829481370756359578518086990519993285655852781").unwrap(), + U256::from_dec_str("11559732032986387107991004021392285783925812861821192530917403151452391805634").unwrap() + ], + vec![ + U256::from_dec_str("8495653923123431417604973247489272438418190587263600148770280649306958101930").unwrap(), + U256::from_dec_str("4082367875863433681332203403145435568316851327593401208105741076214120093531").unwrap() + ], + ]; + + let vk_delta = vec![ + vec![ + U256::from_dec_str("5882870888685857628232224840789532289346124290586616915986585508513239272539").unwrap(), + U256::from_dec_str("8206718104089392401855946495573733123991363841198873660903571227166120193870").unwrap() + ], + vec![ + U256::from_dec_str("14275677868038957349366208693756706908778821863795564855498136614399516409168").unwrap(), + U256::from_dec_str("20950579407520036072561845357324335488555384097745021047033651867265123837403").unwrap() + ] + ]; + + let vk_ic = vec![ + vec![ + U256::from_dec_str("15329034480187562940265095627808115353397553736992059710948268284574612609224").unwrap(), + U256::from_dec_str("13272704791638435782238987852007128987814629753205340563304933194747762248428").unwrap() + ], + vec![ + U256::from_dec_str("17269839325091679315052274785558946544729609490743199699197195008879157661695").unwrap(), + U256::from_dec_str("4142750859697696641705372803120309740931359230261851701215055719438325633654").unwrap() + ] + ]; + + let valid_input = vec![U256::from(66)]; + let mut encoded_call = vec![0u8; 4]; + encoded_call[0..4].copy_from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..4]); + + // append parameters to the encoded call + encoded_call.extend(ethabi::encode(&[ + Token::Array(proof_a.into_iter().map(Token::Uint).collect()), + Token::Array(proof_b.into_iter().map(|b| Token::Array(b.into_iter().map(Token::Uint).collect())).collect()), + Token::Array(proof_c.into_iter().map(Token::Uint).collect()), + Token::Array(vk_alpha.into_iter().map(Token::Uint).collect()), + Token::Array(vk_beta.into_iter().map(|b| Token::Array(b.into_iter().map(Token::Uint).collect())).collect()), + Token::Array(vk_gamma.into_iter().map(|b| Token::Array(b.into_iter().map(Token::Uint).collect())).collect()), + Token::Array(vk_delta.into_iter().map(|b| Token::Array(b.into_iter().map(Token::Uint).collect())).collect()), + Token::Array(vk_ic.into_iter().map(|ic| Token::Array(ic.into_iter().map(Token::Uint).collect())).collect()), + Token::Array(valid_input.into_iter().map(Token::Uint).collect()), + ])); + let gas_limit_call = 1000000; + }:{ - nonce += 1; + let value = U256::default(); + let is_transactional = true; + let validate = true; + let call_runner_results = ::Runner::call( + caller, + contract_address, + encoded_call, + value, + gas_limit_call, + Some(U256::from(1_000_000_000)), + Some(U256::from(1_000_000_000)), + None, + Vec::new(), + is_transactional, + validate, + ::config(), + ); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "call_runner_results:{:?}", + // call_runner_results + // ); + assert!(call_runner_results.is_ok(), "call() failed"); + + // let output = info.value; + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "output result {:?}", + // output + // ); + // if output.len() >= 32 { + // let mut result_bytes = [0u8; 32]; + // result_bytes.copy_from_slice(&output[output.len() - 32..]); + // let result = U256::from_big_endian(&result_bytes); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "Verification result {:?}", + // result + // ); + // assert_eq!(result, U256::one(), "The contract did not return true"); + // } + // } else { + + // } } } impl_benchmark_test_suite!( diff --git a/runtime/runtime-common/src/zk_precompile_gas_estimation/mock.rs b/runtime/runtime-common/src/zk_precompile_gas_estimation/mock.rs index 5785d94b..5976b150 100644 --- a/runtime/runtime-common/src/zk_precompile_gas_estimation/mock.rs +++ b/runtime/runtime-common/src/zk_precompile_gas_estimation/mock.rs @@ -1,17 +1,13 @@ use fp_evm::{IsPrecompileResult, PrecompileHandle}; -use frame_support::{construct_runtime, parameter_types, traits::Everything, weights::Weight}; +use frame_support::{construct_runtime, parameter_types, weights::Weight}; use pallet_evm::{ - AddressMapping, EnsureAddressNever, EnsureAddressRoot, IdentityAddressMapping, Precompile, - PrecompileResult, PrecompileSet, + EnsureAddressNever, EnsureAddressRoot, IdentityAddressMapping, Precompile, PrecompileResult, + PrecompileSet, }; use pallet_evm_precompile_zk_groth16_verify::ZKGroth16Verify; -use scale_codec::{Decode, Encode, MaxEncodedLen}; -use scale_info::TypeInfo; -use serde::{Deserialize, Serialize}; -use sp_core::{ConstU32, H160, H256}; +use sp_core::{ConstU32, H160, H256, U256}; use sp_runtime::{ generic, - testing::Header, traits::{BlakeTwo256, IdentityLookup}, }; use sp_std::marker::PhantomData; @@ -19,15 +15,14 @@ use sp_std::marker::PhantomData; /// Constant values used within the runtime. pub const MILLIGGX: Balance = 1_000_000_000_000_000; pub const GGX: Balance = 1000 * MILLIGGX; -pub const EXISTENTIAL_DEPOSIT: Balance = GGX; +pub const EXISTENTIAL_DEPOSIT: Balance = 0; pub type AccountId = H160; pub type Balance = u64; -pub type BlockNumber = u64; pub type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; pub type Block = frame_system::mocking::MockBlock; -pub const PRECOMPILE_ADDRESS: H160 = H160::from_low_u64_be(0x8888); +// pub const PRECOMPILE_ADDRESS: H160 = H160::from_low_u64_be(0x8888); // #[derive( // Eq, // PartialEq, @@ -144,11 +139,13 @@ impl pallet_balances::Config for Test { type MaxLocks = (); type MaxReserves = (); } +const BLOCK_GAS_LIMIT: u64 = 150_000_000; parameter_types! { pub const MockPrecompiles: MockPrecompileSet = MockPrecompileSet(PhantomData); pub const WeightPerGas: Weight = Weight::from_parts(1, 0); + pub BlockGasLimit: U256 = U256::from(BLOCK_GAS_LIMIT); } impl pallet_evm::Config for Test { @@ -167,7 +164,7 @@ impl pallet_evm::Config for Test { type PrecompilesType = MockPrecompileSet; type PrecompilesValue = MockPrecompiles; type ChainId = (); - type BlockGasLimit = (); + type BlockGasLimit = BlockGasLimit; type Runner = pallet_evm::runner::stack::Runner; type OnChargeTransaction = (); type OnCreate = (); @@ -214,15 +211,16 @@ where ZKGroth16Verify: Precompile, { fn execute(&self, handle: &mut impl PrecompileHandle) -> Option { + println!("aaa: {}", handle.code_address()); match handle.code_address() { - a if a == PRECOMPILE_ADDRESS => Some(ZKGroth16Verify::execute(handle)), + a if a == H160::from_low_u64_be(0x8888) => Some(ZKGroth16Verify::execute(handle)), _ => None, } } fn is_precompile(&self, address: H160, _gas: u64) -> IsPrecompileResult { IsPrecompileResult::Answer { - is_precompile: address == PRECOMPILE_ADDRESS, + is_precompile: address == H160::from_low_u64_be(0x8888), extra_cost: 0, } } diff --git a/runtime/runtime-common/src/zk_precompile_gas_estimation/mod.rs b/runtime/runtime-common/src/zk_precompile_gas_estimation/mod.rs index 62374263..60a1ae41 100644 --- a/runtime/runtime-common/src/zk_precompile_gas_estimation/mod.rs +++ b/runtime/runtime-common/src/zk_precompile_gas_estimation/mod.rs @@ -12,33 +12,17 @@ pub use pallet::*; #[frame_support::pallet] pub mod pallet { - // use frame_support::{ - // pallet_prelude::*, sp_runtime::traits::AtLeast32BitUnsigned, sp_std::fmt::Debug, - // }; - // use frame_system::pallet_prelude::*; - #[pallet::pallet] #[pallet::without_storage_info] pub struct Pallet(_); - // 3. Runtime Configuration Trait #[pallet::config] - pub trait Config: frame_system::Config { - // type Event: From> + IsType<::Event>; - } + pub trait Config: frame_system::Config + pallet_evm::Config {} // 8. Runtime Errors #[pallet::error] pub enum Error {} - // 7. Extrinsics // Functions that are callable from outside the runtime. - impl Pallet { - pub fn do_some_work(i: u32) { - let mut i = i; - while i < 100000000 { - i += 1; - } - } - } + impl Pallet {} } diff --git a/runtime/runtime-common/src/zk_precompile_gas_estimation/tests.rs b/runtime/runtime-common/src/zk_precompile_gas_estimation/tests.rs index 0bb45158..4832ff87 100644 --- a/runtime/runtime-common/src/zk_precompile_gas_estimation/tests.rs +++ b/runtime/runtime-common/src/zk_precompile_gas_estimation/tests.rs @@ -1,14 +1,11 @@ use crate::zk_precompile_gas_estimation::mock::*; +use ethabi::Token; use fp_evm::GenesisAccount; use frame_support::traits::GenesisBuild; -use pallet_evm::GenesisConfig; +use pallet_evm::{GenesisConfig, Runner}; use sp_core::{H160, U256}; use std::{collections::BTreeMap, str::FromStr}; -fn precompiles() -> MockPrecompileSet { - MockPrecompiles::get() -} - pub fn new_test_ext() -> sp_io::TestExternalities { let mut t = frame_system::GenesisConfig::default() .build_storage::() @@ -19,7 +16,7 @@ pub fn new_test_ext() -> sp_io::TestExternalities { H160::from_str("1000000000000000000000000000000000000001").unwrap(), GenesisAccount { nonce: U256::from(1), - balance: U256::from(1000000), + balance: U256::max_value(), storage: Default::default(), code: vec![ 0x00, // STOP @@ -30,7 +27,7 @@ pub fn new_test_ext() -> sp_io::TestExternalities { H160::from_str("1000000000000000000000000000000000000002").unwrap(), GenesisAccount { nonce: U256::from(1), - balance: U256::from(1000000), + balance: U256::max_value(), storage: Default::default(), code: vec![ 0xff, // INVALID @@ -60,187 +57,126 @@ pub fn new_test_ext() -> sp_io::TestExternalities { t.into() } -// #[test] -// fn zk_groth16_verify_work() { -// ExtBuilder::default().build().execute_with(|| { -// let ( -// proof_a, -// proof_b, -// proof_c, -// vk_alpha, -// vk_beta, -// vk_gamma, -// vk_delta, -// vk_ic, -// valid_input, -// _, -// ) = generate_test_case_data().unwrap(); - -// precompiles() -// .prepare_test( -// TestAccount::Alice, -// PRECOMPILE_ADDRESS, -// EvmDataWriter::new_with_selector(Action::Verify) -// .write(proof_a) -// .write(proof_b) -// .write(proof_c) -// .write(vk_alpha) -// .write(vk_beta) -// .write(vk_gamma) -// .write(vk_delta) -// .write(vk_ic) -// .write(valid_input) -// .build(), -// ) -// .expect_no_logs() -// .execute_returns(EvmDataWriter::new().write(true).build()); -// }) -// } - -// #[test] -// fn zk_groth16_verify_work_with_invalid_proof() { -// ExtBuilder::default().build().execute_with(|| { -// let ( -// proof_a, -// proof_b, -// proof_c, -// vk_alpha, -// vk_beta, -// vk_gamma, -// vk_delta, -// vk_ic, -// _, -// invalid_input, -// ) = generate_test_case_data().unwrap(); - -// precompiles() -// .prepare_test( -// TestAccount::Alice, -// PRECOMPILE_ADDRESS, -// EvmDataWriter::new_with_selector(Action::Verify) -// .write(proof_a) -// .write(proof_b) -// .write(proof_c) -// .write(vk_alpha) -// .write(vk_beta) -// .write(vk_gamma) -// .write(vk_delta) -// .write(vk_ic) -// .write(invalid_input) -// .build(), -// ) -// .expect_no_logs() -// .execute_returns(EvmDataWriter::new().write(false).build()); -// }) -// } - -// fn generate_test_case_data() -> Result< -// ( -// (U256, U256), -// ((U256, U256), (U256, U256)), -// (U256, U256), -// (U256, U256), -// ((U256, U256), (U256, U256)), -// ((U256, U256), (U256, U256)), -// ((U256, U256), (U256, U256)), -// Vec<(U256, U256)>, -// Vec, -// Vec, -// ), -// Box, -// > { -// let proof_a = decode_g1_point( -// "13202079600221154376862161785979680082984660469505374274880948735521253479994", -// "19032139815435908179959144311759562497239236177745989139113028703727512477837", -// )?; -// let proof_b = decode_g2_point( -// "9517359327043802798811688827065407805934924568686293993682568334305900037151", -// "13975418982386111217378923290980800393212535787789845393400867460398182717751", -// "11101434469251848949317000686121782094334155840067455941163819739470030872205", -// "3351121397470969456277617123820147601817413346203636355523709813813837616699", -// )?; -// let proof_c = decode_g1_point( -// "21771166379144524714497801611702430117390298454683954881352912868492853507834", -// "5971832614272362565584439633663845994795381011258125087840397908182066694531", -// )?; - -// let vk_alpha = decode_g1_point( -// "7318409901911144874440195167086183143676595981815053389579728623121590098440", -// "18845965879715444612950452554360629789407129470518446134938217746489723713219", -// )?; -// let vk_beta = decode_g2_point( -// "4640649673239597789758809808535118135578677216672702870175791505196312738305", -// "13141288066376351908866878766575256664575916601245245304316354941350328880142", -// "11492338667195076401975872253943030431149343004937779351839311477974294172860", -// "17604387530215185597479117283681563543587978658046512716245947218617178983155", -// )?; -// let vk_gamma = decode_g2_point( -// "10857046999023057135944570762232829481370756359578518086990519993285655852781", -// "11559732032986387107991004021392285783925812861821192530917403151452391805634", -// "8495653923123431417604973247489272438418190587263600148770280649306958101930", -// "4082367875863433681332203403145435568316851327593401208105741076214120093531", -// )?; -// let vk_delta = decode_g2_point( -// "5882870888685857628232224840789532289346124290586616915986585508513239272539", -// "8206718104089392401855946495573733123991363841198873660903571227166120193870", -// "14275677868038957349366208693756706908778821863795564855498136614399516409168", -// "20950579407520036072561845357324335488555384097745021047033651867265123837403", -// )?; -// let vk_ic = decode_ic(vec![ -// [ -// "15329034480187562940265095627808115353397553736992059710948268284574612609224" -// .to_string(), -// "13272704791638435782238987852007128987814629753205340563304933194747762248428" -// .to_string(), -// ], -// [ -// "17269839325091679315052274785558946544729609490743199699197195008879157661695" -// .to_string(), -// "4142750859697696641705372803120309740931359230261851701215055719438325633654" -// .to_string(), -// ], -// ])?; - -// let valid_input: Vec = vec![U256::from(66)]; -// let invalid_input: Vec = vec![U256::from(65)]; - -// Ok(( -// proof_a, -// proof_b, -// proof_c, -// vk_alpha, -// vk_beta, -// vk_gamma, -// vk_delta, -// vk_ic, -// valid_input, -// invalid_input, -// )) -// } - -// fn decode_g1_point(x: &str, y: &str) -> Result<(U256, U256), Box> { -// Ok((U256::from_dec_str(x)?, U256::from_dec_str(y)?)) -// } - -// fn decode_g2_point( -// x1: &str, -// x2: &str, -// y1: &str, -// y2: &str, -// ) -> Result<((U256, U256), (U256, U256)), Box> { -// Ok(( -// (U256::from_dec_str(x1)?, U256::from_dec_str(x2)?), -// (U256::from_dec_str(y1)?, U256::from_dec_str(y2)?), -// )) -// } - -// fn decode_ic(points: Vec<[String; 2]>) -> Result, Box> { -// let mut result = Vec::new(); -// for point in points { -// result.push(( -// U256::from_dec_str(&point[0])?, -// U256::from_dec_str(&point[1])?, -// )); -// } -// Ok(result) -// } +#[test] +fn test_zk_precompile_gas_estimation() { + println!("start"); + new_test_ext().execute_with(|| { + println!("execute"); + + let caller = "1000000000000000000000000000000000000001".parse::().unwrap(); + + let contract_address = H160::from_low_u64_be(0x8888); + + let proof_a = vec![ + U256::from_dec_str("13202079600221154376862161785979680082984660469505374274880948735521253479994").unwrap(), + U256::from_dec_str("19032139815435908179959144311759562497239236177745989139113028703727512477837").unwrap() + ]; + + let proof_b = vec![ + vec![ + U256::from_dec_str("9517359327043802798811688827065407805934924568686293993682568334305900037151").unwrap(), + U256::from_dec_str("13975418982386111217378923290980800393212535787789845393400867460398182717751").unwrap() + ], + vec![ + U256::from_dec_str("11101434469251848949317000686121782094334155840067455941163819739470030872205").unwrap(), + U256::from_dec_str("3351121397470969456277617123820147601817413346203636355523709813813837616699").unwrap() + ], + ]; + + let proof_c = vec![ + U256::from_dec_str("21771166379144524714497801611702430117390298454683954881352912868492853507834").unwrap(), + U256::from_dec_str("5971832614272362565584439633663845994795381011258125087840397908182066694531").unwrap() + ]; + + let vk_alpha = vec![ + U256::from_dec_str("7318409901911144874440195167086183143676595981815053389579728623121590098440").unwrap(), + U256::from_dec_str("18845965879715444612950452554360629789407129470518446134938217746489723713219").unwrap() + ]; + + let vk_beta = vec![ + vec![ + U256::from_dec_str("4640649673239597789758809808535118135578677216672702870175791505196312738305").unwrap(), + U256::from_dec_str("13141288066376351908866878766575256664575916601245245304316354941350328880142").unwrap() + ], + vec![ + U256::from_dec_str("11492338667195076401975872253943030431149343004937779351839311477974294172860").unwrap(), + U256::from_dec_str("17604387530215185597479117283681563543587978658046512716245947218617178983155").unwrap() + ], + ]; + + let vk_gamma = vec![ + vec![ + U256::from_dec_str("10857046999023057135944570762232829481370756359578518086990519993285655852781").unwrap(), + U256::from_dec_str("11559732032986387107991004021392285783925812861821192530917403151452391805634").unwrap() + ], + vec![ + U256::from_dec_str("8495653923123431417604973247489272438418190587263600148770280649306958101930").unwrap(), + U256::from_dec_str("4082367875863433681332203403145435568316851327593401208105741076214120093531").unwrap() + ], + ]; + + let vk_delta = vec![ + vec![ + U256::from_dec_str("5882870888685857628232224840789532289346124290586616915986585508513239272539").unwrap(), + U256::from_dec_str("8206718104089392401855946495573733123991363841198873660903571227166120193870").unwrap() + ], + vec![ + U256::from_dec_str("14275677868038957349366208693756706908778821863795564855498136614399516409168").unwrap(), + U256::from_dec_str("20950579407520036072561845357324335488555384097745021047033651867265123837403").unwrap() + ] + ]; + + let vk_ic = vec![ + vec![ + U256::from_dec_str("15329034480187562940265095627808115353397553736992059710948268284574612609224").unwrap(), + U256::from_dec_str("13272704791638435782238987852007128987814629753205340563304933194747762248428").unwrap() + ], + vec![ + U256::from_dec_str("17269839325091679315052274785558946544729609490743199699197195008879157661695").unwrap(), + U256::from_dec_str("4142750859697696641705372803120309740931359230261851701215055719438325633654").unwrap() + ] + ]; + + let valid_input = vec![U256::from(66)]; + let mut encoded_call = vec![0u8; 4]; + encoded_call[0..4].copy_from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..4]); + + // append parameters to the encoded call + encoded_call.extend(ethabi::encode(&[ + Token::Array(proof_a.into_iter().map(Token::Uint).collect()), + Token::Array(proof_b.into_iter().map(|b| Token::Array(b.into_iter().map(Token::Uint).collect())).collect()), + Token::Array(proof_c.into_iter().map(Token::Uint).collect()), + Token::Array(vk_alpha.into_iter().map(Token::Uint).collect()), + Token::Array(vk_beta.into_iter().map(|b| Token::Array(b.into_iter().map(Token::Uint).collect())).collect()), + Token::Array(vk_gamma.into_iter().map(|b| Token::Array(b.into_iter().map(Token::Uint).collect())).collect()), + Token::Array(vk_delta.into_iter().map(|b| Token::Array(b.into_iter().map(Token::Uint).collect())).collect()), + Token::Array(vk_ic.into_iter().map(|ic| Token::Array(ic.into_iter().map(Token::Uint).collect())).collect()), + Token::Array(valid_input.into_iter().map(Token::Uint).collect()), + ])); + let gas_limit_call = 1000000; + let value = U256::default(); + let is_transactional = true; + let validate = true; + let call_runner_results = ::Runner::call( + caller, + contract_address, + encoded_call, + value, + gas_limit_call, + Some(U256::from(1_000_000_000)), + Some(U256::from(1_000_000_000)), + None, + Vec::new(), + is_transactional, + validate, + ::config(), + ); + match call_runner_results { + Ok(_) => (), + Err(e) => { + println!("Error: {:?}", e); + assert!(false); + } + } + }); +} From d0f123bfe69b3019be670c373f348b9089fcebca Mon Sep 17 00:00:00 2001 From: luckychacha <358140284@qq.com> Date: Fri, 4 Aug 2023 02:19:08 +0800 Subject: [PATCH 11/34] Unit test complete. --- runtime/runtime-common/Cargo.toml | 3 +- .../benchmarking.rs | 90 +++++++++---------- .../src/zk_precompile_gas_estimation/mock.rs | 8 +- .../src/zk_precompile_gas_estimation/mod.rs | 4 +- .../src/zk_precompile_gas_estimation/tests.rs | 63 ++++++++----- runtime/testnet/src/lib.rs | 9 +- 6 files changed, 105 insertions(+), 72 deletions(-) diff --git a/runtime/runtime-common/Cargo.toml b/runtime/runtime-common/Cargo.toml index 6688cc83..1f3ddaeb 100644 --- a/runtime/runtime-common/Cargo.toml +++ b/runtime/runtime-common/Cargo.toml @@ -40,10 +40,9 @@ pallet-xvm = { workspace = true, optional = true } log.workspace = true # zk groth16 precompile gas estimation ethabi.workspace = true -# rlp.workspace = true +# ethers.workspace = true [dev-dependencies] -# derive_more.workspace = true fp-account.workspace = true fp-evm.workspace = true pallet-balances.workspace = true diff --git a/runtime/runtime-common/src/zk_precompile_gas_estimation/benchmarking.rs b/runtime/runtime-common/src/zk_precompile_gas_estimation/benchmarking.rs index f8cd07f0..389d913e 100644 --- a/runtime/runtime-common/src/zk_precompile_gas_estimation/benchmarking.rs +++ b/runtime/runtime-common/src/zk_precompile_gas_estimation/benchmarking.rs @@ -5,14 +5,13 @@ use frame_benchmarking::{benchmarks, impl_benchmark_test_suite}; // frontier use pallet_evm::Runner; use sp_std::prelude::*; - benchmarks! { demo_runner { use frame_benchmarking::vec; use sp_core::{H160, U256}; use ethabi::Token; - let caller = "1000000000000000000000000000000000000001".parse::().unwrap(); + let caller = "1000000000000000000000000000000000000666".parse::().unwrap(); let contract_address = H160::from_low_u64_be(0x8888); @@ -89,26 +88,24 @@ benchmarks! { let valid_input = vec![U256::from(66)]; let mut encoded_call = vec![0u8; 4]; encoded_call[0..4].copy_from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..4]); - - // append parameters to the encoded call - encoded_call.extend(ethabi::encode(&[ - Token::Array(proof_a.into_iter().map(Token::Uint).collect()), - Token::Array(proof_b.into_iter().map(|b| Token::Array(b.into_iter().map(Token::Uint).collect())).collect()), - Token::Array(proof_c.into_iter().map(Token::Uint).collect()), - Token::Array(vk_alpha.into_iter().map(Token::Uint).collect()), - Token::Array(vk_beta.into_iter().map(|b| Token::Array(b.into_iter().map(Token::Uint).collect())).collect()), - Token::Array(vk_gamma.into_iter().map(|b| Token::Array(b.into_iter().map(Token::Uint).collect())).collect()), - Token::Array(vk_delta.into_iter().map(|b| Token::Array(b.into_iter().map(Token::Uint).collect())).collect()), - Token::Array(vk_ic.into_iter().map(|ic| Token::Array(ic.into_iter().map(Token::Uint).collect())).collect()), + let parameters = ethabi::encode(&[ + Token::FixedArray(proof_a.into_iter().map(Token::Uint).collect()), + Token::FixedArray(proof_b.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), + Token::FixedArray(proof_c.into_iter().map(Token::Uint).collect()), + Token::FixedArray(vk_alpha.into_iter().map(Token::Uint).collect()), + Token::FixedArray(vk_beta.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), + Token::FixedArray(vk_gamma.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), + Token::FixedArray(vk_delta.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), + Token::Array(vk_ic.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), Token::Array(valid_input.into_iter().map(Token::Uint).collect()), - ])); + ]); + encoded_call.extend(parameters); let gas_limit_call = 1000000; - - }:{ let value = U256::default(); let is_transactional = true; let validate = true; - let call_runner_results = ::Runner::call( + }:{ + let call_runner_results = ::Runner::call( caller, contract_address, encoded_call, @@ -120,35 +117,38 @@ benchmarks! { Vec::new(), is_transactional, validate, - ::config(), + ::config(), ); - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "call_runner_results:{:?}", - // call_runner_results - // ); - assert!(call_runner_results.is_ok(), "call() failed"); - - // let output = info.value; - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "output result {:?}", - // output - // ); - // if output.len() >= 32 { - // let mut result_bytes = [0u8; 32]; - // result_bytes.copy_from_slice(&output[output.len() - 32..]); - // let result = U256::from_big_endian(&result_bytes); - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "Verification result {:?}", - // result - // ); - // assert_eq!(result, U256::one(), "The contract did not return true"); - // } - // } else { - - // } + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "Benchmarking call end.", + ); + match call_runner_results { + Ok(info) => { + let output = info.value; + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "output result {:?}", + output + ); + if output.len() >= 32 { + let mut result_bytes = [0u8; 32]; + result_bytes.copy_from_slice(&output[output.len() - 32..]); + let result = U256::from_big_endian(&result_bytes); + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "Verification result {result:?}", + ); + assert_eq!(result, U256::one(), "The contract did not return true"); + } + }, + Err(e) => { + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "Benchmarking failed", + ); + } + } } } impl_benchmark_test_suite!( diff --git a/runtime/runtime-common/src/zk_precompile_gas_estimation/mock.rs b/runtime/runtime-common/src/zk_precompile_gas_estimation/mock.rs index 5976b150..e2437742 100644 --- a/runtime/runtime-common/src/zk_precompile_gas_estimation/mock.rs +++ b/runtime/runtime-common/src/zk_precompile_gas_estimation/mock.rs @@ -17,6 +17,11 @@ pub const MILLIGGX: Balance = 1_000_000_000_000_000; pub const GGX: Balance = 1000 * MILLIGGX; pub const EXISTENTIAL_DEPOSIT: Balance = 0; +#[cfg(not(feature = "testnet"))] +pub const CHAIN_ID: u64 = 8866u64; +#[cfg(feature = "testnet")] +pub const CHAIN_ID: u64 = 888866u64; + pub type AccountId = H160; pub type Balance = u64; pub type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; @@ -146,6 +151,7 @@ parameter_types! { MockPrecompileSet(PhantomData); pub const WeightPerGas: Weight = Weight::from_parts(1, 0); pub BlockGasLimit: U256 = U256::from(BLOCK_GAS_LIMIT); + pub ChainId: u64 = CHAIN_ID; } impl pallet_evm::Config for Test { @@ -163,7 +169,7 @@ impl pallet_evm::Config for Test { type RuntimeEvent = RuntimeEvent; type PrecompilesType = MockPrecompileSet; type PrecompilesValue = MockPrecompiles; - type ChainId = (); + type ChainId = ChainId; type BlockGasLimit = BlockGasLimit; type Runner = pallet_evm::runner::stack::Runner; type OnChargeTransaction = (); diff --git a/runtime/runtime-common/src/zk_precompile_gas_estimation/mod.rs b/runtime/runtime-common/src/zk_precompile_gas_estimation/mod.rs index 60a1ae41..ed1de686 100644 --- a/runtime/runtime-common/src/zk_precompile_gas_estimation/mod.rs +++ b/runtime/runtime-common/src/zk_precompile_gas_estimation/mod.rs @@ -1,4 +1,4 @@ -#![cfg_attr(not(feature = "std"), no_std)] +// #![cfg_attr(not(feature = "std"), no_std)] // #![cfg_attr(feature = "runtime-benchmarks", deny(unused_crate_dependencies))] #[cfg(feature = "runtime-benchmarks")] @@ -19,10 +19,8 @@ pub mod pallet { #[pallet::config] pub trait Config: frame_system::Config + pallet_evm::Config {} - // 8. Runtime Errors #[pallet::error] pub enum Error {} - // Functions that are callable from outside the runtime. impl Pallet {} } diff --git a/runtime/runtime-common/src/zk_precompile_gas_estimation/tests.rs b/runtime/runtime-common/src/zk_precompile_gas_estimation/tests.rs index 4832ff87..c33f3f25 100644 --- a/runtime/runtime-common/src/zk_precompile_gas_estimation/tests.rs +++ b/runtime/runtime-common/src/zk_precompile_gas_estimation/tests.rs @@ -1,16 +1,22 @@ use crate::zk_precompile_gas_estimation::mock::*; use ethabi::Token; +// use ethers::{ +// core::types::U256, +// prelude::*, +// providers::{Http, Provider}, +// }; use fp_evm::GenesisAccount; use frame_support::traits::GenesisBuild; use pallet_evm::{GenesisConfig, Runner}; use sp_core::{H160, U256}; use std::{collections::BTreeMap, str::FromStr}; - pub fn new_test_ext() -> sp_io::TestExternalities { let mut t = frame_system::GenesisConfig::default() .build_storage::() .unwrap(); - + // let wallet: LocalWallet = "0x01ab6e801c06e59ca97a14fc0a1978b27fa366fc87450e0b65459dd3515b7391" // Do not include the private key in plain text in any produciton code. This is just for demonstration purposes + // .parse::()? + // .with_chain_id(CHAIN_ID); let mut accounts = BTreeMap::new(); accounts.insert( H160::from_str("1000000000000000000000000000000000000001").unwrap(), @@ -43,6 +49,15 @@ pub fn new_test_ext() -> sp_io::TestExternalities { code: vec![], }, ); + accounts.insert( + H160::from_str("1000000000000000000000000000000000000666").unwrap(), + GenesisAccount { + nonce: U256::from(1), + balance: U256::max_value(), + storage: Default::default(), + code: vec![], // No code, this is an EOA + }, + ); pallet_balances::GenesisConfig:: { // Create the block author account with some balance. @@ -59,11 +74,8 @@ pub fn new_test_ext() -> sp_io::TestExternalities { #[test] fn test_zk_precompile_gas_estimation() { - println!("start"); new_test_ext().execute_with(|| { - println!("execute"); - - let caller = "1000000000000000000000000000000000000001".parse::().unwrap(); + let caller = "1000000000000000000000000000000000000666".parse::().unwrap(); let contract_address = H160::from_low_u64_be(0x8888); @@ -71,7 +83,7 @@ fn test_zk_precompile_gas_estimation() { U256::from_dec_str("13202079600221154376862161785979680082984660469505374274880948735521253479994").unwrap(), U256::from_dec_str("19032139815435908179959144311759562497239236177745989139113028703727512477837").unwrap() ]; - + let proof_b = vec![ vec![ U256::from_dec_str("9517359327043802798811688827065407805934924568686293993682568334305900037151").unwrap(), @@ -140,19 +152,20 @@ fn test_zk_precompile_gas_estimation() { let valid_input = vec![U256::from(66)]; let mut encoded_call = vec![0u8; 4]; encoded_call[0..4].copy_from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..4]); - - // append parameters to the encoded call - encoded_call.extend(ethabi::encode(&[ - Token::Array(proof_a.into_iter().map(Token::Uint).collect()), - Token::Array(proof_b.into_iter().map(|b| Token::Array(b.into_iter().map(Token::Uint).collect())).collect()), - Token::Array(proof_c.into_iter().map(Token::Uint).collect()), - Token::Array(vk_alpha.into_iter().map(Token::Uint).collect()), - Token::Array(vk_beta.into_iter().map(|b| Token::Array(b.into_iter().map(Token::Uint).collect())).collect()), - Token::Array(vk_gamma.into_iter().map(|b| Token::Array(b.into_iter().map(Token::Uint).collect())).collect()), - Token::Array(vk_delta.into_iter().map(|b| Token::Array(b.into_iter().map(Token::Uint).collect())).collect()), - Token::Array(vk_ic.into_iter().map(|ic| Token::Array(ic.into_iter().map(Token::Uint).collect())).collect()), + println!("encoded_call: {:?}", encoded_call); + let parameters = ethabi::encode(&[ + Token::FixedArray(proof_a.into_iter().map(Token::Uint).collect()), + Token::FixedArray(proof_b.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), + Token::FixedArray(proof_c.into_iter().map(Token::Uint).collect()), + Token::FixedArray(vk_alpha.into_iter().map(Token::Uint).collect()), + Token::FixedArray(vk_beta.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), + Token::FixedArray(vk_gamma.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), + Token::FixedArray(vk_delta.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), + Token::Array(vk_ic.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), Token::Array(valid_input.into_iter().map(Token::Uint).collect()), - ])); + ]); + println!("parameters: {:?}", parameters); + encoded_call.extend(parameters); let gas_limit_call = 1000000; let value = U256::default(); let is_transactional = true; @@ -172,7 +185,17 @@ fn test_zk_precompile_gas_estimation() { ::config(), ); match call_runner_results { - Ok(_) => (), + Ok(info) => { + let output = info.value; + println!("output result {output:?}"); + if output.len() >= 32 { + let mut result_bytes = [0u8; 32]; + result_bytes.copy_from_slice(&output[output.len() - 32..]); + let result = U256::from_big_endian(&result_bytes); + println!("Verification result {result:?}"); + assert_eq!(result, U256::one(), "The contract did not return true"); + } + }, Err(e) => { println!("Error: {:?}", e); assert!(false); diff --git a/runtime/testnet/src/lib.rs b/runtime/testnet/src/lib.rs index 7421ecde..bb9dff6d 100644 --- a/runtime/testnet/src/lib.rs +++ b/runtime/testnet/src/lib.rs @@ -58,6 +58,7 @@ use pallet_transaction_payment::CurrencyAdapter; use sp_consensus_beefy as beefy_primitives; use pallet_session::historical::{self as pallet_session_historical}; +use runtime_common::zk_precompile_gas_estimation; // A few exports that help ease life for downstream crates. pub use frame_support::{ @@ -473,6 +474,8 @@ impl> FindAuthor for FindAuthorTruncated { impl pallet_randomness_collective_flip::Config for Runtime {} +impl zk_precompile_gas_estimation::Config for Runtime {} + // Create the runtime by composing the FRAME pallets that were previously configured. construct_runtime!( pub enum Runtime where @@ -523,6 +526,8 @@ construct_runtime!( Mmr: pallet_mmr, Beefy: pallet_beefy, MmrLeaf: pallet_beefy_mmr, + // GGX pallets + ZKPrecompileGasEstimation: zk_precompile_gas_estimation, } ); @@ -601,7 +606,8 @@ extern crate frame_benchmarking; #[cfg(feature = "runtime-benchmarks")] mod benches { - define_benchmarks!([pallet_evm, EVM]); + // define_benchmarks!([pallet_evm, EVM]); + define_benchmarks!([zk_precompile_gas_estimation, ZKPrecompileGasEstimation]); } use fp_rpc::TransactionStatus; @@ -1062,6 +1068,7 @@ impl_runtime_apis! { add_benchmark!(params, batches, pallet_evm, PalletEvmBench::); add_benchmark!(params, batches, pallet_hotfix_sufficients, PalletHotfixSufficients::); + add_benchmark!(params, batches, zk_precompile_gas_estimation, ZKPrecompileGasEstimation); if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) } Ok(batches) From efed2726fed1b978911574c552d6fbcddc855108 Mon Sep 17 00:00:00 2001 From: luckychacha <358140284@qq.com> Date: Fri, 4 Aug 2023 13:32:49 +0800 Subject: [PATCH 12/34] zk groth16 verify precompile benchmark is working. --- Cargo.lock | 1 + node/src/runtime/testnet.rs | 22 ++++++++++++++++++- .../benchmarking.rs | 6 ++--- .../src/zk_precompile_gas_estimation/mock.rs | 2 ++ runtime/testnet/Cargo.toml | 2 ++ runtime/testnet/src/lib.rs | 4 ++++ 6 files changed, 33 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 61681623..cbe44925 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4028,6 +4028,7 @@ dependencies = [ name = "golden-gate-runtime-testnet" version = "0.0.0" dependencies = [ + "fp-evm", "fp-rpc", "fp-self-contained", "frame-benchmarking", diff --git a/node/src/runtime/testnet.rs b/node/src/runtime/testnet.rs index 27efb99c..90470d75 100644 --- a/node/src/runtime/testnet.rs +++ b/node/src/runtime/testnet.rs @@ -57,6 +57,12 @@ pub fn testnet_genesis( ) -> GenesisConfig { let endowment: Balance = (token_supply_in_ggx / endowed_accounts.len() as u64) as Balance * GGX; + // This is supposed the be the simplest bytecode to revert without returning any data. + // We will pre-deploy it under all of our precompiles to ensure they can be called from + // within contracts. + // (PUSH1 0x00 PUSH1 0x00 REVERT) + let revert_bytecode = vec![0x60, 0x00, 0x60, 0x00, 0xFD]; + GenesisConfig { // System system: SystemConfig { @@ -97,7 +103,21 @@ pub fn testnet_genesis( evm_chain_id: EVMChainIdConfig { chain_id }, evm: EVMConfig { accounts: { - let mut map = BTreeMap::new(); + let mut map: BTreeMap = + Precompiles::used_addresses() + .map(|addr| { + ( + addr, + GenesisAccount { + nonce: Default::default(), + balance: Default::default(), + storage: Default::default(), + code: revert_bytecode.clone(), + }, + ) + }) + .into_iter() + .collect(); map.insert( // H160 address of Alice dev account // Derived from SS58 (42 prefix) address diff --git a/runtime/runtime-common/src/zk_precompile_gas_estimation/benchmarking.rs b/runtime/runtime-common/src/zk_precompile_gas_estimation/benchmarking.rs index 389d913e..1f076be4 100644 --- a/runtime/runtime-common/src/zk_precompile_gas_estimation/benchmarking.rs +++ b/runtime/runtime-common/src/zk_precompile_gas_estimation/benchmarking.rs @@ -11,7 +11,7 @@ benchmarks! { use sp_core::{H160, U256}; use ethabi::Token; - let caller = "1000000000000000000000000000000000000666".parse::().unwrap(); + let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); let contract_address = H160::from_low_u64_be(0x8888); @@ -105,7 +105,7 @@ benchmarks! { let is_transactional = true; let validate = true; }:{ - let call_runner_results = ::Runner::call( + let call_runner_results = ::Runner::call( caller, contract_address, encoded_call, @@ -117,7 +117,7 @@ benchmarks! { Vec::new(), is_transactional, validate, - ::config(), + ::config(), ); log::info!( target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", diff --git a/runtime/runtime-common/src/zk_precompile_gas_estimation/mock.rs b/runtime/runtime-common/src/zk_precompile_gas_estimation/mock.rs index e2437742..39453418 100644 --- a/runtime/runtime-common/src/zk_precompile_gas_estimation/mock.rs +++ b/runtime/runtime-common/src/zk_precompile_gas_estimation/mock.rs @@ -179,6 +179,8 @@ impl pallet_evm::Config for Test { type WeightInfo = (); } +impl crate::zk_precompile_gas_estimation::Config for Test {} + // Configure a mock runtime to test the pallet. construct_runtime!( pub enum Test where diff --git a/runtime/testnet/Cargo.toml b/runtime/testnet/Cargo.toml index cc786d88..e856deb2 100644 --- a/runtime/testnet/Cargo.toml +++ b/runtime/testnet/Cargo.toml @@ -61,6 +61,7 @@ pallet-treasury.workspace = true pallet-vesting.workspace = true # Frontier +fp-evm.workspace = true fp-rpc.workspace = true fp-self-contained.workspace = true @@ -150,6 +151,7 @@ std = [ "pallet-treasury/std", "pallet-vesting/std", # Frontier + "fp-evm/std", "fp-rpc/std", "fp-self-contained/std", # Frontier FRAME diff --git a/runtime/testnet/src/lib.rs b/runtime/testnet/src/lib.rs index bb9dff6d..1d269b87 100644 --- a/runtime/testnet/src/lib.rs +++ b/runtime/testnet/src/lib.rs @@ -19,6 +19,8 @@ mod prelude; mod version; pub use version::VERSION; +#[cfg(feature = "std")] +pub use fp_evm::GenesisAccount; use frame_support::{ pallet_prelude::TransactionPriority, weights::constants::WEIGHT_PROOF_SIZE_PER_MB, }; @@ -82,8 +84,10 @@ pub use pallet_timestamp::Call as TimestampCall; pub use runtime_common::{ chain_spec::{self, RuntimeConfig}, + precompiles::GoldenGatePrecompiles, validator_manager, }; +pub type Precompiles = GoldenGatePrecompiles; /// Type of block number. pub type BlockNumber = u32; From a56d4d569d0b127902e6993d785f64eec4175063 Mon Sep 17 00:00:00 2001 From: luckychacha <358140284@qq.com> Date: Fri, 4 Aug 2023 14:20:14 +0800 Subject: [PATCH 13/34] Remove some log in benchmarking. --- .../benchmarking.rs | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/runtime/runtime-common/src/zk_precompile_gas_estimation/benchmarking.rs b/runtime/runtime-common/src/zk_precompile_gas_estimation/benchmarking.rs index 1f076be4..91c18eef 100644 --- a/runtime/runtime-common/src/zk_precompile_gas_estimation/benchmarking.rs +++ b/runtime/runtime-common/src/zk_precompile_gas_estimation/benchmarking.rs @@ -119,26 +119,26 @@ benchmarks! { validate, ::config(), ); - log::info!( - target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - "Benchmarking call end.", - ); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "Benchmarking call end.", + // ); match call_runner_results { Ok(info) => { let output = info.value; - log::info!( - target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - "output result {:?}", - output - ); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "output result {:?}", + // output + // ); if output.len() >= 32 { let mut result_bytes = [0u8; 32]; result_bytes.copy_from_slice(&output[output.len() - 32..]); let result = U256::from_big_endian(&result_bytes); - log::info!( - target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - "Verification result {result:?}", - ); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "Verification result {result:?}", + // ); assert_eq!(result, U256::one(), "The contract did not return true"); } }, From 83dcef7b0bebdfa26ae7242d8e17c7d62d1b5241 Mon Sep 17 00:00:00 2001 From: luckychacha <358140284@qq.com> Date: Fri, 4 Aug 2023 14:46:56 +0800 Subject: [PATCH 14/34] Format code and dependencies. --- runtime/mainnet/src/lib.rs | 7 +- runtime/runtime-common/Cargo.toml | 4 - .../src/zk_precompile_gas_estimation/mock.rs | 75 ------------------- .../src/zk_precompile_gas_estimation/mod.rs | 3 - .../src/zk_precompile_gas_estimation/tests.rs | 8 -- runtime/testnet/src/lib.rs | 7 +- 6 files changed, 2 insertions(+), 102 deletions(-) diff --git a/runtime/mainnet/src/lib.rs b/runtime/mainnet/src/lib.rs index 721329d2..52889237 100644 --- a/runtime/mainnet/src/lib.rs +++ b/runtime/mainnet/src/lib.rs @@ -357,11 +357,6 @@ parameter_types! { // For weight estimation, we assume that the most locks on an individual account will be 50. // This number may need to be adjusted in the future if this assumption no longer holds true. pub const MaxLocks: u32 = 50; - - // The minimum balance that an account must have in order to be kept alive on-chain. - // This value is used by the Balances pallet to determine if an account should be - // kept alive or if it should be reaped to free up storage space. - pub const ExistentialDeposit: Balance = EXISTENTIAL_DEPOSIT; } impl pallet_balances::Config for Runtime { @@ -370,7 +365,7 @@ impl pallet_balances::Config for Runtime { type DustRemoval = (); /// The ubiquitous event type. type RuntimeEvent = RuntimeEvent; - type ExistentialDeposit = ExistentialDeposit; + type ExistentialDeposit = ConstU128; type AccountStore = System; type WeightInfo = pallet_balances::weights::SubstrateWeight; type MaxLocks = MaxLocks; diff --git a/runtime/runtime-common/Cargo.toml b/runtime/runtime-common/Cargo.toml index 1f3ddaeb..002ccde5 100644 --- a/runtime/runtime-common/Cargo.toml +++ b/runtime/runtime-common/Cargo.toml @@ -40,7 +40,6 @@ pallet-xvm = { workspace = true, optional = true } log.workspace = true # zk groth16 precompile gas estimation ethabi.workspace = true -# ethers.workspace = true [dev-dependencies] fp-account.workspace = true @@ -50,9 +49,6 @@ pallet-timestamp.workspace = true proptest.workspace = true test-strategy.workspace = true -# Astar -# precompile-utils = { workspace = true, features = ["testing"] } - [features] default = ["std"] precompiles = [ diff --git a/runtime/runtime-common/src/zk_precompile_gas_estimation/mock.rs b/runtime/runtime-common/src/zk_precompile_gas_estimation/mock.rs index 39453418..955589c2 100644 --- a/runtime/runtime-common/src/zk_precompile_gas_estimation/mock.rs +++ b/runtime/runtime-common/src/zk_precompile_gas_estimation/mock.rs @@ -27,66 +27,6 @@ pub type Balance = u64; pub type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; pub type Block = frame_system::mocking::MockBlock; -// pub const PRECOMPILE_ADDRESS: H160 = H160::from_low_u64_be(0x8888); -// #[derive( -// Eq, -// PartialEq, -// Ord, -// PartialOrd, -// Clone, -// Encode, -// Decode, -// Debug, -// MaxEncodedLen, -// Serialize, -// Deserialize, -// derive_more::Display, -// TypeInfo, -// )] -// pub enum TestAccount { -// Alice, -// Bob, -// Charlie, -// Bogus, -// Precompile, -// } - -// impl Default for TestAccount { -// fn default() -> Self { -// Self::Alice -// } -// } - -// impl AddressMapping for TestAccount { -// fn into_account_id(h160_account: H160) -> TestAccount { -// match h160_account { -// a if a == H160::repeat_byte(0xAA) => Self::Alice, -// a if a == H160::repeat_byte(0xBB) => Self::Bob, -// a if a == H160::repeat_byte(0xCC) => Self::Charlie, -// a if a == PRECOMPILE_ADDRESS => Self::Precompile, -// _ => Self::Bogus, -// } -// } -// } - -// impl From for TestAccount { -// fn from(x: H160) -> TestAccount { -// TestAccount::into_account_id(x) -// } -// } - -// impl From for H160 { -// fn from(value: TestAccount) -> H160 { -// match value { -// TestAccount::Alice => H160::repeat_byte(0xAA), -// TestAccount::Bob => H160::repeat_byte(0xBB), -// TestAccount::Charlie => H160::repeat_byte(0xCC), -// TestAccount::Precompile => PRECOMPILE_ADDRESS, -// TestAccount::Bogus => Default::default(), -// } -// } -// } - parameter_types! { pub const BlockHashCount: u64 = 250; pub BlockWeights: frame_system::limits::BlockWeights = @@ -195,21 +135,6 @@ construct_runtime!( } ); -// #[derive(Default)] -// pub(crate) struct ExtBuilder; - -// impl ExtBuilder { -// pub(crate) fn build(self) -> sp_io::TestExternalities { -// let t = frame_system::GenesisConfig::default() -// .build_storage::() -// .expect("Frame system builds valid default genesis config"); - -// let mut ext = sp_io::TestExternalities::new(t); -// ext.execute_with(|| System::set_block_number(1)); -// ext -// } -// } - #[derive(Debug, Clone, Copy)] pub struct MockPrecompileSet(PhantomData); diff --git a/runtime/runtime-common/src/zk_precompile_gas_estimation/mod.rs b/runtime/runtime-common/src/zk_precompile_gas_estimation/mod.rs index ed1de686..2645174c 100644 --- a/runtime/runtime-common/src/zk_precompile_gas_estimation/mod.rs +++ b/runtime/runtime-common/src/zk_precompile_gas_estimation/mod.rs @@ -1,6 +1,3 @@ -// #![cfg_attr(not(feature = "std"), no_std)] -// #![cfg_attr(feature = "runtime-benchmarks", deny(unused_crate_dependencies))] - #[cfg(feature = "runtime-benchmarks")] pub mod benchmarking; #[cfg(test)] diff --git a/runtime/runtime-common/src/zk_precompile_gas_estimation/tests.rs b/runtime/runtime-common/src/zk_precompile_gas_estimation/tests.rs index c33f3f25..0a388d2f 100644 --- a/runtime/runtime-common/src/zk_precompile_gas_estimation/tests.rs +++ b/runtime/runtime-common/src/zk_precompile_gas_estimation/tests.rs @@ -1,10 +1,5 @@ use crate::zk_precompile_gas_estimation::mock::*; use ethabi::Token; -// use ethers::{ -// core::types::U256, -// prelude::*, -// providers::{Http, Provider}, -// }; use fp_evm::GenesisAccount; use frame_support::traits::GenesisBuild; use pallet_evm::{GenesisConfig, Runner}; @@ -14,9 +9,6 @@ pub fn new_test_ext() -> sp_io::TestExternalities { let mut t = frame_system::GenesisConfig::default() .build_storage::() .unwrap(); - // let wallet: LocalWallet = "0x01ab6e801c06e59ca97a14fc0a1978b27fa366fc87450e0b65459dd3515b7391" // Do not include the private key in plain text in any produciton code. This is just for demonstration purposes - // .parse::()? - // .with_chain_id(CHAIN_ID); let mut accounts = BTreeMap::new(); accounts.insert( H160::from_str("1000000000000000000000000000000000000001").unwrap(), diff --git a/runtime/testnet/src/lib.rs b/runtime/testnet/src/lib.rs index 1d269b87..90d4fc3e 100644 --- a/runtime/testnet/src/lib.rs +++ b/runtime/testnet/src/lib.rs @@ -401,11 +401,6 @@ parameter_types! { // For weight estimation, we assume that the most locks on an individual account will be 50. // This number may need to be adjusted in the future if this assumption no longer holds true. pub const MaxLocks: u32 = 50; - - // The minimum balance that an account must have in order to be kept alive on-chain. - // This value is used by the Balances pallet to determine if an account should be - // kept alive or if it should be reaped to free up storage space. - pub const ExistentialDeposit: Balance = EXISTENTIAL_DEPOSIT; } impl pallet_balances::Config for Runtime { @@ -414,7 +409,7 @@ impl pallet_balances::Config for Runtime { type DustRemoval = (); /// The ubiquitous event type. type RuntimeEvent = RuntimeEvent; - type ExistentialDeposit = ExistentialDeposit; + type ExistentialDeposit = ConstU128; type AccountStore = System; type WeightInfo = pallet_balances::weights::SubstrateWeight; type MaxLocks = MaxLocks; From 830689d8f9964f229fe2400574c33c50cc0b401d Mon Sep 17 00:00:00 2001 From: luckychacha <358140284@qq.com> Date: Sun, 6 Aug 2023 18:29:49 +0800 Subject: [PATCH 15/34] Fix cargo fmt error. --- .../runtime-common/src/zk_precompile_gas_estimation/tests.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/runtime-common/src/zk_precompile_gas_estimation/tests.rs b/runtime/runtime-common/src/zk_precompile_gas_estimation/tests.rs index 0a388d2f..99fbdd37 100644 --- a/runtime/runtime-common/src/zk_precompile_gas_estimation/tests.rs +++ b/runtime/runtime-common/src/zk_precompile_gas_estimation/tests.rs @@ -75,7 +75,7 @@ fn test_zk_precompile_gas_estimation() { U256::from_dec_str("13202079600221154376862161785979680082984660469505374274880948735521253479994").unwrap(), U256::from_dec_str("19032139815435908179959144311759562497239236177745989139113028703727512477837").unwrap() ]; - + let proof_b = vec![ vec![ U256::from_dec_str("9517359327043802798811688827065407805934924568686293993682568334305900037151").unwrap(), From c77a8402814882a813a98bb946f7273d837df069 Mon Sep 17 00:00:00 2001 From: luckychacha <358140284@qq.com> Date: Mon, 7 Aug 2023 18:31:55 +0800 Subject: [PATCH 16/34] Add some benchmarking testcase. --- runtime/mainnet/src/lib.rs | 7 +- .../benchmarking.rs | 1374 ++++++++++++++++- runtime/testnet/src/lib.rs | 7 +- 3 files changed, 1358 insertions(+), 30 deletions(-) diff --git a/runtime/mainnet/src/lib.rs b/runtime/mainnet/src/lib.rs index 52889237..721329d2 100644 --- a/runtime/mainnet/src/lib.rs +++ b/runtime/mainnet/src/lib.rs @@ -357,6 +357,11 @@ parameter_types! { // For weight estimation, we assume that the most locks on an individual account will be 50. // This number may need to be adjusted in the future if this assumption no longer holds true. pub const MaxLocks: u32 = 50; + + // The minimum balance that an account must have in order to be kept alive on-chain. + // This value is used by the Balances pallet to determine if an account should be + // kept alive or if it should be reaped to free up storage space. + pub const ExistentialDeposit: Balance = EXISTENTIAL_DEPOSIT; } impl pallet_balances::Config for Runtime { @@ -365,7 +370,7 @@ impl pallet_balances::Config for Runtime { type DustRemoval = (); /// The ubiquitous event type. type RuntimeEvent = RuntimeEvent; - type ExistentialDeposit = ConstU128; + type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; type WeightInfo = pallet_balances::weights::SubstrateWeight; type MaxLocks = MaxLocks; diff --git a/runtime/runtime-common/src/zk_precompile_gas_estimation/benchmarking.rs b/runtime/runtime-common/src/zk_precompile_gas_estimation/benchmarking.rs index 91c18eef..2df3456d 100644 --- a/runtime/runtime-common/src/zk_precompile_gas_estimation/benchmarking.rs +++ b/runtime/runtime-common/src/zk_precompile_gas_estimation/benchmarking.rs @@ -5,8 +5,1326 @@ use frame_benchmarking::{benchmarks, impl_benchmark_test_suite}; // frontier use pallet_evm::Runner; use sp_std::prelude::*; + +struct VerifyingKey { + proof_a: Vec, + proof_b: Vec>, + proof_c: Vec, + vk_alpha: Vec, + vk_beta: Vec>, + vk_gamma: Vec>, + vk_delta: Vec>, + vk_ic: Vec>, + valid_input: Vec, +} + benchmarks! { - demo_runner { + nconstraints_10 { + use frame_benchmarking::vec; + use sp_core::{H160, U256}; + use ethabi::Token; + + let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + + let contract_address = H160::from_low_u64_be(0x8888); + + let proof_a = vec![ + U256::from_dec_str("323654832133639084097738656057999026789295280666886852594984576709163539526").unwrap(), + U256::from_dec_str("6142957218280645039826855630872622613337777761157366378615236951849913775542").unwrap() + ]; + + let proof_b = vec![ + vec![ + U256::from_dec_str("3781402603457401622553078625624300084337446058890012151530042647448923283156").unwrap(), + U256::from_dec_str("3517436796495769146106898128956048233729888622957356948216773257280783319311").unwrap() + ], + vec![ + U256::from_dec_str("18697717875318192535466611481750571094853863458428844875498420533596881568336").unwrap(), + U256::from_dec_str("21426423909981695530725752097567643188095093768132522705564475372400085021436").unwrap() + ], + ]; + + let proof_c = vec![ + U256::from_dec_str("21613404883582191576526635676329374200679201344239432919502376530553941450391").unwrap(), + U256::from_dec_str("15157755445966041962464884593780030869511182260822371637833098723763718514455").unwrap() + ]; + + let vk_alpha = vec![ + U256::from_dec_str("11521346682463921906610271064518766485088278761420928386309550940286650671457").unwrap(), + U256::from_dec_str("14352830518175561380348856554041231805603495989169432000725584250110291361678").unwrap() + ]; + + let vk_beta = vec![ + vec![ + U256::from_dec_str("15782596638536803844844408481637582589736413871396993858917786753770876529739").unwrap(), + U256::from_dec_str("14911823231521430202833448929652297782496660742577343858219844871404504144036").unwrap() + ], + vec![ + U256::from_dec_str("2082222914940990020573243578958386229340150899029559516350605378857473031525").unwrap(), + U256::from_dec_str("13498996195230132373906915048494917069165130851394909752977335076805840989307").unwrap() + ], + ]; + + let vk_gamma = vec![ + vec![ + U256::from_dec_str("3598021131780341035246011324427156192540414244243113294885735792953741606880").unwrap(), + U256::from_dec_str("2036084172531515709709771052774738245922046202318890723044728246225539963428").unwrap() + ], + vec![ + U256::from_dec_str("5925457711548235099025126547368719549508643015841982506039250719340224619945").unwrap(), + U256::from_dec_str("6297446610567432982066083461547400065680646594595441716191878482607632761242").unwrap() + ], + ]; + + let vk_delta = vec![ + vec![ + U256::from_dec_str("8540596677770285018018336727251534074846909511956041125063939097422779191925").unwrap(), + U256::from_dec_str("4004145476643750015352094786522189637304633549022019774555222068038038169997").unwrap() + ], + vec![ + U256::from_dec_str("14044576757821380530542904664046256148829410228513509672845139471539338485558").unwrap(), + U256::from_dec_str("21655834928283484760531472827487408029775629615266614212974138202212982461041").unwrap() + ] + ]; + + let vk_ic = vec![ + vec![ + U256::from_dec_str("18160015955331442477546361309657533914485780296451278252095683998154112390415").unwrap(), + U256::from_dec_str("2421052745427024367257863480713357899822722660532800486395996070904226714086").unwrap() + ], + vec![ + U256::from_dec_str("13418845437340247256566377432948869602549774753220761674399899795516131627829").unwrap(), + U256::from_dec_str("19073971532401628571532840417056837528958340897410372352356543204393028153748").unwrap() + ] + ]; + + let valid_input = vec![U256::from_dec_str("14965631224775206224").unwrap(), U256::from_dec_str("3021577815302938909").unwrap(), U256::from_dec_str("14359293880404272991").unwrap(), U256::from_dec_str("1555005537055779113").unwrap()]; + let mut encoded_call = vec![0u8; 4]; + encoded_call[0..4].copy_from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..4]); + let parameters = ethabi::encode(&[ + Token::FixedArray(proof_a.into_iter().map(Token::Uint).collect()), + Token::FixedArray(proof_b.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), + Token::FixedArray(proof_c.into_iter().map(Token::Uint).collect()), + Token::FixedArray(vk_alpha.into_iter().map(Token::Uint).collect()), + Token::FixedArray(vk_beta.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), + Token::FixedArray(vk_gamma.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), + Token::FixedArray(vk_delta.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), + Token::Array(vk_ic.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), + Token::Array(valid_input.into_iter().map(Token::Uint).collect()), + ]); + encoded_call.extend(parameters); + let gas_limit_call = 1000000; + let value = U256::default(); + let is_transactional = true; + let validate = true; + }:{ + let call_runner_results = ::Runner::call( + caller, + contract_address, + encoded_call, + value, + gas_limit_call, + Some(U256::from(1_000_000_000)), + Some(U256::from(1_000_000_000)), + None, + Vec::new(), + is_transactional, + validate, + ::config(), + ); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "Benchmarking call end.", + // ); + match call_runner_results { + Ok(info) => { + let output = info.value; + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "output result {:?}", + // output + // ); + if output.len() >= 32 { + let mut result_bytes = [0u8; 32]; + result_bytes.copy_from_slice(&output[output.len() - 32..]); + let result = U256::from_big_endian(&result_bytes); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "Verification result {result:?}", + // ); + assert_eq!(result, U256::one(), "The contract did not return true"); + } + }, + Err(e) => { + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "Benchmarking failed", + ); + } + } + } + + nconstraints_15 { + use frame_benchmarking::vec; + use sp_core::{H160, U256}; + use ethabi::Token; + + let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + + let contract_address = H160::from_low_u64_be(0x8888); + + let proof_a = vec![ + U256::from_dec_str("20130649533606132941076532567185186533385627048731412173183395399598706653722").unwrap(), + U256::from_dec_str("5013302449315195110728085938922390324181635865643940685717581319642064255185").unwrap() + ]; + + let proof_b = vec![ + vec![ + U256::from_dec_str("182349185274378562733946998188496702865899889969489490693307112376287220894").unwrap(), + U256::from_dec_str("21774901779074752042085216201094185472133753187176013828342990679080664340226").unwrap() + ], + vec![ + U256::from_dec_str("5869802804905785526619333457887737025688889410113776710579029089235110697192").unwrap(), + U256::from_dec_str("11299229682492002119651745673740140812409219814076852306943005451224291551902").unwrap() + ], + ]; + + let proof_c = vec![ + U256::from_dec_str("20185206171191904498488721605780661105586137132655998116453037531151235420138").unwrap(), + U256::from_dec_str("10384110586589833558642758431697087208638469907021113041447281049306264412338").unwrap() + ]; + + let vk_alpha = vec![ + U256::from_dec_str("16518131354665416356366619968057793725998398101013238576312579236126088696774").unwrap(), + U256::from_dec_str("16092603482186593319494034095089381923094130901686564523346715807012185857162").unwrap() + ]; + + let vk_beta = vec![ + vec![ + U256::from_dec_str("21734430847137516428081497368042335428479760179384429208483228211390870007889").unwrap(), + U256::from_dec_str("4340802082106264411360501616317193563940246579398950954214582760982827315863").unwrap() + ], + vec![ + U256::from_dec_str("12447957849620237825007220112503702667357790011364771059885655868800342557822").unwrap(), + U256::from_dec_str("14809511833945059264202963765646411224042099188929021476112339598771762711323").unwrap() + ], + ]; + + let vk_gamma = vec![ + vec![ + U256::from_dec_str("17324242037467178377673475424723060403816978313062414185741167494411363117422").unwrap(), + U256::from_dec_str("573707969764376568308084515022276929250394811599970857666617570109713369226").unwrap() + ], + vec![ + U256::from_dec_str("7128237379235615126712368859451728796195891617721045758701935689078823845047").unwrap(), + U256::from_dec_str("10251648689582024203541816575587863025500039856770502839005077409839562057857").unwrap() + ], + ]; + + let vk_delta = vec![ + vec![ + U256::from_dec_str("10606414414773769335220870560841720522962914580715128022037427553027383133468").unwrap(), + U256::from_dec_str("17945431494760095084161450708936397005964902805999383045150147654106302962212").unwrap() + ], + vec![ + U256::from_dec_str("1114602509780071710197893478088881134916626713904515339987079398421518390581").unwrap(), + U256::from_dec_str("193998821630871240239454478188468337135142017574640889316476264339168416109").unwrap() + ] + ]; + + let vk_ic = vec![ + vec![ + U256::from_dec_str("5962671215665825419481336630213008800754405882212434260146565927291026766869").unwrap(), + U256::from_dec_str("16048419286366094768895756097008850316935017795185761633869316473249446959923").unwrap() + ], + vec![ + U256::from_dec_str("11963041201807212594527101484518323233884176930563963184262271167850375002702").unwrap(), + U256::from_dec_str("18844805358753225197609605824296109138813209675865830312094534406203255607198").unwrap() + ] + ]; + + let valid_input = vec![U256::from_dec_str("4843011250846255110").unwrap(), U256::from_dec_str("10798190704713744688").unwrap(), U256::from_dec_str("15134859568936326220").unwrap(), U256::from_dec_str("2883369245646660076").unwrap()]; + let mut encoded_call = vec![0u8; 4]; + encoded_call[0..4].copy_from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..4]); + let parameters = ethabi::encode(&[ + Token::FixedArray(proof_a.into_iter().map(Token::Uint).collect()), + Token::FixedArray(proof_b.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), + Token::FixedArray(proof_c.into_iter().map(Token::Uint).collect()), + Token::FixedArray(vk_alpha.into_iter().map(Token::Uint).collect()), + Token::FixedArray(vk_beta.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), + Token::FixedArray(vk_gamma.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), + Token::FixedArray(vk_delta.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), + Token::Array(vk_ic.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), + Token::Array(valid_input.into_iter().map(Token::Uint).collect()), + ]); + encoded_call.extend(parameters); + let gas_limit_call = 1000000; + let value = U256::default(); + let is_transactional = true; + let validate = true; + }:{ + let call_runner_results = ::Runner::call( + caller, + contract_address, + encoded_call, + value, + gas_limit_call, + Some(U256::from(1_000_000_000)), + Some(U256::from(1_000_000_000)), + None, + Vec::new(), + is_transactional, + validate, + ::config(), + ); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "Benchmarking call end.", + // ); + match call_runner_results { + Ok(info) => { + let output = info.value; + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "output result {:?}", + // output + // ); + if output.len() >= 32 { + let mut result_bytes = [0u8; 32]; + result_bytes.copy_from_slice(&output[output.len() - 32..]); + let result = U256::from_big_endian(&result_bytes); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "Verification result {result:?}", + // ); + assert_eq!(result, U256::one(), "The contract did not return true"); + } + }, + Err(e) => { + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "Benchmarking failed", + ); + } + } + } + + nconstraints_20 { + use frame_benchmarking::vec; + use sp_core::{H160, U256}; + use ethabi::Token; + + let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + + let contract_address = H160::from_low_u64_be(0x8888); + + let proof_a = vec![ + U256::from_dec_str("797572477248804392444831225209327368031406989322029802514696832026672358416").unwrap(), + U256::from_dec_str("14792745011262875092811677474030034668956937211525097875362241962916137456465").unwrap() + ]; + + let proof_b = vec![ + vec![ + U256::from_dec_str("18780733901893439739371423627306821236863790649657196488891599355591321953851").unwrap(), + U256::from_dec_str("9680544448661229130288510239162388428669756867621972396627016600055984349499").unwrap() + ], + vec![ + U256::from_dec_str("11738424367558729478935071422176167853312257211377899850934753533414170335039").unwrap(), + U256::from_dec_str("18233646049353711985788868148390262624363849777798470342741694587137854046312").unwrap() + ], + ]; + + let proof_c = vec![ + U256::from_dec_str("9030949957263413847331466570610168053394322783722896104311457102193711447736").unwrap(), + U256::from_dec_str("19892969453275240241999306433024784295865139436513729478470715581670537973183").unwrap() + ]; + + let vk_alpha = vec![ + U256::from_dec_str("9129483983788792790250516546077504592262306584249196914035593903220113466346").unwrap(), + U256::from_dec_str("12931577676488623470369386127145659839850514961607631368866187840816419893745").unwrap() + ]; + + let vk_beta = vec![ + vec![ + U256::from_dec_str("7733336395661433750318564428962011373303863005056937588991328321699559429718").unwrap(), + U256::from_dec_str("17750049529131446238696663224077924496537231636880056629697436601439393528008").unwrap() + ], + vec![ + U256::from_dec_str("8293377799807146929370692717869590893937274675192938831619975844923042030881").unwrap(), + U256::from_dec_str("4263357454976975022836583944985361945040552205174286149616049652777546621773").unwrap() + ], + ]; + + let vk_gamma = vec![ + vec![ + U256::from_dec_str("14151440830510271657142608578154654007777206023678518530807735001262951045692").unwrap(), + U256::from_dec_str("1767291767856447136921215746781550838727073342526929959676175537783883225487").unwrap() + ], + vec![ + U256::from_dec_str("15173492886826553839363776087467612357738824024869668919975796903208737039768").unwrap(), + U256::from_dec_str("11930052964402267454553402353579104183135244867064411968119095331986593125500").unwrap() + ], + ]; + + let vk_delta = vec![ + vec![ + U256::from_dec_str("7299631212873411609242516274008416712647200249879388590190636109884194725508").unwrap(), + U256::from_dec_str("8501638231329375259007419224045458732070699435817171076438597961712893321854").unwrap() + ], + vec![ + U256::from_dec_str("15047730134046003932972688387420458293142941608648562801026918857178341643816").unwrap(), + U256::from_dec_str("14151346772944327368443846389587994785327280897500259203977403093792866270134").unwrap() + ] + ]; + + let vk_ic = vec![ + vec![ + U256::from_dec_str("731357633257473743905158797156252139612893761758845410915414966970585493895").unwrap(), + U256::from_dec_str("16967744642853731718627404215453394490485627147408404648214694655394595655398").unwrap() + ], + vec![ + U256::from_dec_str("1346463672788502974713113436051481443629775449244308207040448867039527497840").unwrap(), + U256::from_dec_str("18844670641178242764504539209612934748132154582441062514954805312543875749365").unwrap() + ] + ]; + + let valid_input = vec![U256::from_dec_str("9545317761180864681").unwrap(), U256::from_dec_str("15203947991842169444").unwrap(), U256::from_dec_str("11010182592065041277").unwrap(), U256::from_dec_str("2750389353565937097").unwrap()]; + let mut encoded_call = vec![0u8; 4]; + encoded_call[0..4].copy_from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..4]); + let parameters = ethabi::encode(&[ + Token::FixedArray(proof_a.into_iter().map(Token::Uint).collect()), + Token::FixedArray(proof_b.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), + Token::FixedArray(proof_c.into_iter().map(Token::Uint).collect()), + Token::FixedArray(vk_alpha.into_iter().map(Token::Uint).collect()), + Token::FixedArray(vk_beta.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), + Token::FixedArray(vk_gamma.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), + Token::FixedArray(vk_delta.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), + Token::Array(vk_ic.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), + Token::Array(valid_input.into_iter().map(Token::Uint).collect()), + ]); + encoded_call.extend(parameters); + let gas_limit_call = 1000000; + let value = U256::default(); + let is_transactional = true; + let validate = true; + }:{ + let call_runner_results = ::Runner::call( + caller, + contract_address, + encoded_call, + value, + gas_limit_call, + Some(U256::from(1_000_000_000)), + Some(U256::from(1_000_000_000)), + None, + Vec::new(), + is_transactional, + validate, + ::config(), + ); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "Benchmarking call end.", + // ); + match call_runner_results { + Ok(info) => { + let output = info.value; + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "output result {:?}", + // output + // ); + if output.len() >= 32 { + let mut result_bytes = [0u8; 32]; + result_bytes.copy_from_slice(&output[output.len() - 32..]); + let result = U256::from_big_endian(&result_bytes); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "Verification result {result:?}", + // ); + assert_eq!(result, U256::one(), "The contract did not return true"); + } + }, + Err(e) => { + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "Benchmarking failed", + ); + } + } + } + + nconstraints_25 { + use frame_benchmarking::vec; + use sp_core::{H160, U256}; + use ethabi::Token; + + let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + + let contract_address = H160::from_low_u64_be(0x8888); + + let proof_a = vec![ + U256::from_dec_str("5442688768232443344552263783267390208856198689842640798776177410815565547367").unwrap(), + U256::from_dec_str("16310414003289240410078247718742394211798524980802086932072100478604843138879").unwrap() + ]; + + let proof_b = vec![ + vec![ + U256::from_dec_str("18190532627346636099188351540696740134404407871692706498689154867172280651496").unwrap(), + U256::from_dec_str("275967461706136585361355308922764172109936742989119387744117535714873890136").unwrap() + ], + vec![ + U256::from_dec_str("20432859376686408480939951320620928735684720753051796534902941362107917945448").unwrap(), + U256::from_dec_str("20575328298763015614805638365408623315084841523436681299021166233260739215585").unwrap() + ], + ]; + + let proof_c = vec![ + U256::from_dec_str("21729070949671190651383446829182792170701603278872739139487134063534373496928").unwrap(), + U256::from_dec_str("11473159888261500071826283643864569393105028020759142008919378165280126183791").unwrap() + ]; + + let vk_alpha = vec![ + U256::from_dec_str("6116186011971746741793619516283587796788649022044712022866691859910541408388").unwrap(), + U256::from_dec_str("9990751801376433017793027493689116570629263722237360070512991124369867111294").unwrap() + ]; + + let vk_beta = vec![ + vec![ + U256::from_dec_str("19134989187129211715471143723472806940780591878437988384412094557596618102949").unwrap(), + U256::from_dec_str("11002122036813197737012103302067373956587501561568917970913786117384906562322").unwrap() + ], + vec![ + U256::from_dec_str("20227241808293262878318140546702845934510851943742865848865718895434416271823").unwrap(), + U256::from_dec_str("1208695332664339284660261403674630632193027591536251936703796527895870746053").unwrap() + ], + ]; + + let vk_gamma = vec![ + vec![ + U256::from_dec_str("9988080894620831828514001726353047899833627122523386578651185763598814334161").unwrap(), + U256::from_dec_str("1210488941280905931352250513800327257407276187767564156715231067181630088303").unwrap() + ], + vec![ + U256::from_dec_str("9123410895646419307291143661097804061907837645760653809597075433728132210845").unwrap(), + U256::from_dec_str("5940342572290825895021782196790640411792369989666988944848888929369542627086").unwrap() + ], + ]; + + let vk_delta = vec![ + vec![ + U256::from_dec_str("3845390871684034417765460290906605590268084456131570016989104541941027299587").unwrap(), + U256::from_dec_str("19451210342848170935105654531273996195376657542644165412726124373232172955450").unwrap() + ], + vec![ + U256::from_dec_str("12402386430554074306546660621773259523647713153408570111706227556424141104015").unwrap(), + U256::from_dec_str("12206340396174591766842915594324772300487750563590424709980302152249618278504").unwrap() + ] + ]; + + let vk_ic = vec![ + vec![ + U256::from_dec_str("5288881796355507035555160331041001500160990907930198297197056072823274477221").unwrap(), + U256::from_dec_str("13632806080609019911417800900671762249376036835109070627111505646509468055118").unwrap() + ], + vec![ + U256::from_dec_str("17029427908866374993625919576903554103814716934062886672833059297154117520635").unwrap(), + U256::from_dec_str("4259071212917198769064755546045521459903854045469312364340173149295579006240").unwrap() + ] + ]; + + let valid_input = vec![U256::from_dec_str("13322346319448626142").unwrap(), U256::from_dec_str("2125026056706439081").unwrap(), U256::from_dec_str("8305705901596606458").unwrap(), U256::from_dec_str("3095703818812128800").unwrap()]; + let mut encoded_call = vec![0u8; 4]; + encoded_call[0..4].copy_from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..4]); + let parameters = ethabi::encode(&[ + Token::FixedArray(proof_a.into_iter().map(Token::Uint).collect()), + Token::FixedArray(proof_b.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), + Token::FixedArray(proof_c.into_iter().map(Token::Uint).collect()), + Token::FixedArray(vk_alpha.into_iter().map(Token::Uint).collect()), + Token::FixedArray(vk_beta.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), + Token::FixedArray(vk_gamma.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), + Token::FixedArray(vk_delta.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), + Token::Array(vk_ic.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), + Token::Array(valid_input.into_iter().map(Token::Uint).collect()), + ]); + encoded_call.extend(parameters); + let gas_limit_call = 1000000; + let value = U256::default(); + let is_transactional = true; + let validate = true; + }:{ + let call_runner_results = ::Runner::call( + caller, + contract_address, + encoded_call, + value, + gas_limit_call, + Some(U256::from(1_000_000_000)), + Some(U256::from(1_000_000_000)), + None, + Vec::new(), + is_transactional, + validate, + ::config(), + ); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "Benchmarking call end.", + // ); + match call_runner_results { + Ok(info) => { + let output = info.value; + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "output result {:?}", + // output + // ); + if output.len() >= 32 { + let mut result_bytes = [0u8; 32]; + result_bytes.copy_from_slice(&output[output.len() - 32..]); + let result = U256::from_big_endian(&result_bytes); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "Verification result {result:?}", + // ); + assert_eq!(result, U256::one(), "The contract did not return true"); + } + }, + Err(e) => { + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "Benchmarking failed", + ); + } + } + } + + nconstraints_30 { + use frame_benchmarking::vec; + use sp_core::{H160, U256}; + use ethabi::Token; + + let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + + let contract_address = H160::from_low_u64_be(0x8888); + + let proof_a = vec![ + U256::from_dec_str("18690487469105583830896348523194667998180545629275814901431298749603732361922").unwrap(), + U256::from_dec_str("7368590978490025622497872418876156479561347771212306366618589942495456841309").unwrap() + ]; + + let proof_b = vec![ + vec![ + U256::from_dec_str("6458484707522958224040736264962413462988793890751266991780959428701001616723").unwrap(), + U256::from_dec_str("5229552051142880655000908369897792053786596109840647032497320533202927196186").unwrap() + ], + vec![ + U256::from_dec_str("14308631389244366765238213169645232719387098057421285153016420565820252114596").unwrap(), + U256::from_dec_str("5350276954672740804922429900678406990441626154643173671817737280965857560969").unwrap() + ], + ]; + + let proof_c = vec![ + U256::from_dec_str("2116304898851279057226756458603873842331017000957857852682949878590352582212").unwrap(), + U256::from_dec_str("4667525997409073696628336876173638225578496705097212864335627957772434988886").unwrap() + ]; + + let vk_alpha = vec![ + U256::from_dec_str("6699928044611798138494735544984517284373216312890158010790742091150243853313").unwrap(), + U256::from_dec_str("13934807201585568304844420589516599892787718850719460623808296221406392586172").unwrap() + ]; + + let vk_beta = vec![ + vec![ + U256::from_dec_str("14027097432418820340011319545278213614698987547810017425098729501416647686036").unwrap(), + U256::from_dec_str("11193668485833499271260223875108511371976490160655434826777606292642378752410").unwrap() + ], + vec![ + U256::from_dec_str("20045214665848771726931611212381067857571766687548405278435917898412573204852").unwrap(), + U256::from_dec_str("5826006366551155612056429708996305319128773563972295690836601225605275501674").unwrap() + ], + ]; + + let vk_gamma = vec![ + vec![ + U256::from_dec_str("17806409976608908367323888887822121188242647630168482212485920174169347027063").unwrap(), + U256::from_dec_str("8825456074095233176609721582085618649257862500585602911204033640423196905248").unwrap() + ], + vec![ + U256::from_dec_str("7655945321523385522603417723274574493283664938267073386365908771387240995761").unwrap(), + U256::from_dec_str("1391423751277804315942138214547478409852807217621791637137051903290468385729").unwrap() + ], + ]; + + let vk_delta = vec![ + vec![ + U256::from_dec_str("3809610967392539750715448081264997038074319458499796020415928204603377523576").unwrap(), + U256::from_dec_str("21881257755244911884500859203243891779642123470948153619959132693051710001501").unwrap() + ], + vec![ + U256::from_dec_str("18182668523718172991867827330151318111796082889349461468494480610978916492639").unwrap(), + U256::from_dec_str("18346603307568004229749993259186056067010854478467318912554191630050104816892").unwrap() + ] + ]; + + let vk_ic = vec![ + vec![ + U256::from_dec_str("18607870993123209852816319805711229553001696602336350378390522478455144860988").unwrap(), + U256::from_dec_str("15734225289122896815446339472863615677791448850890205504711357677016324894100").unwrap() + ], + vec![ + U256::from_dec_str("3677354038386268432171152235208754414542237317446575011474517892977310796611").unwrap(), + U256::from_dec_str("2220614331603226929967110674993611028989932204445910742740951381331567463169").unwrap() + ] + ]; + + let valid_input = vec![U256::from_dec_str("14321691860995553260").unwrap(), U256::from_dec_str("7152862679273281751").unwrap(), U256::from_dec_str("12752615512303817990").unwrap(), U256::from_dec_str("1576113262537949146").unwrap()]; + let mut encoded_call = vec![0u8; 4]; + encoded_call[0..4].copy_from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..4]); + let parameters = ethabi::encode(&[ + Token::FixedArray(proof_a.into_iter().map(Token::Uint).collect()), + Token::FixedArray(proof_b.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), + Token::FixedArray(proof_c.into_iter().map(Token::Uint).collect()), + Token::FixedArray(vk_alpha.into_iter().map(Token::Uint).collect()), + Token::FixedArray(vk_beta.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), + Token::FixedArray(vk_gamma.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), + Token::FixedArray(vk_delta.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), + Token::Array(vk_ic.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), + Token::Array(valid_input.into_iter().map(Token::Uint).collect()), + ]); + encoded_call.extend(parameters); + let gas_limit_call = 1000000; + let value = U256::default(); + let is_transactional = true; + let validate = true; + }:{ + let call_runner_results = ::Runner::call( + caller, + contract_address, + encoded_call, + value, + gas_limit_call, + Some(U256::from(1_000_000_000)), + Some(U256::from(1_000_000_000)), + None, + Vec::new(), + is_transactional, + validate, + ::config(), + ); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "Benchmarking call end.", + // ); + match call_runner_results { + Ok(info) => { + let output = info.value; + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "output result {:?}", + // output + // ); + if output.len() >= 32 { + let mut result_bytes = [0u8; 32]; + result_bytes.copy_from_slice(&output[output.len() - 32..]); + let result = U256::from_big_endian(&result_bytes); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "Verification result {result:?}", + // ); + assert_eq!(result, U256::one(), "The contract did not return true"); + } + }, + Err(e) => { + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "Benchmarking failed", + ); + } + } + } + + nconstraints_n_30_input_10 { + use frame_benchmarking::vec; + use sp_core::{H160, U256}; + use ethabi::Token; + + let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + + let contract_address = H160::from_low_u64_be(0x8888); + + let proof_a = vec![ + U256::from_dec_str("18690487469105583830896348523194667998180545629275814901431298749603732361922").unwrap(), + U256::from_dec_str("7368590978490025622497872418876156479561347771212306366618589942495456841309").unwrap() + ]; + + let proof_b = vec![ + vec![ + U256::from_dec_str("6458484707522958224040736264962413462988793890751266991780959428701001616723").unwrap(), + U256::from_dec_str("5229552051142880655000908369897792053786596109840647032497320533202927196186").unwrap() + ], + vec![ + U256::from_dec_str("14308631389244366765238213169645232719387098057421285153016420565820252114596").unwrap(), + U256::from_dec_str("5350276954672740804922429900678406990441626154643173671817737280965857560969").unwrap() + ], + ]; + + let proof_c = vec![ + U256::from_dec_str("2116304898851279057226756458603873842331017000957857852682949878590352582212").unwrap(), + U256::from_dec_str("4667525997409073696628336876173638225578496705097212864335627957772434988886").unwrap() + ]; + + let vk_alpha = vec![ + U256::from_dec_str("6699928044611798138494735544984517284373216312890158010790742091150243853313").unwrap(), + U256::from_dec_str("13934807201585568304844420589516599892787718850719460623808296221406392586172").unwrap() + ]; + + let vk_beta = vec![ + vec![ + U256::from_dec_str("14027097432418820340011319545278213614698987547810017425098729501416647686036").unwrap(), + U256::from_dec_str("11193668485833499271260223875108511371976490160655434826777606292642378752410").unwrap() + ], + vec![ + U256::from_dec_str("20045214665848771726931611212381067857571766687548405278435917898412573204852").unwrap(), + U256::from_dec_str("5826006366551155612056429708996305319128773563972295690836601225605275501674").unwrap() + ], + ]; + + let vk_gamma = vec![ + vec![ + U256::from_dec_str("17806409976608908367323888887822121188242647630168482212485920174169347027063").unwrap(), + U256::from_dec_str("8825456074095233176609721582085618649257862500585602911204033640423196905248").unwrap() + ], + vec![ + U256::from_dec_str("7655945321523385522603417723274574493283664938267073386365908771387240995761").unwrap(), + U256::from_dec_str("1391423751277804315942138214547478409852807217621791637137051903290468385729").unwrap() + ], + ]; + + let vk_delta = vec![ + vec![ + U256::from_dec_str("3809610967392539750715448081264997038074319458499796020415928204603377523576").unwrap(), + U256::from_dec_str("21881257755244911884500859203243891779642123470948153619959132693051710001501").unwrap() + ], + vec![ + U256::from_dec_str("18182668523718172991867827330151318111796082889349461468494480610978916492639").unwrap(), + U256::from_dec_str("18346603307568004229749993259186056067010854478467318912554191630050104816892").unwrap() + ] + ]; + + let vk_ic = vec![ + vec![ + U256::from_dec_str("18607870993123209852816319805711229553001696602336350378390522478455144860988").unwrap(), + U256::from_dec_str("15734225289122896815446339472863615677791448850890205504711357677016324894100").unwrap() + ], + vec![ + U256::from_dec_str("3677354038386268432171152235208754414542237317446575011474517892977310796611").unwrap(), + U256::from_dec_str("2220614331603226929967110674993611028989932204445910742740951381331567463169").unwrap() + ] + ]; + + let valid_input = vec![U256::from_dec_str("14321691860995553260").unwrap(), U256::from_dec_str("7152862679273281751").unwrap(), U256::from_dec_str("12752615512303817990").unwrap(), U256::from_dec_str("1576113262537949146").unwrap()]; + let mut encoded_call = vec![0u8; 4]; + encoded_call[0..4].copy_from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..4]); + let parameters = ethabi::encode(&[ + Token::FixedArray(proof_a.into_iter().map(Token::Uint).collect()), + Token::FixedArray(proof_b.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), + Token::FixedArray(proof_c.into_iter().map(Token::Uint).collect()), + Token::FixedArray(vk_alpha.into_iter().map(Token::Uint).collect()), + Token::FixedArray(vk_beta.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), + Token::FixedArray(vk_gamma.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), + Token::FixedArray(vk_delta.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), + Token::Array(vk_ic.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), + Token::Array(valid_input.into_iter().map(Token::Uint).collect()), + ]); + encoded_call.extend(parameters); + let gas_limit_call = 1000000; + let value = U256::default(); + let is_transactional = true; + let validate = true; + }:{ + let call_runner_results = ::Runner::call( + caller, + contract_address, + encoded_call, + value, + gas_limit_call, + Some(U256::from(1_000_000_000)), + Some(U256::from(1_000_000_000)), + None, + Vec::new(), + is_transactional, + validate, + ::config(), + ); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "Benchmarking call end.", + // ); + match call_runner_results { + Ok(info) => { + let output = info.value; + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "output result {:?}", + // output + // ); + if output.len() >= 32 { + let mut result_bytes = [0u8; 32]; + result_bytes.copy_from_slice(&output[output.len() - 32..]); + let result = U256::from_big_endian(&result_bytes); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "Verification result {result:?}", + // ); + assert_eq!(result, U256::one(), "The contract did not return true"); + } + }, + Err(e) => { + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "Benchmarking failed", + ); + } + } + } + + nconstraints_n_30_input_15 { + use frame_benchmarking::vec; + use sp_core::{H160, U256}; + use ethabi::Token; + + let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + + let contract_address = H160::from_low_u64_be(0x8888); + + let proof_a = vec![ + U256::from_dec_str("12887020598237220198032976835022673435562149625889668367844845965730098834830").unwrap(), + U256::from_dec_str("5547693013562036425753166956109600351181086648379743178595634512552397114069").unwrap() + ]; + + let proof_b = vec![ + vec![ + U256::from_dec_str("16962228903458078536456881207808446370619165879473741769286461031761302313925").unwrap(), + U256::from_dec_str("21359014405084746685422343887329959215710120429954270380405915213638462365773").unwrap() + ], + vec![ + U256::from_dec_str("1965804446739736522247393806555217146673165319190290198953140579215540365682").unwrap(), + U256::from_dec_str("17336220908557918009722993863856522126371082788415822133704463388052631237429").unwrap() + ], + ]; + + let proof_c = vec![ + U256::from_dec_str("21289287840088286145802499082911728754744514711185794471060410933719935352734").unwrap(), + U256::from_dec_str("7735843223624767963016539689312235639526880990688180630973191899109833388707").unwrap() + ]; + + let vk_alpha = vec![ + U256::from_dec_str("8219837847335410476943086063649040035108946850004215058051338864845204653730").unwrap(), + U256::from_dec_str("3746608922869186366337371343000548817878727551441378244314034669462645204200").unwrap() + ]; + + let vk_beta = vec![ + vec![ + U256::from_dec_str("10791921184212451462910111849505135112215560450850904575300701984074058761885").unwrap(), + U256::from_dec_str("4316039429358514857629767756887568663426369969101124991106261138164361746936").unwrap() + ], + vec![ + U256::from_dec_str("4955635812176343518126942275795640701344828035542260039596033477800959201829").unwrap(), + U256::from_dec_str("18835858855587795231442750838451623232696087390908796571380078611078267640296").unwrap() + ], + ]; + + let vk_gamma = vec![ + vec![ + U256::from_dec_str("14455985103474869293499052450161566063643705959843058655267780689179003897023").unwrap(), + U256::from_dec_str("18671940900597221048350051608932531159222193402258576279517995276727240232360").unwrap() + ], + vec![ + U256::from_dec_str("12697560912244320596982687035610656622602540075343333727038001021203210410728").unwrap(), + U256::from_dec_str("18504263146151879520679575960347812434433829897678644699385693906415996014848").unwrap() + ], + ]; + + let vk_delta = vec![ + vec![ + U256::from_dec_str("21037497448680943522446235827846511504661282584273281863975228687729637949136").unwrap(), + U256::from_dec_str("21776379845891271099314141614451177025469923146966666607913073612769825420476").unwrap() + ], + vec![ + U256::from_dec_str("11117373909154352545964641618271566801006796957927201839858282655319054162622").unwrap(), + U256::from_dec_str("8761601020737608627675880810307531774963186960493596493629509853637521319476").unwrap() + ] + ]; + + let vk_ic = vec![ + vec![ + U256::from_dec_str("14615765550099232335848106179629691206556397912266277872446949704093515221045").unwrap(), + U256::from_dec_str("6162554008291819782928114499558697072224852754500626110745064581632604362032").unwrap() + ], + vec![ + U256::from_dec_str("8566823584588002931097794273610208557671819171252077099603486344498744585143").unwrap(), + U256::from_dec_str("10591536333958951217832992999045910076326646568032772769778666286942586222933").unwrap() + ] + ]; + + let valid_input = vec![U256::from_dec_str("5692445613459621787").unwrap(), U256::from_dec_str("12028678087606031844").unwrap(), U256::from_dec_str("16634303442742113517").unwrap(), U256::from_dec_str("1607701919348517559").unwrap()]; + let mut encoded_call = vec![0u8; 4]; + encoded_call[0..4].copy_from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..4]); + let parameters = ethabi::encode(&[ + Token::FixedArray(proof_a.into_iter().map(Token::Uint).collect()), + Token::FixedArray(proof_b.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), + Token::FixedArray(proof_c.into_iter().map(Token::Uint).collect()), + Token::FixedArray(vk_alpha.into_iter().map(Token::Uint).collect()), + Token::FixedArray(vk_beta.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), + Token::FixedArray(vk_gamma.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), + Token::FixedArray(vk_delta.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), + Token::Array(vk_ic.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), + Token::Array(valid_input.into_iter().map(Token::Uint).collect()), + ]); + encoded_call.extend(parameters); + let gas_limit_call = 1000000; + let value = U256::default(); + let is_transactional = true; + let validate = true; + }:{ + let call_runner_results = ::Runner::call( + caller, + contract_address, + encoded_call, + value, + gas_limit_call, + Some(U256::from(1_000_000_000)), + Some(U256::from(1_000_000_000)), + None, + Vec::new(), + is_transactional, + validate, + ::config(), + ); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "Benchmarking call end.", + // ); + match call_runner_results { + Ok(info) => { + let output = info.value; + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "output result {:?}", + // output + // ); + if output.len() >= 32 { + let mut result_bytes = [0u8; 32]; + result_bytes.copy_from_slice(&output[output.len() - 32..]); + let result = U256::from_big_endian(&result_bytes); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "Verification result {result:?}", + // ); + assert_eq!(result, U256::one(), "The contract did not return true"); + } + }, + Err(e) => { + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "Benchmarking failed", + ); + } + } + } + + nconstraints_n_30_input_20 { + use frame_benchmarking::vec; + use sp_core::{H160, U256}; + use ethabi::Token; + + let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + + let contract_address = H160::from_low_u64_be(0x8888); + + let proof_a = vec![ + U256::from_dec_str("675300276299245578591094709236990240708914273209938055982582668214795758174").unwrap(), + U256::from_dec_str("13990735151356840356168472337981584444541365401592649678306674505655642720744").unwrap(), + ]; + + let proof_b = vec![ + vec![ + U256::from_dec_str("20662974626567138590845164891104877742207018449180572731972302829490961465377").unwrap(), + U256::from_dec_str("17980826672123191014823546738817744353214706462261563577840570306372367452611").unwrap(), + ], + vec![ + U256::from_dec_str("16771588723175231559633339886504703803804691684198872315901738104890051757400").unwrap(), + U256::from_dec_str("15483086789303204255210084974843463497785089107989053404746931842499188347781").unwrap(), + ], + ]; + + let proof_c = vec![ + U256::from_dec_str("10803326508903591698850591270453065951979818405855788885186501914161310127604").unwrap(), + U256::from_dec_str("7463976916832770397677605389090326852042103199297295653656426503462443575095").unwrap(), + ]; + + let vk_alpha = vec![ + U256::from_dec_str("17808795307067734350448942252050504857802750572499920704974512866462124896173").unwrap(), + U256::from_dec_str("17115681179782086865134005803599891667690289004882667885655096788650956914423").unwrap(), + ]; + + let vk_beta = vec![ + vec![ + U256::from_dec_str("19972461112908818195114127269905083158285147872659880745754440161709753445934").unwrap(), + U256::from_dec_str("5931352730208730296622877139521064931325621630284477295549537572620163532752").unwrap(), + ], + vec![ + U256::from_dec_str("2882185593168745381926882623953300896502789920459989016767915325150853635011").unwrap(), + U256::from_dec_str("18631580128182038958786817732606869739243773104340288087215229087084869651401").unwrap(), + ], + ]; + + let vk_gamma = vec![ + vec![ + U256::from_dec_str("851770636198195762853634545486979938053193628863032188824852166527357841269").unwrap(), + U256::from_dec_str("14031995609625725240579021647119854585086016231593377303976803993039287310339").unwrap(), + ], + vec![ + U256::from_dec_str("20686783438308398939975162795637102332306903166807161288857973107679921334009").unwrap(), + U256::from_dec_str("2532011633268289192635445441332602676050528250745931428259769182816495045641").unwrap(), + ], + ]; + + let vk_delta = vec![ + vec![ + U256::from_dec_str("14714684631646051284376146303759912153045379177454388567159304861853969170973").unwrap(), + U256::from_dec_str("21581087789843023955779607070023575401154216928170460432554645594586663631552").unwrap(), + ], + vec![ + U256::from_dec_str("18800497152775773104784586380904309935376489820003075987643947940762274526501").unwrap(), + U256::from_dec_str("17553212126947187473201629145084482836990004337579399572737167549853121474562").unwrap(), + ] + ]; + + let vk_ic = vec![ + vec![ + U256::from_dec_str("7232111346224912559397152061373338385516036432961030742660350233926241518205").unwrap(), + U256::from_dec_str("1312106886866516986858011448492089642322868115679821300916062234780269911574").unwrap(), + ], + vec![ + U256::from_dec_str("6433608899686307828382554879645744712090018725772338372746278420606357265684").unwrap(), + U256::from_dec_str("10454877373084482498589840527780357413752247536960233289477564876826588932778").unwrap(), + ] + ]; + + let valid_input = vec![U256::from_dec_str("3912017569823150797").unwrap(), U256::from_dec_str("13734487482202628151").unwrap(), U256::from_dec_str("17621575820406120931").unwrap(), U256::from_dec_str("942862921734396008").unwrap()]; + let mut encoded_call = vec![0u8; 4]; + encoded_call[0..4].copy_from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..4]); + let parameters = ethabi::encode(&[ + Token::FixedArray(proof_a.into_iter().map(Token::Uint).collect()), + Token::FixedArray(proof_b.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), + Token::FixedArray(proof_c.into_iter().map(Token::Uint).collect()), + Token::FixedArray(vk_alpha.into_iter().map(Token::Uint).collect()), + Token::FixedArray(vk_beta.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), + Token::FixedArray(vk_gamma.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), + Token::FixedArray(vk_delta.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), + Token::Array(vk_ic.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), + Token::Array(valid_input.into_iter().map(Token::Uint).collect()), + ]); + encoded_call.extend(parameters); + let gas_limit_call = 1000000; + let value = U256::default(); + let is_transactional = true; + let validate = true; + }:{ + let call_runner_results = ::Runner::call( + caller, + contract_address, + encoded_call, + value, + gas_limit_call, + Some(U256::from(1_000_000_000)), + Some(U256::from(1_000_000_000)), + None, + Vec::new(), + is_transactional, + validate, + ::config(), + ); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "Benchmarking call end.", + // ); + match call_runner_results { + Ok(info) => { + let output = info.value; + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "output result {:?}", + // output + // ); + if output.len() >= 32 { + let mut result_bytes = [0u8; 32]; + result_bytes.copy_from_slice(&output[output.len() - 32..]); + let result = U256::from_big_endian(&result_bytes); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "Verification result {result:?}", + // ); + assert_eq!(result, U256::one(), "The contract did not return true"); + } + }, + Err(e) => { + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "Benchmarking failed", + ); + } + } + } + + + nconstraints_n_30_input_25 { + use frame_benchmarking::vec; + use sp_core::{H160, U256}; + use ethabi::Token; + + let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + + let contract_address = H160::from_low_u64_be(0x8888); + + let proof_a = vec![ + U256::from_dec_str("16006545354898718229260951824688742329434625591330021352594388758149873016896").unwrap(), + U256::from_dec_str("1468205165503169447069936905882957144235585999244028403117646701884216745392").unwrap(), + ]; + + let proof_b = vec![ + vec![ + U256::from_dec_str("8852923839895344533619890530783168672405232228640552748869548310905734934401").unwrap(), + U256::from_dec_str("14205972468980433410756631183566705893026836831976200390499104030484143466072").unwrap(), + ], + vec![ + U256::from_dec_str("5273488309799458449304345924433747290680464512658479589035286165842771509674").unwrap(), + U256::from_dec_str("16380658691502717574062613685364050177124879164561079589092985937963750638698").unwrap(), + ], + ]; + + let proof_c = vec![ + U256::from_dec_str("20115812596296892999368823778004624226181425602585514202472590919479136110663").unwrap(), + U256::from_dec_str("4894925383921626127869982825697178632493733742654662142214903567620044651205").unwrap(), + ]; + + let vk_alpha = vec![ + U256::from_dec_str("7941376557483595089971660523849374119116282550293913525516084066171760665760").unwrap(), + U256::from_dec_str("11518059386572304338895027869539849446766258314854264516705855524316523480782").unwrap(), + ]; + + let vk_beta = vec![ + vec![ + U256::from_dec_str("6169389823915190479258473920339684633183862258518826493764760771800535359821").unwrap(), + U256::from_dec_str("17130452746849022487073859340540869381062009205302178500507024318010199396952").unwrap(), + ], + vec![ + U256::from_dec_str("2318544008261920780923055770521739382224787976556999331708881512332672347971").unwrap(), + U256::from_dec_str("1745424225911873055606510145529079726501693479367526857564720869880667302655").unwrap(), + ], + ]; + + let vk_gamma = vec![ + vec![ + U256::from_dec_str("623010707232623462659826601801211232554955056016532044807183015392365318482").unwrap(), + U256::from_dec_str("865232306164050822814381934297685639795963777883253356917760252650841495108").unwrap(), + ], + vec![ + U256::from_dec_str("20499284403708841372819161133131038743430624942488488352074984316323625475649").unwrap(), + U256::from_dec_str("8586534605108047515719534665260604577359156625952909070129967685099418328393").unwrap(), + ], + ]; + + let vk_delta = vec![ + vec![ + U256::from_dec_str("17466746742513346286036517376644263104859467956003283191454165897758552595857").unwrap(), + U256::from_dec_str("5311323701152602220187351314264762414138054616620164066845262834294902529310").unwrap(), + ], + vec![ + U256::from_dec_str("21683159430467589572447310729564760337034354389144135006135111895877568793948").unwrap(), + U256::from_dec_str("14137150650205647732181183821072311493301762612748140449230051456997255133827").unwrap(), + ] + ]; + + let vk_ic = vec![ + vec![ + U256::from_dec_str("7587790987123565575798590220561861914433653529800504392689910235318401885521").unwrap(), + U256::from_dec_str("838359042085515464552622656979816858987026153105984521769778297124070509054").unwrap(), + ], + vec![ + U256::from_dec_str("13124708479886510248630494255189994749135078654655301928099114054732758024498").unwrap(), + U256::from_dec_str("10651906791373118981569686350085926733476784541744614206187906526770681605261").unwrap(), + ] + ]; + + let valid_input = vec![U256::from_dec_str("1514079710047709751").unwrap(), U256::from_dec_str("9927892042756486157").unwrap(), U256::from_dec_str("6795743742855535984").unwrap(), U256::from_dec_str("3178922015906793710").unwrap()]; + let mut encoded_call = vec![0u8; 4]; + encoded_call[0..4].copy_from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..4]); + let parameters = ethabi::encode(&[ + Token::FixedArray(proof_a.into_iter().map(Token::Uint).collect()), + Token::FixedArray(proof_b.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), + Token::FixedArray(proof_c.into_iter().map(Token::Uint).collect()), + Token::FixedArray(vk_alpha.into_iter().map(Token::Uint).collect()), + Token::FixedArray(vk_beta.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), + Token::FixedArray(vk_gamma.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), + Token::FixedArray(vk_delta.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), + Token::Array(vk_ic.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), + Token::Array(valid_input.into_iter().map(Token::Uint).collect()), + ]); + encoded_call.extend(parameters); + let gas_limit_call = 1000000; + let value = U256::default(); + let is_transactional = true; + let validate = true; + }:{ + let call_runner_results = ::Runner::call( + caller, + contract_address, + encoded_call, + value, + gas_limit_call, + Some(U256::from(1_000_000_000)), + Some(U256::from(1_000_000_000)), + None, + Vec::new(), + is_transactional, + validate, + ::config(), + ); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "Benchmarking call end.", + // ); + match call_runner_results { + Ok(info) => { + let output = info.value; + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "output result {:?}", + // output + // ); + if output.len() >= 32 { + let mut result_bytes = [0u8; 32]; + result_bytes.copy_from_slice(&output[output.len() - 32..]); + let result = U256::from_big_endian(&result_bytes); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "Verification result {result:?}", + // ); + assert_eq!(result, U256::one(), "The contract did not return true"); + } + }, + Err(e) => { + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "Benchmarking failed", + ); + } + } + } + nconstraints_n_30_input_30 { use frame_benchmarking::vec; use sp_core::{H160, U256}; use ethabi::Token; @@ -16,76 +1334,76 @@ benchmarks! { let contract_address = H160::from_low_u64_be(0x8888); let proof_a = vec![ - U256::from_dec_str("13202079600221154376862161785979680082984660469505374274880948735521253479994").unwrap(), - U256::from_dec_str("19032139815435908179959144311759562497239236177745989139113028703727512477837").unwrap() + U256::from_dec_str("192383223808332879678223120765873656071487020594757668859947327172062021463").unwrap(), + U256::from_dec_str("20631800377548143112330602909240361504775196179042765937715471405374872743424").unwrap(), ]; let proof_b = vec![ vec![ - U256::from_dec_str("9517359327043802798811688827065407805934924568686293993682568334305900037151").unwrap(), - U256::from_dec_str("13975418982386111217378923290980800393212535787789845393400867460398182717751").unwrap() + U256::from_dec_str("2386546353880304173552960655436514856580592658425839135191217698540932917221").unwrap(), + U256::from_dec_str("8483190656320044020998407034485182750694926538145978907506797577826038755937").unwrap(), ], vec![ - U256::from_dec_str("11101434469251848949317000686121782094334155840067455941163819739470030872205").unwrap(), - U256::from_dec_str("3351121397470969456277617123820147601817413346203636355523709813813837616699").unwrap() + U256::from_dec_str("7615954358803953940045634219422206780946884331580120097208882088362520213892").unwrap(), + U256::from_dec_str("17492892761336449552765644207249662635220549371874833325304908992711325096838").unwrap(), ], ]; let proof_c = vec![ - U256::from_dec_str("21771166379144524714497801611702430117390298454683954881352912868492853507834").unwrap(), - U256::from_dec_str("5971832614272362565584439633663845994795381011258125087840397908182066694531").unwrap() + U256::from_dec_str("14898385768534632459299431757788181862062037231423680879935547707181434062217").unwrap(), + U256::from_dec_str("3670993976640187257001986589710513145495904997157462001138713422198967083793").unwrap(), ]; let vk_alpha = vec![ - U256::from_dec_str("7318409901911144874440195167086183143676595981815053389579728623121590098440").unwrap(), - U256::from_dec_str("18845965879715444612950452554360629789407129470518446134938217746489723713219").unwrap() + U256::from_dec_str("18003389266700451535185768250385473623576088268017984044335576780485413288725").unwrap(), + U256::from_dec_str("10280152748134343381057553800219778246761591399803713656295141924124651318322").unwrap(), ]; let vk_beta = vec![ vec![ - U256::from_dec_str("4640649673239597789758809808535118135578677216672702870175791505196312738305").unwrap(), - U256::from_dec_str("13141288066376351908866878766575256664575916601245245304316354941350328880142").unwrap() + U256::from_dec_str("15705711023641709606059988467186697257075093473077719904710509531659151640887").unwrap(), + U256::from_dec_str("13926583045600156240485358993385159153394021178689044035959053205092441158347").unwrap(), ], vec![ - U256::from_dec_str("11492338667195076401975872253943030431149343004937779351839311477974294172860").unwrap(), - U256::from_dec_str("17604387530215185597479117283681563543587978658046512716245947218617178983155").unwrap() + U256::from_dec_str("2133281544711261852175935529948152371794373217468774127814272513506339581229").unwrap(), + U256::from_dec_str("15266525202021918250529116255077653452497658133580868510244476123771794689087").unwrap(), ], ]; let vk_gamma = vec![ vec![ - U256::from_dec_str("10857046999023057135944570762232829481370756359578518086990519993285655852781").unwrap(), - U256::from_dec_str("11559732032986387107991004021392285783925812861821192530917403151452391805634").unwrap() + U256::from_dec_str("5860932391264318788101713658077318120931708405538141099278626653654316360162").unwrap(), + U256::from_dec_str("18777995924606299529855429493114686078258294137554638538976277652307549742619").unwrap(), ], vec![ - U256::from_dec_str("8495653923123431417604973247489272438418190587263600148770280649306958101930").unwrap(), - U256::from_dec_str("4082367875863433681332203403145435568316851327593401208105741076214120093531").unwrap() + U256::from_dec_str("18381097066271335811045821138274998569498024818257561362659949818983456872550").unwrap(), + U256::from_dec_str("13352938901259724996725843903559730864557166420786660986703127196904357078738").unwrap(), ], ]; let vk_delta = vec![ vec![ - U256::from_dec_str("5882870888685857628232224840789532289346124290586616915986585508513239272539").unwrap(), - U256::from_dec_str("8206718104089392401855946495573733123991363841198873660903571227166120193870").unwrap() + U256::from_dec_str("14145680588609876894681651972036258026026055123025250786927547400650826638120").unwrap(), + U256::from_dec_str("11416850029017788620938610876201750823987651931635585676983799773100880269198").unwrap(), ], vec![ - U256::from_dec_str("14275677868038957349366208693756706908778821863795564855498136614399516409168").unwrap(), - U256::from_dec_str("20950579407520036072561845357324335488555384097745021047033651867265123837403").unwrap() + U256::from_dec_str("17147929122794757054114222102821483783601496318354908417750078988687436213430").unwrap(), + U256::from_dec_str("2750254376147201225382240026981296587762562040528353782979098667468106833906").unwrap(), ] ]; let vk_ic = vec![ vec![ - U256::from_dec_str("15329034480187562940265095627808115353397553736992059710948268284574612609224").unwrap(), - U256::from_dec_str("13272704791638435782238987852007128987814629753205340563304933194747762248428").unwrap() + U256::from_dec_str("11111422270719484684442669128605095987218378443749504485297022350994995674515").unwrap(), + U256::from_dec_str("9009256400033220730477021494653362520677702130766423677465372172912927069348").unwrap(), ], vec![ - U256::from_dec_str("17269839325091679315052274785558946544729609490743199699197195008879157661695").unwrap(), - U256::from_dec_str("4142750859697696641705372803120309740931359230261851701215055719438325633654").unwrap() + U256::from_dec_str("711398778459754876097070294398450479822869186578007297816303943615642796091").unwrap(), + U256::from_dec_str("19953433553885418442641654921645346560623468995060701812216801687443587349442").unwrap(), ] ]; - let valid_input = vec![U256::from(66)]; + let valid_input = vec![U256::from_dec_str("961725266697111609").unwrap(), U256::from_dec_str("7616088020774934521").unwrap(), U256::from_dec_str("4985267006460356416").unwrap(), U256::from_dec_str("1376874925466056414").unwrap()]; let mut encoded_call = vec![0u8; 4]; encoded_call[0..4].copy_from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..4]); let parameters = ethabi::encode(&[ diff --git a/runtime/testnet/src/lib.rs b/runtime/testnet/src/lib.rs index 90d4fc3e..1d269b87 100644 --- a/runtime/testnet/src/lib.rs +++ b/runtime/testnet/src/lib.rs @@ -401,6 +401,11 @@ parameter_types! { // For weight estimation, we assume that the most locks on an individual account will be 50. // This number may need to be adjusted in the future if this assumption no longer holds true. pub const MaxLocks: u32 = 50; + + // The minimum balance that an account must have in order to be kept alive on-chain. + // This value is used by the Balances pallet to determine if an account should be + // kept alive or if it should be reaped to free up storage space. + pub const ExistentialDeposit: Balance = EXISTENTIAL_DEPOSIT; } impl pallet_balances::Config for Runtime { @@ -409,7 +414,7 @@ impl pallet_balances::Config for Runtime { type DustRemoval = (); /// The ubiquitous event type. type RuntimeEvent = RuntimeEvent; - type ExistentialDeposit = ConstU128; + type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; type WeightInfo = pallet_balances::weights::SubstrateWeight; type MaxLocks = MaxLocks; From bb92a512eede8af3cdc4d54cf7063f02902c29b1 Mon Sep 17 00:00:00 2001 From: luckychacha <358140284@qq.com> Date: Tue, 8 Aug 2023 18:52:28 +0800 Subject: [PATCH 17/34] Add some benchmarking. --- precompiles/zk-groth16-verify/src/lib.rs | 16 +- .../benchmarking.rs | 3493 ++++++++++------- .../src/zk_precompile_gas_estimation/tests.rs | 60 +- 3 files changed, 2200 insertions(+), 1369 deletions(-) diff --git a/precompiles/zk-groth16-verify/src/lib.rs b/precompiles/zk-groth16-verify/src/lib.rs index 5da413a2..3cef36cc 100644 --- a/precompiles/zk-groth16-verify/src/lib.rs +++ b/precompiles/zk-groth16-verify/src/lib.rs @@ -9,6 +9,7 @@ use ark_crypto_primitives::snark::SNARK; use ark_groth16::Groth16; use ark::{ark_bn254_fr, ark_bn254_g1, ark_bn254_g2}; +use ark_std::format; use precompile_utils::{EvmDataReader, EvmDataWriter}; pub struct ZKGroth16Verify; @@ -95,7 +96,11 @@ impl ZKGroth16Verify { .chunks_exact(32) .map(ark_bn254_fr) .collect(); - + log::debug!( + target: "precompiles::zk_groth16_verify::execute", + "Pub_inputs: {:?}", + pub_inputs + ); let vk: ark_groth16::VerifyingKey> = ark_groth16::VerifyingKey { alpha_g1: vk_alpha, @@ -110,8 +115,13 @@ impl ZKGroth16Verify { vk ); - let verified = Groth16::::verify(&vk, &pub_inputs, &proof) - .map_err(|_e| PrecompileFailure::from(ExitError::InvalidRange))?; + let verified = + Groth16::::verify(&vk, &pub_inputs, &proof).map_err(|e| { + let error_message = format!("{}", e); // Convert the error to a string + PrecompileFailure::Error { + exit_status: ExitError::Other(error_message.into()), + } + })?; log::debug!( target: "precompiles::zk_groth16_verify::execute", diff --git a/runtime/runtime-common/src/zk_precompile_gas_estimation/benchmarking.rs b/runtime/runtime-common/src/zk_precompile_gas_estimation/benchmarking.rs index 2df3456d..be1abd5f 100644 --- a/runtime/runtime-common/src/zk_precompile_gas_estimation/benchmarking.rs +++ b/runtime/runtime-common/src/zk_precompile_gas_estimation/benchmarking.rs @@ -1,263 +1,264 @@ -// #![cfg(feature = "runtime-benchmarks")] - use super::*; use frame_benchmarking::{benchmarks, impl_benchmark_test_suite}; // frontier +use ethabi::Token; +use frame_benchmarking::vec; use pallet_evm::Runner; +use sp_core::{H256, U256}; use sp_std::prelude::*; -struct VerifyingKey { - proof_a: Vec, - proof_b: Vec>, - proof_c: Vec, - vk_alpha: Vec, - vk_beta: Vec>, - vk_gamma: Vec>, - vk_delta: Vec>, - vk_ic: Vec>, - valid_input: Vec, +struct ZKPrecompileVerifier { + selector: H256, + verifying_key: VerifyingKey, } -benchmarks! { - nconstraints_10 { - use frame_benchmarking::vec; - use sp_core::{H160, U256}; - use ethabi::Token; - - let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); - - let contract_address = H160::from_low_u64_be(0x8888); - - let proof_a = vec![ - U256::from_dec_str("323654832133639084097738656057999026789295280666886852594984576709163539526").unwrap(), - U256::from_dec_str("6142957218280645039826855630872622613337777761157366378615236951849913775542").unwrap() - ]; - - let proof_b = vec![ - vec![ - U256::from_dec_str("3781402603457401622553078625624300084337446058890012151530042647448923283156").unwrap(), - U256::from_dec_str("3517436796495769146106898128956048233729888622957356948216773257280783319311").unwrap() - ], - vec![ - U256::from_dec_str("18697717875318192535466611481750571094853863458428844875498420533596881568336").unwrap(), - U256::from_dec_str("21426423909981695530725752097567643188095093768132522705564475372400085021436").unwrap() - ], - ]; +struct VerifyingKey { + proof: Proof, + vk: VerifyingKeyComponents, + public_input: Vec, +} - let proof_c = vec![ - U256::from_dec_str("21613404883582191576526635676329374200679201344239432919502376530553941450391").unwrap(), - U256::from_dec_str("15157755445966041962464884593780030869511182260822371637833098723763718514455").unwrap() - ]; +struct Proof { + a: Vec, + b: Vec>, + c: Vec, +} - let vk_alpha = vec![ - U256::from_dec_str("11521346682463921906610271064518766485088278761420928386309550940286650671457").unwrap(), - U256::from_dec_str("14352830518175561380348856554041231805603495989169432000725584250110291361678").unwrap() - ]; +struct VerifyingKeyComponents { + alpha: Vec, + beta: Vec>, + gamma: Vec>, + delta: Vec>, + ic: Vec>, +} - let vk_beta = vec![ - vec![ - U256::from_dec_str("15782596638536803844844408481637582589736413871396993858917786753770876529739").unwrap(), - U256::from_dec_str("14911823231521430202833448929652297782496660742577343858219844871404504144036").unwrap() - ], - vec![ - U256::from_dec_str("2082222914940990020573243578958386229340150899029559516350605378857473031525").unwrap(), - U256::from_dec_str("13498996195230132373906915048494917069165130851394909752977335076805840989307").unwrap() - ], - ]; +impl ZKPrecompileVerifier { + pub fn new(selector: H256, verifying_key: VerifyingKey) -> Self { + Self { + selector, + verifying_key, + } + } +} - let vk_gamma = vec![ - vec![ - U256::from_dec_str("3598021131780341035246011324427156192540414244243113294885735792953741606880").unwrap(), - U256::from_dec_str("2036084172531515709709771052774738245922046202318890723044728246225539963428").unwrap() - ], - vec![ - U256::from_dec_str("5925457711548235099025126547368719549508643015841982506039250719340224619945").unwrap(), - U256::from_dec_str("6297446610567432982066083461547400065680646594595441716191878482607632761242").unwrap() - ], - ]; +impl VerifyingKey { + pub fn new(proof: Proof, vk: VerifyingKeyComponents, public_input: Vec) -> Self { + Self { + proof, + vk, + public_input, + } + } +} - let vk_delta = vec![ - vec![ - U256::from_dec_str("8540596677770285018018336727251534074846909511956041125063939097422779191925").unwrap(), - U256::from_dec_str("4004145476643750015352094786522189637304633549022019774555222068038038169997").unwrap() - ], - vec![ - U256::from_dec_str("14044576757821380530542904664046256148829410228513509672845139471539338485558").unwrap(), - U256::from_dec_str("21655834928283484760531472827487408029775629615266614212974138202212982461041").unwrap() - ] - ]; +impl Proof { + pub fn new(a: Vec, b: Vec>, c: Vec) -> Self { + Self { a, b, c } + } +} - let vk_ic = vec![ - vec![ - U256::from_dec_str("18160015955331442477546361309657533914485780296451278252095683998154112390415").unwrap(), - U256::from_dec_str("2421052745427024367257863480713357899822722660532800486395996070904226714086").unwrap() - ], - vec![ - U256::from_dec_str("13418845437340247256566377432948869602549774753220761674399899795516131627829").unwrap(), - U256::from_dec_str("19073971532401628571532840417056837528958340897410372352356543204393028153748").unwrap() - ] - ]; +impl VerifyingKeyComponents { + pub fn new( + alpha: Vec, + beta: Vec>, + gamma: Vec>, + delta: Vec>, + ic: Vec>, + ) -> Self { + Self { + alpha, + beta, + gamma, + delta, + ic, + } + } +} - let valid_input = vec![U256::from_dec_str("14965631224775206224").unwrap(), U256::from_dec_str("3021577815302938909").unwrap(), U256::from_dec_str("14359293880404272991").unwrap(), U256::from_dec_str("1555005537055779113").unwrap()]; +impl ZKPrecompileVerifier { + pub fn generate_benchmarking_parameters(&self) -> Vec { let mut encoded_call = vec![0u8; 4]; - encoded_call[0..4].copy_from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..4]); + encoded_call[0..4].copy_from_slice(&self.selector.as_bytes()[0..4]); + let parameters = ethabi::encode(&[ - Token::FixedArray(proof_a.into_iter().map(Token::Uint).collect()), - Token::FixedArray(proof_b.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), - Token::FixedArray(proof_c.into_iter().map(Token::Uint).collect()), - Token::FixedArray(vk_alpha.into_iter().map(Token::Uint).collect()), - Token::FixedArray(vk_beta.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), - Token::FixedArray(vk_gamma.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), - Token::FixedArray(vk_delta.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), - Token::Array(vk_ic.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), - Token::Array(valid_input.into_iter().map(Token::Uint).collect()), + Token::FixedArray( + self.verifying_key + .proof + .a + .clone() + .into_iter() + .map(Token::Uint) + .collect(), + ), + Token::FixedArray( + self.verifying_key + .proof + .b + .clone() + .into_iter() + .map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())) + .collect(), + ), + Token::FixedArray( + self.verifying_key + .proof + .c + .clone() + .into_iter() + .map(Token::Uint) + .collect(), + ), + Token::FixedArray( + self.verifying_key + .vk + .alpha + .clone() + .into_iter() + .map(Token::Uint) + .collect(), + ), + Token::FixedArray( + self.verifying_key + .vk + .beta + .clone() + .into_iter() + .map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())) + .collect(), + ), + Token::FixedArray( + self.verifying_key + .vk + .gamma + .clone() + .into_iter() + .map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())) + .collect(), + ), + Token::FixedArray( + self.verifying_key + .vk + .delta + .clone() + .into_iter() + .map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())) + .collect(), + ), + Token::Array( + self.verifying_key + .vk + .ic + .clone() + .into_iter() + .map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())) + .collect(), + ), + Token::Array( + self.verifying_key + .public_input + .clone() + .into_iter() + .map(Token::Uint) + .collect(), + ), ]); encoded_call.extend(parameters); - let gas_limit_call = 1000000; - let value = U256::default(); - let is_transactional = true; - let validate = true; - }:{ - let call_runner_results = ::Runner::call( - caller, - contract_address, - encoded_call, - value, - gas_limit_call, - Some(U256::from(1_000_000_000)), - Some(U256::from(1_000_000_000)), - None, - Vec::new(), - is_transactional, - validate, - ::config(), - ); - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "Benchmarking call end.", - // ); - match call_runner_results { - Ok(info) => { - let output = info.value; - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "output result {:?}", - // output - // ); - if output.len() >= 32 { - let mut result_bytes = [0u8; 32]; - result_bytes.copy_from_slice(&output[output.len() - 32..]); - let result = U256::from_big_endian(&result_bytes); - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "Verification result {result:?}", - // ); - assert_eq!(result, U256::one(), "The contract did not return true"); - } - }, - Err(e) => { - log::info!( - target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - "Benchmarking failed", - ); - } - } + encoded_call } +} - nconstraints_15 { +benchmarks! { + nconstraints_10 { use frame_benchmarking::vec; - use sp_core::{H160, U256}; - use ethabi::Token; + use sp_core::{H160, U256, H256}; let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); - let contract_address = H160::from_low_u64_be(0x8888); - let proof_a = vec![ - U256::from_dec_str("20130649533606132941076532567185186533385627048731412173183395399598706653722").unwrap(), - U256::from_dec_str("5013302449315195110728085938922390324181635865643940685717581319642064255185").unwrap() - ]; - - let proof_b = vec![ + let proof = Proof::new( vec![ - U256::from_dec_str("182349185274378562733946998188496702865899889969489490693307112376287220894").unwrap(), - U256::from_dec_str("21774901779074752042085216201094185472133753187176013828342990679080664340226").unwrap() + U256::from_dec_str("323654832133639084097738656057999026789295280666886852594984576709163539526").unwrap(), + U256::from_dec_str("6142957218280645039826855630872622613337777761157366378615236951849913775542").unwrap() ], vec![ - U256::from_dec_str("5869802804905785526619333457887737025688889410113776710579029089235110697192").unwrap(), - U256::from_dec_str("11299229682492002119651745673740140812409219814076852306943005451224291551902").unwrap() + vec![ + U256::from_dec_str("3781402603457401622553078625624300084337446058890012151530042647448923283156").unwrap(), + U256::from_dec_str("3517436796495769146106898128956048233729888622957356948216773257280783319311").unwrap() + ], + vec![ + U256::from_dec_str("18697717875318192535466611481750571094853863458428844875498420533596881568336").unwrap(), + U256::from_dec_str("21426423909981695530725752097567643188095093768132522705564475372400085021436").unwrap() + ], ], - ]; - - let proof_c = vec![ - U256::from_dec_str("20185206171191904498488721605780661105586137132655998116453037531151235420138").unwrap(), - U256::from_dec_str("10384110586589833558642758431697087208638469907021113041447281049306264412338").unwrap() - ]; + vec![ + U256::from_dec_str("21613404883582191576526635676329374200679201344239432919502376530553941450391").unwrap(), + U256::from_dec_str("15157755445966041962464884593780030869511182260822371637833098723763718514455").unwrap() + ] + ); - let vk_alpha = vec![ - U256::from_dec_str("16518131354665416356366619968057793725998398101013238576312579236126088696774").unwrap(), - U256::from_dec_str("16092603482186593319494034095089381923094130901686564523346715807012185857162").unwrap() - ]; + let vk = VerifyingKeyComponents::new( + vec![ + U256::from_dec_str("11521346682463921906610271064518766485088278761420928386309550940286650671457").unwrap(), + U256::from_dec_str("14352830518175561380348856554041231805603495989169432000725584250110291361678").unwrap() + ], + vec![ + vec![ + U256::from_dec_str("15782596638536803844844408481637582589736413871396993858917786753770876529739").unwrap(), + U256::from_dec_str("14911823231521430202833448929652297782496660742577343858219844871404504144036").unwrap() + ], + vec![ + U256::from_dec_str("2082222914940990020573243578958386229340150899029559516350605378857473031525").unwrap(), + U256::from_dec_str("13498996195230132373906915048494917069165130851394909752977335076805840989307").unwrap() + ], + ], + vec![ + vec![ + U256::from_dec_str("3598021131780341035246011324427156192540414244243113294885735792953741606880").unwrap(), + U256::from_dec_str("2036084172531515709709771052774738245922046202318890723044728246225539963428").unwrap() + ], + vec![ + U256::from_dec_str("5925457711548235099025126547368719549508643015841982506039250719340224619945").unwrap(), + U256::from_dec_str("6297446610567432982066083461547400065680646594595441716191878482607632761242").unwrap() + ], + ], + vec![ + vec![ + U256::from_dec_str("8540596677770285018018336727251534074846909511956041125063939097422779191925").unwrap(), + U256::from_dec_str("4004145476643750015352094786522189637304633549022019774555222068038038169997").unwrap() + ], + vec![ + U256::from_dec_str("14044576757821380530542904664046256148829410228513509672845139471539338485558").unwrap(), + U256::from_dec_str("21655834928283484760531472827487408029775629615266614212974138202212982461041").unwrap() + ] + ], + vec![ + vec![ + U256::from_dec_str("18160015955331442477546361309657533914485780296451278252095683998154112390415").unwrap(), + U256::from_dec_str("2421052745427024367257863480713357899822722660532800486395996070904226714086").unwrap() + ], + vec![ + U256::from_dec_str("13418845437340247256566377432948869602549774753220761674399899795516131627829").unwrap(), + U256::from_dec_str("19073971532401628571532840417056837528958340897410372352356543204393028153748").unwrap() + ] + ] + ); - let vk_beta = vec![ - vec![ - U256::from_dec_str("21734430847137516428081497368042335428479760179384429208483228211390870007889").unwrap(), - U256::from_dec_str("4340802082106264411360501616317193563940246579398950954214582760982827315863").unwrap() - ], - vec![ - U256::from_dec_str("12447957849620237825007220112503702667357790011364771059885655868800342557822").unwrap(), - U256::from_dec_str("14809511833945059264202963765646411224042099188929021476112339598771762711323").unwrap() - ], + let valid_input = vec![ + U256::from_dec_str("14965631224775206224").unwrap(), + U256::from_dec_str("3021577815302938909").unwrap(), + U256::from_dec_str("14359293880404272991").unwrap(), + U256::from_dec_str("1555005537055779113").unwrap() ]; - let vk_gamma = vec![ - vec![ - U256::from_dec_str("17324242037467178377673475424723060403816978313062414185741167494411363117422").unwrap(), - U256::from_dec_str("573707969764376568308084515022276929250394811599970857666617570109713369226").unwrap() - ], - vec![ - U256::from_dec_str("7128237379235615126712368859451728796195891617721045758701935689078823845047").unwrap(), - U256::from_dec_str("10251648689582024203541816575587863025500039856770502839005077409839562057857").unwrap() - ], - ]; + let verifying_key = VerifyingKey::new(proof, vk, valid_input); - let vk_delta = vec![ - vec![ - U256::from_dec_str("10606414414773769335220870560841720522962914580715128022037427553027383133468").unwrap(), - U256::from_dec_str("17945431494760095084161450708936397005964902805999383045150147654106302962212").unwrap() - ], - vec![ - U256::from_dec_str("1114602509780071710197893478088881134916626713904515339987079398421518390581").unwrap(), - U256::from_dec_str("193998821630871240239454478188468337135142017574640889316476264339168416109").unwrap() - ] - ]; + let zk_verifier = ZKPrecompileVerifier::new( + H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), + verifying_key + ); - let vk_ic = vec![ - vec![ - U256::from_dec_str("5962671215665825419481336630213008800754405882212434260146565927291026766869").unwrap(), - U256::from_dec_str("16048419286366094768895756097008850316935017795185761633869316473249446959923").unwrap() - ], - vec![ - U256::from_dec_str("11963041201807212594527101484518323233884176930563963184262271167850375002702").unwrap(), - U256::from_dec_str("18844805358753225197609605824296109138813209675865830312094534406203255607198").unwrap() - ] - ]; + let encoded_call = zk_verifier.generate_benchmarking_parameters(); - let valid_input = vec![U256::from_dec_str("4843011250846255110").unwrap(), U256::from_dec_str("10798190704713744688").unwrap(), U256::from_dec_str("15134859568936326220").unwrap(), U256::from_dec_str("2883369245646660076").unwrap()]; - let mut encoded_call = vec![0u8; 4]; - encoded_call[0..4].copy_from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..4]); - let parameters = ethabi::encode(&[ - Token::FixedArray(proof_a.into_iter().map(Token::Uint).collect()), - Token::FixedArray(proof_b.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), - Token::FixedArray(proof_c.into_iter().map(Token::Uint).collect()), - Token::FixedArray(vk_alpha.into_iter().map(Token::Uint).collect()), - Token::FixedArray(vk_beta.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), - Token::FixedArray(vk_gamma.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), - Token::FixedArray(vk_delta.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), - Token::Array(vk_ic.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), - Token::Array(valid_input.into_iter().map(Token::Uint).collect()), - ]); - encoded_call.extend(parameters); let gas_limit_call = 1000000; let value = U256::default(); let is_transactional = true; @@ -277,26 +278,26 @@ benchmarks! { validate, ::config(), ); - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "Benchmarking call end.", - // ); + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "Benchmarking call end.", + ); match call_runner_results { Ok(info) => { let output = info.value; - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "output result {:?}", - // output - // ); + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "output result {:?}", + output + ); if output.len() >= 32 { let mut result_bytes = [0u8; 32]; result_bytes.copy_from_slice(&output[output.len() - 32..]); let result = U256::from_big_endian(&result_bytes); - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "Verification result {result:?}", - // ); + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "Verification result {result:?}", + ); assert_eq!(result, U256::one(), "The contract did not return true"); } }, @@ -309,100 +310,1932 @@ benchmarks! { } } - nconstraints_20 { + // nconstraints_50 { + // use frame_benchmarking::vec; + // use sp_core::{H160, U256, H256}; + + // let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + // let contract_address = H160::from_low_u64_be(0x8888); + + // let proof = Proof::new( + // vec![ + // U256::from_dec_str("2903574088029507435491062627919627539459038881203099780902103872696986272650").unwrap(), + // U256::from_dec_str("3875062839032259754068923295563862040166715100637843024855021734684308685930").unwrap(), + // ], + // vec![ + // vec![ + // U256::from_dec_str("5467576156112132028552287163049386912078800648727055176723583005212825192497").unwrap(), + // U256::from_dec_str("14958898784032520052694892656913773236193256742890765604760593633503039104983").unwrap(), + // ], + // vec![ + // U256::from_dec_str("5396143311660903133040196691443703988892234257628755380984718394981374344158").unwrap(), + // U256::from_dec_str("8621644456104449033213297238562527153800159584768570376273022394943050969320").unwrap(), + // ], + // ], + // vec![ + // U256::from_dec_str("11879092906448699692394725971977132036554363118574468164770659810752018463948").unwrap(), + // U256::from_dec_str("6829624468475499149259780051037762599455296300930683215687755977165243124154").unwrap(), + // ] + // ); + + // let vk = VerifyingKeyComponents::new( + // vec![ + // U256::from_dec_str("12520775544030530008009522467466185193766786263812261579427634884004150619566").unwrap(), + // U256::from_dec_str("5032545863820965741764073435262250124257467813113463153084126384917060899315").unwrap(), + // ], + // vec![ + // vec![ + // U256::from_dec_str("10017955328073015145877787608777450033090741247853140204265773706371885379542").unwrap(), + // U256::from_dec_str("9658203662920649739629860626443008098625554125855709045942833415049413198251").unwrap(), + // ], + // vec![ + // U256::from_dec_str("7602415148393817869205609282139785691690714005596249546125364310759985118071").unwrap(), + // U256::from_dec_str("6621887421318408197643297351639235440436194355283660692959196816576578875866").unwrap(), + // ], + // ], + // vec![ + // vec![ + // U256::from_dec_str("5311307398908794283615493653665859916837738758333406097237626345248614605789").unwrap(), + // U256::from_dec_str("17876886843886949913975349493510247353159584223381019718903135647608874168034").unwrap(), + // ], + // vec![ + // U256::from_dec_str("16871344858870476549165036353120397473700844904231047018564735968613233188965").unwrap(), + // U256::from_dec_str("3780010632071163899826543545524090280002435997376718121100375224910528030644").unwrap(), + // ], + // ], + // vec![ + // vec![ + // U256::from_dec_str("5274939476765287332787933848172441391963317633567336761478263433231602711901").unwrap(), + // U256::from_dec_str("20318717968421229127062334564952813061229602553850186042308931686220563993985").unwrap(), + // ], + // vec![ + // U256::from_dec_str("18867986549807700609691354300906273266753459571664361845748650324369589087167").unwrap(), + // U256::from_dec_str("3462802759155100024118895949055238081126591020075851877084161838812514424801").unwrap(), + // ] + // ], + // vec![ + // vec![ + // U256::from_dec_str("2073721309366561324099267234284336470258146869696430225377434175843251484752").unwrap(), + // U256::from_dec_str("5562089018027206512286783868306950659834000523781522158661084193254167305831").unwrap(), + // ], + // vec![ + // U256::from_dec_str("7633925392184781104787537197952383405066326059553608577981951477761067715424").unwrap(), + // U256::from_dec_str("19510227686274170330355317434483857344641524658406254379151352263942714837771").unwrap(), + // ] + // ] + // ); + + // let valid_input = vec![ + // U256::from_dec_str("14754876691570659999").unwrap(), + // U256::from_dec_str("1449725765053302887").unwrap(), + // U256::from_dec_str("10573592104590215630").unwrap(), + // U256::from_dec_str("2031301759166401468").unwrap() + // ]; + + // let verifying_key = VerifyingKey::new(proof, vk, valid_input); + + // let zk_verifier = ZKPrecompileVerifier::new( + // H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), + // verifying_key + // ); + + // let encoded_call = zk_verifier.generate_benchmarking_parameters(); + + // let gas_limit_call = 1000000; + // let value = U256::default(); + // let is_transactional = true; + // let validate = true; + // }:{ + // let call_runner_results = ::Runner::call( + // caller, + // contract_address, + // encoded_call, + // value, + // gas_limit_call, + // Some(U256::from(1_000_000_000)), + // Some(U256::from(1_000_000_000)), + // None, + // Vec::new(), + // is_transactional, + // validate, + // ::config(), + // ); + // // log::info!( + // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // // "Benchmarking call end.", + // // ); + // match call_runner_results { + // Ok(info) => { + // let output = info.value; + // // log::info!( + // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // // "output result {:?}", + // // output + // // ); + // if output.len() >= 32 { + // let mut result_bytes = [0u8; 32]; + // result_bytes.copy_from_slice(&output[output.len() - 32..]); + // let result = U256::from_big_endian(&result_bytes); + // // log::info!( + // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // // "Verification result {result:?}", + // // ); + // assert_eq!(result, U256::one(), "The contract did not return true"); + // } + // }, + // Err(e) => { + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "Benchmarking failed", + // ); + // } + // } + // } + + // nconstraints_1000 { + // use frame_benchmarking::vec; + // use sp_core::{H160, U256, H256}; + + // let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + // let contract_address = H160::from_low_u64_be(0x8888); + + // let proof = Proof::new( + // vec![ + // U256::from_dec_str("12451505848309631687252015279596976128225375079184616465869275088833975377438").unwrap(), + // U256::from_dec_str("18028472547304696309803026581736164843724278168110632635282700219721294267849").unwrap(), + // ], + // vec![ + // vec![ + // U256::from_dec_str("724941625340075448308940885419778921267046089963198424690563710257350467820").unwrap(), + // U256::from_dec_str("19418815036545241911278056687101064762643664412732993043969007894248087117385").unwrap(), + // ], + // vec![ + // U256::from_dec_str("13249414494230793056410904135885722890271124096600389432878053498484425858770").unwrap(), + // U256::from_dec_str("21762806144353143011028620465453743506764842517668851190776375592288870325215").unwrap(), + // ], + // ], + // vec![ + // U256::from_dec_str("9206867270262791130308246301015463866896172966002943363908694359851632501217").unwrap(), + // U256::from_dec_str("13679683495177263967294831832954860495137891909047512983345948806664713075553").unwrap(), + // ] + // ); + + // let vk = VerifyingKeyComponents::new( + // vec![ + // U256::from_dec_str("13896934827344718021853288836918374118104295193491067840322643424358899121542").unwrap(), + // U256::from_dec_str("8854052944916041632001392967979629780372345382861670282089777314383817716115").unwrap(), + // ], + // vec![ + // vec![ + // U256::from_dec_str("3601177773308419037453361001975316835601350296485805323140167568598797930642").unwrap(), + // U256::from_dec_str("48851914275316782871445347689531673984580545598074561513165366823294923594").unwrap(), + // ], + // vec![ + // U256::from_dec_str("4538012201084519544875007504928553564968897773565284770715803834936680149613").unwrap(), + // U256::from_dec_str("3155968616270588886660033728776257587454508333510911411658919790925259116614").unwrap(), + // ], + // ], + // vec![ + // vec![ + // U256::from_dec_str("6521538659624675039700866061977650833785775087701556120926232218187885377774").unwrap(), + // U256::from_dec_str("18707623749213430453109215145186606994638201653518117177006249287165414157706").unwrap(), + // ], + // vec![ + // U256::from_dec_str("11743109857123024729794370527373948778820323338754388805090881243904381703330").unwrap(), + // U256::from_dec_str("3577725017182890090279110701721773090147301853148322630192233820247926772155").unwrap(), + // ], + // ], + // vec![ + // vec![ + // U256::from_dec_str("10697077492206594361644026971284249101590705030465491131467731100150008255694").unwrap(), + // U256::from_dec_str("1114380532795466865933623446272212800793315337032855536172932313989250445726").unwrap(), + // ], + // vec![ + // U256::from_dec_str("11747915450686416011932172170367549011245903715607283230565719536126230133873").unwrap(), + // U256::from_dec_str("1877153534214274703747923906347594924169181268669702005894131954432202950068").unwrap(), + // ] + // ], + // vec![ + // vec![ + // U256::from_dec_str("6294921440683861296812943370338888809368101163511446375226378176013676840633").unwrap(), + // U256::from_dec_str("8766686502883018606879699065134987161183815270662618961653335871316040755302").unwrap(), + // ], + // vec![ + // U256::from_dec_str("15422085976834841481597157129530660038025986735930069198619117556493669017719").unwrap(), + // U256::from_dec_str("6824904336141021449652133306590775160232847673735850151493603664420102965477").unwrap(), + // ] + // ] + // ); + + // let valid_input = vec![ + // U256::from_dec_str("5637188163546619750").unwrap(), + // U256::from_dec_str("4876642863872575056").unwrap(), + // U256::from_dec_str("11311886144936918135").unwrap(), + // U256::from_dec_str("2620236256196171805").unwrap() + // ]; + + // let verifying_key = VerifyingKey::new(proof, vk, valid_input); + + // let zk_verifier = ZKPrecompileVerifier::new( + // H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), + // verifying_key + // ); + + // let encoded_call = zk_verifier.generate_benchmarking_parameters(); + + // let gas_limit_call = 1000000; + // let value = U256::default(); + // let is_transactional = true; + // let validate = true; + // }:{ + // let call_runner_results = ::Runner::call( + // caller, + // contract_address, + // encoded_call, + // value, + // gas_limit_call, + // Some(U256::from(1_000_000_000)), + // Some(U256::from(1_000_000_000)), + // None, + // Vec::new(), + // is_transactional, + // validate, + // ::config(), + // ); + // // log::info!( + // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // // "Benchmarking call end.", + // // ); + // match call_runner_results { + // Ok(info) => { + // let output = info.value; + // // log::info!( + // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // // "output result {:?}", + // // output + // // ); + // if output.len() >= 32 { + // let mut result_bytes = [0u8; 32]; + // result_bytes.copy_from_slice(&output[output.len() - 32..]); + // let result = U256::from_big_endian(&result_bytes); + // // log::info!( + // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // // "Verification result {result:?}", + // // ); + // assert_eq!(result, U256::one(), "The contract did not return true"); + // } + // }, + // Err(e) => { + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "Benchmarking failed", + // ); + // } + // } + // } + // nconstraints_900000 { + // use frame_benchmarking::vec; + // use sp_core::{H160, U256, H256}; + + // let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + // let contract_address = H160::from_low_u64_be(0x8888); + + // let proof = Proof::new( + // vec![ + // U256::from_dec_str("19469224081137364911375441935428613758543844094780123177610680784796374565509").unwrap(), + // U256::from_dec_str("2964109100176825277964902990593130655404587548088911907169158668561756482373").unwrap(), + // ], + // vec![ + // vec![ + // U256::from_dec_str("1804788596044451078391485097362341934563024367189115611320140606169017734442").unwrap(), + // U256::from_dec_str("13075356869764013404490647878715830765050556805353047586243641659166972614506").unwrap(), + // ], + // vec![ + // U256::from_dec_str("11510752280195741101381678478126680255679095252133774347633523263393718090827").unwrap(), + // U256::from_dec_str("19917734624109913540474402939707087760514256808495299709893660593520804971329").unwrap(), + // ], + // ], + // vec![ + // U256::from_dec_str("17650234014776935476405426867265189573543251264844619398004397025922351000524").unwrap(), + // U256::from_dec_str("13980409623437481166079302794215538337078177634480935418093274323345259996058").unwrap(), + // ] + // ); + + // let vk = VerifyingKeyComponents::new( + // vec![ + // U256::from_dec_str("7204013913559348808806179272679133668079798990573619252699122941477292720367").unwrap(), + // U256::from_dec_str("14448814309541293146746525253301533902449817953703436076734477345366335651547").unwrap(), + // ], + // vec![ + // vec![ + // U256::from_dec_str("12755354931522455226769415963087662012592248962914015697167303994293035888664").unwrap(), + // U256::from_dec_str("19979994508677160041392994419804596139216500302977150541381981675855322022114").unwrap(), + // ], + // vec![ + // U256::from_dec_str("3518578052095992035034011768990132253597152650327354182069223777691356587613").unwrap(), + // U256::from_dec_str("1512363495951297845516866605291301480678745477544041997800458458709067854003").unwrap(), + // ], + // ], + // vec![ + // vec![ + // U256::from_dec_str("21483901865224554977407186643009006049964266844355020377697169106001216486465").unwrap(), + // U256::from_dec_str("18122216236568402305988297032517775914181563813086813006164216689752246508886").unwrap(), + // ], + // vec![ + // U256::from_dec_str("7100124544075226034251596932805277307734457677256004047412258693103409543678").unwrap(), + // U256::from_dec_str("9484826513489508497326605298995346628011303684771342589708630141744196880174").unwrap(), + // ], + // ], + // vec![ + // vec![ + // U256::from_dec_str("4294809674390523555755416088340227038268056188806697061914357207030835445784").unwrap(), + // U256::from_dec_str("12772882987652274474928251216882135157601158713560023135442912416889883375009").unwrap(), + // ], + // vec![ + // U256::from_dec_str("5017814360156811257431228283078380210712481496173867244303167538680301406355").unwrap(), + // U256::from_dec_str("5483986251263351055676143301589669624262947345327185314870128974364440001262").unwrap(), + // ] + // ], + // vec![ + // vec![ + // U256::from_dec_str("10485365056956235833573091505977794158366069646492853613385564319176805042067").unwrap(), + // U256::from_dec_str("21560988819791135038184934219494970236802908435926324068683299817562907341696").unwrap(), + // ], + // vec![ + // U256::from_dec_str("9274251274730510866039258353232655161206943117093211738883330925803202790098").unwrap(), + // U256::from_dec_str("19994917632455570632082635510110118222993755636207706143729050502915579896735").unwrap(), + // ] + // ] + // ); + + // let valid_input = vec![ + // U256::from_dec_str("10518156496175725870").unwrap(), + // U256::from_dec_str("8513656267880232886").unwrap(), + // U256::from_dec_str("1469451646407182009").unwrap(), + // U256::from_dec_str("3425508166019525724").unwrap() + // ]; + + // let verifying_key = VerifyingKey::new(proof, vk, valid_input); + + // let zk_verifier = ZKPrecompileVerifier::new( + // H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), + // verifying_key + // ); + + // let encoded_call = zk_verifier.generate_benchmarking_parameters(); + + // let gas_limit_call = 1000000; + // let value = U256::default(); + // let is_transactional = true; + // let validate = true; + // }:{ + // let call_runner_results = ::Runner::call( + // caller, + // contract_address, + // encoded_call, + // value, + // gas_limit_call, + // Some(U256::from(1_000_000_000)), + // Some(U256::from(1_000_000_000)), + // None, + // Vec::new(), + // is_transactional, + // validate, + // ::config(), + // ); + // // log::info!( + // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // // "Benchmarking call end.", + // // ); + // match call_runner_results { + // Ok(info) => { + // let output = info.value; + // // log::info!( + // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // // "output result {:?}", + // // output + // // ); + // if output.len() >= 32 { + // let mut result_bytes = [0u8; 32]; + // result_bytes.copy_from_slice(&output[output.len() - 32..]); + // let result = U256::from_big_endian(&result_bytes); + // // log::info!( + // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // // "Verification result {result:?}", + // // ); + // assert_eq!(result, U256::one(), "The contract did not return true"); + // } + // }, + // Err(e) => { + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "Benchmarking failed", + // ); + // } + // } + // } + + // nconstraints_30_input_10 { + // use frame_benchmarking::vec; + // use sp_core::{H160, U256, H256}; + + // let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + // let contract_address = H160::from_low_u64_be(0x8888); + + // let proof = Proof::new( + // vec![ + // U256::from_dec_str("344113499780097036133410144688544669449665038469801025061703634064197059916").unwrap(), + // U256::from_dec_str("8339013355837829034186604529242237434382457535922383671882155606562413431689").unwrap(), + // ], + // vec![ + // vec![ + // U256::from_dec_str("6694199005832176626648387473003377778002164049654344388623160500074797775370").unwrap(), + // U256::from_dec_str("6246558478856965861562784864034844546822126660127014237507763330640717221466").unwrap(), + // ], + // vec![ + // U256::from_dec_str("456859418727494804887897697519797382313397623366843307513728588676215628797").unwrap(), + // U256::from_dec_str("19972929684979882956825623277042855987039264105600158828132263230333203670106").unwrap(), + // ], + // ], + // vec![ + // U256::from_dec_str("8991876521515422964548874095107781976525191569601242691722207742733698821028").unwrap(), + // U256::from_dec_str("17304897036279645989594099459944208131107988079437513579584585106093260802053").unwrap(), + // ] + // ); + + // let vk = VerifyingKeyComponents::new( + // vec![ + // U256::from_dec_str("16587578668155053320776501244706909164198053583863284386206654068019392556543").unwrap(), + // U256::from_dec_str("17489859882312386925030082840618136961844042944104008122175974338708995824981").unwrap(), + // ], + // vec![ + // vec![ + // U256::from_dec_str("8243058085082563940310351321464397410632520885003827137093771369586433446018").unwrap(), + // U256::from_dec_str("1806964369040712598415691188975966807767394918682209427183228092832571919497").unwrap(), + // ], + // vec![ + // U256::from_dec_str("5238575049648595236335310308987023404502439315997088611926714272919127054029").unwrap(), + // U256::from_dec_str("10529242360048105445622302340100671863366518517961350431989359465371013288044").unwrap(), + // ], + // ], + // vec![ + // vec![ + // U256::from_dec_str("422118731661843716781379598081446048950684758761078928178953272944418614265").unwrap(), + // U256::from_dec_str("8071137901873450516865398890359069534977349842235015782367912081100468370342").unwrap(), + // ], + // vec![ + // U256::from_dec_str("6616051543776580097026224309598118359974125974677691608309070965923230091481").unwrap(), + // U256::from_dec_str("3144026861846828201735234261898216197057552604232403108299101704912138104081").unwrap(), + // ], + // ], + // vec![ + // vec![ + // U256::from_dec_str("15967728838725285670062386536689775286816477877862913251436519988213464788203").unwrap(), + // U256::from_dec_str("14482652023948193853731701210376245407114581664800773915003137369238699817066").unwrap(), + // ], + // vec![ + // U256::from_dec_str("20222564526826997580988353930405539667760709452060576182511364617433825375503").unwrap(), + // U256::from_dec_str("1855904408322765948314758770516591135802311025429227172106073057339165107921").unwrap(), + // ] + // ], + // vec![ + // vec![ + // U256::from_dec_str("2234398803815490360326379119253073021265347911436036657996997085101774002925").unwrap(), + // U256::from_dec_str("10214773739303944856355679056757071889148916152665035343340628435407174724717").unwrap(), + // ], + // vec![ + // U256::from_dec_str("21500623561133929663133180424780657403302270303706782392356903439186747104812").unwrap(), + // U256::from_dec_str("19328419280811286038333929820672543691407985372391054082759992875889788951230").unwrap(), + // ] + // ] + // ); + + // let valid_input = vec![ + // U256::from_dec_str("14321691860995553260").unwrap(), + // U256::from_dec_str("7152862679273281751").unwrap(), + // U256::from_dec_str("12752615512303817990").unwrap(), + // U256::from_dec_str("1576113262537949146").unwrap() + // ]; + + // let verifying_key = VerifyingKey::new(proof, vk, valid_input); + + // let zk_verifier = ZKPrecompileVerifier::new( + // H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), + // verifying_key + // ); + + // let encoded_call = zk_verifier.generate_benchmarking_parameters(); + + // let gas_limit_call = 1000000; + // let value = U256::default(); + // let is_transactional = true; + // let validate = true; + // }:{ + // let call_runner_results = ::Runner::call( + // caller, + // contract_address, + // encoded_call, + // value, + // gas_limit_call, + // Some(U256::from(1_000_000_000)), + // Some(U256::from(1_000_000_000)), + // None, + // Vec::new(), + // is_transactional, + // validate, + // ::config(), + // ); + // // log::info!( + // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // // "Benchmarking call end.", + // // ); + // match call_runner_results { + // Ok(info) => { + // let output = info.value; + // // log::info!( + // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // // "output result {:?}", + // // output + // // ); + // if output.len() >= 32 { + // let mut result_bytes = [0u8; 32]; + // result_bytes.copy_from_slice(&output[output.len() - 32..]); + // let result = U256::from_big_endian(&result_bytes); + // // log::info!( + // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // // "Verification result {result:?}", + // // ); + // assert_eq!(result, U256::one(), "The contract did not return true"); + // } + // }, + // Err(e) => { + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "Benchmarking failed", + // ); + // } + // } + // } + // nconstraints_30_input_100 { + // use frame_benchmarking::vec; + // use sp_core::{H160, U256, H256}; + + // let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + // let contract_address = H160::from_low_u64_be(0x8888); + + // let proof = Proof::new( + // vec![ + // U256::from_dec_str("3780487311936056381294564418675304364481973966802209296561160829797948105411").unwrap(), + // U256::from_dec_str("12392254879980640223142009257910424254771509444451393927739643876401726307795").unwrap(), + // ], + // vec![ + // vec![ + // U256::from_dec_str("5169548117445173154024813698359426977000013771483410622256640533171985245380").unwrap(), + // U256::from_dec_str("11220449603083268927036844276912830985523128428499468942581840512730495047625").unwrap(), + // ], + // vec![ + // U256::from_dec_str("7617888807668014594076695037395251387521432502213194545531858961238344338860").unwrap(), + // U256::from_dec_str("3206448605631210983027663221710912427383659852717855953276353488187250079459").unwrap(), + // ], + // ], + // vec![ + // U256::from_dec_str("17260938596020642923034443094579912726381749511890996943502017876149586484217").unwrap(), + // U256::from_dec_str("973711408795313031099855712156150142641887502706075552254275664528776194028").unwrap(), + // ] + // ); + + // let vk = VerifyingKeyComponents::new( + // vec![ + // U256::from_dec_str("4155898266631322214574856388057229131381603659142355428000239527171539910720").unwrap(), + // U256::from_dec_str("15919304600573806746067202721026223664629992455130946331020176989460510062648").unwrap(), + // ], + // vec![ + // vec![ + // U256::from_dec_str("10559477888637541108523299513483158185288656601390229631277602982302056830264").unwrap(), + // U256::from_dec_str("21518216923189214839507247102243744126930049565774641401859791113452178471842").unwrap(), + // ], + // vec![ + // U256::from_dec_str("20524972206762616004058259260290957844870248494446046806278424843369643489182").unwrap(), + // U256::from_dec_str("17430943082223119961631960086233630485654941075995072846024219998674392652581").unwrap(), + // ], + // ], + // vec![ + // vec![ + // U256::from_dec_str("4636362103930283526843587215716464395878300635435610009766312980459671398351").unwrap(), + // U256::from_dec_str("15713999866924132629927290621261290205960872899800820372400263081232019214301").unwrap(), + // ], + // vec![ + // U256::from_dec_str("274224283373606674211197218239218941312046485596075799302472837928822177016").unwrap(), + // U256::from_dec_str("10693491445395060496723678108216498586881120243971297703830999940561952271629").unwrap(), + // ], + // ], + // vec![ + // vec![ + // U256::from_dec_str("9540601502504552621404908678855872975596983734893914263055690675850649191273").unwrap(), + // U256::from_dec_str("10288168694112392204164781631687615725045294841966564539511156565183262528849").unwrap(), + // ], + // vec![ + // U256::from_dec_str("16504160099082952601826232467479510151840980336862791499394346450083636791102").unwrap(), + // U256::from_dec_str("9210167978306154509907086298616199856898787966613435045760659519455958969992").unwrap(), + // ] + // ], + // vec![ + // vec![ + // U256::from_dec_str("15812098394101742886061540987450559986219804469912805896076341688421241661621").unwrap(), + // U256::from_dec_str("11920211969663783445335622417572072568292106489672989284415235777753260953099").unwrap(), + // ], + // vec![ + // U256::from_dec_str("7061409000327933635430701054193661775345794014516696263402966093123651666364").unwrap(), + // U256::from_dec_str("17078047162776906089011285464212202278306676406084693061907121919624683442357").unwrap(), + // ] + // ] + // ); + + // let valid_input = vec![ + // U256::from_dec_str("9831528597301135316").unwrap(), + // U256::from_dec_str("11053911270256492840").unwrap(), + // U256::from_dec_str("14337707091878126846").unwrap(), + // U256::from_dec_str("772611368070892958").unwrap() + // ]; + + // let verifying_key = VerifyingKey::new(proof, vk, valid_input); + + // let zk_verifier = ZKPrecompileVerifier::new( + // H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), + // verifying_key + // ); + + // let encoded_call = zk_verifier.generate_benchmarking_parameters(); + + // let gas_limit_call = 1000000; + // let value = U256::default(); + // let is_transactional = true; + // let validate = true; + // }:{ + // let call_runner_results = ::Runner::call( + // caller, + // contract_address, + // encoded_call, + // value, + // gas_limit_call, + // Some(U256::from(1_000_000_000)), + // Some(U256::from(1_000_000_000)), + // None, + // Vec::new(), + // is_transactional, + // validate, + // ::config(), + // ); + // // log::info!( + // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // // "Benchmarking call end.", + // // ); + // match call_runner_results { + // Ok(info) => { + // let output = info.value; + // // log::info!( + // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // // "output result {:?}", + // // output + // // ); + // if output.len() >= 32 { + // let mut result_bytes = [0u8; 32]; + // result_bytes.copy_from_slice(&output[output.len() - 32..]); + // let result = U256::from_big_endian(&result_bytes); + // // log::info!( + // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // // "Verification result {result:?}", + // // ); + // assert_eq!(result, U256::one(), "The contract did not return true"); + // } + // }, + // Err(e) => { + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "Benchmarking failed", + // ); + // } + // } + // } + // nconstraints_30_input_1000 { + // use frame_benchmarking::vec; + // use sp_core::{H160, U256, H256}; + + // let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + // let contract_address = H160::from_low_u64_be(0x8888); + + // let proof = Proof::new( + // vec![ + // U256::from_dec_str("21424271595387505713049534900676381136649432939050012296331964885140120988520").unwrap(), + // U256::from_dec_str("20488789316104689748479888121024139144355086386496471461763924485714534718686").unwrap(), + // ], + // vec![ + // vec![ + // U256::from_dec_str("8417699613540073682519718294821269056423071880647667978060348740795273915651").unwrap(), + // U256::from_dec_str("4036859279888161250878359321718658739242283134835030699023268489309754993434").unwrap(), + // ], + // vec![ + // U256::from_dec_str("16249800568747110450527363597274431407786919086057853194987169090454936230259").unwrap(), + // U256::from_dec_str("15005851458712291005106538565823270955208428726378749297397203143137382225457").unwrap(), + // ], + // ], + // vec![ + // U256::from_dec_str("21239990703864671714190525785674088715931473556140655107585637961585812134589").unwrap(), + // U256::from_dec_str("261928180985765917331919571442880380998408670702589931014636966043229919418").unwrap(), + // ] + // ); + + // let vk = VerifyingKeyComponents::new( + // vec![ + // U256::from_dec_str("1657406292532781196449359079614579852690925607592278296574718289470803732053").unwrap(), + // U256::from_dec_str("18213557747942747074556848145237207574111244905157024361329330629173034829885").unwrap(), + // ], + // vec![ + // vec![ + // U256::from_dec_str("5419856735820685908218319193906907396496344921642651266629131019868853843815").unwrap(), + // U256::from_dec_str("14007905369450574044915098075029863272475910046750101274280969769181784166430").unwrap(), + // ], + // vec![ + // U256::from_dec_str("182200131698860550444455761364918630551676350878779858078817264277300629723").unwrap(), + // U256::from_dec_str("6050431818377820601319883600432739448105157482353041283628740094609821419656").unwrap(), + // ], + // ], + // vec![ + // vec![ + // U256::from_dec_str("14463567879100083166257564330995533094334991709675023767975192973144798919122").unwrap(), + // U256::from_dec_str("6166287541473141918830331239835928582190744434356526822227225877844349692203").unwrap(), + // ], + // vec![ + // U256::from_dec_str("12512843744533735346513506961399336936527367720771340395643503621530703342395").unwrap(), + // U256::from_dec_str("8394818975982736201521422268641084055810886358791398607930311472872317386487").unwrap(), + // ], + // ], + // vec![ + // vec![ + // U256::from_dec_str("8757732756289429354419510422628896433407345473998310348115924113882282945326").unwrap(), + // U256::from_dec_str("1610185885725147927651201796201713521257480620743342969197368887869230657180").unwrap(), + // ], + // vec![ + // U256::from_dec_str("2834338214415807920713929739507915327763263469562351781747229949754640383374").unwrap(), + // U256::from_dec_str("20761263923134391843554423575366232120525285729512411038267095810712916924016").unwrap(), + // ] + // ], + // vec![ + // vec![ + // U256::from_dec_str("16585432354609922217222548226453277630464695131710476183479619760311567992522").unwrap(), + // U256::from_dec_str("5379258900528839934525784961038010961454863754298062530193947624450477797122").unwrap(), + // ], + // vec![ + // U256::from_dec_str("16825349369326282879106301528709807467071985531593215317852699692046311881677").unwrap(), + // U256::from_dec_str("10540450379202726868409867306854114915477889581096312866635875249145708179576").unwrap(), + // ] + // ] + // ); + + // let valid_input = vec![ + // U256::from_dec_str("3008789406746563016").unwrap(), + // U256::from_dec_str("7061370202899273426").unwrap(), + // U256::from_dec_str("2191755323004339933").unwrap(), + // U256::from_dec_str("1005591455220622530").unwrap() + // ]; + + // let verifying_key = VerifyingKey::new(proof, vk, valid_input); + + // let zk_verifier = ZKPrecompileVerifier::new( + // H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), + // verifying_key + // ); + + // let encoded_call = zk_verifier.generate_benchmarking_parameters(); + + // let gas_limit_call = 1000000; + // let value = U256::default(); + // let is_transactional = true; + // let validate = true; + // }:{ + // let call_runner_results = ::Runner::call( + // caller, + // contract_address, + // encoded_call, + // value, + // gas_limit_call, + // Some(U256::from(1_000_000_000)), + // Some(U256::from(1_000_000_000)), + // None, + // Vec::new(), + // is_transactional, + // validate, + // ::config(), + // ); + // // log::info!( + // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // // "Benchmarking call end.", + // // ); + // match call_runner_results { + // Ok(info) => { + // let output = info.value; + // // log::info!( + // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // // "output result {:?}", + // // output + // // ); + // if output.len() >= 32 { + // let mut result_bytes = [0u8; 32]; + // result_bytes.copy_from_slice(&output[output.len() - 32..]); + // let result = U256::from_big_endian(&result_bytes); + // // log::info!( + // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // // "Verification result {result:?}", + // // ); + // assert_eq!(result, U256::one(), "The contract did not return true"); + // } + // }, + // Err(e) => { + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "Benchmarking failed", + // ); + // } + // } + // } + // nconstraints_30_input_5000 { + // use frame_benchmarking::vec; + // use sp_core::{H160, U256, H256}; + + // let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + // let contract_address = H160::from_low_u64_be(0x8888); + + // let proof = Proof::new( + // vec![ + // U256::from_dec_str("4760178114933307527976205229418881302833473087272893863010681924222436742436").unwrap(), + // U256::from_dec_str("6555056836023646163359279772724076765411780318148657506988760187885700674215").unwrap(), + // ], + // vec![ + // vec![ + // U256::from_dec_str("9540205596737585525189386078607957630969059503165883907845238817662495399607").unwrap(), + // U256::from_dec_str("21777913747079267536001051597001736802905779914683258171463923506869689358122").unwrap(), + // ], + // vec![ + // U256::from_dec_str("7652162643714058076103867092157642519402862581818067281609790687905833151647").unwrap(), + // U256::from_dec_str("5174136241284192352871549806655421810249317805219641765935618077180420544939").unwrap(), + // ], + // ], + // vec![ + // U256::from_dec_str("9633653417112713107386510132385608824105920168790226750481878454006412372444").unwrap(), + // U256::from_dec_str("5600932933208824148570351176368803282808856587672889614186338874655752173453").unwrap(), + // ] + // ); + + // let vk = VerifyingKeyComponents::new( + // vec![ + // U256::from_dec_str("20563201722283471489193032980811350162387466733119686723832100493505332037220").unwrap(), + // U256::from_dec_str("458683337854426284881131074995322438618437423037306322290239745015633774839").unwrap(), + // ], + // vec![ + // vec![ + // U256::from_dec_str("802687519037697530569139206036966996588449135138601551566343295868421688400").unwrap(), + // U256::from_dec_str("10902489968444563758310974921240106861656913905085710523025258522577834664814").unwrap(), + // ], + // vec![ + // U256::from_dec_str("8163282908300075270434111132545381898266738500810094061899946027883982232155").unwrap(), + // U256::from_dec_str("2879234862354419255322548813414679750617024208122660306082351289172177493856").unwrap(), + // ], + // ], + // vec![ + // vec![ + // U256::from_dec_str("12946416399098615767859440028401625777970463338055590127763655113029764523456").unwrap(), + // U256::from_dec_str("19000556224902286061769815260124368973839417953399533885850283592096662743016").unwrap(), + // ], + // vec![ + // U256::from_dec_str("16883066945921282046110808795753929362007100542422795769422243319629113077450").unwrap(), + // U256::from_dec_str("3229017908221308993692674040951942449106283130433174678816420254626513367678").unwrap(), + // ], + // ], + // vec![ + // vec![ + // U256::from_dec_str("16459854676924169388774046538295013154707390397685062918225181412137603478923").unwrap(), + // U256::from_dec_str("20996869365345436816737319903210535785982053153529758285286719146777762981985").unwrap(), + // ], + // vec![ + // U256::from_dec_str("21446959969822179574296836241978980045198577120638747119902976563053247153220").unwrap(), + // U256::from_dec_str("4716297282146551186330252875195511360280503254452482577157100992033023717484").unwrap(), + // ] + // ], + // vec![ + // vec![ + // U256::from_dec_str("2127664998061023131080125201643658604092063304061707222326237054428506173927").unwrap(), + // U256::from_dec_str("13918137729545385379467184110597023571257121066683873930760549927318081992996").unwrap(), + // ], + // vec![ + // U256::from_dec_str("16560640526003408304721205785917894782070253870764339317137905014294472374327").unwrap(), + // U256::from_dec_str("19394535992291030838186763750684977819230291410826312937425829210188321257228").unwrap(), + // ] + // ] + // ); + + // let valid_input = vec![ + // U256::from_dec_str("13212982172557049181").unwrap(), + // U256::from_dec_str("17043673098390055166").unwrap(), + // U256::from_dec_str("13971391527459105160").unwrap(), + // U256::from_dec_str("1729491887349651790").unwrap(), + // ]; + + // let verifying_key = VerifyingKey::new(proof, vk, valid_input); + + // let zk_verifier = ZKPrecompileVerifier::new( + // H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), + // verifying_key + // ); + + // let encoded_call = zk_verifier.generate_benchmarking_parameters(); + + // let gas_limit_call = 1000000; + // let value = U256::default(); + // let is_transactional = true; + // let validate = true; + // }:{ + // let call_runner_results = ::Runner::call( + // caller, + // contract_address, + // encoded_call, + // value, + // gas_limit_call, + // Some(U256::from(1_000_000_000)), + // Some(U256::from(1_000_000_000)), + // None, + // Vec::new(), + // is_transactional, + // validate, + // ::config(), + // ); + // // log::info!( + // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // // "Benchmarking call end.", + // // ); + // match call_runner_results { + // Ok(info) => { + // let output = info.value; + // // log::info!( + // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // // "output result {:?}", + // // output + // // ); + // if output.len() >= 32 { + // let mut result_bytes = [0u8; 32]; + // result_bytes.copy_from_slice(&output[output.len() - 32..]); + // let result = U256::from_big_endian(&result_bytes); + // // log::info!( + // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // // "Verification result {result:?}", + // // ); + // assert_eq!(result, U256::one(), "The contract did not return true"); + // } + // }, + // Err(e) => { + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "Benchmarking failed", + // ); + // } + // } + // } + // nconstraints_30_input_10000 { + // use frame_benchmarking::vec; + // use sp_core::{H160, U256, H256}; + + // let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + // let contract_address = H160::from_low_u64_be(0x8888); + + // let proof = Proof::new( + // vec![ + // U256::from_dec_str("20201588552006483041582128307591335561381558661958982754827324334159524114833").unwrap(), + // U256::from_dec_str("17768889616334897699714190449991059857597665579001510168911964966707846254013").unwrap(), + // ], + // vec![ + // vec![ + // U256::from_dec_str("831427914683469755258685737297441858923030844026909228595596228891513784401").unwrap(), + // U256::from_dec_str("17358733390631981546461856303504163975689822422160671163593908204299387350560").unwrap(), + // ], + // vec![ + // U256::from_dec_str("12673178383954759426828314411760863182427996098705680584931403917390222262168").unwrap(), + // U256::from_dec_str("12056092533572380482681874959737292916971452073896642753405050795241584080793").unwrap(), + // ], + // ], + // vec![ + // U256::from_dec_str("11086630979744216291689656728938462056245402184490217943698398792953833540899").unwrap(), + // U256::from_dec_str("6981043472993913602669753829495794560155248771335035866541870305230603679484").unwrap(), + // ] + // ); + + // let vk = VerifyingKeyComponents::new( + // vec![ + // U256::from_dec_str("10088605449330278081588905225706913827985798761474642054412607299987851491561").unwrap(), + // U256::from_dec_str("12349112716571349951448807635426375878752472531266562453302627732729311140226").unwrap(), + // ], + // vec![ + // vec![ + // U256::from_dec_str("11234930657858483584603353214391341220392609835907149947974795594440445721655").unwrap(), + // U256::from_dec_str("1047093079337214465686469751128183347143657884406521365857439579470759333731").unwrap(), + // ], + // vec![ + // U256::from_dec_str("15864899975231343872664645828141071246029692141564279838230890638453916423742").unwrap(), + // U256::from_dec_str("12053277475368564348616897081746431255423835262329161057768339971384736640081").unwrap(), + // ], + // ], + // vec![ + // vec![ + // U256::from_dec_str("20662189442791195318296211376162761628558291902545582141646463139520777475283").unwrap(), + // U256::from_dec_str("9279465006661849499753241364514057268552316193158700659184124742215268752791").unwrap(), + // ], + // vec![ + // U256::from_dec_str("17033606864312833588672465768726096906720807717470346504048425104291392352898").unwrap(), + // U256::from_dec_str("15319242533246792039334613039385600689133248724151496600840914674340560979641").unwrap(), + // ], + // ], + // vec![ + // vec![ + // U256::from_dec_str("3303817333656562581428241644233610206796391323593261940899405821542387319372").unwrap(), + // U256::from_dec_str("12434486975702473910116656089923156849733601159782506519440013280731025013736").unwrap(), + // ], + // vec![ + // U256::from_dec_str("9561232329300105849651786447909752108987569955850131116304832039966768267007").unwrap(), + // U256::from_dec_str("18486557213071145739422364713271115450952939790314495487369777335095317193174").unwrap(), + // ] + // ], + // vec![ + // vec![ + // U256::from_dec_str("5864321703423906069527768678401445332135246771872328360194332677453860634867").unwrap(), + // U256::from_dec_str("3305620141441221125469209629518919979790470359050105194093502369856652644459").unwrap(), + // ], + // vec![ + // U256::from_dec_str("1810088252629429255118238329671475280643793553294287131634484491846973310510").unwrap(), + // U256::from_dec_str("20707970746663158481851347112547705553728126185220754421254503093218351233120").unwrap(), + // ] + // ] + // ); + + // let valid_input = vec![ + // U256::from_dec_str("11033755416221607095").unwrap(), + // U256::from_dec_str("14172640425079373737").unwrap(), + // U256::from_dec_str("17268699570210893519").unwrap(), + // U256::from_dec_str("2451003838444787962").unwrap(), + // ]; + + // let verifying_key = VerifyingKey::new(proof, vk, valid_input); + + // let zk_verifier = ZKPrecompileVerifier::new( + // H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), + // verifying_key + // ); + + // let encoded_call = zk_verifier.generate_benchmarking_parameters(); + + // let gas_limit_call = 1000000; + // let value = U256::default(); + // let is_transactional = true; + // let validate = true; + // }:{ + // let call_runner_results = ::Runner::call( + // caller, + // contract_address, + // encoded_call, + // value, + // gas_limit_call, + // Some(U256::from(1_000_000_000)), + // Some(U256::from(1_000_000_000)), + // None, + // Vec::new(), + // is_transactional, + // validate, + // ::config(), + // ); + // // log::info!( + // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // // "Benchmarking call end.", + // // ); + // match call_runner_results { + // Ok(info) => { + // let output = info.value; + // // log::info!( + // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // // "output result {:?}", + // // output + // // ); + // if output.len() >= 32 { + // let mut result_bytes = [0u8; 32]; + // result_bytes.copy_from_slice(&output[output.len() - 32..]); + // let result = U256::from_big_endian(&result_bytes); + // // log::info!( + // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // // "Verification result {result:?}", + // // ); + // assert_eq!(result, U256::one(), "The contract did not return true"); + // } + // }, + // Err(e) => { + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "Benchmarking failed", + // ); + // } + // } + // } + // nconstraints_30_input_90000 { + // use frame_benchmarking::vec; + // use sp_core::{H160, U256, H256}; + + // let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + // let contract_address = H160::from_low_u64_be(0x8888); + + // let proof = Proof::new( + // vec![ + // U256::from_dec_str("7949275001087845673352113652992317737416671749823042856819742064958185730665").unwrap(), + // U256::from_dec_str("5891863541401068443747112095836743353338477825995666306081231182884954636005").unwrap(), + // ], + // vec![ + // vec![ + // U256::from_dec_str("12960565378826264234747222392568347150301360486418725511109506548813034322775").unwrap(), + // U256::from_dec_str("6924824876048701587380679111548259437770370772320848338373383587483809707515").unwrap(), + // ], + // vec![ + // U256::from_dec_str("21689747160304810742710652756166876177223750769696622871469266436845305438116").unwrap(), + // U256::from_dec_str("14167066926549192557125941689316913820167617731059401320567819691908586156039").unwrap(), + // ], + // ], + // vec![ + // U256::from_dec_str("19186797317064887099470636752510606772753033946198593325337771098325482447274").unwrap(), + // U256::from_dec_str("3350186543680262034371474397706130211690310055235028696466009478959025709845").unwrap(), + // ] + // ); + + // let vk = VerifyingKeyComponents::new( + // vec![ + // U256::from_dec_str("6828794497030502754628523747507406719479438181845328406281207577196379759609").unwrap(), + // U256::from_dec_str("5561027388439947090438746111225212164455366280326670821700904471009784329896").unwrap(), + // ], + // vec![ + // vec![ + // U256::from_dec_str("1648517694167305339737563900225685665396551354808983529387892872646841040850").unwrap(), + // U256::from_dec_str("15406833006990307743521713564090315343374212223020060642984366610793788667116").unwrap(), + // ], + // vec![ + // U256::from_dec_str("14591594646846027404699868040454897990147675572067174007423843530180728597612").unwrap(), + // U256::from_dec_str("2940958434778941597191243007999700895445672570190450648227198352981565653913").unwrap(), + // ], + // ], + // vec![ + // vec![ + // U256::from_dec_str("7676142418543194845482248509044991512324196983308812731866772308356979871307").unwrap(), + // U256::from_dec_str("21511013842679919895947796523736214038726875927496967606596253311081756690725").unwrap(), + // ], + // vec![ + // U256::from_dec_str("4652378032872178978450279958290699982888059033676566152376150880744787185780").unwrap(), + // U256::from_dec_str("467504210088082002071026778234767679654059202832780062786965483300786044530").unwrap(), + // ], + // ], + // vec![ + // vec![ + // U256::from_dec_str("20744282071154891204049714936088748576694067059171789505913191933597423689555").unwrap(), + // U256::from_dec_str("12596866572762256583276410876169296807308160857887657727882625055041251553242").unwrap(), + // ], + // vec![ + // U256::from_dec_str("3588798969790877834321031026222278845206273301850566393834657489341158616535").unwrap(), + // U256::from_dec_str("19268326464935908053037454129640878232926568425004490855381855273084219557079").unwrap(), + // ] + // ], + // vec![ + // vec![ + // U256::from_dec_str("10928515506460596401961934744263657631726985113185854450754018401146226707446").unwrap(), + // U256::from_dec_str("1043421123157233618994554398894819122012315878788274412803269234825060696656").unwrap(), + // ], + // vec![ + // U256::from_dec_str("21802758012415709270812560952687831790545411568500639317690833457802568775035").unwrap(), + // U256::from_dec_str("8926874931677263335476856545765471099163606107894025045476086328360781102193").unwrap(), + // ] + // ] + // ); + + // let valid_input = vec![ + // U256::from_dec_str("2553457387449696641").unwrap(), + // U256::from_dec_str("815105491620421980").unwrap(), + // U256::from_dec_str("17800546104409657428").unwrap(), + // U256::from_dec_str("2866567216183504159").unwrap(), + // ]; + + // let verifying_key = VerifyingKey::new(proof, vk, valid_input); + + // let zk_verifier = ZKPrecompileVerifier::new( + // H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), + // verifying_key + // ); + + // let encoded_call = zk_verifier.generate_benchmarking_parameters(); + + // let gas_limit_call = 1000000; + // let value = U256::default(); + // let is_transactional = true; + // let validate = true; + // }:{ + // let call_runner_results = ::Runner::call( + // caller, + // contract_address, + // encoded_call, + // value, + // gas_limit_call, + // Some(U256::from(1_000_000_000)), + // Some(U256::from(1_000_000_000)), + // None, + // Vec::new(), + // is_transactional, + // validate, + // ::config(), + // ); + // // log::info!( + // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // // "Benchmarking call end.", + // // ); + // match call_runner_results { + // Ok(info) => { + // let output = info.value; + // // log::info!( + // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // // "output result {:?}", + // // output + // // ); + // if output.len() >= 32 { + // let mut result_bytes = [0u8; 32]; + // result_bytes.copy_from_slice(&output[output.len() - 32..]); + // let result = U256::from_big_endian(&result_bytes); + // // log::info!( + // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // // "Verification result {result:?}", + // // ); + // assert_eq!(result, U256::one(), "The contract did not return true"); + // } + // }, + // Err(e) => { + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "Benchmarking failed", + // ); + // } + // } + // } + // nconstraints_30_input_200000 { + // use frame_benchmarking::vec; + // use sp_core::{H160, U256, H256}; + + // let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + // let contract_address = H160::from_low_u64_be(0x8888); + + // let proof = Proof::new( + // vec![ + // U256::from_dec_str("19903885251949679146607224162906437591286076549652044731739108226015926915860").unwrap(), + // U256::from_dec_str("11870922578907159231760438847634888925027596611865086487008358810346509550746").unwrap(), + // ], + // vec![ + // vec![ + // U256::from_dec_str("7572350741301793140585595336451242554319145556316993930579910816773197602180").unwrap(), + // U256::from_dec_str("16166630091911008518878343585755669995589761813810965163203815419554661335912").unwrap(), + // ], + // vec![ + // U256::from_dec_str("10479558631339350148140324543423297113164179377516410954282474094862685762111").unwrap(), + // U256::from_dec_str("1538599836393367534859442557225095989831507256094436416355361165563840234277").unwrap(), + // ], + // ], + // vec![ + // U256::from_dec_str("18566368172831132986640612657510108843544042128267080758083569019690510537842").unwrap(), + // U256::from_dec_str("14637144036179606956000163117625168358523245864386632910728645092984303842870").unwrap(), + // ] + // ); + + // let vk = VerifyingKeyComponents::new( + // vec![ + // U256::from_dec_str("3388366987275268645608688601800038483480506575351380219459271970783548315310").unwrap(), + // U256::from_dec_str("10139982329791419477606385196757134153200700293861474061701578521738893563314").unwrap(), + // ], + // vec![ + // vec![ + // U256::from_dec_str("17293003127353596916845398615566872053529832484770184120881889494052646686398").unwrap(), + // U256::from_dec_str("3746742577904007471872553744363212404516454459540143078991207693255568088158").unwrap(), + // ], + // vec![ + // U256::from_dec_str("18996426015092705424501193523094438770040629737761363033585766320236602756452").unwrap(), + // U256::from_dec_str("5993252813486169444483155589566709251331252167093428959716521680127596688663").unwrap(), + // ], + // ], + // vec![ + // vec![ + // U256::from_dec_str("86221489590459042456285770827248107701675460052532768290239949641616327672").unwrap(), + // U256::from_dec_str("21618235778373592971185937996314200926578828337383413751502402964191761009384").unwrap(), + // ], + // vec![ + // U256::from_dec_str("10453895050472290645179709462208119639593757329666114205922088367970822668124").unwrap(), + // U256::from_dec_str("16924749634830145681809164670725933237166438445526123149706427927968513710893").unwrap(), + // ], + // ], + // vec![ + // vec![ + // U256::from_dec_str("20506347836984398194650179863264269358088067779451739307543701941138658771117").unwrap(), + // U256::from_dec_str("15256122081275324863091225387225218399888282841698960666742408225921079848693").unwrap(), + // ], + // vec![ + // U256::from_dec_str("7881380592415293900063452944037916715621668238658562838630198037249553436647").unwrap(), + // U256::from_dec_str("6003465274284900873747728448177380007802003937728590930467990944623586277089").unwrap(), + // ] + // ], + // vec![ + // vec![ + // U256::from_dec_str("5531662187275540864474040102019845108669876235687831703751327129559212127084").unwrap(), + // U256::from_dec_str("11455786949456856409363436892267690994602451302132959153447251790964376014822").unwrap(), + // ], + // vec![ + // U256::from_dec_str("17221728819314881853232886080533000381382340762620795831983019279828981481257").unwrap(), + // U256::from_dec_str("19341881794793455210912817199750586531241336493382870655971958667936340901503").unwrap(), + // ] + // ] + // ); + + // let valid_input = vec![ + // U256::from_dec_str("17510768071209558285").unwrap(), + // U256::from_dec_str("11281672863963944712").unwrap(), + // U256::from_dec_str("17936011136389338927").unwrap(), + // U256::from_dec_str("2683423138755332222").unwrap(), + // ]; + + // let verifying_key = VerifyingKey::new(proof, vk, valid_input); + + // let zk_verifier = ZKPrecompileVerifier::new( + // H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), + // verifying_key + // ); + + // let encoded_call = zk_verifier.generate_benchmarking_parameters(); + + // let gas_limit_call = 1000000; + // let value = U256::default(); + // let is_transactional = true; + // let validate = true; + // }:{ + // let call_runner_results = ::Runner::call( + // caller, + // contract_address, + // encoded_call, + // value, + // gas_limit_call, + // Some(U256::from(1_000_000_000)), + // Some(U256::from(1_000_000_000)), + // None, + // Vec::new(), + // is_transactional, + // validate, + // ::config(), + // ); + // // log::info!( + // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // // "Benchmarking call end.", + // // ); + // match call_runner_results { + // Ok(info) => { + // let output = info.value; + // // log::info!( + // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // // "output result {:?}", + // // output + // // ); + // if output.len() >= 32 { + // let mut result_bytes = [0u8; 32]; + // result_bytes.copy_from_slice(&output[output.len() - 32..]); + // let result = U256::from_big_endian(&result_bytes); + // // log::info!( + // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // // "Verification result {result:?}", + // // ); + // assert_eq!(result, U256::one(), "The contract did not return true"); + // } + // }, + // Err(e) => { + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "Benchmarking failed", + // ); + // } + // } + // } + + // sum_10 { + // use frame_benchmarking::vec; + // use sp_core::{H160, U256, H256}; + + // let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + // let contract_address = H160::from_low_u64_be(0x8888); + + // let proof = Proof::new( + // vec![ + // U256::from_dec_str("4479438672593572194843316486259284641920166054544576564310150763796220593742").unwrap(), + // U256::from_dec_str("5717857931841301866217201485541887040818093727574311517591849036289507799141").unwrap(), + // ], + // vec![ + // vec![ + // U256::from_dec_str("438102211713357984070931589322877643391719193099221891191956755149301376056").unwrap(), + // U256::from_dec_str("14696299438400225528910058565202329177181471318954607581306780544413371767738").unwrap(), + // ], + // vec![ + // U256::from_dec_str("18723112929967827488252389384208353884816003870032279933823625467146809072448").unwrap(), + // U256::from_dec_str("781225142569358922067919798403956593420009838230922093237868933021043854113").unwrap(), + // ], + // ], + // vec![ + // U256::from_dec_str("10481213903673023503381125372528754955378591812884098928519623211332171467098").unwrap(), + // U256::from_dec_str("15098195705682978185145469811146985310923026878303775073727891846327587112885").unwrap(), + // ] + // ); + + // let vk = VerifyingKeyComponents::new( + // vec![ + // U256::from_dec_str("10600514820627226711889163536575359330497844540484876797299835164575096986123").unwrap(), + // U256::from_dec_str("8955505242614929800342716899005854501255692108538633212406728467939250778259").unwrap(), + // ], + // vec![ + // vec![ + // U256::from_dec_str("11358515176167160981846987587695931342878788452018419590778128561277894807040").unwrap(), + // U256::from_dec_str("7367100375568995524851051084377016949291621141008718892167611998460177966556").unwrap(), + // ], + // vec![ + // U256::from_dec_str("9986374126991936592889887298811366506288970021158383914729072242552712258999").unwrap(), + // U256::from_dec_str("5917047061876555575617149777207682047359711575786648519096749890796145313142").unwrap(), + // ], + // ], + // vec![ + // vec![ + // U256::from_dec_str("13008751738470482081156013535203222043379316308698376931322848604706786065862").unwrap(), + // U256::from_dec_str("3415558414191757405655644967374577939532374518318643852418890898323033638525").unwrap(), + // ], + // vec![ + // U256::from_dec_str("2104722493853714523712648261788727756558190509825976396834309269877977849365").unwrap(), + // U256::from_dec_str("6877732520157662584755946842350755740172704606349660337522459938993730313391").unwrap(), + // ], + // ], + // vec![ + // vec![ + // U256::from_dec_str("12470512550870605078154922234115021580073605821744497867586706681115325377951").unwrap(), + // U256::from_dec_str("3964373607930903502336465614571930627592350216968107805643078708599943392195").unwrap(), + // ], + // vec![ + // U256::from_dec_str("9054619931591683490625148848351137928205510101241639415537408964292455344707").unwrap(), + // U256::from_dec_str("14433710971468466044075036729227299898791551573181475688890434779549865103322").unwrap(), + // ] + // ], + // vec![ + // vec![ + // U256::from_dec_str("17691779713798847872985546462247707503645016076661816616388979822201176829753").unwrap(), + // U256::from_dec_str("14451231434311244057691431183198403713720423327382654964068207207079455187712").unwrap(), + // ], + // vec![ + // U256::from_dec_str("13620414910695185146987530463229819484652710069270717148541433045978322585419").unwrap(), + // U256::from_dec_str("10875872907505029426874795808985164080699672034676409959252328566889297105865").unwrap(), + // ] + // ] + // ); + + // let valid_input = vec![ + // U256::from_dec_str("55").unwrap(), + // U256::from_dec_str("0").unwrap(), + // U256::from_dec_str("0").unwrap(), + // U256::from_dec_str("0").unwrap(), + // ]; + + // let verifying_key = VerifyingKey::new(proof, vk, valid_input); + + // let zk_verifier = ZKPrecompileVerifier::new( + // H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), + // verifying_key + // ); + + // let encoded_call = zk_verifier.generate_benchmarking_parameters(); + + // let gas_limit_call = 1000000; + // let value = U256::default(); + // let is_transactional = true; + // let validate = true; + // }:{ + // let call_runner_results = ::Runner::call( + // caller, + // contract_address, + // encoded_call, + // value, + // gas_limit_call, + // Some(U256::from(1_000_000_000)), + // Some(U256::from(1_000_000_000)), + // None, + // Vec::new(), + // is_transactional, + // validate, + // ::config(), + // ); + // // log::info!( + // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // // "Benchmarking call end.", + // // ); + // match call_runner_results { + // Ok(info) => { + // let output = info.value; + // // log::info!( + // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // // "output result {:?}", + // // output + // // ); + // if output.len() >= 32 { + // let mut result_bytes = [0u8; 32]; + // result_bytes.copy_from_slice(&output[output.len() - 32..]); + // let result = U256::from_big_endian(&result_bytes); + // // log::info!( + // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // // "Verification result {result:?}", + // // ); + // assert_eq!(result, U256::one(), "The contract did not return true"); + // } + // }, + // Err(e) => { + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "Benchmarking failed", + // ); + // } + // } + // } + // sum_50 { + // use frame_benchmarking::vec; + // use sp_core::{H160, U256, H256}; + + // let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + // let contract_address = H160::from_low_u64_be(0x8888); + + // let proof = Proof::new( + // vec![ + // U256::from_dec_str("3114941071688532747454764921300681791980888248199392522675009157778549895455").unwrap(), + // U256::from_dec_str("6816680925124829082835883802586391663161606011222680818599486084577544527516").unwrap(), + // ], + // vec![ + // vec![ + // U256::from_dec_str("15037393792780247314317740287895838240941967969445981241792818111317913065010").unwrap(), + // U256::from_dec_str("3834028682995799272226496422556310257938795862629020590068471611902272764146").unwrap(), + // ], + // vec![ + // U256::from_dec_str("4023883034822047449129381158539093978377425715903419218696272130851521242085").unwrap(), + // U256::from_dec_str("13058906875228264286034925941047330220503025517973111955115072416984072943122").unwrap(), + // ], + // ], + // vec![ + // U256::from_dec_str("5344888056894889487007260648469199417556856955544355154291642477677322944786").unwrap(), + // U256::from_dec_str("19843194668352645797068691966948915569058668700830773246420232986019393210063").unwrap(), + // ] + // ); + + // let vk = VerifyingKeyComponents::new( + // vec![ + // U256::from_dec_str("19257923683733118221652593587810195852599358412856281104090957905722976964370").unwrap(), + // U256::from_dec_str("19519729727735873999148754136012144616045305047716967685280834855818506563720").unwrap(), + // ], + // vec![ + // vec![ + // U256::from_dec_str("4418606700813566482216037680863387214037640478555893901955308344977554198718").unwrap(), + // U256::from_dec_str("18046767849922558936185002168253454007598159984067380537392936220227127228867").unwrap(), + // ], + // vec![ + // U256::from_dec_str("100725403545603844224319783153051757027683253433977048289134569498829183303").unwrap(), + // U256::from_dec_str("9785321212288652698655727476617710557399711491394256119637648908536562741634").unwrap(), + // ], + // ], + // vec![ + // vec![ + // U256::from_dec_str("1627724482578854283892192357407161928314687375966263116172485631707694669812").unwrap(), + // U256::from_dec_str("6839802000376483025048211234449253336394632788399066904541666906747650234382").unwrap(), + // ], + // vec![ + // U256::from_dec_str("17974577137954059751166162247265070307968439813726452160113109110701162631938").unwrap(), + // U256::from_dec_str("21289972529626386698860098501676961527414208445147370800462053148477683157991").unwrap(), + // ], + // ], + // vec![ + // vec![ + // U256::from_dec_str("7184324332054694882815451883063466258810341506246659357034202660488015984306").unwrap(), + // U256::from_dec_str("14398081398842334723334363407187040569418119441776629783632309768037771007327").unwrap(), + // ], + // vec![ + // U256::from_dec_str("17277213124622419955089087696435667358779233792945822269342368397066818801481").unwrap(), + // U256::from_dec_str("19811781065417531456401229702422997450338397507283920558741452740912313583930").unwrap(), + // ] + // ], + // vec![ + // vec![ + // U256::from_dec_str("20284064245383237908740484779775789109386762825985839657586769414934584661714").unwrap(), + // U256::from_dec_str("17363934481847560975462360104367791101351872886050159351690589725380050257409").unwrap(), + // ], + // vec![ + // U256::from_dec_str("3904403738619431633601997032597659843284744078768864151280168218762434423692").unwrap(), + // U256::from_dec_str("4413868989856264583489102855186788724178233679332360263809134874064797750675").unwrap(), + // ] + // ] + // ); + + // let valid_input = vec![ + // U256::from_dec_str("1275").unwrap(), + // U256::from_dec_str("0").unwrap(), + // U256::from_dec_str("0").unwrap(), + // U256::from_dec_str("0").unwrap(), + // ]; + + // let verifying_key = VerifyingKey::new(proof, vk, valid_input); + + // let zk_verifier = ZKPrecompileVerifier::new( + // H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), + // verifying_key + // ); + + // let encoded_call = zk_verifier.generate_benchmarking_parameters(); + + // let gas_limit_call = 1000000; + // let value = U256::default(); + // let is_transactional = true; + // let validate = true; + // }:{ + // let call_runner_results = ::Runner::call( + // caller, + // contract_address, + // encoded_call, + // value, + // gas_limit_call, + // Some(U256::from(1_000_000_000)), + // Some(U256::from(1_000_000_000)), + // None, + // Vec::new(), + // is_transactional, + // validate, + // ::config(), + // ); + // // log::info!( + // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // // "Benchmarking call end.", + // // ); + // match call_runner_results { + // Ok(info) => { + // let output = info.value; + // // log::info!( + // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // // "output result {:?}", + // // output + // // ); + // if output.len() >= 32 { + // let mut result_bytes = [0u8; 32]; + // result_bytes.copy_from_slice(&output[output.len() - 32..]); + // let result = U256::from_big_endian(&result_bytes); + // // log::info!( + // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // // "Verification result {result:?}", + // // ); + // assert_eq!(result, U256::one(), "The contract did not return true"); + // } + // }, + // Err(e) => { + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "Benchmarking failed", + // ); + // } + // } + // } + + // sum_5000 { + // use frame_benchmarking::vec; + // use sp_core::{H160, U256, H256}; + + // let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + // let contract_address = H160::from_low_u64_be(0x8888); + + // let proof = Proof::new( + // vec![ + // U256::from_dec_str("2104134032972066019913571175532882184351637942839921828138208604817397790978").unwrap(), + // U256::from_dec_str("12625149522977248086293073767826715132905823679345516244316272790389621024575").unwrap(), + // ], + // vec![ + // vec![ + // U256::from_dec_str("18955718237898317556602416465218566057031982163829528123671300051574728240883").unwrap(), + // U256::from_dec_str("18075306515520608621953959878874546391551215874677138383864573851396832159644").unwrap(), + // ], + // vec![ + // U256::from_dec_str("3166476742865671627115278436666969186969644878053983393309132722947819232105").unwrap(), + // U256::from_dec_str("8051049247607109861344268872842958063551670273736053865524986958976361214062").unwrap(), + // ], + // ], + // vec![ + // U256::from_dec_str("4814291763265323888812051590287571407031542635142019809665068757723218701627").unwrap(), + // U256::from_dec_str("17930948070313125851452005455953009375012074818817251382455220462443054837203").unwrap(), + // ] + // ); + + // let vk = VerifyingKeyComponents::new( + // vec![ + // U256::from_dec_str("19624232987744880202266197753309961915632611879850947888541508003701736644214").unwrap(), + // U256::from_dec_str("5019843555387010050200067558096501184079196549422645876015184268981691000261").unwrap(), + // ], + // vec![ + // vec![ + // U256::from_dec_str("5150307298606577026396875555180704696345763655981810466632357002439129266461").unwrap(), + // U256::from_dec_str("3020656302335648031712857271727816386298675153130933709481311850060508289333").unwrap(), + // ], + // vec![ + // U256::from_dec_str("19547576195358452722114991449875886954598568010341500952076854329553571219720").unwrap(), + // U256::from_dec_str("3895331072082263654317901227968966808293407907751128382134753194859731114729").unwrap(), + // ], + // ], + // vec![ + // vec![ + // U256::from_dec_str("165136411129701665870237237981894748637834826722462614973940945603783242464").unwrap(), + // U256::from_dec_str("10766657827945181878791518932726777890925519579254084496220957371082172349194").unwrap(), + // ], + // vec![ + // U256::from_dec_str("1813485593016293809685571822392302147347136682526622353828238069063634409991").unwrap(), + // U256::from_dec_str("12730118542350484957903782401323352413406115135420607527656226977122246298735").unwrap(), + // ], + // ], + // vec![ + // vec![ + // U256::from_dec_str("5792479463369352075979003547777370241697788651005116088867026457677720533395").unwrap(), + // U256::from_dec_str("16882159064341957118950974052606760693554763076237663579029547802558086431378").unwrap(), + // ], + // vec![ + // U256::from_dec_str("15201299876801474331768851307298179430198466709727112330042020251492139993850").unwrap(), + // U256::from_dec_str("893863620414771464835789333501093176356026692988850717670551586498757709875").unwrap(), + // ] + // ], + // vec![ + // vec![ + // U256::from_dec_str("19450458898299554306247087083239008884256452312356497246598109368644839627523").unwrap(), + // U256::from_dec_str("123992241310851816418828784530061727329258706748227789362318537744292975333").unwrap(), + // ], + // vec![ + // U256::from_dec_str("1650700423026830428199086201346242616543834285406293983963791012821269466913").unwrap(), + // U256::from_dec_str("3152920600939501404817148774751227981988970987313622659392580888754616114976").unwrap(), + // ] + // ] + // ); + + // let valid_input = vec![ + // U256::from_dec_str("12502500").unwrap(), + // U256::from_dec_str("0").unwrap(), + // U256::from_dec_str("0").unwrap(), + // U256::from_dec_str("0").unwrap(), + // ]; + + // let verifying_key = VerifyingKey::new(proof, vk, valid_input); + + // let zk_verifier = ZKPrecompileVerifier::new( + // H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), + // verifying_key + // ); + + // let encoded_call = zk_verifier.generate_benchmarking_parameters(); + + // let gas_limit_call = 1000000; + // let value = U256::default(); + // let is_transactional = true; + // let validate = true; + // }:{ + // let call_runner_results = ::Runner::call( + // caller, + // contract_address, + // encoded_call, + // value, + // gas_limit_call, + // Some(U256::from(1_000_000_000)), + // Some(U256::from(1_000_000_000)), + // None, + // Vec::new(), + // is_transactional, + // validate, + // ::config(), + // ); + // // log::info!( + // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // // "Benchmarking call end.", + // // ); + // match call_runner_results { + // Ok(info) => { + // let output = info.value; + // // log::info!( + // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // // "output result {:?}", + // // output + // // ); + // if output.len() >= 32 { + // let mut result_bytes = [0u8; 32]; + // result_bytes.copy_from_slice(&output[output.len() - 32..]); + // let result = U256::from_big_endian(&result_bytes); + // // log::info!( + // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // // "Verification result {result:?}", + // // ); + // assert_eq!(result, U256::one(), "The contract did not return true"); + // } + // }, + // Err(e) => { + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "Benchmarking failed", + // ); + // } + // } + // } + + sum_50000 { use frame_benchmarking::vec; - use sp_core::{H160, U256}; - use ethabi::Token; + use sp_core::{H160, U256, H256}; let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); - let contract_address = H160::from_low_u64_be(0x8888); - let proof_a = vec![ - U256::from_dec_str("797572477248804392444831225209327368031406989322029802514696832026672358416").unwrap(), - U256::from_dec_str("14792745011262875092811677474030034668956937211525097875362241962916137456465").unwrap() - ]; - - let proof_b = vec![ + let proof = Proof::new( vec![ - U256::from_dec_str("18780733901893439739371423627306821236863790649657196488891599355591321953851").unwrap(), - U256::from_dec_str("9680544448661229130288510239162388428669756867621972396627016600055984349499").unwrap() + U256::from_dec_str("3622731332670597344105510591712672243986951828055076939276801448101954799142").unwrap(), + U256::from_dec_str("6346995225908387053909829054799399014732696227124687083236550584317776767493").unwrap(), ], vec![ - U256::from_dec_str("11738424367558729478935071422176167853312257211377899850934753533414170335039").unwrap(), - U256::from_dec_str("18233646049353711985788868148390262624363849777798470342741694587137854046312").unwrap() + vec![ + U256::from_dec_str("12374003776423645952892988427832420613719996381174255643042478809936185481102").unwrap(), + U256::from_dec_str("19834002842796431843925774571161786816886891256460707223697642395803180051660").unwrap(), + ], + vec![ + U256::from_dec_str("15842468063355971498862011336838854044444278845667126879720180643365485131394").unwrap(), + U256::from_dec_str("11332976987055222769230958577354523957540694040368499035276674269133591651835").unwrap(), + ], ], - ]; - - let proof_c = vec![ - U256::from_dec_str("9030949957263413847331466570610168053394322783722896104311457102193711447736").unwrap(), - U256::from_dec_str("19892969453275240241999306433024784295865139436513729478470715581670537973183").unwrap() - ]; + vec![ + U256::from_dec_str("18912109791042994221316455125175063781392361813956238026666504224007632366190").unwrap(), + U256::from_dec_str("1279350170906221254449513257961023432324983489115073965271989276735247718491").unwrap(), + ] + ); - let vk_alpha = vec![ - U256::from_dec_str("9129483983788792790250516546077504592262306584249196914035593903220113466346").unwrap(), - U256::from_dec_str("12931577676488623470369386127145659839850514961607631368866187840816419893745").unwrap() - ]; + let vk = VerifyingKeyComponents::new( + vec![ + U256::from_dec_str("4336612673641723359515805150029160944183167584813833363044992795434703631887").unwrap(), + U256::from_dec_str("9137641056584966180441584227424719192181063342929330231422917545355236845740").unwrap(), + ], + vec![ + vec![ + U256::from_dec_str("3730256152430451126522590663651372021566043227051775605895559420879019685920").unwrap(), + U256::from_dec_str("20728862641139597395451147113430954379546155357229963990677814892281218309701").unwrap(), + ], + vec![ + U256::from_dec_str("7502099261339400768454017924955286264806514986185112220563862169144222322249").unwrap(), + U256::from_dec_str("5006842384329558490484345088692295975571937103770535130257247983097172628130").unwrap(), + ], + ], + vec![ + vec![ + U256::from_dec_str("10823916364920299474063731894264827730751008163382814050357751676256530518677").unwrap(), + U256::from_dec_str("2964232036989531397729723217960695207528224009959841295885668746926591289356").unwrap(), + ], + vec![ + U256::from_dec_str("17121950139992519518807185063471627099057806698144667325262783943067486697035").unwrap(), + U256::from_dec_str("20705259140101372627184216142337506779584441204290869224541344200465485566171").unwrap(), + ] + ], + vec![ + vec![ + U256::from_dec_str("4609739673127175843417224333269860670973152461609019180497630782244542871322").unwrap(), + U256::from_dec_str("5981417778986924179768792717543475972483606473185751180808540751057035223819").unwrap(), + ], + vec![ + U256::from_dec_str("20792630753101735929108699805283402009145413137839446488160591610595405740916").unwrap(), + U256::from_dec_str("12712973769233860870993411006074441942320673677464961930321479085937150536543").unwrap(), + ], + ], + vec![ + vec![ + U256::from_dec_str("2422043721758703885072327542268388166893061296643655177987760545832562233524").unwrap(), + U256::from_dec_str("2939428867547955771917605064560167662212054903067344050223483963838535670368").unwrap(), + ], + vec![ + U256::from_dec_str("9800364647151674719834337323206936270428884273217284206736997065787811631092").unwrap(), + U256::from_dec_str("1425891826916485854275507234274197381767987210474487566305467407052485766733").unwrap(), + ] + ] + ); - let vk_beta = vec![ - vec![ - U256::from_dec_str("7733336395661433750318564428962011373303863005056937588991328321699559429718").unwrap(), - U256::from_dec_str("17750049529131446238696663224077924496537231636880056629697436601439393528008").unwrap() - ], - vec![ - U256::from_dec_str("8293377799807146929370692717869590893937274675192938831619975844923042030881").unwrap(), - U256::from_dec_str("4263357454976975022836583944985361945040552205174286149616049652777546621773").unwrap() - ], + let valid_input = vec![ + U256::from_dec_str("1250025000").unwrap() ]; - let vk_gamma = vec![ - vec![ - U256::from_dec_str("14151440830510271657142608578154654007777206023678518530807735001262951045692").unwrap(), - U256::from_dec_str("1767291767856447136921215746781550838727073342526929959676175537783883225487").unwrap() - ], - vec![ - U256::from_dec_str("15173492886826553839363776087467612357738824024869668919975796903208737039768").unwrap(), - U256::from_dec_str("11930052964402267454553402353579104183135244867064411968119095331986593125500").unwrap() - ], - ]; + let verifying_key = VerifyingKey::new(proof, vk, valid_input); - let vk_delta = vec![ - vec![ - U256::from_dec_str("7299631212873411609242516274008416712647200249879388590190636109884194725508").unwrap(), - U256::from_dec_str("8501638231329375259007419224045458732070699435817171076438597961712893321854").unwrap() - ], - vec![ - U256::from_dec_str("15047730134046003932972688387420458293142941608648562801026918857178341643816").unwrap(), - U256::from_dec_str("14151346772944327368443846389587994785327280897500259203977403093792866270134").unwrap() - ] - ]; + let zk_verifier = ZKPrecompileVerifier::new( + H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), + verifying_key + ); - let vk_ic = vec![ - vec![ - U256::from_dec_str("731357633257473743905158797156252139612893761758845410915414966970585493895").unwrap(), - U256::from_dec_str("16967744642853731718627404215453394490485627147408404648214694655394595655398").unwrap() - ], - vec![ - U256::from_dec_str("1346463672788502974713113436051481443629775449244308207040448867039527497840").unwrap(), - U256::from_dec_str("18844670641178242764504539209612934748132154582441062514954805312543875749365").unwrap() - ] - ]; + let encoded_call = zk_verifier.generate_benchmarking_parameters(); - let valid_input = vec![U256::from_dec_str("9545317761180864681").unwrap(), U256::from_dec_str("15203947991842169444").unwrap(), U256::from_dec_str("11010182592065041277").unwrap(), U256::from_dec_str("2750389353565937097").unwrap()]; - let mut encoded_call = vec![0u8; 4]; - encoded_call[0..4].copy_from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..4]); - let parameters = ethabi::encode(&[ - Token::FixedArray(proof_a.into_iter().map(Token::Uint).collect()), - Token::FixedArray(proof_b.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), - Token::FixedArray(proof_c.into_iter().map(Token::Uint).collect()), - Token::FixedArray(vk_alpha.into_iter().map(Token::Uint).collect()), - Token::FixedArray(vk_beta.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), - Token::FixedArray(vk_gamma.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), - Token::FixedArray(vk_delta.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), - Token::Array(vk_ic.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), - Token::Array(valid_input.into_iter().map(Token::Uint).collect()), - ]); - encoded_call.extend(parameters); let gas_limit_call = 1000000; let value = U256::default(); let is_transactional = true; @@ -429,19 +2262,19 @@ benchmarks! { match call_runner_results { Ok(info) => { let output = info.value; - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "output result {:?}", - // output - // ); + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "output result {:?}", + output + ); if output.len() >= 32 { let mut result_bytes = [0u8; 32]; result_bytes.copy_from_slice(&output[output.len() - 32..]); let result = U256::from_big_endian(&result_bytes); - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "Verification result {result:?}", - // ); + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "Verification result {result:?}", + ); assert_eq!(result, U256::one(), "The contract did not return true"); } }, @@ -454,1020 +2287,6 @@ benchmarks! { } } - nconstraints_25 { - use frame_benchmarking::vec; - use sp_core::{H160, U256}; - use ethabi::Token; - - let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); - - let contract_address = H160::from_low_u64_be(0x8888); - - let proof_a = vec![ - U256::from_dec_str("5442688768232443344552263783267390208856198689842640798776177410815565547367").unwrap(), - U256::from_dec_str("16310414003289240410078247718742394211798524980802086932072100478604843138879").unwrap() - ]; - - let proof_b = vec![ - vec![ - U256::from_dec_str("18190532627346636099188351540696740134404407871692706498689154867172280651496").unwrap(), - U256::from_dec_str("275967461706136585361355308922764172109936742989119387744117535714873890136").unwrap() - ], - vec![ - U256::from_dec_str("20432859376686408480939951320620928735684720753051796534902941362107917945448").unwrap(), - U256::from_dec_str("20575328298763015614805638365408623315084841523436681299021166233260739215585").unwrap() - ], - ]; - - let proof_c = vec![ - U256::from_dec_str("21729070949671190651383446829182792170701603278872739139487134063534373496928").unwrap(), - U256::from_dec_str("11473159888261500071826283643864569393105028020759142008919378165280126183791").unwrap() - ]; - - let vk_alpha = vec![ - U256::from_dec_str("6116186011971746741793619516283587796788649022044712022866691859910541408388").unwrap(), - U256::from_dec_str("9990751801376433017793027493689116570629263722237360070512991124369867111294").unwrap() - ]; - - let vk_beta = vec![ - vec![ - U256::from_dec_str("19134989187129211715471143723472806940780591878437988384412094557596618102949").unwrap(), - U256::from_dec_str("11002122036813197737012103302067373956587501561568917970913786117384906562322").unwrap() - ], - vec![ - U256::from_dec_str("20227241808293262878318140546702845934510851943742865848865718895434416271823").unwrap(), - U256::from_dec_str("1208695332664339284660261403674630632193027591536251936703796527895870746053").unwrap() - ], - ]; - - let vk_gamma = vec![ - vec![ - U256::from_dec_str("9988080894620831828514001726353047899833627122523386578651185763598814334161").unwrap(), - U256::from_dec_str("1210488941280905931352250513800327257407276187767564156715231067181630088303").unwrap() - ], - vec![ - U256::from_dec_str("9123410895646419307291143661097804061907837645760653809597075433728132210845").unwrap(), - U256::from_dec_str("5940342572290825895021782196790640411792369989666988944848888929369542627086").unwrap() - ], - ]; - - let vk_delta = vec![ - vec![ - U256::from_dec_str("3845390871684034417765460290906605590268084456131570016989104541941027299587").unwrap(), - U256::from_dec_str("19451210342848170935105654531273996195376657542644165412726124373232172955450").unwrap() - ], - vec![ - U256::from_dec_str("12402386430554074306546660621773259523647713153408570111706227556424141104015").unwrap(), - U256::from_dec_str("12206340396174591766842915594324772300487750563590424709980302152249618278504").unwrap() - ] - ]; - - let vk_ic = vec![ - vec![ - U256::from_dec_str("5288881796355507035555160331041001500160990907930198297197056072823274477221").unwrap(), - U256::from_dec_str("13632806080609019911417800900671762249376036835109070627111505646509468055118").unwrap() - ], - vec![ - U256::from_dec_str("17029427908866374993625919576903554103814716934062886672833059297154117520635").unwrap(), - U256::from_dec_str("4259071212917198769064755546045521459903854045469312364340173149295579006240").unwrap() - ] - ]; - - let valid_input = vec![U256::from_dec_str("13322346319448626142").unwrap(), U256::from_dec_str("2125026056706439081").unwrap(), U256::from_dec_str("8305705901596606458").unwrap(), U256::from_dec_str("3095703818812128800").unwrap()]; - let mut encoded_call = vec![0u8; 4]; - encoded_call[0..4].copy_from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..4]); - let parameters = ethabi::encode(&[ - Token::FixedArray(proof_a.into_iter().map(Token::Uint).collect()), - Token::FixedArray(proof_b.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), - Token::FixedArray(proof_c.into_iter().map(Token::Uint).collect()), - Token::FixedArray(vk_alpha.into_iter().map(Token::Uint).collect()), - Token::FixedArray(vk_beta.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), - Token::FixedArray(vk_gamma.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), - Token::FixedArray(vk_delta.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), - Token::Array(vk_ic.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), - Token::Array(valid_input.into_iter().map(Token::Uint).collect()), - ]); - encoded_call.extend(parameters); - let gas_limit_call = 1000000; - let value = U256::default(); - let is_transactional = true; - let validate = true; - }:{ - let call_runner_results = ::Runner::call( - caller, - contract_address, - encoded_call, - value, - gas_limit_call, - Some(U256::from(1_000_000_000)), - Some(U256::from(1_000_000_000)), - None, - Vec::new(), - is_transactional, - validate, - ::config(), - ); - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "Benchmarking call end.", - // ); - match call_runner_results { - Ok(info) => { - let output = info.value; - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "output result {:?}", - // output - // ); - if output.len() >= 32 { - let mut result_bytes = [0u8; 32]; - result_bytes.copy_from_slice(&output[output.len() - 32..]); - let result = U256::from_big_endian(&result_bytes); - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "Verification result {result:?}", - // ); - assert_eq!(result, U256::one(), "The contract did not return true"); - } - }, - Err(e) => { - log::info!( - target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - "Benchmarking failed", - ); - } - } - } - - nconstraints_30 { - use frame_benchmarking::vec; - use sp_core::{H160, U256}; - use ethabi::Token; - - let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); - - let contract_address = H160::from_low_u64_be(0x8888); - - let proof_a = vec![ - U256::from_dec_str("18690487469105583830896348523194667998180545629275814901431298749603732361922").unwrap(), - U256::from_dec_str("7368590978490025622497872418876156479561347771212306366618589942495456841309").unwrap() - ]; - - let proof_b = vec![ - vec![ - U256::from_dec_str("6458484707522958224040736264962413462988793890751266991780959428701001616723").unwrap(), - U256::from_dec_str("5229552051142880655000908369897792053786596109840647032497320533202927196186").unwrap() - ], - vec![ - U256::from_dec_str("14308631389244366765238213169645232719387098057421285153016420565820252114596").unwrap(), - U256::from_dec_str("5350276954672740804922429900678406990441626154643173671817737280965857560969").unwrap() - ], - ]; - - let proof_c = vec![ - U256::from_dec_str("2116304898851279057226756458603873842331017000957857852682949878590352582212").unwrap(), - U256::from_dec_str("4667525997409073696628336876173638225578496705097212864335627957772434988886").unwrap() - ]; - - let vk_alpha = vec![ - U256::from_dec_str("6699928044611798138494735544984517284373216312890158010790742091150243853313").unwrap(), - U256::from_dec_str("13934807201585568304844420589516599892787718850719460623808296221406392586172").unwrap() - ]; - - let vk_beta = vec![ - vec![ - U256::from_dec_str("14027097432418820340011319545278213614698987547810017425098729501416647686036").unwrap(), - U256::from_dec_str("11193668485833499271260223875108511371976490160655434826777606292642378752410").unwrap() - ], - vec![ - U256::from_dec_str("20045214665848771726931611212381067857571766687548405278435917898412573204852").unwrap(), - U256::from_dec_str("5826006366551155612056429708996305319128773563972295690836601225605275501674").unwrap() - ], - ]; - - let vk_gamma = vec![ - vec![ - U256::from_dec_str("17806409976608908367323888887822121188242647630168482212485920174169347027063").unwrap(), - U256::from_dec_str("8825456074095233176609721582085618649257862500585602911204033640423196905248").unwrap() - ], - vec![ - U256::from_dec_str("7655945321523385522603417723274574493283664938267073386365908771387240995761").unwrap(), - U256::from_dec_str("1391423751277804315942138214547478409852807217621791637137051903290468385729").unwrap() - ], - ]; - - let vk_delta = vec![ - vec![ - U256::from_dec_str("3809610967392539750715448081264997038074319458499796020415928204603377523576").unwrap(), - U256::from_dec_str("21881257755244911884500859203243891779642123470948153619959132693051710001501").unwrap() - ], - vec![ - U256::from_dec_str("18182668523718172991867827330151318111796082889349461468494480610978916492639").unwrap(), - U256::from_dec_str("18346603307568004229749993259186056067010854478467318912554191630050104816892").unwrap() - ] - ]; - - let vk_ic = vec![ - vec![ - U256::from_dec_str("18607870993123209852816319805711229553001696602336350378390522478455144860988").unwrap(), - U256::from_dec_str("15734225289122896815446339472863615677791448850890205504711357677016324894100").unwrap() - ], - vec![ - U256::from_dec_str("3677354038386268432171152235208754414542237317446575011474517892977310796611").unwrap(), - U256::from_dec_str("2220614331603226929967110674993611028989932204445910742740951381331567463169").unwrap() - ] - ]; - - let valid_input = vec![U256::from_dec_str("14321691860995553260").unwrap(), U256::from_dec_str("7152862679273281751").unwrap(), U256::from_dec_str("12752615512303817990").unwrap(), U256::from_dec_str("1576113262537949146").unwrap()]; - let mut encoded_call = vec![0u8; 4]; - encoded_call[0..4].copy_from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..4]); - let parameters = ethabi::encode(&[ - Token::FixedArray(proof_a.into_iter().map(Token::Uint).collect()), - Token::FixedArray(proof_b.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), - Token::FixedArray(proof_c.into_iter().map(Token::Uint).collect()), - Token::FixedArray(vk_alpha.into_iter().map(Token::Uint).collect()), - Token::FixedArray(vk_beta.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), - Token::FixedArray(vk_gamma.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), - Token::FixedArray(vk_delta.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), - Token::Array(vk_ic.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), - Token::Array(valid_input.into_iter().map(Token::Uint).collect()), - ]); - encoded_call.extend(parameters); - let gas_limit_call = 1000000; - let value = U256::default(); - let is_transactional = true; - let validate = true; - }:{ - let call_runner_results = ::Runner::call( - caller, - contract_address, - encoded_call, - value, - gas_limit_call, - Some(U256::from(1_000_000_000)), - Some(U256::from(1_000_000_000)), - None, - Vec::new(), - is_transactional, - validate, - ::config(), - ); - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "Benchmarking call end.", - // ); - match call_runner_results { - Ok(info) => { - let output = info.value; - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "output result {:?}", - // output - // ); - if output.len() >= 32 { - let mut result_bytes = [0u8; 32]; - result_bytes.copy_from_slice(&output[output.len() - 32..]); - let result = U256::from_big_endian(&result_bytes); - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "Verification result {result:?}", - // ); - assert_eq!(result, U256::one(), "The contract did not return true"); - } - }, - Err(e) => { - log::info!( - target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - "Benchmarking failed", - ); - } - } - } - - nconstraints_n_30_input_10 { - use frame_benchmarking::vec; - use sp_core::{H160, U256}; - use ethabi::Token; - - let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); - - let contract_address = H160::from_low_u64_be(0x8888); - - let proof_a = vec![ - U256::from_dec_str("18690487469105583830896348523194667998180545629275814901431298749603732361922").unwrap(), - U256::from_dec_str("7368590978490025622497872418876156479561347771212306366618589942495456841309").unwrap() - ]; - - let proof_b = vec![ - vec![ - U256::from_dec_str("6458484707522958224040736264962413462988793890751266991780959428701001616723").unwrap(), - U256::from_dec_str("5229552051142880655000908369897792053786596109840647032497320533202927196186").unwrap() - ], - vec![ - U256::from_dec_str("14308631389244366765238213169645232719387098057421285153016420565820252114596").unwrap(), - U256::from_dec_str("5350276954672740804922429900678406990441626154643173671817737280965857560969").unwrap() - ], - ]; - - let proof_c = vec![ - U256::from_dec_str("2116304898851279057226756458603873842331017000957857852682949878590352582212").unwrap(), - U256::from_dec_str("4667525997409073696628336876173638225578496705097212864335627957772434988886").unwrap() - ]; - - let vk_alpha = vec![ - U256::from_dec_str("6699928044611798138494735544984517284373216312890158010790742091150243853313").unwrap(), - U256::from_dec_str("13934807201585568304844420589516599892787718850719460623808296221406392586172").unwrap() - ]; - - let vk_beta = vec![ - vec![ - U256::from_dec_str("14027097432418820340011319545278213614698987547810017425098729501416647686036").unwrap(), - U256::from_dec_str("11193668485833499271260223875108511371976490160655434826777606292642378752410").unwrap() - ], - vec![ - U256::from_dec_str("20045214665848771726931611212381067857571766687548405278435917898412573204852").unwrap(), - U256::from_dec_str("5826006366551155612056429708996305319128773563972295690836601225605275501674").unwrap() - ], - ]; - - let vk_gamma = vec![ - vec![ - U256::from_dec_str("17806409976608908367323888887822121188242647630168482212485920174169347027063").unwrap(), - U256::from_dec_str("8825456074095233176609721582085618649257862500585602911204033640423196905248").unwrap() - ], - vec![ - U256::from_dec_str("7655945321523385522603417723274574493283664938267073386365908771387240995761").unwrap(), - U256::from_dec_str("1391423751277804315942138214547478409852807217621791637137051903290468385729").unwrap() - ], - ]; - - let vk_delta = vec![ - vec![ - U256::from_dec_str("3809610967392539750715448081264997038074319458499796020415928204603377523576").unwrap(), - U256::from_dec_str("21881257755244911884500859203243891779642123470948153619959132693051710001501").unwrap() - ], - vec![ - U256::from_dec_str("18182668523718172991867827330151318111796082889349461468494480610978916492639").unwrap(), - U256::from_dec_str("18346603307568004229749993259186056067010854478467318912554191630050104816892").unwrap() - ] - ]; - - let vk_ic = vec![ - vec![ - U256::from_dec_str("18607870993123209852816319805711229553001696602336350378390522478455144860988").unwrap(), - U256::from_dec_str("15734225289122896815446339472863615677791448850890205504711357677016324894100").unwrap() - ], - vec![ - U256::from_dec_str("3677354038386268432171152235208754414542237317446575011474517892977310796611").unwrap(), - U256::from_dec_str("2220614331603226929967110674993611028989932204445910742740951381331567463169").unwrap() - ] - ]; - - let valid_input = vec![U256::from_dec_str("14321691860995553260").unwrap(), U256::from_dec_str("7152862679273281751").unwrap(), U256::from_dec_str("12752615512303817990").unwrap(), U256::from_dec_str("1576113262537949146").unwrap()]; - let mut encoded_call = vec![0u8; 4]; - encoded_call[0..4].copy_from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..4]); - let parameters = ethabi::encode(&[ - Token::FixedArray(proof_a.into_iter().map(Token::Uint).collect()), - Token::FixedArray(proof_b.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), - Token::FixedArray(proof_c.into_iter().map(Token::Uint).collect()), - Token::FixedArray(vk_alpha.into_iter().map(Token::Uint).collect()), - Token::FixedArray(vk_beta.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), - Token::FixedArray(vk_gamma.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), - Token::FixedArray(vk_delta.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), - Token::Array(vk_ic.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), - Token::Array(valid_input.into_iter().map(Token::Uint).collect()), - ]); - encoded_call.extend(parameters); - let gas_limit_call = 1000000; - let value = U256::default(); - let is_transactional = true; - let validate = true; - }:{ - let call_runner_results = ::Runner::call( - caller, - contract_address, - encoded_call, - value, - gas_limit_call, - Some(U256::from(1_000_000_000)), - Some(U256::from(1_000_000_000)), - None, - Vec::new(), - is_transactional, - validate, - ::config(), - ); - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "Benchmarking call end.", - // ); - match call_runner_results { - Ok(info) => { - let output = info.value; - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "output result {:?}", - // output - // ); - if output.len() >= 32 { - let mut result_bytes = [0u8; 32]; - result_bytes.copy_from_slice(&output[output.len() - 32..]); - let result = U256::from_big_endian(&result_bytes); - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "Verification result {result:?}", - // ); - assert_eq!(result, U256::one(), "The contract did not return true"); - } - }, - Err(e) => { - log::info!( - target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - "Benchmarking failed", - ); - } - } - } - - nconstraints_n_30_input_15 { - use frame_benchmarking::vec; - use sp_core::{H160, U256}; - use ethabi::Token; - - let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); - - let contract_address = H160::from_low_u64_be(0x8888); - - let proof_a = vec![ - U256::from_dec_str("12887020598237220198032976835022673435562149625889668367844845965730098834830").unwrap(), - U256::from_dec_str("5547693013562036425753166956109600351181086648379743178595634512552397114069").unwrap() - ]; - - let proof_b = vec![ - vec![ - U256::from_dec_str("16962228903458078536456881207808446370619165879473741769286461031761302313925").unwrap(), - U256::from_dec_str("21359014405084746685422343887329959215710120429954270380405915213638462365773").unwrap() - ], - vec![ - U256::from_dec_str("1965804446739736522247393806555217146673165319190290198953140579215540365682").unwrap(), - U256::from_dec_str("17336220908557918009722993863856522126371082788415822133704463388052631237429").unwrap() - ], - ]; - - let proof_c = vec![ - U256::from_dec_str("21289287840088286145802499082911728754744514711185794471060410933719935352734").unwrap(), - U256::from_dec_str("7735843223624767963016539689312235639526880990688180630973191899109833388707").unwrap() - ]; - - let vk_alpha = vec![ - U256::from_dec_str("8219837847335410476943086063649040035108946850004215058051338864845204653730").unwrap(), - U256::from_dec_str("3746608922869186366337371343000548817878727551441378244314034669462645204200").unwrap() - ]; - - let vk_beta = vec![ - vec![ - U256::from_dec_str("10791921184212451462910111849505135112215560450850904575300701984074058761885").unwrap(), - U256::from_dec_str("4316039429358514857629767756887568663426369969101124991106261138164361746936").unwrap() - ], - vec![ - U256::from_dec_str("4955635812176343518126942275795640701344828035542260039596033477800959201829").unwrap(), - U256::from_dec_str("18835858855587795231442750838451623232696087390908796571380078611078267640296").unwrap() - ], - ]; - - let vk_gamma = vec![ - vec![ - U256::from_dec_str("14455985103474869293499052450161566063643705959843058655267780689179003897023").unwrap(), - U256::from_dec_str("18671940900597221048350051608932531159222193402258576279517995276727240232360").unwrap() - ], - vec![ - U256::from_dec_str("12697560912244320596982687035610656622602540075343333727038001021203210410728").unwrap(), - U256::from_dec_str("18504263146151879520679575960347812434433829897678644699385693906415996014848").unwrap() - ], - ]; - - let vk_delta = vec![ - vec![ - U256::from_dec_str("21037497448680943522446235827846511504661282584273281863975228687729637949136").unwrap(), - U256::from_dec_str("21776379845891271099314141614451177025469923146966666607913073612769825420476").unwrap() - ], - vec![ - U256::from_dec_str("11117373909154352545964641618271566801006796957927201839858282655319054162622").unwrap(), - U256::from_dec_str("8761601020737608627675880810307531774963186960493596493629509853637521319476").unwrap() - ] - ]; - - let vk_ic = vec![ - vec![ - U256::from_dec_str("14615765550099232335848106179629691206556397912266277872446949704093515221045").unwrap(), - U256::from_dec_str("6162554008291819782928114499558697072224852754500626110745064581632604362032").unwrap() - ], - vec![ - U256::from_dec_str("8566823584588002931097794273610208557671819171252077099603486344498744585143").unwrap(), - U256::from_dec_str("10591536333958951217832992999045910076326646568032772769778666286942586222933").unwrap() - ] - ]; - - let valid_input = vec![U256::from_dec_str("5692445613459621787").unwrap(), U256::from_dec_str("12028678087606031844").unwrap(), U256::from_dec_str("16634303442742113517").unwrap(), U256::from_dec_str("1607701919348517559").unwrap()]; - let mut encoded_call = vec![0u8; 4]; - encoded_call[0..4].copy_from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..4]); - let parameters = ethabi::encode(&[ - Token::FixedArray(proof_a.into_iter().map(Token::Uint).collect()), - Token::FixedArray(proof_b.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), - Token::FixedArray(proof_c.into_iter().map(Token::Uint).collect()), - Token::FixedArray(vk_alpha.into_iter().map(Token::Uint).collect()), - Token::FixedArray(vk_beta.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), - Token::FixedArray(vk_gamma.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), - Token::FixedArray(vk_delta.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), - Token::Array(vk_ic.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), - Token::Array(valid_input.into_iter().map(Token::Uint).collect()), - ]); - encoded_call.extend(parameters); - let gas_limit_call = 1000000; - let value = U256::default(); - let is_transactional = true; - let validate = true; - }:{ - let call_runner_results = ::Runner::call( - caller, - contract_address, - encoded_call, - value, - gas_limit_call, - Some(U256::from(1_000_000_000)), - Some(U256::from(1_000_000_000)), - None, - Vec::new(), - is_transactional, - validate, - ::config(), - ); - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "Benchmarking call end.", - // ); - match call_runner_results { - Ok(info) => { - let output = info.value; - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "output result {:?}", - // output - // ); - if output.len() >= 32 { - let mut result_bytes = [0u8; 32]; - result_bytes.copy_from_slice(&output[output.len() - 32..]); - let result = U256::from_big_endian(&result_bytes); - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "Verification result {result:?}", - // ); - assert_eq!(result, U256::one(), "The contract did not return true"); - } - }, - Err(e) => { - log::info!( - target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - "Benchmarking failed", - ); - } - } - } - - nconstraints_n_30_input_20 { - use frame_benchmarking::vec; - use sp_core::{H160, U256}; - use ethabi::Token; - - let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); - - let contract_address = H160::from_low_u64_be(0x8888); - - let proof_a = vec![ - U256::from_dec_str("675300276299245578591094709236990240708914273209938055982582668214795758174").unwrap(), - U256::from_dec_str("13990735151356840356168472337981584444541365401592649678306674505655642720744").unwrap(), - ]; - - let proof_b = vec![ - vec![ - U256::from_dec_str("20662974626567138590845164891104877742207018449180572731972302829490961465377").unwrap(), - U256::from_dec_str("17980826672123191014823546738817744353214706462261563577840570306372367452611").unwrap(), - ], - vec![ - U256::from_dec_str("16771588723175231559633339886504703803804691684198872315901738104890051757400").unwrap(), - U256::from_dec_str("15483086789303204255210084974843463497785089107989053404746931842499188347781").unwrap(), - ], - ]; - - let proof_c = vec![ - U256::from_dec_str("10803326508903591698850591270453065951979818405855788885186501914161310127604").unwrap(), - U256::from_dec_str("7463976916832770397677605389090326852042103199297295653656426503462443575095").unwrap(), - ]; - - let vk_alpha = vec![ - U256::from_dec_str("17808795307067734350448942252050504857802750572499920704974512866462124896173").unwrap(), - U256::from_dec_str("17115681179782086865134005803599891667690289004882667885655096788650956914423").unwrap(), - ]; - - let vk_beta = vec![ - vec![ - U256::from_dec_str("19972461112908818195114127269905083158285147872659880745754440161709753445934").unwrap(), - U256::from_dec_str("5931352730208730296622877139521064931325621630284477295549537572620163532752").unwrap(), - ], - vec![ - U256::from_dec_str("2882185593168745381926882623953300896502789920459989016767915325150853635011").unwrap(), - U256::from_dec_str("18631580128182038958786817732606869739243773104340288087215229087084869651401").unwrap(), - ], - ]; - - let vk_gamma = vec![ - vec![ - U256::from_dec_str("851770636198195762853634545486979938053193628863032188824852166527357841269").unwrap(), - U256::from_dec_str("14031995609625725240579021647119854585086016231593377303976803993039287310339").unwrap(), - ], - vec![ - U256::from_dec_str("20686783438308398939975162795637102332306903166807161288857973107679921334009").unwrap(), - U256::from_dec_str("2532011633268289192635445441332602676050528250745931428259769182816495045641").unwrap(), - ], - ]; - - let vk_delta = vec![ - vec![ - U256::from_dec_str("14714684631646051284376146303759912153045379177454388567159304861853969170973").unwrap(), - U256::from_dec_str("21581087789843023955779607070023575401154216928170460432554645594586663631552").unwrap(), - ], - vec![ - U256::from_dec_str("18800497152775773104784586380904309935376489820003075987643947940762274526501").unwrap(), - U256::from_dec_str("17553212126947187473201629145084482836990004337579399572737167549853121474562").unwrap(), - ] - ]; - - let vk_ic = vec![ - vec![ - U256::from_dec_str("7232111346224912559397152061373338385516036432961030742660350233926241518205").unwrap(), - U256::from_dec_str("1312106886866516986858011448492089642322868115679821300916062234780269911574").unwrap(), - ], - vec![ - U256::from_dec_str("6433608899686307828382554879645744712090018725772338372746278420606357265684").unwrap(), - U256::from_dec_str("10454877373084482498589840527780357413752247536960233289477564876826588932778").unwrap(), - ] - ]; - - let valid_input = vec![U256::from_dec_str("3912017569823150797").unwrap(), U256::from_dec_str("13734487482202628151").unwrap(), U256::from_dec_str("17621575820406120931").unwrap(), U256::from_dec_str("942862921734396008").unwrap()]; - let mut encoded_call = vec![0u8; 4]; - encoded_call[0..4].copy_from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..4]); - let parameters = ethabi::encode(&[ - Token::FixedArray(proof_a.into_iter().map(Token::Uint).collect()), - Token::FixedArray(proof_b.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), - Token::FixedArray(proof_c.into_iter().map(Token::Uint).collect()), - Token::FixedArray(vk_alpha.into_iter().map(Token::Uint).collect()), - Token::FixedArray(vk_beta.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), - Token::FixedArray(vk_gamma.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), - Token::FixedArray(vk_delta.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), - Token::Array(vk_ic.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), - Token::Array(valid_input.into_iter().map(Token::Uint).collect()), - ]); - encoded_call.extend(parameters); - let gas_limit_call = 1000000; - let value = U256::default(); - let is_transactional = true; - let validate = true; - }:{ - let call_runner_results = ::Runner::call( - caller, - contract_address, - encoded_call, - value, - gas_limit_call, - Some(U256::from(1_000_000_000)), - Some(U256::from(1_000_000_000)), - None, - Vec::new(), - is_transactional, - validate, - ::config(), - ); - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "Benchmarking call end.", - // ); - match call_runner_results { - Ok(info) => { - let output = info.value; - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "output result {:?}", - // output - // ); - if output.len() >= 32 { - let mut result_bytes = [0u8; 32]; - result_bytes.copy_from_slice(&output[output.len() - 32..]); - let result = U256::from_big_endian(&result_bytes); - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "Verification result {result:?}", - // ); - assert_eq!(result, U256::one(), "The contract did not return true"); - } - }, - Err(e) => { - log::info!( - target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - "Benchmarking failed", - ); - } - } - } - - - nconstraints_n_30_input_25 { - use frame_benchmarking::vec; - use sp_core::{H160, U256}; - use ethabi::Token; - - let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); - - let contract_address = H160::from_low_u64_be(0x8888); - - let proof_a = vec![ - U256::from_dec_str("16006545354898718229260951824688742329434625591330021352594388758149873016896").unwrap(), - U256::from_dec_str("1468205165503169447069936905882957144235585999244028403117646701884216745392").unwrap(), - ]; - - let proof_b = vec![ - vec![ - U256::from_dec_str("8852923839895344533619890530783168672405232228640552748869548310905734934401").unwrap(), - U256::from_dec_str("14205972468980433410756631183566705893026836831976200390499104030484143466072").unwrap(), - ], - vec![ - U256::from_dec_str("5273488309799458449304345924433747290680464512658479589035286165842771509674").unwrap(), - U256::from_dec_str("16380658691502717574062613685364050177124879164561079589092985937963750638698").unwrap(), - ], - ]; - - let proof_c = vec![ - U256::from_dec_str("20115812596296892999368823778004624226181425602585514202472590919479136110663").unwrap(), - U256::from_dec_str("4894925383921626127869982825697178632493733742654662142214903567620044651205").unwrap(), - ]; - - let vk_alpha = vec![ - U256::from_dec_str("7941376557483595089971660523849374119116282550293913525516084066171760665760").unwrap(), - U256::from_dec_str("11518059386572304338895027869539849446766258314854264516705855524316523480782").unwrap(), - ]; - - let vk_beta = vec![ - vec![ - U256::from_dec_str("6169389823915190479258473920339684633183862258518826493764760771800535359821").unwrap(), - U256::from_dec_str("17130452746849022487073859340540869381062009205302178500507024318010199396952").unwrap(), - ], - vec![ - U256::from_dec_str("2318544008261920780923055770521739382224787976556999331708881512332672347971").unwrap(), - U256::from_dec_str("1745424225911873055606510145529079726501693479367526857564720869880667302655").unwrap(), - ], - ]; - - let vk_gamma = vec![ - vec![ - U256::from_dec_str("623010707232623462659826601801211232554955056016532044807183015392365318482").unwrap(), - U256::from_dec_str("865232306164050822814381934297685639795963777883253356917760252650841495108").unwrap(), - ], - vec![ - U256::from_dec_str("20499284403708841372819161133131038743430624942488488352074984316323625475649").unwrap(), - U256::from_dec_str("8586534605108047515719534665260604577359156625952909070129967685099418328393").unwrap(), - ], - ]; - - let vk_delta = vec![ - vec![ - U256::from_dec_str("17466746742513346286036517376644263104859467956003283191454165897758552595857").unwrap(), - U256::from_dec_str("5311323701152602220187351314264762414138054616620164066845262834294902529310").unwrap(), - ], - vec![ - U256::from_dec_str("21683159430467589572447310729564760337034354389144135006135111895877568793948").unwrap(), - U256::from_dec_str("14137150650205647732181183821072311493301762612748140449230051456997255133827").unwrap(), - ] - ]; - - let vk_ic = vec![ - vec![ - U256::from_dec_str("7587790987123565575798590220561861914433653529800504392689910235318401885521").unwrap(), - U256::from_dec_str("838359042085515464552622656979816858987026153105984521769778297124070509054").unwrap(), - ], - vec![ - U256::from_dec_str("13124708479886510248630494255189994749135078654655301928099114054732758024498").unwrap(), - U256::from_dec_str("10651906791373118981569686350085926733476784541744614206187906526770681605261").unwrap(), - ] - ]; - - let valid_input = vec![U256::from_dec_str("1514079710047709751").unwrap(), U256::from_dec_str("9927892042756486157").unwrap(), U256::from_dec_str("6795743742855535984").unwrap(), U256::from_dec_str("3178922015906793710").unwrap()]; - let mut encoded_call = vec![0u8; 4]; - encoded_call[0..4].copy_from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..4]); - let parameters = ethabi::encode(&[ - Token::FixedArray(proof_a.into_iter().map(Token::Uint).collect()), - Token::FixedArray(proof_b.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), - Token::FixedArray(proof_c.into_iter().map(Token::Uint).collect()), - Token::FixedArray(vk_alpha.into_iter().map(Token::Uint).collect()), - Token::FixedArray(vk_beta.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), - Token::FixedArray(vk_gamma.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), - Token::FixedArray(vk_delta.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), - Token::Array(vk_ic.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), - Token::Array(valid_input.into_iter().map(Token::Uint).collect()), - ]); - encoded_call.extend(parameters); - let gas_limit_call = 1000000; - let value = U256::default(); - let is_transactional = true; - let validate = true; - }:{ - let call_runner_results = ::Runner::call( - caller, - contract_address, - encoded_call, - value, - gas_limit_call, - Some(U256::from(1_000_000_000)), - Some(U256::from(1_000_000_000)), - None, - Vec::new(), - is_transactional, - validate, - ::config(), - ); - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "Benchmarking call end.", - // ); - match call_runner_results { - Ok(info) => { - let output = info.value; - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "output result {:?}", - // output - // ); - if output.len() >= 32 { - let mut result_bytes = [0u8; 32]; - result_bytes.copy_from_slice(&output[output.len() - 32..]); - let result = U256::from_big_endian(&result_bytes); - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "Verification result {result:?}", - // ); - assert_eq!(result, U256::one(), "The contract did not return true"); - } - }, - Err(e) => { - log::info!( - target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - "Benchmarking failed", - ); - } - } - } - nconstraints_n_30_input_30 { - use frame_benchmarking::vec; - use sp_core::{H160, U256}; - use ethabi::Token; - - let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); - - let contract_address = H160::from_low_u64_be(0x8888); - - let proof_a = vec![ - U256::from_dec_str("192383223808332879678223120765873656071487020594757668859947327172062021463").unwrap(), - U256::from_dec_str("20631800377548143112330602909240361504775196179042765937715471405374872743424").unwrap(), - ]; - - let proof_b = vec![ - vec![ - U256::from_dec_str("2386546353880304173552960655436514856580592658425839135191217698540932917221").unwrap(), - U256::from_dec_str("8483190656320044020998407034485182750694926538145978907506797577826038755937").unwrap(), - ], - vec![ - U256::from_dec_str("7615954358803953940045634219422206780946884331580120097208882088362520213892").unwrap(), - U256::from_dec_str("17492892761336449552765644207249662635220549371874833325304908992711325096838").unwrap(), - ], - ]; - - let proof_c = vec![ - U256::from_dec_str("14898385768534632459299431757788181862062037231423680879935547707181434062217").unwrap(), - U256::from_dec_str("3670993976640187257001986589710513145495904997157462001138713422198967083793").unwrap(), - ]; - - let vk_alpha = vec![ - U256::from_dec_str("18003389266700451535185768250385473623576088268017984044335576780485413288725").unwrap(), - U256::from_dec_str("10280152748134343381057553800219778246761591399803713656295141924124651318322").unwrap(), - ]; - - let vk_beta = vec![ - vec![ - U256::from_dec_str("15705711023641709606059988467186697257075093473077719904710509531659151640887").unwrap(), - U256::from_dec_str("13926583045600156240485358993385159153394021178689044035959053205092441158347").unwrap(), - ], - vec![ - U256::from_dec_str("2133281544711261852175935529948152371794373217468774127814272513506339581229").unwrap(), - U256::from_dec_str("15266525202021918250529116255077653452497658133580868510244476123771794689087").unwrap(), - ], - ]; - - let vk_gamma = vec![ - vec![ - U256::from_dec_str("5860932391264318788101713658077318120931708405538141099278626653654316360162").unwrap(), - U256::from_dec_str("18777995924606299529855429493114686078258294137554638538976277652307549742619").unwrap(), - ], - vec![ - U256::from_dec_str("18381097066271335811045821138274998569498024818257561362659949818983456872550").unwrap(), - U256::from_dec_str("13352938901259724996725843903559730864557166420786660986703127196904357078738").unwrap(), - ], - ]; - - let vk_delta = vec![ - vec![ - U256::from_dec_str("14145680588609876894681651972036258026026055123025250786927547400650826638120").unwrap(), - U256::from_dec_str("11416850029017788620938610876201750823987651931635585676983799773100880269198").unwrap(), - ], - vec![ - U256::from_dec_str("17147929122794757054114222102821483783601496318354908417750078988687436213430").unwrap(), - U256::from_dec_str("2750254376147201225382240026981296587762562040528353782979098667468106833906").unwrap(), - ] - ]; - - let vk_ic = vec![ - vec![ - U256::from_dec_str("11111422270719484684442669128605095987218378443749504485297022350994995674515").unwrap(), - U256::from_dec_str("9009256400033220730477021494653362520677702130766423677465372172912927069348").unwrap(), - ], - vec![ - U256::from_dec_str("711398778459754876097070294398450479822869186578007297816303943615642796091").unwrap(), - U256::from_dec_str("19953433553885418442641654921645346560623468995060701812216801687443587349442").unwrap(), - ] - ]; - - let valid_input = vec![U256::from_dec_str("961725266697111609").unwrap(), U256::from_dec_str("7616088020774934521").unwrap(), U256::from_dec_str("4985267006460356416").unwrap(), U256::from_dec_str("1376874925466056414").unwrap()]; - let mut encoded_call = vec![0u8; 4]; - encoded_call[0..4].copy_from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..4]); - let parameters = ethabi::encode(&[ - Token::FixedArray(proof_a.into_iter().map(Token::Uint).collect()), - Token::FixedArray(proof_b.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), - Token::FixedArray(proof_c.into_iter().map(Token::Uint).collect()), - Token::FixedArray(vk_alpha.into_iter().map(Token::Uint).collect()), - Token::FixedArray(vk_beta.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), - Token::FixedArray(vk_gamma.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), - Token::FixedArray(vk_delta.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), - Token::Array(vk_ic.into_iter().map(|inner| Token::FixedArray(inner.into_iter().map(Token::Uint).collect())).collect()), - Token::Array(valid_input.into_iter().map(Token::Uint).collect()), - ]); - encoded_call.extend(parameters); - let gas_limit_call = 1000000; - let value = U256::default(); - let is_transactional = true; - let validate = true; - }:{ - let call_runner_results = ::Runner::call( - caller, - contract_address, - encoded_call, - value, - gas_limit_call, - Some(U256::from(1_000_000_000)), - Some(U256::from(1_000_000_000)), - None, - Vec::new(), - is_transactional, - validate, - ::config(), - ); - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "Benchmarking call end.", - // ); - match call_runner_results { - Ok(info) => { - let output = info.value; - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "output result {:?}", - // output - // ); - if output.len() >= 32 { - let mut result_bytes = [0u8; 32]; - result_bytes.copy_from_slice(&output[output.len() - 32..]); - let result = U256::from_big_endian(&result_bytes); - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "Verification result {result:?}", - // ); - assert_eq!(result, U256::one(), "The contract did not return true"); - } - }, - Err(e) => { - log::info!( - target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - "Benchmarking failed", - ); - } - } - } } impl_benchmark_test_suite!( Pallet, diff --git a/runtime/runtime-common/src/zk_precompile_gas_estimation/tests.rs b/runtime/runtime-common/src/zk_precompile_gas_estimation/tests.rs index 99fbdd37..bca6f78c 100644 --- a/runtime/runtime-common/src/zk_precompile_gas_estimation/tests.rs +++ b/runtime/runtime-common/src/zk_precompile_gas_estimation/tests.rs @@ -72,76 +72,78 @@ fn test_zk_precompile_gas_estimation() { let contract_address = H160::from_low_u64_be(0x8888); let proof_a = vec![ - U256::from_dec_str("13202079600221154376862161785979680082984660469505374274880948735521253479994").unwrap(), - U256::from_dec_str("19032139815435908179959144311759562497239236177745989139113028703727512477837").unwrap() + U256::from_dec_str("17526830733396711760614584592227592290041884054274692385786120317424586951928").unwrap(), + U256::from_dec_str("14572975009604791670190722144346966861775781663452799801994174625223530481293").unwrap(), ]; let proof_b = vec![ vec![ - U256::from_dec_str("9517359327043802798811688827065407805934924568686293993682568334305900037151").unwrap(), - U256::from_dec_str("13975418982386111217378923290980800393212535787789845393400867460398182717751").unwrap() + U256::from_dec_str("601091821423560000095338178586024773386806597229060347992230108339560337314").unwrap(), + U256::from_dec_str("20742329792185135417418009297070484022157549629159037177761763368870046435272").unwrap(), ], vec![ - U256::from_dec_str("11101434469251848949317000686121782094334155840067455941163819739470030872205").unwrap(), - U256::from_dec_str("3351121397470969456277617123820147601817413346203636355523709813813837616699").unwrap() + U256::from_dec_str("16755958476414893111742804329540858423617749911023931584301476920013641667491").unwrap(), + U256::from_dec_str("17783640965723747611121456292908504762681694379312402130038762071821040335901").unwrap(), ], ]; let proof_c = vec![ - U256::from_dec_str("21771166379144524714497801611702430117390298454683954881352912868492853507834").unwrap(), - U256::from_dec_str("5971832614272362565584439633663845994795381011258125087840397908182066694531").unwrap() + U256::from_dec_str("16585885402862686337557433720680035430031425737321159047915573958245961596065").unwrap(), + U256::from_dec_str("21138178351445807771687394250843863988645614435175735346332333179172518378873").unwrap(), ]; let vk_alpha = vec![ - U256::from_dec_str("7318409901911144874440195167086183143676595981815053389579728623121590098440").unwrap(), - U256::from_dec_str("18845965879715444612950452554360629789407129470518446134938217746489723713219").unwrap() + U256::from_dec_str("11484345157460561328461496884344190739368158625792198603002887108334722367669").unwrap(), + U256::from_dec_str("7086541917963105127497541193167841067353924271429224233965614329678507699488").unwrap(), ]; let vk_beta = vec![ vec![ - U256::from_dec_str("4640649673239597789758809808535118135578677216672702870175791505196312738305").unwrap(), - U256::from_dec_str("13141288066376351908866878766575256664575916601245245304316354941350328880142").unwrap() + U256::from_dec_str("11233128783379821052483619196929223312692971108992242120588689458439987752067").unwrap(), + U256::from_dec_str("18640573156008262049228946668908337221222445157240294147034515643976275941832").unwrap(), ], vec![ - U256::from_dec_str("11492338667195076401975872253943030431149343004937779351839311477974294172860").unwrap(), - U256::from_dec_str("17604387530215185597479117283681563543587978658046512716245947218617178983155").unwrap() + U256::from_dec_str("8036983389612370781023375187819482868320454529134623464035669006179478819783").unwrap(), + U256::from_dec_str("16424116254718275500394502257751813449316936907205655002329084814392003619802").unwrap(), ], ]; - let vk_gamma = vec![ + let vk_delta = vec![ vec![ - U256::from_dec_str("10857046999023057135944570762232829481370756359578518086990519993285655852781").unwrap(), - U256::from_dec_str("11559732032986387107991004021392285783925812861821192530917403151452391805634").unwrap() + U256::from_dec_str("11228532404788151396730538740677955321165465678604965636022681521723486460585").unwrap(), + U256::from_dec_str("9126453034411305688949328104662278794713000842053283268128161824572984268064").unwrap(), ], vec![ - U256::from_dec_str("8495653923123431417604973247489272438418190587263600148770280649306958101930").unwrap(), - U256::from_dec_str("4082367875863433681332203403145435568316851327593401208105741076214120093531").unwrap() + U256::from_dec_str("6386111381608251566396732981213051438889552027469318069778613233664780673905").unwrap(), + U256::from_dec_str("20548857422827059363546153463236239952243300189763734417419279501301392340910").unwrap(), ], ]; - let vk_delta = vec![ + let vk_gamma = vec![ vec![ - U256::from_dec_str("5882870888685857628232224840789532289346124290586616915986585508513239272539").unwrap(), - U256::from_dec_str("8206718104089392401855946495573733123991363841198873660903571227166120193870").unwrap() + U256::from_dec_str("16318831326794673155348007016625372642245174324642568461921219640531003953421").unwrap(), + U256::from_dec_str("10357000493091964334208434777562330142557973636508422501741235212619215377564").unwrap(), ], vec![ - U256::from_dec_str("14275677868038957349366208693756706908778821863795564855498136614399516409168").unwrap(), - U256::from_dec_str("20950579407520036072561845357324335488555384097745021047033651867265123837403").unwrap() + U256::from_dec_str("2549252377666082313659764548733755762481620259406193451284130401099909523405").unwrap(), + U256::from_dec_str("17286438687897881040082074476507835506847599850151991459812945029157729581277").unwrap(), ] ]; let vk_ic = vec![ vec![ - U256::from_dec_str("15329034480187562940265095627808115353397553736992059710948268284574612609224").unwrap(), - U256::from_dec_str("13272704791638435782238987852007128987814629753205340563304933194747762248428").unwrap() + U256::from_dec_str("19809018900500753691845636946336582450384254173888544359470795703770668108982").unwrap(), + U256::from_dec_str("18905865743072988362439446807054892183348768606005293094676173646899256980681").unwrap(), ], vec![ - U256::from_dec_str("17269839325091679315052274785558946544729609490743199699197195008879157661695").unwrap(), - U256::from_dec_str("4142750859697696641705372803120309740931359230261851701215055719438325633654").unwrap() + U256::from_dec_str("13731638277857114344416462118077651769684398274209992879843147837262038701628").unwrap(), + U256::from_dec_str("19144851605913607756613362053945586479161724714752749470233682046477131900096").unwrap(), ] ]; - let valid_input = vec![U256::from(66)]; + let valid_input = vec![ + U256::from_dec_str("1250025000").unwrap() + ]; let mut encoded_call = vec![0u8; 4]; encoded_call[0..4].copy_from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..4]); println!("encoded_call: {:?}", encoded_call); From 1d39949e237601e97a3805e0c0f8e73a3280ba6c Mon Sep 17 00:00:00 2001 From: luckychacha <358140284@qq.com> Date: Wed, 9 Aug 2023 02:23:17 +0800 Subject: [PATCH 18/34] Try to deal benchmarking verified fail. --- precompiles/zk-groth16-verify/src/lib.rs | 62 +++++++++++++++++-- .../src/zk_precompile_gas_estimation/tests.rs | 6 ++ 2 files changed, 63 insertions(+), 5 deletions(-) diff --git a/precompiles/zk-groth16-verify/src/lib.rs b/precompiles/zk-groth16-verify/src/lib.rs index 3cef36cc..ba5e8690 100644 --- a/precompiles/zk-groth16-verify/src/lib.rs +++ b/precompiles/zk-groth16-verify/src/lib.rs @@ -79,8 +79,13 @@ impl ZKGroth16Verify { // Read the offset of vk_ic and skip the length field let vk_ic_offset = U256::from_big_endian(next()).low_u32() as usize + 32; - // Read the offset of input and skip the length field - let input_offset = U256::from_big_endian(next()).low_u32() as usize + 32; + // Read the offset of input + let mut input_offset = U256::from_big_endian(next()).low_u32() as usize; + // Read the length of the input array + let input_len = U256::from_big_endian(&input_stripped[input_offset..input_offset + 32]) + .low_u32() as usize; + // Skip the length field + input_offset += 32; // Read the vk_ic array let vk_ic = input_stripped[vk_ic_offset..input_offset] @@ -92,11 +97,58 @@ impl ZKGroth16Verify { .collect::, _>>()?; // Read the input array - let pub_inputs: Vec<_> = input_stripped[input_offset..] + let pub_inputs: Vec = input_stripped[input_offset..] .chunks_exact(32) .map(ark_bn254_fr) .collect(); - log::debug!( + log::info!( + target: "precompiles::zk_groth16_verify::execute", + "Pub_inputs: {:?}", + pub_inputs + ); + + let mut bigints: Vec = input_stripped[input_offset..] + .chunks(32) + .map(|chunk| { + let chunk = &chunk[24..32]; + num_bigint::BigUint::from_bytes_be(chunk) + }) + .collect(); + bigints.resize(4, num_bigint::BigUint::from(0u64)); +let bigints_bytes: Vec = bigints + .iter() + .flat_map(|b| { + let mut bytes = vec![0u8; 8]; + let b_bytes = b.to_bytes_be(); + bytes[(8 - b_bytes.len())..].copy_from_slice(&b_bytes); + bytes + }) + .collect(); + log::info!( + target: "precompiles::zk_groth16_verify::execute", + "bigints: {:?}", + bigints_bytes + ); + log::info!( + target: "precompiles::zk_groth16_verify::execute", + "bigints_len: {:?}", + bigints + .iter() + .flat_map(|b| b.to_bytes_be()) + .collect::>() + ); + + let pub_inputs: Vec = bigints + .iter() + .flat_map(|b| b.to_bytes_be()) + .collect::>() + .chunks_exact(32) + .map(ark_bn254_fr) + .collect(); + // let pub_inputs: Vec, 4>> = + // vec![ark_bn254_fr(&bigints_bytes)]; + + log::info!( target: "precompiles::zk_groth16_verify::execute", "Pub_inputs: {:?}", pub_inputs @@ -117,7 +169,7 @@ impl ZKGroth16Verify { let verified = Groth16::::verify(&vk, &pub_inputs, &proof).map_err(|e| { - let error_message = format!("{}", e); // Convert the error to a string + let error_message = format!("{e}"); // Convert the error to a string PrecompileFailure::Error { exit_status: ExitError::Other(error_message.into()), } diff --git a/runtime/runtime-common/src/zk_precompile_gas_estimation/tests.rs b/runtime/runtime-common/src/zk_precompile_gas_estimation/tests.rs index bca6f78c..86463c89 100644 --- a/runtime/runtime-common/src/zk_precompile_gas_estimation/tests.rs +++ b/runtime/runtime-common/src/zk_precompile_gas_estimation/tests.rs @@ -144,6 +144,12 @@ fn test_zk_precompile_gas_estimation() { let valid_input = vec![ U256::from_dec_str("1250025000").unwrap() ]; + // let valid_input = vec![ + // U256::from_dec_str("14965631224775206224").unwrap(), + // U256::from_dec_str("3021577815302938909").unwrap(), + // U256::from_dec_str("14359293880404272991").unwrap(), + // U256::from_dec_str("1555005537055779113").unwrap(), + // ]; let mut encoded_call = vec![0u8; 4]; encoded_call[0..4].copy_from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..4]); println!("encoded_call: {:?}", encoded_call); From 8f53f1a1a477332d67e20aa72a10ff9a494d14fa Mon Sep 17 00:00:00 2001 From: luckychacha <358140284@qq.com> Date: Wed, 9 Aug 2023 08:30:35 +0800 Subject: [PATCH 19/34] Try to deal benchmarking verified fail. --- precompiles/zk-groth16-verify/src/lib.rs | 37 ++++++++----------- .../src/zk_precompile_gas_estimation/tests.rs | 2 +- 2 files changed, 16 insertions(+), 23 deletions(-) diff --git a/precompiles/zk-groth16-verify/src/lib.rs b/precompiles/zk-groth16-verify/src/lib.rs index ba5e8690..f406d249 100644 --- a/precompiles/zk-groth16-verify/src/lib.rs +++ b/precompiles/zk-groth16-verify/src/lib.rs @@ -3,7 +3,7 @@ use pallet_evm::{ExitError, ExitSucceed, LinearCostPrecompile, PrecompileFailure}; use sp_core::U256; -use sp_std::vec::Vec; +use sp_std::{vec, vec::Vec}; use ark_crypto_primitives::snark::SNARK; use ark_groth16::Groth16; @@ -115,38 +115,31 @@ impl ZKGroth16Verify { }) .collect(); bigints.resize(4, num_bigint::BigUint::from(0u64)); -let bigints_bytes: Vec = bigints - .iter() - .flat_map(|b| { - let mut bytes = vec![0u8; 8]; - let b_bytes = b.to_bytes_be(); - bytes[(8 - b_bytes.len())..].copy_from_slice(&b_bytes); - bytes - }) - .collect(); + log::info!( target: "precompiles::zk_groth16_verify::execute", "bigints: {:?}", - bigints_bytes - ); - log::info!( - target: "precompiles::zk_groth16_verify::execute", - "bigints_len: {:?}", bigints - .iter() - .flat_map(|b| b.to_bytes_be()) - .collect::>() ); - let pub_inputs: Vec = bigints .iter() - .flat_map(|b| b.to_bytes_be()) + .flat_map(|b| { + let mut bytes = vec![0u8; 8]; + let b_bytes = b.to_bytes_be(); + bytes[8 - b_bytes.len()..].copy_from_slice(&b_bytes); + bytes + }) .collect::>() .chunks_exact(32) .map(ark_bn254_fr) .collect(); - // let pub_inputs: Vec, 4>> = - // vec![ark_bn254_fr(&bigints_bytes)]; + + // log::info!( + // target: "precompiles::zk_groth16_verify::execute", + // "bigints_bytes: {:?} len: {:?}", + // bigints_bytes, + // bigints_bytes.len(), + // ); log::info!( target: "precompiles::zk_groth16_verify::execute", diff --git a/runtime/runtime-common/src/zk_precompile_gas_estimation/tests.rs b/runtime/runtime-common/src/zk_precompile_gas_estimation/tests.rs index 86463c89..620d2a44 100644 --- a/runtime/runtime-common/src/zk_precompile_gas_estimation/tests.rs +++ b/runtime/runtime-common/src/zk_precompile_gas_estimation/tests.rs @@ -144,7 +144,7 @@ fn test_zk_precompile_gas_estimation() { let valid_input = vec![ U256::from_dec_str("1250025000").unwrap() ]; - // let valid_input = vec![ + // let valid_input = vec![ // U256::from_dec_str("14965631224775206224").unwrap(), // U256::from_dec_str("3021577815302938909").unwrap(), // U256::from_dec_str("14359293880404272991").unwrap(), From 29d3661c77edee538ca4748a33f27eb4dcf62905 Mon Sep 17 00:00:00 2001 From: luckychacha <358140284@qq.com> Date: Wed, 9 Aug 2023 17:31:48 +0800 Subject: [PATCH 20/34] ZK Groth16 Verify benchamarking working. --- precompiles/zk-groth16-verify/src/lib.rs | 51 +- .../benchmarking.rs | 3808 +++++++++-------- .../src/zk_precompile_gas_estimation/tests.rs | 28 +- 3 files changed, 1938 insertions(+), 1949 deletions(-) diff --git a/precompiles/zk-groth16-verify/src/lib.rs b/precompiles/zk-groth16-verify/src/lib.rs index f406d249..48e63222 100644 --- a/precompiles/zk-groth16-verify/src/lib.rs +++ b/precompiles/zk-groth16-verify/src/lib.rs @@ -3,7 +3,7 @@ use pallet_evm::{ExitError, ExitSucceed, LinearCostPrecompile, PrecompileFailure}; use sp_core::U256; -use sp_std::{vec, vec::Vec}; +use sp_std::vec::Vec; use ark_crypto_primitives::snark::SNARK; use ark_groth16::Groth16; @@ -80,12 +80,7 @@ impl ZKGroth16Verify { let vk_ic_offset = U256::from_big_endian(next()).low_u32() as usize + 32; // Read the offset of input - let mut input_offset = U256::from_big_endian(next()).low_u32() as usize; - // Read the length of the input array - let input_len = U256::from_big_endian(&input_stripped[input_offset..input_offset + 32]) - .low_u32() as usize; - // Skip the length field - input_offset += 32; + let input_offset = U256::from_big_endian(next()).low_u32() as usize + 32; // Read the vk_ic array let vk_ic = input_stripped[vk_ic_offset..input_offset] @@ -101,47 +96,7 @@ impl ZKGroth16Verify { .chunks_exact(32) .map(ark_bn254_fr) .collect(); - log::info!( - target: "precompiles::zk_groth16_verify::execute", - "Pub_inputs: {:?}", - pub_inputs - ); - - let mut bigints: Vec = input_stripped[input_offset..] - .chunks(32) - .map(|chunk| { - let chunk = &chunk[24..32]; - num_bigint::BigUint::from_bytes_be(chunk) - }) - .collect(); - bigints.resize(4, num_bigint::BigUint::from(0u64)); - - log::info!( - target: "precompiles::zk_groth16_verify::execute", - "bigints: {:?}", - bigints - ); - let pub_inputs: Vec = bigints - .iter() - .flat_map(|b| { - let mut bytes = vec![0u8; 8]; - let b_bytes = b.to_bytes_be(); - bytes[8 - b_bytes.len()..].copy_from_slice(&b_bytes); - bytes - }) - .collect::>() - .chunks_exact(32) - .map(ark_bn254_fr) - .collect(); - - // log::info!( - // target: "precompiles::zk_groth16_verify::execute", - // "bigints_bytes: {:?} len: {:?}", - // bigints_bytes, - // bigints_bytes.len(), - // ); - - log::info!( + log::debug!( target: "precompiles::zk_groth16_verify::execute", "Pub_inputs: {:?}", pub_inputs diff --git a/runtime/runtime-common/src/zk_precompile_gas_estimation/benchmarking.rs b/runtime/runtime-common/src/zk_precompile_gas_estimation/benchmarking.rs index be1abd5f..94d57ce0 100644 --- a/runtime/runtime-common/src/zk_precompile_gas_estimation/benchmarking.rs +++ b/runtime/runtime-common/src/zk_precompile_gas_estimation/benchmarking.rs @@ -167,6 +167,20 @@ impl ZKPrecompileVerifier { } } +fn u64s_to_u256(values: Vec) -> U256 { + let mut result = U256::zero(); + for (i, value) in values.into_iter().enumerate().take(4) { + let shift = i * 64; + result |= U256::from(value) << shift; + } + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "u64s_to_u256 result {:?}", + // result + // ); + result +} + benchmarks! { nconstraints_10 { use frame_benchmarking::vec; @@ -243,12 +257,12 @@ benchmarks! { ] ); - let valid_input = vec![ - U256::from_dec_str("14965631224775206224").unwrap(), - U256::from_dec_str("3021577815302938909").unwrap(), - U256::from_dec_str("14359293880404272991").unwrap(), - U256::from_dec_str("1555005537055779113").unwrap() - ]; + let valid_input: Vec = vec![u64s_to_u256(vec![ + 14965631224775206224, + 3021577815302938909, + 14359293880404272991, + 1555005537055779113 + ])]; let verifying_key = VerifyingKey::new(proof, vk, valid_input); @@ -278,1877 +292,185 @@ benchmarks! { validate, ::config(), ); - log::info!( - target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - "Benchmarking call end.", - ); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "Benchmarking call end.", + // ); match call_runner_results { Ok(info) => { let output = info.value; + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "output result {:?}", + // output + // ); + if output.len() >= 32 { + let mut result_bytes = [0u8; 32]; + result_bytes.copy_from_slice(&output[output.len() - 32..]); + let result = U256::from_big_endian(&result_bytes); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "nconstraints_10 Verification result {result:?}", + // ); + assert_eq!(result, U256::one(), "The contract did not return true"); + } + }, + Err(e) => { log::info!( target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - "output result {:?}", - output + "nconstraints_10 Benchmarking failed", ); + assert!(false, "Benchmarking failed"); + + } + } + } + + nconstraints_50 { + use frame_benchmarking::vec; + use sp_core::{H160, U256, H256}; + + let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + let contract_address = H160::from_low_u64_be(0x8888); + + let proof = Proof::new( + vec![ + U256::from_dec_str("2903574088029507435491062627919627539459038881203099780902103872696986272650").unwrap(), + U256::from_dec_str("3875062839032259754068923295563862040166715100637843024855021734684308685930").unwrap(), + ], + vec![ + vec![ + U256::from_dec_str("5467576156112132028552287163049386912078800648727055176723583005212825192497").unwrap(), + U256::from_dec_str("14958898784032520052694892656913773236193256742890765604760593633503039104983").unwrap(), + ], + vec![ + U256::from_dec_str("5396143311660903133040196691443703988892234257628755380984718394981374344158").unwrap(), + U256::from_dec_str("8621644456104449033213297238562527153800159584768570376273022394943050969320").unwrap(), + ], + ], + vec![ + U256::from_dec_str("11879092906448699692394725971977132036554363118574468164770659810752018463948").unwrap(), + U256::from_dec_str("6829624468475499149259780051037762599455296300930683215687755977165243124154").unwrap(), + ] + ); + + let vk = VerifyingKeyComponents::new( + vec![ + U256::from_dec_str("12520775544030530008009522467466185193766786263812261579427634884004150619566").unwrap(), + U256::from_dec_str("5032545863820965741764073435262250124257467813113463153084126384917060899315").unwrap(), + ], + vec![ + vec![ + U256::from_dec_str("10017955328073015145877787608777450033090741247853140204265773706371885379542").unwrap(), + U256::from_dec_str("9658203662920649739629860626443008098625554125855709045942833415049413198251").unwrap(), + ], + vec![ + U256::from_dec_str("7602415148393817869205609282139785691690714005596249546125364310759985118071").unwrap(), + U256::from_dec_str("6621887421318408197643297351639235440436194355283660692959196816576578875866").unwrap(), + ], + ], + vec![ + vec![ + U256::from_dec_str("5311307398908794283615493653665859916837738758333406097237626345248614605789").unwrap(), + U256::from_dec_str("17876886843886949913975349493510247353159584223381019718903135647608874168034").unwrap(), + ], + vec![ + U256::from_dec_str("16871344858870476549165036353120397473700844904231047018564735968613233188965").unwrap(), + U256::from_dec_str("3780010632071163899826543545524090280002435997376718121100375224910528030644").unwrap(), + ], + ], + vec![ + vec![ + U256::from_dec_str("5274939476765287332787933848172441391963317633567336761478263433231602711901").unwrap(), + U256::from_dec_str("20318717968421229127062334564952813061229602553850186042308931686220563993985").unwrap(), + ], + vec![ + U256::from_dec_str("18867986549807700609691354300906273266753459571664361845748650324369589087167").unwrap(), + U256::from_dec_str("3462802759155100024118895949055238081126591020075851877084161838812514424801").unwrap(), + ] + ], + vec![ + vec![ + U256::from_dec_str("2073721309366561324099267234284336470258146869696430225377434175843251484752").unwrap(), + U256::from_dec_str("5562089018027206512286783868306950659834000523781522158661084193254167305831").unwrap(), + ], + vec![ + U256::from_dec_str("7633925392184781104787537197952383405066326059553608577981951477761067715424").unwrap(), + U256::from_dec_str("19510227686274170330355317434483857344641524658406254379151352263942714837771").unwrap(), + ] + ] + ); + + let valid_input: Vec = vec![u64s_to_u256(vec![ + 14754876691570659999, + 1449725765053302887, + 10573592104590215630, + 2031301759166401468 + ])]; + + let verifying_key = VerifyingKey::new(proof, vk, valid_input); + + let zk_verifier = ZKPrecompileVerifier::new( + H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), + verifying_key + ); + + let encoded_call = zk_verifier.generate_benchmarking_parameters(); + + let gas_limit_call = 1000000; + let value = U256::default(); + let is_transactional = true; + let validate = true; + }:{ + let call_runner_results = ::Runner::call( + caller, + contract_address, + encoded_call, + value, + gas_limit_call, + Some(U256::from(1_000_000_000)), + Some(U256::from(1_000_000_000)), + None, + Vec::new(), + is_transactional, + validate, + ::config(), + ); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "Benchmarking call end.", + // ); + match call_runner_results { + Ok(info) => { + let output = info.value; + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "output result {:?}", + // output + // ); if output.len() >= 32 { let mut result_bytes = [0u8; 32]; result_bytes.copy_from_slice(&output[output.len() - 32..]); let result = U256::from_big_endian(&result_bytes); - log::info!( - target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - "Verification result {result:?}", - ); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "nconstraints_50 Verification result {result:?}", + // ); assert_eq!(result, U256::one(), "The contract did not return true"); } }, Err(e) => { log::info!( target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - "Benchmarking failed", + "nconstraints_50 Benchmarking failed", ); + assert!(false, "Benchmarking failed"); + } } } - // nconstraints_50 { - // use frame_benchmarking::vec; - // use sp_core::{H160, U256, H256}; - - // let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); - // let contract_address = H160::from_low_u64_be(0x8888); - - // let proof = Proof::new( - // vec![ - // U256::from_dec_str("2903574088029507435491062627919627539459038881203099780902103872696986272650").unwrap(), - // U256::from_dec_str("3875062839032259754068923295563862040166715100637843024855021734684308685930").unwrap(), - // ], - // vec![ - // vec![ - // U256::from_dec_str("5467576156112132028552287163049386912078800648727055176723583005212825192497").unwrap(), - // U256::from_dec_str("14958898784032520052694892656913773236193256742890765604760593633503039104983").unwrap(), - // ], - // vec![ - // U256::from_dec_str("5396143311660903133040196691443703988892234257628755380984718394981374344158").unwrap(), - // U256::from_dec_str("8621644456104449033213297238562527153800159584768570376273022394943050969320").unwrap(), - // ], - // ], - // vec![ - // U256::from_dec_str("11879092906448699692394725971977132036554363118574468164770659810752018463948").unwrap(), - // U256::from_dec_str("6829624468475499149259780051037762599455296300930683215687755977165243124154").unwrap(), - // ] - // ); - - // let vk = VerifyingKeyComponents::new( - // vec![ - // U256::from_dec_str("12520775544030530008009522467466185193766786263812261579427634884004150619566").unwrap(), - // U256::from_dec_str("5032545863820965741764073435262250124257467813113463153084126384917060899315").unwrap(), - // ], - // vec![ - // vec![ - // U256::from_dec_str("10017955328073015145877787608777450033090741247853140204265773706371885379542").unwrap(), - // U256::from_dec_str("9658203662920649739629860626443008098625554125855709045942833415049413198251").unwrap(), - // ], - // vec![ - // U256::from_dec_str("7602415148393817869205609282139785691690714005596249546125364310759985118071").unwrap(), - // U256::from_dec_str("6621887421318408197643297351639235440436194355283660692959196816576578875866").unwrap(), - // ], - // ], - // vec![ - // vec![ - // U256::from_dec_str("5311307398908794283615493653665859916837738758333406097237626345248614605789").unwrap(), - // U256::from_dec_str("17876886843886949913975349493510247353159584223381019718903135647608874168034").unwrap(), - // ], - // vec![ - // U256::from_dec_str("16871344858870476549165036353120397473700844904231047018564735968613233188965").unwrap(), - // U256::from_dec_str("3780010632071163899826543545524090280002435997376718121100375224910528030644").unwrap(), - // ], - // ], - // vec![ - // vec![ - // U256::from_dec_str("5274939476765287332787933848172441391963317633567336761478263433231602711901").unwrap(), - // U256::from_dec_str("20318717968421229127062334564952813061229602553850186042308931686220563993985").unwrap(), - // ], - // vec![ - // U256::from_dec_str("18867986549807700609691354300906273266753459571664361845748650324369589087167").unwrap(), - // U256::from_dec_str("3462802759155100024118895949055238081126591020075851877084161838812514424801").unwrap(), - // ] - // ], - // vec![ - // vec![ - // U256::from_dec_str("2073721309366561324099267234284336470258146869696430225377434175843251484752").unwrap(), - // U256::from_dec_str("5562089018027206512286783868306950659834000523781522158661084193254167305831").unwrap(), - // ], - // vec![ - // U256::from_dec_str("7633925392184781104787537197952383405066326059553608577981951477761067715424").unwrap(), - // U256::from_dec_str("19510227686274170330355317434483857344641524658406254379151352263942714837771").unwrap(), - // ] - // ] - // ); - - // let valid_input = vec![ - // U256::from_dec_str("14754876691570659999").unwrap(), - // U256::from_dec_str("1449725765053302887").unwrap(), - // U256::from_dec_str("10573592104590215630").unwrap(), - // U256::from_dec_str("2031301759166401468").unwrap() - // ]; - - // let verifying_key = VerifyingKey::new(proof, vk, valid_input); - - // let zk_verifier = ZKPrecompileVerifier::new( - // H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), - // verifying_key - // ); - - // let encoded_call = zk_verifier.generate_benchmarking_parameters(); - - // let gas_limit_call = 1000000; - // let value = U256::default(); - // let is_transactional = true; - // let validate = true; - // }:{ - // let call_runner_results = ::Runner::call( - // caller, - // contract_address, - // encoded_call, - // value, - // gas_limit_call, - // Some(U256::from(1_000_000_000)), - // Some(U256::from(1_000_000_000)), - // None, - // Vec::new(), - // is_transactional, - // validate, - // ::config(), - // ); - // // log::info!( - // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // // "Benchmarking call end.", - // // ); - // match call_runner_results { - // Ok(info) => { - // let output = info.value; - // // log::info!( - // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // // "output result {:?}", - // // output - // // ); - // if output.len() >= 32 { - // let mut result_bytes = [0u8; 32]; - // result_bytes.copy_from_slice(&output[output.len() - 32..]); - // let result = U256::from_big_endian(&result_bytes); - // // log::info!( - // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // // "Verification result {result:?}", - // // ); - // assert_eq!(result, U256::one(), "The contract did not return true"); - // } - // }, - // Err(e) => { - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "Benchmarking failed", - // ); - // } - // } - // } - - // nconstraints_1000 { - // use frame_benchmarking::vec; - // use sp_core::{H160, U256, H256}; - - // let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); - // let contract_address = H160::from_low_u64_be(0x8888); - - // let proof = Proof::new( - // vec![ - // U256::from_dec_str("12451505848309631687252015279596976128225375079184616465869275088833975377438").unwrap(), - // U256::from_dec_str("18028472547304696309803026581736164843724278168110632635282700219721294267849").unwrap(), - // ], - // vec![ - // vec![ - // U256::from_dec_str("724941625340075448308940885419778921267046089963198424690563710257350467820").unwrap(), - // U256::from_dec_str("19418815036545241911278056687101064762643664412732993043969007894248087117385").unwrap(), - // ], - // vec![ - // U256::from_dec_str("13249414494230793056410904135885722890271124096600389432878053498484425858770").unwrap(), - // U256::from_dec_str("21762806144353143011028620465453743506764842517668851190776375592288870325215").unwrap(), - // ], - // ], - // vec![ - // U256::from_dec_str("9206867270262791130308246301015463866896172966002943363908694359851632501217").unwrap(), - // U256::from_dec_str("13679683495177263967294831832954860495137891909047512983345948806664713075553").unwrap(), - // ] - // ); - - // let vk = VerifyingKeyComponents::new( - // vec![ - // U256::from_dec_str("13896934827344718021853288836918374118104295193491067840322643424358899121542").unwrap(), - // U256::from_dec_str("8854052944916041632001392967979629780372345382861670282089777314383817716115").unwrap(), - // ], - // vec![ - // vec![ - // U256::from_dec_str("3601177773308419037453361001975316835601350296485805323140167568598797930642").unwrap(), - // U256::from_dec_str("48851914275316782871445347689531673984580545598074561513165366823294923594").unwrap(), - // ], - // vec![ - // U256::from_dec_str("4538012201084519544875007504928553564968897773565284770715803834936680149613").unwrap(), - // U256::from_dec_str("3155968616270588886660033728776257587454508333510911411658919790925259116614").unwrap(), - // ], - // ], - // vec![ - // vec![ - // U256::from_dec_str("6521538659624675039700866061977650833785775087701556120926232218187885377774").unwrap(), - // U256::from_dec_str("18707623749213430453109215145186606994638201653518117177006249287165414157706").unwrap(), - // ], - // vec![ - // U256::from_dec_str("11743109857123024729794370527373948778820323338754388805090881243904381703330").unwrap(), - // U256::from_dec_str("3577725017182890090279110701721773090147301853148322630192233820247926772155").unwrap(), - // ], - // ], - // vec![ - // vec![ - // U256::from_dec_str("10697077492206594361644026971284249101590705030465491131467731100150008255694").unwrap(), - // U256::from_dec_str("1114380532795466865933623446272212800793315337032855536172932313989250445726").unwrap(), - // ], - // vec![ - // U256::from_dec_str("11747915450686416011932172170367549011245903715607283230565719536126230133873").unwrap(), - // U256::from_dec_str("1877153534214274703747923906347594924169181268669702005894131954432202950068").unwrap(), - // ] - // ], - // vec![ - // vec![ - // U256::from_dec_str("6294921440683861296812943370338888809368101163511446375226378176013676840633").unwrap(), - // U256::from_dec_str("8766686502883018606879699065134987161183815270662618961653335871316040755302").unwrap(), - // ], - // vec![ - // U256::from_dec_str("15422085976834841481597157129530660038025986735930069198619117556493669017719").unwrap(), - // U256::from_dec_str("6824904336141021449652133306590775160232847673735850151493603664420102965477").unwrap(), - // ] - // ] - // ); - - // let valid_input = vec![ - // U256::from_dec_str("5637188163546619750").unwrap(), - // U256::from_dec_str("4876642863872575056").unwrap(), - // U256::from_dec_str("11311886144936918135").unwrap(), - // U256::from_dec_str("2620236256196171805").unwrap() - // ]; - - // let verifying_key = VerifyingKey::new(proof, vk, valid_input); - - // let zk_verifier = ZKPrecompileVerifier::new( - // H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), - // verifying_key - // ); - - // let encoded_call = zk_verifier.generate_benchmarking_parameters(); - - // let gas_limit_call = 1000000; - // let value = U256::default(); - // let is_transactional = true; - // let validate = true; - // }:{ - // let call_runner_results = ::Runner::call( - // caller, - // contract_address, - // encoded_call, - // value, - // gas_limit_call, - // Some(U256::from(1_000_000_000)), - // Some(U256::from(1_000_000_000)), - // None, - // Vec::new(), - // is_transactional, - // validate, - // ::config(), - // ); - // // log::info!( - // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // // "Benchmarking call end.", - // // ); - // match call_runner_results { - // Ok(info) => { - // let output = info.value; - // // log::info!( - // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // // "output result {:?}", - // // output - // // ); - // if output.len() >= 32 { - // let mut result_bytes = [0u8; 32]; - // result_bytes.copy_from_slice(&output[output.len() - 32..]); - // let result = U256::from_big_endian(&result_bytes); - // // log::info!( - // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // // "Verification result {result:?}", - // // ); - // assert_eq!(result, U256::one(), "The contract did not return true"); - // } - // }, - // Err(e) => { - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "Benchmarking failed", - // ); - // } - // } - // } - // nconstraints_900000 { - // use frame_benchmarking::vec; - // use sp_core::{H160, U256, H256}; - - // let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); - // let contract_address = H160::from_low_u64_be(0x8888); - - // let proof = Proof::new( - // vec![ - // U256::from_dec_str("19469224081137364911375441935428613758543844094780123177610680784796374565509").unwrap(), - // U256::from_dec_str("2964109100176825277964902990593130655404587548088911907169158668561756482373").unwrap(), - // ], - // vec![ - // vec![ - // U256::from_dec_str("1804788596044451078391485097362341934563024367189115611320140606169017734442").unwrap(), - // U256::from_dec_str("13075356869764013404490647878715830765050556805353047586243641659166972614506").unwrap(), - // ], - // vec![ - // U256::from_dec_str("11510752280195741101381678478126680255679095252133774347633523263393718090827").unwrap(), - // U256::from_dec_str("19917734624109913540474402939707087760514256808495299709893660593520804971329").unwrap(), - // ], - // ], - // vec![ - // U256::from_dec_str("17650234014776935476405426867265189573543251264844619398004397025922351000524").unwrap(), - // U256::from_dec_str("13980409623437481166079302794215538337078177634480935418093274323345259996058").unwrap(), - // ] - // ); - - // let vk = VerifyingKeyComponents::new( - // vec![ - // U256::from_dec_str("7204013913559348808806179272679133668079798990573619252699122941477292720367").unwrap(), - // U256::from_dec_str("14448814309541293146746525253301533902449817953703436076734477345366335651547").unwrap(), - // ], - // vec![ - // vec![ - // U256::from_dec_str("12755354931522455226769415963087662012592248962914015697167303994293035888664").unwrap(), - // U256::from_dec_str("19979994508677160041392994419804596139216500302977150541381981675855322022114").unwrap(), - // ], - // vec![ - // U256::from_dec_str("3518578052095992035034011768990132253597152650327354182069223777691356587613").unwrap(), - // U256::from_dec_str("1512363495951297845516866605291301480678745477544041997800458458709067854003").unwrap(), - // ], - // ], - // vec![ - // vec![ - // U256::from_dec_str("21483901865224554977407186643009006049964266844355020377697169106001216486465").unwrap(), - // U256::from_dec_str("18122216236568402305988297032517775914181563813086813006164216689752246508886").unwrap(), - // ], - // vec![ - // U256::from_dec_str("7100124544075226034251596932805277307734457677256004047412258693103409543678").unwrap(), - // U256::from_dec_str("9484826513489508497326605298995346628011303684771342589708630141744196880174").unwrap(), - // ], - // ], - // vec![ - // vec![ - // U256::from_dec_str("4294809674390523555755416088340227038268056188806697061914357207030835445784").unwrap(), - // U256::from_dec_str("12772882987652274474928251216882135157601158713560023135442912416889883375009").unwrap(), - // ], - // vec![ - // U256::from_dec_str("5017814360156811257431228283078380210712481496173867244303167538680301406355").unwrap(), - // U256::from_dec_str("5483986251263351055676143301589669624262947345327185314870128974364440001262").unwrap(), - // ] - // ], - // vec![ - // vec![ - // U256::from_dec_str("10485365056956235833573091505977794158366069646492853613385564319176805042067").unwrap(), - // U256::from_dec_str("21560988819791135038184934219494970236802908435926324068683299817562907341696").unwrap(), - // ], - // vec![ - // U256::from_dec_str("9274251274730510866039258353232655161206943117093211738883330925803202790098").unwrap(), - // U256::from_dec_str("19994917632455570632082635510110118222993755636207706143729050502915579896735").unwrap(), - // ] - // ] - // ); - - // let valid_input = vec![ - // U256::from_dec_str("10518156496175725870").unwrap(), - // U256::from_dec_str("8513656267880232886").unwrap(), - // U256::from_dec_str("1469451646407182009").unwrap(), - // U256::from_dec_str("3425508166019525724").unwrap() - // ]; - - // let verifying_key = VerifyingKey::new(proof, vk, valid_input); - - // let zk_verifier = ZKPrecompileVerifier::new( - // H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), - // verifying_key - // ); - - // let encoded_call = zk_verifier.generate_benchmarking_parameters(); - - // let gas_limit_call = 1000000; - // let value = U256::default(); - // let is_transactional = true; - // let validate = true; - // }:{ - // let call_runner_results = ::Runner::call( - // caller, - // contract_address, - // encoded_call, - // value, - // gas_limit_call, - // Some(U256::from(1_000_000_000)), - // Some(U256::from(1_000_000_000)), - // None, - // Vec::new(), - // is_transactional, - // validate, - // ::config(), - // ); - // // log::info!( - // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // // "Benchmarking call end.", - // // ); - // match call_runner_results { - // Ok(info) => { - // let output = info.value; - // // log::info!( - // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // // "output result {:?}", - // // output - // // ); - // if output.len() >= 32 { - // let mut result_bytes = [0u8; 32]; - // result_bytes.copy_from_slice(&output[output.len() - 32..]); - // let result = U256::from_big_endian(&result_bytes); - // // log::info!( - // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // // "Verification result {result:?}", - // // ); - // assert_eq!(result, U256::one(), "The contract did not return true"); - // } - // }, - // Err(e) => { - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "Benchmarking failed", - // ); - // } - // } - // } - - // nconstraints_30_input_10 { - // use frame_benchmarking::vec; - // use sp_core::{H160, U256, H256}; - - // let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); - // let contract_address = H160::from_low_u64_be(0x8888); - - // let proof = Proof::new( - // vec![ - // U256::from_dec_str("344113499780097036133410144688544669449665038469801025061703634064197059916").unwrap(), - // U256::from_dec_str("8339013355837829034186604529242237434382457535922383671882155606562413431689").unwrap(), - // ], - // vec![ - // vec![ - // U256::from_dec_str("6694199005832176626648387473003377778002164049654344388623160500074797775370").unwrap(), - // U256::from_dec_str("6246558478856965861562784864034844546822126660127014237507763330640717221466").unwrap(), - // ], - // vec![ - // U256::from_dec_str("456859418727494804887897697519797382313397623366843307513728588676215628797").unwrap(), - // U256::from_dec_str("19972929684979882956825623277042855987039264105600158828132263230333203670106").unwrap(), - // ], - // ], - // vec![ - // U256::from_dec_str("8991876521515422964548874095107781976525191569601242691722207742733698821028").unwrap(), - // U256::from_dec_str("17304897036279645989594099459944208131107988079437513579584585106093260802053").unwrap(), - // ] - // ); - - // let vk = VerifyingKeyComponents::new( - // vec![ - // U256::from_dec_str("16587578668155053320776501244706909164198053583863284386206654068019392556543").unwrap(), - // U256::from_dec_str("17489859882312386925030082840618136961844042944104008122175974338708995824981").unwrap(), - // ], - // vec![ - // vec![ - // U256::from_dec_str("8243058085082563940310351321464397410632520885003827137093771369586433446018").unwrap(), - // U256::from_dec_str("1806964369040712598415691188975966807767394918682209427183228092832571919497").unwrap(), - // ], - // vec![ - // U256::from_dec_str("5238575049648595236335310308987023404502439315997088611926714272919127054029").unwrap(), - // U256::from_dec_str("10529242360048105445622302340100671863366518517961350431989359465371013288044").unwrap(), - // ], - // ], - // vec![ - // vec![ - // U256::from_dec_str("422118731661843716781379598081446048950684758761078928178953272944418614265").unwrap(), - // U256::from_dec_str("8071137901873450516865398890359069534977349842235015782367912081100468370342").unwrap(), - // ], - // vec![ - // U256::from_dec_str("6616051543776580097026224309598118359974125974677691608309070965923230091481").unwrap(), - // U256::from_dec_str("3144026861846828201735234261898216197057552604232403108299101704912138104081").unwrap(), - // ], - // ], - // vec![ - // vec![ - // U256::from_dec_str("15967728838725285670062386536689775286816477877862913251436519988213464788203").unwrap(), - // U256::from_dec_str("14482652023948193853731701210376245407114581664800773915003137369238699817066").unwrap(), - // ], - // vec![ - // U256::from_dec_str("20222564526826997580988353930405539667760709452060576182511364617433825375503").unwrap(), - // U256::from_dec_str("1855904408322765948314758770516591135802311025429227172106073057339165107921").unwrap(), - // ] - // ], - // vec![ - // vec![ - // U256::from_dec_str("2234398803815490360326379119253073021265347911436036657996997085101774002925").unwrap(), - // U256::from_dec_str("10214773739303944856355679056757071889148916152665035343340628435407174724717").unwrap(), - // ], - // vec![ - // U256::from_dec_str("21500623561133929663133180424780657403302270303706782392356903439186747104812").unwrap(), - // U256::from_dec_str("19328419280811286038333929820672543691407985372391054082759992875889788951230").unwrap(), - // ] - // ] - // ); - - // let valid_input = vec![ - // U256::from_dec_str("14321691860995553260").unwrap(), - // U256::from_dec_str("7152862679273281751").unwrap(), - // U256::from_dec_str("12752615512303817990").unwrap(), - // U256::from_dec_str("1576113262537949146").unwrap() - // ]; - - // let verifying_key = VerifyingKey::new(proof, vk, valid_input); - - // let zk_verifier = ZKPrecompileVerifier::new( - // H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), - // verifying_key - // ); - - // let encoded_call = zk_verifier.generate_benchmarking_parameters(); - - // let gas_limit_call = 1000000; - // let value = U256::default(); - // let is_transactional = true; - // let validate = true; - // }:{ - // let call_runner_results = ::Runner::call( - // caller, - // contract_address, - // encoded_call, - // value, - // gas_limit_call, - // Some(U256::from(1_000_000_000)), - // Some(U256::from(1_000_000_000)), - // None, - // Vec::new(), - // is_transactional, - // validate, - // ::config(), - // ); - // // log::info!( - // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // // "Benchmarking call end.", - // // ); - // match call_runner_results { - // Ok(info) => { - // let output = info.value; - // // log::info!( - // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // // "output result {:?}", - // // output - // // ); - // if output.len() >= 32 { - // let mut result_bytes = [0u8; 32]; - // result_bytes.copy_from_slice(&output[output.len() - 32..]); - // let result = U256::from_big_endian(&result_bytes); - // // log::info!( - // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // // "Verification result {result:?}", - // // ); - // assert_eq!(result, U256::one(), "The contract did not return true"); - // } - // }, - // Err(e) => { - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "Benchmarking failed", - // ); - // } - // } - // } - // nconstraints_30_input_100 { - // use frame_benchmarking::vec; - // use sp_core::{H160, U256, H256}; - - // let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); - // let contract_address = H160::from_low_u64_be(0x8888); - - // let proof = Proof::new( - // vec![ - // U256::from_dec_str("3780487311936056381294564418675304364481973966802209296561160829797948105411").unwrap(), - // U256::from_dec_str("12392254879980640223142009257910424254771509444451393927739643876401726307795").unwrap(), - // ], - // vec![ - // vec![ - // U256::from_dec_str("5169548117445173154024813698359426977000013771483410622256640533171985245380").unwrap(), - // U256::from_dec_str("11220449603083268927036844276912830985523128428499468942581840512730495047625").unwrap(), - // ], - // vec![ - // U256::from_dec_str("7617888807668014594076695037395251387521432502213194545531858961238344338860").unwrap(), - // U256::from_dec_str("3206448605631210983027663221710912427383659852717855953276353488187250079459").unwrap(), - // ], - // ], - // vec![ - // U256::from_dec_str("17260938596020642923034443094579912726381749511890996943502017876149586484217").unwrap(), - // U256::from_dec_str("973711408795313031099855712156150142641887502706075552254275664528776194028").unwrap(), - // ] - // ); - - // let vk = VerifyingKeyComponents::new( - // vec![ - // U256::from_dec_str("4155898266631322214574856388057229131381603659142355428000239527171539910720").unwrap(), - // U256::from_dec_str("15919304600573806746067202721026223664629992455130946331020176989460510062648").unwrap(), - // ], - // vec![ - // vec![ - // U256::from_dec_str("10559477888637541108523299513483158185288656601390229631277602982302056830264").unwrap(), - // U256::from_dec_str("21518216923189214839507247102243744126930049565774641401859791113452178471842").unwrap(), - // ], - // vec![ - // U256::from_dec_str("20524972206762616004058259260290957844870248494446046806278424843369643489182").unwrap(), - // U256::from_dec_str("17430943082223119961631960086233630485654941075995072846024219998674392652581").unwrap(), - // ], - // ], - // vec![ - // vec![ - // U256::from_dec_str("4636362103930283526843587215716464395878300635435610009766312980459671398351").unwrap(), - // U256::from_dec_str("15713999866924132629927290621261290205960872899800820372400263081232019214301").unwrap(), - // ], - // vec![ - // U256::from_dec_str("274224283373606674211197218239218941312046485596075799302472837928822177016").unwrap(), - // U256::from_dec_str("10693491445395060496723678108216498586881120243971297703830999940561952271629").unwrap(), - // ], - // ], - // vec![ - // vec![ - // U256::from_dec_str("9540601502504552621404908678855872975596983734893914263055690675850649191273").unwrap(), - // U256::from_dec_str("10288168694112392204164781631687615725045294841966564539511156565183262528849").unwrap(), - // ], - // vec![ - // U256::from_dec_str("16504160099082952601826232467479510151840980336862791499394346450083636791102").unwrap(), - // U256::from_dec_str("9210167978306154509907086298616199856898787966613435045760659519455958969992").unwrap(), - // ] - // ], - // vec![ - // vec![ - // U256::from_dec_str("15812098394101742886061540987450559986219804469912805896076341688421241661621").unwrap(), - // U256::from_dec_str("11920211969663783445335622417572072568292106489672989284415235777753260953099").unwrap(), - // ], - // vec![ - // U256::from_dec_str("7061409000327933635430701054193661775345794014516696263402966093123651666364").unwrap(), - // U256::from_dec_str("17078047162776906089011285464212202278306676406084693061907121919624683442357").unwrap(), - // ] - // ] - // ); - - // let valid_input = vec![ - // U256::from_dec_str("9831528597301135316").unwrap(), - // U256::from_dec_str("11053911270256492840").unwrap(), - // U256::from_dec_str("14337707091878126846").unwrap(), - // U256::from_dec_str("772611368070892958").unwrap() - // ]; - - // let verifying_key = VerifyingKey::new(proof, vk, valid_input); - - // let zk_verifier = ZKPrecompileVerifier::new( - // H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), - // verifying_key - // ); - - // let encoded_call = zk_verifier.generate_benchmarking_parameters(); - - // let gas_limit_call = 1000000; - // let value = U256::default(); - // let is_transactional = true; - // let validate = true; - // }:{ - // let call_runner_results = ::Runner::call( - // caller, - // contract_address, - // encoded_call, - // value, - // gas_limit_call, - // Some(U256::from(1_000_000_000)), - // Some(U256::from(1_000_000_000)), - // None, - // Vec::new(), - // is_transactional, - // validate, - // ::config(), - // ); - // // log::info!( - // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // // "Benchmarking call end.", - // // ); - // match call_runner_results { - // Ok(info) => { - // let output = info.value; - // // log::info!( - // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // // "output result {:?}", - // // output - // // ); - // if output.len() >= 32 { - // let mut result_bytes = [0u8; 32]; - // result_bytes.copy_from_slice(&output[output.len() - 32..]); - // let result = U256::from_big_endian(&result_bytes); - // // log::info!( - // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // // "Verification result {result:?}", - // // ); - // assert_eq!(result, U256::one(), "The contract did not return true"); - // } - // }, - // Err(e) => { - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "Benchmarking failed", - // ); - // } - // } - // } - // nconstraints_30_input_1000 { - // use frame_benchmarking::vec; - // use sp_core::{H160, U256, H256}; - - // let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); - // let contract_address = H160::from_low_u64_be(0x8888); - - // let proof = Proof::new( - // vec![ - // U256::from_dec_str("21424271595387505713049534900676381136649432939050012296331964885140120988520").unwrap(), - // U256::from_dec_str("20488789316104689748479888121024139144355086386496471461763924485714534718686").unwrap(), - // ], - // vec![ - // vec![ - // U256::from_dec_str("8417699613540073682519718294821269056423071880647667978060348740795273915651").unwrap(), - // U256::from_dec_str("4036859279888161250878359321718658739242283134835030699023268489309754993434").unwrap(), - // ], - // vec![ - // U256::from_dec_str("16249800568747110450527363597274431407786919086057853194987169090454936230259").unwrap(), - // U256::from_dec_str("15005851458712291005106538565823270955208428726378749297397203143137382225457").unwrap(), - // ], - // ], - // vec![ - // U256::from_dec_str("21239990703864671714190525785674088715931473556140655107585637961585812134589").unwrap(), - // U256::from_dec_str("261928180985765917331919571442880380998408670702589931014636966043229919418").unwrap(), - // ] - // ); - - // let vk = VerifyingKeyComponents::new( - // vec![ - // U256::from_dec_str("1657406292532781196449359079614579852690925607592278296574718289470803732053").unwrap(), - // U256::from_dec_str("18213557747942747074556848145237207574111244905157024361329330629173034829885").unwrap(), - // ], - // vec![ - // vec![ - // U256::from_dec_str("5419856735820685908218319193906907396496344921642651266629131019868853843815").unwrap(), - // U256::from_dec_str("14007905369450574044915098075029863272475910046750101274280969769181784166430").unwrap(), - // ], - // vec![ - // U256::from_dec_str("182200131698860550444455761364918630551676350878779858078817264277300629723").unwrap(), - // U256::from_dec_str("6050431818377820601319883600432739448105157482353041283628740094609821419656").unwrap(), - // ], - // ], - // vec![ - // vec![ - // U256::from_dec_str("14463567879100083166257564330995533094334991709675023767975192973144798919122").unwrap(), - // U256::from_dec_str("6166287541473141918830331239835928582190744434356526822227225877844349692203").unwrap(), - // ], - // vec![ - // U256::from_dec_str("12512843744533735346513506961399336936527367720771340395643503621530703342395").unwrap(), - // U256::from_dec_str("8394818975982736201521422268641084055810886358791398607930311472872317386487").unwrap(), - // ], - // ], - // vec![ - // vec![ - // U256::from_dec_str("8757732756289429354419510422628896433407345473998310348115924113882282945326").unwrap(), - // U256::from_dec_str("1610185885725147927651201796201713521257480620743342969197368887869230657180").unwrap(), - // ], - // vec![ - // U256::from_dec_str("2834338214415807920713929739507915327763263469562351781747229949754640383374").unwrap(), - // U256::from_dec_str("20761263923134391843554423575366232120525285729512411038267095810712916924016").unwrap(), - // ] - // ], - // vec![ - // vec![ - // U256::from_dec_str("16585432354609922217222548226453277630464695131710476183479619760311567992522").unwrap(), - // U256::from_dec_str("5379258900528839934525784961038010961454863754298062530193947624450477797122").unwrap(), - // ], - // vec![ - // U256::from_dec_str("16825349369326282879106301528709807467071985531593215317852699692046311881677").unwrap(), - // U256::from_dec_str("10540450379202726868409867306854114915477889581096312866635875249145708179576").unwrap(), - // ] - // ] - // ); - - // let valid_input = vec![ - // U256::from_dec_str("3008789406746563016").unwrap(), - // U256::from_dec_str("7061370202899273426").unwrap(), - // U256::from_dec_str("2191755323004339933").unwrap(), - // U256::from_dec_str("1005591455220622530").unwrap() - // ]; - - // let verifying_key = VerifyingKey::new(proof, vk, valid_input); - - // let zk_verifier = ZKPrecompileVerifier::new( - // H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), - // verifying_key - // ); - - // let encoded_call = zk_verifier.generate_benchmarking_parameters(); - - // let gas_limit_call = 1000000; - // let value = U256::default(); - // let is_transactional = true; - // let validate = true; - // }:{ - // let call_runner_results = ::Runner::call( - // caller, - // contract_address, - // encoded_call, - // value, - // gas_limit_call, - // Some(U256::from(1_000_000_000)), - // Some(U256::from(1_000_000_000)), - // None, - // Vec::new(), - // is_transactional, - // validate, - // ::config(), - // ); - // // log::info!( - // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // // "Benchmarking call end.", - // // ); - // match call_runner_results { - // Ok(info) => { - // let output = info.value; - // // log::info!( - // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // // "output result {:?}", - // // output - // // ); - // if output.len() >= 32 { - // let mut result_bytes = [0u8; 32]; - // result_bytes.copy_from_slice(&output[output.len() - 32..]); - // let result = U256::from_big_endian(&result_bytes); - // // log::info!( - // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // // "Verification result {result:?}", - // // ); - // assert_eq!(result, U256::one(), "The contract did not return true"); - // } - // }, - // Err(e) => { - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "Benchmarking failed", - // ); - // } - // } - // } - // nconstraints_30_input_5000 { - // use frame_benchmarking::vec; - // use sp_core::{H160, U256, H256}; - - // let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); - // let contract_address = H160::from_low_u64_be(0x8888); - - // let proof = Proof::new( - // vec![ - // U256::from_dec_str("4760178114933307527976205229418881302833473087272893863010681924222436742436").unwrap(), - // U256::from_dec_str("6555056836023646163359279772724076765411780318148657506988760187885700674215").unwrap(), - // ], - // vec![ - // vec![ - // U256::from_dec_str("9540205596737585525189386078607957630969059503165883907845238817662495399607").unwrap(), - // U256::from_dec_str("21777913747079267536001051597001736802905779914683258171463923506869689358122").unwrap(), - // ], - // vec![ - // U256::from_dec_str("7652162643714058076103867092157642519402862581818067281609790687905833151647").unwrap(), - // U256::from_dec_str("5174136241284192352871549806655421810249317805219641765935618077180420544939").unwrap(), - // ], - // ], - // vec![ - // U256::from_dec_str("9633653417112713107386510132385608824105920168790226750481878454006412372444").unwrap(), - // U256::from_dec_str("5600932933208824148570351176368803282808856587672889614186338874655752173453").unwrap(), - // ] - // ); - - // let vk = VerifyingKeyComponents::new( - // vec![ - // U256::from_dec_str("20563201722283471489193032980811350162387466733119686723832100493505332037220").unwrap(), - // U256::from_dec_str("458683337854426284881131074995322438618437423037306322290239745015633774839").unwrap(), - // ], - // vec![ - // vec![ - // U256::from_dec_str("802687519037697530569139206036966996588449135138601551566343295868421688400").unwrap(), - // U256::from_dec_str("10902489968444563758310974921240106861656913905085710523025258522577834664814").unwrap(), - // ], - // vec![ - // U256::from_dec_str("8163282908300075270434111132545381898266738500810094061899946027883982232155").unwrap(), - // U256::from_dec_str("2879234862354419255322548813414679750617024208122660306082351289172177493856").unwrap(), - // ], - // ], - // vec![ - // vec![ - // U256::from_dec_str("12946416399098615767859440028401625777970463338055590127763655113029764523456").unwrap(), - // U256::from_dec_str("19000556224902286061769815260124368973839417953399533885850283592096662743016").unwrap(), - // ], - // vec![ - // U256::from_dec_str("16883066945921282046110808795753929362007100542422795769422243319629113077450").unwrap(), - // U256::from_dec_str("3229017908221308993692674040951942449106283130433174678816420254626513367678").unwrap(), - // ], - // ], - // vec![ - // vec![ - // U256::from_dec_str("16459854676924169388774046538295013154707390397685062918225181412137603478923").unwrap(), - // U256::from_dec_str("20996869365345436816737319903210535785982053153529758285286719146777762981985").unwrap(), - // ], - // vec![ - // U256::from_dec_str("21446959969822179574296836241978980045198577120638747119902976563053247153220").unwrap(), - // U256::from_dec_str("4716297282146551186330252875195511360280503254452482577157100992033023717484").unwrap(), - // ] - // ], - // vec![ - // vec![ - // U256::from_dec_str("2127664998061023131080125201643658604092063304061707222326237054428506173927").unwrap(), - // U256::from_dec_str("13918137729545385379467184110597023571257121066683873930760549927318081992996").unwrap(), - // ], - // vec![ - // U256::from_dec_str("16560640526003408304721205785917894782070253870764339317137905014294472374327").unwrap(), - // U256::from_dec_str("19394535992291030838186763750684977819230291410826312937425829210188321257228").unwrap(), - // ] - // ] - // ); - - // let valid_input = vec![ - // U256::from_dec_str("13212982172557049181").unwrap(), - // U256::from_dec_str("17043673098390055166").unwrap(), - // U256::from_dec_str("13971391527459105160").unwrap(), - // U256::from_dec_str("1729491887349651790").unwrap(), - // ]; - - // let verifying_key = VerifyingKey::new(proof, vk, valid_input); - - // let zk_verifier = ZKPrecompileVerifier::new( - // H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), - // verifying_key - // ); - - // let encoded_call = zk_verifier.generate_benchmarking_parameters(); - - // let gas_limit_call = 1000000; - // let value = U256::default(); - // let is_transactional = true; - // let validate = true; - // }:{ - // let call_runner_results = ::Runner::call( - // caller, - // contract_address, - // encoded_call, - // value, - // gas_limit_call, - // Some(U256::from(1_000_000_000)), - // Some(U256::from(1_000_000_000)), - // None, - // Vec::new(), - // is_transactional, - // validate, - // ::config(), - // ); - // // log::info!( - // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // // "Benchmarking call end.", - // // ); - // match call_runner_results { - // Ok(info) => { - // let output = info.value; - // // log::info!( - // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // // "output result {:?}", - // // output - // // ); - // if output.len() >= 32 { - // let mut result_bytes = [0u8; 32]; - // result_bytes.copy_from_slice(&output[output.len() - 32..]); - // let result = U256::from_big_endian(&result_bytes); - // // log::info!( - // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // // "Verification result {result:?}", - // // ); - // assert_eq!(result, U256::one(), "The contract did not return true"); - // } - // }, - // Err(e) => { - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "Benchmarking failed", - // ); - // } - // } - // } - // nconstraints_30_input_10000 { - // use frame_benchmarking::vec; - // use sp_core::{H160, U256, H256}; - - // let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); - // let contract_address = H160::from_low_u64_be(0x8888); - - // let proof = Proof::new( - // vec![ - // U256::from_dec_str("20201588552006483041582128307591335561381558661958982754827324334159524114833").unwrap(), - // U256::from_dec_str("17768889616334897699714190449991059857597665579001510168911964966707846254013").unwrap(), - // ], - // vec![ - // vec![ - // U256::from_dec_str("831427914683469755258685737297441858923030844026909228595596228891513784401").unwrap(), - // U256::from_dec_str("17358733390631981546461856303504163975689822422160671163593908204299387350560").unwrap(), - // ], - // vec![ - // U256::from_dec_str("12673178383954759426828314411760863182427996098705680584931403917390222262168").unwrap(), - // U256::from_dec_str("12056092533572380482681874959737292916971452073896642753405050795241584080793").unwrap(), - // ], - // ], - // vec![ - // U256::from_dec_str("11086630979744216291689656728938462056245402184490217943698398792953833540899").unwrap(), - // U256::from_dec_str("6981043472993913602669753829495794560155248771335035866541870305230603679484").unwrap(), - // ] - // ); - - // let vk = VerifyingKeyComponents::new( - // vec![ - // U256::from_dec_str("10088605449330278081588905225706913827985798761474642054412607299987851491561").unwrap(), - // U256::from_dec_str("12349112716571349951448807635426375878752472531266562453302627732729311140226").unwrap(), - // ], - // vec![ - // vec![ - // U256::from_dec_str("11234930657858483584603353214391341220392609835907149947974795594440445721655").unwrap(), - // U256::from_dec_str("1047093079337214465686469751128183347143657884406521365857439579470759333731").unwrap(), - // ], - // vec![ - // U256::from_dec_str("15864899975231343872664645828141071246029692141564279838230890638453916423742").unwrap(), - // U256::from_dec_str("12053277475368564348616897081746431255423835262329161057768339971384736640081").unwrap(), - // ], - // ], - // vec![ - // vec![ - // U256::from_dec_str("20662189442791195318296211376162761628558291902545582141646463139520777475283").unwrap(), - // U256::from_dec_str("9279465006661849499753241364514057268552316193158700659184124742215268752791").unwrap(), - // ], - // vec![ - // U256::from_dec_str("17033606864312833588672465768726096906720807717470346504048425104291392352898").unwrap(), - // U256::from_dec_str("15319242533246792039334613039385600689133248724151496600840914674340560979641").unwrap(), - // ], - // ], - // vec![ - // vec![ - // U256::from_dec_str("3303817333656562581428241644233610206796391323593261940899405821542387319372").unwrap(), - // U256::from_dec_str("12434486975702473910116656089923156849733601159782506519440013280731025013736").unwrap(), - // ], - // vec![ - // U256::from_dec_str("9561232329300105849651786447909752108987569955850131116304832039966768267007").unwrap(), - // U256::from_dec_str("18486557213071145739422364713271115450952939790314495487369777335095317193174").unwrap(), - // ] - // ], - // vec![ - // vec![ - // U256::from_dec_str("5864321703423906069527768678401445332135246771872328360194332677453860634867").unwrap(), - // U256::from_dec_str("3305620141441221125469209629518919979790470359050105194093502369856652644459").unwrap(), - // ], - // vec![ - // U256::from_dec_str("1810088252629429255118238329671475280643793553294287131634484491846973310510").unwrap(), - // U256::from_dec_str("20707970746663158481851347112547705553728126185220754421254503093218351233120").unwrap(), - // ] - // ] - // ); - - // let valid_input = vec![ - // U256::from_dec_str("11033755416221607095").unwrap(), - // U256::from_dec_str("14172640425079373737").unwrap(), - // U256::from_dec_str("17268699570210893519").unwrap(), - // U256::from_dec_str("2451003838444787962").unwrap(), - // ]; - - // let verifying_key = VerifyingKey::new(proof, vk, valid_input); - - // let zk_verifier = ZKPrecompileVerifier::new( - // H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), - // verifying_key - // ); - - // let encoded_call = zk_verifier.generate_benchmarking_parameters(); - - // let gas_limit_call = 1000000; - // let value = U256::default(); - // let is_transactional = true; - // let validate = true; - // }:{ - // let call_runner_results = ::Runner::call( - // caller, - // contract_address, - // encoded_call, - // value, - // gas_limit_call, - // Some(U256::from(1_000_000_000)), - // Some(U256::from(1_000_000_000)), - // None, - // Vec::new(), - // is_transactional, - // validate, - // ::config(), - // ); - // // log::info!( - // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // // "Benchmarking call end.", - // // ); - // match call_runner_results { - // Ok(info) => { - // let output = info.value; - // // log::info!( - // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // // "output result {:?}", - // // output - // // ); - // if output.len() >= 32 { - // let mut result_bytes = [0u8; 32]; - // result_bytes.copy_from_slice(&output[output.len() - 32..]); - // let result = U256::from_big_endian(&result_bytes); - // // log::info!( - // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // // "Verification result {result:?}", - // // ); - // assert_eq!(result, U256::one(), "The contract did not return true"); - // } - // }, - // Err(e) => { - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "Benchmarking failed", - // ); - // } - // } - // } - // nconstraints_30_input_90000 { - // use frame_benchmarking::vec; - // use sp_core::{H160, U256, H256}; - - // let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); - // let contract_address = H160::from_low_u64_be(0x8888); - - // let proof = Proof::new( - // vec![ - // U256::from_dec_str("7949275001087845673352113652992317737416671749823042856819742064958185730665").unwrap(), - // U256::from_dec_str("5891863541401068443747112095836743353338477825995666306081231182884954636005").unwrap(), - // ], - // vec![ - // vec![ - // U256::from_dec_str("12960565378826264234747222392568347150301360486418725511109506548813034322775").unwrap(), - // U256::from_dec_str("6924824876048701587380679111548259437770370772320848338373383587483809707515").unwrap(), - // ], - // vec![ - // U256::from_dec_str("21689747160304810742710652756166876177223750769696622871469266436845305438116").unwrap(), - // U256::from_dec_str("14167066926549192557125941689316913820167617731059401320567819691908586156039").unwrap(), - // ], - // ], - // vec![ - // U256::from_dec_str("19186797317064887099470636752510606772753033946198593325337771098325482447274").unwrap(), - // U256::from_dec_str("3350186543680262034371474397706130211690310055235028696466009478959025709845").unwrap(), - // ] - // ); - - // let vk = VerifyingKeyComponents::new( - // vec![ - // U256::from_dec_str("6828794497030502754628523747507406719479438181845328406281207577196379759609").unwrap(), - // U256::from_dec_str("5561027388439947090438746111225212164455366280326670821700904471009784329896").unwrap(), - // ], - // vec![ - // vec![ - // U256::from_dec_str("1648517694167305339737563900225685665396551354808983529387892872646841040850").unwrap(), - // U256::from_dec_str("15406833006990307743521713564090315343374212223020060642984366610793788667116").unwrap(), - // ], - // vec![ - // U256::from_dec_str("14591594646846027404699868040454897990147675572067174007423843530180728597612").unwrap(), - // U256::from_dec_str("2940958434778941597191243007999700895445672570190450648227198352981565653913").unwrap(), - // ], - // ], - // vec![ - // vec![ - // U256::from_dec_str("7676142418543194845482248509044991512324196983308812731866772308356979871307").unwrap(), - // U256::from_dec_str("21511013842679919895947796523736214038726875927496967606596253311081756690725").unwrap(), - // ], - // vec![ - // U256::from_dec_str("4652378032872178978450279958290699982888059033676566152376150880744787185780").unwrap(), - // U256::from_dec_str("467504210088082002071026778234767679654059202832780062786965483300786044530").unwrap(), - // ], - // ], - // vec![ - // vec![ - // U256::from_dec_str("20744282071154891204049714936088748576694067059171789505913191933597423689555").unwrap(), - // U256::from_dec_str("12596866572762256583276410876169296807308160857887657727882625055041251553242").unwrap(), - // ], - // vec![ - // U256::from_dec_str("3588798969790877834321031026222278845206273301850566393834657489341158616535").unwrap(), - // U256::from_dec_str("19268326464935908053037454129640878232926568425004490855381855273084219557079").unwrap(), - // ] - // ], - // vec![ - // vec![ - // U256::from_dec_str("10928515506460596401961934744263657631726985113185854450754018401146226707446").unwrap(), - // U256::from_dec_str("1043421123157233618994554398894819122012315878788274412803269234825060696656").unwrap(), - // ], - // vec![ - // U256::from_dec_str("21802758012415709270812560952687831790545411568500639317690833457802568775035").unwrap(), - // U256::from_dec_str("8926874931677263335476856545765471099163606107894025045476086328360781102193").unwrap(), - // ] - // ] - // ); - - // let valid_input = vec![ - // U256::from_dec_str("2553457387449696641").unwrap(), - // U256::from_dec_str("815105491620421980").unwrap(), - // U256::from_dec_str("17800546104409657428").unwrap(), - // U256::from_dec_str("2866567216183504159").unwrap(), - // ]; - - // let verifying_key = VerifyingKey::new(proof, vk, valid_input); - - // let zk_verifier = ZKPrecompileVerifier::new( - // H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), - // verifying_key - // ); - - // let encoded_call = zk_verifier.generate_benchmarking_parameters(); - - // let gas_limit_call = 1000000; - // let value = U256::default(); - // let is_transactional = true; - // let validate = true; - // }:{ - // let call_runner_results = ::Runner::call( - // caller, - // contract_address, - // encoded_call, - // value, - // gas_limit_call, - // Some(U256::from(1_000_000_000)), - // Some(U256::from(1_000_000_000)), - // None, - // Vec::new(), - // is_transactional, - // validate, - // ::config(), - // ); - // // log::info!( - // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // // "Benchmarking call end.", - // // ); - // match call_runner_results { - // Ok(info) => { - // let output = info.value; - // // log::info!( - // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // // "output result {:?}", - // // output - // // ); - // if output.len() >= 32 { - // let mut result_bytes = [0u8; 32]; - // result_bytes.copy_from_slice(&output[output.len() - 32..]); - // let result = U256::from_big_endian(&result_bytes); - // // log::info!( - // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // // "Verification result {result:?}", - // // ); - // assert_eq!(result, U256::one(), "The contract did not return true"); - // } - // }, - // Err(e) => { - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "Benchmarking failed", - // ); - // } - // } - // } - // nconstraints_30_input_200000 { - // use frame_benchmarking::vec; - // use sp_core::{H160, U256, H256}; - - // let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); - // let contract_address = H160::from_low_u64_be(0x8888); - - // let proof = Proof::new( - // vec![ - // U256::from_dec_str("19903885251949679146607224162906437591286076549652044731739108226015926915860").unwrap(), - // U256::from_dec_str("11870922578907159231760438847634888925027596611865086487008358810346509550746").unwrap(), - // ], - // vec![ - // vec![ - // U256::from_dec_str("7572350741301793140585595336451242554319145556316993930579910816773197602180").unwrap(), - // U256::from_dec_str("16166630091911008518878343585755669995589761813810965163203815419554661335912").unwrap(), - // ], - // vec![ - // U256::from_dec_str("10479558631339350148140324543423297113164179377516410954282474094862685762111").unwrap(), - // U256::from_dec_str("1538599836393367534859442557225095989831507256094436416355361165563840234277").unwrap(), - // ], - // ], - // vec![ - // U256::from_dec_str("18566368172831132986640612657510108843544042128267080758083569019690510537842").unwrap(), - // U256::from_dec_str("14637144036179606956000163117625168358523245864386632910728645092984303842870").unwrap(), - // ] - // ); - - // let vk = VerifyingKeyComponents::new( - // vec![ - // U256::from_dec_str("3388366987275268645608688601800038483480506575351380219459271970783548315310").unwrap(), - // U256::from_dec_str("10139982329791419477606385196757134153200700293861474061701578521738893563314").unwrap(), - // ], - // vec![ - // vec![ - // U256::from_dec_str("17293003127353596916845398615566872053529832484770184120881889494052646686398").unwrap(), - // U256::from_dec_str("3746742577904007471872553744363212404516454459540143078991207693255568088158").unwrap(), - // ], - // vec![ - // U256::from_dec_str("18996426015092705424501193523094438770040629737761363033585766320236602756452").unwrap(), - // U256::from_dec_str("5993252813486169444483155589566709251331252167093428959716521680127596688663").unwrap(), - // ], - // ], - // vec![ - // vec![ - // U256::from_dec_str("86221489590459042456285770827248107701675460052532768290239949641616327672").unwrap(), - // U256::from_dec_str("21618235778373592971185937996314200926578828337383413751502402964191761009384").unwrap(), - // ], - // vec![ - // U256::from_dec_str("10453895050472290645179709462208119639593757329666114205922088367970822668124").unwrap(), - // U256::from_dec_str("16924749634830145681809164670725933237166438445526123149706427927968513710893").unwrap(), - // ], - // ], - // vec![ - // vec![ - // U256::from_dec_str("20506347836984398194650179863264269358088067779451739307543701941138658771117").unwrap(), - // U256::from_dec_str("15256122081275324863091225387225218399888282841698960666742408225921079848693").unwrap(), - // ], - // vec![ - // U256::from_dec_str("7881380592415293900063452944037916715621668238658562838630198037249553436647").unwrap(), - // U256::from_dec_str("6003465274284900873747728448177380007802003937728590930467990944623586277089").unwrap(), - // ] - // ], - // vec![ - // vec![ - // U256::from_dec_str("5531662187275540864474040102019845108669876235687831703751327129559212127084").unwrap(), - // U256::from_dec_str("11455786949456856409363436892267690994602451302132959153447251790964376014822").unwrap(), - // ], - // vec![ - // U256::from_dec_str("17221728819314881853232886080533000381382340762620795831983019279828981481257").unwrap(), - // U256::from_dec_str("19341881794793455210912817199750586531241336493382870655971958667936340901503").unwrap(), - // ] - // ] - // ); - - // let valid_input = vec![ - // U256::from_dec_str("17510768071209558285").unwrap(), - // U256::from_dec_str("11281672863963944712").unwrap(), - // U256::from_dec_str("17936011136389338927").unwrap(), - // U256::from_dec_str("2683423138755332222").unwrap(), - // ]; - - // let verifying_key = VerifyingKey::new(proof, vk, valid_input); - - // let zk_verifier = ZKPrecompileVerifier::new( - // H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), - // verifying_key - // ); - - // let encoded_call = zk_verifier.generate_benchmarking_parameters(); - - // let gas_limit_call = 1000000; - // let value = U256::default(); - // let is_transactional = true; - // let validate = true; - // }:{ - // let call_runner_results = ::Runner::call( - // caller, - // contract_address, - // encoded_call, - // value, - // gas_limit_call, - // Some(U256::from(1_000_000_000)), - // Some(U256::from(1_000_000_000)), - // None, - // Vec::new(), - // is_transactional, - // validate, - // ::config(), - // ); - // // log::info!( - // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // // "Benchmarking call end.", - // // ); - // match call_runner_results { - // Ok(info) => { - // let output = info.value; - // // log::info!( - // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // // "output result {:?}", - // // output - // // ); - // if output.len() >= 32 { - // let mut result_bytes = [0u8; 32]; - // result_bytes.copy_from_slice(&output[output.len() - 32..]); - // let result = U256::from_big_endian(&result_bytes); - // // log::info!( - // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // // "Verification result {result:?}", - // // ); - // assert_eq!(result, U256::one(), "The contract did not return true"); - // } - // }, - // Err(e) => { - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "Benchmarking failed", - // ); - // } - // } - // } - - // sum_10 { - // use frame_benchmarking::vec; - // use sp_core::{H160, U256, H256}; - - // let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); - // let contract_address = H160::from_low_u64_be(0x8888); - - // let proof = Proof::new( - // vec![ - // U256::from_dec_str("4479438672593572194843316486259284641920166054544576564310150763796220593742").unwrap(), - // U256::from_dec_str("5717857931841301866217201485541887040818093727574311517591849036289507799141").unwrap(), - // ], - // vec![ - // vec![ - // U256::from_dec_str("438102211713357984070931589322877643391719193099221891191956755149301376056").unwrap(), - // U256::from_dec_str("14696299438400225528910058565202329177181471318954607581306780544413371767738").unwrap(), - // ], - // vec![ - // U256::from_dec_str("18723112929967827488252389384208353884816003870032279933823625467146809072448").unwrap(), - // U256::from_dec_str("781225142569358922067919798403956593420009838230922093237868933021043854113").unwrap(), - // ], - // ], - // vec![ - // U256::from_dec_str("10481213903673023503381125372528754955378591812884098928519623211332171467098").unwrap(), - // U256::from_dec_str("15098195705682978185145469811146985310923026878303775073727891846327587112885").unwrap(), - // ] - // ); - - // let vk = VerifyingKeyComponents::new( - // vec![ - // U256::from_dec_str("10600514820627226711889163536575359330497844540484876797299835164575096986123").unwrap(), - // U256::from_dec_str("8955505242614929800342716899005854501255692108538633212406728467939250778259").unwrap(), - // ], - // vec![ - // vec![ - // U256::from_dec_str("11358515176167160981846987587695931342878788452018419590778128561277894807040").unwrap(), - // U256::from_dec_str("7367100375568995524851051084377016949291621141008718892167611998460177966556").unwrap(), - // ], - // vec![ - // U256::from_dec_str("9986374126991936592889887298811366506288970021158383914729072242552712258999").unwrap(), - // U256::from_dec_str("5917047061876555575617149777207682047359711575786648519096749890796145313142").unwrap(), - // ], - // ], - // vec![ - // vec![ - // U256::from_dec_str("13008751738470482081156013535203222043379316308698376931322848604706786065862").unwrap(), - // U256::from_dec_str("3415558414191757405655644967374577939532374518318643852418890898323033638525").unwrap(), - // ], - // vec![ - // U256::from_dec_str("2104722493853714523712648261788727756558190509825976396834309269877977849365").unwrap(), - // U256::from_dec_str("6877732520157662584755946842350755740172704606349660337522459938993730313391").unwrap(), - // ], - // ], - // vec![ - // vec![ - // U256::from_dec_str("12470512550870605078154922234115021580073605821744497867586706681115325377951").unwrap(), - // U256::from_dec_str("3964373607930903502336465614571930627592350216968107805643078708599943392195").unwrap(), - // ], - // vec![ - // U256::from_dec_str("9054619931591683490625148848351137928205510101241639415537408964292455344707").unwrap(), - // U256::from_dec_str("14433710971468466044075036729227299898791551573181475688890434779549865103322").unwrap(), - // ] - // ], - // vec![ - // vec![ - // U256::from_dec_str("17691779713798847872985546462247707503645016076661816616388979822201176829753").unwrap(), - // U256::from_dec_str("14451231434311244057691431183198403713720423327382654964068207207079455187712").unwrap(), - // ], - // vec![ - // U256::from_dec_str("13620414910695185146987530463229819484652710069270717148541433045978322585419").unwrap(), - // U256::from_dec_str("10875872907505029426874795808985164080699672034676409959252328566889297105865").unwrap(), - // ] - // ] - // ); - - // let valid_input = vec![ - // U256::from_dec_str("55").unwrap(), - // U256::from_dec_str("0").unwrap(), - // U256::from_dec_str("0").unwrap(), - // U256::from_dec_str("0").unwrap(), - // ]; - - // let verifying_key = VerifyingKey::new(proof, vk, valid_input); - - // let zk_verifier = ZKPrecompileVerifier::new( - // H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), - // verifying_key - // ); - - // let encoded_call = zk_verifier.generate_benchmarking_parameters(); - - // let gas_limit_call = 1000000; - // let value = U256::default(); - // let is_transactional = true; - // let validate = true; - // }:{ - // let call_runner_results = ::Runner::call( - // caller, - // contract_address, - // encoded_call, - // value, - // gas_limit_call, - // Some(U256::from(1_000_000_000)), - // Some(U256::from(1_000_000_000)), - // None, - // Vec::new(), - // is_transactional, - // validate, - // ::config(), - // ); - // // log::info!( - // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // // "Benchmarking call end.", - // // ); - // match call_runner_results { - // Ok(info) => { - // let output = info.value; - // // log::info!( - // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // // "output result {:?}", - // // output - // // ); - // if output.len() >= 32 { - // let mut result_bytes = [0u8; 32]; - // result_bytes.copy_from_slice(&output[output.len() - 32..]); - // let result = U256::from_big_endian(&result_bytes); - // // log::info!( - // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // // "Verification result {result:?}", - // // ); - // assert_eq!(result, U256::one(), "The contract did not return true"); - // } - // }, - // Err(e) => { - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "Benchmarking failed", - // ); - // } - // } - // } - // sum_50 { - // use frame_benchmarking::vec; - // use sp_core::{H160, U256, H256}; - - // let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); - // let contract_address = H160::from_low_u64_be(0x8888); - - // let proof = Proof::new( - // vec![ - // U256::from_dec_str("3114941071688532747454764921300681791980888248199392522675009157778549895455").unwrap(), - // U256::from_dec_str("6816680925124829082835883802586391663161606011222680818599486084577544527516").unwrap(), - // ], - // vec![ - // vec![ - // U256::from_dec_str("15037393792780247314317740287895838240941967969445981241792818111317913065010").unwrap(), - // U256::from_dec_str("3834028682995799272226496422556310257938795862629020590068471611902272764146").unwrap(), - // ], - // vec![ - // U256::from_dec_str("4023883034822047449129381158539093978377425715903419218696272130851521242085").unwrap(), - // U256::from_dec_str("13058906875228264286034925941047330220503025517973111955115072416984072943122").unwrap(), - // ], - // ], - // vec![ - // U256::from_dec_str("5344888056894889487007260648469199417556856955544355154291642477677322944786").unwrap(), - // U256::from_dec_str("19843194668352645797068691966948915569058668700830773246420232986019393210063").unwrap(), - // ] - // ); - - // let vk = VerifyingKeyComponents::new( - // vec![ - // U256::from_dec_str("19257923683733118221652593587810195852599358412856281104090957905722976964370").unwrap(), - // U256::from_dec_str("19519729727735873999148754136012144616045305047716967685280834855818506563720").unwrap(), - // ], - // vec![ - // vec![ - // U256::from_dec_str("4418606700813566482216037680863387214037640478555893901955308344977554198718").unwrap(), - // U256::from_dec_str("18046767849922558936185002168253454007598159984067380537392936220227127228867").unwrap(), - // ], - // vec![ - // U256::from_dec_str("100725403545603844224319783153051757027683253433977048289134569498829183303").unwrap(), - // U256::from_dec_str("9785321212288652698655727476617710557399711491394256119637648908536562741634").unwrap(), - // ], - // ], - // vec![ - // vec![ - // U256::from_dec_str("1627724482578854283892192357407161928314687375966263116172485631707694669812").unwrap(), - // U256::from_dec_str("6839802000376483025048211234449253336394632788399066904541666906747650234382").unwrap(), - // ], - // vec![ - // U256::from_dec_str("17974577137954059751166162247265070307968439813726452160113109110701162631938").unwrap(), - // U256::from_dec_str("21289972529626386698860098501676961527414208445147370800462053148477683157991").unwrap(), - // ], - // ], - // vec![ - // vec![ - // U256::from_dec_str("7184324332054694882815451883063466258810341506246659357034202660488015984306").unwrap(), - // U256::from_dec_str("14398081398842334723334363407187040569418119441776629783632309768037771007327").unwrap(), - // ], - // vec![ - // U256::from_dec_str("17277213124622419955089087696435667358779233792945822269342368397066818801481").unwrap(), - // U256::from_dec_str("19811781065417531456401229702422997450338397507283920558741452740912313583930").unwrap(), - // ] - // ], - // vec![ - // vec![ - // U256::from_dec_str("20284064245383237908740484779775789109386762825985839657586769414934584661714").unwrap(), - // U256::from_dec_str("17363934481847560975462360104367791101351872886050159351690589725380050257409").unwrap(), - // ], - // vec![ - // U256::from_dec_str("3904403738619431633601997032597659843284744078768864151280168218762434423692").unwrap(), - // U256::from_dec_str("4413868989856264583489102855186788724178233679332360263809134874064797750675").unwrap(), - // ] - // ] - // ); - - // let valid_input = vec![ - // U256::from_dec_str("1275").unwrap(), - // U256::from_dec_str("0").unwrap(), - // U256::from_dec_str("0").unwrap(), - // U256::from_dec_str("0").unwrap(), - // ]; - - // let verifying_key = VerifyingKey::new(proof, vk, valid_input); - - // let zk_verifier = ZKPrecompileVerifier::new( - // H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), - // verifying_key - // ); - - // let encoded_call = zk_verifier.generate_benchmarking_parameters(); - - // let gas_limit_call = 1000000; - // let value = U256::default(); - // let is_transactional = true; - // let validate = true; - // }:{ - // let call_runner_results = ::Runner::call( - // caller, - // contract_address, - // encoded_call, - // value, - // gas_limit_call, - // Some(U256::from(1_000_000_000)), - // Some(U256::from(1_000_000_000)), - // None, - // Vec::new(), - // is_transactional, - // validate, - // ::config(), - // ); - // // log::info!( - // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // // "Benchmarking call end.", - // // ); - // match call_runner_results { - // Ok(info) => { - // let output = info.value; - // // log::info!( - // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // // "output result {:?}", - // // output - // // ); - // if output.len() >= 32 { - // let mut result_bytes = [0u8; 32]; - // result_bytes.copy_from_slice(&output[output.len() - 32..]); - // let result = U256::from_big_endian(&result_bytes); - // // log::info!( - // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // // "Verification result {result:?}", - // // ); - // assert_eq!(result, U256::one(), "The contract did not return true"); - // } - // }, - // Err(e) => { - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "Benchmarking failed", - // ); - // } - // } - // } - - // sum_5000 { - // use frame_benchmarking::vec; - // use sp_core::{H160, U256, H256}; - - // let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); - // let contract_address = H160::from_low_u64_be(0x8888); - - // let proof = Proof::new( - // vec![ - // U256::from_dec_str("2104134032972066019913571175532882184351637942839921828138208604817397790978").unwrap(), - // U256::from_dec_str("12625149522977248086293073767826715132905823679345516244316272790389621024575").unwrap(), - // ], - // vec![ - // vec![ - // U256::from_dec_str("18955718237898317556602416465218566057031982163829528123671300051574728240883").unwrap(), - // U256::from_dec_str("18075306515520608621953959878874546391551215874677138383864573851396832159644").unwrap(), - // ], - // vec![ - // U256::from_dec_str("3166476742865671627115278436666969186969644878053983393309132722947819232105").unwrap(), - // U256::from_dec_str("8051049247607109861344268872842958063551670273736053865524986958976361214062").unwrap(), - // ], - // ], - // vec![ - // U256::from_dec_str("4814291763265323888812051590287571407031542635142019809665068757723218701627").unwrap(), - // U256::from_dec_str("17930948070313125851452005455953009375012074818817251382455220462443054837203").unwrap(), - // ] - // ); - - // let vk = VerifyingKeyComponents::new( - // vec![ - // U256::from_dec_str("19624232987744880202266197753309961915632611879850947888541508003701736644214").unwrap(), - // U256::from_dec_str("5019843555387010050200067558096501184079196549422645876015184268981691000261").unwrap(), - // ], - // vec![ - // vec![ - // U256::from_dec_str("5150307298606577026396875555180704696345763655981810466632357002439129266461").unwrap(), - // U256::from_dec_str("3020656302335648031712857271727816386298675153130933709481311850060508289333").unwrap(), - // ], - // vec![ - // U256::from_dec_str("19547576195358452722114991449875886954598568010341500952076854329553571219720").unwrap(), - // U256::from_dec_str("3895331072082263654317901227968966808293407907751128382134753194859731114729").unwrap(), - // ], - // ], - // vec![ - // vec![ - // U256::from_dec_str("165136411129701665870237237981894748637834826722462614973940945603783242464").unwrap(), - // U256::from_dec_str("10766657827945181878791518932726777890925519579254084496220957371082172349194").unwrap(), - // ], - // vec![ - // U256::from_dec_str("1813485593016293809685571822392302147347136682526622353828238069063634409991").unwrap(), - // U256::from_dec_str("12730118542350484957903782401323352413406115135420607527656226977122246298735").unwrap(), - // ], - // ], - // vec![ - // vec![ - // U256::from_dec_str("5792479463369352075979003547777370241697788651005116088867026457677720533395").unwrap(), - // U256::from_dec_str("16882159064341957118950974052606760693554763076237663579029547802558086431378").unwrap(), - // ], - // vec![ - // U256::from_dec_str("15201299876801474331768851307298179430198466709727112330042020251492139993850").unwrap(), - // U256::from_dec_str("893863620414771464835789333501093176356026692988850717670551586498757709875").unwrap(), - // ] - // ], - // vec![ - // vec![ - // U256::from_dec_str("19450458898299554306247087083239008884256452312356497246598109368644839627523").unwrap(), - // U256::from_dec_str("123992241310851816418828784530061727329258706748227789362318537744292975333").unwrap(), - // ], - // vec![ - // U256::from_dec_str("1650700423026830428199086201346242616543834285406293983963791012821269466913").unwrap(), - // U256::from_dec_str("3152920600939501404817148774751227981988970987313622659392580888754616114976").unwrap(), - // ] - // ] - // ); - - // let valid_input = vec![ - // U256::from_dec_str("12502500").unwrap(), - // U256::from_dec_str("0").unwrap(), - // U256::from_dec_str("0").unwrap(), - // U256::from_dec_str("0").unwrap(), - // ]; - - // let verifying_key = VerifyingKey::new(proof, vk, valid_input); - - // let zk_verifier = ZKPrecompileVerifier::new( - // H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), - // verifying_key - // ); - - // let encoded_call = zk_verifier.generate_benchmarking_parameters(); - - // let gas_limit_call = 1000000; - // let value = U256::default(); - // let is_transactional = true; - // let validate = true; - // }:{ - // let call_runner_results = ::Runner::call( - // caller, - // contract_address, - // encoded_call, - // value, - // gas_limit_call, - // Some(U256::from(1_000_000_000)), - // Some(U256::from(1_000_000_000)), - // None, - // Vec::new(), - // is_transactional, - // validate, - // ::config(), - // ); - // // log::info!( - // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // // "Benchmarking call end.", - // // ); - // match call_runner_results { - // Ok(info) => { - // let output = info.value; - // // log::info!( - // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // // "output result {:?}", - // // output - // // ); - // if output.len() >= 32 { - // let mut result_bytes = [0u8; 32]; - // result_bytes.copy_from_slice(&output[output.len() - 32..]); - // let result = U256::from_big_endian(&result_bytes); - // // log::info!( - // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // // "Verification result {result:?}", - // // ); - // assert_eq!(result, U256::one(), "The contract did not return true"); - // } - // }, - // Err(e) => { - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "Benchmarking failed", - // ); - // } - // } - // } - - sum_50000 { + nconstraints_1000 { use frame_benchmarking::vec; use sp_core::{H160, U256, H256}; @@ -2157,75 +479,221 @@ benchmarks! { let proof = Proof::new( vec![ - U256::from_dec_str("3622731332670597344105510591712672243986951828055076939276801448101954799142").unwrap(), - U256::from_dec_str("6346995225908387053909829054799399014732696227124687083236550584317776767493").unwrap(), + U256::from_dec_str("12451505848309631687252015279596976128225375079184616465869275088833975377438").unwrap(), + U256::from_dec_str("18028472547304696309803026581736164843724278168110632635282700219721294267849").unwrap(), ], vec![ vec![ - U256::from_dec_str("12374003776423645952892988427832420613719996381174255643042478809936185481102").unwrap(), - U256::from_dec_str("19834002842796431843925774571161786816886891256460707223697642395803180051660").unwrap(), + U256::from_dec_str("724941625340075448308940885419778921267046089963198424690563710257350467820").unwrap(), + U256::from_dec_str("19418815036545241911278056687101064762643664412732993043969007894248087117385").unwrap(), ], vec![ - U256::from_dec_str("15842468063355971498862011336838854044444278845667126879720180643365485131394").unwrap(), - U256::from_dec_str("11332976987055222769230958577354523957540694040368499035276674269133591651835").unwrap(), + U256::from_dec_str("13249414494230793056410904135885722890271124096600389432878053498484425858770").unwrap(), + U256::from_dec_str("21762806144353143011028620465453743506764842517668851190776375592288870325215").unwrap(), ], ], vec![ - U256::from_dec_str("18912109791042994221316455125175063781392361813956238026666504224007632366190").unwrap(), - U256::from_dec_str("1279350170906221254449513257961023432324983489115073965271989276735247718491").unwrap(), + U256::from_dec_str("9206867270262791130308246301015463866896172966002943363908694359851632501217").unwrap(), + U256::from_dec_str("13679683495177263967294831832954860495137891909047512983345948806664713075553").unwrap(), ] ); let vk = VerifyingKeyComponents::new( vec![ - U256::from_dec_str("4336612673641723359515805150029160944183167584813833363044992795434703631887").unwrap(), - U256::from_dec_str("9137641056584966180441584227424719192181063342929330231422917545355236845740").unwrap(), + U256::from_dec_str("13896934827344718021853288836918374118104295193491067840322643424358899121542").unwrap(), + U256::from_dec_str("8854052944916041632001392967979629780372345382861670282089777314383817716115").unwrap(), + ], + vec![ + vec![ + U256::from_dec_str("3601177773308419037453361001975316835601350296485805323140167568598797930642").unwrap(), + U256::from_dec_str("48851914275316782871445347689531673984580545598074561513165366823294923594").unwrap(), + ], + vec![ + U256::from_dec_str("4538012201084519544875007504928553564968897773565284770715803834936680149613").unwrap(), + U256::from_dec_str("3155968616270588886660033728776257587454508333510911411658919790925259116614").unwrap(), + ], ], vec![ vec![ - U256::from_dec_str("3730256152430451126522590663651372021566043227051775605895559420879019685920").unwrap(), - U256::from_dec_str("20728862641139597395451147113430954379546155357229963990677814892281218309701").unwrap(), + U256::from_dec_str("6521538659624675039700866061977650833785775087701556120926232218187885377774").unwrap(), + U256::from_dec_str("18707623749213430453109215145186606994638201653518117177006249287165414157706").unwrap(), ], vec![ - U256::from_dec_str("7502099261339400768454017924955286264806514986185112220563862169144222322249").unwrap(), - U256::from_dec_str("5006842384329558490484345088692295975571937103770535130257247983097172628130").unwrap(), + U256::from_dec_str("11743109857123024729794370527373948778820323338754388805090881243904381703330").unwrap(), + U256::from_dec_str("3577725017182890090279110701721773090147301853148322630192233820247926772155").unwrap(), + ], + ], + vec![ + vec![ + U256::from_dec_str("10697077492206594361644026971284249101590705030465491131467731100150008255694").unwrap(), + U256::from_dec_str("1114380532795466865933623446272212800793315337032855536172932313989250445726").unwrap(), ], + vec![ + U256::from_dec_str("11747915450686416011932172170367549011245903715607283230565719536126230133873").unwrap(), + U256::from_dec_str("1877153534214274703747923906347594924169181268669702005894131954432202950068").unwrap(), + ] ], vec![ vec![ - U256::from_dec_str("10823916364920299474063731894264827730751008163382814050357751676256530518677").unwrap(), - U256::from_dec_str("2964232036989531397729723217960695207528224009959841295885668746926591289356").unwrap(), + U256::from_dec_str("6294921440683861296812943370338888809368101163511446375226378176013676840633").unwrap(), + U256::from_dec_str("8766686502883018606879699065134987161183815270662618961653335871316040755302").unwrap(), ], vec![ - U256::from_dec_str("17121950139992519518807185063471627099057806698144667325262783943067486697035").unwrap(), - U256::from_dec_str("20705259140101372627184216142337506779584441204290869224541344200465485566171").unwrap(), + U256::from_dec_str("15422085976834841481597157129530660038025986735930069198619117556493669017719").unwrap(), + U256::from_dec_str("6824904336141021449652133306590775160232847673735850151493603664420102965477").unwrap(), ] + ] + ); + + let valid_input: Vec = vec![u64s_to_u256(vec![ + 5637188163546619750, + 4876642863872575056, + 11311886144936918135, + 2620236256196171805 + ])]; + + let verifying_key = VerifyingKey::new(proof, vk, valid_input); + + let zk_verifier = ZKPrecompileVerifier::new( + H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), + verifying_key + ); + + let encoded_call = zk_verifier.generate_benchmarking_parameters(); + + let gas_limit_call = 1000000; + let value = U256::default(); + let is_transactional = true; + let validate = true; + }:{ + let call_runner_results = ::Runner::call( + caller, + contract_address, + encoded_call, + value, + gas_limit_call, + Some(U256::from(1_000_000_000)), + Some(U256::from(1_000_000_000)), + None, + Vec::new(), + is_transactional, + validate, + ::config(), + ); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "Benchmarking call end.", + // ); + match call_runner_results { + Ok(info) => { + let output = info.value; + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "output result {:?}", + // output + // ); + if output.len() >= 32 { + let mut result_bytes = [0u8; 32]; + result_bytes.copy_from_slice(&output[output.len() - 32..]); + let result = U256::from_big_endian(&result_bytes); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "nconstraints_1000 Verification result {result:?}", + // ); + assert_eq!(result, U256::one(), "The contract did not return true"); + } + }, + Err(e) => { + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "nconstraints_1000 Benchmarking failed", + ); + assert!(false, "Benchmarking failed"); + + } + } + } + nconstraints_900000 { + use frame_benchmarking::vec; + use sp_core::{H160, U256, H256}; + + let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + let contract_address = H160::from_low_u64_be(0x8888); + + let proof = Proof::new( + vec![ + U256::from_dec_str("19469224081137364911375441935428613758543844094780123177610680784796374565509").unwrap(), + U256::from_dec_str("2964109100176825277964902990593130655404587548088911907169158668561756482373").unwrap(), + ], + vec![ + vec![ + U256::from_dec_str("1804788596044451078391485097362341934563024367189115611320140606169017734442").unwrap(), + U256::from_dec_str("13075356869764013404490647878715830765050556805353047586243641659166972614506").unwrap(), + ], + vec![ + U256::from_dec_str("11510752280195741101381678478126680255679095252133774347633523263393718090827").unwrap(), + U256::from_dec_str("19917734624109913540474402939707087760514256808495299709893660593520804971329").unwrap(), + ], + ], + vec![ + U256::from_dec_str("17650234014776935476405426867265189573543251264844619398004397025922351000524").unwrap(), + U256::from_dec_str("13980409623437481166079302794215538337078177634480935418093274323345259996058").unwrap(), + ] + ); + + let vk = VerifyingKeyComponents::new( + vec![ + U256::from_dec_str("7204013913559348808806179272679133668079798990573619252699122941477292720367").unwrap(), + U256::from_dec_str("14448814309541293146746525253301533902449817953703436076734477345366335651547").unwrap(), + ], + vec![ + vec![ + U256::from_dec_str("12755354931522455226769415963087662012592248962914015697167303994293035888664").unwrap(), + U256::from_dec_str("19979994508677160041392994419804596139216500302977150541381981675855322022114").unwrap(), + ], + vec![ + U256::from_dec_str("3518578052095992035034011768990132253597152650327354182069223777691356587613").unwrap(), + U256::from_dec_str("1512363495951297845516866605291301480678745477544041997800458458709067854003").unwrap(), + ], ], vec![ vec![ - U256::from_dec_str("4609739673127175843417224333269860670973152461609019180497630782244542871322").unwrap(), - U256::from_dec_str("5981417778986924179768792717543475972483606473185751180808540751057035223819").unwrap(), + U256::from_dec_str("21483901865224554977407186643009006049964266844355020377697169106001216486465").unwrap(), + U256::from_dec_str("18122216236568402305988297032517775914181563813086813006164216689752246508886").unwrap(), + ], + vec![ + U256::from_dec_str("7100124544075226034251596932805277307734457677256004047412258693103409543678").unwrap(), + U256::from_dec_str("9484826513489508497326605298995346628011303684771342589708630141744196880174").unwrap(), ], + ], + vec![ vec![ - U256::from_dec_str("20792630753101735929108699805283402009145413137839446488160591610595405740916").unwrap(), - U256::from_dec_str("12712973769233860870993411006074441942320673677464961930321479085937150536543").unwrap(), + U256::from_dec_str("4294809674390523555755416088340227038268056188806697061914357207030835445784").unwrap(), + U256::from_dec_str("12772882987652274474928251216882135157601158713560023135442912416889883375009").unwrap(), ], + vec![ + U256::from_dec_str("5017814360156811257431228283078380210712481496173867244303167538680301406355").unwrap(), + U256::from_dec_str("5483986251263351055676143301589669624262947345327185314870128974364440001262").unwrap(), + ] ], vec![ vec![ - U256::from_dec_str("2422043721758703885072327542268388166893061296643655177987760545832562233524").unwrap(), - U256::from_dec_str("2939428867547955771917605064560167662212054903067344050223483963838535670368").unwrap(), + U256::from_dec_str("10485365056956235833573091505977794158366069646492853613385564319176805042067").unwrap(), + U256::from_dec_str("21560988819791135038184934219494970236802908435926324068683299817562907341696").unwrap(), ], vec![ - U256::from_dec_str("9800364647151674719834337323206936270428884273217284206736997065787811631092").unwrap(), - U256::from_dec_str("1425891826916485854275507234274197381767987210474487566305467407052485766733").unwrap(), + U256::from_dec_str("9274251274730510866039258353232655161206943117093211738883330925803202790098").unwrap(), + U256::from_dec_str("19994917632455570632082635510110118222993755636207706143729050502915579896735").unwrap(), ] ] ); - let valid_input = vec![ - U256::from_dec_str("1250025000").unwrap() - ]; + let valid_input: Vec = vec![u64s_to_u256(vec![ + 10518156496175725870, + 8513656267880232886, + 1469451646407182009, + 3425508166019525724 + ])]; let verifying_key = VerifyingKey::new(proof, vk, valid_input); @@ -2262,27 +730,1583 @@ benchmarks! { match call_runner_results { Ok(info) => { let output = info.value; + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "output result {:?}", + // output + // ); + if output.len() >= 32 { + let mut result_bytes = [0u8; 32]; + result_bytes.copy_from_slice(&output[output.len() - 32..]); + let result = U256::from_big_endian(&result_bytes); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "nconstraints_900000 Verification result {result:?}", + // ); + assert_eq!(result, U256::one(), "The contract did not return true"); + } + }, + Err(e) => { log::info!( target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - "output result {:?}", - output + "nconstraints_900000 Benchmarking failed", ); + assert!(false, "Benchmarking failed"); + + } + } + } + + nconstraints_30_input_10 { + use frame_benchmarking::vec; + use sp_core::{H160, U256, H256}; + + let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + let contract_address = H160::from_low_u64_be(0x8888); + + let proof = Proof::new( + vec![ + U256::from_dec_str("344113499780097036133410144688544669449665038469801025061703634064197059916").unwrap(), + U256::from_dec_str("8339013355837829034186604529242237434382457535922383671882155606562413431689").unwrap(), + ], + vec![ + vec![ + U256::from_dec_str("6694199005832176626648387473003377778002164049654344388623160500074797775370").unwrap(), + U256::from_dec_str("6246558478856965861562784864034844546822126660127014237507763330640717221466").unwrap(), + ], + vec![ + U256::from_dec_str("456859418727494804887897697519797382313397623366843307513728588676215628797").unwrap(), + U256::from_dec_str("19972929684979882956825623277042855987039264105600158828132263230333203670106").unwrap(), + ], + ], + vec![ + U256::from_dec_str("8991876521515422964548874095107781976525191569601242691722207742733698821028").unwrap(), + U256::from_dec_str("17304897036279645989594099459944208131107988079437513579584585106093260802053").unwrap(), + ] + ); + + let vk = VerifyingKeyComponents::new( + vec![ + U256::from_dec_str("16587578668155053320776501244706909164198053583863284386206654068019392556543").unwrap(), + U256::from_dec_str("17489859882312386925030082840618136961844042944104008122175974338708995824981").unwrap(), + ], + vec![ + vec![ + U256::from_dec_str("8243058085082563940310351321464397410632520885003827137093771369586433446018").unwrap(), + U256::from_dec_str("1806964369040712598415691188975966807767394918682209427183228092832571919497").unwrap(), + ], + vec![ + U256::from_dec_str("5238575049648595236335310308987023404502439315997088611926714272919127054029").unwrap(), + U256::from_dec_str("10529242360048105445622302340100671863366518517961350431989359465371013288044").unwrap(), + ], + ], + vec![ + vec![ + U256::from_dec_str("422118731661843716781379598081446048950684758761078928178953272944418614265").unwrap(), + U256::from_dec_str("8071137901873450516865398890359069534977349842235015782367912081100468370342").unwrap(), + ], + vec![ + U256::from_dec_str("6616051543776580097026224309598118359974125974677691608309070965923230091481").unwrap(), + U256::from_dec_str("3144026861846828201735234261898216197057552604232403108299101704912138104081").unwrap(), + ], + ], + vec![ + vec![ + U256::from_dec_str("15967728838725285670062386536689775286816477877862913251436519988213464788203").unwrap(), + U256::from_dec_str("14482652023948193853731701210376245407114581664800773915003137369238699817066").unwrap(), + ], + vec![ + U256::from_dec_str("20222564526826997580988353930405539667760709452060576182511364617433825375503").unwrap(), + U256::from_dec_str("1855904408322765948314758770516591135802311025429227172106073057339165107921").unwrap(), + ] + ], + vec![ + vec![ + U256::from_dec_str("2234398803815490360326379119253073021265347911436036657996997085101774002925").unwrap(), + U256::from_dec_str("10214773739303944856355679056757071889148916152665035343340628435407174724717").unwrap(), + ], + vec![ + U256::from_dec_str("21500623561133929663133180424780657403302270303706782392356903439186747104812").unwrap(), + U256::from_dec_str("19328419280811286038333929820672543691407985372391054082759992875889788951230").unwrap(), + ] + ] + ); + + let valid_input: Vec = vec![u64s_to_u256(vec![ + 14321691860995553260, + 7152862679273281751, + 12752615512303817990, + 1576113262537949146 + ])]; + + let verifying_key = VerifyingKey::new(proof, vk, valid_input); + + let zk_verifier = ZKPrecompileVerifier::new( + H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), + verifying_key + ); + + let encoded_call = zk_verifier.generate_benchmarking_parameters(); + + let gas_limit_call = 1000000; + let value = U256::default(); + let is_transactional = true; + let validate = true; + }:{ + let call_runner_results = ::Runner::call( + caller, + contract_address, + encoded_call, + value, + gas_limit_call, + Some(U256::from(1_000_000_000)), + Some(U256::from(1_000_000_000)), + None, + Vec::new(), + is_transactional, + validate, + ::config(), + ); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "Benchmarking call end.", + // ); + match call_runner_results { + Ok(info) => { + let output = info.value; + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "output result {:?}", + // output + // ); + if output.len() >= 32 { + let mut result_bytes = [0u8; 32]; + result_bytes.copy_from_slice(&output[output.len() - 32..]); + let result = U256::from_big_endian(&result_bytes); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "nconstraints_30_input_10 Verification result {result:?}", + // ); + assert_eq!(result, U256::one(), "The contract did not return true"); + } + }, + Err(e) => { + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "nconstraints_30_input_10 Benchmarking failed", + ); + assert!(false, "Benchmarking failed"); + + } + } + } + nconstraints_30_input_100 { + use frame_benchmarking::vec; + use sp_core::{H160, U256, H256}; + + let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + let contract_address = H160::from_low_u64_be(0x8888); + + let proof = Proof::new( + vec![ + U256::from_dec_str("3780487311936056381294564418675304364481973966802209296561160829797948105411").unwrap(), + U256::from_dec_str("12392254879980640223142009257910424254771509444451393927739643876401726307795").unwrap(), + ], + vec![ + vec![ + U256::from_dec_str("5169548117445173154024813698359426977000013771483410622256640533171985245380").unwrap(), + U256::from_dec_str("11220449603083268927036844276912830985523128428499468942581840512730495047625").unwrap(), + ], + vec![ + U256::from_dec_str("7617888807668014594076695037395251387521432502213194545531858961238344338860").unwrap(), + U256::from_dec_str("3206448605631210983027663221710912427383659852717855953276353488187250079459").unwrap(), + ], + ], + vec![ + U256::from_dec_str("17260938596020642923034443094579912726381749511890996943502017876149586484217").unwrap(), + U256::from_dec_str("973711408795313031099855712156150142641887502706075552254275664528776194028").unwrap(), + ] + ); + + let vk = VerifyingKeyComponents::new( + vec![ + U256::from_dec_str("4155898266631322214574856388057229131381603659142355428000239527171539910720").unwrap(), + U256::from_dec_str("15919304600573806746067202721026223664629992455130946331020176989460510062648").unwrap(), + ], + vec![ + vec![ + U256::from_dec_str("10559477888637541108523299513483158185288656601390229631277602982302056830264").unwrap(), + U256::from_dec_str("21518216923189214839507247102243744126930049565774641401859791113452178471842").unwrap(), + ], + vec![ + U256::from_dec_str("20524972206762616004058259260290957844870248494446046806278424843369643489182").unwrap(), + U256::from_dec_str("17430943082223119961631960086233630485654941075995072846024219998674392652581").unwrap(), + ], + ], + vec![ + vec![ + U256::from_dec_str("4636362103930283526843587215716464395878300635435610009766312980459671398351").unwrap(), + U256::from_dec_str("15713999866924132629927290621261290205960872899800820372400263081232019214301").unwrap(), + ], + vec![ + U256::from_dec_str("274224283373606674211197218239218941312046485596075799302472837928822177016").unwrap(), + U256::from_dec_str("10693491445395060496723678108216498586881120243971297703830999940561952271629").unwrap(), + ], + ], + vec![ + vec![ + U256::from_dec_str("9540601502504552621404908678855872975596983734893914263055690675850649191273").unwrap(), + U256::from_dec_str("10288168694112392204164781631687615725045294841966564539511156565183262528849").unwrap(), + ], + vec![ + U256::from_dec_str("16504160099082952601826232467479510151840980336862791499394346450083636791102").unwrap(), + U256::from_dec_str("9210167978306154509907086298616199856898787966613435045760659519455958969992").unwrap(), + ] + ], + vec![ + vec![ + U256::from_dec_str("15812098394101742886061540987450559986219804469912805896076341688421241661621").unwrap(), + U256::from_dec_str("11920211969663783445335622417572072568292106489672989284415235777753260953099").unwrap(), + ], + vec![ + U256::from_dec_str("7061409000327933635430701054193661775345794014516696263402966093123651666364").unwrap(), + U256::from_dec_str("17078047162776906089011285464212202278306676406084693061907121919624683442357").unwrap(), + ] + ] + ); + + let valid_input: Vec = vec![u64s_to_u256(vec![ + 9831528597301135316, + 11053911270256492840, + 14337707091878126846, + 772611368070892958 + ])]; + + let verifying_key = VerifyingKey::new(proof, vk, valid_input); + + let zk_verifier = ZKPrecompileVerifier::new( + H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), + verifying_key + ); + + let encoded_call = zk_verifier.generate_benchmarking_parameters(); + + let gas_limit_call = 1000000; + let value = U256::default(); + let is_transactional = true; + let validate = true; + }:{ + let call_runner_results = ::Runner::call( + caller, + contract_address, + encoded_call, + value, + gas_limit_call, + Some(U256::from(1_000_000_000)), + Some(U256::from(1_000_000_000)), + None, + Vec::new(), + is_transactional, + validate, + ::config(), + ); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "Benchmarking call end.", + // ); + match call_runner_results { + Ok(info) => { + let output = info.value; + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "output result {:?}", + // output + // ); + if output.len() >= 32 { + let mut result_bytes = [0u8; 32]; + result_bytes.copy_from_slice(&output[output.len() - 32..]); + let result = U256::from_big_endian(&result_bytes); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "nconstraints_30_input_100 Verification result {result:?}", + // ); + assert_eq!(result, U256::one(), "The contract did not return true"); + } + }, + Err(e) => { + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "nconstraints_30_input_100 Benchmarking failed", + ); + assert!(false, "Benchmarking failed"); + } + } + } + nconstraints_30_input_1000 { + use frame_benchmarking::vec; + use sp_core::{H160, U256, H256}; + + let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + let contract_address = H160::from_low_u64_be(0x8888); + + let proof = Proof::new( + vec![ + U256::from_dec_str("21424271595387505713049534900676381136649432939050012296331964885140120988520").unwrap(), + U256::from_dec_str("20488789316104689748479888121024139144355086386496471461763924485714534718686").unwrap(), + ], + vec![ + vec![ + U256::from_dec_str("8417699613540073682519718294821269056423071880647667978060348740795273915651").unwrap(), + U256::from_dec_str("4036859279888161250878359321718658739242283134835030699023268489309754993434").unwrap(), + ], + vec![ + U256::from_dec_str("16249800568747110450527363597274431407786919086057853194987169090454936230259").unwrap(), + U256::from_dec_str("15005851458712291005106538565823270955208428726378749297397203143137382225457").unwrap(), + ], + ], + vec![ + U256::from_dec_str("21239990703864671714190525785674088715931473556140655107585637961585812134589").unwrap(), + U256::from_dec_str("261928180985765917331919571442880380998408670702589931014636966043229919418").unwrap(), + ] + ); + + let vk = VerifyingKeyComponents::new( + vec![ + U256::from_dec_str("1657406292532781196449359079614579852690925607592278296574718289470803732053").unwrap(), + U256::from_dec_str("18213557747942747074556848145237207574111244905157024361329330629173034829885").unwrap(), + ], + vec![ + vec![ + U256::from_dec_str("5419856735820685908218319193906907396496344921642651266629131019868853843815").unwrap(), + U256::from_dec_str("14007905369450574044915098075029863272475910046750101274280969769181784166430").unwrap(), + ], + vec![ + U256::from_dec_str("182200131698860550444455761364918630551676350878779858078817264277300629723").unwrap(), + U256::from_dec_str("6050431818377820601319883600432739448105157482353041283628740094609821419656").unwrap(), + ], + ], + vec![ + vec![ + U256::from_dec_str("14463567879100083166257564330995533094334991709675023767975192973144798919122").unwrap(), + U256::from_dec_str("6166287541473141918830331239835928582190744434356526822227225877844349692203").unwrap(), + ], + vec![ + U256::from_dec_str("12512843744533735346513506961399336936527367720771340395643503621530703342395").unwrap(), + U256::from_dec_str("8394818975982736201521422268641084055810886358791398607930311472872317386487").unwrap(), + ], + ], + vec![ + vec![ + U256::from_dec_str("8757732756289429354419510422628896433407345473998310348115924113882282945326").unwrap(), + U256::from_dec_str("1610185885725147927651201796201713521257480620743342969197368887869230657180").unwrap(), + ], + vec![ + U256::from_dec_str("2834338214415807920713929739507915327763263469562351781747229949754640383374").unwrap(), + U256::from_dec_str("20761263923134391843554423575366232120525285729512411038267095810712916924016").unwrap(), + ] + ], + vec![ + vec![ + U256::from_dec_str("16585432354609922217222548226453277630464695131710476183479619760311567992522").unwrap(), + U256::from_dec_str("5379258900528839934525784961038010961454863754298062530193947624450477797122").unwrap(), + ], + vec![ + U256::from_dec_str("16825349369326282879106301528709807467071985531593215317852699692046311881677").unwrap(), + U256::from_dec_str("10540450379202726868409867306854114915477889581096312866635875249145708179576").unwrap(), + ] + ] + ); + + let valid_input: Vec = vec![u64s_to_u256(vec![ + 3008789406746563016, + 7061370202899273426, + 2191755323004339933, + 1005591455220622530 + ])]; + + let verifying_key = VerifyingKey::new(proof, vk, valid_input); + + let zk_verifier = ZKPrecompileVerifier::new( + H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), + verifying_key + ); + + let encoded_call = zk_verifier.generate_benchmarking_parameters(); + + let gas_limit_call = 1000000; + let value = U256::default(); + let is_transactional = true; + let validate = true; + }:{ + let call_runner_results = ::Runner::call( + caller, + contract_address, + encoded_call, + value, + gas_limit_call, + Some(U256::from(1_000_000_000)), + Some(U256::from(1_000_000_000)), + None, + Vec::new(), + is_transactional, + validate, + ::config(), + ); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "Benchmarking call end.", + // ); + match call_runner_results { + Ok(info) => { + let output = info.value; + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "output result {:?}", + // output + // ); + if output.len() >= 32 { + let mut result_bytes = [0u8; 32]; + result_bytes.copy_from_slice(&output[output.len() - 32..]); + let result = U256::from_big_endian(&result_bytes); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "nconstraints_30_input_1000 Verification result {result:?}", + // ); + assert_eq!(result, U256::one(), "The contract did not return true"); + } + }, + Err(e) => { + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "nconstraints_30_input_1000 Benchmarking failed", + ); + assert!(false, "Benchmarking failed"); + } + } + } + nconstraints_30_input_5000 { + use frame_benchmarking::vec; + use sp_core::{H160, U256, H256}; + + let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + let contract_address = H160::from_low_u64_be(0x8888); + + let proof = Proof::new( + vec![ + U256::from_dec_str("4760178114933307527976205229418881302833473087272893863010681924222436742436").unwrap(), + U256::from_dec_str("6555056836023646163359279772724076765411780318148657506988760187885700674215").unwrap(), + ], + vec![ + vec![ + U256::from_dec_str("9540205596737585525189386078607957630969059503165883907845238817662495399607").unwrap(), + U256::from_dec_str("21777913747079267536001051597001736802905779914683258171463923506869689358122").unwrap(), + ], + vec![ + U256::from_dec_str("7652162643714058076103867092157642519402862581818067281609790687905833151647").unwrap(), + U256::from_dec_str("5174136241284192352871549806655421810249317805219641765935618077180420544939").unwrap(), + ], + ], + vec![ + U256::from_dec_str("9633653417112713107386510132385608824105920168790226750481878454006412372444").unwrap(), + U256::from_dec_str("5600932933208824148570351176368803282808856587672889614186338874655752173453").unwrap(), + ] + ); + + let vk = VerifyingKeyComponents::new( + vec![ + U256::from_dec_str("20563201722283471489193032980811350162387466733119686723832100493505332037220").unwrap(), + U256::from_dec_str("458683337854426284881131074995322438618437423037306322290239745015633774839").unwrap(), + ], + vec![ + vec![ + U256::from_dec_str("802687519037697530569139206036966996588449135138601551566343295868421688400").unwrap(), + U256::from_dec_str("10902489968444563758310974921240106861656913905085710523025258522577834664814").unwrap(), + ], + vec![ + U256::from_dec_str("8163282908300075270434111132545381898266738500810094061899946027883982232155").unwrap(), + U256::from_dec_str("2879234862354419255322548813414679750617024208122660306082351289172177493856").unwrap(), + ], + ], + vec![ + vec![ + U256::from_dec_str("12946416399098615767859440028401625777970463338055590127763655113029764523456").unwrap(), + U256::from_dec_str("19000556224902286061769815260124368973839417953399533885850283592096662743016").unwrap(), + ], + vec![ + U256::from_dec_str("16883066945921282046110808795753929362007100542422795769422243319629113077450").unwrap(), + U256::from_dec_str("3229017908221308993692674040951942449106283130433174678816420254626513367678").unwrap(), + ], + ], + vec![ + vec![ + U256::from_dec_str("16459854676924169388774046538295013154707390397685062918225181412137603478923").unwrap(), + U256::from_dec_str("20996869365345436816737319903210535785982053153529758285286719146777762981985").unwrap(), + ], + vec![ + U256::from_dec_str("21446959969822179574296836241978980045198577120638747119902976563053247153220").unwrap(), + U256::from_dec_str("4716297282146551186330252875195511360280503254452482577157100992033023717484").unwrap(), + ] + ], + vec![ + vec![ + U256::from_dec_str("2127664998061023131080125201643658604092063304061707222326237054428506173927").unwrap(), + U256::from_dec_str("13918137729545385379467184110597023571257121066683873930760549927318081992996").unwrap(), + ], + vec![ + U256::from_dec_str("16560640526003408304721205785917894782070253870764339317137905014294472374327").unwrap(), + U256::from_dec_str("19394535992291030838186763750684977819230291410826312937425829210188321257228").unwrap(), + ] + ] + ); + + let valid_input: Vec = vec![u64s_to_u256(vec![ + 13212982172557049181, + 17043673098390055166, + 13971391527459105160, + 1729491887349651790, + ])]; + + let verifying_key = VerifyingKey::new(proof, vk, valid_input); + + let zk_verifier = ZKPrecompileVerifier::new( + H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), + verifying_key + ); + + let encoded_call = zk_verifier.generate_benchmarking_parameters(); + + let gas_limit_call = 1000000; + let value = U256::default(); + let is_transactional = true; + let validate = true; + }:{ + let call_runner_results = ::Runner::call( + caller, + contract_address, + encoded_call, + value, + gas_limit_call, + Some(U256::from(1_000_000_000)), + Some(U256::from(1_000_000_000)), + None, + Vec::new(), + is_transactional, + validate, + ::config(), + ); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "Benchmarking call end.", + // ); + match call_runner_results { + Ok(info) => { + let output = info.value; + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "output result {:?}", + // output + // ); + if output.len() >= 32 { + let mut result_bytes = [0u8; 32]; + result_bytes.copy_from_slice(&output[output.len() - 32..]); + let result = U256::from_big_endian(&result_bytes); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "nconstraints_30_input_5000 Verification result {result:?}", + // ); + assert_eq!(result, U256::one(), "The contract did not return true"); + } + }, + Err(e) => { + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "nconstraints_30_input_5000 Benchmarking failed", + ); + assert!(false, "Benchmarking failed"); + } + } + } + nconstraints_30_input_10000 { + use frame_benchmarking::vec; + use sp_core::{H160, U256, H256}; + + let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + let contract_address = H160::from_low_u64_be(0x8888); + + let proof = Proof::new( + vec![ + U256::from_dec_str("20201588552006483041582128307591335561381558661958982754827324334159524114833").unwrap(), + U256::from_dec_str("17768889616334897699714190449991059857597665579001510168911964966707846254013").unwrap(), + ], + vec![ + vec![ + U256::from_dec_str("831427914683469755258685737297441858923030844026909228595596228891513784401").unwrap(), + U256::from_dec_str("17358733390631981546461856303504163975689822422160671163593908204299387350560").unwrap(), + ], + vec![ + U256::from_dec_str("12673178383954759426828314411760863182427996098705680584931403917390222262168").unwrap(), + U256::from_dec_str("12056092533572380482681874959737292916971452073896642753405050795241584080793").unwrap(), + ], + ], + vec![ + U256::from_dec_str("11086630979744216291689656728938462056245402184490217943698398792953833540899").unwrap(), + U256::from_dec_str("6981043472993913602669753829495794560155248771335035866541870305230603679484").unwrap(), + ] + ); + + let vk = VerifyingKeyComponents::new( + vec![ + U256::from_dec_str("10088605449330278081588905225706913827985798761474642054412607299987851491561").unwrap(), + U256::from_dec_str("12349112716571349951448807635426375878752472531266562453302627732729311140226").unwrap(), + ], + vec![ + vec![ + U256::from_dec_str("11234930657858483584603353214391341220392609835907149947974795594440445721655").unwrap(), + U256::from_dec_str("1047093079337214465686469751128183347143657884406521365857439579470759333731").unwrap(), + ], + vec![ + U256::from_dec_str("15864899975231343872664645828141071246029692141564279838230890638453916423742").unwrap(), + U256::from_dec_str("12053277475368564348616897081746431255423835262329161057768339971384736640081").unwrap(), + ], + ], + vec![ + vec![ + U256::from_dec_str("20662189442791195318296211376162761628558291902545582141646463139520777475283").unwrap(), + U256::from_dec_str("9279465006661849499753241364514057268552316193158700659184124742215268752791").unwrap(), + ], + vec![ + U256::from_dec_str("17033606864312833588672465768726096906720807717470346504048425104291392352898").unwrap(), + U256::from_dec_str("15319242533246792039334613039385600689133248724151496600840914674340560979641").unwrap(), + ], + ], + vec![ + vec![ + U256::from_dec_str("3303817333656562581428241644233610206796391323593261940899405821542387319372").unwrap(), + U256::from_dec_str("12434486975702473910116656089923156849733601159782506519440013280731025013736").unwrap(), + ], + vec![ + U256::from_dec_str("9561232329300105849651786447909752108987569955850131116304832039966768267007").unwrap(), + U256::from_dec_str("18486557213071145739422364713271115450952939790314495487369777335095317193174").unwrap(), + ] + ], + vec![ + vec![ + U256::from_dec_str("5864321703423906069527768678401445332135246771872328360194332677453860634867").unwrap(), + U256::from_dec_str("3305620141441221125469209629518919979790470359050105194093502369856652644459").unwrap(), + ], + vec![ + U256::from_dec_str("1810088252629429255118238329671475280643793553294287131634484491846973310510").unwrap(), + U256::from_dec_str("20707970746663158481851347112547705553728126185220754421254503093218351233120").unwrap(), + ] + ] + ); + + let valid_input: Vec = vec![u64s_to_u256(vec![ + 11033755416221607095, + 14172640425079373737, + 17268699570210893519, + 2451003838444787962, + ])]; + + let verifying_key = VerifyingKey::new(proof, vk, valid_input); + + let zk_verifier = ZKPrecompileVerifier::new( + H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), + verifying_key + ); + + let encoded_call = zk_verifier.generate_benchmarking_parameters(); + + let gas_limit_call = 1000000; + let value = U256::default(); + let is_transactional = true; + let validate = true; + }:{ + let call_runner_results = ::Runner::call( + caller, + contract_address, + encoded_call, + value, + gas_limit_call, + Some(U256::from(1_000_000_000)), + Some(U256::from(1_000_000_000)), + None, + Vec::new(), + is_transactional, + validate, + ::config(), + ); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "Benchmarking call end.", + // ); + match call_runner_results { + Ok(info) => { + let output = info.value; + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "output result {:?}", + // output + // ); + if output.len() >= 32 { + let mut result_bytes = [0u8; 32]; + result_bytes.copy_from_slice(&output[output.len() - 32..]); + let result = U256::from_big_endian(&result_bytes); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "nconstraints_30_input_10000 Verification result {result:?}", + // ); + assert_eq!(result, U256::one(), "The contract did not return true"); + } + }, + Err(e) => { + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "nconstraints_30_input_10000 Benchmarking failed", + ); + assert!(false, "Benchmarking failed"); + + } + } + } + nconstraints_30_input_90000 { + use frame_benchmarking::vec; + use sp_core::{H160, U256, H256}; + + let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + let contract_address = H160::from_low_u64_be(0x8888); + + let proof = Proof::new( + vec![ + U256::from_dec_str("7949275001087845673352113652992317737416671749823042856819742064958185730665").unwrap(), + U256::from_dec_str("5891863541401068443747112095836743353338477825995666306081231182884954636005").unwrap(), + ], + vec![ + vec![ + U256::from_dec_str("12960565378826264234747222392568347150301360486418725511109506548813034322775").unwrap(), + U256::from_dec_str("6924824876048701587380679111548259437770370772320848338373383587483809707515").unwrap(), + ], + vec![ + U256::from_dec_str("21689747160304810742710652756166876177223750769696622871469266436845305438116").unwrap(), + U256::from_dec_str("14167066926549192557125941689316913820167617731059401320567819691908586156039").unwrap(), + ], + ], + vec![ + U256::from_dec_str("19186797317064887099470636752510606772753033946198593325337771098325482447274").unwrap(), + U256::from_dec_str("3350186543680262034371474397706130211690310055235028696466009478959025709845").unwrap(), + ] + ); + + let vk = VerifyingKeyComponents::new( + vec![ + U256::from_dec_str("6828794497030502754628523747507406719479438181845328406281207577196379759609").unwrap(), + U256::from_dec_str("5561027388439947090438746111225212164455366280326670821700904471009784329896").unwrap(), + ], + vec![ + vec![ + U256::from_dec_str("1648517694167305339737563900225685665396551354808983529387892872646841040850").unwrap(), + U256::from_dec_str("15406833006990307743521713564090315343374212223020060642984366610793788667116").unwrap(), + ], + vec![ + U256::from_dec_str("14591594646846027404699868040454897990147675572067174007423843530180728597612").unwrap(), + U256::from_dec_str("2940958434778941597191243007999700895445672570190450648227198352981565653913").unwrap(), + ], + ], + vec![ + vec![ + U256::from_dec_str("7676142418543194845482248509044991512324196983308812731866772308356979871307").unwrap(), + U256::from_dec_str("21511013842679919895947796523736214038726875927496967606596253311081756690725").unwrap(), + ], + vec![ + U256::from_dec_str("4652378032872178978450279958290699982888059033676566152376150880744787185780").unwrap(), + U256::from_dec_str("467504210088082002071026778234767679654059202832780062786965483300786044530").unwrap(), + ], + ], + vec![ + vec![ + U256::from_dec_str("20744282071154891204049714936088748576694067059171789505913191933597423689555").unwrap(), + U256::from_dec_str("12596866572762256583276410876169296807308160857887657727882625055041251553242").unwrap(), + ], + vec![ + U256::from_dec_str("3588798969790877834321031026222278845206273301850566393834657489341158616535").unwrap(), + U256::from_dec_str("19268326464935908053037454129640878232926568425004490855381855273084219557079").unwrap(), + ] + ], + vec![ + vec![ + U256::from_dec_str("10928515506460596401961934744263657631726985113185854450754018401146226707446").unwrap(), + U256::from_dec_str("1043421123157233618994554398894819122012315878788274412803269234825060696656").unwrap(), + ], + vec![ + U256::from_dec_str("21802758012415709270812560952687831790545411568500639317690833457802568775035").unwrap(), + U256::from_dec_str("8926874931677263335476856545765471099163606107894025045476086328360781102193").unwrap(), + ] + ] + ); + + let valid_input: Vec = vec![u64s_to_u256(vec![ + 2553457387449696641, + 815105491620421980, + 17800546104409657428, + 2866567216183504159, + ])]; + + let verifying_key = VerifyingKey::new(proof, vk, valid_input); + + let zk_verifier = ZKPrecompileVerifier::new( + H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), + verifying_key + ); + + let encoded_call = zk_verifier.generate_benchmarking_parameters(); + + let gas_limit_call = 1000000; + let value = U256::default(); + let is_transactional = true; + let validate = true; + }:{ + let call_runner_results = ::Runner::call( + caller, + contract_address, + encoded_call, + value, + gas_limit_call, + Some(U256::from(1_000_000_000)), + Some(U256::from(1_000_000_000)), + None, + Vec::new(), + is_transactional, + validate, + ::config(), + ); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "Benchmarking call end.", + // ); + match call_runner_results { + Ok(info) => { + let output = info.value; + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "output result {:?}", + // output + // ); + if output.len() >= 32 { + let mut result_bytes = [0u8; 32]; + result_bytes.copy_from_slice(&output[output.len() - 32..]); + let result = U256::from_big_endian(&result_bytes); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "nconstraints_30_input_90000 Verification result {result:?}", + // ); + assert_eq!(result, U256::one(), "The contract did not return true"); + } + }, + Err(e) => { + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "nconstraints_30_input_90000 Benchmarking failed", + ); + assert!(false, "Benchmarking failed"); + } + } + } + nconstraints_30_input_200000 { + use frame_benchmarking::vec; + use sp_core::{H160, U256, H256}; + + let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + let contract_address = H160::from_low_u64_be(0x8888); + + let proof = Proof::new( + vec![ + U256::from_dec_str("19903885251949679146607224162906437591286076549652044731739108226015926915860").unwrap(), + U256::from_dec_str("11870922578907159231760438847634888925027596611865086487008358810346509550746").unwrap(), + ], + vec![ + vec![ + U256::from_dec_str("7572350741301793140585595336451242554319145556316993930579910816773197602180").unwrap(), + U256::from_dec_str("16166630091911008518878343585755669995589761813810965163203815419554661335912").unwrap(), + ], + vec![ + U256::from_dec_str("10479558631339350148140324543423297113164179377516410954282474094862685762111").unwrap(), + U256::from_dec_str("1538599836393367534859442557225095989831507256094436416355361165563840234277").unwrap(), + ], + ], + vec![ + U256::from_dec_str("18566368172831132986640612657510108843544042128267080758083569019690510537842").unwrap(), + U256::from_dec_str("14637144036179606956000163117625168358523245864386632910728645092984303842870").unwrap(), + ] + ); + + let vk = VerifyingKeyComponents::new( + vec![ + U256::from_dec_str("3388366987275268645608688601800038483480506575351380219459271970783548315310").unwrap(), + U256::from_dec_str("10139982329791419477606385196757134153200700293861474061701578521738893563314").unwrap(), + ], + vec![ + vec![ + U256::from_dec_str("17293003127353596916845398615566872053529832484770184120881889494052646686398").unwrap(), + U256::from_dec_str("3746742577904007471872553744363212404516454459540143078991207693255568088158").unwrap(), + ], + vec![ + U256::from_dec_str("18996426015092705424501193523094438770040629737761363033585766320236602756452").unwrap(), + U256::from_dec_str("5993252813486169444483155589566709251331252167093428959716521680127596688663").unwrap(), + ], + ], + vec![ + vec![ + U256::from_dec_str("86221489590459042456285770827248107701675460052532768290239949641616327672").unwrap(), + U256::from_dec_str("21618235778373592971185937996314200926578828337383413751502402964191761009384").unwrap(), + ], + vec![ + U256::from_dec_str("10453895050472290645179709462208119639593757329666114205922088367970822668124").unwrap(), + U256::from_dec_str("16924749634830145681809164670725933237166438445526123149706427927968513710893").unwrap(), + ], + ], + vec![ + vec![ + U256::from_dec_str("20506347836984398194650179863264269358088067779451739307543701941138658771117").unwrap(), + U256::from_dec_str("15256122081275324863091225387225218399888282841698960666742408225921079848693").unwrap(), + ], + vec![ + U256::from_dec_str("7881380592415293900063452944037916715621668238658562838630198037249553436647").unwrap(), + U256::from_dec_str("6003465274284900873747728448177380007802003937728590930467990944623586277089").unwrap(), + ] + ], + vec![ + vec![ + U256::from_dec_str("5531662187275540864474040102019845108669876235687831703751327129559212127084").unwrap(), + U256::from_dec_str("11455786949456856409363436892267690994602451302132959153447251790964376014822").unwrap(), + ], + vec![ + U256::from_dec_str("17221728819314881853232886080533000381382340762620795831983019279828981481257").unwrap(), + U256::from_dec_str("19341881794793455210912817199750586531241336493382870655971958667936340901503").unwrap(), + ] + ] + ); + + let valid_input: Vec = vec![u64s_to_u256(vec![ + 17510768071209558285, + 11281672863963944712, + 17936011136389338927, + 2683423138755332222, + ])]; + + let verifying_key = VerifyingKey::new(proof, vk, valid_input); + + let zk_verifier = ZKPrecompileVerifier::new( + H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), + verifying_key + ); + + let encoded_call = zk_verifier.generate_benchmarking_parameters(); + + let gas_limit_call = 1000000; + let value = U256::default(); + let is_transactional = true; + let validate = true; + }:{ + let call_runner_results = ::Runner::call( + caller, + contract_address, + encoded_call, + value, + gas_limit_call, + Some(U256::from(1_000_000_000)), + Some(U256::from(1_000_000_000)), + None, + Vec::new(), + is_transactional, + validate, + ::config(), + ); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "Benchmarking call end.", + // ); + match call_runner_results { + Ok(info) => { + let output = info.value; + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "output result {:?}", + // output + // ); + if output.len() >= 32 { + let mut result_bytes = [0u8; 32]; + result_bytes.copy_from_slice(&output[output.len() - 32..]); + let result = U256::from_big_endian(&result_bytes); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "nconstraints_30_input_200000 Verification result {result:?}", + // ); + assert_eq!(result, U256::one(), "The contract did not return true"); + } + }, + Err(e) => { + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "nconstraints_30_input_200000 Benchmarking failed", + ); + assert!(false, "Benchmarking failed"); + } + } + } + + sum_10 { + use frame_benchmarking::vec; + use sp_core::{H160, U256, H256}; + + let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + let contract_address = H160::from_low_u64_be(0x8888); + + let proof = Proof::new( + vec![ + U256::from_dec_str("4479438672593572194843316486259284641920166054544576564310150763796220593742").unwrap(), + U256::from_dec_str("5717857931841301866217201485541887040818093727574311517591849036289507799141").unwrap(), + ], + vec![ + vec![ + U256::from_dec_str("438102211713357984070931589322877643391719193099221891191956755149301376056").unwrap(), + U256::from_dec_str("14696299438400225528910058565202329177181471318954607581306780544413371767738").unwrap(), + ], + vec![ + U256::from_dec_str("18723112929967827488252389384208353884816003870032279933823625467146809072448").unwrap(), + U256::from_dec_str("781225142569358922067919798403956593420009838230922093237868933021043854113").unwrap(), + ], + ], + vec![ + U256::from_dec_str("10481213903673023503381125372528754955378591812884098928519623211332171467098").unwrap(), + U256::from_dec_str("15098195705682978185145469811146985310923026878303775073727891846327587112885").unwrap(), + ] + ); + + let vk = VerifyingKeyComponents::new( + vec![ + U256::from_dec_str("10600514820627226711889163536575359330497844540484876797299835164575096986123").unwrap(), + U256::from_dec_str("8955505242614929800342716899005854501255692108538633212406728467939250778259").unwrap(), + ], + vec![ + vec![ + U256::from_dec_str("11358515176167160981846987587695931342878788452018419590778128561277894807040").unwrap(), + U256::from_dec_str("7367100375568995524851051084377016949291621141008718892167611998460177966556").unwrap(), + ], + vec![ + U256::from_dec_str("9986374126991936592889887298811366506288970021158383914729072242552712258999").unwrap(), + U256::from_dec_str("5917047061876555575617149777207682047359711575786648519096749890796145313142").unwrap(), + ], + ], + vec![ + vec![ + U256::from_dec_str("12470512550870605078154922234115021580073605821744497867586706681115325377951").unwrap(), + U256::from_dec_str("3964373607930903502336465614571930627592350216968107805643078708599943392195").unwrap(), + ], + vec![ + U256::from_dec_str("9054619931591683490625148848351137928205510101241639415537408964292455344707").unwrap(), + U256::from_dec_str("14433710971468466044075036729227299898791551573181475688890434779549865103322").unwrap(), + ] + ], + vec![ + vec![ + U256::from_dec_str("13008751738470482081156013535203222043379316308698376931322848604706786065862").unwrap(), + U256::from_dec_str("3415558414191757405655644967374577939532374518318643852418890898323033638525").unwrap(), + ], + vec![ + U256::from_dec_str("2104722493853714523712648261788727756558190509825976396834309269877977849365").unwrap(), + U256::from_dec_str("6877732520157662584755946842350755740172704606349660337522459938993730313391").unwrap(), + ], + ], + vec![ + vec![ + U256::from_dec_str("17691779713798847872985546462247707503645016076661816616388979822201176829753").unwrap(), + U256::from_dec_str("14451231434311244057691431183198403713720423327382654964068207207079455187712").unwrap(), + ], + vec![ + U256::from_dec_str("13620414910695185146987530463229819484652710069270717148541433045978322585419").unwrap(), + U256::from_dec_str("10875872907505029426874795808985164080699672034676409959252328566889297105865").unwrap(), + ] + ] + ); + + let valid_input = vec![ + U256::from_dec_str("55").unwrap() + ]; + + let verifying_key = VerifyingKey::new(proof, vk, valid_input); + + let zk_verifier = ZKPrecompileVerifier::new( + H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), + verifying_key + ); + + let encoded_call = zk_verifier.generate_benchmarking_parameters(); + + let gas_limit_call = 1000000; + let value = U256::default(); + let is_transactional = true; + let validate = true; + }:{ + let call_runner_results = ::Runner::call( + caller, + contract_address, + encoded_call, + value, + gas_limit_call, + Some(U256::from(1_000_000_000)), + Some(U256::from(1_000_000_000)), + None, + Vec::new(), + is_transactional, + validate, + ::config(), + ); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "Benchmarking call end.", + // ); + match call_runner_results { + Ok(info) => { + let output = info.value; + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "output result {:?}", + // output + // ); + if output.len() >= 32 { + let mut result_bytes = [0u8; 32]; + result_bytes.copy_from_slice(&output[output.len() - 32..]); + let result = U256::from_big_endian(&result_bytes); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "sum_10 Verification result {result:?}", + // ); + assert_eq!(result, U256::one(), "The contract did not return true"); + } + }, + Err(e) => { + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "sum_10Benchmarking failed", + ); + assert!(false, "Benchmarking failed"); + } + } + } + sum_50 { + use frame_benchmarking::vec; + use sp_core::{H160, U256, H256}; + + let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + let contract_address = H160::from_low_u64_be(0x8888); + + let proof = Proof::new( + vec![ + U256::from_dec_str("3114941071688532747454764921300681791980888248199392522675009157778549895455").unwrap(), + U256::from_dec_str("6816680925124829082835883802586391663161606011222680818599486084577544527516").unwrap(), + ], + vec![ + vec![ + U256::from_dec_str("15037393792780247314317740287895838240941967969445981241792818111317913065010").unwrap(), + U256::from_dec_str("3834028682995799272226496422556310257938795862629020590068471611902272764146").unwrap(), + ], + vec![ + U256::from_dec_str("4023883034822047449129381158539093978377425715903419218696272130851521242085").unwrap(), + U256::from_dec_str("13058906875228264286034925941047330220503025517973111955115072416984072943122").unwrap(), + ], + ], + vec![ + U256::from_dec_str("5344888056894889487007260648469199417556856955544355154291642477677322944786").unwrap(), + U256::from_dec_str("19843194668352645797068691966948915569058668700830773246420232986019393210063").unwrap(), + ] + ); + + let vk = VerifyingKeyComponents::new( + vec![ + U256::from_dec_str("19257923683733118221652593587810195852599358412856281104090957905722976964370").unwrap(), + U256::from_dec_str("19519729727735873999148754136012144616045305047716967685280834855818506563720").unwrap(), + ], + vec![ + vec![ + U256::from_dec_str("4418606700813566482216037680863387214037640478555893901955308344977554198718").unwrap(), + U256::from_dec_str("18046767849922558936185002168253454007598159984067380537392936220227127228867").unwrap(), + ], + vec![ + U256::from_dec_str("100725403545603844224319783153051757027683253433977048289134569498829183303").unwrap(), + U256::from_dec_str("9785321212288652698655727476617710557399711491394256119637648908536562741634").unwrap(), + ], + ], + vec![ + vec![ + U256::from_dec_str("7184324332054694882815451883063466258810341506246659357034202660488015984306").unwrap(), + U256::from_dec_str("14398081398842334723334363407187040569418119441776629783632309768037771007327").unwrap(), + ], + vec![ + U256::from_dec_str("17277213124622419955089087696435667358779233792945822269342368397066818801481").unwrap(), + U256::from_dec_str("19811781065417531456401229702422997450338397507283920558741452740912313583930").unwrap(), + ] + ], + vec![ + vec![ + U256::from_dec_str("1627724482578854283892192357407161928314687375966263116172485631707694669812").unwrap(), + U256::from_dec_str("6839802000376483025048211234449253336394632788399066904541666906747650234382").unwrap(), + ], + vec![ + U256::from_dec_str("17974577137954059751166162247265070307968439813726452160113109110701162631938").unwrap(), + U256::from_dec_str("21289972529626386698860098501676961527414208445147370800462053148477683157991").unwrap(), + ], + ], + vec![ + vec![ + U256::from_dec_str("20284064245383237908740484779775789109386762825985839657586769414934584661714").unwrap(), + U256::from_dec_str("17363934481847560975462360104367791101351872886050159351690589725380050257409").unwrap(), + ], + vec![ + U256::from_dec_str("3904403738619431633601997032597659843284744078768864151280168218762434423692").unwrap(), + U256::from_dec_str("4413868989856264583489102855186788724178233679332360263809134874064797750675").unwrap(), + ] + ] + ); + + let valid_input = vec![ + U256::from_dec_str("1275").unwrap(), + ]; + + let verifying_key = VerifyingKey::new(proof, vk, valid_input); + + let zk_verifier = ZKPrecompileVerifier::new( + H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), + verifying_key + ); + + let encoded_call = zk_verifier.generate_benchmarking_parameters(); + + let gas_limit_call = 1000000; + let value = U256::default(); + let is_transactional = true; + let validate = true; + }:{ + let call_runner_results = ::Runner::call( + caller, + contract_address, + encoded_call, + value, + gas_limit_call, + Some(U256::from(1_000_000_000)), + Some(U256::from(1_000_000_000)), + None, + Vec::new(), + is_transactional, + validate, + ::config(), + ); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "Benchmarking call end.", + // ); + match call_runner_results { + Ok(info) => { + let output = info.value; + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "output result {:?}", + // output + // ); + if output.len() >= 32 { + let mut result_bytes = [0u8; 32]; + result_bytes.copy_from_slice(&output[output.len() - 32..]); + let result = U256::from_big_endian(&result_bytes); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "sum_50 Verification result {result:?}", + // ); + assert_eq!(result, U256::one(), "The contract did not return true"); + } + }, + Err(e) => { + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "sum_50 Benchmarking failed", + ); + assert!(false, "Benchmarking failed"); + } + } + } + + sum_5000 { + use frame_benchmarking::vec; + use sp_core::{H160, U256, H256}; + + let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + let contract_address = H160::from_low_u64_be(0x8888); + + let proof = Proof::new( + vec![ + U256::from_dec_str("2104134032972066019913571175532882184351637942839921828138208604817397790978").unwrap(), + U256::from_dec_str("12625149522977248086293073767826715132905823679345516244316272790389621024575").unwrap(), + ], + vec![ + vec![ + U256::from_dec_str("18955718237898317556602416465218566057031982163829528123671300051574728240883").unwrap(), + U256::from_dec_str("18075306515520608621953959878874546391551215874677138383864573851396832159644").unwrap(), + ], + vec![ + U256::from_dec_str("3166476742865671627115278436666969186969644878053983393309132722947819232105").unwrap(), + U256::from_dec_str("8051049247607109861344268872842958063551670273736053865524986958976361214062").unwrap(), + ], + ], + vec![ + U256::from_dec_str("4814291763265323888812051590287571407031542635142019809665068757723218701627").unwrap(), + U256::from_dec_str("17930948070313125851452005455953009375012074818817251382455220462443054837203").unwrap(), + ] + ); + + let vk = VerifyingKeyComponents::new( + vec![ + U256::from_dec_str("19624232987744880202266197753309961915632611879850947888541508003701736644214").unwrap(), + U256::from_dec_str("5019843555387010050200067558096501184079196549422645876015184268981691000261").unwrap(), + ], + vec![ + vec![ + U256::from_dec_str("5150307298606577026396875555180704696345763655981810466632357002439129266461").unwrap(), + U256::from_dec_str("3020656302335648031712857271727816386298675153130933709481311850060508289333").unwrap(), + ], + vec![ + U256::from_dec_str("19547576195358452722114991449875886954598568010341500952076854329553571219720").unwrap(), + U256::from_dec_str("3895331072082263654317901227968966808293407907751128382134753194859731114729").unwrap(), + ], + ], + vec![ + vec![ + U256::from_dec_str("5792479463369352075979003547777370241697788651005116088867026457677720533395").unwrap(), + U256::from_dec_str("16882159064341957118950974052606760693554763076237663579029547802558086431378").unwrap(), + ], + vec![ + U256::from_dec_str("15201299876801474331768851307298179430198466709727112330042020251492139993850").unwrap(), + U256::from_dec_str("893863620414771464835789333501093176356026692988850717670551586498757709875").unwrap(), + ] + ], + vec![ + vec![ + U256::from_dec_str("165136411129701665870237237981894748637834826722462614973940945603783242464").unwrap(), + U256::from_dec_str("10766657827945181878791518932726777890925519579254084496220957371082172349194").unwrap(), + ], + vec![ + U256::from_dec_str("1813485593016293809685571822392302147347136682526622353828238069063634409991").unwrap(), + U256::from_dec_str("12730118542350484957903782401323352413406115135420607527656226977122246298735").unwrap(), + ], + ], + vec![ + vec![ + U256::from_dec_str("19450458898299554306247087083239008884256452312356497246598109368644839627523").unwrap(), + U256::from_dec_str("123992241310851816418828784530061727329258706748227789362318537744292975333").unwrap(), + ], + vec![ + U256::from_dec_str("1650700423026830428199086201346242616543834285406293983963791012821269466913").unwrap(), + U256::from_dec_str("3152920600939501404817148774751227981988970987313622659392580888754616114976").unwrap(), + ] + ] + ); + + let valid_input = vec![ + U256::from_dec_str("12502500").unwrap(), + ]; + + let verifying_key = VerifyingKey::new(proof, vk, valid_input); + + let zk_verifier = ZKPrecompileVerifier::new( + H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), + verifying_key + ); + + let encoded_call = zk_verifier.generate_benchmarking_parameters(); + + let gas_limit_call = 1000000; + let value = U256::default(); + let is_transactional = true; + let validate = true; + }:{ + let call_runner_results = ::Runner::call( + caller, + contract_address, + encoded_call, + value, + gas_limit_call, + Some(U256::from(1_000_000_000)), + Some(U256::from(1_000_000_000)), + None, + Vec::new(), + is_transactional, + validate, + ::config(), + ); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "Benchmarking call end.", + // ); + match call_runner_results { + Ok(info) => { + let output = info.value; + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "output result {:?}", + // output + // ); + if output.len() >= 32 { + let mut result_bytes = [0u8; 32]; + result_bytes.copy_from_slice(&output[output.len() - 32..]); + let result = U256::from_big_endian(&result_bytes); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "sum_5000 Verification result {result:?}", + // ); + assert_eq!(result, U256::one(), "The contract did not return true"); + } + }, + Err(e) => { + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "sum_5000 Benchmarking failed", + ); + assert!(false, "Benchmarking failed"); + } + } + } + + sum_50000 { + use frame_benchmarking::vec; + use sp_core::{H160, U256, H256}; + + let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + let contract_address = H160::from_low_u64_be(0x8888); + + let proof = Proof::new( + vec![ + U256::from_dec_str("10521560297681522924956535552101557954055377883537271587209095331672512231293").unwrap(), + U256::from_dec_str("3686654512637749683446869119197341068039068905923579159423036344564025864377").unwrap(), + ], + vec![ + vec![ + U256::from_dec_str("4890395955490088627121586512165392468998481877071173820388882318632254821251").unwrap(), + U256::from_dec_str("9885243823600363166628220433820250724586324090253611358758770212725684204135").unwrap(), + ], + vec![ + U256::from_dec_str("9651185291553128823215307092565172143818838202635271809942597163630971976482").unwrap(), + U256::from_dec_str("7457264071531012293581639749136580536924886204589417402009399054127419592993").unwrap(), + ], + ], + vec![ + U256::from_dec_str("2627345354605748142976160304028628661480987375506843588233396593542954599122").unwrap(), + U256::from_dec_str("8681729968580301984067665769277363721394455178806371130831646417737890294377").unwrap(), + ] + ); + + let vk = VerifyingKeyComponents::new( + vec![ + U256::from_dec_str("7421321362170719195081023585470135389432297716397232604489422086989398701183").unwrap(), + U256::from_dec_str("4072026971341416803293623026670767879574289631340879941991921870784524426920").unwrap(), + ], + vec![ + vec![ + U256::from_dec_str("2973474839676012411019522612887674225146102238495561333683790233803898072056").unwrap(), + U256::from_dec_str("4756088420398356546587372215087817373004751038308642279979561650652947628544").unwrap(), + ], + vec![ + U256::from_dec_str("18134483811751652906456539288278265005968212485396038963550793901997203165973").unwrap(), + U256::from_dec_str("19733531274857979315351276512779996430041767061694237978460875113100798536651").unwrap(), + ], + ], + vec![ + vec![ + U256::from_dec_str("1470135418689977789083190292952479192678178451735632796795673595352524120366").unwrap(), + U256::from_dec_str("5512330648930976997879473235916847191061423400686751865867764833860608466852").unwrap(), + ], + vec![ + U256::from_dec_str("8727385532414213805687214017949229267547242769169729533774216518510791901252").unwrap(), + U256::from_dec_str("6002526157648728322271067956991922780742552704883496238917574496345518669191").unwrap(), + ] + ], + vec![ + vec![ + U256::from_dec_str("20953112965721952332699311075873353918826966291896395544882354080425788226212").unwrap(), + U256::from_dec_str("9244986330211753947979669564454335484807935852348100319901614192766392809174").unwrap(), + ], + vec![ + U256::from_dec_str("14633091132354386243825187195737842488061561784614981035737595152471541943810").unwrap(), + U256::from_dec_str("18226447293937452659919522397971158104569327938800893595903771586125572293911").unwrap(), + ], + ], + vec![ + vec![ + U256::from_dec_str("12814717307556312189651039282215441805578074271611267777533714458773278844960").unwrap(), + U256::from_dec_str("7186820657304904476047212967487229874520184333187156276378594443001564484591").unwrap(), + ], + vec![ + U256::from_dec_str("555198418426478766253895845611805598077310216839822834188225932135183360314").unwrap(), + U256::from_dec_str("13253206399154373951823381980703846825450333469684895600618793136364702673992").unwrap(), + ] + ] + ); + + let valid_input = vec![U256::from_dec_str("1250025000").unwrap()]; + + let verifying_key = VerifyingKey::new(proof, vk, valid_input); + + let zk_verifier = ZKPrecompileVerifier::new( + H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), + verifying_key + ); + + let encoded_call = zk_verifier.generate_benchmarking_parameters(); + + let gas_limit_call = 1000000; + let value = U256::default(); + let is_transactional = true; + let validate = true; + }:{ + let call_runner_results = ::Runner::call( + caller, + contract_address, + encoded_call, + value, + gas_limit_call, + Some(U256::from(1_000_000_000)), + Some(U256::from(1_000_000_000)), + None, + Vec::new(), + is_transactional, + validate, + ::config(), + ); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "Benchmarking call end.", + // ); + match call_runner_results { + Ok(info) => { + let output = info.value; + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "output result {:?}", + // output + // ); if output.len() >= 32 { let mut result_bytes = [0u8; 32]; result_bytes.copy_from_slice(&output[output.len() - 32..]); let result = U256::from_big_endian(&result_bytes); - log::info!( - target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - "Verification result {result:?}", - ); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "sum_50000 Verification result {result:?}", + // ); assert_eq!(result, U256::one(), "The contract did not return true"); } }, Err(e) => { log::info!( target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - "Benchmarking failed", + "sum_50000 Benchmarking failed", ); + assert!(false, "Benchmarking failed"); } } } diff --git a/runtime/runtime-common/src/zk_precompile_gas_estimation/tests.rs b/runtime/runtime-common/src/zk_precompile_gas_estimation/tests.rs index 620d2a44..9e0355c4 100644 --- a/runtime/runtime-common/src/zk_precompile_gas_estimation/tests.rs +++ b/runtime/runtime-common/src/zk_precompile_gas_estimation/tests.rs @@ -5,6 +5,17 @@ use frame_support::traits::GenesisBuild; use pallet_evm::{GenesisConfig, Runner}; use sp_core::{H160, U256}; use std::{collections::BTreeMap, str::FromStr}; + +fn u64s_to_u256(values: Vec) -> U256 { + let mut result = U256::zero(); + for (i, value) in values.into_iter().enumerate().take(4) { + let shift = i * 64; + result |= U256::from(value) << shift; + } + println!("{:?}", result); + result +} + pub fn new_test_ext() -> sp_io::TestExternalities { let mut t = frame_system::GenesisConfig::default() .build_storage::() @@ -141,15 +152,14 @@ fn test_zk_precompile_gas_estimation() { ] ]; - let valid_input = vec![ - U256::from_dec_str("1250025000").unwrap() - ]; - // let valid_input = vec![ - // U256::from_dec_str("14965631224775206224").unwrap(), - // U256::from_dec_str("3021577815302938909").unwrap(), - // U256::from_dec_str("14359293880404272991").unwrap(), - // U256::from_dec_str("1555005537055779113").unwrap(), - // ]; + // let valid_input = vec![u64s_to_u256(vec![1250025000])]; + let valid_input = vec![u64s_to_u256(vec![ + 14965631224775206224, + 3021577815302938909, + 14359293880404272991, + 1555005537055779113, + ])]; + let mut encoded_call = vec![0u8; 4]; encoded_call[0..4].copy_from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..4]); println!("encoded_call: {:?}", encoded_call); From 362e819fbb5bf498b29125c62d87d5d3dbf4e100 Mon Sep 17 00:00:00 2001 From: luckychacha <358140284@qq.com> Date: Thu, 10 Aug 2023 18:38:56 +0800 Subject: [PATCH 21/34] Add more benchmarking --- .../benchmarking.rs | 4203 ++++++++++++----- 1 file changed, 3088 insertions(+), 1115 deletions(-) diff --git a/runtime/runtime-common/src/zk_precompile_gas_estimation/benchmarking.rs b/runtime/runtime-common/src/zk_precompile_gas_estimation/benchmarking.rs index 94d57ce0..b266b1c3 100644 --- a/runtime/runtime-common/src/zk_precompile_gas_estimation/benchmarking.rs +++ b/runtime/runtime-common/src/zk_precompile_gas_estimation/benchmarking.rs @@ -182,7 +182,2136 @@ fn u64s_to_u256(values: Vec) -> U256 { } benchmarks! { - nconstraints_10 { + // nconstraints_10 { + // use frame_benchmarking::vec; + // use sp_core::{H160, U256, H256}; + + // let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + // let contract_address = H160::from_low_u64_be(0x8888); + + // let proof = Proof::new( + // vec![ + // U256::from_dec_str("323654832133639084097738656057999026789295280666886852594984576709163539526").unwrap(), + // U256::from_dec_str("6142957218280645039826855630872622613337777761157366378615236951849913775542").unwrap() + // ], + // vec![ + // vec![ + // U256::from_dec_str("3781402603457401622553078625624300084337446058890012151530042647448923283156").unwrap(), + // U256::from_dec_str("3517436796495769146106898128956048233729888622957356948216773257280783319311").unwrap() + // ], + // vec![ + // U256::from_dec_str("18697717875318192535466611481750571094853863458428844875498420533596881568336").unwrap(), + // U256::from_dec_str("21426423909981695530725752097567643188095093768132522705564475372400085021436").unwrap() + // ], + // ], + // vec![ + // U256::from_dec_str("21613404883582191576526635676329374200679201344239432919502376530553941450391").unwrap(), + // U256::from_dec_str("15157755445966041962464884593780030869511182260822371637833098723763718514455").unwrap() + // ] + // ); + + // let vk = VerifyingKeyComponents::new( + // vec![ + // U256::from_dec_str("11521346682463921906610271064518766485088278761420928386309550940286650671457").unwrap(), + // U256::from_dec_str("14352830518175561380348856554041231805603495989169432000725584250110291361678").unwrap() + // ], + // vec![ + // vec![ + // U256::from_dec_str("15782596638536803844844408481637582589736413871396993858917786753770876529739").unwrap(), + // U256::from_dec_str("14911823231521430202833448929652297782496660742577343858219844871404504144036").unwrap() + // ], + // vec![ + // U256::from_dec_str("2082222914940990020573243578958386229340150899029559516350605378857473031525").unwrap(), + // U256::from_dec_str("13498996195230132373906915048494917069165130851394909752977335076805840989307").unwrap() + // ], + // ], + // vec![ + // vec![ + // U256::from_dec_str("3598021131780341035246011324427156192540414244243113294885735792953741606880").unwrap(), + // U256::from_dec_str("2036084172531515709709771052774738245922046202318890723044728246225539963428").unwrap() + // ], + // vec![ + // U256::from_dec_str("5925457711548235099025126547368719549508643015841982506039250719340224619945").unwrap(), + // U256::from_dec_str("6297446610567432982066083461547400065680646594595441716191878482607632761242").unwrap() + // ], + // ], + // vec![ + // vec![ + // U256::from_dec_str("8540596677770285018018336727251534074846909511956041125063939097422779191925").unwrap(), + // U256::from_dec_str("4004145476643750015352094786522189637304633549022019774555222068038038169997").unwrap() + // ], + // vec![ + // U256::from_dec_str("14044576757821380530542904664046256148829410228513509672845139471539338485558").unwrap(), + // U256::from_dec_str("21655834928283484760531472827487408029775629615266614212974138202212982461041").unwrap() + // ] + // ], + // vec![ + // vec![ + // U256::from_dec_str("18160015955331442477546361309657533914485780296451278252095683998154112390415").unwrap(), + // U256::from_dec_str("2421052745427024367257863480713357899822722660532800486395996070904226714086").unwrap() + // ], + // vec![ + // U256::from_dec_str("13418845437340247256566377432948869602549774753220761674399899795516131627829").unwrap(), + // U256::from_dec_str("19073971532401628571532840417056837528958340897410372352356543204393028153748").unwrap() + // ] + // ] + // ); + + // let valid_input: Vec = vec![u64s_to_u256(vec![ + // 14965631224775206224, + // 3021577815302938909, + // 14359293880404272991, + // 1555005537055779113 + // ])]; + + // let verifying_key = VerifyingKey::new(proof, vk, valid_input); + + // let zk_verifier = ZKPrecompileVerifier::new( + // H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), + // verifying_key + // ); + + // let encoded_call = zk_verifier.generate_benchmarking_parameters(); + + // let gas_limit_call = 1000000; + // let value = U256::default(); + // let is_transactional = true; + // let validate = true; + // }:{ + // let call_runner_results = ::Runner::call( + // caller, + // contract_address, + // encoded_call, + // value, + // gas_limit_call, + // Some(U256::from(1_000_000_000)), + // Some(U256::from(1_000_000_000)), + // None, + // Vec::new(), + // is_transactional, + // validate, + // ::config(), + // ); + // // log::info!( + // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // // "Benchmarking call end.", + // // ); + // match call_runner_results { + // Ok(info) => { + // let output = info.value; + // // log::info!( + // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // // "output result {:?}", + // // output + // // ); + // if output.len() >= 32 { + // let mut result_bytes = [0u8; 32]; + // result_bytes.copy_from_slice(&output[output.len() - 32..]); + // let result = U256::from_big_endian(&result_bytes); + // // log::info!( + // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // // "nconstraints_10 Verification result {result:?}", + // // ); + // assert_eq!(result, U256::one(), "The contract did not return true"); + // } + // }, + // Err(e) => { + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "nconstraints_10 Benchmarking failed", + // ); + // assert!(false, "Benchmarking failed"); + + // } + // } + // } + + // nconstraints_50 { + // use frame_benchmarking::vec; + // use sp_core::{H160, U256, H256}; + + // let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + // let contract_address = H160::from_low_u64_be(0x8888); + + // let proof = Proof::new( + // vec![ + // U256::from_dec_str("2903574088029507435491062627919627539459038881203099780902103872696986272650").unwrap(), + // U256::from_dec_str("3875062839032259754068923295563862040166715100637843024855021734684308685930").unwrap(), + // ], + // vec![ + // vec![ + // U256::from_dec_str("5467576156112132028552287163049386912078800648727055176723583005212825192497").unwrap(), + // U256::from_dec_str("14958898784032520052694892656913773236193256742890765604760593633503039104983").unwrap(), + // ], + // vec![ + // U256::from_dec_str("5396143311660903133040196691443703988892234257628755380984718394981374344158").unwrap(), + // U256::from_dec_str("8621644456104449033213297238562527153800159584768570376273022394943050969320").unwrap(), + // ], + // ], + // vec![ + // U256::from_dec_str("11879092906448699692394725971977132036554363118574468164770659810752018463948").unwrap(), + // U256::from_dec_str("6829624468475499149259780051037762599455296300930683215687755977165243124154").unwrap(), + // ] + // ); + + // let vk = VerifyingKeyComponents::new( + // vec![ + // U256::from_dec_str("12520775544030530008009522467466185193766786263812261579427634884004150619566").unwrap(), + // U256::from_dec_str("5032545863820965741764073435262250124257467813113463153084126384917060899315").unwrap(), + // ], + // vec![ + // vec![ + // U256::from_dec_str("10017955328073015145877787608777450033090741247853140204265773706371885379542").unwrap(), + // U256::from_dec_str("9658203662920649739629860626443008098625554125855709045942833415049413198251").unwrap(), + // ], + // vec![ + // U256::from_dec_str("7602415148393817869205609282139785691690714005596249546125364310759985118071").unwrap(), + // U256::from_dec_str("6621887421318408197643297351639235440436194355283660692959196816576578875866").unwrap(), + // ], + // ], + // vec![ + // vec![ + // U256::from_dec_str("5311307398908794283615493653665859916837738758333406097237626345248614605789").unwrap(), + // U256::from_dec_str("17876886843886949913975349493510247353159584223381019718903135647608874168034").unwrap(), + // ], + // vec![ + // U256::from_dec_str("16871344858870476549165036353120397473700844904231047018564735968613233188965").unwrap(), + // U256::from_dec_str("3780010632071163899826543545524090280002435997376718121100375224910528030644").unwrap(), + // ], + // ], + // vec![ + // vec![ + // U256::from_dec_str("5274939476765287332787933848172441391963317633567336761478263433231602711901").unwrap(), + // U256::from_dec_str("20318717968421229127062334564952813061229602553850186042308931686220563993985").unwrap(), + // ], + // vec![ + // U256::from_dec_str("18867986549807700609691354300906273266753459571664361845748650324369589087167").unwrap(), + // U256::from_dec_str("3462802759155100024118895949055238081126591020075851877084161838812514424801").unwrap(), + // ] + // ], + // vec![ + // vec![ + // U256::from_dec_str("2073721309366561324099267234284336470258146869696430225377434175843251484752").unwrap(), + // U256::from_dec_str("5562089018027206512286783868306950659834000523781522158661084193254167305831").unwrap(), + // ], + // vec![ + // U256::from_dec_str("7633925392184781104787537197952383405066326059553608577981951477761067715424").unwrap(), + // U256::from_dec_str("19510227686274170330355317434483857344641524658406254379151352263942714837771").unwrap(), + // ] + // ] + // ); + + // let valid_input: Vec = vec![u64s_to_u256(vec![ + // 14754876691570659999, + // 1449725765053302887, + // 10573592104590215630, + // 2031301759166401468 + // ])]; + + // let verifying_key = VerifyingKey::new(proof, vk, valid_input); + + // let zk_verifier = ZKPrecompileVerifier::new( + // H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), + // verifying_key + // ); + + // let encoded_call = zk_verifier.generate_benchmarking_parameters(); + + // let gas_limit_call = 1000000; + // let value = U256::default(); + // let is_transactional = true; + // let validate = true; + // }:{ + // let call_runner_results = ::Runner::call( + // caller, + // contract_address, + // encoded_call, + // value, + // gas_limit_call, + // Some(U256::from(1_000_000_000)), + // Some(U256::from(1_000_000_000)), + // None, + // Vec::new(), + // is_transactional, + // validate, + // ::config(), + // ); + // // log::info!( + // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // // "Benchmarking call end.", + // // ); + // match call_runner_results { + // Ok(info) => { + // let output = info.value; + // // log::info!( + // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // // "output result {:?}", + // // output + // // ); + // if output.len() >= 32 { + // let mut result_bytes = [0u8; 32]; + // result_bytes.copy_from_slice(&output[output.len() - 32..]); + // let result = U256::from_big_endian(&result_bytes); + // // log::info!( + // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // // "nconstraints_50 Verification result {result:?}", + // // ); + // assert_eq!(result, U256::one(), "The contract did not return true"); + // } + // }, + // Err(e) => { + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "nconstraints_50 Benchmarking failed", + // ); + // assert!(false, "Benchmarking failed"); + + // } + // } + // } + + // nconstraints_1000 { + // use frame_benchmarking::vec; + // use sp_core::{H160, U256, H256}; + + // let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + // let contract_address = H160::from_low_u64_be(0x8888); + + // let proof = Proof::new( + // vec![ + // U256::from_dec_str("12451505848309631687252015279596976128225375079184616465869275088833975377438").unwrap(), + // U256::from_dec_str("18028472547304696309803026581736164843724278168110632635282700219721294267849").unwrap(), + // ], + // vec![ + // vec![ + // U256::from_dec_str("724941625340075448308940885419778921267046089963198424690563710257350467820").unwrap(), + // U256::from_dec_str("19418815036545241911278056687101064762643664412732993043969007894248087117385").unwrap(), + // ], + // vec![ + // U256::from_dec_str("13249414494230793056410904135885722890271124096600389432878053498484425858770").unwrap(), + // U256::from_dec_str("21762806144353143011028620465453743506764842517668851190776375592288870325215").unwrap(), + // ], + // ], + // vec![ + // U256::from_dec_str("9206867270262791130308246301015463866896172966002943363908694359851632501217").unwrap(), + // U256::from_dec_str("13679683495177263967294831832954860495137891909047512983345948806664713075553").unwrap(), + // ] + // ); + + // let vk = VerifyingKeyComponents::new( + // vec![ + // U256::from_dec_str("13896934827344718021853288836918374118104295193491067840322643424358899121542").unwrap(), + // U256::from_dec_str("8854052944916041632001392967979629780372345382861670282089777314383817716115").unwrap(), + // ], + // vec![ + // vec![ + // U256::from_dec_str("3601177773308419037453361001975316835601350296485805323140167568598797930642").unwrap(), + // U256::from_dec_str("48851914275316782871445347689531673984580545598074561513165366823294923594").unwrap(), + // ], + // vec![ + // U256::from_dec_str("4538012201084519544875007504928553564968897773565284770715803834936680149613").unwrap(), + // U256::from_dec_str("3155968616270588886660033728776257587454508333510911411658919790925259116614").unwrap(), + // ], + // ], + // vec![ + // vec![ + // U256::from_dec_str("6521538659624675039700866061977650833785775087701556120926232218187885377774").unwrap(), + // U256::from_dec_str("18707623749213430453109215145186606994638201653518117177006249287165414157706").unwrap(), + // ], + // vec![ + // U256::from_dec_str("11743109857123024729794370527373948778820323338754388805090881243904381703330").unwrap(), + // U256::from_dec_str("3577725017182890090279110701721773090147301853148322630192233820247926772155").unwrap(), + // ], + // ], + // vec![ + // vec![ + // U256::from_dec_str("10697077492206594361644026971284249101590705030465491131467731100150008255694").unwrap(), + // U256::from_dec_str("1114380532795466865933623446272212800793315337032855536172932313989250445726").unwrap(), + // ], + // vec![ + // U256::from_dec_str("11747915450686416011932172170367549011245903715607283230565719536126230133873").unwrap(), + // U256::from_dec_str("1877153534214274703747923906347594924169181268669702005894131954432202950068").unwrap(), + // ] + // ], + // vec![ + // vec![ + // U256::from_dec_str("6294921440683861296812943370338888809368101163511446375226378176013676840633").unwrap(), + // U256::from_dec_str("8766686502883018606879699065134987161183815270662618961653335871316040755302").unwrap(), + // ], + // vec![ + // U256::from_dec_str("15422085976834841481597157129530660038025986735930069198619117556493669017719").unwrap(), + // U256::from_dec_str("6824904336141021449652133306590775160232847673735850151493603664420102965477").unwrap(), + // ] + // ] + // ); + + // let valid_input: Vec = vec![u64s_to_u256(vec![ + // 5637188163546619750, + // 4876642863872575056, + // 11311886144936918135, + // 2620236256196171805 + // ])]; + + // let verifying_key = VerifyingKey::new(proof, vk, valid_input); + + // let zk_verifier = ZKPrecompileVerifier::new( + // H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), + // verifying_key + // ); + + // let encoded_call = zk_verifier.generate_benchmarking_parameters(); + + // let gas_limit_call = 1000000; + // let value = U256::default(); + // let is_transactional = true; + // let validate = true; + // }:{ + // let call_runner_results = ::Runner::call( + // caller, + // contract_address, + // encoded_call, + // value, + // gas_limit_call, + // Some(U256::from(1_000_000_000)), + // Some(U256::from(1_000_000_000)), + // None, + // Vec::new(), + // is_transactional, + // validate, + // ::config(), + // ); + // // log::info!( + // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // // "Benchmarking call end.", + // // ); + // match call_runner_results { + // Ok(info) => { + // let output = info.value; + // // log::info!( + // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // // "output result {:?}", + // // output + // // ); + // if output.len() >= 32 { + // let mut result_bytes = [0u8; 32]; + // result_bytes.copy_from_slice(&output[output.len() - 32..]); + // let result = U256::from_big_endian(&result_bytes); + // // log::info!( + // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // // "nconstraints_1000 Verification result {result:?}", + // // ); + // assert_eq!(result, U256::one(), "The contract did not return true"); + // } + // }, + // Err(e) => { + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "nconstraints_1000 Benchmarking failed", + // ); + // assert!(false, "Benchmarking failed"); + + // } + // } + // } + // nconstraints_900000 { + // use frame_benchmarking::vec; + // use sp_core::{H160, U256, H256}; + + // let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + // let contract_address = H160::from_low_u64_be(0x8888); + + // let proof = Proof::new( + // vec![ + // U256::from_dec_str("19469224081137364911375441935428613758543844094780123177610680784796374565509").unwrap(), + // U256::from_dec_str("2964109100176825277964902990593130655404587548088911907169158668561756482373").unwrap(), + // ], + // vec![ + // vec![ + // U256::from_dec_str("1804788596044451078391485097362341934563024367189115611320140606169017734442").unwrap(), + // U256::from_dec_str("13075356869764013404490647878715830765050556805353047586243641659166972614506").unwrap(), + // ], + // vec![ + // U256::from_dec_str("11510752280195741101381678478126680255679095252133774347633523263393718090827").unwrap(), + // U256::from_dec_str("19917734624109913540474402939707087760514256808495299709893660593520804971329").unwrap(), + // ], + // ], + // vec![ + // U256::from_dec_str("17650234014776935476405426867265189573543251264844619398004397025922351000524").unwrap(), + // U256::from_dec_str("13980409623437481166079302794215538337078177634480935418093274323345259996058").unwrap(), + // ] + // ); + + // let vk = VerifyingKeyComponents::new( + // vec![ + // U256::from_dec_str("7204013913559348808806179272679133668079798990573619252699122941477292720367").unwrap(), + // U256::from_dec_str("14448814309541293146746525253301533902449817953703436076734477345366335651547").unwrap(), + // ], + // vec![ + // vec![ + // U256::from_dec_str("12755354931522455226769415963087662012592248962914015697167303994293035888664").unwrap(), + // U256::from_dec_str("19979994508677160041392994419804596139216500302977150541381981675855322022114").unwrap(), + // ], + // vec![ + // U256::from_dec_str("3518578052095992035034011768990132253597152650327354182069223777691356587613").unwrap(), + // U256::from_dec_str("1512363495951297845516866605291301480678745477544041997800458458709067854003").unwrap(), + // ], + // ], + // vec![ + // vec![ + // U256::from_dec_str("21483901865224554977407186643009006049964266844355020377697169106001216486465").unwrap(), + // U256::from_dec_str("18122216236568402305988297032517775914181563813086813006164216689752246508886").unwrap(), + // ], + // vec![ + // U256::from_dec_str("7100124544075226034251596932805277307734457677256004047412258693103409543678").unwrap(), + // U256::from_dec_str("9484826513489508497326605298995346628011303684771342589708630141744196880174").unwrap(), + // ], + // ], + // vec![ + // vec![ + // U256::from_dec_str("4294809674390523555755416088340227038268056188806697061914357207030835445784").unwrap(), + // U256::from_dec_str("12772882987652274474928251216882135157601158713560023135442912416889883375009").unwrap(), + // ], + // vec![ + // U256::from_dec_str("5017814360156811257431228283078380210712481496173867244303167538680301406355").unwrap(), + // U256::from_dec_str("5483986251263351055676143301589669624262947345327185314870128974364440001262").unwrap(), + // ] + // ], + // vec![ + // vec![ + // U256::from_dec_str("10485365056956235833573091505977794158366069646492853613385564319176805042067").unwrap(), + // U256::from_dec_str("21560988819791135038184934219494970236802908435926324068683299817562907341696").unwrap(), + // ], + // vec![ + // U256::from_dec_str("9274251274730510866039258353232655161206943117093211738883330925803202790098").unwrap(), + // U256::from_dec_str("19994917632455570632082635510110118222993755636207706143729050502915579896735").unwrap(), + // ] + // ] + // ); + + // let valid_input: Vec = vec![u64s_to_u256(vec![ + // 10518156496175725870, + // 8513656267880232886, + // 1469451646407182009, + // 3425508166019525724 + // ])]; + + // let verifying_key = VerifyingKey::new(proof, vk, valid_input); + + // let zk_verifier = ZKPrecompileVerifier::new( + // H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), + // verifying_key + // ); + + // let encoded_call = zk_verifier.generate_benchmarking_parameters(); + + // let gas_limit_call = 1000000; + // let value = U256::default(); + // let is_transactional = true; + // let validate = true; + // }:{ + // let call_runner_results = ::Runner::call( + // caller, + // contract_address, + // encoded_call, + // value, + // gas_limit_call, + // Some(U256::from(1_000_000_000)), + // Some(U256::from(1_000_000_000)), + // None, + // Vec::new(), + // is_transactional, + // validate, + // ::config(), + // ); + // // log::info!( + // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // // "Benchmarking call end.", + // // ); + // match call_runner_results { + // Ok(info) => { + // let output = info.value; + // // log::info!( + // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // // "output result {:?}", + // // output + // // ); + // if output.len() >= 32 { + // let mut result_bytes = [0u8; 32]; + // result_bytes.copy_from_slice(&output[output.len() - 32..]); + // let result = U256::from_big_endian(&result_bytes); + // // log::info!( + // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // // "nconstraints_900000 Verification result {result:?}", + // // ); + // assert_eq!(result, U256::one(), "The contract did not return true"); + // } + // }, + // Err(e) => { + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "nconstraints_900000 Benchmarking failed", + // ); + // assert!(false, "Benchmarking failed"); + + // } + // } + // } + + // nconstraints_30_input_10 { + // use frame_benchmarking::vec; + // use sp_core::{H160, U256, H256}; + + // let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + // let contract_address = H160::from_low_u64_be(0x8888); + + // let proof = Proof::new( + // vec![ + // U256::from_dec_str("344113499780097036133410144688544669449665038469801025061703634064197059916").unwrap(), + // U256::from_dec_str("8339013355837829034186604529242237434382457535922383671882155606562413431689").unwrap(), + // ], + // vec![ + // vec![ + // U256::from_dec_str("6694199005832176626648387473003377778002164049654344388623160500074797775370").unwrap(), + // U256::from_dec_str("6246558478856965861562784864034844546822126660127014237507763330640717221466").unwrap(), + // ], + // vec![ + // U256::from_dec_str("456859418727494804887897697519797382313397623366843307513728588676215628797").unwrap(), + // U256::from_dec_str("19972929684979882956825623277042855987039264105600158828132263230333203670106").unwrap(), + // ], + // ], + // vec![ + // U256::from_dec_str("8991876521515422964548874095107781976525191569601242691722207742733698821028").unwrap(), + // U256::from_dec_str("17304897036279645989594099459944208131107988079437513579584585106093260802053").unwrap(), + // ] + // ); + + // let vk = VerifyingKeyComponents::new( + // vec![ + // U256::from_dec_str("16587578668155053320776501244706909164198053583863284386206654068019392556543").unwrap(), + // U256::from_dec_str("17489859882312386925030082840618136961844042944104008122175974338708995824981").unwrap(), + // ], + // vec![ + // vec![ + // U256::from_dec_str("8243058085082563940310351321464397410632520885003827137093771369586433446018").unwrap(), + // U256::from_dec_str("1806964369040712598415691188975966807767394918682209427183228092832571919497").unwrap(), + // ], + // vec![ + // U256::from_dec_str("5238575049648595236335310308987023404502439315997088611926714272919127054029").unwrap(), + // U256::from_dec_str("10529242360048105445622302340100671863366518517961350431989359465371013288044").unwrap(), + // ], + // ], + // vec![ + // vec![ + // U256::from_dec_str("422118731661843716781379598081446048950684758761078928178953272944418614265").unwrap(), + // U256::from_dec_str("8071137901873450516865398890359069534977349842235015782367912081100468370342").unwrap(), + // ], + // vec![ + // U256::from_dec_str("6616051543776580097026224309598118359974125974677691608309070965923230091481").unwrap(), + // U256::from_dec_str("3144026861846828201735234261898216197057552604232403108299101704912138104081").unwrap(), + // ], + // ], + // vec![ + // vec![ + // U256::from_dec_str("15967728838725285670062386536689775286816477877862913251436519988213464788203").unwrap(), + // U256::from_dec_str("14482652023948193853731701210376245407114581664800773915003137369238699817066").unwrap(), + // ], + // vec![ + // U256::from_dec_str("20222564526826997580988353930405539667760709452060576182511364617433825375503").unwrap(), + // U256::from_dec_str("1855904408322765948314758770516591135802311025429227172106073057339165107921").unwrap(), + // ] + // ], + // vec![ + // vec![ + // U256::from_dec_str("2234398803815490360326379119253073021265347911436036657996997085101774002925").unwrap(), + // U256::from_dec_str("10214773739303944856355679056757071889148916152665035343340628435407174724717").unwrap(), + // ], + // vec![ + // U256::from_dec_str("21500623561133929663133180424780657403302270303706782392356903439186747104812").unwrap(), + // U256::from_dec_str("19328419280811286038333929820672543691407985372391054082759992875889788951230").unwrap(), + // ] + // ] + // ); + + // let valid_input: Vec = vec![u64s_to_u256(vec![ + // 14321691860995553260, + // 7152862679273281751, + // 12752615512303817990, + // 1576113262537949146 + // ])]; + + // let verifying_key = VerifyingKey::new(proof, vk, valid_input); + + // let zk_verifier = ZKPrecompileVerifier::new( + // H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), + // verifying_key + // ); + + // let encoded_call = zk_verifier.generate_benchmarking_parameters(); + + // let gas_limit_call = 1000000; + // let value = U256::default(); + // let is_transactional = true; + // let validate = true; + // }:{ + // let call_runner_results = ::Runner::call( + // caller, + // contract_address, + // encoded_call, + // value, + // gas_limit_call, + // Some(U256::from(1_000_000_000)), + // Some(U256::from(1_000_000_000)), + // None, + // Vec::new(), + // is_transactional, + // validate, + // ::config(), + // ); + // // log::info!( + // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // // "Benchmarking call end.", + // // ); + // match call_runner_results { + // Ok(info) => { + // let output = info.value; + // // log::info!( + // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // // "output result {:?}", + // // output + // // ); + // if output.len() >= 32 { + // let mut result_bytes = [0u8; 32]; + // result_bytes.copy_from_slice(&output[output.len() - 32..]); + // let result = U256::from_big_endian(&result_bytes); + // // log::info!( + // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // // "nconstraints_30_input_10 Verification result {result:?}", + // // ); + // assert_eq!(result, U256::one(), "The contract did not return true"); + // } + // }, + // Err(e) => { + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "nconstraints_30_input_10 Benchmarking failed", + // ); + // assert!(false, "Benchmarking failed"); + + // } + // } + // } + // nconstraints_30_input_100 { + // use frame_benchmarking::vec; + // use sp_core::{H160, U256, H256}; + + // let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + // let contract_address = H160::from_low_u64_be(0x8888); + + // let proof = Proof::new( + // vec![ + // U256::from_dec_str("3780487311936056381294564418675304364481973966802209296561160829797948105411").unwrap(), + // U256::from_dec_str("12392254879980640223142009257910424254771509444451393927739643876401726307795").unwrap(), + // ], + // vec![ + // vec![ + // U256::from_dec_str("5169548117445173154024813698359426977000013771483410622256640533171985245380").unwrap(), + // U256::from_dec_str("11220449603083268927036844276912830985523128428499468942581840512730495047625").unwrap(), + // ], + // vec![ + // U256::from_dec_str("7617888807668014594076695037395251387521432502213194545531858961238344338860").unwrap(), + // U256::from_dec_str("3206448605631210983027663221710912427383659852717855953276353488187250079459").unwrap(), + // ], + // ], + // vec![ + // U256::from_dec_str("17260938596020642923034443094579912726381749511890996943502017876149586484217").unwrap(), + // U256::from_dec_str("973711408795313031099855712156150142641887502706075552254275664528776194028").unwrap(), + // ] + // ); + + // let vk = VerifyingKeyComponents::new( + // vec![ + // U256::from_dec_str("4155898266631322214574856388057229131381603659142355428000239527171539910720").unwrap(), + // U256::from_dec_str("15919304600573806746067202721026223664629992455130946331020176989460510062648").unwrap(), + // ], + // vec![ + // vec![ + // U256::from_dec_str("10559477888637541108523299513483158185288656601390229631277602982302056830264").unwrap(), + // U256::from_dec_str("21518216923189214839507247102243744126930049565774641401859791113452178471842").unwrap(), + // ], + // vec![ + // U256::from_dec_str("20524972206762616004058259260290957844870248494446046806278424843369643489182").unwrap(), + // U256::from_dec_str("17430943082223119961631960086233630485654941075995072846024219998674392652581").unwrap(), + // ], + // ], + // vec![ + // vec![ + // U256::from_dec_str("4636362103930283526843587215716464395878300635435610009766312980459671398351").unwrap(), + // U256::from_dec_str("15713999866924132629927290621261290205960872899800820372400263081232019214301").unwrap(), + // ], + // vec![ + // U256::from_dec_str("274224283373606674211197218239218941312046485596075799302472837928822177016").unwrap(), + // U256::from_dec_str("10693491445395060496723678108216498586881120243971297703830999940561952271629").unwrap(), + // ], + // ], + // vec![ + // vec![ + // U256::from_dec_str("9540601502504552621404908678855872975596983734893914263055690675850649191273").unwrap(), + // U256::from_dec_str("10288168694112392204164781631687615725045294841966564539511156565183262528849").unwrap(), + // ], + // vec![ + // U256::from_dec_str("16504160099082952601826232467479510151840980336862791499394346450083636791102").unwrap(), + // U256::from_dec_str("9210167978306154509907086298616199856898787966613435045760659519455958969992").unwrap(), + // ] + // ], + // vec![ + // vec![ + // U256::from_dec_str("15812098394101742886061540987450559986219804469912805896076341688421241661621").unwrap(), + // U256::from_dec_str("11920211969663783445335622417572072568292106489672989284415235777753260953099").unwrap(), + // ], + // vec![ + // U256::from_dec_str("7061409000327933635430701054193661775345794014516696263402966093123651666364").unwrap(), + // U256::from_dec_str("17078047162776906089011285464212202278306676406084693061907121919624683442357").unwrap(), + // ] + // ] + // ); + + // let valid_input: Vec = vec![u64s_to_u256(vec![ + // 9831528597301135316, + // 11053911270256492840, + // 14337707091878126846, + // 772611368070892958 + // ])]; + + // let verifying_key = VerifyingKey::new(proof, vk, valid_input); + + // let zk_verifier = ZKPrecompileVerifier::new( + // H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), + // verifying_key + // ); + + // let encoded_call = zk_verifier.generate_benchmarking_parameters(); + + // let gas_limit_call = 1000000; + // let value = U256::default(); + // let is_transactional = true; + // let validate = true; + // }:{ + // let call_runner_results = ::Runner::call( + // caller, + // contract_address, + // encoded_call, + // value, + // gas_limit_call, + // Some(U256::from(1_000_000_000)), + // Some(U256::from(1_000_000_000)), + // None, + // Vec::new(), + // is_transactional, + // validate, + // ::config(), + // ); + // // log::info!( + // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // // "Benchmarking call end.", + // // ); + // match call_runner_results { + // Ok(info) => { + // let output = info.value; + // // log::info!( + // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // // "output result {:?}", + // // output + // // ); + // if output.len() >= 32 { + // let mut result_bytes = [0u8; 32]; + // result_bytes.copy_from_slice(&output[output.len() - 32..]); + // let result = U256::from_big_endian(&result_bytes); + // // log::info!( + // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // // "nconstraints_30_input_100 Verification result {result:?}", + // // ); + // assert_eq!(result, U256::one(), "The contract did not return true"); + // } + // }, + // Err(e) => { + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "nconstraints_30_input_100 Benchmarking failed", + // ); + // assert!(false, "Benchmarking failed"); + // } + // } + // } + // nconstraints_30_input_1000 { + // use frame_benchmarking::vec; + // use sp_core::{H160, U256, H256}; + + // let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + // let contract_address = H160::from_low_u64_be(0x8888); + + // let proof = Proof::new( + // vec![ + // U256::from_dec_str("21424271595387505713049534900676381136649432939050012296331964885140120988520").unwrap(), + // U256::from_dec_str("20488789316104689748479888121024139144355086386496471461763924485714534718686").unwrap(), + // ], + // vec![ + // vec![ + // U256::from_dec_str("8417699613540073682519718294821269056423071880647667978060348740795273915651").unwrap(), + // U256::from_dec_str("4036859279888161250878359321718658739242283134835030699023268489309754993434").unwrap(), + // ], + // vec![ + // U256::from_dec_str("16249800568747110450527363597274431407786919086057853194987169090454936230259").unwrap(), + // U256::from_dec_str("15005851458712291005106538565823270955208428726378749297397203143137382225457").unwrap(), + // ], + // ], + // vec![ + // U256::from_dec_str("21239990703864671714190525785674088715931473556140655107585637961585812134589").unwrap(), + // U256::from_dec_str("261928180985765917331919571442880380998408670702589931014636966043229919418").unwrap(), + // ] + // ); + + // let vk = VerifyingKeyComponents::new( + // vec![ + // U256::from_dec_str("1657406292532781196449359079614579852690925607592278296574718289470803732053").unwrap(), + // U256::from_dec_str("18213557747942747074556848145237207574111244905157024361329330629173034829885").unwrap(), + // ], + // vec![ + // vec![ + // U256::from_dec_str("5419856735820685908218319193906907396496344921642651266629131019868853843815").unwrap(), + // U256::from_dec_str("14007905369450574044915098075029863272475910046750101274280969769181784166430").unwrap(), + // ], + // vec![ + // U256::from_dec_str("182200131698860550444455761364918630551676350878779858078817264277300629723").unwrap(), + // U256::from_dec_str("6050431818377820601319883600432739448105157482353041283628740094609821419656").unwrap(), + // ], + // ], + // vec![ + // vec![ + // U256::from_dec_str("14463567879100083166257564330995533094334991709675023767975192973144798919122").unwrap(), + // U256::from_dec_str("6166287541473141918830331239835928582190744434356526822227225877844349692203").unwrap(), + // ], + // vec![ + // U256::from_dec_str("12512843744533735346513506961399336936527367720771340395643503621530703342395").unwrap(), + // U256::from_dec_str("8394818975982736201521422268641084055810886358791398607930311472872317386487").unwrap(), + // ], + // ], + // vec![ + // vec![ + // U256::from_dec_str("8757732756289429354419510422628896433407345473998310348115924113882282945326").unwrap(), + // U256::from_dec_str("1610185885725147927651201796201713521257480620743342969197368887869230657180").unwrap(), + // ], + // vec![ + // U256::from_dec_str("2834338214415807920713929739507915327763263469562351781747229949754640383374").unwrap(), + // U256::from_dec_str("20761263923134391843554423575366232120525285729512411038267095810712916924016").unwrap(), + // ] + // ], + // vec![ + // vec![ + // U256::from_dec_str("16585432354609922217222548226453277630464695131710476183479619760311567992522").unwrap(), + // U256::from_dec_str("5379258900528839934525784961038010961454863754298062530193947624450477797122").unwrap(), + // ], + // vec![ + // U256::from_dec_str("16825349369326282879106301528709807467071985531593215317852699692046311881677").unwrap(), + // U256::from_dec_str("10540450379202726868409867306854114915477889581096312866635875249145708179576").unwrap(), + // ] + // ] + // ); + + // let valid_input: Vec = vec![u64s_to_u256(vec![ + // 3008789406746563016, + // 7061370202899273426, + // 2191755323004339933, + // 1005591455220622530 + // ])]; + + // let verifying_key = VerifyingKey::new(proof, vk, valid_input); + + // let zk_verifier = ZKPrecompileVerifier::new( + // H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), + // verifying_key + // ); + + // let encoded_call = zk_verifier.generate_benchmarking_parameters(); + + // let gas_limit_call = 1000000; + // let value = U256::default(); + // let is_transactional = true; + // let validate = true; + // }:{ + // let call_runner_results = ::Runner::call( + // caller, + // contract_address, + // encoded_call, + // value, + // gas_limit_call, + // Some(U256::from(1_000_000_000)), + // Some(U256::from(1_000_000_000)), + // None, + // Vec::new(), + // is_transactional, + // validate, + // ::config(), + // ); + // // log::info!( + // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // // "Benchmarking call end.", + // // ); + // match call_runner_results { + // Ok(info) => { + // let output = info.value; + // // log::info!( + // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // // "output result {:?}", + // // output + // // ); + // if output.len() >= 32 { + // let mut result_bytes = [0u8; 32]; + // result_bytes.copy_from_slice(&output[output.len() - 32..]); + // let result = U256::from_big_endian(&result_bytes); + // // log::info!( + // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // // "nconstraints_30_input_1000 Verification result {result:?}", + // // ); + // assert_eq!(result, U256::one(), "The contract did not return true"); + // } + // }, + // Err(e) => { + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "nconstraints_30_input_1000 Benchmarking failed", + // ); + // assert!(false, "Benchmarking failed"); + // } + // } + // } + // nconstraints_30_input_5000 { + // use frame_benchmarking::vec; + // use sp_core::{H160, U256, H256}; + + // let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + // let contract_address = H160::from_low_u64_be(0x8888); + + // let proof = Proof::new( + // vec![ + // U256::from_dec_str("4760178114933307527976205229418881302833473087272893863010681924222436742436").unwrap(), + // U256::from_dec_str("6555056836023646163359279772724076765411780318148657506988760187885700674215").unwrap(), + // ], + // vec![ + // vec![ + // U256::from_dec_str("9540205596737585525189386078607957630969059503165883907845238817662495399607").unwrap(), + // U256::from_dec_str("21777913747079267536001051597001736802905779914683258171463923506869689358122").unwrap(), + // ], + // vec![ + // U256::from_dec_str("7652162643714058076103867092157642519402862581818067281609790687905833151647").unwrap(), + // U256::from_dec_str("5174136241284192352871549806655421810249317805219641765935618077180420544939").unwrap(), + // ], + // ], + // vec![ + // U256::from_dec_str("9633653417112713107386510132385608824105920168790226750481878454006412372444").unwrap(), + // U256::from_dec_str("5600932933208824148570351176368803282808856587672889614186338874655752173453").unwrap(), + // ] + // ); + + // let vk = VerifyingKeyComponents::new( + // vec![ + // U256::from_dec_str("20563201722283471489193032980811350162387466733119686723832100493505332037220").unwrap(), + // U256::from_dec_str("458683337854426284881131074995322438618437423037306322290239745015633774839").unwrap(), + // ], + // vec![ + // vec![ + // U256::from_dec_str("802687519037697530569139206036966996588449135138601551566343295868421688400").unwrap(), + // U256::from_dec_str("10902489968444563758310974921240106861656913905085710523025258522577834664814").unwrap(), + // ], + // vec![ + // U256::from_dec_str("8163282908300075270434111132545381898266738500810094061899946027883982232155").unwrap(), + // U256::from_dec_str("2879234862354419255322548813414679750617024208122660306082351289172177493856").unwrap(), + // ], + // ], + // vec![ + // vec![ + // U256::from_dec_str("12946416399098615767859440028401625777970463338055590127763655113029764523456").unwrap(), + // U256::from_dec_str("19000556224902286061769815260124368973839417953399533885850283592096662743016").unwrap(), + // ], + // vec![ + // U256::from_dec_str("16883066945921282046110808795753929362007100542422795769422243319629113077450").unwrap(), + // U256::from_dec_str("3229017908221308993692674040951942449106283130433174678816420254626513367678").unwrap(), + // ], + // ], + // vec![ + // vec![ + // U256::from_dec_str("16459854676924169388774046538295013154707390397685062918225181412137603478923").unwrap(), + // U256::from_dec_str("20996869365345436816737319903210535785982053153529758285286719146777762981985").unwrap(), + // ], + // vec![ + // U256::from_dec_str("21446959969822179574296836241978980045198577120638747119902976563053247153220").unwrap(), + // U256::from_dec_str("4716297282146551186330252875195511360280503254452482577157100992033023717484").unwrap(), + // ] + // ], + // vec![ + // vec![ + // U256::from_dec_str("2127664998061023131080125201643658604092063304061707222326237054428506173927").unwrap(), + // U256::from_dec_str("13918137729545385379467184110597023571257121066683873930760549927318081992996").unwrap(), + // ], + // vec![ + // U256::from_dec_str("16560640526003408304721205785917894782070253870764339317137905014294472374327").unwrap(), + // U256::from_dec_str("19394535992291030838186763750684977819230291410826312937425829210188321257228").unwrap(), + // ] + // ] + // ); + + // let valid_input: Vec = vec![u64s_to_u256(vec![ + // 13212982172557049181, + // 17043673098390055166, + // 13971391527459105160, + // 1729491887349651790, + // ])]; + + // let verifying_key = VerifyingKey::new(proof, vk, valid_input); + + // let zk_verifier = ZKPrecompileVerifier::new( + // H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), + // verifying_key + // ); + + // let encoded_call = zk_verifier.generate_benchmarking_parameters(); + + // let gas_limit_call = 1000000; + // let value = U256::default(); + // let is_transactional = true; + // let validate = true; + // }:{ + // let call_runner_results = ::Runner::call( + // caller, + // contract_address, + // encoded_call, + // value, + // gas_limit_call, + // Some(U256::from(1_000_000_000)), + // Some(U256::from(1_000_000_000)), + // None, + // Vec::new(), + // is_transactional, + // validate, + // ::config(), + // ); + // // log::info!( + // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // // "Benchmarking call end.", + // // ); + // match call_runner_results { + // Ok(info) => { + // let output = info.value; + // // log::info!( + // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // // "output result {:?}", + // // output + // // ); + // if output.len() >= 32 { + // let mut result_bytes = [0u8; 32]; + // result_bytes.copy_from_slice(&output[output.len() - 32..]); + // let result = U256::from_big_endian(&result_bytes); + // // log::info!( + // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // // "nconstraints_30_input_5000 Verification result {result:?}", + // // ); + // assert_eq!(result, U256::one(), "The contract did not return true"); + // } + // }, + // Err(e) => { + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "nconstraints_30_input_5000 Benchmarking failed", + // ); + // assert!(false, "Benchmarking failed"); + // } + // } + // } + // nconstraints_30_input_10000 { + // use frame_benchmarking::vec; + // use sp_core::{H160, U256, H256}; + + // let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + // let contract_address = H160::from_low_u64_be(0x8888); + + // let proof = Proof::new( + // vec![ + // U256::from_dec_str("20201588552006483041582128307591335561381558661958982754827324334159524114833").unwrap(), + // U256::from_dec_str("17768889616334897699714190449991059857597665579001510168911964966707846254013").unwrap(), + // ], + // vec![ + // vec![ + // U256::from_dec_str("831427914683469755258685737297441858923030844026909228595596228891513784401").unwrap(), + // U256::from_dec_str("17358733390631981546461856303504163975689822422160671163593908204299387350560").unwrap(), + // ], + // vec![ + // U256::from_dec_str("12673178383954759426828314411760863182427996098705680584931403917390222262168").unwrap(), + // U256::from_dec_str("12056092533572380482681874959737292916971452073896642753405050795241584080793").unwrap(), + // ], + // ], + // vec![ + // U256::from_dec_str("11086630979744216291689656728938462056245402184490217943698398792953833540899").unwrap(), + // U256::from_dec_str("6981043472993913602669753829495794560155248771335035866541870305230603679484").unwrap(), + // ] + // ); + + // let vk = VerifyingKeyComponents::new( + // vec![ + // U256::from_dec_str("10088605449330278081588905225706913827985798761474642054412607299987851491561").unwrap(), + // U256::from_dec_str("12349112716571349951448807635426375878752472531266562453302627732729311140226").unwrap(), + // ], + // vec![ + // vec![ + // U256::from_dec_str("11234930657858483584603353214391341220392609835907149947974795594440445721655").unwrap(), + // U256::from_dec_str("1047093079337214465686469751128183347143657884406521365857439579470759333731").unwrap(), + // ], + // vec![ + // U256::from_dec_str("15864899975231343872664645828141071246029692141564279838230890638453916423742").unwrap(), + // U256::from_dec_str("12053277475368564348616897081746431255423835262329161057768339971384736640081").unwrap(), + // ], + // ], + // vec![ + // vec![ + // U256::from_dec_str("20662189442791195318296211376162761628558291902545582141646463139520777475283").unwrap(), + // U256::from_dec_str("9279465006661849499753241364514057268552316193158700659184124742215268752791").unwrap(), + // ], + // vec![ + // U256::from_dec_str("17033606864312833588672465768726096906720807717470346504048425104291392352898").unwrap(), + // U256::from_dec_str("15319242533246792039334613039385600689133248724151496600840914674340560979641").unwrap(), + // ], + // ], + // vec![ + // vec![ + // U256::from_dec_str("3303817333656562581428241644233610206796391323593261940899405821542387319372").unwrap(), + // U256::from_dec_str("12434486975702473910116656089923156849733601159782506519440013280731025013736").unwrap(), + // ], + // vec![ + // U256::from_dec_str("9561232329300105849651786447909752108987569955850131116304832039966768267007").unwrap(), + // U256::from_dec_str("18486557213071145739422364713271115450952939790314495487369777335095317193174").unwrap(), + // ] + // ], + // vec![ + // vec![ + // U256::from_dec_str("5864321703423906069527768678401445332135246771872328360194332677453860634867").unwrap(), + // U256::from_dec_str("3305620141441221125469209629518919979790470359050105194093502369856652644459").unwrap(), + // ], + // vec![ + // U256::from_dec_str("1810088252629429255118238329671475280643793553294287131634484491846973310510").unwrap(), + // U256::from_dec_str("20707970746663158481851347112547705553728126185220754421254503093218351233120").unwrap(), + // ] + // ] + // ); + + // let valid_input: Vec = vec![u64s_to_u256(vec![ + // 11033755416221607095, + // 14172640425079373737, + // 17268699570210893519, + // 2451003838444787962, + // ])]; + + // let verifying_key = VerifyingKey::new(proof, vk, valid_input); + + // let zk_verifier = ZKPrecompileVerifier::new( + // H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), + // verifying_key + // ); + + // let encoded_call = zk_verifier.generate_benchmarking_parameters(); + + // let gas_limit_call = 1000000; + // let value = U256::default(); + // let is_transactional = true; + // let validate = true; + // }:{ + // let call_runner_results = ::Runner::call( + // caller, + // contract_address, + // encoded_call, + // value, + // gas_limit_call, + // Some(U256::from(1_000_000_000)), + // Some(U256::from(1_000_000_000)), + // None, + // Vec::new(), + // is_transactional, + // validate, + // ::config(), + // ); + // // log::info!( + // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // // "Benchmarking call end.", + // // ); + // match call_runner_results { + // Ok(info) => { + // let output = info.value; + // // log::info!( + // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // // "output result {:?}", + // // output + // // ); + // if output.len() >= 32 { + // let mut result_bytes = [0u8; 32]; + // result_bytes.copy_from_slice(&output[output.len() - 32..]); + // let result = U256::from_big_endian(&result_bytes); + // // log::info!( + // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // // "nconstraints_30_input_10000 Verification result {result:?}", + // // ); + // assert_eq!(result, U256::one(), "The contract did not return true"); + // } + // }, + // Err(e) => { + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "nconstraints_30_input_10000 Benchmarking failed", + // ); + // assert!(false, "Benchmarking failed"); + + // } + // } + // } + // nconstraints_30_input_90000 { + // use frame_benchmarking::vec; + // use sp_core::{H160, U256, H256}; + + // let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + // let contract_address = H160::from_low_u64_be(0x8888); + + // let proof = Proof::new( + // vec![ + // U256::from_dec_str("7949275001087845673352113652992317737416671749823042856819742064958185730665").unwrap(), + // U256::from_dec_str("5891863541401068443747112095836743353338477825995666306081231182884954636005").unwrap(), + // ], + // vec![ + // vec![ + // U256::from_dec_str("12960565378826264234747222392568347150301360486418725511109506548813034322775").unwrap(), + // U256::from_dec_str("6924824876048701587380679111548259437770370772320848338373383587483809707515").unwrap(), + // ], + // vec![ + // U256::from_dec_str("21689747160304810742710652756166876177223750769696622871469266436845305438116").unwrap(), + // U256::from_dec_str("14167066926549192557125941689316913820167617731059401320567819691908586156039").unwrap(), + // ], + // ], + // vec![ + // U256::from_dec_str("19186797317064887099470636752510606772753033946198593325337771098325482447274").unwrap(), + // U256::from_dec_str("3350186543680262034371474397706130211690310055235028696466009478959025709845").unwrap(), + // ] + // ); + + // let vk = VerifyingKeyComponents::new( + // vec![ + // U256::from_dec_str("6828794497030502754628523747507406719479438181845328406281207577196379759609").unwrap(), + // U256::from_dec_str("5561027388439947090438746111225212164455366280326670821700904471009784329896").unwrap(), + // ], + // vec![ + // vec![ + // U256::from_dec_str("1648517694167305339737563900225685665396551354808983529387892872646841040850").unwrap(), + // U256::from_dec_str("15406833006990307743521713564090315343374212223020060642984366610793788667116").unwrap(), + // ], + // vec![ + // U256::from_dec_str("14591594646846027404699868040454897990147675572067174007423843530180728597612").unwrap(), + // U256::from_dec_str("2940958434778941597191243007999700895445672570190450648227198352981565653913").unwrap(), + // ], + // ], + // vec![ + // vec![ + // U256::from_dec_str("7676142418543194845482248509044991512324196983308812731866772308356979871307").unwrap(), + // U256::from_dec_str("21511013842679919895947796523736214038726875927496967606596253311081756690725").unwrap(), + // ], + // vec![ + // U256::from_dec_str("4652378032872178978450279958290699982888059033676566152376150880744787185780").unwrap(), + // U256::from_dec_str("467504210088082002071026778234767679654059202832780062786965483300786044530").unwrap(), + // ], + // ], + // vec![ + // vec![ + // U256::from_dec_str("20744282071154891204049714936088748576694067059171789505913191933597423689555").unwrap(), + // U256::from_dec_str("12596866572762256583276410876169296807308160857887657727882625055041251553242").unwrap(), + // ], + // vec![ + // U256::from_dec_str("3588798969790877834321031026222278845206273301850566393834657489341158616535").unwrap(), + // U256::from_dec_str("19268326464935908053037454129640878232926568425004490855381855273084219557079").unwrap(), + // ] + // ], + // vec![ + // vec![ + // U256::from_dec_str("10928515506460596401961934744263657631726985113185854450754018401146226707446").unwrap(), + // U256::from_dec_str("1043421123157233618994554398894819122012315878788274412803269234825060696656").unwrap(), + // ], + // vec![ + // U256::from_dec_str("21802758012415709270812560952687831790545411568500639317690833457802568775035").unwrap(), + // U256::from_dec_str("8926874931677263335476856545765471099163606107894025045476086328360781102193").unwrap(), + // ] + // ] + // ); + + // let valid_input: Vec = vec![u64s_to_u256(vec![ + // 2553457387449696641, + // 815105491620421980, + // 17800546104409657428, + // 2866567216183504159, + // ])]; + + // let verifying_key = VerifyingKey::new(proof, vk, valid_input); + + // let zk_verifier = ZKPrecompileVerifier::new( + // H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), + // verifying_key + // ); + + // let encoded_call = zk_verifier.generate_benchmarking_parameters(); + + // let gas_limit_call = 1000000; + // let value = U256::default(); + // let is_transactional = true; + // let validate = true; + // }:{ + // let call_runner_results = ::Runner::call( + // caller, + // contract_address, + // encoded_call, + // value, + // gas_limit_call, + // Some(U256::from(1_000_000_000)), + // Some(U256::from(1_000_000_000)), + // None, + // Vec::new(), + // is_transactional, + // validate, + // ::config(), + // ); + // // log::info!( + // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // // "Benchmarking call end.", + // // ); + // match call_runner_results { + // Ok(info) => { + // let output = info.value; + // // log::info!( + // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // // "output result {:?}", + // // output + // // ); + // if output.len() >= 32 { + // let mut result_bytes = [0u8; 32]; + // result_bytes.copy_from_slice(&output[output.len() - 32..]); + // let result = U256::from_big_endian(&result_bytes); + // // log::info!( + // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // // "nconstraints_30_input_90000 Verification result {result:?}", + // // ); + // assert_eq!(result, U256::one(), "The contract did not return true"); + // } + // }, + // Err(e) => { + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "nconstraints_30_input_90000 Benchmarking failed", + // ); + // assert!(false, "Benchmarking failed"); + // } + // } + // } + // nconstraints_30_input_200000 { + // use frame_benchmarking::vec; + // use sp_core::{H160, U256, H256}; + + // let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + // let contract_address = H160::from_low_u64_be(0x8888); + + // let proof = Proof::new( + // vec![ + // U256::from_dec_str("19903885251949679146607224162906437591286076549652044731739108226015926915860").unwrap(), + // U256::from_dec_str("11870922578907159231760438847634888925027596611865086487008358810346509550746").unwrap(), + // ], + // vec![ + // vec![ + // U256::from_dec_str("7572350741301793140585595336451242554319145556316993930579910816773197602180").unwrap(), + // U256::from_dec_str("16166630091911008518878343585755669995589761813810965163203815419554661335912").unwrap(), + // ], + // vec![ + // U256::from_dec_str("10479558631339350148140324543423297113164179377516410954282474094862685762111").unwrap(), + // U256::from_dec_str("1538599836393367534859442557225095989831507256094436416355361165563840234277").unwrap(), + // ], + // ], + // vec![ + // U256::from_dec_str("18566368172831132986640612657510108843544042128267080758083569019690510537842").unwrap(), + // U256::from_dec_str("14637144036179606956000163117625168358523245864386632910728645092984303842870").unwrap(), + // ] + // ); + + // let vk = VerifyingKeyComponents::new( + // vec![ + // U256::from_dec_str("3388366987275268645608688601800038483480506575351380219459271970783548315310").unwrap(), + // U256::from_dec_str("10139982329791419477606385196757134153200700293861474061701578521738893563314").unwrap(), + // ], + // vec![ + // vec![ + // U256::from_dec_str("17293003127353596916845398615566872053529832484770184120881889494052646686398").unwrap(), + // U256::from_dec_str("3746742577904007471872553744363212404516454459540143078991207693255568088158").unwrap(), + // ], + // vec![ + // U256::from_dec_str("18996426015092705424501193523094438770040629737761363033585766320236602756452").unwrap(), + // U256::from_dec_str("5993252813486169444483155589566709251331252167093428959716521680127596688663").unwrap(), + // ], + // ], + // vec![ + // vec![ + // U256::from_dec_str("86221489590459042456285770827248107701675460052532768290239949641616327672").unwrap(), + // U256::from_dec_str("21618235778373592971185937996314200926578828337383413751502402964191761009384").unwrap(), + // ], + // vec![ + // U256::from_dec_str("10453895050472290645179709462208119639593757329666114205922088367970822668124").unwrap(), + // U256::from_dec_str("16924749634830145681809164670725933237166438445526123149706427927968513710893").unwrap(), + // ], + // ], + // vec![ + // vec![ + // U256::from_dec_str("20506347836984398194650179863264269358088067779451739307543701941138658771117").unwrap(), + // U256::from_dec_str("15256122081275324863091225387225218399888282841698960666742408225921079848693").unwrap(), + // ], + // vec![ + // U256::from_dec_str("7881380592415293900063452944037916715621668238658562838630198037249553436647").unwrap(), + // U256::from_dec_str("6003465274284900873747728448177380007802003937728590930467990944623586277089").unwrap(), + // ] + // ], + // vec![ + // vec![ + // U256::from_dec_str("5531662187275540864474040102019845108669876235687831703751327129559212127084").unwrap(), + // U256::from_dec_str("11455786949456856409363436892267690994602451302132959153447251790964376014822").unwrap(), + // ], + // vec![ + // U256::from_dec_str("17221728819314881853232886080533000381382340762620795831983019279828981481257").unwrap(), + // U256::from_dec_str("19341881794793455210912817199750586531241336493382870655971958667936340901503").unwrap(), + // ] + // ] + // ); + + // let valid_input: Vec = vec![u64s_to_u256(vec![ + // 17510768071209558285, + // 11281672863963944712, + // 17936011136389338927, + // 2683423138755332222, + // ])]; + + // let verifying_key = VerifyingKey::new(proof, vk, valid_input); + + // let zk_verifier = ZKPrecompileVerifier::new( + // H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), + // verifying_key + // ); + + // let encoded_call = zk_verifier.generate_benchmarking_parameters(); + + // let gas_limit_call = 1000000; + // let value = U256::default(); + // let is_transactional = true; + // let validate = true; + // }:{ + // let call_runner_results = ::Runner::call( + // caller, + // contract_address, + // encoded_call, + // value, + // gas_limit_call, + // Some(U256::from(1_000_000_000)), + // Some(U256::from(1_000_000_000)), + // None, + // Vec::new(), + // is_transactional, + // validate, + // ::config(), + // ); + // // log::info!( + // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // // "Benchmarking call end.", + // // ); + // match call_runner_results { + // Ok(info) => { + // let output = info.value; + // // log::info!( + // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // // "output result {:?}", + // // output + // // ); + // if output.len() >= 32 { + // let mut result_bytes = [0u8; 32]; + // result_bytes.copy_from_slice(&output[output.len() - 32..]); + // let result = U256::from_big_endian(&result_bytes); + // // log::info!( + // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // // "nconstraints_30_input_200000 Verification result {result:?}", + // // ); + // assert_eq!(result, U256::one(), "The contract did not return true"); + // } + // }, + // Err(e) => { + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "nconstraints_30_input_200000 Benchmarking failed", + // ); + // assert!(false, "Benchmarking failed"); + // } + // } + // } + + // sum_10 { + // use frame_benchmarking::vec; + // use sp_core::{H160, U256, H256}; + + // let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + // let contract_address = H160::from_low_u64_be(0x8888); + + // let proof = Proof::new( + // vec![ + // U256::from_dec_str("4479438672593572194843316486259284641920166054544576564310150763796220593742").unwrap(), + // U256::from_dec_str("5717857931841301866217201485541887040818093727574311517591849036289507799141").unwrap(), + // ], + // vec![ + // vec![ + // U256::from_dec_str("438102211713357984070931589322877643391719193099221891191956755149301376056").unwrap(), + // U256::from_dec_str("14696299438400225528910058565202329177181471318954607581306780544413371767738").unwrap(), + // ], + // vec![ + // U256::from_dec_str("18723112929967827488252389384208353884816003870032279933823625467146809072448").unwrap(), + // U256::from_dec_str("781225142569358922067919798403956593420009838230922093237868933021043854113").unwrap(), + // ], + // ], + // vec![ + // U256::from_dec_str("10481213903673023503381125372528754955378591812884098928519623211332171467098").unwrap(), + // U256::from_dec_str("15098195705682978185145469811146985310923026878303775073727891846327587112885").unwrap(), + // ] + // ); + + // let vk = VerifyingKeyComponents::new( + // vec![ + // U256::from_dec_str("10600514820627226711889163536575359330497844540484876797299835164575096986123").unwrap(), + // U256::from_dec_str("8955505242614929800342716899005854501255692108538633212406728467939250778259").unwrap(), + // ], + // vec![ + // vec![ + // U256::from_dec_str("11358515176167160981846987587695931342878788452018419590778128561277894807040").unwrap(), + // U256::from_dec_str("7367100375568995524851051084377016949291621141008718892167611998460177966556").unwrap(), + // ], + // vec![ + // U256::from_dec_str("9986374126991936592889887298811366506288970021158383914729072242552712258999").unwrap(), + // U256::from_dec_str("5917047061876555575617149777207682047359711575786648519096749890796145313142").unwrap(), + // ], + // ], + // vec![ + // vec![ + // U256::from_dec_str("12470512550870605078154922234115021580073605821744497867586706681115325377951").unwrap(), + // U256::from_dec_str("3964373607930903502336465614571930627592350216968107805643078708599943392195").unwrap(), + // ], + // vec![ + // U256::from_dec_str("9054619931591683490625148848351137928205510101241639415537408964292455344707").unwrap(), + // U256::from_dec_str("14433710971468466044075036729227299898791551573181475688890434779549865103322").unwrap(), + // ] + // ], + // vec![ + // vec![ + // U256::from_dec_str("13008751738470482081156013535203222043379316308698376931322848604706786065862").unwrap(), + // U256::from_dec_str("3415558414191757405655644967374577939532374518318643852418890898323033638525").unwrap(), + // ], + // vec![ + // U256::from_dec_str("2104722493853714523712648261788727756558190509825976396834309269877977849365").unwrap(), + // U256::from_dec_str("6877732520157662584755946842350755740172704606349660337522459938993730313391").unwrap(), + // ], + // ], + // vec![ + // vec![ + // U256::from_dec_str("17691779713798847872985546462247707503645016076661816616388979822201176829753").unwrap(), + // U256::from_dec_str("14451231434311244057691431183198403713720423327382654964068207207079455187712").unwrap(), + // ], + // vec![ + // U256::from_dec_str("13620414910695185146987530463229819484652710069270717148541433045978322585419").unwrap(), + // U256::from_dec_str("10875872907505029426874795808985164080699672034676409959252328566889297105865").unwrap(), + // ] + // ] + // ); + + // let valid_input = vec![ + // U256::from_dec_str("55").unwrap() + // ]; + + // let verifying_key = VerifyingKey::new(proof, vk, valid_input); + + // let zk_verifier = ZKPrecompileVerifier::new( + // H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), + // verifying_key + // ); + + // let encoded_call = zk_verifier.generate_benchmarking_parameters(); + + // let gas_limit_call = 1000000; + // let value = U256::default(); + // let is_transactional = true; + // let validate = true; + // }:{ + // let call_runner_results = ::Runner::call( + // caller, + // contract_address, + // encoded_call, + // value, + // gas_limit_call, + // Some(U256::from(1_000_000_000)), + // Some(U256::from(1_000_000_000)), + // None, + // Vec::new(), + // is_transactional, + // validate, + // ::config(), + // ); + // // log::info!( + // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // // "Benchmarking call end.", + // // ); + // match call_runner_results { + // Ok(info) => { + // let output = info.value; + // // log::info!( + // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // // "output result {:?}", + // // output + // // ); + // if output.len() >= 32 { + // let mut result_bytes = [0u8; 32]; + // result_bytes.copy_from_slice(&output[output.len() - 32..]); + // let result = U256::from_big_endian(&result_bytes); + // // log::info!( + // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // // "sum_10 Verification result {result:?}", + // // ); + // assert_eq!(result, U256::one(), "The contract did not return true"); + // } + // }, + // Err(e) => { + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "sum_10Benchmarking failed", + // ); + // assert!(false, "Benchmarking failed"); + // } + // } + // } + // sum_50 { + // use frame_benchmarking::vec; + // use sp_core::{H160, U256, H256}; + + // let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + // let contract_address = H160::from_low_u64_be(0x8888); + + // let proof = Proof::new( + // vec![ + // U256::from_dec_str("3114941071688532747454764921300681791980888248199392522675009157778549895455").unwrap(), + // U256::from_dec_str("6816680925124829082835883802586391663161606011222680818599486084577544527516").unwrap(), + // ], + // vec![ + // vec![ + // U256::from_dec_str("15037393792780247314317740287895838240941967969445981241792818111317913065010").unwrap(), + // U256::from_dec_str("3834028682995799272226496422556310257938795862629020590068471611902272764146").unwrap(), + // ], + // vec![ + // U256::from_dec_str("4023883034822047449129381158539093978377425715903419218696272130851521242085").unwrap(), + // U256::from_dec_str("13058906875228264286034925941047330220503025517973111955115072416984072943122").unwrap(), + // ], + // ], + // vec![ + // U256::from_dec_str("5344888056894889487007260648469199417556856955544355154291642477677322944786").unwrap(), + // U256::from_dec_str("19843194668352645797068691966948915569058668700830773246420232986019393210063").unwrap(), + // ] + // ); + + // let vk = VerifyingKeyComponents::new( + // vec![ + // U256::from_dec_str("19257923683733118221652593587810195852599358412856281104090957905722976964370").unwrap(), + // U256::from_dec_str("19519729727735873999148754136012144616045305047716967685280834855818506563720").unwrap(), + // ], + // vec![ + // vec![ + // U256::from_dec_str("4418606700813566482216037680863387214037640478555893901955308344977554198718").unwrap(), + // U256::from_dec_str("18046767849922558936185002168253454007598159984067380537392936220227127228867").unwrap(), + // ], + // vec![ + // U256::from_dec_str("100725403545603844224319783153051757027683253433977048289134569498829183303").unwrap(), + // U256::from_dec_str("9785321212288652698655727476617710557399711491394256119637648908536562741634").unwrap(), + // ], + // ], + // vec![ + // vec![ + // U256::from_dec_str("7184324332054694882815451883063466258810341506246659357034202660488015984306").unwrap(), + // U256::from_dec_str("14398081398842334723334363407187040569418119441776629783632309768037771007327").unwrap(), + // ], + // vec![ + // U256::from_dec_str("17277213124622419955089087696435667358779233792945822269342368397066818801481").unwrap(), + // U256::from_dec_str("19811781065417531456401229702422997450338397507283920558741452740912313583930").unwrap(), + // ] + // ], + // vec![ + // vec![ + // U256::from_dec_str("1627724482578854283892192357407161928314687375966263116172485631707694669812").unwrap(), + // U256::from_dec_str("6839802000376483025048211234449253336394632788399066904541666906747650234382").unwrap(), + // ], + // vec![ + // U256::from_dec_str("17974577137954059751166162247265070307968439813726452160113109110701162631938").unwrap(), + // U256::from_dec_str("21289972529626386698860098501676961527414208445147370800462053148477683157991").unwrap(), + // ], + // ], + // vec![ + // vec![ + // U256::from_dec_str("20284064245383237908740484779775789109386762825985839657586769414934584661714").unwrap(), + // U256::from_dec_str("17363934481847560975462360104367791101351872886050159351690589725380050257409").unwrap(), + // ], + // vec![ + // U256::from_dec_str("3904403738619431633601997032597659843284744078768864151280168218762434423692").unwrap(), + // U256::from_dec_str("4413868989856264583489102855186788724178233679332360263809134874064797750675").unwrap(), + // ] + // ] + // ); + + // let valid_input = vec![ + // U256::from_dec_str("1275").unwrap(), + // ]; + + // let verifying_key = VerifyingKey::new(proof, vk, valid_input); + + // let zk_verifier = ZKPrecompileVerifier::new( + // H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), + // verifying_key + // ); + + // let encoded_call = zk_verifier.generate_benchmarking_parameters(); + + // let gas_limit_call = 1000000; + // let value = U256::default(); + // let is_transactional = true; + // let validate = true; + // }:{ + // let call_runner_results = ::Runner::call( + // caller, + // contract_address, + // encoded_call, + // value, + // gas_limit_call, + // Some(U256::from(1_000_000_000)), + // Some(U256::from(1_000_000_000)), + // None, + // Vec::new(), + // is_transactional, + // validate, + // ::config(), + // ); + // // log::info!( + // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // // "Benchmarking call end.", + // // ); + // match call_runner_results { + // Ok(info) => { + // let output = info.value; + // // log::info!( + // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // // "output result {:?}", + // // output + // // ); + // if output.len() >= 32 { + // let mut result_bytes = [0u8; 32]; + // result_bytes.copy_from_slice(&output[output.len() - 32..]); + // let result = U256::from_big_endian(&result_bytes); + // // log::info!( + // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // // "sum_50 Verification result {result:?}", + // // ); + // assert_eq!(result, U256::one(), "The contract did not return true"); + // } + // }, + // Err(e) => { + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "sum_50 Benchmarking failed", + // ); + // assert!(false, "Benchmarking failed"); + // } + // } + // } + + // sum_5000 { + // use frame_benchmarking::vec; + // use sp_core::{H160, U256, H256}; + + // let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + // let contract_address = H160::from_low_u64_be(0x8888); + + // let proof = Proof::new( + // vec![ + // U256::from_dec_str("2104134032972066019913571175532882184351637942839921828138208604817397790978").unwrap(), + // U256::from_dec_str("12625149522977248086293073767826715132905823679345516244316272790389621024575").unwrap(), + // ], + // vec![ + // vec![ + // U256::from_dec_str("18955718237898317556602416465218566057031982163829528123671300051574728240883").unwrap(), + // U256::from_dec_str("18075306515520608621953959878874546391551215874677138383864573851396832159644").unwrap(), + // ], + // vec![ + // U256::from_dec_str("3166476742865671627115278436666969186969644878053983393309132722947819232105").unwrap(), + // U256::from_dec_str("8051049247607109861344268872842958063551670273736053865524986958976361214062").unwrap(), + // ], + // ], + // vec![ + // U256::from_dec_str("4814291763265323888812051590287571407031542635142019809665068757723218701627").unwrap(), + // U256::from_dec_str("17930948070313125851452005455953009375012074818817251382455220462443054837203").unwrap(), + // ] + // ); + + // let vk = VerifyingKeyComponents::new( + // vec![ + // U256::from_dec_str("19624232987744880202266197753309961915632611879850947888541508003701736644214").unwrap(), + // U256::from_dec_str("5019843555387010050200067558096501184079196549422645876015184268981691000261").unwrap(), + // ], + // vec![ + // vec![ + // U256::from_dec_str("5150307298606577026396875555180704696345763655981810466632357002439129266461").unwrap(), + // U256::from_dec_str("3020656302335648031712857271727816386298675153130933709481311850060508289333").unwrap(), + // ], + // vec![ + // U256::from_dec_str("19547576195358452722114991449875886954598568010341500952076854329553571219720").unwrap(), + // U256::from_dec_str("3895331072082263654317901227968966808293407907751128382134753194859731114729").unwrap(), + // ], + // ], + // vec![ + // vec![ + // U256::from_dec_str("5792479463369352075979003547777370241697788651005116088867026457677720533395").unwrap(), + // U256::from_dec_str("16882159064341957118950974052606760693554763076237663579029547802558086431378").unwrap(), + // ], + // vec![ + // U256::from_dec_str("15201299876801474331768851307298179430198466709727112330042020251492139993850").unwrap(), + // U256::from_dec_str("893863620414771464835789333501093176356026692988850717670551586498757709875").unwrap(), + // ] + // ], + // vec![ + // vec![ + // U256::from_dec_str("165136411129701665870237237981894748637834826722462614973940945603783242464").unwrap(), + // U256::from_dec_str("10766657827945181878791518932726777890925519579254084496220957371082172349194").unwrap(), + // ], + // vec![ + // U256::from_dec_str("1813485593016293809685571822392302147347136682526622353828238069063634409991").unwrap(), + // U256::from_dec_str("12730118542350484957903782401323352413406115135420607527656226977122246298735").unwrap(), + // ], + // ], + // vec![ + // vec![ + // U256::from_dec_str("19450458898299554306247087083239008884256452312356497246598109368644839627523").unwrap(), + // U256::from_dec_str("123992241310851816418828784530061727329258706748227789362318537744292975333").unwrap(), + // ], + // vec![ + // U256::from_dec_str("1650700423026830428199086201346242616543834285406293983963791012821269466913").unwrap(), + // U256::from_dec_str("3152920600939501404817148774751227981988970987313622659392580888754616114976").unwrap(), + // ] + // ] + // ); + + // let valid_input = vec![ + // U256::from_dec_str("12502500").unwrap(), + // ]; + + // let verifying_key = VerifyingKey::new(proof, vk, valid_input); + + // let zk_verifier = ZKPrecompileVerifier::new( + // H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), + // verifying_key + // ); + + // let encoded_call = zk_verifier.generate_benchmarking_parameters(); + + // let gas_limit_call = 1000000; + // let value = U256::default(); + // let is_transactional = true; + // let validate = true; + // }:{ + // let call_runner_results = ::Runner::call( + // caller, + // contract_address, + // encoded_call, + // value, + // gas_limit_call, + // Some(U256::from(1_000_000_000)), + // Some(U256::from(1_000_000_000)), + // None, + // Vec::new(), + // is_transactional, + // validate, + // ::config(), + // ); + // // log::info!( + // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // // "Benchmarking call end.", + // // ); + // match call_runner_results { + // Ok(info) => { + // let output = info.value; + // // log::info!( + // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // // "output result {:?}", + // // output + // // ); + // if output.len() >= 32 { + // let mut result_bytes = [0u8; 32]; + // result_bytes.copy_from_slice(&output[output.len() - 32..]); + // let result = U256::from_big_endian(&result_bytes); + // // log::info!( + // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // // "sum_5000 Verification result {result:?}", + // // ); + // assert_eq!(result, U256::one(), "The contract did not return true"); + // } + // }, + // Err(e) => { + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "sum_5000 Benchmarking failed", + // ); + // assert!(false, "Benchmarking failed"); + // } + // } + // } + + // sum_50000 { + // use frame_benchmarking::vec; + // use sp_core::{H160, U256, H256}; + + // let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + // let contract_address = H160::from_low_u64_be(0x8888); + + // let proof = Proof::new( + // vec![ + // U256::from_dec_str("10521560297681522924956535552101557954055377883537271587209095331672512231293").unwrap(), + // U256::from_dec_str("3686654512637749683446869119197341068039068905923579159423036344564025864377").unwrap(), + // ], + // vec![ + // vec![ + // U256::from_dec_str("4890395955490088627121586512165392468998481877071173820388882318632254821251").unwrap(), + // U256::from_dec_str("9885243823600363166628220433820250724586324090253611358758770212725684204135").unwrap(), + // ], + // vec![ + // U256::from_dec_str("9651185291553128823215307092565172143818838202635271809942597163630971976482").unwrap(), + // U256::from_dec_str("7457264071531012293581639749136580536924886204589417402009399054127419592993").unwrap(), + // ], + // ], + // vec![ + // U256::from_dec_str("2627345354605748142976160304028628661480987375506843588233396593542954599122").unwrap(), + // U256::from_dec_str("8681729968580301984067665769277363721394455178806371130831646417737890294377").unwrap(), + // ] + // ); + + // let vk = VerifyingKeyComponents::new( + // vec![ + // U256::from_dec_str("7421321362170719195081023585470135389432297716397232604489422086989398701183").unwrap(), + // U256::from_dec_str("4072026971341416803293623026670767879574289631340879941991921870784524426920").unwrap(), + // ], + // vec![ + // vec![ + // U256::from_dec_str("2973474839676012411019522612887674225146102238495561333683790233803898072056").unwrap(), + // U256::from_dec_str("4756088420398356546587372215087817373004751038308642279979561650652947628544").unwrap(), + // ], + // vec![ + // U256::from_dec_str("18134483811751652906456539288278265005968212485396038963550793901997203165973").unwrap(), + // U256::from_dec_str("19733531274857979315351276512779996430041767061694237978460875113100798536651").unwrap(), + // ], + // ], + // vec![ + // vec![ + // U256::from_dec_str("1470135418689977789083190292952479192678178451735632796795673595352524120366").unwrap(), + // U256::from_dec_str("5512330648930976997879473235916847191061423400686751865867764833860608466852").unwrap(), + // ], + // vec![ + // U256::from_dec_str("8727385532414213805687214017949229267547242769169729533774216518510791901252").unwrap(), + // U256::from_dec_str("6002526157648728322271067956991922780742552704883496238917574496345518669191").unwrap(), + // ] + // ], + // vec![ + // vec![ + // U256::from_dec_str("20953112965721952332699311075873353918826966291896395544882354080425788226212").unwrap(), + // U256::from_dec_str("9244986330211753947979669564454335484807935852348100319901614192766392809174").unwrap(), + // ], + // vec![ + // U256::from_dec_str("14633091132354386243825187195737842488061561784614981035737595152471541943810").unwrap(), + // U256::from_dec_str("18226447293937452659919522397971158104569327938800893595903771586125572293911").unwrap(), + // ], + // ], + // vec![ + // vec![ + // U256::from_dec_str("12814717307556312189651039282215441805578074271611267777533714458773278844960").unwrap(), + // U256::from_dec_str("7186820657304904476047212967487229874520184333187156276378594443001564484591").unwrap(), + // ], + // vec![ + // U256::from_dec_str("555198418426478766253895845611805598077310216839822834188225932135183360314").unwrap(), + // U256::from_dec_str("13253206399154373951823381980703846825450333469684895600618793136364702673992").unwrap(), + // ] + // ] + // ); + + // let valid_input = vec![U256::from_dec_str("1250025000").unwrap()]; + + // let verifying_key = VerifyingKey::new(proof, vk, valid_input); + + // let zk_verifier = ZKPrecompileVerifier::new( + // H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), + // verifying_key + // ); + + // let encoded_call = zk_verifier.generate_benchmarking_parameters(); + + // let gas_limit_call = 1000000; + // let value = U256::default(); + // let is_transactional = true; + // let validate = true; + // }:{ + // let call_runner_results = ::Runner::call( + // caller, + // contract_address, + // encoded_call, + // value, + // gas_limit_call, + // Some(U256::from(1_000_000_000)), + // Some(U256::from(1_000_000_000)), + // None, + // Vec::new(), + // is_transactional, + // validate, + // ::config(), + // ); + // // log::info!( + // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // // "Benchmarking call end.", + // // ); + // match call_runner_results { + // Ok(info) => { + // let output = info.value; + // // log::info!( + // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // // "output result {:?}", + // // output + // // ); + // if output.len() >= 32 { + // let mut result_bytes = [0u8; 32]; + // result_bytes.copy_from_slice(&output[output.len() - 32..]); + // let result = U256::from_big_endian(&result_bytes); + // // log::info!( + // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // // "sum_50000 Verification result {result:?}", + // // ); + // assert_eq!(result, U256::one(), "The contract did not return true"); + // } + // }, + // Err(e) => { + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "sum_50000 Benchmarking failed", + // ); + // assert!(false, "Benchmarking failed"); + // } + // } + // } + + sumout_1 { use frame_benchmarking::vec; use sp_core::{H160, U256, H256}; @@ -191,78 +2320,75 @@ benchmarks! { let proof = Proof::new( vec![ - U256::from_dec_str("323654832133639084097738656057999026789295280666886852594984576709163539526").unwrap(), - U256::from_dec_str("6142957218280645039826855630872622613337777761157366378615236951849913775542").unwrap() + U256::from_dec_str("9938350861216112811054231203277972699126921197659464974935544809385001807185").unwrap(), + U256::from_dec_str("20754348601909610501217030084772328592382611181274973942452539895656099027177").unwrap(), ], vec![ vec![ - U256::from_dec_str("3781402603457401622553078625624300084337446058890012151530042647448923283156").unwrap(), - U256::from_dec_str("3517436796495769146106898128956048233729888622957356948216773257280783319311").unwrap() + U256::from_dec_str("5515305015868084342629690395946038238674727665234420855311483453081429329162").unwrap(), + U256::from_dec_str("17446537483455495191309223490656602496508158001423723415129290719905124468748").unwrap(), ], vec![ - U256::from_dec_str("18697717875318192535466611481750571094853863458428844875498420533596881568336").unwrap(), - U256::from_dec_str("21426423909981695530725752097567643188095093768132522705564475372400085021436").unwrap() + U256::from_dec_str("3930386611358464774146562361387598962026666990617968852149397208747098046424").unwrap(), + U256::from_dec_str("12749664200607251956437072816920531804207920954797765500171403273087430585686").unwrap(), ], ], vec![ - U256::from_dec_str("21613404883582191576526635676329374200679201344239432919502376530553941450391").unwrap(), - U256::from_dec_str("15157755445966041962464884593780030869511182260822371637833098723763718514455").unwrap() + U256::from_dec_str("19560759376029246774770917762129576352981383276741459039515891857991305382724").unwrap(), + U256::from_dec_str("15734770292021565005778827149409535166727027683377260372189150049608646364563").unwrap(), ] ); let vk = VerifyingKeyComponents::new( vec![ - U256::from_dec_str("11521346682463921906610271064518766485088278761420928386309550940286650671457").unwrap(), - U256::from_dec_str("14352830518175561380348856554041231805603495989169432000725584250110291361678").unwrap() + U256::from_dec_str("21733217796115117340664094616124062556432735361619337933379922909843902055515").unwrap(), + U256::from_dec_str("11458528445138916020920755047732691641150418138517915174130099425004410419388").unwrap(), ], vec![ vec![ - U256::from_dec_str("15782596638536803844844408481637582589736413871396993858917786753770876529739").unwrap(), - U256::from_dec_str("14911823231521430202833448929652297782496660742577343858219844871404504144036").unwrap() + U256::from_dec_str("1528892777992101851174077814499016728285240514808795953470350987666406934834").unwrap(), + U256::from_dec_str("15719121553978478977205161897674358216198301946293493012613276233509561742855").unwrap(), ], vec![ - U256::from_dec_str("2082222914940990020573243578958386229340150899029559516350605378857473031525").unwrap(), - U256::from_dec_str("13498996195230132373906915048494917069165130851394909752977335076805840989307").unwrap() + U256::from_dec_str("11348304938307062180350959111763404727439270384731375816552220511782794870928").unwrap(), + U256::from_dec_str("7425062298693286516955806409965528686336065862277124413414678440080583191331").unwrap(), ], ], vec![ vec![ - U256::from_dec_str("3598021131780341035246011324427156192540414244243113294885735792953741606880").unwrap(), - U256::from_dec_str("2036084172531515709709771052774738245922046202318890723044728246225539963428").unwrap() + U256::from_dec_str("2804875110900945674713475978302264950571804196556173252173183478206581329693").unwrap(), + U256::from_dec_str("21248149018328674674239251862093725699159113249722538926825249085881448126937").unwrap(), ], vec![ - U256::from_dec_str("5925457711548235099025126547368719549508643015841982506039250719340224619945").unwrap(), - U256::from_dec_str("6297446610567432982066083461547400065680646594595441716191878482607632761242").unwrap() - ], + U256::from_dec_str("11937905968906797411243920288058802112704397972843813290927323952904789450154").unwrap(), + U256::from_dec_str("11583994651687877961370144800492703053197084517566628648623282684591065755611").unwrap(), + ] ], vec![ vec![ - U256::from_dec_str("8540596677770285018018336727251534074846909511956041125063939097422779191925").unwrap(), - U256::from_dec_str("4004145476643750015352094786522189637304633549022019774555222068038038169997").unwrap() + U256::from_dec_str("6948345332843670535874384951250604863187455917521854956702988343215236877699").unwrap(), + U256::from_dec_str("7592227853391758702072244811620141194222566425322898305556974168308138901071").unwrap(), ], vec![ - U256::from_dec_str("14044576757821380530542904664046256148829410228513509672845139471539338485558").unwrap(), - U256::from_dec_str("21655834928283484760531472827487408029775629615266614212974138202212982461041").unwrap() - ] + U256::from_dec_str("20320075749881446343183062003450485857646019655198241442555760885804303255899").unwrap(), + U256::from_dec_str("16287761203840607067547903820157586575039034353110142941200011092583966755993").unwrap(), + ], ], vec![ vec![ - U256::from_dec_str("18160015955331442477546361309657533914485780296451278252095683998154112390415").unwrap(), - U256::from_dec_str("2421052745427024367257863480713357899822722660532800486395996070904226714086").unwrap() + U256::from_dec_str("5903727580143985844443655542650980356290410430996215778341658075199847464323").unwrap(), + U256::from_dec_str("11996884259430469116666694100434422195076194078215478638845899818616578458076").unwrap(), ], vec![ - U256::from_dec_str("13418845437340247256566377432948869602549774753220761674399899795516131627829").unwrap(), - U256::from_dec_str("19073971532401628571532840417056837528958340897410372352356543204393028153748").unwrap() - ] + U256::from_dec_str("7085337881114239321879072118312865301523763704430159554418691955396215633039").unwrap(), + U256::from_dec_str("1480130379115126141544726883503597589909960712327226527274861716229740605644").unwrap(), + ], ] ); - let valid_input: Vec = vec![u64s_to_u256(vec![ - 14965631224775206224, - 3021577815302938909, - 14359293880404272991, - 1555005537055779113 - ])]; + let valid_input = vec![ + U256::from_dec_str("1").unwrap(), + ]; let verifying_key = VerifyingKey::new(proof, vk, valid_input); @@ -292,41 +2418,32 @@ benchmarks! { validate, ::config(), ); - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "Benchmarking call end.", - // ); match call_runner_results { Ok(info) => { let output = info.value; - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "output result {:?}", - // output - // ); if output.len() >= 32 { let mut result_bytes = [0u8; 32]; result_bytes.copy_from_slice(&output[output.len() - 32..]); let result = U256::from_big_endian(&result_bytes); - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "nconstraints_10 Verification result {result:?}", - // ); + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "sumout_1 Verification result {result:?}", + ); assert_eq!(result, U256::one(), "The contract did not return true"); } }, Err(e) => { log::info!( target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - "nconstraints_10 Benchmarking failed", + "sumout_1 Benchmarking failed", ); assert!(false, "Benchmarking failed"); - } } } - nconstraints_50 { + + sumout_3 { use frame_benchmarking::vec; use sp_core::{H160, U256, H256}; @@ -335,78 +2452,85 @@ benchmarks! { let proof = Proof::new( vec![ - U256::from_dec_str("2903574088029507435491062627919627539459038881203099780902103872696986272650").unwrap(), - U256::from_dec_str("3875062839032259754068923295563862040166715100637843024855021734684308685930").unwrap(), + U256::from_dec_str("16886990047698791021397211555946902052303558083480918437568754609520399637420").unwrap(), + U256::from_dec_str("2158666036923715472550204975056204244361247562519274259158726699413361975377").unwrap(), ], vec![ vec![ - U256::from_dec_str("5467576156112132028552287163049386912078800648727055176723583005212825192497").unwrap(), - U256::from_dec_str("14958898784032520052694892656913773236193256742890765604760593633503039104983").unwrap(), + U256::from_dec_str("21825895835348066771949343990501317097894843683430512250115671134066620251631").unwrap(), + U256::from_dec_str("4466621631021858506469772043982203005266775866614490870641688212518524595581").unwrap(), ], vec![ - U256::from_dec_str("5396143311660903133040196691443703988892234257628755380984718394981374344158").unwrap(), - U256::from_dec_str("8621644456104449033213297238562527153800159584768570376273022394943050969320").unwrap(), + U256::from_dec_str("4176035282152177060631306859647233493053656458958851103499068538408191035948").unwrap(), + U256::from_dec_str("11478054618053509184726472858088324642813538303220488990534337782294436141900").unwrap(), ], ], vec![ - U256::from_dec_str("11879092906448699692394725971977132036554363118574468164770659810752018463948").unwrap(), - U256::from_dec_str("6829624468475499149259780051037762599455296300930683215687755977165243124154").unwrap(), + U256::from_dec_str("2783215660066684652951960961708568160262083911582630687913502540009978493094").unwrap(), + U256::from_dec_str("12293216536420324710913866412884718473844766370712205111375513783367059491745").unwrap(), ] ); let vk = VerifyingKeyComponents::new( vec![ - U256::from_dec_str("12520775544030530008009522467466185193766786263812261579427634884004150619566").unwrap(), - U256::from_dec_str("5032545863820965741764073435262250124257467813113463153084126384917060899315").unwrap(), + U256::from_dec_str("5173033808064965357658509659910492294930152276344605525901535639502011399348").unwrap(), + U256::from_dec_str("17068737078093325914601548755287000154671449528138414861362494877844369116679").unwrap(), ], vec![ vec![ - U256::from_dec_str("10017955328073015145877787608777450033090741247853140204265773706371885379542").unwrap(), - U256::from_dec_str("9658203662920649739629860626443008098625554125855709045942833415049413198251").unwrap(), + U256::from_dec_str("18546422218544016845270499276237522358419081403760538321534730027231631447721").unwrap(), + U256::from_dec_str("7810445849810537796619946419860277733990747614871399330031502459697394450024").unwrap(), ], vec![ - U256::from_dec_str("7602415148393817869205609282139785691690714005596249546125364310759985118071").unwrap(), - U256::from_dec_str("6621887421318408197643297351639235440436194355283660692959196816576578875866").unwrap(), + U256::from_dec_str("1170639424349054655683720291779988770761452909673727094673081217226173989816").unwrap(), + U256::from_dec_str("9412518718720962495243722595927760663661173673000956950863625218254861399884").unwrap(), ], ], vec![ vec![ - U256::from_dec_str("5311307398908794283615493653665859916837738758333406097237626345248614605789").unwrap(), - U256::from_dec_str("17876886843886949913975349493510247353159584223381019718903135647608874168034").unwrap(), + U256::from_dec_str("2200736122860885030116625882728423481103104963926248602047366582063573350368").unwrap(), + U256::from_dec_str("10144419795729765523122504674541920919692895267022159856625676910310683074572").unwrap(), ], vec![ - U256::from_dec_str("16871344858870476549165036353120397473700844904231047018564735968613233188965").unwrap(), - U256::from_dec_str("3780010632071163899826543545524090280002435997376718121100375224910528030644").unwrap(), - ], + U256::from_dec_str("13390729254545550118668755621583864033913527349600040291864450051082409115353").unwrap(), + U256::from_dec_str("10049685629671638387934361525360217384621934210702130547016579632581199513700").unwrap(), + ] ], vec![ vec![ - U256::from_dec_str("5274939476765287332787933848172441391963317633567336761478263433231602711901").unwrap(), - U256::from_dec_str("20318717968421229127062334564952813061229602553850186042308931686220563993985").unwrap(), + U256::from_dec_str("19667103121024340857751329572172914473199256004525176516911283862315503618923").unwrap(), + U256::from_dec_str("17096246661332763117514187398699870735557867602087681563046129321059799057215").unwrap(), ], vec![ - U256::from_dec_str("18867986549807700609691354300906273266753459571664361845748650324369589087167").unwrap(), - U256::from_dec_str("3462802759155100024118895949055238081126591020075851877084161838812514424801").unwrap(), - ] + U256::from_dec_str("5747946728261847324885781741547355414535058240068054018513487219209938622249").unwrap(), + U256::from_dec_str("20967849068573472545470716505852386189926392787722866540330567432920833499864").unwrap(), + ], ], vec![ vec![ - U256::from_dec_str("2073721309366561324099267234284336470258146869696430225377434175843251484752").unwrap(), - U256::from_dec_str("5562089018027206512286783868306950659834000523781522158661084193254167305831").unwrap(), + U256::from_dec_str("10845237408084729771758679531905348867405129151866839173812886431855390540097").unwrap(), + U256::from_dec_str("1703707016089191110685983076484608595856556399796329016216676789467749613552").unwrap(), ], vec![ - U256::from_dec_str("7633925392184781104787537197952383405066326059553608577981951477761067715424").unwrap(), - U256::from_dec_str("19510227686274170330355317434483857344641524658406254379151352263942714837771").unwrap(), - ] + U256::from_dec_str("6110149777882922151130458750708717975247447215574560066901560999540213459036").unwrap(), + U256::from_dec_str("2604335473336229760265035630255446069244978528812036061612414998445480891974").unwrap(), + ], + vec![ + U256::from_dec_str("17335232688503638164872257108646124236545159761624108797282027627835697028104").unwrap(), + U256::from_dec_str("8949820120400561503263628231115650124871194346512209521952934432568756809020").unwrap(), + ], + vec![ + U256::from_dec_str("17472945225672873683007250170922636087596020485883147904995489212967632436245").unwrap(), + U256::from_dec_str("3061009963934218559141330300326228190658110279298003565222855302662460452130").unwrap(), + ], ] ); - let valid_input: Vec = vec![u64s_to_u256(vec![ - 14754876691570659999, - 1449725765053302887, - 10573592104590215630, - 2031301759166401468 - ])]; + let valid_input = vec![ + U256::from_dec_str("1").unwrap(), + U256::from_dec_str("3").unwrap(), + U256::from_dec_str("6").unwrap(), + ]; let verifying_key = VerifyingKey::new(proof, vk, valid_input); @@ -436,41 +2560,31 @@ benchmarks! { validate, ::config(), ); - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "Benchmarking call end.", - // ); match call_runner_results { Ok(info) => { let output = info.value; - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "output result {:?}", - // output - // ); if output.len() >= 32 { let mut result_bytes = [0u8; 32]; result_bytes.copy_from_slice(&output[output.len() - 32..]); let result = U256::from_big_endian(&result_bytes); - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "nconstraints_50 Verification result {result:?}", - // ); + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "sumout_3 Verification result {result:?}", + ); assert_eq!(result, U256::one(), "The contract did not return true"); } }, Err(e) => { log::info!( target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - "nconstraints_50 Benchmarking failed", + "sumout_3 Benchmarking failed", ); assert!(false, "Benchmarking failed"); - } } } - nconstraints_1000 { + sumout_5 { use frame_benchmarking::vec; use sp_core::{H160, U256, H256}; @@ -479,78 +2593,95 @@ benchmarks! { let proof = Proof::new( vec![ - U256::from_dec_str("12451505848309631687252015279596976128225375079184616465869275088833975377438").unwrap(), - U256::from_dec_str("18028472547304696309803026581736164843724278168110632635282700219721294267849").unwrap(), + U256::from_dec_str("10843709274069701798511921250280301584693334300670909217788413041083651717163").unwrap(), + U256::from_dec_str("16984929187729614385413559875801633684939267739432542404983191429879545973363").unwrap(), ], vec![ vec![ - U256::from_dec_str("724941625340075448308940885419778921267046089963198424690563710257350467820").unwrap(), - U256::from_dec_str("19418815036545241911278056687101064762643664412732993043969007894248087117385").unwrap(), + U256::from_dec_str("734148988538591964874068908106884716790741858016853636848093036568317136975").unwrap(), + U256::from_dec_str("19009101126100851400074367739886512661512111552427522714684639750197874542269").unwrap(), ], vec![ - U256::from_dec_str("13249414494230793056410904135885722890271124096600389432878053498484425858770").unwrap(), - U256::from_dec_str("21762806144353143011028620465453743506764842517668851190776375592288870325215").unwrap(), + U256::from_dec_str("17592060285412708307279524116763043954397813345633635123760549183251104162936").unwrap(), + U256::from_dec_str("13889506181636214857793531048122114805475801077448416250517876148460169211100").unwrap(), ], ], vec![ - U256::from_dec_str("9206867270262791130308246301015463866896172966002943363908694359851632501217").unwrap(), - U256::from_dec_str("13679683495177263967294831832954860495137891909047512983345948806664713075553").unwrap(), + U256::from_dec_str("14232563060686721866158930720630875371569684145608628878932337428224050961095").unwrap(), + U256::from_dec_str("1153379304505972153074194911346366079704012789387132395115115570476601062069").unwrap(), ] ); let vk = VerifyingKeyComponents::new( vec![ - U256::from_dec_str("13896934827344718021853288836918374118104295193491067840322643424358899121542").unwrap(), - U256::from_dec_str("8854052944916041632001392967979629780372345382861670282089777314383817716115").unwrap(), + U256::from_dec_str("14602929204623575899704572853140632308492709111903618875822489562329338716600").unwrap(), + U256::from_dec_str("1689586738876602514816831803381017781452340558398178586457594640291347324251").unwrap(), ], vec![ vec![ - U256::from_dec_str("3601177773308419037453361001975316835601350296485805323140167568598797930642").unwrap(), - U256::from_dec_str("48851914275316782871445347689531673984580545598074561513165366823294923594").unwrap(), + U256::from_dec_str("5472399972818221760148387617622606184408186046073893949062037156069912958420").unwrap(), + U256::from_dec_str("15088758066943253549000189946806726744988559838853537684885055598950377383100").unwrap(), ], vec![ - U256::from_dec_str("4538012201084519544875007504928553564968897773565284770715803834936680149613").unwrap(), - U256::from_dec_str("3155968616270588886660033728776257587454508333510911411658919790925259116614").unwrap(), + U256::from_dec_str("20965140394004681264140187314264751937007442823435473099253896953347314157448").unwrap(), + U256::from_dec_str("6060690771018416217128945435034565801294536828990641996243103214693154087328").unwrap(), ], ], vec![ vec![ - U256::from_dec_str("6521538659624675039700866061977650833785775087701556120926232218187885377774").unwrap(), - U256::from_dec_str("18707623749213430453109215145186606994638201653518117177006249287165414157706").unwrap(), + U256::from_dec_str("21263140729235433474630918705483709183043987469144755035836936799756516942174").unwrap(), + U256::from_dec_str("15454285754854480671888484669874181801887589102853817499490458030152705038393").unwrap(), ], vec![ - U256::from_dec_str("11743109857123024729794370527373948778820323338754388805090881243904381703330").unwrap(), - U256::from_dec_str("3577725017182890090279110701721773090147301853148322630192233820247926772155").unwrap(), - ], + U256::from_dec_str("131865583299313362102439649370460452157962165364517843475166565097979328681").unwrap(), + U256::from_dec_str("3031199517487834223134891339647304484515505296778183327653617685889942730653").unwrap(), + ] ], vec![ vec![ - U256::from_dec_str("10697077492206594361644026971284249101590705030465491131467731100150008255694").unwrap(), - U256::from_dec_str("1114380532795466865933623446272212800793315337032855536172932313989250445726").unwrap(), + U256::from_dec_str("3468906430674013119693695928268572867728233724074466649670021386689854137425").unwrap(), + U256::from_dec_str("7152580803122005503226572138561796511745831544828490575855116764117124258005").unwrap(), ], vec![ - U256::from_dec_str("11747915450686416011932172170367549011245903715607283230565719536126230133873").unwrap(), - U256::from_dec_str("1877153534214274703747923906347594924169181268669702005894131954432202950068").unwrap(), - ] + U256::from_dec_str("11838997786679875543165785538783421655549584031892121869365192734986828433584").unwrap(), + U256::from_dec_str("9326037833969675641798059567930300590354374810107157670596201469638516559516").unwrap(), + ], ], vec![ vec![ - U256::from_dec_str("6294921440683861296812943370338888809368101163511446375226378176013676840633").unwrap(), - U256::from_dec_str("8766686502883018606879699065134987161183815270662618961653335871316040755302").unwrap(), + U256::from_dec_str("18012654367772022563720142058930749289295704020857186339096955550145993927017").unwrap(), + U256::from_dec_str("1820834164495870618274456212936566261697357111580171595080158790515959828160").unwrap(), + ], + vec![ + U256::from_dec_str("14564921752272533367499159134818448151761069174539749712526942006044013367624").unwrap(), + U256::from_dec_str("21424771264673466693648639329731655135896471263362765164636863696917694576743").unwrap(), + ], + vec![ + U256::from_dec_str("475727869657896018962474075772680190259478188474158088185455044188053740464").unwrap(), + U256::from_dec_str("14410774738558525043590957367040603027587866740036883757867616381286145538306").unwrap(), + ], + vec![ + U256::from_dec_str("11122269591667799379645221047239470153918191911025387915741500657620168268073").unwrap(), + U256::from_dec_str("17658889114158552675967451148822309152599407578222142601435191444872800075124").unwrap(), + ], + vec![ + U256::from_dec_str("10247277070171001623223120619585458877815606242596599730030571392627204008518").unwrap(), + U256::from_dec_str("8479449182628070681609638314620998919468112761035511418595900534618900240479").unwrap(), ], vec![ - U256::from_dec_str("15422085976834841481597157129530660038025986735930069198619117556493669017719").unwrap(), - U256::from_dec_str("6824904336141021449652133306590775160232847673735850151493603664420102965477").unwrap(), + U256::from_dec_str("1962015739865113713712043429590435981426176192245833450140313755224798839430").unwrap(), + U256::from_dec_str("16205122197955925140750583202721983405250616309734059872813415529671902218508").unwrap(), ] ] ); - let valid_input: Vec = vec![u64s_to_u256(vec![ - 5637188163546619750, - 4876642863872575056, - 11311886144936918135, - 2620236256196171805 - ])]; + let valid_input = vec![ + U256::from_dec_str("1").unwrap(), + U256::from_dec_str("3").unwrap(), + U256::from_dec_str("6").unwrap(), + U256::from_dec_str("10").unwrap(), + U256::from_dec_str("15").unwrap() + ]; let verifying_key = VerifyingKey::new(proof, vk, valid_input); @@ -580,40 +2711,32 @@ benchmarks! { validate, ::config(), ); - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "Benchmarking call end.", - // ); match call_runner_results { Ok(info) => { let output = info.value; - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "output result {:?}", - // output - // ); if output.len() >= 32 { let mut result_bytes = [0u8; 32]; result_bytes.copy_from_slice(&output[output.len() - 32..]); let result = U256::from_big_endian(&result_bytes); - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "nconstraints_1000 Verification result {result:?}", - // ); + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "sumout_5 Verification result {result:?}", + ); assert_eq!(result, U256::one(), "The contract did not return true"); } }, Err(e) => { log::info!( target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - "nconstraints_1000 Benchmarking failed", + "sumout_5 Benchmarking failed", ); assert!(false, "Benchmarking failed"); - } } } - nconstraints_900000 { + + + sumout_8 { use frame_benchmarking::vec; use sp_core::{H160, U256, H256}; @@ -622,78 +2745,110 @@ benchmarks! { let proof = Proof::new( vec![ - U256::from_dec_str("19469224081137364911375441935428613758543844094780123177610680784796374565509").unwrap(), - U256::from_dec_str("2964109100176825277964902990593130655404587548088911907169158668561756482373").unwrap(), + U256::from_dec_str("20881676737166493582717361049990209142091151560277146607338080001356130551563").unwrap(), + U256::from_dec_str("18685148182132563281318375875896798947216249273522126721154367752167069271966").unwrap(), ], vec![ vec![ - U256::from_dec_str("1804788596044451078391485097362341934563024367189115611320140606169017734442").unwrap(), - U256::from_dec_str("13075356869764013404490647878715830765050556805353047586243641659166972614506").unwrap(), + U256::from_dec_str("19805017985803942911996819094597598814225347516143362171828062466401419556425").unwrap(), + U256::from_dec_str("6454257483855613540563513163965581345545044507035534598690370868179178950555").unwrap(), ], vec![ - U256::from_dec_str("11510752280195741101381678478126680255679095252133774347633523263393718090827").unwrap(), - U256::from_dec_str("19917734624109913540474402939707087760514256808495299709893660593520804971329").unwrap(), + U256::from_dec_str("6029759526221488701419339807738355794494802551955780707582495359517196927109").unwrap(), + U256::from_dec_str("14267537981552092649796532473776382038697314253728184857929706479499924660588").unwrap(), ], ], vec![ - U256::from_dec_str("17650234014776935476405426867265189573543251264844619398004397025922351000524").unwrap(), - U256::from_dec_str("13980409623437481166079302794215538337078177634480935418093274323345259996058").unwrap(), + U256::from_dec_str("9594194445262469071793565488528689703162142686015495470197658864675667005764").unwrap(), + U256::from_dec_str("12806173576837505234722625501460681990985569361840943288163429373057791635174").unwrap(), ] ); let vk = VerifyingKeyComponents::new( vec![ - U256::from_dec_str("7204013913559348808806179272679133668079798990573619252699122941477292720367").unwrap(), - U256::from_dec_str("14448814309541293146746525253301533902449817953703436076734477345366335651547").unwrap(), + U256::from_dec_str("16843199197487561646169134476888510727371602451967711834418709891625862192118").unwrap(), + U256::from_dec_str("4982834246914059407767022322452524619121175829432542760151885667226965908175").unwrap(), ], vec![ vec![ - U256::from_dec_str("12755354931522455226769415963087662012592248962914015697167303994293035888664").unwrap(), - U256::from_dec_str("19979994508677160041392994419804596139216500302977150541381981675855322022114").unwrap(), + U256::from_dec_str("13537923638822567297513803074712167738585661835781036936983516715534090948855").unwrap(), + U256::from_dec_str("11214527989489337965037448828413554959537012329709327451546605605029975329833").unwrap(), ], vec![ - U256::from_dec_str("3518578052095992035034011768990132253597152650327354182069223777691356587613").unwrap(), - U256::from_dec_str("1512363495951297845516866605291301480678745477544041997800458458709067854003").unwrap(), + U256::from_dec_str("4462141743449864304650718313134032562107623852111180981714224584326923063811").unwrap(), + U256::from_dec_str("8593795430336743569036551388690578138795757924676449205217387344751477578392").unwrap(), ], ], vec![ vec![ - U256::from_dec_str("21483901865224554977407186643009006049964266844355020377697169106001216486465").unwrap(), - U256::from_dec_str("18122216236568402305988297032517775914181563813086813006164216689752246508886").unwrap(), + U256::from_dec_str("17309166272661014787434443764307400135052663428379855697446417017021332297530").unwrap(), + U256::from_dec_str("5496023192794917920401339916944184963784198502465903489239967703087855023608").unwrap(), ], vec![ - U256::from_dec_str("7100124544075226034251596932805277307734457677256004047412258693103409543678").unwrap(), - U256::from_dec_str("9484826513489508497326605298995346628011303684771342589708630141744196880174").unwrap(), - ], + U256::from_dec_str("18916827587111283766401091943196651682285539340427490406407460155259456790394").unwrap(), + U256::from_dec_str("12299438544618647185398496571464375186770593791424093069019355848143426272476").unwrap(), + ] ], vec![ vec![ - U256::from_dec_str("4294809674390523555755416088340227038268056188806697061914357207030835445784").unwrap(), - U256::from_dec_str("12772882987652274474928251216882135157601158713560023135442912416889883375009").unwrap(), + U256::from_dec_str("17783472651095992230194984959634523916458279184006542713077780177849417194806").unwrap(), + U256::from_dec_str("4836569650671318166980489785623247713000662692959335424089941395104953246823").unwrap(), ], vec![ - U256::from_dec_str("5017814360156811257431228283078380210712481496173867244303167538680301406355").unwrap(), - U256::from_dec_str("5483986251263351055676143301589669624262947345327185314870128974364440001262").unwrap(), - ] + U256::from_dec_str("5208397036236600320774363534257475251244044365748886930563031073914567820528").unwrap(), + U256::from_dec_str("19055050817214474907565862351314552256205984947772618507442964780728061953573").unwrap(), + ], ], vec![ vec![ - U256::from_dec_str("10485365056956235833573091505977794158366069646492853613385564319176805042067").unwrap(), - U256::from_dec_str("21560988819791135038184934219494970236802908435926324068683299817562907341696").unwrap(), + U256::from_dec_str("4958353703564853797480558824501374493866572548677008630806682009679433646955").unwrap(), + U256::from_dec_str("11291693312464961842059331703592439948750550091724954216017767042000996236264").unwrap(), ], vec![ - U256::from_dec_str("9274251274730510866039258353232655161206943117093211738883330925803202790098").unwrap(), - U256::from_dec_str("19994917632455570632082635510110118222993755636207706143729050502915579896735").unwrap(), - ] + U256::from_dec_str("12498275799103181792627863878557495829009523362285107656610654372282690766119").unwrap(), + U256::from_dec_str("4660953423300268019590006016093722402476152146326204206929515385340767022285").unwrap(), + ], + vec![ + U256::from_dec_str("7138500762518060350238754675766385436116813573098550938636446616835446824939").unwrap(), + U256::from_dec_str("10593558873947627445673570470975584735484733850711765231108539595431195202419").unwrap(), + ], + vec![ + U256::from_dec_str("5128578074800121244687450741397033494076458406794772068903912438713735124312").unwrap(), + U256::from_dec_str("12739298773375695368884515558611087780028515164769718103051887568287014868554").unwrap(), + ], + vec![ + U256::from_dec_str("14208333732881243428572299578791263825282606806313226027225601452663343234467").unwrap(), + U256::from_dec_str("11697572475523427738804655258597612653697756472591022126910520054756212281641").unwrap(), + ], + vec![ + U256::from_dec_str("12947417320200513077005132775929421525296222658070514082956015435086603716201").unwrap(), + U256::from_dec_str("10603870931188623347190243514602488220386876361489556318755549006254763084062").unwrap(), + ], + vec![ + U256::from_dec_str("16387770851924831042551337157942839466998720794986734312705189727537868513301").unwrap(), + U256::from_dec_str("21530634239892293824934800960052121252877550002298146977275883229302441879110").unwrap(), + ], + vec![ + U256::from_dec_str("13802739621009348580166301250636211668066199382162533891337095173708507625183").unwrap(), + U256::from_dec_str("7390549673741696710038465132307739993957511234849566067102331114963870977526").unwrap(), + ], + vec![ + U256::from_dec_str("7619444939038530089326050845035495508541658656202842508270208357152287148678").unwrap(), + U256::from_dec_str("6500310581417507359356071153065385786035787026399006593758019508960807973327").unwrap(), + ], ] ); - let valid_input: Vec = vec![u64s_to_u256(vec![ - 10518156496175725870, - 8513656267880232886, - 1469451646407182009, - 3425508166019525724 - ])]; + let valid_input = vec![ + U256::from_dec_str("1").unwrap(), + U256::from_dec_str("3").unwrap(), + U256::from_dec_str("6").unwrap(), + U256::from_dec_str("10").unwrap(), + U256::from_dec_str("15").unwrap(), + U256::from_dec_str("21").unwrap(), + U256::from_dec_str("28").unwrap(), + U256::from_dec_str("36").unwrap(), + ]; let verifying_key = VerifyingKey::new(proof, vk, valid_input); @@ -723,41 +2878,32 @@ benchmarks! { validate, ::config(), ); - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "Benchmarking call end.", - // ); match call_runner_results { Ok(info) => { let output = info.value; - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "output result {:?}", - // output - // ); if output.len() >= 32 { let mut result_bytes = [0u8; 32]; result_bytes.copy_from_slice(&output[output.len() - 32..]); let result = U256::from_big_endian(&result_bytes); - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "nconstraints_900000 Verification result {result:?}", - // ); + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "sumout_8 Verification result {result:?}", + ); assert_eq!(result, U256::one(), "The contract did not return true"); } }, Err(e) => { log::info!( target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - "nconstraints_900000 Benchmarking failed", + "sumout_8 Benchmarking failed", ); assert!(false, "Benchmarking failed"); - } } } - nconstraints_30_input_10 { + + sumout_10 { use frame_benchmarking::vec; use sp_core::{H160, U256, H256}; @@ -766,78 +2912,120 @@ benchmarks! { let proof = Proof::new( vec![ - U256::from_dec_str("344113499780097036133410144688544669449665038469801025061703634064197059916").unwrap(), - U256::from_dec_str("8339013355837829034186604529242237434382457535922383671882155606562413431689").unwrap(), + U256::from_dec_str("8095347977558970795244894306973905848904001838702896366752039759486143590655").unwrap(), + U256::from_dec_str("11389786227461730181613149052445453595828636283243249470864002334968553081173").unwrap(), ], vec![ vec![ - U256::from_dec_str("6694199005832176626648387473003377778002164049654344388623160500074797775370").unwrap(), - U256::from_dec_str("6246558478856965861562784864034844546822126660127014237507763330640717221466").unwrap(), + U256::from_dec_str("21708613222549995537668812978970219933649440225134255022725303703626994194813").unwrap(), + U256::from_dec_str("239188211415377402375320392238806616016565549618403346265681937965053169431").unwrap(), ], vec![ - U256::from_dec_str("456859418727494804887897697519797382313397623366843307513728588676215628797").unwrap(), - U256::from_dec_str("19972929684979882956825623277042855987039264105600158828132263230333203670106").unwrap(), + U256::from_dec_str("3239905157092125823769350435491033426008439939030717819312650649959874173134").unwrap(), + U256::from_dec_str("12052232966415578751823016823727256388291367828304994281169873551977365031626").unwrap(), ], ], vec![ - U256::from_dec_str("8991876521515422964548874095107781976525191569601242691722207742733698821028").unwrap(), - U256::from_dec_str("17304897036279645989594099459944208131107988079437513579584585106093260802053").unwrap(), + U256::from_dec_str("897402773553083836675111568099716002998450791951489272035491280385895453675").unwrap(), + U256::from_dec_str("4302991846298387183398271555952452477837006359717803162778715536752182672022").unwrap(), ] ); let vk = VerifyingKeyComponents::new( vec![ - U256::from_dec_str("16587578668155053320776501244706909164198053583863284386206654068019392556543").unwrap(), - U256::from_dec_str("17489859882312386925030082840618136961844042944104008122175974338708995824981").unwrap(), + U256::from_dec_str("1008042868469261437465824462555835872984405918513720852248805969522549317398").unwrap(), + U256::from_dec_str("17948956462462396838284127242383169953057095846419418150844950289307977478505").unwrap(), ], vec![ vec![ - U256::from_dec_str("8243058085082563940310351321464397410632520885003827137093771369586433446018").unwrap(), - U256::from_dec_str("1806964369040712598415691188975966807767394918682209427183228092832571919497").unwrap(), + U256::from_dec_str("8551104548742012199265803926546530567117656701099183084826067603858509033959").unwrap(), + U256::from_dec_str("18033160402793654659203629055551676044915660275765706303943849950983851388359").unwrap(), ], vec![ - U256::from_dec_str("5238575049648595236335310308987023404502439315997088611926714272919127054029").unwrap(), - U256::from_dec_str("10529242360048105445622302340100671863366518517961350431989359465371013288044").unwrap(), + U256::from_dec_str("18666245592989525932086991882662677749245174145376158182567864777290703859953").unwrap(), + U256::from_dec_str("12739445590586817042423266191782746191509898418710009323864773881753277149266").unwrap(), ], ], vec![ vec![ - U256::from_dec_str("422118731661843716781379598081446048950684758761078928178953272944418614265").unwrap(), - U256::from_dec_str("8071137901873450516865398890359069534977349842235015782367912081100468370342").unwrap(), + U256::from_dec_str("2331829126412868358771801117979852694196692966771691214227043519819366059412").unwrap(), + U256::from_dec_str("19888979373549023610391803146710987007008930621488156737270769648673859621478").unwrap(), ], vec![ - U256::from_dec_str("6616051543776580097026224309598118359974125974677691608309070965923230091481").unwrap(), - U256::from_dec_str("3144026861846828201735234261898216197057552604232403108299101704912138104081").unwrap(), - ], + U256::from_dec_str("2453673301402362948623253085750603643389422628968377872756565691580988083845").unwrap(), + U256::from_dec_str("9663445074525460783023482351534650548924461390941888390004047901572505652613").unwrap(), + ] ], vec![ vec![ - U256::from_dec_str("15967728838725285670062386536689775286816477877862913251436519988213464788203").unwrap(), - U256::from_dec_str("14482652023948193853731701210376245407114581664800773915003137369238699817066").unwrap(), + U256::from_dec_str("16927652518569561664756655584955863290280627934729335681190762313953209291004").unwrap(), + U256::from_dec_str("4932558367420707526402578793947314151706672793656462574202517097413681336095").unwrap(), ], vec![ - U256::from_dec_str("20222564526826997580988353930405539667760709452060576182511364617433825375503").unwrap(), - U256::from_dec_str("1855904408322765948314758770516591135802311025429227172106073057339165107921").unwrap(), - ] + U256::from_dec_str("2634665158965720057724065638899982698588247847852682145611641155204230491999").unwrap(), + U256::from_dec_str("9690377563892165618821474298831099678985125870872292050827811231043721368626").unwrap(), + ], ], vec![ vec![ - U256::from_dec_str("2234398803815490360326379119253073021265347911436036657996997085101774002925").unwrap(), - U256::from_dec_str("10214773739303944856355679056757071889148916152665035343340628435407174724717").unwrap(), + U256::from_dec_str("15646752321283466165334982599725570177394246403813099805195136296761241527233").unwrap(), + U256::from_dec_str("2673660939947951312370015187331632544726348142660533215912073160631461110194").unwrap(), ], vec![ - U256::from_dec_str("21500623561133929663133180424780657403302270303706782392356903439186747104812").unwrap(), - U256::from_dec_str("19328419280811286038333929820672543691407985372391054082759992875889788951230").unwrap(), - ] + U256::from_dec_str("8795725431636628672881798189389564709124948886181390178455547202534111009338").unwrap(), + U256::from_dec_str("4110538773071852744620136310168055865424844624884280749230423420272832655948").unwrap(), + ], + vec![ + U256::from_dec_str("1831722434614555360769800136025735307898058715006643917013942103396575104215").unwrap(), + U256::from_dec_str("19989387745164304450269343019866869726210315559728705694008015771363654418682").unwrap(), + ], + vec![ + U256::from_dec_str("10862696719365997074854505211779324198035920467781370644724921446857917651996").unwrap(), + U256::from_dec_str("9116798754108731679801642195848458981493300338319414129478047681468689383121").unwrap(), + ], + vec![ + U256::from_dec_str("16768252193135174475066659836349285218577351670934937518606124353068436732280").unwrap(), + U256::from_dec_str("13373738945795732208212519161819821211235233264106510550098917898260605099707").unwrap(), + ], + vec![ + U256::from_dec_str("542836645169683970941273656817512961230019569896206162978989160115050828365").unwrap(), + U256::from_dec_str("3342534425975518224378168738779764102272719874861318177064435130732411210368").unwrap(), + ], + vec![ + U256::from_dec_str("1770766751918227923442808905725672958134690651505108229474581836615986300515").unwrap(), + U256::from_dec_str("21053352455656543786046861160862658391653611956434282730527309466510916590010").unwrap(), + ], + vec![ + U256::from_dec_str("20880233474430230226643725074209261213944122688335980068588310045451961241696").unwrap(), + U256::from_dec_str("8791463445716605276609109968668430420344826553389688804713588795902347288143").unwrap(), + ], + vec![ + U256::from_dec_str("18577375943106027695484211293909818336439163081296645089367052818189591231338").unwrap(), + U256::from_dec_str("4321732139643796718169445123275382387645361160952863834396437890748602330532").unwrap(), + ], + vec![ + U256::from_dec_str("10314948068545990837002165860394752996164087839142117273228424101259185001002").unwrap(), + U256::from_dec_str("1219317476656503163020791040029674985228288088100785556071334850164078598664").unwrap(), + ], + vec![ + U256::from_dec_str("20369783784101349031638736538393623333643160768611915809859932035797922480026").unwrap(), + U256::from_dec_str("2022155339791641519218630090672540669148716363586469003730495586402216125347").unwrap(), + ], ] ); - let valid_input: Vec = vec![u64s_to_u256(vec![ - 14321691860995553260, - 7152862679273281751, - 12752615512303817990, - 1576113262537949146 - ])]; + let valid_input = vec![ + U256::from_dec_str("1").unwrap(), + U256::from_dec_str("3").unwrap(), + U256::from_dec_str("6").unwrap(), + U256::from_dec_str("10").unwrap(), + U256::from_dec_str("15").unwrap(), + U256::from_dec_str("21").unwrap(), + U256::from_dec_str("28").unwrap(), + U256::from_dec_str("36").unwrap(), + U256::from_dec_str("45").unwrap(), + U256::from_dec_str("55").unwrap(), + ]; let verifying_key = VerifyingKey::new(proof, vk, valid_input); @@ -867,40 +3055,31 @@ benchmarks! { validate, ::config(), ); - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "Benchmarking call end.", - // ); match call_runner_results { Ok(info) => { let output = info.value; - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "output result {:?}", - // output - // ); if output.len() >= 32 { let mut result_bytes = [0u8; 32]; result_bytes.copy_from_slice(&output[output.len() - 32..]); let result = U256::from_big_endian(&result_bytes); - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "nconstraints_30_input_10 Verification result {result:?}", - // ); + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "sumout_10 Verification result {result:?}", + ); assert_eq!(result, U256::one(), "The contract did not return true"); } }, Err(e) => { log::info!( target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - "nconstraints_30_input_10 Benchmarking failed", + "sumout_10 Benchmarking failed", ); assert!(false, "Benchmarking failed"); - } } } - nconstraints_30_input_100 { + + sumout_12 { use frame_benchmarking::vec; use sp_core::{H160, U256, H256}; @@ -909,78 +3088,130 @@ benchmarks! { let proof = Proof::new( vec![ - U256::from_dec_str("3780487311936056381294564418675304364481973966802209296561160829797948105411").unwrap(), - U256::from_dec_str("12392254879980640223142009257910424254771509444451393927739643876401726307795").unwrap(), + U256::from_dec_str("10678216327021239791495061437747847264659254646405410835995870885562189659878").unwrap(), + U256::from_dec_str("8761704370667248778922819575959420459857647618994282299958428953088561107560").unwrap(), ], vec![ vec![ - U256::from_dec_str("5169548117445173154024813698359426977000013771483410622256640533171985245380").unwrap(), - U256::from_dec_str("11220449603083268927036844276912830985523128428499468942581840512730495047625").unwrap(), + U256::from_dec_str("8321848050333625644069000415252127116589656568901903629556956574360865016809").unwrap(), + U256::from_dec_str("8384658520212855102478260838149819693091725582498835147548352582021949594963").unwrap(), ], vec![ - U256::from_dec_str("7617888807668014594076695037395251387521432502213194545531858961238344338860").unwrap(), - U256::from_dec_str("3206448605631210983027663221710912427383659852717855953276353488187250079459").unwrap(), + U256::from_dec_str("3770359937661059505252608927767095077492661514400658547012520648582203048408").unwrap(), + U256::from_dec_str("3529784532113968623662330699908137485954980022129653872444397209141826251473").unwrap(), ], ], vec![ - U256::from_dec_str("17260938596020642923034443094579912726381749511890996943502017876149586484217").unwrap(), - U256::from_dec_str("973711408795313031099855712156150142641887502706075552254275664528776194028").unwrap(), + U256::from_dec_str("4705370747374071844930946489229229872881908444966715664904386641107882480824").unwrap(), + U256::from_dec_str("19986445778680556370923606923016458353128173727636088941150671422181521841587").unwrap(), ] ); let vk = VerifyingKeyComponents::new( vec![ - U256::from_dec_str("4155898266631322214574856388057229131381603659142355428000239527171539910720").unwrap(), - U256::from_dec_str("15919304600573806746067202721026223664629992455130946331020176989460510062648").unwrap(), + U256::from_dec_str("10908812779208764458926225885786000177375281860565170285671641496279275861828").unwrap(), + U256::from_dec_str("9799857308176907495837560301836136037191379657982632569243527710538263747953").unwrap(), ], vec![ vec![ - U256::from_dec_str("10559477888637541108523299513483158185288656601390229631277602982302056830264").unwrap(), - U256::from_dec_str("21518216923189214839507247102243744126930049565774641401859791113452178471842").unwrap(), + U256::from_dec_str("8875574684981713823643201920386676384608102436522842095334134617286263764542").unwrap(), + U256::from_dec_str("6479740794118221987496646366125424954976260650207607249416083588160064029713").unwrap(), ], vec![ - U256::from_dec_str("20524972206762616004058259260290957844870248494446046806278424843369643489182").unwrap(), - U256::from_dec_str("17430943082223119961631960086233630485654941075995072846024219998674392652581").unwrap(), + U256::from_dec_str("2000063549109574433659751301145359407962925053546745695255853892415998211427").unwrap(), + U256::from_dec_str("8978561107432458649913523321794599249451491250594440475529904908089104723622").unwrap(), ], ], vec![ vec![ - U256::from_dec_str("4636362103930283526843587215716464395878300635435610009766312980459671398351").unwrap(), - U256::from_dec_str("15713999866924132629927290621261290205960872899800820372400263081232019214301").unwrap(), + U256::from_dec_str("300802291087457914851925428899689384077331048328269093618223108664964823570").unwrap(), + U256::from_dec_str("8865288388013568285490817864856410066558523665602904501832397747932479098531").unwrap(), ], vec![ - U256::from_dec_str("274224283373606674211197218239218941312046485596075799302472837928822177016").unwrap(), - U256::from_dec_str("10693491445395060496723678108216498586881120243971297703830999940561952271629").unwrap(), - ], + U256::from_dec_str("19869995418496215898062302965642426582779874214462186317706024702601899014194").unwrap(), + U256::from_dec_str("13390306745571857664751285542582216134343088779623754549999133942932770241738").unwrap(), + ] ], vec![ vec![ - U256::from_dec_str("9540601502504552621404908678855872975596983734893914263055690675850649191273").unwrap(), - U256::from_dec_str("10288168694112392204164781631687615725045294841966564539511156565183262528849").unwrap(), + U256::from_dec_str("4865530596920678143514720246031070564475186170621062271332162290940892835646").unwrap(), + U256::from_dec_str("425558782916879613747479872909542286212413009319811627068712669719204459009").unwrap(), ], vec![ - U256::from_dec_str("16504160099082952601826232467479510151840980336862791499394346450083636791102").unwrap(), - U256::from_dec_str("9210167978306154509907086298616199856898787966613435045760659519455958969992").unwrap(), - ] + U256::from_dec_str("14280364779325396808134659809671863728861497766987810166986747587937753155420").unwrap(), + U256::from_dec_str("10157821355317239779823773394681666569085014825500396192845621348313614416302").unwrap(), + ], ], vec![ vec![ - U256::from_dec_str("15812098394101742886061540987450559986219804469912805896076341688421241661621").unwrap(), - U256::from_dec_str("11920211969663783445335622417572072568292106489672989284415235777753260953099").unwrap(), + U256::from_dec_str("5077257330623675885939934768370950104582038333816470525140085934362181966137").unwrap(), + U256::from_dec_str("21590736165200670756412215987782110683410511192188292195822616418371654753741").unwrap(), ], vec![ - U256::from_dec_str("7061409000327933635430701054193661775345794014516696263402966093123651666364").unwrap(), - U256::from_dec_str("17078047162776906089011285464212202278306676406084693061907121919624683442357").unwrap(), - ] + U256::from_dec_str("18280467089374114886419816344796237013631762412466882786964276277982883666042").unwrap(), + U256::from_dec_str("11485344019443762604807444303195364775881039088908610566033356938937497764373").unwrap(), + ], + vec![ + U256::from_dec_str("1751181504701297498660939287755176392070958106184310143186418668952529701336").unwrap(), + U256::from_dec_str("18736932220693579046179817485414749648152355566594839961039608036135808206151").unwrap(), + ], + vec![ + U256::from_dec_str("21312152220282516002927156143098977719015192971046736078567907261902527789628").unwrap(), + U256::from_dec_str("10860773398015071182683502891538197212844225511698561100014964817267559412040").unwrap(), + ], + vec![ + U256::from_dec_str("19213317000677932000832764919824843611437100907614316132834763294564357679030").unwrap(), + U256::from_dec_str("13111222029963575410995049632780974434271987081267940693386298389237806957098").unwrap(), + ], + vec![ + U256::from_dec_str("3443742642228361401389419381310437614798303534754415153009098249760587588145").unwrap(), + U256::from_dec_str("7744789485747118631461059019849731351689596466532055389408736826440805536735").unwrap(), + ], + vec![ + U256::from_dec_str("7435039988569923075244353313547948053391148527555628591292741199024066970135").unwrap(), + U256::from_dec_str("11046311630463377170355961221617143843117652341179127685539086936254925519686").unwrap(), + ], + vec![ + U256::from_dec_str("15297665691078029562294174705734310900359658439705626350781557084124323125519").unwrap(), + U256::from_dec_str("1364806105271580183714977095246233959855350281838839613346051539860853034390").unwrap(), + ], + vec![ + U256::from_dec_str("16182913767360895651204241660486317958300561196841976764409472315424042489856").unwrap(), + U256::from_dec_str("16339286891979828690592962765027450964989749947359765283073535710465615599250").unwrap(), + ], + vec![ + U256::from_dec_str("21575807155821147451222063394016891163053568165439964049101545653944062898132").unwrap(), + U256::from_dec_str("12371960356859909936672076205340736555848052976513199823807067061233917890308").unwrap(), + ], + vec![ + U256::from_dec_str("8990730410639111775085854283714024130596570124701374392253236961070523441877").unwrap(), + U256::from_dec_str("19255521192585577283930550804749005294045120462318692755332022063761472178542").unwrap(), + ], + vec![ + U256::from_dec_str("13320084394492248060490191350301804238250075203939012239448020526455826338619").unwrap(), + U256::from_dec_str("14257121049773316510902540165944619764221000278529377562530357678201148349783").unwrap(), + ], + vec![ + U256::from_dec_str("10413866546283584888554122264730221359972621491764741530663968262596943342816").unwrap(), + U256::from_dec_str("6517317702577541907505416253741115772092764156468351641670910298537704748423").unwrap(), + ], ] ); - let valid_input: Vec = vec![u64s_to_u256(vec![ - 9831528597301135316, - 11053911270256492840, - 14337707091878126846, - 772611368070892958 - ])]; + let valid_input = vec![ + U256::from_dec_str("1").unwrap(), + U256::from_dec_str("3").unwrap(), + U256::from_dec_str("6").unwrap(), + U256::from_dec_str("10").unwrap(), + U256::from_dec_str("15").unwrap(), + U256::from_dec_str("21").unwrap(), + U256::from_dec_str("28").unwrap(), + U256::from_dec_str("36").unwrap(), + U256::from_dec_str("45").unwrap(), + U256::from_dec_str("55").unwrap(), + U256::from_dec_str("66").unwrap(), + U256::from_dec_str("78").unwrap(), + ]; let verifying_key = VerifyingKey::new(proof, vk, valid_input); @@ -1010,39 +3241,31 @@ benchmarks! { validate, ::config(), ); - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "Benchmarking call end.", - // ); match call_runner_results { Ok(info) => { let output = info.value; - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "output result {:?}", - // output - // ); if output.len() >= 32 { let mut result_bytes = [0u8; 32]; result_bytes.copy_from_slice(&output[output.len() - 32..]); let result = U256::from_big_endian(&result_bytes); - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "nconstraints_30_input_100 Verification result {result:?}", - // ); + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "sumout_12 Verification result {result:?}", + ); assert_eq!(result, U256::one(), "The contract did not return true"); } }, Err(e) => { log::info!( target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - "nconstraints_30_input_100 Benchmarking failed", + "sumout_12 Benchmarking failed", ); assert!(false, "Benchmarking failed"); } } } - nconstraints_30_input_1000 { + + sumout_15 { use frame_benchmarking::vec; use sp_core::{H160, U256, H256}; @@ -1051,78 +3274,145 @@ benchmarks! { let proof = Proof::new( vec![ - U256::from_dec_str("21424271595387505713049534900676381136649432939050012296331964885140120988520").unwrap(), - U256::from_dec_str("20488789316104689748479888121024139144355086386496471461763924485714534718686").unwrap(), + U256::from_dec_str("21585823022431357826313674931621886543236834982289246714992743286376977868419").unwrap(), + U256::from_dec_str("7586678945863927211661133741820075312545324139326102654404133129309244972746").unwrap(), ], vec![ vec![ - U256::from_dec_str("8417699613540073682519718294821269056423071880647667978060348740795273915651").unwrap(), - U256::from_dec_str("4036859279888161250878359321718658739242283134835030699023268489309754993434").unwrap(), + U256::from_dec_str("17555814517186373100161784981688729927129395923544443054321966341581129282393").unwrap(), + U256::from_dec_str("7282547604111412630488355620323254420866246961778488838010455131596810507996").unwrap(), ], vec![ - U256::from_dec_str("16249800568747110450527363597274431407786919086057853194987169090454936230259").unwrap(), - U256::from_dec_str("15005851458712291005106538565823270955208428726378749297397203143137382225457").unwrap(), + U256::from_dec_str("20713205203394977430100275064206656162423873472847285768042185373389150331759").unwrap(), + U256::from_dec_str("21594434550845851185653620887682118555994201709039016918315905233204134362395").unwrap(), ], ], vec![ - U256::from_dec_str("21239990703864671714190525785674088715931473556140655107585637961585812134589").unwrap(), - U256::from_dec_str("261928180985765917331919571442880380998408670702589931014636966043229919418").unwrap(), + U256::from_dec_str("9553527308364266671450755468661721124726046549095186915848897612832666669104").unwrap(), + U256::from_dec_str("11201734029982017624737447275065436309338979180962200791637778279686032883214").unwrap(), ] ); let vk = VerifyingKeyComponents::new( vec![ - U256::from_dec_str("1657406292532781196449359079614579852690925607592278296574718289470803732053").unwrap(), - U256::from_dec_str("18213557747942747074556848145237207574111244905157024361329330629173034829885").unwrap(), + U256::from_dec_str("3216230770444528088776158534242932327068728121815873071849223010607020335058").unwrap(), + U256::from_dec_str("21035809065301821627526137231507537292096888122223808691041174759761119220267").unwrap(), ], vec![ vec![ - U256::from_dec_str("5419856735820685908218319193906907396496344921642651266629131019868853843815").unwrap(), - U256::from_dec_str("14007905369450574044915098075029863272475910046750101274280969769181784166430").unwrap(), + U256::from_dec_str("3117446826555143230699140819891988283299523756237412166668770967385826469061").unwrap(), + U256::from_dec_str("1106011150835632885010646871826845378592629967358666497747945481466306112631").unwrap(), ], vec![ - U256::from_dec_str("182200131698860550444455761364918630551676350878779858078817264277300629723").unwrap(), - U256::from_dec_str("6050431818377820601319883600432739448105157482353041283628740094609821419656").unwrap(), + U256::from_dec_str("2031803257794032494221338998687539109995321195789701372872082220755008700935").unwrap(), + U256::from_dec_str("11356081879090717733075995723613325531791197494523954848147361327178076996398").unwrap(), ], ], vec![ vec![ - U256::from_dec_str("14463567879100083166257564330995533094334991709675023767975192973144798919122").unwrap(), - U256::from_dec_str("6166287541473141918830331239835928582190744434356526822227225877844349692203").unwrap(), + U256::from_dec_str("18501235594532758685356617643293397665990404990535859450562994349740531359954").unwrap(), + U256::from_dec_str("6064697307908680945151400145510311630157828610555420079802490329525473148112").unwrap(), ], vec![ - U256::from_dec_str("12512843744533735346513506961399336936527367720771340395643503621530703342395").unwrap(), - U256::from_dec_str("8394818975982736201521422268641084055810886358791398607930311472872317386487").unwrap(), - ], + U256::from_dec_str("7588288119916448725682829538677035363474240351868137059873143928863164784498").unwrap(), + U256::from_dec_str("9274782715817123279177582291910200696665013934498334039985344489430227846656").unwrap(), + ] ], vec![ vec![ - U256::from_dec_str("8757732756289429354419510422628896433407345473998310348115924113882282945326").unwrap(), - U256::from_dec_str("1610185885725147927651201796201713521257480620743342969197368887869230657180").unwrap(), + U256::from_dec_str("1371652079761960603156000555240109860059987026059613009913618544836739152585").unwrap(), + U256::from_dec_str("16438218313867099055033729216771189397229055480760839479410444015762186153011").unwrap(), ], vec![ - U256::from_dec_str("2834338214415807920713929739507915327763263469562351781747229949754640383374").unwrap(), - U256::from_dec_str("20761263923134391843554423575366232120525285729512411038267095810712916924016").unwrap(), - ] + U256::from_dec_str("21625074976737722082451218446149574583326591404236641360262678817113664694657").unwrap(), + U256::from_dec_str("20796091416200429030650333330639080121294047317030102213022681141542267122695").unwrap(), + ], ], vec![ vec![ - U256::from_dec_str("16585432354609922217222548226453277630464695131710476183479619760311567992522").unwrap(), - U256::from_dec_str("5379258900528839934525784961038010961454863754298062530193947624450477797122").unwrap(), + U256::from_dec_str("2269623709920728903617646620096243620327949366550222548011870028242497613358").unwrap(), + U256::from_dec_str("1721591364215678281087769539296348528917077738930021482596272432159152444992").unwrap(), ], vec![ - U256::from_dec_str("16825349369326282879106301528709807467071985531593215317852699692046311881677").unwrap(), - U256::from_dec_str("10540450379202726868409867306854114915477889581096312866635875249145708179576").unwrap(), - ] + U256::from_dec_str("4351290528334741701086467877839775176289883245427946235071571814919796918896").unwrap(), + U256::from_dec_str("4623623087098123792032780719067218809631814301015875737326472476776737187664").unwrap(), + ], + vec![ + U256::from_dec_str("10252611518525171358643906944080590081835551889067213413963176637715118491735").unwrap(), + U256::from_dec_str("12808501284953465818004421681457302335036426618905271633262458529689968964126").unwrap(), + ], + vec![ + U256::from_dec_str("10981451002832697773062138382859126275926702959532767987336745018160655315751").unwrap(), + U256::from_dec_str("9013927030633677625778473876432702183373603209076101904574814352400708922379").unwrap(), + ], + vec![ + U256::from_dec_str("20570333858794685470455854052142258100074980426834489402096708371481795292792").unwrap(), + U256::from_dec_str("15956512164458091255235753566653194130138151604902408378082844639163963683640").unwrap(), + ], + vec![ + U256::from_dec_str("1810920619373659655004366626576702325696132807184568159455273357389553192281").unwrap(), + U256::from_dec_str("1003480095719919700122990934105236095705355474829745254732375849367589900011").unwrap(), + ], + vec![ + U256::from_dec_str("13039615164171221481521921362114175385649000627043496255793789378858554035982").unwrap(), + U256::from_dec_str("17510910511311660067327571445074639404525503060298062838447037718941394979779").unwrap(), + ], + vec![ + U256::from_dec_str("14165329950765673430990332163153038866908713915209946170837286178877146886660").unwrap(), + U256::from_dec_str("20793339422175421707121785907356839672588761368373996623737044948407075380863").unwrap(), + ], + vec![ + U256::from_dec_str("3883256103961824093488903468324246690649140067919691822154370105123302528628").unwrap(), + U256::from_dec_str("7561475158831403196993480443820632892645092082726176558327718750568963291037").unwrap(), + ], + vec![ + U256::from_dec_str("409664433526832013116877287300401090775361274457633011032558918365352310607").unwrap(), + U256::from_dec_str("17915319827370112847684027302775847360731246969152629190102908994479804002536").unwrap(), + ], + vec![ + U256::from_dec_str("8783158326340533223560056224761519419016551580825409101025477639190392573598").unwrap(), + U256::from_dec_str("13707722239341829918696323583233367883921076402405851150543609078213603790929").unwrap(), + ], + vec![ + U256::from_dec_str("20473370039043622683429816021606510529102905509776081241485577312164955536715").unwrap(), + U256::from_dec_str("10758908262111334689282452504541297068601729063936562246389590828664826425253").unwrap(), + ], + vec![ + U256::from_dec_str("1475500216206520471930942390519271535125544856677111800223296044790407084884").unwrap(), + U256::from_dec_str("11779748037669787286041766573080352957811656930851243042004933736078318402770").unwrap(), + ], + vec![ + U256::from_dec_str("13598685577793421380004205729308386952260129613827073513489648865810711589158").unwrap(), + U256::from_dec_str("8828420191868575584209720851114347878775413131164313846108918081819270797245").unwrap(), + ], + vec![ + U256::from_dec_str("5841283600010020706817581126281272248796034770291297306880281256297906914129").unwrap(), + U256::from_dec_str("19573442695439575558179849102246406448222304178063434531164484895634034938076").unwrap(), + ], + vec![ + U256::from_dec_str("12732593393130810020796334300053525912829502041711447313821913815961692050846").unwrap(), + U256::from_dec_str("2396355716633209699405102047603034959746626203843654407433538259302908360443").unwrap(), + ], ] ); - let valid_input: Vec = vec![u64s_to_u256(vec![ - 3008789406746563016, - 7061370202899273426, - 2191755323004339933, - 1005591455220622530 - ])]; + let valid_input = vec![ + U256::from_dec_str("1").unwrap(), + U256::from_dec_str("3").unwrap(), + U256::from_dec_str("6").unwrap(), + U256::from_dec_str("10").unwrap(), + U256::from_dec_str("15").unwrap(), + U256::from_dec_str("21").unwrap(), + U256::from_dec_str("28").unwrap(), + U256::from_dec_str("36").unwrap(), + U256::from_dec_str("45").unwrap(), + U256::from_dec_str("55").unwrap(), + U256::from_dec_str("66").unwrap(), + U256::from_dec_str("78").unwrap(), + U256::from_dec_str("91").unwrap(), + U256::from_dec_str("105").unwrap(), + U256::from_dec_str("120").unwrap(), + ]; let verifying_key = VerifyingKey::new(proof, vk, valid_input); @@ -1152,39 +3442,31 @@ benchmarks! { validate, ::config(), ); - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "Benchmarking call end.", - // ); match call_runner_results { Ok(info) => { let output = info.value; - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "output result {:?}", - // output - // ); if output.len() >= 32 { let mut result_bytes = [0u8; 32]; result_bytes.copy_from_slice(&output[output.len() - 32..]); let result = U256::from_big_endian(&result_bytes); - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "nconstraints_30_input_1000 Verification result {result:?}", - // ); + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "sumout_15 Verification result {result:?}", + ); assert_eq!(result, U256::one(), "The contract did not return true"); } }, Err(e) => { log::info!( target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - "nconstraints_30_input_1000 Benchmarking failed", + "sumout_15 Benchmarking failed", ); assert!(false, "Benchmarking failed"); } } } - nconstraints_30_input_5000 { + + sumout_18 { use frame_benchmarking::vec; use sp_core::{H160, U256, H256}; @@ -1193,78 +3475,160 @@ benchmarks! { let proof = Proof::new( vec![ - U256::from_dec_str("4760178114933307527976205229418881302833473087272893863010681924222436742436").unwrap(), - U256::from_dec_str("6555056836023646163359279772724076765411780318148657506988760187885700674215").unwrap(), + U256::from_dec_str("12430633769581102247540296520133403875606526791119053988338140734241680888772").unwrap(), + U256::from_dec_str("18442332250316996812297811822409136992315114037253390339439613098875601509891").unwrap(), ], vec![ vec![ - U256::from_dec_str("9540205596737585525189386078607957630969059503165883907845238817662495399607").unwrap(), - U256::from_dec_str("21777913747079267536001051597001736802905779914683258171463923506869689358122").unwrap(), + U256::from_dec_str("8769812720201850845212552423116339332017173636860658639095486287960968364628").unwrap(), + U256::from_dec_str("15679609225338281006396442534228723562221249428725922637917135773932321194569").unwrap(), ], vec![ - U256::from_dec_str("7652162643714058076103867092157642519402862581818067281609790687905833151647").unwrap(), - U256::from_dec_str("5174136241284192352871549806655421810249317805219641765935618077180420544939").unwrap(), + U256::from_dec_str("11736822938524029545900531415301990557371724695717091442770706694108764792897").unwrap(), + U256::from_dec_str("14276131700804161157283912487255205591674223192147331953987891031341492138831").unwrap(), ], ], vec![ - U256::from_dec_str("9633653417112713107386510132385608824105920168790226750481878454006412372444").unwrap(), - U256::from_dec_str("5600932933208824148570351176368803282808856587672889614186338874655752173453").unwrap(), + U256::from_dec_str("13829860464295019021916660157613562204483787530756857271489430053870068539213").unwrap(), + U256::from_dec_str("2635154643612779766721540915999489277398619320264472919611172655006207593243").unwrap(), ] ); let vk = VerifyingKeyComponents::new( vec![ - U256::from_dec_str("20563201722283471489193032980811350162387466733119686723832100493505332037220").unwrap(), - U256::from_dec_str("458683337854426284881131074995322438618437423037306322290239745015633774839").unwrap(), + U256::from_dec_str("11478354889186703145064785718789051075161412405402409375958203264983577174612").unwrap(), + U256::from_dec_str("2051932981799192988614815520842778215358192513999820653139553771063993577502").unwrap(), ], vec![ vec![ - U256::from_dec_str("802687519037697530569139206036966996588449135138601551566343295868421688400").unwrap(), - U256::from_dec_str("10902489968444563758310974921240106861656913905085710523025258522577834664814").unwrap(), + U256::from_dec_str("19202672763976837199930038746574488489616398769933191173401842283930856630824").unwrap(), + U256::from_dec_str("9894585412193132052039710787371205702047848152467990282623721538452088473643").unwrap(), ], vec![ - U256::from_dec_str("8163282908300075270434111132545381898266738500810094061899946027883982232155").unwrap(), - U256::from_dec_str("2879234862354419255322548813414679750617024208122660306082351289172177493856").unwrap(), + U256::from_dec_str("11087012751377729871020942087037603184858545608921665053341734432443613964736").unwrap(), + U256::from_dec_str("19920592886298080734865733588618209252746933681013350273253589451940373444177").unwrap(), ], ], vec![ vec![ - U256::from_dec_str("12946416399098615767859440028401625777970463338055590127763655113029764523456").unwrap(), - U256::from_dec_str("19000556224902286061769815260124368973839417953399533885850283592096662743016").unwrap(), + U256::from_dec_str("3442170070232630048373467858370187550597693105970967239471088845868856625578").unwrap(), + U256::from_dec_str("2565836555349760764341846699730262037514609346007897474387212424068759288925").unwrap(), ], vec![ - U256::from_dec_str("16883066945921282046110808795753929362007100542422795769422243319629113077450").unwrap(), - U256::from_dec_str("3229017908221308993692674040951942449106283130433174678816420254626513367678").unwrap(), - ], + U256::from_dec_str("9177399628115629455311170363743761185656955089341861651556728182077007742962").unwrap(), + U256::from_dec_str("8978098454385577234885149545555358562524532626359474543660036795706680306193").unwrap(), + ] ], vec![ vec![ - U256::from_dec_str("16459854676924169388774046538295013154707390397685062918225181412137603478923").unwrap(), - U256::from_dec_str("20996869365345436816737319903210535785982053153529758285286719146777762981985").unwrap(), + U256::from_dec_str("3475249974036476162964977391934788659886943458806724530569597219135120562284").unwrap(), + U256::from_dec_str("5909974155820403611803060790871333693814260546794228782122506894217269077189").unwrap(), ], vec![ - U256::from_dec_str("21446959969822179574296836241978980045198577120638747119902976563053247153220").unwrap(), - U256::from_dec_str("4716297282146551186330252875195511360280503254452482577157100992033023717484").unwrap(), - ] + U256::from_dec_str("8948147707464445512770554781127804344587029394518818985316769045847167306053").unwrap(), + U256::from_dec_str("6244220639119464514520028052853849971703107458448799275761796309223160549660").unwrap(), + ], ], vec![ vec![ - U256::from_dec_str("2127664998061023131080125201643658604092063304061707222326237054428506173927").unwrap(), - U256::from_dec_str("13918137729545385379467184110597023571257121066683873930760549927318081992996").unwrap(), + U256::from_dec_str("2066389909367768648597251810241027238345950972070643168750070171403496171911").unwrap(), + U256::from_dec_str("1898304115952366298651129001635333706379006960765262098012458123450995159651").unwrap(), ], vec![ - U256::from_dec_str("16560640526003408304721205785917894782070253870764339317137905014294472374327").unwrap(), - U256::from_dec_str("19394535992291030838186763750684977819230291410826312937425829210188321257228").unwrap(), - ] + U256::from_dec_str("1856555603107176523301771843124578764710746111740718726027487402075434689409").unwrap(), + U256::from_dec_str("7410693559992655229357237250636084977735760442337432185456859934632425894132").unwrap(), + ], + vec![ + U256::from_dec_str("17947286896053445598360953488679420610443470034968632274205506527392450039725").unwrap(), + U256::from_dec_str("3895334080718582330725304074745412588636689677985273210895763904111201321640").unwrap(), + ], + vec![ + U256::from_dec_str("21416214099488461436673890273348837879747513591241316002695561057333083776292").unwrap(), + U256::from_dec_str("3391691542348081290104434304460012299076546080317713666198018566085844483904").unwrap(), + ], + vec![ + U256::from_dec_str("5831865841542264981997258578340410586666887289198813310234035199414406992287").unwrap(), + U256::from_dec_str("541152292220907791488763854655135017975093511835597661057761318298652196836").unwrap(), + ], + vec![ + U256::from_dec_str("5056168195537204983120415283750457101925458655675783189653370539259027807168").unwrap(), + U256::from_dec_str("11956502234641567117145556474094025233261632560009796443598718512204491926824").unwrap(), + ], + vec![ + U256::from_dec_str("6001795269485013587505281910832139630835802223081148889043717533427764920854").unwrap(), + U256::from_dec_str("4228015156236533342169460797257057970676666487255154758089286838763712626409").unwrap(), + ], + vec![ + U256::from_dec_str("5462314927338346325491378900451830239683587227473550602000626797213724740299").unwrap(), + U256::from_dec_str("1884219370385302317855636369662856824751120927325767389612486204220720900912").unwrap(), + ], + vec![ + U256::from_dec_str("13243039687919994991813543240226795294935323461312147727968488200651708291457").unwrap(), + U256::from_dec_str("827035014682483050709645177362885116745935024256222539550691237849700735839").unwrap(), + ], + vec![ + U256::from_dec_str("15681975845101161355157873836131193921807006515040811534580021927544498786807").unwrap(), + U256::from_dec_str("18756207560876955742174557757015375223394082477254380529240274611994283460010").unwrap(), + ], + vec![ + U256::from_dec_str("1882705712389915779003978943973188953955260555599932161800577389240520357270").unwrap(), + U256::from_dec_str("8629850575835595094144763041260818362612673534288612613928346317196841467522").unwrap(), + ], + vec![ + U256::from_dec_str("8745855082804994819863529631763084442816205249584071058941190555898569479735").unwrap(), + U256::from_dec_str("21692253036198249194141883338115917121473268018207126949013452222295505497687").unwrap(), + ], + vec![ + U256::from_dec_str("12613094626743071120691866963796778649837681616812682051563400684414421533813").unwrap(), + U256::from_dec_str("9365490776656343962433114014307365201522923168991847888677225365929586030792").unwrap(), + ], + vec![ + U256::from_dec_str("6793880159203088817715392452604750348453297413441771558492674201855922113128").unwrap(), + U256::from_dec_str("14346139603312465753236789574853960983726518372342712328180962073472090606196").unwrap(), + ], + vec![ + U256::from_dec_str("12253978157854975741926086916623300218115958594798658756062517256213069901319").unwrap(), + U256::from_dec_str("15755875237340037763639033271530197989745016797836395000137836295436129566278").unwrap(), + ], + vec![ + U256::from_dec_str("17526046055364152839416951169028421866813866182183381491456998835227689276379").unwrap(), + U256::from_dec_str("8841542110539524297880983325365406606216349430596688342346193657692690166816").unwrap(), + ], + vec![ + U256::from_dec_str("18615347970012612210861525771234905658961350491594352447044050613860219550724").unwrap(), + U256::from_dec_str("3923619697613397146786407151934132719962859996691619643410472870976985170973").unwrap(), + ], + vec![ + U256::from_dec_str("20291060583560144641358065825340025080860431713628862915256408411377719001439").unwrap(), + U256::from_dec_str("17123445630419458544438131056773390642498133859695306119353438106606840478651").unwrap(), + ], + vec![ + U256::from_dec_str("4202847509845861205906637237139552898497275001434929028982440441966918234993").unwrap(), + U256::from_dec_str("10019675637336603739195974439962186867185262170660507535822968246476463670570").unwrap(), + ], ] ); - let valid_input: Vec = vec![u64s_to_u256(vec![ - 13212982172557049181, - 17043673098390055166, - 13971391527459105160, - 1729491887349651790, - ])]; + let valid_input = vec![ + U256::from_dec_str("1").unwrap(), + U256::from_dec_str("3").unwrap(), + U256::from_dec_str("6").unwrap(), + U256::from_dec_str("10").unwrap(), + U256::from_dec_str("15").unwrap(), + U256::from_dec_str("21").unwrap(), + U256::from_dec_str("28").unwrap(), + U256::from_dec_str("36").unwrap(), + U256::from_dec_str("45").unwrap(), + U256::from_dec_str("55").unwrap(), + U256::from_dec_str("66").unwrap(), + U256::from_dec_str("78").unwrap(), + U256::from_dec_str("91").unwrap(), + U256::from_dec_str("105").unwrap(), + U256::from_dec_str("120").unwrap(), + U256::from_dec_str("136").unwrap(), + U256::from_dec_str("153").unwrap(), + U256::from_dec_str("171").unwrap(), + ]; let verifying_key = VerifyingKey::new(proof, vk, valid_input); @@ -1294,39 +3658,31 @@ benchmarks! { validate, ::config(), ); - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "Benchmarking call end.", - // ); match call_runner_results { Ok(info) => { let output = info.value; - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "output result {:?}", - // output - // ); if output.len() >= 32 { let mut result_bytes = [0u8; 32]; result_bytes.copy_from_slice(&output[output.len() - 32..]); let result = U256::from_big_endian(&result_bytes); - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "nconstraints_30_input_5000 Verification result {result:?}", - // ); + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "sumout_18 Verification result {result:?}", + ); assert_eq!(result, U256::one(), "The contract did not return true"); } }, Err(e) => { log::info!( target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - "nconstraints_30_input_5000 Benchmarking failed", + "sumout_18 Benchmarking failed", ); assert!(false, "Benchmarking failed"); } } } - nconstraints_30_input_10000 { + + sumout_20 { use frame_benchmarking::vec; use sp_core::{H160, U256, H256}; @@ -1335,78 +3691,170 @@ benchmarks! { let proof = Proof::new( vec![ - U256::from_dec_str("20201588552006483041582128307591335561381558661958982754827324334159524114833").unwrap(), - U256::from_dec_str("17768889616334897699714190449991059857597665579001510168911964966707846254013").unwrap(), + U256::from_dec_str("5656680928965688826993118194012753618765968357565979972595276559147873694083").unwrap(), + U256::from_dec_str("6967549426192095910922952274984550698556833242157857540292539138373310729143").unwrap(), ], vec![ vec![ - U256::from_dec_str("831427914683469755258685737297441858923030844026909228595596228891513784401").unwrap(), - U256::from_dec_str("17358733390631981546461856303504163975689822422160671163593908204299387350560").unwrap(), + U256::from_dec_str("19268885367267656136131197855524200613191251527598109247559449729103347917426").unwrap(), + U256::from_dec_str("13276555837892122843601384924562081175658016150684783638795380360267979518059").unwrap(), ], vec![ - U256::from_dec_str("12673178383954759426828314411760863182427996098705680584931403917390222262168").unwrap(), - U256::from_dec_str("12056092533572380482681874959737292916971452073896642753405050795241584080793").unwrap(), + U256::from_dec_str("6192395283135706284507684938197927443456404304371530286126690358787918110065").unwrap(), + U256::from_dec_str("8819009190264908298811100900277161411847764736308179893794014638324292594780").unwrap(), ], ], vec![ - U256::from_dec_str("11086630979744216291689656728938462056245402184490217943698398792953833540899").unwrap(), - U256::from_dec_str("6981043472993913602669753829495794560155248771335035866541870305230603679484").unwrap(), + U256::from_dec_str("12737674974511230996771863495830727745486180187120990738854988060882540937222").unwrap(), + U256::from_dec_str("17139125343511579901747204746002442189775589547519308944117697554234845166515").unwrap(), ] ); let vk = VerifyingKeyComponents::new( vec![ - U256::from_dec_str("10088605449330278081588905225706913827985798761474642054412607299987851491561").unwrap(), - U256::from_dec_str("12349112716571349951448807635426375878752472531266562453302627732729311140226").unwrap(), + U256::from_dec_str("244263057245854881181695352829624456418211798865192445082991456290482557985").unwrap(), + U256::from_dec_str("11379591029981368411890266449113199799040076029174714233656465956470810325768").unwrap(), ], vec![ vec![ - U256::from_dec_str("11234930657858483584603353214391341220392609835907149947974795594440445721655").unwrap(), - U256::from_dec_str("1047093079337214465686469751128183347143657884406521365857439579470759333731").unwrap(), + U256::from_dec_str("21682669782412056972659921333433470180823921348801871274366645367524620903864").unwrap(), + U256::from_dec_str("2455009268298884604476741290429694617356204701265455596321899599145219280549").unwrap(), ], vec![ - U256::from_dec_str("15864899975231343872664645828141071246029692141564279838230890638453916423742").unwrap(), - U256::from_dec_str("12053277475368564348616897081746431255423835262329161057768339971384736640081").unwrap(), + U256::from_dec_str("21125883925383156333929232848711525380172926056014142857886611755830225500203").unwrap(), + U256::from_dec_str("15135796545808937165305203902401320696776563359425008931719414027175268786847").unwrap(), ], ], vec![ vec![ - U256::from_dec_str("20662189442791195318296211376162761628558291902545582141646463139520777475283").unwrap(), - U256::from_dec_str("9279465006661849499753241364514057268552316193158700659184124742215268752791").unwrap(), + U256::from_dec_str("15450920303903437518361455913102265455988608824135846597836221037214352737619").unwrap(), + U256::from_dec_str("11439120571496221085972693042194450422532276411899764622108255930379779573186").unwrap(), ], vec![ - U256::from_dec_str("17033606864312833588672465768726096906720807717470346504048425104291392352898").unwrap(), - U256::from_dec_str("15319242533246792039334613039385600689133248724151496600840914674340560979641").unwrap(), - ], + U256::from_dec_str("5504373244182826481954471057557555369791621799450298835807839203848086857375").unwrap(), + U256::from_dec_str("5801334494957666066246189629199512612886312175942824799309062312586542544118").unwrap(), + ] ], vec![ vec![ - U256::from_dec_str("3303817333656562581428241644233610206796391323593261940899405821542387319372").unwrap(), - U256::from_dec_str("12434486975702473910116656089923156849733601159782506519440013280731025013736").unwrap(), + U256::from_dec_str("1141374384314887705660896617887241019152129114063489281405071135888366753641").unwrap(), + U256::from_dec_str("13076370956699658631269582407826656960323339094757103831961309662392298659347").unwrap(), ], vec![ - U256::from_dec_str("9561232329300105849651786447909752108987569955850131116304832039966768267007").unwrap(), - U256::from_dec_str("18486557213071145739422364713271115450952939790314495487369777335095317193174").unwrap(), - ] + U256::from_dec_str("4426949087394010699249325505509668334533507346720007620471403313387916351148").unwrap(), + U256::from_dec_str("4708947509252113613324407090303358949370926839796559574786305350757928334665").unwrap(), + ], ], vec![ vec![ - U256::from_dec_str("5864321703423906069527768678401445332135246771872328360194332677453860634867").unwrap(), - U256::from_dec_str("3305620141441221125469209629518919979790470359050105194093502369856652644459").unwrap(), + U256::from_dec_str("7357683365595790287993998127975259977742608220801091434413870585009415257676").unwrap(), + U256::from_dec_str("1506871282350279588306866242730945049104836644264089499533750872901945500369").unwrap(), ], vec![ - U256::from_dec_str("1810088252629429255118238329671475280643793553294287131634484491846973310510").unwrap(), - U256::from_dec_str("20707970746663158481851347112547705553728126185220754421254503093218351233120").unwrap(), - ] + U256::from_dec_str("17603107985343948702246104170283386613575028902039517361540799399845966575171").unwrap(), + U256::from_dec_str("18820643961153442592821124056307287292205523842039764422947098696032617853855").unwrap(), + ], + vec![ + U256::from_dec_str("17650798421825975173386758567164281203076719989952311509598797371365178680199").unwrap(), + U256::from_dec_str("17890175687403291785665866239824911374421216792676533545119802637975578402883").unwrap(), + ], + vec![ + U256::from_dec_str("16455874793994696207521701175245486604558008503740725889172000827379626158043").unwrap(), + U256::from_dec_str("14031822690471685955088571269493319864920100659777524458853309643802282343571").unwrap(), + ], + vec![ + U256::from_dec_str("20217336577454114538708064936313780793013155591226224224827483353091280187207").unwrap(), + U256::from_dec_str("7274595912406355919980207840714132002561348049707935735401310529040588077044").unwrap(), + ], + vec![ + U256::from_dec_str("21481014700554264388848521790017731722166888066694391737960816015477266386487").unwrap(), + U256::from_dec_str("17455044584700880292255973227977239165349932901603612566533923980353194321813").unwrap(), + ], + vec![ + U256::from_dec_str("21397911766364883257937607904549984527882328767474455543633946325088982450338").unwrap(), + U256::from_dec_str("8473738210819751426980400124613437104723530057983009606149842528359834537276").unwrap(), + ], + vec![ + U256::from_dec_str("17581651979137517837372735764325843253645494664157105398993836978138260652408").unwrap(), + U256::from_dec_str("17769300675471550881080026982937776951432530235743530865543166960549108293804").unwrap(), + ], + vec![ + U256::from_dec_str("3642823531932009942227226738288531842509469524513016172644199939718550077569").unwrap(), + U256::from_dec_str("17432723582900147732334867408509412616629549151824191911587120144347800943104").unwrap(), + ], + vec![ + U256::from_dec_str("12421919210235701164201409268688646230307360862186347052760389576025389595076").unwrap(), + U256::from_dec_str("18330339236406203807629192609438039320235594597301963978705179812699763588479").unwrap(), + ], + vec![ + U256::from_dec_str("19947323889374706457771950555677486901830894290183470381305433037498145547023").unwrap(), + U256::from_dec_str("5203650088207812959138372874327437440900018099517864797228477559056193893752").unwrap(), + ], + vec![ + U256::from_dec_str("4255951379517667170373780028202354788803406813972719150978785542172116669531").unwrap(), + U256::from_dec_str("14451136209830519398067981987488499900976834426547453885610521940106213984929").unwrap(), + ], + vec![ + U256::from_dec_str("3925629517135871256290787439634621941614062463495442837265339103765138337761").unwrap(), + U256::from_dec_str("2497491815757381945749671166420308545458065641820045413388573704927695241813").unwrap(), + ], + vec![ + U256::from_dec_str("21466120707849646160137487346724407872042410344830040590993945475592511746214").unwrap(), + U256::from_dec_str("3045215934664432127908841075160905018526084085596312155808606706810118424050").unwrap(), + ], + vec![ + U256::from_dec_str("17180695787385241592651918696972083237984540030182966929320858606796263773636").unwrap(), + U256::from_dec_str("2049214809205333765116872668089154986377762659390367408031763978502033709374").unwrap(), + ], + vec![ + U256::from_dec_str("4774299874040054677277833517513219583032845720635034514759165863256091223071").unwrap(), + U256::from_dec_str("2817429278103215029312280393926618707332349894417886654266983777338602669217").unwrap(), + ], + vec![ + U256::from_dec_str("11849511390994459187777805386685940997731436566748603872125066265609444105290").unwrap(), + U256::from_dec_str("15749060430488318934192185845451610512322384322770593887198388744891795166876").unwrap(), + ], + vec![ + U256::from_dec_str("6816330773235217141791322362184115309193655994447714036407608955587670289691").unwrap(), + U256::from_dec_str("6202757244116766574486999165436015492276224399898135936516804984343474464324").unwrap(), + ], + vec![ + U256::from_dec_str("4472916876847760069533088181774934171702146143581240908666459515397433940327").unwrap(), + U256::from_dec_str("16847088658324790629288327397928655196248049022361853173150753668961227880157").unwrap(), + ], + vec![ + U256::from_dec_str("4704407312269183027827709279804690513392733846890090565911802030907318348957").unwrap(), + U256::from_dec_str("12023785273031858079896145099534749991123742716328675854453794204222375745635").unwrap(), + ], + vec![ + U256::from_dec_str("14489517201954926339160541383066537697773411650355771620316229200747554266343").unwrap(), + U256::from_dec_str("1201374487316207220705666090779729243474012798987516363690861140880166104963").unwrap(), + ], ] ); - let valid_input: Vec = vec![u64s_to_u256(vec![ - 11033755416221607095, - 14172640425079373737, - 17268699570210893519, - 2451003838444787962, - ])]; + let valid_input = vec![ + U256::from_dec_str("1").unwrap(), + U256::from_dec_str("3").unwrap(), + U256::from_dec_str("6").unwrap(), + U256::from_dec_str("10").unwrap(), + U256::from_dec_str("15").unwrap(), + U256::from_dec_str("21").unwrap(), + U256::from_dec_str("28").unwrap(), + U256::from_dec_str("36").unwrap(), + U256::from_dec_str("45").unwrap(), + U256::from_dec_str("55").unwrap(), + U256::from_dec_str("66").unwrap(), + U256::from_dec_str("78").unwrap(), + U256::from_dec_str("91").unwrap(), + U256::from_dec_str("105").unwrap(), + U256::from_dec_str("120").unwrap(), + U256::from_dec_str("136").unwrap(), + U256::from_dec_str("153").unwrap(), + U256::from_dec_str("171").unwrap(), + U256::from_dec_str("190").unwrap(), + U256::from_dec_str("210").unwrap(), + ]; let verifying_key = VerifyingKey::new(proof, vk, valid_input); @@ -1436,40 +3884,31 @@ benchmarks! { validate, ::config(), ); - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "Benchmarking call end.", - // ); match call_runner_results { Ok(info) => { let output = info.value; - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "output result {:?}", - // output - // ); if output.len() >= 32 { let mut result_bytes = [0u8; 32]; result_bytes.copy_from_slice(&output[output.len() - 32..]); let result = U256::from_big_endian(&result_bytes); - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "nconstraints_30_input_10000 Verification result {result:?}", - // ); + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "sumout_20 Verification result {result:?}", + ); assert_eq!(result, U256::one(), "The contract did not return true"); } }, Err(e) => { log::info!( target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - "nconstraints_30_input_10000 Benchmarking failed", + "sumout_20 Benchmarking failed", ); assert!(false, "Benchmarking failed"); - } } } - nconstraints_30_input_90000 { + + sumout_50 { use frame_benchmarking::vec; use sp_core::{H160, U256, H256}; @@ -1478,777 +3917,320 @@ benchmarks! { let proof = Proof::new( vec![ - U256::from_dec_str("7949275001087845673352113652992317737416671749823042856819742064958185730665").unwrap(), - U256::from_dec_str("5891863541401068443747112095836743353338477825995666306081231182884954636005").unwrap(), + U256::from_dec_str("13827879866301415538857432999218866982628860414954597546568484592640037099744").unwrap(), + U256::from_dec_str("14551999579990087654454739665634365604997695433710312891076467259913934388803").unwrap(), ], vec![ vec![ - U256::from_dec_str("12960565378826264234747222392568347150301360486418725511109506548813034322775").unwrap(), - U256::from_dec_str("6924824876048701587380679111548259437770370772320848338373383587483809707515").unwrap(), + U256::from_dec_str("15771353158313563683613152088814408294817138752077129512988787477344110757188").unwrap(), + U256::from_dec_str("14399279855844834913268182033927156273557513850691671069599176570477483195735").unwrap(), ], vec![ - U256::from_dec_str("21689747160304810742710652756166876177223750769696622871469266436845305438116").unwrap(), - U256::from_dec_str("14167066926549192557125941689316913820167617731059401320567819691908586156039").unwrap(), + U256::from_dec_str("12275212562972350055374119845928748810285249001807183087376345867226594250614").unwrap(), + U256::from_dec_str("13756757166577921760248781523737155114632832632168220989358664582399059540764").unwrap(), ], ], vec![ - U256::from_dec_str("19186797317064887099470636752510606772753033946198593325337771098325482447274").unwrap(), - U256::from_dec_str("3350186543680262034371474397706130211690310055235028696466009478959025709845").unwrap(), + U256::from_dec_str("7744904145895296256394657338969049284442931947677085357490462223272611262824").unwrap(), + U256::from_dec_str("6220983930078260337427503798082895905560328943244814949511556092413235993784").unwrap(), ] ); let vk = VerifyingKeyComponents::new( vec![ - U256::from_dec_str("6828794497030502754628523747507406719479438181845328406281207577196379759609").unwrap(), - U256::from_dec_str("5561027388439947090438746111225212164455366280326670821700904471009784329896").unwrap(), + U256::from_dec_str("6115335040929689045763833235655184287313807320983573556493260194789528971686").unwrap(), + U256::from_dec_str("6166532138119800856613629046632439223273859498423658929523110122960131290393").unwrap(), ], vec![ vec![ - U256::from_dec_str("1648517694167305339737563900225685665396551354808983529387892872646841040850").unwrap(), - U256::from_dec_str("15406833006990307743521713564090315343374212223020060642984366610793788667116").unwrap(), + U256::from_dec_str("16072185984981940759925604108298758265427751820417866991432783389012340676920").unwrap(), + U256::from_dec_str("12038526475382871968757930147404918510943224535062619233972655078048128772207").unwrap(), ], vec![ - U256::from_dec_str("14591594646846027404699868040454897990147675572067174007423843530180728597612").unwrap(), - U256::from_dec_str("2940958434778941597191243007999700895445672570190450648227198352981565653913").unwrap(), + U256::from_dec_str("3357579678449381536683529270370009397075211562688187149111391775074561165741").unwrap(), + U256::from_dec_str("18242626048326784141288643701409962774080323384992795292954067136702849374522").unwrap(), ], ], vec![ vec![ - U256::from_dec_str("7676142418543194845482248509044991512324196983308812731866772308356979871307").unwrap(), - U256::from_dec_str("21511013842679919895947796523736214038726875927496967606596253311081756690725").unwrap(), + U256::from_dec_str("8666829685645767563314329202552522059811973795622694031857713490395410267737").unwrap(), + U256::from_dec_str("11859365458670977483026426220940789952575696888959917148983915658234029017108").unwrap(), ], vec![ - U256::from_dec_str("4652378032872178978450279958290699982888059033676566152376150880744787185780").unwrap(), - U256::from_dec_str("467504210088082002071026778234767679654059202832780062786965483300786044530").unwrap(), - ], + U256::from_dec_str("14130230782411277014762522839402392302490685104885373749038912991243039063851").unwrap(), + U256::from_dec_str("8372970790028263146112897121060860570673044309366330703937159104057494533039").unwrap(), + ] ], vec![ vec![ - U256::from_dec_str("20744282071154891204049714936088748576694067059171789505913191933597423689555").unwrap(), - U256::from_dec_str("12596866572762256583276410876169296807308160857887657727882625055041251553242").unwrap(), + U256::from_dec_str("17810070930649725073550928999479437396879560471136036549038763141608403698246").unwrap(), + U256::from_dec_str("5892003699669605510258891634989426469331530174006810427612794736057219035068").unwrap(), ], vec![ - U256::from_dec_str("3588798969790877834321031026222278845206273301850566393834657489341158616535").unwrap(), - U256::from_dec_str("19268326464935908053037454129640878232926568425004490855381855273084219557079").unwrap(), - ] + U256::from_dec_str("17627382974715312497434404825093389646496261744940225730753163482625180535264").unwrap(), + U256::from_dec_str("8810117541294897071211549144170262855239024685766481396194935888376586571442").unwrap(), + ], ], vec![ vec![ - U256::from_dec_str("10928515506460596401961934744263657631726985113185854450754018401146226707446").unwrap(), - U256::from_dec_str("1043421123157233618994554398894819122012315878788274412803269234825060696656").unwrap(), + U256::from_dec_str("657738098560847380495053334619058455958793334766494917034230275292791995444").unwrap(), + U256::from_dec_str("532105491296268554235023930179690358089560316352213261084871842896383948711").unwrap(), ], vec![ - U256::from_dec_str("21802758012415709270812560952687831790545411568500639317690833457802568775035").unwrap(), - U256::from_dec_str("8926874931677263335476856545765471099163606107894025045476086328360781102193").unwrap(), - ] - ] - ); - - let valid_input: Vec = vec![u64s_to_u256(vec![ - 2553457387449696641, - 815105491620421980, - 17800546104409657428, - 2866567216183504159, - ])]; - - let verifying_key = VerifyingKey::new(proof, vk, valid_input); - - let zk_verifier = ZKPrecompileVerifier::new( - H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), - verifying_key - ); - - let encoded_call = zk_verifier.generate_benchmarking_parameters(); - - let gas_limit_call = 1000000; - let value = U256::default(); - let is_transactional = true; - let validate = true; - }:{ - let call_runner_results = ::Runner::call( - caller, - contract_address, - encoded_call, - value, - gas_limit_call, - Some(U256::from(1_000_000_000)), - Some(U256::from(1_000_000_000)), - None, - Vec::new(), - is_transactional, - validate, - ::config(), - ); - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "Benchmarking call end.", - // ); - match call_runner_results { - Ok(info) => { - let output = info.value; - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "output result {:?}", - // output - // ); - if output.len() >= 32 { - let mut result_bytes = [0u8; 32]; - result_bytes.copy_from_slice(&output[output.len() - 32..]); - let result = U256::from_big_endian(&result_bytes); - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "nconstraints_30_input_90000 Verification result {result:?}", - // ); - assert_eq!(result, U256::one(), "The contract did not return true"); - } - }, - Err(e) => { - log::info!( - target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - "nconstraints_30_input_90000 Benchmarking failed", - ); - assert!(false, "Benchmarking failed"); - } - } - } - nconstraints_30_input_200000 { - use frame_benchmarking::vec; - use sp_core::{H160, U256, H256}; - - let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); - let contract_address = H160::from_low_u64_be(0x8888); - - let proof = Proof::new( - vec![ - U256::from_dec_str("19903885251949679146607224162906437591286076549652044731739108226015926915860").unwrap(), - U256::from_dec_str("11870922578907159231760438847634888925027596611865086487008358810346509550746").unwrap(), - ], - vec![ - vec![ - U256::from_dec_str("7572350741301793140585595336451242554319145556316993930579910816773197602180").unwrap(), - U256::from_dec_str("16166630091911008518878343585755669995589761813810965163203815419554661335912").unwrap(), + U256::from_dec_str("1097662479221345957152012749497455033885787513971827778405858673808706126572").unwrap(), + U256::from_dec_str("2447207493658220005172443593380979137893421348377510383419810991856073882654").unwrap(), ], vec![ - U256::from_dec_str("10479558631339350148140324543423297113164179377516410954282474094862685762111").unwrap(), - U256::from_dec_str("1538599836393367534859442557225095989831507256094436416355361165563840234277").unwrap(), + U256::from_dec_str("14987702786869929603736432978965272287140970095658077826321786680678257701539").unwrap(), + U256::from_dec_str("6623830625206727823787295668755924167882248998617207072323403593721086329595").unwrap(), ], - ], - vec![ - U256::from_dec_str("18566368172831132986640612657510108843544042128267080758083569019690510537842").unwrap(), - U256::from_dec_str("14637144036179606956000163117625168358523245864386632910728645092984303842870").unwrap(), - ] - ); - - let vk = VerifyingKeyComponents::new( - vec![ - U256::from_dec_str("3388366987275268645608688601800038483480506575351380219459271970783548315310").unwrap(), - U256::from_dec_str("10139982329791419477606385196757134153200700293861474061701578521738893563314").unwrap(), - ], - vec![ vec![ - U256::from_dec_str("17293003127353596916845398615566872053529832484770184120881889494052646686398").unwrap(), - U256::from_dec_str("3746742577904007471872553744363212404516454459540143078991207693255568088158").unwrap(), + U256::from_dec_str("16083000893807119940364492004763007744340588623320271607738723759855697960706").unwrap(), + U256::from_dec_str("14441879876890467114234414051431347036645300127848755680103166207990794576758").unwrap(), ], vec![ - U256::from_dec_str("18996426015092705424501193523094438770040629737761363033585766320236602756452").unwrap(), - U256::from_dec_str("5993252813486169444483155589566709251331252167093428959716521680127596688663").unwrap(), + U256::from_dec_str("15731029203716777672456183943350227025919210853689017608162251677628010445863").unwrap(), + U256::from_dec_str("3243323103776869275672187227239319642124956814578013158853719229338650062946").unwrap(), ], - ], - vec![ vec![ - U256::from_dec_str("86221489590459042456285770827248107701675460052532768290239949641616327672").unwrap(), - U256::from_dec_str("21618235778373592971185937996314200926578828337383413751502402964191761009384").unwrap(), + U256::from_dec_str("11507951232495383993382480534635046047566127951931310314719985521726794994855").unwrap(), + U256::from_dec_str("16521537108350445831368232156819046644534933711158400995311389097851953323826").unwrap(), ], vec![ - U256::from_dec_str("10453895050472290645179709462208119639593757329666114205922088367970822668124").unwrap(), - U256::from_dec_str("16924749634830145681809164670725933237166438445526123149706427927968513710893").unwrap(), + U256::from_dec_str("14900110644751936433863090329189868498744457501863570858210025530486652384145").unwrap(), + U256::from_dec_str("14359597649211951395870532227205969995295738578955836733248597883152057352152").unwrap(), ], - ], - vec![ vec![ - U256::from_dec_str("20506347836984398194650179863264269358088067779451739307543701941138658771117").unwrap(), - U256::from_dec_str("15256122081275324863091225387225218399888282841698960666742408225921079848693").unwrap(), + U256::from_dec_str("16088110181600531322538582358406898104352202099807306598784290518774717043236").unwrap(), + U256::from_dec_str("1939008393245671182845407198815819570976145968765277955677921816083337658264").unwrap(), ], vec![ - U256::from_dec_str("7881380592415293900063452944037916715621668238658562838630198037249553436647").unwrap(), - U256::from_dec_str("6003465274284900873747728448177380007802003937728590930467990944623586277089").unwrap(), - ] - ], - vec![ + U256::from_dec_str("1716154303829123720378392190766578286599416024855264465881476079904832192454").unwrap(), + U256::from_dec_str("15136578653408806943816555010155427299402698229965663640184024060430500322706").unwrap(), + ], vec![ - U256::from_dec_str("5531662187275540864474040102019845108669876235687831703751327129559212127084").unwrap(), - U256::from_dec_str("11455786949456856409363436892267690994602451302132959153447251790964376014822").unwrap(), + U256::from_dec_str("21607870289382776942440929696746256287606813134801627227394120993907081115482").unwrap(), + U256::from_dec_str("15216673476758896215159140003517149726322470027268268399303559990796350851668").unwrap(), ], vec![ - U256::from_dec_str("17221728819314881853232886080533000381382340762620795831983019279828981481257").unwrap(), - U256::from_dec_str("19341881794793455210912817199750586531241336493382870655971958667936340901503").unwrap(), - ] - ] - ); - - let valid_input: Vec = vec![u64s_to_u256(vec![ - 17510768071209558285, - 11281672863963944712, - 17936011136389338927, - 2683423138755332222, - ])]; - - let verifying_key = VerifyingKey::new(proof, vk, valid_input); - - let zk_verifier = ZKPrecompileVerifier::new( - H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), - verifying_key - ); - - let encoded_call = zk_verifier.generate_benchmarking_parameters(); - - let gas_limit_call = 1000000; - let value = U256::default(); - let is_transactional = true; - let validate = true; - }:{ - let call_runner_results = ::Runner::call( - caller, - contract_address, - encoded_call, - value, - gas_limit_call, - Some(U256::from(1_000_000_000)), - Some(U256::from(1_000_000_000)), - None, - Vec::new(), - is_transactional, - validate, - ::config(), - ); - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "Benchmarking call end.", - // ); - match call_runner_results { - Ok(info) => { - let output = info.value; - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "output result {:?}", - // output - // ); - if output.len() >= 32 { - let mut result_bytes = [0u8; 32]; - result_bytes.copy_from_slice(&output[output.len() - 32..]); - let result = U256::from_big_endian(&result_bytes); - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "nconstraints_30_input_200000 Verification result {result:?}", - // ); - assert_eq!(result, U256::one(), "The contract did not return true"); - } - }, - Err(e) => { - log::info!( - target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - "nconstraints_30_input_200000 Benchmarking failed", - ); - assert!(false, "Benchmarking failed"); - } - } - } - - sum_10 { - use frame_benchmarking::vec; - use sp_core::{H160, U256, H256}; - - let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); - let contract_address = H160::from_low_u64_be(0x8888); - - let proof = Proof::new( - vec![ - U256::from_dec_str("4479438672593572194843316486259284641920166054544576564310150763796220593742").unwrap(), - U256::from_dec_str("5717857931841301866217201485541887040818093727574311517591849036289507799141").unwrap(), - ], - vec![ + U256::from_dec_str("3470717514306671402640704490357575134271293191039101496626686232282200916588").unwrap(), + U256::from_dec_str("1644143157682464475771925146618463012305479502919125062639366962721572466038").unwrap(), + ], vec![ - U256::from_dec_str("438102211713357984070931589322877643391719193099221891191956755149301376056").unwrap(), - U256::from_dec_str("14696299438400225528910058565202329177181471318954607581306780544413371767738").unwrap(), + U256::from_dec_str("14141951040433426732708898160256492540100390122590931176192871614825767567823").unwrap(), + U256::from_dec_str("14970870554510027003883479850485276956804732428074135837976610927084756596698").unwrap(), ], vec![ - U256::from_dec_str("18723112929967827488252389384208353884816003870032279933823625467146809072448").unwrap(), - U256::from_dec_str("781225142569358922067919798403956593420009838230922093237868933021043854113").unwrap(), + U256::from_dec_str("6757052599412251823187168407425869720480978223208220243035283923157486962640").unwrap(), + U256::from_dec_str("19998998568187199475005177265892129077143217765879194219305910411258469180208").unwrap(), ], - ], - vec![ - U256::from_dec_str("10481213903673023503381125372528754955378591812884098928519623211332171467098").unwrap(), - U256::from_dec_str("15098195705682978185145469811146985310923026878303775073727891846327587112885").unwrap(), - ] - ); - - let vk = VerifyingKeyComponents::new( - vec![ - U256::from_dec_str("10600514820627226711889163536575359330497844540484876797299835164575096986123").unwrap(), - U256::from_dec_str("8955505242614929800342716899005854501255692108538633212406728467939250778259").unwrap(), - ], - vec![ vec![ - U256::from_dec_str("11358515176167160981846987587695931342878788452018419590778128561277894807040").unwrap(), - U256::from_dec_str("7367100375568995524851051084377016949291621141008718892167611998460177966556").unwrap(), + U256::from_dec_str("20881696828098941844228741422556682968632634770060670451389297054104176440621").unwrap(), + U256::from_dec_str("13608889661472160976940462761860587603342008277901142604062787628433773176010").unwrap(), ], vec![ - U256::from_dec_str("9986374126991936592889887298811366506288970021158383914729072242552712258999").unwrap(), - U256::from_dec_str("5917047061876555575617149777207682047359711575786648519096749890796145313142").unwrap(), + U256::from_dec_str("7213318721268961019485708544153236686954566374506720345579959324834177101641").unwrap(), + U256::from_dec_str("19592958466387187227162933705639453686422518128902348109190215207992371486918").unwrap(), ], - ], - vec![ vec![ - U256::from_dec_str("12470512550870605078154922234115021580073605821744497867586706681115325377951").unwrap(), - U256::from_dec_str("3964373607930903502336465614571930627592350216968107805643078708599943392195").unwrap(), + U256::from_dec_str("11492956236335799028306792618137865677945795549817827579564445070141572466907").unwrap(), + U256::from_dec_str("16711820022758729063513408191192188870792118206420418650892132773179116683557").unwrap(), ], vec![ - U256::from_dec_str("9054619931591683490625148848351137928205510101241639415537408964292455344707").unwrap(), - U256::from_dec_str("14433710971468466044075036729227299898791551573181475688890434779549865103322").unwrap(), - ] - ], - vec![ + U256::from_dec_str("20945069163147606665108872405227233214878505928402156102335106047734925593215").unwrap(), + U256::from_dec_str("1423987675745181080834644795321752693594601107027563001974881039188492021171").unwrap(), + ], vec![ - U256::from_dec_str("13008751738470482081156013535203222043379316308698376931322848604706786065862").unwrap(), - U256::from_dec_str("3415558414191757405655644967374577939532374518318643852418890898323033638525").unwrap(), + U256::from_dec_str("15891267199767390072540329971020389290472310562561860106988736756158294968407").unwrap(), + U256::from_dec_str("2267503153642457690523865861608670312822668575934691972853239401502939363062").unwrap(), ], vec![ - U256::from_dec_str("2104722493853714523712648261788727756558190509825976396834309269877977849365").unwrap(), - U256::from_dec_str("6877732520157662584755946842350755740172704606349660337522459938993730313391").unwrap(), + U256::from_dec_str("7474594013463066171479789286133270044299000414563424286960176499673549013911").unwrap(), + U256::from_dec_str("8122674047183480331694645349931807273093092753341828673326730648947527889665").unwrap(), ], - ], - vec![ vec![ - U256::from_dec_str("17691779713798847872985546462247707503645016076661816616388979822201176829753").unwrap(), - U256::from_dec_str("14451231434311244057691431183198403713720423327382654964068207207079455187712").unwrap(), + U256::from_dec_str("10257111743245921777033251489771345706287334159675215734672219144502175080691").unwrap(), + U256::from_dec_str("9949970303925511520216099354542476962005374285896059168560924362910911093080").unwrap(), ], vec![ - U256::from_dec_str("13620414910695185146987530463229819484652710069270717148541433045978322585419").unwrap(), - U256::from_dec_str("10875872907505029426874795808985164080699672034676409959252328566889297105865").unwrap(), - ] - ] - ); - - let valid_input = vec![ - U256::from_dec_str("55").unwrap() - ]; - - let verifying_key = VerifyingKey::new(proof, vk, valid_input); - - let zk_verifier = ZKPrecompileVerifier::new( - H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), - verifying_key - ); - - let encoded_call = zk_verifier.generate_benchmarking_parameters(); - - let gas_limit_call = 1000000; - let value = U256::default(); - let is_transactional = true; - let validate = true; - }:{ - let call_runner_results = ::Runner::call( - caller, - contract_address, - encoded_call, - value, - gas_limit_call, - Some(U256::from(1_000_000_000)), - Some(U256::from(1_000_000_000)), - None, - Vec::new(), - is_transactional, - validate, - ::config(), - ); - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "Benchmarking call end.", - // ); - match call_runner_results { - Ok(info) => { - let output = info.value; - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "output result {:?}", - // output - // ); - if output.len() >= 32 { - let mut result_bytes = [0u8; 32]; - result_bytes.copy_from_slice(&output[output.len() - 32..]); - let result = U256::from_big_endian(&result_bytes); - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "sum_10 Verification result {result:?}", - // ); - assert_eq!(result, U256::one(), "The contract did not return true"); - } - }, - Err(e) => { - log::info!( - target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - "sum_10Benchmarking failed", - ); - assert!(false, "Benchmarking failed"); - } - } - } - sum_50 { - use frame_benchmarking::vec; - use sp_core::{H160, U256, H256}; - - let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); - let contract_address = H160::from_low_u64_be(0x8888); - - let proof = Proof::new( - vec![ - U256::from_dec_str("3114941071688532747454764921300681791980888248199392522675009157778549895455").unwrap(), - U256::from_dec_str("6816680925124829082835883802586391663161606011222680818599486084577544527516").unwrap(), - ], - vec![ + U256::from_dec_str("19537041589568134851029831433550253908067307517024871465298468340397396673864").unwrap(), + U256::from_dec_str("16858223705695697450984778594276887015292986391267341267776294917186229957278").unwrap(), + ], vec![ - U256::from_dec_str("15037393792780247314317740287895838240941967969445981241792818111317913065010").unwrap(), - U256::from_dec_str("3834028682995799272226496422556310257938795862629020590068471611902272764146").unwrap(), + U256::from_dec_str("15246698552087261534042715485066570376107106051211884589703176775025917332690").unwrap(), + U256::from_dec_str("10750598760851770035286468210307770266777083135480137548147767265257368199367").unwrap(), ], vec![ - U256::from_dec_str("4023883034822047449129381158539093978377425715903419218696272130851521242085").unwrap(), - U256::from_dec_str("13058906875228264286034925941047330220503025517973111955115072416984072943122").unwrap(), + U256::from_dec_str("20630242320426959800851643081479738249548329066422905492655846397008060618115").unwrap(), + U256::from_dec_str("16326371293493241977282281258423453788627821631429026408337594541860635510205").unwrap(), ], - ], - vec![ - U256::from_dec_str("5344888056894889487007260648469199417556856955544355154291642477677322944786").unwrap(), - U256::from_dec_str("19843194668352645797068691966948915569058668700830773246420232986019393210063").unwrap(), - ] - ); - - let vk = VerifyingKeyComponents::new( - vec![ - U256::from_dec_str("19257923683733118221652593587810195852599358412856281104090957905722976964370").unwrap(), - U256::from_dec_str("19519729727735873999148754136012144616045305047716967685280834855818506563720").unwrap(), - ], - vec![ vec![ - U256::from_dec_str("4418606700813566482216037680863387214037640478555893901955308344977554198718").unwrap(), - U256::from_dec_str("18046767849922558936185002168253454007598159984067380537392936220227127228867").unwrap(), + U256::from_dec_str("9259379886124890427913666590932019503885682624879306600117835935139457180688").unwrap(), + U256::from_dec_str("11581379817981971916924055685584021099145296077431456350129178254038600126989").unwrap(), ], vec![ - U256::from_dec_str("100725403545603844224319783153051757027683253433977048289134569498829183303").unwrap(), - U256::from_dec_str("9785321212288652698655727476617710557399711491394256119637648908536562741634").unwrap(), + U256::from_dec_str("6611770750163234216247925941306289769928406522729441385143389903289545931187").unwrap(), + U256::from_dec_str("16388238514629781365495798832142666963626297616941516091917404053288951061020").unwrap(), ], - ], - vec![ vec![ - U256::from_dec_str("7184324332054694882815451883063466258810341506246659357034202660488015984306").unwrap(), - U256::from_dec_str("14398081398842334723334363407187040569418119441776629783632309768037771007327").unwrap(), + U256::from_dec_str("16643609599328489508845877463250216488035062509642391199018340115352661317445").unwrap(), + U256::from_dec_str("19287928770096457485364071157830517856406460763445755502553439072821026326160").unwrap(), ], vec![ - U256::from_dec_str("17277213124622419955089087696435667358779233792945822269342368397066818801481").unwrap(), - U256::from_dec_str("19811781065417531456401229702422997450338397507283920558741452740912313583930").unwrap(), - ] - ], - vec![ + U256::from_dec_str("16668268135822983565074541614143405097045096145537034830204790679728078054636").unwrap(), + U256::from_dec_str("1066083751611943963019573342152116287954637626803138791681744825116321882626").unwrap(), + ], vec![ - U256::from_dec_str("1627724482578854283892192357407161928314687375966263116172485631707694669812").unwrap(), - U256::from_dec_str("6839802000376483025048211234449253336394632788399066904541666906747650234382").unwrap(), + U256::from_dec_str("17564263958855568483001610697806473789956400903711217865830758776454673450601").unwrap(), + U256::from_dec_str("4296134423505578747039658012410131620047948001497680469667933158152933142610").unwrap(), ], vec![ - U256::from_dec_str("17974577137954059751166162247265070307968439813726452160113109110701162631938").unwrap(), - U256::from_dec_str("21289972529626386698860098501676961527414208445147370800462053148477683157991").unwrap(), + U256::from_dec_str("504256330700931929914991961911525033003353677755203482879812398706411650385").unwrap(), + U256::from_dec_str("20984100739676535922476274553914885299249152392042051753547982635038546311916").unwrap(), ], - ], - vec![ vec![ - U256::from_dec_str("20284064245383237908740484779775789109386762825985839657586769414934584661714").unwrap(), - U256::from_dec_str("17363934481847560975462360104367791101351872886050159351690589725380050257409").unwrap(), + U256::from_dec_str("3869421570438658969494179519379461979744673196979406788310235907475541151866").unwrap(), + U256::from_dec_str("10384783961201503389960224508131172245984891572889398757617253808540561858064").unwrap(), ], vec![ - U256::from_dec_str("3904403738619431633601997032597659843284744078768864151280168218762434423692").unwrap(), - U256::from_dec_str("4413868989856264583489102855186788724178233679332360263809134874064797750675").unwrap(), - ] - ] - ); - - let valid_input = vec![ - U256::from_dec_str("1275").unwrap(), - ]; - - let verifying_key = VerifyingKey::new(proof, vk, valid_input); - - let zk_verifier = ZKPrecompileVerifier::new( - H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), - verifying_key - ); - - let encoded_call = zk_verifier.generate_benchmarking_parameters(); - - let gas_limit_call = 1000000; - let value = U256::default(); - let is_transactional = true; - let validate = true; - }:{ - let call_runner_results = ::Runner::call( - caller, - contract_address, - encoded_call, - value, - gas_limit_call, - Some(U256::from(1_000_000_000)), - Some(U256::from(1_000_000_000)), - None, - Vec::new(), - is_transactional, - validate, - ::config(), - ); - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "Benchmarking call end.", - // ); - match call_runner_results { - Ok(info) => { - let output = info.value; - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "output result {:?}", - // output - // ); - if output.len() >= 32 { - let mut result_bytes = [0u8; 32]; - result_bytes.copy_from_slice(&output[output.len() - 32..]); - let result = U256::from_big_endian(&result_bytes); - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "sum_50 Verification result {result:?}", - // ); - assert_eq!(result, U256::one(), "The contract did not return true"); - } - }, - Err(e) => { - log::info!( - target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - "sum_50 Benchmarking failed", - ); - assert!(false, "Benchmarking failed"); - } - } - } - - sum_5000 { - use frame_benchmarking::vec; - use sp_core::{H160, U256, H256}; - - let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); - let contract_address = H160::from_low_u64_be(0x8888); - - let proof = Proof::new( - vec![ - U256::from_dec_str("2104134032972066019913571175532882184351637942839921828138208604817397790978").unwrap(), - U256::from_dec_str("12625149522977248086293073767826715132905823679345516244316272790389621024575").unwrap(), - ], - vec![ + U256::from_dec_str("7122215811122822268507423970767532589760454224609641145825381146476966978386").unwrap(), + U256::from_dec_str("18629120702848018429623470369106570770627862115848413285088767540695603529504").unwrap(), + ], vec![ - U256::from_dec_str("18955718237898317556602416465218566057031982163829528123671300051574728240883").unwrap(), - U256::from_dec_str("18075306515520608621953959878874546391551215874677138383864573851396832159644").unwrap(), + U256::from_dec_str("17761362406558450236735871511552593182707619093161051811749087853668432576447").unwrap(), + U256::from_dec_str("19034593786971827440873811266124476710852272184042594489649531393766747348571").unwrap(), ], vec![ - U256::from_dec_str("3166476742865671627115278436666969186969644878053983393309132722947819232105").unwrap(), - U256::from_dec_str("8051049247607109861344268872842958063551670273736053865524986958976361214062").unwrap(), + U256::from_dec_str("15804166932378673108559283693463783257192568677741795632273990124666564682412").unwrap(), + U256::from_dec_str("11551825304007398963235970620449268090281036794735216055254821775490144519805").unwrap(), ], - ], - vec![ - U256::from_dec_str("4814291763265323888812051590287571407031542635142019809665068757723218701627").unwrap(), - U256::from_dec_str("17930948070313125851452005455953009375012074818817251382455220462443054837203").unwrap(), - ] - ); - - let vk = VerifyingKeyComponents::new( - vec![ - U256::from_dec_str("19624232987744880202266197753309961915632611879850947888541508003701736644214").unwrap(), - U256::from_dec_str("5019843555387010050200067558096501184079196549422645876015184268981691000261").unwrap(), - ], - vec![ vec![ - U256::from_dec_str("5150307298606577026396875555180704696345763655981810466632357002439129266461").unwrap(), - U256::from_dec_str("3020656302335648031712857271727816386298675153130933709481311850060508289333").unwrap(), + U256::from_dec_str("21646450176753271316838399881606539827387849682556972105696360925302077438232").unwrap(), + U256::from_dec_str("2511076513821207007348582223879937756955220822617888786870823449323773645256").unwrap(), ], vec![ - U256::from_dec_str("19547576195358452722114991449875886954598568010341500952076854329553571219720").unwrap(), - U256::from_dec_str("3895331072082263654317901227968966808293407907751128382134753194859731114729").unwrap(), + U256::from_dec_str("16904410309855743683736810330775505669696719943988498514719208857633212308605").unwrap(), + U256::from_dec_str("21324333522424177499994582360198666554142246038524559672999661787897876060143").unwrap(), ], - ], - vec![ vec![ - U256::from_dec_str("5792479463369352075979003547777370241697788651005116088867026457677720533395").unwrap(), - U256::from_dec_str("16882159064341957118950974052606760693554763076237663579029547802558086431378").unwrap(), + U256::from_dec_str("16945490191295215569999901067842377598942481617410852961564362274204107146706").unwrap(), + U256::from_dec_str("18314156748004089222492732633319765815006654008818903454759444358188055539728").unwrap(), ], vec![ - U256::from_dec_str("15201299876801474331768851307298179430198466709727112330042020251492139993850").unwrap(), - U256::from_dec_str("893863620414771464835789333501093176356026692988850717670551586498757709875").unwrap(), - ] - ], - vec![ + U256::from_dec_str("16917767336476454814446678739488168052806439126778827398781629030350151857387").unwrap(), + U256::from_dec_str("11342172614570752746108213362461158451964820583854525536745594715060784857536").unwrap(), + ], vec![ - U256::from_dec_str("165136411129701665870237237981894748637834826722462614973940945603783242464").unwrap(), - U256::from_dec_str("10766657827945181878791518932726777890925519579254084496220957371082172349194").unwrap(), + U256::from_dec_str("19655214901040692360358163384134838077837280723734255140594660062110580656545").unwrap(), + U256::from_dec_str("3362419428602909135476998407729641861009514940918624516093829774638749378477").unwrap(), ], vec![ - U256::from_dec_str("1813485593016293809685571822392302147347136682526622353828238069063634409991").unwrap(), - U256::from_dec_str("12730118542350484957903782401323352413406115135420607527656226977122246298735").unwrap(), + U256::from_dec_str("10068364657928239999688712782881075590100091150035478948591571494298540064040").unwrap(), + U256::from_dec_str("3925841392732674526382167900635378545357933312779748980213399765561568501954").unwrap(), ], - ], - vec![ vec![ - U256::from_dec_str("19450458898299554306247087083239008884256452312356497246598109368644839627523").unwrap(), - U256::from_dec_str("123992241310851816418828784530061727329258706748227789362318537744292975333").unwrap(), + U256::from_dec_str("7859837372449593447197076679734892380978595170122834233920177020113058884162").unwrap(), + U256::from_dec_str("15267327488914432697481346031072906103448848928991578280835939381635251283161").unwrap(), ], vec![ - U256::from_dec_str("1650700423026830428199086201346242616543834285406293983963791012821269466913").unwrap(), - U256::from_dec_str("3152920600939501404817148774751227981988970987313622659392580888754616114976").unwrap(), - ] - ] - ); - - let valid_input = vec![ - U256::from_dec_str("12502500").unwrap(), - ]; - - let verifying_key = VerifyingKey::new(proof, vk, valid_input); - - let zk_verifier = ZKPrecompileVerifier::new( - H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), - verifying_key - ); - - let encoded_call = zk_verifier.generate_benchmarking_parameters(); - - let gas_limit_call = 1000000; - let value = U256::default(); - let is_transactional = true; - let validate = true; - }:{ - let call_runner_results = ::Runner::call( - caller, - contract_address, - encoded_call, - value, - gas_limit_call, - Some(U256::from(1_000_000_000)), - Some(U256::from(1_000_000_000)), - None, - Vec::new(), - is_transactional, - validate, - ::config(), - ); - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "Benchmarking call end.", - // ); - match call_runner_results { - Ok(info) => { - let output = info.value; - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "output result {:?}", - // output - // ); - if output.len() >= 32 { - let mut result_bytes = [0u8; 32]; - result_bytes.copy_from_slice(&output[output.len() - 32..]); - let result = U256::from_big_endian(&result_bytes); - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "sum_5000 Verification result {result:?}", - // ); - assert_eq!(result, U256::one(), "The contract did not return true"); - } - }, - Err(e) => { - log::info!( - target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - "sum_5000 Benchmarking failed", - ); - assert!(false, "Benchmarking failed"); - } - } - } - - sum_50000 { - use frame_benchmarking::vec; - use sp_core::{H160, U256, H256}; - - let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); - let contract_address = H160::from_low_u64_be(0x8888); - - let proof = Proof::new( - vec![ - U256::from_dec_str("10521560297681522924956535552101557954055377883537271587209095331672512231293").unwrap(), - U256::from_dec_str("3686654512637749683446869119197341068039068905923579159423036344564025864377").unwrap(), - ], - vec![ + U256::from_dec_str("17820543025474357991914589452937303503868675134182823718184408612418457106496").unwrap(), + U256::from_dec_str("4080173097768027859462877326409054600046050536583611074603903692960179295306").unwrap(), + ], vec![ - U256::from_dec_str("4890395955490088627121586512165392468998481877071173820388882318632254821251").unwrap(), - U256::from_dec_str("9885243823600363166628220433820250724586324090253611358758770212725684204135").unwrap(), + U256::from_dec_str("7222395274549846905402287163598280036522206923543195587339746656511726156757").unwrap(), + U256::from_dec_str("17997737062514751282939534276628529489984717427968026247212791392586232604551").unwrap(), ], vec![ - U256::from_dec_str("9651185291553128823215307092565172143818838202635271809942597163630971976482").unwrap(), - U256::from_dec_str("7457264071531012293581639749136580536924886204589417402009399054127419592993").unwrap(), + U256::from_dec_str("1711582578037897629120492811026654304279972642865731976334484807734905010624").unwrap(), + U256::from_dec_str("11417750330605984209119442624747765360816092826690016986275336228747618648201").unwrap(), ], - ], - vec![ - U256::from_dec_str("2627345354605748142976160304028628661480987375506843588233396593542954599122").unwrap(), - U256::from_dec_str("8681729968580301984067665769277363721394455178806371130831646417737890294377").unwrap(), - ] - ); - - let vk = VerifyingKeyComponents::new( - vec![ - U256::from_dec_str("7421321362170719195081023585470135389432297716397232604489422086989398701183").unwrap(), - U256::from_dec_str("4072026971341416803293623026670767879574289631340879941991921870784524426920").unwrap(), - ], - vec![ vec![ - U256::from_dec_str("2973474839676012411019522612887674225146102238495561333683790233803898072056").unwrap(), - U256::from_dec_str("4756088420398356546587372215087817373004751038308642279979561650652947628544").unwrap(), + U256::from_dec_str("5091961738279253769908069837603749933382976381492972380907447338157526366714").unwrap(), + U256::from_dec_str("2098634419436065415091734819109653428284310850731241021115434822766452990108").unwrap(), ], vec![ - U256::from_dec_str("18134483811751652906456539288278265005968212485396038963550793901997203165973").unwrap(), - U256::from_dec_str("19733531274857979315351276512779996430041767061694237978460875113100798536651").unwrap(), + U256::from_dec_str("12771630983152860380958654612308310234837340761565253596054160793193407831416").unwrap(), + U256::from_dec_str("9149694848418949644717518759058810074518704169947141770421799720539197666625").unwrap(), ], - ], - vec![ vec![ - U256::from_dec_str("1470135418689977789083190292952479192678178451735632796795673595352524120366").unwrap(), - U256::from_dec_str("5512330648930976997879473235916847191061423400686751865867764833860608466852").unwrap(), + U256::from_dec_str("9918837719060277739930324221392324331275666891900263953129450726331466863134").unwrap(), + U256::from_dec_str("13829770172279463687649225699345042056345548299961998544225247740202252340439").unwrap(), ], vec![ - U256::from_dec_str("8727385532414213805687214017949229267547242769169729533774216518510791901252").unwrap(), - U256::from_dec_str("6002526157648728322271067956991922780742552704883496238917574496345518669191").unwrap(), - ] - ], - vec![ + U256::from_dec_str("21556772538865001220884467378626718237742195027485835738020776901730681324637").unwrap(), + U256::from_dec_str("19778672038763116743630250909961650038370256095030032529759391735347222925746").unwrap(), + ], vec![ - U256::from_dec_str("20953112965721952332699311075873353918826966291896395544882354080425788226212").unwrap(), - U256::from_dec_str("9244986330211753947979669564454335484807935852348100319901614192766392809174").unwrap(), + U256::from_dec_str("14856861307423975278581613005761934562358117742422665247736527476263653360349").unwrap(), + U256::from_dec_str("1867918246775206089638452481671058455990990896563653326270871198890663017878").unwrap(), ], vec![ - U256::from_dec_str("14633091132354386243825187195737842488061561784614981035737595152471541943810").unwrap(), - U256::from_dec_str("18226447293937452659919522397971158104569327938800893595903771586125572293911").unwrap(), + U256::from_dec_str("7358292501557376813334144315791019321478041455375833895705472993641179430655").unwrap(), + U256::from_dec_str("19639382277696759182661917452231356435729059958722755277286321238745721897653").unwrap(), ], - ], - vec![ vec![ - U256::from_dec_str("12814717307556312189651039282215441805578074271611267777533714458773278844960").unwrap(), - U256::from_dec_str("7186820657304904476047212967487229874520184333187156276378594443001564484591").unwrap(), + U256::from_dec_str("5776957264346829457305929424782026635416082038398352721156570341141914144551").unwrap(), + U256::from_dec_str("15767534494868786069535421819233640712284308687242022324923974165520151035749").unwrap(), ], vec![ - U256::from_dec_str("555198418426478766253895845611805598077310216839822834188225932135183360314").unwrap(), - U256::from_dec_str("13253206399154373951823381980703846825450333469684895600618793136364702673992").unwrap(), - ] + U256::from_dec_str("15314810752842818694345949990176494977521994584277889144518086930381852217499").unwrap(), + U256::from_dec_str("7856791107683021983787028049162290107091787348782025165222243877660987556554").unwrap(), + ], ] ); - let valid_input = vec![U256::from_dec_str("1250025000").unwrap()]; + let valid_input = vec![ + U256::from_dec_str("1").unwrap(), + U256::from_dec_str("3").unwrap(), + U256::from_dec_str("6").unwrap(), + U256::from_dec_str("10").unwrap(), + U256::from_dec_str("15").unwrap(), + U256::from_dec_str("21").unwrap(), + U256::from_dec_str("28").unwrap(), + U256::from_dec_str("36").unwrap(), + U256::from_dec_str("45").unwrap(), + U256::from_dec_str("55").unwrap(), + U256::from_dec_str("66").unwrap(), + U256::from_dec_str("78").unwrap(), + U256::from_dec_str("91").unwrap(), + U256::from_dec_str("105").unwrap(), + U256::from_dec_str("120").unwrap(), + U256::from_dec_str("136").unwrap(), + U256::from_dec_str("153").unwrap(), + U256::from_dec_str("171").unwrap(), + U256::from_dec_str("190").unwrap(), + U256::from_dec_str("210").unwrap(), + U256::from_dec_str("231").unwrap(), + U256::from_dec_str("253").unwrap(), + U256::from_dec_str("276").unwrap(), + U256::from_dec_str("300").unwrap(), + U256::from_dec_str("325").unwrap(), + U256::from_dec_str("351").unwrap(), + U256::from_dec_str("378").unwrap(), + U256::from_dec_str("406").unwrap(), + U256::from_dec_str("435").unwrap(), + U256::from_dec_str("465").unwrap(), + U256::from_dec_str("496").unwrap(), + U256::from_dec_str("528").unwrap(), + U256::from_dec_str("561").unwrap(), + U256::from_dec_str("595").unwrap(), + U256::from_dec_str("630").unwrap(), + U256::from_dec_str("666").unwrap(), + U256::from_dec_str("703").unwrap(), + U256::from_dec_str("741").unwrap(), + U256::from_dec_str("780").unwrap(), + U256::from_dec_str("820").unwrap(), + U256::from_dec_str("861").unwrap(), + U256::from_dec_str("903").unwrap(), + U256::from_dec_str("946").unwrap(), + U256::from_dec_str("990").unwrap(), + U256::from_dec_str("1035").unwrap(), + U256::from_dec_str("1081").unwrap(), + U256::from_dec_str("1128").unwrap(), + U256::from_dec_str("1176").unwrap(), + U256::from_dec_str("1225").unwrap(), + U256::from_dec_str("1275").unwrap(), + ]; let verifying_key = VerifyingKey::new(proof, vk, valid_input); @@ -2278,33 +4260,24 @@ benchmarks! { validate, ::config(), ); - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "Benchmarking call end.", - // ); match call_runner_results { Ok(info) => { let output = info.value; - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "output result {:?}", - // output - // ); if output.len() >= 32 { let mut result_bytes = [0u8; 32]; result_bytes.copy_from_slice(&output[output.len() - 32..]); let result = U256::from_big_endian(&result_bytes); - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "sum_50000 Verification result {result:?}", - // ); + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "sumout_50 Verification result {result:?}", + ); assert_eq!(result, U256::one(), "The contract did not return true"); } }, Err(e) => { log::info!( target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - "sum_50000 Benchmarking failed", + "sumout_50 Benchmarking failed", ); assert!(false, "Benchmarking failed"); } From 1bbda62235093d95c1c0fdb80bc647c840cf46c6 Mon Sep 17 00:00:00 2001 From: luckychacha <358140284@qq.com> Date: Fri, 11 Aug 2023 18:33:52 +0800 Subject: [PATCH 22/34] Add more benchmarking --- .../benchmarking.rs | 873 +++++++++++++++++- 1 file changed, 870 insertions(+), 3 deletions(-) diff --git a/runtime/runtime-common/src/zk_precompile_gas_estimation/benchmarking.rs b/runtime/runtime-common/src/zk_precompile_gas_estimation/benchmarking.rs index b266b1c3..7416668b 100644 --- a/runtime/runtime-common/src/zk_precompile_gas_estimation/benchmarking.rs +++ b/runtime/runtime-common/src/zk_precompile_gas_estimation/benchmarking.rs @@ -2442,7 +2442,6 @@ benchmarks! { } } - sumout_3 { use frame_benchmarking::vec; use sp_core::{H160, U256, H256}; @@ -2735,7 +2734,6 @@ benchmarks! { } } - sumout_8 { use frame_benchmarking::vec; use sp_core::{H160, U256, H256}; @@ -2902,7 +2900,6 @@ benchmarks! { } } - sumout_10 { use frame_benchmarking::vec; use sp_core::{H160, U256, H256}; @@ -4284,6 +4281,876 @@ benchmarks! { } } + fib_3 { + use frame_benchmarking::vec; + use sp_core::{H160, U256, H256}; + + let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + let contract_address = H160::from_low_u64_be(0x8888); + + let proof = Proof::new( + vec![ + U256::from_dec_str("3132971325870222259639561706189758098287244657388649414392529352718303714530").unwrap(), + U256::from_dec_str("6507826058647329464322284230325703133591122928282742834699944707019156258809").unwrap(), + ], + vec![ + vec![ + U256::from_dec_str("17772115053309497146137293588980018321863662294867005210136855479605214186180").unwrap(), + U256::from_dec_str("10038179076166881173143876188899696762808386040833545597371587600563515084302").unwrap(), + ], + vec![ + U256::from_dec_str("84866774058471735936350793806054983511272962266883047883471400112941191037").unwrap(), + U256::from_dec_str("5568809559395193198199152670834662954559187185156161953287752106001302001344").unwrap(), + ], + ], + vec![ + U256::from_dec_str("8880668092662582662151749297267512620096355234087050144351597799319681896574").unwrap(), + U256::from_dec_str("11528980930108519143107616915390840029128779349741456778024327951728523777236").unwrap(), + ] + ); + + let vk = VerifyingKeyComponents::new( + vec![ + U256::from_dec_str("11973149780461845670977457832614205154706068463789633369928681722573108265443").unwrap(), + U256::from_dec_str("560154769206684285089883239395400651095151098880172398808069275901669863769").unwrap(), + ], + vec![ + vec![ + U256::from_dec_str("13756428714932434595021589136752822391122965542123120193354239911120469699709").unwrap(), + U256::from_dec_str("120112527160047884703620942006841978570569214359122057960251258287184219697").unwrap(), + ], + vec![ + U256::from_dec_str("13463898713692437806260449684498030384996189360575139011629743781467141790304").unwrap(), + U256::from_dec_str("1194002625152303589071335639210384071235225241955701801770234611166742017055").unwrap(), + ], + ], + vec![ + vec![ + U256::from_dec_str("11139054187995416626739127332337577172136803991433018900962790056334353344291").unwrap(), + U256::from_dec_str("6070725161016897987520708628733735347166393581684474326320014699046060380622").unwrap(), + ], + vec![ + U256::from_dec_str("19209700656348280109959147287216993350201779451119908883346282260552870356387").unwrap(), + U256::from_dec_str("17266437688499472585954564896738180051466183385397662700252060765908415760821").unwrap(), + ] + ], + vec![ + vec![ + U256::from_dec_str("8518978947911781334617073974199814521245393345576825252918283414965139226281").unwrap(), + U256::from_dec_str("1919930890570357741377145521418378700589359366071674476012553393210299710266").unwrap(), + ], + vec![ + U256::from_dec_str("20518172778897855607538153208553426015126061748797486778622889113076225553601").unwrap(), + U256::from_dec_str("4341433561739154626175616238599696777704881435167300120740573786688737320206").unwrap(), + ], + ], + vec![ + vec![ + U256::from_dec_str("6257454378471671954508216959821760138899506248862124107543881832751496243381").unwrap(), + U256::from_dec_str("849484394494738364726633009377512849646844450581834914681550559373523098955").unwrap(), + ], + vec![ + U256::from_dec_str("13065948243673575219205285761966669534222259117764240672025250386712503766186").unwrap(), + U256::from_dec_str("14256307983349064955937850546866094921248521794981704681964738514708851084548").unwrap(), + ], + vec![ + U256::from_dec_str("11615738609008198513128136474869049796581791264774401388480327383708701220818").unwrap(), + U256::from_dec_str("17975851278557099428627721105403634331615370696748419056473417067984791293951").unwrap(), + ], + vec![ + U256::from_dec_str("17708563515128206907836464584450502652129276662274674459408979775646454697813").unwrap(), + U256::from_dec_str("19932771729628827926695230158177139025768662902055116478576202138537488865502").unwrap(), + ], + ] + ); + + let valid_input = vec![ + U256::from_dec_str("1").unwrap(), + U256::from_dec_str("1").unwrap(), + U256::from_dec_str("2").unwrap(), + ]; + + let verifying_key = VerifyingKey::new(proof, vk, valid_input); + + let zk_verifier = ZKPrecompileVerifier::new( + H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), + verifying_key + ); + + let encoded_call = zk_verifier.generate_benchmarking_parameters(); + + let gas_limit_call = 1000000; + let value = U256::default(); + let is_transactional = true; + let validate = true; + }:{ + let call_runner_results = ::Runner::call( + caller, + contract_address, + encoded_call, + value, + gas_limit_call, + Some(U256::from(1_000_000_000)), + Some(U256::from(1_000_000_000)), + None, + Vec::new(), + is_transactional, + validate, + ::config(), + ); + match call_runner_results { + Ok(info) => { + let output = info.value; + if output.len() >= 32 { + let mut result_bytes = [0u8; 32]; + result_bytes.copy_from_slice(&output[output.len() - 32..]); + let result = U256::from_big_endian(&result_bytes); + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "fib_3 Verification result {result:?}", + ); + assert_eq!(result, U256::one(), "The contract did not return true"); + } + }, + Err(e) => { + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "fib_3 Benchmarking failed", + ); + assert!(false, "Benchmarking failed"); + } + } + } + + fib_5 { + use frame_benchmarking::vec; + use sp_core::{H160, U256, H256}; + + let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + let contract_address = H160::from_low_u64_be(0x8888); + + let proof = Proof::new( + vec![ + U256::from_dec_str("7107575577163000349795659359956168176171101387530780151824981638484262486978").unwrap(), + U256::from_dec_str("897133249212133391804343723156610138182460716033738784908100029698973225852").unwrap(), + ], + vec![ + vec![ + U256::from_dec_str("170389711510642910317680110863332628397432593441060800544776128980970914252").unwrap(), + U256::from_dec_str("6920395653366563258534283590246960198394308227032492249037643353403270317045").unwrap(), + ], + vec![ + U256::from_dec_str("8480799764075268077172001588258796963309752386101311077889514097122873239882").unwrap(), + U256::from_dec_str("12451695893898630503865218111936486188627157726164511249977202673656946431620").unwrap(), + ], + ], + vec![ + U256::from_dec_str("21597992290581954545776627017098028702839071011677341576724377506987149993751").unwrap(), + U256::from_dec_str("19053567793179926208306730705211711754174669587802570078364147255403467780151").unwrap(), + ] + ); + + let vk = VerifyingKeyComponents::new( + vec![ + U256::from_dec_str("2357887722618418674206341083287923328601312919804823733855833233026791743663").unwrap(), + U256::from_dec_str("975374039805822885844240552519100209502334213678144709852000084502893973008").unwrap(), + ], + vec![ + vec![ + U256::from_dec_str("16280105556148393779575170892506606219120071731060039616507494801779121328832").unwrap(), + U256::from_dec_str("20950039635055833909912134692658157347220364503511282528956587902894228703712").unwrap(), + ], + vec![ + U256::from_dec_str("7993964715201116449357589101743367175186265961068472625342038948672634732296").unwrap(), + U256::from_dec_str("11099581941940578041819214468757040086707821891633617156886035885244647996327").unwrap(), + ], + ], + vec![ + vec![ + U256::from_dec_str("12636329372753298988357489028292457750683260728540316442371004560814413226626").unwrap(), + U256::from_dec_str("4045455970628132355106370857917185793087210373549168231277818312754971612807").unwrap(), + ], + vec![ + U256::from_dec_str("1300344419079427628501727843429767670124424070337281261058615696156550837549").unwrap(), + U256::from_dec_str("2174525330618542624943912040794362533422023824780024477106228987295196169137").unwrap(), + ] + ], + vec![ + vec![ + U256::from_dec_str("21390433795647917247027254319423864113578346839713218763993047007421497228495").unwrap(), + U256::from_dec_str("21661918443945562352764731942118046974455095191616778616511655172171711481914").unwrap(), + ], + vec![ + U256::from_dec_str("6520633594028678038498884349163102469806602416433112898771095987637595066617").unwrap(), + U256::from_dec_str("19663631449513124110735458456019142408282532497123847160755982598286201463717").unwrap(), + ], + ], + vec![ + vec![ + U256::from_dec_str("18657381897074200796904415404231863341895995632749476893629144717257679103963").unwrap(), + U256::from_dec_str("8345650724109397616811518344854358214988563616857860428608140138066962138957").unwrap(), + ], + vec![ + U256::from_dec_str("6080713600081003917101685986497728921078282571010625261265667442187252662937").unwrap(), + U256::from_dec_str("513944790500250868640338307249655484768530127653315385350721456220511760102").unwrap(), + ], + vec![ + U256::from_dec_str("16799415331247767599223181727867706342904206821513386749641266330877174898760").unwrap(), + U256::from_dec_str("19420916090388399599536229341092487229974297531937960707965143244382507176964").unwrap(), + ], + vec![ + U256::from_dec_str("13668334697827007947302996095199479530567641377939668790543641044451953957139").unwrap(), + U256::from_dec_str("12476894726233017534672279206882408584567103640359862711942440003398820167147").unwrap(), + ], + vec![ + U256::from_dec_str("13809977379539470670333778802717132743390915159675198170487848397796913472215").unwrap(), + U256::from_dec_str("5304572538397463768441415723346479145852763698142825603512106636952539776032").unwrap(), + ], + vec![ + U256::from_dec_str("701521285562685954268529162647895469084095604096437475664109908959446258033").unwrap(), + U256::from_dec_str("15172311417293466130771317503680468656450805959709148012902980907068100374524").unwrap(), + ] + ] + ); + + let valid_input = vec![ + U256::from_dec_str("1").unwrap(), + U256::from_dec_str("1").unwrap(), + U256::from_dec_str("2").unwrap(), + U256::from_dec_str("3").unwrap(), + U256::from_dec_str("5").unwrap() + ]; + + let verifying_key = VerifyingKey::new(proof, vk, valid_input); + + let zk_verifier = ZKPrecompileVerifier::new( + H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), + verifying_key + ); + + let encoded_call = zk_verifier.generate_benchmarking_parameters(); + + let gas_limit_call = 1000000; + let value = U256::default(); + let is_transactional = true; + let validate = true; + }:{ + let call_runner_results = ::Runner::call( + caller, + contract_address, + encoded_call, + value, + gas_limit_call, + Some(U256::from(1_000_000_000)), + Some(U256::from(1_000_000_000)), + None, + Vec::new(), + is_transactional, + validate, + ::config(), + ); + match call_runner_results { + Ok(info) => { + let output = info.value; + if output.len() >= 32 { + let mut result_bytes = [0u8; 32]; + result_bytes.copy_from_slice(&output[output.len() - 32..]); + let result = U256::from_big_endian(&result_bytes); + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "fib_5 Verification result {result:?}", + ); + assert_eq!(result, U256::one(), "The contract did not return true"); + } + }, + Err(e) => { + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "fib_5 Benchmarking failed", + ); + assert!(false, "Benchmarking failed"); + } + } + } + + fib_10 { + use frame_benchmarking::vec; + use sp_core::{H160, U256, H256}; + + let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + let contract_address = H160::from_low_u64_be(0x8888); + + let proof = Proof::new( + vec![ + U256::from_dec_str("15598002460690588437896426762633589755681380926526826007650911266155302746971").unwrap(), + U256::from_dec_str("14048781467582620915514707321102379170342351199203838720084613707384189246618").unwrap(), + ], + vec![ + vec![ + U256::from_dec_str("5701442717558059864094936857346939502743862376737227680931736705155409754850").unwrap(), + U256::from_dec_str("6705418082619681590489582801426443732890080590377224079621881818162843204595").unwrap(), + ], + vec![ + U256::from_dec_str("13279521252289501630047789160726986062397338623708136865134983184465749454165").unwrap(), + U256::from_dec_str("21033452491153645343877459007984264553702116582842254942279478167695403794865").unwrap(), + ], + ], + vec![ + U256::from_dec_str("4781563429922683357122820523637836932301917765582180198660942288815260302421").unwrap(), + U256::from_dec_str("14814729180207128675172446059166803635423524097383393305814823960659595806329").unwrap(), + ] + ); + + let vk = VerifyingKeyComponents::new( + vec![ + U256::from_dec_str("21128226372968921480959222733647870812725374627959087109938949205782449934509").unwrap(), + U256::from_dec_str("7018642648086750325301120070974798999557335793924792347011375693170409195098").unwrap(), + ], + vec![ + vec![ + U256::from_dec_str("10332150704003579947885996835615852693671986689983776582911110245805513692668").unwrap(), + U256::from_dec_str("1124448241753524378997499989602955777745777344553269747221648865489793488975").unwrap(), + ], + vec![ + U256::from_dec_str("18359851081925516932372626627155466137254869746456141360772489145074657585390").unwrap(), + U256::from_dec_str("2503686322149969597053196188893305621132468879410881045066232089347592198484").unwrap(), + ], + ], + vec![ + vec![ + U256::from_dec_str("4816278985941566400895633011850808885261900890766698900964554024095285628690").unwrap(), + U256::from_dec_str("4481223810973703865132739390383257176145788880766036414318913695394582687416").unwrap(), + ], + vec![ + U256::from_dec_str("15603469913936514792797227253072839537192706677995431175913126336649422890069").unwrap(), + U256::from_dec_str("21864594615695298757460783973470516017964190218336035301988952994099300002552").unwrap(), + ] + ], + vec![ + vec![ + U256::from_dec_str("21231927944393920243160099971507175021287196370917268996863763412686284403869").unwrap(), + U256::from_dec_str("11235057574641688951864488055161587538057015254360438255114278019066405496417").unwrap(), + ], + vec![ + U256::from_dec_str("13775234459674435911239591565261874307122702001326411862915067861775676454154").unwrap(), + U256::from_dec_str("16068368840115781322039412863465620735514071242596879769482158447800688468756").unwrap(), + ], + ], + vec![ + vec![ + U256::from_dec_str("8946500491146824741411381190131650044873203574966470669798623284509235212225").unwrap(), + U256::from_dec_str("9207778656916363948673619648074334783746856414577233256897457918279555367126").unwrap(), + ], + vec![ + U256::from_dec_str("18229827395116865835955974167555190610618187087749776491709874843200696280698").unwrap(), + U256::from_dec_str("5354841661231629559124068306361245380218908391918092200894031389928119849378").unwrap(), + ], + vec![ + U256::from_dec_str("8406088130432915530837275071042043342847231172695656108751797564706756513873").unwrap(), + U256::from_dec_str("1692113603002985183084671804623810248784246597585146031631850722491435245828").unwrap(), + ], + vec![ + U256::from_dec_str("3781409869223206029979945624869146198489017871864132897653633688094104894010").unwrap(), + U256::from_dec_str("914649635961084769359381892125208118471978903853445450960187255648945554484").unwrap(), + ], + vec![ + U256::from_dec_str("4681412300653217556730318589043345985554894195960903393718460114249743089179").unwrap(), + U256::from_dec_str("21360858821457283911073676012703566640289750014744439028328185444091026027882").unwrap(), + ], + vec![ + U256::from_dec_str("20897966082308332377807565195025690308345926928964539367186230582160325134474").unwrap(), + U256::from_dec_str("9626498089212728094225083170299883982718296909352243901431927962362382218927").unwrap(), + ], + vec![ + U256::from_dec_str("14359853109533518444168562509201102039176753094698437798285771319619295861708").unwrap(), + U256::from_dec_str("90829535353937971257007177217967887697692463940020220682809349058293661638").unwrap(), + ], + vec![ + U256::from_dec_str("6493829119246187593593139749123040079754197652894022722457052662159433878735").unwrap(), + U256::from_dec_str("15262423895688782694421350413428209962260663475050857280745519572187099177290").unwrap(), + ], + vec![ + U256::from_dec_str("5720350053817277761103752188290987255397596237781800199881859365664717896938").unwrap(), + U256::from_dec_str("18530651271212069093450925444649953034166690271614200467237140911087116714410").unwrap(), + ], + vec![ + U256::from_dec_str("16749960532530207200560191146014575700596418430016017388393265928266457503270").unwrap(), + U256::from_dec_str("806706467165047542403196455896239214513895671141081869269826693258304989974").unwrap(), + ], + vec![ + U256::from_dec_str("5556621093836642227227787846531768876794773395668568501898035445111568303923").unwrap(), + U256::from_dec_str("16207931580028655113776293873436654483020022939317876762036644049054941054638").unwrap(), + ], + ] + ); + + let valid_input = vec![ + U256::from_dec_str("1").unwrap(), + U256::from_dec_str("1").unwrap(), + U256::from_dec_str("2").unwrap(), + U256::from_dec_str("3").unwrap(), + U256::from_dec_str("5").unwrap(), + U256::from_dec_str("8").unwrap(), + U256::from_dec_str("13").unwrap(), + U256::from_dec_str("21").unwrap(), + U256::from_dec_str("34").unwrap(), + U256::from_dec_str("55").unwrap(), + ]; + + let verifying_key = VerifyingKey::new(proof, vk, valid_input); + + let zk_verifier = ZKPrecompileVerifier::new( + H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), + verifying_key + ); + + let encoded_call = zk_verifier.generate_benchmarking_parameters(); + + let gas_limit_call = 1000000; + let value = U256::default(); + let is_transactional = true; + let validate = true; + }:{ + let call_runner_results = ::Runner::call( + caller, + contract_address, + encoded_call, + value, + gas_limit_call, + Some(U256::from(1_000_000_000)), + Some(U256::from(1_000_000_000)), + None, + Vec::new(), + is_transactional, + validate, + ::config(), + ); + match call_runner_results { + Ok(info) => { + let output = info.value; + if output.len() >= 32 { + let mut result_bytes = [0u8; 32]; + result_bytes.copy_from_slice(&output[output.len() - 32..]); + let result = U256::from_big_endian(&result_bytes); + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "fib_10 Verification result {result:?}", + ); + assert_eq!(result, U256::one(), "The contract did not return true"); + } + }, + Err(e) => { + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "fib_10 Benchmarking failed", + ); + assert!(false, "Benchmarking failed"); + } + } + } + + copy_10 { + use frame_benchmarking::vec; + use sp_core::{H160, U256, H256}; + + let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + let contract_address = H160::from_low_u64_be(0x8888); + + let proof = Proof::new( + vec![ + U256::from_dec_str("16390962836043729391713651706041034686233675080495652797663011252649219608453").unwrap(), + U256::from_dec_str("6865787639719296962717876412738042601880427078298243582467975656325852949218").unwrap(), + ], + vec![ + vec![ + U256::from_dec_str("17210141815814974498912537431655049857450919262672383343442093136850563838206").unwrap(), + U256::from_dec_str("12342441380929407693451343058085382102105226929110424541171233890701211265557").unwrap(), + ], + vec![ + U256::from_dec_str("14791256228758178288432683409274509098808992656590403960492149355352931241876").unwrap(), + U256::from_dec_str("9757744402966524420081791838465495321308702736965720459936221854562488721275").unwrap(), + ], + ], + vec![ + U256::from_dec_str("12074129776039590906909589024919710171422616332187991404856704813889669348927").unwrap(), + U256::from_dec_str("987324030858231431967082277102247672880769004615236440649645498996213854200").unwrap(), + ] + ); + + let vk = VerifyingKeyComponents::new( + vec![ + U256::from_dec_str("17240412344702891229776489031231066040782132824948269228246148252519138466366").unwrap(), + U256::from_dec_str("15893975335803942380118071522945358115037231080796902411459398036409803599182").unwrap(), + ], + vec![ + vec![ + U256::from_dec_str("1271417771372629644611717230761961857698909743161160107041194135970629739863").unwrap(), + U256::from_dec_str("4939081731814081619963862075681020612775752067767844815503719074388485924144").unwrap(), + ], + vec![ + U256::from_dec_str("15763747362287654829011432461657723100243353639302509576933192822234504950406").unwrap(), + U256::from_dec_str("10562112977940817988663571736399452005642324818400887824616415414761510289790").unwrap(), + ], + ], + vec![ + vec![ + U256::from_dec_str("6840359036458076382079357592817160014882757907637013803537268679884532127606").unwrap(), + U256::from_dec_str("1346535467813261885766726379794214479097664664392345988272417354157960728671").unwrap(), + ], + vec![ + U256::from_dec_str("19427354612139857884342478002431397034023252622750272907992730527833498646839").unwrap(), + U256::from_dec_str("5337050117201999843103633899784755367092656102396877506066058827688289940046").unwrap(), + ] + ], + vec![ + vec![ + U256::from_dec_str("20823611397282852479822978978685532830296682705009136373592940707301503646033").unwrap(), + U256::from_dec_str("7789186167969658306688153593800998736943152689699161855707311457653271858926").unwrap(), + ], + vec![ + U256::from_dec_str("5844206256345363695439174408404096072235672265143152167172459387708567781148").unwrap(), + U256::from_dec_str("235843202490932637756232553215192204134845956931540834734914009496237634184").unwrap(), + ], + ], + vec![ + vec![ + U256::from_dec_str("20550659483735211121802551760554631025807244045676695123218122991238619501699").unwrap(), + U256::from_dec_str("11945951364844791529623571555332639031054156303670814242701717081599466357872").unwrap(), + ], + vec![ + U256::from_dec_str("654879587106775033263721472009262072007272314520227570335994171228983103986").unwrap(), + U256::from_dec_str("14361342781229557997760264881879944101650636599963169957537169085125448452547").unwrap(), + ], + vec![ + U256::from_dec_str("11133904625121643992823528155721740987974874506160472484890920541446857113467").unwrap(), + U256::from_dec_str("4436717642021319260725328966952365487651517574980287441477089608456027630542").unwrap(), + ], + vec![ + U256::from_dec_str("16685780983916865650387043033283449729899552702220387957248765192791587962503").unwrap(), + U256::from_dec_str("1956353155823917762807403460270916420225712366921387635794647149170454029020").unwrap(), + ], + vec![ + U256::from_dec_str("3167458143773351335886873071351828587468972050558968173198746552524979899343").unwrap(), + U256::from_dec_str("14706542627970265967501101570095076370616715291368867838796404315730798645263").unwrap(), + ], + vec![ + U256::from_dec_str("3169288635570110804535167586039046075463922680257787193769750793599418836937").unwrap(), + U256::from_dec_str("6027690424292016493627852337260456340093207521914688143324731183496975625359").unwrap(), + ], + vec![ + U256::from_dec_str("16745129804724758320492257405054914946034714396740595023799347270606765091207").unwrap(), + U256::from_dec_str("5179934402554548729647017662939357756072702074261387023337145559991485834818").unwrap(), + ], + vec![ + U256::from_dec_str("20612137209143666732486995940592065546560294302298353386853309983097185298163").unwrap(), + U256::from_dec_str("5861820384642620925499126057189223472137276803184996411582299498362694892662").unwrap(), + ], + vec![ + U256::from_dec_str("5151144014489768285719815999895590607805899943411423671520418528161058212389").unwrap(), + U256::from_dec_str("5021097391934366383971983202419604465348564028049147673972539360521330534532").unwrap(), + ], + vec![ + U256::from_dec_str("17919926668723224822853766036925499138771026625911650899155968406167299184157").unwrap(), + U256::from_dec_str("16822830740823282288084447970705913414694049222039026855174213870807229940846").unwrap(), + ], + vec![ + U256::from_dec_str("11506678974796799469204749431033361084874528449390062358406908850400100405067").unwrap(), + U256::from_dec_str("15362354576852649604151397236428588651091047930604360653191543795436089896761").unwrap(), + ], + ] + ); + + let valid_input = vec![ + U256::from_dec_str("10000").unwrap(), + U256::from_dec_str("10000").unwrap(), + U256::from_dec_str("10000").unwrap(), + U256::from_dec_str("10000").unwrap(), + U256::from_dec_str("10000").unwrap(), + U256::from_dec_str("10000").unwrap(), + U256::from_dec_str("10000").unwrap(), + U256::from_dec_str("10000").unwrap(), + U256::from_dec_str("10000").unwrap(), + U256::from_dec_str("10000").unwrap(), + ]; + + let verifying_key = VerifyingKey::new(proof, vk, valid_input); + + let zk_verifier = ZKPrecompileVerifier::new( + H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), + verifying_key + ); + + let encoded_call = zk_verifier.generate_benchmarking_parameters(); + + let gas_limit_call = 1000000; + let value = U256::default(); + let is_transactional = true; + let validate = true; + }:{ + let call_runner_results = ::Runner::call( + caller, + contract_address, + encoded_call, + value, + gas_limit_call, + Some(U256::from(1_000_000_000)), + Some(U256::from(1_000_000_000)), + None, + Vec::new(), + is_transactional, + validate, + ::config(), + ); + match call_runner_results { + Ok(info) => { + let output = info.value; + if output.len() >= 32 { + let mut result_bytes = [0u8; 32]; + result_bytes.copy_from_slice(&output[output.len() - 32..]); + let result = U256::from_big_endian(&result_bytes); + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "copy_10 Verification result {result:?}", + ); + assert_eq!(result, U256::one(), "The contract did not return true"); + } + }, + Err(e) => { + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "copy_10 Benchmarking failed", + ); + assert!(false, "Benchmarking failed"); + } + } + } + + copy_20 { + use frame_benchmarking::vec; + use sp_core::{H160, U256, H256}; + + let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + let contract_address = H160::from_low_u64_be(0x8888); + + let proof = Proof::new( + vec![ + U256::from_dec_str("2379977889230914820672594034039121593840586279251765411407892083495964290586").unwrap(), + U256::from_dec_str("19717766810117850874712820192154455597011669501170003294244878423890590018861").unwrap(), + ], + vec![ + vec![ + U256::from_dec_str("3973159193607304635677110039121846796616184019135954866315181300786429744636").unwrap(), + U256::from_dec_str("19738101583692327553695201324955632910514950057767721207797779165572562320591").unwrap(), + ], + vec![ + U256::from_dec_str("18009039990446914928726774542606020968862991368419340325967317177749500045223").unwrap(), + U256::from_dec_str("9293138879208966557577361306623499801334435975158650451755325697234789178182").unwrap(), + ], + ], + vec![ + U256::from_dec_str("206777167290693892804178251336642443297985114484409374966071658530105269696").unwrap(), + U256::from_dec_str("2267483584645623390884362686034664874106799646106704430718053204392987070526").unwrap(), + ] + ); + + let vk = VerifyingKeyComponents::new( + vec![ + U256::from_dec_str("18186832346943283968189021374987462202481085857954829692288945756447069609876").unwrap(), + U256::from_dec_str("5402524640789301913788019447399651923814806381669718491322583849494894802268").unwrap(), + ], + vec![ + vec![ + U256::from_dec_str("5528524380609293441422858282765117427241355019381336135853739470431762592324").unwrap(), + U256::from_dec_str("1508226221479911609651693048768866341319973826577926330664018889585487258525").unwrap(), + ], + vec![ + U256::from_dec_str("4028947148020159142728283348567876171081494727087452959443137954265098854797").unwrap(), + U256::from_dec_str("4215883472206722706123802147720262143796686837980046137743755262651347678843").unwrap(), + ], + ], + vec![ + vec![ + U256::from_dec_str("18358409527104302643151877377191921884362264066571296795400828166440394581356").unwrap(), + U256::from_dec_str("16397242299165439412854345647920988068174648012394612865878728614273133142679").unwrap(), + ], + vec![ + U256::from_dec_str("17800981185981546727325645880080997001476675047091692601614288140235437092669").unwrap(), + U256::from_dec_str("18740407875764131523921983143028060498186857273067309944248989237432327688403").unwrap(), + ] + ], + vec![ + vec![ + U256::from_dec_str("665772934717175177777949524098312092352764855175335277424591571425164110495").unwrap(), + U256::from_dec_str("14100679580899773878692255597131271645919787770156674267632120179255213163919").unwrap(), + ], + vec![ + U256::from_dec_str("11550483577636357067438501129303480300849727408381097797290690228588830430753").unwrap(), + U256::from_dec_str("9393054484305485081338275095253982915344196959843349099876609724972300123416").unwrap(), + ], + ], + vec![ + vec![ + U256::from_dec_str("11935857310771353301113078485816547646734693035868999119793358992399371905384").unwrap(), + U256::from_dec_str("11076391388262632214871501512549398943625460082535158648764826100124319684977").unwrap(), + ], + vec![ + U256::from_dec_str("3710665449666757495807260984495481142659978308600359337780598549499120138938").unwrap(), + U256::from_dec_str("6839803279250166998041675738233682206460875086384455306323331018124376381750").unwrap(), + ], + vec![ + U256::from_dec_str("4856493623582275736770069967742171908738373534012202112313355761651931717892").unwrap(), + U256::from_dec_str("7519753620411063893993038654245337200396081075176594821170650629333484307735").unwrap(), + ], + vec![ + U256::from_dec_str("3710770660542853524064560607689078015597423835131235506678560299694689990300").unwrap(), + U256::from_dec_str("5614292083398031256628051490208894298153846073526157332595481788509741490501").unwrap(), + ], + vec![ + U256::from_dec_str("20078380866648795629722839999599227955238325032514828038799728064893941679517").unwrap(), + U256::from_dec_str("20119759053067063735852536902576059766817546016509338827246433947870754928064").unwrap(), + ], + vec![ + U256::from_dec_str("21534411071117043370935210470042510482349669599514544586993218380262317946766").unwrap(), + U256::from_dec_str("3732652593424164815218097269577235093879112219070020480532471157884566435575").unwrap(), + ], + vec![ + U256::from_dec_str("914202501664188624437217460875067356655116871746027158611430275383721262460").unwrap(), + U256::from_dec_str("4705734910142038706008803835426807351430196670983074725174783743408516772252").unwrap(), + ], + vec![ + U256::from_dec_str("13269671382861063801742656963590767807574299083001338650656571090411520374435").unwrap(), + U256::from_dec_str("9384491173431647196874286778881722649539037427812437964731971759984118937933").unwrap(), + ], + vec![ + U256::from_dec_str("13125729058979703434326838390930436241715053680615211947758998735780663742234").unwrap(), + U256::from_dec_str("18251916520687748821686727257519897597261855663648932489281707717905152117467").unwrap(), + ], + vec![ + U256::from_dec_str("17344976452759912859216359556893576140899470724959684738889968775015869557197").unwrap(), + U256::from_dec_str("6389133661768713273368557048511335405494395213461472689525395186324704423376").unwrap(), + ], + vec![ + U256::from_dec_str("6654285101199080658766691402142671572613283476585253631584625231199984295297").unwrap(), + U256::from_dec_str("8781098977168486108004226572214388660098607817298006388220592119281389247107").unwrap(), + ], + vec![ + U256::from_dec_str("6222451681253934476137669768565736742025192662359478248756258775339796690138").unwrap(), + U256::from_dec_str("10135462584425053010794649955169082355399546688339847053640822820061877996779").unwrap(), + ], + vec![ + U256::from_dec_str("9001863072157687892542090021143207450374263146576957968961232315660797205691").unwrap(), + U256::from_dec_str("15485950372480454815754011467338385709915066127940363063996809472444868794768").unwrap(), + ], + vec![ + U256::from_dec_str("13854609252443964014253500266170779699772110475010273610098934711691037018431").unwrap(), + U256::from_dec_str("20183951798722484000813923295692960832600657304539510159073478598858845049884").unwrap(), + ], + vec![ + U256::from_dec_str("5009149762864565156931790177584262364524677499527751998450184844302995178615").unwrap(), + U256::from_dec_str("13593924634624192524816933676404605700054878909664226093265862736105894857387").unwrap(), + ], + vec![ + U256::from_dec_str("3235679020196617835617599419401376052093999618129660419896130076627172691776").unwrap(), + U256::from_dec_str("3672945914965606232288988588985362074692638978894414972844938524443558943294").unwrap(), + ], + vec![ + U256::from_dec_str("19997430478065411692446626965613571768401892436308376031777419505234898610525").unwrap(), + U256::from_dec_str("19496028539659666741307055192005464165365294110953457722351854025470690326368").unwrap(), + ], + vec![ + U256::from_dec_str("1126032053729725776969471166249327076697801974223436266234319829936142994428").unwrap(), + U256::from_dec_str("1936782966048939191038918746223733360522372518808305064770434481582538990769").unwrap(), + ], + vec![ + U256::from_dec_str("13322112226503241766242224434970603478241980167632482340846160572506467551993").unwrap(), + U256::from_dec_str("8183177369271153094538982832407066557058612152657745323415828015061401611878").unwrap(), + ], + vec![ + U256::from_dec_str("20914993233890112480061138799883565180987813697290385292901393950679298583773").unwrap(), + U256::from_dec_str("2158104559326662347973637565816542707843557115605024872122369365555774497928").unwrap(), + ], + vec![ + U256::from_dec_str("17919815233747636707024612684230423799222935350810031519005389277454122478732").unwrap(), + U256::from_dec_str("11388966857843853598028901823801313703810538258166813391542959146274971387057").unwrap(), + ], + ] + ); + + let valid_input = vec![ + U256::from_dec_str("100000").unwrap(), + U256::from_dec_str("100000").unwrap(), + U256::from_dec_str("100000").unwrap(), + U256::from_dec_str("100000").unwrap(), + U256::from_dec_str("100000").unwrap(), + U256::from_dec_str("100000").unwrap(), + U256::from_dec_str("100000").unwrap(), + U256::from_dec_str("100000").unwrap(), + U256::from_dec_str("100000").unwrap(), + U256::from_dec_str("100000").unwrap(), + U256::from_dec_str("100000").unwrap(), + U256::from_dec_str("100000").unwrap(), + U256::from_dec_str("100000").unwrap(), + U256::from_dec_str("100000").unwrap(), + U256::from_dec_str("100000").unwrap(), + U256::from_dec_str("100000").unwrap(), + U256::from_dec_str("100000").unwrap(), + U256::from_dec_str("100000").unwrap(), + U256::from_dec_str("100000").unwrap(), + U256::from_dec_str("100000").unwrap(), + ]; + + let verifying_key = VerifyingKey::new(proof, vk, valid_input); + + let zk_verifier = ZKPrecompileVerifier::new( + H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), + verifying_key + ); + + let encoded_call = zk_verifier.generate_benchmarking_parameters(); + + let gas_limit_call = 1000000; + let value = U256::default(); + let is_transactional = true; + let validate = true; + }:{ + let call_runner_results = ::Runner::call( + caller, + contract_address, + encoded_call, + value, + gas_limit_call, + Some(U256::from(1_000_000_000)), + Some(U256::from(1_000_000_000)), + None, + Vec::new(), + is_transactional, + validate, + ::config(), + ); + match call_runner_results { + Ok(info) => { + let output = info.value; + if output.len() >= 32 { + let mut result_bytes = [0u8; 32]; + result_bytes.copy_from_slice(&output[output.len() - 32..]); + let result = U256::from_big_endian(&result_bytes); + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "copy_20 Verification result {result:?}", + ); + assert_eq!(result, U256::one(), "The contract did not return true"); + } + }, + Err(e) => { + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "copy_20 Benchmarking failed", + ); + assert!(false, "Benchmarking failed"); + } + } + } + } impl_benchmark_test_suite!( Pallet, From 6d1b9c15003fd4d5ce1dceef6b96539b143f7f2d Mon Sep 17 00:00:00 2001 From: luckychacha <358140284@qq.com> Date: Mon, 14 Aug 2023 18:31:36 +0800 Subject: [PATCH 23/34] Update unit test testcase. --- .../src/zk_precompile_gas_estimation/mock.rs | 2 +- .../src/zk_precompile_gas_estimation/tests.rs | 82 +++++++++++-------- 2 files changed, 50 insertions(+), 34 deletions(-) diff --git a/runtime/runtime-common/src/zk_precompile_gas_estimation/mock.rs b/runtime/runtime-common/src/zk_precompile_gas_estimation/mock.rs index 955589c2..7c802647 100644 --- a/runtime/runtime-common/src/zk_precompile_gas_estimation/mock.rs +++ b/runtime/runtime-common/src/zk_precompile_gas_estimation/mock.rs @@ -144,7 +144,7 @@ where ZKGroth16Verify: Precompile, { fn execute(&self, handle: &mut impl PrecompileHandle) -> Option { - println!("aaa: {}", handle.code_address()); + println!("handle.code_address() = {:?}", handle.code_address()); match handle.code_address() { a if a == H160::from_low_u64_be(0x8888) => Some(ZKGroth16Verify::execute(handle)), _ => None, diff --git a/runtime/runtime-common/src/zk_precompile_gas_estimation/tests.rs b/runtime/runtime-common/src/zk_precompile_gas_estimation/tests.rs index 9e0355c4..0732baf0 100644 --- a/runtime/runtime-common/src/zk_precompile_gas_estimation/tests.rs +++ b/runtime/runtime-common/src/zk_precompile_gas_estimation/tests.rs @@ -61,6 +61,22 @@ pub fn new_test_ext() -> sp_io::TestExternalities { code: vec![], // No code, this is an EOA }, ); + accounts.insert( + // H160 address of Alice dev account + // Derived from SS58 (42 prefix) address + // SS58: 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY + // hex: 0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d + // Using the full hex key, truncating to the first 20 bytes (the first 40 hex chars) + H160::from_str("d43593c715fdd31c61141abd04a99fd6822c8558") + .expect("internal H160 is valid; qed"), + fp_evm::GenesisAccount { + balance: U256::from_str("0xffffffffffffffffffffffffffffffff") + .expect("internal U256 is valid; qed"), + code: Default::default(), + nonce: Default::default(), + storage: Default::default(), + }, + ); pallet_balances::GenesisConfig:: { // Create the block author account with some balance. @@ -78,86 +94,86 @@ pub fn new_test_ext() -> sp_io::TestExternalities { #[test] fn test_zk_precompile_gas_estimation() { new_test_ext().execute_with(|| { - let caller = "1000000000000000000000000000000000000666".parse::().unwrap(); + let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); let contract_address = H160::from_low_u64_be(0x8888); let proof_a = vec![ - U256::from_dec_str("17526830733396711760614584592227592290041884054274692385786120317424586951928").unwrap(), - U256::from_dec_str("14572975009604791670190722144346966861775781663452799801994174625223530481293").unwrap(), + U256::from_dec_str("344113499780097036133410144688544669449665038469801025061703634064197059916").unwrap(), + U256::from_dec_str("8339013355837829034186604529242237434382457535922383671882155606562413431689").unwrap(), ]; let proof_b = vec![ vec![ - U256::from_dec_str("601091821423560000095338178586024773386806597229060347992230108339560337314").unwrap(), - U256::from_dec_str("20742329792185135417418009297070484022157549629159037177761763368870046435272").unwrap(), + U256::from_dec_str("6694199005832176626648387473003377778002164049654344388623160500074797775370").unwrap(), + U256::from_dec_str("6246558478856965861562784864034844546822126660127014237507763330640717221466").unwrap(), ], vec![ - U256::from_dec_str("16755958476414893111742804329540858423617749911023931584301476920013641667491").unwrap(), - U256::from_dec_str("17783640965723747611121456292908504762681694379312402130038762071821040335901").unwrap(), + U256::from_dec_str("456859418727494804887897697519797382313397623366843307513728588676215628797").unwrap(), + U256::from_dec_str("19972929684979882956825623277042855987039264105600158828132263230333203670106").unwrap(), ], ]; let proof_c = vec![ - U256::from_dec_str("16585885402862686337557433720680035430031425737321159047915573958245961596065").unwrap(), - U256::from_dec_str("21138178351445807771687394250843863988645614435175735346332333179172518378873").unwrap(), + U256::from_dec_str("8991876521515422964548874095107781976525191569601242691722207742733698821028").unwrap(), + U256::from_dec_str("17304897036279645989594099459944208131107988079437513579584585106093260802053").unwrap(), ]; let vk_alpha = vec![ - U256::from_dec_str("11484345157460561328461496884344190739368158625792198603002887108334722367669").unwrap(), - U256::from_dec_str("7086541917963105127497541193167841067353924271429224233965614329678507699488").unwrap(), + U256::from_dec_str("16587578668155053320776501244706909164198053583863284386206654068019392556543").unwrap(), + U256::from_dec_str("17489859882312386925030082840618136961844042944104008122175974338708995824981").unwrap(), ]; let vk_beta = vec![ vec![ - U256::from_dec_str("11233128783379821052483619196929223312692971108992242120588689458439987752067").unwrap(), - U256::from_dec_str("18640573156008262049228946668908337221222445157240294147034515643976275941832").unwrap(), + U256::from_dec_str("8243058085082563940310351321464397410632520885003827137093771369586433446018").unwrap(), + U256::from_dec_str("1806964369040712598415691188975966807767394918682209427183228092832571919497").unwrap(), ], vec![ - U256::from_dec_str("8036983389612370781023375187819482868320454529134623464035669006179478819783").unwrap(), - U256::from_dec_str("16424116254718275500394502257751813449316936907205655002329084814392003619802").unwrap(), + U256::from_dec_str("5238575049648595236335310308987023404502439315997088611926714272919127054029").unwrap(), + U256::from_dec_str("10529242360048105445622302340100671863366518517961350431989359465371013288044").unwrap(), ], ]; - let vk_delta = vec![ + let vk_gamma = vec![ vec![ - U256::from_dec_str("11228532404788151396730538740677955321165465678604965636022681521723486460585").unwrap(), - U256::from_dec_str("9126453034411305688949328104662278794713000842053283268128161824572984268064").unwrap(), + U256::from_dec_str("422118731661843716781379598081446048950684758761078928178953272944418614265").unwrap(), + U256::from_dec_str("8071137901873450516865398890359069534977349842235015782367912081100468370342").unwrap(), ], vec![ - U256::from_dec_str("6386111381608251566396732981213051438889552027469318069778613233664780673905").unwrap(), - U256::from_dec_str("20548857422827059363546153463236239952243300189763734417419279501301392340910").unwrap(), + U256::from_dec_str("6616051543776580097026224309598118359974125974677691608309070965923230091481").unwrap(), + U256::from_dec_str("3144026861846828201735234261898216197057552604232403108299101704912138104081").unwrap(), ], ]; - let vk_gamma = vec![ + let vk_delta = vec![ vec![ - U256::from_dec_str("16318831326794673155348007016625372642245174324642568461921219640531003953421").unwrap(), - U256::from_dec_str("10357000493091964334208434777562330142557973636508422501741235212619215377564").unwrap(), + U256::from_dec_str("15967728838725285670062386536689775286816477877862913251436519988213464788203").unwrap(), + U256::from_dec_str("14482652023948193853731701210376245407114581664800773915003137369238699817066").unwrap(), ], vec![ - U256::from_dec_str("2549252377666082313659764548733755762481620259406193451284130401099909523405").unwrap(), - U256::from_dec_str("17286438687897881040082074476507835506847599850151991459812945029157729581277").unwrap(), + U256::from_dec_str("20222564526826997580988353930405539667760709452060576182511364617433825375503").unwrap(), + U256::from_dec_str("1855904408322765948314758770516591135802311025429227172106073057339165107921").unwrap(), ] ]; let vk_ic = vec![ vec![ - U256::from_dec_str("19809018900500753691845636946336582450384254173888544359470795703770668108982").unwrap(), - U256::from_dec_str("18905865743072988362439446807054892183348768606005293094676173646899256980681").unwrap(), + U256::from_dec_str("2234398803815490360326379119253073021265347911436036657996997085101774002925").unwrap(), + U256::from_dec_str("10214773739303944856355679056757071889148916152665035343340628435407174724717").unwrap(), ], vec![ - U256::from_dec_str("13731638277857114344416462118077651769684398274209992879843147837262038701628").unwrap(), - U256::from_dec_str("19144851605913607756613362053945586479161724714752749470233682046477131900096").unwrap(), + U256::from_dec_str("21500623561133929663133180424780657403302270303706782392356903439186747104812").unwrap(), + U256::from_dec_str("19328419280811286038333929820672543691407985372391054082759992875889788951230").unwrap(), ] ]; // let valid_input = vec![u64s_to_u256(vec![1250025000])]; let valid_input = vec![u64s_to_u256(vec![ - 14965631224775206224, - 3021577815302938909, - 14359293880404272991, - 1555005537055779113, + 14321691860995553260, + 7152862679273281751, + 12752615512303817990, + 1576113262537949146, ])]; let mut encoded_call = vec![0u8; 4]; From 5fd865a3e4ce648b278b44846d723f72dae8f86a Mon Sep 17 00:00:00 2001 From: luckychacha <358140284@qq.com> Date: Tue, 15 Aug 2023 18:53:18 +0800 Subject: [PATCH 24/34] Got gas used from benchmarking for gas estimation. --- .../benchmarking.rs | 4581 +++++++++-------- .../src/zk_precompile_gas_estimation/tests.rs | 3 +- 2 files changed, 2395 insertions(+), 2189 deletions(-) diff --git a/runtime/runtime-common/src/zk_precompile_gas_estimation/benchmarking.rs b/runtime/runtime-common/src/zk_precompile_gas_estimation/benchmarking.rs index 7416668b..c253d1c6 100644 --- a/runtime/runtime-common/src/zk_precompile_gas_estimation/benchmarking.rs +++ b/runtime/runtime-common/src/zk_precompile_gas_estimation/benchmarking.rs @@ -182,2134 +182,2234 @@ fn u64s_to_u256(values: Vec) -> U256 { } benchmarks! { - // nconstraints_10 { - // use frame_benchmarking::vec; - // use sp_core::{H160, U256, H256}; - - // let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); - // let contract_address = H160::from_low_u64_be(0x8888); - - // let proof = Proof::new( - // vec![ - // U256::from_dec_str("323654832133639084097738656057999026789295280666886852594984576709163539526").unwrap(), - // U256::from_dec_str("6142957218280645039826855630872622613337777761157366378615236951849913775542").unwrap() - // ], - // vec![ - // vec![ - // U256::from_dec_str("3781402603457401622553078625624300084337446058890012151530042647448923283156").unwrap(), - // U256::from_dec_str("3517436796495769146106898128956048233729888622957356948216773257280783319311").unwrap() - // ], - // vec![ - // U256::from_dec_str("18697717875318192535466611481750571094853863458428844875498420533596881568336").unwrap(), - // U256::from_dec_str("21426423909981695530725752097567643188095093768132522705564475372400085021436").unwrap() - // ], - // ], - // vec![ - // U256::from_dec_str("21613404883582191576526635676329374200679201344239432919502376530553941450391").unwrap(), - // U256::from_dec_str("15157755445966041962464884593780030869511182260822371637833098723763718514455").unwrap() - // ] - // ); - - // let vk = VerifyingKeyComponents::new( - // vec![ - // U256::from_dec_str("11521346682463921906610271064518766485088278761420928386309550940286650671457").unwrap(), - // U256::from_dec_str("14352830518175561380348856554041231805603495989169432000725584250110291361678").unwrap() - // ], - // vec![ - // vec![ - // U256::from_dec_str("15782596638536803844844408481637582589736413871396993858917786753770876529739").unwrap(), - // U256::from_dec_str("14911823231521430202833448929652297782496660742577343858219844871404504144036").unwrap() - // ], - // vec![ - // U256::from_dec_str("2082222914940990020573243578958386229340150899029559516350605378857473031525").unwrap(), - // U256::from_dec_str("13498996195230132373906915048494917069165130851394909752977335076805840989307").unwrap() - // ], - // ], - // vec![ - // vec![ - // U256::from_dec_str("3598021131780341035246011324427156192540414244243113294885735792953741606880").unwrap(), - // U256::from_dec_str("2036084172531515709709771052774738245922046202318890723044728246225539963428").unwrap() - // ], - // vec![ - // U256::from_dec_str("5925457711548235099025126547368719549508643015841982506039250719340224619945").unwrap(), - // U256::from_dec_str("6297446610567432982066083461547400065680646594595441716191878482607632761242").unwrap() - // ], - // ], - // vec![ - // vec![ - // U256::from_dec_str("8540596677770285018018336727251534074846909511956041125063939097422779191925").unwrap(), - // U256::from_dec_str("4004145476643750015352094786522189637304633549022019774555222068038038169997").unwrap() - // ], - // vec![ - // U256::from_dec_str("14044576757821380530542904664046256148829410228513509672845139471539338485558").unwrap(), - // U256::from_dec_str("21655834928283484760531472827487408029775629615266614212974138202212982461041").unwrap() - // ] - // ], - // vec![ - // vec![ - // U256::from_dec_str("18160015955331442477546361309657533914485780296451278252095683998154112390415").unwrap(), - // U256::from_dec_str("2421052745427024367257863480713357899822722660532800486395996070904226714086").unwrap() - // ], - // vec![ - // U256::from_dec_str("13418845437340247256566377432948869602549774753220761674399899795516131627829").unwrap(), - // U256::from_dec_str("19073971532401628571532840417056837528958340897410372352356543204393028153748").unwrap() - // ] - // ] - // ); - - // let valid_input: Vec = vec![u64s_to_u256(vec![ - // 14965631224775206224, - // 3021577815302938909, - // 14359293880404272991, - // 1555005537055779113 - // ])]; - - // let verifying_key = VerifyingKey::new(proof, vk, valid_input); - - // let zk_verifier = ZKPrecompileVerifier::new( - // H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), - // verifying_key - // ); - - // let encoded_call = zk_verifier.generate_benchmarking_parameters(); - - // let gas_limit_call = 1000000; - // let value = U256::default(); - // let is_transactional = true; - // let validate = true; - // }:{ - // let call_runner_results = ::Runner::call( - // caller, - // contract_address, - // encoded_call, - // value, - // gas_limit_call, - // Some(U256::from(1_000_000_000)), - // Some(U256::from(1_000_000_000)), - // None, - // Vec::new(), - // is_transactional, - // validate, - // ::config(), - // ); - // // log::info!( - // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // // "Benchmarking call end.", - // // ); - // match call_runner_results { - // Ok(info) => { - // let output = info.value; - // // log::info!( - // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // // "output result {:?}", - // // output - // // ); - // if output.len() >= 32 { - // let mut result_bytes = [0u8; 32]; - // result_bytes.copy_from_slice(&output[output.len() - 32..]); - // let result = U256::from_big_endian(&result_bytes); - // // log::info!( - // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // // "nconstraints_10 Verification result {result:?}", - // // ); - // assert_eq!(result, U256::one(), "The contract did not return true"); - // } - // }, - // Err(e) => { - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "nconstraints_10 Benchmarking failed", - // ); - // assert!(false, "Benchmarking failed"); - - // } - // } - // } - - // nconstraints_50 { - // use frame_benchmarking::vec; - // use sp_core::{H160, U256, H256}; - - // let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); - // let contract_address = H160::from_low_u64_be(0x8888); - - // let proof = Proof::new( - // vec![ - // U256::from_dec_str("2903574088029507435491062627919627539459038881203099780902103872696986272650").unwrap(), - // U256::from_dec_str("3875062839032259754068923295563862040166715100637843024855021734684308685930").unwrap(), - // ], - // vec![ - // vec![ - // U256::from_dec_str("5467576156112132028552287163049386912078800648727055176723583005212825192497").unwrap(), - // U256::from_dec_str("14958898784032520052694892656913773236193256742890765604760593633503039104983").unwrap(), - // ], - // vec![ - // U256::from_dec_str("5396143311660903133040196691443703988892234257628755380984718394981374344158").unwrap(), - // U256::from_dec_str("8621644456104449033213297238562527153800159584768570376273022394943050969320").unwrap(), - // ], - // ], - // vec![ - // U256::from_dec_str("11879092906448699692394725971977132036554363118574468164770659810752018463948").unwrap(), - // U256::from_dec_str("6829624468475499149259780051037762599455296300930683215687755977165243124154").unwrap(), - // ] - // ); - - // let vk = VerifyingKeyComponents::new( - // vec![ - // U256::from_dec_str("12520775544030530008009522467466185193766786263812261579427634884004150619566").unwrap(), - // U256::from_dec_str("5032545863820965741764073435262250124257467813113463153084126384917060899315").unwrap(), - // ], - // vec![ - // vec![ - // U256::from_dec_str("10017955328073015145877787608777450033090741247853140204265773706371885379542").unwrap(), - // U256::from_dec_str("9658203662920649739629860626443008098625554125855709045942833415049413198251").unwrap(), - // ], - // vec![ - // U256::from_dec_str("7602415148393817869205609282139785691690714005596249546125364310759985118071").unwrap(), - // U256::from_dec_str("6621887421318408197643297351639235440436194355283660692959196816576578875866").unwrap(), - // ], - // ], - // vec![ - // vec![ - // U256::from_dec_str("5311307398908794283615493653665859916837738758333406097237626345248614605789").unwrap(), - // U256::from_dec_str("17876886843886949913975349493510247353159584223381019718903135647608874168034").unwrap(), - // ], - // vec![ - // U256::from_dec_str("16871344858870476549165036353120397473700844904231047018564735968613233188965").unwrap(), - // U256::from_dec_str("3780010632071163899826543545524090280002435997376718121100375224910528030644").unwrap(), - // ], - // ], - // vec![ - // vec![ - // U256::from_dec_str("5274939476765287332787933848172441391963317633567336761478263433231602711901").unwrap(), - // U256::from_dec_str("20318717968421229127062334564952813061229602553850186042308931686220563993985").unwrap(), - // ], - // vec![ - // U256::from_dec_str("18867986549807700609691354300906273266753459571664361845748650324369589087167").unwrap(), - // U256::from_dec_str("3462802759155100024118895949055238081126591020075851877084161838812514424801").unwrap(), - // ] - // ], - // vec![ - // vec![ - // U256::from_dec_str("2073721309366561324099267234284336470258146869696430225377434175843251484752").unwrap(), - // U256::from_dec_str("5562089018027206512286783868306950659834000523781522158661084193254167305831").unwrap(), - // ], - // vec![ - // U256::from_dec_str("7633925392184781104787537197952383405066326059553608577981951477761067715424").unwrap(), - // U256::from_dec_str("19510227686274170330355317434483857344641524658406254379151352263942714837771").unwrap(), - // ] - // ] - // ); - - // let valid_input: Vec = vec![u64s_to_u256(vec![ - // 14754876691570659999, - // 1449725765053302887, - // 10573592104590215630, - // 2031301759166401468 - // ])]; - - // let verifying_key = VerifyingKey::new(proof, vk, valid_input); - - // let zk_verifier = ZKPrecompileVerifier::new( - // H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), - // verifying_key - // ); - - // let encoded_call = zk_verifier.generate_benchmarking_parameters(); - - // let gas_limit_call = 1000000; - // let value = U256::default(); - // let is_transactional = true; - // let validate = true; - // }:{ - // let call_runner_results = ::Runner::call( - // caller, - // contract_address, - // encoded_call, - // value, - // gas_limit_call, - // Some(U256::from(1_000_000_000)), - // Some(U256::from(1_000_000_000)), - // None, - // Vec::new(), - // is_transactional, - // validate, - // ::config(), - // ); - // // log::info!( - // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // // "Benchmarking call end.", - // // ); - // match call_runner_results { - // Ok(info) => { - // let output = info.value; - // // log::info!( - // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // // "output result {:?}", - // // output - // // ); - // if output.len() >= 32 { - // let mut result_bytes = [0u8; 32]; - // result_bytes.copy_from_slice(&output[output.len() - 32..]); - // let result = U256::from_big_endian(&result_bytes); - // // log::info!( - // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // // "nconstraints_50 Verification result {result:?}", - // // ); - // assert_eq!(result, U256::one(), "The contract did not return true"); - // } - // }, - // Err(e) => { - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "nconstraints_50 Benchmarking failed", - // ); - // assert!(false, "Benchmarking failed"); - - // } - // } - // } - - // nconstraints_1000 { - // use frame_benchmarking::vec; - // use sp_core::{H160, U256, H256}; - - // let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); - // let contract_address = H160::from_low_u64_be(0x8888); - - // let proof = Proof::new( - // vec![ - // U256::from_dec_str("12451505848309631687252015279596976128225375079184616465869275088833975377438").unwrap(), - // U256::from_dec_str("18028472547304696309803026581736164843724278168110632635282700219721294267849").unwrap(), - // ], - // vec![ - // vec![ - // U256::from_dec_str("724941625340075448308940885419778921267046089963198424690563710257350467820").unwrap(), - // U256::from_dec_str("19418815036545241911278056687101064762643664412732993043969007894248087117385").unwrap(), - // ], - // vec![ - // U256::from_dec_str("13249414494230793056410904135885722890271124096600389432878053498484425858770").unwrap(), - // U256::from_dec_str("21762806144353143011028620465453743506764842517668851190776375592288870325215").unwrap(), - // ], - // ], - // vec![ - // U256::from_dec_str("9206867270262791130308246301015463866896172966002943363908694359851632501217").unwrap(), - // U256::from_dec_str("13679683495177263967294831832954860495137891909047512983345948806664713075553").unwrap(), - // ] - // ); - - // let vk = VerifyingKeyComponents::new( - // vec![ - // U256::from_dec_str("13896934827344718021853288836918374118104295193491067840322643424358899121542").unwrap(), - // U256::from_dec_str("8854052944916041632001392967979629780372345382861670282089777314383817716115").unwrap(), - // ], - // vec![ - // vec![ - // U256::from_dec_str("3601177773308419037453361001975316835601350296485805323140167568598797930642").unwrap(), - // U256::from_dec_str("48851914275316782871445347689531673984580545598074561513165366823294923594").unwrap(), - // ], - // vec![ - // U256::from_dec_str("4538012201084519544875007504928553564968897773565284770715803834936680149613").unwrap(), - // U256::from_dec_str("3155968616270588886660033728776257587454508333510911411658919790925259116614").unwrap(), - // ], - // ], - // vec![ - // vec![ - // U256::from_dec_str("6521538659624675039700866061977650833785775087701556120926232218187885377774").unwrap(), - // U256::from_dec_str("18707623749213430453109215145186606994638201653518117177006249287165414157706").unwrap(), - // ], - // vec![ - // U256::from_dec_str("11743109857123024729794370527373948778820323338754388805090881243904381703330").unwrap(), - // U256::from_dec_str("3577725017182890090279110701721773090147301853148322630192233820247926772155").unwrap(), - // ], - // ], - // vec![ - // vec![ - // U256::from_dec_str("10697077492206594361644026971284249101590705030465491131467731100150008255694").unwrap(), - // U256::from_dec_str("1114380532795466865933623446272212800793315337032855536172932313989250445726").unwrap(), - // ], - // vec![ - // U256::from_dec_str("11747915450686416011932172170367549011245903715607283230565719536126230133873").unwrap(), - // U256::from_dec_str("1877153534214274703747923906347594924169181268669702005894131954432202950068").unwrap(), - // ] - // ], - // vec![ - // vec![ - // U256::from_dec_str("6294921440683861296812943370338888809368101163511446375226378176013676840633").unwrap(), - // U256::from_dec_str("8766686502883018606879699065134987161183815270662618961653335871316040755302").unwrap(), - // ], - // vec![ - // U256::from_dec_str("15422085976834841481597157129530660038025986735930069198619117556493669017719").unwrap(), - // U256::from_dec_str("6824904336141021449652133306590775160232847673735850151493603664420102965477").unwrap(), - // ] - // ] - // ); - - // let valid_input: Vec = vec![u64s_to_u256(vec![ - // 5637188163546619750, - // 4876642863872575056, - // 11311886144936918135, - // 2620236256196171805 - // ])]; - - // let verifying_key = VerifyingKey::new(proof, vk, valid_input); - - // let zk_verifier = ZKPrecompileVerifier::new( - // H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), - // verifying_key - // ); - - // let encoded_call = zk_verifier.generate_benchmarking_parameters(); - - // let gas_limit_call = 1000000; - // let value = U256::default(); - // let is_transactional = true; - // let validate = true; - // }:{ - // let call_runner_results = ::Runner::call( - // caller, - // contract_address, - // encoded_call, - // value, - // gas_limit_call, - // Some(U256::from(1_000_000_000)), - // Some(U256::from(1_000_000_000)), - // None, - // Vec::new(), - // is_transactional, - // validate, - // ::config(), - // ); - // // log::info!( - // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // // "Benchmarking call end.", - // // ); - // match call_runner_results { - // Ok(info) => { - // let output = info.value; - // // log::info!( - // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // // "output result {:?}", - // // output - // // ); - // if output.len() >= 32 { - // let mut result_bytes = [0u8; 32]; - // result_bytes.copy_from_slice(&output[output.len() - 32..]); - // let result = U256::from_big_endian(&result_bytes); - // // log::info!( - // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // // "nconstraints_1000 Verification result {result:?}", - // // ); - // assert_eq!(result, U256::one(), "The contract did not return true"); - // } - // }, - // Err(e) => { - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "nconstraints_1000 Benchmarking failed", - // ); - // assert!(false, "Benchmarking failed"); - - // } - // } - // } - // nconstraints_900000 { - // use frame_benchmarking::vec; - // use sp_core::{H160, U256, H256}; - - // let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); - // let contract_address = H160::from_low_u64_be(0x8888); - - // let proof = Proof::new( - // vec![ - // U256::from_dec_str("19469224081137364911375441935428613758543844094780123177610680784796374565509").unwrap(), - // U256::from_dec_str("2964109100176825277964902990593130655404587548088911907169158668561756482373").unwrap(), - // ], - // vec![ - // vec![ - // U256::from_dec_str("1804788596044451078391485097362341934563024367189115611320140606169017734442").unwrap(), - // U256::from_dec_str("13075356869764013404490647878715830765050556805353047586243641659166972614506").unwrap(), - // ], - // vec![ - // U256::from_dec_str("11510752280195741101381678478126680255679095252133774347633523263393718090827").unwrap(), - // U256::from_dec_str("19917734624109913540474402939707087760514256808495299709893660593520804971329").unwrap(), - // ], - // ], - // vec![ - // U256::from_dec_str("17650234014776935476405426867265189573543251264844619398004397025922351000524").unwrap(), - // U256::from_dec_str("13980409623437481166079302794215538337078177634480935418093274323345259996058").unwrap(), - // ] - // ); - - // let vk = VerifyingKeyComponents::new( - // vec![ - // U256::from_dec_str("7204013913559348808806179272679133668079798990573619252699122941477292720367").unwrap(), - // U256::from_dec_str("14448814309541293146746525253301533902449817953703436076734477345366335651547").unwrap(), - // ], - // vec![ - // vec![ - // U256::from_dec_str("12755354931522455226769415963087662012592248962914015697167303994293035888664").unwrap(), - // U256::from_dec_str("19979994508677160041392994419804596139216500302977150541381981675855322022114").unwrap(), - // ], - // vec![ - // U256::from_dec_str("3518578052095992035034011768990132253597152650327354182069223777691356587613").unwrap(), - // U256::from_dec_str("1512363495951297845516866605291301480678745477544041997800458458709067854003").unwrap(), - // ], - // ], - // vec![ - // vec![ - // U256::from_dec_str("21483901865224554977407186643009006049964266844355020377697169106001216486465").unwrap(), - // U256::from_dec_str("18122216236568402305988297032517775914181563813086813006164216689752246508886").unwrap(), - // ], - // vec![ - // U256::from_dec_str("7100124544075226034251596932805277307734457677256004047412258693103409543678").unwrap(), - // U256::from_dec_str("9484826513489508497326605298995346628011303684771342589708630141744196880174").unwrap(), - // ], - // ], - // vec![ - // vec![ - // U256::from_dec_str("4294809674390523555755416088340227038268056188806697061914357207030835445784").unwrap(), - // U256::from_dec_str("12772882987652274474928251216882135157601158713560023135442912416889883375009").unwrap(), - // ], - // vec![ - // U256::from_dec_str("5017814360156811257431228283078380210712481496173867244303167538680301406355").unwrap(), - // U256::from_dec_str("5483986251263351055676143301589669624262947345327185314870128974364440001262").unwrap(), - // ] - // ], - // vec![ - // vec![ - // U256::from_dec_str("10485365056956235833573091505977794158366069646492853613385564319176805042067").unwrap(), - // U256::from_dec_str("21560988819791135038184934219494970236802908435926324068683299817562907341696").unwrap(), - // ], - // vec![ - // U256::from_dec_str("9274251274730510866039258353232655161206943117093211738883330925803202790098").unwrap(), - // U256::from_dec_str("19994917632455570632082635510110118222993755636207706143729050502915579896735").unwrap(), - // ] - // ] - // ); - - // let valid_input: Vec = vec![u64s_to_u256(vec![ - // 10518156496175725870, - // 8513656267880232886, - // 1469451646407182009, - // 3425508166019525724 - // ])]; - - // let verifying_key = VerifyingKey::new(proof, vk, valid_input); - - // let zk_verifier = ZKPrecompileVerifier::new( - // H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), - // verifying_key - // ); - - // let encoded_call = zk_verifier.generate_benchmarking_parameters(); - - // let gas_limit_call = 1000000; - // let value = U256::default(); - // let is_transactional = true; - // let validate = true; - // }:{ - // let call_runner_results = ::Runner::call( - // caller, - // contract_address, - // encoded_call, - // value, - // gas_limit_call, - // Some(U256::from(1_000_000_000)), - // Some(U256::from(1_000_000_000)), - // None, - // Vec::new(), - // is_transactional, - // validate, - // ::config(), - // ); - // // log::info!( - // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // // "Benchmarking call end.", - // // ); - // match call_runner_results { - // Ok(info) => { - // let output = info.value; - // // log::info!( - // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // // "output result {:?}", - // // output - // // ); - // if output.len() >= 32 { - // let mut result_bytes = [0u8; 32]; - // result_bytes.copy_from_slice(&output[output.len() - 32..]); - // let result = U256::from_big_endian(&result_bytes); - // // log::info!( - // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // // "nconstraints_900000 Verification result {result:?}", - // // ); - // assert_eq!(result, U256::one(), "The contract did not return true"); - // } - // }, - // Err(e) => { - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "nconstraints_900000 Benchmarking failed", - // ); - // assert!(false, "Benchmarking failed"); - - // } - // } - // } - - // nconstraints_30_input_10 { - // use frame_benchmarking::vec; - // use sp_core::{H160, U256, H256}; - - // let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); - // let contract_address = H160::from_low_u64_be(0x8888); - - // let proof = Proof::new( - // vec![ - // U256::from_dec_str("344113499780097036133410144688544669449665038469801025061703634064197059916").unwrap(), - // U256::from_dec_str("8339013355837829034186604529242237434382457535922383671882155606562413431689").unwrap(), - // ], - // vec![ - // vec![ - // U256::from_dec_str("6694199005832176626648387473003377778002164049654344388623160500074797775370").unwrap(), - // U256::from_dec_str("6246558478856965861562784864034844546822126660127014237507763330640717221466").unwrap(), - // ], - // vec![ - // U256::from_dec_str("456859418727494804887897697519797382313397623366843307513728588676215628797").unwrap(), - // U256::from_dec_str("19972929684979882956825623277042855987039264105600158828132263230333203670106").unwrap(), - // ], - // ], - // vec![ - // U256::from_dec_str("8991876521515422964548874095107781976525191569601242691722207742733698821028").unwrap(), - // U256::from_dec_str("17304897036279645989594099459944208131107988079437513579584585106093260802053").unwrap(), - // ] - // ); - - // let vk = VerifyingKeyComponents::new( - // vec![ - // U256::from_dec_str("16587578668155053320776501244706909164198053583863284386206654068019392556543").unwrap(), - // U256::from_dec_str("17489859882312386925030082840618136961844042944104008122175974338708995824981").unwrap(), - // ], - // vec![ - // vec![ - // U256::from_dec_str("8243058085082563940310351321464397410632520885003827137093771369586433446018").unwrap(), - // U256::from_dec_str("1806964369040712598415691188975966807767394918682209427183228092832571919497").unwrap(), - // ], - // vec![ - // U256::from_dec_str("5238575049648595236335310308987023404502439315997088611926714272919127054029").unwrap(), - // U256::from_dec_str("10529242360048105445622302340100671863366518517961350431989359465371013288044").unwrap(), - // ], - // ], - // vec![ - // vec![ - // U256::from_dec_str("422118731661843716781379598081446048950684758761078928178953272944418614265").unwrap(), - // U256::from_dec_str("8071137901873450516865398890359069534977349842235015782367912081100468370342").unwrap(), - // ], - // vec![ - // U256::from_dec_str("6616051543776580097026224309598118359974125974677691608309070965923230091481").unwrap(), - // U256::from_dec_str("3144026861846828201735234261898216197057552604232403108299101704912138104081").unwrap(), - // ], - // ], - // vec![ - // vec![ - // U256::from_dec_str("15967728838725285670062386536689775286816477877862913251436519988213464788203").unwrap(), - // U256::from_dec_str("14482652023948193853731701210376245407114581664800773915003137369238699817066").unwrap(), - // ], - // vec![ - // U256::from_dec_str("20222564526826997580988353930405539667760709452060576182511364617433825375503").unwrap(), - // U256::from_dec_str("1855904408322765948314758770516591135802311025429227172106073057339165107921").unwrap(), - // ] - // ], - // vec![ - // vec![ - // U256::from_dec_str("2234398803815490360326379119253073021265347911436036657996997085101774002925").unwrap(), - // U256::from_dec_str("10214773739303944856355679056757071889148916152665035343340628435407174724717").unwrap(), - // ], - // vec![ - // U256::from_dec_str("21500623561133929663133180424780657403302270303706782392356903439186747104812").unwrap(), - // U256::from_dec_str("19328419280811286038333929820672543691407985372391054082759992875889788951230").unwrap(), - // ] - // ] - // ); - - // let valid_input: Vec = vec![u64s_to_u256(vec![ - // 14321691860995553260, - // 7152862679273281751, - // 12752615512303817990, - // 1576113262537949146 - // ])]; - - // let verifying_key = VerifyingKey::new(proof, vk, valid_input); - - // let zk_verifier = ZKPrecompileVerifier::new( - // H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), - // verifying_key - // ); - - // let encoded_call = zk_verifier.generate_benchmarking_parameters(); - - // let gas_limit_call = 1000000; - // let value = U256::default(); - // let is_transactional = true; - // let validate = true; - // }:{ - // let call_runner_results = ::Runner::call( - // caller, - // contract_address, - // encoded_call, - // value, - // gas_limit_call, - // Some(U256::from(1_000_000_000)), - // Some(U256::from(1_000_000_000)), - // None, - // Vec::new(), - // is_transactional, - // validate, - // ::config(), - // ); - // // log::info!( - // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // // "Benchmarking call end.", - // // ); - // match call_runner_results { - // Ok(info) => { - // let output = info.value; - // // log::info!( - // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // // "output result {:?}", - // // output - // // ); - // if output.len() >= 32 { - // let mut result_bytes = [0u8; 32]; - // result_bytes.copy_from_slice(&output[output.len() - 32..]); - // let result = U256::from_big_endian(&result_bytes); - // // log::info!( - // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // // "nconstraints_30_input_10 Verification result {result:?}", - // // ); - // assert_eq!(result, U256::one(), "The contract did not return true"); - // } - // }, - // Err(e) => { - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "nconstraints_30_input_10 Benchmarking failed", - // ); - // assert!(false, "Benchmarking failed"); - - // } - // } - // } - // nconstraints_30_input_100 { - // use frame_benchmarking::vec; - // use sp_core::{H160, U256, H256}; - - // let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); - // let contract_address = H160::from_low_u64_be(0x8888); - - // let proof = Proof::new( - // vec![ - // U256::from_dec_str("3780487311936056381294564418675304364481973966802209296561160829797948105411").unwrap(), - // U256::from_dec_str("12392254879980640223142009257910424254771509444451393927739643876401726307795").unwrap(), - // ], - // vec![ - // vec![ - // U256::from_dec_str("5169548117445173154024813698359426977000013771483410622256640533171985245380").unwrap(), - // U256::from_dec_str("11220449603083268927036844276912830985523128428499468942581840512730495047625").unwrap(), - // ], - // vec![ - // U256::from_dec_str("7617888807668014594076695037395251387521432502213194545531858961238344338860").unwrap(), - // U256::from_dec_str("3206448605631210983027663221710912427383659852717855953276353488187250079459").unwrap(), - // ], - // ], - // vec![ - // U256::from_dec_str("17260938596020642923034443094579912726381749511890996943502017876149586484217").unwrap(), - // U256::from_dec_str("973711408795313031099855712156150142641887502706075552254275664528776194028").unwrap(), - // ] - // ); - - // let vk = VerifyingKeyComponents::new( - // vec![ - // U256::from_dec_str("4155898266631322214574856388057229131381603659142355428000239527171539910720").unwrap(), - // U256::from_dec_str("15919304600573806746067202721026223664629992455130946331020176989460510062648").unwrap(), - // ], - // vec![ - // vec![ - // U256::from_dec_str("10559477888637541108523299513483158185288656601390229631277602982302056830264").unwrap(), - // U256::from_dec_str("21518216923189214839507247102243744126930049565774641401859791113452178471842").unwrap(), - // ], - // vec![ - // U256::from_dec_str("20524972206762616004058259260290957844870248494446046806278424843369643489182").unwrap(), - // U256::from_dec_str("17430943082223119961631960086233630485654941075995072846024219998674392652581").unwrap(), - // ], - // ], - // vec![ - // vec![ - // U256::from_dec_str("4636362103930283526843587215716464395878300635435610009766312980459671398351").unwrap(), - // U256::from_dec_str("15713999866924132629927290621261290205960872899800820372400263081232019214301").unwrap(), - // ], - // vec![ - // U256::from_dec_str("274224283373606674211197218239218941312046485596075799302472837928822177016").unwrap(), - // U256::from_dec_str("10693491445395060496723678108216498586881120243971297703830999940561952271629").unwrap(), - // ], - // ], - // vec![ - // vec![ - // U256::from_dec_str("9540601502504552621404908678855872975596983734893914263055690675850649191273").unwrap(), - // U256::from_dec_str("10288168694112392204164781631687615725045294841966564539511156565183262528849").unwrap(), - // ], - // vec![ - // U256::from_dec_str("16504160099082952601826232467479510151840980336862791499394346450083636791102").unwrap(), - // U256::from_dec_str("9210167978306154509907086298616199856898787966613435045760659519455958969992").unwrap(), - // ] - // ], - // vec![ - // vec![ - // U256::from_dec_str("15812098394101742886061540987450559986219804469912805896076341688421241661621").unwrap(), - // U256::from_dec_str("11920211969663783445335622417572072568292106489672989284415235777753260953099").unwrap(), - // ], - // vec![ - // U256::from_dec_str("7061409000327933635430701054193661775345794014516696263402966093123651666364").unwrap(), - // U256::from_dec_str("17078047162776906089011285464212202278306676406084693061907121919624683442357").unwrap(), - // ] - // ] - // ); - - // let valid_input: Vec = vec![u64s_to_u256(vec![ - // 9831528597301135316, - // 11053911270256492840, - // 14337707091878126846, - // 772611368070892958 - // ])]; - - // let verifying_key = VerifyingKey::new(proof, vk, valid_input); - - // let zk_verifier = ZKPrecompileVerifier::new( - // H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), - // verifying_key - // ); - - // let encoded_call = zk_verifier.generate_benchmarking_parameters(); - - // let gas_limit_call = 1000000; - // let value = U256::default(); - // let is_transactional = true; - // let validate = true; - // }:{ - // let call_runner_results = ::Runner::call( - // caller, - // contract_address, - // encoded_call, - // value, - // gas_limit_call, - // Some(U256::from(1_000_000_000)), - // Some(U256::from(1_000_000_000)), - // None, - // Vec::new(), - // is_transactional, - // validate, - // ::config(), - // ); - // // log::info!( - // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // // "Benchmarking call end.", - // // ); - // match call_runner_results { - // Ok(info) => { - // let output = info.value; - // // log::info!( - // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // // "output result {:?}", - // // output - // // ); - // if output.len() >= 32 { - // let mut result_bytes = [0u8; 32]; - // result_bytes.copy_from_slice(&output[output.len() - 32..]); - // let result = U256::from_big_endian(&result_bytes); - // // log::info!( - // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // // "nconstraints_30_input_100 Verification result {result:?}", - // // ); - // assert_eq!(result, U256::one(), "The contract did not return true"); - // } - // }, - // Err(e) => { - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "nconstraints_30_input_100 Benchmarking failed", - // ); - // assert!(false, "Benchmarking failed"); - // } - // } - // } - // nconstraints_30_input_1000 { - // use frame_benchmarking::vec; - // use sp_core::{H160, U256, H256}; - - // let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); - // let contract_address = H160::from_low_u64_be(0x8888); - - // let proof = Proof::new( - // vec![ - // U256::from_dec_str("21424271595387505713049534900676381136649432939050012296331964885140120988520").unwrap(), - // U256::from_dec_str("20488789316104689748479888121024139144355086386496471461763924485714534718686").unwrap(), - // ], - // vec![ - // vec![ - // U256::from_dec_str("8417699613540073682519718294821269056423071880647667978060348740795273915651").unwrap(), - // U256::from_dec_str("4036859279888161250878359321718658739242283134835030699023268489309754993434").unwrap(), - // ], - // vec![ - // U256::from_dec_str("16249800568747110450527363597274431407786919086057853194987169090454936230259").unwrap(), - // U256::from_dec_str("15005851458712291005106538565823270955208428726378749297397203143137382225457").unwrap(), - // ], - // ], - // vec![ - // U256::from_dec_str("21239990703864671714190525785674088715931473556140655107585637961585812134589").unwrap(), - // U256::from_dec_str("261928180985765917331919571442880380998408670702589931014636966043229919418").unwrap(), - // ] - // ); - - // let vk = VerifyingKeyComponents::new( - // vec![ - // U256::from_dec_str("1657406292532781196449359079614579852690925607592278296574718289470803732053").unwrap(), - // U256::from_dec_str("18213557747942747074556848145237207574111244905157024361329330629173034829885").unwrap(), - // ], - // vec![ - // vec![ - // U256::from_dec_str("5419856735820685908218319193906907396496344921642651266629131019868853843815").unwrap(), - // U256::from_dec_str("14007905369450574044915098075029863272475910046750101274280969769181784166430").unwrap(), - // ], - // vec![ - // U256::from_dec_str("182200131698860550444455761364918630551676350878779858078817264277300629723").unwrap(), - // U256::from_dec_str("6050431818377820601319883600432739448105157482353041283628740094609821419656").unwrap(), - // ], - // ], - // vec![ - // vec![ - // U256::from_dec_str("14463567879100083166257564330995533094334991709675023767975192973144798919122").unwrap(), - // U256::from_dec_str("6166287541473141918830331239835928582190744434356526822227225877844349692203").unwrap(), - // ], - // vec![ - // U256::from_dec_str("12512843744533735346513506961399336936527367720771340395643503621530703342395").unwrap(), - // U256::from_dec_str("8394818975982736201521422268641084055810886358791398607930311472872317386487").unwrap(), - // ], - // ], - // vec![ - // vec![ - // U256::from_dec_str("8757732756289429354419510422628896433407345473998310348115924113882282945326").unwrap(), - // U256::from_dec_str("1610185885725147927651201796201713521257480620743342969197368887869230657180").unwrap(), - // ], - // vec![ - // U256::from_dec_str("2834338214415807920713929739507915327763263469562351781747229949754640383374").unwrap(), - // U256::from_dec_str("20761263923134391843554423575366232120525285729512411038267095810712916924016").unwrap(), - // ] - // ], - // vec![ - // vec![ - // U256::from_dec_str("16585432354609922217222548226453277630464695131710476183479619760311567992522").unwrap(), - // U256::from_dec_str("5379258900528839934525784961038010961454863754298062530193947624450477797122").unwrap(), - // ], - // vec![ - // U256::from_dec_str("16825349369326282879106301528709807467071985531593215317852699692046311881677").unwrap(), - // U256::from_dec_str("10540450379202726868409867306854114915477889581096312866635875249145708179576").unwrap(), - // ] - // ] - // ); - - // let valid_input: Vec = vec![u64s_to_u256(vec![ - // 3008789406746563016, - // 7061370202899273426, - // 2191755323004339933, - // 1005591455220622530 - // ])]; - - // let verifying_key = VerifyingKey::new(proof, vk, valid_input); - - // let zk_verifier = ZKPrecompileVerifier::new( - // H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), - // verifying_key - // ); - - // let encoded_call = zk_verifier.generate_benchmarking_parameters(); - - // let gas_limit_call = 1000000; - // let value = U256::default(); - // let is_transactional = true; - // let validate = true; - // }:{ - // let call_runner_results = ::Runner::call( - // caller, - // contract_address, - // encoded_call, - // value, - // gas_limit_call, - // Some(U256::from(1_000_000_000)), - // Some(U256::from(1_000_000_000)), - // None, - // Vec::new(), - // is_transactional, - // validate, - // ::config(), - // ); - // // log::info!( - // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // // "Benchmarking call end.", - // // ); - // match call_runner_results { - // Ok(info) => { - // let output = info.value; - // // log::info!( - // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // // "output result {:?}", - // // output - // // ); - // if output.len() >= 32 { - // let mut result_bytes = [0u8; 32]; - // result_bytes.copy_from_slice(&output[output.len() - 32..]); - // let result = U256::from_big_endian(&result_bytes); - // // log::info!( - // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // // "nconstraints_30_input_1000 Verification result {result:?}", - // // ); - // assert_eq!(result, U256::one(), "The contract did not return true"); - // } - // }, - // Err(e) => { - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "nconstraints_30_input_1000 Benchmarking failed", - // ); - // assert!(false, "Benchmarking failed"); - // } - // } - // } - // nconstraints_30_input_5000 { - // use frame_benchmarking::vec; - // use sp_core::{H160, U256, H256}; - - // let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); - // let contract_address = H160::from_low_u64_be(0x8888); - - // let proof = Proof::new( - // vec![ - // U256::from_dec_str("4760178114933307527976205229418881302833473087272893863010681924222436742436").unwrap(), - // U256::from_dec_str("6555056836023646163359279772724076765411780318148657506988760187885700674215").unwrap(), - // ], - // vec![ - // vec![ - // U256::from_dec_str("9540205596737585525189386078607957630969059503165883907845238817662495399607").unwrap(), - // U256::from_dec_str("21777913747079267536001051597001736802905779914683258171463923506869689358122").unwrap(), - // ], - // vec![ - // U256::from_dec_str("7652162643714058076103867092157642519402862581818067281609790687905833151647").unwrap(), - // U256::from_dec_str("5174136241284192352871549806655421810249317805219641765935618077180420544939").unwrap(), - // ], - // ], - // vec![ - // U256::from_dec_str("9633653417112713107386510132385608824105920168790226750481878454006412372444").unwrap(), - // U256::from_dec_str("5600932933208824148570351176368803282808856587672889614186338874655752173453").unwrap(), - // ] - // ); - - // let vk = VerifyingKeyComponents::new( - // vec![ - // U256::from_dec_str("20563201722283471489193032980811350162387466733119686723832100493505332037220").unwrap(), - // U256::from_dec_str("458683337854426284881131074995322438618437423037306322290239745015633774839").unwrap(), - // ], - // vec![ - // vec![ - // U256::from_dec_str("802687519037697530569139206036966996588449135138601551566343295868421688400").unwrap(), - // U256::from_dec_str("10902489968444563758310974921240106861656913905085710523025258522577834664814").unwrap(), - // ], - // vec![ - // U256::from_dec_str("8163282908300075270434111132545381898266738500810094061899946027883982232155").unwrap(), - // U256::from_dec_str("2879234862354419255322548813414679750617024208122660306082351289172177493856").unwrap(), - // ], - // ], - // vec![ - // vec![ - // U256::from_dec_str("12946416399098615767859440028401625777970463338055590127763655113029764523456").unwrap(), - // U256::from_dec_str("19000556224902286061769815260124368973839417953399533885850283592096662743016").unwrap(), - // ], - // vec![ - // U256::from_dec_str("16883066945921282046110808795753929362007100542422795769422243319629113077450").unwrap(), - // U256::from_dec_str("3229017908221308993692674040951942449106283130433174678816420254626513367678").unwrap(), - // ], - // ], - // vec![ - // vec![ - // U256::from_dec_str("16459854676924169388774046538295013154707390397685062918225181412137603478923").unwrap(), - // U256::from_dec_str("20996869365345436816737319903210535785982053153529758285286719146777762981985").unwrap(), - // ], - // vec![ - // U256::from_dec_str("21446959969822179574296836241978980045198577120638747119902976563053247153220").unwrap(), - // U256::from_dec_str("4716297282146551186330252875195511360280503254452482577157100992033023717484").unwrap(), - // ] - // ], - // vec![ - // vec![ - // U256::from_dec_str("2127664998061023131080125201643658604092063304061707222326237054428506173927").unwrap(), - // U256::from_dec_str("13918137729545385379467184110597023571257121066683873930760549927318081992996").unwrap(), - // ], - // vec![ - // U256::from_dec_str("16560640526003408304721205785917894782070253870764339317137905014294472374327").unwrap(), - // U256::from_dec_str("19394535992291030838186763750684977819230291410826312937425829210188321257228").unwrap(), - // ] - // ] - // ); - - // let valid_input: Vec = vec![u64s_to_u256(vec![ - // 13212982172557049181, - // 17043673098390055166, - // 13971391527459105160, - // 1729491887349651790, - // ])]; - - // let verifying_key = VerifyingKey::new(proof, vk, valid_input); - - // let zk_verifier = ZKPrecompileVerifier::new( - // H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), - // verifying_key - // ); - - // let encoded_call = zk_verifier.generate_benchmarking_parameters(); - - // let gas_limit_call = 1000000; - // let value = U256::default(); - // let is_transactional = true; - // let validate = true; - // }:{ - // let call_runner_results = ::Runner::call( - // caller, - // contract_address, - // encoded_call, - // value, - // gas_limit_call, - // Some(U256::from(1_000_000_000)), - // Some(U256::from(1_000_000_000)), - // None, - // Vec::new(), - // is_transactional, - // validate, - // ::config(), - // ); - // // log::info!( - // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // // "Benchmarking call end.", - // // ); - // match call_runner_results { - // Ok(info) => { - // let output = info.value; - // // log::info!( - // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // // "output result {:?}", - // // output - // // ); - // if output.len() >= 32 { - // let mut result_bytes = [0u8; 32]; - // result_bytes.copy_from_slice(&output[output.len() - 32..]); - // let result = U256::from_big_endian(&result_bytes); - // // log::info!( - // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // // "nconstraints_30_input_5000 Verification result {result:?}", - // // ); - // assert_eq!(result, U256::one(), "The contract did not return true"); - // } - // }, - // Err(e) => { - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "nconstraints_30_input_5000 Benchmarking failed", - // ); - // assert!(false, "Benchmarking failed"); - // } - // } - // } - // nconstraints_30_input_10000 { - // use frame_benchmarking::vec; - // use sp_core::{H160, U256, H256}; - - // let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); - // let contract_address = H160::from_low_u64_be(0x8888); - - // let proof = Proof::new( - // vec![ - // U256::from_dec_str("20201588552006483041582128307591335561381558661958982754827324334159524114833").unwrap(), - // U256::from_dec_str("17768889616334897699714190449991059857597665579001510168911964966707846254013").unwrap(), - // ], - // vec![ - // vec![ - // U256::from_dec_str("831427914683469755258685737297441858923030844026909228595596228891513784401").unwrap(), - // U256::from_dec_str("17358733390631981546461856303504163975689822422160671163593908204299387350560").unwrap(), - // ], - // vec![ - // U256::from_dec_str("12673178383954759426828314411760863182427996098705680584931403917390222262168").unwrap(), - // U256::from_dec_str("12056092533572380482681874959737292916971452073896642753405050795241584080793").unwrap(), - // ], - // ], - // vec![ - // U256::from_dec_str("11086630979744216291689656728938462056245402184490217943698398792953833540899").unwrap(), - // U256::from_dec_str("6981043472993913602669753829495794560155248771335035866541870305230603679484").unwrap(), - // ] - // ); - - // let vk = VerifyingKeyComponents::new( - // vec![ - // U256::from_dec_str("10088605449330278081588905225706913827985798761474642054412607299987851491561").unwrap(), - // U256::from_dec_str("12349112716571349951448807635426375878752472531266562453302627732729311140226").unwrap(), - // ], - // vec![ - // vec![ - // U256::from_dec_str("11234930657858483584603353214391341220392609835907149947974795594440445721655").unwrap(), - // U256::from_dec_str("1047093079337214465686469751128183347143657884406521365857439579470759333731").unwrap(), - // ], - // vec![ - // U256::from_dec_str("15864899975231343872664645828141071246029692141564279838230890638453916423742").unwrap(), - // U256::from_dec_str("12053277475368564348616897081746431255423835262329161057768339971384736640081").unwrap(), - // ], - // ], - // vec![ - // vec![ - // U256::from_dec_str("20662189442791195318296211376162761628558291902545582141646463139520777475283").unwrap(), - // U256::from_dec_str("9279465006661849499753241364514057268552316193158700659184124742215268752791").unwrap(), - // ], - // vec![ - // U256::from_dec_str("17033606864312833588672465768726096906720807717470346504048425104291392352898").unwrap(), - // U256::from_dec_str("15319242533246792039334613039385600689133248724151496600840914674340560979641").unwrap(), - // ], - // ], - // vec![ - // vec![ - // U256::from_dec_str("3303817333656562581428241644233610206796391323593261940899405821542387319372").unwrap(), - // U256::from_dec_str("12434486975702473910116656089923156849733601159782506519440013280731025013736").unwrap(), - // ], - // vec![ - // U256::from_dec_str("9561232329300105849651786447909752108987569955850131116304832039966768267007").unwrap(), - // U256::from_dec_str("18486557213071145739422364713271115450952939790314495487369777335095317193174").unwrap(), - // ] - // ], - // vec![ - // vec![ - // U256::from_dec_str("5864321703423906069527768678401445332135246771872328360194332677453860634867").unwrap(), - // U256::from_dec_str("3305620141441221125469209629518919979790470359050105194093502369856652644459").unwrap(), - // ], - // vec![ - // U256::from_dec_str("1810088252629429255118238329671475280643793553294287131634484491846973310510").unwrap(), - // U256::from_dec_str("20707970746663158481851347112547705553728126185220754421254503093218351233120").unwrap(), - // ] - // ] - // ); - - // let valid_input: Vec = vec![u64s_to_u256(vec![ - // 11033755416221607095, - // 14172640425079373737, - // 17268699570210893519, - // 2451003838444787962, - // ])]; - - // let verifying_key = VerifyingKey::new(proof, vk, valid_input); - - // let zk_verifier = ZKPrecompileVerifier::new( - // H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), - // verifying_key - // ); - - // let encoded_call = zk_verifier.generate_benchmarking_parameters(); - - // let gas_limit_call = 1000000; - // let value = U256::default(); - // let is_transactional = true; - // let validate = true; - // }:{ - // let call_runner_results = ::Runner::call( - // caller, - // contract_address, - // encoded_call, - // value, - // gas_limit_call, - // Some(U256::from(1_000_000_000)), - // Some(U256::from(1_000_000_000)), - // None, - // Vec::new(), - // is_transactional, - // validate, - // ::config(), - // ); - // // log::info!( - // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // // "Benchmarking call end.", - // // ); - // match call_runner_results { - // Ok(info) => { - // let output = info.value; - // // log::info!( - // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // // "output result {:?}", - // // output - // // ); - // if output.len() >= 32 { - // let mut result_bytes = [0u8; 32]; - // result_bytes.copy_from_slice(&output[output.len() - 32..]); - // let result = U256::from_big_endian(&result_bytes); - // // log::info!( - // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // // "nconstraints_30_input_10000 Verification result {result:?}", - // // ); - // assert_eq!(result, U256::one(), "The contract did not return true"); - // } - // }, - // Err(e) => { - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "nconstraints_30_input_10000 Benchmarking failed", - // ); - // assert!(false, "Benchmarking failed"); - - // } - // } - // } - // nconstraints_30_input_90000 { - // use frame_benchmarking::vec; - // use sp_core::{H160, U256, H256}; - - // let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); - // let contract_address = H160::from_low_u64_be(0x8888); - - // let proof = Proof::new( - // vec![ - // U256::from_dec_str("7949275001087845673352113652992317737416671749823042856819742064958185730665").unwrap(), - // U256::from_dec_str("5891863541401068443747112095836743353338477825995666306081231182884954636005").unwrap(), - // ], - // vec![ - // vec![ - // U256::from_dec_str("12960565378826264234747222392568347150301360486418725511109506548813034322775").unwrap(), - // U256::from_dec_str("6924824876048701587380679111548259437770370772320848338373383587483809707515").unwrap(), - // ], - // vec![ - // U256::from_dec_str("21689747160304810742710652756166876177223750769696622871469266436845305438116").unwrap(), - // U256::from_dec_str("14167066926549192557125941689316913820167617731059401320567819691908586156039").unwrap(), - // ], - // ], - // vec![ - // U256::from_dec_str("19186797317064887099470636752510606772753033946198593325337771098325482447274").unwrap(), - // U256::from_dec_str("3350186543680262034371474397706130211690310055235028696466009478959025709845").unwrap(), - // ] - // ); - - // let vk = VerifyingKeyComponents::new( - // vec![ - // U256::from_dec_str("6828794497030502754628523747507406719479438181845328406281207577196379759609").unwrap(), - // U256::from_dec_str("5561027388439947090438746111225212164455366280326670821700904471009784329896").unwrap(), - // ], - // vec![ - // vec![ - // U256::from_dec_str("1648517694167305339737563900225685665396551354808983529387892872646841040850").unwrap(), - // U256::from_dec_str("15406833006990307743521713564090315343374212223020060642984366610793788667116").unwrap(), - // ], - // vec![ - // U256::from_dec_str("14591594646846027404699868040454897990147675572067174007423843530180728597612").unwrap(), - // U256::from_dec_str("2940958434778941597191243007999700895445672570190450648227198352981565653913").unwrap(), - // ], - // ], - // vec![ - // vec![ - // U256::from_dec_str("7676142418543194845482248509044991512324196983308812731866772308356979871307").unwrap(), - // U256::from_dec_str("21511013842679919895947796523736214038726875927496967606596253311081756690725").unwrap(), - // ], - // vec![ - // U256::from_dec_str("4652378032872178978450279958290699982888059033676566152376150880744787185780").unwrap(), - // U256::from_dec_str("467504210088082002071026778234767679654059202832780062786965483300786044530").unwrap(), - // ], - // ], - // vec![ - // vec![ - // U256::from_dec_str("20744282071154891204049714936088748576694067059171789505913191933597423689555").unwrap(), - // U256::from_dec_str("12596866572762256583276410876169296807308160857887657727882625055041251553242").unwrap(), - // ], - // vec![ - // U256::from_dec_str("3588798969790877834321031026222278845206273301850566393834657489341158616535").unwrap(), - // U256::from_dec_str("19268326464935908053037454129640878232926568425004490855381855273084219557079").unwrap(), - // ] - // ], - // vec![ - // vec![ - // U256::from_dec_str("10928515506460596401961934744263657631726985113185854450754018401146226707446").unwrap(), - // U256::from_dec_str("1043421123157233618994554398894819122012315878788274412803269234825060696656").unwrap(), - // ], - // vec![ - // U256::from_dec_str("21802758012415709270812560952687831790545411568500639317690833457802568775035").unwrap(), - // U256::from_dec_str("8926874931677263335476856545765471099163606107894025045476086328360781102193").unwrap(), - // ] - // ] - // ); - - // let valid_input: Vec = vec![u64s_to_u256(vec![ - // 2553457387449696641, - // 815105491620421980, - // 17800546104409657428, - // 2866567216183504159, - // ])]; - - // let verifying_key = VerifyingKey::new(proof, vk, valid_input); - - // let zk_verifier = ZKPrecompileVerifier::new( - // H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), - // verifying_key - // ); - - // let encoded_call = zk_verifier.generate_benchmarking_parameters(); - - // let gas_limit_call = 1000000; - // let value = U256::default(); - // let is_transactional = true; - // let validate = true; - // }:{ - // let call_runner_results = ::Runner::call( - // caller, - // contract_address, - // encoded_call, - // value, - // gas_limit_call, - // Some(U256::from(1_000_000_000)), - // Some(U256::from(1_000_000_000)), - // None, - // Vec::new(), - // is_transactional, - // validate, - // ::config(), - // ); - // // log::info!( - // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // // "Benchmarking call end.", - // // ); - // match call_runner_results { - // Ok(info) => { - // let output = info.value; - // // log::info!( - // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // // "output result {:?}", - // // output - // // ); - // if output.len() >= 32 { - // let mut result_bytes = [0u8; 32]; - // result_bytes.copy_from_slice(&output[output.len() - 32..]); - // let result = U256::from_big_endian(&result_bytes); - // // log::info!( - // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // // "nconstraints_30_input_90000 Verification result {result:?}", - // // ); - // assert_eq!(result, U256::one(), "The contract did not return true"); - // } - // }, - // Err(e) => { - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "nconstraints_30_input_90000 Benchmarking failed", - // ); - // assert!(false, "Benchmarking failed"); - // } - // } - // } - // nconstraints_30_input_200000 { - // use frame_benchmarking::vec; - // use sp_core::{H160, U256, H256}; - - // let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); - // let contract_address = H160::from_low_u64_be(0x8888); - - // let proof = Proof::new( - // vec![ - // U256::from_dec_str("19903885251949679146607224162906437591286076549652044731739108226015926915860").unwrap(), - // U256::from_dec_str("11870922578907159231760438847634888925027596611865086487008358810346509550746").unwrap(), - // ], - // vec![ - // vec![ - // U256::from_dec_str("7572350741301793140585595336451242554319145556316993930579910816773197602180").unwrap(), - // U256::from_dec_str("16166630091911008518878343585755669995589761813810965163203815419554661335912").unwrap(), - // ], - // vec![ - // U256::from_dec_str("10479558631339350148140324543423297113164179377516410954282474094862685762111").unwrap(), - // U256::from_dec_str("1538599836393367534859442557225095989831507256094436416355361165563840234277").unwrap(), - // ], - // ], - // vec![ - // U256::from_dec_str("18566368172831132986640612657510108843544042128267080758083569019690510537842").unwrap(), - // U256::from_dec_str("14637144036179606956000163117625168358523245864386632910728645092984303842870").unwrap(), - // ] - // ); - - // let vk = VerifyingKeyComponents::new( - // vec![ - // U256::from_dec_str("3388366987275268645608688601800038483480506575351380219459271970783548315310").unwrap(), - // U256::from_dec_str("10139982329791419477606385196757134153200700293861474061701578521738893563314").unwrap(), - // ], - // vec![ - // vec![ - // U256::from_dec_str("17293003127353596916845398615566872053529832484770184120881889494052646686398").unwrap(), - // U256::from_dec_str("3746742577904007471872553744363212404516454459540143078991207693255568088158").unwrap(), - // ], - // vec![ - // U256::from_dec_str("18996426015092705424501193523094438770040629737761363033585766320236602756452").unwrap(), - // U256::from_dec_str("5993252813486169444483155589566709251331252167093428959716521680127596688663").unwrap(), - // ], - // ], - // vec![ - // vec![ - // U256::from_dec_str("86221489590459042456285770827248107701675460052532768290239949641616327672").unwrap(), - // U256::from_dec_str("21618235778373592971185937996314200926578828337383413751502402964191761009384").unwrap(), - // ], - // vec![ - // U256::from_dec_str("10453895050472290645179709462208119639593757329666114205922088367970822668124").unwrap(), - // U256::from_dec_str("16924749634830145681809164670725933237166438445526123149706427927968513710893").unwrap(), - // ], - // ], - // vec![ - // vec![ - // U256::from_dec_str("20506347836984398194650179863264269358088067779451739307543701941138658771117").unwrap(), - // U256::from_dec_str("15256122081275324863091225387225218399888282841698960666742408225921079848693").unwrap(), - // ], - // vec![ - // U256::from_dec_str("7881380592415293900063452944037916715621668238658562838630198037249553436647").unwrap(), - // U256::from_dec_str("6003465274284900873747728448177380007802003937728590930467990944623586277089").unwrap(), - // ] - // ], - // vec![ - // vec![ - // U256::from_dec_str("5531662187275540864474040102019845108669876235687831703751327129559212127084").unwrap(), - // U256::from_dec_str("11455786949456856409363436892267690994602451302132959153447251790964376014822").unwrap(), - // ], - // vec![ - // U256::from_dec_str("17221728819314881853232886080533000381382340762620795831983019279828981481257").unwrap(), - // U256::from_dec_str("19341881794793455210912817199750586531241336493382870655971958667936340901503").unwrap(), - // ] - // ] - // ); - - // let valid_input: Vec = vec![u64s_to_u256(vec![ - // 17510768071209558285, - // 11281672863963944712, - // 17936011136389338927, - // 2683423138755332222, - // ])]; - - // let verifying_key = VerifyingKey::new(proof, vk, valid_input); - - // let zk_verifier = ZKPrecompileVerifier::new( - // H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), - // verifying_key - // ); - - // let encoded_call = zk_verifier.generate_benchmarking_parameters(); - - // let gas_limit_call = 1000000; - // let value = U256::default(); - // let is_transactional = true; - // let validate = true; - // }:{ - // let call_runner_results = ::Runner::call( - // caller, - // contract_address, - // encoded_call, - // value, - // gas_limit_call, - // Some(U256::from(1_000_000_000)), - // Some(U256::from(1_000_000_000)), - // None, - // Vec::new(), - // is_transactional, - // validate, - // ::config(), - // ); - // // log::info!( - // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // // "Benchmarking call end.", - // // ); - // match call_runner_results { - // Ok(info) => { - // let output = info.value; - // // log::info!( - // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // // "output result {:?}", - // // output - // // ); - // if output.len() >= 32 { - // let mut result_bytes = [0u8; 32]; - // result_bytes.copy_from_slice(&output[output.len() - 32..]); - // let result = U256::from_big_endian(&result_bytes); - // // log::info!( - // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // // "nconstraints_30_input_200000 Verification result {result:?}", - // // ); - // assert_eq!(result, U256::one(), "The contract did not return true"); - // } - // }, - // Err(e) => { - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "nconstraints_30_input_200000 Benchmarking failed", - // ); - // assert!(false, "Benchmarking failed"); - // } - // } - // } - - // sum_10 { - // use frame_benchmarking::vec; - // use sp_core::{H160, U256, H256}; - - // let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); - // let contract_address = H160::from_low_u64_be(0x8888); - - // let proof = Proof::new( - // vec![ - // U256::from_dec_str("4479438672593572194843316486259284641920166054544576564310150763796220593742").unwrap(), - // U256::from_dec_str("5717857931841301866217201485541887040818093727574311517591849036289507799141").unwrap(), - // ], - // vec![ - // vec![ - // U256::from_dec_str("438102211713357984070931589322877643391719193099221891191956755149301376056").unwrap(), - // U256::from_dec_str("14696299438400225528910058565202329177181471318954607581306780544413371767738").unwrap(), - // ], - // vec![ - // U256::from_dec_str("18723112929967827488252389384208353884816003870032279933823625467146809072448").unwrap(), - // U256::from_dec_str("781225142569358922067919798403956593420009838230922093237868933021043854113").unwrap(), - // ], - // ], - // vec![ - // U256::from_dec_str("10481213903673023503381125372528754955378591812884098928519623211332171467098").unwrap(), - // U256::from_dec_str("15098195705682978185145469811146985310923026878303775073727891846327587112885").unwrap(), - // ] - // ); - - // let vk = VerifyingKeyComponents::new( - // vec![ - // U256::from_dec_str("10600514820627226711889163536575359330497844540484876797299835164575096986123").unwrap(), - // U256::from_dec_str("8955505242614929800342716899005854501255692108538633212406728467939250778259").unwrap(), - // ], - // vec![ - // vec![ - // U256::from_dec_str("11358515176167160981846987587695931342878788452018419590778128561277894807040").unwrap(), - // U256::from_dec_str("7367100375568995524851051084377016949291621141008718892167611998460177966556").unwrap(), - // ], - // vec![ - // U256::from_dec_str("9986374126991936592889887298811366506288970021158383914729072242552712258999").unwrap(), - // U256::from_dec_str("5917047061876555575617149777207682047359711575786648519096749890796145313142").unwrap(), - // ], - // ], - // vec![ - // vec![ - // U256::from_dec_str("12470512550870605078154922234115021580073605821744497867586706681115325377951").unwrap(), - // U256::from_dec_str("3964373607930903502336465614571930627592350216968107805643078708599943392195").unwrap(), - // ], - // vec![ - // U256::from_dec_str("9054619931591683490625148848351137928205510101241639415537408964292455344707").unwrap(), - // U256::from_dec_str("14433710971468466044075036729227299898791551573181475688890434779549865103322").unwrap(), - // ] - // ], - // vec![ - // vec![ - // U256::from_dec_str("13008751738470482081156013535203222043379316308698376931322848604706786065862").unwrap(), - // U256::from_dec_str("3415558414191757405655644967374577939532374518318643852418890898323033638525").unwrap(), - // ], - // vec![ - // U256::from_dec_str("2104722493853714523712648261788727756558190509825976396834309269877977849365").unwrap(), - // U256::from_dec_str("6877732520157662584755946842350755740172704606349660337522459938993730313391").unwrap(), - // ], - // ], - // vec![ - // vec![ - // U256::from_dec_str("17691779713798847872985546462247707503645016076661816616388979822201176829753").unwrap(), - // U256::from_dec_str("14451231434311244057691431183198403713720423327382654964068207207079455187712").unwrap(), - // ], - // vec![ - // U256::from_dec_str("13620414910695185146987530463229819484652710069270717148541433045978322585419").unwrap(), - // U256::from_dec_str("10875872907505029426874795808985164080699672034676409959252328566889297105865").unwrap(), - // ] - // ] - // ); - - // let valid_input = vec![ - // U256::from_dec_str("55").unwrap() - // ]; - - // let verifying_key = VerifyingKey::new(proof, vk, valid_input); - - // let zk_verifier = ZKPrecompileVerifier::new( - // H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), - // verifying_key - // ); - - // let encoded_call = zk_verifier.generate_benchmarking_parameters(); - - // let gas_limit_call = 1000000; - // let value = U256::default(); - // let is_transactional = true; - // let validate = true; - // }:{ - // let call_runner_results = ::Runner::call( - // caller, - // contract_address, - // encoded_call, - // value, - // gas_limit_call, - // Some(U256::from(1_000_000_000)), - // Some(U256::from(1_000_000_000)), - // None, - // Vec::new(), - // is_transactional, - // validate, - // ::config(), - // ); - // // log::info!( - // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // // "Benchmarking call end.", - // // ); - // match call_runner_results { - // Ok(info) => { - // let output = info.value; - // // log::info!( - // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // // "output result {:?}", - // // output - // // ); - // if output.len() >= 32 { - // let mut result_bytes = [0u8; 32]; - // result_bytes.copy_from_slice(&output[output.len() - 32..]); - // let result = U256::from_big_endian(&result_bytes); - // // log::info!( - // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // // "sum_10 Verification result {result:?}", - // // ); - // assert_eq!(result, U256::one(), "The contract did not return true"); - // } - // }, - // Err(e) => { - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "sum_10Benchmarking failed", - // ); - // assert!(false, "Benchmarking failed"); - // } - // } - // } - // sum_50 { - // use frame_benchmarking::vec; - // use sp_core::{H160, U256, H256}; - - // let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); - // let contract_address = H160::from_low_u64_be(0x8888); - - // let proof = Proof::new( - // vec![ - // U256::from_dec_str("3114941071688532747454764921300681791980888248199392522675009157778549895455").unwrap(), - // U256::from_dec_str("6816680925124829082835883802586391663161606011222680818599486084577544527516").unwrap(), - // ], - // vec![ - // vec![ - // U256::from_dec_str("15037393792780247314317740287895838240941967969445981241792818111317913065010").unwrap(), - // U256::from_dec_str("3834028682995799272226496422556310257938795862629020590068471611902272764146").unwrap(), - // ], - // vec![ - // U256::from_dec_str("4023883034822047449129381158539093978377425715903419218696272130851521242085").unwrap(), - // U256::from_dec_str("13058906875228264286034925941047330220503025517973111955115072416984072943122").unwrap(), - // ], - // ], - // vec![ - // U256::from_dec_str("5344888056894889487007260648469199417556856955544355154291642477677322944786").unwrap(), - // U256::from_dec_str("19843194668352645797068691966948915569058668700830773246420232986019393210063").unwrap(), - // ] - // ); - - // let vk = VerifyingKeyComponents::new( - // vec![ - // U256::from_dec_str("19257923683733118221652593587810195852599358412856281104090957905722976964370").unwrap(), - // U256::from_dec_str("19519729727735873999148754136012144616045305047716967685280834855818506563720").unwrap(), - // ], - // vec![ - // vec![ - // U256::from_dec_str("4418606700813566482216037680863387214037640478555893901955308344977554198718").unwrap(), - // U256::from_dec_str("18046767849922558936185002168253454007598159984067380537392936220227127228867").unwrap(), - // ], - // vec![ - // U256::from_dec_str("100725403545603844224319783153051757027683253433977048289134569498829183303").unwrap(), - // U256::from_dec_str("9785321212288652698655727476617710557399711491394256119637648908536562741634").unwrap(), - // ], - // ], - // vec![ - // vec![ - // U256::from_dec_str("7184324332054694882815451883063466258810341506246659357034202660488015984306").unwrap(), - // U256::from_dec_str("14398081398842334723334363407187040569418119441776629783632309768037771007327").unwrap(), - // ], - // vec![ - // U256::from_dec_str("17277213124622419955089087696435667358779233792945822269342368397066818801481").unwrap(), - // U256::from_dec_str("19811781065417531456401229702422997450338397507283920558741452740912313583930").unwrap(), - // ] - // ], - // vec![ - // vec![ - // U256::from_dec_str("1627724482578854283892192357407161928314687375966263116172485631707694669812").unwrap(), - // U256::from_dec_str("6839802000376483025048211234449253336394632788399066904541666906747650234382").unwrap(), - // ], - // vec![ - // U256::from_dec_str("17974577137954059751166162247265070307968439813726452160113109110701162631938").unwrap(), - // U256::from_dec_str("21289972529626386698860098501676961527414208445147370800462053148477683157991").unwrap(), - // ], - // ], - // vec![ - // vec![ - // U256::from_dec_str("20284064245383237908740484779775789109386762825985839657586769414934584661714").unwrap(), - // U256::from_dec_str("17363934481847560975462360104367791101351872886050159351690589725380050257409").unwrap(), - // ], - // vec![ - // U256::from_dec_str("3904403738619431633601997032597659843284744078768864151280168218762434423692").unwrap(), - // U256::from_dec_str("4413868989856264583489102855186788724178233679332360263809134874064797750675").unwrap(), - // ] - // ] - // ); - - // let valid_input = vec![ - // U256::from_dec_str("1275").unwrap(), - // ]; - - // let verifying_key = VerifyingKey::new(proof, vk, valid_input); - - // let zk_verifier = ZKPrecompileVerifier::new( - // H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), - // verifying_key - // ); - - // let encoded_call = zk_verifier.generate_benchmarking_parameters(); - - // let gas_limit_call = 1000000; - // let value = U256::default(); - // let is_transactional = true; - // let validate = true; - // }:{ - // let call_runner_results = ::Runner::call( - // caller, - // contract_address, - // encoded_call, - // value, - // gas_limit_call, - // Some(U256::from(1_000_000_000)), - // Some(U256::from(1_000_000_000)), - // None, - // Vec::new(), - // is_transactional, - // validate, - // ::config(), - // ); - // // log::info!( - // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // // "Benchmarking call end.", - // // ); - // match call_runner_results { - // Ok(info) => { - // let output = info.value; - // // log::info!( - // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // // "output result {:?}", - // // output - // // ); - // if output.len() >= 32 { - // let mut result_bytes = [0u8; 32]; - // result_bytes.copy_from_slice(&output[output.len() - 32..]); - // let result = U256::from_big_endian(&result_bytes); - // // log::info!( - // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // // "sum_50 Verification result {result:?}", - // // ); - // assert_eq!(result, U256::one(), "The contract did not return true"); - // } - // }, - // Err(e) => { - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "sum_50 Benchmarking failed", - // ); - // assert!(false, "Benchmarking failed"); - // } - // } - // } - - // sum_5000 { - // use frame_benchmarking::vec; - // use sp_core::{H160, U256, H256}; - - // let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); - // let contract_address = H160::from_low_u64_be(0x8888); - - // let proof = Proof::new( - // vec![ - // U256::from_dec_str("2104134032972066019913571175532882184351637942839921828138208604817397790978").unwrap(), - // U256::from_dec_str("12625149522977248086293073767826715132905823679345516244316272790389621024575").unwrap(), - // ], - // vec![ - // vec![ - // U256::from_dec_str("18955718237898317556602416465218566057031982163829528123671300051574728240883").unwrap(), - // U256::from_dec_str("18075306515520608621953959878874546391551215874677138383864573851396832159644").unwrap(), - // ], - // vec![ - // U256::from_dec_str("3166476742865671627115278436666969186969644878053983393309132722947819232105").unwrap(), - // U256::from_dec_str("8051049247607109861344268872842958063551670273736053865524986958976361214062").unwrap(), - // ], - // ], - // vec![ - // U256::from_dec_str("4814291763265323888812051590287571407031542635142019809665068757723218701627").unwrap(), - // U256::from_dec_str("17930948070313125851452005455953009375012074818817251382455220462443054837203").unwrap(), - // ] - // ); - - // let vk = VerifyingKeyComponents::new( - // vec![ - // U256::from_dec_str("19624232987744880202266197753309961915632611879850947888541508003701736644214").unwrap(), - // U256::from_dec_str("5019843555387010050200067558096501184079196549422645876015184268981691000261").unwrap(), - // ], - // vec![ - // vec![ - // U256::from_dec_str("5150307298606577026396875555180704696345763655981810466632357002439129266461").unwrap(), - // U256::from_dec_str("3020656302335648031712857271727816386298675153130933709481311850060508289333").unwrap(), - // ], - // vec![ - // U256::from_dec_str("19547576195358452722114991449875886954598568010341500952076854329553571219720").unwrap(), - // U256::from_dec_str("3895331072082263654317901227968966808293407907751128382134753194859731114729").unwrap(), - // ], - // ], - // vec![ - // vec![ - // U256::from_dec_str("5792479463369352075979003547777370241697788651005116088867026457677720533395").unwrap(), - // U256::from_dec_str("16882159064341957118950974052606760693554763076237663579029547802558086431378").unwrap(), - // ], - // vec![ - // U256::from_dec_str("15201299876801474331768851307298179430198466709727112330042020251492139993850").unwrap(), - // U256::from_dec_str("893863620414771464835789333501093176356026692988850717670551586498757709875").unwrap(), - // ] - // ], - // vec![ - // vec![ - // U256::from_dec_str("165136411129701665870237237981894748637834826722462614973940945603783242464").unwrap(), - // U256::from_dec_str("10766657827945181878791518932726777890925519579254084496220957371082172349194").unwrap(), - // ], - // vec![ - // U256::from_dec_str("1813485593016293809685571822392302147347136682526622353828238069063634409991").unwrap(), - // U256::from_dec_str("12730118542350484957903782401323352413406115135420607527656226977122246298735").unwrap(), - // ], - // ], - // vec![ - // vec![ - // U256::from_dec_str("19450458898299554306247087083239008884256452312356497246598109368644839627523").unwrap(), - // U256::from_dec_str("123992241310851816418828784530061727329258706748227789362318537744292975333").unwrap(), - // ], - // vec![ - // U256::from_dec_str("1650700423026830428199086201346242616543834285406293983963791012821269466913").unwrap(), - // U256::from_dec_str("3152920600939501404817148774751227981988970987313622659392580888754616114976").unwrap(), - // ] - // ] - // ); - - // let valid_input = vec![ - // U256::from_dec_str("12502500").unwrap(), - // ]; - - // let verifying_key = VerifyingKey::new(proof, vk, valid_input); - - // let zk_verifier = ZKPrecompileVerifier::new( - // H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), - // verifying_key - // ); - - // let encoded_call = zk_verifier.generate_benchmarking_parameters(); - - // let gas_limit_call = 1000000; - // let value = U256::default(); - // let is_transactional = true; - // let validate = true; - // }:{ - // let call_runner_results = ::Runner::call( - // caller, - // contract_address, - // encoded_call, - // value, - // gas_limit_call, - // Some(U256::from(1_000_000_000)), - // Some(U256::from(1_000_000_000)), - // None, - // Vec::new(), - // is_transactional, - // validate, - // ::config(), - // ); - // // log::info!( - // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // // "Benchmarking call end.", - // // ); - // match call_runner_results { - // Ok(info) => { - // let output = info.value; - // // log::info!( - // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // // "output result {:?}", - // // output - // // ); - // if output.len() >= 32 { - // let mut result_bytes = [0u8; 32]; - // result_bytes.copy_from_slice(&output[output.len() - 32..]); - // let result = U256::from_big_endian(&result_bytes); - // // log::info!( - // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // // "sum_5000 Verification result {result:?}", - // // ); - // assert_eq!(result, U256::one(), "The contract did not return true"); - // } - // }, - // Err(e) => { - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "sum_5000 Benchmarking failed", - // ); - // assert!(false, "Benchmarking failed"); - // } - // } - // } - - // sum_50000 { - // use frame_benchmarking::vec; - // use sp_core::{H160, U256, H256}; - - // let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); - // let contract_address = H160::from_low_u64_be(0x8888); - - // let proof = Proof::new( - // vec![ - // U256::from_dec_str("10521560297681522924956535552101557954055377883537271587209095331672512231293").unwrap(), - // U256::from_dec_str("3686654512637749683446869119197341068039068905923579159423036344564025864377").unwrap(), - // ], - // vec![ - // vec![ - // U256::from_dec_str("4890395955490088627121586512165392468998481877071173820388882318632254821251").unwrap(), - // U256::from_dec_str("9885243823600363166628220433820250724586324090253611358758770212725684204135").unwrap(), - // ], - // vec![ - // U256::from_dec_str("9651185291553128823215307092565172143818838202635271809942597163630971976482").unwrap(), - // U256::from_dec_str("7457264071531012293581639749136580536924886204589417402009399054127419592993").unwrap(), - // ], - // ], - // vec![ - // U256::from_dec_str("2627345354605748142976160304028628661480987375506843588233396593542954599122").unwrap(), - // U256::from_dec_str("8681729968580301984067665769277363721394455178806371130831646417737890294377").unwrap(), - // ] - // ); - - // let vk = VerifyingKeyComponents::new( - // vec![ - // U256::from_dec_str("7421321362170719195081023585470135389432297716397232604489422086989398701183").unwrap(), - // U256::from_dec_str("4072026971341416803293623026670767879574289631340879941991921870784524426920").unwrap(), - // ], - // vec![ - // vec![ - // U256::from_dec_str("2973474839676012411019522612887674225146102238495561333683790233803898072056").unwrap(), - // U256::from_dec_str("4756088420398356546587372215087817373004751038308642279979561650652947628544").unwrap(), - // ], - // vec![ - // U256::from_dec_str("18134483811751652906456539288278265005968212485396038963550793901997203165973").unwrap(), - // U256::from_dec_str("19733531274857979315351276512779996430041767061694237978460875113100798536651").unwrap(), - // ], - // ], - // vec![ - // vec![ - // U256::from_dec_str("1470135418689977789083190292952479192678178451735632796795673595352524120366").unwrap(), - // U256::from_dec_str("5512330648930976997879473235916847191061423400686751865867764833860608466852").unwrap(), - // ], - // vec![ - // U256::from_dec_str("8727385532414213805687214017949229267547242769169729533774216518510791901252").unwrap(), - // U256::from_dec_str("6002526157648728322271067956991922780742552704883496238917574496345518669191").unwrap(), - // ] - // ], - // vec![ - // vec![ - // U256::from_dec_str("20953112965721952332699311075873353918826966291896395544882354080425788226212").unwrap(), - // U256::from_dec_str("9244986330211753947979669564454335484807935852348100319901614192766392809174").unwrap(), - // ], - // vec![ - // U256::from_dec_str("14633091132354386243825187195737842488061561784614981035737595152471541943810").unwrap(), - // U256::from_dec_str("18226447293937452659919522397971158104569327938800893595903771586125572293911").unwrap(), - // ], - // ], - // vec![ - // vec![ - // U256::from_dec_str("12814717307556312189651039282215441805578074271611267777533714458773278844960").unwrap(), - // U256::from_dec_str("7186820657304904476047212967487229874520184333187156276378594443001564484591").unwrap(), - // ], - // vec![ - // U256::from_dec_str("555198418426478766253895845611805598077310216839822834188225932135183360314").unwrap(), - // U256::from_dec_str("13253206399154373951823381980703846825450333469684895600618793136364702673992").unwrap(), - // ] - // ] - // ); - - // let valid_input = vec![U256::from_dec_str("1250025000").unwrap()]; - - // let verifying_key = VerifyingKey::new(proof, vk, valid_input); - - // let zk_verifier = ZKPrecompileVerifier::new( - // H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), - // verifying_key - // ); - - // let encoded_call = zk_verifier.generate_benchmarking_parameters(); - - // let gas_limit_call = 1000000; - // let value = U256::default(); - // let is_transactional = true; - // let validate = true; - // }:{ - // let call_runner_results = ::Runner::call( - // caller, - // contract_address, - // encoded_call, - // value, - // gas_limit_call, - // Some(U256::from(1_000_000_000)), - // Some(U256::from(1_000_000_000)), - // None, - // Vec::new(), - // is_transactional, - // validate, - // ::config(), - // ); - // // log::info!( - // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // // "Benchmarking call end.", - // // ); - // match call_runner_results { - // Ok(info) => { - // let output = info.value; - // // log::info!( - // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // // "output result {:?}", - // // output - // // ); - // if output.len() >= 32 { - // let mut result_bytes = [0u8; 32]; - // result_bytes.copy_from_slice(&output[output.len() - 32..]); - // let result = U256::from_big_endian(&result_bytes); - // // log::info!( - // // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // // "sum_50000 Verification result {result:?}", - // // ); - // assert_eq!(result, U256::one(), "The contract did not return true"); - // } - // }, - // Err(e) => { - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "sum_50000 Benchmarking failed", - // ); - // assert!(false, "Benchmarking failed"); - // } - // } - // } + nconstraints_10 { + use frame_benchmarking::vec; + use sp_core::{H160, U256, H256}; + + let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + let contract_address = H160::from_low_u64_be(0x8888); + + let proof = Proof::new( + vec![ + U256::from_dec_str("323654832133639084097738656057999026789295280666886852594984576709163539526").unwrap(), + U256::from_dec_str("6142957218280645039826855630872622613337777761157366378615236951849913775542").unwrap() + ], + vec![ + vec![ + U256::from_dec_str("3781402603457401622553078625624300084337446058890012151530042647448923283156").unwrap(), + U256::from_dec_str("3517436796495769146106898128956048233729888622957356948216773257280783319311").unwrap() + ], + vec![ + U256::from_dec_str("18697717875318192535466611481750571094853863458428844875498420533596881568336").unwrap(), + U256::from_dec_str("21426423909981695530725752097567643188095093768132522705564475372400085021436").unwrap() + ], + ], + vec![ + U256::from_dec_str("21613404883582191576526635676329374200679201344239432919502376530553941450391").unwrap(), + U256::from_dec_str("15157755445966041962464884593780030869511182260822371637833098723763718514455").unwrap() + ] + ); + + let vk = VerifyingKeyComponents::new( + vec![ + U256::from_dec_str("11521346682463921906610271064518766485088278761420928386309550940286650671457").unwrap(), + U256::from_dec_str("14352830518175561380348856554041231805603495989169432000725584250110291361678").unwrap() + ], + vec![ + vec![ + U256::from_dec_str("15782596638536803844844408481637582589736413871396993858917786753770876529739").unwrap(), + U256::from_dec_str("14911823231521430202833448929652297782496660742577343858219844871404504144036").unwrap() + ], + vec![ + U256::from_dec_str("2082222914940990020573243578958386229340150899029559516350605378857473031525").unwrap(), + U256::from_dec_str("13498996195230132373906915048494917069165130851394909752977335076805840989307").unwrap() + ], + ], + vec![ + vec![ + U256::from_dec_str("3598021131780341035246011324427156192540414244243113294885735792953741606880").unwrap(), + U256::from_dec_str("2036084172531515709709771052774738245922046202318890723044728246225539963428").unwrap() + ], + vec![ + U256::from_dec_str("5925457711548235099025126547368719549508643015841982506039250719340224619945").unwrap(), + U256::from_dec_str("6297446610567432982066083461547400065680646594595441716191878482607632761242").unwrap() + ], + ], + vec![ + vec![ + U256::from_dec_str("8540596677770285018018336727251534074846909511956041125063939097422779191925").unwrap(), + U256::from_dec_str("4004145476643750015352094786522189637304633549022019774555222068038038169997").unwrap() + ], + vec![ + U256::from_dec_str("14044576757821380530542904664046256148829410228513509672845139471539338485558").unwrap(), + U256::from_dec_str("21655834928283484760531472827487408029775629615266614212974138202212982461041").unwrap() + ] + ], + vec![ + vec![ + U256::from_dec_str("18160015955331442477546361309657533914485780296451278252095683998154112390415").unwrap(), + U256::from_dec_str("2421052745427024367257863480713357899822722660532800486395996070904226714086").unwrap() + ], + vec![ + U256::from_dec_str("13418845437340247256566377432948869602549774753220761674399899795516131627829").unwrap(), + U256::from_dec_str("19073971532401628571532840417056837528958340897410372352356543204393028153748").unwrap() + ] + ] + ); + + let valid_input: Vec = vec![u64s_to_u256(vec![ + 14965631224775206224, + 3021577815302938909, + 14359293880404272991, + 1555005537055779113 + ])]; + + let verifying_key = VerifyingKey::new(proof, vk, valid_input); + + let zk_verifier = ZKPrecompileVerifier::new( + H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), + verifying_key + ); + + let encoded_call = zk_verifier.generate_benchmarking_parameters(); + + let gas_limit_call = 1000000; + let value = U256::default(); + let is_transactional = true; + let validate = true; + }:{ + let call_runner_results = ::Runner::call( + caller, + contract_address, + encoded_call, + value, + gas_limit_call, + Some(U256::from(1_000_000_000)), + Some(U256::from(1_000_000_000)), + None, + Vec::new(), + is_transactional, + validate, + ::config(), + ); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "Benchmarking call end.", + // ); + match call_runner_results { + Ok(info) => { + let output = info.value; + let used_gas = info.used_gas; + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "nconstraints_10 output result {:?} used_gas: {:?}", + output, + used_gas, + ); + if output.len() >= 32 { + let mut result_bytes = [0u8; 32]; + result_bytes.copy_from_slice(&output[output.len() - 32..]); + let result = U256::from_big_endian(&result_bytes); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "nconstraints_10 Verification result {result:?}", + // ); + assert_eq!(result, U256::one(), "The contract did not return true"); + } + }, + Err(e) => { + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "nconstraints_10 Benchmarking failed", + ); + assert!(false, "Benchmarking failed"); + + } + } + } + + nconstraints_50 { + use frame_benchmarking::vec; + use sp_core::{H160, U256, H256}; + + let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + let contract_address = H160::from_low_u64_be(0x8888); + + let proof = Proof::new( + vec![ + U256::from_dec_str("2903574088029507435491062627919627539459038881203099780902103872696986272650").unwrap(), + U256::from_dec_str("3875062839032259754068923295563862040166715100637843024855021734684308685930").unwrap(), + ], + vec![ + vec![ + U256::from_dec_str("5467576156112132028552287163049386912078800648727055176723583005212825192497").unwrap(), + U256::from_dec_str("14958898784032520052694892656913773236193256742890765604760593633503039104983").unwrap(), + ], + vec![ + U256::from_dec_str("5396143311660903133040196691443703988892234257628755380984718394981374344158").unwrap(), + U256::from_dec_str("8621644456104449033213297238562527153800159584768570376273022394943050969320").unwrap(), + ], + ], + vec![ + U256::from_dec_str("11879092906448699692394725971977132036554363118574468164770659810752018463948").unwrap(), + U256::from_dec_str("6829624468475499149259780051037762599455296300930683215687755977165243124154").unwrap(), + ] + ); + + let vk = VerifyingKeyComponents::new( + vec![ + U256::from_dec_str("12520775544030530008009522467466185193766786263812261579427634884004150619566").unwrap(), + U256::from_dec_str("5032545863820965741764073435262250124257467813113463153084126384917060899315").unwrap(), + ], + vec![ + vec![ + U256::from_dec_str("10017955328073015145877787608777450033090741247853140204265773706371885379542").unwrap(), + U256::from_dec_str("9658203662920649739629860626443008098625554125855709045942833415049413198251").unwrap(), + ], + vec![ + U256::from_dec_str("7602415148393817869205609282139785691690714005596249546125364310759985118071").unwrap(), + U256::from_dec_str("6621887421318408197643297351639235440436194355283660692959196816576578875866").unwrap(), + ], + ], + vec![ + vec![ + U256::from_dec_str("5311307398908794283615493653665859916837738758333406097237626345248614605789").unwrap(), + U256::from_dec_str("17876886843886949913975349493510247353159584223381019718903135647608874168034").unwrap(), + ], + vec![ + U256::from_dec_str("16871344858870476549165036353120397473700844904231047018564735968613233188965").unwrap(), + U256::from_dec_str("3780010632071163899826543545524090280002435997376718121100375224910528030644").unwrap(), + ], + ], + vec![ + vec![ + U256::from_dec_str("5274939476765287332787933848172441391963317633567336761478263433231602711901").unwrap(), + U256::from_dec_str("20318717968421229127062334564952813061229602553850186042308931686220563993985").unwrap(), + ], + vec![ + U256::from_dec_str("18867986549807700609691354300906273266753459571664361845748650324369589087167").unwrap(), + U256::from_dec_str("3462802759155100024118895949055238081126591020075851877084161838812514424801").unwrap(), + ] + ], + vec![ + vec![ + U256::from_dec_str("2073721309366561324099267234284336470258146869696430225377434175843251484752").unwrap(), + U256::from_dec_str("5562089018027206512286783868306950659834000523781522158661084193254167305831").unwrap(), + ], + vec![ + U256::from_dec_str("7633925392184781104787537197952383405066326059553608577981951477761067715424").unwrap(), + U256::from_dec_str("19510227686274170330355317434483857344641524658406254379151352263942714837771").unwrap(), + ] + ] + ); + + let valid_input: Vec = vec![u64s_to_u256(vec![ + 14754876691570659999, + 1449725765053302887, + 10573592104590215630, + 2031301759166401468 + ])]; + + let verifying_key = VerifyingKey::new(proof, vk, valid_input); + + let zk_verifier = ZKPrecompileVerifier::new( + H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), + verifying_key + ); + + let encoded_call = zk_verifier.generate_benchmarking_parameters(); + + let gas_limit_call = 1000000; + let value = U256::default(); + let is_transactional = true; + let validate = true; + }:{ + let call_runner_results = ::Runner::call( + caller, + contract_address, + encoded_call, + value, + gas_limit_call, + Some(U256::from(1_000_000_000)), + Some(U256::from(1_000_000_000)), + None, + Vec::new(), + is_transactional, + validate, + ::config(), + ); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "Benchmarking call end.", + // ); + match call_runner_results { + Ok(info) => { + let output = info.value; + let used_gas = info.used_gas; + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "nconstraints_50 output result {:?} used_gas: {:?}", + output, + used_gas, + ); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "output result {:?}", + // output + // ); + if output.len() >= 32 { + let mut result_bytes = [0u8; 32]; + result_bytes.copy_from_slice(&output[output.len() - 32..]); + let result = U256::from_big_endian(&result_bytes); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "nconstraints_50 Verification result {result:?}", + // ); + assert_eq!(result, U256::one(), "The contract did not return true"); + } + }, + Err(e) => { + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "nconstraints_50 Benchmarking failed", + ); + assert!(false, "Benchmarking failed"); + + } + } + } + + nconstraints_1000 { + use frame_benchmarking::vec; + use sp_core::{H160, U256, H256}; + + let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + let contract_address = H160::from_low_u64_be(0x8888); + + let proof = Proof::new( + vec![ + U256::from_dec_str("12451505848309631687252015279596976128225375079184616465869275088833975377438").unwrap(), + U256::from_dec_str("18028472547304696309803026581736164843724278168110632635282700219721294267849").unwrap(), + ], + vec![ + vec![ + U256::from_dec_str("724941625340075448308940885419778921267046089963198424690563710257350467820").unwrap(), + U256::from_dec_str("19418815036545241911278056687101064762643664412732993043969007894248087117385").unwrap(), + ], + vec![ + U256::from_dec_str("13249414494230793056410904135885722890271124096600389432878053498484425858770").unwrap(), + U256::from_dec_str("21762806144353143011028620465453743506764842517668851190776375592288870325215").unwrap(), + ], + ], + vec![ + U256::from_dec_str("9206867270262791130308246301015463866896172966002943363908694359851632501217").unwrap(), + U256::from_dec_str("13679683495177263967294831832954860495137891909047512983345948806664713075553").unwrap(), + ] + ); + + let vk = VerifyingKeyComponents::new( + vec![ + U256::from_dec_str("13896934827344718021853288836918374118104295193491067840322643424358899121542").unwrap(), + U256::from_dec_str("8854052944916041632001392967979629780372345382861670282089777314383817716115").unwrap(), + ], + vec![ + vec![ + U256::from_dec_str("3601177773308419037453361001975316835601350296485805323140167568598797930642").unwrap(), + U256::from_dec_str("48851914275316782871445347689531673984580545598074561513165366823294923594").unwrap(), + ], + vec![ + U256::from_dec_str("4538012201084519544875007504928553564968897773565284770715803834936680149613").unwrap(), + U256::from_dec_str("3155968616270588886660033728776257587454508333510911411658919790925259116614").unwrap(), + ], + ], + vec![ + vec![ + U256::from_dec_str("6521538659624675039700866061977650833785775087701556120926232218187885377774").unwrap(), + U256::from_dec_str("18707623749213430453109215145186606994638201653518117177006249287165414157706").unwrap(), + ], + vec![ + U256::from_dec_str("11743109857123024729794370527373948778820323338754388805090881243904381703330").unwrap(), + U256::from_dec_str("3577725017182890090279110701721773090147301853148322630192233820247926772155").unwrap(), + ], + ], + vec![ + vec![ + U256::from_dec_str("10697077492206594361644026971284249101590705030465491131467731100150008255694").unwrap(), + U256::from_dec_str("1114380532795466865933623446272212800793315337032855536172932313989250445726").unwrap(), + ], + vec![ + U256::from_dec_str("11747915450686416011932172170367549011245903715607283230565719536126230133873").unwrap(), + U256::from_dec_str("1877153534214274703747923906347594924169181268669702005894131954432202950068").unwrap(), + ] + ], + vec![ + vec![ + U256::from_dec_str("6294921440683861296812943370338888809368101163511446375226378176013676840633").unwrap(), + U256::from_dec_str("8766686502883018606879699065134987161183815270662618961653335871316040755302").unwrap(), + ], + vec![ + U256::from_dec_str("15422085976834841481597157129530660038025986735930069198619117556493669017719").unwrap(), + U256::from_dec_str("6824904336141021449652133306590775160232847673735850151493603664420102965477").unwrap(), + ] + ] + ); + + let valid_input: Vec = vec![u64s_to_u256(vec![ + 5637188163546619750, + 4876642863872575056, + 11311886144936918135, + 2620236256196171805 + ])]; + + let verifying_key = VerifyingKey::new(proof, vk, valid_input); + + let zk_verifier = ZKPrecompileVerifier::new( + H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), + verifying_key + ); + + let encoded_call = zk_verifier.generate_benchmarking_parameters(); + + let gas_limit_call = 1000000; + let value = U256::default(); + let is_transactional = true; + let validate = true; + }:{ + let call_runner_results = ::Runner::call( + caller, + contract_address, + encoded_call, + value, + gas_limit_call, + Some(U256::from(1_000_000_000)), + Some(U256::from(1_000_000_000)), + None, + Vec::new(), + is_transactional, + validate, + ::config(), + ); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "Benchmarking call end.", + // ); + match call_runner_results { + Ok(info) => { + let output = info.value; + let used_gas = info.used_gas; + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "nconstraints_1000 output result {:?} used_gas: {:?}", + output, + used_gas, + ); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "output result {:?}", + // output + // ); + if output.len() >= 32 { + let mut result_bytes = [0u8; 32]; + result_bytes.copy_from_slice(&output[output.len() - 32..]); + let result = U256::from_big_endian(&result_bytes); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "nconstraints_1000 Verification result {result:?}", + // ); + assert_eq!(result, U256::one(), "The contract did not return true"); + } + }, + Err(e) => { + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "nconstraints_1000 Benchmarking failed", + ); + assert!(false, "Benchmarking failed"); + + } + } + } + nconstraints_900000 { + use frame_benchmarking::vec; + use sp_core::{H160, U256, H256}; + + let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + let contract_address = H160::from_low_u64_be(0x8888); + + let proof = Proof::new( + vec![ + U256::from_dec_str("19469224081137364911375441935428613758543844094780123177610680784796374565509").unwrap(), + U256::from_dec_str("2964109100176825277964902990593130655404587548088911907169158668561756482373").unwrap(), + ], + vec![ + vec![ + U256::from_dec_str("1804788596044451078391485097362341934563024367189115611320140606169017734442").unwrap(), + U256::from_dec_str("13075356869764013404490647878715830765050556805353047586243641659166972614506").unwrap(), + ], + vec![ + U256::from_dec_str("11510752280195741101381678478126680255679095252133774347633523263393718090827").unwrap(), + U256::from_dec_str("19917734624109913540474402939707087760514256808495299709893660593520804971329").unwrap(), + ], + ], + vec![ + U256::from_dec_str("17650234014776935476405426867265189573543251264844619398004397025922351000524").unwrap(), + U256::from_dec_str("13980409623437481166079302794215538337078177634480935418093274323345259996058").unwrap(), + ] + ); + + let vk = VerifyingKeyComponents::new( + vec![ + U256::from_dec_str("7204013913559348808806179272679133668079798990573619252699122941477292720367").unwrap(), + U256::from_dec_str("14448814309541293146746525253301533902449817953703436076734477345366335651547").unwrap(), + ], + vec![ + vec![ + U256::from_dec_str("12755354931522455226769415963087662012592248962914015697167303994293035888664").unwrap(), + U256::from_dec_str("19979994508677160041392994419804596139216500302977150541381981675855322022114").unwrap(), + ], + vec![ + U256::from_dec_str("3518578052095992035034011768990132253597152650327354182069223777691356587613").unwrap(), + U256::from_dec_str("1512363495951297845516866605291301480678745477544041997800458458709067854003").unwrap(), + ], + ], + vec![ + vec![ + U256::from_dec_str("21483901865224554977407186643009006049964266844355020377697169106001216486465").unwrap(), + U256::from_dec_str("18122216236568402305988297032517775914181563813086813006164216689752246508886").unwrap(), + ], + vec![ + U256::from_dec_str("7100124544075226034251596932805277307734457677256004047412258693103409543678").unwrap(), + U256::from_dec_str("9484826513489508497326605298995346628011303684771342589708630141744196880174").unwrap(), + ], + ], + vec![ + vec![ + U256::from_dec_str("4294809674390523555755416088340227038268056188806697061914357207030835445784").unwrap(), + U256::from_dec_str("12772882987652274474928251216882135157601158713560023135442912416889883375009").unwrap(), + ], + vec![ + U256::from_dec_str("5017814360156811257431228283078380210712481496173867244303167538680301406355").unwrap(), + U256::from_dec_str("5483986251263351055676143301589669624262947345327185314870128974364440001262").unwrap(), + ] + ], + vec![ + vec![ + U256::from_dec_str("10485365056956235833573091505977794158366069646492853613385564319176805042067").unwrap(), + U256::from_dec_str("21560988819791135038184934219494970236802908435926324068683299817562907341696").unwrap(), + ], + vec![ + U256::from_dec_str("9274251274730510866039258353232655161206943117093211738883330925803202790098").unwrap(), + U256::from_dec_str("19994917632455570632082635510110118222993755636207706143729050502915579896735").unwrap(), + ] + ] + ); + + let valid_input: Vec = vec![u64s_to_u256(vec![ + 10518156496175725870, + 8513656267880232886, + 1469451646407182009, + 3425508166019525724 + ])]; + + let verifying_key = VerifyingKey::new(proof, vk, valid_input); + + let zk_verifier = ZKPrecompileVerifier::new( + H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), + verifying_key + ); + + let encoded_call = zk_verifier.generate_benchmarking_parameters(); + + let gas_limit_call = 1000000; + let value = U256::default(); + let is_transactional = true; + let validate = true; + }:{ + let call_runner_results = ::Runner::call( + caller, + contract_address, + encoded_call, + value, + gas_limit_call, + Some(U256::from(1_000_000_000)), + Some(U256::from(1_000_000_000)), + None, + Vec::new(), + is_transactional, + validate, + ::config(), + ); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "Benchmarking call end.", + // ); + match call_runner_results { + Ok(info) => { + let output = info.value; + let used_gas = info.used_gas; + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "nconstraints_900000 output result {:?} used_gas: {:?}", + output, + used_gas, + ); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "output result {:?}", + // output + // ); + if output.len() >= 32 { + let mut result_bytes = [0u8; 32]; + result_bytes.copy_from_slice(&output[output.len() - 32..]); + let result = U256::from_big_endian(&result_bytes); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "nconstraints_900000 Verification result {result:?}", + // ); + assert_eq!(result, U256::one(), "The contract did not return true"); + } + }, + Err(e) => { + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "nconstraints_900000 Benchmarking failed", + ); + assert!(false, "Benchmarking failed"); + + } + } + } + + nconstraints_30_input_10 { + use frame_benchmarking::vec; + use sp_core::{H160, U256, H256}; + + let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + let contract_address = H160::from_low_u64_be(0x8888); + + let proof = Proof::new( + vec![ + U256::from_dec_str("344113499780097036133410144688544669449665038469801025061703634064197059916").unwrap(), + U256::from_dec_str("8339013355837829034186604529242237434382457535922383671882155606562413431689").unwrap(), + ], + vec![ + vec![ + U256::from_dec_str("6694199005832176626648387473003377778002164049654344388623160500074797775370").unwrap(), + U256::from_dec_str("6246558478856965861562784864034844546822126660127014237507763330640717221466").unwrap(), + ], + vec![ + U256::from_dec_str("456859418727494804887897697519797382313397623366843307513728588676215628797").unwrap(), + U256::from_dec_str("19972929684979882956825623277042855987039264105600158828132263230333203670106").unwrap(), + ], + ], + vec![ + U256::from_dec_str("8991876521515422964548874095107781976525191569601242691722207742733698821028").unwrap(), + U256::from_dec_str("17304897036279645989594099459944208131107988079437513579584585106093260802053").unwrap(), + ] + ); + + let vk = VerifyingKeyComponents::new( + vec![ + U256::from_dec_str("16587578668155053320776501244706909164198053583863284386206654068019392556543").unwrap(), + U256::from_dec_str("17489859882312386925030082840618136961844042944104008122175974338708995824981").unwrap(), + ], + vec![ + vec![ + U256::from_dec_str("8243058085082563940310351321464397410632520885003827137093771369586433446018").unwrap(), + U256::from_dec_str("1806964369040712598415691188975966807767394918682209427183228092832571919497").unwrap(), + ], + vec![ + U256::from_dec_str("5238575049648595236335310308987023404502439315997088611926714272919127054029").unwrap(), + U256::from_dec_str("10529242360048105445622302340100671863366518517961350431989359465371013288044").unwrap(), + ], + ], + vec![ + vec![ + U256::from_dec_str("422118731661843716781379598081446048950684758761078928178953272944418614265").unwrap(), + U256::from_dec_str("8071137901873450516865398890359069534977349842235015782367912081100468370342").unwrap(), + ], + vec![ + U256::from_dec_str("6616051543776580097026224309598118359974125974677691608309070965923230091481").unwrap(), + U256::from_dec_str("3144026861846828201735234261898216197057552604232403108299101704912138104081").unwrap(), + ], + ], + vec![ + vec![ + U256::from_dec_str("15967728838725285670062386536689775286816477877862913251436519988213464788203").unwrap(), + U256::from_dec_str("14482652023948193853731701210376245407114581664800773915003137369238699817066").unwrap(), + ], + vec![ + U256::from_dec_str("20222564526826997580988353930405539667760709452060576182511364617433825375503").unwrap(), + U256::from_dec_str("1855904408322765948314758770516591135802311025429227172106073057339165107921").unwrap(), + ] + ], + vec![ + vec![ + U256::from_dec_str("2234398803815490360326379119253073021265347911436036657996997085101774002925").unwrap(), + U256::from_dec_str("10214773739303944856355679056757071889148916152665035343340628435407174724717").unwrap(), + ], + vec![ + U256::from_dec_str("21500623561133929663133180424780657403302270303706782392356903439186747104812").unwrap(), + U256::from_dec_str("19328419280811286038333929820672543691407985372391054082759992875889788951230").unwrap(), + ] + ] + ); + + let valid_input: Vec = vec![u64s_to_u256(vec![ + 14321691860995553260, + 7152862679273281751, + 12752615512303817990, + 1576113262537949146 + ])]; + + let verifying_key = VerifyingKey::new(proof, vk, valid_input); + + let zk_verifier = ZKPrecompileVerifier::new( + H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), + verifying_key + ); + + let encoded_call = zk_verifier.generate_benchmarking_parameters(); + + let gas_limit_call = 1000000; + let value = U256::default(); + let is_transactional = true; + let validate = true; + }:{ + let call_runner_results = ::Runner::call( + caller, + contract_address, + encoded_call, + value, + gas_limit_call, + Some(U256::from(1_000_000_000)), + Some(U256::from(1_000_000_000)), + None, + Vec::new(), + is_transactional, + validate, + ::config(), + ); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "Benchmarking call end.", + // ); + match call_runner_results { + Ok(info) => { + let output = info.value; + let used_gas = info.used_gas; + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "nconstraints_30_input_10 output result {:?} used_gas: {:?}", + output, + used_gas, + ); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "output result {:?}", + // output + // ); + if output.len() >= 32 { + let mut result_bytes = [0u8; 32]; + result_bytes.copy_from_slice(&output[output.len() - 32..]); + let result = U256::from_big_endian(&result_bytes); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "nconstraints_30_input_10 Verification result {result:?}", + // ); + assert_eq!(result, U256::one(), "The contract did not return true"); + } + }, + Err(e) => { + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "nconstraints_30_input_10 Benchmarking failed", + ); + assert!(false, "Benchmarking failed"); + + } + } + } + nconstraints_30_input_100 { + use frame_benchmarking::vec; + use sp_core::{H160, U256, H256}; + + let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + let contract_address = H160::from_low_u64_be(0x8888); + + let proof = Proof::new( + vec![ + U256::from_dec_str("3780487311936056381294564418675304364481973966802209296561160829797948105411").unwrap(), + U256::from_dec_str("12392254879980640223142009257910424254771509444451393927739643876401726307795").unwrap(), + ], + vec![ + vec![ + U256::from_dec_str("5169548117445173154024813698359426977000013771483410622256640533171985245380").unwrap(), + U256::from_dec_str("11220449603083268927036844276912830985523128428499468942581840512730495047625").unwrap(), + ], + vec![ + U256::from_dec_str("7617888807668014594076695037395251387521432502213194545531858961238344338860").unwrap(), + U256::from_dec_str("3206448605631210983027663221710912427383659852717855953276353488187250079459").unwrap(), + ], + ], + vec![ + U256::from_dec_str("17260938596020642923034443094579912726381749511890996943502017876149586484217").unwrap(), + U256::from_dec_str("973711408795313031099855712156150142641887502706075552254275664528776194028").unwrap(), + ] + ); + + let vk = VerifyingKeyComponents::new( + vec![ + U256::from_dec_str("4155898266631322214574856388057229131381603659142355428000239527171539910720").unwrap(), + U256::from_dec_str("15919304600573806746067202721026223664629992455130946331020176989460510062648").unwrap(), + ], + vec![ + vec![ + U256::from_dec_str("10559477888637541108523299513483158185288656601390229631277602982302056830264").unwrap(), + U256::from_dec_str("21518216923189214839507247102243744126930049565774641401859791113452178471842").unwrap(), + ], + vec![ + U256::from_dec_str("20524972206762616004058259260290957844870248494446046806278424843369643489182").unwrap(), + U256::from_dec_str("17430943082223119961631960086233630485654941075995072846024219998674392652581").unwrap(), + ], + ], + vec![ + vec![ + U256::from_dec_str("4636362103930283526843587215716464395878300635435610009766312980459671398351").unwrap(), + U256::from_dec_str("15713999866924132629927290621261290205960872899800820372400263081232019214301").unwrap(), + ], + vec![ + U256::from_dec_str("274224283373606674211197218239218941312046485596075799302472837928822177016").unwrap(), + U256::from_dec_str("10693491445395060496723678108216498586881120243971297703830999940561952271629").unwrap(), + ], + ], + vec![ + vec![ + U256::from_dec_str("9540601502504552621404908678855872975596983734893914263055690675850649191273").unwrap(), + U256::from_dec_str("10288168694112392204164781631687615725045294841966564539511156565183262528849").unwrap(), + ], + vec![ + U256::from_dec_str("16504160099082952601826232467479510151840980336862791499394346450083636791102").unwrap(), + U256::from_dec_str("9210167978306154509907086298616199856898787966613435045760659519455958969992").unwrap(), + ] + ], + vec![ + vec![ + U256::from_dec_str("15812098394101742886061540987450559986219804469912805896076341688421241661621").unwrap(), + U256::from_dec_str("11920211969663783445335622417572072568292106489672989284415235777753260953099").unwrap(), + ], + vec![ + U256::from_dec_str("7061409000327933635430701054193661775345794014516696263402966093123651666364").unwrap(), + U256::from_dec_str("17078047162776906089011285464212202278306676406084693061907121919624683442357").unwrap(), + ] + ] + ); + + let valid_input: Vec = vec![u64s_to_u256(vec![ + 9831528597301135316, + 11053911270256492840, + 14337707091878126846, + 772611368070892958 + ])]; + + let verifying_key = VerifyingKey::new(proof, vk, valid_input); + + let zk_verifier = ZKPrecompileVerifier::new( + H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), + verifying_key + ); + + let encoded_call = zk_verifier.generate_benchmarking_parameters(); + + let gas_limit_call = 1000000; + let value = U256::default(); + let is_transactional = true; + let validate = true; + }:{ + let call_runner_results = ::Runner::call( + caller, + contract_address, + encoded_call, + value, + gas_limit_call, + Some(U256::from(1_000_000_000)), + Some(U256::from(1_000_000_000)), + None, + Vec::new(), + is_transactional, + validate, + ::config(), + ); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "Benchmarking call end.", + // ); + match call_runner_results { + Ok(info) => { + let output = info.value; + let used_gas = info.used_gas; + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "nconstraints_30_input_100 output result {:?} used_gas: {:?}", + output, + used_gas, + ); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "output result {:?}", + // output + // ); + if output.len() >= 32 { + let mut result_bytes = [0u8; 32]; + result_bytes.copy_from_slice(&output[output.len() - 32..]); + let result = U256::from_big_endian(&result_bytes); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "nconstraints_30_input_100 Verification result {result:?}", + // ); + assert_eq!(result, U256::one(), "The contract did not return true"); + } + }, + Err(e) => { + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "nconstraints_30_input_100 Benchmarking failed", + ); + assert!(false, "Benchmarking failed"); + } + } + } + nconstraints_30_input_1000 { + use frame_benchmarking::vec; + use sp_core::{H160, U256, H256}; + + let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + let contract_address = H160::from_low_u64_be(0x8888); + + let proof = Proof::new( + vec![ + U256::from_dec_str("21424271595387505713049534900676381136649432939050012296331964885140120988520").unwrap(), + U256::from_dec_str("20488789316104689748479888121024139144355086386496471461763924485714534718686").unwrap(), + ], + vec![ + vec![ + U256::from_dec_str("8417699613540073682519718294821269056423071880647667978060348740795273915651").unwrap(), + U256::from_dec_str("4036859279888161250878359321718658739242283134835030699023268489309754993434").unwrap(), + ], + vec![ + U256::from_dec_str("16249800568747110450527363597274431407786919086057853194987169090454936230259").unwrap(), + U256::from_dec_str("15005851458712291005106538565823270955208428726378749297397203143137382225457").unwrap(), + ], + ], + vec![ + U256::from_dec_str("21239990703864671714190525785674088715931473556140655107585637961585812134589").unwrap(), + U256::from_dec_str("261928180985765917331919571442880380998408670702589931014636966043229919418").unwrap(), + ] + ); + + let vk = VerifyingKeyComponents::new( + vec![ + U256::from_dec_str("1657406292532781196449359079614579852690925607592278296574718289470803732053").unwrap(), + U256::from_dec_str("18213557747942747074556848145237207574111244905157024361329330629173034829885").unwrap(), + ], + vec![ + vec![ + U256::from_dec_str("5419856735820685908218319193906907396496344921642651266629131019868853843815").unwrap(), + U256::from_dec_str("14007905369450574044915098075029863272475910046750101274280969769181784166430").unwrap(), + ], + vec![ + U256::from_dec_str("182200131698860550444455761364918630551676350878779858078817264277300629723").unwrap(), + U256::from_dec_str("6050431818377820601319883600432739448105157482353041283628740094609821419656").unwrap(), + ], + ], + vec![ + vec![ + U256::from_dec_str("14463567879100083166257564330995533094334991709675023767975192973144798919122").unwrap(), + U256::from_dec_str("6166287541473141918830331239835928582190744434356526822227225877844349692203").unwrap(), + ], + vec![ + U256::from_dec_str("12512843744533735346513506961399336936527367720771340395643503621530703342395").unwrap(), + U256::from_dec_str("8394818975982736201521422268641084055810886358791398607930311472872317386487").unwrap(), + ], + ], + vec![ + vec![ + U256::from_dec_str("8757732756289429354419510422628896433407345473998310348115924113882282945326").unwrap(), + U256::from_dec_str("1610185885725147927651201796201713521257480620743342969197368887869230657180").unwrap(), + ], + vec![ + U256::from_dec_str("2834338214415807920713929739507915327763263469562351781747229949754640383374").unwrap(), + U256::from_dec_str("20761263923134391843554423575366232120525285729512411038267095810712916924016").unwrap(), + ] + ], + vec![ + vec![ + U256::from_dec_str("16585432354609922217222548226453277630464695131710476183479619760311567992522").unwrap(), + U256::from_dec_str("5379258900528839934525784961038010961454863754298062530193947624450477797122").unwrap(), + ], + vec![ + U256::from_dec_str("16825349369326282879106301528709807467071985531593215317852699692046311881677").unwrap(), + U256::from_dec_str("10540450379202726868409867306854114915477889581096312866635875249145708179576").unwrap(), + ] + ] + ); + + let valid_input: Vec = vec![u64s_to_u256(vec![ + 3008789406746563016, + 7061370202899273426, + 2191755323004339933, + 1005591455220622530 + ])]; + + let verifying_key = VerifyingKey::new(proof, vk, valid_input); + + let zk_verifier = ZKPrecompileVerifier::new( + H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), + verifying_key + ); + + let encoded_call = zk_verifier.generate_benchmarking_parameters(); + + let gas_limit_call = 1000000; + let value = U256::default(); + let is_transactional = true; + let validate = true; + }:{ + let call_runner_results = ::Runner::call( + caller, + contract_address, + encoded_call, + value, + gas_limit_call, + Some(U256::from(1_000_000_000)), + Some(U256::from(1_000_000_000)), + None, + Vec::new(), + is_transactional, + validate, + ::config(), + ); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "Benchmarking call end.", + // ); + match call_runner_results { + Ok(info) => { + let output = info.value; + let used_gas = info.used_gas; + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "nconstraints_30_input_1000 output result {:?} used_gas: {:?}", + output, + used_gas, + ); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "output result {:?}", + // output + // ); + if output.len() >= 32 { + let mut result_bytes = [0u8; 32]; + result_bytes.copy_from_slice(&output[output.len() - 32..]); + let result = U256::from_big_endian(&result_bytes); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "nconstraints_30_input_1000 Verification result {result:?}", + // ); + assert_eq!(result, U256::one(), "The contract did not return true"); + } + }, + Err(e) => { + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "nconstraints_30_input_1000 Benchmarking failed", + ); + assert!(false, "Benchmarking failed"); + } + } + } + nconstraints_30_input_5000 { + use frame_benchmarking::vec; + use sp_core::{H160, U256, H256}; + + let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + let contract_address = H160::from_low_u64_be(0x8888); + + let proof = Proof::new( + vec![ + U256::from_dec_str("4760178114933307527976205229418881302833473087272893863010681924222436742436").unwrap(), + U256::from_dec_str("6555056836023646163359279772724076765411780318148657506988760187885700674215").unwrap(), + ], + vec![ + vec![ + U256::from_dec_str("9540205596737585525189386078607957630969059503165883907845238817662495399607").unwrap(), + U256::from_dec_str("21777913747079267536001051597001736802905779914683258171463923506869689358122").unwrap(), + ], + vec![ + U256::from_dec_str("7652162643714058076103867092157642519402862581818067281609790687905833151647").unwrap(), + U256::from_dec_str("5174136241284192352871549806655421810249317805219641765935618077180420544939").unwrap(), + ], + ], + vec![ + U256::from_dec_str("9633653417112713107386510132385608824105920168790226750481878454006412372444").unwrap(), + U256::from_dec_str("5600932933208824148570351176368803282808856587672889614186338874655752173453").unwrap(), + ] + ); + + let vk = VerifyingKeyComponents::new( + vec![ + U256::from_dec_str("20563201722283471489193032980811350162387466733119686723832100493505332037220").unwrap(), + U256::from_dec_str("458683337854426284881131074995322438618437423037306322290239745015633774839").unwrap(), + ], + vec![ + vec![ + U256::from_dec_str("802687519037697530569139206036966996588449135138601551566343295868421688400").unwrap(), + U256::from_dec_str("10902489968444563758310974921240106861656913905085710523025258522577834664814").unwrap(), + ], + vec![ + U256::from_dec_str("8163282908300075270434111132545381898266738500810094061899946027883982232155").unwrap(), + U256::from_dec_str("2879234862354419255322548813414679750617024208122660306082351289172177493856").unwrap(), + ], + ], + vec![ + vec![ + U256::from_dec_str("12946416399098615767859440028401625777970463338055590127763655113029764523456").unwrap(), + U256::from_dec_str("19000556224902286061769815260124368973839417953399533885850283592096662743016").unwrap(), + ], + vec![ + U256::from_dec_str("16883066945921282046110808795753929362007100542422795769422243319629113077450").unwrap(), + U256::from_dec_str("3229017908221308993692674040951942449106283130433174678816420254626513367678").unwrap(), + ], + ], + vec![ + vec![ + U256::from_dec_str("16459854676924169388774046538295013154707390397685062918225181412137603478923").unwrap(), + U256::from_dec_str("20996869365345436816737319903210535785982053153529758285286719146777762981985").unwrap(), + ], + vec![ + U256::from_dec_str("21446959969822179574296836241978980045198577120638747119902976563053247153220").unwrap(), + U256::from_dec_str("4716297282146551186330252875195511360280503254452482577157100992033023717484").unwrap(), + ] + ], + vec![ + vec![ + U256::from_dec_str("2127664998061023131080125201643658604092063304061707222326237054428506173927").unwrap(), + U256::from_dec_str("13918137729545385379467184110597023571257121066683873930760549927318081992996").unwrap(), + ], + vec![ + U256::from_dec_str("16560640526003408304721205785917894782070253870764339317137905014294472374327").unwrap(), + U256::from_dec_str("19394535992291030838186763750684977819230291410826312937425829210188321257228").unwrap(), + ] + ] + ); + + let valid_input: Vec = vec![u64s_to_u256(vec![ + 13212982172557049181, + 17043673098390055166, + 13971391527459105160, + 1729491887349651790, + ])]; + + let verifying_key = VerifyingKey::new(proof, vk, valid_input); + + let zk_verifier = ZKPrecompileVerifier::new( + H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), + verifying_key + ); + + let encoded_call = zk_verifier.generate_benchmarking_parameters(); + + let gas_limit_call = 1000000; + let value = U256::default(); + let is_transactional = true; + let validate = true; + }:{ + let call_runner_results = ::Runner::call( + caller, + contract_address, + encoded_call, + value, + gas_limit_call, + Some(U256::from(1_000_000_000)), + Some(U256::from(1_000_000_000)), + None, + Vec::new(), + is_transactional, + validate, + ::config(), + ); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "Benchmarking call end.", + // ); + match call_runner_results { + Ok(info) => { + let output = info.value; + let used_gas = info.used_gas; + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "nconstraints_30_input_5000 output result {:?} used_gas: {:?}", + output, + used_gas, + ); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "output result {:?}", + // output + // ); + if output.len() >= 32 { + let mut result_bytes = [0u8; 32]; + result_bytes.copy_from_slice(&output[output.len() - 32..]); + let result = U256::from_big_endian(&result_bytes); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "nconstraints_30_input_5000 Verification result {result:?}", + // ); + assert_eq!(result, U256::one(), "The contract did not return true"); + } + }, + Err(e) => { + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "nconstraints_30_input_5000 Benchmarking failed", + ); + assert!(false, "Benchmarking failed"); + } + } + } + nconstraints_30_input_10000 { + use frame_benchmarking::vec; + use sp_core::{H160, U256, H256}; + + let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + let contract_address = H160::from_low_u64_be(0x8888); + + let proof = Proof::new( + vec![ + U256::from_dec_str("20201588552006483041582128307591335561381558661958982754827324334159524114833").unwrap(), + U256::from_dec_str("17768889616334897699714190449991059857597665579001510168911964966707846254013").unwrap(), + ], + vec![ + vec![ + U256::from_dec_str("831427914683469755258685737297441858923030844026909228595596228891513784401").unwrap(), + U256::from_dec_str("17358733390631981546461856303504163975689822422160671163593908204299387350560").unwrap(), + ], + vec![ + U256::from_dec_str("12673178383954759426828314411760863182427996098705680584931403917390222262168").unwrap(), + U256::from_dec_str("12056092533572380482681874959737292916971452073896642753405050795241584080793").unwrap(), + ], + ], + vec![ + U256::from_dec_str("11086630979744216291689656728938462056245402184490217943698398792953833540899").unwrap(), + U256::from_dec_str("6981043472993913602669753829495794560155248771335035866541870305230603679484").unwrap(), + ] + ); + + let vk = VerifyingKeyComponents::new( + vec![ + U256::from_dec_str("10088605449330278081588905225706913827985798761474642054412607299987851491561").unwrap(), + U256::from_dec_str("12349112716571349951448807635426375878752472531266562453302627732729311140226").unwrap(), + ], + vec![ + vec![ + U256::from_dec_str("11234930657858483584603353214391341220392609835907149947974795594440445721655").unwrap(), + U256::from_dec_str("1047093079337214465686469751128183347143657884406521365857439579470759333731").unwrap(), + ], + vec![ + U256::from_dec_str("15864899975231343872664645828141071246029692141564279838230890638453916423742").unwrap(), + U256::from_dec_str("12053277475368564348616897081746431255423835262329161057768339971384736640081").unwrap(), + ], + ], + vec![ + vec![ + U256::from_dec_str("20662189442791195318296211376162761628558291902545582141646463139520777475283").unwrap(), + U256::from_dec_str("9279465006661849499753241364514057268552316193158700659184124742215268752791").unwrap(), + ], + vec![ + U256::from_dec_str("17033606864312833588672465768726096906720807717470346504048425104291392352898").unwrap(), + U256::from_dec_str("15319242533246792039334613039385600689133248724151496600840914674340560979641").unwrap(), + ], + ], + vec![ + vec![ + U256::from_dec_str("3303817333656562581428241644233610206796391323593261940899405821542387319372").unwrap(), + U256::from_dec_str("12434486975702473910116656089923156849733601159782506519440013280731025013736").unwrap(), + ], + vec![ + U256::from_dec_str("9561232329300105849651786447909752108987569955850131116304832039966768267007").unwrap(), + U256::from_dec_str("18486557213071145739422364713271115450952939790314495487369777335095317193174").unwrap(), + ] + ], + vec![ + vec![ + U256::from_dec_str("5864321703423906069527768678401445332135246771872328360194332677453860634867").unwrap(), + U256::from_dec_str("3305620141441221125469209629518919979790470359050105194093502369856652644459").unwrap(), + ], + vec![ + U256::from_dec_str("1810088252629429255118238329671475280643793553294287131634484491846973310510").unwrap(), + U256::from_dec_str("20707970746663158481851347112547705553728126185220754421254503093218351233120").unwrap(), + ] + ] + ); + + let valid_input: Vec = vec![u64s_to_u256(vec![ + 11033755416221607095, + 14172640425079373737, + 17268699570210893519, + 2451003838444787962, + ])]; + + let verifying_key = VerifyingKey::new(proof, vk, valid_input); + + let zk_verifier = ZKPrecompileVerifier::new( + H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), + verifying_key + ); + + let encoded_call = zk_verifier.generate_benchmarking_parameters(); + + let gas_limit_call = 1000000; + let value = U256::default(); + let is_transactional = true; + let validate = true; + }:{ + let call_runner_results = ::Runner::call( + caller, + contract_address, + encoded_call, + value, + gas_limit_call, + Some(U256::from(1_000_000_000)), + Some(U256::from(1_000_000_000)), + None, + Vec::new(), + is_transactional, + validate, + ::config(), + ); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "Benchmarking call end.", + // ); + match call_runner_results { + Ok(info) => { + let output = info.value; + let used_gas = info.used_gas; + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "nconstraints_30_input_10000 output result {:?} used_gas: {:?}", + output, + used_gas, + ); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "output result {:?}", + // output + // ); + if output.len() >= 32 { + let mut result_bytes = [0u8; 32]; + result_bytes.copy_from_slice(&output[output.len() - 32..]); + let result = U256::from_big_endian(&result_bytes); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "nconstraints_30_input_10000 Verification result {result:?}", + // ); + assert_eq!(result, U256::one(), "The contract did not return true"); + } + }, + Err(e) => { + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "nconstraints_30_input_10000 Benchmarking failed", + ); + assert!(false, "Benchmarking failed"); + + } + } + } + nconstraints_30_input_90000 { + use frame_benchmarking::vec; + use sp_core::{H160, U256, H256}; + + let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + let contract_address = H160::from_low_u64_be(0x8888); + + let proof = Proof::new( + vec![ + U256::from_dec_str("7949275001087845673352113652992317737416671749823042856819742064958185730665").unwrap(), + U256::from_dec_str("5891863541401068443747112095836743353338477825995666306081231182884954636005").unwrap(), + ], + vec![ + vec![ + U256::from_dec_str("12960565378826264234747222392568347150301360486418725511109506548813034322775").unwrap(), + U256::from_dec_str("6924824876048701587380679111548259437770370772320848338373383587483809707515").unwrap(), + ], + vec![ + U256::from_dec_str("21689747160304810742710652756166876177223750769696622871469266436845305438116").unwrap(), + U256::from_dec_str("14167066926549192557125941689316913820167617731059401320567819691908586156039").unwrap(), + ], + ], + vec![ + U256::from_dec_str("19186797317064887099470636752510606772753033946198593325337771098325482447274").unwrap(), + U256::from_dec_str("3350186543680262034371474397706130211690310055235028696466009478959025709845").unwrap(), + ] + ); + + let vk = VerifyingKeyComponents::new( + vec![ + U256::from_dec_str("6828794497030502754628523747507406719479438181845328406281207577196379759609").unwrap(), + U256::from_dec_str("5561027388439947090438746111225212164455366280326670821700904471009784329896").unwrap(), + ], + vec![ + vec![ + U256::from_dec_str("1648517694167305339737563900225685665396551354808983529387892872646841040850").unwrap(), + U256::from_dec_str("15406833006990307743521713564090315343374212223020060642984366610793788667116").unwrap(), + ], + vec![ + U256::from_dec_str("14591594646846027404699868040454897990147675572067174007423843530180728597612").unwrap(), + U256::from_dec_str("2940958434778941597191243007999700895445672570190450648227198352981565653913").unwrap(), + ], + ], + vec![ + vec![ + U256::from_dec_str("7676142418543194845482248509044991512324196983308812731866772308356979871307").unwrap(), + U256::from_dec_str("21511013842679919895947796523736214038726875927496967606596253311081756690725").unwrap(), + ], + vec![ + U256::from_dec_str("4652378032872178978450279958290699982888059033676566152376150880744787185780").unwrap(), + U256::from_dec_str("467504210088082002071026778234767679654059202832780062786965483300786044530").unwrap(), + ], + ], + vec![ + vec![ + U256::from_dec_str("20744282071154891204049714936088748576694067059171789505913191933597423689555").unwrap(), + U256::from_dec_str("12596866572762256583276410876169296807308160857887657727882625055041251553242").unwrap(), + ], + vec![ + U256::from_dec_str("3588798969790877834321031026222278845206273301850566393834657489341158616535").unwrap(), + U256::from_dec_str("19268326464935908053037454129640878232926568425004490855381855273084219557079").unwrap(), + ] + ], + vec![ + vec![ + U256::from_dec_str("10928515506460596401961934744263657631726985113185854450754018401146226707446").unwrap(), + U256::from_dec_str("1043421123157233618994554398894819122012315878788274412803269234825060696656").unwrap(), + ], + vec![ + U256::from_dec_str("21802758012415709270812560952687831790545411568500639317690833457802568775035").unwrap(), + U256::from_dec_str("8926874931677263335476856545765471099163606107894025045476086328360781102193").unwrap(), + ] + ] + ); + + let valid_input: Vec = vec![u64s_to_u256(vec![ + 2553457387449696641, + 815105491620421980, + 17800546104409657428, + 2866567216183504159, + ])]; + + let verifying_key = VerifyingKey::new(proof, vk, valid_input); + + let zk_verifier = ZKPrecompileVerifier::new( + H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), + verifying_key + ); + + let encoded_call = zk_verifier.generate_benchmarking_parameters(); + + let gas_limit_call = 1000000; + let value = U256::default(); + let is_transactional = true; + let validate = true; + }:{ + let call_runner_results = ::Runner::call( + caller, + contract_address, + encoded_call, + value, + gas_limit_call, + Some(U256::from(1_000_000_000)), + Some(U256::from(1_000_000_000)), + None, + Vec::new(), + is_transactional, + validate, + ::config(), + ); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "Benchmarking call end.", + // ); + match call_runner_results { + Ok(info) => { + let output = info.value; + let used_gas = info.used_gas; + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "nconstraints_30_input_90000 output result {:?} used_gas: {:?}", + output, + used_gas, + ); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "output result {:?}", + // output + // ); + if output.len() >= 32 { + let mut result_bytes = [0u8; 32]; + result_bytes.copy_from_slice(&output[output.len() - 32..]); + let result = U256::from_big_endian(&result_bytes); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "nconstraints_30_input_90000 Verification result {result:?}", + // ); + assert_eq!(result, U256::one(), "The contract did not return true"); + } + }, + Err(e) => { + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "nconstraints_30_input_90000 Benchmarking failed", + ); + assert!(false, "Benchmarking failed"); + } + } + } + nconstraints_30_input_200000 { + use frame_benchmarking::vec; + use sp_core::{H160, U256, H256}; + + let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + let contract_address = H160::from_low_u64_be(0x8888); + + let proof = Proof::new( + vec![ + U256::from_dec_str("19903885251949679146607224162906437591286076549652044731739108226015926915860").unwrap(), + U256::from_dec_str("11870922578907159231760438847634888925027596611865086487008358810346509550746").unwrap(), + ], + vec![ + vec![ + U256::from_dec_str("7572350741301793140585595336451242554319145556316993930579910816773197602180").unwrap(), + U256::from_dec_str("16166630091911008518878343585755669995589761813810965163203815419554661335912").unwrap(), + ], + vec![ + U256::from_dec_str("10479558631339350148140324543423297113164179377516410954282474094862685762111").unwrap(), + U256::from_dec_str("1538599836393367534859442557225095989831507256094436416355361165563840234277").unwrap(), + ], + ], + vec![ + U256::from_dec_str("18566368172831132986640612657510108843544042128267080758083569019690510537842").unwrap(), + U256::from_dec_str("14637144036179606956000163117625168358523245864386632910728645092984303842870").unwrap(), + ] + ); + + let vk = VerifyingKeyComponents::new( + vec![ + U256::from_dec_str("3388366987275268645608688601800038483480506575351380219459271970783548315310").unwrap(), + U256::from_dec_str("10139982329791419477606385196757134153200700293861474061701578521738893563314").unwrap(), + ], + vec![ + vec![ + U256::from_dec_str("17293003127353596916845398615566872053529832484770184120881889494052646686398").unwrap(), + U256::from_dec_str("3746742577904007471872553744363212404516454459540143078991207693255568088158").unwrap(), + ], + vec![ + U256::from_dec_str("18996426015092705424501193523094438770040629737761363033585766320236602756452").unwrap(), + U256::from_dec_str("5993252813486169444483155589566709251331252167093428959716521680127596688663").unwrap(), + ], + ], + vec![ + vec![ + U256::from_dec_str("86221489590459042456285770827248107701675460052532768290239949641616327672").unwrap(), + U256::from_dec_str("21618235778373592971185937996314200926578828337383413751502402964191761009384").unwrap(), + ], + vec![ + U256::from_dec_str("10453895050472290645179709462208119639593757329666114205922088367970822668124").unwrap(), + U256::from_dec_str("16924749634830145681809164670725933237166438445526123149706427927968513710893").unwrap(), + ], + ], + vec![ + vec![ + U256::from_dec_str("20506347836984398194650179863264269358088067779451739307543701941138658771117").unwrap(), + U256::from_dec_str("15256122081275324863091225387225218399888282841698960666742408225921079848693").unwrap(), + ], + vec![ + U256::from_dec_str("7881380592415293900063452944037916715621668238658562838630198037249553436647").unwrap(), + U256::from_dec_str("6003465274284900873747728448177380007802003937728590930467990944623586277089").unwrap(), + ] + ], + vec![ + vec![ + U256::from_dec_str("5531662187275540864474040102019845108669876235687831703751327129559212127084").unwrap(), + U256::from_dec_str("11455786949456856409363436892267690994602451302132959153447251790964376014822").unwrap(), + ], + vec![ + U256::from_dec_str("17221728819314881853232886080533000381382340762620795831983019279828981481257").unwrap(), + U256::from_dec_str("19341881794793455210912817199750586531241336493382870655971958667936340901503").unwrap(), + ] + ] + ); + + let valid_input: Vec = vec![u64s_to_u256(vec![ + 17510768071209558285, + 11281672863963944712, + 17936011136389338927, + 2683423138755332222, + ])]; + + let verifying_key = VerifyingKey::new(proof, vk, valid_input); + + let zk_verifier = ZKPrecompileVerifier::new( + H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), + verifying_key + ); + + let encoded_call = zk_verifier.generate_benchmarking_parameters(); + + let gas_limit_call = 1000000; + let value = U256::default(); + let is_transactional = true; + let validate = true; + }:{ + let call_runner_results = ::Runner::call( + caller, + contract_address, + encoded_call, + value, + gas_limit_call, + Some(U256::from(1_000_000_000)), + Some(U256::from(1_000_000_000)), + None, + Vec::new(), + is_transactional, + validate, + ::config(), + ); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "Benchmarking call end.", + // ); + match call_runner_results { + Ok(info) => { + let output = info.value; + let used_gas = info.used_gas; + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "nconstraints_30_input_200000 output result {:?} used_gas: {:?}", + output, + used_gas, + ); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "output result {:?}", + // output + // ); + if output.len() >= 32 { + let mut result_bytes = [0u8; 32]; + result_bytes.copy_from_slice(&output[output.len() - 32..]); + let result = U256::from_big_endian(&result_bytes); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "nconstraints_30_input_200000 Verification result {result:?}", + // ); + assert_eq!(result, U256::one(), "The contract did not return true"); + } + }, + Err(e) => { + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "nconstraints_30_input_200000 Benchmarking failed", + ); + assert!(false, "Benchmarking failed"); + } + } + } + + sum_10 { + use frame_benchmarking::vec; + use sp_core::{H160, U256, H256}; + + let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + let contract_address = H160::from_low_u64_be(0x8888); + + let proof = Proof::new( + vec![ + U256::from_dec_str("4479438672593572194843316486259284641920166054544576564310150763796220593742").unwrap(), + U256::from_dec_str("5717857931841301866217201485541887040818093727574311517591849036289507799141").unwrap(), + ], + vec![ + vec![ + U256::from_dec_str("438102211713357984070931589322877643391719193099221891191956755149301376056").unwrap(), + U256::from_dec_str("14696299438400225528910058565202329177181471318954607581306780544413371767738").unwrap(), + ], + vec![ + U256::from_dec_str("18723112929967827488252389384208353884816003870032279933823625467146809072448").unwrap(), + U256::from_dec_str("781225142569358922067919798403956593420009838230922093237868933021043854113").unwrap(), + ], + ], + vec![ + U256::from_dec_str("10481213903673023503381125372528754955378591812884098928519623211332171467098").unwrap(), + U256::from_dec_str("15098195705682978185145469811146985310923026878303775073727891846327587112885").unwrap(), + ] + ); + + let vk = VerifyingKeyComponents::new( + vec![ + U256::from_dec_str("10600514820627226711889163536575359330497844540484876797299835164575096986123").unwrap(), + U256::from_dec_str("8955505242614929800342716899005854501255692108538633212406728467939250778259").unwrap(), + ], + vec![ + vec![ + U256::from_dec_str("11358515176167160981846987587695931342878788452018419590778128561277894807040").unwrap(), + U256::from_dec_str("7367100375568995524851051084377016949291621141008718892167611998460177966556").unwrap(), + ], + vec![ + U256::from_dec_str("9986374126991936592889887298811366506288970021158383914729072242552712258999").unwrap(), + U256::from_dec_str("5917047061876555575617149777207682047359711575786648519096749890796145313142").unwrap(), + ], + ], + vec![ + vec![ + U256::from_dec_str("12470512550870605078154922234115021580073605821744497867586706681115325377951").unwrap(), + U256::from_dec_str("3964373607930903502336465614571930627592350216968107805643078708599943392195").unwrap(), + ], + vec![ + U256::from_dec_str("9054619931591683490625148848351137928205510101241639415537408964292455344707").unwrap(), + U256::from_dec_str("14433710971468466044075036729227299898791551573181475688890434779549865103322").unwrap(), + ] + ], + vec![ + vec![ + U256::from_dec_str("13008751738470482081156013535203222043379316308698376931322848604706786065862").unwrap(), + U256::from_dec_str("3415558414191757405655644967374577939532374518318643852418890898323033638525").unwrap(), + ], + vec![ + U256::from_dec_str("2104722493853714523712648261788727756558190509825976396834309269877977849365").unwrap(), + U256::from_dec_str("6877732520157662584755946842350755740172704606349660337522459938993730313391").unwrap(), + ], + ], + vec![ + vec![ + U256::from_dec_str("17691779713798847872985546462247707503645016076661816616388979822201176829753").unwrap(), + U256::from_dec_str("14451231434311244057691431183198403713720423327382654964068207207079455187712").unwrap(), + ], + vec![ + U256::from_dec_str("13620414910695185146987530463229819484652710069270717148541433045978322585419").unwrap(), + U256::from_dec_str("10875872907505029426874795808985164080699672034676409959252328566889297105865").unwrap(), + ] + ] + ); + + let valid_input = vec![ + U256::from_dec_str("55").unwrap() + ]; + + let verifying_key = VerifyingKey::new(proof, vk, valid_input); + + let zk_verifier = ZKPrecompileVerifier::new( + H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), + verifying_key + ); + + let encoded_call = zk_verifier.generate_benchmarking_parameters(); + + let gas_limit_call = 1000000; + let value = U256::default(); + let is_transactional = true; + let validate = true; + }:{ + let call_runner_results = ::Runner::call( + caller, + contract_address, + encoded_call, + value, + gas_limit_call, + Some(U256::from(1_000_000_000)), + Some(U256::from(1_000_000_000)), + None, + Vec::new(), + is_transactional, + validate, + ::config(), + ); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "Benchmarking call end.", + // ); + match call_runner_results { + Ok(info) => { + let output = info.value; + let used_gas = info.used_gas; + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "sum_10 output result {:?} used_gas: {:?}", + output, + used_gas, + ); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "output result {:?}", + // output + // ); + if output.len() >= 32 { + let mut result_bytes = [0u8; 32]; + result_bytes.copy_from_slice(&output[output.len() - 32..]); + let result = U256::from_big_endian(&result_bytes); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "sum_10 Verification result {result:?}", + // ); + assert_eq!(result, U256::one(), "The contract did not return true"); + } + }, + Err(e) => { + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "sum_10 Benchmarking failed", + ); + assert!(false, "Benchmarking failed"); + } + } + } + sum_50 { + use frame_benchmarking::vec; + use sp_core::{H160, U256, H256}; + + let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + let contract_address = H160::from_low_u64_be(0x8888); + + let proof = Proof::new( + vec![ + U256::from_dec_str("3114941071688532747454764921300681791980888248199392522675009157778549895455").unwrap(), + U256::from_dec_str("6816680925124829082835883802586391663161606011222680818599486084577544527516").unwrap(), + ], + vec![ + vec![ + U256::from_dec_str("15037393792780247314317740287895838240941967969445981241792818111317913065010").unwrap(), + U256::from_dec_str("3834028682995799272226496422556310257938795862629020590068471611902272764146").unwrap(), + ], + vec![ + U256::from_dec_str("4023883034822047449129381158539093978377425715903419218696272130851521242085").unwrap(), + U256::from_dec_str("13058906875228264286034925941047330220503025517973111955115072416984072943122").unwrap(), + ], + ], + vec![ + U256::from_dec_str("5344888056894889487007260648469199417556856955544355154291642477677322944786").unwrap(), + U256::from_dec_str("19843194668352645797068691966948915569058668700830773246420232986019393210063").unwrap(), + ] + ); + + let vk = VerifyingKeyComponents::new( + vec![ + U256::from_dec_str("19257923683733118221652593587810195852599358412856281104090957905722976964370").unwrap(), + U256::from_dec_str("19519729727735873999148754136012144616045305047716967685280834855818506563720").unwrap(), + ], + vec![ + vec![ + U256::from_dec_str("4418606700813566482216037680863387214037640478555893901955308344977554198718").unwrap(), + U256::from_dec_str("18046767849922558936185002168253454007598159984067380537392936220227127228867").unwrap(), + ], + vec![ + U256::from_dec_str("100725403545603844224319783153051757027683253433977048289134569498829183303").unwrap(), + U256::from_dec_str("9785321212288652698655727476617710557399711491394256119637648908536562741634").unwrap(), + ], + ], + vec![ + vec![ + U256::from_dec_str("7184324332054694882815451883063466258810341506246659357034202660488015984306").unwrap(), + U256::from_dec_str("14398081398842334723334363407187040569418119441776629783632309768037771007327").unwrap(), + ], + vec![ + U256::from_dec_str("17277213124622419955089087696435667358779233792945822269342368397066818801481").unwrap(), + U256::from_dec_str("19811781065417531456401229702422997450338397507283920558741452740912313583930").unwrap(), + ] + ], + vec![ + vec![ + U256::from_dec_str("1627724482578854283892192357407161928314687375966263116172485631707694669812").unwrap(), + U256::from_dec_str("6839802000376483025048211234449253336394632788399066904541666906747650234382").unwrap(), + ], + vec![ + U256::from_dec_str("17974577137954059751166162247265070307968439813726452160113109110701162631938").unwrap(), + U256::from_dec_str("21289972529626386698860098501676961527414208445147370800462053148477683157991").unwrap(), + ], + ], + vec![ + vec![ + U256::from_dec_str("20284064245383237908740484779775789109386762825985839657586769414934584661714").unwrap(), + U256::from_dec_str("17363934481847560975462360104367791101351872886050159351690589725380050257409").unwrap(), + ], + vec![ + U256::from_dec_str("3904403738619431633601997032597659843284744078768864151280168218762434423692").unwrap(), + U256::from_dec_str("4413868989856264583489102855186788724178233679332360263809134874064797750675").unwrap(), + ] + ] + ); + + let valid_input = vec![ + U256::from_dec_str("1275").unwrap(), + ]; + + let verifying_key = VerifyingKey::new(proof, vk, valid_input); + + let zk_verifier = ZKPrecompileVerifier::new( + H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), + verifying_key + ); + + let encoded_call = zk_verifier.generate_benchmarking_parameters(); + + let gas_limit_call = 1000000; + let value = U256::default(); + let is_transactional = true; + let validate = true; + }:{ + let call_runner_results = ::Runner::call( + caller, + contract_address, + encoded_call, + value, + gas_limit_call, + Some(U256::from(1_000_000_000)), + Some(U256::from(1_000_000_000)), + None, + Vec::new(), + is_transactional, + validate, + ::config(), + ); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "Benchmarking call end.", + // ); + match call_runner_results { + Ok(info) => { + let output = info.value; + let used_gas = info.used_gas; + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "sum_50 output result {:?} used_gas: {:?}", + output, + used_gas, + ); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "output result {:?}", + // output + // ); + if output.len() >= 32 { + let mut result_bytes = [0u8; 32]; + result_bytes.copy_from_slice(&output[output.len() - 32..]); + let result = U256::from_big_endian(&result_bytes); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "sum_50 Verification result {result:?}", + // ); + assert_eq!(result, U256::one(), "The contract did not return true"); + } + }, + Err(e) => { + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "sum_50 Benchmarking failed", + ); + assert!(false, "Benchmarking failed"); + } + } + } + + sum_5000 { + use frame_benchmarking::vec; + use sp_core::{H160, U256, H256}; + + let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + let contract_address = H160::from_low_u64_be(0x8888); + + let proof = Proof::new( + vec![ + U256::from_dec_str("2104134032972066019913571175532882184351637942839921828138208604817397790978").unwrap(), + U256::from_dec_str("12625149522977248086293073767826715132905823679345516244316272790389621024575").unwrap(), + ], + vec![ + vec![ + U256::from_dec_str("18955718237898317556602416465218566057031982163829528123671300051574728240883").unwrap(), + U256::from_dec_str("18075306515520608621953959878874546391551215874677138383864573851396832159644").unwrap(), + ], + vec![ + U256::from_dec_str("3166476742865671627115278436666969186969644878053983393309132722947819232105").unwrap(), + U256::from_dec_str("8051049247607109861344268872842958063551670273736053865524986958976361214062").unwrap(), + ], + ], + vec![ + U256::from_dec_str("4814291763265323888812051590287571407031542635142019809665068757723218701627").unwrap(), + U256::from_dec_str("17930948070313125851452005455953009375012074818817251382455220462443054837203").unwrap(), + ] + ); + + let vk = VerifyingKeyComponents::new( + vec![ + U256::from_dec_str("19624232987744880202266197753309961915632611879850947888541508003701736644214").unwrap(), + U256::from_dec_str("5019843555387010050200067558096501184079196549422645876015184268981691000261").unwrap(), + ], + vec![ + vec![ + U256::from_dec_str("5150307298606577026396875555180704696345763655981810466632357002439129266461").unwrap(), + U256::from_dec_str("3020656302335648031712857271727816386298675153130933709481311850060508289333").unwrap(), + ], + vec![ + U256::from_dec_str("19547576195358452722114991449875886954598568010341500952076854329553571219720").unwrap(), + U256::from_dec_str("3895331072082263654317901227968966808293407907751128382134753194859731114729").unwrap(), + ], + ], + vec![ + vec![ + U256::from_dec_str("5792479463369352075979003547777370241697788651005116088867026457677720533395").unwrap(), + U256::from_dec_str("16882159064341957118950974052606760693554763076237663579029547802558086431378").unwrap(), + ], + vec![ + U256::from_dec_str("15201299876801474331768851307298179430198466709727112330042020251492139993850").unwrap(), + U256::from_dec_str("893863620414771464835789333501093176356026692988850717670551586498757709875").unwrap(), + ] + ], + vec![ + vec![ + U256::from_dec_str("165136411129701665870237237981894748637834826722462614973940945603783242464").unwrap(), + U256::from_dec_str("10766657827945181878791518932726777890925519579254084496220957371082172349194").unwrap(), + ], + vec![ + U256::from_dec_str("1813485593016293809685571822392302147347136682526622353828238069063634409991").unwrap(), + U256::from_dec_str("12730118542350484957903782401323352413406115135420607527656226977122246298735").unwrap(), + ], + ], + vec![ + vec![ + U256::from_dec_str("19450458898299554306247087083239008884256452312356497246598109368644839627523").unwrap(), + U256::from_dec_str("123992241310851816418828784530061727329258706748227789362318537744292975333").unwrap(), + ], + vec![ + U256::from_dec_str("1650700423026830428199086201346242616543834285406293983963791012821269466913").unwrap(), + U256::from_dec_str("3152920600939501404817148774751227981988970987313622659392580888754616114976").unwrap(), + ] + ] + ); + + let valid_input = vec![ + U256::from_dec_str("12502500").unwrap(), + ]; + + let verifying_key = VerifyingKey::new(proof, vk, valid_input); + + let zk_verifier = ZKPrecompileVerifier::new( + H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), + verifying_key + ); + + let encoded_call = zk_verifier.generate_benchmarking_parameters(); + + let gas_limit_call = 1000000; + let value = U256::default(); + let is_transactional = true; + let validate = true; + }:{ + let call_runner_results = ::Runner::call( + caller, + contract_address, + encoded_call, + value, + gas_limit_call, + Some(U256::from(1_000_000_000)), + Some(U256::from(1_000_000_000)), + None, + Vec::new(), + is_transactional, + validate, + ::config(), + ); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "Benchmarking call end.", + // ); + match call_runner_results { + Ok(info) => { + let output = info.value; + let used_gas = info.used_gas; + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "sum_5000 output result {:?} used_gas: {:?}", + output, + used_gas, + ); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "output result {:?}", + // output + // ); + if output.len() >= 32 { + let mut result_bytes = [0u8; 32]; + result_bytes.copy_from_slice(&output[output.len() - 32..]); + let result = U256::from_big_endian(&result_bytes); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "sum_5000 Verification result {result:?}", + // ); + assert_eq!(result, U256::one(), "The contract did not return true"); + } + }, + Err(e) => { + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "sum_5000 Benchmarking failed", + ); + assert!(false, "Benchmarking failed"); + } + } + } + + sum_50000 { + use frame_benchmarking::vec; + use sp_core::{H160, U256, H256}; + + let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + let contract_address = H160::from_low_u64_be(0x8888); + + let proof = Proof::new( + vec![ + U256::from_dec_str("10521560297681522924956535552101557954055377883537271587209095331672512231293").unwrap(), + U256::from_dec_str("3686654512637749683446869119197341068039068905923579159423036344564025864377").unwrap(), + ], + vec![ + vec![ + U256::from_dec_str("4890395955490088627121586512165392468998481877071173820388882318632254821251").unwrap(), + U256::from_dec_str("9885243823600363166628220433820250724586324090253611358758770212725684204135").unwrap(), + ], + vec![ + U256::from_dec_str("9651185291553128823215307092565172143818838202635271809942597163630971976482").unwrap(), + U256::from_dec_str("7457264071531012293581639749136580536924886204589417402009399054127419592993").unwrap(), + ], + ], + vec![ + U256::from_dec_str("2627345354605748142976160304028628661480987375506843588233396593542954599122").unwrap(), + U256::from_dec_str("8681729968580301984067665769277363721394455178806371130831646417737890294377").unwrap(), + ] + ); + + let vk = VerifyingKeyComponents::new( + vec![ + U256::from_dec_str("7421321362170719195081023585470135389432297716397232604489422086989398701183").unwrap(), + U256::from_dec_str("4072026971341416803293623026670767879574289631340879941991921870784524426920").unwrap(), + ], + vec![ + vec![ + U256::from_dec_str("2973474839676012411019522612887674225146102238495561333683790233803898072056").unwrap(), + U256::from_dec_str("4756088420398356546587372215087817373004751038308642279979561650652947628544").unwrap(), + ], + vec![ + U256::from_dec_str("18134483811751652906456539288278265005968212485396038963550793901997203165973").unwrap(), + U256::from_dec_str("19733531274857979315351276512779996430041767061694237978460875113100798536651").unwrap(), + ], + ], + vec![ + vec![ + U256::from_dec_str("1470135418689977789083190292952479192678178451735632796795673595352524120366").unwrap(), + U256::from_dec_str("5512330648930976997879473235916847191061423400686751865867764833860608466852").unwrap(), + ], + vec![ + U256::from_dec_str("8727385532414213805687214017949229267547242769169729533774216518510791901252").unwrap(), + U256::from_dec_str("6002526157648728322271067956991922780742552704883496238917574496345518669191").unwrap(), + ] + ], + vec![ + vec![ + U256::from_dec_str("20953112965721952332699311075873353918826966291896395544882354080425788226212").unwrap(), + U256::from_dec_str("9244986330211753947979669564454335484807935852348100319901614192766392809174").unwrap(), + ], + vec![ + U256::from_dec_str("14633091132354386243825187195737842488061561784614981035737595152471541943810").unwrap(), + U256::from_dec_str("18226447293937452659919522397971158104569327938800893595903771586125572293911").unwrap(), + ], + ], + vec![ + vec![ + U256::from_dec_str("12814717307556312189651039282215441805578074271611267777533714458773278844960").unwrap(), + U256::from_dec_str("7186820657304904476047212967487229874520184333187156276378594443001564484591").unwrap(), + ], + vec![ + U256::from_dec_str("555198418426478766253895845611805598077310216839822834188225932135183360314").unwrap(), + U256::from_dec_str("13253206399154373951823381980703846825450333469684895600618793136364702673992").unwrap(), + ] + ] + ); + + let valid_input = vec![U256::from_dec_str("1250025000").unwrap()]; + + let verifying_key = VerifyingKey::new(proof, vk, valid_input); + + let zk_verifier = ZKPrecompileVerifier::new( + H256::from_slice(&sp_io::hashing::keccak_256(b"verify(uint256[2],uint256[2][2],uint256[2],uint256[2],uint256[2][2],uint256[2][2],uint256[2][2],uint256[2][],uint256[])")[0..32]), + verifying_key + ); + + let encoded_call = zk_verifier.generate_benchmarking_parameters(); + + let gas_limit_call = 1000000; + let value = U256::default(); + let is_transactional = true; + let validate = true; + }:{ + let call_runner_results = ::Runner::call( + caller, + contract_address, + encoded_call, + value, + gas_limit_call, + Some(U256::from(1_000_000_000)), + Some(U256::from(1_000_000_000)), + None, + Vec::new(), + is_transactional, + validate, + ::config(), + ); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "Benchmarking call end.", + // ); + match call_runner_results { + Ok(info) => { + let output = info.value; + let used_gas = info.used_gas; + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "sum_50000 output result {:?} used_gas: {:?}", + output, + used_gas, + ); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "output result {:?}", + // output + // ); + if output.len() >= 32 { + let mut result_bytes = [0u8; 32]; + result_bytes.copy_from_slice(&output[output.len() - 32..]); + let result = U256::from_big_endian(&result_bytes); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "sum_50000 Verification result {result:?}", + // ); + assert_eq!(result, U256::one(), "The contract did not return true"); + } + }, + Err(e) => { + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "sum_50000 Benchmarking failed", + ); + assert!(false, "Benchmarking failed"); + } + } + } sumout_1 { use frame_benchmarking::vec; @@ -2421,14 +2521,21 @@ benchmarks! { match call_runner_results { Ok(info) => { let output = info.value; + let used_gas = info.used_gas; + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "sumout_1 output result {:?} used_gas: {:?}", + output, + used_gas, + ); if output.len() >= 32 { let mut result_bytes = [0u8; 32]; result_bytes.copy_from_slice(&output[output.len() - 32..]); let result = U256::from_big_endian(&result_bytes); - log::info!( - target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - "sumout_1 Verification result {result:?}", - ); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "sumout_1 Verification result {result:?}", + // ); assert_eq!(result, U256::one(), "The contract did not return true"); } }, @@ -2562,14 +2669,21 @@ benchmarks! { match call_runner_results { Ok(info) => { let output = info.value; + let used_gas = info.used_gas; + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "sumout_3 output result {:?} used_gas: {:?}", + output, + used_gas, + ); if output.len() >= 32 { let mut result_bytes = [0u8; 32]; result_bytes.copy_from_slice(&output[output.len() - 32..]); let result = U256::from_big_endian(&result_bytes); - log::info!( - target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - "sumout_3 Verification result {result:?}", - ); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "sumout_3 Verification result {result:?}", + // ); assert_eq!(result, U256::one(), "The contract did not return true"); } }, @@ -2713,14 +2827,21 @@ benchmarks! { match call_runner_results { Ok(info) => { let output = info.value; + let used_gas = info.used_gas; + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "sumout_5 output result {:?} used_gas: {:?}", + output, + used_gas, + ); if output.len() >= 32 { let mut result_bytes = [0u8; 32]; result_bytes.copy_from_slice(&output[output.len() - 32..]); let result = U256::from_big_endian(&result_bytes); - log::info!( - target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - "sumout_5 Verification result {result:?}", - ); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "sumout_5 Verification result {result:?}", + // ); assert_eq!(result, U256::one(), "The contract did not return true"); } }, @@ -2879,14 +3000,21 @@ benchmarks! { match call_runner_results { Ok(info) => { let output = info.value; + let used_gas = info.used_gas; + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "sumout_8 output result {:?} used_gas: {:?}", + output, + used_gas, + ); if output.len() >= 32 { let mut result_bytes = [0u8; 32]; result_bytes.copy_from_slice(&output[output.len() - 32..]); let result = U256::from_big_endian(&result_bytes); - log::info!( - target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - "sumout_8 Verification result {result:?}", - ); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "sumout_8 Verification result {result:?}", + // ); assert_eq!(result, U256::one(), "The contract did not return true"); } }, @@ -3055,14 +3183,21 @@ benchmarks! { match call_runner_results { Ok(info) => { let output = info.value; + let used_gas = info.used_gas; + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "sumout_10 output result {:?} used_gas: {:?}", + output, + used_gas, + ); if output.len() >= 32 { let mut result_bytes = [0u8; 32]; result_bytes.copy_from_slice(&output[output.len() - 32..]); let result = U256::from_big_endian(&result_bytes); - log::info!( - target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - "sumout_10 Verification result {result:?}", - ); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "sumout_10 Verification result {result:?}", + // ); assert_eq!(result, U256::one(), "The contract did not return true"); } }, @@ -3241,14 +3376,21 @@ benchmarks! { match call_runner_results { Ok(info) => { let output = info.value; + let used_gas = info.used_gas; + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "sumout_12 output result {:?} used_gas: {:?}", + output, + used_gas, + ); if output.len() >= 32 { let mut result_bytes = [0u8; 32]; result_bytes.copy_from_slice(&output[output.len() - 32..]); let result = U256::from_big_endian(&result_bytes); - log::info!( - target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - "sumout_12 Verification result {result:?}", - ); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "sumout_12 Verification result {result:?}", + // ); assert_eq!(result, U256::one(), "The contract did not return true"); } }, @@ -3442,14 +3584,21 @@ benchmarks! { match call_runner_results { Ok(info) => { let output = info.value; + let used_gas = info.used_gas; + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "nconstraints_10 output result {:?} used_gas: {:?}", + output, + used_gas, + ); if output.len() >= 32 { let mut result_bytes = [0u8; 32]; result_bytes.copy_from_slice(&output[output.len() - 32..]); let result = U256::from_big_endian(&result_bytes); - log::info!( - target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - "sumout_15 Verification result {result:?}", - ); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "sumout_15 Verification result {result:?}", + // ); assert_eq!(result, U256::one(), "The contract did not return true"); } }, @@ -3658,14 +3807,21 @@ benchmarks! { match call_runner_results { Ok(info) => { let output = info.value; + let used_gas = info.used_gas; + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "sumout_18 output result {:?} used_gas: {:?}", + output, + used_gas, + ); if output.len() >= 32 { let mut result_bytes = [0u8; 32]; result_bytes.copy_from_slice(&output[output.len() - 32..]); let result = U256::from_big_endian(&result_bytes); - log::info!( - target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - "sumout_18 Verification result {result:?}", - ); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "sumout_18 Verification result {result:?}", + // ); assert_eq!(result, U256::one(), "The contract did not return true"); } }, @@ -3884,14 +4040,21 @@ benchmarks! { match call_runner_results { Ok(info) => { let output = info.value; + let used_gas = info.used_gas; + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "sumout_20 output result {:?} used_gas: {:?}", + output, + used_gas, + ); if output.len() >= 32 { let mut result_bytes = [0u8; 32]; result_bytes.copy_from_slice(&output[output.len() - 32..]); let result = U256::from_big_endian(&result_bytes); - log::info!( - target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - "sumout_20 Verification result {result:?}", - ); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "sumout_20 Verification result {result:?}", + // ); assert_eq!(result, U256::one(), "The contract did not return true"); } }, @@ -4260,14 +4423,21 @@ benchmarks! { match call_runner_results { Ok(info) => { let output = info.value; + let used_gas = info.used_gas; + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "sumout_50 output result {:?} used_gas: {:?}", + output, + used_gas, + ); if output.len() >= 32 { let mut result_bytes = [0u8; 32]; result_bytes.copy_from_slice(&output[output.len() - 32..]); let result = U256::from_big_endian(&result_bytes); - log::info!( - target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - "sumout_50 Verification result {result:?}", - ); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "sumout_50 Verification result {result:?}", + // ); assert_eq!(result, U256::one(), "The contract did not return true"); } }, @@ -4401,14 +4571,21 @@ benchmarks! { match call_runner_results { Ok(info) => { let output = info.value; + let used_gas = info.used_gas; + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "fib_3 output result {:?} used_gas: {:?}", + output, + used_gas, + ); if output.len() >= 32 { let mut result_bytes = [0u8; 32]; result_bytes.copy_from_slice(&output[output.len() - 32..]); let result = U256::from_big_endian(&result_bytes); - log::info!( - target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - "fib_3 Verification result {result:?}", - ); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "fib_3 Verification result {result:?}", + // ); assert_eq!(result, U256::one(), "The contract did not return true"); } }, @@ -4552,14 +4729,21 @@ benchmarks! { match call_runner_results { Ok(info) => { let output = info.value; + let used_gas = info.used_gas; + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "fib_5 output result {:?} used_gas: {:?}", + output, + used_gas, + ); if output.len() >= 32 { let mut result_bytes = [0u8; 32]; result_bytes.copy_from_slice(&output[output.len() - 32..]); let result = U256::from_big_endian(&result_bytes); - log::info!( - target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - "fib_5 Verification result {result:?}", - ); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "fib_5 Verification result {result:?}", + // ); assert_eq!(result, U256::one(), "The contract did not return true"); } }, @@ -4728,14 +4912,21 @@ benchmarks! { match call_runner_results { Ok(info) => { let output = info.value; + let used_gas = info.used_gas; + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "fib_10 output result {:?} used_gas: {:?}", + output, + used_gas, + ); if output.len() >= 32 { let mut result_bytes = [0u8; 32]; result_bytes.copy_from_slice(&output[output.len() - 32..]); let result = U256::from_big_endian(&result_bytes); - log::info!( - target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - "fib_10 Verification result {result:?}", - ); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "fib_10 Verification result {result:?}", + // ); assert_eq!(result, U256::one(), "The contract did not return true"); } }, @@ -4904,14 +5095,21 @@ benchmarks! { match call_runner_results { Ok(info) => { let output = info.value; + let used_gas = info.used_gas; + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "copy_10 output result {:?} used_gas: {:?}", + output, + used_gas, + ); if output.len() >= 32 { let mut result_bytes = [0u8; 32]; result_bytes.copy_from_slice(&output[output.len() - 32..]); let result = U256::from_big_endian(&result_bytes); - log::info!( - target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - "copy_10 Verification result {result:?}", - ); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "copy_10 Verification result {result:?}", + // ); assert_eq!(result, U256::one(), "The contract did not return true"); } }, @@ -5130,14 +5328,21 @@ benchmarks! { match call_runner_results { Ok(info) => { let output = info.value; + let used_gas = info.used_gas; + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "copy_20 output result {:?} used_gas: {:?}", + output, + used_gas, + ); if output.len() >= 32 { let mut result_bytes = [0u8; 32]; result_bytes.copy_from_slice(&output[output.len() - 32..]); let result = U256::from_big_endian(&result_bytes); - log::info!( - target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - "copy_20 Verification result {result:?}", - ); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "copy_20 Verification result {result:?}", + // ); assert_eq!(result, U256::one(), "The contract did not return true"); } }, diff --git a/runtime/runtime-common/src/zk_precompile_gas_estimation/tests.rs b/runtime/runtime-common/src/zk_precompile_gas_estimation/tests.rs index 0732baf0..97e5df7b 100644 --- a/runtime/runtime-common/src/zk_precompile_gas_estimation/tests.rs +++ b/runtime/runtime-common/src/zk_precompile_gas_estimation/tests.rs @@ -213,7 +213,8 @@ fn test_zk_precompile_gas_estimation() { match call_runner_results { Ok(info) => { let output = info.value; - println!("output result {output:?}"); + let used_gas = info.used_gas; + println!("output result {output:?} used gas: {used_gas:?}"); if output.len() >= 32 { let mut result_bytes = [0u8; 32]; result_bytes.copy_from_slice(&output[output.len() - 32..]); From 60d10a530b0f6c28b06f4bbfe8ae7f6adc8480ef Mon Sep 17 00:00:00 2001 From: luckychacha <358140284@qq.com> Date: Wed, 16 Aug 2023 01:21:37 +0800 Subject: [PATCH 25/34] Fix action error. --- node/src/benchmarking.rs | 1 - node/src/runtime/mainnet.rs | 1 - node/src/runtime/testnet.rs | 1 - 3 files changed, 3 deletions(-) diff --git a/node/src/benchmarking.rs b/node/src/benchmarking.rs index 1725e75e..f3736576 100644 --- a/node/src/benchmarking.rs +++ b/node/src/benchmarking.rs @@ -23,7 +23,6 @@ use std::{sync::Arc, time::Duration}; use scale_codec::Encode; // Substrate -use ggxchain_runtime::{self as runtime, AccountId, Balance, BalancesCall, SystemCall}; use sc_cli::Result; use sc_client_api::BlockBackend; use sp_core::{sr25519, Pair}; diff --git a/node/src/runtime/mainnet.rs b/node/src/runtime/mainnet.rs index e4251de5..5d5c4b9b 100644 --- a/node/src/runtime/mainnet.rs +++ b/node/src/runtime/mainnet.rs @@ -148,7 +148,6 @@ pub fn testnet_genesis( }, ) }) - .into_iter() .collect(), }, ethereum: Default::default(), diff --git a/node/src/runtime/testnet.rs b/node/src/runtime/testnet.rs index 2db892da..32f1297f 100644 --- a/node/src/runtime/testnet.rs +++ b/node/src/runtime/testnet.rs @@ -114,7 +114,6 @@ pub fn testnet_genesis( }, ) }) - .into_iter() .collect(); map.insert( // H160 address of Alice dev account From 7eb9f363f92d6018ca5d6abbf85ce606b4a48dc3 Mon Sep 17 00:00:00 2001 From: luckychacha <358140284@qq.com> Date: Wed, 16 Aug 2023 11:42:15 +0800 Subject: [PATCH 26/34] Optimize benchmarking code. --- node/Cargo.toml | 2 +- node/src/benchmarking.rs | 6 +- .../benchmarking.rs | 635 +++++++++--------- 3 files changed, 305 insertions(+), 338 deletions(-) diff --git a/node/Cargo.toml b/node/Cargo.toml index 3d5bed59..c9af956b 100644 --- a/node/Cargo.toml +++ b/node/Cargo.toml @@ -76,8 +76,8 @@ fp-evm = { workspace = true, features = ["std"] } fp-rpc = { workspace = true, features = ["std"] } fp-storage = { workspace = true, features = ["std"] } -ggxchain-runtime-sydney = { workspace = true, features = ["std"] } ggxchain-runtime-brooklyn = { workspace = true, features = ["std"], optional = true } +ggxchain-runtime-sydney = { workspace = true, features = ["std"] } [dev-dependencies] assert_cmd = { workspace = true } diff --git a/node/src/benchmarking.rs b/node/src/benchmarking.rs index f3736576..0ac52ce1 100644 --- a/node/src/benchmarking.rs +++ b/node/src/benchmarking.rs @@ -155,7 +155,9 @@ pub fn create_benchmark_extrinsic( )), frame_system::CheckNonce::::from(nonce), frame_system::CheckWeight::::new(), - pallet_transaction_payment::ChargeTransactionPayment::::from(0), + (pallet_transaction_payment::ChargeTransactionPayment::< + runtime::Runtime, + >::from(0),), ); let raw_payload = runtime::SignedPayload::from_raw( @@ -169,7 +171,7 @@ pub fn create_benchmark_extrinsic( best_hash, (), (), - (), + ((),), ), ); let signature = raw_payload.using_encoded(|e| sender.sign(e)); diff --git a/runtime/runtime-common/src/zk_precompile_gas_estimation/benchmarking.rs b/runtime/runtime-common/src/zk_precompile_gas_estimation/benchmarking.rs index c253d1c6..98f64d6f 100644 --- a/runtime/runtime-common/src/zk_precompile_gas_estimation/benchmarking.rs +++ b/runtime/runtime-common/src/zk_precompile_gas_estimation/benchmarking.rs @@ -306,24 +306,22 @@ benchmarks! { output, used_gas, ); - if output.len() >= 32 { - let mut result_bytes = [0u8; 32]; - result_bytes.copy_from_slice(&output[output.len() - 32..]); - let result = U256::from_big_endian(&result_bytes); - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "nconstraints_10 Verification result {result:?}", - // ); - assert_eq!(result, U256::one(), "The contract did not return true"); - } + assert!(output.len() >= 32, "The contract did not return true"); + let mut result_bytes = [0u8; 32]; + result_bytes.copy_from_slice(&output[output.len() - 32..]); + let result = U256::from_big_endian(&result_bytes); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "nconstraints_10 Verification result {result:?}", + // ); + assert_eq!(result, U256::one(), "The contract did not return true"); }, Err(e) => { log::info!( target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", "nconstraints_10 Benchmarking failed", ); - assert!(false, "Benchmarking failed"); - + panic!("nconstraints_10 Benchmarking failed"); } } } @@ -457,24 +455,22 @@ benchmarks! { // "output result {:?}", // output // ); - if output.len() >= 32 { - let mut result_bytes = [0u8; 32]; - result_bytes.copy_from_slice(&output[output.len() - 32..]); - let result = U256::from_big_endian(&result_bytes); - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "nconstraints_50 Verification result {result:?}", - // ); - assert_eq!(result, U256::one(), "The contract did not return true"); - } + assert!(output.len() >= 32, "The contract did not return true"); + let mut result_bytes = [0u8; 32]; + result_bytes.copy_from_slice(&output[output.len() - 32..]); + let result = U256::from_big_endian(&result_bytes); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "nconstraints_50 Verification result {result:?}", + // ); + assert_eq!(result, U256::one(), "The contract did not return true"); }, Err(e) => { log::info!( target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", "nconstraints_50 Benchmarking failed", ); - assert!(false, "Benchmarking failed"); - + panic!("nconstraints_50 Benchmarking failed"); } } } @@ -608,24 +604,22 @@ benchmarks! { // "output result {:?}", // output // ); - if output.len() >= 32 { - let mut result_bytes = [0u8; 32]; - result_bytes.copy_from_slice(&output[output.len() - 32..]); - let result = U256::from_big_endian(&result_bytes); - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "nconstraints_1000 Verification result {result:?}", - // ); - assert_eq!(result, U256::one(), "The contract did not return true"); - } + assert!(output.len() >= 32, "The contract did not return true"); + let mut result_bytes = [0u8; 32]; + result_bytes.copy_from_slice(&output[output.len() - 32..]); + let result = U256::from_big_endian(&result_bytes); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "nconstraints_1000 Verification result {result:?}", + // ); + assert_eq!(result, U256::one(), "The contract did not return true"); }, Err(e) => { log::info!( target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", "nconstraints_1000 Benchmarking failed", ); - assert!(false, "Benchmarking failed"); - + panic!("nconstraints_1000 Benchmarking failed"); } } } @@ -758,24 +752,22 @@ benchmarks! { // "output result {:?}", // output // ); - if output.len() >= 32 { - let mut result_bytes = [0u8; 32]; - result_bytes.copy_from_slice(&output[output.len() - 32..]); - let result = U256::from_big_endian(&result_bytes); - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "nconstraints_900000 Verification result {result:?}", - // ); - assert_eq!(result, U256::one(), "The contract did not return true"); - } + assert!(output.len() >= 32, "The contract did not return true"); + let mut result_bytes = [0u8; 32]; + result_bytes.copy_from_slice(&output[output.len() - 32..]); + let result = U256::from_big_endian(&result_bytes); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "nconstraints_900000 Verification result {result:?}", + // ); + assert_eq!(result, U256::one(), "The contract did not return true"); }, Err(e) => { log::info!( target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", "nconstraints_900000 Benchmarking failed", ); - assert!(false, "Benchmarking failed"); - + panic!("nconstraints_900000 Benchmarking failed"); } } } @@ -909,24 +901,22 @@ benchmarks! { // "output result {:?}", // output // ); - if output.len() >= 32 { - let mut result_bytes = [0u8; 32]; - result_bytes.copy_from_slice(&output[output.len() - 32..]); - let result = U256::from_big_endian(&result_bytes); - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "nconstraints_30_input_10 Verification result {result:?}", - // ); - assert_eq!(result, U256::one(), "The contract did not return true"); - } + assert!(output.len() >= 32, "The contract did not return true"); + let mut result_bytes = [0u8; 32]; + result_bytes.copy_from_slice(&output[output.len() - 32..]); + let result = U256::from_big_endian(&result_bytes); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "nconstraints_30_input_10 Verification result {result:?}", + // ); + assert_eq!(result, U256::one(), "The contract did not return true"); }, Err(e) => { log::info!( target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", "nconstraints_30_input_10 Benchmarking failed", ); - assert!(false, "Benchmarking failed"); - + panic!("nconstraints_30_input_10 Benchmarking failed"); } } } @@ -1059,23 +1049,22 @@ benchmarks! { // "output result {:?}", // output // ); - if output.len() >= 32 { - let mut result_bytes = [0u8; 32]; - result_bytes.copy_from_slice(&output[output.len() - 32..]); - let result = U256::from_big_endian(&result_bytes); - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "nconstraints_30_input_100 Verification result {result:?}", - // ); - assert_eq!(result, U256::one(), "The contract did not return true"); - } + assert!(output.len() >= 32, "The contract did not return true"); + let mut result_bytes = [0u8; 32]; + result_bytes.copy_from_slice(&output[output.len() - 32..]); + let result = U256::from_big_endian(&result_bytes); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "nconstraints_30_input_100 Verification result {result:?}", + // ); + assert_eq!(result, U256::one(), "The contract did not return true"); }, Err(e) => { log::info!( target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", "nconstraints_30_input_100 Benchmarking failed", ); - assert!(false, "Benchmarking failed"); + panic!("nconstraints_30_input_100 Benchmarking failed"); } } } @@ -1208,23 +1197,22 @@ benchmarks! { // "output result {:?}", // output // ); - if output.len() >= 32 { - let mut result_bytes = [0u8; 32]; - result_bytes.copy_from_slice(&output[output.len() - 32..]); - let result = U256::from_big_endian(&result_bytes); - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "nconstraints_30_input_1000 Verification result {result:?}", - // ); - assert_eq!(result, U256::one(), "The contract did not return true"); - } + assert!(output.len() >= 32, "The contract did not return true"); + let mut result_bytes = [0u8; 32]; + result_bytes.copy_from_slice(&output[output.len() - 32..]); + let result = U256::from_big_endian(&result_bytes); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "nconstraints_30_input_1000 Verification result {result:?}", + // ); + assert_eq!(result, U256::one(), "The contract did not return true"); }, Err(e) => { log::info!( target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", "nconstraints_30_input_1000 Benchmarking failed", ); - assert!(false, "Benchmarking failed"); + panic!("nconstraints_30_input_1000 Benchmarking failed"); } } } @@ -1357,23 +1345,22 @@ benchmarks! { // "output result {:?}", // output // ); - if output.len() >= 32 { - let mut result_bytes = [0u8; 32]; - result_bytes.copy_from_slice(&output[output.len() - 32..]); - let result = U256::from_big_endian(&result_bytes); - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "nconstraints_30_input_5000 Verification result {result:?}", - // ); - assert_eq!(result, U256::one(), "The contract did not return true"); - } + assert!(output.len() >= 32, "The contract did not return true"); + let mut result_bytes = [0u8; 32]; + result_bytes.copy_from_slice(&output[output.len() - 32..]); + let result = U256::from_big_endian(&result_bytes); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "nconstraints_30_input_5000 Verification result {result:?}", + // ); + assert_eq!(result, U256::one(), "The contract did not return true"); }, Err(e) => { log::info!( target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", "nconstraints_30_input_5000 Benchmarking failed", ); - assert!(false, "Benchmarking failed"); + panic!("nconstraints_30_input_5000 Benchmarking failed"); } } } @@ -1506,23 +1493,22 @@ benchmarks! { // "output result {:?}", // output // ); - if output.len() >= 32 { - let mut result_bytes = [0u8; 32]; - result_bytes.copy_from_slice(&output[output.len() - 32..]); - let result = U256::from_big_endian(&result_bytes); - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "nconstraints_30_input_10000 Verification result {result:?}", - // ); - assert_eq!(result, U256::one(), "The contract did not return true"); - } + assert!(output.len() >= 32, "The contract did not return true"); + let mut result_bytes = [0u8; 32]; + result_bytes.copy_from_slice(&output[output.len() - 32..]); + let result = U256::from_big_endian(&result_bytes); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "nconstraints_30_input_10000 Verification result {result:?}", + // ); + assert_eq!(result, U256::one(), "The contract did not return true"); }, Err(e) => { log::info!( target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", "nconstraints_30_input_10000 Benchmarking failed", ); - assert!(false, "Benchmarking failed"); + panic!("nconstraints_30_input_10000 Benchmarking failed"); } } @@ -1656,23 +1642,22 @@ benchmarks! { // "output result {:?}", // output // ); - if output.len() >= 32 { - let mut result_bytes = [0u8; 32]; - result_bytes.copy_from_slice(&output[output.len() - 32..]); - let result = U256::from_big_endian(&result_bytes); - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "nconstraints_30_input_90000 Verification result {result:?}", - // ); - assert_eq!(result, U256::one(), "The contract did not return true"); - } + assert!(output.len() >= 32, "The contract did not return true"); + let mut result_bytes = [0u8; 32]; + result_bytes.copy_from_slice(&output[output.len() - 32..]); + let result = U256::from_big_endian(&result_bytes); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "nconstraints_30_input_90000 Verification result {result:?}", + // ); + assert_eq!(result, U256::one(), "The contract did not return true"); }, Err(e) => { log::info!( target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", "nconstraints_30_input_90000 Benchmarking failed", ); - assert!(false, "Benchmarking failed"); + panic!("nconstraints_30_input_90000 Benchmarking failed"); } } } @@ -1805,23 +1790,22 @@ benchmarks! { // "output result {:?}", // output // ); - if output.len() >= 32 { - let mut result_bytes = [0u8; 32]; - result_bytes.copy_from_slice(&output[output.len() - 32..]); - let result = U256::from_big_endian(&result_bytes); - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "nconstraints_30_input_200000 Verification result {result:?}", - // ); - assert_eq!(result, U256::one(), "The contract did not return true"); - } + assert!(output.len() >= 32, "The contract did not return true"); + let mut result_bytes = [0u8; 32]; + result_bytes.copy_from_slice(&output[output.len() - 32..]); + let result = U256::from_big_endian(&result_bytes); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "nconstraints_30_input_200000 Verification result {result:?}", + // ); + assert_eq!(result, U256::one(), "The contract did not return true"); }, Err(e) => { log::info!( target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", "nconstraints_30_input_200000 Benchmarking failed", ); - assert!(false, "Benchmarking failed"); + panic!("nconstraints_30_input_200000 Benchmarking failed"); } } } @@ -1952,23 +1936,22 @@ benchmarks! { // "output result {:?}", // output // ); - if output.len() >= 32 { - let mut result_bytes = [0u8; 32]; - result_bytes.copy_from_slice(&output[output.len() - 32..]); - let result = U256::from_big_endian(&result_bytes); - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "sum_10 Verification result {result:?}", - // ); - assert_eq!(result, U256::one(), "The contract did not return true"); - } + assert!(output.len() >= 32, "The contract did not return true"); + let mut result_bytes = [0u8; 32]; + result_bytes.copy_from_slice(&output[output.len() - 32..]); + let result = U256::from_big_endian(&result_bytes); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "sum_10 Verification result {result:?}", + // ); + assert_eq!(result, U256::one(), "The contract did not return true"); }, Err(e) => { log::info!( target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", "sum_10 Benchmarking failed", ); - assert!(false, "Benchmarking failed"); + panic!("sum_10 Benchmarking failed"); } } } @@ -2098,23 +2081,22 @@ benchmarks! { // "output result {:?}", // output // ); - if output.len() >= 32 { - let mut result_bytes = [0u8; 32]; - result_bytes.copy_from_slice(&output[output.len() - 32..]); - let result = U256::from_big_endian(&result_bytes); - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "sum_50 Verification result {result:?}", - // ); - assert_eq!(result, U256::one(), "The contract did not return true"); - } + assert!(output.len() >= 32, "The contract did not return true"); + let mut result_bytes = [0u8; 32]; + result_bytes.copy_from_slice(&output[output.len() - 32..]); + let result = U256::from_big_endian(&result_bytes); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "sum_50 Verification result {result:?}", + // ); + assert_eq!(result, U256::one(), "The contract did not return true"); }, Err(e) => { log::info!( target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", "sum_50 Benchmarking failed", ); - assert!(false, "Benchmarking failed"); + panic!("sum_50 Benchmarking failed"); } } } @@ -2245,23 +2227,22 @@ benchmarks! { // "output result {:?}", // output // ); - if output.len() >= 32 { - let mut result_bytes = [0u8; 32]; - result_bytes.copy_from_slice(&output[output.len() - 32..]); - let result = U256::from_big_endian(&result_bytes); - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "sum_5000 Verification result {result:?}", - // ); - assert_eq!(result, U256::one(), "The contract did not return true"); - } + assert!(output.len() >= 32, "The contract did not return true"); + let mut result_bytes = [0u8; 32]; + result_bytes.copy_from_slice(&output[output.len() - 32..]); + let result = U256::from_big_endian(&result_bytes); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "sum_5000 Verification result {result:?}", + // ); + assert_eq!(result, U256::one(), "The contract did not return true"); }, Err(e) => { log::info!( target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", "sum_5000 Benchmarking failed", ); - assert!(false, "Benchmarking failed"); + panic!("sum_5000 Benchmarking failed"); } } } @@ -2390,23 +2371,22 @@ benchmarks! { // "output result {:?}", // output // ); - if output.len() >= 32 { - let mut result_bytes = [0u8; 32]; - result_bytes.copy_from_slice(&output[output.len() - 32..]); - let result = U256::from_big_endian(&result_bytes); - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "sum_50000 Verification result {result:?}", - // ); - assert_eq!(result, U256::one(), "The contract did not return true"); - } + assert!(output.len() >= 32, "The contract did not return true"); + let mut result_bytes = [0u8; 32]; + result_bytes.copy_from_slice(&output[output.len() - 32..]); + let result = U256::from_big_endian(&result_bytes); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "sum_50000 Verification result {result:?}", + // ); + assert_eq!(result, U256::one(), "The contract did not return true"); }, Err(e) => { log::info!( target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", "sum_50000 Benchmarking failed", ); - assert!(false, "Benchmarking failed"); + panic!("sum_50000 Benchmarking failed"); } } } @@ -2528,23 +2508,22 @@ benchmarks! { output, used_gas, ); - if output.len() >= 32 { - let mut result_bytes = [0u8; 32]; - result_bytes.copy_from_slice(&output[output.len() - 32..]); - let result = U256::from_big_endian(&result_bytes); - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "sumout_1 Verification result {result:?}", - // ); - assert_eq!(result, U256::one(), "The contract did not return true"); - } + assert!(output.len() >= 32, "The contract did not return true"); + let mut result_bytes = [0u8; 32]; + result_bytes.copy_from_slice(&output[output.len() - 32..]); + let result = U256::from_big_endian(&result_bytes); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "sumout_1 Verification result {result:?}", + // ); + assert_eq!(result, U256::one(), "The contract did not return true"); }, Err(e) => { log::info!( target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", "sumout_1 Benchmarking failed", ); - assert!(false, "Benchmarking failed"); + panic!("sumout_1 Benchmarking failed"); } } } @@ -2676,23 +2655,22 @@ benchmarks! { output, used_gas, ); - if output.len() >= 32 { - let mut result_bytes = [0u8; 32]; - result_bytes.copy_from_slice(&output[output.len() - 32..]); - let result = U256::from_big_endian(&result_bytes); - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "sumout_3 Verification result {result:?}", - // ); - assert_eq!(result, U256::one(), "The contract did not return true"); - } + assert!(output.len() >= 32, "The contract did not return true"); + let mut result_bytes = [0u8; 32]; + result_bytes.copy_from_slice(&output[output.len() - 32..]); + let result = U256::from_big_endian(&result_bytes); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "sumout_3 Verification result {result:?}", + // ); + assert_eq!(result, U256::one(), "The contract did not return true"); }, Err(e) => { log::info!( target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", "sumout_3 Benchmarking failed", ); - assert!(false, "Benchmarking failed"); + panic!("sumout_3 Benchmarking failed"); } } } @@ -2834,23 +2812,22 @@ benchmarks! { output, used_gas, ); - if output.len() >= 32 { - let mut result_bytes = [0u8; 32]; - result_bytes.copy_from_slice(&output[output.len() - 32..]); - let result = U256::from_big_endian(&result_bytes); - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "sumout_5 Verification result {result:?}", - // ); - assert_eq!(result, U256::one(), "The contract did not return true"); - } + assert!(output.len() >= 32, "The contract did not return true"); + let mut result_bytes = [0u8; 32]; + result_bytes.copy_from_slice(&output[output.len() - 32..]); + let result = U256::from_big_endian(&result_bytes); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "sumout_5 Verification result {result:?}", + // ); + assert_eq!(result, U256::one(), "The contract did not return true"); }, Err(e) => { log::info!( target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", "sumout_5 Benchmarking failed", ); - assert!(false, "Benchmarking failed"); + panic!("sumout_5 Benchmarking failed"); } } } @@ -3007,23 +2984,22 @@ benchmarks! { output, used_gas, ); - if output.len() >= 32 { - let mut result_bytes = [0u8; 32]; - result_bytes.copy_from_slice(&output[output.len() - 32..]); - let result = U256::from_big_endian(&result_bytes); - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "sumout_8 Verification result {result:?}", - // ); - assert_eq!(result, U256::one(), "The contract did not return true"); - } + assert!(output.len() >= 32, "The contract did not return true"); + let mut result_bytes = [0u8; 32]; + result_bytes.copy_from_slice(&output[output.len() - 32..]); + let result = U256::from_big_endian(&result_bytes); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "sumout_8 Verification result {result:?}", + // ); + assert_eq!(result, U256::one(), "The contract did not return true"); }, Err(e) => { log::info!( target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", "sumout_8 Benchmarking failed", ); - assert!(false, "Benchmarking failed"); + panic!("sumout_8 Benchmarking failed"); } } } @@ -3190,23 +3166,22 @@ benchmarks! { output, used_gas, ); - if output.len() >= 32 { - let mut result_bytes = [0u8; 32]; - result_bytes.copy_from_slice(&output[output.len() - 32..]); - let result = U256::from_big_endian(&result_bytes); - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "sumout_10 Verification result {result:?}", - // ); - assert_eq!(result, U256::one(), "The contract did not return true"); - } + assert!(output.len() >= 32, "The contract did not return true"); + let mut result_bytes = [0u8; 32]; + result_bytes.copy_from_slice(&output[output.len() - 32..]); + let result = U256::from_big_endian(&result_bytes); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "sumout_10 Verification result {result:?}", + // ); + assert_eq!(result, U256::one(), "The contract did not return true"); }, Err(e) => { log::info!( target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", "sumout_10 Benchmarking failed", ); - assert!(false, "Benchmarking failed"); + panic!("sumout_10 Benchmarking failed"); } } } @@ -3383,23 +3358,22 @@ benchmarks! { output, used_gas, ); - if output.len() >= 32 { - let mut result_bytes = [0u8; 32]; - result_bytes.copy_from_slice(&output[output.len() - 32..]); - let result = U256::from_big_endian(&result_bytes); - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "sumout_12 Verification result {result:?}", - // ); - assert_eq!(result, U256::one(), "The contract did not return true"); - } + assert!(output.len() >= 32, "The contract did not return true"); + let mut result_bytes = [0u8; 32]; + result_bytes.copy_from_slice(&output[output.len() - 32..]); + let result = U256::from_big_endian(&result_bytes); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "sumout_12 Verification result {result:?}", + // ); + assert_eq!(result, U256::one(), "The contract did not return true"); }, Err(e) => { log::info!( target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", "sumout_12 Benchmarking failed", ); - assert!(false, "Benchmarking failed"); + panic!("sumout_12 Benchmarking failed"); } } } @@ -3591,23 +3565,22 @@ benchmarks! { output, used_gas, ); - if output.len() >= 32 { - let mut result_bytes = [0u8; 32]; - result_bytes.copy_from_slice(&output[output.len() - 32..]); - let result = U256::from_big_endian(&result_bytes); - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "sumout_15 Verification result {result:?}", - // ); - assert_eq!(result, U256::one(), "The contract did not return true"); - } + assert!(output.len() >= 32, "The contract did not return true"); + let mut result_bytes = [0u8; 32]; + result_bytes.copy_from_slice(&output[output.len() - 32..]); + let result = U256::from_big_endian(&result_bytes); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "sumout_15 Verification result {result:?}", + // ); + assert_eq!(result, U256::one(), "The contract did not return true"); }, Err(e) => { log::info!( target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", "sumout_15 Benchmarking failed", ); - assert!(false, "Benchmarking failed"); + panic!("sumout_15 Benchmarking failed"); } } } @@ -3814,23 +3787,22 @@ benchmarks! { output, used_gas, ); - if output.len() >= 32 { - let mut result_bytes = [0u8; 32]; - result_bytes.copy_from_slice(&output[output.len() - 32..]); - let result = U256::from_big_endian(&result_bytes); - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "sumout_18 Verification result {result:?}", - // ); - assert_eq!(result, U256::one(), "The contract did not return true"); - } + assert!(output.len() >= 32, "The contract did not return true"); + let mut result_bytes = [0u8; 32]; + result_bytes.copy_from_slice(&output[output.len() - 32..]); + let result = U256::from_big_endian(&result_bytes); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "sumout_18 Verification result {result:?}", + // ); + assert_eq!(result, U256::one(), "The contract did not return true"); }, Err(e) => { log::info!( target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", "sumout_18 Benchmarking failed", ); - assert!(false, "Benchmarking failed"); + panic!("sumout_18 Benchmarking failed"); } } } @@ -4047,23 +4019,22 @@ benchmarks! { output, used_gas, ); - if output.len() >= 32 { - let mut result_bytes = [0u8; 32]; - result_bytes.copy_from_slice(&output[output.len() - 32..]); - let result = U256::from_big_endian(&result_bytes); - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "sumout_20 Verification result {result:?}", - // ); - assert_eq!(result, U256::one(), "The contract did not return true"); - } + assert!(output.len() >= 32, "The contract did not return true"); + let mut result_bytes = [0u8; 32]; + result_bytes.copy_from_slice(&output[output.len() - 32..]); + let result = U256::from_big_endian(&result_bytes); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "sumout_20 Verification result {result:?}", + // ); + assert_eq!(result, U256::one(), "The contract did not return true"); }, Err(e) => { log::info!( target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", "sumout_20 Benchmarking failed", ); - assert!(false, "Benchmarking failed"); + panic!("sumout_20 Benchmarking failed"); } } } @@ -4430,23 +4401,22 @@ benchmarks! { output, used_gas, ); - if output.len() >= 32 { - let mut result_bytes = [0u8; 32]; - result_bytes.copy_from_slice(&output[output.len() - 32..]); - let result = U256::from_big_endian(&result_bytes); - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "sumout_50 Verification result {result:?}", - // ); - assert_eq!(result, U256::one(), "The contract did not return true"); - } + assert!(output.len() >= 32, "The contract did not return true"); + let mut result_bytes = [0u8; 32]; + result_bytes.copy_from_slice(&output[output.len() - 32..]); + let result = U256::from_big_endian(&result_bytes); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "sumout_50 Verification result {result:?}", + // ); + assert_eq!(result, U256::one(), "The contract did not return true"); }, Err(e) => { log::info!( target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", "sumout_50 Benchmarking failed", ); - assert!(false, "Benchmarking failed"); + panic!("sumout_50 Benchmarking failed"); } } } @@ -4578,23 +4548,22 @@ benchmarks! { output, used_gas, ); - if output.len() >= 32 { - let mut result_bytes = [0u8; 32]; - result_bytes.copy_from_slice(&output[output.len() - 32..]); - let result = U256::from_big_endian(&result_bytes); - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "fib_3 Verification result {result:?}", - // ); - assert_eq!(result, U256::one(), "The contract did not return true"); - } + assert!(output.len() >= 32, "The contract did not return true"); + let mut result_bytes = [0u8; 32]; + result_bytes.copy_from_slice(&output[output.len() - 32..]); + let result = U256::from_big_endian(&result_bytes); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "fib_3 Verification result {result:?}", + // ); + assert_eq!(result, U256::one(), "The contract did not return true"); }, Err(e) => { log::info!( target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", "fib_3 Benchmarking failed", ); - assert!(false, "Benchmarking failed"); + panic!("fib_3 Benchmarking failed"); } } } @@ -4736,23 +4705,22 @@ benchmarks! { output, used_gas, ); - if output.len() >= 32 { - let mut result_bytes = [0u8; 32]; - result_bytes.copy_from_slice(&output[output.len() - 32..]); - let result = U256::from_big_endian(&result_bytes); - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "fib_5 Verification result {result:?}", - // ); - assert_eq!(result, U256::one(), "The contract did not return true"); - } + assert!(output.len() >= 32, "The contract did not return true"); + let mut result_bytes = [0u8; 32]; + result_bytes.copy_from_slice(&output[output.len() - 32..]); + let result = U256::from_big_endian(&result_bytes); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "fib_5 Verification result {result:?}", + // ); + assert_eq!(result, U256::one(), "The contract did not return true"); }, Err(e) => { log::info!( target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", "fib_5 Benchmarking failed", ); - assert!(false, "Benchmarking failed"); + panic!("fib_5 Benchmarking failed"); } } } @@ -4919,23 +4887,22 @@ benchmarks! { output, used_gas, ); - if output.len() >= 32 { - let mut result_bytes = [0u8; 32]; - result_bytes.copy_from_slice(&output[output.len() - 32..]); - let result = U256::from_big_endian(&result_bytes); - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "fib_10 Verification result {result:?}", - // ); - assert_eq!(result, U256::one(), "The contract did not return true"); - } + assert!(output.len() >= 32, "The contract did not return true"); + let mut result_bytes = [0u8; 32]; + result_bytes.copy_from_slice(&output[output.len() - 32..]); + let result = U256::from_big_endian(&result_bytes); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "fib_10 Verification result {result:?}", + // ); + assert_eq!(result, U256::one(), "The contract did not return true"); }, Err(e) => { log::info!( target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", "fib_10 Benchmarking failed", ); - assert!(false, "Benchmarking failed"); + panic!("fib_10 Benchmarking failed"); } } } @@ -5102,23 +5069,22 @@ benchmarks! { output, used_gas, ); - if output.len() >= 32 { - let mut result_bytes = [0u8; 32]; - result_bytes.copy_from_slice(&output[output.len() - 32..]); - let result = U256::from_big_endian(&result_bytes); - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "copy_10 Verification result {result:?}", - // ); - assert_eq!(result, U256::one(), "The contract did not return true"); - } + assert!(output.len() >= 32, "The contract did not return true"); + let mut result_bytes = [0u8; 32]; + result_bytes.copy_from_slice(&output[output.len() - 32..]); + let result = U256::from_big_endian(&result_bytes); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "copy_10 Verification result {result:?}", + // ); + assert_eq!(result, U256::one(), "The contract did not return true"); }, Err(e) => { log::info!( target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", "copy_10 Benchmarking failed", ); - assert!(false, "Benchmarking failed"); + panic!("copy_10 Benchmarking failed"); } } } @@ -5335,23 +5301,22 @@ benchmarks! { output, used_gas, ); - if output.len() >= 32 { - let mut result_bytes = [0u8; 32]; - result_bytes.copy_from_slice(&output[output.len() - 32..]); - let result = U256::from_big_endian(&result_bytes); - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "copy_20 Verification result {result:?}", - // ); - assert_eq!(result, U256::one(), "The contract did not return true"); - } + assert!(output.len() >= 32, "The contract did not return true"); + let mut result_bytes = [0u8; 32]; + result_bytes.copy_from_slice(&output[output.len() - 32..]); + let result = U256::from_big_endian(&result_bytes); + // log::info!( + // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + // "copy_20 Verification result {result:?}", + // ); + assert_eq!(result, U256::one(), "The contract did not return true"); }, Err(e) => { log::info!( target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", "copy_20 Benchmarking failed", ); - assert!(false, "Benchmarking failed"); + panic!("copy_20 Benchmarking failed"); } } } From 96a1cd5170df038e17da2f792810311dd0b34d1f Mon Sep 17 00:00:00 2001 From: luckychacha <358140284@qq.com> Date: Wed, 16 Aug 2023 15:00:55 +0800 Subject: [PATCH 27/34] Fix code. --- node/src/benchmarking.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/node/src/benchmarking.rs b/node/src/benchmarking.rs index 0ac52ce1..f3736576 100644 --- a/node/src/benchmarking.rs +++ b/node/src/benchmarking.rs @@ -155,9 +155,7 @@ pub fn create_benchmark_extrinsic( )), frame_system::CheckNonce::::from(nonce), frame_system::CheckWeight::::new(), - (pallet_transaction_payment::ChargeTransactionPayment::< - runtime::Runtime, - >::from(0),), + pallet_transaction_payment::ChargeTransactionPayment::::from(0), ); let raw_payload = runtime::SignedPayload::from_raw( @@ -171,7 +169,7 @@ pub fn create_benchmark_extrinsic( best_hash, (), (), - ((),), + (), ), ); let signature = raw_payload.using_encoded(|e| sender.sign(e)); From 813e2f7274e4a0295ceee6235fa8a3c64495e474 Mon Sep 17 00:00:00 2001 From: luckychacha <358140284@qq.com> Date: Wed, 16 Aug 2023 16:42:04 +0800 Subject: [PATCH 28/34] Compatibility with different runtime::SignedExtra for Sydney and Brooklyn. --- Cargo.toml | 2 +- node/src/benchmarking.rs | 13 ++++++++++--- precompiles/zk-groth16-verify/src/lib.rs | 2 +- .../zk_precompile_gas_estimation/benchmarking.rs | 14 -------------- .../src/zk_precompile_gas_estimation/mock.rs | 13 ++----------- .../src/zk_precompile_gas_estimation/mod.rs | 16 ++++++++++++++++ .../src/zk_precompile_gas_estimation/tests.rs | 11 +---------- 7 files changed, 31 insertions(+), 40 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9abe24df..ceb39fc1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -161,7 +161,7 @@ fc-rpc-core = { version = "1.1.0-dev", git = "https://github.com/AstarNetwork/fr # Frontier Primitive fc-storage = { version = "1.0.0-dev", git = "https://github.com/AstarNetwork/frontier.git", branch = "polkadot-v0.9.40", default-features = false } -fp-account = { git = "https://github.com/AstarNetwork/frontier.git", branch = "polkadot-v0.9.40", default-features = false } +fp-account = { version = "1.0.0-dev", git = "https://github.com/AstarNetwork/frontier.git", branch = "polkadot-v0.9.40", default-features = false } fp-dynamic-fee = { version = "1.0.0", git = "https://github.com/AstarNetwork/frontier.git", branch = "polkadot-v0.9.40", default-features = false } fp-evm = { version = "3.0.0-dev", git = "https://github.com/AstarNetwork/frontier.git", branch = "polkadot-v0.9.40", default-features = false } fp-rpc = { version = "3.0.0-dev", git = "https://github.com/AstarNetwork/frontier.git", branch = "polkadot-v0.9.40", default-features = false } diff --git a/node/src/benchmarking.rs b/node/src/benchmarking.rs index f3736576..22c17b82 100644 --- a/node/src/benchmarking.rs +++ b/node/src/benchmarking.rs @@ -29,14 +29,12 @@ use sp_core::{sr25519, Pair}; use sp_inherents::{InherentData, InherentDataProvider}; use sp_keyring::Sr25519Keyring; use sp_runtime::{generic::Era, AccountId32, OpaqueExtrinsic, SaturatedConversion}; -// Frontier + #[cfg(feature = "brooklyn")] use ggxchain_runtime_brooklyn::{self as runtime, AccountId, Balance, BalancesCall, SystemCall}; #[cfg(not(feature = "brooklyn"))] use ggxchain_runtime_sydney::{self as runtime, AccountId, Balance, BalancesCall, SystemCall}; -// use golden_gate_runtime::{self as runtime, AccountId, Balance, BalancesCall, SystemCall}; - use crate::service::FullClient; /// Generates extrinsics for the `benchmark overhead` command. @@ -144,6 +142,7 @@ pub fn create_benchmark_extrinsic( .checked_next_power_of_two() .map(|c| c / 2) .unwrap_or(2) as u64; + let extra: runtime::SignedExtra = ( //frame_system::CheckNonZeroSender::::new(), frame_system::CheckSpecVersion::::new(), @@ -155,7 +154,12 @@ pub fn create_benchmark_extrinsic( )), frame_system::CheckNonce::::from(nonce), frame_system::CheckWeight::::new(), + #[cfg(feature = "brooklyn")] pallet_transaction_payment::ChargeTransactionPayment::::from(0), + #[cfg(not(feature = "brooklyn"))] + (pallet_transaction_payment::ChargeTransactionPayment::< + runtime::Runtime, + >::from(0),), ); let raw_payload = runtime::SignedPayload::from_raw( @@ -169,7 +173,10 @@ pub fn create_benchmark_extrinsic( best_hash, (), (), + #[cfg(feature = "brooklyn")] (), + #[cfg(not(feature = "brooklyn"))] + ((),), ), ); let signature = raw_payload.using_encoded(|e| sender.sign(e)); diff --git a/precompiles/zk-groth16-verify/src/lib.rs b/precompiles/zk-groth16-verify/src/lib.rs index 48e63222..6d608b56 100644 --- a/precompiles/zk-groth16-verify/src/lib.rs +++ b/precompiles/zk-groth16-verify/src/lib.rs @@ -79,7 +79,7 @@ impl ZKGroth16Verify { // Read the offset of vk_ic and skip the length field let vk_ic_offset = U256::from_big_endian(next()).low_u32() as usize + 32; - // Read the offset of input + // Read the offset of input and skip the length field let input_offset = U256::from_big_endian(next()).low_u32() as usize + 32; // Read the vk_ic array diff --git a/runtime/runtime-common/src/zk_precompile_gas_estimation/benchmarking.rs b/runtime/runtime-common/src/zk_precompile_gas_estimation/benchmarking.rs index 98f64d6f..433902f1 100644 --- a/runtime/runtime-common/src/zk_precompile_gas_estimation/benchmarking.rs +++ b/runtime/runtime-common/src/zk_precompile_gas_estimation/benchmarking.rs @@ -167,20 +167,6 @@ impl ZKPrecompileVerifier { } } -fn u64s_to_u256(values: Vec) -> U256 { - let mut result = U256::zero(); - for (i, value) in values.into_iter().enumerate().take(4) { - let shift = i * 64; - result |= U256::from(value) << shift; - } - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "u64s_to_u256 result {:?}", - // result - // ); - result -} - benchmarks! { nconstraints_10 { use frame_benchmarking::vec; diff --git a/runtime/runtime-common/src/zk_precompile_gas_estimation/mock.rs b/runtime/runtime-common/src/zk_precompile_gas_estimation/mock.rs index ee7fd9d4..30f5d3a6 100644 --- a/runtime/runtime-common/src/zk_precompile_gas_estimation/mock.rs +++ b/runtime/runtime-common/src/zk_precompile_gas_estimation/mock.rs @@ -5,18 +5,13 @@ use pallet_evm::{ PrecompileSet, }; use pallet_evm_precompile_zk_groth16_verify::ZKGroth16Verify; -use sp_core::{ConstU32, H160, H256, U256}; +use sp_core::{ConstU32, ConstU64, H160, H256, U256}; use sp_runtime::{ generic, traits::{BlakeTwo256, IdentityLookup}, }; use sp_std::marker::PhantomData; -/// Constant values used within the runtime. -pub const MILLIGGX: Balance = 1_000_000_000_000_000; -pub const GGX: Balance = 1000 * MILLIGGX; -pub const EXISTENTIAL_DEPOSIT: Balance = 0; - #[cfg(not(feature = "brooklyn"))] pub const CHAIN_ID: u64 = 8866u64; #[cfg(feature = "brooklyn")] @@ -69,16 +64,12 @@ impl pallet_timestamp::Config for Test { type WeightInfo = (); } -parameter_types! { - pub const ExistentialDeposit: u64 = EXISTENTIAL_DEPOSIT; -} - impl pallet_balances::Config for Test { type RuntimeEvent = RuntimeEvent; type WeightInfo = (); type Balance = Balance; type DustRemoval = (); - type ExistentialDeposit = ExistentialDeposit; + type ExistentialDeposit = ConstU64<2>; type AccountStore = System; type ReserveIdentifier = (); type MaxLocks = (); diff --git a/runtime/runtime-common/src/zk_precompile_gas_estimation/mod.rs b/runtime/runtime-common/src/zk_precompile_gas_estimation/mod.rs index 2645174c..765e6206 100644 --- a/runtime/runtime-common/src/zk_precompile_gas_estimation/mod.rs +++ b/runtime/runtime-common/src/zk_precompile_gas_estimation/mod.rs @@ -6,6 +6,22 @@ mod mock; mod tests; pub use pallet::*; +use sp_core::U256; +use sp_std::vec::Vec; + +pub fn u64s_to_u256(values: Vec) -> U256 { + let mut result = U256::zero(); + for (i, value) in values.into_iter().enumerate().take(4) { + let shift = i * 64; + result |= U256::from(value) << shift; + } + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "u64s_to_u256 result {:?}", + result + ); + result +} #[frame_support::pallet] pub mod pallet { diff --git a/runtime/runtime-common/src/zk_precompile_gas_estimation/tests.rs b/runtime/runtime-common/src/zk_precompile_gas_estimation/tests.rs index 97e5df7b..f20d7035 100644 --- a/runtime/runtime-common/src/zk_precompile_gas_estimation/tests.rs +++ b/runtime/runtime-common/src/zk_precompile_gas_estimation/tests.rs @@ -1,3 +1,4 @@ +use super::*; use crate::zk_precompile_gas_estimation::mock::*; use ethabi::Token; use fp_evm::GenesisAccount; @@ -6,16 +7,6 @@ use pallet_evm::{GenesisConfig, Runner}; use sp_core::{H160, U256}; use std::{collections::BTreeMap, str::FromStr}; -fn u64s_to_u256(values: Vec) -> U256 { - let mut result = U256::zero(); - for (i, value) in values.into_iter().enumerate().take(4) { - let shift = i * 64; - result |= U256::from(value) << shift; - } - println!("{:?}", result); - result -} - pub fn new_test_ext() -> sp_io::TestExternalities { let mut t = frame_system::GenesisConfig::default() .build_storage::() From 8e2c8c8ac5ec1a4d0280b732f11a9e931eea2d57 Mon Sep 17 00:00:00 2001 From: luckychacha <358140284@qq.com> Date: Mon, 21 Aug 2023 15:30:17 +0800 Subject: [PATCH 29/34] remove unused dev-dependencies. --- Cargo.lock | 1 - runtime/runtime-common/Cargo.toml | 1 - 2 files changed, 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e7906fcd..344ac107 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9033,7 +9033,6 @@ name = "runtime-common" version = "0.1.0" dependencies = [ "ethabi 18.0.0", - "fp-account", "fp-evm", "frame-benchmarking", "frame-support", diff --git a/runtime/runtime-common/Cargo.toml b/runtime/runtime-common/Cargo.toml index 002ccde5..688a90bb 100644 --- a/runtime/runtime-common/Cargo.toml +++ b/runtime/runtime-common/Cargo.toml @@ -42,7 +42,6 @@ log.workspace = true ethabi.workspace = true [dev-dependencies] -fp-account.workspace = true fp-evm.workspace = true pallet-balances.workspace = true pallet-timestamp.workspace = true From a6ae9f3b125970e4f2023a03b4f7c85fca075400 Mon Sep 17 00:00:00 2001 From: luckychacha <358140284@qq.com> Date: Mon, 21 Aug 2023 15:52:11 +0800 Subject: [PATCH 30/34] remove comment dependencies. --- runtime/runtime-common/Cargo.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/runtime/runtime-common/Cargo.toml b/runtime/runtime-common/Cargo.toml index 3528a673..fd2f1fe9 100644 --- a/runtime/runtime-common/Cargo.toml +++ b/runtime/runtime-common/Cargo.toml @@ -77,7 +77,6 @@ std = [ "sp-staking/std", "sp-std/std", "frame-benchmarking/std", - # "rlp/std", "pallet-contracts?/std", "pallet-evm?/std", From 9fd6f78ae6d00d522a0033c1cf9b1870c8326ffd Mon Sep 17 00:00:00 2001 From: luckychacha <358140284@qq.com> Date: Thu, 7 Sep 2023 18:24:15 +0800 Subject: [PATCH 31/34] Resolve conversation. --- node/src/benchmarking.rs | 4 ++-- runtime/brooklyn/src/lib.rs | 1 + runtime/sydney/src/lib.rs | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/node/src/benchmarking.rs b/node/src/benchmarking.rs index 22c17b82..88f2fea9 100644 --- a/node/src/benchmarking.rs +++ b/node/src/benchmarking.rs @@ -144,7 +144,7 @@ pub fn create_benchmark_extrinsic( .unwrap_or(2) as u64; let extra: runtime::SignedExtra = ( - //frame_system::CheckNonZeroSender::::new(), + frame_system::CheckNonZeroSender::::new(), frame_system::CheckSpecVersion::::new(), frame_system::CheckTxVersion::::new(), frame_system::CheckGenesis::::new(), @@ -166,7 +166,7 @@ pub fn create_benchmark_extrinsic( call.clone(), extra.clone(), ( - // (), + (), runtime::VERSION.spec_version, runtime::VERSION.transaction_version, genesis_hash, diff --git a/runtime/brooklyn/src/lib.rs b/runtime/brooklyn/src/lib.rs index 1d269b87..5377ab94 100644 --- a/runtime/brooklyn/src/lib.rs +++ b/runtime/brooklyn/src/lib.rs @@ -153,6 +153,7 @@ pub type SignedBlock = generic::SignedBlock; pub type BlockId = generic::BlockId; /// The SignedExtension to the basic transaction logic. pub type SignedExtra = ( + frame_system::CheckNonZeroSender, frame_system::CheckSpecVersion, frame_system::CheckTxVersion, frame_system::CheckGenesis, diff --git a/runtime/sydney/src/lib.rs b/runtime/sydney/src/lib.rs index 4a524a67..2b217f5b 100644 --- a/runtime/sydney/src/lib.rs +++ b/runtime/sydney/src/lib.rs @@ -164,6 +164,7 @@ pub type OptionalSignedExtension = ( pub type OptionalSignedExtension = (pallet_transaction_payment::ChargeTransactionPayment,); pub type SignedExtra = ( + frame_system::CheckNonZeroSender, frame_system::CheckSpecVersion, frame_system::CheckTxVersion, frame_system::CheckGenesis, From 7846e3787d6e82e6ad02f763ef316843a5d20b85 Mon Sep 17 00:00:00 2001 From: luckychacha <358140284@qq.com> Date: Fri, 8 Sep 2023 14:32:12 +0800 Subject: [PATCH 32/34] Remove unused dependence. --- Cargo.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 32d5d8d1..80a6a831 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -163,7 +163,6 @@ fc-rpc-core = { version = "1.1.0-dev", git = "https://github.com/AstarNetwork/fr # Frontier Primitive fc-storage = { version = "1.0.0-dev", git = "https://github.com/AstarNetwork/frontier.git", branch = "polkadot-v0.9.40", default-features = false } -fp-account = { version = "1.0.0-dev", git = "https://github.com/AstarNetwork/frontier.git", branch = "polkadot-v0.9.40", default-features = false } fp-dynamic-fee = { version = "1.0.0", git = "https://github.com/AstarNetwork/frontier.git", branch = "polkadot-v0.9.40", default-features = false } fp-evm = { version = "3.0.0-dev", git = "https://github.com/AstarNetwork/frontier.git", branch = "polkadot-v0.9.40", default-features = false } fp-rpc = { version = "3.0.0-dev", git = "https://github.com/AstarNetwork/frontier.git", branch = "polkadot-v0.9.40", default-features = false } From 858055e1a9cab7fdf1e4d082db3869f44bb38f11 Mon Sep 17 00:00:00 2001 From: luckychacha <358140284@qq.com> Date: Wed, 27 Sep 2023 14:47:27 +0800 Subject: [PATCH 33/34] update chain_id in mock file. --- runtime/runtime-common/src/zk_precompile_gas_estimation/mock.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/runtime-common/src/zk_precompile_gas_estimation/mock.rs b/runtime/runtime-common/src/zk_precompile_gas_estimation/mock.rs index 30f5d3a6..7a8c28b6 100644 --- a/runtime/runtime-common/src/zk_precompile_gas_estimation/mock.rs +++ b/runtime/runtime-common/src/zk_precompile_gas_estimation/mock.rs @@ -13,7 +13,7 @@ use sp_runtime::{ use sp_std::marker::PhantomData; #[cfg(not(feature = "brooklyn"))] -pub const CHAIN_ID: u64 = 8866u64; +pub const CHAIN_ID: u64 = 8886u64; #[cfg(feature = "brooklyn")] pub const CHAIN_ID: u64 = 888866u64; From dab33535d4aca93e9b8c58d89f398e7bcb4b4bcf Mon Sep 17 00:00:00 2001 From: luckychacha <358140284@qq.com> Date: Thu, 28 Sep 2023 02:43:05 +0800 Subject: [PATCH 34/34] Deal benchmark running error. --- node/src/runtime/testnet.rs | 10 +++ .../benchmarking.rs | 75 ++++++++++--------- 2 files changed, 48 insertions(+), 37 deletions(-) diff --git a/node/src/runtime/testnet.rs b/node/src/runtime/testnet.rs index b66f92a7..725e56c8 100644 --- a/node/src/runtime/testnet.rs +++ b/node/src/runtime/testnet.rs @@ -197,6 +197,16 @@ pub fn testnet_genesis( code: vec![0x00], }, ); + map.insert( + H160::from_str("1000000000000000000000000000000000000666") + .expect("internal H160 is valid; qed"), + fp_evm::GenesisAccount { + nonce: U256::from(1), + balance: U256::max_value(), + storage: Default::default(), + code: vec![], // No code, this is an EOA + }, + ); map }, }, diff --git a/runtime/runtime-common/src/zk_precompile_gas_estimation/benchmarking.rs b/runtime/runtime-common/src/zk_precompile_gas_estimation/benchmarking.rs index 433902f1..75a019ac 100644 --- a/runtime/runtime-common/src/zk_precompile_gas_estimation/benchmarking.rs +++ b/runtime/runtime-common/src/zk_precompile_gas_estimation/benchmarking.rs @@ -172,7 +172,7 @@ benchmarks! { use frame_benchmarking::vec; use sp_core::{H160, U256, H256}; - let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + let caller = "1000000000000000000000000000000000000666".parse::().unwrap(); let contract_address = H160::from_low_u64_be(0x8888); let proof = Proof::new( @@ -264,7 +264,7 @@ benchmarks! { let is_transactional = true; let validate = true; }:{ - let call_runner_results = ::Runner::call( + let call_runner_results: Result = ::Runner::call( caller, contract_address, encoded_call, @@ -277,11 +277,11 @@ benchmarks! { is_transactional, validate, ::config(), + ).map_err(|e| e.error.into()); + log::info!( + target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", + "nconstraints_10 Benchmarking call end." ); - // log::info!( - // target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - // "Benchmarking call end.", - // ); match call_runner_results { Ok(info) => { let output = info.value; @@ -305,7 +305,8 @@ benchmarks! { Err(e) => { log::info!( target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - "nconstraints_10 Benchmarking failed", + "nconstraints_10 Benchmarking failed: {:?}", + e, ); panic!("nconstraints_10 Benchmarking failed"); } @@ -316,7 +317,7 @@ benchmarks! { use frame_benchmarking::vec; use sp_core::{H160, U256, H256}; - let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + let caller = "1000000000000000000000000000000000000666".parse::().unwrap(); let contract_address = H160::from_low_u64_be(0x8888); let proof = Proof::new( @@ -465,7 +466,7 @@ benchmarks! { use frame_benchmarking::vec; use sp_core::{H160, U256, H256}; - let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + let caller = "1000000000000000000000000000000000000666".parse::().unwrap(); let contract_address = H160::from_low_u64_be(0x8888); let proof = Proof::new( @@ -613,7 +614,7 @@ benchmarks! { use frame_benchmarking::vec; use sp_core::{H160, U256, H256}; - let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + let caller = "1000000000000000000000000000000000000666".parse::().unwrap(); let contract_address = H160::from_low_u64_be(0x8888); let proof = Proof::new( @@ -762,7 +763,7 @@ benchmarks! { use frame_benchmarking::vec; use sp_core::{H160, U256, H256}; - let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + let caller = "1000000000000000000000000000000000000666".parse::().unwrap(); let contract_address = H160::from_low_u64_be(0x8888); let proof = Proof::new( @@ -910,7 +911,7 @@ benchmarks! { use frame_benchmarking::vec; use sp_core::{H160, U256, H256}; - let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + let caller = "1000000000000000000000000000000000000666".parse::().unwrap(); let contract_address = H160::from_low_u64_be(0x8888); let proof = Proof::new( @@ -1058,7 +1059,7 @@ benchmarks! { use frame_benchmarking::vec; use sp_core::{H160, U256, H256}; - let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + let caller = "1000000000000000000000000000000000000666".parse::().unwrap(); let contract_address = H160::from_low_u64_be(0x8888); let proof = Proof::new( @@ -1206,7 +1207,7 @@ benchmarks! { use frame_benchmarking::vec; use sp_core::{H160, U256, H256}; - let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + let caller = "1000000000000000000000000000000000000666".parse::().unwrap(); let contract_address = H160::from_low_u64_be(0x8888); let proof = Proof::new( @@ -1354,7 +1355,7 @@ benchmarks! { use frame_benchmarking::vec; use sp_core::{H160, U256, H256}; - let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + let caller = "1000000000000000000000000000000000000666".parse::().unwrap(); let contract_address = H160::from_low_u64_be(0x8888); let proof = Proof::new( @@ -1503,7 +1504,7 @@ benchmarks! { use frame_benchmarking::vec; use sp_core::{H160, U256, H256}; - let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + let caller = "1000000000000000000000000000000000000666".parse::().unwrap(); let contract_address = H160::from_low_u64_be(0x8888); let proof = Proof::new( @@ -1651,7 +1652,7 @@ benchmarks! { use frame_benchmarking::vec; use sp_core::{H160, U256, H256}; - let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + let caller = "1000000000000000000000000000000000000666".parse::().unwrap(); let contract_address = H160::from_low_u64_be(0x8888); let proof = Proof::new( @@ -1800,7 +1801,7 @@ benchmarks! { use frame_benchmarking::vec; use sp_core::{H160, U256, H256}; - let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + let caller = "1000000000000000000000000000000000000666".parse::().unwrap(); let contract_address = H160::from_low_u64_be(0x8888); let proof = Proof::new( @@ -1945,7 +1946,7 @@ benchmarks! { use frame_benchmarking::vec; use sp_core::{H160, U256, H256}; - let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + let caller = "1000000000000000000000000000000000000666".parse::().unwrap(); let contract_address = H160::from_low_u64_be(0x8888); let proof = Proof::new( @@ -2091,7 +2092,7 @@ benchmarks! { use frame_benchmarking::vec; use sp_core::{H160, U256, H256}; - let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + let caller = "1000000000000000000000000000000000000666".parse::().unwrap(); let contract_address = H160::from_low_u64_be(0x8888); let proof = Proof::new( @@ -2237,7 +2238,7 @@ benchmarks! { use frame_benchmarking::vec; use sp_core::{H160, U256, H256}; - let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + let caller = "1000000000000000000000000000000000000666".parse::().unwrap(); let contract_address = H160::from_low_u64_be(0x8888); let proof = Proof::new( @@ -2381,7 +2382,7 @@ benchmarks! { use frame_benchmarking::vec; use sp_core::{H160, U256, H256}; - let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + let caller = "1000000000000000000000000000000000000666".parse::().unwrap(); let contract_address = H160::from_low_u64_be(0x8888); let proof = Proof::new( @@ -2518,7 +2519,7 @@ benchmarks! { use frame_benchmarking::vec; use sp_core::{H160, U256, H256}; - let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + let caller = "1000000000000000000000000000000000000666".parse::().unwrap(); let contract_address = H160::from_low_u64_be(0x8888); let proof = Proof::new( @@ -2665,7 +2666,7 @@ benchmarks! { use frame_benchmarking::vec; use sp_core::{H160, U256, H256}; - let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + let caller = "1000000000000000000000000000000000000666".parse::().unwrap(); let contract_address = H160::from_low_u64_be(0x8888); let proof = Proof::new( @@ -2822,7 +2823,7 @@ benchmarks! { use frame_benchmarking::vec; use sp_core::{H160, U256, H256}; - let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + let caller = "1000000000000000000000000000000000000666".parse::().unwrap(); let contract_address = H160::from_low_u64_be(0x8888); let proof = Proof::new( @@ -2994,7 +2995,7 @@ benchmarks! { use frame_benchmarking::vec; use sp_core::{H160, U256, H256}; - let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + let caller = "1000000000000000000000000000000000000666".parse::().unwrap(); let contract_address = H160::from_low_u64_be(0x8888); let proof = Proof::new( @@ -3176,7 +3177,7 @@ benchmarks! { use frame_benchmarking::vec; use sp_core::{H160, U256, H256}; - let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + let caller = "1000000000000000000000000000000000000666".parse::().unwrap(); let contract_address = H160::from_low_u64_be(0x8888); let proof = Proof::new( @@ -3368,7 +3369,7 @@ benchmarks! { use frame_benchmarking::vec; use sp_core::{H160, U256, H256}; - let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + let caller = "1000000000000000000000000000000000000666".parse::().unwrap(); let contract_address = H160::from_low_u64_be(0x8888); let proof = Proof::new( @@ -3547,7 +3548,7 @@ benchmarks! { let used_gas = info.used_gas; log::info!( target: "runtime::runtime-common::zk_precompile_gas_estimation::benchmarking", - "nconstraints_10 output result {:?} used_gas: {:?}", + "sumout_15 output result {:?} used_gas: {:?}", output, used_gas, ); @@ -3575,7 +3576,7 @@ benchmarks! { use frame_benchmarking::vec; use sp_core::{H160, U256, H256}; - let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + let caller = "1000000000000000000000000000000000000666".parse::().unwrap(); let contract_address = H160::from_low_u64_be(0x8888); let proof = Proof::new( @@ -3797,7 +3798,7 @@ benchmarks! { use frame_benchmarking::vec; use sp_core::{H160, U256, H256}; - let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + let caller = "1000000000000000000000000000000000000666".parse::().unwrap(); let contract_address = H160::from_low_u64_be(0x8888); let proof = Proof::new( @@ -4029,7 +4030,7 @@ benchmarks! { use frame_benchmarking::vec; use sp_core::{H160, U256, H256}; - let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + let caller = "1000000000000000000000000000000000000666".parse::().unwrap(); let contract_address = H160::from_low_u64_be(0x8888); let proof = Proof::new( @@ -4411,7 +4412,7 @@ benchmarks! { use frame_benchmarking::vec; use sp_core::{H160, U256, H256}; - let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + let caller = "1000000000000000000000000000000000000666".parse::().unwrap(); let contract_address = H160::from_low_u64_be(0x8888); let proof = Proof::new( @@ -4558,7 +4559,7 @@ benchmarks! { use frame_benchmarking::vec; use sp_core::{H160, U256, H256}; - let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + let caller = "1000000000000000000000000000000000000666".parse::().unwrap(); let contract_address = H160::from_low_u64_be(0x8888); let proof = Proof::new( @@ -4715,7 +4716,7 @@ benchmarks! { use frame_benchmarking::vec; use sp_core::{H160, U256, H256}; - let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + let caller = "1000000000000000000000000000000000000666".parse::().unwrap(); let contract_address = H160::from_low_u64_be(0x8888); let proof = Proof::new( @@ -4897,7 +4898,7 @@ benchmarks! { use frame_benchmarking::vec; use sp_core::{H160, U256, H256}; - let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + let caller = "1000000000000000000000000000000000000666".parse::().unwrap(); let contract_address = H160::from_low_u64_be(0x8888); let proof = Proof::new( @@ -5079,7 +5080,7 @@ benchmarks! { use frame_benchmarking::vec; use sp_core::{H160, U256, H256}; - let caller = "d43593c715fdd31c61141abd04a99fd6822c8558".parse::().unwrap(); + let caller = "1000000000000000000000000000000000000666".parse::().unwrap(); let contract_address = H160::from_low_u64_be(0x8888); let proof = Proof::new(