Skip to content

Commit 18f0a42

Browse files
committed
solana: Add fuzz harness for RateLimitState
1 parent d555365 commit 18f0a42

File tree

4 files changed

+22
-3
lines changed

4 files changed

+22
-3
lines changed

solana/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[workspace]
22
members = [
33
"programs/*",
4-
"modules/*"
4+
"modules/*",
55
]
66
resolver = "2"
77

solana/fuzz/src/Cargo.toml

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
[package]
22
name = "ntt-fuzz"
33
version = "0.0.1"
4+
edition = "2021"
45

56
[[bin]]
6-
name = "ntt-fuzz"
7+
name = "fuzz-trimmed-amount"
78
path = "fuzz_trimmed_amount.rs"
9+
[[bin]]
10+
name = "fuzz-rate-limit-state"
11+
path = "fuzz_rate_limit.rs"
812

9-
edition = "2021"
1013
[dependencies]
1114
ntt-messages = { path = "../../modules/ntt-messages" }
15+
example-native-token-transfers = { path = "../../programs/example-native-token-transfers" }
1216
honggfuzz = "0.5"
1317
arbitrary = { version = "1", optional = true, features = ["derive"] }
1418

solana/fuzz/src/fuzz_rate_limit.rs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
use honggfuzz::fuzz;
2+
use example_native_token_transfers::queue::rate_limit::RateLimitState;
3+
4+
fn main() {
5+
loop {
6+
fuzz!(|input: (u64, u64)| {
7+
let (limit, new_limit) = input;
8+
9+
let mut rls = RateLimitState::new(limit);
10+
rls.set_limit(new_limit)
11+
});
12+
}
13+
}

solana/modules/ntt-messages/src/trimmed_amount.rs

+2
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ impl TrimmedAmount {
6161
return Ok(amount);
6262
}
6363
if from_decimals > to_decimals {
64+
// [`u64::checked_pow`] expects a u32 argument
6465
let power: u32 = (from_decimals - to_decimals).into();
6566
// Exponentiation will overflow u64 when `power` is greater than 18
6667
let scaling_factor: u64 = 10u64
@@ -69,6 +70,7 @@ impl TrimmedAmount {
6970

7071
Ok(amount / scaling_factor)
7172
} else {
73+
// [`u64::checked_pow`] expects a u32 argument
7274
let power: u32 = (to_decimals - from_decimals).into();
7375

7476
// Exponentiation will overflow u64 when `power` is greater than 18

0 commit comments

Comments
 (0)