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
/* Bad */ | |
contract Bad{} | |
contract Tom is Bad{ | |
constructor() public Bad(){} | |
} | |
/* Better */ | |
contract Good{} | |
contract Tom is Good{ | |
constructor() public {} // remove the constructor call. |
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
/* Bad */ | |
contract A { | |
uint x; | |
constructor() public { | |
x = 0; | |
} | |
function A() public { | |
x = 1; | |
} | |
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
/* Bad */ | |
modifier myModif(){ | |
if(..){ | |
_; | |
} | |
} | |
function get() myModif returns(uint){} | |
/* Better */ | |
modidfier myModif(){ |
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
/* Bad */ | |
contract BadGuy { | |
function isLove(address _addr) external returns(bool) {} | |
} | |
contract BadGirl { | |
BadGuy badguy; | |
modifier isCheck(address _addr) { | |
require(badguy.isLove(_addr)); | |
_; |
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
/* Bad */ | |
contract Bad { | |
function badDelegate(address _yourContract, bytes calldata _data) payable public returns (bytes memory) { | |
(bool success, bytes memory data) = _yourContract.delegatecall(_data); | |
require(success); | |
return data; | |
} | |
} | |
/* Vulnerability | |
Anyone can destroy the Bad contract using by “selfdestruct” |
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
/* Bad */ | |
contract SendEth{ | |
mapping(address => uint256) public balanceOf; | |
function withdraw(address user, uint256 numTokens) public { | |
require(balanceOf[user] >= numTokens); | |
balanceOf[user] -= numTokens; | |
user.transfer(numTokens * 1 ether); | |
} | |
} |
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
/* Bad */ | |
address owner; | |
function setOwner() public { | |
owner = msg.sender; | |
} | |
/* Better */ | |
contract Buggy{ | |
/* | |
modifier onlyOwner() { |
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
/* Bad */ | |
// Sample1.sol | |
pragma solidity =0.8.4; | |
// Sample2.sol | |
pragma solidity =0.8.0; | |
/* Better */ | |
// Sample1.sol | |
pragma solidity =0.8.4; |
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
/* Bad */ | |
pragma solidity ^0.8.4; | |
/* Better */ | |
pragma solidity =0.8.4; |
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
/* Bad */ | |
pragma solidity ^0.4.25; | |
/* Better */ | |
pragma solidity 0.8.17; |