Skip to content
This repository has been archived by the owner on Apr 9, 2024. It is now read-only.

Commit

Permalink
chore: add method to get slice of unresolved opcodes
Browse files Browse the repository at this point in the history
  • Loading branch information
TomAFrench committed Jun 21, 2023
1 parent aade0c8 commit dbc4945
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
20 changes: 16 additions & 4 deletions acvm/src/pwg/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub enum PartialWitnessGeneratorStatus {
/// to retrieve information from outside of the ACVM. The result of the foreign call must be passed back
/// to the ACVM using [`ACVM::resolve_pending_foreign_call`].
///
/// Once this is done, the `ACVM` can be restarted to solve the remaining opcodes.
/// Once this is done, the ACVM can be restarted to solve the remaining opcodes.
RequiresForeignCall,
}

Expand Down Expand Up @@ -112,13 +112,25 @@ impl<B: PartialWitnessGenerator> ACVM<B> {
}
}

// necessary to fix integration tests. Should replace with a better VM status model.
pub fn remaining_opcodes_len(&self) -> usize {
self.opcodes.len()
/// Returns a reference to the current state of the ACVM's [`WitnessMap`].
///
/// Once execution has completed, the witness map can be extracted using [`ACVM::finalize`]
pub fn witness_map(&self) -> &WitnessMap {
&self.witness_map
}

/// Returns a slice containing the opcodes which remain to be solved.
///
/// Note: this doesn't include any opcodes which are waiting on a pending foreign call.
pub fn unresolved_opcodes(&self) -> &[Opcode] {
&self.opcodes
}

/// Finalize the ACVM execution, returning the resulting [`WitnessMap`].
pub fn finalize(self) -> WitnessMap {
if self.opcodes.is_empty() || self.get_pending_foreign_call().is_some() {
panic!("ACVM is not ready to be finalized");
}
self.witness_map
}

Expand Down
6 changes: 3 additions & 3 deletions acvm/tests/solver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ fn inversion_brillig_oracle_equivalence() {
PartialWitnessGeneratorStatus::RequiresForeignCall,
"Should require oracle data"
);
assert_eq!(acvm.remaining_opcodes_len(), 0, "brillig should have been removed");
assert!(acvm.unresolved_opcodes().is_empty(), "brillig should have been removed");

let foreign_call_wait_info: &ForeignCallWaitInfo =
acvm.get_pending_foreign_call().expect("should have a brillig foreign call request");
Expand Down Expand Up @@ -274,7 +274,7 @@ fn double_inversion_brillig_oracle() {
PartialWitnessGeneratorStatus::RequiresForeignCall,
"Should require oracle data"
);
assert_eq!(acvm.remaining_opcodes_len(), 0, "brillig should have been removed");
assert!(acvm.unresolved_opcodes().is_empty(), "brillig should have been removed");

let foreign_call_wait_info: &ForeignCallWaitInfo =
acvm.get_pending_foreign_call().expect("should have a brillig foreign call request");
Expand All @@ -292,7 +292,7 @@ fn double_inversion_brillig_oracle() {
PartialWitnessGeneratorStatus::RequiresForeignCall,
"Should require oracle data"
);
assert_eq!(acvm.remaining_opcodes_len(), 0, "should be fully solved");
assert!(acvm.unresolved_opcodes().is_empty(), "should be fully solved");

let foreign_call_wait_info =
acvm.get_pending_foreign_call().expect("should have a brillig foreign call request");
Expand Down

0 comments on commit dbc4945

Please sign in to comment.