Skip to content

feat(corpus): add sender and value mutation in corpus fuzzing#12934

Open
mattvaux wants to merge 6 commits intofoundry-rs:masterfrom
mattvaux:feat/corpus-sender-value-mutation
Open

feat(corpus): add sender and value mutation in corpus fuzzing#12934
mattvaux wants to merge 6 commits intofoundry-rs:masterfrom
mattvaux:feat/corpus-sender-value-mutation

Conversation

@mattvaux
Copy link

Fixes TODO: mutate sender and value in corpus fuzzing.

Only calldata was being mutated, so we missed bugs in contracts that depend on msg.sender or msg.value. Added mutation for both fields with 15% probability each.

Added value field to CallDetails with serde default for backward compatibility.

Comment on lines +635 to +646
// Mutate value with 15% probability
if test_runner.rng().random_ratio(15, 100) {
// Generate random value, biased towards smaller values for practical fuzzing
let value = match test_runner.rng().random_range(0..=10) {
0..=5 => U256::from(test_runner.rng().random_range(0..=1000)), // Small values
6..=8 => U256::from(test_runner.rng().random_range(0..=1_000_000_000_000_000u64)), // Medium values (up to 0.001 ETH)
9 => U256::from(test_runner.rng().random_range(0..=1_000_000_000_000_000_000u64)), // Large values (up to 1 ETH)
10 => U256::MAX, // Edge case
_ => unreachable!(),
};
tx.call_details.value = Some(value);
}
Copy link
Contributor

@0xalpharush 0xalpharush Dec 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should use the existing U256 mutator or something like this one that considers whether func is payable and be added as a mutation here

I believe you will also need to add the balance to the sender in the DB as in #8644

tx.call_details.calldata =
function.abi_encode_input(&prev_inputs).map_err(|e| eyre!(e.to_string()))?.into();

// Mutate sender with 15% probability
Copy link
Contributor

@0xalpharush 0xalpharush Dec 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This cannot be purely random and needs to use this function. It should also be added as a mutation here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants