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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3,956 changes: 3,929 additions & 27 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@
"name": "eth-homework",
"private": true,
"devDependencies": {
"solhint": "^5.0.0",
"prettier": "^3.0.0",
"prettier-plugin-solidity": "^2.0.0"
"prettier-plugin-solidity": "^2.0.0",
"solhint": "^5.0.0"
},
"scripts": {
"lint": "solhint 'week-*/dev/src/**/*.sol'",
"lint:fix": "solhint 'week-*/dev/src/**/*.sol' --fix",
"format": "prettier --check 'week-*/dev/src/**/*.sol'",
"format:fix": "prettier --write 'week-*/dev/src/**/*.sol'"
},
"dependencies": {
"@react-native-async-storage/async-storage": "^3.0.1",
"pino-pretty": "^13.1.3"
}
}
10 changes: 5 additions & 5 deletions week-03/dev/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ forge test --match-test test_ReentrancyAttack_CannotDrainVault -vvvv

과제 제출 전 확인하세요:

- [ ] `deposit()` 함수 구현 완료
- [ ] `withdraw()` 함수 구현 완료 (CEI 또는 ReentrancyGuard)
- [ ] 모든 테스트 통과 (`forge test --match-path week-03/dev/test/Vault.t.sol`)
- [ ] 특히 `test_ReentrancyAttack_CannotDrainVault` 통과
- [ ] 코드에 적절한 주석 추가
- [o] `deposit()` 함수 구현 완료
- [o] `withdraw()` 함수 구현 완료 (CEI 또는 ReentrancyGuard)
- [o] 모든 테스트 통과 (`forge test --match-path week-03/dev/test/Vault.t.sol`)
- [o] 특히 `test_ReentrancyAttack_CannotDrainVault` 통과
- [o] 코드에 적절한 주석 추가
14 changes: 11 additions & 3 deletions week-03/dev/src/VaultSecure.sol
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,9 @@ 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 @@ -92,6 +91,9 @@ 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 @@ -111,6 +113,12 @@ contract VaultSecure {
/// ReentrancyGuard 사용 시: nonReentrant modifier 추가
function withdraw(uint256 amount) public {
// TODO: 구현하세요
require(balances[msg.sender] >= amount, "Insufficient balance");
balances[msg.sender] -= amount;
// ETH 전송
(bool success, ) = msg.sender.call{value: amount}("");
require(success, "Transfer failed");
emit Withdrawn(msg.sender, amount);
}

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