-
Notifications
You must be signed in to change notification settings - Fork 248
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: update to ACVM 0.16.0 (#1863)
* feat!: update to ACVM 0.16.0 * update acvm commit hash * chore: bump to latest acvm version * chore: fix test * chore: remove stale comment * chore: remove clones from `Language` * chore: support arbitrary numbers of foreign calls * chore: update to crates.io releases --------- Co-authored-by: kevaundray <kevtheappdev@gmail.com>
- Loading branch information
1 parent
2ef9c34
commit 9c89def
Showing
13 changed files
with
118 additions
and
126 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,62 @@ | ||
use acvm::acir::circuit::Opcode; | ||
use acvm::pwg::{solve, Blocks, PartialWitnessGeneratorStatus, UnresolvedBrilligCall}; | ||
use acvm::PartialWitnessGenerator; | ||
use acvm::acir::brillig_vm::ForeignCallResult; | ||
use acvm::pwg::{ACVMStatus, ForeignCallWaitInfo, ACVM}; | ||
use acvm::BlackBoxFunctionSolver; | ||
use acvm::{acir::circuit::Circuit, acir::native_types::WitnessMap}; | ||
|
||
use crate::NargoError; | ||
|
||
pub fn execute_circuit( | ||
backend: &impl PartialWitnessGenerator, | ||
pub fn execute_circuit<B: BlackBoxFunctionSolver + Default>( | ||
_backend: &B, | ||
circuit: Circuit, | ||
mut initial_witness: WitnessMap, | ||
initial_witness: WitnessMap, | ||
) -> Result<WitnessMap, NargoError> { | ||
let mut blocks = Blocks::default(); | ||
let solver_status = solve(backend, &mut initial_witness, &mut blocks, circuit.opcodes)?; | ||
let mut acvm = ACVM::new(B::default(), circuit.opcodes, initial_witness); | ||
|
||
// TODO(#1615): Nargo only supports "oracle_print_**_impl" functions that print a singular value or an array and nothing else | ||
// This should be expanded in a general logging refactor | ||
if let PartialWitnessGeneratorStatus::RequiresOracleData { | ||
unresolved_brillig_calls, | ||
required_oracle_data, | ||
unsolved_opcodes, | ||
} = solver_status | ||
{ | ||
if !required_oracle_data.is_empty() { | ||
unreachable!("oracles are not supported by nargo execute") | ||
} | ||
for unresolved_brillig_call in unresolved_brillig_calls { | ||
let UnresolvedBrilligCall { foreign_call_wait_info, mut brillig } = | ||
unresolved_brillig_call; | ||
loop { | ||
let solver_status = acvm.solve(); | ||
|
||
// Execute foreign calls | ||
// TODO(#1615): "oracle_print_impl" and "oracle_print_array_impl" are just identity funcs | ||
if foreign_call_wait_info.function == "oracle_print_impl" { | ||
let values = &foreign_call_wait_info.inputs[0]; | ||
println!("{:?}", values[0].to_field().to_hex()); | ||
brillig.foreign_call_results.push(foreign_call_wait_info.inputs[0][0].into()); | ||
} else if foreign_call_wait_info.function == "oracle_print_array_impl" { | ||
let mut outputs_hex = Vec::new(); | ||
for values in foreign_call_wait_info.inputs.clone() { | ||
for value in values { | ||
outputs_hex.push(value.to_field().to_hex()); | ||
} | ||
match solver_status { | ||
ACVMStatus::Solved => break, | ||
ACVMStatus::InProgress => { | ||
unreachable!("Execution should not stop while in `InProgress` state.") | ||
} | ||
ACVMStatus::Failure(error) => return Err(error.into()), | ||
ACVMStatus::RequiresForeignCall => { | ||
while let Some(foreign_call) = acvm.get_pending_foreign_call() { | ||
let foreign_call_result = execute_foreign_call(foreign_call); | ||
acvm.resolve_pending_foreign_call(foreign_call_result); | ||
} | ||
// Join all of the hex strings using a comma | ||
let comma_separated_elements = outputs_hex.join(", "); | ||
let output_witnesses_string = "[".to_owned() + &comma_separated_elements + "]"; | ||
println!("{output_witnesses_string}"); | ||
brillig.foreign_call_results.push(foreign_call_wait_info.inputs[0][0].into()); | ||
} | ||
} | ||
} | ||
|
||
let mut next_opcodes_for_solving = vec![Opcode::Brillig(brillig)]; | ||
next_opcodes_for_solving.extend_from_slice(&unsolved_opcodes[..]); | ||
let solved_witness = acvm.finalize(); | ||
Ok(solved_witness) | ||
} | ||
|
||
let solver_status = | ||
solve(backend, &mut initial_witness, &mut blocks, next_opcodes_for_solving)?; | ||
if matches!(solver_status, PartialWitnessGeneratorStatus::RequiresOracleData { .. }) { | ||
todo!("Add multiple foreign call support to nargo execute") | ||
// TODO 1557 | ||
fn execute_foreign_call(foreign_call: &ForeignCallWaitInfo) -> ForeignCallResult { | ||
// TODO(#1615): Nargo only supports "oracle_print_**_impl" functions that print a singular value or an array and nothing else | ||
// This should be expanded in a general logging refactor | ||
match foreign_call.function.as_str() { | ||
"oracle_print_impl" => { | ||
let values = &foreign_call.inputs[0]; | ||
println!("{:?}", values[0].to_field().to_hex()); | ||
values[0].into() | ||
} | ||
"oracle_print_array_impl" => { | ||
let mut outputs_hex = Vec::new(); | ||
for values in &foreign_call.inputs { | ||
for value in values { | ||
outputs_hex.push(value.to_field().to_hex()); | ||
} | ||
} | ||
// Join all of the hex strings using a comma | ||
let comma_separated_elements = outputs_hex.join(", "); | ||
let output_witnesses_string = "[".to_owned() + &comma_separated_elements + "]"; | ||
println!("{output_witnesses_string}"); | ||
|
||
foreign_call.inputs[0][0].into() | ||
} | ||
_ => panic!("unexpected foreign call type"), | ||
} | ||
|
||
Ok(initial_witness) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.