Skip to content

Mismatch between circuit_index documentation and implementation (internal masks not accounted for) #60

@ConstanceBeguier

Description

@ConstanceBeguier

Crate

ragu_pcd

Severity

low

Repo commit

4a40b3e (2nd audit leg)

Description

The documentation of circuit_index states that circuit indices are assigned in the following order: internal circuits, internal masks, internal steps, then application steps.

However, the current implementation does not account for internal masks when computing indices. Only NUM_INTERNAL_CIRCUITS and NUM_INTERNAL_STEPS are used, which makes the documented ordering inaccurate.

Code

File name: crates/ragu_pcd/src/step/mod.rs

    /// Returns the circuit index for this step.
    ///
    /// Circuits are registered in the following order: internal circuits,
    /// internal masks, internal steps, then application steps.
    ///
    /// Pass the known number of application steps to validate and compute the
    /// final index of this step. Returns an error if an application step index
    /// exceeds the number of registered steps.
    pub(crate) fn circuit_index(&self, num_application_steps: usize) -> Result<CircuitIndex> {
        match self.index {
            StepIndex::Internal(i) => {
                // Internal steps come after internal circuits
                Ok(CircuitIndex::from_u32(
                    NUM_INTERNAL_CIRCUITS as u32 + i as u32,
                ))
            }
            StepIndex::Application(i) => {
                if i >= num_application_steps {
                    return Err(ragu_core::Error::Initialization(
                            "attempted to use application Step index that exceeds Application registered steps".into(),
                        ));
                }

                Ok(CircuitIndex::new(
                    NUM_INTERNAL_STEPS + NUM_INTERNAL_CIRCUITS + i,
                ))
            }
        }
    }

Recommendations

The documentation should be updated to reflect the actual behavior.

    /// Returns the circuit index for this step.
    ///
    /// Circuits are registered in the following order: internal circuits,
    /// internal steps, then application steps.
    ///
    /// Pass the known number of application steps to validate and compute the
    /// final index of this step. Returns an error if an application step index
    /// exceeds the number of registered steps.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions