How To Get Front-Run on Ethereum mainnet

Поділитися
Вставка
  • Опубліковано 27 січ 2025

КОМЕНТАРІ • 130

  • @decipherwithzaryab5106
    @decipherwithzaryab5106 4 роки тому +68

    Keep the videos coming. There are literally very few channels that explain such imperative concepts with utmost clarity.
    This is channel is one of those. Thank you

  • @henrytirla
    @henrytirla Рік тому

    Very concise and self explanatory. One thing I try to figure out is how to make one's gas fees dynamic in terms of current block, current state of gas prices and current competition on the same block.

  • @leftysmalls
    @leftysmalls 4 роки тому +10

    Love the video. Please do continue the series on front running!

  • @dwiz121
    @dwiz121 4 роки тому +2

    Awesome so see the front-runners front-running. Great content, thanks.

  • @ffckode
    @ffckode 3 роки тому +2

    Thanks for sharing this. Super helpful. It would be nice to see how to prevent the front running. Thanks

  • @567BTHTY
    @567BTHTY 4 роки тому +2

    thank you for this clear explanation, I also loved the medium article posted in the comments.

  • @alexeynavalny4732
    @alexeynavalny4732 3 роки тому

    Its very intreesting video as a newbie web3 developer.
    Expecting more videos like this.
    Thank you so much 😘😘😘

  • @theycallmeken
    @theycallmeken 3 роки тому

    This is exceptional content! My only critique would be to speak slower for those of us not at your level. Keep it coming 🙌🏾

  • @viewer8221
    @viewer8221 3 роки тому +2

    Thank you very much Scott for the informative and potentially project saving videos. I am sure I am not the only developer who appreciates being able to see these potential threats and how to handle them. Keep it up!

  • @christianmontague571
    @christianmontague571 Рік тому

    great video very insightful ! question what do you recommend where to learn solidity and how to write smart contracts

  • @dariohernanerasmo5030
    @dariohernanerasmo5030 2 роки тому +3

    First of all, thank you very much for the video. It was quite entertaining and eye-opening. Got a couple of questions though,
    1. Could you explain a little bit more about the parts where you were calculating the gas price (ie. 15:22 and 16:45)? I'm assuming you were calculating how much you'd have to pay for gas in order to get your transaction included quickly, but what about the locahost tab you opened around 15:22? what was it that you were checking?
    2. How would a bot like the one that sniped you know that it'd get payed if they send the same data as your transaction? I'm guessing that they don't know, and they just replicate the transactions and payload with "payable" contract functions as destination, to outbid your gas price and just hope for the best. But if that's the case, how could they know if a function is payable? is that information public for all contracts living on the mainnet?
    Thanks,

  • @danielmaina4942
    @danielmaina4942 3 роки тому

    Oh my! it's really the wild west out there ! Thanks Scott for this video. Liked and subscribed !

  • @davidlee-wf2no
    @davidlee-wf2no 3 роки тому +10

    A great video. But I have a little confused about how a front runner can recognize they can get benefit from this contract so quickly since you said they even don't need to understand the contract itself.

    • @magicmedia.channel
      @magicmedia.channel 3 роки тому

      Yeah that is not explained at all. They can't front-run billions of tx on good luck. The gas fees would kill them. So how do they know in advance which tx have any kind of value?

    • @ichigokurosaki5707
      @ichigokurosaki5707 3 роки тому +7

      they scan all the transactions on the waiting pool, then calculate output - input eth if its greater than some value they copy the transaction and try doing it with higher fees.

    • @cedricdb
      @cedricdb 2 роки тому

      @@ichigokurosaki5707 Thats pretty obvious but the question is how can they calculate this potential profit without knowing anything about the contract in advance? Are they somehow simulating how contracts will react to a transaction?

    • @maptuffs
      @maptuffs 2 роки тому +3

      @@cedricdb not sure if you are still looking for an answer , but yes they simulate the contract on a testnet. copy the pending transaction function calls and if their wallet ends up with more ether than they put in, they shoot the transaction to the real network and front run

    • @zaidelsontube
      @zaidelsontube 2 роки тому

      @@maptuffs Thanks Mike! But the Testnet contract may have different logic and different value... So they are risking money with every such try, correct?

  • @thoyo
    @thoyo 3 роки тому

    Excellent tutorial. No idea how this doesn't have more views

  • @MrDoGoOd1000
    @MrDoGoOd1000 3 роки тому +3

    this was very informative! thanks for paying for our education :)

  • @urisrssfeeds
    @urisrssfeeds 2 роки тому +1

    In this particular example, can't you just guard by checking that the caller of take is the same as the contract owner? That is, if a front-runner tries to copy the transaction, they'll fail because they're not the contract owner?

  • @johnmosesman
    @johnmosesman 2 роки тому +1

    Great video thanks for making it!
    As others have mentioned, a video on how these bots simulate these transactions (testnet? local node?) would be really interesting.

  • @urisrssfeeds
    @urisrssfeeds 2 роки тому +1

    How do front-runners know which transactions to front run? Do they also know if a transaction results in money being transferred to the caller?

  • @theanimalix5877
    @theanimalix5877 Рік тому

    Awesome vid, you are a great educator!

  • @leetcodewhitebelt
    @leetcodewhitebelt 3 роки тому +8

    In your example, i see how the frontrunners took advantage of the exploit, by i dont understand *how* they knew that calling your contract with those inputs will give them eth. can u explain?

    • @OGZxBEEf
      @OGZxBEEf 3 роки тому

      can someone please answer this?

    • @SapiensHomo-k7r
      @SapiensHomo-k7r 3 роки тому +1

      The transactions in the pool are public. Which means the sender address, the contract called, the exact transaction of the contract, the inputs. Everything is in the open. The front running bots can then go through the pending transactions and try to evaluate which one would benefit them if they run it for themselves (using the now public inputs). In order to make sure their transaction comes first they pay more gas because miners prioritize the more expensive transactions.

    • @magicmedia.channel
      @magicmedia.channel 3 роки тому

      @@SapiensHomo-k7r thanks but you didn't answer the core question: How can they "evaluate" (in your words) in microseconds, that running this transaction would send them ETH? Even spending a little gas on millions of useless contracts can get expensive for them. So HOW exactly do they "try to evaluate" something that's only known to the contract author, or somebody who reverse-engineers the bytecode in microseconds and opine that executing this probably makes money.

    • @SapiensHomo-k7r
      @SapiensHomo-k7r 3 роки тому

      @@magicmedia.channel Anyone can run solidity code anywhere. The blockchain's state is public and free to use (reads are free, writes cost validation fees). They can just have a local blockchain with the same state and run tests there.
      The fees are required as a mean to ensure only valid transactions get recorded on the public network. Otherwise just running the code is (often) dirt cheap.

    • @SapiensHomo-k7r
      @SapiensHomo-k7r 3 роки тому +2

      @@magicmedia.channel Also they don't need to read the source code of a contract. They just need to run it with the current state of the main net, which nothing prevents them from by design (Otherwise nobody would be able to validate transactions)

  • @elku3775
    @elku3775 2 роки тому

    man. this is gold.

  • @fevicoI
    @fevicoI 3 роки тому +1

    Do you deliver trainings?

  • @decipherwithzaryab5106
    @decipherwithzaryab5106 4 роки тому +2

    Hey, Scott. This is indeed a great video man.
    So as of now I do have a long list of questions and doubts. And also I am desperately waiting for the next video on How to solve this Front-Running Issue?

  • @garyb99
    @garyb99 2 роки тому +1

    Awesome video!
    Great explanation

  • @metalpartiez
    @metalpartiez Рік тому

    Thank you for showing this!

  • @mrsmokinamigo
    @mrsmokinamigo 2 роки тому

    Great video, thank you Scott!

  • @felo806
    @felo806 3 роки тому

    amazing video thank you for sharing and spending your money to teach us!!!
    For these kind of attacks the first thing that comes to mind is to include the address of the sender in the message to be signed. That way, even if someone steals your transaction, it will end up being invalid as they will have a different address to yours. Is that the way to avoid this? Would be interested to know other approaches!

  • @RibbetRiches
    @RibbetRiches 4 місяці тому

    great explanation thanks

  • @lz6272
    @lz6272 4 роки тому +3

    Could you explain a bit on how they know copying your transaction would pay them the reward?

    • @thefish2010
      @thefish2010 4 роки тому +15

      I know your comment is 4 months old, but I thought I would answer. Most of these guys are running ganache, which is a program that lets you simulate transactions in a given block. They can then see what the transaction does during the simulation, and then decide if they want to try to front run it. Ganache is not the only such program, there are a few others.

    • @jesusmendezgalvez6586
      @jesusmendezgalvez6586 3 роки тому

      @@thefish2010 Hi, could you explain more please? docs, or courses

    • @urisrssfeeds
      @urisrssfeeds 2 роки тому

      @@thefish2010 that is plausible. I was under the impression that transactions also report output.

  • @PaperToProfit
    @PaperToProfit 3 роки тому

    Great video, straight to the point and with a really good example.
    Only critique is what sounds like a door closing in the distance or perhaps footsteps above periodically.

    • @PaperToProfit
      @PaperToProfit 3 роки тому

      oh probably the kids lol, I just noticed the drawing on the wall. Still great video

  • @langwang9130
    @langwang9130 2 роки тому

    Great video! I'd like to be a solidity auditor one day!

  • @kkjlai
    @kkjlai 3 роки тому +1

    Very well explained and demonstrated.. Thanks!

  • @code-swat
    @code-swat Рік тому

    Amazing, thank you!

  • @StyleTrick
    @StyleTrick 3 роки тому

    Great vid, explained in a clear manner!

  • @z.m.4331
    @z.m.4331 3 роки тому

    Great demonstration, thank you!

  • @abhimanyugrover2793
    @abhimanyugrover2793 3 роки тому +1

    How is it that hackers/bots knew that this transaction would result them in getting ETH, without the code ever being released or known?

  • @cryptoholic5120
    @cryptoholic5120 3 роки тому

    Great stuff Scott

  • @Juliapak
    @Juliapak 3 роки тому +1

    Thank you very much. I got a question: this mainly affects miners right? I would take it that those mining the eth are the ones validating the contract and getting the reward?

    • @epheph33
      @epheph33  3 роки тому +3

      Not necessarily. Miners normally aren't in the game of creating these transactions, they usually let bot operators fight for them and, when multiple bot operators compete, the gas prices paid for taking the opportunity approach the value of the transaction over time

  • @iamzeeshankhan
    @iamzeeshankhan 3 роки тому

    Incredible, loved the video

  • @MrNinja342
    @MrNinja342 3 роки тому

    Awesome demo

  • @luloxeth
    @luloxeth Рік тому

    I liked that you call the mempool "pending pool". That makes the concept so much easier to grasp

  • @wuxiaoeth
    @wuxiaoeth 2 роки тому

    Thanks for sharing this.

  • @l刘信
    @l刘信 10 місяців тому

    great video! thaks

  • @artvandelay5921
    @artvandelay5921 4 роки тому +2

    How do they know copying your transaction would pay them the reward?

    • @jagodic6796
      @jagodic6796 4 роки тому +1

      probably its miner who simulate the tx beforehand, try to mangle it and see if it somehow benefits. must be quite sophisticated

  • @ericfan4314
    @ericfan4314 2 роки тому

    Great video!!!

  • @outy4013
    @outy4013 3 роки тому +1

    A stupid question: Why cant I hard code the withdrawer's address(my own address) and require the msg.sender to be equal to it in the take() function?

    • @flatheadpolitics1895
      @flatheadpolitics1895 3 роки тому

      I agree. I would think that you would be able to set a constant value that represents your address and put a conditional statement in the smart contract to check..

    • @robanmodel
      @robanmodel 3 роки тому

      @@flatheadpolitics1895 yes, there are many ways to prevent front running, the problem he pointed out is that there are bots that simulate if they run the transaction, will it be profitable and if so do it. They pickup your message from the tx pool, check if profitable and then send it from their account.

    • @flatheadpolitics1895
      @flatheadpolitics1895 3 роки тому

      @@robanmodel Thanks for the feedback! I am still learning- lots of nooks and crannies to explore...

  • @CryptoRootz
    @CryptoRootz 3 роки тому

    great demonstrations, thank you.

  • @r4v1
    @r4v1 3 роки тому

    We would appreciate you making small solidity project tutorials. It'd be very helpful for the beginners.

  • @Oussamaabdallah
    @Oussamaabdallah 3 роки тому

    Amazing video, i would like to see how we can combat these attacks .

  • @jackgraham3813
    @jackgraham3813 4 роки тому

    Best video I have seen well done 🙂👍🌱

  • @angelosolazzo7095
    @angelosolazzo7095 3 роки тому

    It is possible to do front running with flash loan to use as funds ?

  • @connor8268
    @connor8268 3 роки тому

    How are they able to simulate how much there is to me made, what if you had submitted the transaction with an incorrect value?

  • @spiz02930
    @spiz02930 4 роки тому +1

    great video mate

  • @TheLightofScience
    @TheLightofScience 3 роки тому

    This is very valuable tutorial, thank you so much sir

  • @babylonventures3533
    @babylonventures3533 3 роки тому

    Telos is solving this problem with their EVM which will release before end of summer

  • @MagicPlants
    @MagicPlants 3 роки тому

    Excellent job!

    • @MagicPlants
      @MagicPlants 3 роки тому

      Are you interested in having an intro or any channel graphics or animations created? I would love to contribute.

  • @jaytime662
    @jaytime662 3 роки тому

    Love the vids! Plz make more!!

  • @tendies
    @tendies 3 роки тому

    Thank you for this information

  • @quochaiphan5261
    @quochaiphan5261 3 роки тому

    How to deploy large smart contracts to main net binance , error timedout or pollingblocktracker. Can you help me, please

  • @vanessabridge1498
    @vanessabridge1498 3 роки тому

    this is wild! I cant believe I am only seeing this video until 2022

  • @Flutesy
    @Flutesy 3 роки тому +1

    great video! how can we combat front running? id love to see that video! also, if one were to front run, what would be the slippage tolerance?

    • @realwit4976
      @realwit4976 3 роки тому +3

      There are multiple ways to solve this, but a general solution would be to allow only authorised users to execute the "take" function. You could use this by having a custom modifier that checks if the message sender is in a whitelist stored in the smart contract.

  • @luci0rullz
    @luci0rullz 3 роки тому

    awesome video bro

  • @jessojohn9226
    @jessojohn9226 2 роки тому

    Where they able to front run because the secret you passed when calling the function was visible to everyone? Is there any way of encrypting the message call to make it difficult to frontrun?

    • @epheph33
      @epheph33  2 роки тому

      Exactly, the pending pool is public (just somewhat difficult to see in time, requiring special tools). Encryption won't work, because the tx needs to work on the miner/validator. It can be privately relayed to that party or you could try some tricks using several transactions that work together, but it would still be possible to front-run, just more difficult for the counter-party

    • @jessojohn9226
      @jessojohn9226 2 роки тому

      @@epheph33 do we have to privately relay to every miner on the blockchain?

    • @epheph33
      @epheph33  2 роки тому

      @@jessojohn9226 Check out my most recent video

    • @jessojohn9226
      @jessojohn9226 2 роки тому

      @@epheph33 so flashbots relay can be used to send transactions directly to miners in bundles.but if the block is mined by a validator that does not integrate flashbots, the transactions get failed right?Also flashbots transactions are not visible to anyone?

  • @omparikh4426
    @omparikh4426 3 роки тому

    This is gold!

  • @RickSkunk
    @RickSkunk 3 роки тому

    great video

  • @coupeL0VE
    @coupeL0VE 3 роки тому

    scott brother u rule

  • @alduouzconde580
    @alduouzconde580 2 роки тому

    Hello! I've started learning coding to eventually build NFT bots and flashbots. What language do you think I should learn first? Is python any good before I try solidity? Should I change to js? Should I do solidity immediately? Thank you :)

    • @epheph33
      @epheph33  2 роки тому

      I would learn Python or JavaScript (or TypeScript, a language built on top of JavaScript that makes things friendlier) first. Don't learn solidity first, you need a "local" language to run the bot.

    • @alduouzconde580
      @alduouzconde580 2 роки тому

      @@epheph33 I appreciate your response a lot! I'll pay this back somehow :)

  • @RetroKafas
    @RetroKafas 3 роки тому

    Great content!

  • @eldadperetz9262
    @eldadperetz9262 3 роки тому

    How did they know that will be rewarded by 0.035 ETH?

  • @noeldsouza6395
    @noeldsouza6395 4 роки тому

    Thank you so much

  • @sricharan1368
    @sricharan1368 3 роки тому

    great video mate, why not make a video on how to frontrun, i hate the front run feeling on bsc when ever we make a big buy the bots buy before us and sell after us, now i wonder how they do it.

  • @protocoltechnologies7867
    @protocoltechnologies7867 2 роки тому

    Hello i am very influenced with this video i need your help can you help me with one of my contract?

  • @aposenteiComBTC
    @aposenteiComBTC 4 роки тому

    Nice video. Why wen I increase the slippage on the Uniswap the system says "Your transaction may be frontrun", if the the frontrun occurs I could lost the transaction funds? And, the frontrun would be similar to the exemple on this video? Thanks! :)

    • @thefish2010
      @thefish2010 4 роки тому +7

      Not exactly. The front running you are seeing in this video is different than the front running in Uniswap. Your funds couldn't be "lost" per se on a Uniswap transaction. When Uniswap talks about front running, what they mean is that if you allow high slippage, people can insert a transaction in front of yours, that runs up the price up close to your allowed slippage, and then trade those coins back into the pool at a profit (through another separate transaction) after your purchase goes through (because you will have further raised the price when your purchase went through).
      They should actually tell you that your transaction may be "sandwiched" because this technique is referred to as a "sandwich attack" - one transaction gets inserted just before yours (to buy the coin) and then another right after yours (to sell it back at a profit). It is called a sandwich because you get stuck in the middle.

    • @epheph33
      @epheph33  3 роки тому +2

      @@thefish2010 ^ Exactly

  • @lifeoftraderlot5647
    @lifeoftraderlot5647 3 роки тому

    We need audits

  • @fevicoI
    @fevicoI 3 роки тому +3

    $8 spent them are now $80.

  • @bb-kw7tq
    @bb-kw7tq 4 роки тому

    could you potentially get front runned if you are just transferring coins from one account to another? Or is that not a concern because there is no "reward" for copying the transaction and using higher gas fees?

    • @epheph33
      @epheph33  4 роки тому +4

      Bryan Breznau the tokens need to be available to everyone to benefit from copying. Your own tokens are locked to your account, so they can’t be front-run. Here’s another article that discusses this: medium.com/@danrobinson/ethereum-is-a-dark-forest-ecc5f0505dff

    • @animator7584
      @animator7584 4 роки тому

      @@epheph33 could a require statement stop this frontruning?

    • @jonan2199
      @jonan2199 2 роки тому

      @@animator7584 require msg.sender == Animatorsaddress

  • @dscmtr686
    @dscmtr686 3 роки тому

    how front-runners know how much they would get from running a transaction?

    • @epheph33
      @epheph33  3 роки тому +3

      Check out my other video about Honeypots: ua-cam.com/video/DDn5mksOUCc/v-deo.html . Ethereum RPC offers simulation endpoints, and an advanced bot can simulate everything it sees

  • @jagodic6796
    @jagodic6796 4 роки тому +1

    i deployed a contract which pays its content to the msg.sender. i sent a tx to it and submitted it with very low gas, but now its 10 minutes and nobody copied/frontran my TX yet. but i made my function so it costs 0.01 ether, can it be cause of that?

    • @epheph33
      @epheph33  4 роки тому +1

      It has to be enticing enough compared to the gas fee required to run the transaction

    • @thefish2010
      @thefish2010 4 роки тому +3

      In addition to Scott's reply, just FYI, very few front runners will run transactions where they have to send ETH to unknown contracts. Also, as he said, there has to be enough value to cover the all transaction costs plus a profit before they'll do it.

  • @JaredMassa
    @JaredMassa 4 роки тому +2

    if only he knew what gas was going to become

  • @FG-qs8uj
    @FG-qs8uj 4 роки тому

    do front runners try any transaction? what if the transaction does not yield anything in return? it seems like they are taking a lot of risk without knowing they will be rewarded.

    • @thefish2010
      @thefish2010 4 роки тому +3

      They simulate the transactions locally using a program called Ganache, and they get to see what the transaction will do when it is run in the blockchain. They only do this when that test shows that the transaction will result in a profit.

  • @日本人-i4e
    @日本人-i4e 3 роки тому

    good

  • @realwit4976
    @realwit4976 3 роки тому

    By storing the "secret" in a private state variable, there is no need in front running it. You can just simply read the states from the raw bytecode of the smart contract xd.

    • @epheph33
      @epheph33  3 роки тому +1

      The secret wasn't there, the hash of the secret was. Nobody knew what the value that hashed to that state variable until it appeared in a pending transaction

  • @stavalfi
    @stavalfi Рік тому

    crazy

  • @dineshbs444
    @dineshbs444 3 роки тому

    Ethereum is really a dark forest

  • @kz687
    @kz687 2 роки тому

    Most of front runner not on UA-cam are scams! I

  • @TunaIlgaz
    @TunaIlgaz 4 роки тому

    LMAO wild wild west

  • @danilvlasov8666
    @danilvlasov8666 3 роки тому

    +++