Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ remappings = [

[fmt]
line_length = 100 # While we allow up to 120, we lint at 100 for readability.
ignore = ["src/accounts/EIP7702Proxy.sol"]

[profile.default.fuzz]
runs = 256
Expand Down
4 changes: 3 additions & 1 deletion src/accounts/ERC1271.sol
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ abstract contract ERC1271 is EIP712 {
virtual
returns (bool result)
{
if (_erc1271CallerIsSafe()) result = _erc1271IsValidSignatureNowCalldata(hash, signature);
if (_erc1271CallerIsSafe()) {
result = _erc1271IsValidSignatureNowCalldata(hash, signature);
}
}

/// @dev ERC1271 signature validation (Nested EIP-712 workflow).
Expand Down
14 changes: 7 additions & 7 deletions src/accounts/ERC4337.sol
Original file line number Diff line number Diff line change
Expand Up @@ -340,14 +340,13 @@ abstract contract ERC4337 is Ownable, UUPSUpgradeable, Receiver, ERC1271 {
assembly {
mstore(0x20, address()) // Store the `account` argument.
mstore(0x00, 0x70a08231) // `balanceOf(address)`.
result :=
mul( // Returns 0 if the EntryPoint does not exist.
mload(0x20),
and( // The arguments of `and` are evaluated from right to left.
gt(returndatasize(), 0x1f), // At least 32 bytes returned.
staticcall(gas(), ep, 0x1c, 0x24, 0x20, 0x20)
)
result := mul( // Returns 0 if the EntryPoint does not exist.
mload(0x20),
and( // The arguments of `and` are evaluated from right to left.
gt(returndatasize(), 0x1f), // At least 32 bytes returned.
staticcall(gas(), ep, 0x1c, 0x24, 0x20, 0x20)
)
)
}
}

Expand All @@ -356,6 +355,7 @@ abstract contract ERC4337 is Ownable, UUPSUpgradeable, Receiver, ERC1271 {
address ep = entryPoint();
/// @solidity memory-safe-assembly
assembly {

// The EntryPoint has balance accounting logic in the `receive()` function, as defined in ERC-4337.
// forgefmt: disable-next-item
if iszero(mul(extcodesize(ep), call(gas(), ep, callvalue(), codesize(), 0x00, codesize(), 0x00))) {
Expand Down
13 changes: 6 additions & 7 deletions src/accounts/ERC6551.sol
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,13 @@ abstract contract ERC6551 is UUPSUpgradeable, Receiver, ERC1271 {
let tokenContract := mload(0x20)
// `tokenId` is already at 0x40.
mstore(0x20, 0x6352211e) // `ownerOf(uint256)`.
result :=
mul( // Returns `address(0)` on failure or if contract does not exist.
mload(0x20),
and(
gt(returndatasize(), 0x1f),
staticcall(gas(), tokenContract, 0x3c, 0x24, 0x20, 0x20)
)
result := mul( // Returns `address(0)` on failure or if contract does not exist.
mload(0x20),
and(
gt(returndatasize(), 0x1f),
staticcall(gas(), tokenContract, 0x3c, 0x24, 0x20, 0x20)
)
)
}
mstore(0x40, m) // Restore the free memory pointer.
}
Expand Down
5 changes: 3 additions & 2 deletions src/accounts/LibERC7579.sol
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,9 @@ library LibERC7579 {
function hasOpData(bytes calldata executionData) internal pure returns (bool result) {
/// @solidity memory-safe-assembly
assembly {
result :=
iszero(or(lt(executionData.length, 0x40), lt(calldataload(executionData.offset), 0x40)))
result := iszero(
or(lt(executionData.length, 0x40), lt(calldataload(executionData.offset), 0x40))
)
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/accounts/Timelock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ contract Timelock is ERC7821, EnumerableRoles {
Waiting, // 1.
Ready, // 2.
Done // 3.

}

/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
Expand Down Expand Up @@ -384,7 +383,9 @@ contract Timelock is ERC7821, EnumerableRoles {
Call[] calldata calls,
bytes calldata opData
) internal virtual override(ERC7821) {
if (!hasRole(OPEN_ROLE_HOLDER, EXECUTOR_ROLE)) _checkRole(EXECUTOR_ROLE);
if (!hasRole(OPEN_ROLE_HOLDER, EXECUTOR_ROLE)) {
_checkRole(EXECUTOR_ROLE);
}
bytes32 id;
uint256 s;
/// @solidity memory-safe-assembly
Expand Down
9 changes: 4 additions & 5 deletions src/auth/EnumerableRoles.sol
Original file line number Diff line number Diff line change
Expand Up @@ -296,11 +296,10 @@ abstract contract EnumerableRoles {
/// @solidity memory-safe-assembly
assembly {
mstore(0x00, 0x8da5cb5b) // `owner()`.
result :=
and(
and(eq(caller(), mload(0x00)), gt(returndatasize(), 0x1f)),
staticcall(gas(), address(), 0x1c, 0x04, 0x00, 0x20)
)
result := and(
and(eq(caller(), mload(0x00)), gt(returndatasize(), 0x1f)),
staticcall(gas(), address(), 0x1c, 0x04, 0x00, 0x20)
)
}
}

Expand Down
24 changes: 13 additions & 11 deletions src/auth/TimedRoles.sol
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,12 @@ abstract contract TimedRoles {
}

/// @dev Checks that the caller is authorized to set the timed role.
function _authorizeSetTimedRole(address holder, uint256 timedRole, uint40 start, uint40 expires)
internal
virtual
{
function _authorizeSetTimedRole(
address holder,
uint256 timedRole,
uint40 start,
uint40 expires
) internal virtual {
if (!_timedRolesSenderIsContractOwner()) _revertTimedRolesUnauthorized();
// Silence compiler warning on unused variables.
(holder, timedRole, start, expires) = (holder, timedRole, start, expires);
Expand All @@ -193,8 +195,9 @@ abstract contract TimedRoles {
encodedTimeRoles := add(0x20, encodedTimeRoles)
mstore(0x00, mload(encodedTimeRoles))
let p := sload(keccak256(0x00, 0x38))
result :=
iszero(or(lt(timestamp(), shr(216, p)), gt(timestamp(), and(0xffffffffff, p))))
result := iszero(
or(lt(timestamp(), shr(216, p)), gt(timestamp(), and(0xffffffffff, p)))
)
}
}
}
Expand Down Expand Up @@ -263,11 +266,10 @@ abstract contract TimedRoles {
/// @solidity memory-safe-assembly
assembly {
mstore(0x00, 0x8da5cb5b) // `owner()`.
result :=
and(
and(eq(caller(), mload(0x00)), gt(returndatasize(), 0x1f)),
staticcall(gas(), address(), 0x1c, 0x04, 0x00, 0x20)
)
result := and(
and(eq(caller(), mload(0x00)), gt(returndatasize(), 0x1f)),
staticcall(gas(), address(), 0x1c, 0x04, 0x00, 0x20)
)
}
}

Expand Down
13 changes: 6 additions & 7 deletions src/tokens/ERC4626.sol
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,12 @@ abstract contract ERC4626 is ERC20 {
// Store the function selector of `decimals()`.
mstore(0x00, 0x313ce567)
// Arguments are evaluated last to first.
success :=
and(
// Returned value is less than 256, at left-padded to 32 bytes.
and(lt(mload(0x00), 0x100), gt(returndatasize(), 0x1f)),
// The staticcall succeeds.
staticcall(gas(), underlying, 0x1c, 0x04, 0x00, 0x20)
)
success := and(
// Returned value is less than 256, at left-padded to 32 bytes.
and(lt(mload(0x00), 0x100), gt(returndatasize(), 0x1f)),
// The staticcall succeeds.
staticcall(gas(), underlying, 0x1c, 0x04, 0x00, 0x20)
)
result := mul(mload(0x00), success)
}
}
Expand Down
11 changes: 3 additions & 8 deletions src/tokens/ERC6909.sol
Original file line number Diff line number Diff line change
Expand Up @@ -486,10 +486,7 @@ abstract contract ERC6909 {
/// @dev Sets `amount` as the allowance of `spender` for `owner` for token `id`.
///
/// Emits a {Approval} event.
function _approve(address owner, address spender, uint256 id, uint256 amount)
internal
virtual
{
function _approve(address owner, address spender, uint256 id, uint256 amount) internal virtual {
/// @solidity memory-safe-assembly
assembly {
// Compute the allowance slot and store the amount.
Expand Down Expand Up @@ -535,13 +532,11 @@ abstract contract ERC6909 {
/// This includes minting and burning.
function _beforeTokenTransfer(address from, address to, uint256 id, uint256 amount)
internal
virtual
{}
virtual {}

/// @dev Hook that is called after any transfer of tokens.
/// This includes minting and burning.
function _afterTokenTransfer(address from, address to, uint256 id, uint256 amount)
internal
virtual
{}
virtual {}
}
5 changes: 3 additions & 2 deletions src/utils/Base58.sol
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,10 @@ library Base58 {
o := add(o, w)
mstore8(o, mload(mod(v, 58)))
}
for {} iszero(byte(z, data)) { z := add(z, 1) } {} // Just loop, `z` is often tiny.
for {} // Just loop, `z` is often tiny.
iszero(byte(z, data)) { z := add(z, 1) } {}
}
if z { mstore(sub(o, 0x20), mul(div(w, 0xff), 49)) } // '1111...1111' in ASCII.
if z { mstore(sub(o, 0x20), mul(div(w, 0xff), 49))} // '1111...1111' in ASCII.
o := sub(o, z)

let n := sub(e, o) // Compute the final length.
Expand Down
6 changes: 1 addition & 5 deletions src/utils/Base64.sol
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,7 @@ library Base64 {

/// @dev Encodes `data` using the base64 encoding described in RFC 4648.
/// Equivalent to `encode(data, fileSafe, false)`.
function encode(bytes memory data, bool fileSafe)
internal
pure
returns (string memory result)
{
function encode(bytes memory data, bool fileSafe) internal pure returns (string memory result) {
result = encode(data, fileSafe, false);
}

Expand Down
15 changes: 8 additions & 7 deletions src/utils/DateTimeLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,10 @@ library DateTimeLib {
assembly {
// `daysInMonths = [31,28,31,30,31,30,31,31,30,31,30,31]`.
// `result = daysInMonths[month - 1] + isLeapYear(year)`.
result :=
add(byte(month, shl(152, 0x1f1c1f1e1f1e1f1f1e1f1e1f)), and(eq(month, 2), flag))
result := add(
byte(month, shl(152, 0x1f1c1f1e1f1e1f1f1e1f1e1f)),
and(eq(month, 2), flag)
)
}
}

Expand All @@ -206,11 +208,10 @@ library DateTimeLib {
uint256 md = daysInMonth(year, month);
/// @solidity memory-safe-assembly
assembly {
result :=
and(
lt(sub(year, 1970), sub(MAX_SUPPORTED_YEAR, 1969)),
and(lt(sub(month, 1), 12), lt(sub(day, 1), md))
)
result := and(
lt(sub(year, 1970), sub(MAX_SUPPORTED_YEAR, 1969)),
and(lt(sub(month, 1), 12), lt(sub(day, 1), md))
)
}
}

Expand Down
22 changes: 6 additions & 16 deletions src/utils/DynamicArrayLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,9 @@ library DynamicArrayLib {
let arrLen := mload(arrData)
if iszero(lt(n, arrLen)) {
calldatacopy(
add(arrData, shl(5, add(1, arrLen))), calldatasize(), shl(5, sub(n, arrLen))
add(arrData, shl(5, add(1, arrLen))),
calldatasize(),
shl(5, sub(n, arrLen))
)
}
mstore(arrData, n)
Expand Down Expand Up @@ -802,23 +804,15 @@ library DynamicArrayLib {
}

/// @dev Returns the underlying array as a `uint256[]`.
function asUint256Array(DynamicArray memory a)
internal
pure
returns (uint256[] memory result)
{
function asUint256Array(DynamicArray memory a) internal pure returns (uint256[] memory result) {
/// @solidity memory-safe-assembly
assembly {
result := mload(a)
}
}

/// @dev Returns the underlying array as a `address[]`.
function asAddressArray(DynamicArray memory a)
internal
pure
returns (address[] memory result)
{
function asAddressArray(DynamicArray memory a) internal pure returns (address[] memory result) {
/// @solidity memory-safe-assembly
assembly {
result := mload(a)
Expand All @@ -834,11 +828,7 @@ library DynamicArrayLib {
}

/// @dev Returns the underlying array as a `bytes32[]`.
function asBytes32Array(DynamicArray memory a)
internal
pure
returns (bytes32[] memory result)
{
function asBytes32Array(DynamicArray memory a) internal pure returns (bytes32[] memory result) {
/// @solidity memory-safe-assembly
assembly {
result := mload(a)
Expand Down
3 changes: 2 additions & 1 deletion src/utils/ECDSA.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ library ECDSA {
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

/// @dev The order of the secp256k1 elliptic curve.
uint256 internal constant N = 0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141;
uint256 internal constant N =
0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141;

/// @dev `N/2 + 1`. Used for checking the malleability of the signature.
uint256 private constant _HALF_N_PLUS_1 =
Expand Down
Loading