Skip to content

Commit

Permalink
Add: SC01-Access Control
Browse files Browse the repository at this point in the history
  • Loading branch information
WarlordSam07 committed Jan 20, 2025
1 parent 1c88eb6 commit ccffc4f
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 47 deletions.
45 changes: 0 additions & 45 deletions docs/sctop10/SC01-Reentrancy.md

This file was deleted.

48 changes: 48 additions & 0 deletions docs/sctop10/SC01-access-control.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
## SC01:2025 - Improper Access Control

### Description:
An access control vulnerability is a security flaw that allows unauthorized users to access or modify the contract's data or functions. These vulnerabilities arise when the contract's code fails to adequately restrict access based on user permission levels. Access control in smart contracts can relate to governance and critical logic, such as minting tokens, voting on proposals, withdrawing funds, pausing and upgrading the contracts, and changing ownership.

### Example (Vulnerable contract):
```
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract Solidity_AccessControl {
mapping(address => uint256) public balances;
// Burn function with no access control
function burn(address account, uint256 amount) public {
_burn(account, amount);
}
}
```
### Impact:
- Attackers can gain unauthorized access to critical functions and data within the contract, compromising its integrity and security.
- Vulnerabilities can lead to the theft of funds or assets controlled by the contract, causing significant financial damage to users and stakeholders.

### Remediation:
- Ensure initialization functions can only be called once and exclusively by authorized entities.
- Use established access control patterns like Ownable or RBAC (Role-Based Access Control) in your contracts to manage permissions and ensure that only authorized users can access certain functions. This can be done by adding appropriate access control modifiers, such as `onlyOwner` or custom roles to sensitive functions.

### Example (Fixed version):
```
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
// Import the Ownable contract from OpenZeppelin to manage ownership
import "@openzeppelin/contracts/access/Ownable.sol";
contract Solidity_AccessControl is Ownable {
mapping(address => uint256) public balances;
// Burn function with proper access control, only accessible by the contract owner
function burn(address account, uint256 amount) public onlyOwner {
_burn(account, amount);
}
}
```

### Examples of Smart Contracts That Fell Victim to Improper Access Control Attacks:
1. [HospoWise Hack](https://etherscan.io/address/0x952aa09109e3ce1a66d41dc806d9024a91dd5684#code) : A Comprehensive [Hack Analysis](https://blog.solidityscan.com/access-control-vulnerabilities-in-smart-contracts-a31757f5d707)
2. [LAND NFT Hack](https://bscscan.com/address/0x1a62fe088F46561bE92BB5F6e83266289b94C154#code) : A Comprehensive [Hack Analysis](https://blog.solidityscan.com/land-hack-analysis-missing-access-control-66fb9555a3e3)
2 changes: 1 addition & 1 deletion docs/sctop10/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ It serves as a reference to ensure that smart contracts are secured against the

### Top 10

* SC01:2025 - [Access Control Vulnerabilities](2025/en/src/SC01-access-control.md)
* SC01:2025 - [Access Control Vulnerabilities](SC01-access-control.md)
* SC02:2025 - [Price Oracle Manipulation](2025/en/src/SC02-price-oracle-manipulation.md)
* SC03:2025 - [Logic Errors](2025/en/src/SC03-logic-errors.md)
* SC04:2025 - [Lack of Input Validation](2025/en/src/SC04-lack-of-input-validation.md)
Expand Down
3 changes: 2 additions & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ nav:

- "Smart Contract Top 10":
- sctop10/index.md
- SC01:2023 - Reentrancy Attacks: sctop10/SC01-Reentrancy.md
- sctop10/Top10:2023.md
- SC01:2025 - Improper Access Control: sctop10/SC01-access-control.md
- SC02:2023 - Integer Overflow and Underflow: sctop10/SC02-IntegerOverflowUnderflow.md
- SC03:2023 - Timestamp Dependence: sctop10/SC03-TimestampDependence.md
- SC04:2023 - Access Control Vulnerabilities: sctop10/SC04-AccessControl.md
Expand Down

0 comments on commit ccffc4f

Please sign in to comment.