Skip to content

Commit fc9c5fc

Browse files
committed
Merge with main
2 parents 973f6f8 + 328b772 commit fc9c5fc

34 files changed

+1333
-575
lines changed

circuit/src/alloc_entry.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pub enum AllocationType {
2121
Mul,
2222
Div,
2323
NonPrimitiveOp(NonPrimitiveOpType),
24+
WitnessHint,
2425
}
2526

2627
/// Detailed allocation entry for debugging
@@ -92,6 +93,7 @@ fn dump_internal_log(allocation_log: &[AllocationEntry]) {
9293
let mut muls = Vec::new();
9394
let mut divs = Vec::new();
9495
let mut non_primitives = Vec::new();
96+
let mut witness_hints = Vec::new();
9597

9698
fn display_label(label: &str) -> String {
9799
if label.is_empty() {
@@ -110,6 +112,7 @@ fn dump_internal_log(allocation_log: &[AllocationEntry]) {
110112
AllocationType::Mul => muls.push(entry),
111113
AllocationType::Div => divs.push(entry),
112114
AllocationType::NonPrimitiveOp(_) => non_primitives.push(entry),
115+
AllocationType::WitnessHint => witness_hints.push(entry),
113116
}
114117
}
115118

@@ -256,6 +259,18 @@ fn dump_internal_log(allocation_log: &[AllocationEntry]) {
256259
}
257260
tracing::debug!("");
258261
}
262+
263+
if !witness_hints.is_empty() {
264+
tracing::debug!("--- Witness Hints ({}) ---", witness_hints.len());
265+
for entry in witness_hints {
266+
tracing::debug!(
267+
" expr_{} (WitnessHint){}",
268+
entry.expr_id.0,
269+
display_label(entry.label)
270+
);
271+
}
272+
tracing::debug!("");
273+
}
259274
}
260275

261276
/// List all unique scopes present in the allocation log.

circuit/src/builder/circuit_builder.rs

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use alloc::vec::Vec;
2+
use core::hash::Hash;
23

34
use hashbrown::HashMap;
4-
use p3_field::PrimeCharacteristicRing;
5+
use p3_field::{Field, PrimeCharacteristicRing};
56

67
use super::compiler::{ExpressionLowerer, NonPrimitiveLowerer, Optimizer};
78
use super::{BuilderConfig, ExpressionBuilder, PublicInputTracker};
@@ -122,6 +123,18 @@ where
122123
self.public_tracker.count()
123124
}
124125

126+
/// Allocates a witness hint (uninitialized witness slot set during non-primitive execution).
127+
#[must_use]
128+
pub fn alloc_witness_hint(&mut self, label: &'static str) -> ExprId {
129+
self.expr_builder.add_witness_hint(label)
130+
}
131+
132+
/// Allocates multiple witness hints.
133+
#[must_use]
134+
pub fn alloc_witness_hints(&mut self, count: usize, label: &'static str) -> Vec<ExprId> {
135+
self.expr_builder.add_witness_hints(count, label)
136+
}
137+
125138
/// Adds a constant to the circuit (deduplicated).
126139
///
127140
/// If this value was previously added, returns the original ExprId.
@@ -299,7 +312,7 @@ where
299312

300313
impl<F> CircuitBuilder<F>
301314
where
302-
F: Clone + PrimeCharacteristicRing + PartialEq + Eq + core::hash::Hash,
315+
F: Field + Clone + PrimeCharacteristicRing + PartialEq + Eq + Hash,
303316
{
304317
/// Builds the circuit into a Circuit with separate lowering and IR transformation stages.
305318
/// Returns an error if lowering fails due to an internal inconsistency.
@@ -333,7 +346,7 @@ where
333346
let primitive_ops = optimizer.optimize(primitive_ops);
334347

335348
// Stage 4: Generate final circuit
336-
let mut circuit = Circuit::new(witness_count);
349+
let mut circuit = Circuit::new(witness_count, expr_to_widx);
337350
circuit.primitive_ops = primitive_ops;
338351
circuit.non_primitive_ops = lowered_non_primitive_ops;
339352
circuit.public_rows = public_rows;
@@ -478,7 +491,7 @@ mod tests {
478491
assert!(circuit.enabled_ops.is_empty());
479492

480493
match &circuit.primitive_ops[0] {
481-
crate::op::Prim::Const { out, val } => {
494+
crate::op::Op::Const { out, val } => {
482495
assert_eq!(*out, WitnessId(0));
483496
assert_eq!(*val, BabyBear::ZERO);
484497
}
@@ -501,23 +514,23 @@ mod tests {
501514
assert_eq!(circuit.primitive_ops.len(), 3);
502515

503516
match &circuit.primitive_ops[0] {
504-
crate::op::Prim::Const { out, val } => {
517+
crate::op::Op::Const { out, val } => {
505518
assert_eq!(*out, WitnessId(0));
506519
assert_eq!(*val, BabyBear::ZERO);
507520
}
508521
_ => panic!("Expected Const at index 0"),
509522
}
510523

511524
match &circuit.primitive_ops[1] {
512-
crate::op::Prim::Public { out, public_pos } => {
525+
crate::op::Op::Public { out, public_pos } => {
513526
assert_eq!(*out, WitnessId(1));
514527
assert_eq!(*public_pos, 0);
515528
}
516529
_ => panic!("Expected Public at index 1"),
517530
}
518531

519532
match &circuit.primitive_ops[2] {
520-
crate::op::Prim::Public { out, public_pos } => {
533+
crate::op::Op::Public { out, public_pos } => {
521534
assert_eq!(*out, WitnessId(2));
522535
assert_eq!(*public_pos, 1);
523536
}
@@ -543,23 +556,23 @@ mod tests {
543556
assert_eq!(circuit.primitive_ops.len(), 3);
544557

545558
match &circuit.primitive_ops[0] {
546-
crate::op::Prim::Const { out, val } => {
559+
crate::op::Op::Const { out, val } => {
547560
assert_eq!(*out, WitnessId(0));
548561
assert_eq!(*val, BabyBear::ZERO);
549562
}
550563
_ => panic!("Expected Const at index 0"),
551564
}
552565

553566
match &circuit.primitive_ops[1] {
554-
crate::op::Prim::Const { out, val } => {
567+
crate::op::Op::Const { out, val } => {
555568
assert_eq!(*out, WitnessId(1));
556569
assert_eq!(*val, BabyBear::from_u64(1));
557570
}
558571
_ => panic!("Expected Const at index 1"),
559572
}
560573

561574
match &circuit.primitive_ops[2] {
562-
crate::op::Prim::Const { out, val } => {
575+
crate::op::Op::Const { out, val } => {
563576
assert_eq!(*out, WitnessId(2));
564577
assert_eq!(*val, BabyBear::from_u64(2));
565578
}
@@ -581,7 +594,7 @@ mod tests {
581594
assert_eq!(circuit.primitive_ops.len(), 4);
582595

583596
match &circuit.primitive_ops[3] {
584-
crate::op::Prim::Add { out, a, b } => {
597+
crate::op::Op::Add { out, a, b } => {
585598
assert_eq!(*out, WitnessId(3));
586599
assert_eq!(*a, WitnessId(1));
587600
assert_eq!(*b, WitnessId(2));

0 commit comments

Comments
 (0)