From bc63b44b07f57038c041c6ba8a41978346c700d2 Mon Sep 17 00:00:00 2001 From: plebhash Date: Wed, 29 Jan 2025 13:28:37 -0300 Subject: [PATCH] add tproxy_refuses_bad_extranonce_size integration test --- .../tests/translator_integration.rs | 35 ++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/roles/tests-integration/tests/translator_integration.rs b/roles/tests-integration/tests/translator_integration.rs index 6aabfb4ca..dcafa6283 100644 --- a/roles/tests-integration/tests/translator_integration.rs +++ b/roles/tests-integration/tests/translator_integration.rs @@ -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 @@ -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()); +} \ No newline at end of file