Skip to content

Commit 5b9e738

Browse files
committed
minor touchups
1 parent fa0612f commit 5b9e738

File tree

4 files changed

+47
-10
lines changed

4 files changed

+47
-10
lines changed

circuit/src/builder/compiler/non_primitive_lowerer.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,10 @@ mod tests {
210210
// Test MmcsVerify with mock config (simplest case: 1 leaf + 1 index + 1 root)
211211
let mock_config = MmcsVerifyConfig::mock_config();
212212
assert_eq!(mock_config.ext_field_digest_elems, 1);
213-
assert_eq!(mock_config.input_size(), 2 * mock_config.ext_field_digest_elems + 1);
213+
assert_eq!(
214+
mock_config.input_size(),
215+
2 * mock_config.ext_field_digest_elems + 1
216+
);
214217

215218
let mut config = BuilderConfig::new();
216219
config.enable_mmcs(&mock_config);

circuit/src/builder/config.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,50 @@ use hashbrown::HashMap;
22

33
use crate::op::{NonPrimitiveOpConfig, NonPrimitiveOpType};
44

5+
/// Configuration for the circuit builder.
56
#[derive(Debug, Clone, Default)]
67
pub struct BuilderConfig {
8+
/// Enabled non-primitive operation types with their respective configuration.
79
enabled_ops: HashMap<NonPrimitiveOpType, NonPrimitiveOpConfig>,
810
}
911

1012
impl BuilderConfig {
13+
/// Creates a new builder configuration.
1114
pub fn new() -> Self {
1215
Self {
1316
enabled_ops: HashMap::new(),
1417
}
1518
}
1619

20+
/// Enables a non-primitive operation type with its configuration.
1721
pub fn enable_op(&mut self, op: NonPrimitiveOpType, cfg: NonPrimitiveOpConfig) {
1822
self.enabled_ops.insert(op, cfg);
1923
}
2024

25+
/// Enables MMCS verification operations with the given configuration.
2126
pub fn enable_mmcs(&mut self, mmcs_config: &crate::ops::MmcsVerifyConfig) {
2227
self.enable_op(
2328
NonPrimitiveOpType::MmcsVerify,
2429
NonPrimitiveOpConfig::MmcsVerifyConfig(mmcs_config.clone()),
2530
);
2631
}
2732

33+
/// Enables FRI verification operations.
2834
pub fn enable_fri(&mut self) {
29-
// TODO when available
35+
// TODO: Add FRI ops when available.
3036
}
3137

38+
/// Checks whether an operation type is enabled.
3239
pub fn is_op_enabled(&self, op: &NonPrimitiveOpType) -> bool {
3340
self.enabled_ops.contains_key(op)
3441
}
3542

43+
/// Gets the configuration for an operation type, if enabled.
3644
pub fn get_op_config(&self, op: &NonPrimitiveOpType) -> Option<&NonPrimitiveOpConfig> {
3745
self.enabled_ops.get(op)
3846
}
3947

48+
/// Consumes the config and returns the enabled operations map.
4049
pub fn into_enabled_ops(self) -> HashMap<NonPrimitiveOpType, NonPrimitiveOpConfig> {
4150
self.enabled_ops
4251
}

circuit/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub use builder::{CircuitBuilder, CircuitBuilderError};
2323
pub use circuit::{Circuit, CircuitField};
2424
pub use errors::CircuitError;
2525
pub use expr::{Expr, ExpressionGraph};
26-
pub use op::{NonPrimitiveOp, NonPrimitiveOpPrivateData, NonPrimitiveOpType, Op};
26+
pub use op::{NonPrimitiveOpPrivateData, NonPrimitiveOpType, Op};
2727
pub use ops::{FriOps, MmcsOps};
2828
pub use tables::{CircuitRunner, MmcsPrivateData, MmcsTrace, Traces};
2929
pub use types::{ExprId, NonPrimitiveOpId, WitnessAllocator, WitnessId};

circuit/src/tables/runner.rs

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,42 @@ impl<F: CircuitField> CircuitRunner<F> {
7171
});
7272
}
7373

74-
// Validate that the private data matches the operation type (if any)
74+
// Validate that the private data matches the operation type
7575
if let Op::NonPrimitiveOpWithExecutor { executor, .. } =
7676
&self.circuit.non_primitive_ops[op_id.0 as usize]
77-
&& let (
78-
crate::op::NonPrimitiveOpType::MmcsVerify,
79-
NonPrimitiveOpPrivateData::MmcsVerify(_),
80-
) = (executor.op_type(), &private_data)
8177
{
82-
// ok
78+
match (executor.op_type(), &private_data) {
79+
(
80+
crate::op::NonPrimitiveOpType::MmcsVerify,
81+
NonPrimitiveOpPrivateData::MmcsVerify(_),
82+
) => {
83+
// ok
84+
}
85+
(op_ty, _) => {
86+
// Other ops currently don't expect private data
87+
return Err(CircuitError::IncorrectNonPrimitiveOpPrivateData {
88+
op: op_ty.clone(),
89+
operation_index: op_id,
90+
expected: format!("no private data"),
91+
got: format!("{private_data:?}"),
92+
});
93+
}
94+
}
95+
}
96+
97+
// Disallow double-setting private data
98+
if self.non_primitive_op_private_data[op_id.0 as usize].is_some() {
99+
if let Op::NonPrimitiveOpWithExecutor { executor, .. } =
100+
&self.circuit.non_primitive_ops[op_id.0 as usize]
101+
{
102+
return Err(CircuitError::IncorrectNonPrimitiveOpPrivateData {
103+
op: executor.op_type().clone(),
104+
operation_index: op_id,
105+
expected: format!("private data not previously set"),
106+
got: format!("already set"),
107+
});
108+
}
83109
}
84-
// Other ops currently don't expect private data
85110

86111
// Store private data for this operation
87112
self.non_primitive_op_private_data[op_id.0 as usize] = Some(private_data);

0 commit comments

Comments
 (0)