Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(precompile): use Aurora modexp lib. (#769)
* Aurora modexp precompile wip * Clean input parsing and comments * cargo toml, rm num add modexp rev * bump aurora modexp to crate version * Update crates/precompile/src/utilities.rs * Update crates/precompile/src/utilities.rs
- Loading branch information
Showing
5 changed files
with
130 additions
and
101 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
use core::cmp::min; | ||
|
||
use alloc::vec::Vec; | ||
|
||
/// Get an array from the data, if data does not contain `start` to `len` bytes, add right padding with | ||
/// zeroes | ||
#[inline(always)] | ||
pub fn get_right_padded<const S: usize>(data: &[u8], offset: usize) -> [u8; S] { | ||
let mut padded = [0; S]; | ||
let start = min(offset, data.len()); | ||
let end = min(start.saturating_add(S), data.len()); | ||
padded[..end - start].copy_from_slice(&data[start..end]); | ||
padded | ||
} | ||
|
||
/// Get a vector of the data, if data does not contain the slice of `start` to `len`, right pad missing | ||
/// part with zeroes | ||
#[inline(always)] | ||
pub fn get_right_padded_vec(data: &[u8], offset: usize, len: usize) -> Vec<u8> { | ||
let mut padded = vec![0; len]; | ||
let start = min(offset, data.len()); | ||
let end = min(start.saturating_add(len), data.len()); | ||
padded[..end - start].copy_from_slice(&data[start..end]); | ||
padded | ||
} | ||
|
||
/// Left padding until `len`. If data is more then len, truncate the right most bytes. | ||
#[inline(always)] | ||
pub fn left_padding<const S: usize>(data: &[u8]) -> [u8; S] { | ||
let mut padded = [0; S]; | ||
let end = min(S, data.len()); | ||
padded[S - end..].copy_from_slice(&data[..end]); | ||
padded | ||
} | ||
|
||
/// Left padding until `len`. If data is more then len, truncate the right most bytes. | ||
#[inline(always)] | ||
pub fn left_padding_vec(data: &[u8], len: usize) -> Vec<u8> { | ||
let mut padded = vec![0; len]; | ||
let end = min(len, data.len()); | ||
padded[len - end..].copy_from_slice(&data[..end]); | ||
padded | ||
} |