diff --git a/bus-mapping/src/evm.rs b/bus-mapping/src/evm.rs index a2d5e0ff41..6caeb9beac 100644 --- a/bus-mapping/src/evm.rs +++ b/bus-mapping/src/evm.rs @@ -65,6 +65,15 @@ impl MemoryAddress { pub fn zero() -> MemoryAddress { MEM_ADDR_ZERO.clone() } + + /// Return the little-endian byte representation of the word as a 32-byte + /// array. + pub fn to_bytes(&self) -> [u8; 32] { + let mut array = [0u8; 32]; + array.copy_from_slice(&self.0.to_bytes_le()); + + array + } } impl From for BigUint { @@ -152,4 +161,20 @@ macro_rules! impl_from_basic_types { }; } -impl_from_basic_types!(u8, u16, u32, u64, u128); +impl_from_basic_types!(u8, u16, u32, u64, u128, usize); + +impl EvmWord { + /// Return the little-endian byte representation of the word as a 32-byte + /// array. + pub fn to_bytes(&self) -> [u8; 32] { + let mut array = [0u8; 32]; + array.copy_from_slice(&self.0.to_bytes_le()); + + array + } + + /// Returns the underlying representation of the `EvmWord` as a [`BigUint`]. + pub fn as_big_uint(&self) -> &BigUint { + &self.0 + } +}