Socket
Socket
Sign inDemoInstall

hardhat

Package Overview
Dependencies
Maintainers
5
Versions
159
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hardhat - npm Package Compare versions

Comparing version 2.23.0-dev.0 to 2.23.0-dev.1

internal/solidity/compiler/solcjs-runner.js

7

internal/core/errors-list.d.ts

@@ -694,2 +694,9 @@ export declare const ERROR_PREFIX = "HH";

};
SOLCJS_ERROR: {
number: number;
message: string;
title: string;
description: string;
shouldBeReported: boolean;
};
};

@@ -696,0 +703,0 @@ BUILTIN_TASKS: {

@@ -956,2 +956,9 @@ "use strict";

},
SOLCJS_ERROR: {
number: 506,
message: "Error running solcjs: %error%",
title: "Error running solcjs",
description: `There was an error while running the solcjs compiler.`,
shouldBeReported: false,
},
},

@@ -958,0 +965,0 @@ BUILTIN_TASKS: {

1

internal/hardhat-network/provider/provider.d.ts

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

private _setCallOverrideCallback;
private _setVerboseTracing;
private _ethEventListener;

@@ -53,0 +54,0 @@ private _emitLegacySubscriptionEvent;

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

const needsTraces = this._node._vm.evm.events.eventNames().length > 0 ||
this._node._vm.events.eventNames().length > 0 ||
this._rawTraceCallbacks.onStep !== undefined ||

@@ -232,3 +233,8 @@ this._rawTraceCallbacks.onAfterMessage !== undefined ||

const trace = rawTrace.trace();
// beforeTx event
if (this._node._vm.events.listenerCount("beforeTx") > 0) {
this._node._vm.events.emit("beforeTx");
}
for (const traceItem of trace) {
// step event
if ("pc" in traceItem) {

@@ -242,2 +248,3 @@ if (this._node._vm.evm.events.listenerCount("step") > 0) {

}
// afterMessage event
else if ("executionResult" in traceItem) {

@@ -251,2 +258,3 @@ if (this._node._vm.evm.events.listenerCount("afterMessage") > 0) {

}
// beforeMessage event
else {

@@ -261,2 +269,6 @@ if (this._node._vm.evm.events.listenerCount("beforeMessage") > 0) {

}
// afterTx event
if (this._node._vm.events.listenerCount("afterTx") > 0) {
this._node._vm.events.emit("afterTx");
}
}

@@ -316,2 +328,5 @@ }

}
_setVerboseTracing(enabled) {
this._provider.setVerboseTracing(enabled);
}
_ethEventListener(event) {

@@ -318,0 +333,0 @@ const subscription = `0x${event.filterId.toString(16)}`;

@@ -167,3 +167,3 @@ "use strict";

function edrTracingStepToMinimalInterpreterStep(step) {
return {
const minimalInterpreterStep = {
pc: Number(step.pc),

@@ -174,12 +174,28 @@ depth: step.depth,

},
stack: step.stackTop !== undefined ? [step.stackTop] : [],
stack: step.stack,
};
if (step.memory !== undefined) {
minimalInterpreterStep.memory = step.memory;
}
return minimalInterpreterStep;
}
exports.edrTracingStepToMinimalInterpreterStep = edrTracingStepToMinimalInterpreterStep;
function edrTracingMessageResultToMinimalEVMResult(tracingMessageResult) {
return {
const { result, contractAddress } = tracingMessageResult.executionResult;
// only SuccessResult has logs
const success = "logs" in result;
const minimalEVMResult = {
execResult: {
executionGasUsed: tracingMessageResult.executionResult.result.gasUsed,
executionGasUsed: result.gasUsed,
success,
},
};
// only success and exceptional halt have reason
if ("reason" in result) {
minimalEVMResult.execResult.reason = result.reason;
}
if (contractAddress !== undefined) {
minimalEVMResult.execResult.contractAddress = new ethereumjs_util_1.Address(contractAddress);
}
return minimalEVMResult;
}

@@ -197,2 +213,3 @@ exports.edrTracingMessageResultToMinimalEVMResult = edrTracingMessageResultToMinimalEVMResult;

gasLimit: message.gasLimit,
isStaticCall: message.isStaticCall,
};

@@ -199,0 +216,0 @@ }

@@ -11,4 +11,5 @@ /// <reference types="node" />

export interface MinimalEthereumJsVm {
events: AsyncEventEmitter<MinimalEthereumJsVmEvents>;
evm: {
events: AsyncEventEmitter<MinimalEthereumJsVmEvents>;
events: AsyncEventEmitter<MinimalEthereumJsEvmEvents>;
};

@@ -22,2 +23,6 @@ stateManager: {

type MinimalEthereumJsVmEvents = {
beforeTx: () => void;
afterTx: () => void;
};
type MinimalEthereumJsEvmEvents = {
beforeMessage: (data: MinimalMessage, resolve?: (result?: any) => void) => void;

@@ -29,4 +34,6 @@ afterMessage: (data: MinimalEVMResult, resolve?: (result?: any) => void) => void;

}
export declare class MinimalEthereumJsEvmEventEmitter extends AsyncEventEmitter<MinimalEthereumJsEvmEvents> {
}
export declare function getMinimalEthereumJsVm(provider: EdrProviderT): MinimalEthereumJsVm;
export {};
//# sourceMappingURL=minimal-vm.d.ts.map

8

internal/hardhat-network/provider/vm/minimal-vm.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getMinimalEthereumJsVm = exports.MinimalEthereumJsVmEventEmitter = void 0;
exports.getMinimalEthereumJsVm = exports.MinimalEthereumJsEvmEventEmitter = exports.MinimalEthereumJsVmEventEmitter = void 0;
const ethereumjs_util_1 = require("@nomicfoundation/ethereumjs-util");

@@ -8,6 +8,10 @@ class MinimalEthereumJsVmEventEmitter extends ethereumjs_util_1.AsyncEventEmitter {

exports.MinimalEthereumJsVmEventEmitter = MinimalEthereumJsVmEventEmitter;
class MinimalEthereumJsEvmEventEmitter extends ethereumjs_util_1.AsyncEventEmitter {
}
exports.MinimalEthereumJsEvmEventEmitter = MinimalEthereumJsEvmEventEmitter;
function getMinimalEthereumJsVm(provider) {
const minimalEthereumJsVm = {
events: new MinimalEthereumJsVmEventEmitter(),
evm: {
events: new MinimalEthereumJsVmEventEmitter(),
events: new MinimalEthereumJsEvmEventEmitter(),
},

@@ -14,0 +18,0 @@ stateManager: {

@@ -0,1 +1,2 @@

import type { ExceptionalHalt, SuccessReason } from "@nomicfoundation/edr";
import type { Address } from "@nomicfoundation/ethereumjs-util";

@@ -13,5 +14,9 @@ /**

stack: bigint[];
memory?: Uint8Array;
}
export interface MinimalExecResult {
success: boolean;
executionGasUsed: bigint;
contractAddress?: Address;
reason?: SuccessReason | ExceptionalHalt;
}

@@ -28,3 +33,4 @@ export interface MinimalEVMResult {

gasLimit: bigint;
isStaticCall: boolean;
}
//# sourceMappingURL=types.d.ts.map

@@ -50,7 +50,7 @@ "use strict";

}
function addUnmappedInstructions(instructions, bytecode, bytesIndex) {
function addUnmappedInstructions(instructions, bytecode) {
const lastInstrPc = instructions[instructions.length - 1].pc;
let nextPc = lastInstrPc + 1;
while (bytecode[nextPc] !== opcodes_1.Opcode.INVALID) {
const opcode = bytecode[nextPc];
let bytesIndex = lastInstrPc + 1;
while (bytecode[bytesIndex] !== opcodes_1.Opcode.INVALID) {
const opcode = bytecode[bytesIndex];
let pushData;

@@ -65,5 +65,5 @@ let pushDataLenth = 0;

: model_1.JumpType.NOT_JUMP;
const instruction = new model_1.Instruction(nextPc, opcode, jumpType, pushData);
const instruction = new model_1.Instruction(bytesIndex, opcode, jumpType, pushData);
instructions.push(instruction);
nextPc += 1 + pushDataLenth;
bytesIndex += (0, opcodes_1.getOpcodeLength)(opcode);
}

@@ -103,3 +103,3 @@ }

if (isDeployment) {
addUnmappedInstructions(instructions, bytecode, bytesIndex);
addUnmappedInstructions(instructions, bytecode);
}

@@ -106,0 +106,0 @@ return instructions;

@@ -155,3 +155,5 @@ "use strict";

function getCompilerConfigForFile(file, directDependencies, transitiveDependencies, solidityConfig) {
const transitiveDependenciesVersionPragmas = transitiveDependencies.map(({ dependency }) => dependency.content.versionPragmas);
const transitiveDependenciesVersionPragmas = transitiveDependencies
.map(({ dependency }) => dependency.content.versionPragmas)
.flat();
const versionRange = Array.from(new Set([

@@ -158,0 +160,0 @@ ...file.content.versionPragmas,

@@ -7,13 +7,4 @@ import { CompilerInput, CompilerOutput } from "../../../types";

private _pathToSolcJs;
private _loadedSolc?;
constructor(_pathToSolcJs: string);
compile(input: CompilerInput): Promise<any>;
getSolc(): Promise<any>;
/**
* This function loads the compiler sources bypassing any require hook.
*
* The compiler is a huge asm.js file, and using a simple require may trigger
* babel/register and hang the process.
*/
private _loadCompilerSources;
}

@@ -20,0 +11,0 @@ export declare class NativeCompiler implements ICompiler {

@@ -42,37 +42,22 @@ "use strict";

async compile(input) {
const solc = await this.getSolc();
const jsonOutput = solc.compile(JSON.stringify(input));
return JSON.parse(jsonOutput);
const scriptPath = node_path_1.default.join(__dirname, "./solcjs-runner.js");
const output = await new Promise((resolve, reject) => {
try {
const subprocess = (0, child_process_1.execFile)(process.execPath, [scriptPath, this._pathToSolcJs], {
maxBuffer: 1024 * 1024 * 500,
}, (err, stdout) => {
if (err !== null) {
return reject(err);
}
resolve(stdout);
});
subprocess.stdin.write(JSON.stringify(input));
subprocess.stdin.end();
}
catch (e) {
throw new errors_1.HardhatError(errors_list_1.ERRORS.SOLC.SOLCJS_ERROR, { error: e.message }, e);
}
});
return JSON.parse(output);
}
async getSolc() {
if (this._loadedSolc !== undefined) {
return this._loadedSolc;
}
const solcWrapper = require("solc/wrapper");
this._loadedSolc = solcWrapper(this._loadCompilerSources(this._pathToSolcJs));
return this._loadedSolc;
}
/**
* This function loads the compiler sources bypassing any require hook.
*
* The compiler is a huge asm.js file, and using a simple require may trigger
* babel/register and hang the process.
*/
_loadCompilerSources(compilerPath) {
const Module = module.constructor;
// if Hardhat is bundled (for example, in the vscode extension), then
// Module._extenions might be undefined. In that case, we just use a plain
// require.
if (Module._extensions === undefined) {
return require(compilerPath);
}
const previousHook = Module._extensions[".js"];
Module._extensions[".js"] = function (module, filename) {
const content = fs.readFileSync(filename, "utf8");
Object.getPrototypeOf(module)._compile.call(module, content, filename);
};
const loadedSolc = require(compilerPath);
Module._extensions[".js"] = previousHook;
return loadedSolc;
}
}

@@ -79,0 +64,0 @@ exports.Compiler = Compiler;

{
"name": "hardhat",
"version": "2.23.0-dev.0",
"version": "2.23.0-dev.1",
"author": "Nomic Labs LLC",

@@ -88,3 +88,3 @@ "license": "MIT",

"@metamask/eth-sig-util": "^4.0.0",
"@nomicfoundation/edr": "^0.3.7",
"@nomicfoundation/edr": "0.4.0-alpha.0",
"@nomicfoundation/ethereumjs-common": "4.0.4",

@@ -181,8 +181,8 @@ "@nomicfoundation/ethereumjs-tx": "5.0.4",

"pretest:except-tracing": "cd ../../crates/edr_napi && pnpm build",
"prebuild": "cd ../../crates/edr_napi && pnpm build",
"postbuild": "cp src/internal/solidity/compiler/solcjs-runner.js internal/solidity/compiler/solcjs-runner.js",
"prebuild:tracing": "cd ../../crates/edr_napi && pnpm build:tracing",
"build": "tsc --build --force --incremental .",
"build:tracing": "tsc --build --force --incremental .",
"clean": "rimraf builtin-tasks internal types utils *.d.ts *.map *.js build-test tsconfig.tsbuildinfo test/internal/hardhat-network/provider/.hardhat_node_test_cache test/internal/hardhat-network/stack-traces/test-files/artifacts"
"clean": "rimraf builtin-tasks internal types utils *.d.ts *.map *.js build-test tsconfig.tsbuildinfo test/internal/hardhat-network/stack-traces/test-files/artifacts"
}
}

@@ -1,2 +0,2 @@

import { HardhatUserConfig } from "hardhat/config";
import type { HardhatUserConfig } from "hardhat/config";
import "@nomicfoundation/hardhat-toolbox-viem";

@@ -3,0 +3,0 @@

@@ -1023,2 +1023,9 @@ export const ERROR_PREFIX = "HH";

},
SOLCJS_ERROR: {
number: 506,
message: "Error running solcjs: %error%",
title: "Error running solcjs",
description: `There was an error while running the solcjs compiler.`,
shouldBeReported: false,
},
},

@@ -1025,0 +1032,0 @@ BUILTIN_TASKS: {

@@ -373,2 +373,3 @@ import type {

this._node._vm.evm.events.eventNames().length > 0 ||
this._node._vm.events.eventNames().length > 0 ||
this._rawTraceCallbacks.onStep !== undefined ||

@@ -382,3 +383,10 @@ this._rawTraceCallbacks.onAfterMessage !== undefined ||

const trace = rawTrace.trace();
// beforeTx event
if (this._node._vm.events.listenerCount("beforeTx") > 0) {
this._node._vm.events.emit("beforeTx");
}
for (const traceItem of trace) {
// step event
if ("pc" in traceItem) {

@@ -394,3 +402,5 @@ if (this._node._vm.evm.events.listenerCount("step") > 0) {

}
} else if ("executionResult" in traceItem) {
}
// afterMessage event
else if ("executionResult" in traceItem) {
if (this._node._vm.evm.events.listenerCount("afterMessage") > 0) {

@@ -407,3 +417,5 @@ this._node._vm.evm.events.emit(

}
} else {
}
// beforeMessage event
else {
if (this._node._vm.evm.events.listenerCount("beforeMessage") > 0) {

@@ -420,2 +432,7 @@ this._node._vm.evm.events.emit(

}
// afterTx event
if (this._node._vm.events.listenerCount("afterTx") > 0) {
this._node._vm.events.emit("afterTx");
}
}

@@ -486,2 +503,6 @@ }

private _setVerboseTracing(enabled: boolean) {
this._provider.setVerboseTracing(enabled);
}
private _ethEventListener(event: SubscriptionEvent) {

@@ -488,0 +509,0 @@ const subscription = `0x${event.filterId.toString(16)}`;

@@ -211,3 +211,3 @@ import type {

): MinimalInterpreterStep {
return {
const minimalInterpreterStep: MinimalInterpreterStep = {
pc: Number(step.pc),

@@ -218,4 +218,10 @@ depth: step.depth,

},
stack: step.stackTop !== undefined ? [step.stackTop] : [],
stack: step.stack,
};
if (step.memory !== undefined) {
minimalInterpreterStep.memory = step.memory;
}
return minimalInterpreterStep;
}

@@ -226,7 +232,24 @@

): MinimalEVMResult {
return {
const { result, contractAddress } = tracingMessageResult.executionResult;
// only SuccessResult has logs
const success = "logs" in result;
const minimalEVMResult: MinimalEVMResult = {
execResult: {
executionGasUsed: tracingMessageResult.executionResult.result.gasUsed,
executionGasUsed: result.gasUsed,
success,
},
};
// only success and exceptional halt have reason
if ("reason" in result) {
minimalEVMResult.execResult.reason = result.reason;
}
if (contractAddress !== undefined) {
minimalEVMResult.execResult.contractAddress = new Address(contractAddress);
}
return minimalEVMResult;
}

@@ -247,3 +270,4 @@

gasLimit: message.gasLimit,
isStaticCall: message.isStaticCall,
};
}

@@ -16,4 +16,5 @@ import type { Provider as EdrProviderT } from "@nomicfoundation/edr";

export interface MinimalEthereumJsVm {
events: AsyncEventEmitter<MinimalEthereumJsVmEvents>;
evm: {
events: AsyncEventEmitter<MinimalEthereumJsVmEvents>;
events: AsyncEventEmitter<MinimalEthereumJsEvmEvents>;
};

@@ -31,6 +32,14 @@ stateManager: {

// we need to use a type instead of an interface to satisfy the type constarint
// we need to use a type instead of an interface to satisfy the type constraint
// of the AsyncEventEmitter type param
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
type MinimalEthereumJsVmEvents = {
beforeTx: () => void;
afterTx: () => void;
};
// we need to use a type instead of an interface to satisfy the type constraint
// of the AsyncEventEmitter type param
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
type MinimalEthereumJsEvmEvents = {
beforeMessage: (

@@ -51,2 +60,3 @@ data: MinimalMessage,

export class MinimalEthereumJsVmEventEmitter extends AsyncEventEmitter<MinimalEthereumJsVmEvents> {}
export class MinimalEthereumJsEvmEventEmitter extends AsyncEventEmitter<MinimalEthereumJsEvmEvents> {}

@@ -57,4 +67,5 @@ export function getMinimalEthereumJsVm(

const minimalEthereumJsVm: MinimalEthereumJsVm = {
events: new MinimalEthereumJsVmEventEmitter(),
evm: {
events: new MinimalEthereumJsVmEventEmitter(),
events: new MinimalEthereumJsEvmEventEmitter(),
},

@@ -61,0 +72,0 @@ stateManager: {

@@ -0,1 +1,2 @@

import type { ExceptionalHalt, SuccessReason } from "@nomicfoundation/edr";
import type { Address } from "@nomicfoundation/ethereumjs-util";

@@ -15,6 +16,10 @@

stack: bigint[];
memory?: Uint8Array;
}
export interface MinimalExecResult {
success: boolean;
executionGasUsed: bigint;
contractAddress?: Address;
reason?: SuccessReason | ExceptionalHalt;
}

@@ -33,2 +38,3 @@

gasLimit: bigint;
isStaticCall: boolean;
}

@@ -78,10 +78,9 @@ import { Instruction, JumpType, SourceFile, SourceLocation } from "./model";

instructions: Instruction[],
bytecode: Buffer,
bytesIndex: number
bytecode: Buffer
) {
const lastInstrPc = instructions[instructions.length - 1].pc;
let nextPc = lastInstrPc + 1;
let bytesIndex = lastInstrPc + 1;
while (bytecode[nextPc] !== Opcode.INVALID) {
const opcode = bytecode[nextPc];
while (bytecode[bytesIndex] !== Opcode.INVALID) {
const opcode = bytecode[bytesIndex];
let pushData: Buffer | undefined;

@@ -99,6 +98,6 @@

const instruction = new Instruction(nextPc, opcode, jumpType, pushData);
const instruction = new Instruction(bytesIndex, opcode, jumpType, pushData);
instructions.push(instruction);
nextPc += 1 + pushDataLenth;
bytesIndex += getOpcodeLength(opcode);
}

@@ -166,3 +165,3 @@ }

if (isDeployment) {
addUnmappedInstructions(instructions, bytecode, bytesIndex);
addUnmappedInstructions(instructions, bytecode);
}

@@ -169,0 +168,0 @@

@@ -237,5 +237,5 @@ import type { LoDashStatic } from "lodash";

): SolcConfig | CompilationJobCreationError {
const transitiveDependenciesVersionPragmas = transitiveDependencies.map(
({ dependency }) => dependency.content.versionPragmas
);
const transitiveDependenciesVersionPragmas = transitiveDependencies
.map(({ dependency }) => dependency.content.versionPragmas)
.flat();
const versionRange = Array.from(

@@ -242,0 +242,0 @@ new Set([

@@ -15,58 +15,36 @@ import { execFile } from "child_process";

export class Compiler implements ICompiler {
private _loadedSolc?: any;
constructor(private _pathToSolcJs: string) {}
public async compile(input: CompilerInput) {
const solc = await this.getSolc();
const scriptPath = path.join(__dirname, "./solcjs-runner.js");
const jsonOutput = solc.compile(JSON.stringify(input));
return JSON.parse(jsonOutput);
}
const output: string = await new Promise((resolve, reject) => {
try {
const subprocess = execFile(
process.execPath,
[scriptPath, this._pathToSolcJs],
{
maxBuffer: 1024 * 1024 * 500,
},
(err, stdout) => {
if (err !== null) {
return reject(err);
}
resolve(stdout);
}
);
public async getSolc() {
if (this._loadedSolc !== undefined) {
return this._loadedSolc;
}
subprocess.stdin!.write(JSON.stringify(input));
subprocess.stdin!.end();
} catch (e: any) {
throw new HardhatError(
ERRORS.SOLC.SOLCJS_ERROR,
{ error: e.message },
e
);
}
});
const solcWrapper = require("solc/wrapper");
this._loadedSolc = solcWrapper(
this._loadCompilerSources(this._pathToSolcJs)
);
return this._loadedSolc;
return JSON.parse(output);
}
/**
* This function loads the compiler sources bypassing any require hook.
*
* The compiler is a huge asm.js file, and using a simple require may trigger
* babel/register and hang the process.
*/
private _loadCompilerSources(compilerPath: string) {
const Module = module.constructor as any;
// if Hardhat is bundled (for example, in the vscode extension), then
// Module._extenions might be undefined. In that case, we just use a plain
// require.
if (Module._extensions === undefined) {
return require(compilerPath);
}
const previousHook = Module._extensions[".js"];
Module._extensions[".js"] = function (
module: NodeJS.Module,
filename: string
) {
const content = fs.readFileSync(filename, "utf8");
Object.getPrototypeOf(module)._compile.call(module, content, filename);
};
const loadedSolc = require(compilerPath);
Module._extensions[".js"] = previousHook;
return loadedSolc;
}
}

@@ -73,0 +51,0 @@

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

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