Giter Site home page Giter Site logo

ocskiurity / n0tte Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 1.0 333 KB

n0tte enables private on-chain FHE-ML inference on one-layer MLP models interacting with a command-line interface running hardhat scripts

License: MIT License

Solidity 32.35% TypeScript 62.46% JavaScript 5.19%
ethereum fhe ml smartcontract

n0tte's Introduction

logo

๐Ÿบ n0tte ๐Ÿบ

n0tte enables private on-chain FHE-ML inference on one-layer MLP models interacting with a command-line interface running hardhat scripts

The current machine learning (ML) landscape is controlled by a few major players who keep their high-quality trained models proprietary to maintain their dominance in the industry. This creates a significant obstacle for individuals, such as researchers, students, and small institutions, who want to leverage these high-quality models to analyze their own data.

n0tte addresses this issue by facilitating ML inference through Fully Homomorphic Encryption (FHE) within Ethereum Smart Contracts. This approach allows model owners to set the encrypted weights and biases of a pre-trained general-purpose 1-layer MLP model on a smart contract. Using the provided initiator set of Python scripts, model owners can train and quantize ML models and data off-chain. Consequently, any user can perform inference on their encrypted data directly on-chain, ensuring the privacy and security of user data.

Prerequisities

Please, make sure you have Docker installed and running on your machine. You can find instructions on how to install docker here.

Install

Clone this repository:

git clone https://github.com/ocskiurity/n0tte.git

And install the dependencies and build the project: nb. the build script compiles the smart contract too.

cd n0tte && pnpm install && pnpm build

Config

Copy the .env.example file as .env:

cp .env.example .env

And add your environment variables. You can leave the default values for the sake of demoing.

Remember to put your data about the model and / or inference under the tasks/data/ folder and update the paths accordingly. Right now, we are pointing to the tasks/data/sample JSON files (and please, follow their structure and naming conventions).

Usage

Run the LocalFhenix instance with Docker

pnpm localfhenix:start

โš ๏ธ you may need to chmod the docker.sock file on Linux distros.

sudo chmod 666 /var/run/docker.sock

Deploy the 1L MLP model running. You can modify the configuration on the task.

pnpm task:deploy

CLI

We provide a command line interface to run hardhat scripts and have a fancy output on your console. You can use it locally by linking for now (heads up: it needs an hardhat environment for execution!)

To link and have the n0tte CLI locally

npm link
n0tte

You can run the hardhat tasks through the CLI (or through pnpm run-task <name>)

n0tte run-task set:bias
n0tte run-task set:weights
n0tte run-task set:quantized-data
n0tte run-task inference

# or use 'all' to run everything in order (bias, weights, data, inference).

n0tte run-task all 
  • set:bias: sets the quantized bias of the model in an FHE encrypted form on-chain.
  • set:weights: sets the quantized weights of the model in an FHE encrypted form on-chain. The weights are obtained from the off-chain training of the model + quantization.
  • set:quantized-data: sets the quantized data of the model in an FHE encrypted form on-chain for doing inference.
  • set:inference: computes a run of the inference of the model in a private-preserving fashion.

nb. the CLI may hang due to latency & heavy computations (there's one tx x computation step) - do not exit before seeing any output of the CLI.

--

Note that you can run just one inference because we are not resetting anything (data + result). Therefore, we suggest to execute the following (long) one-time script to make an e2e run

pnpm clean && pnpm compile && pnpm task:deploy && pnpm run build && npm link && clear && n0tte run-task all

Learn more

To learn more about the Fhenix, please visit the official docs and Github org.

Team

ocskiurity team - zkHack Krakow

n0tte's People

Contributors

0xjei avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.