Skip to content

Commit

Permalink
chore: add l2 contract address to public side effect tracing for l2to…
Browse files Browse the repository at this point in the history
…l1messages
  • Loading branch information
dbanks12 committed Oct 1, 2024
1 parent b49bd6b commit 2f94f0c
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion yarn-project/simulator/src/avm/journal/journal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ describe('journal', () => {

it('Should maintain l1 messages', () => {
const recipient = new Fr(1);
persistableState.writeL2ToL1Message(recipient, utxo);
persistableState.writeL2ToL1Message(address, recipient, utxo);
expect(trace.traceNewL2ToL1Message).toHaveBeenCalledTimes(1);
expect(trace.traceNewL2ToL1Message).toHaveBeenCalledWith(recipient, utxo);
});
Expand Down
7 changes: 4 additions & 3 deletions yarn-project/simulator/src/avm/journal/journal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,13 @@ export class AvmPersistableStateManager {

/**
* Write an L2 to L1 message.
* @param contractAddress - L2 contract address that created this message
* @param recipient - L1 contract address to send the message to.
* @param content - Message content.
*/
public writeL2ToL1Message(recipient: Fr, content: Fr) {
this.log.debug(`L1Messages(${recipient}) += ${content}.`);
this.trace.traceNewL2ToL1Message(recipient, content);
public writeL2ToL1Message(contractAddress: Fr, recipient: Fr, content: Fr) {
this.log.debug(`L2ToL1Messages(${contractAddress}) += (recipient: ${recipient}, content: ${content}).`);
this.trace.traceNewL2ToL1Message(contractAddress, recipient, content);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/simulator/src/avm/opcodes/accrued_substate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ export class SendL2ToL1Message extends Instruction {

const recipient = memory.get(recipientOffset).toFr();
const content = memory.get(contentOffset).toFr();
context.persistableState.writeL2ToL1Message(recipient, content);
context.persistableState.writeL2ToL1Message(context.environment.address, recipient, content);

memory.assert({ reads: 2, addressing });
context.machineState.incrementPc();
Expand Down
8 changes: 4 additions & 4 deletions yarn-project/simulator/src/public/side_effect_trace.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ describe('Side Effect Trace', () => {
});

it('Should trace new L2ToL1 messages', () => {
trace.traceNewL2ToL1Message(recipient, content);
trace.traceNewL2ToL1Message(address, recipient, content);
expect(trace.getCounter()).toBe(startCounterPlus1);

const pxResult = toPxResult(trace);
Expand Down Expand Up @@ -320,9 +320,9 @@ describe('Side Effect Trace', () => {

it('Should enforce maximum number of new l2 to l1 messagse', () => {
for (let i = 0; i < MAX_L2_TO_L1_MSGS_PER_TX; i++) {
trace.traceNewL2ToL1Message(new Fr(i), new Fr(i));
trace.traceNewL2ToL1Message(new Fr(i), new Fr(i), new Fr(i));
}
expect(() => trace.traceNewL2ToL1Message(new Fr(42), new Fr(42))).toThrow(SideEffectLimitReachedError);
expect(() => trace.traceNewL2ToL1Message(new Fr(42), new Fr(42), new Fr(42))).toThrow(SideEffectLimitReachedError);
});

it('Should enforce maximum number of new logs hashes', () => {
Expand Down Expand Up @@ -381,7 +381,7 @@ describe('Side Effect Trace', () => {
testCounter++;
nestedTrace.traceL1ToL2MessageCheck(address, utxo, leafIndex, existsDefault);
testCounter++;
nestedTrace.traceNewL2ToL1Message(recipient, content);
nestedTrace.traceNewL2ToL1Message(address, recipient, content);
testCounter++;
nestedTrace.traceUnencryptedLog(address, log);
testCounter++;
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/simulator/src/public/side_effect_trace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ export class PublicSideEffectTrace implements PublicSideEffectTraceInterface {
this.incrementSideEffectCounter();
}

public traceNewL2ToL1Message(recipient: Fr, content: Fr) {
public traceNewL2ToL1Message(_contractAddress: Fr, recipient: Fr, content: Fr) {
if (this.newL2ToL1Messages.length >= MAX_L2_TO_L1_MSGS_PER_TX) {
throw new SideEffectLimitReachedError("l2 to l1 message", MAX_L2_TO_L1_MSGS_PER_TX);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ export interface PublicSideEffectTraceInterface {
traceNullifierCheck(storageAddress: Fr, nullifier: Fr, leafIndex: Fr, exists: boolean, isPending: boolean): void;
traceNewNullifier(storageAddress: Fr, nullifier: Fr): void;
traceL1ToL2MessageCheck(contractAddress: Fr, msgHash: Fr, msgLeafIndex: Fr, exists: boolean): void;
// TODO(dbanks12): should new message accept contract address as arg?
traceNewL2ToL1Message(recipient: Fr, content: Fr): void;
traceNewL2ToL1Message(contractAddress: Fr, recipient: Fr, content: Fr): void;
traceUnencryptedLog(contractAddress: Fr, log: Fr[]): void;
// TODO(dbanks12): odd that getContractInstance is a one-off in that it accepts an entire object instead of components
traceGetContractInstance(instance: TracedContractInstance): void;
Expand Down

0 comments on commit 2f94f0c

Please sign in to comment.