Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Apr 22, 2024
1 parent dbc3ceb commit b092351
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 61 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use dep::aztec::prelude::{AztecAddress, PrivateContext, NoteHeader, emit_encrypted_log, NoteInterface};
use dep::aztec::{
constants::GENERATOR_INDEX__NULLIFIER, note::utils::compute_note_hash_for_consumption,
protocol_types::constants::GENERATOR_INDEX__NULLIFIER, note::utils::compute_note_hash_for_consumption,
hash::poseidon2_hash,
oracle::{nullifier_key::get_app_nullifier_secret_key, get_public_key::get_public_key}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use dep::aztec::prelude::{AztecAddress, NoteInterface, NoteHeader, PrivateContex
use dep::aztec::{
note::{utils::compute_note_hash_for_consumption},
oracle::{nullifier_key::get_app_nullifier_secret_key, get_public_key::get_public_key},
hash::pedersen_hash, protocol_types::traits::Empty
hash::poseidon2_hash, protocol_types::{traits::Empty, constants::GENERATOR_INDEX__NULLIFIER},
};

// Shows how to create a custom note
Expand All @@ -28,19 +28,21 @@ impl NoteInterface<CARD_NOTE_LEN> for CardNote {
fn compute_nullifier(self, context: &mut PrivateContext) -> Field {
let note_hash_for_nullify = compute_note_hash_for_consumption(self);
let secret = context.request_app_nullifier_secret_key(self.owner);
pedersen_hash([
poseidon2_hash([
note_hash_for_nullify,
secret,
],0)
GENERATOR_INDEX__NULLIFIER as Field,
])
}

fn compute_nullifier_without_context(self) -> Field {
let note_hash_for_nullify = compute_note_hash_for_consumption(self);
let secret = get_app_nullifier_secret_key(self.owner);
pedersen_hash([
poseidon2_hash([
note_hash_for_nullify,
secret,
],0)
GENERATOR_INDEX__NULLIFIER as Field,
])
}

// Broadcasts the note as an encrypted log on L1.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use dep::aztec::prelude::{
use dep::aztec::{
note::utils::compute_note_hash_for_consumption,
oracle::{nullifier_key::get_app_nullifier_secret_key, get_public_key::get_public_key},
hash::pedersen_hash
hash::poseidon2_hash, protocol_types::constants::GENERATOR_INDEX__NULLIFIER,
};

global ECDSA_PUBLIC_KEY_NOTE_LEN: Field = 5;
Expand Down Expand Up @@ -67,23 +67,23 @@ impl NoteInterface<ECDSA_PUBLIC_KEY_NOTE_LEN> for EcdsaPublicKeyNote {
}

fn compute_nullifier(self, context: &mut PrivateContext) -> Field {
let unique_siloed_note_hash = compute_note_hash_for_consumption(self);
let note_hash_for_nullify = compute_note_hash_for_consumption(self);
let secret = context.request_app_nullifier_secret_key(self.owner);
// TODO(#1205) Should use a non-zero generator index.
pedersen_hash([
unique_siloed_note_hash,
poseidon2_hash([
note_hash_for_nullify,
secret,
],0)
GENERATOR_INDEX__NULLIFIER as Field,
])
}

fn compute_nullifier_without_context(self) -> Field {
let unique_siloed_note_hash = compute_note_hash_for_consumption(self);
let note_hash_for_nullify = compute_note_hash_for_consumption(self);
let secret = get_app_nullifier_secret_key(self.owner);
// TODO(#1205) Should use a non-zero generator index.
pedersen_hash([
unique_siloed_note_hash,
poseidon2_hash([
note_hash_for_nullify,
secret,
],0)
GENERATOR_INDEX__NULLIFIER as Field,
])
}

// Broadcasts the note as an encrypted log on L1.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use dep::aztec::prelude::{AztecAddress, NoteHeader, NoteInterface, PrivateContext, emit_encrypted_log};
use dep::aztec::{
note::utils::compute_note_hash_for_consumption, hash::pedersen_hash,
oracle::{nullifier_key::get_app_nullifier_secret_key, get_public_key::get_public_key}
note::utils::compute_note_hash_for_consumption, hash::poseidon2_hash,
oracle::{nullifier_key::get_app_nullifier_secret_key, get_public_key::get_public_key},
protocol_types::constants::GENERATOR_INDEX__NULLIFIER,
};

global PUBLIC_KEY_NOTE_LEN: Field = 3;
Expand All @@ -17,23 +18,23 @@ struct PublicKeyNote {

impl NoteInterface<PUBLIC_KEY_NOTE_LEN> for PublicKeyNote {
fn compute_nullifier(self, context: &mut PrivateContext) -> Field {
let unique_siloed_note_hash = compute_note_hash_for_consumption(self);
let note_hash_for_nullify = compute_note_hash_for_consumption(self);
let secret = context.request_app_nullifier_secret_key(self.owner);
// TODO(#1205) Should use a non-zero generator index.
pedersen_hash([
unique_siloed_note_hash,
poseidon2_hash([
note_hash_for_nullify,
secret,
],0)
GENERATOR_INDEX__NULLIFIER as Field,
])
}

fn compute_nullifier_without_context(self) -> Field {
let unique_siloed_note_hash = compute_note_hash_for_consumption(self);
let note_hash_for_nullify = compute_note_hash_for_consumption(self);
let secret = get_app_nullifier_secret_key(self.owner);
// TODO(#1205) Should use a non-zero generator index.
pedersen_hash([
unique_siloed_note_hash,
poseidon2_hash([
note_hash_for_nullify,
secret,
],0)
GENERATOR_INDEX__NULLIFIER as Field,
])
}

// Broadcasts the note as an encrypted log on L1.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use dep::aztec::prelude::{AztecAddress, NoteHeader, NoteInterface, PrivateContext, emit_encrypted_log};
use dep::aztec::{note::utils::compute_note_hash_for_consumption, hash::pedersen_hash};
use dep::aztec::oracle::{unsafe_rand::unsafe_rand, nullifier_key::get_app_nullifier_secret_key, get_public_key::get_public_key};
use dep::aztec::{
prelude::{AztecAddress, NoteHeader, NoteInterface, PrivateContext, emit_encrypted_log},
protocol_types::constants::GENERATOR_INDEX__NULLIFIER,
note::utils::compute_note_hash_for_consumption, hash::poseidon2_hash,
oracle::{unsafe_rand::unsafe_rand, nullifier_key::get_app_nullifier_secret_key, get_public_key::get_public_key},
};

trait OwnedNote {
fn new(amount: U128, owner: AztecAddress) -> Self;
Expand All @@ -27,22 +30,22 @@ impl NoteInterface<TOKEN_NOTE_LEN> for TokenNote {
fn compute_nullifier(self, context: &mut PrivateContext) -> Field {
let note_hash_for_nullify = compute_note_hash_for_consumption(self);
let secret = context.request_app_nullifier_secret_key(self.owner);
// TODO(#1205) Should use a non-zero generator index.
pedersen_hash([
poseidon2_hash([
note_hash_for_nullify,
secret,
],0)
GENERATOR_INDEX__NULLIFIER as Field,
])
}
// docs:end:nullifier

fn compute_nullifier_without_context(self) -> Field {
let note_hash_for_nullify = compute_note_hash_for_consumption(self);
let secret = get_app_nullifier_secret_key(self.owner);
// TODO(#1205) Should use a non-zero generator index.
pedersen_hash([
poseidon2_hash([
note_hash_for_nullify,
secret,
],0)
GENERATOR_INDEX__NULLIFIER as Field,
])
}

// Broadcasts the note as an encrypted log on L1.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// docs:start:token_types_all
use dep::aztec::prelude::{NoteHeader, NoteInterface, PrivateContext};
use dep::aztec::{
note::{note_getter_options::PropertySelector, utils::compute_note_hash_for_consumption},
hash::{compute_secret_hash, pedersen_hash}
hash::poseidon2_hash, prelude::{NoteHeader, NoteInterface, PrivateContext},
protocol_types::constants::GENERATOR_INDEX__NULLIFIER
};

global TRANSPARENT_NOTE_LEN: Field = 2;
Expand Down Expand Up @@ -52,9 +52,11 @@ impl NoteInterface<TRANSPARENT_NOTE_LEN> for TransparentNote {
// circuit.
// This achieves that the note can only be spent by the party that knows the secret.
fn compute_nullifier_without_context(self) -> Field {
let siloed_note_hash = compute_note_hash_for_consumption(self);
// TODO(#1205) Should use a non-zero generator index.
pedersen_hash([siloed_note_hash], 0)
let note_hash_for_nullify = compute_note_hash_for_consumption(self);
poseidon2_hash([
note_hash_for_nullify,
GENERATOR_INDEX__NULLIFIER as Field,
])
}

fn broadcast(self, context: &mut PrivateContext, slot: Field) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use dep::aztec::prelude::{
AztecAddress, NoteInterface, NoteGetterOptions, NoteViewerOptions, NoteHeader, PrivateContext,
PrivateSet, Map, emit_encrypted_log
use dep::aztec::{
prelude::{AztecAddress, NoteHeader, NoteInterface, PrivateContext, emit_encrypted_log},
protocol_types::constants::GENERATOR_INDEX__NULLIFIER,
note::utils::compute_note_hash_for_consumption, hash::poseidon2_hash,
oracle::{unsafe_rand::unsafe_rand, nullifier_key::get_app_nullifier_secret_key, get_public_key::get_public_key},
};
use dep::aztec::{note::utils::compute_note_hash_for_consumption, hash::pedersen_hash};
use dep::aztec::oracle::{unsafe_rand::unsafe_rand, nullifier_key::get_app_nullifier_secret_key, get_public_key::get_public_key};

trait OwnedNote {
fn new(amount: U128, owner: AztecAddress) -> Self;
Expand All @@ -30,22 +30,22 @@ impl NoteInterface<TOKEN_NOTE_LEN> for TokenNote {
fn compute_nullifier(self, context: &mut PrivateContext) -> Field {
let note_hash_for_nullify = compute_note_hash_for_consumption(self);
let secret = context.request_app_nullifier_secret_key(self.owner);
// TODO(#1205) Should use a non-zero generator index.
pedersen_hash([
poseidon2_hash([
note_hash_for_nullify,
secret,
],0)
GENERATOR_INDEX__NULLIFIER as Field,
])
}
// docs:end:nullifier

fn compute_nullifier_without_context(self) -> Field {
let note_hash_for_nullify = compute_note_hash_for_consumption(self);
let secret = get_app_nullifier_secret_key(self.owner);
// TODO(#1205) Should use a non-zero generator index.
pedersen_hash([
poseidon2_hash([
note_hash_for_nullify,
secret,
],0)
GENERATOR_INDEX__NULLIFIER as Field,
])
}

// Broadcasts the note as an encrypted log on L1.
Expand All @@ -63,7 +63,7 @@ impl NoteInterface<TOKEN_NOTE_LEN> for TokenNote {
);
}
}
}
}

impl OwnedNote for TokenNote {
fn new(amount: U128, owner: AztecAddress) -> Self {
Expand All @@ -82,5 +82,5 @@ impl OwnedNote for TokenNote {
fn get_owner(self) -> AztecAddress {
self.owner
}

}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// docs:start:token_types_all
use dep::aztec::prelude::{NoteHeader, NoteInterface, PrivateContext};
use dep::aztec::{
note::{note_getter_options::PropertySelector, utils::compute_note_hash_for_consumption},
hash::{compute_secret_hash, pedersen_hash}
hash::poseidon2_hash, prelude::{NoteHeader, NoteInterface, PrivateContext},
protocol_types::constants::GENERATOR_INDEX__NULLIFIER
};

global TRANSPARENT_NOTE_LEN: Field = 2;
Expand Down Expand Up @@ -52,9 +52,11 @@ impl NoteInterface<TRANSPARENT_NOTE_LEN> for TransparentNote {
// circuit.
// This achieves that the note can only be spent by the party that knows the secret.
fn compute_nullifier_without_context(self) -> Field {
let siloed_note_hash = compute_note_hash_for_consumption(self);
// TODO(#1205) Should use a non-zero generator index.
pedersen_hash([siloed_note_hash], 0)
let note_hash_for_nullify = compute_note_hash_for_consumption(self);
poseidon2_hash([
note_hash_for_nullify,
GENERATOR_INDEX__NULLIFIER as Field,
])
}

fn broadcast(self, context: &mut PrivateContext, slot: Field) {
Expand Down

0 comments on commit b092351

Please sign in to comment.