Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@nomicfoundation/ethereumjs-evm

Package Overview
Dependencies
Maintainers
2
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nomicfoundation/ethereumjs-evm - npm Package Compare versions

Comparing version 1.0.0-rc.1 to 1.0.0-rc.2

75

dist/evm.js

@@ -7,3 +7,2 @@ "use strict";

const AsyncEventEmitter = require("async-eventemitter");
const debug_1 = require("debug");
const util_1 = require("util");

@@ -17,4 +16,2 @@ const eof_1 = require("./eof");

const transientStorage_1 = require("./transientStorage");
const debug = (0, debug_1.debug)('evm');
const debugGas = (0, debug_1.debug)('evm:gas');
// very ugly way to detect if we are running in a browser

@@ -187,11 +184,5 @@ const isBrowser = new Function('try {return this===window;}catch(e){ return false;}');

exit = true;
if (this.DEBUG) {
debug(`Exit early on no code`);
}
}
if ((0, ethereumjs_util_1.isTruthy)(errorMessage)) {
exit = true;
if (this.DEBUG) {
debug(`Exit early on value transfer overflowed`);
}
}

@@ -210,5 +201,2 @@ if (exit) {

if (message.isCompiled) {
if (this.DEBUG) {
debug(`Run precompile`);
}
result = await this.runPrecompile(message.code, message.data, message.gasLimit);

@@ -218,5 +206,2 @@ result.gasRefund = message.gasRefund;

else {
if (this.DEBUG) {
debug(`Start bytecode processing...`);
}
result = await this.runInterpreter(message);

@@ -250,5 +235,2 @@ }

message.to = await this._generateAddress(message);
if (this.DEBUG) {
debug(`Generated CREATE contract address ${message.to}`);
}
let toAccount = await this.eei.getAccount(message.to);

@@ -258,5 +240,2 @@ // Check for collision

!toAccount.codeHash.equals(ethereumjs_util_1.KECCAK256_NULL)) {
if (this.DEBUG) {
debug(`Returning on address collision`);
}
return {

@@ -293,11 +272,5 @@ createdAddress: message.to,

exit = true;
if (this.DEBUG) {
debug(`Exit early on no code`);
}
}
if ((0, ethereumjs_util_1.isTruthy)(errorMessage)) {
exit = true;
if (this.DEBUG) {
debug(`Exit early on value transfer overflowed`);
}
}

@@ -315,5 +288,2 @@ if (exit) {

}
if (this.DEBUG) {
debug(`Start bytecode processing...`);
}
let result = await this.runInterpreter(message);

@@ -327,5 +297,2 @@ // fee for size of the return value

totalGas = totalGas + returnFee;
if (this.DEBUG) {
debugGas(`Add return value size fee (${returnFee} to gas used (-> ${totalGas}))`);
}
}

@@ -378,5 +345,2 @@ // Check for SpuriousDragon EIP-170 code size limit

if (this._common.gteHardfork(ethereumjs_common_1.Hardfork.Homestead)) {
if (this.DEBUG) {
debug(`Not enough gas or code size not allowed (>= Homestead)`);
}
result = { ...result, ...OOGResult(message.gasLimit) };

@@ -386,5 +350,2 @@ }

// we are in Frontier
if (this.DEBUG) {
debug(`Not enough gas or code size not allowed (Frontier)`);
}
if (totalGas - returnFee <= message.gasLimit) {

@@ -405,5 +366,2 @@ // we cannot pay the code deposit fee (but the deposit code actually did run)

await this.eei.putContractCode(message.to, result.returnValue);
if (this.DEBUG) {
debug(`Code saved on new contract creation`);
}
}

@@ -525,27 +483,9 @@ else if (CodestoreOOG) {

this._transientStorage.checkpoint();
if (this.DEBUG) {
debug('-'.repeat(100));
debug(`message checkpoint`);
}
let result;
if (this.DEBUG) {
const { caller, gasLimit, to, value, delegatecall } = message;
debug(`New message caller=${caller} gasLimit=${gasLimit} to=${to?.toString() ?? 'none'} value=${value} delegatecall=${delegatecall ? 'yes' : 'no'}`);
}
if (message.to) {
if (this.DEBUG) {
debug(`Message CALL execution (to: ${message.to})`);
}
result = await this._executeCall(message);
}
else {
if (this.DEBUG) {
debug(`Message CREATE execution (to undefined)`);
}
result = await this._executeCreate(message);
}
if (this.DEBUG) {
const { executionGasUsed, exceptionError, returnValue } = result.execResult;
debug(`Received message execResult: [ gasUsed=${executionGasUsed} exceptionError=${exceptionError ? `'${exceptionError.error}'` : 'none'} returnValue=0x${(0, ethereumjs_util_1.short)(returnValue)} gasRefund=${result.execResult.gasRefund ?? 0} ]`);
}
const err = result.execResult.exceptionError;

@@ -564,5 +504,2 @@ // This clause captures any error which happened during execution

this._transientStorage.revert();
if (this.DEBUG) {
debug(`message checkpoint reverted`);
}
}

@@ -574,5 +511,2 @@ else {

this._transientStorage.commit();
if (this.DEBUG) {
debug(`message checkpoint committed`);
}
}

@@ -583,5 +517,2 @@ }

this._transientStorage.commit();
if (this.DEBUG) {
debug(`message checkpoint committed`);
}
}

@@ -670,5 +601,2 @@ await this._emit('afterMessage', result);

const result = this.eei.putAccount(message.authcallOrigin ?? message.caller, account);
if (this.DEBUG) {
debug(`Reduced sender (${message.caller}) balance (-> ${account.balance})`);
}
return result;

@@ -684,5 +612,2 @@ }

const result = this.eei.putAccount(message.to, toAccount);
if (this.DEBUG) {
debug(`Added toAccount (${message.to}) balance (-> ${toAccount.balance})`);
}
return result;

@@ -689,0 +614,0 @@ }

6

dist/interpreter.d.ts

@@ -124,3 +124,3 @@ /// <reference types="node" />

*/
useGas(amount: bigint, context?: string): void;
useGas(amount: bigint, _context?: string): void;
/**

@@ -131,3 +131,3 @@ * Adds a positive amount to the gas counter.

*/
refundGas(amount: bigint, context?: string): void;
refundGas(amount: bigint, _context?: string): void;
/**

@@ -138,3 +138,3 @@ * Reduces amount of gas to be refunded by a positive value.

*/
subRefund(amount: bigint, context?: string): void;
subRefund(amount: bigint, _context?: string): void;
/**

@@ -141,0 +141,0 @@ * Increments the internal gasLeft counter. Used for adding callStipend.

@@ -6,3 +6,2 @@ "use strict";

const ethereumjs_util_1 = require("@nomicfoundation/ethereumjs-util");
const debug_1 = require("debug");
const eof_1 = require("./eof");

@@ -14,3 +13,2 @@ const exceptions_1 = require("./exceptions");

const stack_1 = require("./stack");
const debugGas = (0, debug_1.debug)('evm:eei:gas');
/**

@@ -202,22 +200,2 @@ * Parses and executes EVM bytecode.

};
if (this._evm.DEBUG) {
// Create opTrace for debug functionality
let hexStack = [];
hexStack = eventObj.stack.map((item) => {
return (0, ethereumjs_util_1.bigIntToHex)(BigInt(item));
});
const name = eventObj.opcode.name;
const opTrace = {
pc: eventObj.pc,
op: name,
gas: (0, ethereumjs_util_1.bigIntToHex)(eventObj.gasLeft),
gasCost: (0, ethereumjs_util_1.intToHex)(eventObj.opcode.fee),
stack: hexStack,
depth: eventObj.depth,
};
if (!(name in this.opDebuggers)) {
this.opDebuggers[name] = (0, debug_1.debug)(`evm:ops:${name}`);
}
this.opDebuggers[name](JSON.stringify(opTrace));
}
/**

@@ -279,7 +257,4 @@ * The `step` event for trace output

*/
useGas(amount, context) {
useGas(amount, _context) {
this._runState.gasLeft -= amount;
if (this._evm.DEBUG) {
debugGas(`${typeof context === 'string' ? context + ': ' : ''}used ${amount} gas (-> ${this._runState.gasLeft})`);
}
if (this._runState.gasLeft < BigInt(0)) {

@@ -295,6 +270,3 @@ this._runState.gasLeft = BigInt(0);

*/
refundGas(amount, context) {
if (this._evm.DEBUG) {
debugGas(`${typeof context === 'string' ? context + ': ' : ''}refund ${amount} gas (-> ${this._runState.gasRefund})`);
}
refundGas(amount, _context) {
this._runState.gasRefund += amount;

@@ -307,6 +279,3 @@ }

*/
subRefund(amount, context) {
if (this._evm.DEBUG) {
debugGas(`${typeof context === 'string' ? context + ': ' : ''}sub gas refund ${amount} (-> ${this._runState.gasRefund})`);
}
subRefund(amount, _context) {
this._runState.gasRefund -= amount;

@@ -323,5 +292,2 @@ if (this._runState.gasRefund < BigInt(0)) {

addStipend(amount) {
if (this._evm.DEBUG) {
debugGas(`add stipend ${amount} (-> ${this._runState.gasLeft})`);
}
this._runState.gasLeft += amount;

@@ -328,0 +294,0 @@ }

@@ -6,3 +6,2 @@ "use strict";

const keccak_1 = require("ethereum-cryptography/keccak");
const utils_1 = require("ethereum-cryptography/utils");
const exceptions_1 = require("../exceptions");

@@ -343,3 +342,3 @@ const util_1 = require("./util");

}
const r = BigInt('0x' + (0, utils_1.bytesToHex)((0, keccak_1.keccak256)(data)));
const r = BigInt('0x' + (0, keccak_1.keccak256)(data).toString('hex'));
runState.stack.push(r);

@@ -346,0 +345,0 @@ },

@@ -7,3 +7,2 @@ "use strict";

const keccak_1 = require("ethereum-cryptography/keccak");
const utils_1 = require("ethereum-cryptography/utils");
const exceptions_1 = require("../exceptions");

@@ -47,3 +46,3 @@ const MASK_160 = (BigInt(1) << BigInt(160)) - BigInt(1);

function describeLocation(runState) {
const hash = (0, utils_1.bytesToHex)((0, keccak_1.keccak256)(runState.interpreter.getCode()));
const hash = (0, keccak_1.keccak256)(runState.interpreter.getCode()).toString('hex');
const address = runState.interpreter.getAddress().buf.toString('hex');

@@ -50,0 +49,0 @@ const pc = runState.programCounter - 1;

{
"name": "@nomicfoundation/ethereumjs-evm",
"version": "1.0.0-rc.1",
"version": "1.0.0-rc.2",
"description": "JavaScript Ethereum Virtual Machine (EVM) implementation",

@@ -48,8 +48,8 @@ "keywords": [

"dependencies": {
"@nomicfoundation/ethereumjs-common": "3.0.0-rc.1",
"@nomicfoundation/ethereumjs-util": "8.0.0-rc.1",
"@nomicfoundation/ethereumjs-common": "3.0.0-rc.2",
"@nomicfoundation/ethereumjs-util": "8.0.0-rc.2",
"@types/async-eventemitter": "^0.2.1",
"async-eventemitter": "^0.2.4",
"debug": "^4.3.3",
"ethereum-cryptography": "^1.1.2",
"ethereum-cryptography": "0.1.3",
"mcl-wasm": "^0.7.1",

@@ -59,3 +59,3 @@ "rustbn.js": "~0.2.0"

"devDependencies": {
"@nomicfoundation/ethereumjs-statemanager": "1.0.0-rc.1",
"@nomicfoundation/ethereumjs-statemanager": "1.0.0-rc.2",
"@ethersproject/abi": "^5.0.12",

@@ -62,0 +62,0 @@ "@types/benchmark": "^1.0.33",

@@ -11,7 +11,5 @@ import { Chain, Common, Hardfork } from '@nomicfoundation/ethereumjs-common'

isTruthy,
short,
zeros,
} from '@nomicfoundation/ethereumjs-util'
import AsyncEventEmitter = require('async-eventemitter')
import { debug as createDebugLogger } from 'debug'
import { promisify } from 'util'

@@ -46,5 +44,2 @@

const debug = createDebugLogger('evm')
const debugGas = createDebugLogger('evm:gas')
// very ugly way to detect if we are running in a browser

@@ -373,11 +368,5 @@ const isBrowser = new Function('try {return this===window;}catch(e){ return false;}')

exit = true
if (this.DEBUG) {
debug(`Exit early on no code`)
}
}
if (isTruthy(errorMessage)) {
exit = true
if (this.DEBUG) {
debug(`Exit early on value transfer overflowed`)
}
}

@@ -397,5 +386,2 @@ if (exit) {

if (message.isCompiled) {
if (this.DEBUG) {
debug(`Run precompile`)
}
result = await this.runPrecompile(

@@ -408,5 +394,2 @@ message.code as PrecompileFunc,

} else {
if (this.DEBUG) {
debug(`Start bytecode processing...`)
}
result = await this.runInterpreter(message)

@@ -445,5 +428,2 @@ }

message.to = await this._generateAddress(message)
if (this.DEBUG) {
debug(`Generated CREATE contract address ${message.to}`)
}
let toAccount = await this.eei.getAccount(message.to)

@@ -456,5 +436,2 @@

) {
if (this.DEBUG) {
debug(`Returning on address collision`)
}
return {

@@ -496,11 +473,5 @@ createdAddress: message.to,

exit = true
if (this.DEBUG) {
debug(`Exit early on no code`)
}
}
if (isTruthy(errorMessage)) {
exit = true
if (this.DEBUG) {
debug(`Exit early on value transfer overflowed`)
}
}

@@ -519,6 +490,2 @@ if (exit) {

if (this.DEBUG) {
debug(`Start bytecode processing...`)
}
let result = await this.runInterpreter(message)

@@ -532,5 +499,2 @@ // fee for size of the return value

totalGas = totalGas + returnFee
if (this.DEBUG) {
debugGas(`Add return value size fee (${returnFee} to gas used (-> ${totalGas}))`)
}
}

@@ -587,11 +551,5 @@

if (this._common.gteHardfork(Hardfork.Homestead)) {
if (this.DEBUG) {
debug(`Not enough gas or code size not allowed (>= Homestead)`)
}
result = { ...result, ...OOGResult(message.gasLimit) }
} else {
// we are in Frontier
if (this.DEBUG) {
debug(`Not enough gas or code size not allowed (Frontier)`)
}
if (totalGas - returnFee <= message.gasLimit) {

@@ -614,5 +572,2 @@ // we cannot pay the code deposit fee (but the deposit code actually did run)

await this.eei.putContractCode(message.to, result.returnValue)
if (this.DEBUG) {
debug(`Code saved on new contract creation`)
}
} else if (CodestoreOOG) {

@@ -752,35 +707,9 @@ // This only happens at Frontier. But, let's do a sanity check;

this._transientStorage.checkpoint()
if (this.DEBUG) {
debug('-'.repeat(100))
debug(`message checkpoint`)
}
let result
if (this.DEBUG) {
const { caller, gasLimit, to, value, delegatecall } = message
debug(
`New message caller=${caller} gasLimit=${gasLimit} to=${
to?.toString() ?? 'none'
} value=${value} delegatecall=${delegatecall ? 'yes' : 'no'}`
)
}
if (message.to) {
if (this.DEBUG) {
debug(`Message CALL execution (to: ${message.to})`)
}
result = await this._executeCall(message as MessageWithTo)
} else {
if (this.DEBUG) {
debug(`Message CREATE execution (to undefined)`)
}
result = await this._executeCreate(message)
}
if (this.DEBUG) {
const { executionGasUsed, exceptionError, returnValue } = result.execResult
debug(
`Received message execResult: [ gasUsed=${executionGasUsed} exceptionError=${
exceptionError ? `'${exceptionError.error}'` : 'none'
} returnValue=0x${short(returnValue)} gasRefund=${result.execResult.gasRefund ?? 0} ]`
)
}
const err = result.execResult.exceptionError

@@ -801,5 +730,2 @@ // This clause captures any error which happened during execution

this._transientStorage.revert()
if (this.DEBUG) {
debug(`message checkpoint reverted`)
}
} else {

@@ -810,5 +736,2 @@ // we are in chainstart and the error was the code deposit error

this._transientStorage.commit()
if (this.DEBUG) {
debug(`message checkpoint committed`)
}
}

@@ -818,5 +741,2 @@ } else {

this._transientStorage.commit()
if (this.DEBUG) {
debug(`message checkpoint committed`)
}
}

@@ -919,5 +839,2 @@ await this._emit('afterMessage', result)

const result = this.eei.putAccount(message.authcallOrigin ?? message.caller, account)
if (this.DEBUG) {
debug(`Reduced sender (${message.caller}) balance (-> ${account.balance})`)
}
return result

@@ -934,5 +851,2 @@ }

const result = this.eei.putAccount(message.to, toAccount)
if (this.DEBUG) {
debug(`Added toAccount (${message.to}) balance (-> ${toAccount.balance})`)
}
return result

@@ -939,0 +853,0 @@ }

import { ConsensusAlgorithm } from '@nomicfoundation/ethereumjs-common'
import {
MAX_UINT64,
bigIntToHex,
bufferToBigInt,
intToHex,
isFalsy,
isTruthy,
} from '@nomicfoundation/ethereumjs-util'
import { debug as createDebugLogger } from 'debug'
import { MAX_UINT64, bufferToBigInt, isFalsy, isTruthy } from '@nomicfoundation/ethereumjs-util'

@@ -25,4 +17,2 @@ import { EOF } from './eof'

const debugGas = createDebugLogger('evm:eei:gas')
export interface InterpreterOpts {

@@ -320,26 +310,2 @@ pc?: number

if (this._evm.DEBUG) {
// Create opTrace for debug functionality
let hexStack = []
hexStack = eventObj.stack.map((item: any) => {
return bigIntToHex(BigInt(item))
})
const name = eventObj.opcode.name
const opTrace = {
pc: eventObj.pc,
op: name,
gas: bigIntToHex(eventObj.gasLeft),
gasCost: intToHex(eventObj.opcode.fee),
stack: hexStack,
depth: eventObj.depth,
}
if (!(name in this.opDebuggers)) {
this.opDebuggers[name] = createDebugLogger(`evm:ops:${name}`)
}
this.opDebuggers[name](JSON.stringify(opTrace))
}
/**

@@ -403,11 +369,4 @@ * The `step` event for trace output

*/
useGas(amount: bigint, context?: string): void {
useGas(amount: bigint, _context?: string): void {
this._runState.gasLeft -= amount
if (this._evm.DEBUG) {
debugGas(
`${typeof context === 'string' ? context + ': ' : ''}used ${amount} gas (-> ${
this._runState.gasLeft
})`
)
}
if (this._runState.gasLeft < BigInt(0)) {

@@ -424,10 +383,3 @@ this._runState.gasLeft = BigInt(0)

*/
refundGas(amount: bigint, context?: string): void {
if (this._evm.DEBUG) {
debugGas(
`${typeof context === 'string' ? context + ': ' : ''}refund ${amount} gas (-> ${
this._runState.gasRefund
})`
)
}
refundGas(amount: bigint, _context?: string): void {
this._runState.gasRefund += amount

@@ -441,10 +393,3 @@ }

*/
subRefund(amount: bigint, context?: string): void {
if (this._evm.DEBUG) {
debugGas(
`${typeof context === 'string' ? context + ': ' : ''}sub gas refund ${amount} (-> ${
this._runState.gasRefund
})`
)
}
subRefund(amount: bigint, _context?: string): void {
this._runState.gasRefund -= amount

@@ -462,5 +407,2 @@ if (this._runState.gasRefund < BigInt(0)) {

addStipend(amount: bigint): void {
if (this._evm.DEBUG) {
debugGas(`add stipend ${amount} (-> ${this._runState.gasLeft})`)
}
this._runState.gasLeft += amount

@@ -467,0 +409,0 @@ }

@@ -14,3 +14,2 @@ import {

import { keccak256 } from 'ethereum-cryptography/keccak'
import { bytesToHex } from 'ethereum-cryptography/utils'

@@ -377,3 +376,3 @@ import { ERROR } from '../exceptions'

}
const r = BigInt('0x' + bytesToHex(keccak256(data)))
const r = BigInt('0x' + keccak256(data).toString('hex'))
runState.stack.push(r)

@@ -380,0 +379,0 @@ },

import { Hardfork } from '@nomicfoundation/ethereumjs-common'
import { bigIntToBuffer, setLengthLeft, setLengthRight } from '@nomicfoundation/ethereumjs-util'
import { keccak256 } from 'ethereum-cryptography/keccak'
import { bytesToHex } from 'ethereum-cryptography/utils'

@@ -48,3 +47,3 @@ import { EvmError } from '../exceptions'

export function describeLocation(runState: RunState): string {
const hash = bytesToHex(keccak256(runState.interpreter.getCode()))
const hash = keccak256(runState.interpreter.getCode()).toString('hex')
const address = runState.interpreter.getAddress().buf.toString('hex')

@@ -51,0 +50,0 @@ const pc = runState.programCounter - 1

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc