diff --git a/banderwagon/src/lib.rs b/banderwagon/src/lib.rs index 55820c5..6111885 100644 --- a/banderwagon/src/lib.rs +++ b/banderwagon/src/lib.rs @@ -5,37 +5,18 @@ use ark_ed_on_bls12_381_bandersnatch::Fq; use ark_ff::BigInteger256; pub use element::{multi_scalar_mul, Element, Fr}; -pub trait VerkleField { - fn zero() -> Self; - fn is_zero(&self) -> bool; - - fn one() -> Self; - - fn from_be_bytes_mod_order(bytes: &[u8]) -> Self; - fn from_le_bytes_mod_order(bytes: &[u8]) -> Self; -} - -// TODO: This avoids leaking arkworks in verkle_trie, but it's not ideal -// TODO: Another method would be to create a new type that wraps Fr -impl VerkleField for Fr { - fn zero() -> Self { - ark_ff::Zero::zero() - } - fn is_zero(&self) -> bool { - ark_ff::Zero::is_zero(self) - } - - fn one() -> Self { - ark_ff::One::one() - } - - fn from_be_bytes_mod_order(bytes: &[u8]) -> Self { - ark_ff::PrimeField::from_be_bytes_mod_order(bytes) - } - - fn from_le_bytes_mod_order(bytes: &[u8]) -> Self { - ark_ff::PrimeField::from_le_bytes_mod_order(bytes) - } +// Re-export arkworks traits that one may need to use in order to use +// specific methods on field elements and for serialization. +// +// For example, if we expose Fr directly, then for consumers to call methods like Fr::one() +// they will need to import ark_ff::One, which means they will need to import +// ark_ff as a dependency. +// +// This reexport allows us to avoid that. +pub use trait_defs::*; +pub mod trait_defs { + pub use ark_ff::{One, PrimeField, Zero}; + pub use ark_serialize::{CanonicalDeserialize, CanonicalSerialize, SerializationError}; } pub const fn fr_from_u64_limbs(limbs: [u64; 4]) -> Fr { @@ -47,9 +28,6 @@ pub const fn fr_from_u64_limbs(limbs: [u64; 4]) -> Fr { // // This is useful in try-and-increment algorithms. pub fn try_reduce_to_element(bytes: &[u8]) -> Option { - use ark_ff::PrimeField; - use ark_serialize::CanonicalSerialize; - // The Element::from_bytes method does not reduce the bytes, it expects the // input to be in a canonical format, so we must do the reduction ourselves let x_coord = Fq::from_be_bytes_mod_order(bytes);