1

i have an upgradable smart contract with 3 mappings, i set only the first two in the initialize function .

pragma solidity ^0.8.0;

contract ContractA {
    mapping(uint256 => address) public mappingA;
    mapping(uint256 => address) public mappingB;
    mapping(address => bool) public mappingC;

    bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;

    bool public initialized;

    function initialize(bytes calldata params) public {
        if (initialized) revert();
        initialized = true;

        (address _addressA, address _addressB) = abi.decode(params, (address, address));
        mappingA[0] = _addressA;
        mappingB[0] = _addressB;

    }

    function setMappingC(address _addressC) public  {
        mappingC[_addressC] = true;
    }

    function upgrade(
        address newImplementation,
        address _addressA, 
        address _addressB
    ) public {

        bytes memory params = abi.encode(_addressA, _addressB);

        (bool success, ) = newImplementation.delegatecall(abi.encodeWithSelector(this.initialize.selector, params));

        if (!success) revert();

        assembly {
            sstore(_IMPLEMENTATION_SLOT, newImplementation)
        }
    }
}

is there any potential problems ( E.g. with storage ) regarding the third one mappingC when calling setMappingC through the proxy, or in a future upgrade ? since the Proxy does not have the MappingC context .

1 Answer 1

0

First thing first. I would advise you to use well tested libraries ofr upgradable smart contracts(OpenZeppelin UUPS and such) if you are developing anything of significance.

If however you are doing this just to learn more about the concept of upgradable SmartContracts, I would love to answer your questions.

That said, I am not sure as to what exactly you question is.

I don't have your proxy contact code, but what you wrote here seems very similar to UUPS design patterns (You upgrade logic is inside implementation contact).

You should have no issues with mappingC. But mappingA might conflict with first storage slot of your proxy contact.

In short, I would need to see the code of the Proxy contact to give you correct answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.