Skip to content

Commit 73093a3

Browse files
committed
chore: resolve comments
1 parent a79b0be commit 73093a3

3 files changed

Lines changed: 36 additions & 6 deletions

File tree

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
pub use aleo::*;
2+
pub use base::*;
3+
pub use traits::*;
4+
15
mod aleo;
26
mod base;
37
mod traits;
@@ -6,7 +10,3 @@ mod traits;
610
mod mock;
711
#[cfg(test)]
812
mod tests;
9-
10-
pub use aleo::*;
11-
pub use base::*;
12-
pub use traits::*;

rust/main/chains/hyperlane-aleo/src/types.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@ use snarkvm::{
44
};
55
use snarkvm_console_account::Field;
66

7-
/// Default Network that we go to
8-
/// We need this as aleo annotates every type - even types that don't change with a different network
7+
// This actually works for all networks. I've raised this with the Aleo team, but the type annotation here doesn't actually change the underlying type.
8+
// The Aleo VM types all inherit a generic Network type, but that Type is not relevant for many structs of Aleo and is supposed to be more of an additional information for the internal VM processing.
9+
// They need this, because they generate ZK Proofs differently for different networks but the actual data of these types are the same across all Networks.
10+
// We pass CurrentNetwork into a lot of types, because we don't have to generate ZK Proofs in almost every situation - except when submitting a TX. There is one exception to this and that is when parsing/handling with Blocks.
11+
// The Block type verifies its validity on creation and that changes based on the Network type, thats why we have to pass the correct Type when dealing with blocks.
912
pub(crate) type CurrentNetwork = MainnetV0;
1013
/// TxID Type
1114
pub(crate) type TxID = AleoID<Field<TestnetV0>, { hrp2!("at") }>;

rust/main/chains/hyperlane-aleo/src/utils.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ pub(crate) fn get_tx_id(hash: impl Into<H256>) -> ChainResult<TxID> {
1111
/// Convert a TxID or any other struct that implements ToBytes to H256
1212
pub(crate) fn to_h256<T: ToBytes>(id: T) -> ChainResult<H256> {
1313
let bytes = id.to_bytes_le().map_err(HyperlaneAleoError::from)?;
14+
if bytes.len() != 32 {
15+
return Err(hyperlane_core::ChainCommunicationError::from_other_str(
16+
&format! {"Invalid length for H256 conversion: expected 32, got {}", bytes.len()},
17+
));
18+
}
1419
Ok(H256::from_slice(&bytes))
1520
}
1621

@@ -23,6 +28,17 @@ mod tests {
2328
use super::*;
2429
use crate::CurrentNetwork;
2530

31+
struct TestStruct {}
32+
33+
impl ToBytes for TestStruct {
34+
fn write_le<W: std::io::Write>(&self, writer: W) -> std::io::Result<()>
35+
where
36+
Self: Sized,
37+
{
38+
[0u8; 33].write_le(writer)
39+
}
40+
}
41+
2642
#[test]
2743
fn test_get_tx_id() {
2844
let hash = H256::zero();
@@ -45,4 +61,15 @@ mod tests {
4561
.unwrap();
4662
assert_eq!(h256.as_bytes(), expected_bytes.as_slice());
4763
}
64+
65+
#[test]
66+
fn test_to_h256_with_custom_struct() {
67+
let test_struct = TestStruct {};
68+
let h256 = super::to_h256(test_struct);
69+
assert!(h256.is_err());
70+
assert_eq!(
71+
h256.err().unwrap().to_string(),
72+
"Invalid length for H256 conversion: expected 32, got 33"
73+
);
74+
}
4875
}

0 commit comments

Comments
 (0)