-
Notifications
You must be signed in to change notification settings - Fork 305
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
6 changed files
with
124 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
54 changes: 54 additions & 0 deletions
54
yarn-project/acir-simulator/src/avm/avm_execution_environment.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,54 @@ | ||
import { AztecAddress } from "@aztec/foundation/aztec-address"; | ||
import { EthAddress } from "@aztec/foundation/eth-address"; | ||
import { Fr } from "@aztec/foundation/fields"; | ||
|
||
/** - */ | ||
export class ExecutionEnvironment { | ||
constructor( | ||
/** - */ | ||
public readonly address: AztecAddress, | ||
/** - */ | ||
public readonly storageAddress: AztecAddress, | ||
/** - */ | ||
public readonly origin: AztecAddress, | ||
/** - */ | ||
public readonly sender: AztecAddress, | ||
/** - */ | ||
public readonly portal: EthAddress, | ||
/** - */ | ||
public readonly feePerL1Gas: Fr, | ||
/** - */ | ||
public readonly feePerL2Gas: Fr, | ||
/** - */ | ||
public readonly feePerDaGas: Fr, | ||
/** - */ | ||
public readonly contractCallDepth: Fr, | ||
/** - */ | ||
// globals: TODO: | ||
/** - */ | ||
public readonly isStaticCall: boolean, | ||
/** - */ | ||
public readonly isDelegateCall: boolean, | ||
/** - */ | ||
public readonly calldata: Fr[], | ||
|
||
) {} | ||
|
||
static empty(): ExecutionEnvironment { | ||
return new ExecutionEnvironment( | ||
AztecAddress.zero(), | ||
AztecAddress.zero(), | ||
AztecAddress.zero(), | ||
AztecAddress.zero(), | ||
EthAddress.ZERO, | ||
Fr.zero(), | ||
Fr.zero(), | ||
Fr.zero(), | ||
Fr.zero(), | ||
false, | ||
false, | ||
[], | ||
); | ||
} | ||
|
||
} |
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,44 @@ | ||
import { AvmMachineState } from "../avm_machine_state.js"; | ||
import { AvmStateManager } from "../avm_state_manager.js"; | ||
import { Instruction } from "./instruction.js"; | ||
|
||
/** - */ | ||
export class SStore extends Instruction { | ||
static type: string = "SSTORE"; | ||
static numberOfOperands = 2; | ||
|
||
|
||
constructor(private slotOffset: number, private dataOffset: number) { | ||
super(); | ||
} | ||
|
||
execute(machineState: AvmMachineState, stateManager: AvmStateManager): void { | ||
const slot = machineState.readMemory(this.slotOffset); | ||
const data = machineState.readMemory(this.dataOffset); | ||
|
||
stateManager.store(machineState.executionEnvironment.storageAddress, slot, data) | ||
|
||
this.incrementPc(machineState); | ||
} | ||
} | ||
|
||
/** - */ | ||
export class SLoad extends Instruction { | ||
static type: string = "SLOAD"; | ||
static numberOfOperands = 2; | ||
|
||
|
||
constructor(private slotOffset: number, private destOffset: number) { | ||
super(); | ||
} | ||
|
||
async execute(machineState: AvmMachineState, stateManager: AvmStateManager): Promise<void> { | ||
const slot = machineState.readMemory(this.slotOffset); | ||
|
||
const data = stateManager.read(machineState.executionEnvironment.storageAddress, slot); | ||
|
||
machineState.writeMemory(this.destOffset, await data) | ||
|
||
this.incrementPc(machineState); | ||
} | ||
} |
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