Skip to content

Commit

Permalink
feat: blacklist full string instead of substrings
Browse files Browse the repository at this point in the history
  • Loading branch information
TuDo1403 committed Nov 14, 2023
1 parent c212df2 commit e8ccaa4
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ contract Migration__20231106_RevertRenewalFees is RNSDeploy {
vm.broadcast(domainPrice.getRoleMember(domainPrice.DEFAULT_ADMIN_ROLE(), 0));
vm.resumeGasMetering();
domainPrice.setRenewalFeeByLengths(config.renewalFees);
vm.pauseGasMetering();
vm.pauseGasMetering();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import { ProxyAdmin } from "@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol";
import {
ITransparentUpgradeableProxy,
TransparentUpgradeableProxy
} from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
import { NameChecker } from "@rns-contracts/NameChecker.sol";
import { ContractKey } from "foundry-deployment-kit/configs/ContractConfig.sol";
import { RNSDeploy } from "script/RNSDeploy.s.sol";

contract Migration__20231114_DeployNameCheckerLogic is RNSDeploy {
function run() public trySetUp {
address newLogic = _deployLogic(ContractKey.NameChecker);

NameChecker currentNameChecker = NameChecker(_config.getAddressFromCurrentNetwork(ContractKey.NameChecker));
assertTrue(currentNameChecker.forbidden("hell"));
assertTrue(currentNameChecker.forbidden("hellscream"));

address proxyAdmin = _getProxyAdmin(address(currentNameChecker));
vm.prank(ProxyAdmin(proxyAdmin).owner());
ProxyAdmin(proxyAdmin).upgrade(ITransparentUpgradeableProxy(address(currentNameChecker)), newLogic);

assertTrue(currentNameChecker.forbidden("hell"));
assertFalse(currentNameChecker.forbidden("hellscream"));
}
}
17 changes: 3 additions & 14 deletions src/NameChecker.sol
Original file line number Diff line number Diff line change
Expand Up @@ -45,25 +45,14 @@ contract NameChecker is Initializable, AccessControlEnumerable, INameChecker {
* @inheritdoc INameChecker
*/
function forbidden(string calldata name) public view returns (bool) {
return containsInvalidCharacter(name) || containsBlacklistedWord(name);
return containsInvalidCharacter(name) || isBlacklistedWord(name);
}

/**
* @inheritdoc INameChecker
*/
function containsBlacklistedWord(string calldata name) public view returns (bool) {
string[] memory sstrs = getAllSubStrings(name);
uint256 length = sstrs.length;

for (uint256 i; i < length;) {
if (_forbiddenWordMap.get(pack(sstrs[i]))) return true;

unchecked {
++i;
}
}

return false;
function isBlacklistedWord(string calldata name) public view returns (bool) {
return _forbiddenWordMap.get(pack(name));
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/interfaces/INameChecker.sol
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ interface INameChecker {
function forbidden(string calldata name) external view returns (bool);

/**
* @notice Checks if a given name contains any blacklisted words.
* @notice Checks if a given name is blacklisted.
* @param name The string to check.
* @return true if the name contains blacklisted words, false otherwise.
* @return true if the name is blacklisted, false otherwise.
*/
function containsBlacklistedWord(string calldata name) external view returns (bool);
function isBlacklistedWord(string calldata name) external view returns (bool);

/**
* @notice Checks if a given name contains any invalid characters.
Expand Down

0 comments on commit e8ccaa4

Please sign in to comment.