-
Notifications
You must be signed in to change notification settings - Fork 286
Automatic checking of storage compatibility of structs and enums #261
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
Merged
Merged
Changes from 19 commits
Commits
Show all changes
92 commits
Select commit
Hold shift + click to select a range
e8f4765
extract and store struct and enum members
frangio 3f03499
implement type id parsing
frangio 2e88710
expand storage layouts before comparing
frangio 8c60e39
add assertion to type id parsing
frangio eb0b3ab
lay foundation to compare storage fields recursively
frangio 994ecf5
compare struct members recursively
frangio dd64a36
test type id parser with unknown mapping key from oz cli migration
frangio aee06bc
implement type compatibility check
frangio 5fe1b8e
explain parameter Type
frangio 4f2968f
add comment explaining ASTDereferencer
frangio a847daa
typo
frangio 5a4c06b
add note about UserDefinedTypes
frangio c3890fc
explain implementation decisions and add todo about recursive types
frangio 97126ff
remove unsafeAllowCustomTypes flag
frangio 45e29f9
Merge branch 'master' into extract-structs
frangio d5c1d9d
fix error message expected in test
frangio e6b9c05
add note about generic function
frangio 5ea5c09
improve comment
frangio aeb6414
add documentation for parse-type-id
frangio 09e9b64
remove unused argument to matchStorageField
frangio 22e48e5
rename canGrow -> allowAppend
frangio 8de6555
add more tests for parse-type-id
frangio 9fd620f
grammar
frangio e99ed1c
limit enum members to 256
frangio 4eec9ae
detect and fail with recursive types
frangio 90f6c56
validate compatibility of array member type
frangio 2eab1cf
add more tests comparing upgraded types
frangio 4898422
improve storage layout tests
frangio 7b19889
add initial support for complex storage layout error reporting
frangio fb35da6
cache results of comparing two types
frangio 07af28b
return StorageMatchResult instances from compatibleTypes
frangio 4dda814
rename message -> errorMessage
frangio 4ef2b3e
fix regex
frangio 277f271
make ErrorDescriptor.hint a function
frangio ff629d4
remove unused default value
frangio 7b8a49d
rename operation kinds to past tense
frangio 8be7b72
remove unused default value
frangio cfa3e26
improve enum incompatibility error message
frangio 036fac6
simplify error message
frangio 20f603e
break up storage.ts into separate files
frangio 935ed03
fix tests
frangio f944834
use t.like for levenshtein tests
frangio f70bedf
refactor levenshtein
frangio a66e07b
add Manifest.loadAll to load all manifests
frangio 7312b91
reorganize validate module
frangio 33d9363
rename RunValidation -> ValidationRunData
frangio db023c8
define new validation data version
frangio 949d587
add DeepArray utils
frangio 710c051
add a migration of all manifests as a first step
frangio 1689918
improve handling of outdated validations in hardhat
frangio 15007cf
Merge remote-tracking branch 'origin/master' into extract-structs
frangio cd7e576
fix validations cache errors on hardhat
frangio a0d7da9
stabilize test snapshot
frangio 02852be
fix Manifest.loadAll
frangio a98b83f
fix manifest-migrate tests
frangio 096f3fc
fix findVersionWithoutMetadataMatches
frangio fe53519
refactor storage comparison reporting
frangio b4f361a
stop extracting struct and enum errors
frangio 415c959
remove unsafeAllowCustomTypes flag tests
frangio 4a4f72d
use unsafeAllowCustomTypes when there are missing members
frangio 3454497
remove more old tests
frangio 55c37bf
rename 'different kinds' error to 'obvious mismatch'
frangio ed483db
add tests for obvious mismatch errors
frangio 10244d1
add test for changed inner struct member
frangio 8a6a2d5
Merge remote-tracking branch 'origin/master' into extract-structs
frangio 8ce0ded
migrate manifest version earlier in hardhat
frangio f93c856
fix manifest-migrate validating manifest version before migration
frangio 98bc695
migrate manifest version earlier in truffle
frangio f729466
add tests for storage layout error reporting and fix found bugs
frangio 9cdd007
pass missing option to approve missing members and add tests
frangio 39ad18f
shorten warning
frangio e03e40b
add more detail to expected data in test
frangio 2fa7173
improve plugin tests involving structs and enums
frangio 7a97e4f
remove redundant type change detail in struct change description
frangio 3f4888e
add backwards compatible interface for storage module
frangio dc8972a
simplify deepEqual
frangio bb563c6
add function to get or update storage layout in manifest
frangio 42f63e9
remove migrateAllManifests
frangio 72f386e
rename manifest-migrate -> manifest-storage-layout
frangio d10dd2c
revert breaking change to assertStorageUpgradeSafe arguments
frangio 5977eb6
disable color in tests
frangio cdd906b
Merge remote-tracking branch 'origin/master' into extract-structs
frangio 065d242
tweak wording for storage error
frangio 20ea4a0
print a note when unsafeAllowCustomTypes is not needed
frangio b9b19e6
lint
frangio 7f10362
detect when dependencies should be updated and notify
frangio 42dbf3e
clean up whitespace around warnings
frangio a5e180a
update FAQ entry about structs and enums
frangio 84999a7
fix error from merge
frangio 106aecf
update api docs
frangio 6ad37ae
update faq
frangio 335bc1d
improve messaging and formatting of storage layout report
frangio File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| import { findAll } from 'solidity-ast/utils'; | ||
| import type { Node, NodeType, NodeTypeMap } from 'solidity-ast/node'; | ||
|
|
||
| import { curry2 } from './utils/curry'; | ||
| import type { SolcOutput } from './solc-api'; | ||
|
|
||
| // An ASTDereferencer is a function that looks up an AST node given its id, in all of the source files involved in a | ||
| // solc run. It will generally be used together with the AST property `referencedDeclaration` (found in Identifier, | ||
| // UserDefinedTypeName, etc.) to look up a variable definition or type definition. | ||
|
|
||
| export interface ASTDereferencer { | ||
| <T extends NodeType>(nodeTypes: T[]): (id: number) => NodeTypeMap[T]; | ||
| <T extends NodeType>(nodeTypes: T[], id: number): NodeTypeMap[T]; | ||
| } | ||
|
|
||
| export function astDereferencer(solcOutput: SolcOutput): ASTDereferencer { | ||
| const asts = Array.from(Object.values(solcOutput.sources), s => s.ast); | ||
| const cache = new Map<number, Node>(); | ||
|
|
||
| function deref<T extends NodeType>(nodeTypes: T[], id: number): NodeTypeMap[T] { | ||
| const cached = cache.get(id); | ||
|
|
||
| if (cached) { | ||
| if ((nodeTypes as NodeType[]).includes(cached.nodeType)) { | ||
| return cached as NodeTypeMap[T]; | ||
| } | ||
| } | ||
|
|
||
| for (const ast of asts) { | ||
| for (const node of findAll(nodeTypes, ast)) { | ||
| if (node.id === id) { | ||
| cache.set(id, node); | ||
| return node; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| throw new Error(`No node with id ${id} of type ${nodeTypes}`); | ||
| } | ||
|
|
||
| return curry2(deref); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.