diff --git a/yarn-project/simulator/src/avm/fixtures/index.ts b/yarn-project/simulator/src/avm/fixtures/index.ts index b292074abfb1..14db8d632a36 100644 --- a/yarn-project/simulator/src/avm/fixtures/index.ts +++ b/yarn-project/simulator/src/avm/fixtures/index.ts @@ -105,9 +105,11 @@ export function allSameExcept(original: any, overrides: any): any { /** * Create an empty L1ToL2Message oracle input */ -export function initL1ToL2MessageOracleInput(leafIndex?: bigint): any { +export function initL1ToL2MessageOracleInput( + leafIndex?: bigint, +): MessageLoadOracleInputs { return new MessageLoadOracleInputs( - leafIndex ? leafIndex : BigInt(0), + leafIndex ?? 0n, new SiblingPath(L1_TO_L2_MSG_TREE_HEIGHT, Array(L1_TO_L2_MSG_TREE_HEIGHT)), ); } diff --git a/yarn-project/simulator/src/avm/journal/journal.test.ts b/yarn-project/simulator/src/avm/journal/journal.test.ts index 4a4db8e33041..bcee9bbea5a3 100644 --- a/yarn-project/simulator/src/avm/journal/journal.test.ts +++ b/yarn-project/simulator/src/avm/journal/journal.test.ts @@ -70,7 +70,7 @@ describe('journal', () => { expect(exists).toEqual(false); const journalUpdates = journal.flush(); - expect(journalUpdates.nullifierChecks.map(c => [c.nullifier, c.exists])).toEqual([[utxo, false]]); + expect(journalUpdates.nullifierChecks).toEqual([expect.objectContaining({ nullifier: utxo, exists: false })]); }); it('checkNullifierExists works for existing nullifiers', async () => { const contractAddress = new Fr(1); @@ -82,7 +82,7 @@ describe('journal', () => { expect(exists).toEqual(true); const journalUpdates = journal.flush(); - expect(journalUpdates.nullifierChecks.map(c => [c.nullifier, c.exists])).toEqual([[utxo, true]]); + expect(journalUpdates.nullifierChecks).toEqual([expect.objectContaining({ nullifier: utxo, exists: true })]); }); it('Should maintain nullifiers', async () => { const contractAddress = new Fr(1); @@ -100,8 +100,8 @@ describe('journal', () => { expect(exists).toEqual(false); const journalUpdates = journal.flush(); - expect(journalUpdates.l1ToL2MessageChecks.map(c => [c.leafIndex, c.msgHash, c.exists])).toEqual([ - [leafIndex, utxo, false], + expect(journalUpdates.l1ToL2MessageChecks).toEqual([ + expect.objectContaining({ leafIndex: leafIndex, msgHash: utxo, exists: false }), ]); }); it('checkL1ToL2MessageExists works for existing nullifiers', async () => { @@ -113,8 +113,8 @@ describe('journal', () => { expect(exists).toEqual(true); const journalUpdates = journal.flush(); - expect(journalUpdates.l1ToL2MessageChecks.map(c => [c.leafIndex, c.msgHash, c.exists])).toEqual([ - [leafIndex, utxo, true], + expect(journalUpdates.l1ToL2MessageChecks).toEqual([ + expect.objectContaining({ leafIndex: leafIndex, msgHash: utxo, exists: true }), ]); }); it('Should maintain nullifiers', async () => { @@ -200,14 +200,14 @@ describe('journal', () => { { recipient, content: commitment }, { recipient, content: commitmentT1 }, ]); - expect(journalUpdates.nullifierChecks.map(c => [c.nullifier, c.exists])).toEqual([ - [commitment, true], - [commitmentT1, true], + expect(journalUpdates.nullifierChecks).toEqual([ + expect.objectContaining({ nullifier: commitment, exists: true }), + expect.objectContaining({ nullifier: commitmentT1, exists: true }), ]); expect(journalUpdates.newNullifiers).toEqual([commitment, commitmentT1]); - expect(journalUpdates.l1ToL2MessageChecks.map(c => [c.leafIndex, c.msgHash, c.exists])).toEqual([ - [index, commitment, false], - [indexT1, commitmentT1, false], + expect(journalUpdates.l1ToL2MessageChecks).toEqual([ + expect.objectContaining({ leafIndex: index, msgHash: commitment, exists: false }), + expect.objectContaining({ leafIndex: indexT1, msgHash: commitmentT1, exists: false }), ]); }); @@ -274,14 +274,14 @@ describe('journal', () => { // Check that the world state _traces_ are merged even on rejection expect(journalUpdates.newNoteHashes).toEqual([commitment, commitmentT1]); - expect(journalUpdates.nullifierChecks.map(c => [c.nullifier, c.exists])).toEqual([ - [commitment, true], - [commitmentT1, true], + expect(journalUpdates.nullifierChecks).toEqual([ + expect.objectContaining({ nullifier: commitment, exists: true }), + expect.objectContaining({ nullifier: commitmentT1, exists: true }), ]); expect(journalUpdates.newNullifiers).toEqual([commitment, commitmentT1]); - expect(journalUpdates.l1ToL2MessageChecks.map(c => [c.leafIndex, c.msgHash, c.exists])).toEqual([ - [index, commitment, false], - [indexT1, commitmentT1, false], + expect(journalUpdates.l1ToL2MessageChecks).toEqual([ + expect.objectContaining({ leafIndex: index, msgHash: commitment, exists: false }), + expect.objectContaining({ leafIndex: indexT1, msgHash: commitmentT1, exists: false }), ]); // Check that rejected Accrued Substate is absent diff --git a/yarn-project/simulator/src/avm/journal/trace.test.ts b/yarn-project/simulator/src/avm/journal/trace.test.ts index 1b2cb5880c1d..a7b309fbb30a 100644 --- a/yarn-project/simulator/src/avm/journal/trace.test.ts +++ b/yarn-project/simulator/src/avm/journal/trace.test.ts @@ -224,5 +224,9 @@ describe('world state access trace', () => { exists: c.exists, })), ).toEqual([expectedMessageCheck, expectedMessageCheckT1]); + expect(trace.l1ToL2MessageChecks).toEqual([ + expect.objectContaining({ leafIndex: msgLeafIndex, msgHash: msgHash, exists: msgExists }), + expect.objectContaining({ leafIndex: msgLeafIndexT1, msgHash: msgHashT1, exists: msgExistsT1 }), + ]); }); }); diff --git a/yarn-project/simulator/src/avm/opcodes/accrued_substate.test.ts b/yarn-project/simulator/src/avm/opcodes/accrued_substate.test.ts index 9a1168916023..1dbe2f5ad5b8 100644 --- a/yarn-project/simulator/src/avm/opcodes/accrued_substate.test.ts +++ b/yarn-project/simulator/src/avm/opcodes/accrued_substate.test.ts @@ -191,8 +191,9 @@ describe('Accrued Substate', () => { expect(exists).toEqual(new Uint8(0)); const journalState = context.persistableState.flush(); - expect(journalState.nullifierChecks.length).toEqual(1); - expect(journalState.nullifierChecks[0].exists).toEqual(false); + expect(journalState.nullifierChecks).toEqual([ + expect.objectContaining({ nullifier: value.toFr(), exists: false }), + ]); }); it('Should correctly show true when nullifier exists', async () => { @@ -214,8 +215,9 @@ describe('Accrued Substate', () => { expect(exists).toEqual(new Uint8(1)); const journalState = context.persistableState.flush(); - expect(journalState.nullifierChecks.length).toEqual(1); - expect(journalState.nullifierChecks[0].exists).toEqual(true); + expect(journalState.nullifierChecks).toEqual([ + expect.objectContaining({ nullifier: value.toFr(), exists: true }), + ]); }); }); @@ -278,7 +280,7 @@ describe('Accrued Substate', () => { }); }); - describe('L1ToL1MessageExists', () => { + describe('L1ToL2MessageExists', () => { it('Should (de)serialize correctly', () => { const buf = Buffer.from([ L1ToL2MessageExists.opcode, // opcode @@ -314,8 +316,9 @@ describe('Accrued Substate', () => { expect(exists).toEqual(new Uint8(0)); const journalState = context.persistableState.flush(); - expect(journalState.l1ToL2MessageChecks.length).toEqual(1); - expect(journalState.l1ToL2MessageChecks[0].exists).toEqual(false); + expect(journalState.l1ToL2MessageChecks).toEqual([ + expect.objectContaining({ leafIndex: leafIndex.toFr(), msgHash: msgHash.toFr(), exists: false }), + ]); }); it('Should correctly show true when L1ToL2 message exists', async () => { @@ -340,8 +343,9 @@ describe('Accrued Substate', () => { expect(exists).toEqual(new Uint8(1)); const journalState = context.persistableState.flush(); - expect(journalState.l1ToL2MessageChecks.length).toEqual(1); - expect(journalState.l1ToL2MessageChecks[0].exists).toEqual(true); + expect(journalState.l1ToL2MessageChecks).toEqual([ + expect.objectContaining({ leafIndex: leafIndex.toFr(), msgHash: msgHash.toFr(), exists: true }), + ]); }); }); @@ -393,7 +397,7 @@ describe('Accrued Substate', () => { expect(inst.serialize()).toEqual(buf); }); - it('Should append l1 to l2 messages correctly', async () => { + it('Should append l2 to l1 messages correctly', async () => { const recipientOffset = 0; const recipient = new Fr(42); const contentOffset = 1; diff --git a/yarn-project/simulator/src/avm/opcodes/accrued_substate.ts b/yarn-project/simulator/src/avm/opcodes/accrued_substate.ts index 669c6035a9db..d34354336dc5 100644 --- a/yarn-project/simulator/src/avm/opcodes/accrued_substate.ts +++ b/yarn-project/simulator/src/avm/opcodes/accrued_substate.ts @@ -140,10 +140,6 @@ export class L1ToL2MessageExists extends Instruction { } async execute(context: AvmContext): Promise { - if (context.environment.isStaticCall) { - throw new StaticCallStorageAlterError(); - } - const msgHash = context.machineState.memory.get(this.msgHashOffset).toFr(); const msgLeafIndex = context.machineState.memory.get(this.msgLeafIndexOffset).toFr(); const exists = await context.persistableState.checkL1ToL2MessageExists(msgHash, msgLeafIndex);