Skip to content

Commit

Permalink
add tproxy_refuses_bad_extranonce_size integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
plebhash committed Jan 29, 2025
1 parent 80c5851 commit bc63b44
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion roles/tests-integration/tests/translator_integration.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use const_sv2::{MESSAGE_TYPE_SETUP_CONNECTION, MESSAGE_TYPE_SUBMIT_SHARES_EXTENDED};
use const_sv2::{MESSAGE_TYPE_SETUP_CONNECTION, MESSAGE_TYPE_SUBMIT_SHARES_EXTENDED, MESSAGE_TYPE_OPEN_EXTENDED_MINING_CHANNEL_SUCCES};
use integration_tests_sv2::{sniffer::*, *};
use roles_logic_sv2::parsers::{CommonMessages, Mining, PoolMessages};
use roles_logic_sv2::mining_sv2::OpenExtendedMiningChannelSuccess;
use std::convert::TryInto;

// This test runs an sv2 translator between an sv1 mining device and a pool. the connection between
// the translator and the pool is intercepted by a sniffer. The test checks if the translator and
Expand Down Expand Up @@ -44,3 +46,34 @@ async fn translation_proxy() {
)
.await;
}

// when a tProxy receives a OpenExtendedMiningChannelSuccess with a bad extranonce_size
// we expect it to shut down gracefully
#[tokio::test]
async fn tproxy_refuses_bad_extranonce_size() {
let (_tp, tp_addr) = start_template_provider(None).await;
let (_pool, pool_addr) = start_pool(Some(tp_addr)).await;

let message_replacement = PoolMessages::Mining(Mining::OpenExtendedMiningChannelSuccess(OpenExtendedMiningChannelSuccess {
request_id: 0,
channel_id: 1,
target: [112, 123, 89, 188, 221, 164, 162, 167, 139, 39, 104, 137, 2, 111, 185, 17, 165, 85, 33, 115, 67, 45, 129, 197, 134, 103, 128, 151, 59, 19, 0, 0].into(),
extranonce_prefix: vec![0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1].try_into().unwrap(),
extranonce_size: 44 // bad extranonce size
}));
let intercept = InterceptMessage::new(
MessageDirection::ToDownstream,
MESSAGE_TYPE_OPEN_EXTENDED_MINING_CHANNEL_SUCCES,
message_replacement,
);

// this sniffer will replace OpenExtendedMiningChannelSuccess with a bad extranonce size
let (sniffer, sniffer_addr) =
start_sniffer("0".to_string(), pool_addr, false, Some(vec![intercept])).await;

let (_, tproxy_addr) = start_sv2_translator(sniffer_addr).await;

// make sure tProxy shut down (expected behavior)
// we only assert that the listening port is now available
assert!(tokio::net::TcpListener::bind(tproxy_addr).await.is_ok());
}

0 comments on commit bc63b44

Please sign in to comment.