Skip to content

Commit

Permalink
🎉 start askeladd
Browse files Browse the repository at this point in the history
  • Loading branch information
AbdelStark committed Jul 16, 2024
1 parent bc1f561 commit 3f5407a
Show file tree
Hide file tree
Showing 14 changed files with 225 additions and 2 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: CI

on:
push:
branches:
- main

pull_request:
types:
- opened
- reopened
- synchronize
- auto_merge_enabled
jobs:
format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@master
with:
components: rustfmt
toolchain: nightly-2024-01-04
- uses: Swatinem/rust-cache@v2
- run: scripts/rust_fmt.sh --check

clippy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@master
with:
components: clippy
toolchain: nightly-2024-01-04
- uses: Swatinem/rust-cache@v2
- run: scripts/clippy.sh

run-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@master
with:
toolchain: nightly-2024-01-04
- uses: Swatinem/rust-cache@v2
- run: cargo +nightly-2024-01-04 test
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,8 @@ Cargo.lock

# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb


# Added by cargo

/target
10 changes: 10 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[workspace]
members = ["crates/cli", "crates/core"]
resolver = "2"

[workspace.package]
version = "0.1.1"
edition = "2021"

[workspace.dependencies]
stwo-prover = { git = "https://github.com/starkware-libs/stwo.git" }
54 changes: 52 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,52 @@
# askeladd
Censorship-resistant global proving network.
<div align="center">
<h1>Askeladd</h1>
<h2>Censorship-resistant global proving network.</h2>

<a href="https://github.com/AbdelStark/askeladd/actions/workflows/ci.yaml"><img alt="GitHub Workflow Status (with event)" src="https://img.shields.io/github/actions/workflow/status/AbdelStark/askeladd/ci.yaml?style=for-the-badge" height=30></a>
<a href="https://starkware.co/"><img src="https://img.shields.io/badge/By StarkWare-29296E.svg?&style=for-the-badge&logo=data:image/svg%2bxml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz48c3ZnIGlkPSJhIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxODEgMTgxIj48ZGVmcz48c3R5bGU+LmJ7ZmlsbDojZmZmO308L3N0eWxlPjwvZGVmcz48cGF0aCBjbGFzcz0iYiIgZD0iTTE3Ni43Niw4OC4xOGwtMzYtMzcuNDNjLTEuMzMtMS40OC0zLjQxLTIuMDQtNS4zMS0xLjQybC0xMC42MiwyLjk4LTEyLjk1LDMuNjNoLjc4YzUuMTQtNC41Nyw5LjktOS41NSwxNC4yNS0xNC44OSwxLjY4LTEuNjgsMS44MS0yLjcyLDAtNC4yN0w5Mi40NSwuNzZxLTEuOTQtMS4wNC00LjAxLC4xM2MtMTIuMDQsMTIuNDMtMjMuODMsMjQuNzQtMzYsMzcuNjktMS4yLDEuNDUtMS41LDMuNDQtLjc4LDUuMThsNC4yNywxNi41OGMwLDIuNzIsMS40Miw1LjU3LDIuMDcsOC4yOS00LjczLTUuNjEtOS43NC0xMC45Ny0xNS4wMi0xNi4wNi0xLjY4LTEuODEtMi41OS0xLjgxLTQuNCwwTDQuMzksODguMDVjLTEuNjgsMi4zMy0xLjgxLDIuMzMsMCw0LjUzbDM1Ljg3LDM3LjNjMS4zNiwxLjUzLDMuNSwyLjEsNS40NCwxLjQybDExLjQtMy4xMSwxMi45NS0zLjYzdi45MWMtNS4yOSw0LjE3LTEwLjIyLDguNzYtMTQuNzYsMTMuNzNxLTMuNjMsMi45OC0uNzgsNS4zMWwzMy40MSwzNC44NGMyLjIsMi4yLDIuOTgsMi4yLDUuMTgsMGwzNS40OC0zNy4xN2MxLjU5LTEuMzgsMi4xNi0zLjYsMS40Mi01LjU3LTEuNjgtNi4wOS0zLjI0LTEyLjMtNC43OS0xOC4zOS0uNzQtMi4yNy0xLjIyLTQuNjItMS40Mi02Ljk5LDQuMyw1LjkzLDkuMDcsMTEuNTIsMTQuMjUsMTYuNzEsMS42OCwxLjY4LDIuNzIsMS42OCw0LjQsMGwzNC4zMi0zNS43NHExLjU1LTEuODEsMC00LjAxWm0tNzIuMjYsMTUuMTVjLTMuMTEtLjc4LTYuMDktMS41NS05LjE5LTIuNTktMS43OC0uMzQtMy42MSwuMy00Ljc5LDEuNjhsLTEyLjk1LDEzLjg2Yy0uNzYsLjg1LTEuNDUsMS43Ni0yLjA3LDIuNzJoLS42NWMxLjMtNS4zMSwyLjcyLTEwLjYyLDQuMDEtMTUuOGwxLjY4LTYuNzNjLjg0LTIuMTgsLjE1LTQuNjUtMS42OC02LjA5bC0xMi45NS0xNC4xMmMtLjY0LS40NS0xLjE0LTEuMDgtMS40Mi0xLjgxbDE5LjA0LDUuMTgsMi41OSwuNzhjMi4wNCwuNzYsNC4zMywuMTQsNS43LTEuNTVsMTIuOTUtMTQuMzhzLjc4LTEuMDQsMS42OC0xLjE3Yy0xLjgxLDYuNi0yLjk4LDE0LjEyLTUuNDQsMjAuNDYtMS4wOCwyLjk2LS4wOCw2LjI4LDIuNDYsOC4xNiw0LjI3LDQuMTQsOC4yOSw4LjU1LDEyLjk1LDEyLjk1LDAsMCwxLjMsLjkxLDEuNDIsMi4wN2wtMTMuMzQtMy42M1oiLz48L3N2Zz4=" alt="StarkWare" height="30"></a>

</div>

## About

Askeladd is a censorship-resistant global proving network, for anyone to be able to generate validity proofs, using [STWO](https://github.com/starkware-libs/stwo) prover, and verify them. It enables to submit proving request to the network and retrieve the generated proof for any given request.
Askeladd leverages [Nostr](https://github.com/nostr-protocol/nostr) for the communication layer, to gossip the proving requests and generated proofs.

As Zero-Knowledge-Proof technology keeps evolving rapidly, it's clear that there will be a need for decentralised infrastructure to be able to generate and verify proofs in a censorship-resistant way. Not everythng has to live on blockchain, and Askeladd is here to help, leveraging the simplicity of Nostr.

## Architecture

![Askeladd Architecture](./docs/img/askeladd-architecture.png)

Typical flow:

1. User submits a proving request to the network
2. An Askeladd prover agent generates a proof for the request
3. The proof is published to the Nostr network
4. The user can verify the proof using the Askeladd verifier agent

## Getting Started

### Running the CLI

```bash
cargo run --bin askeladd-cli
```

### Use as library

```bash
cargo add askeladd-core
```

## 🤝 Contributing

We love contributions! If you have ideas for improvements or find any issues, please open an issue or submit a pull request.

## 📜 License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

## 🙏 Acknowledgements

This demo is powered by the amazing [STWO Prover](https://github.com/starkware-libs/stwo) from StarkWare. A big thank you to the StarkWare team and all contributors!
9 changes: 9 additions & 0 deletions crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "askeladd-cli"
version.workspace = true
edition.workspace = true

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
askeladd-core = { path = "../core" }
19 changes: 19 additions & 0 deletions crates/cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use askeladd_core::prover_service::ProverService;
use askeladd_core::types::FibonnacciProvingRequest;
use askeladd_core::verifier_service::VerifierService;

fn main() {
let proving_service: ProverService = Default::default();
let log_size = 5;
let claim = 443693538;
let request = FibonnacciProvingRequest { log_size, claim };
println!("Generating proof...");
let response = proving_service.generate_proof(request).unwrap();
println!("Proof successfully generated.");
let verifier_service: VerifierService = Default::default();
println!("Verifying proof...");
match verifier_service.verify_proof(response) {
Ok(_) => println!("Proof successfully verified"),
Err(e) => println!("Proof verification failed: {}", e),
}
}
7 changes: 7 additions & 0 deletions crates/core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "askeladd-core"
version.workspace = true
edition.workspace = true

[dependencies]
stwo-prover.workspace = true
3 changes: 3 additions & 0 deletions crates/core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub mod prover_service;
pub mod types;
pub mod verifier_service;
25 changes: 25 additions & 0 deletions crates/core/src/prover_service.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use stwo_prover::core::fields::m31::BaseField;
use stwo_prover::core::prover::ProvingError;
use stwo_prover::examples::fibonacci::Fibonacci;

use crate::types::{FibonnacciProvingRequest, FibonnacciProvingResponse};

#[derive(Debug, Default)]
pub struct ProverService {}

impl ProverService {
pub fn generate_proof(
&self,
request: FibonnacciProvingRequest,
) -> Result<FibonnacciProvingResponse, ProvingError> {
let fib = Fibonacci::new(request.log_size, BaseField::from(request.claim));
match fib.prove() {
Ok(proof) => Ok(FibonnacciProvingResponse {
proof,
log_size: request.log_size,
claim: request.claim,
}),
Err(e) => Err(e),
}
}
}
18 changes: 18 additions & 0 deletions crates/core/src/types.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use stwo_prover::core::prover::StarkProof;

/// A request to generate a proof for a Fibonnacci sequence.
pub struct FibonnacciProvingRequest {
/// The size of the log to generate.
pub log_size: u32,
/// The claim to be proved.
pub claim: u32,
}

pub struct FibonnacciProvingResponse {
/// The size of the log to generate.
pub log_size: u32,
/// The claim to be proved.
pub claim: u32,
/// The proof generated for the request.
pub proof: StarkProof,
}
18 changes: 18 additions & 0 deletions crates/core/src/verifier_service.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use stwo_prover::core::fields::m31::BaseField;
use stwo_prover::core::prover::VerificationError;
use stwo_prover::examples::fibonacci::Fibonacci;

use crate::types::FibonnacciProvingResponse;

#[derive(Debug, Default)]
pub struct VerifierService {}

impl VerifierService {
pub fn verify_proof(
&self,
response: FibonnacciProvingResponse,
) -> Result<(), VerificationError> {
let fib = Fibonacci::new(response.log_size, BaseField::from(response.claim));
fib.verify(response.proof)
}
}
Binary file added docs/img/askeladd-architecture.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[toolchain]
channel = "nightly-2024-01-04"
12 changes: 12 additions & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# See: https://rust-lang.github.io/rustfmt
normalize_comments = true
use_field_init_shorthand = true

# Unstable
comment_width = 100
condense_wildcard_suffixes = true
format_code_in_doc_comments = true
group_imports = "StdExternalCrate"
imports_granularity = "Module"
unstable_features = true
wrap_comments = true

0 comments on commit 3f5407a

Please sign in to comment.