int8, int128, int256
The storage of int8, int128, int256 in memory are very simple, they are written directly at our chosen
memory location and are returned the same. Yul wraps around negative int[n] values.
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.0;
contract Yul {
function int8InMemory(int8 value) public pure returns (bytes32) {
assembly {
mstore(0x80, value)
return(0x80, 0x20)
}
}
function int128InMemory(int128 value) public pure returns (bytes32) {
assembly {
mstore(0x80, value)
return(0x80, 0x20)
}
}
function int256InMemory(int256 value) public pure returns (bytes32) {
assembly {
mstore(0x80, value)
return(0x80, 0x20)
}
}
}
🚨 Due to the tricky nature of the storage of
int[n]types, apply more care when storing and manipulating values from storage.
🚨 Do not store negative
int[n]values directly from your Yul block of code, Yul treats it as auint[n]type overflow, meaning that-1will be converted to(2^256) - 1. This can lead to security breaches. Yul wraps around negativeint[n]values.