@openzeppelin/upgrades-core 1.40.0 → 1.42.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/dist/cli/validate.js +3 -1
  2. package/dist/cli/validate.js.map +1 -1
  3. package/dist/index.d.ts +1 -1
  4. package/dist/index.d.ts.map +1 -1
  5. package/dist/index.js +2 -1
  6. package/dist/index.js.map +1 -1
  7. package/dist/utils/make-namespaced.d.ts +13 -2
  8. package/dist/utils/make-namespaced.d.ts.map +1 -1
  9. package/dist/utils/make-namespaced.js +47 -48
  10. package/dist/utils/make-namespaced.js.map +1 -1
  11. package/dist/utils/make-namespaced.test.js +4 -1
  12. package/dist/utils/make-namespaced.test.js.map +1 -1
  13. package/dist/validate/overrides.d.ts +6 -2
  14. package/dist/validate/overrides.d.ts.map +1 -1
  15. package/dist/validate/overrides.js +36 -10
  16. package/dist/validate/overrides.js.map +1 -1
  17. package/dist/validate/report.d.ts +1 -0
  18. package/dist/validate/report.d.ts.map +1 -1
  19. package/dist/validate/report.js +23 -1
  20. package/dist/validate/report.js.map +1 -1
  21. package/dist/validate/run/initializer.d.ts +13 -0
  22. package/dist/validate/run/initializer.d.ts.map +1 -0
  23. package/dist/validate/run/initializer.js +246 -0
  24. package/dist/validate/run/initializer.js.map +1 -0
  25. package/dist/validate/run.d.ts +23 -2
  26. package/dist/validate/run.d.ts.map +1 -1
  27. package/dist/validate/run.js +9 -1
  28. package/dist/validate/run.js.map +1 -1
  29. package/dist/validate-initializers.test.d.ts +2 -0
  30. package/dist/validate-initializers.test.d.ts.map +1 -0
  31. package/dist/validate-initializers.test.js +176 -0
  32. package/dist/validate-initializers.test.js.map +1 -0
  33. package/package.json +3 -3
  34. package/src/cli/cli.test.ts.md +6 -2
  35. package/src/cli/cli.test.ts.snap +0 -0
  36. package/src/cli/validate.ts +4 -4
  37. package/src/index.ts +1 -1
  38. package/src/utils/make-namespaced.test.ts +5 -6
  39. package/src/utils/make-namespaced.ts +54 -51
  40. package/src/validate/overrides.ts +40 -15
  41. package/src/validate/report.ts +24 -2
  42. package/src/validate/run/initializer.ts +316 -0
  43. package/src/validate/run.ts +38 -2
  44. package/src/validate-initializers.test.ts +218 -0
  45. package/CHANGELOG.md +0 -416
  46. package/dist/utils/slang/trivia.d.ts +0 -9
  47. package/dist/utils/slang/trivia.d.ts.map +0 -1
  48. package/dist/utils/slang/trivia.js +0 -23
  49. package/dist/utils/slang/trivia.js.map +0 -1
  50. package/src/utils/slang/trivia.ts +0 -23
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validate-initializers.test.js","sourceRoot":"","sources":["../src/validate-initializers.test.ts"],"names":[],"mappings":";;;;;AAAA,8CAAoC;AACpC,qCAAoC;AAEpC,yCAOoB;AACpB,+CAAuD;AAMvD,MAAM,IAAI,GAAG,aAAwB,CAAC;AAEtC,IAAI,CAAC,MAAM,CAAC,KAAK,EAAC,CAAC,EAAC,EAAE;IACpB,MAAM,SAAS,GAAG,CAAC,gEAAgE,CAAC,CAAC;IAErF,CAAC,CAAC,OAAO,CAAC,UAAU,GAAG,EAAmB,CAAC;IAC3C,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE,CAAC;QACjC,MAAM,SAAS,GAAG,MAAM,mBAAS,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC;QACzD,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;YAC5B,MAAM,IAAI,KAAK,CAAC,qCAAqC,QAAQ,EAAE,CAAC,CAAC;QACnE,CAAC;QACD,MAAM,UAAU,GAAG,SAAS,CAAC,MAAM,CAAC;QACpC,MAAM,SAAS,GAAG,SAAS,CAAC,KAAK,CAAC;QAClC,MAAM,SAAS,GAAG,IAAA,oCAAsB,EAAC,SAAS,EAAE,UAAU,CAAC,CAAC;QAChE,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,UAAU,EAAE,IAAA,mBAAQ,EAAC,UAAU,EAAE,SAAS,CAAC,CA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Q,EAAE,CAAC,sEAAsE,CAAC;IAClF,KAAK,EAAE,CAAC;CACT,CAAC,CAAC;AACH,WAAW,CAAC,cAAc,EAAE,aAAa,CAAC,CAAC;AAE3C,WAAW,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;AAChC,WAAW,CAAC,WAAW,EAAE,MAAM,EAAE;IAC/B,QAAQ,EAAE;QACR,sJAAsJ;KACvJ;IACD,KAAK,EAAE,CAAC;CACT,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openzeppelin/upgrades-core",
3
- "version": "1.40.0",
3
+ "version": "1.42.0",
4
4
  "description": "",
5
5
  "repository": "https://github.com/OpenZeppelin/openzeppelin-upgrades/tree/master/packages/core",
6
6
  "license": "MIT",
@@ -61,8 +61,8 @@
61
61
  "typescript": "^5.0.0"
62
62
  },
63
63
  "dependencies": {
64
- "@nomicfoundation/slang": "^0.17.0",
65
- "cbor": "^9.0.0",
64
+ "@nomicfoundation/slang": "^0.18.3",
65
+ "cbor": "^10.0.0",
66
66
  "chalk": "^4.1.0",
67
67
  "compare-versions": "^6.0.0",
68
68
  "debug": "^4.1.1",
@@ -21,7 +21,9 @@ Generated by [AVA](https://avajs.dev).
21
21
  --requireReference Can only be used when the --contract option is also provided. Not compatible with --unsafeSkipStorageCheck. If specified, requires either the --reference option to be provided or the contract to have a @custom:oz-upgrades-from annotation.␊
22
22
  --referenceBuildInfoDirs "<BUILD_INFO_DIR>[,<BUILD_INFO_DIR>...]" Optional paths of additional build info directories from previous versions of the project to use for storage layout comparisons. When using this option, refer to one of these directories using prefix '<dirName>:' before the contract name or fully qualified name in the --reference option or @custom:oz-upgrades-from annotation, where <dirName> is the directory short name. Each directory short name must be unique, including compared to the main build info directory. If passing in multiple directories, separate them with commas or call the option multiple times, once for each directory.␊
23
23
  --exclude "<GLOB_PATTERN>" [--exclude "<GLOB_PATTERN>"...] Exclude validations for contracts in source file paths that match any of the given glob patterns. For example, --exclude "contracts/mocks/**/*.sol". Does not apply to reference contracts. If passing in multiple patterns, call the option multiple times, once for each pattern.␊
24
- --unsafeAllow "<VALIDATION_ERROR>[,<VALIDATION_ERROR>...]" Selectively disable one or more validation errors. Comma-separated list with one or more of the following: state-variable-assignment, state-variable-immutable, external-library-linking, struct-definition, enum-definition, constructor, delegatecall, selfdestruct, missing-public-upgradeto, internal-function-storage␊
24
+ --unsafeAllow "<VALIDATION_ERROR>[,<VALIDATION_ERROR>...]" Selectively disable one or more validation errors or warnings. Comma-separated list with one or more of the following:␊
25
+ Errors: state-variable-assignment, state-variable-immutable, external-library-linking, struct-definition, enum-definition, constructor, delegatecall, selfdestruct, missing-public-upgradeto, internal-function-storage, missing-initializer, missing-initializer-call, duplicate-initializer-call␊
26
+ Warnings: incorrect-initializer-order␊
25
27
  --unsafeAllowRenames Configure storage layout check to allow variable renaming.␊
26
28
  --unsafeSkipStorageCheck Skips checking for storage layout compatibility errors. This is a dangerous option meant to be used as a last resort.␊
27
29
  `
@@ -43,7 +45,9 @@ Generated by [AVA](https://avajs.dev).
43
45
  --requireReference Can only be used when the --contract option is also provided. Not compatible with --unsafeSkipStorageCheck. If specified, requires either the --reference option to be provided or the contract to have a @custom:oz-upgrades-from annotation.␊
44
46
  --referenceBuildInfoDirs "<BUILD_INFO_DIR>[,<BUILD_INFO_DIR>...]" Optional paths of additional build info directories from previous versions of the project to use for storage layout comparisons. When using this option, refer to one of these directories using prefix '<dirName>:' before the contract name or fully qualified name in the --reference option or @custom:oz-upgrades-from annotation, where <dirName> is the directory short name. Each directory short name must be unique, including compared to the main build info directory. If passing in multiple directories, separate them with commas or call the option multiple times, once for each directory.␊
45
47
  --exclude "<GLOB_PATTERN>" [--exclude "<GLOB_PATTERN>"...] Exclude validations for contracts in source file paths that match any of the given glob patterns. For example, --exclude "contracts/mocks/**/*.sol". Does not apply to reference contracts. If passing in multiple patterns, call the option multiple times, once for each pattern.␊
46
- --unsafeAllow "<VALIDATION_ERROR>[,<VALIDATION_ERROR>...]" Selectively disable one or more validation errors. Comma-separated list with one or more of the following: state-variable-assignment, state-variable-immutable, external-library-linking, struct-definition, enum-definition, constructor, delegatecall, selfdestruct, missing-public-upgradeto, internal-function-storage␊
48
+ --unsafeAllow "<VALIDATION_ERROR>[,<VALIDATION_ERROR>...]" Selectively disable one or more validation errors or warnings. Comma-separated list with one or more of the following:␊
49
+ Errors: state-variable-assignment, state-variable-immutable, external-library-linking, struct-definition, enum-definition, constructor, delegatecall, selfdestruct, missing-public-upgradeto, internal-function-storage, missing-initializer, missing-initializer-call, duplicate-initializer-call␊
50
+ Warnings: incorrect-initializer-order␊
47
51
  --unsafeAllowRenames Configure storage layout check to allow variable renaming.␊
48
52
  --unsafeSkipStorageCheck Skips checking for storage layout compatibility errors. This is a dangerous option meant to be used as a last resort.␊
49
53
  `
Binary file
@@ -1,7 +1,7 @@
1
1
  import minimist from 'minimist';
2
2
 
3
3
  import { ValidateUpgradeSafetyOptions, validateUpgradeSafety } from '.';
4
- import { ValidationError, errorKinds } from '../validate/run';
4
+ import { ValidationError, convertToWarnings, errorKinds } from '../validate/run';
5
5
  import debug from '../utils/debug';
6
6
  import { withCliDefaults } from './validate/validate-upgrade-safety';
7
7
 
@@ -18,9 +18,9 @@ Options:
18
18
  --requireReference Can only be used when the --contract option is also provided. Not compatible with --unsafeSkipStorageCheck. If specified, requires either the --reference option to be provided or the contract to have a @custom:oz-upgrades-from annotation.
19
19
  --referenceBuildInfoDirs "<BUILD_INFO_DIR>[,<BUILD_INFO_DIR>...]" Optional paths of additional build info directories from previous versions of the project to use for storage layout comparisons. When using this option, refer to one of these directories using prefix '<dirName>:' before the contract name or fully qualified name in the --reference option or @custom:oz-upgrades-from annotation, where <dirName> is the directory short name. Each directory short name must be unique, including compared to the main build info directory. If passing in multiple directories, separate them with commas or call the option multiple times, once for each directory.
20
20
  --exclude "<GLOB_PATTERN>" [--exclude "<GLOB_PATTERN>"...] Exclude validations for contracts in source file paths that match any of the given glob patterns. For example, --exclude "contracts/mocks/**/*.sol". Does not apply to reference contracts. If passing in multiple patterns, call the option multiple times, once for each pattern.
21
- --unsafeAllow "<VALIDATION_ERROR>[,<VALIDATION_ERROR>...]" Selectively disable one or more validation errors. Comma-separated list with one or more of the following: ${errorKinds.join(
22
- ', ',
23
- )}
21
+ --unsafeAllow "<VALIDATION_ERROR>[,<VALIDATION_ERROR>...]" Selectively disable one or more validation errors or warnings. Comma-separated list with one or more of the following:
22
+ Errors: ${errorKinds.filter(kind => !convertToWarnings.includes(kind)).join(', ')}
23
+ Warnings: ${convertToWarnings.join(', ')}
24
24
  --unsafeAllowRenames Configure storage layout check to allow variable renaming.
25
25
  --unsafeSkipStorageCheck Skips checking for storage layout compatibility errors. This is a dangerous option meant to be used as a last resort.`;
26
26
 
package/src/index.ts CHANGED
@@ -60,7 +60,7 @@ export {
60
60
  export { ValidateUpgradeSafetyOptions, validateUpgradeSafety, ProjectReport, ReferenceContractNotFound } from './cli';
61
61
 
62
62
  export { getUpgradeInterfaceVersion } from './upgrade-interface-version';
63
- export { makeNamespacedInput } from './utils/make-namespaced';
63
+ export { makeNamespacedInput, trySanitizeNatSpec } from './utils/make-namespaced';
64
64
  export { isNamespaceSupported } from './storage/namespace';
65
65
  export { inferProxyAdmin } from './infer-proxy-admin';
66
66
  export { assertUnreachable } from './utils/assert';
@@ -6,7 +6,7 @@ import {
6
6
  TASK_COMPILE_SOLIDITY_RUN_SOLCJS,
7
7
  } from 'hardhat/builtin-tasks/task-names';
8
8
 
9
- import { makeNamespacedInput } from './make-namespaced';
9
+ import { makeNamespacedInput, trySanitizeNatSpec } from './make-namespaced';
10
10
  import { SolcBuild } from 'hardhat/types/builtin-tasks';
11
11
  import { SolcInput, SolcOutput } from '../solc-api';
12
12
  import { BuildInfo } from 'hardhat/types';
@@ -40,11 +40,10 @@ async function testMakeNamespaced(
40
40
  // Inefficient, but we want to test that we don't actually modify the original input object
41
41
  const origInput = JSON.parse(JSON.stringify(origBuildInfo.input));
42
42
 
43
- const modifiedInput = makeNamespacedInput(
44
- origBuildInfo.input,
45
- origBuildInfo.output,
46
- keepAllNatSpec ? undefined : origBuildInfo.solcVersion,
47
- );
43
+ let modifiedInput = makeNamespacedInput(origBuildInfo.input, origBuildInfo.output, origBuildInfo.solcVersion);
44
+ if (!keepAllNatSpec) {
45
+ modifiedInput = await trySanitizeNatSpec(modifiedInput, origBuildInfo.solcVersion);
46
+ }
48
47
 
49
48
  // Run hardhat compile on the modified input and make sure it has no errors
50
49
  const modifiedOutput = await hardhatCompile(modifiedInput, solcVersion);
@@ -34,10 +34,10 @@ const OUTPUT_SELECTION = {
34
34
  *
35
35
  * @param input The original solc input.
36
36
  * @param output The original solc output.
37
- * @param solcVersion The version of the solc compiler that was originally used to compile the input.
37
+ * @param _solcVersion The version of the solc compiler that was originally used to compile the input. This argument is no longer used and is kept for backwards compatibility.
38
38
  * @returns The modified solc input with storage layout that includes namespaced type information.
39
39
  */
40
- export function makeNamespacedInput(input: SolcInput, output: SolcOutput, solcVersion?: string): SolcInput {
40
+ export function makeNamespacedInput(input: SolcInput, output: SolcOutput, _solcVersion?: string): SolcInput {
41
41
  const modifiedSources: Record<string, { content?: string }> = {};
42
42
 
43
43
  for (const [sourcePath] of Object.entries(input.sources)) {
@@ -163,74 +163,77 @@ export function makeNamespacedInput(input: SolcInput, output: SolcOutput, solcVe
163
163
  }
164
164
  }
165
165
 
166
- const modifiedSource = tryRemoveNonStructNatSpec(getModifiedSource(orig, modifications), solcVersion);
167
-
168
- modifiedSources[sourcePath] = { ...source, content: modifiedSource };
166
+ modifiedSources[sourcePath] = { ...source, content: getModifiedSource(orig, modifications) };
169
167
  }
170
168
 
171
169
  return { ...input, sources: modifiedSources, settings: { ...input.settings, outputSelection: OUTPUT_SELECTION } };
172
170
  }
173
171
 
174
172
  /**
175
- * If we have the compiler version available and Slang is supported for the current platform and compiler version,
176
- * use Slang to parse and remove all NatSpec comments that do not precede a struct definition and return the modified content.
173
+ * Attempts to remove all NatSpec comments that do not precede a struct definition from the input source contents.
174
+ * Directly modifies the input source contents, and also returns the modified input.
175
+ *
176
+ * If the solc version is not supported by the parser, the original content is kept.
177
+ *
178
+ * @param solcInput Solc input.
179
+ * @param solcVersion The version of the solc compiler that was originally used to compile the input.
180
+ * @returns The modified solc input with NatSpec comments removed where they do not precede a struct definition.
181
+ */
182
+ export async function trySanitizeNatSpec(solcInput: SolcInput, solcVersion: string): Promise<SolcInput> {
183
+ for (const [sourcePath, source] of Object.entries(solcInput.sources)) {
184
+ if (source.content !== undefined) {
185
+ solcInput.sources[sourcePath].content = await tryRemoveNonStructNatSpec(source.content, solcVersion);
186
+ }
187
+ }
188
+ return solcInput;
189
+ }
190
+
191
+ /**
192
+ * If Slang is supported for the current compiler version, use Slang to parse and remove all NatSpec comments
193
+ * that do not precede a struct definition and return the modified content.
177
194
  *
178
195
  * Otherwise, return the original content.
179
196
  */
180
- function tryRemoveNonStructNatSpec(origContent: string, solcVersion: string | undefined): string {
181
- const natSpecRemovals: Modification[] = [];
197
+ async function tryRemoveNonStructNatSpec(origContent: string, solcVersion: string): Promise<string> {
198
+ if (solcVersion === undefined) {
199
+ return origContent;
200
+ }
182
201
 
183
- if (solcVersion !== undefined && tryRequire('@nomicfoundation/slang') && slangSupportsVersion(solcVersion)) {
184
- /* eslint-disable @typescript-eslint/no-var-requires */
185
- const { Language } = require('@nomicfoundation/slang/language');
186
- const { NonterminalKind, TerminalKind } = require('@nomicfoundation/slang/kinds');
187
- const { TerminalNode } = require('@nomicfoundation/slang/cst');
188
- const { isTrivia } = require('./slang/trivia');
189
- /* eslint-enable @typescript-eslint/no-var-requires */
202
+ const { Parser } = await import('@nomicfoundation/slang/parser');
203
+ if (!Parser.supportedVersions().includes(solcVersion)) {
204
+ return origContent;
205
+ }
206
+
207
+ const { TerminalKind, TerminalKindExtensions } = await import('@nomicfoundation/slang/cst');
190
208
 
191
- const language = new Language(solcVersion);
192
- const parseOutput = language.parse(NonterminalKind.SourceUnit, origContent);
193
- const cursor = parseOutput.createTreeCursor();
209
+ const parser = Parser.create(solcVersion);
210
+ const parseOutput = parser.parse(Parser.rootKind(), origContent);
211
+ const cursor = parseOutput.createTreeCursor();
212
+
213
+ const natSpecRemovals: Modification[] = [];
194
214
 
215
+ while (
216
+ cursor.goToNextTerminalWithKinds([TerminalKind.MultiLineNatSpecComment, TerminalKind.SingleLineNatSpecComment])
217
+ ) {
218
+ // Lookahead to determine if the next non-trivia node is the struct keyword.
219
+ // If so, this NatSpec is part of the struct definition and should not be removed.
220
+ const lookaheadCursor = cursor.clone();
195
221
  while (
196
- cursor.goToNextTerminalWithKinds([TerminalKind.MultiLineNatSpecComment, TerminalKind.SingleLineNatSpecComment])
222
+ lookaheadCursor.goToNextTerminal() &&
223
+ lookaheadCursor.node.isTerminalNode() &&
224
+ TerminalKindExtensions.isTrivia(lookaheadCursor.node.kind)
197
225
  ) {
198
- // Lookahead to determine if the next non-trivia node is the struct keyword.
199
- // If so, this NatSpec is part of the struct definition and should not be removed.
200
- const lookaheadCursor = cursor.clone();
201
- while (lookaheadCursor.goToNextTerminal() && isTrivia(lookaheadCursor.node())) {
202
- // skip over trivia nodes
203
- }
204
- if (lookaheadCursor.node().kind === TerminalKind.StructKeyword) {
205
- continue;
206
- }
226
+ // skip over trivia nodes
227
+ }
207
228
 
208
- const triviaNode = cursor.node();
209
- assert(triviaNode instanceof TerminalNode);
210
- natSpecRemovals.push(makeDeleteRange(cursor.textRange.start.utf8, cursor.textRange.end.utf8));
229
+ if (lookaheadCursor.node.kind === TerminalKind.StructKeyword) {
230
+ continue;
211
231
  }
212
- return getModifiedSource(Buffer.from(origContent, 'utf8'), natSpecRemovals);
213
- } else {
214
- return origContent;
215
- }
216
- }
217
232
 
218
- function tryRequire(id: string) {
219
- try {
220
- require(id);
221
- return true;
222
- } catch (e: any) {
223
- // do nothing
233
+ natSpecRemovals.push(makeDeleteRange(cursor.textRange.start.utf8, cursor.textRange.end.utf8));
224
234
  }
225
- return false;
226
- }
227
-
228
- function slangSupportsVersion(solcVersion: string): boolean {
229
- /* eslint-disable @typescript-eslint/no-var-requires */
230
- const { Language } = require('@nomicfoundation/slang/language');
231
- /* eslint-enable @typescript-eslint/no-var-requires */
232
235
 
233
- return Language.supportedVersions().includes(solcVersion);
236
+ return getModifiedSource(Buffer.from(origContent, 'utf8'), natSpecRemovals);
234
237
  }
235
238
 
236
239
  interface Modification {
@@ -1,6 +1,7 @@
1
- import { ValidationError } from './run';
1
+ import { ValidationError, convertToWarnings } from './run';
2
2
  import { ProxyDeployment } from '../manifest';
3
3
  import { logWarning } from '../utils/log';
4
+ import { describeError } from './report';
4
5
 
5
6
  // Backwards compatibility
6
7
  export { silenceWarnings } from '../utils/log';
@@ -30,7 +31,7 @@ export interface StandaloneValidationOptions extends ProxyKindOption {
30
31
  unsafeAllowLinkedLibraries?: boolean;
31
32
 
32
33
  /**
33
- * Selectively disable one or more validation errors.
34
+ * Selectively disable one or more validation errors or warnings.
34
35
  */
35
36
  unsafeAllow?: ValidationError['kind'][];
36
37
  }
@@ -50,7 +51,11 @@ export interface ValidationOptions extends StandaloneValidationOptions {
50
51
  unsafeSkipStorageCheck?: boolean;
51
52
  }
52
53
 
53
- export const ValidationErrorUnsafeMessages: Record<ValidationError['kind'], string[]> = {
54
+ /**
55
+ * Warnings to display when a validation error occurs but is allowed.
56
+ * `null` indicates that the original message should be displayed.
57
+ */
58
+ export const ValidationErrorUnsafeMessages: Record<ValidationError['kind'], string[] | null> = {
54
59
  'state-variable-assignment': [
55
60
  `You are using the \`unsafeAllow.state-variable-assignment\` flag.`,
56
61
  `The value will be stored in the implementation and not the proxy.`,
@@ -81,6 +86,19 @@ export const ValidationErrorUnsafeMessages: Record<ValidationError['kind'], stri
81
86
  `Internal functions are code pointers which will no longer be valid after an upgrade.`,
82
87
  `Make sure you reassign internal functions in storage variables during upgrades.`,
83
88
  ],
89
+ 'missing-initializer': [
90
+ `You are using the \`unsafeAllow.missing-initializer\` flag.`,
91
+ `Make sure you have manually checked that the contract has an initializer and that it correctly calls all parent initializers.`,
92
+ ],
93
+ 'missing-initializer-call': [
94
+ `You are using the \`unsafeAllow.missing-initializer-call\` flag.`,
95
+ `Make sure you have manually checked that the contract initializer calls all parent initializers.`,
96
+ ],
97
+ 'duplicate-initializer-call': [
98
+ `You are using the \`unsafeAllow.duplicate-initializer-call\` flag.`,
99
+ `Make sure you have manually checked that the contract initializer calls each parent initializer only once.`,
100
+ ],
101
+ 'incorrect-initializer-order': null,
84
102
  };
85
103
 
86
104
  export function withValidationDefaults(opts: ValidationOptions): Required<ValidationOptions> {
@@ -97,6 +115,7 @@ export function withValidationDefaults(opts: ValidationOptions): Required<Valida
97
115
  if (unsafeAllowLinkedLibraries) {
98
116
  unsafeAllow.push('external-library-linking');
99
117
  }
118
+
100
119
  const kind = opts.kind ?? 'transparent';
101
120
 
102
121
  const unsafeAllowRenames = opts.unsafeAllowRenames ?? false;
@@ -123,18 +142,24 @@ export function processExceptions(
123
142
  errors = errors.filter(error => error.kind !== 'missing-public-upgradeto');
124
143
  }
125
144
 
126
- for (const [errorType, errorDescription] of Object.entries(ValidationErrorUnsafeMessages)) {
127
- if (unsafeAllow.includes(errorType as ValidationError['kind'])) {
128
- let exceptionsFound = false;
129
-
130
- errors = errors.filter(error => {
131
- const isException = errorType === error.kind;
132
- exceptionsFound = exceptionsFound || isException;
133
- return !isException;
134
- });
135
-
136
- if (exceptionsFound && errorDescription) {
137
- logWarning(`Potentially unsafe deployment of ${contractName}`, errorDescription);
145
+ for (const [key, errorDescription] of Object.entries(ValidationErrorUnsafeMessages)) {
146
+ const errorType = key as ValidationError['kind'];
147
+ const skip = unsafeAllow.includes(errorType);
148
+ const warn = convertToWarnings.includes(errorType);
149
+
150
+ if (skip || warn) {
151
+ const errorsWithType = errors.filter(error => error.kind === errorType);
152
+ errors = errors.filter(error => !errorsWithType.includes(error));
153
+
154
+ // Display message about the exception, unless it is a warning that the user has chosen to skip
155
+ if (errorsWithType.length > 0 && !(skip && warn)) {
156
+ if (errorDescription !== null) {
157
+ logWarning(`Potentially unsafe deployment of ${contractName}`, errorDescription);
158
+ } else {
159
+ for (const error of errorsWithType) {
160
+ logWarning(`Potentially unsafe deployment of ${contractName}`, [describeError(error)]);
161
+ }
162
+ }
138
163
  }
139
164
  }
140
165
  }
@@ -72,11 +72,33 @@ const errorInfo: ErrorDescriptions<ValidationError> = {
72
72
  ` flag and ensure you always reassign internal functions in storage during upgrades`,
73
73
  link: 'https://zpl.in/upgrades/error-009',
74
74
  },
75
+ 'missing-initializer': {
76
+ msg: () => `Missing initializer`,
77
+ hint: () => `Define an initializer function and use it to call the initializers of parent contracts`,
78
+ link: 'https://zpl.in/upgrades/error-001',
79
+ },
80
+ 'missing-initializer-call': {
81
+ msg: e => `Missing initializer calls for one or more parent contracts: \`${e.parentContracts.join(', ')}\``,
82
+ hint: () => `Call the parent initializers in your initializer function`,
83
+ link: 'https://zpl.in/upgrades/error-001',
84
+ },
85
+ 'duplicate-initializer-call': {
86
+ msg: e => `Duplicate calls found to initializer \`${e.parentInitializer}\` for contract \`${e.parentContract}\``,
87
+ hint: () => `Only call each parent initializer once`,
88
+ link: 'https://zpl.in/upgrades/error-001',
89
+ },
90
+ 'incorrect-initializer-order': {
91
+ msg: e =>
92
+ `Incorrect order of parent initializer calls.
93
+ - Found initializer calls to parent contracts in the following order: ${e.foundOrder.join(', ')}
94
+ - Expected: ${e.expectedLinearization.join(', ')}`,
95
+ hint: () => `Call parent initializers in linearized order`,
96
+ },
75
97
  };
76
98
 
77
- function describeError(e: ValidationError, color = true): string {
99
+ export function describeError(e: ValidationError, color = true): string {
78
100
  const chalk = new _chalk.Instance({ level: color && _chalk.supportsColor ? _chalk.supportsColor.level : 0 });
79
- const info = errorInfo[e.kind];
101
+ const info: any = errorInfo[e.kind]; // union type is too complex for TypeScript to represent, so we use `any`
80
102
  const log = [chalk.bold(e.src) + ': ' + info.msg(e as any)];
81
103
  const hint = info.hint?.(e as any);
82
104
  if (hint) {