Build a Blind AI App on Nillion - ETHGlobal Brussels 2024
ETHGlobal·Wed, Oct 9, 2024, 12:00 AM
Join Steph Orpilla from Nillion, for a workshop titled, "Build a Blind AI App on Nillion." Speedrun building a Nillion blind app that runs blind inference with nada-ai. Nada-ai is a cutting-edge Machine Learning framework inspired by SKLearn and PyTorch, designed to seamlessly integrate model-building capabilities into Nada DSL. This workshop took place during ETHGlobal Brussels, a 3-day hackathon held in Brussels, Belgium from July 12 to 14, 2024. ETHGlobal Brussels brought together the most skilled web3 developers, designers and product builders from all around the globe for a weekend-long adventure to advance the Ethereum ecosystem! ---------------- Follow us: x.com/ethglobal Website: https://ethglobal.com Email us at: hello@ethglobal.com
Transcript
[Music] and just to introduce myself quickly I'm sta orilia I lead developer relations at Nan and I'm also oceans 404 on Twitter um if you want to ask questions there or say hello so we at Nilan are building Humanity's first blind computer and the first time I heard that I was like what does that mean how could a computer be blind um computers are just reading numbers what ises that all about um but what we're building is a dual architecture Network so it is a pet net plus a coordination layer so what the pet net is doing is it's combining different privacy enhancing Technologies uh like MPC garbled circuits um FHA all types of different cryptographic Primitives to do interesting math on and to do blind computation and then the coordination layer is how we pay for all of the different operations that happen on the pet net so whether it's like storing data retrieving data or Running Blind computation to do any of that what you do is you pay on the coordination layer which is a blockchain and then you send a ZK proof of a receipt to um the pet net and so once it knows that you've paid you're able to perform your operation so that's kind of what the network looks like at a high level and we have a test net right now and also a local devet so when you're building your apps you can connect to either uh but I'll show you the test net today let's go back to this idea of blind computation so blind computation basically just lets functions or programs be performed on secret inputs without ever revealing them or showing those values so this is really great if you have a type of application that needs security and privacy especially if it's combining inputs from multiple different parties so if you've heard of like a ZK proof that is a powerful primitive for verification or checking against a single value but something like MPC in blind computation is powerful because you can compare Secrets add Secrets do anything with secrets from multiple parties uh without revealing or exposing that underlying data so it is privacy preserving um and just to show you kind of like classic computation versus blind computation this is a really simple addition function it's just taking two inputs so int one and int two and it's returning the sum so there's two inputs and one output and if you conso logged these inputs in the middle of the program you could see these in plain text and something like that doesn't matter for an addition function but if you think of things that have more sensitive data maybe you don't want that data exposed so that's where blind computation could be really great and what a blind computation function looks like is something like this so there's two secret inputs you can see I've kind of of uh put blindfolds over the two secret inputs to show that you can't actually see them and a sum that's returned and a big difference uh between blind computation and writing just like traditional programs is that you attach a who and a what to each of the secrets that you're passing into a computation so you can see that in one is attached to me I'm the party providing it in two is attached to my cooworker Charlie he's the co he's the party provider diving into and each of these also needs a name so that we can reference what secret the integer uh corresponds to so that previous slide was just kind of um a simplification of what a program could look like but this is what it actually looks like we have a language called NADA um it's based on python so if you're familiar with python this should look very similar and I'll just go line by line and explain what's happening here so on line one we're just importing NADA DS which is the library uh that helps um the compiler understand what's going on on line three we're creating that function and then on line four and five we're defining the parties those are the who to who is providing the secret inputs so on line six you can see for INT one party Steph which is me is providing this secret input and then on line seven you can see party two Charlie is providing int two so when this uh computation happens it's completely blind and one of the different parties which happens to be me Steph will receive the output um but I'll I won't have any idea what Charlie's input was except for that I kind of know because I provided one of the secrets so this is not the best example because I could just subtract the output from my original input but you can imagine that as these get more complex the programs get more complex um you would have no idea what different secrets were passed in all you would know is the output so this is an example of just a simple addition program but we've also got two different libraries that help you do really interesting things with AI so the first one is not a AI um and we have different models that are able to be exported so we've got linear regression neural networks and then some more complex ones like time series ban detection um and forecasting and also classification so you can do all of these things within your NADA programs which makes them really powerful and also allows you to run blind inference which I'll talk about next we also have a library called n a numpy so this is really similar to just the numai uh python library that you might already be used to and it makes it easier to just do Matrix operations and any of that more complicated math within NADA that way you don't have to write all these functions out yourself you can just just use the helpers um and have a better developer experience so what I did uh for this example is I created linear an example of linear regression on housing data with blind inference so we're going to get into this code um but just to in case anyone's not um in the AI World inference is when you take a trained model to make predictions on new data so for this data set I used um some housing data from kaggle and what I did was put it into a model and I trained the model and then I put the model weights into a secret onnon so that anytime somebody adds new inputs they can be evaluated against those Secret model weights and it will come up with what it predicts the new price of a home that um adheres to the inputs is so let's check out this code you can scan the QR code here I'll give you a second for that but this is my repo so again it's just doing the linear linear regression um and I'll open up the actual code okay so this is the NADA program for linear regression um so I seted up by importing NADA numpy and also NADA Ai and then I need the linear model from linear regression I'm setting the Precision which is just 32 that's just uh what I figured was the right Precision for this model then I create the two different parties so party zero and party one those are just each of the parties that we'll use in the computation um and so the first party will be the one that's storing the secret weights of the model and the second party is the party that's providing that new input data to figure out the price of this new home so this data set happens to have 12 different features we can just look at the data set really quickly on kaggle um it's things like square footage of a house number of bathrooms number of bedrooms um and that all corresponds to the overall price and that's what we'll be guessing when we pass in new inputs uh to run blind inference so that was the data set with 12 different features that we're interested in then we take the linear regression model and tell it how many features which is 12 next we load the model State and then also the input data to compare against and then we get the result of the blind inference um so this is just telling us the expected price of the new house based on the data that we pass in so this program does a lot but it's actually pretty simple and the way that we interact with it is either through the JavaScript client for nilon or the python client so I'll show you the python code first but we'll eventually plug this into the JavaScript side so that we can create a web app where we can actually run this program um against data that we're putting in on the fly so if I go to my main file this is where all of the different neon code is happening so that it can connect to the network store the relevant secrets in the programs and also pay for the different operations and in this file I also compared the result that I'm getting from the NADA program to something from the sklearn linear model so that we can make sure that what we're getting from the NADA program is uh about the same as what we would get from a different model so we're setting the prec the Precision of the model um and then we're referencing the program that we wrote around linear regression that I just showed you next we have to just establish the party names so party zero is the one that is passing in the secret weights and party one has the new input data and then we just do some setup uh so that each of the different parties has their own user key ID pair which is just it's kind of like a private public key for a user then we configure payments so I'm just setting something up with a ledger client and that's reading from a private key that's been funded uh so you can just fund with our faucet and then your private key will have some nil tokens that it can use to pay for any of the operations that you're doing so next we store the program this just stores that linear regression program in the network and then we store the two secrets so the first secret that we're storing is the model so this is all of the different model weights that uh we found when training the data set so the model weights are stored as a secret Inon we give permissions to anyone that needs to run this program so we'll give permissions to the front end and a couple other users we do that by user ID which is the user public key so I added a couple different user IDs so that we can do this from the front end as different users um and then last of all we store the secret so we store the model as a secret in nilon and this is just a test that I did uh with a house that has these inputs for area bedrooms all of these types of things so when we run this program just zoom in here I can just do Python 3 Main and this will run through oops this will run through my script and evaluate the blind computation to figure out how much a house would cost that has these different criteria so as the script runs you'll see that we're getting quotes for operations that's just estimating how much it will cost um and then once we get the quote it will automatically pay with the private key so it submits a payment it stores the program and you follow that pattern for any operation you do on million so you create um a quote which is just saying what you're going to do on the network whether that's storing a secret retrieving a secret or performing a computation and then you pay for the operation and then you can pass the operation to the pet net so this got the expected result it looks like this home is about $7.6 million which seems very expensive um but this is also what the other model got uh I think this data set was like fancy homes on the East Coast so that kind of makes sense but I probably would not be buying this home maybe if eth goes way up this cycle okay so this is how uh you create the program and you do all of that and the next thing I want to show you is how you make this interactive so how you turn this into a blind app on million so I've got a starter for you all to check out and you can find it by going to our docs so docs. million.com and then you can just go to developer quick start build a blind app this will take you through all of the steps to actually building a blind app I showed you creating a notada project that's what the linear regression model was um but the actual blind app uses this CRA milon so a create react app starter repo and you can use this as your base to build whatever type of project um it has all of the payments already it has the quoting so all you really have to do is add your business logic so this is what this CRA million app looks like first I have an operations page so you can just generate a user key and connect with the user key and then you can perform any different types of operations this doesn't actually have to do with the housing example but it's just to show you that you can store Secrets retrieve Secrets store programs all of the different operations against the testet but if we want to run blind inference to figure out how uh how much the house would cost we could use this page so this is just another page I've spun up with react and it's connected to the specific program ID for linear regression and it also knows about the secret that's already been stored and that secret is the weighted model so I'm going to generate a user key and connect and now I'm going to set some different input features for a house and the model will tell me how much it is without actually having to see those weights so the weights stay completely private and hidden but we're able to run inference so let's give it a 2,000 foot area three bedrooms three bathrooms maybe two stories n two stories we'll say it's not on a main road there's no guest room we'll just say no to the rest of these maybe one parking spot so I submitted the input feature set and now I can run blind computation on the program so let's get the quote this is just an estimation of how much uh this operation will cost on the network it looks like it'll cost 28 youo so then I can pay and compute and I should see the result of the blind computation come on Wi-Fi let's see okay so we'll just give this a minute to load oh here we go so it's saying that this house is like 4.6 million which is also a lot but again this was a pretty expensive data set so I think that's why uh but this is an example of how you can plug your programs into an app and a front end really easily with our JavaScript client so whether you're writing um code in python or JavaScript you'll be able to create web apps if you use the CRA Nan starter repo so that's the linear regression model example um and I just wanted to talk quickly about our prizes so we have 5,000 usdc in prizes so we have 3,000 for building a blind AI project on million we have 1,000 for building a blind app which doesn't need to use AI um and then we have 1,000 for the best tool or blockchain integration and we also came up with a nice big list of ideas for you all so this has ideas for each of those prize categories of the different types of things you can build um and this is linked in our prizes so just look Fillion ideas uh inside of the prize links but there's tons of different things you can build with AI with the different models that we've exposed in NADA AI so you could do something with housing data like what I did you could do something with health or medical imaging um you could predict temperature anything like that for blind app ideas um one thing that I've been thinking about a lot is creating like a meeting calculator like to calculate the cost of a meeting if you had each of your co-workers secretly put in their salary and then you calculated how much the meeting costs based on the number of meeting minutes I think that would be fun uh you could also do things with secure voting blind auctions and we have examples of both of those you can do a multi multiplayer game anything that requires secrets to be stored and computed on so anything where privacy and secret storage is important for computation as for developer tool ideas and blockchain and app integration ideas basically if you you combine us with any other sponsor you'd be eligible for this prize um and it's especially good if you're deploying to a bunch of the l2s you could maybe store your store IDs on chain so that those stay on chain Forever Without exposing the secrets you could create a forecaster frame anything like that you could build a bridge we're looking for anything creative um and especially things that we haven't thought of on this list we're excited to see what you build I think that's every for me and I saw that it's time but does anyone have any questions about prizes or anything otherwise we'll be at our million Booth so we're happy to help all all weekend long [Music]
Automatic transcript — names and jargon may be misspelled.