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.22.3 to 2.22.4

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: {

@@ -22,2 +22,8 @@ import { ArgumentType, CLIArgumentType } from "../../../types";

/**
* BigInt type.
* Accepts either a decimal string integer or hexadecimal string integer.
* @throws HH301
*/
export declare const bigint: CLIArgumentType<bigint>;
/**
* Float type.

@@ -24,0 +30,0 @@ * Accepts either a decimal string number or hexadecimal string number.

41

internal/core/params/argumentTypes.js

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

Object.defineProperty(exports, "__esModule", { value: true });
exports.any = exports.json = exports.inputFile = exports.float = exports.int = exports.boolean = exports.string = void 0;
exports.any = exports.json = exports.inputFile = exports.float = exports.bigint = exports.int = exports.boolean = exports.string = void 0;
const fs = __importStar(require("fs"));

@@ -142,2 +142,41 @@ const fs_extra_1 = __importDefault(require("fs-extra"));

/**
* BigInt type.
* Accepts either a decimal string integer or hexadecimal string integer.
* @throws HH301
*/
exports.bigint = {
name: "bigint",
parse: (argName, strValue) => {
const decimalPattern = /^\d+(?:n)?$/;
const hexPattern = /^0[xX][\dABCDEabcde]+$/;
if (strValue.match(decimalPattern) === null &&
strValue.match(hexPattern) === null) {
throw new errors_1.HardhatError(errors_list_1.ERRORS.ARGUMENTS.INVALID_VALUE_FOR_TYPE, {
value: strValue,
name: argName,
type: exports.bigint.name,
});
}
return BigInt(strValue.replace("n", ""));
},
/**
* Check if argument value is of type "bigint".
*
* @param argName {string} argument's name - used for context in case of error.
* @param value {any} argument's value to validate.
*
* @throws HH301 if value is not of type "bigint"
*/
validate: (argName, value) => {
const isBigInt = typeof value === "bigint";
if (!isBigInt) {
throw new errors_1.HardhatError(errors_list_1.ERRORS.ARGUMENTS.INVALID_VALUE_FOR_TYPE, {
value,
name: argName,
type: exports.bigint.name,
});
}
},
};
/**
* Float type.

@@ -144,0 +183,0 @@ * Accepts either a decimal string number or hexadecimal string number.

54

internal/hardhat-network/provider/provider.js

@@ -223,30 +223,36 @@ "use strict";

const response = JSON.parse(responseObject.json);
const rawTraces = responseObject.traces;
for (const rawTrace of rawTraces) {
const trace = rawTrace.trace();
for (const traceItem of trace) {
if ("pc" in traceItem) {
if (this._node._vm.evm.events.listenerCount("step") > 0) {
this._node._vm.evm.events.emit("step", (0, convertToEdr_1.edrTracingStepToMinimalInterpreterStep)(traceItem));
const needsTraces = this._node._vm.evm.events.eventNames().length > 0 ||
this._rawTraceCallbacks.onStep !== undefined ||
this._rawTraceCallbacks.onAfterMessage !== undefined ||
this._rawTraceCallbacks.onBeforeMessage !== undefined;
if (needsTraces) {
const rawTraces = responseObject.traces;
for (const rawTrace of rawTraces) {
const trace = rawTrace.trace();
for (const traceItem of trace) {
if ("pc" in traceItem) {
if (this._node._vm.evm.events.listenerCount("step") > 0) {
this._node._vm.evm.events.emit("step", (0, convertToEdr_1.edrTracingStepToMinimalInterpreterStep)(traceItem));
}
if (this._rawTraceCallbacks.onStep !== undefined) {
await this._rawTraceCallbacks.onStep(traceItem);
}
}
if (this._rawTraceCallbacks.onStep !== undefined) {
await this._rawTraceCallbacks.onStep(traceItem);
else if ("executionResult" in traceItem) {
if (this._node._vm.evm.events.listenerCount("afterMessage") > 0) {
this._node._vm.evm.events.emit("afterMessage", (0, convertToEdr_1.edrTracingMessageResultToMinimalEVMResult)(traceItem));
}
if (this._rawTraceCallbacks.onAfterMessage !== undefined) {
await this._rawTraceCallbacks.onAfterMessage(traceItem.executionResult);
}
}
}
else if ("executionResult" in traceItem) {
if (this._node._vm.evm.events.listenerCount("afterMessage") > 0) {
this._node._vm.evm.events.emit("afterMessage", (0, convertToEdr_1.edrTracingMessageResultToMinimalEVMResult)(traceItem));
else {
if (this._node._vm.evm.events.listenerCount("beforeMessage") > 0) {
this._node._vm.evm.events.emit("beforeMessage", (0, convertToEdr_1.edrTracingMessageToMinimalMessage)(traceItem));
}
if (this._rawTraceCallbacks.onBeforeMessage !== undefined) {
await this._rawTraceCallbacks.onBeforeMessage(traceItem);
}
}
if (this._rawTraceCallbacks.onAfterMessage !== undefined) {
await this._rawTraceCallbacks.onAfterMessage(traceItem.executionResult);
}
}
else {
if (this._node._vm.evm.events.listenerCount("beforeMessage") > 0) {
this._node._vm.evm.events.emit("beforeMessage", (0, convertToEdr_1.edrTracingMessageToMinimalMessage)(traceItem));
}
if (this._rawTraceCallbacks.onBeforeMessage !== undefined) {
await this._rawTraceCallbacks.onBeforeMessage(traceItem);
}
}
}

@@ -253,0 +259,0 @@ }

@@ -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.22.3",
"version": "2.22.4",
"author": "Nomic Labs LLC",

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

"@metamask/eth-sig-util": "^4.0.0",
"@nomicfoundation/edr": "^0.3.5",
"@nomicfoundation/edr": "^0.3.7",
"@nomicfoundation/ethereumjs-common": "4.0.4",

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

"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: {

@@ -125,2 +125,46 @@ import * as fs from "fs";

/**
* BigInt type.
* Accepts either a decimal string integer or hexadecimal string integer.
* @throws HH301
*/
export const bigint: CLIArgumentType<bigint> = {
name: "bigint",
parse: (argName, strValue) => {
const decimalPattern = /^\d+(?:n)?$/;
const hexPattern = /^0[xX][\dABCDEabcde]+$/;
if (
strValue.match(decimalPattern) === null &&
strValue.match(hexPattern) === null
) {
throw new HardhatError(ERRORS.ARGUMENTS.INVALID_VALUE_FOR_TYPE, {
value: strValue,
name: argName,
type: bigint.name,
});
}
return BigInt(strValue.replace("n", ""));
},
/**
* Check if argument value is of type "bigint".
*
* @param argName {string} argument's name - used for context in case of error.
* @param value {any} argument's value to validate.
*
* @throws HH301 if value is not of type "bigint"
*/
validate: (argName: string, value: any): void => {
const isBigInt = typeof value === "bigint";
if (!isBigInt) {
throw new HardhatError(ERRORS.ARGUMENTS.INVALID_VALUE_FOR_TYPE, {
value,
name: argName,
type: bigint.name,
});
}
},
};
/**
* Float type.

@@ -127,0 +171,0 @@ * Accepts either a decimal string number or hexadecimal string number.

@@ -371,38 +371,46 @@ import type {

const rawTraces = responseObject.traces;
for (const rawTrace of rawTraces) {
const trace = rawTrace.trace();
for (const traceItem of trace) {
if ("pc" in traceItem) {
if (this._node._vm.evm.events.listenerCount("step") > 0) {
this._node._vm.evm.events.emit(
"step",
edrTracingStepToMinimalInterpreterStep(traceItem)
);
const needsTraces =
this._node._vm.evm.events.eventNames().length > 0 ||
this._rawTraceCallbacks.onStep !== undefined ||
this._rawTraceCallbacks.onAfterMessage !== undefined ||
this._rawTraceCallbacks.onBeforeMessage !== undefined;
if (needsTraces) {
const rawTraces = responseObject.traces;
for (const rawTrace of rawTraces) {
const trace = rawTrace.trace();
for (const traceItem of trace) {
if ("pc" in traceItem) {
if (this._node._vm.evm.events.listenerCount("step") > 0) {
this._node._vm.evm.events.emit(
"step",
edrTracingStepToMinimalInterpreterStep(traceItem)
);
}
if (this._rawTraceCallbacks.onStep !== undefined) {
await this._rawTraceCallbacks.onStep(traceItem);
}
} else if ("executionResult" in traceItem) {
if (this._node._vm.evm.events.listenerCount("afterMessage") > 0) {
this._node._vm.evm.events.emit(
"afterMessage",
edrTracingMessageResultToMinimalEVMResult(traceItem)
);
}
if (this._rawTraceCallbacks.onAfterMessage !== undefined) {
await this._rawTraceCallbacks.onAfterMessage(
traceItem.executionResult
);
}
} else {
if (this._node._vm.evm.events.listenerCount("beforeMessage") > 0) {
this._node._vm.evm.events.emit(
"beforeMessage",
edrTracingMessageToMinimalMessage(traceItem)
);
}
if (this._rawTraceCallbacks.onBeforeMessage !== undefined) {
await this._rawTraceCallbacks.onBeforeMessage(traceItem);
}
}
if (this._rawTraceCallbacks.onStep !== undefined) {
await this._rawTraceCallbacks.onStep(traceItem);
}
} else if ("executionResult" in traceItem) {
if (this._node._vm.evm.events.listenerCount("afterMessage") > 0) {
this._node._vm.evm.events.emit(
"afterMessage",
edrTracingMessageResultToMinimalEVMResult(traceItem)
);
}
if (this._rawTraceCallbacks.onAfterMessage !== undefined) {
await this._rawTraceCallbacks.onAfterMessage(
traceItem.executionResult
);
}
} else {
if (this._node._vm.evm.events.listenerCount("beforeMessage") > 0) {
this._node._vm.evm.events.emit(
"beforeMessage",
edrTracingMessageToMinimalMessage(traceItem)
);
}
if (this._rawTraceCallbacks.onBeforeMessage !== undefined) {
await this._rawTraceCallbacks.onBeforeMessage(traceItem);
}
}

@@ -409,0 +417,0 @@ }

@@ -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

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