A zkMNIST dApp, Applied ZK - Day 1
Ethereum DEV NL·Sun, Oct 9, 2022, 12:00 AM
We introduce and demonstrate a dApp with a zkSNARK prover/verifier for a simple computer vision deep learning convolutional neural network for handwritten digit recognition (MNIST). This enables on-chain verification of off-chain, private data. Potential applications of this type of zk technology may include the protection of sensitive and private information such as personal financial info, personal biometric info, or private video/audio/image data. Speaker(s): Francis Ho, Horace Pan Hosted at Devconnect Amsterdam, 2022 Visit the website: https://devconnect.org/ Or follow @EFDevconnect on Twitter
Transcript
[Music] uh hey everyone i'm horse and uh me and francis we're going to show this zkmnist app all right um to set the stage a bit um why are we interested in machine learning and uh zero knowledge proofs um so from some of the past talks and demos we know that with zero knowledge proofs we can take private data perform some computation on it and then generate a proof of uh or certificate of the result right and that's really useful for uh machine learning applications where we often have uh things that we to keep private right so we might have like some sensitive data like biometrics that we don't want to reveal or maybe we have like a machine learning model that we want to keep private because it's like intellectual property right so some applications yeah we might have a private model but public data or a public model and private data or public model and public data right um so in the case of like a private model in public data example of this is let's say we have this tumor classification model that we want to keep private but we want to like uh just like certify that this this model is actually really good it classifies like 99 percent of images correctly on this public nhs public tumor data set right or if we have some uh public model and private data suppose let's say uh some insurance company or yeah some financial company they have a publix credit score model um and you don't want to release your like financial information but you want to like certify that oh uh i actually do have the assets to qualify for this big loan right and then finally in the case of like a public model and public data there's no sensitive information but it's still like useful to verify the correctness of the results of applying this machine learning model on this public data right okay so as is tradition in the machine learning community um we always do a proof of concepts on mnist which is this uh handwritten uh uh data set so i'm gonna open up this app okay so in this uh in this demo we have a uh public uh machine learning model and uh here we're like picking uh digits uh to use as our like private data set and we're just gonna classify them so this will take like i don't know a few seconds so we picked 8 2 1 3 and 6 and it's almost right um all right let's see and i know francis is going to talk a bit about the model end all right thanks horace i'm francis so um i want to give you a bit more kind of under the hood what's going on so in case you're you know from the crypto community not familiar with machine learning basically the example we gave here is a kind of very simple what's called a cnn convolutional network and it's basically a series of as you can see here a series of modules each module is very simple it's basically some kind of matrix multiply so it's times an ad basically repeated many times and then there's some kind of a non-linear function and that's essential so you just stack them on each other and that's a very kind of a plain vanilla neural network and most neural nets are basically variants on this so the point is that this is fairly easy to put into a snark because the you know the circum circuitry to arithmetizes all that works the hard part is probably the non-linear part which we'll talk about in a second but here we put a i think it looks like seven or so layer network into the the model but we wanted to be sort of uh make sure it worked in our very limited time to do this project so we picked the simplest possible thing which was we put only the final layer here into the snark so what we actually did was we executed the prior layer in a normal you know web app js whatever and then we put the final part which is the a set of matrix multiply in this case a fully connected network and then the softmax which is the non-linear decision kind of thing into the approver of the snark and um uh yeah so and i guess what i'm not sure where that goes but this is actually a instantiated via some matrix multiply and then a arg max in the snark circuit you can see that if you go to our repo um how we did that and there are a number of challenges challenges really more like things we had to learn not so much challenges um in every case going forward so first one was we figured out that negative numbers don't kind of work that well inside the the the field inside the the snark so we want to make sure that everything was biased so it's going to be positive second thing is that you know there's no floating points inside the snark circuit so we have to think about how to quantize or how to make floating point models into integers and this can be tricky because you don't want to overflow so just kind of try it out and make it work out the third part is really both a learning point as well as ongoing challenge which is non-linear activation functions are tricky to do inside a circuit you can make it blow up basically if you have many layers of cascading functions like that so we that's why we picked only one layer inside our model and there's many ideas for how to do that for example like x square x cube or different combinations of that all this can be tried out i think and we've heard that there are people who have put impressively huge amounts of calculations into a ml model in the snark so i think all that will be coming especially as hardware acceleration becomes more common which i think it will at some point the last thing is that this is more personal speaking for myself i had no clue what to do here so i had to learn the whole two chain for the zika snark uh the dap development so the fact that we did it you know this is the point please go to our our repo and you know see what you can copy and paste from that um so then maybe the most interesting part for me was kind of the use cases here right so i won't dwell too much about the on-chain use cases you can have like we heard today different defy or dow governance voting kind of use cases because all those cases where you want to do some kind of validation or checking often machine learning is a preferred way to do that when the input data is not like completely crisp you want to have some kind of you know black box now linear function to go map from the input to some classified output so whenever that happens you may want to have a machine learning network in somewhere in the thing again this is just a primitive this is not meant to be a standalone but this is probably a very powerful primitive to be cascaded together but the off chain you see this as brian said before there are many there's many things which are probably beyond blockchain so i'll just touch on a few so you know biometrics right fingerprint analysis where you have some kind of identity based on fuzzy real world analog data it could be your your face your fingerprint it could be your your gate as you're walking the way you wax all these things are being captured by machine learning um iot so just automated sensors in our world for example cameras to monitor elderly people falling many cases you don't want the the actual raw data to be you know exposed but in many cases you want to actually have have guaranteed secure guarantees that these are actually being being authentically supplied to the system is interesting because there's of course gps as a waypoint but what's more interesting is like a combination some movement via some pattern or it could be being in a certain location near some specific waypoints all these things are no longer if then statement it's something more complicated that might require some ml model wellness i saw a touch time which is if i want to make sure that you're being rewarded if you're walking or running or biking whatever all these things are actually pretty easy now to use accelerometers to kind of classify but again it could be an input into a more complicated use case than horse mission medical data very private dna data or other kind of things future directions clearly can be deeper bigger better models you know more computer vision video analytics maybe language models at some point it could be other kinds of non-deep neural network models and then there could be many many applications that we can't think of right now and i think that's it thank you [Music] good
Automatic transcript — names and jargon may be misspelled.