SC05:2025 - 再入可能性 (Reentrancy)
説明:
事例 (脆弱なコントラクト):
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract Solidity_Reentrancy {
mapping(address => uint) public balances;
function deposit() external payable {
balances[msg.sender] += msg.value;
}
function withdraw() external {
uint amount = balances[msg.sender];
require(amount > 0, "Insufficient balance");
// Vulnerability: Ether is sent before updating the user's balance, allowing reentrancy.
(bool success, ) = msg.sender.call{value: amount}("");
require(success, "Transfer failed");
// Update balance after sending Ether
balances[msg.sender] = 0;
}
}影響:
対策:
事例 (修正バージョン):
再入攻撃の被害を受けたスマートコントラクトの事例:
PreviousSC04:2025 - 入力バリデーションの欠如 (Lack of Input Validation)NextSC06:2025 - チェックされていない外部呼び出し (Unchecked External Calls)
Last updated