From 34282ec4be1bbe48f9896e63a9ae30e62967b661 Mon Sep 17 00:00:00 2001 From: fcarreiro Date: Fri, 10 May 2024 12:04:55 +0000 Subject: [PATCH 1/2] fix(avm-simulator): fix message sender --- .../src/avm/avm_execution_environment.test.ts | 12 ++- .../src/avm/avm_execution_environment.ts | 76 +++++++++---------- 2 files changed, 43 insertions(+), 45 deletions(-) diff --git a/yarn-project/simulator/src/avm/avm_execution_environment.test.ts b/yarn-project/simulator/src/avm/avm_execution_environment.test.ts index 6aad1e2ea259..7a45a5beb042 100644 --- a/yarn-project/simulator/src/avm/avm_execution_environment.test.ts +++ b/yarn-project/simulator/src/avm/avm_execution_environment.test.ts @@ -1,3 +1,4 @@ +import { FunctionSelector } from '@aztec/circuits.js'; import { Fr } from '@aztec/foundation/fields'; import { allSameExcept, anyAvmContextInputs, initExecutionEnvironment } from './fixtures/index.js'; @@ -5,10 +6,11 @@ import { allSameExcept, anyAvmContextInputs, initExecutionEnvironment } from './ 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, { @@ -22,7 +24,7 @@ describe('Execution Environment', () => { it('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, { @@ -36,7 +38,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, { diff --git a/yarn-project/simulator/src/avm/avm_execution_environment.ts b/yarn-project/simulator/src/avm/avm_execution_environment.ts index 4a38171103d1..e57f94eecda0 100644 --- a/yarn-project/simulator/src/avm/avm_execution_environment.ts +++ b/yarn-project/simulator/src/avm/avm_execution_environment.ts @@ -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!'); + } } From 91e56868bb91852a195b1a7f3a74b4b03c82f009 Mon Sep 17 00:00:00 2001 From: fcarreiro Date: Fri, 10 May 2024 15:16:21 +0000 Subject: [PATCH 2/2] disable delegate call test --- .../simulator/src/avm/avm_execution_environment.test.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/yarn-project/simulator/src/avm/avm_execution_environment.test.ts b/yarn-project/simulator/src/avm/avm_execution_environment.test.ts index 7a45a5beb042..68bde3962fb5 100644 --- a/yarn-project/simulator/src/avm/avm_execution_environment.test.ts +++ b/yarn-project/simulator/src/avm/avm_execution_environment.test.ts @@ -22,7 +22,8 @@ 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, selector);