From 92895a6904d3941eceda4e0dab270f83f12570fc Mon Sep 17 00:00:00 2001 From: Kevaundray Wedderburn Date: Sun, 7 Jan 2024 22:16:51 +0000 Subject: [PATCH] use VerkleField abstraction from banderwagon crate --- verkle-trie/Cargo.toml | 5 +---- verkle-trie/src/committer/precompute.rs | 5 ++--- verkle-trie/src/constants.rs | 7 +++---- verkle-trie/src/database/meta.rs | 2 +- verkle-trie/src/proof.rs | 1 - verkle-trie/src/proof/opening_data.rs | 4 ++-- verkle-trie/src/proof/stateless_updater.rs | 3 +-- verkle-trie/src/proof/verifier.rs | 3 +-- verkle-trie/src/trie.rs | 5 ++--- 9 files changed, 13 insertions(+), 22 deletions(-) diff --git a/verkle-trie/Cargo.toml b/verkle-trie/Cargo.toml index c4e456c..d4d8f3b 100644 --- a/verkle-trie/Cargo.toml +++ b/verkle-trie/Cargo.toml @@ -12,8 +12,6 @@ tempfile = "3.2.0" thiserror = "1.0" ipa-multipoint = { path = "../ipa-multipoint" } banderwagon = { path = "../banderwagon" } -ark-ff = { version = "^0.4.2", default-features = false } -ark-ec = { version = "^0.4.2", default-features = false } ark-serialize = { version = "^0.4.2", default-features = false } verkle-db = { path = "../verkle-db", default-features = false } once_cell = "1.8.0" @@ -33,5 +31,4 @@ name = "benchmark_main" harness = false [features] -default = ["parallel"] -parallel = ["ark-ff/parallel", "ark-ff/asm", "ark-ec/parallel"] +default = [] diff --git a/verkle-trie/src/committer/precompute.rs b/verkle-trie/src/committer/precompute.rs index d0bbd9f..6f371fe 100644 --- a/verkle-trie/src/committer/precompute.rs +++ b/verkle-trie/src/committer/precompute.rs @@ -1,9 +1,8 @@ use crate::committer::Committer; -use ark_ff::Zero; -use banderwagon::{Element, Fr}; +use banderwagon::{Element, Fr, VerkleField}; -use ark_serialize::{CanonicalDeserialize, CanonicalSerialize, Read, SerializationError, Write}; +use ark_serialize::{CanonicalDeserialize, CanonicalSerialize}; #[derive(Debug, Clone, CanonicalSerialize, CanonicalDeserialize, PartialEq, Eq)] pub struct PrecomputeLagrange { diff --git a/verkle-trie/src/constants.rs b/verkle-trie/src/constants.rs index 3a7c2f8..c8ed0a2 100644 --- a/verkle-trie/src/constants.rs +++ b/verkle-trie/src/constants.rs @@ -1,4 +1,4 @@ -use ark_ff::BigInteger256; +use banderwagon::fr_from_u64_limbs; pub use banderwagon::Fr; use ipa_multipoint::{crs::CRS, lagrange_basis::PrecomputedWeights}; use once_cell::sync::Lazy; @@ -11,7 +11,7 @@ pub const VERKLE_NODE_WIDTH: usize = 256; // using try-and-increment const PEDERSEN_SEED: &[u8] = b"eth_verkle_oct_2021"; -pub(crate) const TWO_POW_128: Fr = Fr::new(BigInteger256::new([0, 0, 1, 0])); +pub(crate) const TWO_POW_128: Fr = fr_from_u64_limbs([0, 0, 1, 0]); pub static CRS: Lazy = Lazy::new(|| CRS::new(VERKLE_NODE_WIDTH, PEDERSEN_SEED)); @@ -21,8 +21,7 @@ pub static PRECOMPUTED_WEIGHTS: Lazy = #[cfg(test)] mod tests { use super::TWO_POW_128; - use ark_ff::PrimeField; - use banderwagon::Fr; + use banderwagon::{Fr, VerkleField}; #[test] fn test_two_pow128_constant() { diff --git a/verkle-trie/src/database/meta.rs b/verkle-trie/src/database/meta.rs index 20a4cd5..a5dfdf6 100644 --- a/verkle-trie/src/database/meta.rs +++ b/verkle-trie/src/database/meta.rs @@ -136,7 +136,7 @@ impl std::fmt::Debug for BranchMeta { } impl BranchMeta { pub fn zero() -> BranchMeta { - use ark_ff::Zero; + use banderwagon::VerkleField; BranchMeta { commitment: Element::zero(), hash_commitment: Fr::zero(), diff --git a/verkle-trie/src/proof.rs b/verkle-trie/src/proof.rs index b708cbb..882dba2 100644 --- a/verkle-trie/src/proof.rs +++ b/verkle-trie/src/proof.rs @@ -2,7 +2,6 @@ use crate::{ constants::{CRS, PRECOMPUTED_WEIGHTS}, errors::HintError, }; -use ark_serialize::{CanonicalDeserialize, CanonicalSerialize}; use banderwagon::Element; use ipa_multipoint::multiproof::MultiPointProof; diff --git a/verkle-trie/src/proof/opening_data.rs b/verkle-trie/src/proof/opening_data.rs index c897ca7..8230bb5 100644 --- a/verkle-trie/src/proof/opening_data.rs +++ b/verkle-trie/src/proof/opening_data.rs @@ -5,8 +5,8 @@ use crate::{ database::{Meta, ReadOnlyHigherDb}, proof::key_path_finder::{KeyNotFound, KeyPathFinder, KeyState}, }; -use ark_ff::{One, PrimeField, Zero}; -use banderwagon::Fr; + +use banderwagon::{Fr, VerkleField}; use ipa_multipoint::{lagrange_basis::LagrangeBasis, multiproof::ProverQuery}; use std::{ collections::{BTreeMap, BTreeSet}, diff --git a/verkle-trie/src/proof/stateless_updater.rs b/verkle-trie/src/proof/stateless_updater.rs index 0753182..5c93bc8 100644 --- a/verkle-trie/src/proof/stateless_updater.rs +++ b/verkle-trie/src/proof/stateless_updater.rs @@ -1,7 +1,6 @@ use crate::constants::TWO_POW_128; use crate::{committer::Committer, errors::VerificationError, group_to_field, proof::ExtPresent}; -use ark_ff::{One, PrimeField, Zero}; -use banderwagon::{Element, Fr}; +use banderwagon::{Element, Fr, VerkleField}; use std::collections::{BTreeMap, HashSet}; use super::{UpdateHint, VerkleProof}; diff --git a/verkle-trie/src/proof/verifier.rs b/verkle-trie/src/proof/verifier.rs index 1a5dfc5..d065149 100644 --- a/verkle-trie/src/proof/verifier.rs +++ b/verkle-trie/src/proof/verifier.rs @@ -4,8 +4,7 @@ use crate::{ group_to_field, proof::{ExtPresent, UpdateHint}, }; -use ark_ff::{One, PrimeField, Zero}; -use banderwagon::{Element, Fr}; +use banderwagon::{Element, Fr, VerkleField}; use ipa_multipoint::multiproof::VerifierQuery; use std::{ collections::{BTreeMap, BTreeSet}, diff --git a/verkle-trie/src/trie.rs b/verkle-trie/src/trie.rs index 7efb72d..0d5ecff 100644 --- a/verkle-trie/src/trie.rs +++ b/verkle-trie/src/trie.rs @@ -3,9 +3,8 @@ use crate::constants::{CRS, TWO_POW_128}; use crate::database::{BranchMeta, Flush, Meta, ReadWriteHigherDb, StemMeta}; use crate::{committer::Committer, Config}; use crate::{group_to_field, TrieTrait}; -use ark_ff::{PrimeField, Zero}; -use banderwagon::{Element, Fr}; +use banderwagon::{Element, Fr, VerkleField}; #[derive(Debug, Clone)] // The trie implements the logic to insert values, fetch values, and create paths to said values @@ -763,8 +762,8 @@ fn paths_from_relative(parent_path: Vec, relative_paths: Vec) -> Vec