openzeppelin-upgrades icon indicating copy to clipboard operation
openzeppelin-upgrades copied to clipboard

validateUpgradeSafety: Cannot read properties of undefined (reading 'ast')

Open crystalbit opened this issue 10 months ago • 2 comments

Hi! I use validateUpgradeSafety on two folders:

  const report = await validateUpgradeSafety(
    join(__dirname, "..", "out", "build-info"),
    undefined,
    undefined,
    undefined,
    [join(__dirname, "..", "out-stable", "build-info-stable")],
  );

Folders are foundry build artifacts of same contracts from different times.

To make this more reproducible, I'll use folders with same files.

I have this error:

/Users/dmitrii/FLUENCE/compute-marketplace/storage-checker/node_modules/@openzeppelin/upgrades-core/src/validate/run.ts:305
  for (const node of solcOutput.sources[source].ast.nodes) {
                                                ^


TypeError: Cannot read properties of undefined (reading 'ast')
    at checkNamespacesOutsideContract (/Users/dmitrii/FLUENCE/compute-marketplace/storage-checker/node_modules/@openzeppelin/upgrades-core/src/validate/run.ts:305:49)
    at validate (/Users/dmitrii/FLUENCE/compute-marketplace/storage-checker/node_modules/@openzeppelin/upgrades-core/src/validate/run.ts:203:5)
    at runValidations (/Users/dmitrii/FLUENCE/compute-marketplace/storage-checker/node_modules/@openzeppelin/upgrades-core/src/cli/validate/validations.ts:31:30)
    at validateBuildInfoContracts (/Users/dmitrii/FLUENCE/compute-marketplace/storage-checker/node_modules/@openzeppelin/upgrades-core/src/cli/validate/validations.ts:22:25)
    at validateUpgradeSafety (/Users/dmitrii/FLUENCE/compute-marketplace/storage-checker/node_modules/@openzeppelin/upgrades-core/src/cli/validate/validate-upgrade-safety.ts:45:53)
    at async <anonymous> (/Users/dmitrii/FLUENCE/compute-marketplace/storage-checker/index.ts:60:18)

Node.js v22.7.0

Then I try to do some logs in node_modules compiled js code I see that this error is while iterating on EnumerableSet.sol file.
Can't find out what to do to skip it

crystalbit avatar Feb 12 '25 14:02 crystalbit

Hi @crystalbit, it looks like there is some inconsistency in your build artifacts, where the contract names in the solc output's contracts and sources sections do not match.

In order for us to investigate this further, would you be able to provide the entire contents of your build-info directory? (Note that it will include all of your contracts' source code)

ericglau avatar Feb 13 '25 18:02 ericglau

Hi! Cannot share, sorry. But finally I found the problem and here is my fix:

Image

So the error was because of double slash in import file address.

I think a good fix on oz side would be not failing on such paths which are still ok to solc

crystalbit avatar Feb 15 '25 15:02 crystalbit

I have the same issue with my upgradable contracts setup in Foundry, no issues like the one shown in the image above - updated all the contracts to work with correct remapping suggested in the docs - no luck, still the same:

[FAIL: revert: Failed to run upgrade safety validation: /Users/user/.nvm/versions/node/v22.11.0/lib/node_modules/@openzeppelin/upgrades-core/dist/validate/run.js:178
    for (const node of solcOutput.sources[source].ast.nodes) {
                                                  ^

TypeError: Cannot read properties of undefined (reading 'ast')

drinkius avatar Apr 27 '25 15:04 drinkius