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!: autogenerate compute_note_hash_and_nullifier #4610

Merged
merged 19 commits into from
Feb 19, 2024
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
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.

13 changes: 0 additions & 13 deletions boxes/blank/src/contracts/src/main.nr
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,4 @@ contract Blank {

[pub_key.x, pub_key.y]
}

// A function which needs to be implemented by every contract working with storage. Replace it's content with your
// own logic once you start working with private storage.
// TODO: Remove this placeholder once https://github.com/AztecProtocol/aztec-packages/issues/2918 is implemented.
unconstrained fn compute_note_hash_and_nullifier(
contract_address: AztecAddress,
nonce: Field,
storage_slot: Field,
note_type_id: Field,
serialized_note: [Field; 0]
) -> pub [Field; 4] {
[0, 0, 0, 0]
}
}
27 changes: 1 addition & 26 deletions boxes/token/src/contracts/src/main.nr
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ contract Token {

use crate::types::{
transparent_note::TransparentNote,
token_note::{TokenNote, TOKEN_NOTE_LEN},
token_note::TokenNote,
balances_map::BalancesMap
};
// docs:end::imports
Expand Down Expand Up @@ -379,30 +379,5 @@ contract Token {
storage.public_balances.at(owner).read().value
}
// docs:end:balance_of_public

// docs:start:compute_note_hash_and_nullifier
nventuro marked this conversation as resolved.
Show resolved Hide resolved
// Computes note hash and nullifier.
// Note 1: Needs to be defined by every contract producing logs.
// Note 2: Having it in all the contracts gives us the ability to compute the note hash and nullifier differently for different kind of notes.
unconstrained fn compute_note_hash_and_nullifier(
contract_address: AztecAddress,
nonce: Field,
storage_slot: Field,
note_type_id: Field,
serialized_note: [Field; TOKEN_NOTE_LEN]
) -> pub [Field; 4] {
let note_header = NoteHeader::new(contract_address, nonce, storage_slot);

if (note_type_id == TransparentNote::get_note_type_id()) {
note_utils::compute_note_hash_and_nullifier(
TransparentNote::deserialize_content,
note_header,
serialized_note
)
} else {
note_utils::compute_note_hash_and_nullifier(TokenNote::deserialize_content, note_header, serialized_note)
}
}
// docs:end:compute_note_hash_and_nullifier
}
// docs:end:token_all
2 changes: 1 addition & 1 deletion boxes/token/src/contracts/src/types/token_note.nr
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ impl NoteInterface<TOKEN_NOTE_LEN> for TokenNote {
fn get_note_type_id() -> Field {
// TODO(#4519): autogenerate
// python -c "print(int(''.join(str(ord(c)) for c in 'TokenNote')))"
8411110710111078111116101
F
nventuro marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down
2 changes: 1 addition & 1 deletion noir-projects/aztec-nr/value-note/src/balance_utils.nr
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use dep::aztec::note::{note_getter::view_notes, note_viewer_options::NoteViewerOptions};
use dep::aztec::state_vars::set::Set;
use crate::value_note::{VALUE_NOTE_LEN, ValueNote};
use crate::value_note::ValueNote;

unconstrained pub fn get_balance(set: Set<ValueNote>) -> Field {
get_balance_with_offset(set, 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,20 +113,8 @@ contract AvmTest {
fn getTimestamp() -> pub Field {
context.timestamp()
}

// #[aztec(public-vm)]
// fn getContractCallDepth() -> pub Field {
// context.contract_call_depth()
// }
nventuro marked this conversation as resolved.
Show resolved Hide resolved

// Function required for all contracts
unconstrained fn compute_note_hash_and_nullifier(
_contract_address: AztecAddress,
_nonce: Field,
_storage_slot: Field,
_note_type_id: Field,
_serialized_note: [Field; 1]
) -> pub [Field; 4] {
[0, 0, 0, 0]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// arise from code changes.

contract Benchmarking {
use dep::value_note::{utils::{increment, decrement}, value_note::{VALUE_NOTE_LEN, ValueNote}};
use dep::value_note::{utils::{increment, decrement}, value_note::ValueNote};

use dep::aztec::{
protocol_types::{abis::function_selector::FunctionSelector, address::AztecAddress},
Expand Down Expand Up @@ -60,15 +60,4 @@ contract Benchmarking {
fn broadcast(owner: AztecAddress) {
emit_unencrypted_log(&mut context, storage.balances.at(owner).read());
}

unconstrained fn compute_note_hash_and_nullifier(
contract_address: AztecAddress,
nonce: Field,
storage_slot: Field,
note_type_id: Field,
serialized_note: [Field; VALUE_NOTE_LEN]
) -> pub [Field; 4] {
let note_header = NoteHeader::new(contract_address, nonce, storage_slot);
note_utils::compute_note_hash_and_nullifier(ValueNote::deserialize_content, note_header, serialized_note)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use dep::std::{
option::Option,
};
use dep::value_note::{
value_note::{ValueNote, VALUE_NOTE_LEN},
value_note::ValueNote,
};

struct Card {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,18 +148,4 @@ contract CardGame {
unconstrained fn view_game(game: u32) -> pub Game {
storage.games.at(game as Field).read()
}

// Computes note hash and nullifier.
nventuro marked this conversation as resolved.
Show resolved Hide resolved
// Note 1: Needs to be defined by every contract producing logs.
// Note 2: Having it in all the contracts gives us the ability to compute the note hash and nullifier differently for different kind of notes.
unconstrained fn compute_note_hash_and_nullifier(
contract_address: AztecAddress,
nonce: Field,
storage_slot: Field,
note_type_id: Field,
serialized_note: [Field; VALUE_NOTE_LEN]
) -> pub [Field; 4] {
let note_header = NoteHeader::new(contract_address, nonce, storage_slot);
note_utils::compute_note_hash_and_nullifier(ValueNote::deserialize_content, note_header, serialized_note)
}
}
11 changes: 0 additions & 11 deletions noir-projects/noir-contracts/contracts/child_contract/src/main.nr
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,4 @@ contract Child {
let pubSetValueSelector = FunctionSelector::from_signature("pubSetValue(Field)");
let _ret = context.call_public_function(context.this_address(), pubSetValueSelector, [10]);
}

// TODO: remove this placeholder once https://github.com/AztecProtocol/aztec-packages/issues/2918 is implemented
unconstrained fn compute_note_hash_and_nullifier(
contract_address: AztecAddress,
nonce: Field,
storage_slot: Field,
note_type_id: Field,
serialized_note: [Field; 0]
) -> pub [Field; 4] {
[0, 0, 0, 0]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,4 @@ contract Counter {
balance_utils::get_balance(counters.at(owner).set)
}
// docs:end:get_counter

// docs:start:nullifier
nventuro marked this conversation as resolved.
Show resolved Hide resolved
unconstrained fn compute_note_hash_and_nullifier(
contract_address: AztecAddress,
nonce: Field,
storage_slot: Field,
note_type_id: Field,
serialized_note: [Field; VALUE_NOTE_LEN]
) -> pub [Field; 4] {
let note_header = NoteHeader::new(contract_address, nonce, storage_slot);
note_utils::compute_note_hash_and_nullifier(ValueNote::deserialize_content, note_header, serialized_note)
}
// docs:end:nullifier
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ contract DocsExample {
// how to import methods from other files/folders within your workspace
use crate::options::create_account_card_getter_options;
use crate::types::{
card_note::{CardNote, CARD_NOTE_LEN},
card_note::CardNote,
leader::Leader,
};

Expand Down Expand Up @@ -232,18 +232,6 @@ contract DocsExample {
storage.imm_singleton.is_initialized()
}

// TODO: remove this placeholder once https://github.com/AztecProtocol/aztec-packages/issues/2918 is implemented
unconstrained fn compute_note_hash_and_nullifier(
contract_address: AztecAddress,
nonce: Field,
storage_slot: Field,
note_type_id: Field,
serialized_note: [Field; CARD_NOTE_LEN]
) -> pub [Field; 4] {
let note_header = NoteHeader::new(contract_address, nonce, storage_slot);
note_utils::compute_note_hash_and_nullifier(CardNote::deserialize_content, note_header, serialized_note)
}

/// Macro equivalence section
use dep::aztec::hasher::Hasher;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ contract EasyPrivateToken {
};
use dep::value_note::{
balance_utils,
value_note::{
ValueNote,
VALUE_NOTE_LEN,
},
value_note::ValueNote,
};
use dep::easy_private_state::easy_private_state::EasyPrivateUint;

Expand Down Expand Up @@ -57,19 +54,5 @@ contract EasyPrivateToken {
// Return the sum of all notes in the set.
balance_utils::get_balance(balances.at(owner).set)
}

// Computes note hash and nullifier.
// Note 1: Needs to be defined by every contract producing logs.
// Note 2: Having it in all the contracts gives us the ability to compute the note hash and nullifier differently for different kind of notes.
unconstrained fn compute_note_hash_and_nullifier(
contract_address: AztecAddress,
nonce: Field,
storage_slot: Field,
note_type_id: Field,
serialized_note: [Field; VALUE_NOTE_LEN]
) -> pub [Field; 4] {
let note_header = NoteHeader::new(contract_address, nonce, storage_slot);
note_utils::compute_note_hash_and_nullifier(ValueNote::deserialize_content, note_header, serialized_note)
}
}
// docs:end:easy_private_token_contract
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,4 @@ contract EasyPrivateVoting {
storage.tally.at(candidate).read()
}
// docs:end:get_vote
// docs:start:compute_note_hash_and_nullifier
nventuro marked this conversation as resolved.
Show resolved Hide resolved
unconstrained fn compute_note_hash_and_nullifier(
contract_address: AztecAddress,
nonce: Field,
storage_slot: Field,
note_type_id: Field,
serialized_note: [Field; 0]
) -> pub [Field; 4] {
[0, 0, 0, 0]
}
// docs:end:compute_note_hash_and_nullifier
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ contract EcdsaAccount {
auth_witness::get_auth_witness
};

use crate::ecdsa_public_key_note::{EcdsaPublicKeyNote, ECDSA_PUBLIC_KEY_NOTE_LEN};
use crate::ecdsa_public_key_note::EcdsaPublicKeyNote;

struct Storage {
public_key: ImmutableSingleton<EcdsaPublicKeyNote>,
Expand Down Expand Up @@ -78,23 +78,4 @@ contract EcdsaAccount {

true
}

// Computes note hash and nullifier.
// Note 1: Needs to be defined by every contract producing logs.
// Note 2: Having it in all the contracts gives us the ability to compute the note hash and nullifier differently for different kind of notes.
unconstrained fn compute_note_hash_and_nullifier(
contract_address: AztecAddress,
nonce: Field,
storage_slot: Field,
note_type_id: Field,
serialized_note: [Field; ECDSA_PUBLIC_KEY_NOTE_LEN]
) -> pub [Field; 4] {
assert(storage_slot == storage.public_key.get_storage_slot());
let note_header = NoteHeader::new(contract_address, nonce, storage_slot);
note_utils::compute_note_hash_and_nullifier(
EcdsaPublicKeyNote::deserialize_content,
note_header,
serialized_note
)
}
}
12 changes: 0 additions & 12 deletions noir-projects/noir-contracts/contracts/escrow_contract/src/main.nr
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,4 @@ contract Escrow {
[this.to_field(), recipient.to_field(), amount, 0]
);
}

unconstrained fn compute_note_hash_and_nullifier(
contract_address: AztecAddress,
nonce: Field,
storage_slot: Field,
note_type_id: Field,
serialized_note: [Field; ADDRESS_NOTE_LEN]
) -> pub [Field; 4] {
let note_header = NoteHeader::new(contract_address, nonce, storage_slot);
assert(storage_slot == storage.owners.get_storage_slot());
note_utils::compute_note_hash_and_nullifier(AddressNote::deserialize_content, note_header, serialized_note)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ contract InclusionProofs {
};
// docs:end:imports
// docs:start:value_note_imports
use dep::value_note::value_note::{ValueNote, VALUE_NOTE_LEN};
use dep::value_note::value_note::ValueNote;
// docs:end:value_note_imports
struct Storage {
private_values: Map<AztecAddress, Set<ValueNote>>,
Expand Down Expand Up @@ -250,18 +250,4 @@ contract InclusionProofs {
);
// Here typically the factory would add the contract address to its internal map of deployed contracts.
}

// Computes note hash and nullifier.
// Note 1: Needs to be defined by every contract producing logs.
// Note 2: Having it in all the contracts gives us the ability to compute the note hash and nullifier differently for different kind of notes.
unconstrained fn compute_note_hash_and_nullifier(
contract_address: AztecAddress,
nonce: Field,
storage_slot: Field,
note_type_id: Field,
serialized_note: [Field; VALUE_NOTE_LEN]
) -> pub [Field; 4] {
let note_header = NoteHeader::new(contract_address, nonce, storage_slot);
note_utils::compute_note_hash_and_nullifier(ValueNote::deserialize_content, note_header, serialized_note)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -306,15 +306,4 @@ contract Lending {
unconstrained fn get_assets() -> pub [AztecAddress; 2] {
[storage.collateral_asset.read(), storage.stable_coin.read()]
}

// TODO: remove this placeholder once https://github.com/AztecProtocol/aztec-packages/issues/2918 is implemented
unconstrained fn compute_note_hash_and_nullifier(
contract_address: AztecAddress,
nonce: Field,
storage_slot: Field,
note_type_id: Field,
serialized_note: [Field; 0]
) -> pub [Field; 4] {
[0, 0, 0, 0]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,6 @@ contract PendingCommitments {
[owner.to_field()]
);
}

// Confirm cannot get/read a pending commitment in a nested call
// that is created/inserted later in execution but in the parent.
// NOTE: This test is especially important in an end-to-end context because the parent call
Expand All @@ -259,18 +258,4 @@ contract PendingCommitments {
// get_then_nullify_fn_selector: FunctionSelector,
//) {
//}

// Computes note hash and nullifier.
// Note 1: Needs to be defined by every contract producing logs.
// Note 2: Having it in all the contracts gives us the ability to compute the note hash and nullifier differently for different kind of notes.
unconstrained fn compute_note_hash_and_nullifier(
contract_address: AztecAddress,
nonce: Field,
storage_slot: Field,
note_type_id: Field,
serialized_note: [Field; VALUE_NOTE_LEN]
) -> pub [Field; 4] {
let note_header = NoteHeader::new(contract_address, nonce, storage_slot);
note_utils::compute_note_hash_and_nullifier(ValueNote::deserialize_content, note_header, serialized_note)
}
}
Loading
Loading