@@ -17,6 +17,7 @@ import {
17
17
type PXE ,
18
18
type PXEInfo ,
19
19
type PrivateKernelProver ,
20
+ type SiblingPath ,
20
21
SimulatedTx ,
21
22
SimulationError ,
22
23
TaggedLog ,
@@ -32,11 +33,12 @@ import {
32
33
import {
33
34
AztecAddress ,
34
35
type CompleteAddress ,
36
+ type L1_TO_L2_MSG_TREE_HEIGHT ,
35
37
type PartialAddress ,
36
38
computeContractClassId ,
37
39
getContractClassFromArtifact ,
38
40
} from '@aztec/circuits.js' ;
39
- import { computeNoteHashNonce , siloNullifier } from '@aztec/circuits.js/hash' ;
41
+ import { computeL1ToL2MessageNullifier , computeNoteHashNonce , siloNullifier } from '@aztec/circuits.js/hash' ;
40
42
import {
41
43
type ContractArtifact ,
42
44
type DecodedReturn ,
@@ -56,6 +58,7 @@ import { getCanonicalMultiCallEntrypointAddress } from '@aztec/protocol-contract
56
58
import {
57
59
type AcirSimulator ,
58
60
type ExecutionResult ,
61
+ MessageLoadOracleInputs ,
59
62
accumulateReturnValues ,
60
63
collectEnqueuedPublicFunctionCalls ,
61
64
collectPublicTeardownFunctionCall ,
@@ -355,6 +358,35 @@ export class PXEService implements PXE {
355
358
return Promise . all ( extendedNotes ) ;
356
359
}
357
360
361
+ async getL1ToL2MembershipWitness (
362
+ contractAddress : AztecAddress ,
363
+ messageHash : Fr ,
364
+ secret : Fr ,
365
+ ) : Promise < [ bigint , SiblingPath < typeof L1_TO_L2_MSG_TREE_HEIGHT > ] | undefined > {
366
+ let nullifierIndex : bigint | undefined ;
367
+ let messageIndex = 0n ;
368
+ let startIndex = 0n ;
369
+ let siblingPath : SiblingPath < typeof L1_TO_L2_MSG_TREE_HEIGHT > ;
370
+
371
+ // We iterate over messages until we find one whose nullifier is not in the nullifier tree --> we need to check
372
+ // for nullifiers because messages can have duplicates.
373
+ do {
374
+ const response = await this . node . getL1ToL2MessageMembershipWitness ( 'latest' , messageHash , startIndex ) ;
375
+ if ( ! response ) {
376
+ throw new Error ( `No non-nullified L1 to L2 message found for message hash ${ messageHash . toString ( ) } ` ) ;
377
+ }
378
+ [ messageIndex , siblingPath ] = response ;
379
+
380
+ const messageNullifier = computeL1ToL2MessageNullifier ( contractAddress , messageHash , secret , messageIndex ) ;
381
+
382
+ nullifierIndex = await this . node . findLeafIndex ( 'latest' , MerkleTreeId . NULLIFIER_TREE , messageNullifier ) ;
383
+
384
+ startIndex = messageIndex + 1n ;
385
+ } while ( nullifierIndex !== undefined ) ;
386
+
387
+ return [ messageIndex , siblingPath ] ;
388
+ }
389
+
358
390
public async addNote ( note : ExtendedNote , scope ?: AztecAddress ) {
359
391
const owner = await this . db . getCompleteAddress ( note . owner ) ;
360
392
if ( ! owner ) {
0 commit comments