Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Mar 22, 2024
1 parent 5f5c43c commit 1e7d392
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 8 deletions.
2 changes: 1 addition & 1 deletion noir-projects/aztec-nr/aztec/src/messaging.nr
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub fn process_l1_to_l2_message(
);
let message_hash = msg.hash();

let returned_message = get_l1_to_l2_membership_witness(message_hash);
let returned_message = get_l1_to_l2_membership_witness(message_hash, secret);
let leaf_index = returned_message[0];
let sibling_path = arr_copy_slice(returned_message, [0; L1_TO_L2_MSG_TREE_HEIGHT], 1);

Expand Down
5 changes: 5 additions & 0 deletions yarn-project/pxe/src/simulator_oracle/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,17 @@ export class SimulatorOracle implements DBOracle {
let nullifierIndex: bigint | undefined;
let messageIndex = 0n;
let siblingPath: SiblingPath<typeof L1_TO_L2_MSG_TREE_HEIGHT>;

// We iterate over messages until we find one whose nullifier is not in the nullifier tree --> ewe need to check
// for nullifiers because messages can have duplicates.
do {
const response = await this.aztecNode.getL1ToL2MessageMembershipWitness('latest', messageHash, messageIndex);
if (!response) {
throw new Error(`No non-nullified L1 to L2 message found for message hash ${messageHash.toString()}`);
}
[messageIndex, siblingPath] = response;

// TODO: create separate helper function
const messageNullifier = pedersenHash(
[messageHash, secret, new Fr(messageIndex)].map(v => v.toBuffer()),
GeneratorIndex.NULLIFIER,
Expand Down
33 changes: 26 additions & 7 deletions yarn-project/sequencer-client/src/simulator/public_executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
L1ToL2MessageSource,
MerkleTreeId,
NullifierMembershipWitness,
SiblingPath,
Tx,
UnencryptedL2Log,
} from '@aztec/circuit-types';
Expand All @@ -12,12 +13,14 @@ import {
EthAddress,
Fr,
FunctionSelector,
GeneratorIndex,
L1_TO_L2_MSG_TREE_HEIGHT,
NULLIFIER_TREE_HEIGHT,
NullifierLeafPreimage,
PublicDataTreeLeafPreimage,
} from '@aztec/circuits.js';
import { computePublicDataTreeLeafSlot } from '@aztec/circuits.js/hash';
import { pedersenHash } from '@aztec/foundation/crypto';
import { createDebugLogger } from '@aztec/foundation/log';
import { getCanonicalClassRegistererAddress } from '@aztec/protocol-contracts/class-registerer';
import { CommitmentsDB, MessageLoadOracleInputs, PublicContractsDB, PublicStateDB } from '@aztec/simulator';
Expand Down Expand Up @@ -227,16 +230,32 @@ export class WorldStateDB implements CommitmentsDB {
messageHash: Fr,
secret: Fr,
): Promise<MessageLoadOracleInputs<typeof L1_TO_L2_MSG_TREE_HEIGHT>> {
// TODO: do the nullifier check here
const index = (await this.db.findLeafIndex(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, messageHash.toBuffer()))!;
if (index === undefined) {
throw new Error(`Message ${messageHash.toString()} not found`);
}
let nullifierIndex: bigint | undefined;
let messageIndex: bigint | undefined;

// We iterate over messages until we find one whose nullifier is not in the nullifier tree --> ewe need to check
// for nullifiers because messages can have duplicates.
do {
messageIndex = (await this.db.findLeafIndex(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, messageHash.toBuffer()))!;
if (messageIndex === undefined) {
throw new Error(`No non-nullified L1 to L2 message found for message hash ${messageHash.toString()}`);
}

// TODO: create separate helper function
const messageNullifier = pedersenHash(
[messageHash, secret, new Fr(messageIndex)].map(v => v.toBuffer()),
GeneratorIndex.NULLIFIER,
);

nullifierIndex = await this.getNullifierIndex(messageNullifier);
} while (nullifierIndex !== undefined);

const siblingPath = await this.db.getSiblingPath<typeof L1_TO_L2_MSG_TREE_HEIGHT>(
MerkleTreeId.L1_TO_L2_MESSAGE_TREE,
index,
messageIndex,
);
return new MessageLoadOracleInputs<typeof L1_TO_L2_MSG_TREE_HEIGHT>(index, siblingPath);

return new MessageLoadOracleInputs<typeof L1_TO_L2_MSG_TREE_HEIGHT>(messageIndex, siblingPath);
}

public async getCommitmentIndex(commitment: Fr): Promise<bigint | undefined> {
Expand Down

0 comments on commit 1e7d392

Please sign in to comment.