Skip to content

Commit

Permalink
fix: merkle tree version and some warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
sebasti810 authored and distractedm1nd committed Jul 2, 2024
1 parent 98898be commit 2a00b48
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 43 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ clap = { version = "4.3.2", features = ["derive"] }
config = "0.14.0"
fs2 = "0.4.3"
thiserror = "1.0.50"
indexed-merkle-tree = "0.3.0"
indexed-merkle-tree = "0.3.1"
dotenvy = "0.15.7"
ahash = "0.8.7"
celestia-rpc = "0.1.0"
Expand Down
7 changes: 6 additions & 1 deletion src/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ use config::{builder::DefaultState, ConfigBuilder, File, FileFormat};
use serde::Deserialize;
use std::sync::Arc;

use crate::da::{CelestiaConnection, DataAvailabilityLayer, LocalDataAvailabilityLayer};
#[cfg(not(test))]
use crate::da::CelestiaConnection;
#[cfg(test)]
use crate::da::LocalDataAvailabilityLayer;

use crate::da::DataAvailabilityLayer;

#[derive(Clone, Debug, Subcommand, Deserialize)]
pub enum Commands {
Expand Down
36 changes: 20 additions & 16 deletions src/da.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
use crate::error::{DataAvailabilityError, DatabaseError, DeimosError, GeneralError};
use crate::utils::Signable;
use crate::zk_snark::{Bls12Proof, VerifyingKey};
use crate::{
error::{DataAvailabilityError, DatabaseError, DeimosError, GeneralError},
utils::Signable,
zk_snark::{Bls12Proof, VerifyingKey},
};
use async_trait::async_trait;
use celestia_rpc::{BlobClient, Client, HeaderClient};
use celestia_types::blob::SubmitOptions;
use celestia_types::{nmt::Namespace, Blob};
use celestia_types::{blob::SubmitOptions, nmt::Namespace, Blob};
use ed25519::Signature;
use fs2::FileExt;
use serde::{Deserialize, Serialize};
use serde_json::json;
use serde_json::Value;
use std::fs::{File, OpenOptions};
use std::io::{Read, Seek, Write};
use std::str::FromStr;
use std::{self, sync::Arc};
use tokio::sync::mpsc;
use tokio::task::spawn;
use serde_json::{json, Value};
use std::{
self,
fs::{File, OpenOptions},
io::{Read, Seek, Write},
str::FromStr,
sync::Arc,
};
use tokio::{sync::mpsc, task::spawn};

#[derive(Serialize, Deserialize, Clone)]
pub struct EpochJson {
Expand Down Expand Up @@ -363,13 +365,15 @@ mod da_tests {
use bellman::groth16;
use bls12_381::Bls12;
use indexed_merkle_tree::{
node::{InnerNode, LeafNode, Node},
node::Node,
sha256,
tree::{IndexedMerkleTree, Proof},
};
use rand::rngs::OsRng;
use std::fs::OpenOptions;
use std::io::{Error, Seek, SeekFrom};
use std::{
fs::OpenOptions,
io::{Error, Seek, SeekFrom},
};

const EMPTY_HASH: &str = Node::EMPTY_HASH;
const TAIL: &str = Node::TAIL;
Expand Down
3 changes: 2 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ mod webserver;
pub mod zk_snark;
extern crate keystore;

use cfg::{initialize_da_layer, load_config};
use clap::Parser;
use keystore::{KeyChain, KeyStore, KeyStoreType};

use cfg::{initialize_da_layer, load_config, CommandLineArgs, Commands};
use crate::cfg::{CommandLineArgs, Commands};
use dotenvy::dotenv;
use node_types::{LightClient, NodeType, Sequencer};
use std::sync::Arc;
Expand Down
10 changes: 5 additions & 5 deletions src/node_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ use bellman::groth16::Proof;
use bls12_381::Bls12;
use crypto_hash::{hex_digest, Algorithm};
use ed25519_dalek::{Signer, SigningKey};
use indexed_merkle_tree::{
error::MerkleTreeError, node::LeafNode, node::Node, tree::IndexedMerkleTree,
};
use indexed_merkle_tree::{error::MerkleTreeError, node::Node, tree::IndexedMerkleTree};
use std::{self, io::ErrorKind, sync::Arc, time::Duration};
use tokio::{task::spawn, time::sleep};

Expand Down Expand Up @@ -54,7 +52,7 @@ impl NodeType for Sequencer {
Ok(keys) => {
if keys.len() == 0 {
// if the dict is empty, we need to initialize the dict and the input order
self.db.initialize_derived_dict();
self.db.initialize_derived_dict().unwrap();
}
}
Err(e) => {
Expand Down Expand Up @@ -262,7 +260,9 @@ impl Sequencer {

if let Some(da) = &self.da {
// TODO: retries (#10)
da.submit(&epoch_json_with_signature).await;
da.submit(&epoch_json_with_signature)
.await
.expect("Failed to submit epoch");
}
Ok(proof)
}
Expand Down
23 changes: 6 additions & 17 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,15 @@ use crate::{
error::{DeimosError, GeneralError, ProofError},
storage::{ChainEntry, Operation},
zk_snark::{
hex_to_scalar, BatchMerkleProofCircuit, InsertMerkleProofCircuit, ProofVariantCircuit,
UpdateMerkleProofCircuit,
hex_to_scalar, InsertMerkleProofCircuit, ProofVariantCircuit, UpdateMerkleProofCircuit,
},
};
use base64::{engine::general_purpose::STANDARD as engine, Engine as _};
use bellman::groth16::{self, VerifyingKey};
use bls12_381::{Bls12, Scalar};
use ed25519::Signature;
use ed25519_dalek::{Verifier, VerifyingKey as Ed25519VerifyingKey};
use indexed_merkle_tree::tree::{
IndexedMerkleTree, InsertProof, MerkleProof, NonMembershipProof, Proof, UpdateProof,
};
use indexed_merkle_tree::tree::{InsertProof, NonMembershipProof, Proof, UpdateProof};
use rand::rngs::OsRng;

/// Checks if a given public key in the list of `ChainEntry` objects has been revoked.
Expand Down Expand Up @@ -42,14 +39,6 @@ pub fn parse_json_to_proof(json_str: &str) -> Result<Proof, Box<dyn std::error::
Ok(proof)
}

fn parse_option_to_scalar(option_input: Option<String>) -> Result<Scalar, GeneralError> {
let input_str = option_input
.ok_or_else(|| GeneralError::ParsingError("Could not parse input".to_string()))?;

hex_to_scalar(&input_str)
.map_err(|_| GeneralError::ParsingError("Could not convert input to scalar".to_string()))
}

pub fn decode_public_key(pub_key_str: &String) -> Result<Ed25519VerifyingKey, GeneralError> {
// decode the public key from base64 string to bytes
let public_key_bytes = engine.decode(pub_key_str).map_err(|e| {
Expand Down Expand Up @@ -183,10 +172,10 @@ pub fn verify_signature<T: Signable>(

#[cfg(test)]
mod tests {
use indexed_merkle_tree::{
node::{LeafNode, Node},
sha256,
};
use crate::zk_snark::BatchMerkleProofCircuit;
use indexed_merkle_tree::tree::{IndexedMerkleTree, Proof};

use indexed_merkle_tree::{node::Node, sha256};

use super::*;

Expand Down

0 comments on commit 2a00b48

Please sign in to comment.