SC02:2023 - 整数オーバーフローとアンダーフロー (Integer Overflow and Underflow)
説明:
事例:
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.0;
contract TimeWrapVault {
mapping(address => uint256) public accountBalances;
mapping(address => uint256) public withdrawalUnlockTime;
// Allows anyone to deposit ETH and set a lock time
function depositFunds() external payable {
accountBalances[msg.sender] += msg.value;
withdrawalUnlockTime[msg.sender] = block.timestamp + 1 weeks;
}
// Vulnerable to overflow, the user could pass a very large value causing overflow
function extendLockTime(uint256 _additionalSeconds) public {
withdrawalUnlockTime[msg.sender] += _additionalSeconds;
}
// Allows withdrawals only if the current time is greater than the lock time
function releaseFunds() public {
require(accountBalances[msg.sender] > 0, "Insufficient funds");
require(block.timestamp > withdrawalUnlockTime[msg.sender], "Lock time not expired");
uint256 withdrawalAmount = accountBalances[msg.sender];
accountBalances[msg.sender] = 0;
(bool successfulWithdrawal,) = msg.sender.call{value: withdrawalAmount}("");
require(successfulWithdrawal, "Failed to send Ether");
}
}
影響:
対策:
整数オーバーフローとアンダーフロー攻撃の被害を受けたスマートコントラクトの事例:
Last updated