Skip to content
Closed
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
2,161 changes: 663 additions & 1,498 deletions Cargo.lock

Large diffs are not rendered by default.

25 changes: 9 additions & 16 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,51 +23,44 @@ borsh = { version = "1.5.1", features = ["derive"] }
tower-http = { version = "0.4", features = ["cors"] }
utoipa = { version = "3.3", features = ["axum_extras"] }
utoipa-swagger-ui = { version = "3.1", features = ["axum"] }
crypto-hash = "0.3.4"
async-trait = "0.1.68"
serde = { version = "1.0.151", features = ["derive"] }
serde_json = "1.0.79"
redis = "0.24.0"
actix-web = { version = "4.4.1" }
actix-cors = "0.7.0"
async-redis-session = "0.2.2"
ed25519-dalek = "2.1.0"
ed25519 = "2.2.0"
base64 = "0.22.0"
tokio = { version = "1.16.1", features = ["full"] }
reqwest = { version = "0.11.23", features = ["json"] }
ctrlc = "3.1.5"
num = "0.4.0"
bellman = "0.14.0"
pairing = "0.23.0"
jsonrpsee = { version = "0.22.2", features = ["ws-client"] }
bls12_381 = "0.8.0"
rand = "0.8.5"
rand07 = { package = "rand", version = "0.7.0" }
hex = "0.4.3"
ff = "0.13.0"
openssl = "0.10.66"
futures = "0.3"
lazy_static = "1.4"
colored = "2.0.0"
log = "0.4"
pretty_env_logger = "0.5.0"
clap = { version = "4.3.2", features = ["derive"] }
config = "0.14.0"
fs2 = "0.4.3"
thiserror = "1.0.62"
indexed-merkle-tree = "0.6.2"
dotenvy = "0.15.7"
ahash = "0.8.7"
celestia-rpc = "0.2.0"
celestia-types = "0.2.0"
mockall = "0.12.1"
keystore-rs = "0.1.0"
pyroscope = "0.5.7"
pyroscope_pprofrs = "0.2.7"
toml = "0.8.14"
dirs = "5.0.1"
anyhow = "1.0.44"
jmt = { git = "https://github.com/deltadevsde/jmt", features = [
"mocks",
] } #{ version = "0.10.0", features = ["mocks"] }
bellpepper-core = { version = "0.4.0", default-features = false }
arecibo = { git = "https://github.com/deltadevsde/arecibo" }
itertools = "0.13.0" # zip_eq
sha2 = "0.10.8"
auto_impl = "1.2.0"
bincode = "1.3.3"

[dev-dependencies]
serial_test = "3.1.1"
Expand Down
3 changes: 2 additions & 1 deletion rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
imports_granularity="Crate"
merge_imports = true
imports_granularity = "Crate"
17 changes: 14 additions & 3 deletions src/cfg.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use crate::consts::{DA_RETRY_COUNT, DA_RETRY_INTERVAL};
use crate::da::memory::InMemoryDataAvailabilityLayer;
use crate::error::{DataAvailabilityError, GeneralError, PrismError};
use crate::{
consts::{DA_RETRY_COUNT, DA_RETRY_INTERVAL},
da::memory::InMemoryDataAvailabilityLayer,
error::{DataAvailabilityError, GeneralError, PrismError},
};
use anyhow::{anyhow, Context, Result};
use clap::{Parser, Subcommand};
use config::{builder::DefaultState, ConfigBuilder, File};
Expand All @@ -15,6 +17,7 @@ use crate::da::{celestia::CelestiaConnection, DataAvailabilityLayer};
pub enum Commands {
LightClient,
Sequencer,
GeneratePublicParams,
}

#[derive(Parser, Clone, Debug, Deserialize)]
Expand Down Expand Up @@ -57,6 +60,10 @@ pub struct CommandLineArgs {
#[arg(long)]
config_path: Option<String>,

/// Path to the bin file containing serialized PublicParams<PallasEngine>
#[arg(long)]
public_params_path: Option<String>,

#[command(subcommand)]
pub command: Commands,
}
Expand All @@ -70,6 +77,7 @@ pub struct Config {
pub da_layer: Option<DALayerOption>,
pub redis_config: Option<RedisConfig>,
pub verifying_key: Option<String>,
pub public_params_path: Option<String>,
}

#[derive(Debug, Default, Clone, Eq, PartialEq, Serialize, Deserialize)]
Expand Down Expand Up @@ -135,6 +143,7 @@ impl Default for Config {
celestia_config: Some(CelestiaConfig::default()),
redis_config: Some(RedisConfig::default()),
verifying_key: None,
public_params_path: None,
}
}
}
Expand Down Expand Up @@ -201,6 +210,7 @@ fn merge_configs(loaded: Config, default: Config) -> Config {
celestia_config: loaded.celestia_config.or(default.celestia_config),
da_layer: loaded.da_layer.or(default.da_layer),
verifying_key: loaded.verifying_key.or(default.verifying_key),
public_params_path: loaded.public_params_path.or(default.public_params_path),
}
}

Expand Down Expand Up @@ -264,6 +274,7 @@ fn apply_command_line_args(config: Config, args: CommandLineArgs) -> Config {
}),
da_layer: config.da_layer,
verifying_key: args.verifying_key.or(config.verifying_key),
public_params_path: args.public_params_path.or(config.public_params_path),
}
}

Expand Down
7 changes: 4 additions & 3 deletions src/circuits/merkle_batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ use crate::{
merkle_insertion::prove_insertion, merkle_update::prove_update, InsertMerkleProofCircuit,
ProofVariantCircuit, UpdateMerkleProofCircuit,
},
tree::Digest,
utils::create_and_verify_snark,
};
use anyhow::Result;
use bellman::{groth16, Circuit, ConstraintSystem, SynthesisError};
use bls12_381::{Bls12, Scalar};
use indexed_merkle_tree::{tree::Proof, Hash};
use indexed_merkle_tree::tree::Proof;

/// BatchMerkleProofCircuit represents a circuit for proving a batch of merkle proof circuits.
#[derive(Clone)]
Expand All @@ -20,8 +21,8 @@ pub struct BatchMerkleProofCircuit {

impl BatchMerkleProofCircuit {
pub fn new(
old_commitment: &Hash,
new_commitment: &Hash,
old_commitment: &Digest,
new_commitment: &Digest,
proofs: Vec<Proof>,
) -> Result<BatchMerkleProofCircuit> {
let parsed_old_commitment: Scalar = (*old_commitment).try_into()?;
Expand Down
106 changes: 53 additions & 53 deletions src/circuits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ pub mod merkle_insertion;
pub mod merkle_update;
pub mod utils;

pub use hashchain::HashChainEntryCircuit;
pub use less_than::LessThanCircuit;
pub use merkle_batch::BatchMerkleProofCircuit;
pub use merkle_insertion::InsertMerkleProofCircuit;
Expand Down Expand Up @@ -189,6 +188,7 @@ impl TryFrom<VerifyingKey> for groth16::VerifyingKey<Bls12> {
#[cfg(test)]
mod tests {
use super::*;
use crate::tree::Digest;
use bellman::groth16;
use bls12_381::Bls12;
use indexed_merkle_tree::{
Expand Down Expand Up @@ -278,58 +278,58 @@ mod tests {
setup_and_test_less_than_circuit(head, head)
}

#[test]
fn test_serialize_and_deserialize_proof() {
let mut tree = IndexedMerkleTree::new_with_size(4).unwrap();
let prev_commitment = tree.get_commitment().unwrap();

// create two nodes to insert
let ryan = sha256_mod(b"Ryan");
let ford = sha256_mod(b"Ford");
let sebastian = sha256_mod(b"Sebastian");
let pusch = sha256_mod(b"Pusch");
let ethan = sha256_mod(b"Ethan");
let triple_zero = sha256_mod(b"000");

let mut ryans_node = Node::new_leaf(true, ryan, ford, Node::TAIL);
let mut sebastians_node = Node::new_leaf(true, sebastian, pusch, Node::TAIL);
let mut ethans_node = Node::new_leaf(true, ethan, triple_zero, Node::TAIL);

// generate proofs for the two nodes
let first_insert_proof = tree.insert_node(&mut ryans_node).unwrap();
let second_insert_proof = tree.insert_node(&mut sebastians_node).unwrap();
let third_insert_proof = tree.insert_node(&mut ethans_node).unwrap();

// create zkSNARKs for the two proofs
let first_insert_zk_snark = Proof::Insert(first_insert_proof);
let second_insert_zk_snark = Proof::Insert(second_insert_proof);
let third_insert_zk_snark = Proof::Insert(third_insert_proof);

let proofs = vec![
first_insert_zk_snark,
second_insert_zk_snark,
third_insert_zk_snark,
];
let current_commitment = tree.get_commitment().unwrap();

let batched_proof =
BatchMerkleProofCircuit::new(&prev_commitment, &current_commitment, proofs).unwrap();

let rng = &mut OsRng;
let params =
groth16::generate_random_parameters::<Bls12, _, _>(batched_proof.clone(), rng).unwrap();
let proof = groth16::create_random_proof(batched_proof.clone(), &params, rng).unwrap();

let serialized_proof: Bls12Proof = proof.clone().into();
let deserialized_proof_result: Result<groth16::Proof<Bls12>> =
serialized_proof.clone().try_into();
assert!(deserialized_proof_result.is_ok(), "Deserialization failed");

let deserialized_proof = deserialized_proof_result.unwrap();
assert_eq!(proof.a, deserialized_proof.a);
assert_eq!(proof.b, deserialized_proof.b);
assert_eq!(proof.c, deserialized_proof.c);
}
// Commented because needs to be rewritten to JMT
// #[test]
// fn test_serialize_and_deserialize_proof() {
// let mut tree = IndexedMerkleTree::new_with_size(4).unwrap();

// // create two nodes to insert
// let ryan = sha256_mod(b"Ryan");
// let ford = sha256_mod(b"Ford");
// let sebastian = sha256_mod(b"Sebastian");
// let pusch = sha256_mod(b"Pusch");
// let ethan = sha256_mod(b"Ethan");
// let triple_zero = sha256_mod(b"000");

// let mut ryans_node = Node::new_leaf(true, ryan, ford, Node::TAIL);
// let mut sebastians_node = Node::new_leaf(true, sebastian, pusch, Node::TAIL);
// let mut ethans_node = Node::new_leaf(true, ethan, triple_zero, Node::TAIL);

// // generate proofs for the two nodes
// let first_insert_proof = tree.insert_node(&mut ryans_node).unwrap();
// let second_insert_proof = tree.insert_node(&mut sebastians_node).unwrap();
// let third_insert_proof = tree.insert_node(&mut ethans_node).unwrap();

// // create zkSNARKs for the two proofs
// let first_insert_zk_snark = Proof::Insert(first_insert_proof);
// let second_insert_zk_snark = Proof::Insert(second_insert_proof);
// let third_insert_zk_snark = Proof::Insert(third_insert_proof);

// let proofs = vec![
// first_insert_zk_snark,
// second_insert_zk_snark,
// third_insert_zk_snark,
// ];
// let current_commitment = tree.get_commitment().unwrap();

// let batched_proof =
// BatchMerkleProofCircuit::new(&prev_commitment, &current_commitment, proofs).unwrap();

// let rng = &mut OsRng;
// let params =
// groth16::generate_random_parameters::<Bls12, _, _>(batched_proof.clone(), rng).unwrap();
// let proof = groth16::create_random_proof(batched_proof.clone(), &params, rng).unwrap();

// let serialized_proof: Bls12Proof = proof.clone().into();
// let deserialized_proof_result: Result<groth16::Proof<Bls12>> =
// serialized_proof.clone().try_into();
// assert!(deserialized_proof_result.is_ok(), "Deserialization failed");

// let deserialized_proof = deserialized_proof_result.unwrap();
// assert_eq!(proof.a, deserialized_proof.a);
// assert_eq!(proof.b, deserialized_proof.b);
// assert_eq!(proof.c, deserialized_proof.c);
// }

#[test]
fn test_deserialize_invalid_proof() {
Expand Down
Loading
Loading