Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 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 noir-projects/aztec-nr/aztec/src/oracle/capsules.nr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use protocol_types::{address::AztecAddress, traits::{Deserialize, Serialize}};
use protocol_types::{address::AztecAddress, traits::{Deserialize, Serialize, ToField}};

/// Stores arbitrary information in a per-contract non-volatile database, which can later be retrieved with `load`. If
/// data was already stored at this slot, it is overwritten.
Expand Down
5 changes: 4 additions & 1 deletion noir-projects/aztec-nr/aztec/src/utils/with_hash.nr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ use crate::{
oracle,
};
use dep::protocol_types::{
address::AztecAddress, block_header::BlockHeader, hash::poseidon2_hash, traits::Packable,
address::AztecAddress,
block_header::BlockHeader,
hash::poseidon2_hash,
traits::{Packable, ToField},
};

/// A struct that allows for efficient reading of value `T` from public storage in private.
Expand Down
2 changes: 2 additions & 0 deletions noir-projects/noir-contracts/Nargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ members = [
"contracts/token_contract",
"contracts/token_blacklist_contract",
"contracts/token_bridge_contract",
# This breaks ci3's way of compiling contracts
# "contracts/token_portal_content_hash_lib",
"contracts/uniswap_contract",
"contracts/updatable_contract",
"contracts/updated_contract",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ pub contract AvmTest {
};
use dep::aztec::state_vars::PublicMutable;
use dep::compressed_string::CompressedString;
use aztec::protocol_types::traits::Serialize;
use std::embedded_curve_ops::{EmbeddedCurvePoint, multi_scalar_mul};

use std::ops::Add;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub contract NFT {
functions::{initializer, internal, private, public, view},
storage::storage,
},
note::constants::MAX_NOTES_PER_PAGE,
note::{constants::MAX_NOTES_PER_PAGE, note_interface::{NoteProperties, PartialNote}},
oracle::random::random,
prelude::{
AztecAddress, Map, NoteGetterOptions, NoteViewerOptions, PrivateContext, PrivateSet,
Expand All @@ -30,6 +30,7 @@ pub contract NFT {
utils::comparison::Comparator,
};
use dep::compressed_string::FieldCompressedString;
use aztec::protocol_types::traits::ToField;
use std::meta::derive;

// docs:end:imports
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::NFT;
use crate::test::utils;
use aztec::protocol_types::traits::ToField;

#[test]
unconstrained fn access_control() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pub contract Parent {
use dep::aztec::{context::gas::GasOpts, macros::functions::{private, public}};
use dep::aztec::prelude::{AztecAddress, FunctionSelector};
use dep::aztec::protocol_types::constants::MAX_FR_ARGS_TO_ALL_ENQUEUED_CALLS;
use aztec::protocol_types::traits::ToField;
// Private function to call another private function in the target_contract using the provided selector
#[private]
fn entry_point(target_contract: AztecAddress, target_selector: FunctionSelector) -> Field {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub contract PendingNoteHashes {
MAX_NOTE_HASH_READ_REQUESTS_PER_CALL, MAX_NOTE_HASHES_PER_CALL,
};
use dep::value_note::{filter::filter_notes_min_sum, value_note::ValueNote};
use aztec::protocol_types::traits::ToField;

#[storage]
struct Storage<Context> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use dep::aztec::{
protocol_types::{address::PartialAddress, public_keys::{PUBLIC_KEYS_LENGTH, PublicKeys}},
utils::array,
};
use aztec::protocol_types::traits::Deserialize;

pub struct AuthWitness {
keys: PublicKeys,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use dep::aztec::{
use dep::aztec::prelude::{
NoteGetterOptions, NoteHash, NoteType, NoteViewerOptions, PrivateSet, RetrievedNote,
};
use std::ops::Add;

pub struct BalanceSet<Note, Context> {
set: PrivateSet<Note, Context>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub contract StaticChild {
utils::comparison::Comparator,
};
use dep::value_note::value_note::ValueNote;
use aztec::note::note_interface::NoteProperties;

#[storage]
struct Storage<Context> {
Expand Down
24 changes: 15 additions & 9 deletions noir-projects/noir-contracts/contracts/test_contract/src/main.nr
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub contract Test {
deploy::deploy_contract as aztec_deploy_contract,
discovery::private_logs::do_process_log,
event::event_interface::EventInterface,
hash::{ArgsHasher, compute_secret_hash, pedersen_hash},
hash::{ArgsHasher, pedersen_hash},
history::note_inclusion::ProveNoteInclusion,
macros::{
events::event,
Expand All @@ -48,7 +48,6 @@ pub contract Test {
note_interface::NoteType,
retrieved_note::RetrievedNote,
},
state_vars::storage::Storage as _,
test::mocks::mock_struct::MockStruct,
};
use dep::token_portal_content_hash_lib::{
Expand Down Expand Up @@ -140,7 +139,8 @@ pub contract Test {
storage_slot: Field,
) {
assert(
storage_slot != storage.example_constant.get_storage_slot(),
storage_slot
!= aztec::state_vars::storage::Storage::get_storage_slot(storage.example_constant),
"this storage slot is reserved for example_constant",
);

Expand All @@ -156,7 +156,8 @@ pub contract Test {
#[private]
fn call_get_notes(storage_slot: Field, active_or_nullified: bool) -> Field {
assert(
storage_slot != storage.example_constant.get_storage_slot(),
storage_slot
!= aztec::state_vars::storage::Storage::get_storage_slot(storage.example_constant),
"this storage slot is reserved for example_constant",
);

Expand All @@ -176,7 +177,8 @@ pub contract Test {
#[private]
fn call_get_notes_many(storage_slot: Field, active_or_nullified: bool) -> [Field; 2] {
assert(
storage_slot != storage.example_constant.get_storage_slot(),
storage_slot
!= aztec::state_vars::storage::Storage::get_storage_slot(storage.example_constant),
"this storage slot is reserved for example_constant",
);

Expand All @@ -193,7 +195,8 @@ pub contract Test {

unconstrained fn call_view_notes(storage_slot: Field, active_or_nullified: bool) -> pub Field {
assert(
storage_slot != storage.example_constant.get_storage_slot(),
storage_slot
!= aztec::state_vars::storage::Storage::get_storage_slot(storage.example_constant),
"this storage slot is reserved for example_constant",
);

Expand All @@ -212,7 +215,8 @@ pub contract Test {
active_or_nullified: bool,
) -> pub [Field; 2] {
assert(
storage_slot != storage.example_constant.get_storage_slot(),
storage_slot
!= aztec::state_vars::storage::Storage::get_storage_slot(storage.example_constant),
"this storage slot is reserved for example_constant",
);

Expand All @@ -229,7 +233,8 @@ pub contract Test {
#[private]
fn call_destroy_note(storage_slot: Field) {
assert(
storage_slot != storage.example_constant.get_storage_slot(),
storage_slot
!= aztec::state_vars::storage::Storage::get_storage_slot(storage.example_constant),
"this storage slot is reserved for example_constant",
);

Expand Down Expand Up @@ -371,7 +376,8 @@ pub contract Test {

#[private]
fn emit_encrypted_logs_nested(value: Field, owner: AztecAddress, sender: AztecAddress) {
let mut storage_slot = storage.example_constant.get_storage_slot() + 1;
let mut storage_slot =
aztec::state_vars::storage::Storage::get_storage_slot(storage.example_constant) + 1;
Test::at(context.this_address()).call_create_note(value, owner, sender, storage_slot).call(
&mut context,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ pub contract TestLog {
use dep::aztec::protocol_types::{address::AztecAddress, traits::Serialize};
use dep::aztec::unencrypted_logs::unencrypted_event_emission::encode_event;
use dep::value_note::value_note::ValueNote;
use aztec::event::event_interface::EventInterface;
use aztec::protocol_types::traits::FromField;
use std::meta::derive;

#[derive(Serialize)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ pub contract TokenBlacklist {
utils::comparison::Comparator,
};

use aztec::note::note_interface::NoteHash;
use aztec::note::note_interface::NoteProperties;
use aztec::note::note_interface::NoteType;
use aztec::protocol_types::traits::ToField;
use std::ops::{Add, Sub};

use dep::authwit::auth::{
assert_current_call_valid_authwit, assert_current_call_valid_authwit_public,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ use dep::aztec::prelude::{
RetrievedNote,
};

use std::ops::Add;

pub struct BalancesMap<Note, Context> {
map: Map<AztecAddress, PrivateSet<Note, Context>, Context>,
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use dep::aztec::protocol_types::traits::{Deserialize, Packable, Serialize};
use aztec::protocol_types::traits::ToField;

global ADMIN_FLAG: u64 = 1;
global MINTER_FLAG: u64 = 2;
Expand Down Expand Up @@ -72,6 +73,7 @@ impl Deserialize<3> for UserFlags {

mod test {
use crate::types::roles::UserFlags;
use aztec::protocol_types::traits::Packable;

fn assert_packable(is_minter: bool, is_admin: bool, is_blacklisted: bool) {
let flags = UserFlags { is_minter, is_admin, is_blacklisted };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ pub contract Token {
protocol_types::{point::Point, traits::Serialize},
};

use aztec::protocol_types::traits::ToField;

use dep::uint_note::uint_note::UintNote;

// docs:start:import_authwit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ use dep::aztec::protocol_types::{hash::sha256_to_field, traits::ToField};
// Refer TokenPortal.sol for reference on L1.
pub fn get_mint_to_public_content_hash(owner: AztecAddress, amount: u128) -> Field {
let mut hash_bytes = [0; 68];
let recipient_bytes:[u8; 32] = owner.to_field().to_be_bytes();
let amount_bytes:[u8; 32] = (amount as Field).to_be_bytes();
let recipient_bytes: [u8; 32] = owner.to_field().to_be_bytes();
let amount_bytes: [u8; 32] = (amount as Field).to_be_bytes();

// The purpose of including the following selector is to make the message unique to that specific call. Note that
// it has nothing to do with calling the function.
let selector = comptime { keccak256::keccak256("mint_to_public(bytes32,uint256)".as_bytes(), 31) };
let selector =
comptime { keccak256::keccak256("mint_to_public(bytes32,uint256)".as_bytes(), 31) };

for i in 0..4 {
hash_bytes[i] = selector[i];
Expand All @@ -32,7 +33,7 @@ pub fn get_mint_to_public_content_hash(owner: AztecAddress, amount: u128) -> Fie
// Refer TokenPortal.sol for reference on L1.
pub fn get_mint_to_private_content_hash(amount: u128) -> Field {
let mut hash_bytes = [0; 36];
let amount_bytes:[u8; 32] = (amount as Field).to_be_bytes();
let amount_bytes: [u8; 32] = (amount as Field).to_be_bytes();

// The purpose of including the following selector is to make the message unique to that specific call. Note that
// it has nothing to do with calling the function.
Expand All @@ -53,7 +54,11 @@ pub fn get_mint_to_private_content_hash(amount: u128) -> Field {

// docs:start:get_withdraw_content_hash
// Computes a content hash of a withdraw message.
pub fn get_withdraw_content_hash(recipient: EthAddress, amount: u128, caller_on_l1: EthAddress) -> Field {
pub fn get_withdraw_content_hash(
recipient: EthAddress,
amount: u128,
caller_on_l1: EthAddress,
) -> Field {
// Compute the content hash
// Compute sha256(selector || amount || recipient)
// then convert to a single field element
Expand All @@ -65,7 +70,8 @@ pub fn get_withdraw_content_hash(recipient: EthAddress, amount: u128, caller_on_

// The purpose of including the following selector is to make the message unique to that specific call. Note that
// it has nothing to do with calling the function.
let selector = comptime { keccak256::keccak256("withdraw(address,uint256,address)".as_bytes(), 33) };
let selector =
comptime { keccak256::keccak256("withdraw(address,uint256,address)".as_bytes(), 33) };

for i in 0..4 {
hash_bytes[i] = selector[i];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ pub contract Uniswap {
use dep::token::Token;
use dep::token_bridge::TokenBridge;

use dep::aztec::protocol_types::traits::ToField;

#[storage]
struct Storage<Context> {
portal_address: PublicImmutable<EthAddress, Context>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// docs:start:uniswap_public_content_hash
use dep::aztec::prelude::{AztecAddress, EthAddress};
use dep::aztec::protocol_types::hash::sha256_to_field;
use dep::aztec::protocol_types::{hash::sha256_to_field, traits::ToField};

// This method computes the L2 to L1 message content hash for the public
// refer `l1-contracts/test/portals/UniswapPortal.sol` on how L2 to L1 message is expected
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ contract Updatable {
use aztec::prelude::{PrivateMutable, PublicMutable};

use aztec::protocol_types::{
constants::DEPLOYER_CONTRACT_ADDRESS,
contract_class_id::ContractClassId,
traits::{Hash, Serialize},
constants::DEPLOYER_CONTRACT_ADDRESS, contract_class_id::ContractClassId,
};
use contract_instance_deployer::ContractInstanceDeployer;
use value_note::value_note::ValueNote;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ contract Updated {
use aztec::macros::{functions::{private, public}, storage::storage};
use aztec::prelude::{PrivateMutable, PublicMutable};

use aztec::protocol_types::{constants::DEPLOYER_CONTRACT_ADDRESS, traits::Hash};
use aztec::protocol_types::constants::DEPLOYER_CONTRACT_ADDRESS;
use contract_instance_deployer::ContractInstanceDeployer;
use value_note::value_note::ValueNote;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,12 @@ pub comptime fn generate_serialize_to_fields(
let packed_struct_name = f"{name_at_one_token}_aux_var".quoted_contents();

// We add the individual fields to the fields array
let packed_struct = quote { let $packed_struct_name = $name.pack() };
let pack_method = get_trait_impl_method(
typ,
quote { crate::traits::Packable<$packed_len> },
quote { pack },
);
let packed_struct = quote { let $packed_struct_name = $pack_method($name) };
for i in 0..packed_len {
fields = fields.push_back(quote { $packed_struct_name[$i] });
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{
},
hash::poseidon2_hash_with_separator,
point::POINT_LENGTH,
traits::{Deserialize, Hash, Serialize},
traits::{Deserialize, Hash, Serialize, ToField},
};

use dep::std::embedded_curve_ops::EmbeddedCurvePoint as Point;
Expand Down