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패턴을 사용하였다. deposit함수는 그대로 사용을 하였고 withdraw함수가 중요하다. 우선은 bool 타입의 locked라는 변수를 선언해준다. locked는 기본값으로 false를 가진다. 그 후 withdraw함수에서 require로 출금하려는 금액만큼 잔액이 있는지 확인을 하고 locked 값을 true로 바꾸어 준다. 그 후 잔액을 상태 변경 하고 외부 호출을 실행한다. 그런데 이때 재진입 공격은 외부 호출 이전에 상태변경을 해주었으니 막아지지만 문제는 단순히 순서를 변경하여 외부호출 후 require을 사용하여 suceess == true인지 확인하여 아니라고 뜬다면 첫번째의 정상적인 출금마저 실패한다는 것을 알게 되었다. 이 때문에 bool 타입의 locked를 사용하였다. locked 값을 잔액 확인 후 true로 변경해놓았다. 일종의 화장실을 잠금 표시 한 것 과 같다. 이때 withdraw 첫째줄에 if (locked) return을 한다면 재진입시 실패하였을 때 revert를 시켜 정상 출금마저 실패하게 하는 것이 아닌 조용히 return 시킬 수 잇게 되었다.
배운 점 (What I Learned)
이번 주에 배운 것 (2-3가지)
어려웠던 점과 해결 방법
어려웠던 점:
CEI를 실행할때 단순히 순서만 변경하여 했더니 첫번째 정상 출금마저 실패하는 오류가 생겨 어려웠다.
해결 방법:
챗 gpt가 bool 타입의 locked라는 변수를 통해 화장실 문을 사용 중 빈칸 두가지로 표현할 수 있듯이 잠금 표현을 할 수 있음을 알려주어 해결하였습니다.
질문 사항
-3주차의 추가학습 자료 중 보안 패턴 상세 가이드가 열리지 않는 데 혹시 어떻게 볼 수 있는지 여쭤봅니다.
체크리스트
테스트
forge build성공forge test모든 테스트 통과제출 규칙
{username}/week-{XX}형식.env파일이 커밋에 포함되지 않음