Skip to content

Commit

Permalink
remove ark-serialize from verkle-trie and make code use trait_defs::*
Browse files Browse the repository at this point in the history
  • Loading branch information
kevaundray committed Jan 10, 2024
1 parent 47c08c4 commit 5ff1a95
Show file tree
Hide file tree
Showing 10 changed files with 12 additions and 48 deletions.
1 change: 0 additions & 1 deletion verkle-trie/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ tempfile = "3.2.0"
thiserror = "1.0"
ipa-multipoint = { path = "../ipa-multipoint" }
banderwagon = { path = "../banderwagon" }
ark-serialize = { version = "^0.4.2", default-features = false }
verkle-db = { path = "../verkle-db", default-features = false }
once_cell = "1.8.0"
hex = "0.4.3"
Expand Down
2 changes: 1 addition & 1 deletion verkle-trie/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub static PRECOMPUTED_WEIGHTS: Lazy<PrecomputedWeights> =
#[cfg(test)]
mod tests {
use super::TWO_POW_128;
use banderwagon::{Fr, VerkleField};
use banderwagon::{trait_defs::*, Fr};

#[test]
fn test_two_pow128_constant() {
Expand Down
6 changes: 2 additions & 4 deletions verkle-trie/src/database/meta.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![allow(clippy::identity_op)]
#![allow(clippy::large_enum_variant)]
use ark_serialize::{CanonicalDeserialize, SerializationError};
use banderwagon::trait_defs::*;
use banderwagon::{Element, Fr};

#[derive(Clone, Copy, PartialEq, Eq, Hash)]
Expand Down Expand Up @@ -45,8 +45,6 @@ impl std::fmt::Debug for StemMeta {
}
}

use ark_serialize::CanonicalSerialize;

fn point_to_array(p: &Element) -> Result<[u8; 64], SerializationError> {
let mut bytes = [0u8; 64];
p.serialize_uncompressed(&mut bytes[..])?;
Expand Down Expand Up @@ -136,7 +134,7 @@ impl std::fmt::Debug for BranchMeta {
}
impl BranchMeta {
pub fn zero() -> BranchMeta {
use banderwagon::VerkleField;
use banderwagon::trait_defs::*;
BranchMeta {
commitment: Element::zero(),
hash_commitment: Fr::zero(),
Expand Down
2 changes: 1 addition & 1 deletion verkle-trie/src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use ark_serialize::SerializationError;
use banderwagon::trait_defs::*;
use thiserror::Error;

// Right now there are lots of unwraps which are immediately switched to Results, but in the future
Expand Down
33 changes: 1 addition & 32 deletions verkle-trie/src/from_to_bytes.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
use ark_serialize::SerializationError;
// use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
// use banderwagon::{Element, Fr};
// use std::result::Result;
use banderwagon::trait_defs::*;

// // TODO: The only things that need to be converted to bytes are Points and scalars
// // so maybe we can return a [u8;32] and avoid allocating
// // Then use this instead of ark_serialize in the codebase
pub trait ToBytes<T> {
fn to_bytes(&self) -> Result<T, SerializationError>;
}
Expand All @@ -14,28 +8,3 @@ pub trait FromBytes<T> {
where
Self: Sized;
}

// impl ToBytes<[u8; 32]> for Element {
// fn to_bytes(&self) -> Result<[u8; 32], SerializationError> {
// let mut bytes = self.to_bytes();
// Ok(bytes)
// }
// }
// impl FromBytes<&[u8]> for Element {
// fn from_bytes(bytes: &[u8]) -> Result<Self, SerializationError> {
// CanonicalDeserialize::deserialize(bytes)
// }
// }
// impl ToBytes<[u8; 32]> for Fr {
// fn to_bytes(&self) -> Result<[u8; 32], SerializationError> {
// let mut bytes = [0u8; 32];
// self.serialize(&mut bytes[..])?;

// Ok(bytes)
// }
// }
// impl FromBytes<&[u8]> for Fr {
// fn from_bytes(bytes: &[u8]) -> Result<Self, SerializationError> {
// CanonicalDeserialize::deserialize(bytes)
// }
// }
2 changes: 1 addition & 1 deletion verkle-trie/src/proof/opening_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{
proof::key_path_finder::{KeyNotFound, KeyPathFinder, KeyState},
};

use banderwagon::{Fr, VerkleField};
use banderwagon::{trait_defs::*, Fr};
use ipa_multipoint::{lagrange_basis::LagrangeBasis, multiproof::ProverQuery};
use std::{
collections::{BTreeMap, BTreeSet},
Expand Down
4 changes: 2 additions & 2 deletions verkle-trie/src/proof/stateless_updater.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::constants::TWO_POW_128;
use crate::{errors::VerificationError, group_to_field, proof::ExtPresent};
use banderwagon::{Element, Fr, VerkleField};
use banderwagon::{trait_defs::*, Element, Fr};
use ipa_multipoint::committer::Committer;
use std::collections::{BTreeMap, HashSet};

Expand Down Expand Up @@ -574,7 +574,7 @@ where
#[cfg(test)]
mod test {

use ark_serialize::CanonicalSerialize;
use banderwagon::trait_defs::*;

use crate::constants::new_crs;
use crate::database::memory_db::MemoryDb;
Expand Down
2 changes: 1 addition & 1 deletion verkle-trie/src/proof/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
group_to_field,
proof::{ExtPresent, UpdateHint},
};
use banderwagon::{Element, Fr, VerkleField};
use banderwagon::{trait_defs::*, Element, Fr};
use ipa_multipoint::multiproof::VerifierQuery;
use std::{
collections::{BTreeMap, BTreeSet},
Expand Down
6 changes: 2 additions & 4 deletions verkle-trie/src/trie.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::Config;
use crate::{group_to_field, TrieTrait};
use ipa_multipoint::committer::Committer;

use banderwagon::{Element, Fr, VerkleField};
use banderwagon::{trait_defs::*, Element, Fr};

#[derive(Debug, Clone)]
// The trie implements the logic to insert values, fetch values, and create paths to said values
Expand Down Expand Up @@ -760,16 +760,14 @@ fn paths_from_relative(parent_path: Vec<u8>, relative_paths: Vec<u8>) -> Vec<Vec
}
#[cfg(test)]
mod tests {
use ark_serialize::CanonicalSerialize;
use banderwagon::VerkleField;

use crate::constants::{CRS, TWO_POW_128};
use crate::database::memory_db::MemoryDb;
use crate::database::ReadOnlyHigherDb;
use crate::trie::Trie;
use crate::TrieTrait;
use crate::{group_to_field, TestConfig};
use banderwagon::{Element, Fr};
use banderwagon::{trait_defs::*, Element, Fr};
use std::ops::Mul;

#[test]
Expand Down
2 changes: 1 addition & 1 deletion verkle-trie/tests/trie_fuzzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ fn step_test_helper<C: Committer>(

let root = trie.root_hash();

use ark_serialize::CanonicalSerialize;
use banderwagon::trait_defs::*;
let mut root_bytes = [0u8; 32];
root.serialize_compressed(&mut root_bytes[..]).unwrap();
assert_eq!(hex::encode(root_bytes), expected);
Expand Down

0 comments on commit 5ff1a95

Please sign in to comment.