I tried asking chat-gpt but it kept shitting the be for the explaination. I have some code which looks like so:
function getAuthorityScope(bytes memory authorityScope) public pure returns (address, uint256, uint256) {
address authorityAddress;
uint256 tokenId;
// Extracting address and tokenId from the authorityScope bytes variable
assembly {
authorityAddress := mload(add(authorityScope, 20)) // Load the first 20 bytes (address size)
tokenId := mload(add(authorityScope, 52)) // Load the next 32 bytes (uint256 size)
}
return (authorityAddress, tokenId, releaseTime);
}
mload is loading from the authority scope however im trying to understand the offset.
1. Address is 20 bytes long
2. Uint256 is 32 bytes long
I'm trying to understand how 20, and then 52 works. My initial assumption is that some how the compiler is tracking where to read from the memory buffer.
e.g 0-20 is the address, and 20-52 is the uint256. However its unclear to me how the pointer to the location in memory is tracked.
Does add shift the memory pointer 20 bytes and put that into a variable.
Leaving the memory pointer at the last place read (20 bytes past the starting point).
Then the second read grabs out 32 bytes (starting from the last place read)?