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

add: verkle proof aggregation for multiproof, and updated stateRoot #45

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
21 changes: 17 additions & 4 deletions ipa-multipoint/ipa_multipoint_jni/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,29 @@ repository = "https://github.com/hyperledger/besu-native"
edition = "2018"

[dependencies]
verkle-spec = { git = "https://github.com/crate-crypto/rust-verkle", branch = "master" }
anyhow = "1.0"
tempfile = "3.2.0"
thiserror = "1.0"
ipa-multipoint = { git = "https://github.com/crate-crypto/ipa_multipoint", branch = "banderwagon_migration" }
banderwagon = { git = "https://github.com/crate-crypto/banderwagon" }
bandersnatch = "0.1.1"
ark-ff = { version = "^0.3.0", default-features = false }
ark-ec = { version = "^0.3.0", default-features = false }
ark-serialize = { version = "^0.3.0", default-features = false }
ark-std = { version = "^0.3.0", default-features = false }
jni = { version = "0.19.0", features = ["invocation"] } # We use invocation in tests.
verkle-db = { git = "https://github.com/crate-crypto/rust-verkle", branch = "master" }
verkle-trie = { git = "https://github.com/crate-crypto/rust-verkle", branch = "master" }
verkle-spec = { git = "https://github.com/crate-crypto/rust-verkle", branch = "master" }
once_cell = "1.8.0"
hex = "0.4.3"
rand_chacha = { version = "0.3.0", default-features = false }
rayon = "1.5.1"
smallvec = "1.6.1"
sha2 = "0.9.3"
itertools = "0.10.1"
jni = { version = "0.19.0", features = ["invocation"] }

[dev-dependencies]
criterion = "0.3.4"
tempfile = "3.2.0"

[lib]
name = "ipa_multipoint_jni"
Expand Down
150 changes: 150 additions & 0 deletions ipa-multipoint/ipa_multipoint_jni/src/proofs/proverint.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
use crate::{
constants::{CRS, PRECOMPUTED_WEIGHTS},
errors::ProofCreationError,
proof::opening_data::{OpeningData, Openings},
};
use crate::{
errors::HintError,
};
use ark_serialize::{CanonicalDeserialize, CanonicalSerialize, Read, SerializationError, Write};

use banderwagon::Element;
use ipa_multipoint::multiproof::MultiPointProof;
use std::collections::{BTreeMap, BTreeSet};
use ipa_multipoint::{
multiproof::{MultiPoint, ProverQuery},
transcript::Transcript,
};

use verkle_trieproof::{VerkleProof, VerificationHint};
use itertools::Itertools;
use std::collections::BTreeSet;
use verkle_trie::database::{StemMeta, BranchMeta, Meta};
use verkle_trie::committer::{trie::Trie, TrieTrait};
use verkle_trie::committer::{Committer, PrecomputeLagrange, precompute::LagrangeTablePoints};
use verkle_spec::*;

use jni::JNIEnv;
use jni::objects::JClass;
use jni::sys::jbyteArray;

#[no_mangle]
pub extern "system" fn Java_org_hyperledger_besu_nativelib_ipamultipoint_LibIpaMultipoint_stemSerde(
env: JNIEnv,
_class:JClass,
input: jbyteArray,
)->jbyteArray{

let input = env.convert_byte_array(input).unwrap();
let mut stem_bytes = Vec::<u8>::new();

stem_bytes.resize(input.len(), 0);
stem_bytes.copy_from_slice(&input[0..32])

match StemMeta::from_bytes(stem_bytes) {
Ok(stem_meta) => {
println!("Deserialized stem successfully: {:?}", stem_meta);
}

Err(SerializationError::InvalidData) => {
println!("Failed to deserialize stem: Invalid data!")
}

Err(_) => {
println!("Failed for some unknown error!")
}
}
}

#[no_mangle]
pub extern "system" fn Java_org_hyperledger_besu_nativelib_ipamultipoint_LibIpaMultipoint_branchSerde(
env: JNIEnv,
_class:JClass,
input: jbyteArray,
)->jbyteArray{

let input = env.convert_byte_array(input).unwrap();
let mut stem_bytes = Vec::<u8>::new();

branch_bytes.resize(input.len(), 0);
branch_bytes.copy_from_slice(&input[0..32])

match BranchMeta::from_bytes(stem_bytes) {
Ok(stem_meta) => {
println!("Deserialized branch successfully: {:?}", stem_meta);
}

Err(SerializationError::InvalidData) => {
println!("Failed to deserialize branch: Invalid data!")
}

Err(_) => {
println!("Failed for some unknown error!")
}
}
}

#[no_mangle]
pub extern "system" fn Java_org_hyperledger_besu_nativelib_ipamultipoint_LibIpaMultipoint_updateRootBasic(
env: JNIEnv,
_class:JClass,
input: jbyteArray,
)->jbyteArray{
let input = env.convert_byte_array(input).unwrap();
let mut root_bytes = Vec::<u8>::new();

root_bytes.resize(input.len(), 0);
root_bytes.copy_from_slice(&input[0..32])

match Element::from_bytes(root_bytes) {
Ok(element) => {
println!("Deserialized Element properly!", element)
}
Err(SerializationError::InvalidData) => {
println!("Failed to deserialize Element: Invalid data");
}
Err(_) => {
println!("Failed to deserialize Element: Unknown error");
}
}

let mut trie = Trie::new(element);

let mut keys = Vec::new();
for i in 0..2 {
let mut key_0 = [0u8, 32]
key_0[0] = i;

keys.push(key_0);
Trie::insert_single(key_0, key_0);
}
let root = vec![]
let meta = trie.storage.get_branch_meta(&root).unwrap();

let proof = prover::create_verkle_proof(&trie.storage, keys.clone());

let values: Vec<_> = keys.iter().map(|val| Some(*val).collect());

let (ok, updated_hint) = proof.check(keys.clone(), values.clone(), meta.commitment());
assert!(ok);


let point = Element::prime_subgroup_generator();

let lagrange_points = LagrangeTablePoints::precompute(&CRS.G)

let new_root_commitment = update_root(
updated_hint.unwrap(),
keys.clone(),
values,
vec![Some([0u8, 32]), None],
meta.commitment,
lagrange_points
)

let mut got_bytes = [0u8; 32]
group_to_field(&new_root_commitment.unwrap()).serialize(&mut got_bytes[..]).unwrap()

new_root_commitment.reverse();
return env.byte_array_from_slice(&new_root_commitment).expect("Couldn't convert to byte array");
}
42 changes: 42 additions & 0 deletions ipa-multipoint/ipa_multipoint_jni/src/proofs/trieproof.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#![allow(clippy::large_enum_variant)]
use verkle_trie::constants::{CRS, TWO_POLY_128};
use verkle_trie::database::{BranchMeta, StemMeta, Flush, Meta};
use verkle_trie::committer::{group_to_field,Trie, TrieTrait};
use ark_ff::{PrimeField, Zero};

use ark_serialize::{CanonicalDeserialize, CanonicalSerialize, Read, SerializationError, Write};

use banderwagon::{Element, Fr};
use std::ops::Mul;


//inserting into the tree when the key values are all zeroes
#[no_mangle]
pub extern "system" fn Java_org_hyperledger_besu_nativelib_ipamultipoint_LibIpaMultipoint_insertKeyValue0(
env: JNIEnv,
_class:JClass,
input1: jbyteArray,
input2: jbyteArray,
)->jbyteArray{

let input1 = env.convert_byte_array(input1).unwrap();
let mut key_bytes = Vec::<u8>::new();

key_bytes.resize(input1.len(), 0);
key_bytes.copy_from_slice(&input1[0..32])

match Element::from_bytes(root_bytes) {
Ok(element) => {
println!("Deserialized Element properly!", element)
}
Err(SerializationError::InvalidData) => {
println!("Failed to deserialize Element: Invalid data");
}
Err(_) => {
println!("Failed to deserialize Element: Unknown error");
}
}

//TODO

}