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 #4494

Merged
merged 32 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
50e001a
feat(avm): storage (https://github.com/AztecProtocol/aztec-packages/p…
AztecBot Mar 6, 2024
fe892a4
feat: Integrated native ACVM (https://github.com/AztecProtocol/aztec-…
AztecBot Mar 6, 2024
09f371f
feat: Integrated native ACVM (https://github.com/AztecProtocol/aztec-…
AztecBot Mar 6, 2024
6d284d4
fix(revert): "feat(avm): storage" (https://github.com/AztecProtocol/a…
AztecBot Mar 7, 2024
dd0bfed
fix(revert): "feat(avm): storage" (https://github.com/AztecProtocol/a…
AztecBot Mar 7, 2024
46737e6
chore: purging calldata hash (https://github.com/AztecProtocol/aztec-…
AztecBot Mar 7, 2024
94b9d5b
chore: purging calldata hash (https://github.com/AztecProtocol/aztec-…
AztecBot Mar 7, 2024
699f43d
fix: storage v2 (https://github.com/AztecProtocol/aztec-packages/pull…
AztecBot Mar 7, 2024
0bba5e8
fix: storage v2 (https://github.com/AztecProtocol/aztec-packages/pull…
AztecBot Mar 7, 2024
e5f34fb
chore: delete bootstrap scripts from `noir/noir-repo` (https://github…
AztecBot Mar 7, 2024
792518e
chore: delete bootstrap scripts from `noir/noir-repo` (https://github…
AztecBot Mar 7, 2024
0d6e7fd
chore(ci): Re-enable certain bb solidity ACIR tests (https://github.c…
AztecBot Mar 8, 2024
aecf7cf
chore(ci): Re-enable certain bb solidity ACIR tests (https://github.c…
AztecBot Mar 8, 2024
a340e64
feat: detect unknown note type ids in compute_note_hash (https://gith…
AztecBot Mar 8, 2024
8657c6b
feat: detect unknown note type ids in compute_note_hash (https://gith…
AztecBot Mar 8, 2024
61840d0
chore: run nargo fmt on each nargo project (https://github.com/AztecP…
AztecBot Mar 9, 2024
7807ce1
chore: run nargo fmt on each nargo project (https://github.com/AztecP…
AztecBot Mar 9, 2024
0c0c242
feat(avm): fix some Brillig problems (https://github.com/AztecProtoco…
AztecBot Mar 11, 2024
5c502ef
feat(avm): fix some Brillig problems (https://github.com/AztecProtoco…
AztecBot Mar 11, 2024
d020684
fix clippy
sirasistant Mar 11, 2024
da264ad
fix: ignore new test that has recursive aggregation
sirasistant Mar 11, 2024
f598182
chore(ci): fail on clippy warnings in noir (https://github.com/AztecP…
AztecBot Mar 11, 2024
82d6f52
chore(ci): fail on clippy warnings in noir (https://github.com/AztecP…
AztecBot Mar 11, 2024
57d02e7
Merge branch 'master' into aztec-packages
TomAFrench Mar 11, 2024
230709d
feat: Sync from noir (https://github.com/AztecProtocol/aztec-packages…
AztecBot Mar 12, 2024
b10086d
feat: Sync from noir (https://github.com/AztecProtocol/aztec-packages…
AztecBot Mar 12, 2024
07d5518
Merge branch 'master' into aztec-packages
sirasistant Mar 13, 2024
c556205
feat: Check initialization arguments in constructors (https://github.…
AztecBot Mar 13, 2024
e3f9c1a
feat: Check initialization arguments in constructors (https://github.…
AztecBot Mar 13, 2024
08cde49
Delete bootstrap.sh
TomAFrench Mar 13, 2024
7464bee
Delete bootstrap_cache.sh
TomAFrench Mar 13, 2024
1e97f6b
Merge branch 'master' into aztec-packages
TomAFrench Mar 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 .aztec-sync-commit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7ff9b71d8d87fc93ae7dbd8ba63f5176b0cd17be
07dd8215dffd2c3c6d22e0f430f5072b4ff7c763
20 changes: 20 additions & 0 deletions Cargo.lock

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

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ members = [
"tooling/nargo_toml",
"tooling/noirc_abi",
"tooling/noirc_abi_wasm",
"tooling/acvm_cli",
# ACVM
"acvm-repo/acir_field",
"acvm-repo/acir",
Expand All @@ -36,7 +37,7 @@ members = [
"acvm-repo/blackbox_solver",
"acvm-repo/bn254_blackbox_solver",
]
default-members = ["tooling/nargo_cli"]
default-members = ["tooling/nargo_cli", "tooling/acvm_cli"]
resolver = "2"

[workspace.package]
Expand Down Expand Up @@ -78,6 +79,7 @@ noir_lsp = { path = "tooling/lsp" }
noir_debugger = { path = "tooling/debugger" }
noirc_abi = { path = "tooling/noirc_abi" }
bb_abstraction_leaks = { path = "tooling/bb_abstraction_leaks" }
acvm_cli = { path = "tooling/acvm_cli" }

# LSP
async-lsp = { version = "0.1.0", default-features = false }
Expand Down
15 changes: 11 additions & 4 deletions aztec_macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@
} else if is_custom_attribute(&secondary_attribute, "aztec(initializer)") {
is_initializer = true;
insert_init_check = false;
} else if is_custom_attribute(&secondary_attribute, "aztec(noinitcheck)") {

Check warning on line 448 in aztec_macros/src/lib.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (noinitcheck)
insert_init_check = false;
} else if is_custom_attribute(&secondary_attribute, "aztec(internal)") {
is_internal = true;
Expand Down Expand Up @@ -727,8 +727,14 @@
/// Transform a function to work with AVM bytecode
fn transform_vm_function(
func: &mut NoirFunction,
_storage_defined: bool,
storage_defined: bool,
) -> Result<(), AztecMacroError> {
// Create access to storage
if storage_defined {
let storage = abstract_storage("public_vm", true);
func.def.body.0.insert(0, storage);
}

// Push Avm context creation to the beginning of the function
let create_context = create_avm_context()?;
func.def.body.0.insert(0, create_context);
Expand Down Expand Up @@ -1754,8 +1760,8 @@
// If compute_note_hash_and_nullifier is already defined by the user, we skip auto-generation in order to provide an
// escape hatch for this mechanism.
// TODO(#4647): improve this diagnosis and error messaging.
if collected_functions.iter().any(|coll_funcs_data| {

Check warning on line 1763 in aztec_macros/src/lib.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (funcs)
check_for_compute_note_hash_and_nullifier_definition(&coll_funcs_data.functions, module_id)

Check warning on line 1764 in aztec_macros/src/lib.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (funcs)
}) {
return Ok(());
}
Expand Down Expand Up @@ -1809,7 +1815,7 @@
unresolved_traits_impls: &[UnresolvedTraitImpl],
trait_name: &str,
) -> Vec<String> {
let mut struct_typenames: Vec<String> = Vec::new();

Check warning on line 1818 in aztec_macros/src/lib.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (typenames)

// These structs can be declared in either external crates or the current one. External crates that contain
// dependencies have already been processed and resolved, but are available here via the NodeInterner. Note that
Expand All @@ -1819,7 +1825,7 @@

if trait_impl.borrow().ident.0.contents == *trait_name {
if let Type::Struct(s, _) = &trait_impl.borrow().typ {
struct_typenames.push(s.borrow().name.0.contents.clone());

Check warning on line 1828 in aztec_macros/src/lib.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (typenames)
} else {
panic!("Found impl for {} on non-Struct", trait_name);
}
Expand All @@ -1827,7 +1833,7 @@
}

// This crate's traits and impls have not yet been resolved, so we look for impls in unresolved_trait_impls.
struct_typenames.extend(

Check warning on line 1836 in aztec_macros/src/lib.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (typenames)
unresolved_traits_impls
.iter()
.filter(|trait_impl| {
Expand All @@ -1848,7 +1854,7 @@
}),
);

struct_typenames

Check warning on line 1857 in aztec_macros/src/lib.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (typenames)
}

fn generate_compute_note_hash_and_nullifier(note_types: &Vec<String>) -> NoirFunction {
Expand All @@ -1869,8 +1875,8 @@
// For now we hardcode it to 20, which is the same as MAX_NOTE_FIELDS_LENGTH.

if note_types.is_empty() {
// TODO(#4520): Even if the contract does not include any notes, other parts of the stack expect for this
// function to exist, so we include a dummy version. We likely should error out here instead.
// Even if the contract does not include any notes, other parts of the stack expect for this function to exist,
// so we include a dummy version.
"
unconstrained fn compute_note_hash_and_nullifier(
contract_address: AztecAddress,
Expand All @@ -1879,6 +1885,7 @@
note_type_id: Field,
serialized_note: [Field; 20]
) -> pub [Field; 4] {
assert(false, \"This contract does not use private notes\");
[0, 0, 0, 0]
}"
.to_string()
Expand All @@ -1892,10 +1899,10 @@
}}"
, note_type)).collect();

// TODO(#4520): error out on the else instead of returning a zero array
let full_if_statement = if_statements.join(" else ")
+ "
else {
assert(false, \"Unknown note type ID\");
[0, 0, 0, 0]
}";

Expand Down
22 changes: 22 additions & 0 deletions bootstrap.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bash
set -eu

cd $(dirname "$0")

CMD=${1:-}

if [ -n "$CMD" ]; then
if [ "$CMD" = "clean" ]; then
git clean -fdx
exit 0
else
echo "Unknown command: $CMD"
exit 1
fi
fi

# Attempt to just pull artefacts from CI and exit on success.
[ -n "${USE_CACHE:-}" ] && ./bootstrap_cache.sh && exit

./scripts/bootstrap_native.sh
./scripts/bootstrap_packages.sh
13 changes: 13 additions & 0 deletions bootstrap_cache.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash
set -eu

cd "$(dirname "$0")"
source ../build-system/scripts/setup_env '' '' mainframe_$USER > /dev/null

echo -e "\033[1mRetrieving noir packages from remote cache...\033[0m"
extract_repo noir-packages /usr/src/noir/packages ./
echo -e "\033[1mRetrieving nargo from remote cache...\033[0m"
extract_repo noir /usr/src/noir/target/release ./target/

remove_old_images noir-packages
remove_old_images noir
Original file line number Diff line number Diff line change
Expand Up @@ -831,16 +831,10 @@ impl<'block> BrilligBlock<'block> {
_ => unreachable!("ICE: array set on non-array"),
};

// Here we want to compare the reference count against 1.
let one = self.brillig_context.make_usize_constant(1_usize.into());
let condition = self.brillig_context.allocate_register();

self.brillig_context.binary_instruction(
reference_count,
one,
condition,
BrilligBinaryOp::Field { op: BinaryFieldOp::Equals },
);

self.brillig_context.memory_op(reference_count, one, condition, BinaryIntOp::Equals);
self.brillig_context.branch_instruction(condition, |ctx, cond| {
if cond {
// Reference count is 1, we can mutate the array directly
Expand Down
39 changes: 15 additions & 24 deletions compiler/noirc_evaluator/src/brillig/brillig_ir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,11 @@ use acvm::{
FieldElement,
};
use debug_show::DebugShow;
use num_bigint::BigUint;

/// The Brillig VM does not apply a limit to the memory address space,
/// As a convention, we take use 64 bits. This means that we assume that
/// memory has 2^64 memory slots.
pub(crate) const BRILLIG_MEMORY_ADDRESSING_BIT_SIZE: u32 = 32;
pub(crate) const BRILLIG_MEMORY_ADDRESSING_BIT_SIZE: u32 = 64;

// Registers reserved in runtime for special purposes.
pub(crate) enum ReservedRegisters {
Expand Down Expand Up @@ -213,13 +212,7 @@ impl BrilligContext {
self.debug_show.array_get(array_ptr, index, result);
// Computes array_ptr + index, ie array[index]
let index_of_element_in_memory = self.allocate_register();
self.binary_instruction(
array_ptr,
index,
index_of_element_in_memory,
BrilligBinaryOp::Field { op: BinaryFieldOp::Add },
);

self.memory_op(array_ptr, index, index_of_element_in_memory, BinaryIntOp::Add);
self.load_instruction(result, index_of_element_in_memory);
// Free up temporary register
self.deallocate_register(index_of_element_in_memory);
Expand All @@ -239,7 +232,10 @@ impl BrilligContext {
array_ptr,
index,
index_of_element_in_memory,
BrilligBinaryOp::Field { op: BinaryFieldOp::Add },
BrilligBinaryOp::Integer {
op: BinaryIntOp::Add,
bit_size: BRILLIG_MEMORY_ADDRESSING_BIT_SIZE,
},
);

self.store_instruction(index_of_element_in_memory, value);
Expand Down Expand Up @@ -562,6 +558,7 @@ impl BrilligContext {
bit_size: u32,
) {
self.debug_show.const_instruction(result, constant);

self.push_opcode(BrilligOpcode::Const { destination: result, value: constant, bit_size });
}

Expand Down Expand Up @@ -725,6 +722,8 @@ impl BrilligContext {
/// Instead truncation instructions are emitted as to when a
/// truncation should be done.
/// For Brillig, all integer operations will overflow as its cheap.
/// We currently use cast to truncate: we cast to the required bit size
/// and back to the original bit size.
pub(crate) fn truncate_instruction(
&mut self,
destination_of_truncated_value: SingleAddrVariable,
Expand All @@ -743,20 +742,12 @@ impl BrilligContext {
value_to_truncate.bit_size
);

let mask = BigUint::from(2_u32).pow(bit_size) - BigUint::from(1_u32);
let mask_constant = self.make_constant(
FieldElement::from_be_bytes_reduce(&mask.to_bytes_be()).into(),
value_to_truncate.bit_size,
);

self.binary_instruction(
value_to_truncate.address,
mask_constant,
destination_of_truncated_value.address,
BrilligBinaryOp::Integer { op: BinaryIntOp::And, bit_size: value_to_truncate.bit_size },
);

self.deallocate_register(mask_constant);
// We cast back and forth to ensure that the value is truncated.
let intermediate_register =
SingleAddrVariable { address: self.allocate_register(), bit_size };
self.cast_instruction(intermediate_register, value_to_truncate);
self.cast_instruction(destination_of_truncated_value, intermediate_register);
self.deallocate_register(intermediate_register.address);
}

/// Emits a stop instruction
Expand Down
2 changes: 1 addition & 1 deletion compiler/wasm/test/fixtures/deps/lib-c/src/lib.nr
Original file line number Diff line number Diff line change
@@ -1 +1 @@
mod module;
mod module;
2 changes: 1 addition & 1 deletion compiler/wasm/test/fixtures/deps/lib-c/src/module.nr
Original file line number Diff line number Diff line change
@@ -1 +1 @@
mod foo;
mod foo;
2 changes: 1 addition & 1 deletion compiler/wasm/test/fixtures/deps/lib-c/src/module/foo.nr
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
pub fn bar(param: Field) -> Field {
dep::std::hash::pedersen_hash([param])
dep::std::hash::pedersen_hash([param])
}
1 change: 0 additions & 1 deletion compiler/wasm/test/fixtures/noir-contract/src/main.nr
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@ contract TestContract {
open fn openFunction() -> pub Field {
42
}

}
2 changes: 1 addition & 1 deletion docs/scripts/codegen_nargo_reference.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ sidebar_position: 0
---
" > $NARGO_REFERENCE

cargo run -F codegen-docs -- info >> $NARGO_REFERENCE
cargo run --bin nargo -F codegen-docs -- info >> $NARGO_REFERENCE
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ fn main(x: Field, y: pub Field) {
let z = x + y;
assert(z != y, f"Expected z != y, but got both equal {z}");
assert_eq(x, y, f"Expected x == y, but x is {x} and y is {y}");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ unconstrained fn conditional(x: Field) -> Field {
assert_eq(z, 25, f"Expected 25 but got {z}");
assert(x == 10, f"Expected x to equal 10, but got {x}");
1
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ unconstrained fn mut_ref_identity(value: &mut Field) -> Field {
fn main(mut x: Field, y: pub Field) {
let returned_x = mut_ref_identity(&mut x);
assert(returned_x == x);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ contract Foo {
struct T { x: [Field] }

impl T {
fn t(self){}
fn t(self) {}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ contract Foo {
}
// Regression for issue #3344
#[contract_library_method]
fn foo(x : u8) -> u8 {
fn foo(x: u8) -> u8 {
x
}
}
Loading
Loading