Skip to content

Commit b1c9435

Browse files
committed
Address v0.3.0 pentest findings
1 parent 5ebf560 commit b1c9435

6 files changed

Lines changed: 208 additions & 98 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ All notable changes to `cardano` will be documented here.
1010
- Re-exported the primitive domains through the `cardano` facade crate.
1111
- Pinned official Cardano source revisions for the first protocol-domain
1212
milestone and recorded the primitive evidence in the spec matrix.
13+
- Hardened spec-lock validation so pinned official source revisions must be
14+
fetchable from their declared upstream repositories.
15+
- Changed `AssetName` equality, hashing, and ordering to use significant bytes
16+
only, preventing future unused-tail padding from affecting semantic identity.
1317
- Added the explicit `scripts/release_0_3_gate.sh` milestone gate.
1418

1519
## 0.2.0 - 2026-07-02

‎crates/cardano-valkyoth-primitives/src/lib.rs‎

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@
55
#[cfg(feature = "std")]
66
extern crate std;
77

8-
use core::fmt;
8+
use core::{
9+
cmp::Ordering,
10+
fmt,
11+
hash::{Hash, Hasher},
12+
};
913

1014
/// Network id for transaction-body network discriminants.
1115
///
@@ -286,7 +290,7 @@ impl Credential {
286290
}
287291

288292
/// Native asset name bytes.
289-
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
293+
#[derive(Clone, Copy, Debug)]
290294
pub struct AssetName {
291295
bytes: [u8; Self::MAX_LEN],
292296
len: u8,
@@ -373,6 +377,32 @@ impl TryFrom<&[u8]> for AssetName {
373377
}
374378
}
375379

380+
impl PartialEq for AssetName {
381+
fn eq(&self, other: &Self) -> bool {
382+
self.as_bytes() == other.as_bytes()
383+
}
384+
}
385+
386+
impl Eq for AssetName {}
387+
388+
impl Hash for AssetName {
389+
fn hash<H: Hasher>(&self, state: &mut H) {
390+
self.as_bytes().hash(state);
391+
}
392+
}
393+
394+
impl PartialOrd for AssetName {
395+
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
396+
Some(self.cmp(other))
397+
}
398+
}
399+
400+
impl Ord for AssetName {
401+
fn cmp(&self, other: &Self) -> Ordering {
402+
self.as_bytes().cmp(other.as_bytes())
403+
}
404+
}
405+
376406
/// Primitive constructor failures.
377407
#[non_exhaustive]
378408
#[derive(Clone, Copy, Debug, Eq, PartialEq)]

‎crates/cardano-valkyoth-primitives/src/tests.rs‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use super::{
22
AssetName, BlockHash, BlockNumber, Coin, Credential, DatumHash, Epoch, Era, KeyHash, NetworkId,
33
PolicyId, PrimitiveError, ScriptHash, Slot, TransactionId,
44
};
5+
use core::hash::{Hash, Hasher};
56

67
#[test]
78
fn network_id_round_trips() {
@@ -122,3 +123,29 @@ fn asset_name_rejects_more_than_thirty_two_bytes() {
122123
})
123124
);
124125
}
126+
127+
#[test]
128+
fn asset_name_identity_uses_significant_bytes_only() {
129+
let clean_result = AssetName::try_from_slice(&[9]);
130+
assert!(clean_result.is_ok());
131+
let Ok(clean) = clean_result else {
132+
return;
133+
};
134+
let mut padded = [0u8; AssetName::MAX_LEN];
135+
padded[0] = 9;
136+
padded[1] = 99;
137+
let dirty_tail = AssetName {
138+
bytes: padded,
139+
len: 1,
140+
};
141+
142+
assert_eq!(clean, dirty_tail);
143+
assert_eq!(clean.cmp(&dirty_tail), core::cmp::Ordering::Equal);
144+
assert_eq!(stable_hash(clean), stable_hash(dirty_tail));
145+
}
146+
147+
fn stable_hash(value: AssetName) -> u64 {
148+
let mut hasher = std::collections::hash_map::DefaultHasher::new();
149+
value.hash(&mut hasher);
150+
hasher.finish()
151+
}

‎release-notes/RELEASE_NOTES_0.3.0.md‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ Status: implementation stop reached; waiting for pentest.
1313
- Add the explicit `scripts/release_0_3_gate.sh` milestone gate.
1414
- Pin official Cardano source revisions for the first protocol-domain
1515
milestone.
16+
- Harden spec-lock validation so pinned official source revisions must be
17+
fetchable from their declared upstream repositories.
1618

1719
## Security
1820

@@ -23,7 +25,12 @@ Status: implementation stop reached; waiting for pentest.
2325
hashes. No secret-bearing primitive or constant-time equality policy is
2426
admitted in this release.
2527
- Asset names are bounded to 0..32 bytes before storage.
28+
- Asset-name equality, hashing, and ordering use significant bytes only, so
29+
unused padding cannot affect semantic identity.
2630
- Fixed hash/id domains reject slices with the wrong byte length.
31+
- The v0.3.0 scratch pentest found a medium spec-lock integrity gap and a low
32+
`AssetName` padding-invariant hazard; both are remediated before tag
33+
readiness.
2734

2835
## Spec Evidence
2936

@@ -40,6 +47,9 @@ for `hash32`, `hash28`, `transaction_id`, `script_hash`, `policy_id`,
4047
`asset_name`, `credential`, `network_id`, `slot_no`, `epoch_no`, `block_no`,
4148
and `coin`.
4249

50+
The release gate validates that each pinned source revision can be fetched from
51+
the official repository named in `spec-lock.toml`.
52+
4353
## Publishing
4454

4555
`cardano-valkyoth-primitives` is published at `0.2.0`. The `cardano` facade is

0 commit comments

Comments
 (0)