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 aztec-packages #6210

Merged
merged 9 commits into from
Oct 2, 2024
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 .aztec-sync-commit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
b0d1bab1f02819e7efbe0db73c3c805b5927b66a
670af8a158633d106a3f1df82dbd28ef9a9e4ceb
39 changes: 16 additions & 23 deletions compiler/noirc_evaluator/src/ssa/function_builder/data_bus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use serde::{Deserialize, Serialize};

use super::FunctionBuilder;

#[derive(Clone, Debug, Eq, PartialEq)]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub(crate) enum DatabusVisibility {
None,
CallData(u32),
Expand Down Expand Up @@ -214,34 +214,27 @@ impl FunctionBuilder {
fn deflatten_databus_visibilities(
&self,
ssa_params: &[ValueId],
flattened_params_databus_visibility: Vec<DatabusVisibility>,
mut flattened_params_databus_visibility: Vec<DatabusVisibility>,
) -> Vec<DatabusVisibility> {
// To do so, create a vec the size of the flattened arguments where the items are the ssa param index they correspond to
let ssa_param_indices: Vec<_> = ssa_params
let ssa_param_sizes: Vec<_> = ssa_params
.iter()
.enumerate()
.flat_map(|(ssa_param_index, ssa_param)| {
let flattened_size =
self.current_function.dfg[*ssa_param].get_type().flattened_size();
std::iter::repeat(ssa_param_index).take(flattened_size)
})
.map(|ssa_param| self.current_function.dfg[*ssa_param].get_type().flattened_size())
.collect();

let mut is_ssa_params_databus = Vec::with_capacity(ssa_params.len());
assert!(flattened_params_databus_visibility.len() == ssa_param_indices.len());
for (databus_visibility, ssa_index) in
flattened_params_databus_visibility.into_iter().zip(ssa_param_indices)
{
if let Some(previous_databus_visibility) = is_ssa_params_databus.get(ssa_index) {
assert!(
*previous_databus_visibility == databus_visibility,
"inconsistent databus visibility for ssa param"
);
} else {
assert!(ssa_index == is_ssa_params_databus.len());
is_ssa_params_databus.push(databus_visibility);
}
for size in ssa_param_sizes {
let visibilities: Vec<DatabusVisibility> =
flattened_params_databus_visibility.drain(0..size).collect();
let visibility = visibilities.get(0).copied().unwrap_or(DatabusVisibility::None);
assert!(
visibilities.iter().all(|v| *v == visibility),
"inconsistent databus visibility for ssa param"
);
is_ssa_params_databus.push(visibility);
}

assert_eq!(is_ssa_params_databus.len(), ssa_params.len());

is_ssa_params_databus
}
}
52 changes: 0 additions & 52 deletions compiler/noirc_frontend/src/tests/unused_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,58 +188,6 @@ fn errors_on_unused_type_alias() {
assert_eq!(item.item_type(), "type alias");
}

#[test]
fn errors_if_type_alias_aliases_more_private_type() {
let src = r#"
struct Foo {}
pub type Bar = Foo;
pub fn no_unused_warnings(_b: Bar) {
let _ = Foo {};
}
fn main() {}
"#;

let errors = get_program_errors(src);
assert_eq!(errors.len(), 1);

let CompilationError::ResolverError(ResolverError::TypeIsMorePrivateThenItem {
typ, item, ..
}) = &errors[0].0
else {
panic!("Expected an unused item error");
};

assert_eq!(typ, "Foo");
assert_eq!(item, "Bar");
}

#[test]
fn errors_if_type_alias_aliases_more_private_type_in_generic() {
let src = r#"
pub struct Generic<T> { value: T }
struct Foo {}
pub type Bar = Generic<Foo>;
pub fn no_unused_warnings(_b: Bar) {
let _ = Foo {};
let _ = Generic { value: 1 };
}
fn main() {}
"#;

let errors = get_program_errors(src);
assert_eq!(errors.len(), 1);

let CompilationError::ResolverError(ResolverError::TypeIsMorePrivateThenItem {
typ, item, ..
}) = &errors[0].0
else {
panic!("Expected an unused item error");
};

assert_eq!(typ, "Foo");
assert_eq!(item, "Bar");
}

#[test]
fn warns_on_unused_global() {
let src = r#"
Expand Down
6 changes: 0 additions & 6 deletions compiler/noirc_frontend/src/tests/visibility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,14 @@ fn errors_once_on_unused_import_that_is_not_accessible() {
))
));
}

#[test]
fn errors_if_type_alias_aliases_more_private_type() {
let src = r#"
struct Foo {}
pub type Bar = Foo;

pub fn no_unused_warnings(_b: Bar) {
let _ = Foo {};
}

fn main() {}
"#;

Expand All @@ -60,15 +57,12 @@ fn errors_if_type_alias_aliases_more_private_type() {
fn errors_if_type_alias_aliases_more_private_type_in_generic() {
let src = r#"
pub struct Generic<T> { value: T }

struct Foo {}
pub type Bar = Generic<Foo>;

pub fn no_unused_warnings(_b: Bar) {
let _ = Foo {};
let _ = Generic { value: 1 };
}

fn main() {}
"#;

Expand Down
4 changes: 2 additions & 2 deletions noir_stdlib/src/hash/mod.nr
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub fn pedersen_commitment<let N: u32>(input: [Field; N]) -> EmbeddedCurvePoint
}

pub fn pedersen_hash_with_separator<let N: u32>(input: [Field; N], separator: u32) -> Field {
__pedersen_hash_with_separator(input, separator)
pedersen_hash_with_separator_noir(input, separator)
}

pub fn pedersen_commitment_with_separator<let N: u32>(input: [Field; N], separator: u32) -> EmbeddedCurvePoint {
Expand Down Expand Up @@ -78,7 +78,7 @@ fn pedersen_hash_with_separator_noir<let N: u32>(input: [Field; N], separator: u
pub fn pedersen_hash<let N: u32>(input: [Field; N]) -> Field
// docs:end:pedersen_hash
{
__pedersen_hash_with_separator(input, 0)
pedersen_hash_with_separator_noir(input, 0)
}

#[foreign(pedersen_hash)]
Expand Down
27 changes: 9 additions & 18 deletions test_programs/execution_success/aes128_encrypt/src/main.nr
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,20 @@ unconstrained fn decode_hex<let N: u32, let M: u32>(s: str<N>) -> [u8; M] {
}

unconstrained fn cipher(plaintext: [u8; 12], iv: [u8; 16], key: [u8; 16]) -> [u8; 16] {
let slice_res = std::aes128::aes128_encrypt(plaintext, iv, key);
let mut result = [0; 16];
for i in 0..16 {
result[i] = slice_res[i];
}
result
let result = std::aes128::aes128_encrypt(plaintext, iv, key);
result.as_array()
}

fn main(inputs: str<12>, iv: str<16>, key: str<16>, output: str<32>) {
let result = std::aes128::aes128_encrypt(inputs.as_bytes(), iv.as_bytes(), key.as_bytes());
let result: [u8; 16] = std::aes128::aes128_encrypt(inputs.as_bytes(), iv.as_bytes(), key.as_bytes()).as_array();

let output_bytes: [u8; 16] = unsafe {
let output_bytes: [u8; 16] = decode_hex(output);
for i in 0..16 {
assert(result[i] == output_bytes[i]);
}
output_bytes
decode_hex(output)
};
assert(result == output_bytes);

unsafe {
let unconstrained_result = cipher(inputs.as_bytes(), iv.as_bytes(), key.as_bytes());
for i in 0..16 {
assert(unconstrained_result[i] == output_bytes[i]);
}
}
let unconstrained_result = unsafe {
cipher(inputs.as_bytes(), iv.as_bytes(), key.as_bytes())
};
assert(unconstrained_result == output_bytes);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "databus_in_fn_with_empty_arr"
type = "bin"
authors = [""]

[dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
_empty = []
value_1 = "1"
value_2 = "2"
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main(_empty: [u32; 0], value_1: u32, value_2: call_data(0) u32) {
assert_eq(value_1 + 1, value_2);
}
1 change: 1 addition & 0 deletions tooling/nargo_fmt/src/visitor/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ impl super::FmtVisitor<'_> {
self.push_rewrite(use_tree, span);
self.last_position = span.end();
}

ItemKind::Struct(_)
| ItemKind::Trait(_)
| ItemKind::TypeAlias(_)
Expand Down
2 changes: 1 addition & 1 deletion tooling/noir_js_backend_barretenberg/src/backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export class UltraHonkBackend implements Backend, VerifierBackend {

async generateProof(compressedWitness: Uint8Array): Promise<ProofData> {
const proofWithPublicInputs = await this.backend.generateProof(gunzip(compressedWitness));

const proofAsStrings = deflattenFields(proofWithPublicInputs.slice(4));

const numPublicInputs = Number(proofAsStrings[1]);
Expand All @@ -121,7 +122,6 @@ export class UltraHonkBackend implements Backend, VerifierBackend {

async verifyProof(proofData: ProofData): Promise<boolean> {
const proof = reconstructProofWithPublicInputsHonk(proofData);

return this.backend.verifyProof(proof);
}

Expand Down
Loading