layout

Function layout 

Source
pub fn layout<F: Field>(
    input_layer_nodes: Vec<InputLayerNode>,
    input_shred_nodes: Vec<InputShred>,
    fiat_shamir_challenge_nodes: Vec<FiatShamirChallengeNode>,
    output_nodes: Vec<OutputNode>,
    sector_nodes: Vec<Sector<F>>,
    gate_nodes: Vec<GateNode>,
    identity_gate_nodes: Vec<IdentityGateNode>,
    split_nodes: Vec<SplitNode>,
    matmult_nodes: Vec<MatMultNode>,
    lookup_constraint_nodes: Vec<LookupConstraint>,
    lookup_table_nodes: Vec<LookupTable>,
    should_combine: bool,
) -> Result<(Vec<InputLayerNode>, Vec<FiatShamirChallengeNode>, Vec<Vec<Box<dyn CompilableNode<F>>>>, Vec<LookupTable>, Vec<OutputNode>)>
Expand description

Given the nodes provided by the circuit builder, this function returns a tuple of type LayouterNodes.

This function categorizes nodes into their respective layers, by doing the following:

  • Assigning input_shred_nodes to their respective input_layer_nodes parent.
  • The fiat_shamir_challenge_nodes are to be compiled next, so they are returned as is.
  • sector_nodes, gate_nodes, identity_gate_nodes, matmult_nodes, and split_nodes are considered intermediate nodes. sector_nodes are the only nodes which can be combined with each other via a selector. Therefore, first we topologically sort the intermediate nodes by creating a dependency graph using their specified sources. Then, we do a forward pass through these sorted nodes, identify which ones are the sectors, and combine them greedily (if there is no dependency between them, we combine). We then return a Vec<Vec<Box<dyn CompilableNode<F>>>> for which each inner vector represents nodes that can be combined into a single layer.
  • lookup_constraint_nodes are added to their respective lookup_table_nodes. Because no nodes are dependent on lookups (their results are always outputs), we compile them after the intermediate nodes.
  • output_nodes are compiled last, so they are returned as is.

The ordering in which the nodes are returned as LayouterNodes is the order in which the nodes are expected to be compiled into layers.