referrerpolicy=no-referrer-when-downgrade

pallet_revive/precompiles/builtin/
benchmarking.rs

1// This file is part of Substrate.
2
3// Copyright (C) Parity Technologies (UK) Ltd.
4// SPDX-License-Identifier: Apache-2.0
5
6// Licensed under the Apache License, Version 2.0 (the "License");
7// you may not use this file except in compliance with the License.
8// You may obtain a copy of the License at
9//
10// http://www.apache.org/licenses/LICENSE-2.0
11//
12// Unless required by applicable law or agreed to in writing, software
13// distributed under the License is distributed on an "AS IS" BASIS,
14// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15// See the License for the specific language governing permissions and
16// limitations under the License.
17
18use crate::{
19	precompiles::{BuiltinAddressMatcher, BuiltinPrecompile, Error, Ext, ExtWithInfo},
20	Config,
21};
22use alloc::vec::Vec;
23use alloy_core::sol;
24use core::{marker::PhantomData, num::NonZero};
25
26sol! {
27	interface IBenchmarking {
28		function bench(bytes calldata input) external;
29	}
30}
31
32pub struct WithInfo<T>(PhantomData<T>);
33
34impl<T: Config> BuiltinPrecompile for WithInfo<T> {
35	type T = T;
36	type Interface = IBenchmarking::IBenchmarkingCalls;
37	const MATCHER: BuiltinAddressMatcher =
38		BuiltinAddressMatcher::Fixed(NonZero::new(0xFF_FF).unwrap());
39	const HAS_CONTRACT_INFO: bool = true;
40
41	fn call_with_info(
42		_address: &[u8; 20],
43		_input: &Self::Interface,
44		_env: &mut impl ExtWithInfo<T = Self::T>,
45	) -> Result<Vec<u8>, Error> {
46		Ok(Vec::new())
47	}
48}
49
50pub struct NoInfo<T>(PhantomData<T>);
51
52impl<T: Config> BuiltinPrecompile for NoInfo<T> {
53	type T = T;
54	type Interface = IBenchmarking::IBenchmarkingCalls;
55	const MATCHER: BuiltinAddressMatcher =
56		BuiltinAddressMatcher::Fixed(NonZero::new(0xEF_FF).unwrap());
57	const HAS_CONTRACT_INFO: bool = false;
58
59	fn call(
60		_address: &[u8; 20],
61		_input: &Self::Interface,
62		_env: &mut impl Ext<T = Self::T>,
63	) -> Result<Vec<u8>, Error> {
64		Ok(Vec::new())
65	}
66}