referrerpolicy=no-referrer-when-downgrade

pallet_revive/precompiles/
builtin.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
18mod blake2f;
19mod bn128;
20mod ecrecover;
21mod identity;
22mod modexp;
23mod point_eval;
24mod ripemd160;
25mod sha256;
26mod system;
27
28#[cfg(feature = "runtime-benchmarks")]
29mod benchmarking;
30
31#[cfg(feature = "runtime-benchmarks")]
32use crate::{
33	precompiles::{ExtWithInfo, Instance, Precompiles},
34	Config,
35};
36
37#[cfg(feature = "runtime-benchmarks")]
38pub use self::{
39	benchmarking::{IBenchmarking, NoInfo, WithInfo},
40	system::{ISystem, System},
41};
42
43#[cfg(not(feature = "runtime-benchmarks"))]
44pub type Builtin<T> = Production<T>;
45
46#[cfg(feature = "runtime-benchmarks")]
47pub type Builtin<T> = (Production<T>, Benchmarking<T>);
48
49type Production<T> = (
50	ecrecover::EcRecover<T>,
51	sha256::Sha256<T>,
52	ripemd160::Ripemd160<T>,
53	identity::Identity<T>,
54	modexp::Modexp<T>,
55	bn128::Bn128Add<T>,
56	bn128::Bn128Mul<T>,
57	bn128::Bn128Pairing<T>,
58	blake2f::Blake2F<T>,
59	point_eval::PointEval<T>,
60	system::System<T>,
61);
62
63#[cfg(feature = "runtime-benchmarks")]
64type Benchmarking<T> = (benchmarking::WithInfo<T>, benchmarking::NoInfo<T>);
65
66#[cfg(feature = "runtime-benchmarks")]
67impl<T: Config> Precompiles<T> for (Production<T>, Benchmarking<T>) {
68	const CHECK_COLLISION: () = ();
69	const USES_EXTERNAL_RANGE: bool =
70		Production::<T>::USES_EXTERNAL_RANGE || Benchmarking::<T>::USES_EXTERNAL_RANGE;
71
72	fn code(address: &[u8; 20]) -> Option<&'static [u8]> {
73		<Production<T>>::code(address).or_else(|| Benchmarking::<T>::code(address))
74	}
75
76	fn get<E: ExtWithInfo<T = T>>(address: &[u8; 20]) -> Option<Instance<E>> {
77		let _ = <Self as Precompiles<T>>::CHECK_COLLISION;
78		<Production<T>>::get(address).or_else(|| Benchmarking::<T>::get(address))
79	}
80}