Skip to content

Commit

Permalink
Refactor KintoAppRegistry to use constants for rate and gas limits, u…
Browse files Browse the repository at this point in the history
…pdate access modifiers, and remove redundant assertions.
  • Loading branch information
ylv-io committed Nov 9, 2024
1 parent a715606 commit f1e41da
Show file tree
Hide file tree
Showing 14 changed files with 140 additions and 281 deletions.
9 changes: 1 addition & 8 deletions script/migrations/100-kinto_core_app.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,7 @@ contract KintoCoreAppScript is MigrationHelper {
appContracts[1] = address(0x8a4720488CA32f1223ccFE5A087e250fE3BC5D75); //Wallet Factory
appContracts[2] = address(0x5A2b641b84b0230C8e75F55d5afd27f4Dbd59d5b); //App Registry

KintoAppRegistry kintoAppRegistry = KintoAppRegistry(payable(_getChainDeployment("KintoAppRegistry")));

uint256[4] memory appLimits = [
kintoAppRegistry.RATE_LIMIT_PERIOD(),
kintoAppRegistry.RATE_LIMIT_THRESHOLD(),
kintoAppRegistry.GAS_LIMIT_PERIOD(),
kintoAppRegistry.GAS_LIMIT_THRESHOLD()
];
uint256[4] memory appLimits = [RATE_LIMIT_PERIOD, RATE_LIMIT_THRESHOLD, GAS_LIMIT_PERIOD, GAS_LIMIT_THRESHOLD];

// Socket-batcher app
address[] memory devEOAs = new address[](2);
Expand Down
4 changes: 0 additions & 4 deletions script/migrations/111-upgrade_app_registry.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,5 @@ contract DeployScript is MigrationHelper {
saveContractAddress("KintoAppRegistryV21", impl);

KintoAppRegistry registry = KintoAppRegistry(_getChainDeployment("KintoAppRegistry"));

assertEq(address(registry.paymaster()), _getChainDeployment("SponsorPaymaster"));
assertEq(address(registry.walletFactory()), _getChainDeployment("KintoWalletFactory"));
assertEq(address(registry.ENTRYPOINT_V7()), 0x0000000071727De22E5E9d8BAf0edAc6f37da032);
}
}
1 change: 0 additions & 1 deletion script/migrations/27-deploy_registry-v4.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ contract KintoMigration27DeployScript is MigrationHelper {

// check KintoID is set on Registry
IKintoAppRegistry registry = IKintoAppRegistry(_getChainDeployment("KintoAppRegistry"));
require(address(registry.kintoID()) == _getChainDeployment("KintoID"), "KintoID not set on Registry");

// check we can't call registerApp without being KYC'd
try registry.registerApp(
Expand Down
7 changes: 1 addition & 6 deletions script/migrations/66-socket-app.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,7 @@ contract KintoMigration66DeployScript is MigrationHelper {
appContracts[23] = _getChainDeployment("weETH");
appContracts[25] = _getChainDeployment("ETHFI");

uint256[4] memory appLimits = [
kintoAppRegistry.RATE_LIMIT_PERIOD(),
kintoAppRegistry.RATE_LIMIT_THRESHOLD(),
kintoAppRegistry.GAS_LIMIT_PERIOD(),
kintoAppRegistry.GAS_LIMIT_THRESHOLD()
];
uint256[4] memory appLimits = [RATE_LIMIT_PERIOD, RATE_LIMIT_THRESHOLD, GAS_LIMIT_PERIOD, GAS_LIMIT_THRESHOLD];

vm.broadcast(deployerPrivateKey);
kintoAppRegistry.registerApp("Socket", parentContract, appContracts, appLimits, new address[](0));
Expand Down
7 changes: 1 addition & 6 deletions script/migrations/78-update-socket-app.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,7 @@ contract KintoMigration78DeployScript is MigrationHelper {
appContracts[12] = address(0x24f287b474a05E48627846148cCdA3D05de03953); // ETHFI controller
appContracts[13] = address(0xA2a13094baB725D6D9dd8b9B5c01F1a1bF67F986); // SolvBTC controller

uint256[4] memory appLimits = [
kintoAppRegistry.RATE_LIMIT_PERIOD(),
kintoAppRegistry.RATE_LIMIT_THRESHOLD(),
kintoAppRegistry.GAS_LIMIT_PERIOD(),
kintoAppRegistry.GAS_LIMIT_THRESHOLD()
];
uint256[4] memory appLimits = [RATE_LIMIT_PERIOD, RATE_LIMIT_THRESHOLD, GAS_LIMIT_PERIOD, GAS_LIMIT_THRESHOLD];

vm.broadcast(deployerPrivateKey);
kintoAppRegistry.updateMetadata("Socket", parentContract, appContracts, appLimits, new address[](0));
Expand Down
7 changes: 1 addition & 6 deletions script/migrations/85-dinari_apps.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,7 @@ contract KintoMigration85DeployScript is MigrationHelper {
appContracts[9] = address(0xeDA274898ED364Bd346fA74cf6eCAB4BF8f1665f); // UsdPlusMinte
appContracts[10] = address(0x931C5dC9eA13b0F6B4768a98AFfEA773b888e978); // USDPlus Redeeemer

uint256[4] memory appLimits = [
kintoAppRegistry.RATE_LIMIT_PERIOD(),
kintoAppRegistry.RATE_LIMIT_THRESHOLD(),
kintoAppRegistry.GAS_LIMIT_PERIOD(),
kintoAppRegistry.GAS_LIMIT_THRESHOLD()
];
uint256[4] memory appLimits = [RATE_LIMIT_PERIOD, RATE_LIMIT_THRESHOLD, GAS_LIMIT_PERIOD, GAS_LIMIT_THRESHOLD];

eoas[0] = address(0x400880b800410B2951Afd0503dC457aea8A4bAb5); // Treasury
eoas[1] = address(0xF96b974FE330C29e80121E33ed4071C283257979); // dshares
Expand Down
7 changes: 1 addition & 6 deletions script/migrations/97-update_socket_app.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,7 @@ contract KintoMigration97DeployScript is MigrationHelper {
appContracts[26] = address(0x8cd4725D32CcFB201A25F1E1a18260E53F37C927); // cbETH controller
appContracts[27] = address(0xB0FC8B7fb66958fe813475bBDC91c1Ac75725442); // cbBTC controller

uint256[4] memory appLimits = [
kintoAppRegistry.RATE_LIMIT_PERIOD(),
kintoAppRegistry.RATE_LIMIT_THRESHOLD(),
kintoAppRegistry.GAS_LIMIT_PERIOD(),
kintoAppRegistry.GAS_LIMIT_THRESHOLD()
];
uint256[4] memory appLimits = [RATE_LIMIT_PERIOD, RATE_LIMIT_THRESHOLD, GAS_LIMIT_PERIOD, GAS_LIMIT_THRESHOLD];

_handleOps(
abi.encodeWithSelector(
Expand Down
4 changes: 4 additions & 0 deletions script/migrations/const.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@ contract Constants {
address WUSDM = 0x57F5E098CaD7A3D1Eed53991D4d66C45C9AF7812; // wUSDM
uint64 internal constant NIO_GOVERNOR_ROLE = uint64(uint256(keccak256("NIO_GOVERNOR_ROLE")));
uint256 internal constant NIO_EXECUTION_DELAY = 3 days;
uint256 internal constant RATE_LIMIT_PERIOD = 1 minutes;
uint256 internal constant RATE_LIMIT_THRESHOLD = 10;
uint256 internal constant GAS_LIMIT_PERIOD = 30 days;
uint256 internal constant GAS_LIMIT_THRESHOLD = 0.01 ether;
}
75 changes: 37 additions & 38 deletions src/apps/KintoAppRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,50 +40,38 @@ contract KintoAppRegistry is
{
/* ============ Constants ============ */

/// @notice The default period for rate limiting, set to 1 minute
uint256 public constant override RATE_LIMIT_PERIOD = 1 minutes;

/// @notice The default threshold for rate limiting, set to 10 calls
uint256 public constant override RATE_LIMIT_THRESHOLD = 10;

/// @notice The default period for gas limiting, set to 30 days
uint256 public constant override GAS_LIMIT_PERIOD = 30 days;

/// @notice The default threshold for gas limiting, set to 0.01 ether
uint256 public constant override GAS_LIMIT_THRESHOLD = 0.01 ether;

/// @notice The address of the CREATE2 contract
address public constant CREATE2 = 0x4e59b44847b379578588920cA78FbF26c0B4956C;
address private constant CREATE2 = 0x4e59b44847b379578588920cA78FbF26c0B4956C;

/// @notice The SponsorPaymaster contract
SponsorPaymaster public immutable paymaster;
SponsorPaymaster private immutable paymaster;

/// @notice The KintoWalletFactory contract
IKintoWalletFactory public immutable override walletFactory;
IKintoWalletFactory private immutable walletFactory;

/// @notice The KintoID contract
IKintoID public immutable kintoID;
IKintoID private immutable kintoID;

/// @notice The address of the admin deployer
address public constant ADMIN_DEPLOYER = 0x660ad4B5A74130a4796B4d54BC6750Ae93C86e6c;
address private constant ADMIN_DEPLOYER = 0x660ad4B5A74130a4796B4d54BC6750Ae93C86e6c;

/// @notice
address public constant ENTRYPOINT_V6 = 0x2843C269D2a64eCfA63548E8B3Fc0FD23B7F70cb;
address private constant ENTRYPOINT_V6 = 0x2843C269D2a64eCfA63548E8B3Fc0FD23B7F70cb;

/// @notice
address public constant ENTRYPOINT_V7 = 0x0000000071727De22E5E9d8BAf0edAc6f37da032;
address private constant ENTRYPOINT_V7 = 0x0000000071727De22E5E9d8BAf0edAc6f37da032;

/// @notice
address public constant ARB_RETRAYABLE_TX = 0x000000000000000000000000000000000000006E;
address private constant ARB_RETRAYABLE_TX = 0x000000000000000000000000000000000000006E;

bytes4 public constant SELECTOR_EP_WITHDRAW_STAKE = 0xc23a5cea;
bytes4 public constant SELECTOR_EP_WITHDRAW_TO = 0x205c2878;
bytes4 public constant SELECTOR_EP_HANDLEO_AGGREGATED_OPS = 0x4b1d7cf5;
bytes4 public constant SELECTOR_EP_HANDLE_AGGREGATED_OPS_V7 = 0xdbed18e0;
bytes4 public constant SELECTOR_EP_HANDLEOPS = 0x1fad948c;
bytes4 public constant SELECTOR_EP_HANDLE_OPS_V7 = 0x765e827f;
bytes4 public constant SELECTOR_EP_DEPOSIT = 0xb760faf9;
bytes4 public constant SELECTOR_EMPTY = 0x00000000;
bytes4 private constant SELECTOR_EP_WITHDRAW_STAKE = 0xc23a5cea;
bytes4 private constant SELECTOR_EP_WITHDRAW_TO = 0x205c2878;
bytes4 private constant SELECTOR_EP_HANDLEO_AGGREGATED_OPS = 0x4b1d7cf5;
bytes4 private constant SELECTOR_EP_HANDLE_AGGREGATED_OPS_V7 = 0xdbed18e0;
bytes4 private constant SELECTOR_EP_HANDLEOPS = 0x1fad948c;
bytes4 private constant SELECTOR_EP_HANDLE_OPS_V7 = 0x765e827f;
bytes4 private constant SELECTOR_EP_DEPOSIT = 0xb760faf9;
bytes4 private constant SELECTOR_EMPTY = 0x00000000;

/* ============ State Variables ============ */

Expand Down Expand Up @@ -155,7 +143,9 @@ contract KintoAppRegistry is
* @notice Authorizes the upgrade of the contract
* @param newImplementation The address of the new implementation
*/
function _authorizeUpgrade(address newImplementation) internal override onlyOwner {}
function _authorizeUpgrade(address newImplementation) internal override {
_checkOwner();
}

/* ============ Token name, symbol & URI ============ */

Expand Down Expand Up @@ -299,19 +289,22 @@ contract KintoAppRegistry is
}

/// @inheritdoc IKintoAppRegistry
function enableDSA(address app) external override onlyOwner {
function enableDSA(address app) external override {
_checkOwner();
if (_appMetadata[app].dsaEnabled) revert DSAAlreadyEnabled(app);
_appMetadata[app].dsaEnabled = true;
emit AppDSAEnabled(app, block.timestamp);
}

/// @inheritdoc IKintoAppRegistry
function overrideChildToParentContract(address child, address parent) external override onlyOwner {
function overrideChildToParentContract(address child, address parent) external override {
_checkOwner();

Check warning on line 301 in src/apps/KintoAppRegistry.sol

View check run for this annotation

Codecov / codecov/patch

src/apps/KintoAppRegistry.sol#L301

Added line #L301 was not covered by tests
childToParentContract[child] = parent;
}

/// @inheritdoc IKintoAppRegistry
function updateSystemApps(address[] calldata newSystemApps) external onlyOwner {
function updateSystemApps(address[] calldata newSystemApps) external {
_checkOwner();
emit SystemAppsUpdated(systemApps, newSystemApps);
for (uint256 index = 0; index < systemApps.length; index++) {
isSystemApp[systemApps[index]] = false;
Expand All @@ -323,7 +316,8 @@ contract KintoAppRegistry is
}

/// @inheritdoc IKintoAppRegistry
function updateSystemContracts(address[] calldata newSystemContracts) external onlyOwner {
function updateSystemContracts(address[] calldata newSystemContracts) external {
_checkOwner();
emit SystemContractsUpdated(systemContracts, newSystemContracts);
for (uint256 index = 0; index < systemContracts.length; index++) {
_isSystemContract[systemContracts[index]] = false;
Expand All @@ -335,7 +329,8 @@ contract KintoAppRegistry is
}

/// @inheritdoc IKintoAppRegistry
function updateReservedContracts(address[] calldata newReservedContracts) external onlyOwner {
function updateReservedContracts(address[] calldata newReservedContracts) external {
_checkOwner();
emit ReservedContractsUpdated(reservedContracts, newReservedContracts);
for (uint256 index = 0; index < reservedContracts.length; index++) {
isReservedContract[reservedContracts[index]] = false;
Expand Down Expand Up @@ -389,10 +384,14 @@ contract KintoAppRegistry is
uint256 gasLimitCost = _appMetadata[app].gasLimitCost;

// Assign values to the return array
limits[0] = rateLimitPeriod != 0 ? rateLimitPeriod : RATE_LIMIT_PERIOD;
limits[1] = rateLimitNumber != 0 ? rateLimitNumber : RATE_LIMIT_THRESHOLD;
limits[2] = gasLimitPeriod != 0 ? gasLimitPeriod : GAS_LIMIT_PERIOD;
limits[3] = gasLimitCost != 0 ? gasLimitCost : GAS_LIMIT_THRESHOLD;
// The default period for rate limiting, set to 1 minute
limits[0] = rateLimitPeriod != 0 ? rateLimitPeriod : 1 minutes;
// The default threshold for rate limiting, set to 10 calls
limits[1] = rateLimitNumber != 0 ? rateLimitNumber : 10;
// The default period for gas limiting, set to 30 days
limits[2] = gasLimitPeriod != 0 ? gasLimitPeriod : 30 days;
// The default threshold for gas limiting, set to 0.01 ether
limits[3] = gasLimitCost != 0 ? gasLimitCost : 0.01 ether;
}

/// @inheritdoc IKintoAppRegistry
Expand Down
38 changes: 0 additions & 38 deletions src/interfaces/IKintoAppRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -303,18 +303,6 @@ interface IKintoAppRegistry {
*/
function isSponsored(address app, address target) external view returns (bool);

/**
* @notice Returns the wallet factory contract
* @return The address of the wallet factory contract
*/
function walletFactory() external view returns (IKintoWalletFactory);

/**
* @notice Returns the KintoID contract
* @return The address of the KintoID contract
*/
function kintoID() external view returns (IKintoID);

/**
* @notice Returns the app address for a given token ID
* @param _tokenId The token ID
Expand Down Expand Up @@ -415,30 +403,4 @@ interface IKintoAppRegistry {
external
view
returns (bool);

/* ============ Constants and Attributes ============ */

/**
* @notice Returns the rate limit period
* @return The rate limit period in seconds
*/
function RATE_LIMIT_PERIOD() external view returns (uint256);

/**
* @notice Returns the rate limit threshold
* @return The rate limit threshold
*/
function RATE_LIMIT_THRESHOLD() external view returns (uint256);

/**
* @notice Returns the gas limit period
* @return The gas limit period in seconds
*/
function GAS_LIMIT_PERIOD() external view returns (uint256);

/**
* @notice Returns the gas limit threshold
* @return The gas limit threshold in wei
*/
function GAS_LIMIT_THRESHOLD() external view returns (uint256);
}
26 changes: 8 additions & 18 deletions test/helpers/AATestScaffolding.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ import {SponsorPaymasterHarness} from "../harness/SponsorPaymasterHarness.sol";
import {KintoAppRegistryHarness} from "../harness/KintoAppRegistryHarness.sol";

abstract contract AATestScaffolding is SignatureHelper, StdAssertions, StdCheats {
uint256 internal constant RATE_LIMIT_PERIOD = 1 minutes;
uint256 internal constant RATE_LIMIT_THRESHOLD = 10;
uint256 internal constant GAS_LIMIT_PERIOD = 30 days;
uint256 internal constant GAS_LIMIT_THRESHOLD = 0.01 ether;

IKintoEntryPoint _entryPoint;

// Kinto Registry
Expand Down Expand Up @@ -102,12 +107,7 @@ abstract contract AATestScaffolding is SignatureHelper, StdAssertions, StdCheats
// fixme: these should go through entrypoint
function registerApp(address _owner, string memory name, address parentContract, address[] memory devEOAs) public {
address[] memory appContracts = new address[](0);
uint256[4] memory appLimits = [
_kintoAppRegistry.RATE_LIMIT_PERIOD(),
_kintoAppRegistry.RATE_LIMIT_THRESHOLD(),
_kintoAppRegistry.GAS_LIMIT_PERIOD(),
_kintoAppRegistry.GAS_LIMIT_THRESHOLD()
];
uint256[4] memory appLimits = [RATE_LIMIT_PERIOD, RATE_LIMIT_THRESHOLD, GAS_LIMIT_PERIOD, GAS_LIMIT_THRESHOLD];
registerApp(_owner, name, parentContract, appContracts, appLimits, devEOAs);
}

Expand All @@ -129,12 +129,7 @@ abstract contract AATestScaffolding is SignatureHelper, StdAssertions, StdCheats
address[] memory appContracts,
address[] memory devEOAs
) public {
uint256[4] memory appLimits = [
_kintoAppRegistry.RATE_LIMIT_PERIOD(),
_kintoAppRegistry.RATE_LIMIT_THRESHOLD(),
_kintoAppRegistry.GAS_LIMIT_PERIOD(),
_kintoAppRegistry.GAS_LIMIT_THRESHOLD()
];
uint256[4] memory appLimits = [RATE_LIMIT_PERIOD, RATE_LIMIT_THRESHOLD, GAS_LIMIT_PERIOD, GAS_LIMIT_THRESHOLD];
registerApp(_owner, name, parentContract, appContracts, appLimits, devEOAs);
}

Expand All @@ -160,12 +155,7 @@ abstract contract AATestScaffolding is SignatureHelper, StdAssertions, StdCheats
address[] memory appContracts,
address[] memory devEOAs
) public {
uint256[4] memory appLimits = [
_kintoAppRegistry.RATE_LIMIT_PERIOD(),
_kintoAppRegistry.RATE_LIMIT_THRESHOLD(),
_kintoAppRegistry.GAS_LIMIT_PERIOD(),
_kintoAppRegistry.GAS_LIMIT_THRESHOLD()
];
uint256[4] memory appLimits = [RATE_LIMIT_PERIOD, RATE_LIMIT_THRESHOLD, GAS_LIMIT_PERIOD, GAS_LIMIT_THRESHOLD];
vm.prank(_owner);
_kintoAppRegistry.updateMetadata(name, parentContract, appContracts, appLimits, devEOAs);
}
Expand Down
Loading

0 comments on commit f1e41da

Please sign in to comment.