Skip to content

Commit

Permalink
fix: upstream rebase fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Maddiaa0 committed Jan 24, 2024
1 parent 9ec7ef2 commit 8307837
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 25 deletions.
6 changes: 4 additions & 2 deletions yarn-project/acir-simulator/src/avm/avm_context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,11 @@ export class AvmContext {
*/
public static prepExternalCall(
address: AztecAddress,
calldata: Fr[],
executionEnvironment: AvmExecutionEnvironment,
journal: AvmJournal,
): AvmContext {
const newExecutionEnvironment = executionEnvironment.newCall(address);
const newExecutionEnvironment = executionEnvironment.newCall(address, calldata);
const forkedState = AvmJournal.branchParent(journal);
return new AvmContext(newExecutionEnvironment, forkedState);
}
Expand All @@ -105,10 +106,11 @@ export class AvmContext {
*/
public static prepExternalStaticCall(
address: AztecAddress,
calldata: Fr[],
executionEnvironment: AvmExecutionEnvironment,
journal: AvmJournal,
): AvmContext {
const newExecutionEnvironment = executionEnvironment.newStaticCall(address);
const newExecutionEnvironment = executionEnvironment.newStaticCall(address, calldata);
const forkedState = AvmJournal.branchParent(journal);
return new AvmContext(newExecutionEnvironment, forkedState);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,40 @@ import { Fr } from '@aztec/foundation/fields';
import { initExecutionEnvironment } from './fixtures/index.js';

describe('Execution Environment', () => {
it('New call should fork execution environment correctly', () => {
const newAddress = new Fr(123456n);
const newAddress = new Fr(123456n);
const calldata = [new Fr(1n), new Fr(2n), new Fr(3n)];

it('New call should fork execution environment correctly', () => {
const executionEnvironment = initExecutionEnvironment();
const newExecutionEnvironment = executionEnvironment.newCall(newAddress);
const newExecutionEnvironment = executionEnvironment.newCall(newAddress, calldata);

allTheSameExcept(executionEnvironment, newExecutionEnvironment, {
address: newAddress,
storageAddress: newAddress,
calldata
});
});

it('New delegate call should fork execution environment correctly', () => {
const newAddress = new Fr(123456n);

const executionEnvironment = initExecutionEnvironment();
const newExecutionEnvironment = executionEnvironment.newDelegateCall(newAddress);
const newExecutionEnvironment = executionEnvironment.newDelegateCall(newAddress, calldata);

allTheSameExcept(executionEnvironment, newExecutionEnvironment, {
address: newAddress,
isDelegateCall: true,
calldata
});
});

it('New static call call should fork execution environment correctly', () => {
const newAddress = new Fr(123456n);

const executionEnvironment = initExecutionEnvironment();
const newExecutionEnvironment = executionEnvironment.newStaticCall(newAddress);
const newExecutionEnvironment = executionEnvironment.newStaticCall(newAddress, calldata);

allTheSameExcept(executionEnvironment, newExecutionEnvironment, {
address: newAddress,
storageAddress: newAddress,
isStaticCall: true,
calldata
});
});
});
Expand Down
12 changes: 6 additions & 6 deletions yarn-project/acir-simulator/src/avm/avm_execution_environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class AvmExecutionEnvironment {
public readonly calldata: Fr[],
) {}

public newCall(address: AztecAddress): AvmExecutionEnvironment {
public newCall(address: AztecAddress, calldata: Fr[]): AvmExecutionEnvironment {
return new AvmExecutionEnvironment(
address,
address,
Expand All @@ -52,11 +52,11 @@ export class AvmExecutionEnvironment {
this.globals,
this.isStaticCall,
this.isDelegateCall,
this.calldata,
calldata,
);
}

public newStaticCall(address: AztecAddress): AvmExecutionEnvironment {
public newStaticCall(address: AztecAddress, calldata: Fr[]): AvmExecutionEnvironment {
return new AvmExecutionEnvironment(
address,
address,
Expand All @@ -70,11 +70,11 @@ export class AvmExecutionEnvironment {
this.globals,
true,
this.isDelegateCall,
this.calldata,
calldata,
);
}

public newDelegateCall(address: AztecAddress): AvmExecutionEnvironment {
public newDelegateCall(address: AztecAddress, calldata: Fr[]): AvmExecutionEnvironment {
return new AvmExecutionEnvironment(
address,
this.storageAddress,
Expand All @@ -88,7 +88,7 @@ export class AvmExecutionEnvironment {
this.globals,
this.isStaticCall,
true,
this.calldata,
calldata,
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('External Calls', () => {
let contractsDb: MockProxy<PublicContractsDB>;

beforeEach(() => {
machineState = new AvmMachineState([], initExecutionEnvironment());
machineState = new AvmMachineState(initExecutionEnvironment());

contractsDb = mock<PublicContractsDB>();

Expand Down
16 changes: 10 additions & 6 deletions yarn-project/acir-simulator/src/avm/opcodes/external_calls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ export class Call extends Instruction {
const callAddress = machineState.readMemory(this.addrOffset);
const calldata = machineState.readMemoryChunk(this.argsOffset, this.argSize);

const avmContext = AvmContext.prepExternalCall(callAddress, machineState.executionEnvironment, journal);
const avmContext = AvmContext.prepExternalCall(callAddress, calldata, machineState.executionEnvironment, journal);

const returnObject = await avmContext.call(calldata);
const returnObject = await avmContext.call();
const success = !returnObject.reverted;

// We only take as much data as was specified in the return size -> TODO: should we be reverting here
Expand All @@ -38,7 +38,9 @@ export class Call extends Instruction {
machineState.writeMemory(this.successOffset, new Fr(success));
machineState.writeMemoryChunk(this.retOffset, returnData);

avmContext.mergeJournal();
if (success) {
avmContext.mergeJournal();
}

this.incrementPc(machineState);
}
Expand All @@ -64,9 +66,9 @@ export class StaticCall extends Instruction {
const callAddress = machineState.readMemory(this.addrOffset);
const calldata = machineState.readMemoryChunk(this.argsOffset, this.argSize);

const avmContext = AvmContext.prepExternalStaticCall(callAddress, machineState.executionEnvironment, journal);
const avmContext = AvmContext.prepExternalStaticCall(callAddress, calldata, machineState.executionEnvironment, journal);

const returnObject = await avmContext.call(calldata);
const returnObject = await avmContext.call();
const success = !returnObject.reverted;

// We only take as much data as was specified in the return size -> TODO: should we be reverting here
Expand All @@ -76,7 +78,9 @@ export class StaticCall extends Instruction {
machineState.writeMemory(this.successOffset, new Fr(success));
machineState.writeMemoryChunk(this.retOffset, returnData);

avmContext.mergeJournal();
if (success) {
avmContext.mergeJournal();
}

this.incrementPc(machineState);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('Storage Instructions', () => {

it('Should not be able to write to storage in a static call', () => {
const executionEnvironment = initExecutionEnvironment({ isStaticCall: true });
machineState = new AvmMachineState([], executionEnvironment);
machineState = new AvmMachineState(executionEnvironment);

const a = new Fr(1n);
const b = new Fr(2n);
Expand Down

0 comments on commit 8307837

Please sign in to comment.