Skip to content

Commit

Permalink
feat: use forked protobufjs (#556)
Browse files Browse the repository at this point in the history
* fix: use forked protobufjs
* feat: make snark task splitable
* chore: update readme
  • Loading branch information
RyanKung authored Feb 19, 2024
1 parent dd4a20b commit 7988290
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 10 deletions.
18 changes: 10 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,14 @@ rings help

## Resource

| Resource | Link | Status |
|---------------------------------|-----------------------------------------------|---------|
| Rings Whitepaper | [Rings Whitepaper](https://github.com/RingsNetwork/whitepaper) | [![rings-ext-v2](https://github.com/RingsNetwork/rings_ext_v2/actions/workflows/dev.yml/badge.svg)](https://github.com/RingsNetwork/rings_ext_v2/actions/workflows/dev.yml)|
| Rings Documentation | [Rings Docs](https://rings.gitbook.io/) | |
| Rings Browser Handshakes Example| [Rings Browser Handshakes](https://github.com/RingsNetwork/rings-wasm-p2p) | Demo / PoC |
| Rings Browser Extension | [Rings Browser Extension](https://github.com/RingsNetwork/rings_ext_v2) | Beta |
| Rings dWeb Demo | [Rings dWeb Demo](https://github.com/RingsNetwork/rings-dweb) | [![rings-ext-v2](https://github.com/RingsNetwork/rings_dweb/actions/workflows/nextjs.yml/badge.svg?branch=page)](https://github.com/RingsNetwork/rings_dweb/actions/workflows/nextjs.yml)|

| Resource | Link | Status |
|----------------------------------|----------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Rings Whitepaper | [Rings Whitepaper](https://github.com/RingsNetwork/whitepaper) | [![rings-ext-v2](https://github.com/RingsNetwork/rings_ext_v2/actions/workflows/dev.yml/badge.svg)](https://github.com/RingsNetwork/rings_ext_v2/actions/workflows/dev.yml) |
| Rings Documentation | [Rings Docs](https://rings.gitbook.io/) | |
| Rings Browser Handshakes Example | [Rings Browser Handshakes](https://github.com/RingsNetwork/rings-wasm-p2p) | Demo / PoC |
| Rings Browser Extension | [Rings Browser Extension](https://github.com/RingsNetwork/rings_ext_v2) | Beta |
| Rings dWeb Demo | [Rings dWeb Demo](https://github.com/RingsNetwork/rings-dweb) | [![rings-ext-v2](https://github.com/RingsNetwork/rings_dweb/actions/workflows/nextjs.yml/badge.svg?branch=page)](https://github.com/RingsNetwork/rings_dweb/actions/workflows/nextjs.yml) |
|Rings zkProof Demo | [Rings zkProof Demo](https://zkp.rings.rs) |![rings-snark-demo](https://github.com/RingsNetwork/rings-proof-demo/actions/workflows/nextjs.yml/badge.svg?branch=page)|

## Components:

Expand All @@ -105,6 +105,8 @@ rings help

* transport: Rings Transport implementation, including native transport and `web_sys` based transport.

* snark: Rings SNARK is based on fold scheme and zkSNARK

## Architecture

The Rings Network architecture is streamlined into five distinct layers.
Expand Down
7 changes: 7 additions & 0 deletions crates/node/src/backend/snark/browser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ pub struct SNARKProofTaskRef {
inner: Arc<types::SNARKProofTask>,
}

impl SNARKProofTaskRef {
/// Make snark proof task ref splitable
pub fn split(&self, n: usize) -> Vec<SNARKProofTaskRef> {
self.inner.split(n).into_iter().map(|t| t.into()).collect()
}
}

#[wasm_bindgen]
impl SNARKProofTaskRef {
/// serialize SNARKProofTaskRef to json
Expand Down
45 changes: 45 additions & 0 deletions crates/node/src/backend/snark/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,29 @@ where
pp: Arc<PublicParams<E1, E2>>,
}

impl SNARKProofTask {
/// Make snark proof task splitable
pub fn split(&self, n: usize) -> Vec<SNARKProofTask> {
match self {
SNARKProofTask::PallasVasta(g) => g
.split(n)
.into_iter()
.map(SNARKProofTask::PallasVasta)
.collect(),
SNARKProofTask::VastaPallas(g) => g
.split(n)
.into_iter()
.map(SNARKProofTask::VastaPallas)
.collect(),
SNARKProofTask::Bn256KZGGrumpkin(g) => g
.split(n)
.into_iter()
.map(SNARKProofTask::Bn256KZGGrumpkin)
.collect(),
}
}
}

impl<E1, E2> SNARKGenerator<E1, E2>
where
E1: Engine<Base = <E2 as Engine>::Scalar>,
Expand All @@ -697,6 +720,28 @@ where
Ok(())
}

/// Split a SNARKGenerator task to multiple, by split circuits into multiple
pub fn split(&self, n: usize) -> Vec<Self> {
let SNARKGenerator {
snark,
circuits,
pp,
} = self;

let mut split = Vec::new();
let chunk_size = (circuits.len() + n - 1) / n;

for circuit_chunk in circuits.chunks(chunk_size) {
let new_generator = SNARKGenerator {
snark: snark.clone(),
circuits: circuit_chunk.to_vec(),
pp: Arc::clone(pp),
};
split.push(new_generator);
}
split
}

/// setup compressed snark, get (pk, vk)
#[allow(clippy::type_complexity)]
pub fn setup<S1: RelaxedR1CSSNARKTrait<E1>, S2: RelaxedR1CSSNARKTrait<E2>>(
Expand Down
2 changes: 1 addition & 1 deletion crates/snark/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
[![docs](https://docs.rs/rings-node/badge.svg)](https://docs.rs/rings-node/latest/rings_node/)
![GitHub](https://img.shields.io/github/license/RingsNetwork/rings-node)

This create contains the implementation of Rings SNARK, which is based on Nova
This crate contains the implementation of Rings SNARK, which is based on Nova

### TL;DR

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
},
"dependencies": {
"circomlib": "^2.0.5",
"protobufjs": "^7.2.5"
"protobufjs": "https://github.com/RingsNetwork/protobuf.js#83686a0"
},
"devDependencies": {
"protobufjs-cli": "^1.1.2",
Expand Down

0 comments on commit 7988290

Please sign in to comment.