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 4 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.

25 changes: 0 additions & 25 deletions boxes/token/src/contracts/src/main.nr
Original file line number Diff line number Diff line change
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
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 @@ -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 @@ -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 @@ -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 @@ -57,19 +57,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 @@ -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 @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,4 @@ contract PriceFeed {
unconstrained fn fetch_price(assetId: Field) -> pub Asset {
storage.assets.at(assetId).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 @@ -88,23 +88,4 @@ contract SchnorrAccount {
// docs:end:entrypoint
true
}

// Computes notes 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; PUBLIC_KEY_NOTE_LEN]
) -> pub [Field; 4] {
assert(storage_slot == storage.signing_public_key.get_storage_slot());
let note_header = NoteHeader::new(contract_address, nonce, storage_slot);
note_utils::compute_note_hash_and_nullifier(
PublicKeyNote::deserialize_content,
note_header,
serialized_note
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Account contract that uses Schnorr signatures for authentication using a hardcoded public key.
contract SchnorrHardcodedAccount {
use dep::std;
use dep::aztec::context::PrivateContext;
use dep::aztec::{context::PrivateContext, protocol_types::address::AztecAddress};

use dep::authwit::{
entrypoint::{app::AppPayload, fee::FeePayload}, account::AccountActions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ mod auth_oracle;

contract SchnorrSingleKeyAccount {
use dep::std::{option::Option};
use dep::aztec::context::{PrivateContext, PublicContext, Context};
use dep::aztec::{context::{PrivateContext, PublicContext, Context}, protocol_types::address::AztecAddress};

use dep::authwit::{entrypoint::{app::AppPayload, fee::FeePayload}, account::AccountActions};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,4 @@ contract SlowTree {
unconstrained fn un_read_root(address: AztecAddress) -> pub Leaf {
storage.trees.at(address.to_field()).read_root()
}

unconstrained fn compute_note_hash_and_nullifier(
_contract_address: AztecAddress,
_nonce: Field,
_storage_slot: Field,
_note_type_id: Field,
_serialized_note: [Field; 4]
) -> pub [Field; 4] {
[0x0d, 0x0e, 0x0a, 0x0d]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added via Giphy

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,4 @@ contract StatefulTest {
unconstrained fn get_public_value(owner: AztecAddress) -> pub Field {
storage.public_values.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)
}
}
Loading
Loading