Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
SWvheerden committed Aug 18, 2022
1 parent 80763fe commit c1e5ecd
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 64 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 8 additions & 7 deletions applications/tari_merge_mining_proxy/src/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion base_layer/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 1 addition & 2 deletions base_layer/core/src/proof_of_work/monero_rx/fixed_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ impl FixedByteArray {
self.len += 1;
}


#[inline]
pub fn is_full(&self) -> bool {
self.len() == MAX_ARR_SIZE
Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 5 additions & 3 deletions base_layer/core/src/proof_of_work/monero_rx/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion base_layer/core/src/proof_of_work/monero_rx/merkle_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ impl ConsensusDecoding for MerkleProof {
impl ConsensusEncoding for MerkleProof {
fn consensus_encode<W: Write>(&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(())
}
Expand Down
59 changes: 12 additions & 47 deletions base_layer/core/src/proof_of_work/monero_rx/pow_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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::<Vec<TxIn>>(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::<monero::Block>(&data);
}
}
}
8 changes: 6 additions & 2 deletions base_layer/core/tests/block_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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::{
Expand Down

0 comments on commit c1e5ecd

Please sign in to comment.