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

chore: remove foreign calls array from Brillig VM constructor #7337

Merged
merged 2 commits into from
Feb 10, 2025
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
2 changes: 1 addition & 1 deletion acvm-repo/acvm/src/pwg/brillig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ impl<'b, B: BlackBoxFunctionSolver<F>, F: AcirField> BrilligSolver<'b, F, B> {

// Instantiate a Brillig VM given the solved calldata
// along with the Brillig bytecode.
let vm = VM::new(calldata, brillig_bytecode, vec![], bb_solver, profiling_active);
let vm = VM::new(calldata, brillig_bytecode, bb_solver, profiling_active);
Ok(vm)
}

Expand Down
25 changes: 12 additions & 13 deletions acvm-repo/brillig_vm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@
pub fn new(
calldata: Vec<F>,
bytecode: &'a [Opcode<F>],
foreign_call_results: Vec<ForeignCallResult<F>>,
black_box_solver: &'a B,
profiling_active: bool,
) -> Self {
Expand All @@ -117,7 +116,7 @@
calldata,
program_counter: 0,
foreign_call_counter: 0,
foreign_call_results,
foreign_call_results: Vec::new(),
bytecode,
status: VMStatus::InProgress,
memory: Memory::default(),
Expand Down Expand Up @@ -390,7 +389,7 @@
self.set_program_counter(*location)
}
Opcode::Const { destination, value, bit_size } => {
// Consts are not checked in runtime to fit in the bit size, since they can safely be checked statically.

Check warning on line 392 in acvm-repo/brillig_vm/src/lib.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (Consts)
self.memory.write(*destination, MemoryValue::new_from_field(*value, *bit_size));
self.increment_program_counter()
}
Expand Down Expand Up @@ -857,7 +856,7 @@

// Start VM
let solver = StubbedBlackBoxSolver::default();
let mut vm = VM::new(calldata, &opcodes, vec![], &solver, false);
let mut vm = VM::new(calldata, &opcodes, &solver, false);

let status = vm.process_opcode();
assert_eq!(status, VMStatus::Finished { return_data_offset: 0, return_data_size: 0 });
Expand Down Expand Up @@ -908,7 +907,7 @@
];

let solver = StubbedBlackBoxSolver::default();
let mut vm = VM::new(calldata, &opcodes, vec![], &solver, false);
let mut vm = VM::new(calldata, &opcodes, &solver, false);

let status = vm.process_opcode();
assert_eq!(status, VMStatus::InProgress);
Expand All @@ -930,7 +929,7 @@
}

#[test]
fn jmpifnot_opcode() {

Check warning on line 932 in acvm-repo/brillig_vm/src/lib.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (jmpifnot)
let calldata: Vec<FieldElement> = vec![1u128.into(), 2u128.into()];

let opcodes = vec![
Expand Down Expand Up @@ -977,7 +976,7 @@
];

let solver = StubbedBlackBoxSolver::default();
let mut vm = VM::new(calldata, &opcodes, vec![], &solver, false);
let mut vm = VM::new(calldata, &opcodes, &solver, false);

let status = vm.process_opcode();
assert_eq!(status, VMStatus::InProgress);
Expand Down Expand Up @@ -1050,7 +1049,7 @@
},
];
let solver = StubbedBlackBoxSolver::default();
let mut vm = VM::new(calldata, opcodes, vec![], &solver, false);
let mut vm = VM::new(calldata, opcodes, &solver, false);

let status = vm.process_opcode();
assert_eq!(status, VMStatus::InProgress);
Expand Down Expand Up @@ -1111,7 +1110,7 @@
},
];
let solver = StubbedBlackBoxSolver::default();
let mut vm = VM::new(calldata, opcodes, vec![], &solver, false);
let mut vm = VM::new(calldata, opcodes, &solver, false);

let status = vm.process_opcode();
assert_eq!(status, VMStatus::InProgress);
Expand Down Expand Up @@ -1158,7 +1157,7 @@
Opcode::Mov { destination: MemoryAddress::direct(2), source: MemoryAddress::direct(0) },
];
let solver = StubbedBlackBoxSolver::default();
let mut vm = VM::new(calldata, opcodes, vec![], &solver, false);
let mut vm = VM::new(calldata, opcodes, &solver, false);

let status = vm.process_opcode();
assert_eq!(status, VMStatus::InProgress);
Expand All @@ -1180,7 +1179,7 @@
}

#[test]
fn cmov_opcode() {

Check warning on line 1182 in acvm-repo/brillig_vm/src/lib.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (cmov)
let calldata: Vec<FieldElement> =
vec![(0u128).into(), (1u128).into(), (2u128).into(), (3u128).into()];

Expand Down Expand Up @@ -1224,7 +1223,7 @@
},
];
let solver = StubbedBlackBoxSolver::default();
let mut vm = VM::new(calldata, opcodes, vec![], &solver, false);
let mut vm = VM::new(calldata, opcodes, &solver, false);

let status = vm.process_opcode();
assert_eq!(status, VMStatus::InProgress);
Expand Down Expand Up @@ -1321,7 +1320,7 @@
.chain([equal_opcode, not_equal_opcode, less_than_opcode, less_than_equal_opcode])
.collect();
let solver = StubbedBlackBoxSolver::default();
let mut vm = VM::new(calldata, &opcodes, vec![], &solver, false);
let mut vm = VM::new(calldata, &opcodes, &solver, false);

// Calldata copy
let status = vm.process_opcode();
Expand Down Expand Up @@ -1437,7 +1436,7 @@
}

#[test]
fn iconst_opcode() {

Check warning on line 1439 in acvm-repo/brillig_vm/src/lib.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (iconst)
let opcodes = &[
Opcode::Const {
destination: MemoryAddress::direct(0),
Expand All @@ -1451,7 +1450,7 @@
},
];
let solver = StubbedBlackBoxSolver::default();
let mut vm = VM::new(vec![], opcodes, vec![], &solver, false);
let mut vm = VM::new(vec![], opcodes, &solver, false);

let status = vm.process_opcode();
assert_eq!(status, VMStatus::InProgress);
Expand Down Expand Up @@ -1678,7 +1677,7 @@
opcodes: &'a [Opcode<F>],
solver: &'a StubbedBlackBoxSolver,
) -> VM<'a, F, StubbedBlackBoxSolver> {
let mut vm = VM::new(calldata, opcodes, vec![], solver, false);
let mut vm = VM::new(calldata, opcodes, solver, false);
brillig_execute(&mut vm);
assert_eq!(vm.call_stack, vec![]);
vm
Expand Down Expand Up @@ -2366,7 +2365,7 @@
];

let solver = StubbedBlackBoxSolver::default();
let mut vm = VM::new(calldata, &opcodes, vec![], &solver, false);
let mut vm = VM::new(calldata, &opcodes, &solver, false);

vm.process_opcode();
vm.process_opcode();
Expand Down
2 changes: 1 addition & 1 deletion compiler/noirc_evaluator/src/acir/brillig_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ fn execute_brillig<F: AcirField, B: BlackBoxFunctionSolver<F>>(

// Instantiate a Brillig VM given the solved input registers and memory, along with the Brillig bytecode.
let profiling_active = false;
let mut vm = VM::new(calldata, code, Vec::new(), blackbox_solver, profiling_active);
let mut vm = VM::new(calldata, code, blackbox_solver, profiling_active);

// Run the Brillig VM on these inputs, bytecode, etc!
let vm_status = vm.process_opcodes();
Expand Down
23 changes: 15 additions & 8 deletions compiler/noirc_evaluator/src/brillig/brillig_ir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ pub(crate) mod tests {
bytecode: &[BrilligOpcode<FieldElement>],
) -> (VM<'_, FieldElement, DummyBlackBoxSolver>, usize, usize) {
let profiling_active = false;
let mut vm = VM::new(calldata, bytecode, vec![], &DummyBlackBoxSolver, profiling_active);
let mut vm = VM::new(calldata, bytecode, &DummyBlackBoxSolver, profiling_active);

let status = vm.process_opcodes();
if let VMStatus::Finished { return_data_offset, return_data_size } = status {
Expand Down Expand Up @@ -427,15 +427,22 @@ pub(crate) mod tests {
});

let bytecode: Vec<BrilligOpcode<FieldElement>> = context.artifact().finish().byte_code;

let mut vm = VM::new(vec![], &bytecode, &DummyBlackBoxSolver, false);
let status = vm.process_opcodes();
assert_eq!(
status,
VMStatus::ForeignCallWait {
function: "make_number_sequence".to_string(),
inputs: vec![ForeignCallParam::Single(FieldElement::from(12u128))]
}
);

let number_sequence: Vec<FieldElement> =
(0_usize..12_usize).map(FieldElement::from).collect();
let mut vm = VM::new(
vec![],
&bytecode,
vec![ForeignCallResult { values: vec![ForeignCallParam::Array(number_sequence)] }],
&DummyBlackBoxSolver,
false,
);
let response = ForeignCallResult { values: vec![ForeignCallParam::Array(number_sequence)] };
vm.resolve_foreign_call(response);

let status = vm.process_opcodes();
assert_eq!(status, VMStatus::Finished { return_data_offset: 0, return_data_size: 0 });
}
Expand Down
4 changes: 1 addition & 3 deletions compiler/noirc_evaluator/src/ssa/opt/constant_folding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -600,12 +600,10 @@ impl<'brillig> Context<'brillig> {
}

let bytecode = &generated_brillig.byte_code;
let foreign_call_results = Vec::new();
let pedantic_solving = true;
let black_box_solver = Bn254BlackBoxSolver(pedantic_solving);
let profiling_active = false;
let mut vm =
VM::new(calldata, bytecode, foreign_call_results, &black_box_solver, profiling_active);
let mut vm = VM::new(calldata, bytecode, &black_box_solver, profiling_active);
let vm_status: VMStatus<_> = vm.process_opcodes();
let VMStatus::Finished { return_data_offset, return_data_size } = vm_status else {
return EvaluationResult::CannotEvaluate;
Expand Down
Loading