Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Changelog

## [0.8.0]

### Fixed
- `CodeHash::encode` no longer lowercases its Base58 output. The
BITCOIN alphabet is case-sensitive, so lowercasing corrupted the
bytes for any hash whose encoding contained uppercase characters and
broke the `encode` → `ContractKey::from_params` roundtrip (which
decodes with the same case-sensitive alphabet). `CodeHash::encode`
now matches `ContractInstanceId::encode`,
`ContractKey::encoded_code_hash`, and `ContractCode::hash_str`, all
of which already preserved case. See freenet/freenet-core#4214.

## [0.7.0]

### Fixed (wire-format break in `NodeDiagnosticsResponse`)
Expand Down
26 changes: 25 additions & 1 deletion rust/src/code_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ impl CodeHash {
bs58::encode(self.0)
.with_alphabet(bs58::Alphabet::BITCOIN)
.into_string()
.to_lowercase()
}
}

Expand Down Expand Up @@ -80,3 +79,28 @@ impl std::fmt::Debug for CodeHash {
f.debug_tuple("CodeHash").field(&self.encode()).finish()
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn encode_roundtrips_with_case_sensitive_alphabet() {
// Bytes chosen so the base58 encoding contains uppercase characters,
// which a lowercasing `encode` would corrupt.
let original = CodeHash([0xFF; CONTRACT_KEY_SIZE]);
let encoded = original.encode();
assert!(
encoded.chars().any(|c| c.is_ascii_uppercase()),
"test fixture must contain uppercase base58 chars, got {encoded}"
);

let mut decoded = [0u8; CONTRACT_KEY_SIZE];
bs58::decode(&encoded)
.with_alphabet(bs58::Alphabet::BITCOIN)
.onto(&mut decoded)
.expect("encoded CodeHash must decode with the BITCOIN alphabet");

assert_eq!(original.0, decoded);
}
}
Loading