Contract not Upgrading through script

Create an upgradeable contract using UUPS pattern.

The main implementation contract inherits a parent contract(also UUPS);
the child initialize calls parent initialize having ownable.

Implementation(Child) initialize:

    function initializeChild() external initializer {
        super.initializeParent(); // calling parent initializer
        isInitialized = true; // intialized to true
    }

Implementation(Parent) initialize:

    function initializeParent() internal onlyInitializing {
        // initialize function
        __Ownable_init(msg.sender);
    }

Deployed above contract on Foundry(Anvil) using script:

    function run() external returns (address) {
        child_Implment = new implementChild(); // deploying contract
        ERC1967Proxy proxy = new ERC1967Proxy(address(child_Implment), ""); // deplying proxy and pointing to implement
        return address(proxy); // proxy address
    }

This works properly, the issue arises when i tries to upgrade to a new implementation.

New implementation(child):

/// @custom:oz-upgrades-unsafe-allow constructor
    constructor() {
        _disableInitializers(); // avoid front running of initialzer
    }

    function initializeChildUp() external reinitializer(2) {
        super.initializeParent(); // calling parent initializer
        isInitialize = false; // intialized to true
    }

New parent:

    function initializeParent() internal onlyInitializing {
        // initialize function
        __Ownable_init(msg.sender);
    }

The script for upgrade (takes proxy address as argument):

    function run(address newProxy) external returns(address) {
        implement_Up = new upgradedImplement(); // deploying contract
        implementChild child_Proxy = implementChild(newProxy); // pointing proxy to old implement
        child_Proxy.upgradeToAndCall(address(implement_Up), ""); // calling upgrade function and pointing proxy to new implement
        return address(child_Proxy); // proxy address
    }
}

when running the script in anvil, cast send UpgradeScript_Contract_Address 'run(address)' proxy_Address --private-key $pvt_key;
it shows error:
server returned an error response: error code 3: execution reverted: custom error 0x118cdaa7: 000000000000000000000000f39fd6e51aad88f6f4ce6ab88 27279cfffb92266, data: "0x118cdaa7000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb92266"

0x118cdaa7 is function selector of OwnableUnauthorizedAccount(address) error and f39fd6e51aad88f6f4ce6ab8827279cfffb92266" is caller which is pvt key used to deploy the main implementation contract using script

If the error is like above, maybe the caller account is not the owner, so you can check the permission of the caller account.

yes figure that out already..an upgradeable contract(with ownable library) once initialized cannot be upgraded with script, it can be upgraded with the owner as the caller.

2 Likes