-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVulnerableVault.sol
More file actions
44 lines (37 loc) · 1.43 KB
/
Copy pathVulnerableVault.sol
File metadata and controls
44 lines (37 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
/// @title VulnerableVault - Intentionally vulnerable contract for scanner demo
/// @notice DO NOT deploy this contract. It contains intentional vulnerabilities.
contract VulnerableVault {
mapping(address => uint256) public balances;
address public owner;
constructor() {
owner = msg.sender;
}
function deposit() external payable {
balances[msg.sender] += msg.value;
}
// VULNERABILITY: Reentrancy - external call before state update
function withdraw() external {
uint256 amount = balances[msg.sender];
require(amount > 0, "No balance");
(bool success, ) = msg.sender.call{value: amount}("");
require(success, "Transfer failed");
balances[msg.sender] = 0; // State update AFTER external call!
}
// VULNERABILITY: Unprotected selfdestruct
function destroy() external {
selfdestruct(payable(msg.sender));
}
// VULNERABILITY: Uncached array length + post-increment
function processDeposits(address[] memory depositors) external {
for (uint256 i = 0; i < depositors.length; i++) {
balances[depositors[i]] += 1 ether;
}
}
// VULNERABILITY: tx.origin authentication
function emergencyWithdraw() external {
require(tx.origin == owner, "Not owner");
payable(owner).transfer(address(this).balance);
}
}