revm_precompile/
identity.rs

1//! Identity precompile returns
2use super::calc_linear_cost_u32;
3use crate::{PrecompileError, PrecompileOutput, PrecompileResult, PrecompileWithAddress};
4use primitives::Bytes;
5
6/// Address of the identity precompile.
7pub const FUN: PrecompileWithAddress =
8    PrecompileWithAddress(crate::u64_to_address(4), identity_run);
9
10/// The base cost of the operation
11pub const IDENTITY_BASE: u64 = 15;
12/// The cost per word
13pub const IDENTITY_PER_WORD: u64 = 3;
14
15/// Takes the input bytes, copies them, and returns it as the output.
16///
17/// See: <https://ethereum.github.io/yellowpaper/paper.pdf>
18///
19/// See: <https://etherscan.io/address/0000000000000000000000000000000000000004>
20pub fn identity_run(input: &[u8], gas_limit: u64) -> PrecompileResult {
21    let gas_used = calc_linear_cost_u32(input.len(), IDENTITY_BASE, IDENTITY_PER_WORD);
22    if gas_used > gas_limit {
23        return Err(PrecompileError::OutOfGas);
24    }
25    Ok(PrecompileOutput::new(
26        gas_used,
27        Bytes::copy_from_slice(input),
28    ))
29}