Skip to content

Commit

Permalink
chore: remove get_number_sequence foreign calls (#3613)
Browse files Browse the repository at this point in the history
Co-authored-by: kevaundray <[email protected]>
  • Loading branch information
TomAFrench and kevaundray authored Nov 28, 2023
1 parent 9e1717c commit e72f5af
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 37 deletions.
28 changes: 22 additions & 6 deletions test_programs/execution_success/brillig_oracle/src/main.nr
Original file line number Diff line number Diff line change
@@ -1,25 +1,41 @@
use dep::std::slice;
use dep::std::test::OracleMock;

// Tests oracle usage in brillig/unconstrained functions
fn main(x: Field) {
get_number_sequence_wrapper(20);
let size = 20;
// TODO: Add a method along the lines of `(0..size).to_array()`.
let mut mock_oracle_response = [0; 20];
// TODO: Add an `array.reverse()` method.
let mut reversed_mock_oracle_response = [0; 20];
for i in 0..size {
mock_oracle_response[i] = i;
reversed_mock_oracle_response[19 - i] = i;
}

// TODO: this method of returning a slice feels hacky.
let _ = OracleMock::mock("get_number_sequence").with_params(size).returns((20, mock_oracle_response));
let _ = OracleMock::mock("get_reverse_number_sequence").with_params(size).returns((20, reversed_mock_oracle_response));

get_number_sequence_wrapper(size);
}
// TODO(#1911): This function does not need to be an oracle but acts
// as a useful test while we finalize code generation for slices in Brillig

// Define oracle functions which we have mocked above
#[oracle(get_number_sequence)]
unconstrained fn get_number_sequence(_size: Field) -> [Field] {}
// TODO(#1911)

#[oracle(get_reverse_number_sequence)]
unconstrained fn get_reverse_number_sequence(_size: Field) -> [Field] {}

unconstrained fn get_number_sequence_wrapper(size: Field) {
let slice = get_number_sequence(size);
for i in 0..19 as u32 {
for i in 0..20 as u32 {
assert(slice[i] == i as Field);
}

let reversed_slice = get_reverse_number_sequence(size);
// Regression test that we have not overwritten memory
for i in 0..19 as u32 {
for i in 0..20 as u32 {
assert(slice[i] == reversed_slice[19 - i]);
}
}
Expand Down
31 changes: 0 additions & 31 deletions tooling/nargo/src/ops/foreign_calls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use acvm::{
acir::brillig::{ForeignCallParam, ForeignCallResult, Value},
pwg::ForeignCallWaitInfo,
};
use iter_extended::vecmap;
use noirc_printable_type::{decode_string_value, ForeignCallError, PrintableValueDisplay};

pub trait ForeignCallExecutor {
Expand All @@ -16,8 +15,6 @@ pub trait ForeignCallExecutor {
/// After resolution of a foreign call, nargo will restart execution of the ACVM
pub(crate) enum ForeignCall {
Println,
Sequence,
ReverseSequence,
CreateMock,
SetMockParams,
SetMockReturns,
Expand All @@ -35,8 +32,6 @@ impl ForeignCall {
pub(crate) fn name(&self) -> &'static str {
match self {
ForeignCall::Println => "println",
ForeignCall::Sequence => "get_number_sequence",
ForeignCall::ReverseSequence => "get_reverse_number_sequence",
ForeignCall::CreateMock => "create_mock",
ForeignCall::SetMockParams => "set_mock_params",
ForeignCall::SetMockReturns => "set_mock_returns",
Expand All @@ -48,8 +43,6 @@ impl ForeignCall {
pub(crate) fn lookup(op_name: &str) -> Option<ForeignCall> {
match op_name {
"println" => Some(ForeignCall::Println),
"get_number_sequence" => Some(ForeignCall::Sequence),
"get_reverse_number_sequence" => Some(ForeignCall::ReverseSequence),
"create_mock" => Some(ForeignCall::CreateMock),
"set_mock_params" => Some(ForeignCall::SetMockParams),
"set_mock_returns" => Some(ForeignCall::SetMockReturns),
Expand Down Expand Up @@ -147,30 +140,6 @@ impl ForeignCallExecutor for DefaultForeignCallExecutor {
}
Ok(ForeignCallResult { values: vec![] })
}
Some(ForeignCall::Sequence) => {
let sequence_length: u128 =
foreign_call.inputs[0].unwrap_value().to_field().to_u128();
let sequence = vecmap(0..sequence_length, Value::from);

Ok(ForeignCallResult {
values: vec![
ForeignCallParam::Single(sequence_length.into()),
ForeignCallParam::Array(sequence),
],
})
}
Some(ForeignCall::ReverseSequence) => {
let sequence_length: u128 =
foreign_call.inputs[0].unwrap_value().to_field().to_u128();
let sequence = vecmap((0..sequence_length).rev(), Value::from);

Ok(ForeignCallResult {
values: vec![
ForeignCallParam::Single(sequence_length.into()),
ForeignCallParam::Array(sequence),
],
})
}
Some(ForeignCall::CreateMock) => {
let mock_oracle_name = Self::parse_string(&foreign_call.inputs[0]);
assert!(ForeignCall::lookup(&mock_oracle_name).is_none());
Expand Down

0 comments on commit e72f5af

Please sign in to comment.