Skip to content

Commit

Permalink
Merge pull request #288 from 0xPolygonMiden/tohrnii-evaluator-fix
Browse files Browse the repository at this point in the history
fix(ir): throw an error on segment mismatch in evaluators
tohrnii authored May 1, 2023

Unverified

The committer email address is not verified.
2 parents 65bb98d + 8857f6e commit db86cfc
Showing 3 changed files with 42 additions and 2 deletions.
11 changes: 9 additions & 2 deletions ir/src/constraint_builder/evaluators.rs
Original file line number Diff line number Diff line change
@@ -78,11 +78,18 @@ impl ConstraintBuilder {
) -> Result<Vec<Vec<usize>>, SemanticError> {
// get the offsets for the trace binding accesses as a vector of indices
let mut offsets: Vec<Vec<usize>> = Vec::new();
for segment in args.iter() {
for (segment, segment_binding_access) in args.iter().enumerate() {
let mut segment_offsets = Vec::new();
for trace_binding_access in segment {
for trace_binding_access in segment_binding_access {
let trace_access = self.symbol_table.get_trace_access(trace_binding_access)?;

if trace_access.trace_segment() as usize != segment {
return Err(SemanticError::evaluator_trace_segment_mismatch(
trace_access.trace_segment(),
segment,
));
}

// bindings referencing more than one trace element must be split into one offset
// per trace element.
for inner_offset in 0..trace_access.size() {
24 changes: 24 additions & 0 deletions ir/src/tests/evaluators.rs
Original file line number Diff line number Diff line change
@@ -177,3 +177,27 @@ fn ev_fn_call_with_column_group() {
let result = AirIR::new(parsed);
assert!(result.is_ok());
}

#[test]
fn err_ev_fn_call_wrong_segment_columns() {
let source = "
ev is_binary([x]):
enf x^2 = x
trace_columns:
main: [b]
aux: [c]
public_inputs:
stack_inputs: [16]
boundary_constraints:
enf b.first = 0
integrity_constraints:
enf is_binary([c])";

let parsed = parse(source).expect("Parsing failed");
let result = AirIR::new(parsed);
assert!(result.is_err());
}
9 changes: 9 additions & 0 deletions ir/src/validation/error.rs
Original file line number Diff line number Diff line change
@@ -157,6 +157,15 @@ impl SemanticError {
))
}

pub(crate) fn evaluator_trace_segment_mismatch(
trace_segment: u8,
required_segment: usize,
) -> Self {
SemanticError::InvalidUsage(format!(
"Evaluator function expected binding in trace segment {required_segment}, but was given binding in trace segment {trace_segment}.",
))
}

// --- INVALID CONSTRAINT ERRORS --------------------------------------------------------------

pub(crate) fn incompatible_constraint_domains(

0 comments on commit db86cfc

Please sign in to comment.