DittoETH

Ditto
DeFiFoundryOracle
55,000 USDC
View results
Submission Details
Severity: low
Invalid

Asset.sol's onlyDiamond() Modifier Lacks Initializer, Allowing Unauthorized Access

Summary

The smart contract in question, Asset.sol, contains a potential security vulnerability in the onlyDiamond() modifier. This modifier is intended to restrict certain functions to be called only by a specific address, diamond. However, the modifier lacks an initializer, which could potentially allow unauthorized addresses to call these functions.

Vulnerability Details

File: tokens/Asset.sol
modifier onlyDiamond() {
if (msg.sender != diamond) {
revert NotDiamond();
}
_;
}

The onlyDiamond() modifier checks if the msg.sender is the diamond address. If not, it reverts the transaction. However, this function is not protected by an initializer, which means it can be called by any address, not just the diamond address.

Impact

The impact of this issue is potentially high. If an attacker is able to call functions that are supposed to be restricted to the diamond address, they could mint or burn tokens at will, leading to a potential manipulation of the token's supply. This could lead to a loss of funds for token holders and a loss of trust in the token's ecosystem.

Tools Used

manual code review techniques and write report with help of chatgpt

Recommendations

It is recommended to add an initializer to the onlyDiamond() function to ensure that it can only be called once and by the diamond address. This will prevent potential unauthorized access and manipulation of the contract's functions.

Here is the recommended fix:

bool private initialized = false;
modifier onlyDiamond() {
require(!initialized, "Already initialized");
require(msg.sender == diamond, "Not a diamond address");
initialized = true;
_;
}

This code adds a boolean variable initialized that is set to true after the first call to onlyDiamond(). Any subsequent calls will fail the require(!initialized, "Already initialized") check and revert.

Updates

Lead Judging Commences

0xnevi Lead Judge
over 1 year ago
0xnevi Lead Judge over 1 year ago
Submission Judgement Published
Invalidated
Reason: Other

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.