@@ -6,6 +6,7 @@ import { bufferToHex } from '@aztec/foundation/string';
66import { SiblingPath } from '@aztec/foundation/trees' ;
77
88import type { AztecAddress } from '../aztec-address/index.js' ;
9+ import type { BlockParameter } from '../block/block_parameter.js' ;
910import { computeL1ToL2MessageNullifier } from '../hash/hash.js' ;
1011import type { AztecNode } from '../interfaces/aztec-node.js' ;
1112import { 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