Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ node_modules/

# npm
package-lock.json

lib
17 changes: 13 additions & 4 deletions week-03/dev/src/VaultSecure.sol
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ pragma solidity 0.8.26;
// ============================================
// OpenZeppelin 사용 시 주석 해제
// ============================================
// import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";

/// @dev ReentrancyGuard 사용 시: contract VaultSecure is ReentrancyGuard
contract VaultSecure {
contract VaultSecure is ReentrancyGuard {
// ============================================
// 상태 변수
// ============================================
Expand Down Expand Up @@ -106,7 +106,11 @@ contract VaultSecure {
///
/// 힌트: Vault.sol의 deposit()과 동일하게 구현하면 됩니다
function deposit() public payable {
// TODO: 구현하세요
// 잔액 증가
balances[msg.sender] += msg.value;

// 입금 이벤트 발생
emit Deposited(msg.sender, msg.value);
}

/// @notice 예치한 ETH를 출금합니다
Expand All @@ -124,8 +128,13 @@ contract VaultSecure {
///
/// CEI 패턴 사용 시 순서: Checks -> Effects -> Interactions
/// ReentrancyGuard 사용 시: nonReentrant modifier 추가
function withdraw(uint256 amount) public {
function withdraw(uint256 amount) public nonReentrant {
// TODO: 구현하세요
require(balances[msg.sender] >= amount, "Insufficient balance");
balances[msg.sender] -= amount;
(bool success, ) = msg.sender.call{ value: amount }("");
require(success, "Transfer failed");
emit Withdrawn(msg.sender, amount);
}

// ============================================
Expand Down
Loading