Concepts
Different abi functions
- abi.encode : you can encode everything, and abi.decode all the data inside.
- abi.encodePacked : you can convert string into bytes, or you can concatenate bytes together along with other types. Doesn’t work with abi.decode. But cool for type conversion (that doesn’t work with bytes()) and to bundle lot of different types together. Note that abi.encodePacked() is a bit more gas-consumming than bytes() for simple type conversion.
Assembly
When creating a variable in memory (in the stack, inside a function like uint a;), it stores a value;
When creating a variable inside assembly, it stores a pointer to the memory address.
Arrays, bytes and string are stored differently : the first 32 bytes slot is the size, and the next slots are the different values. 1 element == 1 slot (so 6 elements of 1 bytes, takes 6*32 bytes).
To load a brand new memory slot : mload(0x40)