From 75c6db48ef9ec4c96c0dd268b125fe4f9881d421 Mon Sep 17 00:00:00 2001 From: Deepanshu Hooda Date: Fri, 11 Aug 2023 10:45:10 +0530 Subject: [PATCH] refactor --- precompiles/utils/src/bytes.rs | 9 ++------- precompiles/utils/src/data.rs | 8 ++------ 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/precompiles/utils/src/bytes.rs b/precompiles/utils/src/bytes.rs index cfeb020a99..ba86df9297 100644 --- a/precompiles/utils/src/bytes.rs +++ b/precompiles/utils/src/bytes.rs @@ -106,12 +106,7 @@ impl> EvmData for BoundedBytesString { return Err(revert("length, value too large").into()); } - // Get valid range over the bytes data. - let range = inner_reader.move_cursor(array_size)?; - - let data = inner_reader - .get_input_from_range(range) - .ok_or_else(|| revert(K::signature()))?; + let data = inner_reader.read_raw_bytes(array_size)?; let bytes = Self { data: data.to_owned(), @@ -140,7 +135,7 @@ impl> EvmData for BoundedBytesString { writer.write_pointer( EvmDataWriter::new() .write(U256::from(length)) - .write_raw_bytes(&value) + .write(value) .build(), ); } diff --git a/precompiles/utils/src/data.rs b/precompiles/utils/src/data.rs index e6bb0363c5..ef910ec537 100644 --- a/precompiles/utils/src/data.rs +++ b/precompiles/utils/src/data.rs @@ -187,15 +187,11 @@ impl<'a> EvmDataReader<'a> { Ok(data) } - /// Return Option<&[u8]> from a given range for EvmDataReader - pub fn get_input_from_range(&self, range: Range) -> Option<&[u8]> { - self.input.get(range) - } /// Move the reading cursor with provided length, and return a range from the previous cursor /// location to the new one. /// Checks cursor overflows. - pub fn move_cursor(&mut self, len: usize) -> EvmResult> { + fn move_cursor(&mut self, len: usize) -> EvmResult> { let start = self.cursor; let end = self .cursor @@ -290,7 +286,7 @@ impl EvmDataWriter { /// Write arbitrary bytes. /// Doesn't handle any alignement checks, prefer using `write` instead if possible. - pub fn write_raw_bytes(mut self, value: &[u8]) -> Self { + fn write_raw_bytes(mut self, value: &[u8]) -> Self { self.data.extend_from_slice(value); self }