I am trying to understand the basics of storage manipulation using Solidity assembly (Yul) by changing the storage slot for a variable and trying to read it afterwards to see if it's stored in the correct slot but I don't get the return value I expect when calling seeSlot():
//SPDX-License-Identifier: MIT
pragma solidity 0.8.16;
contract Assembly {
uint public age = 30;
function changeStorageSlot(uint newSlot) pure external {
bytes storage _age;
assembly {
_age.slot := newSlot
}
}
function seeSlot() external view returns(uint) {
uint _age = age;
assembly {
let sl:= sload(_age)
sl := age.slot
return (sl, 0x20)
}
}
}
What am I doing wrong?