Skip to content

Commit 3b5c135

Browse files
committed
fixed size ref
1 parent 1c8ee77 commit 3b5c135

File tree

6 files changed

+21
-4
lines changed

6 files changed

+21
-4
lines changed

hotshot-types/src/data.rs

+9
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,15 @@ impl AsRef<[u8]> for VidCommitment {
298298
}
299299
}
300300

301+
impl AsRef<[u8; 32]> for VidCommitment {
302+
fn as_ref(&self) -> &[u8; 32] {
303+
match self {
304+
Self::V0(comm) => comm.as_ref().as_ref(),
305+
Self::V1(comm) => comm.as_ref(),
306+
}
307+
}
308+
}
309+
301310
impl VidCommitment {
302311
/// Unwrap an ADVZCommitment. Panic if incorrect version.
303312
pub fn unwrap_v0(self) -> ADVZCommitment {

types/src/reference_tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ async fn reference_header(version: Version) -> Header {
158158

159159
const REFERENCE_V1_HEADER_COMMITMENT: &str = "BLOCK~dh1KpdvvxSvnnPpOi2yI3DOg8h6ltr2Kv13iRzbQvtN2";
160160
const REFERENCE_V2_HEADER_COMMITMENT: &str = "BLOCK~V0GJjL19nCrlm9n1zZ6gaOKEekSMCT6uR5P-h7Gi6UJR";
161-
const REFERENCE_V99_HEADER_COMMITMENT: &str = "BLOCK~q_3j4RuQMmxNx0JQbeapzFon4oyYO1F8vZdbLftwCBYP";
161+
const REFERENCE_V99_HEADER_COMMITMENT: &str = "BLOCK~0yvjXWEW6T3sZiM3-bT-k7X_PuZo_lCDeBmdeYjoEMvo";
162162

163163
fn reference_transaction<R>(ns_id: NamespaceId, rng: &mut R) -> Transaction
164164
where

types/src/v0/impls/header.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ impl v0_1::Header {
5858
.u64_field("l1_head", self.l1_head)
5959
.optional("l1_finalized", &self.l1_finalized)
6060
.constant_str("payload_commitment")
61-
.var_size_bytes(self.payload_commitment.as_ref())
61+
.fixed_size_bytes(self.payload_commitment.as_ref())
6262
.constant_str("builder_commitment")
6363
.fixed_size_bytes(self.builder_commitment.as_ref())
6464
.field("ns_table", self.ns_table.commit())

types/src/v0/v0_1/header.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ impl Committable for Header {
5454
.u64_field("l1_head", self.l1_head)
5555
.optional("l1_finalized", &self.l1_finalized)
5656
.constant_str("payload_commitment")
57-
.var_size_bytes(self.payload_commitment.as_ref())
57+
.fixed_size_bytes(self.payload_commitment.as_ref())
5858
.constant_str("builder_commitment")
5959
.fixed_size_bytes(self.builder_commitment.as_ref())
6060
.field("ns_table", self.ns_table.commit())

types/src/v0/v0_99/header.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ impl Committable for Header {
4545
.u64_field("l1_head", self.l1_head)
4646
.optional("l1_finalized", &self.l1_finalized)
4747
.constant_str("payload_commitment")
48-
.var_size_bytes(self.payload_commitment.as_ref())
48+
.fixed_size_bytes(self.payload_commitment.as_ref())
4949
.constant_str("builder_commitment")
5050
.fixed_size_bytes(self.builder_commitment.as_ref())
5151
.field("ns_table", self.ns_table.commit())

vid/src/avid_m.rs

+8
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,14 @@ impl AsRef<[u8]> for AvidMCommit {
7777
}
7878
}
7979

80+
impl AsRef<[u8; 32]> for AvidMCommit {
81+
fn as_ref(&self) -> &[u8; 32] {
82+
unsafe { ::core::slice::from_raw_parts((self as *const Self) as *const u8, 32) }
83+
.try_into()
84+
.unwrap()
85+
}
86+
}
87+
8088
/// Share type to be distributed among the parties.
8189
#[derive(Clone, Debug, Hash, Serialize, Deserialize, Eq, PartialEq)]
8290
pub struct RawAvidMShare {

0 commit comments

Comments
 (0)