Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect issues in parent initializer calls #1095

Open
wants to merge 54 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
ab0ca0c
Check for initializer errors
ericglau Oct 25, 2024
cfadde9
Omit abstract functions from initializers, fix tests to satisfy new r…
ericglau Nov 29, 2024
133fdd2
Update snapshots
ericglau Nov 29, 2024
991d1da
Refactor errors, add linearization WIP
ericglau Dec 2, 2024
c43ba46
Improve error messages
ericglau Dec 6, 2024
88eaa6d
Use onlyInitializing in test
ericglau Dec 6, 2024
ff52d4c
Improve types
ericglau Dec 6, 2024
b65c2b8
Check error messages in tests
ericglau Dec 10, 2024
c08ecfd
Improve error message details
ericglau Dec 10, 2024
e38c1a1
Add more details to errors
ericglau Dec 10, 2024
2c1bfdd
Update doc options for hardhat
ericglau Dec 10, 2024
523e542
Update cli docs
ericglau Dec 10, 2024
92e4c2c
Update changelog
ericglau Dec 10, 2024
2137d40
Merge branch 'master' into initializers
ericglau Dec 10, 2024
e17b5c4
Ignore public initializers from parent contracts
ericglau Dec 10, 2024
d8bcedd
Only consider internal parent initializers, and non private child ini…
ericglau Dec 10, 2024
210c71b
Test initializer visibility
ericglau Dec 10, 2024
4a4ea90
Address review comments - simplify tests
ericglau Dec 17, 2024
d7385c1
Apply review comments - simplify
ericglau Dec 17, 2024
9f45301
Clarify duplicate and incorrect order handling
ericglau Dec 18, 2024
4e8c435
Only require calling non-empty parent initializers
ericglau Dec 19, 2024
a8d06cf
Add testcases for transitive initialization
ericglau Dec 19, 2024
330057e
Check for missing calls to transitive parent initializers - WIP
ericglau Dec 20, 2024
d1fce2c
Comment out console.log
ericglau Dec 20, 2024
b2ef161
Detect duplicate calls in transitive dependencies
ericglau Jan 7, 2025
324c8f8
Improve expects for tests
ericglau Jan 8, 2025
ec65312
Treat incorrect initializer order as warning
ericglau Jan 8, 2025
bf5fb0b
Update tests to not expect incorrect order error
ericglau Jan 9, 2025
c65b9c5
Treat specific errors as skippable warning
ericglau Jan 9, 2025
0874d36
Improve types
ericglau Jan 9, 2025
5d23f45
Update linearized order warning
ericglau Jan 9, 2025
f28d3ea
Update docs/usage for validation errors and warnings
ericglau Jan 9, 2025
bb2d442
Fix lint
ericglau Jan 9, 2025
3ea283c
Refactor WIP
ericglau Jan 9, 2025
fdea823
Refactor
ericglau Jan 9, 2025
a7acf4a
Rework logic of required parent initializers
ericglau Jan 9, 2025
456bc4f
Fix lint
ericglau Jan 9, 2025
16e93e4
Improve testcases for visibility
ericglau Jan 10, 2025
637f6ce
Update comments
ericglau Jan 10, 2025
ec2dc56
Adjust check logic for missing initializer
ericglau Jan 11, 2025
c4c210d
Lint
ericglau Jan 11, 2025
ab71725
Change variable usage
ericglau Jan 11, 2025
3509f5d
Simplify logic
ericglau Jan 11, 2025
a42188d
Update doc comment
ericglau Jan 11, 2025
041beca
Refactor, update comments
ericglau Jan 11, 2025
85c5de7
Rename variable
ericglau Jan 11, 2025
66e4c3c
Update doc
ericglau Jan 11, 2025
0a1b8d7
Refactor to clarify code
ericglau Jan 13, 2025
de3b081
Move initializer checks into separate file
ericglau Jan 13, 2025
b4c9789
Remove reinitializers from validations
ericglau Jan 15, 2025
99fe5e0
Check for duplicates recursively in an initializer
ericglau Jan 15, 2025
8fd1064
Only report missing initializer calls for directly initializable parents
ericglau Jan 16, 2025
c0c5466
Use more direct error messages
ericglau Jan 16, 2025
f867a69
Merge branch 'master' into initializers
ericglau Jan 17, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion docs/modules/ROOT/pages/api-core.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ If any errors are found, the command will exit with a non-zero exit code and pri
* `--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.
* `--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.
* `--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.
* `--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`
* `--unsafeAllow "<VALIDATION_ERROR>[,<VALIDATION_ERROR>...]"` - Selectively disable one or more validation errors or warnings. Comma-separated list with one or more of the following:
** 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`
** Warnings: `incorrect-initializer-order`
* `--unsafeAllowRenames` - Configure storage layout check to allow variable renaming.
* `--unsafeSkipStorageCheck` - Skips checking for storage layout compatibility errors. This is a dangerous option meant to be used as a last resort.

Expand Down
6 changes: 5 additions & 1 deletion docs/modules/ROOT/pages/api-hardhat-upgrades.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Both `deployProxy` and `upgradeProxy` functions will return instances of https:/
The following options are common to some functions.

* `kind`: (`"uups" | "transparent" | "beacon"`) The kind of proxy to deploy, upgrade or import, or the kind of proxy that the implementation will be used with. `deployProxy()` and `upgradeProxy()` only support the values `"uups" | "transparent"`. Defaults to `"transparent"`. See xref:contracts:api:proxy.adoc#transparent-vs-uups[Transparent vs UUPS].
* `unsafeAllow`: (`ValidationError[]`) Selectively disable one or more validation errors:
* `unsafeAllow`: (`ValidationError[]`) Selectively disable one or more validation errors or warnings:
** `"external-library-linking"`: Allows a deployment with external libraries linked to the implementation contract. (External libraries are otherwise xref:faq.adoc#why-cant-i-use-external-libraries[not yet supported].)
** `"struct-definition"`, `"enum-definition"`: Used to be necessary to deploy a contract with structs or enums. No longer necessary.
** `"state-variable-assignment"`: Allows assigning state variables in a contract even though they will be stored in the implementation.
Expand All @@ -17,6 +17,10 @@ The following options are common to some functions.
** `"delegatecall"`, `"selfdestruct"`: Allow the use of these operations. Incorrect use of this option can put funds at risk of permanent loss. See xref:faq.adoc#delegatecall-selfdestruct[Can I safely use `delegatecall` and `selfdestruct`?]
** `"missing-public-upgradeto"`: Allow UUPS implementations that do not contain a public `upgradeTo` or `upgradeToAndCall` function. Enabling this option is likely to cause a revert due to the built-in UUPS safety mechanism.
** `"internal-function-storage"`: Allow internal functions in storage variables. Internal functions are code pointers which will no longer be valid after an upgrade, so they must be reassigned during upgrades. See xref:faq.adoc#internal-function-storage[How can I use internal functions in storage variables?]
** `"missing-initializer"`: Allows implementations where an initializer function is not detected.
** `"missing-initializer-call"`: Allows implementations where a parent initializer is not called from the child initializer.
** `"duplicate-initializer-call"`: Allows implementations where a parent initializer is called more than once from the child initializer.
** `"incorrect-initializer-order"`: Allows implementations where parent initializers are not called in linearized order. *Note*: This condition shows a warning by default, and setting this option will silence the warning.
* `unsafeAllowRenames`: (`boolean`) Configure storage layout check to allow variable renaming.
* `unsafeSkipStorageCheck`: (`boolean`) upgrades the proxy or beacon without first checking for storage layout compatibility errors. This is a dangerous option meant to be used as a last resort.
* `constructorArgs`: (`unknown[]`) Provide arguments for the constructor of the implementation contract. Note that these are different from initializer arguments, and will be used in the deployment of the implementation contract itself. Can be used to initialize immutable variables.
Expand Down
1 change: 1 addition & 0 deletions packages/core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Unreleased

- Update dependencies. ([#1096](https://github.com/OpenZeppelin/openzeppelin-upgrades/pull/1096))
- Detect issues in parent initializer calls. ([#1095](https://github.com/OpenZeppelin/openzeppelin-upgrades/pull/1095))

## 1.41.0 (2024-11-25)

Expand Down
Loading
Loading