Skip to content

Commit b679ec6

Browse files
committed
make slither happy
1 parent 950b501 commit b679ec6

File tree

1 file changed

+43
-38
lines changed

1 file changed

+43
-38
lines changed

contracts/src/Payer.sol

+43-38
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,12 @@ contract Payer is
7373
}
7474

7575
// keccak256(abi.encode(uint256(keccak256("xmtp.storage.Payer")) - 1)) & ~bytes32(uint256(0xff))
76-
bytes32 internal constant PayerStorageLocation = 0xd0335f337c570f3417b0f0d20340c88da711d60e810b5e9b3ecabe9ccfcdce5a;
76+
bytes32 internal constant PAYER_STORAGE_LOCATION = 0xd0335f337c570f3417b0f0d20340c88da711d60e810b5e9b3ecabe9ccfcdce5a;
7777

7878
function _getPayerStorage() internal pure returns (PayerStorage storage $) {
79+
// slither-disable-next-line assembly
7980
assembly {
80-
$.slot := PayerStorageLocation
81+
$.slot := PAYER_STORAGE_LOCATION
8182
}
8283
}
8384

@@ -116,13 +117,13 @@ contract Payer is
116117

117118
/**
118119
* @notice Initializes the contract with the deployer as admin.
119-
* @param _initialAdmin The address of the admin.
120+
* @param initialAdmin The address of the admin.
120121
* @dev There's a chicken-egg problem here with PayerReport and Distribution contracts.
121122
* We need to deploy these contracts first, then set their addresses
122123
* in the Payer contract.
123124
*/
124-
function initialize(address _initialAdmin, address _usdcToken, address _nodesContract) public initializer {
125-
if (_initialAdmin == address(0) || _usdcToken == address(0) || _nodesContract == address(0)) {
125+
function initialize(address initialAdmin, address usdcToken, address nodesContract) public initializer {
126+
if (initialAdmin == address(0) || usdcToken == address(0) || nodesContract == address(0)) {
126127
revert InvalidAddress();
127128
}
128129

@@ -138,11 +139,11 @@ contract Payer is
138139
$.maxTolerableDebtAmountMicroDollars = DEFAULT_MAX_TOLERABLE_DEBT_AMOUNT_MICRO_DOLLARS;
139140
$.transferFeesPeriod = DEFAULT_MINIMUM_TRANSFER_FEES_PERIOD;
140141

141-
_setUsdcTokenContract(_usdcToken);
142-
_setNodesContract(_nodesContract);
142+
_setUsdcTokenContract(usdcToken);
143+
_setNodesContract(nodesContract);
143144

144-
require(_grantRole(DEFAULT_ADMIN_ROLE, _initialAdmin), FailedToGrantRole(DEFAULT_ADMIN_ROLE, _initialAdmin));
145-
require(_grantRole(ADMIN_ROLE, _initialAdmin), FailedToGrantRole(ADMIN_ROLE, _initialAdmin));
145+
require(_grantRole(DEFAULT_ADMIN_ROLE, initialAdmin), FailedToGrantRole(DEFAULT_ADMIN_ROLE, initialAdmin));
146+
require(_grantRole(ADMIN_ROLE, initialAdmin), FailedToGrantRole(ADMIN_ROLE, initialAdmin));
146147
}
147148

148149
/* ============ Payers Management ============ */
@@ -394,7 +395,12 @@ contract Payer is
394395
function transferFeesToDistribution() external whenNotPaused nonReentrant {
395396
PayerStorage storage $ = _getPayerStorage();
396397

398+
/// @dev slither marks this as a security issue because validators can modify block.timestamp.
399+
/// However, in this scenario it's fine, as we'd just send fees a earlier than expected.
400+
/// It would be a bigger issue if we'd rely on timestamp for randomness or calculations.
401+
// slither-disable-next-line timestamp
397402
require(block.timestamp - $.lastFeeTransferTimestamp >= $.transferFeesPeriod, InsufficientTimePassed());
403+
398404
require($.pendingFees > 0, InsufficientAmount());
399405

400406
uint256 feesToTransfer = $.pendingFees;
@@ -413,105 +419,104 @@ contract Payer is
413419
/**
414420
* @inheritdoc IPayer
415421
*/
416-
function setDistributionContract(address _newDistributionContract) external onlyRole(ADMIN_ROLE) {
417-
_setDistributionContract(_newDistributionContract);
422+
function setDistributionContract(address newDistributionContract) external onlyRole(ADMIN_ROLE) {
423+
_setDistributionContract(newDistributionContract);
418424
}
419425

420426
/**
421427
* @inheritdoc IPayer
422428
*/
423-
function setPayerReportContract(address _newPayerReportContract) external onlyRole(ADMIN_ROLE) {
424-
_setPayerReportContract(_newPayerReportContract);
429+
function setPayerReportContract(address newPayerReportContract) external onlyRole(ADMIN_ROLE) {
430+
_setPayerReportContract(newPayerReportContract);
425431
}
426432

427433
/**
428434
* @inheritdoc IPayer
429435
*/
430-
function setNodesContract(address _newNodesContract) external onlyRole(ADMIN_ROLE) {
431-
_setNodesContract(_newNodesContract);
436+
function setNodesContract(address newNodesContract) external onlyRole(ADMIN_ROLE) {
437+
_setNodesContract(newNodesContract);
432438
}
433439

434440
/**
435441
* @inheritdoc IPayer
436442
*/
437-
function setUsdcToken(address _newUsdcToken) external onlyRole(ADMIN_ROLE) {
438-
_setUsdcTokenContract(_newUsdcToken);
443+
function setUsdcToken(address newUsdcToken) external onlyRole(ADMIN_ROLE) {
444+
_setUsdcTokenContract(newUsdcToken);
439445
}
440446

441447
/**
442448
* @inheritdoc IPayer
443449
*/
444-
function setMinimumDeposit(uint64 _newMinimumDeposit) external onlyRole(ADMIN_ROLE) {
445-
require(_newMinimumDeposit > DEFAULT_MINIMUM_DEPOSIT_AMOUNT_MICRO_DOLLARS, InvalidMinimumDeposit());
450+
function setMinimumDeposit(uint64 newMinimumDeposit) external onlyRole(ADMIN_ROLE) {
451+
require(newMinimumDeposit > DEFAULT_MINIMUM_DEPOSIT_AMOUNT_MICRO_DOLLARS, InvalidMinimumDeposit());
446452

447453
PayerStorage storage $ = _getPayerStorage();
448454

449455
uint256 oldMinimumDeposit = $.minimumDepositAmountMicroDollars;
450-
$.minimumDepositAmountMicroDollars = _newMinimumDeposit;
456+
$.minimumDepositAmountMicroDollars = newMinimumDeposit;
451457

452-
emit MinimumDepositSet(oldMinimumDeposit, _newMinimumDeposit);
458+
emit MinimumDepositSet(oldMinimumDeposit, newMinimumDeposit);
453459
}
454460

455461
/**
456462
* @inheritdoc IPayer
457463
*/
458-
function setMinimumRegistrationAmount(uint64 _newMinimumRegistrationAmount) external onlyRole(ADMIN_ROLE) {
464+
function setMinimumRegistrationAmount(uint64 newMinimumRegistrationAmount) external onlyRole(ADMIN_ROLE) {
459465
require(
460-
_newMinimumRegistrationAmount > DEFAULT_MINIMUM_REGISTRATION_AMOUNT_MICRO_DOLLARS,
466+
newMinimumRegistrationAmount > DEFAULT_MINIMUM_REGISTRATION_AMOUNT_MICRO_DOLLARS,
461467
InvalidMinimumRegistrationAmount()
462468
);
463469

464470
PayerStorage storage $ = _getPayerStorage();
465471

466472
uint256 oldMinimumRegistrationAmount = $.minimumRegistrationAmountMicroDollars;
467-
$.minimumRegistrationAmountMicroDollars = _newMinimumRegistrationAmount;
473+
$.minimumRegistrationAmountMicroDollars = newMinimumRegistrationAmount;
468474

469-
emit MinimumRegistrationAmountSet(oldMinimumRegistrationAmount, _newMinimumRegistrationAmount);
475+
emit MinimumRegistrationAmountSet(oldMinimumRegistrationAmount, newMinimumRegistrationAmount);
470476
}
471477

472478
/**
473479
* @inheritdoc IPayer
474480
*/
475-
function setWithdrawalLockPeriod(uint32 _newWithdrawalLockPeriod) external onlyRole(ADMIN_ROLE) {
476-
require(_newWithdrawalLockPeriod >= ABSOLUTE_MINIMUM_WITHDRAWAL_LOCK_PERIOD, InvalidWithdrawalLockPeriod());
481+
function setWithdrawalLockPeriod(uint32 newWithdrawalLockPeriod) external onlyRole(ADMIN_ROLE) {
482+
require(newWithdrawalLockPeriod >= ABSOLUTE_MINIMUM_WITHDRAWAL_LOCK_PERIOD, InvalidWithdrawalLockPeriod());
477483

478484
PayerStorage storage $ = _getPayerStorage();
479485

480486
uint256 oldWithdrawalLockPeriod = $.withdrawalLockPeriod;
481-
$.withdrawalLockPeriod = _newWithdrawalLockPeriod;
487+
$.withdrawalLockPeriod = newWithdrawalLockPeriod;
482488

483-
emit WithdrawalLockPeriodSet(oldWithdrawalLockPeriod, _newWithdrawalLockPeriod);
489+
emit WithdrawalLockPeriodSet(oldWithdrawalLockPeriod, newWithdrawalLockPeriod);
484490
}
485491

486492
/**
487493
* @inheritdoc IPayer
488494
*/
489-
function setMaxTolerableDebtAmount(uint64 _newMaxTolerableDebtAmountMicroDollars) external onlyRole(ADMIN_ROLE) {
490-
require(_newMaxTolerableDebtAmountMicroDollars > 0, InvalidMaxTolerableDebtAmount());
495+
function setMaxTolerableDebtAmount(uint64 newMaxTolerableDebtAmountMicroDollars) external onlyRole(ADMIN_ROLE) {
496+
require(newMaxTolerableDebtAmountMicroDollars > 0, InvalidMaxTolerableDebtAmount());
491497

492498
PayerStorage storage $ = _getPayerStorage();
493499

494500
uint64 oldMaxTolerableDebtAmount = $.maxTolerableDebtAmountMicroDollars;
495-
$.maxTolerableDebtAmountMicroDollars = _newMaxTolerableDebtAmountMicroDollars;
501+
$.maxTolerableDebtAmountMicroDollars = newMaxTolerableDebtAmountMicroDollars;
496502

497-
emit MaxTolerableDebtAmountSet(oldMaxTolerableDebtAmount, _newMaxTolerableDebtAmountMicroDollars);
503+
emit MaxTolerableDebtAmountSet(oldMaxTolerableDebtAmount, newMaxTolerableDebtAmountMicroDollars);
498504
}
499505

500506
/**
501507
* @inheritdoc IPayer
502508
*/
503-
function setTransferFeesPeriod(uint32 _newTransferFeesPeriod) external onlyRole(ADMIN_ROLE) {
504-
require(_newTransferFeesPeriod >= ABSOLUTE_MINIMUM_TRANSFER_FEES_PERIOD, InvalidTransferFeesPeriod());
509+
function setTransferFeesPeriod(uint32 newTransferFeesPeriod) external onlyRole(ADMIN_ROLE) {
510+
require(newTransferFeesPeriod >= ABSOLUTE_MINIMUM_TRANSFER_FEES_PERIOD, InvalidTransferFeesPeriod());
505511

506512
PayerStorage storage $ = _getPayerStorage();
507513

508514
uint32 oldTransferFeesPeriod = $.transferFeesPeriod;
509-
$.transferFeesPeriod = _newTransferFeesPeriod;
515+
$.transferFeesPeriod = newTransferFeesPeriod;
510516

511-
emit TransferFeesPeriodSet(oldTransferFeesPeriod, _newTransferFeesPeriod);
517+
emit TransferFeesPeriodSet(oldTransferFeesPeriod, newTransferFeesPeriod);
512518
}
513519

514-
515520
/**
516521
* @inheritdoc IPayer
517522
*/

0 commit comments

Comments
 (0)