Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jsonified Trusted Setup #1

Merged
merged 1 commit into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
65 changes: 61 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ serde_derive = "1.0"
serde_yaml = { version = "0.9" }
sp1-derive = { git = "https://github.com/succinctlabs/sp1.git", branch = "main" }
once_cell = "1.19.0"
bls12_381 = "0.8.0"
bls12_381 = { git = "https://github.com/0xWOLAND/bls12_381/" }
regex = "1.10.5"
subtle = "2.2.1"
serde_json = "1.0.117"

[features]
default = ["std"]
Expand Down
4 changes: 2 additions & 2 deletions src/kzg_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,13 @@ impl KzgProof {
mod tests {
use std::{fs, path::PathBuf};

use crate::{test_format::Test, trusted_setup::KzgSettings, KzgProof, TRUSTED_SETUP};
use crate::{test_format::Test, KzgProof, KzgSettings};

const VERIFY_KZG_PROOF_TESTS: &str = "tests/verify_kzg_proof/*/*";

#[test]
fn test_verify_kzg_proof() {
let kzg_settings = &TRUSTED_SETUP;
let kzg_settings = KzgSettings::load_trusted_setup_file().unwrap();
let test_files: Vec<PathBuf> = glob::glob(VERIFY_KZG_PROOF_TESTS)
.unwrap()
.map(|x| x.unwrap())
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub mod consts;
pub mod dtypes;
pub mod enums;
pub mod kzg_proof;
mod parse;
pub mod test_format;
pub mod trusted_setup;

Expand Down
87 changes: 87 additions & 0 deletions src/parse.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
use crate::KzgSettings;
use bls12_381::{fp::Fp, fp2::Fp2, G1Affine, G2Affine};
use serde_json::Value;
use subtle::Choice;

const TRUSTED_SETUP_FILE: &str = include_str!("trusted_setup.json");

pub(crate) fn get_trusted_setup() -> KzgSettings {
let json: Value = serde_json::from_str(TRUSTED_SETUP_FILE).unwrap();
let max_width = json["max_width"].as_u64().unwrap() as usize;

let g1_values: Vec<G1Affine> = json["g1_values"]
.as_array()
.unwrap()
.iter()
.map(|entry| {
let x = Fp((&entry["x"])
.as_array()
.map(|xs| xs.iter().map(|x| x.as_u64().unwrap()).collect::<Vec<u64>>())
.unwrap()
.clone()
.try_into()
.unwrap());
let y = Fp((&entry["y"])
.as_array()
.map(|ys| ys.iter().map(|y| y.as_u64().unwrap()).collect::<Vec<u64>>())
.unwrap()
.clone()
.try_into()
.unwrap());
let infinity = Choice::from(entry["infinity"].as_u64().unwrap() as u8);
G1Affine { x, y, infinity }
})
.collect();

let g2_values: Vec<G2Affine> = json["g2_values"]
.as_array()
.unwrap()
.iter()
.map(|entry| {
let x = Fp2 {
c0: Fp((&entry["x"]["c0"])
.as_array()
.unwrap()
.iter()
.map(|x| x.as_u64().unwrap())
.collect::<Vec<u64>>()
.try_into()
.unwrap()),
c1: Fp((&entry["x"]["c1"])
.as_array()
.unwrap()
.iter()
.map(|x| x.as_u64().unwrap())
.collect::<Vec<u64>>()
.try_into()
.unwrap()),
};
let y = Fp2 {
c0: Fp((&entry["y"]["c0"])
.as_array()
.unwrap()
.iter()
.map(|y| y.as_u64().unwrap())
.collect::<Vec<u64>>()
.try_into()
.unwrap()),
c1: Fp((&entry["y"]["c1"])
.as_array()
.unwrap()
.iter()
.map(|y| y.as_u64().unwrap())
.collect::<Vec<u64>>()
.try_into()
.unwrap()),
};
let infinity = Choice::from(entry["infinity"].as_u64().unwrap() as u8);
G2Affine { x, y, infinity }
})
.collect();

KzgSettings {
max_width,
g1_values,
g2_values,
}
}
Loading