`NewTemplate::coinbase_prefix` field accepts more bytes then expected
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 78/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- rust
- Domain
- networking
Research direction
Start in sv2/subprotocols/template-distribution/src/new_template.rs and run the existing tests around NewTemplate serialization. Use the supplied oversized and maximum-length cases to verify the boundary behavior. Done means an 8-byte coinbase_prefix remains valid while a 9-byte value is rejected according to Template Distribution Protocol spec 7.2.
Written by the indexing model from the issue text.
Description
according to the spec 7.2:
the coinbase_prefix field in NewTemplate of the Template Distribution Protocol should have UP TO 8 bytes .
but the test below shows that we can successfully create a message with more bytes then it is suppose to have:
diff --git a/sv2/subprotocols/template-distribution/src/new_template.rs b/sv2/subprotocols/template-distribution/src/new_template.rs
index 8fd8b59c..343ca0a3 100644
--- a/sv2/subprotocols/template-distribution/src/new_template.rs
+++ b/sv2/subprotocols/template-distribution/src/new_template.rs
@@ -94,3 +94,75 @@ impl fmt::Display for NewTemplateOwned {
)
}
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+ use alloc::vec;
+ use binary_sv2::{from_bytes, GetSize, Serialize};
+
+ /// Spec 7.2: coinbase_prefix is B0255 but the spec limits it to "up to 8 bytes
+ /// (not including the length byte)". A 9-byte payload exceeds this limit.
+ ///
+ /// This test proves the parser accepts oversized coinbase_prefix without error.
+ #[test]
+ fn oversized_coinbase_prefix_roundtrips() {
+ let prefix_9_bytes = vec![0xAB_u8; 9];
+ let empty: Vec<U256<'_>> = vec![];
+ let merkle = Seq0255::new(empty).unwrap();
+
+ let msg = NewTemplate {
+ template_id: 0,
+ future_template: false,
+ version: 0,
+ coinbase_tx_version: 2,
+ coinbase_prefix: B0255::new(&prefix_9_bytes).unwrap(),
+ coinbase_tx_input_sequence: 0,
+ coinbase_tx_value_remaining: 0,
+ coinbase_tx_outputs_count: 0,
+ coinbase_tx_outputs: B064K::new(&[]).unwrap(),
+ coinbase_tx_locktime: 0,
+ merkle_path: merkle,
+ };
+
+ let mut encoded = vec![0u8; msg.get_size()];
+ msg.clone().to_bytes(&mut encoded).unwrap();
+
+ let decoded: NewTemplate = from_bytes(&mut encoded).unwrap();
+
+ assert_eq!(
+ decoded.coinbase_prefix.as_bytes(),
+ prefix_9_bytes.as_slice(),
+ "parser should roundtrip a 9-byte coinbase_prefix (spec violation passes through)"
+ );
+ }
+
+ /// Spec 7.2: 8-byte coinbase_prefix is the maximum allowed.
+ #[test]
+ fn max_valid_coinbase_prefix_roundtrips() {
+ let prefix_8_bytes = vec![0xCD_u8; 8];
+ let empty: Vec<U256<'_>> = vec![];
+ let merkle = Seq0255::new(empty).unwrap();
+
+ let msg = NewTemplate {
+ template_id: 0,
+ future_template: false,
+ version: 0,
+ coinbase_tx_version: 2,
+ coinbase_prefix: B0255::new(&prefix_8_bytes).unwrap(),
+ coinbase_tx_input_sequence: 0,
+ coinbase_tx_value_remaining: 0,
+ coinbase_tx_outputs_count: 0,
+ coinbase_tx_outputs: B064K::new(&[]).unwrap(),
+ coinbase_tx_locktime: 0,
+ merkle_path: merkle,
+ };
+
+ let mut encoded = vec![0u8; msg.get_size()];
+ msg.clone().to_bytes(&mut encoded).unwrap();
+
+ let decoded: NewTemplate = from_bytes(&mut encoded).unwrap();
+
+ assert_eq!(decoded.coinbase_prefix.as_bytes(), prefix_8_bytes.as_slice());
+ }
+}
- Dominant language
- Rust
- Stars
- 352
- Forks
- 200
- Avg merge
- 4d 17h
- Merged PRs (30d)
- 12
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from stratum-mining/stratum
-
MessageFrame::encode_into accepts a serializer that writes fewer bytes than the header declares Open
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
stratum-mining/stratum#2386 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 85/100
stratum-mining/stratum#2385 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
stratum-mining/stratum#2384 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
stratum-mining/stratum#2383 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
stratum-mining/stratum#2381 ·
All issues in stratum-mining/stratum
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Eynzof/Hermes-CN-Desktop#610 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
gitbutlerapp/gitbutler#15998 · 1 comment ·
-
bug triage:deciding
Difficulty 1/5 Under an hour Newbie friendliness 88/100
open-telemetry/otel-arrow#4132 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100