Skip to content

Commit

Permalink
secret_hash funcs cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Apr 22, 2024
1 parent bf234b4 commit 369f485
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 16 deletions.
4 changes: 2 additions & 2 deletions noir-projects/aztec-nr/aztec/src/context/avm_context.nr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::hash::{compute_secret_hash, compute_message_hash, compute_message_nullifier};
use crate::hash::{compute_message_secret_hash, compute_message_hash, compute_message_nullifier};
use dep::protocol_types::{
address::{AztecAddress, EthAddress},
constants::{L1_TO_L2_MESSAGE_LENGTH, NESTED_CALL_L2_GAS_BUFFER}, header::Header
Expand Down Expand Up @@ -96,7 +96,7 @@ impl PublicContextInterface for AvmContext {
}

fn consume_l1_to_l2_message(&mut self, content: Field, secret: Field, sender: EthAddress, leaf_index: Field) {
let secret_hash = compute_secret_hash(secret);
let secret_hash = compute_message_secret_hash(secret);
let message_hash = compute_message_hash(
sender,
self.chain_id(),
Expand Down
9 changes: 6 additions & 3 deletions noir-projects/aztec-nr/aztec/src/hash.nr
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@ use dep::protocol_types::{
address::{AztecAddress, EthAddress},
constants::{
GENERATOR_INDEX__L1_TO_L2_MESSAGE_SECRET, GENERATOR_INDEX__MESSAGE_NULLIFIER, ARGS_HASH_CHUNK_COUNT,
GENERATOR_INDEX__FUNCTION_ARGS, ARGS_HASH_CHUNK_LENGTH
GENERATOR_INDEX__FUNCTION_ARGS, ARGS_HASH_CHUNK_LENGTH, GENERATOR_INDEX__NOTE_SECRET_HASH
},
traits::Hash, hash::{pedersen_hash, poseidon2_hash, silo_nullifier, sha256_to_field}
};

pub fn compute_secret_hash(secret: Field) -> Field {
// TODO(#1205) This is probably not the right index to use
pub fn compute_message_secret_hash(secret: Field) -> Field {
pedersen_hash([secret], GENERATOR_INDEX__L1_TO_L2_MESSAGE_SECRET)
}

pub fn compute_note_secret_hash(secret: Field) -> Field {
pedersen_hash([secret], GENERATOR_INDEX__NOTE_SECRET_HASH)
}

pub fn compute_message_hash(
sender: EthAddress,
chain_id: Field,
Expand Down
4 changes: 2 additions & 2 deletions noir-projects/aztec-nr/aztec/src/messaging.nr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{
hash::{compute_secret_hash, compute_message_hash, compute_message_nullifier},
hash::{compute_message_secret_hash, compute_message_hash, compute_message_nullifier},
oracle::get_l1_to_l2_membership_witness::get_l1_to_l2_membership_witness
};

Expand All @@ -15,7 +15,7 @@ pub fn process_l1_to_l2_message(
content: Field,
secret: Field
) -> Field {
let secret_hash = compute_secret_hash(secret);
let secret_hash = compute_message_secret_hash(secret);
let message_hash = compute_message_hash(
portal_contract_address,
chain_id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ mod lib;

contract GasToken {
use dep::aztec::protocol_types::{abis::function_selector::FunctionSelector, address::{AztecAddress, EthAddress}};
use dep::aztec::{hash::compute_secret_hash, state_vars::{PublicMutable, Map}};
use dep::aztec::state_vars::{PublicMutable, Map};

use crate::lib::{calculate_fee, get_bridge_gas_msg_hash};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ contract Test {

use dep::aztec::{
context::{Context, inputs::private_context_inputs::PrivateContextInputs},
hash::{pedersen_hash, compute_secret_hash, ArgsHasher},
hash::{pedersen_hash, compute_note_secret_hash, ArgsHasher},
note::{
lifecycle::{create_note, destroy_note}, note_getter::{get_notes, view_notes},
note_getter_options::NoteStatus
Expand Down Expand Up @@ -364,7 +364,7 @@ contract Test {
// Adapted from TokenContract#redeem_shield but without an initcheck so it can be run in simulator/src/client/private_execution.test.ts
fn consume_note_from_secret(secret: Field) {
let notes_set = storage.example_set;
let secret_hash = compute_secret_hash(secret);
let secret_hash = compute_note_secret_hash(secret);
let mut options = NoteGetterOptions::new();
options = options.select(FieldNote::properties().value, secret_hash, Option::none()).set_limit(1);
let notes = notes_set.get_notes(options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ contract TokenBlacklist {
use dep::aztec::protocol_types::{abis::function_selector::FunctionSelector, address::AztecAddress};
use dep::aztec::{
note::{note_getter_options::NoteGetterOptions, note_header::NoteHeader},
hash::compute_secret_hash, state_vars::{Map, PublicMutable, PrivateSet, SharedImmutable}
hash::compute_note_secret_hash, state_vars::{Map, PublicMutable, PrivateSet, SharedImmutable}
};

use dep::field_note::field_note::FieldNote;
Expand Down Expand Up @@ -193,7 +193,7 @@ contract TokenBlacklist {
assert(!to_roles.is_blacklisted, "Blacklisted: Recipient");

let pending_shields = storage.pending_shields;
let secret_hash = compute_secret_hash(secret);
let secret_hash = compute_note_secret_hash(secret);
// Get 1 note (set_limit(1)) which has amount stored in field with index 0 (select(0, amount)) and secret_hash
// stored in field with index 1 (select(1, secret_hash)).
let mut options = NoteGetterOptions::new();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
contract TokenBridge {
use dep::aztec::prelude::{FunctionSelector, AztecAddress, EthAddress, PublicMutable};

use dep::aztec::{context::Context, hash::compute_secret_hash};

use dep::token_portal_content_hash_lib::{get_mint_public_content_hash, get_mint_private_content_hash, get_withdraw_content_hash};

use dep::token::Token;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ contract Token {
use dep::compressed_string::FieldCompressedString;

use dep::aztec::prelude::{NoteGetterOptions, Map, PublicMutable, SharedImmutable, PrivateSet, AztecAddress};
use dep::aztec::hash::compute_secret_hash;
use dep::aztec::hash::compute_note_secret_hash;

// docs:start:import_authwit
use dep::authwit::{auth::{assert_current_call_valid_authwit, assert_current_call_valid_authwit_public}};
Expand Down Expand Up @@ -239,7 +239,7 @@ contract Token {
#[aztec(private)]
fn redeem_shield(to: AztecAddress, amount: Field, secret: Field) {
let pending_shields = storage.pending_shields;
let secret_hash = compute_secret_hash(secret);
let secret_hash = compute_note_secret_hash(secret);
// Get 1 note (set_limit(1)) which has amount stored in field with index 0 (select(0, amount)) and secret_hash
// stored in field with index 1 (select(1, secret_hash)).
let mut options = NoteGetterOptions::new();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,3 +243,4 @@ global GENERATOR_INDEX__OVSK_M = 49;
global GENERATOR_INDEX__TSK_M = 50;
global GENERATOR_INDEX__PUBLIC_KEYS_HASH = 51;
global GENERATOR_INDEX__NOTE_NULLIFIER = 52;
global GENERATOR_INDEX__NOTE_SECRET_HASH = 53;
1 change: 1 addition & 0 deletions yarn-project/circuits.js/src/constants.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,4 +203,5 @@ export enum GeneratorIndex {
TSK_M = 50,
PUBLIC_KEYS_HASH = 51,
NOTE_NULLIFIER = 52,
NOTE_SECRET_HASH = 53,
}

0 comments on commit 369f485

Please sign in to comment.