-
Notifications
You must be signed in to change notification settings - Fork 237
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(avm): introduce small e2e test (#4470)
- Loading branch information
Showing
13 changed files
with
233 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { DebugLogger, Fr, Wallet } from '@aztec/aztec.js'; | ||
import { AvmTestContract } from '@aztec/noir-contracts'; | ||
|
||
import { setup } from './fixtures/utils.js'; | ||
|
||
process.env.AVM_ENABLED = 'absofrigginlutely'; | ||
|
||
describe('e2e_nested_contract', () => { | ||
let wallet: Wallet; | ||
let logger: DebugLogger; | ||
let teardown: () => Promise<void>; | ||
|
||
beforeEach(async () => { | ||
({ teardown, wallet, logger } = await setup()); | ||
}, 100_000); | ||
|
||
afterEach(() => teardown()); | ||
|
||
describe('Call succeeds through AVM', () => { | ||
let avmContact: AvmTestContract; | ||
|
||
beforeEach(async () => { | ||
avmContact = await AvmTestContract.deploy(wallet).send().deployed(); | ||
}, 50_000); | ||
|
||
it('Calls an avm contract', async () => { | ||
const a = new Fr(1); | ||
const b = new Fr(2); | ||
|
||
logger('Calling avm_addArgsReturn...'); | ||
await avmContact.methods.avm_addArgsReturn(a, b).send().wait(); | ||
logger('Success'); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
yarn-project/simulator/src/avm/temporary_executor_migration.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
// All code in this file needs to die once the public executor is phased out. | ||
import { FunctionL2Logs } from '@aztec/circuit-types'; | ||
import { | ||
ContractStorageRead, | ||
ContractStorageUpdateRequest, | ||
GlobalVariables, | ||
SideEffect, | ||
SideEffectLinkedToNoteHash, | ||
} from '@aztec/circuits.js'; | ||
import { Fr } from '@aztec/foundation/fields'; | ||
|
||
import { PublicExecution, PublicExecutionResult } from '../public/execution.js'; | ||
import { AvmExecutionEnvironment } from './avm_execution_environment.js'; | ||
import { AvmContractCallResults } from './avm_message_call_result.js'; | ||
import { JournalData } from './journal/journal.js'; | ||
|
||
/** Temporary Method | ||
* | ||
* Convert a PublicExecution(Environment) object to an AvmExecutionEnvironment | ||
* | ||
* @param current | ||
* @param globalVariables | ||
* @returns | ||
*/ | ||
export function temporaryCreateAvmExecutionEnvironment( | ||
current: PublicExecution, | ||
globalVariables: GlobalVariables, | ||
): AvmExecutionEnvironment { | ||
// Function selector is included temporarily until noir codegens public contract bytecode in a single blob | ||
return new AvmExecutionEnvironment( | ||
current.contractAddress, | ||
current.callContext.storageContractAddress, | ||
current.callContext.msgSender, // TODO: origin is not available | ||
current.callContext.msgSender, | ||
current.callContext.portalContractAddress, | ||
/*feePerL1Gas=*/ Fr.zero(), | ||
/*feePerL2Gas=*/ Fr.zero(), | ||
/*feePerDaGas=*/ Fr.zero(), | ||
/*contractCallDepth=*/ Fr.zero(), | ||
globalVariables, | ||
current.callContext.isStaticCall, | ||
current.callContext.isDelegateCall, | ||
current.args, | ||
current.functionData.selector, | ||
); | ||
} | ||
|
||
/** Temporary Method | ||
* | ||
* Convert the result of an AVM contract call to a PublicExecutionResult for the public kernel | ||
* | ||
* @param execution | ||
* @param newWorldState | ||
* @param result | ||
* @returns | ||
*/ | ||
export function temporaryConvertAvmResults( | ||
execution: PublicExecution, | ||
newWorldState: JournalData, | ||
result: AvmContractCallResults, | ||
): PublicExecutionResult { | ||
const newCommitments = newWorldState.newNoteHashes.map(noteHash => new SideEffect(noteHash, Fr.zero())); | ||
|
||
const contractStorageReads: ContractStorageRead[] = []; | ||
const reduceStorageReadRequests = (contractAddress: bigint, storageReads: Map<bigint, Fr[]>) => { | ||
return storageReads.forEach((innerArray, key) => { | ||
innerArray.forEach(value => { | ||
contractStorageReads.push(new ContractStorageRead(new Fr(key), new Fr(value), 0)); | ||
}); | ||
}); | ||
}; | ||
newWorldState.storageReads.forEach((storageMap: Map<bigint, Fr[]>, address: bigint) => | ||
reduceStorageReadRequests(address, storageMap), | ||
); | ||
|
||
const contractStorageUpdateRequests: ContractStorageUpdateRequest[] = []; | ||
const reduceStorageUpdateRequests = (contractAddress: bigint, storageUpdateRequests: Map<bigint, Fr[]>) => { | ||
return storageUpdateRequests.forEach((innerArray, key) => { | ||
innerArray.forEach(value => { | ||
contractStorageUpdateRequests.push( | ||
new ContractStorageUpdateRequest(new Fr(key), /*TODO: old value not supported */ Fr.zero(), new Fr(value), 0), | ||
); | ||
}); | ||
}); | ||
}; | ||
newWorldState.storageWrites.forEach((storageMap: Map<bigint, Fr[]>, address: bigint) => | ||
reduceStorageUpdateRequests(address, storageMap), | ||
); | ||
|
||
const returnValues = result.output; | ||
|
||
// TODO(follow up in pr tree): NOT SUPPORTED YET, make sure hashing and log resolution is done correctly | ||
// Disabled. | ||
const nestedExecutions: PublicExecutionResult[] = []; | ||
const newNullifiers: SideEffectLinkedToNoteHash[] = []; | ||
const unencryptedLogs = FunctionL2Logs.empty(); | ||
const newL2ToL1Messages = newWorldState.newL1Messages.map(() => Fr.zero()); | ||
|
||
return { | ||
execution, | ||
newCommitments, | ||
newL2ToL1Messages, | ||
newNullifiers, | ||
contractStorageReads, | ||
contractStorageUpdateRequests, | ||
returnValues, | ||
nestedExecutions, | ||
unencryptedLogs, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters