-
Notifications
You must be signed in to change notification settings - Fork 234
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
160 additions
and
115 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
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 was deleted.
Oops, something went wrong.
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 temporaryMapToExecutionEnvironment( | ||
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 temporaryMapAvmReturnTypes( | ||
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
Oops, something went wrong.