Privacy in Cosmos Live: Shane Vitarana (Stargaze)- MEV in Primary NFT Markets.

6 May 2022 · 17:03

Shane Vitarana of Stargaze gives a talk at ZKValidator's Privacy in Cosmos: Live event in Amsterdam on MEV in primary NFT markets. He examines how miner extractable value dynamics affect NFT minting and primary sales, extending MEV research that originated in DeFi trading into the NFT space.

Speakers

Topics

Transcript

guys uh to this uh talk this is the last talk in this room for today so let's welcome shane uh vitarana from stargates so shane all yours thank you hey guys how's it going so um i'm shane from stevargays and i am going to talk about mev and nft primary markets so let me go ahead and share my screen okay

so mav in nfg primary markets so what am i talking about here when i'm talking about an mev so in this context m stands for minter minter extractable value and um when i'm talking about a primary market i'm talking about the first sale between the creator and the collector so this is not about the secondary market which is something like openc where you have bids and asks this is only about mev in the very first sale and um the minter is the person um in this case is minting the nft for the first time

so just a note about um mev in tenement uh because tenement uses uh an ordering of first in first out it it eliminates a whole class of uh mev that you get in other blockchains where you have uh priority gas gas auctions so in this case mebs only contained to the nft minting size and and the order of the minting so to understand this a little better we first need to understand the anatomy of an nft which has both on-chain data and off-chain data

so first let's talk about the on-chain data now um the on-chain data um is uh in the nfd collection in the case of stargaze uh it's a sg721 and you have this mapping of token ids and token uris the token uris is the metadata file that is stored um on ipfs for a lot of the generative collections like you see on on stargazers for like start shows and stargaze punks and a bunch of all the other collections the way it's stored is that you have a base url

which is a url to the folder and then you have a token id and every time you mint it just goes to the next sequential token id um so that kind of long string of characters you see over there is the ipfs content id and this is basically a hash of the content so so this is how content addressing on ipfs works so now if someone goes to ipa and changes the data it also changes the link that the data points to so this is how uh you know if the data for the underlying nfg changed or not um so on chain you have a record of the ipfs content ids that are

associated with with each token so let's let's take an example let's look at an example of this right so this is um star chart or baby cho 1829 you have uh the nft on the left you have the you have the metadata on the on on the left side and this is just a json file uh it has a name image and then it has a bunch of attributes or traits and you can kind of see the representation on the website on the right hand side so the traits is what gives the rarity for an nft um and and and this is how nfts are typically valued so for example uh in this nft you have uh this baby child has um

um a head of aqua mohawk and only one percent of um nfts in this collection um have an aqua mohawk um so this is represented in this uh in this metadata so um anyone looking at this uh can look at the whole collection compile um all the rarities and figure out a rarity score um for each nft in this collection so given that the problem we have right now is sequential minting right so so now if you go and mint an nft um

you know ethereum also started this way um the you have a problem of sequential minting where um every time you meant it just increments the token id by one right so let's break it down to like a very trivial case where you mint uh one of nft per block right so let's say that um right now you're on block four four five nine and someone minted baby chilled four four five nine um but by looking someone who's really savvy can look at ipfs and figure out um that baby child 4461 is incredibly rare right so uh in this case um that that nft has the highest rarity score

so knowing that someone who sat who's savvy can wait for two blocks and then mint the exact nft that they want and they can snipe it this way so can the devs do something how do we fix this problem so i'm just going to kind of walk through um a few of the solutions here so they kind of ordered from uh from easy to hard okay um ipfs submarining um is one way to solve this problem so the way this works is that um a creator would uh publish the the metadata

to a private ipfs note and because of content addressing nothing has to change on the contract side so they can go ahead and deploy this contract but won't have to change any of the token urls because um once this is published to a public node is going to be exactly the same right so first they publish it to a private node and then they do the minting right then everyone comes amidst their entities and then only afterwards the publishers to apply to to to a public node right so this way um the creator hides all the metadata and uh there's no way for the

mentor uh to know um and and and figure out which nft they want uh in in order to snipe it now uh the advantages of this is that for the developer they don't have to have to do have to do a thing right this is this all kind of falls in into the hands of of the creator um the disadvantage of this is that um the ux is worse right so so now when when the user mints they don't get uh to see what they got got immediately right they have to wait until either a validator some third party or the creator themselves goes ahead and publishes the public version of the inft all right

and then reveal later is um is very similar right instead of publishing to a private ipf's node first the creator goes ahead and publishes a placeholder collection to ipfs so generally this is like some kind of animated gif that just kind of rolls through a sampling of the nfts in in the collection um then the user go goes ahead and performs the mint um and then when they do that they just get you know this kind of like um a random sample it's not the real nft they minted and then they have to wait for the creator to go and upload um the real version of it and then they get the

nnft right so uh the advantage of this again is uh you know the the developer doesn't have to do anything but the smart contract has to have the ability to go and update uh the token uris of course the disadvantage to the user is that they have to wait until uh the creator goes ahead and uploads the real the real collection um so what can we do can we make uh the ux better so that the nft is available as soon as the mint happens so this can be solved

using randomness and a shuffle and shuffling okay so the way this works is that first you have to generate a random number um the reason you need a random number is because it's an input into the shuffle algo so in this case we're using fishery eights which is a well known shuffling algorithm um and i'll i'll get back to the randomness in a little bit because as some of you may know is not trivial to generate a random number on a blockchain is because you know every node would have to generate the same random number at the same time for it to work

so um so there's there's various approaches to solve solving that problem but this is the approach that stargaze is taking and uh let me just go over this a little bit so first when a collection is launched um it all the token ids for that collection uh is randomly shuffled okay so that solves the sequential momentum just a little bit because now you don't know um exactly which one you're gonna get next but someone who's savvy can look into the blockchain and query the data and um you know know which one still that that that's going to be minted next

um so so this is you know better than just regular sequential minting but but it adds a bit of a extra extra element to it so um so you can't just do the single shuffle right you have to do do do a little bit more than that um so what we do is that on on the minting process we do another smaller shuffle so what this does is that it takes um a range of token ids either from the first uh either from the front of the list or from the back back of the list and that's going to be random right so you don't know if you're getting one from the front or the back

and then it does a secondary shuffle on the minute and that's how that's how you get that's how you get the nft right so um the reason uh for not doing a full shuffle on each mint is because it's an expensive operation so if you have um a collection of ten thousand you don't want to be shuffling that on every mint now someone could still potentially figure out the order so you need another element to this and that is having a shuffle function that anyone can call

when when anyone can call the shuffle function uh it adds an element of time to it right so now if someone's really savvy they can figure out exactly what's going on inside the blockchain they don't know that at uh they don't know exactly what they're gonna get next because anyone can come and call it the shuffle function um uh and and and that randomizes the order again um so anyone can call this and generally um it's something that maybe whales can do and and and when whales call this function they're kind of socializing the cost of it and you know they're also kind of benefiting the blockchain at the same time

and the reason for this is at least in the context of stargaze it has this fee structure called fair burn uh in fair burn 50 of the fees are burned and fifty percent go to stakers right so when whales come and uh do the shuffle um they're they're actually uh you know helping the network in two ways they're helping to randomize the collections and they're also um you know potentially increasing the value of the token and and also uh you know distributing fees to all the stakers um so this is this is kind of neat so um i mentioned earlier that getting randomness um on a blockchain is non-trivial

um well one way to do it is to use a service called drand d rand is run by a consortium of companies i believe and they generate um a random number every 30 seconds now now blockchains can't talk to the outside world right they can't just use the api for d rand and get a random number um so so the way this has to work is that some external party has to submit the randomness to the chain right so let's say you have a smart contract um you know in our case it's kazuma awesome right so there has to be some kind of incentive structure some kind of bounty

maybe some kind of reward for submitting um some for submitting a random beacon and and also this random beacon is expensive expensive to verify uh so one thing we're thinking of doing is to uh is to implement this in an sdk go module uh so um so the gas will be less to verify um another option is to build this into tendermint itself and kind of like provide it as a service to uh you know any any chain that wants that one the one that wants to use it and once again this is the input that is fed into the shuffle algorithm

um okay and um so one one more thing i wanted to mention is that uh another potential way to to do this is to use a threshold decryption um this is a bit beyond the scope of the top because we have decided to go with the the random shuffling approach but this is probably another way you can do it right um in cosmos and intended you have a validator set that validator set could be in control of a decryption key so when the seller publishes the collection they can encrypt the ipfs cids or they can also you know encrypt a

shuffled version of the set and then during the mint operation um the evaluator set can go and decrypt uh either the token id or the or the uri and this is something you can only do in a app specific chain and this is probably cheaper than verifying a random beacon so this is probably more of a advanced way of doing it of doing it that we might explore a bit later okay anyway folks uh that's all i had for my talk uh you can reach me on twitter i am strain3v on twitter

um a bunch of people helped me out with this talk so um uh you know hats off to them and um also uh you know if you're interested in any of this stuff if you're interested in in nfts uh with causa and mechanism design around nfts you know please please get in touch uh you can also check us out at stargaze.zoom thank you