revm_precompile/
identity.rs

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