Forcefully Send Ether with selfdestruct | Hack Solidity (0.6)

  Рет қаралды 17,098

Smart Contract Programmer

Smart Contract Programmer

Күн бұрын

Пікірлер
@BarziniNwa
@BarziniNwa 2 жыл бұрын
Reading through “Mastering Ethereum” and watching your videos for further clarification is gold 👌🏼 thank you
@smartcontractprogrammer
@smartcontractprogrammer 4 жыл бұрын
Overview of the exploit 0:42 Contract vulnerable to the exploit 1:54 Preventative technique 6:50
@MehranHydary
@MehranHydary 4 жыл бұрын
After creating the uint public balance variable - we would have to update the claimReward + getBalance functions too right?
@smartcontractprogrammer
@smartcontractprogrammer 4 жыл бұрын
​ claimReward() after Ether is forcefully sent, so address(this).balance >= balance, user will receive more Ether than balance when calling claimReward(). this does not hurt the winner, so you as a smart contract coder can choose to reward the winner with balance or address(this).balance
@Morais479
@Morais479 2 жыл бұрын
Great video! One of the best channels for solidity if not the best!
@malikaremu2344
@malikaremu2344 2 жыл бұрын
is the best
@salem232
@salem232 4 жыл бұрын
😍 thanks for the video!! Very clear!! And breaking the game by wasting 5 Ether ?!!!! Truly self destructive!!! 😬
@smartcontractprogrammer
@smartcontractprogrammer 4 жыл бұрын
Actually you can take all of the 7 ether, using a special function called create2. Here is how it works create2 is used to deploy a contract at the same address (even contracts that were previously deleted) 1. deploy Attack contract using create2 2. selfdestruct to force send Ether. this will delete Attack contract 3. use create2 to redeploy the Attack contract 4. Attack is the winner and can claim the 7 ethers
@salem232
@salem232 4 жыл бұрын
Smart Contract Programmer 😯 !!! Wow, that sounds like hacking!!! Will you cover create2 later ?
@dashemanija
@dashemanija 3 жыл бұрын
Breaking the game was possible with only 0.1 eth, in fact with every amount different from one because sum would never going to be == 7
@jagadishk5827
@jagadishk5827 3 жыл бұрын
@@smartcontractprogrammer how is the attack winner in step 4 ?
@raviojhayt
@raviojhayt 2 жыл бұрын
@@smartcontractprogrammer Another way would be to send 4 Ether when calling attack, which makes the Game ther to 6. Then quickly deposit the 1 Ether to the game like a normal player. to become the winner :)
@broli450
@broli450 2 жыл бұрын
What happen if you sent 3 wei ? The contract will be blocked too because you verifiy that its strictly equal to 7 eth ?
@Ts2pc
@Ts2pc 2 жыл бұрын
Great! Very smart! I have question, In 3:35 line 49, you set the address of target as payable, does it means that we can change the address of another contract from non-payable to payable? It seems unreasonable?
@smartcontractprogrammer
@smartcontractprogrammer 2 жыл бұрын
yes
@andrewpan3047
@andrewpan3047 2 жыл бұрын
hi, the question is not how to break the contract but how to retrieve all the ethers after Yves sent all 5 ethers
@_chonkov
@_chonkov 2 жыл бұрын
What if the target was 7 ether, 3 ether were already sent, we make a selfdestruct in a contract that had another 3 ether and immediately deposit one more...3 easily stolen ether🤔
@dogcare5376
@dogcare5376 3 жыл бұрын
Awesome review,so amazing
@neoanderson1865
@neoanderson1865 2 жыл бұрын
I was wondering if you could clarify something for me. Before the attack happens the EtherGame balance is 2 ether, the attack function is called forcefully sending 5 ether, making the balance = 7 ether. That would mean the attacker would be the winner no? The require(balance
@smartcontractprogrammer
@smartcontractprogrammer 2 жыл бұрын
Game requires each deposit to be exactly 1 ETH. Under normal circumstance, 7th depositor will win. However this rule can be broken by forcefully sending more than 1 ETH and immediately win the game
@ErhanTezcan
@ErhanTezcan 2 жыл бұрын
The attacker's 5 eth was sent forcefully via selfdestruct, not via the deposit function as intended; therefore, it did not go through the if condition that would set the winner. I believe if the game is not active enough, you could forcefully send 4 ether and then immediately send the remaining 1 ether to win the game on your demand. The caveat there would be that there is a probability some other player deposited just after your attack has finished. (someone else also suggested this in the comments) To be more reliable, you could write an attack with 2 contracts for that: say there is N ether remaining to win the game, and you have contract X with 1 ether and Y with N-1 ether. You write an attack function in X such that it calls an external function in your Y contract which will cause Y to selfdestruct and send its N-1 to the target, and right after that the next line in X attack will be to deposit 1 ether to the target, thereby winning the game. The game could also defend against this by only allowing EOA's to play, and disallow contracts (i.e. requiring that msg. sender == tx. origin)
@neoanderson1865
@neoanderson1865 2 жыл бұрын
​@@ErhanTezcan Thank you for taking the time to reply. This makes much more sense now. For some reason I was thinking the eth that was forcefully sent was done through the deposit function instead of selfdestruct
@allaboutdata512
@allaboutdata512 2 жыл бұрын
great vid thanks. Please use dark theme. my eyes are hurting badly after competing the playlist
@leojamescharles181
@leojamescharles181 3 жыл бұрын
I want to delete the contract itself. selfdestruct(0x0); But solidity says this does "Invalid implicit conversion" can you please tell me how to selfdestruct the contract ?
@smartcontractprogrammer
@smartcontractprogrammer 3 жыл бұрын
selfdestruct(address(0))
@leojamescharles181
@leojamescharles181 3 жыл бұрын
@@smartcontractprogrammer hey thanx man appreciate it 👍
@shashanksingh4708
@shashanksingh4708 2 жыл бұрын
how do i test this using hardhat ?
@totalingarc
@totalingarc 3 жыл бұрын
kool video, thank you
@fahadaslamtanoli
@fahadaslamtanoli Жыл бұрын
can attacker can update the balance variable
@smartcontractprogrammer
@smartcontractprogrammer Жыл бұрын
only increase by sending ETH
@QuickstickD
@QuickstickD 3 жыл бұрын
Is the self destruct function how people rug projects?
@smartcontractprogrammer
@smartcontractprogrammer 3 жыл бұрын
There are alot of ways to rug pull. Self destruct can be a part of it.
@akif409
@akif409 4 жыл бұрын
You are the best!
@cryptonut4498
@cryptonut4498 3 жыл бұрын
Is the ether stuck in the contract forever? How can someone get it out?
@smartcontractprogrammer
@smartcontractprogrammer 3 жыл бұрын
if there is a function to withdraw ETH, otherwise it's stuck
@ongmorel5098
@ongmorel5098 3 жыл бұрын
Nice video but a people has just to directly send 5 ether to the contract without calling a function and the contract will be broken
@smartcontractprogrammer
@smartcontractprogrammer 3 жыл бұрын
People cannot directly send Ether because the contract doesn't have a payable fallback function. That is why selfdestruct is used to forcefully send ETH and break the contract
@ongmorel5098
@ongmorel5098 3 жыл бұрын
@@smartcontractprogrammer thks!
@RobloxGamer-g9n
@RobloxGamer-g9n 4 жыл бұрын
Cool!!!
@baddepakaprasad1565
@baddepakaprasad1565 4 жыл бұрын
Hi.. when i am trying to execute ethereum smart contracts by using Remix and the warning dispalys like and also code cannot be executed . plz solve this issue. Warning: SPDX license identifier not provided in source file. Before publishing, consider adding a comment containing "SPDX-License-Identifier: " to each source file. Use "SPDX-License-Identifier: UNLICENSED" for non-open-source code. Please see spdx.org for more information.
@smartcontractprogrammer
@smartcontractprogrammer 4 жыл бұрын
Warning can be fixed if you put this up at the first line // SPDX-License-Identifier: MIT What error are you getting?
Accessing Private Data | Hack Solidity (0.6)
17:13
Smart Contract Programmer
Рет қаралды 20 М.
Unsafe Delegatecall (part 2) | Hack Solidity (0.6)
14:01
Smart Contract Programmer
Рет қаралды 8 М.
Jaidarman TOP / Жоғары лига-2023 / Жекпе-жек 1-ТУР / 1-топ
1:30:54
진짜✅ 아님 가짜❌???
0:21
승비니 Seungbini
Рет қаралды 10 МЛН
Какой я клей? | CLEX #shorts
0:59
CLEX
Рет қаралды 1,9 МЛН
EP 55: Creating Secure Device Storage For Autonomous Vehicles
28:49
Error Code Podcast
Рет қаралды 1
Denial of Service | Hack Solidity (0.6)
10:59
Smart Contract Programmer
Рет қаралды 9 М.
Signature Replay | Hack Solidity (0.6)
10:54
Smart Contract Programmer
Рет қаралды 10 М.
Unsafe Delegatecall (part 1) | Hack Solidity (0.6)
9:04
Smart Contract Programmer
Рет қаралды 12 М.
Authentication is a developer nightmare
15:58
Tom Delalande
Рет қаралды 66 М.
Smart Contract Hacking - 0x0C - Attacking Authorization with Web3.js
14:52
Insecure Source of Randomness | Hack Solidity (0.6)
8:34
Smart Contract Programmer
Рет қаралды 7 М.
AI Is Making You An Illiterate Programmer
27:22
ThePrimeTime
Рет қаралды 287 М.
Honeypot | Hack Solidity (0.6)
8:46
Smart Contract Programmer
Рет қаралды 18 М.
Jaidarman TOP / Жоғары лига-2023 / Жекпе-жек 1-ТУР / 1-топ
1:30:54