mark assembly blocks as memory-safe

This commit is contained in:
hueso 2023-05-24 14:43:33 -03:00
parent e2ae92563e
commit 8adccd2739
3 changed files with 26 additions and 26 deletions

View File

@ -20,7 +20,7 @@ abstract contract BaseUtils is
/// Helper FX /// Helper FX
function _setUsedTransactions(bytes32 message) internal { function _setUsedTransactions(bytes32 message) internal {
assembly { assembly ("memory-safe") {
sstore(message, true) sstore(message, true)
} }
} }
@ -28,7 +28,7 @@ abstract contract BaseUtils is
function usedTransactions( function usedTransactions(
bytes32 message bytes32 message
) public view returns (bool used) { ) public view returns (bool used) {
assembly { assembly ("memory-safe") {
used := sload(message) used := sload(message)
} }
} }
@ -71,7 +71,7 @@ abstract contract BaseUtils is
function _castBool( function _castBool(
bool _valid bool _valid
) internal pure returns (uint256 _validCasted) { ) internal pure returns (uint256 _validCasted) {
assembly { assembly ("memory-safe") {
_validCasted := _valid _validCasted := _valid
} }
} }
@ -80,7 +80,7 @@ abstract contract BaseUtils is
string memory str string memory str
) public pure returns (bytes32 strEnc) { ) public pure returns (bytes32 strEnc) {
bytes memory enc = bytes(abi.encodePacked(str)); bytes memory enc = bytes(abi.encodePacked(str));
assembly { assembly ("memory-safe") {
if lt(0x20, mload(enc)) { if lt(0x20, mload(enc)) {
invalid() invalid()
} }
@ -94,7 +94,7 @@ abstract contract BaseUtils is
uint256 _packed, uint256 _packed,
bytes32 _pixTarget bytes32 _pixTarget
) internal { ) internal {
assembly { assembly ("memory-safe") {
mstore(0x20, _erc20) mstore(0x20, _erc20)
mstore(0x0c, _SELLER_BALANCE_SLOT_SEED) mstore(0x0c, _SELLER_BALANCE_SLOT_SEED)
mstore(0x00, _sellerKey) mstore(0x00, _sellerKey)
@ -109,7 +109,7 @@ abstract contract BaseUtils is
ERC20 _erc20, ERC20 _erc20,
uint256 _packed uint256 _packed
) internal { ) internal {
assembly { assembly ("memory-safe") {
mstore(0x20, _erc20) mstore(0x20, _erc20)
mstore(0x0c, _SELLER_BALANCE_SLOT_SEED) mstore(0x0c, _SELLER_BALANCE_SLOT_SEED)
mstore(0x00, _sellerKey) mstore(0x00, _sellerKey)
@ -123,7 +123,7 @@ abstract contract BaseUtils is
ERC20 _erc20, ERC20 _erc20,
uint256 _amount uint256 _amount
) internal { ) internal {
assembly { assembly ("memory-safe") {
mstore(0x20, _erc20) mstore(0x20, _erc20)
mstore(0x0c, _SELLER_BALANCE_SLOT_SEED) mstore(0x0c, _SELLER_BALANCE_SLOT_SEED)
mstore(0x00, _sellerKey) mstore(0x00, _sellerKey)
@ -137,7 +137,7 @@ abstract contract BaseUtils is
ERC20 _erc20, ERC20 _erc20,
uint256 _amount uint256 _amount
) internal { ) internal {
assembly { assembly ("memory-safe") {
mstore(0x20, _erc20) mstore(0x20, _erc20)
mstore(0x0c, _SELLER_BALANCE_SLOT_SEED) mstore(0x0c, _SELLER_BALANCE_SLOT_SEED)
mstore(0x00, _sellerKey) mstore(0x00, _sellerKey)
@ -150,7 +150,7 @@ abstract contract BaseUtils is
address _sellerKey, address _sellerKey,
ERC20 _erc20 ERC20 _erc20
) internal view returns (uint256 _packed) { ) internal view returns (uint256 _packed) {
assembly { assembly ("memory-safe") {
mstore(0x20, _erc20) mstore(0x20, _erc20)
mstore(0x0c, _SELLER_BALANCE_SLOT_SEED) mstore(0x0c, _SELLER_BALANCE_SLOT_SEED)
mstore(0x00, _sellerKey) mstore(0x00, _sellerKey)
@ -165,7 +165,7 @@ abstract contract BaseUtils is
address _addr address _addr
) public pure returns (uint256 _key) { ) public pure returns (uint256 _key) {
// _key = uint256(uint160(address(_addr))) << 12; // _key = uint256(uint160(address(_addr))) << 12;
assembly { assembly ("memory-safe") {
_key := shl(0xc, _addr) _key := shl(0xc, _addr)
} }
} }
@ -174,7 +174,7 @@ abstract contract BaseUtils is
uint256 _key uint256 _key
) public pure returns (address _addr) { ) public pure returns (address _addr) {
// _addr = address(uint160(uint256(_key >> 12))); // _addr = address(uint160(uint256(_key >> 12)));
assembly { assembly ("memory-safe") {
_addr := shr(0xc, _key) _addr := shr(0xc, _key)
} }
} }

View File

@ -46,7 +46,7 @@ abstract contract OwnerSettings is
address[] memory forwarders, address[] memory forwarders,
bool[] memory states bool[] memory states
) external onlyOwner { ) external onlyOwner {
assembly { assembly ("memory-safe") {
// first 32 bytes eq to array's length // first 32 bytes eq to array's length
let fLen := mload(forwarders) let fLen := mload(forwarders)
// halts execution if forwarders.length eq 0 // halts execution if forwarders.length eq 0
@ -95,7 +95,7 @@ abstract contract OwnerSettings is
function setReputation( function setReputation(
IReputation _reputation IReputation _reputation
) public onlyOwner { ) public onlyOwner {
assembly { assembly ("memory-safe") {
sstore(reputation.slot, _reputation) sstore(reputation.slot, _reputation)
} }
emit ReputationUpdated(address(_reputation)); emit ReputationUpdated(address(_reputation));
@ -104,7 +104,7 @@ abstract contract OwnerSettings is
function setDefaultLockBlocks( function setDefaultLockBlocks(
uint256 _blocks uint256 _blocks
) public onlyOwner { ) public onlyOwner {
assembly { assembly ("memory-safe") {
sstore(defaultLockBlocks.slot, _blocks) sstore(defaultLockBlocks.slot, _blocks)
} }
emit LockBlocksUpdated(_blocks); emit LockBlocksUpdated(_blocks);
@ -113,7 +113,7 @@ abstract contract OwnerSettings is
function setValidSigners( function setValidSigners(
address[] memory _validSigners address[] memory _validSigners
) public onlyOwner { ) public onlyOwner {
assembly { assembly ("memory-safe") {
let i := add(_validSigners, 0x20) let i := add(_validSigners, 0x20)
let end := add(i, shl(0x05, mload(_validSigners))) let end := add(i, shl(0x05, mload(_validSigners)))
for { for {
@ -137,7 +137,7 @@ abstract contract OwnerSettings is
bool[] memory _states bool[] memory _states
) public onlyOwner { ) public onlyOwner {
/* Yul Impl */ /* Yul Impl */
assembly { assembly ("memory-safe") {
// first 32 bytes eq to array's length // first 32 bytes eq to array's length
let tLen := mload(_tokens) let tLen := mload(_tokens)
// NoTokens() // NoTokens()
@ -181,7 +181,7 @@ abstract contract OwnerSettings is
function validBacenSigners( function validBacenSigners(
uint256 signer uint256 signer
) public view returns (bool valid) { ) public view returns (bool valid) {
assembly { assembly ("memory-safe") {
valid := sload(signer) valid := sload(signer)
} }
} }
@ -189,7 +189,7 @@ abstract contract OwnerSettings is
function sellerAllowList( function sellerAllowList(
address sellerKey address sellerKey
) public view returns (bytes32 root) { ) public view returns (bytes32 root) {
assembly { assembly ("memory-safe") {
mstore(0x0c, _SELLER_ALLOWLIST_SLOT_SEED) mstore(0x0c, _SELLER_ALLOWLIST_SLOT_SEED)
mstore(0x00, sellerKey) mstore(0x00, sellerKey)
root := sload(keccak256(0x00, 0x20)) root := sload(keccak256(0x00, 0x20))
@ -199,7 +199,7 @@ abstract contract OwnerSettings is
function allowedERC20s( function allowedERC20s(
ERC20 erc20 ERC20 erc20
) public view returns (bool state) { ) public view returns (bool state) {
assembly { assembly ("memory-safe") {
mstore(0x0c, _ALLOWED_ERC20_SLOT_SEED) mstore(0x0c, _ALLOWED_ERC20_SLOT_SEED)
mstore(0x00, erc20) mstore(0x00, erc20)
state := sload(keccak256(0x0c, 0x20)) state := sload(keccak256(0x0c, 0x20))
@ -215,7 +215,7 @@ abstract contract OwnerSettings is
_userCredit _userCredit
); );
bool success; bool success;
assembly { assembly ("memory-safe") {
success := staticcall( success := staticcall(
// gas // gas
gas(), gas(),

View File

@ -297,7 +297,7 @@ contract P2PIX is BaseUtils {
} }
} }
assembly { assembly ("memory-safe") {
if lt(i, locksSize) { if lt(i, locksSize) {
// LoopOverflow() // LoopOverflow()
mstore(0x00, 0xdfb035c9) mstore(0x00, 0xdfb035c9)
@ -344,7 +344,7 @@ contract P2PIX is BaseUtils {
function setRoot(address addr, bytes32 merkleroot) function setRoot(address addr, bytes32 merkleroot)
public public
{ {
assembly { assembly ("memory-safe") {
// if (addr != msg.sender) // if (addr != msg.sender)
if iszero(eq(addr, caller())) { if iszero(eq(addr, caller())) {
// revert OnlySeller() // revert OnlySeller()
@ -404,7 +404,7 @@ contract P2PIX is BaseUtils {
ERC20 _t, ERC20 _t,
address _k address _k
) private { ) private {
assembly { assembly ("memory-safe") {
if iszero( if iszero(
iszero( iszero(
or( or(
@ -428,7 +428,7 @@ contract P2PIX is BaseUtils {
view view
returns (uint256 bal) returns (uint256 bal)
{ {
assembly { assembly ("memory-safe") {
for { for {
/* */ /* */
} iszero(returndatasize()) { } iszero(returndatasize()) {
@ -451,7 +451,7 @@ contract P2PIX is BaseUtils {
view view
returns (bool valid) returns (bool valid)
{ {
assembly { assembly ("memory-safe") {
for { for {
/* */ /* */
} iszero(returndatasize()) { } iszero(returndatasize()) {
@ -477,7 +477,7 @@ contract P2PIX is BaseUtils {
view view
returns (bytes32 pixTarget) returns (bytes32 pixTarget)
{ {
assembly { assembly ("memory-safe") {
for { for {
/* */ /* */
} iszero(returndatasize()) { } iszero(returndatasize()) {