Weird error

Here is my code :

// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;

contract Preservation{
    
    address public timeZoneLibrary ;
    address public owner ;
    uint256 storedTime ;
    //Sets the function signature for delegateCall 
    bytes4 constant setTimeSignature = bytes4(keccak256("setTime(uint256)"));
    
    constructor(
        address libraryAddr
    ){
        timeZoneLibrary = libraryAddr;
        owner = msg.sender;
    }

    function setFirstTime(uint256 _timeStamp) public {
        timeZoneLibrary.delegatecall(abi.encodePacked(setTimeSignature, _timeStamp));    
    }    
}



contract LibraryContract {
    
    // stores a timestamp 
    uint storedTime;
    
    function setTime(uint256 _timeStamp) public {
        storedTime = _timeStamp ;
        Preservation p = Preservation(address(this));
        p.owner()  = msg.sender ;
    }
}

I was trying to modify the LibraryContract's setTime function , to make it reset the owner .
In terms of the current output , it said the expression needs to be an lvalue (i.e. referring to the last line of code p.owner()) .

Anyone would figure this out for me ?
THANKS !

2 Likes
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.9;

contract Preservation{
    
    address public timeZoneLibrary ;
    address public owner ;
    uint256 storedTime ;
    //Sets the function signature for delegateCall 
    bytes4 constant setTimeSignature = bytes4(keccak256("setTime(uint256)"));
    
    constructor(address libraryAddr){
        timeZoneLibrary = libraryAddr;
        owner = msg.sender;
    }

    function setFirstTime(uint256 _timeStamp) public {
        timeZoneLibrary.delegatecall(abi.encodePacked(setTimeSignature, _timeStamp));    
    }

    //create a function in this contract that can update the contract owner variable.
    function changeOwner(address newAddress) external {
        owner = newAddress;
    }
}



contract LibraryContract {
    
    // stores a timestamp 
    uint storedTime;
    
    function setTime(uint256 _timeStamp) public {
        storedTime = _timeStamp ;
        Preservation p = Preservation(address(this));
        //p.owner()  = msg.sender ;
    }

    function setTime2(uint256 _timeStamp) public {
        storedTime = _timeStamp ;
        address addy = 0x5B38Da6a701c568545dCfcB03FcB875f56beddC4;//address of deployed preservation contract
        Preservation p = Preservation(addy);
        p.changeOwner(msg.sender);
        //p.owner()  = msg.sender ;
    }

}

But we are not able to modify the original Preservation contract
Is there any alternative way to do it ?

1 Like

Not possible.

You can update what has been programmed in the original contract.

Alright , thanks !

Defi Solutions via OpenZeppelin Forum <notifications@zeppelin.discoursemail.com> 于2023年1月4日周三 22:40写道: