L11 - How to Prevent MEV | by Vasu | BlocSoc Lecture Series
BlocSoc Lecture Series · 25:36
Vasu examines MEV, including sandwich trades, arbitrage and liquidations. He explains proposer-builder separation and MEV-Boost, then discusses builder centralization, relay risks and fallback behavior.
Speakers
Topics
From BlocSoc Lecture Series, published by BlockChain Society IIT Roorkee; community: Blockchain Society IIT Roorkee.
Transcript
in today's lecture uh welcome everyone uh in today's lecture we will study about preventing m in sequences so in last lecture we had a brief in about what m is and what are its types and what are the good and bad it holds for the CM ecosystem today's lecture we'll go into more depth of it or how does m really affect the ecosystem be positive or the negative sides and what are the steps taken by the community to basically build upon this and kind of trying to tackle it or maybe trying to just live with it so let's begin uh so what is M uh here is a summary from the last lecture uh maximum profit which a Blog producer can get uh
basically by manipulating the me so you change the order of transactions or you change the arrangement of transactions in a block so it's basically the maximum value you can extract from a Blog production in additional to you know the standard reward you get and the gas spe you get this is the additional money block producers try making uh from basically the me miners or validators the generally through transactions from the MEO in the block which pay the highest fees that makes sense economically right uh so there is a term in M called Searchers what are these Searchers they basically scan the meol continuously through complex algorithms so the meol is public right so this uh they spot M
opportunities in the meol and what you they do they quickly Place their transitions with a higher gas fees to get their transaction related with first uh it does involves risk because you're paying a lot of gas fees and sometimes it ends up being in a lot of competition among different uh miners or validators who are trying to compete for that same M but uh the risk is worth it uh examples of M includes FR runs arbitrages uh sandwich and liquidations these are four General types of mu transactions uh and interesting fact is that 99% of Meb transitions are Arbitrage and sandwich transition so there is a term in uh M which is called gas calling so what is
that is you try to program transactions in a way that it uses the least amount of gas so you basically optimize your contracts or if you're not using if you're not doing a contract based transaction you will just try to program it in a way that it uses the least amount of gas so what it does is it allows the Searchers to set a higher gas price while keeping their total gas fees constant so so the equation is gas fees is equals to gas price multiplied by gas use right so you can set a higher gas price if you basically uh use a lower amount of gases it's inversely proportional right uh example techniques include uh using addresses with a long string of zeros what it does is it consumes Le less space right in the
stack and so it occupies less gas and takes less amount of storage space to store another example can be you leave small uh token balances in your contract uh so instead of just uh emptying them or draining them completely you leave a small amount of balance in your contracts what it does is it costs more gas why you do is because it costs more gas to initialize the storage slot storage slot happens when the balance is zero in your contract uh so it costs more gas in that case then it costs to update a storage slot what of print Runners uh so basically they are generalized BS uh what I told uh basically the most common form of MV you you just watch the meol continuously and detect profitable opportunities so these
are the type of transaction so this is a flow chart showing a sandwich transaction so what a sandwich attacker does is uh the attacker was continuously monitoring the me pool and just got to know this uh uh Target transaction so assume it's aveil and this transtion involves a large amount of e being purchased for example uh so this will definitely cause uh a dip or an assurgent price right so what uh the Tacker will do is he will place a transaction which will involve a higher amount than the target transaction before the target transaction so you FR that's called front training a transaction you place your transaction before that and how do you ensure that
your transaction will be uh uh basically uh arranged first in the block is by paying a higher gas Fe to the validator so they validate your transaction first and what you do is just after the target transaction you back run your transaction so what happened is uh when you front R you bought a large amount of a token at a very low price and after the target transaction has taken place and your front wining transaction has taken place the price is definitely searched right this is the this is what happens after after sandwich this and uh just after the price has searched you just dump it dump it so this is the amount that uh that is uh the profit of an attacker and it's a zero some game for the am that user loses is the amount
that attacker profits so basically uh uh uh ignorant people are just victimized uh so this is the most dangerous form of mu transaction and uh it seriously uh dampens the ecosystem's opportunity to you know to scale and expand another type of transaction is liquidation what uh so this is an example of a which is a lending and boring protocol and you have a concept called Health Factor so whenever your health Factor drops your collateral can be liquid right so what do they do is attackers in these case they observe such accounts uh which are on the verge of liquidation and as uh they're not unable to basically pay their fees back so what do they do is
they settle the transaction on behalf of them and they take the collateral plus the liquidation fee and they repay the loan on their behalf so this collateral plus liquidation Fe minus repay loan is that amount which uh uh the attacker will benefit in this case this is a positive side of me because uh they are in this case helping a protocol like a maintain its health because uh health of any land lending protocol depends on how well people who have borrowed from there are able to repat and S this transaction was a trans was a type of M where uh it seriously uh impacts the ecosystem negatively this is the third type and the most classical type of M transaction which is an Arbitrage transaction so
what an m b does is it uh places swap event on unisoft for 0.065 for example swaps it with another token on Sushi Swap and then just swaps it back to 0.069 so basically it's trying to uh you for the same asset uh if two different uh your Protocols are offering different price so you harness that opportunity uh of difference in prices at two different dexes and you just uh make a profit which was 0.04 is here and if you like what T for does is it is they'll scale this transaction to a massive amount let's say 65 E or 650 and then and like uh for now the profit might sound very less but if you multiply it by thousand
the scale in actual transactions happen in case of M then this will be like a a free money for basically nothing done just being a little more smart so what are the solutions you ask uh so the topic is PBS flash BS and M boost uh yeah it might sound overwhelming at the moment but uh let's try to uh get into them one by one so what is PBS it was the most famous architecturally proposed method to tackle Im so what happens in what happened at that time was present day eum uh so this the present day in this uh slide uh means uh there when this uh this method was not developed so etherum validators create and broadcast
blocks that's what gener happens in ethereum right you have a validator who will create a block and then will propose it and then other validators will basically vote for it what you call as attestations and after it has achieved a majority which is two3 of the votes uh the block will be justified and after another block is Justified on top of it the block will be finalized so this was a standard method for validating a transaction on etherium chain what what this method proposed was proposer build a separation so the task of proposing a block and the task of building a block was separated in this so it splits these task across multiple validators now blog Builders are the ones who become responsible for creating
blogs and offering them to the blog proposer in each slot so that you have a new role introduced which is a Blog Builder uh and what does that blog Builder do is basically uh uh that blog Builder will now create every blog and it will offer them to the blog proposer and the blog proposer cannot see the contents of the blog what do they do is they simply choose the most profitable one uh and they pay a portion of the fees to the blog Builder before sending the blog to it peers for validation so what it does is like how does it make sense is that uh initially like solo validators who don't have very complex algorithms to run can be left out of the system in this case where M because M can lead to centralization very easily can lead to centralization because
Advanced uh systems can not be used by everybody and so what this does is let the task of extracting MVP on blog Builders who have very sophisticated hardware for that purpose and uh let individual validators like you and me be blog proposers and so blog proposers will definitely get the share of MB and what this does is it will uh more equitably distribute the Rewards or more equitably uh share the rewards among all the validators so the Builder will basically extract the M opportunity and then we'll bid we'll make a bid and send it to the validator with a promise that uh if you include my
block uh uh so we sh split the profits right and every validator who will attest to that block will also be having a share of the profit so now everyone can get a much more fairer share of M uh in this case rather than compared to M centralization what is flashboards so flashboards is a research and development organization uh which works on uh uh minimizing the negative effects of Meb and avoiding the risk Meb could cause to blockchain like ethereum uh their products include me boost sua uh M inspect M get M RS M explore and many many more so yeah M boost which was mentioned here is one of their product is only so what is me boost it is an
open source middleware uh which is run by validators to access a competitive blog building market so just now before I told in PBS uh that now blog Builders are the one who are building the block so they use a sophisticated software called M Bru which is a middleware and so basically it is run by validators to access that market so you can't so proposers can't really access uh Builders without MV boost because you have no guarantee that uh the Builder who has bid who has made a bid will definitely pay uh the proposer uh the fees they promise to pay until there is a there is a commitment made right uh so what flash wordss does what M boost does this uh it uh kind of legalizes that
commitment and so now uh the is uh obligated to pay so uh that Builder doesn't ends up losing reputation and just gets thrown out of the network or seded out of the network so me boost is an implementation of PBS for POS ethereum right so PBS was used separated and currently uh ethum doesn't have that feature uh so validators are the only one who propose the block each validator is chosen randomly to propose a block uh taking the number of validators which is the current number of validator in ethereum network you get to if you are active on the ethereum as a validator then you will get to propose a block let's say every two months approximately
consider the number of validat ethereum currently has which is a very large number uh so uh right now the Builder uh methodology is not implemented directly but it is in process and MB boost is one such implementation so you have something called as a builder API which we will look later in the lecture and so Builder API is that community unication spec which allows this Builder and proposer to communicate so MV post legalizes that commitment which Builder was bidding for and M poost ensur that the share is being distributed so now validators can access blocks from a Marketplace of Builders Builders produce blocks containing the transaction order flow and a fee for the block proposing validator separating this role promotes
greater competition decentralization and censorship resistance as I explained earlier so now is it okay to centralize building that's a question that might po up in your head because right now in PBS what we are trying to say is doesn't matter who proposes blocks right we said that large institution investors can because they have a sophisticated Hardware so is it isn't it like centralizing block building well the important concept is pro verifier asymmetry and it refers to the idea that centralized blog production is fine as long as there is a robust and a large number of validator network who are able to prove that the blocks which are built by the builders are honest so as vitalic say decentralization is a means not an
end goal what we want are honest blocks right so basically it's completely fine if the person who is building the block is a centralized entity doesn't matter but we do have a very large number of nodes what you call as validators who are able to prove that the block which was built by that entity is fine so you don't have any more sensorship resistance or centralization in the main Network so uh this this is how M boost actually works so let me explain it uh so this this is your user and this is that role I was talking about Searchers what these Searchers do is is they will track for those profitable opportunities and these are run by Builders right and they might they might be independent
they might not be so these track for profitable M opportunities share it to the builders so Builders will pass them through something called as relays relays will pass them through M boost and now this was your ethereum client right uh which is which which has an execution layer and a consensus layer both engines are running and local blog building is taking place but uh as I mentioned the client can't directly communicate to the Builder so what it does it does through the Builder API so this is a an experimental implementation of uh PBS proposal Builder separation in current ethereum you can't directly communicate but you can surely communicate through this and it has several function which will look later uh on how does consistance client really
communicate so uh this is a basic flow of how a block building takes place the Builder will build the block propos it to the relays pass through the M boost the M boost will extract the most profitable block will pass through the Builder API and then the consensus will vote that I'll propose this uh XYZ block so let's take this very simple example and this will make clear every single thing I just spoke currently so we have a serger a he has a bundle of transactions here from the MEO he identified these three transactions uh 0 x0 0 X1 0x2 and uh the in net profit 0.25 we to the vator we have another Searcher who has just one transaction in his bundle but that
single transaction can profit one e to the validator we have yet another Searcher who has two transactions in his bundle and those two transactions collectively can profit two e to the validator and we have yet more Searcher who has two more transactions and they can collectively profit three e so these Searchers according to their capabilities have identified some potential transactions from the meol for so which will they will broadcast to the buiders and the the transactions accordingly varies in their profitability which was 0.251 2 and three just be careful of the numbers because those numbers will add up of what this really means so Searcher a Searcher B and Searcher C broadcast their transactions to Builder a so Builder a gets this blog0 x0 and what he
has is bundle two bundle one and bundle 0 arranged in their order of profitability which was two e 1 e and 0.25 e respectively and if you sum them up this will in net profit 3.25 all right and Searcher B Searcher C and Searcher D what they does is they also broadcast their transaction to Builder B so Builder B has this block which is 0x01 and arranged in their profit transactions are arranged in their profitability order which is bundle three which is three e bundle two two e and bundle one which is one e and in total it sums up to net six e so now you can really startingly see the difference of what Builder a is proposing a block and Builder B is proposing a block and this block has almost half the profit of the block that Builder B proposing and so uh from
here itself if you don't even see the rest of the architecture let's say you hide it uh if there was no Builder there would have been a centralization at this point because the validator would never ever get the share of what this profit means right and so what now Builder does is Builder a uh sends his block to relay a and relay B what uh the same relay I talked about here right these are the relays which are used to communicate with M Po and so Rel a what does is Rel a tells blog 0x00 is the most profitable to propose relay B tells blog 0x01 is the most profitable to propose okay so this is your me boost now your proposer as we mentioned earlier doesn't knows
your Builder doesn't validator doesn't knows that what are the contents present inside the blog so a blinded blog 0x and a blinded blog 0x01 one will pass on to the m boost this is your first step okay uh so both blocks which are blinded because the validator can't see what are the contents inside the block he will just have to assume what MV boost tells that will be fine so the MV boost now compares the profit which was block 0x and block 0x01 0x01 will profit 6 e to the validator and block 0x will profit only 3.25 so M boost tells that block 0x01 is the most profitable block to propose to your client which was your
validator so the consensus client now after getting this instruction from MV boost will say I will propose 0x01 since that makes me more profit right so now M boost will request the Rel to uh say that validator will propose 0x01 fine so relay will send the full block 0x01 to M boost and then M boost will send the execution payload for this block consensus client will then propose that block validate that block and after getting an uh two3 of attestations the block will be finalized block 0x01 is on your eam network so this was your whole architecture which goes behind before a block is now finalized on the Chain uh in case of M boost so these are
Searchers who spotted opportunities they sent it to builders builder then bundled them according to their profitabilities sent them to relas relas said that this is profitable according to me and this is profitable according to me the blinded blocks are then sent to M boost M boost Compares what is sent by the and then tells the consensus client that this XYZ block is the most profitable to propose consensus client has to believe what M boost says and uh we'll just propose that block because what consensus client gets is blocks and the profitability they offer that is it they don't get to see what are the transactions present so no censorship at all and M boost now will ask the Rel that validator will propose this block so please send me the full block the
full block will be received and the execution payload will be sent to the cons client and then your normal execution consensus client communication will start and your block will be finalized on your ethereum n so this is how M boost Works in its architecture and I hope it was very clear and if you go function by function on how this relay uh M boost and consistence communication really happens so I showed six steps which were uh Layman's language of what this this works how does it works and if you go into the the more depth of trying to understand the specs of how does it works then this is how it works so consensus client starts up you use the function the consensus client starts up
you use the function register validator on the M boost the validator gets registered M boost then register that same validator onto the relay now consensus client will waits for their allocated slot so this slot we are talking about the general slot committee right which works in ethereum based on Rand F and after get uh the consor client has achieved their slot they will use the get header function to request the header of the blog they they are going to propose the M boost will then broadcast that function to the relays relay will send a response which will be get header response MB boost will verify that the response matches as it was expected and it will also select the best payload right as it said that M post will tell that this was the most
profitable block for you and the cons client will just get that response we'll sign the header and will then ask for payload from the M boost M boost will then identify the payload Source among all those relays that are sent request that particular relay to uh give the payload the relay will validate the signature that is coming from that particular consens client it will give the payload response and MV boost will again verify if the response matches expected and the consens client would then get the payload response and will then just go on to the validation and the two3 stations and the block will be finalized so these are those four functions that are used in this process these four functions are the core part of Builder API and also your M boost uh repository if you go into that and try
to study of how this code really works uh so this was uh the uh uh overview explanation of how you'll try to understand and this was the function by function explanation of how Meb boost works and this is uh your PBS uh and this is the solution we currently have to tackle MBS so basically your trying to prevent censorship as well as you are trying to distribute the shares which was identified by The Searchers equally among all the validators th promoting more decentralization so that's it let's move on to the last part which are the risks and the considerations you have to take while uh using M poost right so number one is Li uh liveness and local fall
back so the ethereum network has to be alive at every single time right you can't lose any particular State and uh if the network is halted for let's say a few seconds or minutes also so then it can be troubling so to prevent that risk MV boost is implemented as a side car for consensus client software like if you see this m boost is just integrated with the C client and it's not on the ethum main chain at all so you run M boost along with a full consisten node as well as an execution node on your system so it doesn't affects any other validator if you are running an M uh next is Builder centralization so a builder that dominates the market
because of its uh you know outsize profitability it gains the ability to for censorship now you should note that MV boost is not something that is prop uh that is uh creating censorship right it is me that is creating censorship not me boost M boost is in it trying to basically encourage the competition among a lot of Builders to basically build the most profitable block and then just broadcast it onto theor so MV boost is trying to tackle this bindle centralization but it is definitely in its very early stage RK then there is another risk which is Builder or relay pollution so anyone can be a relay right this was the most trickiest part in this that relay is centralized yes relay is centralized in uh M boost implementation
and now you might just ask that that that is a problem as well because really can according to its wish block a particular transaction or can unblock a transaction as now while this is a you know a strict improvement company to the m extraction model which was in proof of work ethereum but relays can still be a risk and they can be a risk to both Builders and validators because the Builder is also is also trusting Rel that the relay will forward they block and the M boost is also trusting that relay is you know sending that most profitable block and uh another is then very obviously comes malicious relays so nothing prevents malicious relays from submitting fraud beds right uh and that
will obviously affect the profit and your last is Meb hiding uh this is something that node operators uh when managing uh when trying to make offchain deals with customers uh they are incentivized to hide M Rewards in a given block and then this also basically uh you know makes the network suffer and everyone in the consensus committee suffer because uh they are trying to basically uh demonitize uh the whole system of decentralization so this was it uh about maybe I hope uh it was uh it was clear and uh thank you