fix_lint (#11)

Co-authored-by: Arthur Abeilice <afa7789@gmail.com>
Reviewed-on: https://git.p2pix.co/doiim/p2pix-smart-contracts/pulls/11
Co-authored-by: arthur <abeilice@kosmos.org>
Co-committed-by: arthur <abeilice@kosmos.org>
This commit is contained in:
arthur
2026-05-29 20:09:12 +00:00
committed by hueso
parent 1addaae1c7
commit 9cc62efb8a
21 changed files with 1086 additions and 858 deletions

View File

@@ -45,9 +45,8 @@ abstract contract BaseUtils is
!validBacenSigners(
_castAddrToKey(
ECDSA.recover(
MessageHashUtils.toEthSignedMessageHash(
_message
),
MessageHashUtils
.toEthSignedMessageHash(_message),
_signature
)
)

View File

@@ -4,19 +4,23 @@ pragma solidity ^0.8.19;
abstract contract Constants {
/// ███ Constants ██████████████████████████████████████████████████████████
uint256 constant _ROOT_UPDATED_EVENT_SIGNATURE =
uint256 internal constant _ROOT_UPDATED_EVENT_SIGNATURE =
0x0b294da292f26e55fd442b5c0164fbb9013036ff00c5cfdde0efd01c1baaf632;
uint256 constant _ALLOWED_ERC20_UPDATED_EVENT_SIGNATURE =
uint256
internal constant _ALLOWED_ERC20_UPDATED_EVENT_SIGNATURE =
0x5d6e86e5341d57a92c49934296c51542a25015c9b1782a1c2722a940131c3d9a;
uint256 constant _TRUSTED_FORWARDER_UPDATED_EVENT_SIGNATURE =
uint256
internal constant _TRUSTED_FORWARDER_UPDATED_EVENT_SIGNATURE =
0xbee55516e29d3969d3cb8eb01351eb3c52d06f9e2435bd5a8bfe3647e185df92;
/// @dev Seller casted to key => Seller's allowlist merkleroot.
/// mapping(uint256 => bytes32) public sellerAllowList;
uint256 constant _SELLER_ALLOWLIST_SLOT_SEED = 0x74dfee70;
uint256 internal constant _SELLER_ALLOWLIST_SLOT_SEED =
0x74dfee70;
/// @dev Tokens allowed to serve as the underlying amount of a deposit.
/// mapping(ERC20 => bool) public allowedERC20s;
uint256 constant _ALLOWED_ERC20_SLOT_SEED = 0xcbc9d1c4;
uint256 internal constant _ALLOWED_ERC20_SLOT_SEED =
0xcbc9d1c4;
/// @dev `balance` max. value = 10**26.
/// @dev `pixTarget` keys are restricted to 160 bits.
@@ -32,16 +36,21 @@ abstract contract Constants {
/// mstore(0x0c, _SELLER_BALANCE_SLOT_SEED)
/// mstore(0x00, seller)
/// let value := sload(keccak256(0x0c, 0x34)).
uint256 constant _SELLER_BALANCE_SLOT_SEED = 0x739094b1;
uint256 internal constant _SELLER_BALANCE_SLOT_SEED =
0x739094b1;
/// @dev The bitmask of `sellerBalance` entry.
uint256 constant BITMASK_SB_ENTRY = (1 << 94) - 1;
uint256 internal constant BITMASK_SB_ENTRY =
(1 << 94) - 1;
/// @dev The bit position of `valid` in `sellerBalance`.
uint256 constant BITPOS_VALID = 95;
uint256 internal constant BITPOS_VALID = 95;
/// @dev The scalar of BRZ token.
uint256 constant WAD = 1e18;
uint256 constant MAXBALANCE_UPPERBOUND = 1e8 ether;
uint256 constant REPUTATION_LOWERBOUND = 1e2 ether;
uint256 constant LOCKAMOUNT_UPPERBOUND = 1e6 ether;
uint256 internal constant WAD = 1e18;
uint256 internal constant MAXBALANCE_UPPERBOUND =
1e8 ether;
uint256 internal constant REPUTATION_LOWERBOUND =
1e2 ether;
uint256 internal constant LOCKAMOUNT_UPPERBOUND =
1e6 ether;
}

View File

@@ -4,7 +4,6 @@ pragma solidity ^0.8.19;
import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
library DataTypes {
struct Lock {
uint256 counter;
uint256 expirationBlock;

View File

@@ -6,9 +6,10 @@ import { ERC2771Context } from "@openzeppelin/contracts/metatx/ERC2771Context.so
abstract contract ERC2771 is ERC2771Context(address(0)) {
mapping(address => bool) public trustedForwarders;
function isTrustedForwarder(address forwarder) public view override returns (bool) {
return trustedForwarders[forwarder];
}
function isTrustedForwarder(
address forwarder
) public view override returns (bool) {
return trustedForwarders[forwarder];
}
}

View File

@@ -19,12 +19,12 @@ contract Multicall {
}
//prettier-ignore
//solhint-disable-next-line no-empty-blocks
constructor(/* */) payable {/* */}
function mtc1(Call[] calldata calls)
external
returns (uint256, bytes[] memory)
{
function mtc1(
Call[] calldata calls
) external returns (uint256, bytes[] memory) {
uint256 bn = block.number;
uint256 len = calls.length;
bytes[] memory res = new bytes[](len);
@@ -49,21 +49,14 @@ contract Multicall {
return (bn, res);
}
function mtc2(Call[] calldata calls)
external
returns (
uint256,
bytes32,
Result[] memory
)
{
function mtc2(
Call[] calldata calls
) external returns (uint256, bytes32, Result[] memory) {
uint256 bn = block.number;
// µ 0 s [0] ≡ P(IHp , µs [0], 0) ∴ P is the hash of a block of a particular number, up to a maximum age.
// 0 is left on the stack if the looked for `block.number` is >= to the current `block.number` or more than 256
// blocks behind the current block (Yellow Paper, p. 33, https://ethereum.github.io/yellowpaper/paper.pdf).
bytes32 bh = blockhash(
bn /* - 1 */
);
bytes32 bh = blockhash(bn /* - 1 */);
uint256 len = calls.length;
Result[] memory res = new Result[](len);
uint256 i;

View File

@@ -12,7 +12,6 @@ import { OwnerSettings, ERC20, SafeTransferLib } from "contracts/core/OwnerSetti
import { BaseUtils } from "contracts/core/BaseUtils.sol";
import { DataTypes as DT } from "contracts/core/DataTypes.sol";
contract P2PIX is BaseUtils {
// solhint-disable use-forbidden-name
// solhint-disable no-inline-assembly
@@ -34,15 +33,18 @@ contract P2PIX is BaseUtils {
address _reputation,
ERC20[] memory tokens,
bool[] memory tokenStates
)
)
payable
OwnerSettings(
defaultBlocks,
validSigners,
_reputation,
tokens,
defaultBlocks,
validSigners,
_reputation,
tokens,
tokenStates
)
payable {/* */}
)
{
/* */
}
/// @notice Creates a deposit order based on a seller's
/// offer of an amount of ERC20 tokens.
@@ -58,13 +60,16 @@ contract P2PIX is BaseUtils {
uint96 amount,
bool valid
) public nonReentrant {
if (bytes(pixTarget).length == 0) revert EmptyPixTarget();
if (bytes(pixTarget).length == 0)
revert EmptyPixTarget();
if (!allowedERC20s(token)) revert TokenDenied();
uint256 _sellerBalance = __sellerBalance(msg.sender, token);
uint256 _sellerBalance = __sellerBalance(
msg.sender,
token
);
uint256 currBal = _sellerBalance & BITMASK_SB_ENTRY;
uint256 _newBal = uint256(currBal + amount);
uint256 _newBal = uint256(currBal + amount);
if (_newBal > MAXBALANCE_UPPERBOUND)
revert MaxBalExceeded();
@@ -76,8 +81,8 @@ contract P2PIX is BaseUtils {
uint256 validCasted = _castBool(valid);
_setSellerBalance(
msg.sender,
token,
msg.sender,
token,
(_newBal | (validCasted << BITPOS_VALID)),
pixTargetCasted
);
@@ -97,7 +102,10 @@ contract P2PIX is BaseUtils {
/// @notice This function does not affect any ongoing active locks.
/// @dev Function sighash: 0x6d82d9e0
function setValidState(ERC20 token, bool state) public {
uint256 _sellerBalance = __sellerBalance(msg.sender, token);
uint256 _sellerBalance = __sellerBalance(
msg.sender,
token
);
if (_sellerBalance != 0) {
uint256 _valid = _castBool(state);
@@ -115,7 +123,7 @@ contract P2PIX is BaseUtils {
/// @notice Public method designed to lock an remaining amount of
/// the deposit order of a seller.
/// @notice Transaction forwarding must leave `merkleProof` empty;
/// otherwise, the trustedForwarder must be previously added
/// otherwise, the trustedForwarder must be previously added
/// to a seller whitelist.
/// @notice This method can be performed either by:
/// - An user allowed via the seller's allowlist;
@@ -144,30 +152,36 @@ contract P2PIX is BaseUtils {
uint256 bal = getBalance(seller, token);
if (bal < amount) revert NotEnoughTokens();
unchecked {
unchecked {
lockID = ++lockCounter;
}
if (
mapLocks[lockID].expirationBlock >= block.number
) revert NotExpired();
if (mapLocks[lockID].expirationBlock >= block.number)
revert NotExpired();
bytes32 _pixTarget = getPixTarget(seller, token);
// transaction forwarding must leave `merkleProof` empty;
// otherwise, the trustedForwarder must be previously added
// otherwise, the trustedForwarder must be previously added
// to a seller whitelist.
if (merkleProof.length != 0) {
_merkleVerify( merkleProof, sellerAllowList(seller), _msgSender());
} else if ( amount > REPUTATION_LOWERBOUND && msg.sender == _msgSender() ) {
uint256 spendLimit; uint256 userCredit =
userRecord[_castAddrToKey(_msgSender())];
_merkleVerify(
merkleProof,
sellerAllowList(seller),
_msgSender()
);
} else if (
amount > REPUTATION_LOWERBOUND &&
msg.sender == _msgSender()
) {
uint256 spendLimit;
uint256 userCredit = userRecord[
_castAddrToKey(_msgSender())
];
(spendLimit) = _limiter(userCredit / WAD);
if (
amount > (spendLimit * WAD) ||
amount > LOCKAMOUNT_UPPERBOUND
if (
amount > (spendLimit * WAD) ||
amount > LOCKAMOUNT_UPPERBOUND
) revert AmountNotAllowed();
}
@@ -225,14 +239,21 @@ contract P2PIX is BaseUtils {
l.amount = 0;
l.expirationBlock = 0;
_setUsedTransactions(message);
if (_msgSender() == msg.sender) {
if (msg.sender != l.buyerAddress) {
userRecord[_castAddrToKey(msg.sender)] += (lockAmount >> 1);
userRecord[_castAddrToKey(l.buyerAddress)] += (lockAmount >> 1);
} else {
userRecord[_castAddrToKey(msg.sender)] += lockAmount;
}}
if (_msgSender() == msg.sender) {
if (msg.sender != l.buyerAddress) {
userRecord[
_castAddrToKey(msg.sender)
] += (lockAmount >> 1);
userRecord[
_castAddrToKey(l.buyerAddress)
] += (lockAmount >> 1);
} else {
userRecord[
_castAddrToKey(msg.sender)
] += lockAmount;
}
}
SafeTransferLib.safeTransfer(
t,
@@ -249,9 +270,9 @@ contract P2PIX is BaseUtils {
/// @notice For each successfull unexpired lock recovered,
/// `userRecord[_castAddrToKey(l.relayerAddress)]` is decreased by half of its value.
/// @dev Function sighash: 0xb0983d39
function unlockExpired(uint256[] calldata lockIDs)
public
{
function unlockExpired(
uint256[] calldata lockIDs
) public {
uint256 i;
uint256 locksSize = lockIDs.length;
@@ -260,19 +281,21 @@ contract P2PIX is BaseUtils {
_notExpired(l);
uint256 _sellerBalance =
__sellerBalance(l.seller, l.token) & BITMASK_SB_ENTRY;
uint256 _sellerBalance = __sellerBalance(
l.seller,
l.token
) & BITMASK_SB_ENTRY;
if ((_sellerBalance + l.amount) > MAXBALANCE_UPPERBOUND)
revert MaxBalExceeded();
if (
(_sellerBalance + l.amount) >
MAXBALANCE_UPPERBOUND
) revert MaxBalExceeded();
_addSellerBalance(l.seller, l.token, l.amount);
l.amount = 0;
uint256 userKey = _castAddrToKey(
l.buyerAddress
);
uint256 userKey = _castAddrToKey(l.buyerAddress);
uint256 _newUserRecord = (userRecord[userKey] >>
1);
@@ -312,7 +335,8 @@ contract P2PIX is BaseUtils {
setValidState(token, false);
_decBal(
(__sellerBalance(msg.sender, token) & BITMASK_SB_ENTRY),
(__sellerBalance(msg.sender, token) &
BITMASK_SB_ENTRY),
amount,
token,
msg.sender
@@ -325,18 +349,15 @@ contract P2PIX is BaseUtils {
amount
);
emit DepositWithdrawn(
msg.sender,
token,
amount
);
emit DepositWithdrawn(msg.sender, token, amount);
}
function setRoot(address addr, bytes32 merkleroot)
public
{
function setRoot(
address addr,
bytes32 merkleroot
) public {
assembly ("memory-safe") {
// if (addr != msg.sender)
// if (addr != msg.sender)
if iszero(eq(addr, caller())) {
// revert OnlySeller()
mstore(0x00, 0x85d1f726)
@@ -349,8 +370,8 @@ contract P2PIX is BaseUtils {
// emit RootUpdated(addr, merkleroot);
log3(
0,
0,
0,
0,
_ROOT_UPDATED_EVENT_SIGNATURE,
addr,
merkleroot
@@ -408,14 +429,13 @@ contract P2PIX is BaseUtils {
}
// we can directly dec from packed uint entry value
_decSellerBalance(_k,_t, _amount);
_decSellerBalance(_k, _t, _amount);
}
function getBalance(address seller, ERC20 token)
public
view
returns (uint256 bal)
{
function getBalance(
address seller,
ERC20 token
) public view returns (uint256 bal) {
assembly ("memory-safe") {
for {
/* */
@@ -434,11 +454,10 @@ contract P2PIX is BaseUtils {
}
}
function getValid(address seller, ERC20 token)
public
view
returns (bool valid)
{
function getValid(
address seller,
ERC20 token
) public view returns (bool valid) {
assembly ("memory-safe") {
for {
/* */
@@ -452,7 +471,9 @@ contract P2PIX is BaseUtils {
BITMASK_SB_ENTRY,
shr(
BITPOS_VALID,
sload(add(keccak256(0x0c, 0x34), 0x01))
sload(
add(keccak256(0x0c, 0x34), 0x01)
)
)
)
break
@@ -460,11 +481,10 @@ contract P2PIX is BaseUtils {
}
}
function getPixTarget(address seller, ERC20 token)
public
view
returns (bytes32 pixTarget)
{
function getPixTarget(
address seller,
ERC20 token
) public view returns (bytes32 pixTarget) {
assembly ("memory-safe") {
for {
/* */
@@ -480,9 +500,12 @@ contract P2PIX is BaseUtils {
}
}
function getPixTargetString(address seller, ERC20 token) public view returns (string memory pixTarget) {
function getPixTargetString(
address seller,
ERC20 token
) public view returns (string memory pixTarget) {
bytes32 _pixEnc = getPixTarget(seller, token);
pixTarget = string(abi.encodePacked(_pixEnc));
pixTarget = string(abi.encodePacked(_pixEnc));
}
function getBalances(
@@ -506,7 +529,9 @@ contract P2PIX is BaseUtils {
/// @notice External getter that returns the status of a lockIDs array.
/// @notice Call will not revert if provided with an empty array as parameter.
/// @dev Function sighash: 0x49ef8448
function getLocksStatus(uint256[] memory ids)
function getLocksStatus(
uint256[] memory ids
)
external
view
returns (uint256[] memory, DT.LockStatus[] memory)