I want to double-check something.
I had been writing upgradable smart contact that uses a lot of constants
.
As far as I can see, smart contracts aren't storing constant
variables in their storage.
Meaning those variables can't cause memory collisions for upgradable smart contracts.
I wrote some simple code to test it myself, and that seems to be the case.
//SPDX-License-Identifier: UNLICENCED
pragma solidity 0.8.3;
contract ReadStorage {
///////////////// Main Functionality /////////////////////
uint firstVariable = 1;
// Public Constant
uint public constant secondVariable = 2;
function updateFirstVariable(uint newValue) public {
firstVariable = newValue;
}
function readFirstVariable() public view returns (uint) {
return firstVariable;
}
///////////////// Assembly Functions /////////////////////
function updateSlot(uint256 slotNumber, uint256 newValue) public {
assembly {
sstore(slotNumber, newValue)
}
}
function readSlot(uint slotNumber) public view returns (uint value) {
assembly{
value := sload(slotNumber)
}
}
}
My question now is: Where are constants
stored if not in storage? Are they somehow "embedded" in the contract during the compiling? The EVM has to read those values from somewhere. I assume the constants are maybe added to bytecode or something like that. But I wasn't able to find an explanation. So I would appreciate it if someone could explain it in more detail.