snarkvm_circuit_program/function_id/
mod.rs

1// Copyright (c) 2019-2025 Provable Inc.
2// This file is part of the snarkVM library.
3
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at:
7
8// http://www.apache.org/licenses/LICENSE-2.0
9
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16use crate::{Identifier, ProgramID};
17use snarkvm_circuit_network::Aleo;
18use snarkvm_circuit_types::{Field, U16, environment::prelude::*};
19
20/// Compute the function ID as `Hash(network_id, program_id.len(), program_id, function_name.len(), function_name)`.
21pub fn compute_function_id<A: Aleo>(
22    network_id: &U16<A>,
23    program_id: &ProgramID<A>,
24    function_name: &Identifier<A>,
25) -> Field<A> {
26    A::hash_bhp1024(
27        &(
28            network_id,
29            program_id.name().size_in_bits(),
30            program_id.name(),
31            program_id.network().size_in_bits(),
32            program_id.network(),
33            function_name.size_in_bits(),
34            function_name,
35        )
36            .to_bits_le(),
37    )
38}