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

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

Open
crystalbit opened this issue Feb 12, 2025 · 2 comments

Comments

@crystalbit
Copy link

crystalbit commented Feb 12, 2025

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

Setland34 added a commit to Setland34/openzeppelin-upgrades that referenced this issue Feb 13, 2025
Fixes OpenZeppelin#1126

Handle undefined `ast` in `validateUpgradeSafety`.

* Add a check in `checkNamespacesOutsideContract` to verify if `solcOutput.sources[source].ast` is undefined before accessing its `nodes` property.
* Log a warning and skip the check if `solcOutput.sources[source].ast` is undefined.
* Add a test case in `validate-upgrade-safety.test.ts` to verify the behavior when `solcOutput.sources[source].ast` is undefined.

---

For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/OpenZeppelin/openzeppelin-upgrades/issues/1126?shareId=XXXX-XXXX-XXXX-XXXX).
@ericglau
Copy link
Member

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)

@crystalbit
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants