Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement access manager #8

Merged
merged 4 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .yarn/install-state.gz
Binary file not shown.
3 changes: 2 additions & 1 deletion biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"./cache",
"./node_modules",
"./coverage",
"./coverage.json"
"./coverage.json",
"./ignition/deployments"
]
}
}
20 changes: 14 additions & 6 deletions contracts/ApplicationManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@
pragma solidity 0.8.26;

import {IApplicationManager} from "./IApplicationManager.sol";
import {AccessManaged} from "@openzeppelin/contracts/access/manager/AccessManaged.sol";
import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";

contract ApplicationManager is IApplicationManager {
contract ApplicationManager is
IApplicationManager,
AccessManaged,
ReentrancyGuard
{
mapping(uint => Application) private applications;
mapping(address => bool) private addressUsed;
uint private nextApplicationId;

constructor() {}
constructor(address initialAuthority) AccessManaged(initialAuthority) {}

function applicationExists(uint id) internal view returns (bool) {
return applications[id].account != address(0);
Expand All @@ -18,40 +24,42 @@
return nextApplicationId;
}

function createApplication(Application memory newApplication) external {
function createApplication(
Application memory newApplication
) external nonReentrant restricted {
require(
!addressUsed[newApplication.account],
"Address already used for another application"
);
applications[nextApplicationId] = newApplication;
addressUsed[newApplication.account] = true;
emit ApplicationCreated(
nextApplicationId,
applications[nextApplicationId]
);
nextApplicationId++;
}

function updateApplication(
uint id,
Application memory updatedApplication
) external {
) external nonReentrant restricted {
require(applicationExists(id), "Application does not exist");
require(
!addressUsed[updatedApplication.account] ||
applications[id].account == updatedApplication.account,
"Address already used for another application"
"Account used by another application"
);
applications[id] = updatedApplication;
emit ApplicationUpdated(id, applications[id]);
Comment on lines +46 to 54
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potential reentrancy vulnerability in updateApplication.

The updateApplication function has potential reentrancy vulnerabilities due to state changes after external calls. Consider refactoring to update state variables before making external calls.

+  applications[id] = updatedApplication;
  require(applicationExists(id), "Application does not exist");
  require(
      !addressUsed[updatedApplication.account] ||
          applications[id].account == updatedApplication.account,
      "Account used by another application"
  );
-  applications[id] = updatedApplication;
  emit ApplicationUpdated(id, applications[id]);

Committable suggestion was skipped due to low confidence.

}

function deleteApplication(uint id) external {
function deleteApplication(uint id) external nonReentrant restricted {
require(applicationExists(id), "Application does not exist");
addressUsed[applications[id].account] = false;
emit ApplicationDeleted(id, applications[id]);
delete applications[id];
}

Check notice

Code scanning / Slither

Reentrancy vulnerabilities Low


function getApplication(
uint id
Expand Down
11 changes: 11 additions & 0 deletions contracts/OIDAccessManager.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.26;

// solhint-disable-next-line max-line-length
import {AccessManagerUpgradeable} from "@openzeppelin/contracts-upgradeable/access/manager/AccessManagerUpgradeable.sol";

contract OIDAccessManager is AccessManagerUpgradeable {
function initialize() public initializer {
__AccessManager_init(msg.sender);
}
}
18 changes: 0 additions & 18 deletions ignition/modules/Lock.ts

This file was deleted.

17 changes: 17 additions & 0 deletions ignition/modules/OIDAccessManager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { buildModule } from "@nomicfoundation/hardhat-ignition/modules";

const OIDAccessManagerModule = buildModule("OIDAccessManagerModule", (m) => {
// const deployer = m.getAccount(0);

const manager = m.contract("OIDAccessManager", [], {});
m.call(manager, "initialize", []);

// m.call(manager, "labelRole", [1n, "APP_MANAGER_ROLE"]);

// console.log(appManager);
// m.call(manager, "grantRole", [1n, appManager, 0]);

return { manager };
});

export default OIDAccessManagerModule;
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
"@nomicfoundation/hardhat-verify": "^2.0.0",
"@nomicfoundation/hardhat-viem": "^2.0.0",
"@nomiclabs/hardhat-solhint": "^3.1.0",
"@openzeppelin/contracts": "^5.0.2",
"@openzeppelin/contracts-upgradeable": "^5.0.2",
"@types/chai": "^4.2.0",
"@types/chai-as-promised": "^7.1.6",
"@types/mocha": ">=9.1.0",
Expand Down
Loading