Open Source Monday: Homomorphic Encryption Meets NFT
For the second installment of our “Open Source Monday” blog series, we are offering up a smart contract-based homomorphic encryption example. Check it out below!
Since you’re reading today’s blog, we’re betting you’ll have seen the fun math video we shared last week explaining how homomorphic encryption (HE) works. And, if you’re a long-time VIA follower, you will recall that we first released our own HE library back in 2020*.
Moving from math to code, here is an example of how to use the library using a smart contract. The great thing about this particular example is that you can use a standard ERC-1155 token.
In summary, here’s what you’ll see:
- Two NFTs (bird images) that have one encrypted number each in their metadata.
a. The NFTs are hosted on IPFS and searchable on OpenSea.
b. The metadata also includes the public key and a sequence of coordinates on an elliptical curve.
c. VIA uses NIST-compliant, 2048-bit RSA equivalent, elliptic curve cryptography (ECC).
- Polygon is used to create a standard ERC-1155 contract and mint all NFTs. The sum of the encrypted number NFT is represented as a third image (an egg).
- For this example, a Polygon scanner was used to enter the encrypted numbers and then sum them with VIA’s HE library. NOTE: In a live setting we would use an Oracle to execute the computation programmatically.
- The encrypted sum gets placed in the metadata of a new NFT and minted.
- The sum can be decrypted by the private key owner as verified by an Oracle.
OpenSea has the NFTs with encrypted data. For everyone’s reference, here are the unencrypted NFTs.
Of course, NFTs don’t have to be the source of the addition. This illustration, however, should resonate with Web3 game designers and NFT minters alike. For example, you could offer treasury chest NFTs based on breeding and only provide the reward, decrypted value, to the owner of the NFT.
You can also substitute another HE library, other than VIA’s, if you prefer. The VIA library has a number of advantages that we described in our original 2020 post.
Some of the key advantages of VIA’s HE library include:
- NIST-compliant ECC
- No limit on digits for addition
- Fixed point calculations
- Benchmarked as significantly faster than many other HE libraries
Reach out if you’d like to learn more about the VIA library.
We’re considering hosting an Oracle to enable this functionality in general for anyone on a public blockchain. Would this be of interest to you? If so, Support this post (via LinkedIn) and RT (via Twitter).
*As one update to the 2020 HE post, VIA was issued patents on its homomorphic encryption approach in 2021 and additional patents in February 2022.