From c1e5ecd8015dd9a64ecc6bd5ddc1db21e65177de Mon Sep 17 00:00:00 2001 From: SW van Heerden Date: Thu, 18 Aug 2022 12:44:38 +0200 Subject: [PATCH] fmt --- Cargo.lock | 2 +- .../tari_merge_mining_proxy/src/proxy.rs | 15 ++--- base_layer/core/Cargo.toml | 2 +- .../proof_of_work/monero_rx/fixed_array.rs | 3 +- .../src/proof_of_work/monero_rx/helpers.rs | 8 ++- .../proof_of_work/monero_rx/merkle_tree.rs | 2 +- .../src/proof_of_work/monero_rx/pow_data.rs | 59 ++++--------------- base_layer/core/tests/block_validation.rs | 8 ++- 8 files changed, 35 insertions(+), 64 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index afb94a6f8f..3469af0317 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2663,7 +2663,7 @@ dependencies = [ [[package]] name = "monero" version = "0.17.2" -source = "git+https://github.com/Boog900/monero-rs.git#1bd8bc8cedc95fd941d55ca55b59acaf89ab7f0c" +source = "git+https://github.com/tari-project/monero-rs.git#7aebfd0aa037025cac6cbded3f72d73bf3c18123" dependencies = [ "base58-monero 1.0.0", "curve25519-dalek", diff --git a/applications/tari_merge_mining_proxy/src/proxy.rs b/applications/tari_merge_mining_proxy/src/proxy.rs index 7e415d4e7e..be0bd2427d 100644 --- a/applications/tari_merge_mining_proxy/src/proxy.rs +++ b/applications/tari_merge_mining_proxy/src/proxy.rs @@ -41,15 +41,12 @@ use jsonrpc::error::StandardError; use reqwest::{ResponseBuilderExt, Url}; use serde_json as json; use tari_app_grpc::tari_rpc as grpc; -use tari_core::proof_of_work::{ - monero_difficulty, - monero_rx, - monero_rx::FixedByteArray, - randomx_factory::RandomXFactory, +use tari_core::{ + consensus::ConsensusEncoding, + proof_of_work::{monero_difficulty, monero_rx, monero_rx::FixedByteArray, randomx_factory::RandomXFactory}, }; use tari_utilities::hex::Hex; use tracing::{debug, error, info, instrument, trace, warn}; -use tari_core::consensus::ConsensusEncoding; use crate::{ block_template_data::BlockTemplateRepository, @@ -271,7 +268,11 @@ impl InnerService { let header_mut = block_data.tari_block.header.as_mut().unwrap(); let height = header_mut.height; monero_data.consensus_encode(&mut header_mut.pow.as_mut().unwrap().pow_data)?; - + debug!( + target: LOG_TARGET, + "MONEROPOWDATA: {}", + header_mut.pow.clone().unwrap().pow_data.to_hex() + ); let tari_header = header_mut.clone().try_into().map_err(MmProxyError::ConversionError)?; let mut base_node_client = self.base_node_client.clone(); let start = Instant::now(); diff --git a/base_layer/core/Cargo.toml b/base_layer/core/Cargo.toml index 54030c2bbb..a35f118211 100644 --- a/base_layer/core/Cargo.toml +++ b/base_layer/core/Cargo.toml @@ -54,7 +54,7 @@ integer-encoding = "3.0.2" lmdb-zero = "0.4.4" log = "0.4" log-mdc = "0.1.0" -monero = { git = "https://github.com/Boog900/monero-rs.git", features = ["serde"], optional = true } +monero = { git = "https://github.com/tari-project/monero-rs.git", features = ["serde"], optional = true } newtype-ops = "0.1.4" num-traits = "0.2.15" num-derive = "0.3.3" diff --git a/base_layer/core/src/proof_of_work/monero_rx/fixed_array.rs b/base_layer/core/src/proof_of_work/monero_rx/fixed_array.rs index a1e613f7fd..c27495bffe 100644 --- a/base_layer/core/src/proof_of_work/monero_rx/fixed_array.rs +++ b/base_layer/core/src/proof_of_work/monero_rx/fixed_array.rs @@ -60,7 +60,6 @@ impl FixedByteArray { self.len += 1; } - #[inline] pub fn is_full(&self) -> bool { self.len() == MAX_ARR_SIZE @@ -122,7 +121,7 @@ impl ConsensusDecoding for FixedByteArray { return Err(io::Error::new( io::ErrorKind::InvalidInput, format!("length exceeded maximum of 64-bytes for FixedByteArray: {}", len), - )) + )); } let mut ret = FixedByteArray::new(); for _ in 0..len { diff --git a/base_layer/core/src/proof_of_work/monero_rx/helpers.rs b/base_layer/core/src/proof_of_work/monero_rx/helpers.rs index 6fb6ce22ad..5b7449a211 100644 --- a/base_layer/core/src/proof_of_work/monero_rx/helpers.rs +++ b/base_layer/core/src/proof_of_work/monero_rx/helpers.rs @@ -197,10 +197,12 @@ mod test { hex::{from_hex, Hex}, ByteArray, }; - use crate::consensus::ConsensusEncoding; use super::*; - use crate::proof_of_work::{monero_rx::fixed_array::FixedByteArray, PowAlgorithm, ProofOfWork}; + use crate::{ + consensus::ConsensusEncoding, + proof_of_work::{monero_rx::fixed_array::FixedByteArray, PowAlgorithm, ProofOfWork}, + }; // This tests checks the hash of monero-rs #[test] @@ -321,7 +323,7 @@ mod test { coinbase_tx: block.miner_tx, }; let mut serialized = Vec::new(); - monero_data.consensus_encode(&mut serialized).unwrap(); + monero_data.consensus_encode(&mut serialized).unwrap(); let pow = ProofOfWork { pow_algo: PowAlgorithm::Monero, pow_data: serialized, diff --git a/base_layer/core/src/proof_of_work/monero_rx/merkle_tree.rs b/base_layer/core/src/proof_of_work/monero_rx/merkle_tree.rs index 61d75bd709..45787be3bd 100644 --- a/base_layer/core/src/proof_of_work/monero_rx/merkle_tree.rs +++ b/base_layer/core/src/proof_of_work/monero_rx/merkle_tree.rs @@ -196,7 +196,7 @@ impl ConsensusDecoding for MerkleProof { impl ConsensusEncoding for MerkleProof { fn consensus_encode(&self, writer: &mut W) -> Result<(), io::Error> { let _ = self.branch.consensus_encode(writer)?; - ConsensusEncoding::consensus_encode(&self.depth,writer)?; + ConsensusEncoding::consensus_encode(&self.depth, writer)?; ConsensusEncoding::consensus_encode(&self.path_bitmap, writer)?; Ok(()) } diff --git a/base_layer/core/src/proof_of_work/monero_rx/pow_data.rs b/base_layer/core/src/proof_of_work/monero_rx/pow_data.rs index 3ccb985bd0..55431f0522 100644 --- a/base_layer/core/src/proof_of_work/monero_rx/pow_data.rs +++ b/base_layer/core/src/proof_of_work/monero_rx/pow_data.rs @@ -32,10 +32,13 @@ use monero::{ cryptonote::hash::Hashable, }; use tari_utilities::hex::{to_hex, Hex}; -use crate::consensus::{ConsensusDecoding,ConsensusEncoding}; -use super::{ error::MergeMineError, fixed_array::FixedByteArray, merkle_tree::MerkleProof}; -use crate::{blocks::BlockHeader, proof_of_work::monero_rx::helpers::create_block_hashing_blob}; +use super::{error::MergeMineError, fixed_array::FixedByteArray, merkle_tree::MerkleProof}; +use crate::{ + blocks::BlockHeader, + consensus::{ConsensusDecoding, ConsensusEncoding}, + proof_of_work::monero_rx::helpers::create_block_hashing_blob, +}; /// This is a struct to deserialize the data from he pow field into data required for the randomX Monero merged mine /// pow. @@ -134,56 +137,18 @@ mod test { use super::*; - const POW_DATA_BLOB: &str = "0e0eff8a828606e62827cbb1c8f13eeddaae1d2c5dbb36c12a3d30d20d20b35a540bdba9d8e162604a0000202378cf4e85ef9a0629719e228c8c9807575469c3f45b3710c7960079a5dfdd661600b3cdc310a8f619ea2feadb178021ea0b853caa2f41749f7f039dcd4102d24f0504b4d72f22ca81245c538371a07331546cbd9935068637166d9cd627c521fb0e98d6161a7d971ee608b2b93719327d1cf5f95f9cc15beab7c6fb0894205c9218e4f9810873976eaf62d53ce631e8ad37bbaacc5da0267cd38342d66bdecce6541bb5c761b8ff66e7f6369cd3b0c2cb106a325c7342603516c77c9dcbb67388128a04000000000002fd873401ffc1873401c983eae58cd001026eb5be712030e2d49c9329f7f578325daa8ad7296a58985131544d8fe8a24c934d01ad27b94726423084ffc0f7eda31a8c9691836839c587664a036c3986b33f568f020861f4f1c2c37735680300916c27a920e462fbbfce5ac661ea9ef91fc78d620c61c43d5bb6a9644e3c17e000"; + const POW_DATA_BLOB: &str = "1010989af89706d7fc36490967c52552f5f970b3e71857145426d55f19a0f291aad87fe3949ca7ab2b03002098a7ff37940ab2a8199192b6468d7704b1a46b37aa533298c8b020c2945f36485088afcd6c40c6d6b5fba15ffc256d7bdfdc7879e98287803d9602752df500e35b066d1cf333fcce964b72063915f082d730c708859a0e9288241bfdd9c3c6b471a432a8434282ada7df2675826e086c85b0085bef38b88f2984790553d4925e74f445cc42a810ed9ae296f7e105e5da77e8c58c51fe3e6f1b122c94ae2e27ecffff8511d9dc3554b49d41c9acdaccab04452126e4e2d897d09d49a794e192cd51b76b52628bed70ddb8a3f755035e4e6f23eda8e01e5af885f07c5e5ec742307c88f4446cf32225f52bf019ef198fa2f3957937b6ba96366c731ee47212be92ac5e06000292a9a40101ffd6a8a40101b9f998fcd81103502bb7087b807c5f4fec15891983ac05d05412e5900ca47e6bdf31d7e2c55082574d01ffb9bb5f384f2725a21e36b44fb100791f7259066d7982d616950981e9ce77010208e74c7cee8930e6800300020c4db762c76a89966cebe345f55f725a59c6cbba8630cc0b6bae388718dd1f00"; #[test] fn consensus_serialization() { let bytes = from_hex(POW_DATA_BLOB).unwrap(); - let data = MoneroPowData::consensus_decode(&mut bytes.as_slice()).expect("If this fails then consensus has changed"); - assert_eq!(data.transaction_count, 22); - assert_eq!(data.coinbase_merkle_proof.branch().len(), 4); - assert_eq!(bytes.len(), 374); + let data = + MoneroPowData::consensus_decode(&mut bytes.as_slice()).expect("If this fails then consensus has changed"); + assert_eq!(data.transaction_count, 80); + assert_eq!(data.coinbase_merkle_proof.branch().len(), 6); + assert_eq!(bytes.len(), 435); let mut ser = Vec::new(); data.consensus_encode(&mut ser).unwrap(); assert_eq!(ser, bytes); } - - #[test] - fn consensus_deserialize_reject_extra_bytes() { - let mut bytes = from_hex(POW_DATA_BLOB).unwrap(); - bytes.extend(&[0u8; 10]); - - let _err = MoneroPowData::consensus_decode(&mut bytes.as_slice()).unwrap_err(); - - let mut bytes = from_hex(POW_DATA_BLOB).unwrap(); - bytes.push(1); - let _err = MoneroPowData::consensus_decode(&mut bytes.as_slice()).unwrap_err(); - } - - mod fuzz { - use monero::TxIn; - use monero::consensus::encode::deserialize; - - #[test] - #[should_panic(expected = "capacity overflow")] - fn simple_capacity_overflow_panic() { - let data = &[0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f]; - let _result = deserialize::>(data); - } - - #[test] - #[should_panic(expected = "capacity overflow")] - fn panic_alloc_capacity_overflow_moneroblock_deserialize() { - let data = [ - 0x0f, 0x9e, 0xa5, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, - 0x00, 0x08, 0x9e, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x04, 0x9e, 0x9e, 0x9e, 0x9e, 0x9e, 0x9e, 0x9e, 0x9e, - 0x9e, 0xe7, 0xaa, 0xfd, 0x8b, 0x47, 0x06, 0x8d, 0xed, 0xe3, 0x00, 0xed, 0x44, 0xfc, 0x77, 0xd6, 0x58, - 0xf6, 0xf2, 0x69, 0x06, 0x8d, 0xed, 0xe3, 0x00, 0xed, 0x44, 0xfc, 0x77, 0xd6, 0x58, 0xf6, 0xf2, 0x69, - 0x62, 0x38, 0xdb, 0x5e, 0x4d, 0x6d, 0x9c, 0x94, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, - 0x8f, 0x74, 0x3c, 0xb3, 0x1b, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - ]; - let _result = deserialize::(&data); - } - } } diff --git a/base_layer/core/tests/block_validation.rs b/base_layer/core/tests/block_validation.rs index abb7298477..c2ea9271f9 100644 --- a/base_layer/core/tests/block_validation.rs +++ b/base_layer/core/tests/block_validation.rs @@ -28,7 +28,12 @@ use tari_common::configuration::Network; use tari_core::{ blocks::{Block, BlockHeaderAccumulatedData, BlockHeaderValidationError, BlockValidationError, ChainBlock}, chain_storage::{BlockchainDatabase, BlockchainDatabaseConfig, ChainStorageError, Validators}, - consensus::{consensus_constants::PowAlgorithmConstants, ConsensusConstantsBuilder, ConsensusManager}, + consensus::{ + consensus_constants::PowAlgorithmConstants, + ConsensusConstantsBuilder, + ConsensusEncoding, + ConsensusManager, + }, proof_of_work::{ monero_rx, monero_rx::{FixedByteArray, MoneroPowData}, @@ -59,7 +64,6 @@ use tari_core::{ use tari_script::{inputs, script}; use tari_test_utils::unpack_enum; use tari_utilities::{hex::Hex, Hashable}; -use tari_core::consensus::ConsensusEncoding; use crate::helpers::{ block_builders::{