Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions yarn-project/simulator/src/avm/avm_execution_environment.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { FunctionSelector } from '@aztec/circuits.js';
import { Fr } from '@aztec/foundation/fields';

import { allSameExcept, anyAvmContextInputs, initExecutionEnvironment } from './fixtures/index.js';

describe('Execution Environment', () => {
const newAddress = new Fr(123456n);
const calldata = [new Fr(1n), new Fr(2n), new Fr(3n)];
const selector = FunctionSelector.empty();

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

expect(newExecutionEnvironment).toEqual(
allSameExcept(executionEnvironment, {
Expand All @@ -20,9 +22,10 @@ describe('Execution Environment', () => {
);
});

it('New delegate call should fork execution environment correctly', () => {
// Delegate calls not supported.
it.skip('New delegate call should fork execution environment correctly', () => {
const executionEnvironment = initExecutionEnvironment();
const newExecutionEnvironment = executionEnvironment.newDelegateCall(newAddress, calldata);
const newExecutionEnvironment = executionEnvironment.newDelegateCall(newAddress, calldata, selector);

expect(newExecutionEnvironment).toEqual(
allSameExcept(executionEnvironment, {
Expand All @@ -36,7 +39,11 @@ describe('Execution Environment', () => {

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

expect(newExecutionEnvironment).toEqual(
allSameExcept(executionEnvironment, {
Expand Down
76 changes: 34 additions & 42 deletions yarn-project/simulator/src/avm/avm_execution_environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,72 +45,64 @@ export class AvmExecutionEnvironment {
this.calldata = [...inputs.toFields(), ...calldata];
}

public deriveEnvironmentForNestedCall(
private deriveEnvironmentForNestedCallInternal(
targetAddress: AztecAddress,
calldata: Fr[],
temporaryFunctionSelector: FunctionSelector = FunctionSelector.empty(),
): AvmExecutionEnvironment {
functionSelector: FunctionSelector,
isStaticCall: boolean,
isDelegateCall: boolean,
) {
return new AvmExecutionEnvironment(
targetAddress,
/*address=*/ targetAddress,
/*storageAddress=*/ targetAddress,
this.address,
/*sender=*/ this.address,
this.feePerL2Gas,
this.feePerDaGas,
this.contractCallDepth,
this.header,
this.globals,
this.isStaticCall,
this.isDelegateCall,
isStaticCall,
isDelegateCall,
calldata,
this.gasSettings,
this.transactionFee,
temporaryFunctionSelector,
functionSelector,
);
}

public deriveEnvironmentForNestedStaticCall(
address: AztecAddress,
public deriveEnvironmentForNestedCall(
targetAddress: AztecAddress,
calldata: Fr[],
temporaryFunctionSelector: FunctionSelector = FunctionSelector.empty(),
functionSelector: FunctionSelector = FunctionSelector.empty(),
): AvmExecutionEnvironment {
return new AvmExecutionEnvironment(
address,
/*storageAddress=*/ address,
this.sender,
this.feePerL2Gas,
this.feePerDaGas,
this.contractCallDepth,
this.header,
this.globals,
/*isStaticCall=*/ true,
this.isDelegateCall,
return this.deriveEnvironmentForNestedCallInternal(
targetAddress,
calldata,
this.gasSettings,
this.transactionFee,
temporaryFunctionSelector,
functionSelector,
/*isStaticCall=*/ false,
/*isDelegateCall=*/ false,
);
}

public newDelegateCall(
address: AztecAddress,
public deriveEnvironmentForNestedStaticCall(
targetAddress: AztecAddress,
calldata: Fr[],
temporaryFunctionSelector: FunctionSelector = FunctionSelector.empty(),
functionSelector: FunctionSelector,
): AvmExecutionEnvironment {
return new AvmExecutionEnvironment(
address,
this.storageAddress,
this.sender,
this.feePerL2Gas,
this.feePerDaGas,
this.contractCallDepth,
this.header,
this.globals,
this.isStaticCall,
/*isDelegateCall=*/ true,
return this.deriveEnvironmentForNestedCallInternal(
targetAddress,
calldata,
this.gasSettings,
this.transactionFee,
temporaryFunctionSelector,
functionSelector,
/*isStaticCall=*/ true,
/*isDelegateCall=*/ false,
);
}

public newDelegateCall(
_targetAddress: AztecAddress,
_calldata: Fr[],
_functionSelector: FunctionSelector,
): AvmExecutionEnvironment {
throw new Error('Delegate calls not supported!');
}
}