Skip to content
Open
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
8 changes: 5 additions & 3 deletions utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,16 @@ pub async fn wait_for_rpc(

/// converting a keccak256-based structured commitment (32 bytes) into type `U256`
pub fn commitment_to_u256<T: Committable>(comm: Commitment<T>) -> U256 {
let mut buf = vec![];
comm.serialize_uncompressed(&mut buf).unwrap();
let mut buf = [0u8; 32];
let mut cursor = &mut buf[..];
comm.serialize_uncompressed(&mut cursor).unwrap();
U256::from_le_slice(&buf)
}

/// converting a `U256` value into a keccak256-based structured commitment (32 bytes)
pub fn u256_to_commitment<T: Committable>(comm: U256) -> Result<Commitment<T>, SerializationError> {
Commitment::deserialize_uncompressed_unchecked(&*comm.to_le_bytes_vec())
let bytes = comm.to_le_bytes_vec();
Commitment::deserialize_uncompressed_unchecked(&bytes)
}

/// Implement `to_fixed_bytes` for wrapped types
Expand Down