From 8142e2537984cac43b6963e2ce3d5825c52d4f7c Mon Sep 17 00:00:00 2001 From: Patricio Palladino Date: Fri, 16 Sep 2022 14:10:48 -0300 Subject: [PATCH 1/4] Upgrade @nomicfoundation/solidity-analyzer --- packages/hardhat-core/package.json | 2 +- yarn.lock | 108 ++++++++++++++--------------- 2 files changed, 55 insertions(+), 55 deletions(-) diff --git a/packages/hardhat-core/package.json b/packages/hardhat-core/package.json index 0ef0bf382c..cdcdb38279 100644 --- a/packages/hardhat-core/package.json +++ b/packages/hardhat-core/package.json @@ -109,7 +109,7 @@ "@nomicfoundation/ethereumjs-tx": "^4.0.0", "@nomicfoundation/ethereumjs-util": "^8.0.0", "@nomicfoundation/ethereumjs-vm": "^6.0.0", - "@nomicfoundation/solidity-analyzer": "^0.0.3", + "@nomicfoundation/solidity-analyzer": "^0.1.0", "@sentry/node": "^5.18.1", "@types/bn.js": "^5.1.0", "@types/lru-cache": "^5.1.0", diff --git a/yarn.lock b/yarn.lock index 6be155e69f..f02181b9aa 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1146,71 +1146,71 @@ mcl-wasm "^0.7.1" rustbn.js "~0.2.0" -"@nomicfoundation/solidity-analyzer-darwin-arm64@0.0.3": - version "0.0.3" - resolved "https://registry.yarnpkg.com/@nomicfoundation/solidity-analyzer-darwin-arm64/-/solidity-analyzer-darwin-arm64-0.0.3.tgz#1d49e4ac028831a3011a9f3dca60bd1963185342" - integrity sha512-W+bIiNiZmiy+MTYFZn3nwjyPUO6wfWJ0lnXx2zZrM8xExKObMrhCh50yy8pQING24mHfpPFCn89wEB/iG7vZDw== +"@nomicfoundation/solidity-analyzer-darwin-arm64@0.1.0": + version "0.1.0" + resolved "https://registry.yarnpkg.com/@nomicfoundation/solidity-analyzer-darwin-arm64/-/solidity-analyzer-darwin-arm64-0.1.0.tgz#83a7367342bd053a76d04bbcf4f373fef07cf760" + integrity sha512-vEF3yKuuzfMHsZecHQcnkUrqm8mnTWfJeEVFHpg+cO+le96xQA4lAJYdUan8pXZohQxv1fSReQsn4QGNuBNuCw== -"@nomicfoundation/solidity-analyzer-darwin-x64@0.0.3": - version "0.0.3" - resolved "https://registry.yarnpkg.com/@nomicfoundation/solidity-analyzer-darwin-x64/-/solidity-analyzer-darwin-x64-0.0.3.tgz#c0fccecc5506ff5466225e41e65691abafef3dbe" - integrity sha512-HuJd1K+2MgmFIYEpx46uzwEFjvzKAI765mmoMxy4K+Aqq1p+q7hHRlsFU2kx3NB8InwotkkIq3A5FLU1sI1WDw== +"@nomicfoundation/solidity-analyzer-darwin-x64@0.1.0": + version "0.1.0" + resolved "https://registry.yarnpkg.com/@nomicfoundation/solidity-analyzer-darwin-x64/-/solidity-analyzer-darwin-x64-0.1.0.tgz#1225f7da647ae1ad25a87125664704ecc0af6ccc" + integrity sha512-dlHeIg0pTL4dB1l9JDwbi/JG6dHQaU1xpDK+ugYO8eJ1kxx9Dh2isEUtA4d02cQAl22cjOHTvifAk96A+ItEHA== -"@nomicfoundation/solidity-analyzer-freebsd-x64@0.0.3": - version "0.0.3" - resolved "https://registry.yarnpkg.com/@nomicfoundation/solidity-analyzer-freebsd-x64/-/solidity-analyzer-freebsd-x64-0.0.3.tgz#8261d033f7172b347490cd005931ef8168ab4d73" - integrity sha512-2cR8JNy23jZaO/vZrsAnWCsO73asU7ylrHIe0fEsXbZYqBP9sMr+/+xP3CELDHJxUbzBY8zqGvQt1ULpyrG+Kw== +"@nomicfoundation/solidity-analyzer-freebsd-x64@0.1.0": + version "0.1.0" + resolved "https://registry.yarnpkg.com/@nomicfoundation/solidity-analyzer-freebsd-x64/-/solidity-analyzer-freebsd-x64-0.1.0.tgz#dbc052dcdfd50ae50fd5ae1788b69b4e0fa40040" + integrity sha512-WFCZYMv86WowDA4GiJKnebMQRt3kCcFqHeIomW6NMyqiKqhK1kIZCxSLDYsxqlx396kKLPN1713Q1S8tu68GKg== -"@nomicfoundation/solidity-analyzer-linux-arm64-gnu@0.0.3": - version "0.0.3" - resolved "https://registry.yarnpkg.com/@nomicfoundation/solidity-analyzer-linux-arm64-gnu/-/solidity-analyzer-linux-arm64-gnu-0.0.3.tgz#1ba64b1d76425f8953dedc6367bd7dd46f31dfc5" - integrity sha512-Eyv50EfYbFthoOb0I1568p+eqHGLwEUhYGOxcRNywtlTE9nj+c+MT1LA53HnxD9GsboH4YtOOmJOulrjG7KtbA== +"@nomicfoundation/solidity-analyzer-linux-arm64-gnu@0.1.0": + version "0.1.0" + resolved "https://registry.yarnpkg.com/@nomicfoundation/solidity-analyzer-linux-arm64-gnu/-/solidity-analyzer-linux-arm64-gnu-0.1.0.tgz#e6b2eea633995b557e74e881d2a43eab4760903d" + integrity sha512-DTw6MNQWWlCgc71Pq7CEhEqkb7fZnS7oly13pujs4cMH1sR0JzNk90Mp1zpSCsCs4oKan2ClhMlLKtNat/XRKQ== -"@nomicfoundation/solidity-analyzer-linux-arm64-musl@0.0.3": - version "0.0.3" - resolved "https://registry.yarnpkg.com/@nomicfoundation/solidity-analyzer-linux-arm64-musl/-/solidity-analyzer-linux-arm64-musl-0.0.3.tgz#8d864c49b55e683f7e3b5cce9d10b628797280ac" - integrity sha512-V8grDqI+ivNrgwEt2HFdlwqV2/EQbYAdj3hbOvjrA8Qv+nq4h9jhQUxFpegYMDtpU8URJmNNlXgtfucSrAQwtQ== +"@nomicfoundation/solidity-analyzer-linux-arm64-musl@0.1.0": + version "0.1.0" + resolved "https://registry.yarnpkg.com/@nomicfoundation/solidity-analyzer-linux-arm64-musl/-/solidity-analyzer-linux-arm64-musl-0.1.0.tgz#af81107f5afa794f19988a368647727806e18dc4" + integrity sha512-wUpUnR/3GV5Da88MhrxXh/lhb9kxh9V3Jya2NpBEhKDIRCDmtXMSqPMXHZmOR9DfCwCvG6vLFPr/+YrPCnUN0w== -"@nomicfoundation/solidity-analyzer-linux-x64-gnu@0.0.3": - version "0.0.3" - resolved "https://registry.yarnpkg.com/@nomicfoundation/solidity-analyzer-linux-x64-gnu/-/solidity-analyzer-linux-x64-gnu-0.0.3.tgz#16e769500cf1a8bb42ab9498cee3b93c30f78295" - integrity sha512-uRfVDlxtwT1vIy7MAExWAkRD4r9M79zMG7S09mCrWUn58DbLs7UFl+dZXBX0/8FTGYWHhOT/1Etw1ZpAf5DTrg== +"@nomicfoundation/solidity-analyzer-linux-x64-gnu@0.1.0": + version "0.1.0" + resolved "https://registry.yarnpkg.com/@nomicfoundation/solidity-analyzer-linux-x64-gnu/-/solidity-analyzer-linux-x64-gnu-0.1.0.tgz#6877e1da1a06a9f08446070ab6e0a5347109f868" + integrity sha512-lR0AxK1x/MeKQ/3Pt923kPvwigmGX3OxeU5qNtQ9pj9iucgk4PzhbS3ruUeSpYhUxG50jN4RkIGwUMoev5lguw== -"@nomicfoundation/solidity-analyzer-linux-x64-musl@0.0.3": - version "0.0.3" - resolved "https://registry.yarnpkg.com/@nomicfoundation/solidity-analyzer-linux-x64-musl/-/solidity-analyzer-linux-x64-musl-0.0.3.tgz#75f4e1a25526d54c506e4eba63b3d698b6255b8f" - integrity sha512-8HPwYdLbhcPpSwsE0yiU/aZkXV43vlXT2ycH+XlOjWOnLfH8C41z0njK8DHRtEFnp4OVN6E7E5lHBBKDZXCliA== +"@nomicfoundation/solidity-analyzer-linux-x64-musl@0.1.0": + version "0.1.0" + resolved "https://registry.yarnpkg.com/@nomicfoundation/solidity-analyzer-linux-x64-musl/-/solidity-analyzer-linux-x64-musl-0.1.0.tgz#bb6cd83a0c259eccef4183796b6329a66cf7ebd9" + integrity sha512-A1he/8gy/JeBD3FKvmI6WUJrGrI5uWJNr5Xb9WdV+DK0F8msuOqpEByLlnTdLkXMwW7nSl3awvLezOs9xBHJEg== -"@nomicfoundation/solidity-analyzer-win32-arm64-msvc@0.0.3": - version "0.0.3" - resolved "https://registry.yarnpkg.com/@nomicfoundation/solidity-analyzer-win32-arm64-msvc/-/solidity-analyzer-win32-arm64-msvc-0.0.3.tgz#ef6e20cfad5eedfdb145cc34a44501644cd7d015" - integrity sha512-5WWcT6ZNvfCuxjlpZOY7tdvOqT1kIQYlDF9Q42wMpZ5aTm4PvjdCmFDDmmTvyXEBJ4WTVmY5dWNWaxy8h/E28g== +"@nomicfoundation/solidity-analyzer-win32-arm64-msvc@0.1.0": + version "0.1.0" + resolved "https://registry.yarnpkg.com/@nomicfoundation/solidity-analyzer-win32-arm64-msvc/-/solidity-analyzer-win32-arm64-msvc-0.1.0.tgz#9d4bca1cc9a1333fde985675083b0b7d165f6076" + integrity sha512-7x5SXZ9R9H4SluJZZP8XPN+ju7Mx+XeUMWZw7ZAqkdhP5mK19I4vz3x0zIWygmfE8RT7uQ5xMap0/9NPsO+ykw== -"@nomicfoundation/solidity-analyzer-win32-ia32-msvc@0.0.3": - version "0.0.3" - resolved "https://registry.yarnpkg.com/@nomicfoundation/solidity-analyzer-win32-ia32-msvc/-/solidity-analyzer-win32-ia32-msvc-0.0.3.tgz#98c4e3af9cee68896220fa7e270aefdf7fc89c7b" - integrity sha512-P/LWGZwWkyjSwkzq6skvS2wRc3gabzAbk6Akqs1/Iiuggql2CqdLBkcYWL5Xfv3haynhL+2jlNkak+v2BTZI4A== +"@nomicfoundation/solidity-analyzer-win32-ia32-msvc@0.1.0": + version "0.1.0" + resolved "https://registry.yarnpkg.com/@nomicfoundation/solidity-analyzer-win32-ia32-msvc/-/solidity-analyzer-win32-ia32-msvc-0.1.0.tgz#0db5bfc6aa952bea4098d8d2c8947b4e5c4337ee" + integrity sha512-m7w3xf+hnE774YRXu+2mGV7RiF3QJtUoiYU61FascCkQhX3QMQavh7saH/vzb2jN5D24nT/jwvaHYX/MAM9zUw== -"@nomicfoundation/solidity-analyzer-win32-x64-msvc@0.0.3": - version "0.0.3" - resolved "https://registry.yarnpkg.com/@nomicfoundation/solidity-analyzer-win32-x64-msvc/-/solidity-analyzer-win32-x64-msvc-0.0.3.tgz#12da288e7ef17ec14848f19c1e8561fed20d231d" - integrity sha512-4AcTtLZG1s/S5mYAIr/sdzywdNwJpOcdStGF3QMBzEt+cGn3MchMaS9b1gyhb2KKM2c39SmPF5fUuWq1oBSQZQ== +"@nomicfoundation/solidity-analyzer-win32-x64-msvc@0.1.0": + version "0.1.0" + resolved "https://registry.yarnpkg.com/@nomicfoundation/solidity-analyzer-win32-x64-msvc/-/solidity-analyzer-win32-x64-msvc-0.1.0.tgz#2e0f39a2924dcd77db6b419828595e984fabcb33" + integrity sha512-xCuybjY0sLJQnJhupiFAXaek2EqF0AP0eBjgzaalPXSNvCEN6ZYHvUzdA50ENDVeSYFXcUsYf3+FsD3XKaeptA== -"@nomicfoundation/solidity-analyzer@^0.0.3": - version "0.0.3" - resolved "https://registry.yarnpkg.com/@nomicfoundation/solidity-analyzer/-/solidity-analyzer-0.0.3.tgz#d1029f872e66cb1082503b02cc8b0be12f8dd95e" - integrity sha512-VFMiOQvsw7nx5bFmrmVp2Q9rhIjw2AFST4DYvWVVO9PMHPE23BY2+kyfrQ4J3xCMFC8fcBbGLt7l4q7m1SlTqg== +"@nomicfoundation/solidity-analyzer@^0.1.0": + version "0.1.0" + resolved "https://registry.yarnpkg.com/@nomicfoundation/solidity-analyzer/-/solidity-analyzer-0.1.0.tgz#e5ddc43ad5c0aab96e5054520d8e16212e125f50" + integrity sha512-xGWAiVCGOycvGiP/qrlf9f9eOn7fpNbyJygcB0P21a1MDuVPlKt0Srp7rvtBEutYQ48ouYnRXm33zlRnlTOPHg== optionalDependencies: - "@nomicfoundation/solidity-analyzer-darwin-arm64" "0.0.3" - "@nomicfoundation/solidity-analyzer-darwin-x64" "0.0.3" - "@nomicfoundation/solidity-analyzer-freebsd-x64" "0.0.3" - "@nomicfoundation/solidity-analyzer-linux-arm64-gnu" "0.0.3" - "@nomicfoundation/solidity-analyzer-linux-arm64-musl" "0.0.3" - "@nomicfoundation/solidity-analyzer-linux-x64-gnu" "0.0.3" - "@nomicfoundation/solidity-analyzer-linux-x64-musl" "0.0.3" - "@nomicfoundation/solidity-analyzer-win32-arm64-msvc" "0.0.3" - "@nomicfoundation/solidity-analyzer-win32-ia32-msvc" "0.0.3" - "@nomicfoundation/solidity-analyzer-win32-x64-msvc" "0.0.3" + "@nomicfoundation/solidity-analyzer-darwin-arm64" "0.1.0" + "@nomicfoundation/solidity-analyzer-darwin-x64" "0.1.0" + "@nomicfoundation/solidity-analyzer-freebsd-x64" "0.1.0" + "@nomicfoundation/solidity-analyzer-linux-arm64-gnu" "0.1.0" + "@nomicfoundation/solidity-analyzer-linux-arm64-musl" "0.1.0" + "@nomicfoundation/solidity-analyzer-linux-x64-gnu" "0.1.0" + "@nomicfoundation/solidity-analyzer-linux-x64-musl" "0.1.0" + "@nomicfoundation/solidity-analyzer-win32-arm64-msvc" "0.1.0" + "@nomicfoundation/solidity-analyzer-win32-ia32-msvc" "0.1.0" + "@nomicfoundation/solidity-analyzer-win32-x64-msvc" "0.1.0" "@nomiclabs/truffle-contract@^4.2.23": version "4.5.10" From b5e106ddf1f03486bf08fa0cdd500aa189192d3e Mon Sep 17 00:00:00 2001 From: Patricio Palladino Date: Fri, 16 Sep 2022 14:11:09 -0300 Subject: [PATCH 2/4] Handle npm issue #4828. --- .../src/internal/core/errors-list.ts | 15 +++++++++++++ .../src/internal/solidity/parse.ts | 21 ++++++++++++++----- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/packages/hardhat-core/src/internal/core/errors-list.ts b/packages/hardhat-core/src/internal/core/errors-list.ts index c86c8de7c0..b42a8f1230 100644 --- a/packages/hardhat-core/src/internal/core/errors-list.ts +++ b/packages/hardhat-core/src/internal/core/errors-list.ts @@ -237,6 +237,21 @@ Either try using a new directory name, or remove the conflicting files.`, "Hardhat attempted to convert the input value to a BigInt, but no known conversion method was applicable to the given value.", shouldBeReported: false, }, + CORRUPTED_LOCKFILE: { + number: 18, + message: `You installed Hardhat with a corrupted lockfile due to the NPM bug #4828. + +Please delete your node_modules, package-lock.json, reinstall your project, and try again.`, + title: "Corrupted lockfile", + description: `Some versions of NPM are affected [by a bug](https://github.com/npm/cli/issues/4828) that leads to corrupt lockfiles being generated. + +This bug can only affect you if you are installing your project without a lockfile, but with an existing node_modules. + +To avoid it, please delete both your node_modules and package-lock.json, and reinstall your project. + +Note that you don't need to do this every time you install a new dependency, but please make sure to delete your node_modules every time you delete your package-lock.json.`, + shouldBeReported: false, + }, }, NETWORK: { CONFIG_NOT_FOUND: { diff --git a/packages/hardhat-core/src/internal/solidity/parse.ts b/packages/hardhat-core/src/internal/solidity/parse.ts index f3af0eab9a..4a09efc876 100644 --- a/packages/hardhat-core/src/internal/solidity/parse.ts +++ b/packages/hardhat-core/src/internal/solidity/parse.ts @@ -1,6 +1,8 @@ import type SolidityAnalyzerT from "@nomicfoundation/solidity-analyzer"; import { SolidityFilesCache } from "../../builtin-tasks/utils/solidity-files-cache"; +import { HardhatError } from "../core/errors"; +import { ERRORS } from "../core/errors-list"; interface ParsedData { imports: string[]; @@ -27,13 +29,22 @@ export class Parser { return cacheResult; } - const { analyze } = - require("@nomicfoundation/solidity-analyzer") as typeof SolidityAnalyzerT; - const result = analyze(fileContent); + try { + const { analyze } = + require("@nomicfoundation/solidity-analyzer") as typeof SolidityAnalyzerT; + const result = analyze(fileContent); - this._cache.set(contentHash, result); + this._cache.set(contentHash, result); - return result; + return result; + } catch (e: any) { + if (e.code === "MODULE_NOT_FOUND") { + throw new HardhatError(ERRORS.GENERAL.CORRUPTED_LOCKFILE); + } + + // eslint-disable-next-line @nomiclabs/hardhat-internal-rules/only-hardhat-error + throw e; + } } /** From 6d2edac4e84a4404655917c713bca55834561498 Mon Sep 17 00:00:00 2001 From: Patricio Palladino Date: Fri, 16 Sep 2022 14:15:08 -0300 Subject: [PATCH 3/4] Create twelve-bags-collect.md --- .changeset/twelve-bags-collect.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/twelve-bags-collect.md diff --git a/.changeset/twelve-bags-collect.md b/.changeset/twelve-bags-collect.md new file mode 100644 index 0000000000..3dba7e12f0 --- /dev/null +++ b/.changeset/twelve-bags-collect.md @@ -0,0 +1,5 @@ +--- +"hardhat": patch +--- + +Upgrade `solidity-analyzer` and handle NPM's issue #4828. From 3f3802003f452b7673f326270618307c087449d9 Mon Sep 17 00:00:00 2001 From: Patricio Palladino Date: Wed, 5 Oct 2022 14:27:51 -0300 Subject: [PATCH 4/4] Wording fix --- packages/hardhat-core/src/internal/core/errors-list.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/hardhat-core/src/internal/core/errors-list.ts b/packages/hardhat-core/src/internal/core/errors-list.ts index b42a8f1230..0eab7ac847 100644 --- a/packages/hardhat-core/src/internal/core/errors-list.ts +++ b/packages/hardhat-core/src/internal/core/errors-list.ts @@ -245,7 +245,7 @@ Please delete your node_modules, package-lock.json, reinstall your project, and title: "Corrupted lockfile", description: `Some versions of NPM are affected [by a bug](https://github.com/npm/cli/issues/4828) that leads to corrupt lockfiles being generated. -This bug can only affect you if you are installing your project without a lockfile, but with an existing node_modules. +This bug can only affect you if you, or someone at your team, installed the project without a lockfile, but with an existing node_modules. To avoid it, please delete both your node_modules and package-lock.json, and reinstall your project.