diff --git a/base_layer/core/Cargo.toml b/base_layer/core/Cargo.toml index 80b325dd63..6a71fe47d2 100644 --- a/base_layer/core/Cargo.toml +++ b/base_layer/core/Cargo.toml @@ -49,7 +49,7 @@ arrayref = "0.3.5" bincode = "1.1.4" log = "0.4" blake2 = "^0.8.0" -bigint = "^4.4.1" +uint = { version = "0.8", default-features = false } ttl_cache = "0.5.1" tokio = { version="^0.2", features = ["blocking", "time"] } futures = {version = "^0.3.1", features = ["async-await"] } diff --git a/base_layer/core/src/lib.rs b/base_layer/core/src/lib.rs index 00fa6dd421..dab8c94b3a 100644 --- a/base_layer/core/src/lib.rs +++ b/base_layer/core/src/lib.rs @@ -60,3 +60,8 @@ pub mod transactions; // Re-export the crypto crate to make exposing traits etc easier for clients of this crate pub use crypto::tari_utilities; pub use tari_crypto as crypto; + +uint::construct_uint! { + /// 256-bit unsigned integer. + pub(crate) struct U256(4); +} diff --git a/base_layer/core/src/proof_of_work/blake_pow.rs b/base_layer/core/src/proof_of_work/blake_pow.rs index bc987bfd08..b950a7350c 100644 --- a/base_layer/core/src/proof_of_work/blake_pow.rs +++ b/base_layer/core/src/proof_of_work/blake_pow.rs @@ -20,8 +20,7 @@ // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE // USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -use crate::{blocks::BlockHeader, proof_of_work::Difficulty}; -use bigint::uint::U256; +use crate::{blocks::BlockHeader, proof_of_work::Difficulty, U256}; use blake2::Blake2b; use digest::Digest; use tari_crypto::{common::Blake256, tari_utilities::Hashable}; @@ -43,7 +42,7 @@ pub fn blake_difficulty_with_hash(header: &BlockHeader) -> (Difficulty, Vec) let hash = Blake256::digest(&hash).to_vec(); let scalar = U256::from_big_endian(&hash); // Big endian so the hash has leading zeroes let result = MAX_TARGET / scalar; - let difficulty = u64::from(result).into(); + let difficulty = result.low_u64().into(); (difficulty, hash) } diff --git a/base_layer/core/src/proof_of_work/monero_rx.rs b/base_layer/core/src/proof_of_work/monero_rx.rs index c9ced9d777..6d4fe86585 100644 --- a/base_layer/core/src/proof_of_work/monero_rx.rs +++ b/base_layer/core/src/proof_of_work/monero_rx.rs @@ -23,8 +23,8 @@ use crate::{ blocks::BlockHeader, proof_of_work::{monero_rx::MergeMineError::HashingError, Difficulty}, + U256, }; -use bigint::uint::U256; use derive_error::Error; use monero::blockdata::{block::BlockHeader as MoneroBlockHeader, Transaction as MoneroTransaction}; #[cfg(feature = "monero_merge_mining")] @@ -94,7 +94,7 @@ fn monero_difficulty_calculation(header: &BlockHeader) -> Result