Skip to content

Instantly share code, notes, and snippets.

@AmanRaj1608
Created November 12, 2021 23:10
Show Gist options
  • Save AmanRaj1608/54b99b0c71bbed4a94d612666c4cdf4c to your computer and use it in GitHub Desktop.
Save AmanRaj1608/54b99b0c71bbed4a94d612666c4cdf4c to your computer and use it in GitHub Desktop.
#![no_main]
use libfuzzer_sys::fuzz_target;
use ethereum_types::U256;
use myproject::convert_wei_to_satoshis;
fuzz_target!(|data: &[u8]| {
// fuzzed code goes here
if let Ok(s) = std::str::from_utf8(data) {
let ptoken = U256::from_dec_str(s).unwrap();
let _ = convert_wei_to_satoshis(ptokens);
}
});
use ethereum_types::U256;
pub fn convert_wei_to_satoshis(ptoken: U256) -> u64 {
match ptoken.checked_div(U256::from(
10u64.pow(PTOKEN_ERC777_NUM_DECIMALS - BTC_NUM_DECIMALS as u32),
)) {
Some(amount) => amount.as_u64(),
None => 0,
}
}
pub const PTOKEN_ERC777_NUM_DECIMALS: u32 = 18;
pub const BTC_NUM_DECIMALS: usize = 8;
ethereum-types = "0.12.1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment