Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
과제 제출 정보
주차: Week
과제 유형:
구현 내용
-재진입 공격을 막기 위한 cei패턴
스마트 컨트랙트의 치명적인 취약점인 재진입(Reentrancy) 공격을 원천적으로 차단하기 위해 로직의 순서를 재설계했다. 잔고 차감(Effects)을 이더 전송(Interactions)보다 먼저 수행하도록 하여, 해커가 악의적으로 함수를 재호출하더라도 이미 잔고가 0으로 처리되어 출금이 불가능하도록 방어한다.
-OpenZeppelin ReentrancyGuard 도입: 로직 순서 변경에 더해, 보안을 한 층 더 강화하기 위해 검증된 외부 라이브러리인 OpenZeppelin의 ReentrancyGuard를 상속(import)받아 사용함. 출금 함수에 nonReentrant 변경자(modifier)를 부착하여 함수 실행이 끝날 때까지 동일한 함수의 재진입을 물리적으로 잠그는 이중 방어망을 구축했다. 운영체제에서 배운 뮤텍스락이랑 같은원리.. 원자적으로 일어나게함!
배운 점 (What I Learned)
이번 주에 배운 것 (2-3가지)
하지만 이번 과제를 통해 스마트 컨트랙트의 취약점은 컴퓨터의 '물리적인 속도' 문제가 아니라 '코드 제어권(Control Flow)'의 문제라는 것을 완벽하게 깨달았다.
스마트 컨트랙트에서 call을 통해 외부로 이더를 보내는 순간, 실행의 제어권이 해커의 악의적인 컨트랙트(fallback 또는 receive 함수)로 완전히 넘어감.
블록체인의 트랜잭션은 단일 스레드(Atomic)로 작동하기 때문에, 해커의 함수가 모두 끝날 때까지 내 컨트랙트의 다음 줄 코드는 절대 실행되지 않고 멈춰서 기다린다.
처음엔 해커 지갑만 동결하는 소프트포크를 시도했으나, 가비지 트랜잭션으로 채굴자를 마비시키는 디도스(DoS) 취약점이 발견되어 중단되었고, 결국 기록을 되돌리는 하드포크를 단행했고, 이 과정에서 "코드는 법이다"라는 신념을 지킨 진영이 이더리움 클래식(ETC)으로 갈라져 나온 배경을 이해하게 되었다.
어려웠던 점과 해결 방법
어려웠던 점:
Error writing output JSON 컴파일 에러 발생
원인: 윈도우 환경에서 프로젝트 폴더 경로에 한글이 포함되어 있어, 솔리디티 컴파일러(solc)가 결과물(JSON)을 생성하는 과정에서 경로를 인식하지 못하고 충돌이 발생함.
시도한 방법: subst 명령어를 통해 가상 드라이브(X:)를 만들어 경로를 단축해 보았으나, 컴파일러가 원본 경로의 한글을 감지하여 동일한 에러가 반복됨.
해결 방법:
한글이 포함되지 않은 경로인 C:/temp_dev로 프로젝트 폴더를 복사하여 환경을 격리함. 이후 forge install로 필요한 라이브러리(forge-std, openzeppelin)를 재설치하고 remappings.txt를 설정하여 의존성 문제를 해결한 뒤, 테스트 완료함
질문 사항
체크리스트
테스트
forge build성공forge test모든 테스트 통과제출 규칙
{username}/week-{XX}형식.env파일이 커밋에 포함되지 않음