Skip to content

Commit

Permalink
EVM: _* methods/properties -> protected
Browse files Browse the repository at this point in the history
  • Loading branch information
holgerd77 committed Jul 4, 2023
1 parent 0a55c87 commit 852c5ce
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 38 deletions.
47 changes: 18 additions & 29 deletions packages/evm/src/evm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export interface EVMOpts {
* @ignore
*/
export class EVM implements EVMInterface {
private static supportedHardforks = [
protected static supportedHardforks = [
Hardfork.Chainstart,
Hardfork.Homestead,
Hardfork.Dao,
Expand All @@ -182,36 +182,25 @@ export class EVM implements EVMInterface {
protected _block?: Block

public readonly common: Common
public readonly events: AsyncEventEmitter<EVMEvents>

public stateManager: EVMStateManagerInterface
public blockchain: Blockchain
public journal: Journal

public readonly _transientStorage: TransientStorage

public readonly events: AsyncEventEmitter<EVMEvents>
public readonly transientStorage: TransientStorage

/**
* This opcode data is always set since `getActiveOpcodes()` is called in the constructor
* @hidden
*/
_opcodes!: OpcodeList
protected _opcodes!: OpcodeList

public readonly _allowUnlimitedContractSize: boolean
public readonly _allowUnlimitedInitCodeSize: boolean
public readonly allowUnlimitedContractSize: boolean
public readonly allowUnlimitedInitCodeSize: boolean

protected readonly _customOpcodes?: CustomOpcode[]
protected readonly _customPrecompiles?: CustomPrecompile[]

/**
* @hidden
*/
_handlers!: Map<number, OpHandler>
protected _handlers!: Map<number, OpHandler>

/**
* @hidden
*/
_dynamicGasHandlers!: Map<number, AsyncDynamicGasHandler | SyncDynamicGasHandler>
protected _dynamicGasHandlers!: Map<number, AsyncDynamicGasHandler | SyncDynamicGasHandler>

protected _precompiles!: Map<string, PrecompileFunc>

Expand Down Expand Up @@ -244,7 +233,7 @@ export class EVM implements EVMInterface {
*/
readonly DEBUG: boolean = false

public readonly _emit: (topic: string, data: any) => Promise<void>
protected readonly _emit: (topic: string, data: any) => Promise<void>

/**
* EVM async constructor. Creates engine instance and initializes it.
Expand All @@ -262,7 +251,7 @@ export class EVM implements EVMInterface {

this._optsCached = opts

this._transientStorage = new TransientStorage()
this.transientStorage = new TransientStorage()

if (opts.common) {
this.common = opts.common
Expand Down Expand Up @@ -300,8 +289,8 @@ export class EVM implements EVMInterface {
)
}

this._allowUnlimitedContractSize = opts.allowUnlimitedContractSize ?? false
this._allowUnlimitedInitCodeSize = opts.allowUnlimitedInitCodeSize ?? false
this.allowUnlimitedContractSize = opts.allowUnlimitedContractSize ?? false
this.allowUnlimitedInitCodeSize = opts.allowUnlimitedInitCodeSize ?? false
this._customOpcodes = opts.customOpcodes
this._customPrecompiles = opts.customPrecompiles

Expand Down Expand Up @@ -455,7 +444,7 @@ export class EVM implements EVMInterface {
if (this.common.isActivatedEIP(3860)) {
if (
message.data.length > Number(this.common.param('vm', 'maxInitCodeSize')) &&
!this._allowUnlimitedInitCodeSize
!this.allowUnlimitedInitCodeSize
) {
return {
createdAddress: message.to,
Expand Down Expand Up @@ -583,7 +572,7 @@ export class EVM implements EVMInterface {

// If enough gas and allowed code size
let CodestoreOOG = false
if (totalGas <= message.gasLimit && (this._allowUnlimitedContractSize || allowedCodeSize)) {
if (totalGas <= message.gasLimit && (this.allowUnlimitedContractSize || allowedCodeSize)) {
if (this.common.isActivatedEIP(3541) && result.returnValue[0] === EOF.FORMAT) {
if (!this.common.isActivatedEIP(3540)) {
result = { ...result, ...INVALID_BYTECODE_RESULT(message.gasLimit) }
Expand Down Expand Up @@ -826,7 +815,7 @@ export class EVM implements EVMInterface {
}

await this.journal.checkpoint()
if (this.common.isActivatedEIP(1153)) this._transientStorage.checkpoint()
if (this.common.isActivatedEIP(1153)) this.transientStorage.checkpoint()
if (this.DEBUG) {
debug('-'.repeat(100))
debug(`message checkpoint`)
Expand Down Expand Up @@ -877,13 +866,13 @@ export class EVM implements EVMInterface {
) {
result.execResult.logs = []
await this.journal.revert()
if (this.common.isActivatedEIP(1153)) this._transientStorage.revert()
if (this.common.isActivatedEIP(1153)) this.transientStorage.revert()
if (this.DEBUG) {
debug(`message checkpoint reverted`)
}
} else {
await this.journal.commit()
if (this.common.isActivatedEIP(1153)) this._transientStorage.commit()
if (this.common.isActivatedEIP(1153)) this.transientStorage.commit()
if (this.DEBUG) {
debug(`message checkpoint committed`)
}
Expand Down Expand Up @@ -1015,7 +1004,7 @@ export class EVM implements EVMInterface {
* Once the interpreter has finished depth 0, a post-message cleanup should be done
*/
private postMessageCleanup() {
if (this.common.isActivatedEIP(1153)) this._transientStorage.clear()
if (this.common.isActivatedEIP(1153)) this.transientStorage.clear()
}

public shallowCopy(): EVMInterface {
Expand Down
14 changes: 7 additions & 7 deletions packages/evm/src/interpreter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ export class Interpreter {
const gasLimitClone = this.getGasLeft()

if (opInfo.dynamicGas) {
const dynamicGasHandler = this._evm._dynamicGasHandlers.get(this._runState.opCode)!
const dynamicGasHandler = (this._evm as any)._dynamicGasHandlers.get(this._runState.opCode)!
// This function updates the gas in-place.
// It needs the base fee, for correct gas limit calculation for the CALL opcodes
gas = await dynamicGasHandler(this._runState, gas, this.common)
Expand Down Expand Up @@ -293,15 +293,15 @@ export class Interpreter {
* Get the handler function for an opcode.
*/
getOpHandler(opInfo: Opcode): OpHandler {
return this._evm._handlers.get(opInfo.code)!
return (this._evm as any)._handlers.get(opInfo.code)!
}

/**
* Get info for an opcode from EVM's list of opcodes.
*/
lookupOpInfo(op: number): Opcode {
// if not found, return 0xfe: INVALID
return this._evm._opcodes.get(op) ?? this._evm._opcodes.get(0xfe)!
return this._evm.opcodes.get(op) ?? this._evm.opcodes.get(0xfe)!
}

async _runStepHook(dynamicFee: bigint, gasLeft: bigint): Promise<void> {
Expand Down Expand Up @@ -374,7 +374,7 @@ export class Interpreter {
* @property {BigInt} memoryWordCount current size of memory in words
* @property {Address} codeAddress the address of the code which is currently being ran (this differs from `address` in a `DELEGATECALL` and `CALLCODE` call)
*/
await this._evm._emit('step', eventObj)
await (this._evm as any)._emit('step', eventObj)
}

// Returns all valid jump and jumpsub destinations.
Expand Down Expand Up @@ -516,7 +516,7 @@ export class Interpreter {
* @param value Storage value
*/
transientStorageStore(key: Uint8Array, value: Uint8Array): void {
return this._evm._transientStorage.put(this._env.address, key, value)
return this._evm.transientStorage.put(this._env.address, key, value)
}

/**
Expand All @@ -525,7 +525,7 @@ export class Interpreter {
* @param key Storage key
*/
transientStorageLoad(key: Uint8Array): Uint8Array {
return this._evm._transientStorage.get(this._env.address, key)
return this._evm.transientStorage.get(this._env.address, key)
}

/**
Expand Down Expand Up @@ -939,7 +939,7 @@ export class Interpreter {
if (this.common.isActivatedEIP(3860)) {
if (
data.length > Number(this.common.param('vm', 'maxInitCodeSize')) &&
this._evm._allowUnlimitedInitCodeSize === false
this._evm.allowUnlimitedInitCodeSize === false
) {
return BigInt(0)
}
Expand Down
4 changes: 2 additions & 2 deletions packages/evm/src/opcodes/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -930,7 +930,7 @@ export const handlers: Map<number, OpHandler> = new Map([
if (
common.isActivatedEIP(3860) &&
length > Number(common.param('vm', 'maxInitCodeSize')) &&
!runState.interpreter._evm._allowUnlimitedInitCodeSize
!runState.interpreter._evm.allowUnlimitedInitCodeSize
) {
trap(ERROR.INITCODE_SIZE_VIOLATION)
}
Expand Down Expand Up @@ -960,7 +960,7 @@ export const handlers: Map<number, OpHandler> = new Map([
if (
common.isActivatedEIP(3860) &&
length > Number(common.param('vm', 'maxInitCodeSize')) &&
!runState.interpreter._evm._allowUnlimitedInitCodeSize
!runState.interpreter._evm.allowUnlimitedInitCodeSize
) {
trap(ERROR.INITCODE_SIZE_VIOLATION)
}
Expand Down

0 comments on commit 852c5ce

Please sign in to comment.