-
Notifications
You must be signed in to change notification settings - Fork 0
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
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,8 @@ | |
"./cache", | ||
"./node_modules", | ||
"./coverage", | ||
"./coverage.json" | ||
"./coverage.json", | ||
"./ignition/deployments" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
|
@@ -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++; | ||
} | ||
Check notice Code scanning / Slither Reentrancy vulnerabilities Low
Reentrancy in ApplicationManager.createApplication(IApplicationManager.Application):
External calls: - restricted() - IAccessManager(authority()).consumeScheduledOp(caller,data) State variables written after the call(s): - addressUsed[newApplication.account] = true - applications[nextApplicationId] = newApplication - 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]); | ||
} | ||
|
||
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
Reentrancy in ApplicationManager.deleteApplication(uint256):
External calls: - restricted() - IAccessManager(authority()).consumeScheduledOp(caller,data) State variables written after the call(s): - addressUsed[applications[id].account] = false - delete applications[id] |
||
|
||
function getApplication( | ||
uint id | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.