Skip to content

smite-ir: Add InstructionReorderMutator - #61

Merged
morehouse merged 2 commits into
lnfuzz:masterfrom
Chand-ra:instr_reorder
Jun 18, 2026
Merged

smite-ir: Add InstructionReorderMutator#61
morehouse merged 2 commits into
lnfuzz:masterfrom
Chand-ra:instr_reorder

Conversation

@Chand-ra

Copy link
Copy Markdown

Add an InstructionReorder mutator for Smite IR. Mutates a given program by swapping two '"Act" instructions that have no data dependencies between them. This explores alternative execution orderings while preserving SSA invariants.

@Chand-ra

Copy link
Copy Markdown
Author

Drafting right now because tests for the mutator are yet to be implemented.

@morehouse morehouse left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This all looks correctly implemented to me.

Unfortunately I don't think it's useful until we implement more Act operations and start generating more interesting programs. Currently we just have SendMessage and RecvAcceptChannel, which we actually don't want to swap (doing so would lead to 5s timeout delays as we wait to receive a message that never comes, which would register as a hang).

I think it would be best to defer further work on this mutator until we have some more interesting things to swap. Then we can figure out how to avoid swapping a Recv* operation to a location before a SendMessage. We will also then be able to collect better data about how often swapping is actually possible with the current implementation, which may lead us to investigate further changes to this mutator (e.g., moving entire dependency trees).

Comment thread smite-ir/src/mutators/instruction_reorder.rs Outdated
Comment thread smite-ir/src/mutators/instruction_reorder.rs Outdated
Comment thread smite-ir/src/mutators/instruction_reorder.rs Outdated
@Chand-ra
Chand-ra marked this pull request as ready for review June 15, 2026 11:13
@Chand-ra
Chand-ra force-pushed the instr_reorder branch 2 times, most recently from ea4f6d4 to 3f95a3e Compare June 15, 2026 11:21

@morehouse morehouse left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think this is a good first implementation of a reordering mutator. Currently it isn't useful, since we never generate programs with independent act operations, but once we have splice or generator-insertion mutators it should be more useful.

I also think it would be worth evaluating this mutator against an alternative implementation that moves and inserts an act operation elsewhere instead of swapping. That seems like a more general mutation that may be more effective.

Comment thread smite-ir/src/operation.rs Outdated

/// Returns true for Act instructions.
#[must_use]
pub fn is_act(&self) -> bool {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

has_side_effects is almost identical to this function. We should add a comment explaining why we need a different function.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

This confused me as well. Do we need a different function, instead of making do with has_side_effects()? Here's how Act instructions are defined:

/ -- Act: side effects against the target --

The only difference between the two is that is_act() returns false for CreateFundingTransaction and has_side_effects() returns true.

This is because CreateFundingTransaction isn't mentioned in the list of Act instructions, but I think it should because it interacts with the Bitcoin CLI similar to MineBlocks and MineBlocks is listed as an Act instruction.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Either way is fine with me.

Really the only benefit of having a separate function is to remove any Create* operations that only interact with the Bitcoin CLI and not the target. In practice I'd expect such functions to have minimal effect on the target itself, and I'm not sure rearranging them will make a big difference. For corpus minimization we might care more about the side effects because we're trying to preserve the exact same coverage on the target (or else AFL++ rejects the minimization).

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I'll go ahead and drop is_act().

  1. I don't see a point in artificially separating operations that perform Bitcoin CLI interactions.
  2. Maintaining two methods that are 99% identical sounds like a maintenance trap.
  3. It may be that swapping such functions has minimal effect on the target itself, but we're not decreasing the mutator's surface area. Since the change is a net-positive, or neutral at worst, I think it's worth making.

Comment thread smite-ir-mutator/src/lib.rs Outdated
Comment thread smite-ir/src/tests.rs
Comment thread smite-ir/src/tests.rs
Comment thread smite-ir/src/operation.rs Outdated
@Chand-ra

Copy link
Copy Markdown
Author

I also think it would be worth evaluating this mutator against an alternative implementation that moves and inserts an act operation elsewhere instead of swapping. That seems like a more general mutation that may be more effective.

Hmm, not very sure about this. The target does not, after all, care about whether we LoadBytes or DerivePoint before sending it a message or mining blocks. I do agree that it is a more general version of this mutator. Maybe there's some edge case that I cannot think of.

@morehouse

Copy link
Copy Markdown
Collaborator

I also think it would be worth evaluating this mutator against an alternative implementation that moves and inserts an act operation elsewhere instead of swapping. That seems like a more general mutation that may be more effective.

Hmm, not very sure about this. The target does not, after all, care about whether we LoadBytes or DerivePoint before sending it a message or mining blocks. I do agree that it is a more general version of this mutator. Maybe there's some edge case that I cannot think of.

Here's an example where the insertion mutator could mutate the program in ways a swap mutator could not:

v1 = BuildOpenChannel(...)
v2 = SendOpenChannel(v1)
v3 = RecvAcceptChannel(v2)
v4 = ExtractAcceptChannelChannelType(v3)
MineBlocks(6)

The swap mutator cannot modify the program at all. The insertion mutator can move MineBlocks to any point between or before the other Act operations.

@Chand-ra

Copy link
Copy Markdown
Author

Will rebase after review.

@morehouse morehouse left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Ready to rebase

@Chand-ra

Copy link
Copy Markdown
Author

Rebased on top of the latest master.

@morehouse morehouse left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM.

Smoke tested against LDK IR scenario for 10 minutes.

@morehouse
morehouse merged commit 46bdf2b into lnfuzz:master Jun 18, 2026
5 checks passed
@Chand-ra
Chand-ra deleted the instr_reorder branch June 19, 2026 03:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants