Module ir_builder

Module ir_builder 

Source
Expand description

Graph-IR generation backend for the chip_traits traits.

Halo2IRBuilder implements the same chip traits as Halo2Backend but records a dataflow graph of Halo2GraphNodes instead of assigning halo2 cells. Each node writes a statically-sized slice of the advice + range tapes; executing them in tape order reproduces the halo2 backend’s stream byte-for-byte.

To keep replay stateless (parallel-safe), the builder mirrors chip bookkeeping exactly:

  • max_bits tracking + explicit Halo2Opcode::BBReduce nodes for pre-op reduces; atomic ops (div, ext mul/div) re-derive interleaved reduce decisions from operand bit bounds at replay.
  • Constant caching (zero_cell + BabyBear const cache) matches Context::load_zero / BabyBearChip::const_cache. Atomic ops expose internally-loaded constants (BBDiv→ONE, ExtMul→W, ExtDiv→ONE/ZERO/W) as extra outputs; whether each materializes is decided at build time and recorded in NodeMeta::constant_skip_inds.
  • Transcript sponge/buffer state mirrors TranscriptChip.

Fixed-column QuantumCell::Constants (select branches, IP coefficients, Const witness values) are GraphCell::Const operands, not nodes.

Non-arithmetic opcodes cover the rest of the populate pipeline: LoadWitness, InnerProduct, DecomposeBn254ToBabyBear, RangeDiv.

Structs§

Halo2GraphNode
Halo2IRBuilder
Backend that records the circuit-population trace as a graph IR.
NodeMeta
Per-node replay metadata deduced at build time; together with operand values it is everything an executor needs to replay a node in isolation (no runtime cache), enabling parallel replay.

Enums§

GraphCell
IR operand/result: a node-produced value or a fixed-column constant.
Halo2Opcode
IR opcodes. Each op writes a statically-known slice of the advice + range tapes when executed.

Type Aliases§

NodeId
Unique id of an IR node; also its index in Halo2IRBuilder::nodes.