Tuples, revert, keccak256
Last updated
Last updated
memory allows us to deal with data types that are larger than 32 bytes
if we want to return a struct or an array within one function, this would not be possible with a single variable, if that struct/array is larger than 32 bytes
we can do this in Yul by simply denoting the boundaries/area of memory whose values we wish to return (this is what Solidity does under the hood)
function return2and4() external pure returns (uint256, uint256) {
assembly {
mstore(0x00, 2)
mstore(0x20, 4)
when we want to revert a statement, we also have to specify an area in memory to store the revert values, just like return
Solidity obscures the fact that in a revert case, data can still be sent so caller can debug it
Most of the time, we want to revert just so that execution stops, and not return a value. we can do this with: revert(0, 0)
values in abi.encode
are stored in memory in solidity:
// Solidity example
function hashV1() external pure returns (bytes32) {
bytes memory toBeHashed = abi.encode(1, 2, 3);
return
in Yul, keccak256
takes in the start location in memory of the variables to be hashed, and how many bytes of data (0x60
in this case)