Skip to content

ASTDereferencerError: No node with id 64707 of type ContractDefinition #112

@gleb-altarey

Description

@gleb-altarey

foundry.toml

[profile.default]
src = "."
test = "test"
out = "out"
libs = ["../lib"]
solc_version = "0.8.20"
remappings = [
    "forge-std/=../lib/forge-std/src/"
]
forge -V
forge 1.3.5-stable (9979a41b5d 2025-09-09T04:49:44.505104000Z)

Contracts >>

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.22;

import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";

contract MyContractV1 is Initializable {
    uint256 public value;

    function initialize(uint256 _val) public initializer {
        value = _val;
    }

    function getValue() public view returns (uint256) {
        return value;
    }
}


/// @custom:oz-upgrades-from example.sol:MyContractV1
contract MyContractV2 is Initializable {
    uint256 public value;

    function initialize(uint256 _val) public initializer {
        value = _val;
    }

    function getValue() public view returns (uint256) {
        return value;
    }

    function increment() public {
        value += 1;
    }
}

Upgrade test>>

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.22;

import "forge-std/Test.sol";
import {Upgrades, Options} from "openzeppelin-foundry-upgrades/Upgrades.sol";
import {MyContractV1, MyContractV2} from "../example.sol";

contract UpgradeTest is Test {
    address public proxy;
    Options private opts;

    function setUp() public {
        //opts.unsafeSkipAllChecks = true; // <<<<----- works OK if uncomment here
        //opts.unsafeSkipProxyAdminCheck = true;
        //opts.unsafeSkipStorageCheck = true;

        // Deploy transparent proxy pointing to V1
        proxy = Upgrades.deployTransparentProxy(
            "example.sol:MyContractV1",
            address(this),   // initial owner of ProxyAdmin
            abi.encodeCall(MyContractV1.initialize, (42)),
            opts
        );
    }

    function testUpgrade() public {
        // check initial behavior
        MyContractV1 instance1 = MyContractV1(proxy);
        assertEq(instance1.getValue(), 42);

        // Upgrade to V2, and call increment during upgrade
        Upgrades.upgradeProxy(
            proxy,
            "example.sol:MyContractV2",
            abi.encodeCall(MyContractV2.increment, ()),
            opts
        );

        // After upgrade
        MyContractV2 instance2 = MyContractV2(proxy);
        // value was 42, and increment adds 1
        assertEq(instance2.getValue(), 43);
    }
}
% forge clean && forge test -vv
[⠊] Compiling...
[⠢] Compiling 58 files with Solc 0.8.22
[⠔] Solc 0.8.22 finished in 2.22s
Compiler run successful!

Ran 1 test for test/example.t.sol:UpgradeTest
[FAIL: Failed to run upgrade safety validation: /Users/x/.npm/_npx/e9c2fe9985ed1095/node_modules/solidity-ast/dist/ast-dereferencer.js:73
        throw new ASTDereferencerError(id, nodeType);                                                                                                                                                                                     
              ^                                                                                                                                                                                                                           
                                                                                                                                                                                                                                          
ASTDereferencerError: No node with id 64707 of type ContractDefinition                                                                                                                                                                    
    at deref (/Users/x/.npm/_npx/e9c2fe9985ed1095/node_modules/solidity-ast/dist/ast-dereferencer.js:73:15)                                                                                                                         
    at derefNode (/Users/x/.npm/_npx/e9c2fe9985ed1095/node_modules/solidity-ast/dist/ast-dereferencer.js:76:16)                                                                                                                     
    at curried (/Users/x/.npm/_npx/e9c2fe9985ed1095/node_modules/solidity-ast/dist/ast-dereferencer.js:86:20)                                                                                                                       
    at getInheritedContractOpcodeErrors (/Users/x/.npm/_npx/e9c2fe9985ed1095/node_modules/@openzeppelin/upgrades-core/dist/validate/run.js:338:40)                                                                                  
    at getInheritedContractOpcodeErrors.next (<anonymous>)                                                                                                                                                                                
    at getContractOpcodeErrors (/Users/x/.npm/_npx/e9c2fe9985ed1095/node_modules/@openzeppelin/upgrades-core/dist/validate/run.js:259:105)                                                                                          
    at getContractOpcodeErrors.next (<anonymous>)                                                                                                                                                                                         
    at getOpcodeErrors (/Users/x/.npm/_npx/e9c2fe9985ed1095/node_modules/@openzeppelin/upgrades-core/dist/validate/run.js:248:12)                                                                                                   
    at getOpcodeErrors.next (<anonymous>)                                                                                                                                                                                                 
    at validate (/Users/x/.npm/_npx/e9c2fe9985ed1095/node_modules/@openzeppelin/upgrades-core/dist/validate/run.js:133:24) {                                                                                                        
  id: 64707,                                                                                                                                                                                                                              
  nodeType: [ 'ContractDefinition' ]                                                                                                                                                                                                      
}                                                                                                                                                                                                                                         
                                                                                                                                                                                                                                          
Node.js v18.19.1                                                                                                                                                                                                                          
] setUp() (gas: 0)                                                                                                                                                                                                                        
Suite result: FAILED. 0 passed; 1 failed; 0 skipped; finished in 3.28s (0.00ns CPU time)

Ran 1 test suite in 3.28s (3.28s CPU time): 0 tests passed, 1 failed, 0 skipped (1 total tests)

Failing tests:
Encountered 1 failing test in test/example.t.sol:UpgradeTest
[FAIL: Failed to run upgrade safety validation: /Users/x/.npm/_npx/e9c2fe9985ed1095/node_modules/solidity-ast/dist/ast-dereferencer.js:73
        throw new ASTDereferencerError(id, nodeType);                                                                                                                                                                                     
              ^                                                                                                                                                                                                                           
                                                                                                                                                                                                                                          
ASTDereferencerError: No node with id 64707 of type ContractDefinition                                                                                                                                                                    
    at deref (/Users/x/.npm/_npx/e9c2fe9985ed1095/node_modules/solidity-ast/dist/ast-dereferencer.js:73:15)                                                                                                                         
    at derefNode (/Users/x/.npm/_npx/e9c2fe9985ed1095/node_modules/solidity-ast/dist/ast-dereferencer.js:76:16)                                                                                                                     
    at curried (/Users/x/.npm/_npx/e9c2fe9985ed1095/node_modules/solidity-ast/dist/ast-dereferencer.js:86:20)                                                                                                                       
    at getInheritedContractOpcodeErrors (/Users/x/.npm/_npx/e9c2fe9985ed1095/node_modules/@openzeppelin/upgrades-core/dist/validate/run.js:338:40)                                                                                  
    at getInheritedContractOpcodeErrors.next (<anonymous>)                                                                                                                                                                                
    at getContractOpcodeErrors (/Users/x/.npm/_npx/e9c2fe9985ed1095/node_modules/@openzeppelin/upgrades-core/dist/validate/run.js:259:105)                                                                                          
    at getContractOpcodeErrors.next (<anonymous>)                                                                                                                                                                                         
    at getOpcodeErrors (/Users/x/.npm/_npx/e9c2fe9985ed1095/node_modules/@openzeppelin/upgrades-core/dist/validate/run.js:248:12)                                                                                                   
    at getOpcodeErrors.next (<anonymous>)                                                                                                                                                                                                 
    at validate (/Users/x/.npm/_npx/e9c2fe9985ed1095/node_modules/@openzeppelin/upgrades-core/dist/validate/run.js:133:24) {                                                                                                        
  id: 64707,                                                                                                                                                                                                                              
  nodeType: [ 'ContractDefinition' ]                                                                                                                                                                                                      
}                                                                                                                                                                                                                                         
                                                                                                                                                                                                                                          
Node.js v18.19.1                                                                                                                                                                                                                          
] setUp() (gas: 0)                                                                                                                                                                                                                        

Encountered a total of 1 failing tests, 0 tests succeeded

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions