Slides from my PHLAI Talk

Last week I was invited to give a talk at the PHLAI conference on the intersection of Blockchains and Machine Learning, 2 areas I have been working with a fair bit in the last couple of years. My hope with the talk was to get more AI practitioners interested in the Blockchain space, which I feel perfectly complements the AI space by providing a layer of trust on black-box AI systems.

Powerpoint presentations do not make good blog posts, so I’ll elaborate on some of the ideas in the future, but here is my deck from the presentation for now

https://speakerdeck.com/arpit/living-at-the-intersection-of-blockchains-and-machine-learning

Notes from A16Z’s NFT Virtual Summit

NFTs have been a lot in the news lately, jolted into mainstream spotlight by Beeple’s $69M sale of his NFT art piece called the first The First 5000 Days. As with most things crypto, there are as many passionate believers as there are skeptics of this new model for digital collectables. Regardless, from a purely technical level, I have been fascinated by digital collectables for a while (ever since CryptoKitties broke the Ethereum Blockchain) and have been trying to learn more about the technical underpinnings for the last couple of weeks.

A16Z, the venture capital firm, has been a great source for information on the whole crypto space for a while and organized an online summit this afternoon bringing in some big names in the field to speak about the state of the NFT space. Below are some of my takeaways from the event

On NFTs in general

Dan Boneh from Stanford University and Chris Dixon from A16Z kicked off the event with a fireside discussion on the state of the NFT space in general. Some interesting points of discussion included:

  • How one of the big reasons that Decentralized Finance (DeFi) exploded was because of the composable nature of Blockchain finance primitives. NFTs could offer similar capabilities. For example, you could wrap non-fungible ERC-721 tokens in fungible ERC-20 wrappers.
  • How we are already starting to see NFTs be used as collateral just as other assets tend to be
  • Could Quantum Compute destroy Blockchains and therefore the NFT value (nope, we have quantum resistant algorithms which we can move to as QC attacks start becoming more probable)

On NFT Marketplaces

It was fascinating to hear Kayvon Tehranian from Foundation and Devin Finzer from OpenSea talk about their NFT marketplaces. I missed a big part of the latter’s talk but I have been really curious about how Foundation works and it was great to hear a bit about that.

  • Every action on Foundation (listings, bids, etc) are recorded on the Blockchain and the asset itself is stored in IPFS. The system only works with non-custodial wallets (sorry Coinbase)
  • While technically it is possible for someone to upload an asset that they don’t own, Foundation manages this a bit by a pretty exclusive invite process with only current artists being able to invite new artists (which does feel a bit centralized IMO)
  • Since everything is managed in a decentralized way, it is theoretically possible to buy an asset from Foundation and sell on a different marketplace
The Nyan Cat NFT sold on Foundation by its original creator

Dieter Shirley and the Flow Blockchain

This may have been my favorite session since I am already interested in Flow. Dieter Shirley is the CEO of Dapper Labs but really got famous when he and his team built CryptoKitties while still working at Axiom Zen. Flow is a new blockchain designed for applications, not financial instruments and is famous for running the NBA Top Shot NFT

Flow’s architecture is driven by 3 goals:

  • Enabling building tangible products
  • Simple on-boarding for non-crypto-nerds
  • Higher capacity to enable web-scale products

He also talked about the decision to build their own chain instead of using Ethereum (“wasn’t easy”), though he does feel that interop with other chains is going to happen among different chains anyway.

On his one regret with the ERC-721 specification that he drafted, he wishes they hadn’t punted on the metadata specification for ERC-721 tokens (“it was a classic bikeshedding moment and there were too many people with too many opinions”).

On the challenges he sees with NFTs in general, he feels legitimacy of the NFT, the challenge of balancing scarcity and abundance and the challenge of interacting with the traditional financial system will remain the big challenges for the near future.

DAOs and NFTs

The last talk of the evening was by digital artist pplpleasr who talked a little bit about her process for NFTs but then mostly talked about the birth of the PleasrDAO, a Decentralized Autonomous Organization that was formed organically to acquire her Uniswap NFT and now exists as a community that buys other NFTs and leverages their assets to power socially conscious projects on the Blockchain. Her talk ended with her revealing her new NFT titled “Apes Together Strong”, with all proceeds going towards charities supporting autism advocacy.

Apes Together Strong by pplpleasr

I love the idea of DAOs and the talk, as well as the sentiment on her slide below, was the perfect talk to end on

Building Smart Contracts on the Ethereum Blockchain

Last week’s Comcast Lab Week gave me another opportunity to dig deeper into Blockchains. In my previous writeup on CodeCoin, I had used Ethereum to create a bounty system for Github issues. However under the hood, we had cloud servers managing various wallets belonging to the different issues. Smart Contracts offer a better way to handle this.

What Are Smart Contracts?

Smart Contracts are pieces of code that execute on the Blockchain. Think of them as classes in an Object Oriented Programming model. Once deployed, you can invoke methods on the Contract from any wallet on the Blockchain. The method, when called, gets not only the parameters that you explicitly sent as part of the method call but also the caller’s wallet address and any value (Ether or its smaller fraction Wei) that the contract was sent. The contract can then keep part or all of the value sent in return for executing the code.

The world’s simplest Smart Contract.

Note that the above contract is a “hello world” contract. Ours was a bit more complicated.

Tools and Setup

Similar to the last time, we used the TestRPC program, now rebranded as Ganache, or specifically it’s CLI  version, the Ganache-CLI) to develop and test the application. The app itself was pretty simple: It allowed users to rent an asset in our store by sending a particular amount of ether to our smart contract.

ganache setup
Configuring Ganache

In addition to Ganache, we also used the Truffle framework to build the application as well as MetaMask to run the transaction.

The Smart Contract itself was written in Solidity. Even though there are may editor plugins you can add to your favorite editor, I found using the the cloud hosted Remix IDE the best to get started. It’s already configured with linters and debug tools that make developing your contract much simpler.

The Truffle framework can be thought of as an equivalent to Ruby on Rails, just for Ethereum projects. When you start a new project, it creates a project structure with folders for contracts, migrations, tests and a truffle.js configuration file that lets you deploy your code to various dev/test/prod environments (think of truffle.js as a config.yml from Rails)

Once you place your contract in the contracts/ folder, running truffle compile compiles the Solidity code to the bytecode that can be deployed to the Ethereum Blockchain. Running truffle migrate deploys the contract to the chain. Truffle also provides a handy REPL console that you can use to interact with your contract from the command line. Very convenient to find your contract’s deployed address for example by calling

Truffle Console
Find the address of the SimpleStorage Contract

Running the Application

Our client application ran a small React app that would send a little bit of Ether to a deployed smart contract. If the transaction was successful, we’d send the successful Transaction ID to a middleware server that would validate it and authorize the user to a piece of content

The client code communicates with the Blockchain via the Web3 library injected into the browser by MetaMask. The code to use the contract looks something like this:

That’s pretty much it.

Random Learnings

  • We had issues with MetaMask and Ganache seeing each other’s wallets. This might be by design but to get anything done, I had to write another small server script that funded Metamask accounts with Ether from Ganache accounts
  • All transactions are done in Wei (10^-18 Ether). During development we’d send small values like 10 Wei across and were perplexed that Metamask or other wallets didn’t change their displays till we realized that the number was too small for MetaMask to show in its UI
  • We assumed a successful transaction on the contract assumed successful payment. We did not wait on the transaction to be mined to declare payment success. We should be waiting on that using the Web3’s filter API but we just ran out of time on the project.
  • To connect with a contract using Web3, you need to point it to its address and the JSON interface of the contract. Truffle’s console has a `toJSON()` method but that is not the JSON you are looking for. The right JSON file is located in the `/build/contracts/` directory. Once you have that JSON file you can create the Contract object in Web3 by using
    var myContract = new web3.eth.Contract(SimpleStorageABI, address)
  • We found an interesting project called OpenZeppelin that seems to be a public repo/tool for often used Contracts. I need to try that next.

Final Thoughts

This was a fun 5 day project that demystified a lot of things around Smart Contracts that I wasn’t sure about. And as always, it was great to work with a bunch of smart engineers I usually don’t get the opportunity to work with otherwise 🙂

Building CodeCoin: A Blockchain DApp prototype

If you know me, there is a good chance that you know how 👍 I am about Blockchain and Decentralized apps. I have given a few talks on it but till recently these were mostly either focused on Bitcoin or on the academics of Blockchain technology. At a recent Comcast Labweek, I was finally able to get my hands dirty with building a Blockchain based decentralized app (DApp) on Ethereum.

Labweek is a week long hackathon at the T&P org in Comcast that lets people work on pretty much anything. I was pretty fortunate to end up working with a bunch of really smart engineers here. The problem we decided to look into was the challenge of funding open source projects. I am pretty passionate about open source technologies but I have seen great ideas die on Github because supporting a project when you aren’t getting paid for it is really hard. Our solution to this problem was a bounty system for Github issues that we called CodeCoin.

The way CodeCoin worked was as follows:

  • A project using CodeCoin would sign up on our site and download some Git hooks.
  • When anyone creates an issue on Github, we create an Ethereum wallet for the issue and post the wallet address back to Github so its the first comment on the issue.
  • We use a Chrome extension that adds a “Fund this issue” button on the Github page that starts the Ethereum payment flow.
  • To actually handle the payment, we require MetaMask that we can trigger using its JavaScript api
  • Ether is held in the wallet till the issue is marked resolved and merged into master. At this time another Git hook fires that tells our server to release the Ether into the wallets of all the developers who worked on the issue.

app-screen.png
Issue page design. Most of the UI changes came from a custom Chrome extension

flow.png
Application Flow

Note that while we held the Ether on our side in wallets, the right way to do this would have been to use a Smart Contract. We started down that route but since most of the code was done in like 2 days (while juggling other real projects), wallets seemed like the easier route.

Releasing money into developer accounts was also a hack. Since developers don’t sign up to Github with any digital wallet address, we need the wallet addresses as part of the final commit message. This could be done with a lookup on a service like Keybase.IO maybe and with more time we would have tried integrating it to our prototype. In fact it was the next week that I heard about their own Git offering. I haven’t read enough about that yet though.

Development notes:

  • For local development, we used the TestRPC library to run a Ethereum chain simulation on our machine.
  • We used web3js, the Ethereum JavaScript api for doing most of the actual transactions
  • Web3js was injected into the browser by the MetaMask extension. There were some challenges getting Metamask to talk to the TestRPC. Basically, you had to make sure that you initialized MetaMask with the same seed words as you used for your account on TestRPC (which makes sense) but there isn’t a way afaik to change that information in MetaMask. Early on, we were restarting TestRPC without configuring the initial accounts so we’d have to reinstall MetaMask to configure it with the new account. Chalk that to our own unfamiliarity with the whole setup.

metamask
MetaMask transaction

  • We did try to use Solidity to run a smart contract on TestRPC which worked for the demo apps, but canned that effort in the last moment as we were running out of time

All in all, it was a fun couple of days of intense coding and I feel I learnt a lot. Most of all I enjoyed working with a group of really smart peers, most of whom I didn’t know before the project at all. Hopefully we get to do more of that in the future 🙂

IMG_0310.jpg

 

Bitcoin Pow Wow 2 notes

Every couple of months I meet a few friends over lunch to geek out over the latest in the world of Bitcoin, Blockchains and Crypocurrencies in general. Just so that I dont forget them, here is a list of things we discussed today 🙂