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

feat: Sync from noir #6986

Merged
merged 36 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
0e01b10
[1 changes] feat!: add session id to foreign call RPC requests (https…
AztecBot Jun 10, 2024
667085b
chore: apply sync fixes
AztecBot Jun 10, 2024
bdddac9
Merge branch 'master' into sync-noir
TomAFrench Jun 10, 2024
7eba86e
chore: update cargo.lock
TomAFrench Jun 10, 2024
2470833
Update noir/noir-repo/compiler/integration-tests/test/node/prove_and_…
TomAFrench Jun 10, 2024
14df10d
temp
TomAFrench Jun 10, 2024
9b4b174
Merge branch 'master' into sync-noir
TomAFrench Jun 11, 2024
ff8b27e
Merge branch 'master' into sync-noir
TomAFrench Jun 11, 2024
cb6e6b9
[1 changes] chore: avoid `bn254_blackbox_solver` polluting feature fl…
AztecBot Jun 11, 2024
b456ac1
chore: apply sync fixes
AztecBot Jun 11, 2024
e1dc886
chore: avoid `bn254_blackbox_solver` polluting feature flags (https:/…
AztecBot Jun 11, 2024
c30f091
push a scope in interpreter enter_function even when scopes.len() == 1
vezenovm Jun 11, 2024
f8c16cb
Merge branch 'master' into sync-noir
vezenovm Jun 11, 2024
d7877de
Merge branch 'master' into sync-noir
TomAFrench Jun 12, 2024
ee7965f
try bug fix with checking let_.comptime
vezenovm Jun 12, 2024
b0317ac
Merge remote-tracking branch 'origin/sync-noir' into sync-noir
vezenovm Jun 12, 2024
110385f
nargo fmt
vezenovm Jun 12, 2024
ca708d4
clippy and fmt
vezenovm Jun 12, 2024
5b34bec
Merge branch 'master' into sync-noir
vezenovm Jun 12, 2024
b1bc45d
a little debug cleanup
vezenovm Jun 12, 2024
ffecb8c
Merge remote-tracking branch 'origin/sync-noir' into sync-noir
vezenovm Jun 12, 2024
7d08148
nargo fmt aztec-nr
vezenovm Jun 12, 2024
14235fe
cleanup old debug stuff
vezenovm Jun 12, 2024
1eb3857
bring back verify_honk_proof test
vezenovm Jun 12, 2024
8f41207
format verify_honk_proof
vezenovm Jun 12, 2024
c1f3881
bring back honk_recursion flag that got reverted
vezenovm Jun 12, 2024
c9234c8
fix up hardcoded abis in noirc_abi_wasm
vezenovm Jun 12, 2024
b04cc42
update yarn lock
vezenovm Jun 12, 2024
6e45192
bring back testing integration-tests in series that was reverted
vezenovm Jun 12, 2024
e819ebe
one backendi nstance in prove_and_verify.test.ts integration-tests
vezenovm Jun 12, 2024
a6da3b3
Merge branch 'master' into sync-noir
vezenovm Jun 13, 2024
7fd2bec
Merge branch 'master' into sync-noir
vezenovm Jun 13, 2024
62996ab
remove last references to param_witnesses
vezenovm Jun 13, 2024
f5d1dda
Merge branch 'master' into sync-noir
vezenovm Jun 13, 2024
b2e8fe1
delete noir yarn.lock
vezenovm Jun 13, 2024
d8fa1c7
Merge remote-tracking branch 'origin/sync-noir' into sync-noir
vezenovm Jun 13, 2024
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 .noir-sync-commit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
9c99a97ca8f42bee23cf97ebd724fdc51e647c60
14adafc965fa9c833e096ec037e086aae67703ad
1 change: 1 addition & 0 deletions avm-transpiler/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions noir/noir-repo/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions noir/noir-repo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ similar-asserts = "1.5.0"
tempfile = "3.6.0"
jsonrpc = { version = "0.16.0", features = ["minreq_http"] }
flate2 = "1.0.24"
rand = "0.8.5"

im = { version = "15.1", features = ["serde"] }
tracing = "0.1.40"
Expand Down
2 changes: 1 addition & 1 deletion noir/noir-repo/acvm-repo/acir_field/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
#![warn(unreachable_pub)]
#![warn(clippy::semicolon_if_nothing_returned)]
#![cfg_attr(not(test), warn(unused_crate_dependencies, unused_extern_crates))]
mod generic_ark;

mod field_element;
mod generic_ark;

pub use generic_ark::AcirField;

Expand Down
3 changes: 2 additions & 1 deletion noir/noir-repo/acvm-repo/acvm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ repository.workspace = true
num-bigint.workspace = true
thiserror.workspace = true
tracing.workspace = true
serde.workspace = true

acir.workspace = true
brillig_vm.workspace = true
Expand All @@ -36,7 +37,7 @@ bls12_381 = [
]

[dev-dependencies]
rand = "0.8.5"
rand.workspace = true
proptest = "1.2.0"
paste = "1.0.14"
ark-bls12-381 = { version = "^0.4.0", default-features = false, features = ["curve"] }
3 changes: 2 additions & 1 deletion noir/noir-repo/acvm-repo/acvm/src/pwg/brillig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use acir::{
};
use acvm_blackbox_solver::BlackBoxFunctionSolver;
use brillig_vm::{FailureReason, MemoryValue, VMStatus, VM};
use serde::{Deserialize, Serialize};

use crate::{pwg::OpcodeNotSolvable, OpcodeResolutionError};

Expand Down Expand Up @@ -286,7 +287,7 @@ impl<'b, B: BlackBoxFunctionSolver<F>, F: AcirField> BrilligSolver<'b, F, B> {
/// where the result of the foreign call has not yet been provided.
///
/// The caller must resolve this opcode externally based upon the information in the request.
#[derive(Debug, PartialEq, Clone)]
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
pub struct ForeignCallWaitInfo<F> {
/// An identifier interpreted by the caller process
pub function: String,
Expand Down
1 change: 1 addition & 0 deletions noir/noir-repo/acvm-repo/brillig/src/foreign_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use serde::{Deserialize, Serialize};

/// Single output of a [foreign call][crate::Opcode::ForeignCall].
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone)]
#[serde(untagged)]
pub enum ForeignCallParam<F> {
Single(F),
Array(Vec<F>),
Expand Down
64 changes: 32 additions & 32 deletions noir/noir-repo/compiler/integration-tests/package.json
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
{
"name": "integration-tests",
"license": "(MIT OR Apache-2.0)",
"main": "index.js",
"private": true,
"scripts": {
"build": "echo Integration Test build step",
"test": "yarn test:browser && yarn test:node",
"test:node": "bash ./scripts/setup.sh && hardhat test test/node/prove_and_verify.test.ts && hardhat test test/node/smart_contract_verifier.test.ts && hardhat test test/node/onchain_recursive_verification.test.ts",
"test:browser": "web-test-runner",
"test:integration:browser": "web-test-runner test/browser/**/*.test.ts",
"test:integration:browser:watch": "web-test-runner test/browser/**/*.test.ts --watch",
"lint": "NODE_NO_WARNINGS=1 eslint . --ext .ts --ignore-path ./.eslintignore --max-warnings 0"
},
"dependencies": {
"@noir-lang/backend_barretenberg": "workspace:*",
"@noir-lang/noir_js": "workspace:*",
"@noir-lang/noir_wasm": "workspace:*",
"@nomicfoundation/hardhat-chai-matchers": "^2.0.0",
"@nomicfoundation/hardhat-ethers": "^3.0.0",
"@web/dev-server-esbuild": "^0.3.6",
"@web/dev-server-import-maps": "^0.2.0",
"@web/test-runner": "^0.18.1",
"@web/test-runner-playwright": "^0.10.0",
"eslint": "^8.57.0",
"eslint-plugin-prettier": "^5.1.3",
"ethers": "^6.7.1",
"hardhat": "^2.17.4",
"prettier": "3.2.5",
"smol-toml": "^1.1.2",
"toml": "^3.0.0",
"tslog": "^4.9.2"
}
"name": "integration-tests",
"license": "(MIT OR Apache-2.0)",
"main": "index.js",
"private": true,
"scripts": {
"build": "echo Integration Test build step",
"test": "yarn test:browser && yarn test:node",
"test:node": "bash ./scripts/setup.sh && hardhat test test/node/**/*",
"test:browser": "web-test-runner",
"test:integration:browser": "web-test-runner test/browser/**/*.test.ts",
"test:integration:browser:watch": "web-test-runner test/browser/**/*.test.ts --watch",
"lint": "NODE_NO_WARNINGS=1 eslint . --ext .ts --ignore-path ./.eslintignore --max-warnings 0"
},
"dependencies": {
"@noir-lang/backend_barretenberg": "workspace:*",
"@noir-lang/noir_js": "workspace:*",
"@noir-lang/noir_wasm": "workspace:*",
"@nomicfoundation/hardhat-chai-matchers": "^2.0.0",
"@nomicfoundation/hardhat-ethers": "^3.0.0",
"@web/dev-server-esbuild": "^0.3.6",
"@web/dev-server-import-maps": "^0.2.0",
"@web/test-runner": "^0.18.1",
"@web/test-runner-playwright": "^0.10.0",
"eslint": "^8.57.0",
"eslint-plugin-prettier": "^5.1.3",
"ethers": "^6.7.1",
"hardhat": "^2.17.4",
"prettier": "3.2.5",
"smol-toml": "^1.1.2",
"toml": "^3.0.0",
"tslog": "^4.9.2"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ it('end-to-end proof creation and verification (outer)', async () => {
const proof = await backend.generateProof(witness);

// Proof verification
const isValid = await backend.verifyProof(proof);
const isValid = await prover.verifyProof(proof);
TomAFrench marked this conversation as resolved.
Show resolved Hide resolved
expect(isValid).to.be.true;
});

Expand All @@ -44,7 +44,7 @@ it('end-to-end proof creation and verification (outer) -- Verifier API', async (
const { witness } = await program.execute(inputs);

// Generate proof
// const backend = new Backend(assert_lt_program);
const backend = new Backend(assert_lt_program);
const proof = await backend.generateProof(witness);

const verificationKey = await backend.getVerificationKey();
Expand Down
5 changes: 4 additions & 1 deletion noir/noir-repo/compiler/noirc_evaluator/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ pub enum RuntimeError {
UnconstrainedSliceReturnToConstrained { call_stack: CallStack },
#[error("All `oracle` methods should be wrapped in an unconstrained fn")]
UnconstrainedOracleReturnToConstrained { call_stack: CallStack },
#[error("Could not resolve some references to the array. All references must be resolved at compile time")]
UnknownReference { call_stack: CallStack },
}

#[derive(Debug, Clone, Serialize, Deserialize)]
Expand Down Expand Up @@ -123,7 +125,8 @@ impl RuntimeError {
| RuntimeError::NestedSlice { call_stack, .. }
| RuntimeError::BigIntModulus { call_stack, .. }
| RuntimeError::UnconstrainedSliceReturnToConstrained { call_stack }
| RuntimeError::UnconstrainedOracleReturnToConstrained { call_stack } => call_stack,
| RuntimeError::UnconstrainedOracleReturnToConstrained { call_stack }
| RuntimeError::UnknownReference { call_stack } => call_stack,
}
}
}
Expand Down
10 changes: 8 additions & 2 deletions noir/noir-repo/compiler/noirc_evaluator/src/ssa/acir_gen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,9 @@ impl<'a> Context<'a> {
self.handle_array_operation(instruction_id, dfg)?;
}
Instruction::Allocate => {
unreachable!("Expected all allocate instructions to be removed before acir_gen")
return Err(RuntimeError::UnknownReference {
call_stack: self.acir_context.get_call_stack().clone(),
});
}
Instruction::Store { .. } => {
unreachable!("Expected all store instructions to be removed before acir_gen")
Expand Down Expand Up @@ -839,9 +841,10 @@ impl<'a> Context<'a> {
self.handle_ssa_call_outputs(result_ids, outputs, dfg)?;
}
Value::ForeignFunction(_) => {
// TODO: Remove this once elaborator is default frontend. This is now caught by a lint inside the frontend.
return Err(RuntimeError::UnconstrainedOracleReturnToConstrained {
call_stack: self.acir_context.get_call_stack(),
})
});
}
_ => unreachable!("expected calling a function but got {function_value:?}"),
}
Expand Down Expand Up @@ -1306,6 +1309,9 @@ impl<'a> Context<'a> {
}
Ok(AcirValue::Array(values))
}
Type::Reference(reference_type) => {
self.array_get_value(reference_type.as_ref(), block_id, var_index)
}
_ => unreachable!("ICE: Expected an array or numeric but got {ssa_type:?}"),
}
}
Expand Down
4 changes: 2 additions & 2 deletions noir/noir-repo/compiler/noirc_frontend/src/ast/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub enum ExpressionKind {
Lambda(Box<Lambda>),
Parenthesized(Box<Expression>),
Quote(BlockExpression),
Comptime(BlockExpression),
Comptime(BlockExpression, Span),

// This variant is only emitted when inlining the result of comptime
// code. It is used to translate function values back into the AST while
Expand Down Expand Up @@ -536,7 +536,7 @@ impl Display for ExpressionKind {
Lambda(lambda) => lambda.fmt(f),
Parenthesized(sub_expr) => write!(f, "({sub_expr})"),
Quote(block) => write!(f, "quote {block}"),
Comptime(block) => write!(f, "comptime {block}"),
Comptime(block, _) => write!(f, "comptime {block}"),
Error => write!(f, "Error"),
Resolved(_) => write!(f, "?Resolved"),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl<'context> Elaborator<'context> {
ExpressionKind::Lambda(lambda) => self.elaborate_lambda(*lambda),
ExpressionKind::Parenthesized(expr) => return self.elaborate_expression(*expr),
ExpressionKind::Quote(quote) => self.elaborate_quote(quote),
ExpressionKind::Comptime(comptime) => {
ExpressionKind::Comptime(comptime, _) => {
return self.elaborate_comptime_block(comptime, expr.span)
}
ExpressionKind::Resolved(id) => return (id, self.interner.id_type(id)),
Expand Down
36 changes: 35 additions & 1 deletion noir/noir-repo/compiler/noirc_frontend/src/elaborator/lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{
HirExpression, HirLiteral, NodeInterner, NoirFunction, UnaryOp, UnresolvedTypeData,
Visibility,
},
node_interner::{DefinitionKind, ExprId},
node_interner::{DefinitionKind, ExprId, FuncId},
Type,
};
use acvm::AcirField;
Expand Down Expand Up @@ -72,6 +72,40 @@ pub(super) fn low_level_function_outside_stdlib(
}
}

/// Oracle definitions (functions with the `#[oracle]` attribute) must be marked as unconstrained.
pub(super) fn oracle_not_marked_unconstrained(func: &NoirFunction) -> Option<ResolverError> {
let is_oracle_function =
func.attributes().function.as_ref().map_or(false, |func| func.is_oracle());
if is_oracle_function && !func.def.is_unconstrained {
Some(ResolverError::OracleMarkedAsConstrained { ident: func.name_ident().clone() })
} else {
None
}
}

/// Oracle functions may not be called by constrained functions directly.
///
/// In order for a constrained function to call an oracle it must first call through an unconstrained function.
pub(super) fn oracle_called_from_constrained_function(
interner: &NodeInterner,
called_func: &FuncId,
calling_from_constrained_runtime: bool,
span: Span,
) -> Option<ResolverError> {
if !calling_from_constrained_runtime {
return None;
}

let function_attributes = interner.function_attributes(called_func);
let is_oracle_call =
function_attributes.function.as_ref().map_or(false, |func| func.is_oracle());
if is_oracle_call {
Some(ResolverError::UnconstrainedOracleReturnToConstrained { span })
} else {
None
}
}

/// `pub` is required on return types for entry point functions
pub(super) fn missing_pub(func: &NoirFunction, is_entry_point: bool) -> Option<ResolverError> {
if is_entry_point
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,7 @@ impl<'context> Elaborator<'context> {
self.run_lint(|elaborator| {
lints::unnecessary_pub_return(func, elaborator.pub_allowed(func)).map(Into::into)
});
self.run_lint(|_| lints::oracle_not_marked_unconstrained(func).map(Into::into));
self.run_lint(|elaborator| {
lints::low_level_function_outside_stdlib(func, elaborator.crate_id).map(Into::into)
});
Expand Down
28 changes: 19 additions & 9 deletions noir/noir-repo/compiler/noirc_frontend/src/elaborator/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::{
},
hir_def::{
expr::{
HirBinaryOp, HirCallExpression, HirIdent, HirMemberAccess, HirMethodReference,
HirBinaryOp, HirCallExpression, HirMemberAccess, HirMethodReference,
HirPrefixExpression,
},
function::{FuncMeta, Parameters},
Expand Down Expand Up @@ -1155,6 +1155,19 @@ impl<'context> Elaborator<'context> {
let is_unconstrained_call = self.is_unconstrained_call(call.func);
let crossing_runtime_boundary = is_current_func_constrained && is_unconstrained_call;
if crossing_runtime_boundary {
let called_func_id = self
.interner
.lookup_function_from_expr(&call.func)
.expect("Called function should exist");
self.run_lint(|elaborator| {
lints::oracle_called_from_constrained_function(
elaborator.interner,
&called_func_id,
is_current_func_constrained,
span,
)
.map(Into::into)
});
let errors = lints::unconstrained_function_args(&args);
for error in errors {
self.push_err(error);
Expand All @@ -1173,15 +1186,12 @@ impl<'context> Elaborator<'context> {
}

fn is_unconstrained_call(&self, expr: ExprId) -> bool {
if let HirExpression::Ident(HirIdent { id, .. }, _) = self.interner.expression(&expr) {
if let Some(DefinitionKind::Function(func_id)) =
self.interner.try_definition(id).map(|def| &def.kind)
{
let modifiers = self.interner.function_modifiers(func_id);
return modifiers.is_unconstrained;
}
if let Some(func_id) = self.interner.lookup_function_from_expr(&expr) {
let modifiers = self.interner.function_modifiers(&func_id);
modifiers.is_unconstrained
} else {
false
}
false
}

/// Check if the given method type requires a mutable reference to the object type, and check
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub enum InterpreterError {
CannotInlineMacro { value: Value, location: Location },
UnquoteFoundDuringEvaluation { location: Location },

Unimplemented { item: &'static str, location: Location },
Unimplemented { item: String, location: Location },

// Perhaps this should be unreachable! due to type checking also preventing this error?
// Currently it and the Continue variant are the only interpreter errors without a Location field
Expand Down
Loading
Loading