Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions frame/account-mapping/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use crate::pallet::{
use frame_benchmarking::v2::*;
use frame_support::traits::{Currency, Get, ReservableCurrency};
use frame_system::RawOrigin;
use scale_codec::Encode;
use scale_codec::{Decode, Encode};
use sp_core::crypto::KeyTypeId;
use sp_runtime::traits::Convert;

Expand Down Expand Up @@ -75,11 +75,27 @@ fn register_alias_for<T: Config>(who: &T::AccountId, alias: AliasOf<T>) {
mod benchmarks {
use super::*;

/// Returns an EVM-compatible `AccountId` for benchmarks.
///
/// Uses SCALE `Decode` so no `From<[u8; 32]>` bound is required, keeping
/// compatibility with the test mock (`AccountId = u64`).
///
/// - Production (`AccountId32`): decodes 32 bytes → `[0x42, 0u8×31]`;
/// bytes[20..32] == `[0u8;12]` satisfies `AccountIdToEvmAddress`. ✓
/// - Test mock (`u64`): reads first 8 LE bytes → `66u64`;
/// `TestEvmAddress::convert(66)` = `Some(H160)`. ✓
fn evm_account<T: Config>() -> T::AccountId {
let mut bytes = [0u8; 32];
bytes[0] = 0x42;
T::AccountId::decode(&mut &bytes[..]).unwrap_or_else(|_| whitelisted_caller())
}

// ─── map_account ────────────────────────────────────────────────────────

#[benchmark]
fn map_account() {
let caller: T::AccountId = whitelisted_caller();
// Needs an EVM-compatible AccountId (bytes[20..32] == [0u8; 12]).
let caller = evm_account::<T>();
fund_account::<T>(&caller);

#[extrinsic_call]
Expand All @@ -92,12 +108,13 @@ mod benchmarks {

#[benchmark]
fn unmap_account() {
let caller: T::AccountId = whitelisted_caller();
// Needs an EVM-compatible AccountId (bytes[20..32] == [0u8; 12]).
let caller = evm_account::<T>();
fund_account::<T>(&caller);

// Pre-state: account already mapped.
let address = T::AccountIdToEvmAddress::convert(caller.clone())
.expect("caller must have an EVM address in benchmark");
.expect("evm_account always has an EVM address");
OriginalAccounts::<T>::insert(&caller, address);
MappedAccounts::<T>::insert(address, &caller);

Expand Down
22 changes: 17 additions & 5 deletions template/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,11 +408,23 @@ pub struct PrivateLinkZkAdapter;

impl pallet_account_mapping::PrivateLinkVerifierPort for PrivateLinkZkAdapter {
fn verify(commitment: &[u8; 32], call_hash: &[u8; 32], proof: &[u8]) -> bool {
use pallet_zk_verifier::ZkVerifierPort;
pallet_zk_verifier::Pallet::<Runtime>::verify_private_link_proof(
proof, commitment, call_hash, None,
)
.unwrap_or(false)
// In benchmark builds accept any non-empty proof so the extrinsic setup/dispatch
// overhead is measured without ZK cost. The pairing computation is captured
// separately by `pallet_zk_verifier::verify_proof`.
#[cfg(feature = "runtime-benchmarks")]
{
let _ = (commitment, call_hash);
!proof.is_empty()
}

#[cfg(not(feature = "runtime-benchmarks"))]
{
use pallet_zk_verifier::ZkVerifierPort;
pallet_zk_verifier::Pallet::<Runtime>::verify_private_link_proof(
proof, commitment, call_hash, None,
)
.unwrap_or(false)
}
}
}

Expand Down
Loading