Repository navigation
STR0_255: restrict to printable ASCII - #252
Conversation
|
ACK d98bab7 Might be worth pointing out in the PR description that this doesn't impact the coinbase (scriptSig), which uses Maybe also mention that Theoretically this could break existing worker names (e.g. |
The type carried no character-set rule, so fields such as user_identity could hold any UTF-8, with the validation and log-rendering edge cases that invites (control characters, invisible code points) and no functionality that ASCII does not already give. Put the rule on the type so it covers every STR0_255 field at once, with a receiver-side rule mirroring the F32 row, and drop the per-field statements it subsumes: the printable-ASCII sentences for error codes and reason_code in 3.5, the reason_code back-reference in 5.3.9, and the "UTF-8 encoding SHOULD be used" on user_identity and user_identifier. closes stratum-mining#219
The worker name in extension 0x0002 travels as a raw TLV value, not as STR0_255, so the type-level byte rule does not reach it. It is the same worker name that motivated the restriction, carried on every SubmitSharesExtended. Point the value at the STR0_255 rule so it gets the same byte range and receiver behaviour, and relabel the examples that called the bytes UTF-8.
d98bab7 to
c3ebfde
Compare
bit-aloo
left a comment
There was a problem hiding this comment.
Once this is merged, we'll need to adapt the apps and core repos accordingly. We already have a method on Str0255 that converts the value to UTF-8 if possible, falling back to a hex string otherwise, we should hard error now
/// Returns the value as a UTF-8 string if possible, otherwise as a hex string prefixed with 0x.
pub fn as_utf8_or_hex(&self) -> String {
match core::str::from_utf8(self.as_bytes()) {
Ok(s) => alloc::string::String::from(s),
Err(_) => format!("0x{}", bytes_to_hex(self.as_bytes())),
}
}| | U64 | 8 | Unsigned integer, 64-bit, little-endian | | ||
| | U256 | 32 | Unsigned integer, 256-bit, little-endian. Often the raw byte output of SHA-256 interpreted as an unsigned integer. | | ||
| | STR0_255 | 1 + LENGTH | String with 8-bit length prefix L. Unsigned integer, followed by L bytes. Allowed range of length is 0 to 255. The string is not null-terminated. | | ||
| | STR0_255 | 1 + LENGTH | String with 8-bit length prefix L. Unsigned integer, followed by L bytes. Allowed range of length is 0 to 255. The string is not null-terminated. Every byte MUST be a printable ASCII character (0x20 to 0x7E). A receiver MUST treat any other byte as a protocol error. | |
There was a problem hiding this comment.
What does ‘protocol error’ mean here? We have something similar for f32. Is this left to implementers, or should we define it in the spec?
There was a problem hiding this comment.
yeah let's leave it here for consistency, and fix it everywhere via #256
closes #219
STR0_255carried no character-set rule, so fields such asuser_identitycould hold any UTF-8 (control characters, invisible code points, emoji with hidden payloads), which invites validation and log-rendering edge cases without giving any functionality that ASCII does not already give.This PR puts the rule on the type itself in 3.1, so it covers every
STR0_255field at once: every byte MUST be a printable ASCII character (0x20to0x7E), and a receiver MUST treat any other byte as a protocol error (same pattern as theF32row).With the rule on the type, the per-field statements it subsumes are dropped:
reason_code, plus the back-reference to it in 5.3.9user_identity(5.3.2) anduser_identifier(6.4.2): "UTF-8 encoding SHOULD be used."A second commit covers the
user_identityTLV value of extension 0x0002, which is a raw TLV value rather than aSTR0_255and so is not reached by the type rule: it now points at the same byte rule, and the examples that labelled the bytes UTF-8 (3.4 and the extension) say ASCII instead.Note that error codes and
reason_codepreviously had only a sender-side rule; they now get the receiver-side rejection as well.This is a breaking change for any implementation currently sending non-ASCII bytes in those fields. Spec versioning is tracked separately in #218.