revm_precompile/
identity.rs

1use super::calc_linear_cost_u32;
2use crate::{Error, Precompile, PrecompileResult, PrecompileWithAddress};
3use revm_primitives::{Bytes, PrecompileOutput};
4
5pub const FUN: PrecompileWithAddress =
6    PrecompileWithAddress(crate::u64_to_address(4), Precompile::Standard(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/// See: <https://etherscan.io/address/0000000000000000000000000000000000000004>
17pub fn identity_run(input: &Bytes, gas_limit: u64) -> PrecompileResult {
18    let gas_used = calc_linear_cost_u32(input.len(), IDENTITY_BASE, IDENTITY_PER_WORD);
19    if gas_used > gas_limit {
20        return Err(Error::OutOfGas.into());
21    }
22    Ok(PrecompileOutput::new(gas_used, input.clone()))
23}