Skip to content

Commit

Permalink
fix: maintain ordering of return value witnesses when constructing ABI (
Browse files Browse the repository at this point in the history
#1177)

fix: maintain ordering of return value witnesses
  • Loading branch information
TomAFrench authored Apr 19, 2023
1 parent 73df465 commit b799c8a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 6 additions & 4 deletions crates/noirc_evaluator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ pub struct Evaluator {
// Witnesses below `num_witnesses_abi_len` and not included in this set
// correspond to private parameters and must not be made public.
public_parameters: BTreeSet<Witness>,
return_values: BTreeSet<Witness>,
// The witness indices for return values are not guaranteed to be contiguous
// and increasing as for `public_parameters`. We then use a `Vec` rather
// than a `BTreeSet` to preserve this order for the ABI.
return_values: Vec<Witness>,

opcodes: Vec<AcirOpcode>,
}
Expand Down Expand Up @@ -78,16 +81,15 @@ pub fn create_circuit(
current_witness_index,
opcodes,
public_parameters: PublicInputs(public_parameters),
return_values: PublicInputs(return_values.clone()),
return_values: PublicInputs(return_values.iter().copied().collect()),
},
np_language,
is_opcode_supported,
)
.map_err(|_| RuntimeErrorKind::Spanless(String::from("produced an acvm compile error")))?;

let (parameters, return_type) = program.main_function_signature;
let return_witnesses: Vec<Witness> = return_values.into_iter().collect();
let abi = Abi { parameters, param_witnesses, return_type, return_witnesses };
let abi = Abi { parameters, param_witnesses, return_type, return_witnesses: return_values };

Ok((optimized_circuit, abi))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub(crate) fn evaluate(
"we do not allow private ABI inputs to be returned as public outputs",
)));
}
evaluator.return_values.insert(witness);
evaluator.return_values.push(witness);
}
}

Expand Down

0 comments on commit b799c8a

Please sign in to comment.