Skip to content

Commit 5c51ac3

Browse files
authored
fix: use anchor block on getL1ToL2MsgWitness (#21872)
I made the param be optional in the fn since it has other unrelated callsites (e.g. the CLI). I also merged both node roundtrips into a single one.
1 parent 2343ec8 commit 5c51ac3

2 files changed

Lines changed: 14 additions & 10 deletions

File tree

yarn-project/pxe/src/contract_function_simulator/oracle/utility_execution_oracle.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
380380
}
381381

382382
/**
383-
* Fetches a message from the executionStore, given its key.
383+
* Returns the membership witness of an un-nullified L1 to L2 message.
384384
* @param contractAddress - Address of a contract by which the message was emitted.
385385
* @param messageHash - Hash of the message.
386386
* @param secret - Secret used to compute a nullifier.
@@ -393,6 +393,7 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
393393
contractAddress,
394394
messageHash,
395395
secret,
396+
await this.anchorBlockHeader.hash(),
396397
);
397398

398399
return new MessageLoadOracleInputs(messageIndex, siblingPath);

yarn-project/stdlib/src/messaging/l1_to_l2_message.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { bufferToHex } from '@aztec/foundation/string';
66
import { SiblingPath } from '@aztec/foundation/trees';
77

88
import type { AztecAddress } from '../aztec-address/index.js';
9+
import type { BlockParameter } from '../block/block_parameter.js';
910
import { computeL1ToL2MessageNullifier } from '../hash/hash.js';
1011
import type { AztecNode } from '../interfaces/aztec-node.js';
1112
import { MerkleTreeId } from '../trees/merkle_tree_id.js';
@@ -79,20 +80,22 @@ export async function getNonNullifiedL1ToL2MessageWitness(
7980
contractAddress: AztecAddress,
8081
messageHash: Fr,
8182
secret: Fr,
83+
referenceBlock: BlockParameter = 'latest',
8284
): Promise<[bigint, SiblingPath<typeof L1_TO_L2_MSG_TREE_HEIGHT>]> {
83-
const response = await node.getL1ToL2MessageMembershipWitness('latest', messageHash);
84-
if (!response) {
85-
throw new Error(`No L1 to L2 message found for message hash ${messageHash.toString()}`);
86-
}
85+
const messageNullifier = await computeL1ToL2MessageNullifier(contractAddress, messageHash, secret);
8786

88-
const [messageIndex, siblingPath] = response;
87+
const [l1ToL2Response, nullifierResponse] = await Promise.all([
88+
node.getL1ToL2MessageMembershipWitness(referenceBlock, messageHash),
89+
node.findLeavesIndexes(referenceBlock, MerkleTreeId.NULLIFIER_TREE, [messageNullifier]),
90+
]);
8991

90-
const messageNullifier = await computeL1ToL2MessageNullifier(contractAddress, messageHash, secret);
92+
if (!l1ToL2Response) {
93+
throw new Error(`No L1 to L2 message found for message hash ${messageHash.toString()}`);
94+
}
9195

92-
const [nullifierIndex] = await node.findLeavesIndexes('latest', MerkleTreeId.NULLIFIER_TREE, [messageNullifier]);
93-
if (nullifierIndex !== undefined) {
96+
if (nullifierResponse[0] !== undefined) {
9497
throw new Error(`No non-nullified L1 to L2 message found for message hash ${messageHash.toString()}`);
9598
}
9699

97-
return [messageIndex, siblingPath];
100+
return l1ToL2Response;
98101
}

0 commit comments

Comments
 (0)