Can't retrieve constants behind proxy #334
Answered
by
EngrPips
juliancabmar
asked this question in
Q&A
-
Hello to all. I have a doubt about how retrieve a constant on implementation behind a UUPS proxy pattern. Here is my contract: import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
// Implementation V1
contract MyContractV1 is Initializable, UUPSUpgradeable {
uint256 public value;
uint256 public WAGE_L1 = 35;
// Initializer function (replaces constructor)
function initialize(uint256 _value) public initializer {
__UUPSUpgradeable_init();
value = _value;
}
// Required by UUPSUpgradeable to authorize upgrades
function _authorizeUpgrade(address newImplementation) internal override {}
// Function to update the value
function setValue(uint256 _value) public onlyOwner {
value = _value;
}
} And tis is my test: // SPDX-License-Identifier: SEE LICENSE IN LICENSE
pragma solidity 0.8.26;
import {Test, console2} from "forge-std/Test.sol";
import {MyContractV1, MyContractV2} from "./Aux.sol";
import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";
contract AuditTests is Test {
ERC1967Proxy proxy;
MyContractV1 implementOne;
MyContractV2 implementTwo;
function testAux() public {
// Deploy One
implementOne = new MyContractV1();
// Deploy proxy and pass One address how first implementation
proxy = new ERC1967Proxy(address(implementOne), "");
// Call the initializer function on new implementation
address(proxy).call(abi.encodeCall(implementOne.initialize, (666)));
// Call WAGE_L1 constant
(, bytes memory wageL1) = address(proxy).call(abi.encodeCall(implementOne.WAGE_L1, ()));
console2.log("WAGE_L1:", abi.decode(wageL1, (uint256)));
}
} And allways obtain:
I know that is unnecessary complicate code, but I want to use |
Beta Was this translation helpful? Give feedback.
Answered by
EngrPips
May 13, 2025
Replies: 1 comment 7 replies
-
@juliancabmar If you do this |
Beta Was this translation helpful? Give feedback.
7 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
constant and immutable variables do not take a storage slot, as their value is imprinted in the bytecode of the smart contract, so the
WAGE_L1
will be stored in the bytecode of theimplementOne
contract and not in any storage slot and I think that is why you are unable to retrieve it through the proxy. Try calling thegetWageL1
function on theimplementOne
contract directly, and I expect that you will get the appropriate value returned.