pub fn trim_padded_evm_bytecode(bytecode_hash: BytecodeHash, raw: &[u8]) -> anyhow::Result<&[u8]> {
    if bytecode_hash.marker() != BytecodeMarker::Evm {
        anyhow::bail!("only EVM bytecode hashes allowed")
    }
    validate_bytecode(raw).context("bytecode fails basic validity checks")?;

    // Actual raw unpadded EVM bytecode length is encoded in bytecode hash
    let bytecode_len: usize = bytecode_hash.len_in_bytes();
    let bytecode = raw.get(0..bytecode_len).with_context(|| {
        format!(
            "encoded length ({bytecode_len}) exceeds real length ({})",
            raw.len()
        )
    })?;
    // Since slicing above succeeded, this one is safe.
    let padding = &raw[bytecode_len..];
    anyhow::ensure!(
        padding.iter().all(|&b| b == 0),
        "bytecode padding contains non-zero bytes"
    );
    Ok(bytecode)
}
Removes padding from an EVM bytecode, returning the original EVM bytecode.
core/lib/basic_types/src/bytecode.rs