Skip to content

Commit

Permalink
feat: switch to substrate
Browse files Browse the repository at this point in the history
  • Loading branch information
iajoiner committed Oct 2, 2024
1 parent 0b6d9ad commit b4c9785
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 17 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ ark-std = { version = "0.4.0", features = [ "parallel" ] }
curve25519-dalek = { version = "4", features = ["rand_core"] }
flexbuffers = { version = "2.0.0" }
proof-of-sql = { version = "0.12.3", default-features = false, features = ["blitzar", "test"] }
proof-of-sql-parser = { version = "0.12.3" }
prost = "0.12"
serde = { version = "1.0", features = ["serde_derive"] }
subxt = "0.37.0"
subxt-signer = "0.37.0"
tokio = { version = "1.0", features = ["rt-multi-thread", "macros"] }
tonic = { version = "0.11", features = ["tls", "tls-roots"] }

Expand Down
28 changes: 12 additions & 16 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
mod substrate;
mod sxt_chain_runtime;

use ark_std::test_rng;
Expand All @@ -6,7 +7,7 @@ use curve25519_dalek::RistrettoPoint;
use flexbuffers;
use proof_of_sql::{
base::{
commitment::InnerProductProof,
commitment::{InnerProductProof, QueryCommitments},
database::{owned_table_utility::*, OwnedTableTestAccessor, TestAccessor},
},
proof_primitive::dory::{
Expand All @@ -15,7 +16,7 @@ use proof_of_sql::{
},
sql::{parse::QueryExpr, proof::VerifiableQueryResult},
};
use prover::{prover_client::ProverClient, ProverQuery, ProverContextRange};
use prover::{prover_client::ProverClient, ProverContextRange, ProverQuery};
use std::collections::HashMap;

mod prover {
Expand All @@ -33,19 +34,14 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
// let dory_prover_setup = DoryProverPublicSetup::new(&prover_setup, 3);
// let dory_verifier_setup = DoryVerifierPublicSetup::new(&verifier_setup, 3);
// Accessor setup
let mut accessor = OwnedTableTestAccessor::<InnerProductProof>::new_empty_with_setup(());
let table = owned_table([
smallint("smallint_minmax", [i16::MIN, -1, 0, 1, i16::MAX]),
int("int_minmax", [i32::MIN, -1, 0, 1, i32::MAX]),
bigint("bigint_minmax", [i64::MIN, -1, 0, 1, i64::MAX]),
boolean("boolean_minmax", [false, true, false, true, false]),
bigint("proof_order", [0_i64, 1, 2, 3, 4]),
]);
accessor.add_table(
"proofs_smoke_tests.kyucqklhqcmlvuyc".parse()?,
table.clone(),
0,
);
let accessor = substrate::query_commitments(
&[
"proofs_smoke_tests".parse()?,
"proofs_smoke_tests.kyucqklhqcmlvuyc".parse()?,
],
"<URL>",
"dory".parse()?,
)?;
// Parse the SQL query
let query: QueryExpr<RistrettoPoint> =
QueryExpr::try_new(sql.parse()?, "proofs_smoke_tests".parse()?, &accessor)?;
Expand All @@ -58,7 +54,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
ProverContextRange {
start: 0,
ends: vec![5],
}
},
);
let prover_query = ProverQuery {
proof_plan: serialized_proof_plan,
Expand Down
56 changes: 56 additions & 0 deletions src/substrate.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
use proof_of_sql::base::{commitment::{QueryCommitments, TableCommitment}, database::TableRef};
use proof_of_sql_parser::{Identifier, ResourceId};
use proof_of_sql_commitment_map::CommitmentScheme;
use subxt::{
client::OfflineClientT,
utils::{AccountId32, MultiAddress},
OnlineClient, PolkadotConfig,
};
use subxt_signer::sr25519::dev::{self};
use crate::sxt_chain_runtime::api::runtime_types::sxt_core::{ByteString, tables::TableIdentifier};

/// Derive the runtime from the metadata
#[subxt::subxt(runtime_metadata_path = "sxt.scale")]
pub mod sxt_runtime {}
/// Use the standard PolkadotConfig
type SxtConfig = PolkadotConfig;

/// Convert PoSQL `Identifier` to SxT Core `ByteString`
fn identifier_to_byte_string(identifier: &Identifier) -> ByteString {
let byte_string = ByteString::new();
let name = identifier.as_str().as_bytes();
// Unwrapping is allowed since both PoSQL and SxT Core identifiers have the same length restrictions
ByteString.try_extend(name).unwrap()
}

/// Convert PoSQL resource IDs to SxT Core table identifiers
fn resource_id_to_table_id(resource_id: &ResourceId) -> TableIdentifier {
TableIdentifier {
name: identifier_to_byte_string(resource_id.object_name()),
namespace: identifier_to_byte_string(resource_id.schema()),
}
}

/// Query the commitments pallet to find which commitments
pub fn query_commitments(
resource_ids: &[ResourceId],
url: &str,
commitment_scheme: CommitmentScheme,
) -> Result<QueryCommitments, Box<dyn std::error::Error>> {
let api = OnlineClient::<SxtConfig>::from_url(url).await?;
let mut accessor = QueryCommitments::new();
resource_ids.iter().map(|id| -> Result<(TableRef, TableCommitment), Box<dyn std::error::Error>>{
let table_id = resource_id_to_table_id(id);
let commitments_query = sxt_runtime::storage()
.commitments()
.commitments(table_id, commitment_scheme);
let table_commitments: TableCommitment = api
.storage()
.at_latest()
.await?
.fetch(&commitments_query)
.await?
.unwrap();
(TableRef::new(id), commitments)
}).collect::<Result<QueryCommitments, Box<dyn std::error::Error>>>()
}
1 change: 0 additions & 1 deletion src/sxt_chain_runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11031,4 +11031,3 @@ pub mod api {
}
}
}

0 comments on commit b4c9785

Please sign in to comment.