Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: maintain ordering of return value witnesses when constructing ABI #1177

Merged
merged 1 commit into from
Apr 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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