Skip to content

Commit

Permalink
Merge pull request #73 from danut13/fix-role-name-validation
Browse files Browse the repository at this point in the history
fix: role name validation
  • Loading branch information
danut13 authored Nov 26, 2024
2 parents 7148aac + e10ac09 commit 479f838
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
5 changes: 3 additions & 2 deletions script/helpers/PantosBaseAddresses.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {PantosBaseScript} from "./PantosBaseScript.s.sol";

abstract contract PantosBaseAddresses is PantosBaseScript {
enum Contract {
GENERIC,
HUB_PROXY,
HUB_INIT,
DIAMOND_CUT_FACET,
Expand Down Expand Up @@ -67,9 +68,9 @@ abstract contract PantosBaseAddresses is PantosBaseScript {
string private constant _contractSerializer = "address";

mapping(BlockchainId => mapping(Contract => ContractInfo))
private _otherChaincontractInfo;
internal _otherChaincontractInfo;
mapping(Contract => CurrentChainContractInfo)
private _currentChainContractInfo;
internal _currentChainContractInfo;
mapping(string => Contract) internal _keysToContracts;

Blockchain private thisBlockchain;
Expand Down
20 changes: 18 additions & 2 deletions script/helpers/SafeAddresses.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,21 @@ contract SafeAddresses is PantosBaseScript {

Blockchain private thisBlockchain;

modifier onlyValidRoleName(string memory roleName) {
bool isValidRoleName = false;
for (uint256 i = 0; i < getRolesLength(); i++) {
if (
keccak256(abi.encodePacked(_roleInfo[Role(i)].key)) ==
keccak256(abi.encodePacked(roleName))
) {
isValidRoleName = true;
break;
}
}
require(isValidRoleName, "Invalid role name");
_;
}

function getRoleAddress(Role role) public view returns (address) {
address roleAddress = _roleInfo[role].address_;
require(roleAddress != address(0), "Error: Address is zero");
Expand Down Expand Up @@ -129,8 +144,9 @@ contract SafeAddresses is PantosBaseScript {
writeSafeInfo(safeAddresses);
}

function getRole(string memory roleName) public view returns (Role) {
require(_keysToRoles[roleName] != Role(0), "Role does not exist");
function getRole(
string memory roleName
) public view onlyValidRoleName(roleName) returns (Role) {
return _keysToRoles[roleName];
}

Expand Down

0 comments on commit 479f838

Please sign in to comment.